Changeset 37351


Ignore:
Timestamp:
2023-02-24T13:52:49+13:00 (12 months ago)
Author:
davidb
Message:

More careful definition of function externs. Macs now treat an implicit declaration of a function as an error, not a warning, and so the mg source code needs to be tightened up on its include headers

Location:
main/trunk/greenstone2/common-src/indexers/mg/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/common-src/indexers/mg/lib/perf_hash.c

    r29083 r37351  
    2828#define STRUCT
    2929
     30#include <time.h>
     31
    3032#include "sysfuncs.h"
    3133
     
    3436#include "messages.h"
    3537#include "perf_hash.h"
     38#include "random.h"
    3639#include "netorder.h"  /* [RPAP - Jan 97: Endian Ordering] */
    3740
     
    4346/* Random Number stuff */
    4447static mg_s_long seed[] = {0, 0};
    45 #define RANDOM() irandm(seed)
     48#define RANDOM() mgirandm(seed)
    4649#define SEED_RANDOM(the_seed) do{ seed[0] = the_seed; }while(0)
    4750
     
    6265
    6366/* An arbitrary amount to add to both MAX_N and n for building tree/acyclic
    64    graph -- John McPherson - jrm21 (22-02-2001) */
     67graph -- John McPherson - jrm21 (22-02-2001) */
    6568#define MAX_N_HEADROOM  100
    6669
     
    9699/* test, used in the assignment step               */
    97100static struct
    98   {
    99     int sp;
    100     int *st;
    101   }
     101{
     102int sp;
     103int *st;
     104}
    102105S;
    103106#define push(s, e) s.st[s.sp++] = (e)
     
    114117unique (int v)
    115118{               /* checks if vertex v belongs to only one edge */
    116   return (FIRST[v] != 0 && NEXT[FIRST[v]] == 0) ? FIRST[v] : 0;
     119return (FIRST[v] != 0 && NEXT[FIRST[v]] == 0) ? FIRST[v] : 0;
    117120}               /*unique */
    118121
     
    128131{               /* deletes edge e from list of v */
    129132
    130   int b, norm_b;
    131   b = FIRST[v];
     133int b, norm_b;
     134b = FIRST[v];
     135assert (norm (b) != 0);
     136if (norm (b) == e)
     137FIRST[v] = NEXT[FIRST[v]];
     138else
     139{
     140while (norm (NEXT[b]) != e)
     141{
     142  b = NEXT[b];
    132143  assert (norm (b) != 0);
    133   if (norm (b) == e)
    134     FIRST[v] = NEXT[FIRST[v]];
    135   else
    136     {
    137       while (norm (NEXT[b]) != e)
    138     {
    139       b = NEXT[b];
    140       assert (norm (b) != 0);
    141     }
    142       NEXT[b] = NEXT[NEXT[b]];
    143     }
     144}
     145NEXT[b] = NEXT[NEXT[b]];
     146}
    144147}               /*delete */
    145148
     
    155158ph_remove (int e, int v)
    156159{
    157   int b;
    158   mk[e] = ERASED;
    159   push (S, e);
    160 
    161   if (NODEa[e] != v)
    162     delete (NODEa[e], e);
    163   if (NODEb[e] != v)
    164     delete (NODEb[e], e);
    165   if (NODEc[e] != v)
    166     delete (NODEc[e], e);
    167 
    168   if (NODEa[e] != v && mk[b = norm (unique (NODEa[e]))] == MEMBER)
    169     ph_remove (b, NODEa[e]);
    170   if (NODEb[e] != v && mk[b = norm (unique (NODEb[e]))] == MEMBER)
    171     ph_remove (b, NODEb[e]);
    172   if (NODEc[e] != v && mk[b = norm (unique (NODEc[e]))] == MEMBER)
    173     ph_remove (b, NODEc[e]);
     160int b;
     161mk[e] = ERASED;
     162push (S, e);
     163
     164if (NODEa[e] != v)
     165delete (NODEa[e], e);
     166if (NODEb[e] != v)
     167delete (NODEb[e], e);
     168if (NODEc[e] != v)
     169delete (NODEc[e], e);
     170
     171if (NODEa[e] != v && mk[b = norm (unique (NODEa[e]))] == MEMBER)
     172ph_remove (b, NODEa[e]);
     173if (NODEb[e] != v && mk[b = norm (unique (NODEb[e]))] == MEMBER)
     174ph_remove (b, NODEb[e]);
     175if (NODEc[e] != v && mk[b = norm (unique (NODEc[e]))] == MEMBER)
     176ph_remove (b, NODEc[e]);
    174177}
    175178#else
     
    178181static int StackPos, StackMax;
    179182static struct Stack
    180   {
    181     int e, v, m;
    182   }
    183  *Stack = NULL;
     183{
     184int e, v, m;
     185}
     186*Stack = NULL;
    184187
    185188#define StackAdd(_e, _v, _m)                        \
    186   do {                                  \
    187     if (StackPos == StackMax)                       \
    188       {                                 \
    189         StackMax <<= 1;                         \
    190     if (!(Stack = Xrealloc(Stack, sizeof(*Stack) * StackMax)))  \
    191       return(-1);                           \
    192       }                                 \
    193     Stack[StackPos].e = (_e);                       \
    194     Stack[StackPos].v = (_v);                       \
    195     Stack[StackPos++].m = (_m);                     \
    196   } while(0)
     189do {                                    \
     190if (StackPos == StackMax)                       \
     191{                                   \
     192StackMax <<= 1;                         \
     193if (!(Stack = Xrealloc(Stack, sizeof(*Stack) * StackMax)))  \
     194  return(-1);                           \
     195}                                   \
     196Stack[StackPos].e = (_e);                       \
     197Stack[StackPos].v = (_v);                       \
     198Stack[StackPos++].m = (_m);                     \
     199} while(0)
    197200
    198201
     
    200203ph_remove (int e, int v)
    201204{
    202   if (!Stack)
    203     {
    204       StackMax = 256;
    205       if (!(Stack = Xmalloc (sizeof (*Stack) * StackMax)))
    206     return (-1);
    207       StackPos = 0;
    208     }
    209   Stack[StackPos].e = e;
    210   Stack[StackPos].v = v;
    211   Stack[StackPos].m = 0;
    212   StackPos++;
    213   while (StackPos)
    214     {
    215       int m, b;
    216       StackPos--;
    217       e = Stack[StackPos].e;
    218       v = Stack[StackPos].v;
    219       m = Stack[StackPos].m;
    220 
    221 
    222       switch (m)
    223     {
    224     case 0:
    225       {
    226         mk[e] = ERASED;
    227         push (S, e);
    228 
    229         if (NODEa[e] != v)
    230           delete (NODEa[e], e);
    231         if (NODEb[e] != v)
    232           delete (NODEb[e], e);
    233         if (NODEc[e] != v)
    234           delete (NODEc[e], e);
    235 
    236         if (NODEa[e] != v && mk[b = norm (unique (NODEa[e]))] == MEMBER)
    237           {
    238         Stack[StackPos++].m = 1;
    239         StackAdd (b, NODEa[e], 0);
    240         break;
    241           }
    242       }
    243     case 1:
    244       {
    245         if (NODEb[e] != v && mk[b = norm (unique (NODEb[e]))] == MEMBER)
    246           {
    247         Stack[StackPos++].m = 2;
    248         StackAdd (b, NODEb[e], 0);
    249         break;
    250           }
    251       }
    252     case 2:
    253       if (NODEc[e] != v && mk[b = norm (unique (NODEc[e]))] == MEMBER)
    254         StackAdd (b, NODEc[e], 0);
    255     }
    256     }
    257   return (0);
     205if (!Stack)
     206{
     207StackMax = 256;
     208if (!(Stack = Xmalloc (sizeof (*Stack) * StackMax)))
     209return (-1);
     210StackPos = 0;
     211}
     212Stack[StackPos].e = e;
     213Stack[StackPos].v = v;
     214Stack[StackPos].m = 0;
     215StackPos++;
     216while (StackPos)
     217{
     218int m, b;
     219StackPos--;
     220e = Stack[StackPos].e;
     221v = Stack[StackPos].v;
     222m = Stack[StackPos].m;
     223
     224
     225switch (m)
     226{
     227case 0:
     228  {
     229    mk[e] = ERASED;
     230    push (S, e);
     231
     232    if (NODEa[e] != v)
     233      delete (NODEa[e], e);
     234    if (NODEb[e] != v)
     235      delete (NODEb[e], e);
     236    if (NODEc[e] != v)
     237      delete (NODEc[e], e);
     238
     239    if (NODEa[e] != v && mk[b = norm (unique (NODEa[e]))] == MEMBER)
     240      {
     241    Stack[StackPos++].m = 1;
     242    StackAdd (b, NODEa[e], 0);
     243    break;
     244      }
     245  }
     246case 1:
     247  {
     248    if (NODEb[e] != v && mk[b = norm (unique (NODEb[e]))] == MEMBER)
     249      {
     250    Stack[StackPos++].m = 2;
     251    StackAdd (b, NODEb[e], 0);
     252    break;
     253      }
     254  }
     255case 2:
     256  if (NODEc[e] != v && mk[b = norm (unique (NODEc[e]))] == MEMBER)
     257    StackAdd (b, NODEc[e], 0);
     258}
     259}
     260return (0);
    258261}
    259262#endif
     
    271274{
    272275
    273   int v, e;
    274   /* build list of edges for each node */
    275   for (v = 1; v <= n; FIRST[v++] = 0);
    276   for (e = 1; e <= m; e++)
    277     {
    278       NEXT[A + e] = FIRST[NODEa[e]];
    279       FIRST[NODEa[e]] = A + e;
    280       NEXT[B + e] = FIRST[NODEb[e]];
    281       FIRST[NODEb[e]] = B + e;
    282       NEXT[C + e] = FIRST[NODEc[e]];
    283       FIRST[NODEc[e]] = C + e;
    284 
    285       /* mark edge e as belonging to the hypergraph */
    286       mk[e] = MEMBER;
    287     }
    288 
    289 
    290   S.sp = 0;         /* empty the stack */
    291   mk[0] = ERASED;       /* a sentinel for the test below */
    292   for (v = 1; v <= n; v++)
    293     {
    294       if (mk[e = norm (unique (v))] == MEMBER)
    295     ph_remove (e, v);
    296     }
    297 
    298   /* check if any edges were left in the graph */
    299   return S.sp == m;
     276int v, e;
     277/* build list of edges for each node */
     278for (v = 1; v <= n; FIRST[v++] = 0);
     279for (e = 1; e <= m; e++)
     280{
     281NEXT[A + e] = FIRST[NODEa[e]];
     282FIRST[NODEa[e]] = A + e;
     283NEXT[B + e] = FIRST[NODEb[e]];
     284FIRST[NODEb[e]] = B + e;
     285NEXT[C + e] = FIRST[NODEc[e]];
     286FIRST[NODEc[e]] = C + e;
     287
     288/* mark edge e as belonging to the hypergraph */
     289mk[e] = MEMBER;
     290}
     291
     292
     293S.sp = 0;           /* empty the stack */
     294mk[0] = ERASED;     /* a sentinel for the test below */
     295for (v = 1; v <= n; v++)
     296{
     297if (mk[e = norm (unique (v))] == MEMBER)
     298ph_remove (e, v);
     299}
     300
     301/* check if any edges were left in the graph */
     302return S.sp == m;
    300303}               /*acyclic */
    301304
     
    313316{
    314317
    315   int e, k = 0;
    316   int i, j;
    317   u_char *w;
    318 
    319   do
    320     {
    321       /* Added variable - need to increase MAX_N on allocate as well */
    322       *n = (int) (num * c + MAX_N_HEADROOM); /* john mcpherson 22-02-2001 */
    323 
    324       /* initialize tables of random integers */
    325       for (i = 0; i < MAX_CH; i++)
    326     for (j = 0; j < MAX_L; j++)
    327       {
     318int e, k = 0;
     319int i, j;
     320u_char *w;
     321
     322do
     323{
     324/* Added variable - need to increase MAX_N on allocate as well */
     325*n = (int) (num * c + MAX_N_HEADROOM); /* john mcpherson 22-02-2001 */
     326
     327/* initialize tables of random integers */
     328for (i = 0; i < MAX_CH; i++)
     329for (j = 0; j < MAX_L; j++)
     330  {
    328331#ifndef STRUCT
    329         tb0[i][j] = RANDOM () % *n;
    330         tb1[i][j] = RANDOM () % *n;
    331         tb2[i][j] = RANDOM () % *n;
     332    tb0[i][j] = RANDOM () % *n;
     333    tb1[i][j] = RANDOM () % *n;
     334    tb2[i][j] = RANDOM () % *n;
    332335#else
    333336        struct tb_entry *tbp = &tb[i][j];
  • main/trunk/greenstone2/common-src/indexers/mg/lib/random.c

    r25147 r37351  
    2222/*
    2323 *  A random number generator called as a function by
    24  *  random (iseed)  or  irandm (iseed)
     24 *  mgrandom (iseed)    or  mgirandm (iseed)
    2525 *  The parameter should be a pointer to a 2-element long vector.
    2626 *  The first function returns a double uniform in 0 .. 1.
     
    173173
    174174double
    175 random (mg_s_long is [2])
     175mgrandom (mg_s_long is [2])
    176176{
    177177    mg_s_long it, leh, nit;
     
    194194
    195195mg_s_long
    196 irandm (mg_s_long is [2])
     196mgirandm (mg_s_long is [2])
    197197{
    198198    mg_s_long it, leh, nit;
  • main/trunk/greenstone2/common-src/indexers/mg/lib/random.h

    r25147 r37351  
    3838#include "mglong.h"
    3939
    40 double random (mg_s_long is [2]);
    41 mg_s_long irandm (mg_s_long is [2]);
     40double mgrandom (mg_s_long is [2]);
     41mg_s_long mgirandm (mg_s_long is [2]);
    4242
    4343#endif
  • main/trunk/greenstone2/common-src/indexers/mg/lib/simplefrenchstem.c

    r16583 r37351  
    1919 **************************************************************************/
    2020
     21#include "unitool.h"
    2122#include "simplefrenchstem.h"
    2223
Note: See TracChangeset for help on using the changeset viewer.