pike.git / src / modules / _WhiteFish / whitefish.c

version» Context lines:

pike.git/src/modules/_WhiteFish/whitefish.c:1: + /* -*- c -*- + || This file is part of Pike. For copyright information see COPYRIGHT. + || Pike is distributed under GPL, LGPL and MPL. See the file COPYING + || for more information. + */ +    #include <math.h>    - #include "global.h" - #include "stralloc.h" - #include "global.h" + #include "module.h"   #include "pike_macros.h"   #include "interpret.h"   #include "program.h" - #include "object.h" - #include "array.h" +    #include "module_support.h" - #include "module.h" +       #include "config.h"      #include "whitefish.h"   #include "resultset.h"   #include "blob.h"   #include "blobs.h"   #include "linkfarm.h"    - /* 7.2 compatibility stuff. */ -  - #ifndef PIKE_MODULE_INIT - /* must be included last */ - #include "module_magic.h" - #define PIKE_MODULE_INIT void pike_module_init(void) - #define PIKE_MODULE_EXIT void pike_module_exit(void) - #endif -  +    struct tofree   {    Blob **blobs;    Blob **tmp;    int nblobs;    struct object *res;   };      static void free_stuff( void *_t )   {
pike.git/src/modules/_WhiteFish/whitefish.c:70:   static void handle_hit( Blob **blobs,    int nblobs,    struct object *res,    int docid,    double *field_c[65],    double *prox_c[8],    double mc, double mp,    int cutoff )   {    int i, j, k, end = 0; -  Hit *hits = malloc( nblobs * sizeof(Hit) ); +  Hit *hits = calloc( nblobs, sizeof(Hit) );    unsigned char *nhits = malloc( nblobs );    unsigned char *pos = malloc( nblobs );       int matrix[65][8];    -  MEMSET(matrix, 0, sizeof(matrix) ); -  MEMSET(hits, 0, nblobs * sizeof(Hit) ); -  MEMSET(pos, 0, nblobs ); +  memset(matrix, 0, sizeof(matrix) );       for( i = 0; i<nblobs; i++ )    nhits[i] = wf_blob_nhits( blobs[i] );          for( i = 0; i<nblobs; i++ )    { -  MEMSET( pos, 0, nblobs ); +  memset( pos, 0, nblobs );    for( j = 0; j<nhits[i]; j++ )    {    hits[i] = wf_blob_hit( blobs[i], j );    matrix[MOFF(hits[i])][3]++;       /* forward the other positions */    for( k = 0; k<nblobs; k++ )    if( k != i && pos[ k ] < nhits[ k ] )    {    while( (hits[k].raw < hits[i].raw) && (pos[ k ] < nhits[ k ]))
pike.git/src/modules/_WhiteFish/whitefish.c:139:    double field_c[65],    double prox_c[8],    int cutoff)   {    struct object *res = wf_resultset_new();    struct tofree *__f = malloc( sizeof( struct tofree ) );    double max_c=0.0, max_p=0.0;    ONERROR e;    int i, j;    Blob **tmp; -  tmp = malloc( nblobs * sizeof( Blob *) ); +  tmp = calloc( nblobs, sizeof( Blob *) );       __f->res = res;    __f->blobs = blobs;    __f->nblobs = nblobs;    __f->tmp = tmp;    SET_ONERROR( e, free_stuff, __f );          for( i = 0; i<65; i++ )    if( field_c[i] > max_c )
pike.git/src/modules/_WhiteFish/whitefish.c:205:    int docid,    double *field_c[65],    double mc )   {    int i, j, k;    unsigned char *nhits = malloc( nblobs*2 );    unsigned char *first = nhits+nblobs;    int matrix[65];    double accum = 0.0;    -  MEMSET(matrix, 0, sizeof(matrix) ); +  memset(matrix, 0, sizeof(matrix) );          for( i = 0; i<nblobs; i++ )    {    nhits[i] = wf_blob_nhits( blobs[i] );    first[i] = 0;    }          for( i = 0; i<nhits[0]; i++)
pike.git/src/modules/_WhiteFish/whitefish.c:414:    double proximity_coefficients[8];    double field_coefficients[65];    int numblobs, i;    Blob **blobs;       struct svalue *cb;    struct object *res;    struct array *_words, *_field;       /* 1: Get all arguments. */ -  get_all_args( "do_query_phrase", args, "%a%a%*", +  get_all_args( NULL, args, "%a%a%*",    &_words, &_field, &cb);       if( _field->size != 65 )    Pike_error("Illegal size of field_coefficients array (expected 65)\n" );       numblobs = _words->size;    if( !numblobs )    {    struct object *o = wf_resultset_new( );    pop_n_elems( args );    wf_resultset_push( o );    return;    }    -  blobs = malloc( sizeof(Blob *) * numblobs ); +  blobs = calloc( numblobs, sizeof(Blob *) );       for( i = 0; i<numblobs; i++ )    blobs[i] = wf_blob_new( cb, _words->item[i].u.string );       for( i = 0; i<65; i++ )    field_coefficients[i] = (double)_field->item[i].u.integer;       res = low_do_query_phrase(blobs,numblobs, field_coefficients );    pop_n_elems( args );    wf_resultset_push( res );
pike.git/src/modules/_WhiteFish/whitefish.c:506:    double proximity_coefficients[8];    double field_coefficients[65];    int numblobs, i, cutoff;    Blob **blobs;       struct svalue *cb;    struct object *res;    struct array *_words, *_field, *_prox;       /* 1: Get all arguments. */ -  get_all_args( "do_query_and", args, "%a%a%a%d%*", +  get_all_args( NULL, args, "%a%a%a%d%*",    &_words, &_field, &_prox, &cutoff, &cb);       if( _field->size != 65 )    Pike_error("Illegal size of field_coefficients array (expected 65)\n" );    if( _prox->size != 8 )    Pike_error("Illegal size of proximity_coefficients array (expected 8)\n" );       numblobs = _words->size;    if( !numblobs )    {    struct object *o = wf_resultset_new( );    pop_n_elems( args );    wf_resultset_push( o );    return;    }    -  blobs = malloc( sizeof(Blob *) * numblobs ); +  blobs = calloc( numblobs, sizeof(Blob *) );       for( i = 0; i<numblobs; i++ )    blobs[i] = wf_blob_new( cb, _words->item[i].u.string );       for( i = 0; i<8; i++ )    proximity_coefficients[i] = (double)_prox->item[i].u.integer;       for( i = 0; i<65; i++ )    field_coefficients[i] = (double)_field->item[i].u.integer;   
pike.git/src/modules/_WhiteFish/whitefish.c:607:    double proximity_coefficients[8];    double field_coefficients[65];    int numblobs, i, cutoff;    Blob **blobs;       struct svalue *cb;    struct object *res;    struct array *_words, *_field, *_prox;       /* 1: Get all arguments. */ -  get_all_args( "do_query_or", args, "%a%a%a%d%*", +  get_all_args( NULL, args, "%a%a%a%d%*",    &_words, &_field, &_prox, &cutoff, &cb);       if( _field->size != 65 )    Pike_error("Illegal size of field_coefficients array (expected 65)\n" );    if( _prox->size != 8 )    Pike_error("Illegal size of proximity_coefficients array (expected 8)\n" );       numblobs = _words->size;    if( !numblobs )    {    struct object *o = wf_resultset_new( );    pop_n_elems( args );    wf_resultset_push( o );    return;    }    -  blobs = malloc( sizeof(Blob *) * numblobs ); +  blobs = calloc( numblobs, sizeof(Blob *) );       for( i = 0; i<numblobs; i++ )    blobs[i] = wf_blob_new( cb, _words->item[i].u.string );       for( i = 0; i<8; i++ )    proximity_coefficients[i] = (double)_prox->item[i].u.integer;       for( i = 0; i<65; i++ )    field_coefficients[i] = (double)_field->item[i].u.integer;   
pike.git/src/modules/_WhiteFish/whitefish.c:654:    */         PIKE_MODULE_INIT   {    init_resultset_program();    init_blob_program();    init_blobs_program();    init_linkfarm_program();    -  add_function( "do_query_or", f_do_query_or, -  "function(array(string),array(int),array(int),int" -  ",function(string,int,int:string):object)", -  0 ); +  ADD_FUNCTION( "do_query_or", f_do_query_or, +  tFunc( tArr(tStr) tArr(tInt) tArr(tInt) tInt +  tFunc(tStr tInt tInt, tStr), tObj), 0 );    -  add_function( "do_query_and", f_do_query_and, -  "function(array(string),array(int),array(int),int" -  ",function(string,int,int:string):object)", -  0 ); +  ADD_FUNCTION( "do_query_and", f_do_query_and, +  tFunc( tArr(tStr) tArr(tInt) tArr(tInt) tInt +  tFunc(tStr tInt tInt, tStr), tObj), 0 );    -  add_function( "do_query_phrase", f_do_query_phrase, -  "function(array(string),array(int)" -  ",function(string,int,int:string):object)", -  0 ); +  ADD_FUNCTION( "do_query_phrase", f_do_query_phrase, +  tFunc( tArr(tStr) tArr(tInt) tFunc(tStr tInt tInt, tStr), +  tObj ), 0 );   }      PIKE_MODULE_EXIT   {    exit_resultset_program();    exit_blob_program();    exit_blobs_program();    exit_linkfarm_program();   }