~ubuntu-branches/ubuntu/warty/ncbi-tools6/warty

« back to all changes in this revision

Viewing changes to network/medarch/server/getmedart.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2002-04-04 22:13:09 UTC
  • Revision ID: james.westby@ubuntu.com-20020404221309-vfze028rfnlrldct
Tags: upstream-6.1.20011220a
ImportĀ upstreamĀ versionĀ 6.1.20011220a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "getmedart.h"
 
2
 
 
3
#include <sys/types.h>
 
4
#include <sys/time.h>
 
5
#include <sys/timeb.h>
 
6
#include <string.h>
 
7
 
 
8
#define bzero(b,length) memset(b,0,length)
 
9
#define bcopy(b1,b2,length) memmove(b2,b1,length)
 
10
 
 
11
/* NOTE: The mr_get_article script will return sections is numerical order! */
 
12
 
 
13
#define MR_STATE_ARTICLE        0               /* Basic article data */
 
14
#define MR_STATE_ISO_VTITLE     1
 
15
#define MR_STATE_ISO_ADDRESS    2
 
16
#define MR_STATE_AUTHOR         3
 
17
#define MR_STATE_ISO_AUTHOR     4
 
18
#define MR_STATE_ISO_ABSTRACT   5               /* We send ISO first for the */
 
19
#define MR_STATE_ABSTRACT       6               /* abstract only */
 
20
#define MR_STATE_MESH           7
 
21
#define MR_STATE_SUBHEADING     8
 
22
#define MR_STATE_SUBSTANCE      9
 
23
#define MR_STATE_CROSSREFERENCE 10
 
24
#define MR_STATE_SUPPORT        11
 
25
#define MR_STATE_GENESYMBOL     12
 
26
#define MR_STATE_DONE           255
 
27
 
 
28
#define PATCH_BUFFER_SIZE       8192
 
29
#define TEXT_BUFFER_SIZE        8192
 
30
#define MAX_ABSTRACT_PATCHES    64
 
31
 
 
32
extern FILE * Id_timing_file;
 
33
 
 
34
#ifdef SYSV
 
35
hrtime_t Time_start, Time_back;
 
36
#define MACRO_before_exec \
 
37
        if (Id_timing_file) \
 
38
        Time_start = gethrtime();
 
39
 
 
40
#define MACRO_after_exec(type) \
 
41
        if (Id_timing_file) {\
 
42
        Time_back = gethrtime();\
 
43
        fprintf(Id_timing_file,"%s %ld %ld\n", #type, (long) (Time_start/1000000.), (long) (( Time_back- Time_start)/ 1000000. )); fflush(Id_timing_file);}
 
44
#else
 
45
struct timeb Time_start, Time_back;
 
46
#define MACRO_before_exec \
 
47
        if (Id_timing_file) \
 
48
        ftime(&Time_start);
 
49
 
 
50
#define MACRO_after_exec(type) \
 
51
        if (Id_timing_file) {\
 
52
        ftime (&Time_back);\
 
53
        fprintf(Id_timing_file,"%s %ld %ld\n", #type, (long) Time_start.time, (long) (( Time_back.time - Time_start.time)* 1000 + (Time_back.millitm - Time_start.millitm))); fflush(Id_timing_file);}
 
54
#endif  
 
55
 
 
56
typedef struct AbPatch {
 
57
        DBINT            line_no;
 
58
        DBINT            length;
 
59
        DBBINARY        *start;
 
60
} AbPatch;
 
61
 
 
62
typedef struct  AbPList {
 
63
        int             n_patches;
 
64
        AbPatch         patches[MAX_ABSTRACT_PATCHES];
 
65
        int             used;
 
66
        DBBINARY        buffer[PATCH_BUFFER_SIZE];
 
67
} AbPList;
 
68
 
 
69
 
 
70
char *strstr();
 
71
static
 
72
/*
 
73
*               skip_undefined_section(DBPROCESSdb)
 
74
* RCS Modification History:
 
75
* $Log: getmedart.c,v $
 
76
* Revision 6.0  1997/08/25 18:36:12  madden
 
77
* Revision changed to 6.0
 
78
*
 
79
* Revision 1.3  1995/05/30 18:00:10  tatiana
 
80
* cleanup title
 
81
*
 
82
* Revision 1.2  1995/05/17  17:54:43  epstein
 
83
* add RCS log revision history
 
84
*
 
85
*/
 
86
int     skip_undefined_section( DBPROCESS *db )
 
87
{
 
88
    RETCODE     rc;
 
89
 
 
90
    /* This simply skips to the end of the data */
 
91
 
 
92
    while( (rc = dbnextrow( db )) != NO_MORE_ROWS && rc != FAIL );
 
93
    return( (rc == FAIL) ? Error : True );
 
94
}
 
95
 
 
96
 
 
97
static
 
98
/*
 
99
*               title_append(DbTitle(title),charrest)
 
100
*/
 
101
void    title_append( DbTitle(title), char *rest )
 
102
{
 
103
    int len;
 
104
 
 
105
    if( *rest == 0 ) return;
 
106
    for( len = strlen( title ); len < DBSIZE_Article_title; len++ )
 
107
        title[len] = ' ';
 
108
    strcpy( &title[len], rest );
 
109
}
 
110
 
 
111
static void check_title(char *title)
 
112
{
 
113
        char *s;
 
114
        
 
115
        if ((s = strstr(title, "[see comments]")) != NULL) {
 
116
                        s--;
 
117
                        while( s >= title && (*s == ' ') ) {
 
118
                                *s = '\0';
 
119
                                s--;
 
120
                        }
 
121
        }
 
122
}
 
123
 
 
124
void check_pages(char *pages)
 
125
{
 
126
        char    *s;
 
127
        
 
128
        for (; isspace(*pages); pages++);
 
129
        if ((s = strchr(pages, ' ')) != NULL) {
 
130
                *s = '\0';
 
131
        }
 
132
}
 
133
 
 
134
static
 
135
/*
 
136
*               process_article(DBPROCESSdb,MedArtrec)
 
137
*/
 
138
int     process_article( DBPROCESS *db, MedArt *rec )
 
139
{
 
140
    RETCODE             rc;
 
141
    DbColumn    (Article,title1);
 
142
    DbColumn    (Article,vtitle1);
 
143
    char                *chr;
 
144
 
 
145
    /* Load the article row from the database */
 
146
        /* TODO - CHECK THE FIELDS IN THE BIND! */
 
147
    rc = SybaseLoad( db,
 
148
            1,  INTBIND,        sizeof(rec->ui),        &rec->ui,
 
149
            2,  INTBIND,        sizeof(rec->mri),       &rec->mri,
 
150
            3,  NTBSTRINGBIND,  sizeof(rec->title),     rec->title,
 
151
            4,  NTBSTRINGBIND,  sizeof(title1),         title1,
 
152
            5,  NTBSTRINGBIND,  sizeof(rec->vtitle),    rec->vtitle,
 
153
            6,  NTBSTRINGBIND,  sizeof(vtitle1),        vtitle1,
 
154
            7,  NTBSTRINGBIND,  sizeof(rec->address),   rec->address,
 
155
            8,  NTBSTRINGBIND,  sizeof(rec->pages),     rec->pages,
 
156
            9,  SMALLBIND,      0,                      &rec->entry_month,
 
157
            10, NTBSTRINGBIND,  sizeof(rec->volume),    rec->volume,
 
158
            11, NTBSTRINGBIND,  sizeof(rec->issue),     rec->issue,
 
159
            12, NTBSTRINGBIND,  sizeof(rec->pubdate),   rec->pubdate,
 
160
            13, NTBSTRINGBIND,  sizeof(rec->med_abbr),  rec->med_abbr,
 
161
            14, NTBSTRINGBIND,  sizeof(rec->language_code), rec->language_code,
 
162
            0 );
 
163
    if( rc != REG_ROW ) return( False );
 
164
 
 
165
    /* Add the extension columns to the title and vtitle fields */
 
166
 
 
167
    rec->title_type = 6; /* ml-jta */
 
168
    title_append( rec->title,  title1  );
 
169
    title_append( rec->vtitle, vtitle1 );
 
170
    
 
171
    check_title(rec->title);
 
172
    check_title(rec->vtitle);
 
173
    
 
174
        if (strncmp(rec->pages, "Suppl", 5) == 0) {
 
175
                if ((chr = strchr(rec->pages, ':')) != NULL) {
 
176
                        *chr = '\0';
 
177
                        if (rec->issue[0] != '\0') {
 
178
                                strncat(rec->issue, rec->pages, 
 
179
                                                DBSIZE_Issue_issue - strlen(rec->issue));
 
180
                        } else {
 
181
                                strncat(rec->volume, rec->pages, 
 
182
                                                DBSIZE_Issue_volume - strlen(rec->volume));
 
183
                        }
 
184
                        strcpy(rec->pages, chr + 1);
 
185
                }
 
186
        }
 
187
        check_pages(rec->pages);
 
188
 
 
189
    /* Done */
 
190
 
 
191
    return( True );
 
192
}
 
193
 
 
194
 
 
195
static
 
196
/*
 
197
*               process_pub_article(DBPROCESSdb,MedArtrec)
 
198
*/
 
199
int     process_pub_article( DBPROCESS *db, MedArt *rec )
 
200
{
 
201
    RETCODE             rc;
 
202
    DbColumn    (Article,title1);
 
203
    DbColumn    (Article,vtitle1);
 
204
    char                *chr;
 
205
 
 
206
    /* Load the article row from the database */
 
207
        /* TODO - CHECK THE FIELDS IN THE BIND! */
 
208
    rc = SybaseLoad( db,
 
209
            1,  INTBIND,        sizeof(rec->ui),        &rec->ui,
 
210
            2,  INTBIND,        sizeof(rec->mri),       &rec->mri,
 
211
            3,  NTBSTRINGBIND,  sizeof(rec->title),     rec->title,
 
212
            4,  NTBSTRINGBIND,  sizeof(title1),         title1,
 
213
            5,  NTBSTRINGBIND,  sizeof(rec->vtitle),    rec->vtitle,
 
214
            6,  NTBSTRINGBIND,  sizeof(vtitle1),        vtitle1,
 
215
            7,  NTBSTRINGBIND,  sizeof(rec->address),   rec->address,
 
216
            8,  NTBSTRINGBIND,  sizeof(rec->pages),     rec->pages,
 
217
            9,  SMALLBIND,      0,                      &rec->entry_month,
 
218
            10, NTBSTRINGBIND,  sizeof(rec->volume),    rec->volume,
 
219
            11, NTBSTRINGBIND,  sizeof(rec->issue),     rec->issue,
 
220
            12, NTBSTRINGBIND,  sizeof(rec->pubdate),   rec->pubdate,
 
221
            13, NTBSTRINGBIND,  sizeof(rec->med_abbr),  rec->med_abbr,
 
222
            14, NTBSTRINGBIND,  sizeof(rec->language_code), rec->language_code,
 
223
            15, INTBIND,        sizeof(rec->title_type),&rec->title_type,
 
224
            0 );
 
225
    if( rc != REG_ROW ) return( False );
 
226
 
 
227
    /* Add the extension columns to the title and vtitle fields */
 
228
 
 
229
    title_append( rec->title,  title1  );
 
230
    title_append( rec->vtitle, vtitle1 );
 
231
 
 
232
        check_title(rec->title);
 
233
        check_title(rec->vtitle);
 
234
 
 
235
        if (strncmp(rec->pages, "Suppl", 5) == 0) {
 
236
                if ((chr = strchr(rec->pages, ':')) != NULL) {
 
237
                        *chr = '\0';
 
238
                        if (rec->issue[0] != '\0') {
 
239
                                strncat(rec->issue, rec->pages, 
 
240
                                                DBSIZE_Issue_issue - strlen(rec->issue));
 
241
                        } else {
 
242
                                strncat(rec->volume, rec->pages, 
 
243
                                                DBSIZE_Issue_volume - strlen(rec->volume));
 
244
                        }
 
245
                        strcpy(rec->pages, chr + 1);
 
246
                }
 
247
        }
 
248
        check_pages(rec->pages);
 
249
 
 
250
    /* Done */
 
251
 
 
252
    return( True );
 
253
}
 
254
 
 
255
 
 
256
static  DBINT           patch_sequence = 0;
 
257
static  DBINT           patch_item = 0;
 
258
static  DBINT           patch_length;
 
259
static  MaxBinary       patch_line;
 
260
 
 
261
static
 
262
/*
 
263
*               load_patch(DBPROCESSdb,DBBINARYpatches,intsize,
 
264
*/
 
265
int     load_patch( DBPROCESS *db, DBBINARY *patches, int size,
 
266
                DBINT   *item, DBINT *length, int first )
 
267
{
 
268
    RETCODE     rc;
 
269
    DBINT       sequence;
 
270
 
 
271
    /* If we have buffered a line - get it */
 
272
 
 
273
    if( ! first && patch_sequence == 1 ) {
 
274
        *item = patch_item;
 
275
        bcopy( patch_line, patches, patch_length );
 
276
        *length = patch_length;
 
277
        sequence = 1;
 
278
    } else {
 
279
        *length = patch_length = patch_item = sequence = 0;
 
280
    }
 
281
 
 
282
    while ( (rc = SybaseLoad( db,
 
283
        1,      INTBIND,        0,                      &patch_item,
 
284
        2,      INTBIND,        0,                      &patch_sequence,
 
285
        3,      INTBIND,        0,                      &patch_length,
 
286
        4,      BINARYBIND,     sizeof(patch_line),      patch_line,
 
287
        0)) == REG_ROW )
 
288
    {
 
289
        /* If this is the first line - init the setup */
 
290
 
 
291
        if( sequence == 0 ) {
 
292
            if( patch_sequence != 1 ) continue;         /* Skip junk */
 
293
            *item = patch_item;
 
294
        }
 
295
 
 
296
        /* If we get this far, test for a continuation line */
 
297
 
 
298
        if( patch_sequence == (sequence + 1) && patch_item == *item ) {
 
299
            if( ( patch_length + *length ) > size )
 
300
                goto error;                     /* Overflow */
 
301
            bcopy( patch_line, patches + *length, patch_length );
 
302
            *length += patch_length;
 
303
            continue;
 
304
        } else if( patch_sequence != 1 )
 
305
            goto error;                         /* Patch sequence error */
 
306
 
 
307
        /* If we get here - we're at the start of the next patch */
 
308
 
 
309
        break;
 
310
    }
 
311
    if( rc == FAIL ) goto error;
 
312
    if( rc != REG_ROW ) patch_sequence = 0;     /* Reset on end */
 
313
 
 
314
    /* Normal exit */
 
315
 
 
316
    return( (*length == 0) ? False : True );
 
317
 
 
318
    /* Error exit */
 
319
 
 
320
error:
 
321
    patch_sequence = 0;
 
322
    return( Error );
 
323
}
 
324
 
 
325
 
 
326
/*ARGSUSED*/
 
327
static
 
328
/*
 
329
*               patch_string(DBPROCESSdb,charstr,intsize)
 
330
*/
 
331
int     patch_string( DBPROCESS *db, char *str, int size )
 
332
{
 
333
    DBBINARY    patches[PATCH_BUFFER_SIZE];
 
334
    DBINT       patch_length = 0, item = 0;
 
335
    DBCHAR      buffer[TEXT_BUFFER_SIZE];
 
336
    int         rv;
 
337
    char        *ptr;
 
338
 
 
339
    /* Get the title patches from the input string */
 
340
 
 
341
    if( ! DBROWS( db ) ) return( False );
 
342
    rv = load_patch( db, patches, sizeof(patches), &item, &patch_length, True );
 
343
    if( rv != True ) return( rv );
 
344
 
 
345
    /* We have the patches, apply them */
 
346
 
 
347
    if( ApplyIsoPatches( str, size, buffer, sizeof(buffer),
 
348
        patches, patch_length ) > 0 )
 
349
    {
 
350
        return( Error );
 
351
    }
 
352
 
 
353
  /* Done - put the stuff back */
 
354
   strcpy( str, buffer );
 
355
    return( True );
 
356
}
 
357
 
 
358
 
 
359
static
 
360
/*
 
361
*               process_author(DBPROCESSdb,MedArtrec)
 
362
*/
 
363
int     process_author( DBPROCESS *db, MedArt *rec )
 
364
{
 
365
    DbColumn(Name,name);
 
366
    RETCODE     rc;
 
367
    DBINT       seq;
 
368
 
 
369
    /* Read the author list */
 
370
 
 
371
    while( (rc = SybaseLoad( db,
 
372
                1,      INTBIND,        0,              &seq,
 
373
                2,      NTBSTRINGBIND,  sizeof(name),   name,
 
374
                0 )) == REG_ROW )
 
375
    {
 
376
        if( seq > MAX_AUTHOR_COUNT )
 
377
            continue;                   /* Author index too large */
 
378
        strcpy( rec->authors[seq], name );
 
379
        if( (seq+1) > rec->n_authors ) rec->n_authors = seq+1;
 
380
    }
 
381
 
 
382
    return((rc == NO_MORE_ROWS) ? ((rec->n_authors == 0) ? False: True): Error);
 
383
}
 
384
 
 
385
 
 
386
/*ARGSUSED*/
 
387
static
 
388
/*
 
389
*               patch_author(DBPROCESSdb,MedArtrec)
 
390
*/
 
391
int     patch_author( DBPROCESS *db, MedArt *rec )
 
392
{
 
393
    DBBINARY    patches[PATCH_BUFFER_SIZE];
 
394
    DBINT       patch_length = 0, item = 0;
 
395
    DBCHAR      buffer[TEXT_BUFFER_SIZE];
 
396
    int         rv = False;
 
397
    int first;
 
398
 
 
399
    for( first = 1;; first = 0 ) {
 
400
        switch( load_patch( db, patches, sizeof(patches), &item,
 
401
                                &patch_length, first ) )
 
402
        {
 
403
            case True:  /* We found a patch */
 
404
                if( ApplyIsoPatches( rec->authors[item-1],
 
405
                        sizeof(rec->authors[0]), buffer, sizeof(buffer),
 
406
                        patches, patch_length ) == 0 )
 
407
                {
 
408
                    strcpy( rec->authors[item-1], buffer );
 
409
                    rv = True;
 
410
                }
 
411
                break;
 
412
            case False: /* No patch found */
 
413
                return( rv );
 
414
            case Error: /* Oops - */
 
415
                return( Error );
 
416
        }
 
417
    }
 
418
}
 
419
 
 
420
 
 
421
/*ARGSUSED*/
 
422
static
 
423
/*
 
424
*               process_abstract(DBPROCESSdb,MedArtrec,AbPListplist)
 
425
*/
 
426
int     process_abstract( DBPROCESS *db, MedArt *rec, AbPList *plist )
 
427
{
 
428
    DbNColumn(Abstract,abstract,line);  /* Line buffer */
 
429
    int pi = 0;                         /* Index to next patch */
 
430
    int ti = 0;                         /* Index to next text line */
 
431
    int next_line = 1;                  /* Expect this line next */
 
432
    int rv = False;
 
433
    RETCODE     rc;
 
434
    DBINT       line_no;
 
435
 
 
436
    while( (sizeof(rec->abstract) - ti) >= sizeof(line) ) {
 
437
 
 
438
        /* Skip patches to lines alsready passed */
 
439
 
 
440
        while(pi < plist->n_patches && next_line > plist->patches[pi].line_no)
 
441
                pi++;
 
442
        /* If a patch is expected, prepare for it */
 
443
 
 
444
        if( pi < plist->n_patches && next_line == plist->patches[pi].line_no ) {
 
445
 
 
446
            /* The next line should be a patch line */
 
447
            rc = SybaseLoad( db,
 
448
                1,      INTBIND,        sizeof(line_no), &line_no,
 
449
                2,      NTBSTRINGBIND,  sizeof(line),    line,
 
450
                0 );
 
451
 
 
452
            /* Apply the patch */
 
453
 
 
454
            if( rc == REG_ROW && line_no == next_line ) {
 
455
                (void) ApplyIsoPatches( line, strlen(line), &rec->abstract[ti],
 
456
                    sizeof(rec->abstract) - ti, plist->patches[pi].start,
 
457
                    plist->patches[pi].length );
 
458
            }
 
459
        } else {
 
460
            rc = SybaseLoad( db,
 
461
                1,      INTBIND,        sizeof(line_no), &line_no,
 
462
                2,      NTBSTRINGBIND,  sizeof(line),    &rec->abstract[ti],
 
463
                0 );
 
464
            if( rc != REG_ROW ) break;
 
465
        }
 
466
        ti += strlen( &rec->abstract[ti] );     /* New abstract length */
 
467
        next_line = line_no + 1;
 
468
 
 
469
        /* Exit */
 
470
    }
 
471
 
 
472
    /* Return the status */
 
473
 
 
474
    return( (rv == Error) ? rv : ((ti > 0) ? True : False) );
 
475
}
 
476
 
 
477
 
 
478
/*ARGSUSED*/
 
479
static
 
480
/*
 
481
*               patch_abstract(DBPROCESSdb,MedArtrec,AbPListplist)
 
482
*/
 
483
int     patch_abstract( DBPROCESS *db, MedArt *rec, AbPList *plist )
 
484
{
 
485
    int first = 1;
 
486
    int rv;
 
487
 
 
488
    /* Load the patches */
 
489
 
 
490
    for( plist->n_patches = 0; plist->n_patches < MAX_ABSTRACT_PATCHES &&
 
491
         (rv = load_patch( db, &plist->buffer[plist->used],
 
492
                sizeof(plist->buffer) - plist->used,
 
493
                &plist->patches[plist->n_patches].line_no,
 
494
                &plist->patches[plist->n_patches].length,
 
495
                first )) == True;
 
496
         plist->n_patches++ )
 
497
    {
 
498
        /* A patch was loaded - record it */
 
499
        plist->used += plist->patches[plist->n_patches].length;
 
500
        first = 0;
 
501
    }
 
502
 
 
503
    /* Done */
 
504
 
 
505
    return( (rv == Error) ? Error : ((plist->n_patches > 0) ? True : False) );
 
506
}
 
507
 
 
508
 
 
509
static
 
510
int     mesh_compare( const void *m1, const void *m2 )
 
511
{
 
512
    return( strcmp( ((Mesh *) m1)->heading, ((Mesh *) m2)->heading ) );
 
513
}
 
514
 
 
515
static
 
516
/*
 
517
*               process_mesh(DBPROCESSdb,MedArtrec)
 
518
*/
 
519
int     process_mesh( DBPROCESS *db, MedArt *rec )
 
520
{
 
521
    DBINT       id_mesh;
 
522
    DbColumn    (Mesh,main_point);
 
523
    DbColumn    (Mesh,heading);
 
524
    RETCODE     rc;
 
525
 
 
526
 
 
527
    /* Read the main mesh headings into the table */
 
528
 
 
529
    rec->n_mesh = 0;
 
530
 
 
531
    while( (rc = SybaseLoad( db,
 
532
                1,      INTBIND,        0,                      &id_mesh,
 
533
                2,      NTBSTRINGBIND,  sizeof(main_point),      main_point,
 
534
                3,      NTBSTRINGBIND,  sizeof(heading),         heading,
 
535
                0 )) == REG_ROW )
 
536
    {
 
537
        /* Load the MeSH heading into the table. */
 
538
        if( rec->n_mesh >= MAX_MESH_COUNT ) continue;   /* Too many */
 
539
        rec->mesh[rec->n_mesh].id_mesh = id_mesh;
 
540
        strcpy( rec->mesh[rec->n_mesh].main_point, main_point );
 
541
        strcpy( rec->mesh[rec->n_mesh].heading, heading );
 
542
        ( rec->n_mesh )++;
 
543
    }
 
544
 
 
545
    /* Done */
 
546
 
 
547
    if ( rec->n_mesh > 0 )
 
548
        qsort( rec->mesh, rec->n_mesh, sizeof(Mesh), mesh_compare );
 
549
 
 
550
    return( rec->n_mesh == 0 ? False : True );
 
551
}
 
552
 
 
553
 
 
554
/*ARGSUSED*/
 
555
static
 
556
/*
 
557
*               process_subheading(DBPROCESSdb,MedArtrec)
 
558
*/
 
559
int     process_subheading( DBPROCESS *db, MedArt *rec )
 
560
{
 
561
    RETCODE     rc;
 
562
    DbColumn    (Subheading,main_point);
 
563
    DbColumn    (Subheading,code);
 
564
    DbColumn    (Subheading,name);
 
565
    DbColumn    (Subheading,description);
 
566
    int         id_mesh, i, seq;
 
567
 
 
568
    while( (rc = SybaseLoad( db,
 
569
                1,      INTBIND,        0,                      &id_mesh,
 
570
                2,      NTBSTRINGBIND,  sizeof(main_point),      main_point,
 
571
                3,      NTBSTRINGBIND,  sizeof(code),            code,
 
572
                4,      NTBSTRINGBIND,  sizeof(name),            name,
 
573
                5,      NTBSTRINGBIND,  sizeof(description),     description,
 
574
                0 )) == REG_ROW )
 
575
    {
 
576
        Qual    *q;
 
577
        Mesh    *m;
 
578
 
 
579
        for ( i = 0, seq = -1; i< rec->n_mesh; i++ )
 
580
           if ( id_mesh == rec->mesh[i].id_mesh )
 
581
           {
 
582
                seq = i; break;
 
583
           }
 
584
 
 
585
        if( seq == -1 ) continue;
 
586
        m = &rec->mesh[seq];
 
587
 
 
588
        if( m->n_qual >= MAX_QUALIFIER_COUNT ) continue;
 
589
        q = &m->qualifiers[m->n_qual++];
 
590
        strcpy(q->main_point, main_point);
 
591
        strcpy(q->code, code);
 
592
        strcpy(q->name, name);
 
593
        strcpy(q->description, description);
 
594
    }
 
595
    return( True );
 
596
}
 
597
 
 
598
 
 
599
/*ARGSUSED*/
 
600
static
 
601
/*
 
602
*               process_substance(DBPROCESSdb,MedArtrec)
 
603
*/
 
604
int     process_substance( DBPROCESS *db, MedArt *rec )
 
605
{
 
606
    int         i;
 
607
    RETCODE     rc;
 
608
 
 
609
    /* Read the subsances from the database */
 
610
 
 
611
    for( i = 0; i < MAX_SUBSTANCE_COUNT; i++ ) {
 
612
        rc = SybaseLoad( db,
 
613
                1,      NTBSTRINGBIND,  sizeof(rec->substances[0].number),
 
614
                                        rec->substances[i].number,
 
615
                2,      NTBSTRINGBIND,  sizeof(rec->substances[0].name),
 
616
                                        rec->substances[i].name,
 
617
                0 );
 
618
        if( rc != REG_ROW ) break;
 
619
    }
 
620
    rec->n_substances = i;
 
621
 
 
622
    return( (rc == FAIL) ? Error : ( (i==0) ? False : True ) );
 
623
}
 
624
 
 
625
 
 
626
/*ARGSUSED*/
 
627
static
 
628
/*
 
629
*               process_xref(DBPROCESSdb,MedArtrec)
 
630
*/
 
631
int     process_xref( DBPROCESS *db, MedArt *rec )
 
632
{
 
633
    int         i;
 
634
    RETCODE     rc;
 
635
 
 
636
    /* Read the subsances from the database */
 
637
 
 
638
    for( i = 0; i < MAX_XREF_COUNT; i++ ) {
 
639
        rc = SybaseLoad( db,
 
640
                1,      NTBSTRINGBIND,  sizeof(rec->xrefs[0].database),
 
641
                                        rec->xrefs[i].database,
 
642
                2,      NTBSTRINGBIND,  sizeof(rec->xrefs[0].accession),
 
643
                                        rec->xrefs[i].accession,
 
644
                0 );
 
645
        if( rc != REG_ROW ) break;
 
646
    }
 
647
 
 
648
    /* Make sure that + is last */
 
649
 
 
650
    rec->n_xrefs = i;
 
651
 
 
652
    return( (rc == FAIL) ? Error : ( (i==0) ? False : True ) );
 
653
}
 
654
 
 
655
 
 
656
/*ARGSUSED*/
 
657
static
 
658
/*
 
659
*               process_support(DBPROCESSdb,MedArtrec)
 
660
*/
 
661
int     process_support( DBPROCESS *db, MedArt *rec )
 
662
{
 
663
    int         i;
 
664
    RETCODE     rc;
 
665
    int         have_plus = 0;
 
666
 
 
667
    /* Read the subsances from the database */
 
668
 
 
669
    for( i = 0; i < MAX_IDNUM_COUNT; i++ ) {
 
670
        rc = SybaseLoad( db,
 
671
                1,      NTBSTRINGBIND,  sizeof(SupportId),      rec->idnums[i],
 
672
                0 );
 
673
        if( rc != REG_ROW ) break;
 
674
 
 
675
        /* If we get a +, just remeber that we saw it.  We'll put it last */
 
676
 
 
677
        if( strcmp( rec->idnums[i], "+" ) == 0 ) {
 
678
            i--;
 
679
            have_plus++;
 
680
        }
 
681
    }
 
682
 
 
683
    /* Add the plus back in */
 
684
 
 
685
    if( i < MAX_IDNUM_COUNT && have_plus > 0 ) {
 
686
        strcpy( rec->idnums[i], "+" );
 
687
        i++;
 
688
    }
 
689
    rec->n_idnum = i;
 
690
 
 
691
    return( (rc == FAIL) ? Error : ( (i==0) ? False : True ) );
 
692
}
 
693
 
 
694
 
 
695
/*ARGSUSED*/
 
696
static
 
697
/*
 
698
*               process_genesymbol(DBPROCESSdb,MedArtrec)
 
699
*/
 
700
int     process_genesymbol( DBPROCESS *db, MedArt *rec )
 
701
{
 
702
    int         i;
 
703
    RETCODE     rc;
 
704
 
 
705
    /* Read the subsances from the database */
 
706
 
 
707
    for( i = 0; i < MAX_GENESYM_COUNT; i++ ) {
 
708
        rc = SybaseLoad( db,
 
709
            1,  NTBSTRINGBIND,  sizeof(GeneSymbol),     rec->gene_symbols[i],
 
710
            0 );
 
711
        if( rc != REG_ROW ) break;
 
712
    }
 
713
    rec->n_gene_symbols = i;
 
714
 
 
715
    return( (rc == FAIL) ? Error : ( (i==0) ? False : True ) );
 
716
}
 
717
 
 
718
 
 
719
/*
 
720
*               ProcessMedlineArticle(DBPROCESS *db, MedArt *rec)
 
721
*/
 
722
 
 
723
int ProcessMedlineArticle( DBPROCESS *db, MedArt *rec, int is_pub )
 
724
{
 
725
    AbPList     plist;
 
726
    RETCODE     rc;
 
727
    DBCHAR      state_msg[40];          /* Text description of state */
 
728
    DBINT       state;
 
729
    int         status;
 
730
 
 
731
    /* Clear out the input record */
 
732
 
 
733
    bzero( rec, sizeof(MedArt) );
 
734
    bzero( &plist, sizeof(plist) );     /* Get rid of all patches */
 
735
 
 
736
    /* Collect the data from the database */
 
737
 
 
738
    for(status = True; status != Error; rc = dbresults( db )) {
 
739
 
 
740
        /* Get the next header row from the batch and then skip to
 
741
           the results batch associated with the header (dbresults call) */
 
742
 
 
743
        rc = SybaseLoad( db,
 
744
                1,      INTBIND,        0,                      &state,
 
745
                2,      NTBSTRINGBIND,  sizeof(state_msg),      state_msg,
 
746
                0 );
 
747
        if( rc == REG_ROW ) {
 
748
            /* EOF marked with MR_STATE_DONE as the state */
 
749
            if( state == MR_STATE_DONE ) 
 
750
                return( True );
 
751
 
 
752
            /* Prepare to read the results section */
 
753
            rc = dbresults(db);
 
754
        }
 
755
        if( rc != SUCCEED ) return( Error );
 
756
 
 
757
        /* Dispatch to the handler for this block of input */
 
758
 
 
759
        switch( state ) {
 
760
            case MR_STATE_ARTICLE:      /* This one should be first */
 
761
                if ( is_pub )
 
762
                        status = process_pub_article( db, rec );
 
763
                else
 
764
                        status = process_article( db, rec );
 
765
                if( status != True ) return( status );
 
766
                break;
 
767
            case MR_STATE_ISO_VTITLE:
 
768
                status = patch_string(db, rec->vtitle, sizeof(rec->vtitle));
 
769
                break;
 
770
            case MR_STATE_ISO_ADDRESS:
 
771
                status = patch_string(db, rec->address, sizeof(rec->address));
 
772
                break;
 
773
            case MR_STATE_AUTHOR:
 
774
                status = process_author( db, rec );
 
775
                break;
 
776
            case MR_STATE_ISO_AUTHOR:
 
777
                status = patch_author( db, rec );
 
778
                break;
 
779
            case MR_STATE_ISO_ABSTRACT:
 
780
                if( plist.n_patches > 0 )
 
781
                    bzero( &plist, sizeof(plist) );
 
782
                status = patch_abstract( db, rec, &plist );
 
783
                break;
 
784
            case MR_STATE_ABSTRACT:
 
785
                status = process_abstract( db, rec, &plist );
 
786
                break;
 
787
            case MR_STATE_MESH:
 
788
                status = process_mesh( db, rec );
 
789
                break;
 
790
            case MR_STATE_SUBHEADING:
 
791
                status = process_subheading( db, rec );
 
792
                break;
 
793
            case MR_STATE_SUBSTANCE:
 
794
                status = process_substance( db, rec );
 
795
                break;
 
796
            case MR_STATE_CROSSREFERENCE:
 
797
                status = process_xref( db, rec );
 
798
                break;
 
799
            case MR_STATE_SUPPORT:
 
800
                status = process_support( db, rec );
 
801
                break;
 
802
            case MR_STATE_GENESYMBOL:
 
803
                status = process_genesymbol( db, rec );
 
804
                break;
 
805
            default:                    /* Unknown state - ignore it */
 
806
                status = skip_undefined_section( db );
 
807
                break;
 
808
        }
 
809
    }
 
810
 
 
811
    /* Return the proper status */
 
812
 
 
813
    return( Error );
 
814
}
 
815
 
 
816
 
 
817
/*
 
818
*               GetMedlineArticle(DBPROCESSdb,intui,intflags,MedArtrec)
 
819
*/
 
820
int     GetMedlineArticle( DBPROCESS *db, int ui, int flags, MedArt *rec )
 
821
{
 
822
    RETCODE     rc;
 
823
 
 
824
    dbfreebuf( db );
 
825
MACRO_before_exec
 
826
    rc = RunSybase( db, "execute mr_get_article %d, %d", ui, flags );
 
827
MACRO_after_exec(GetMedlineArticle)
 
828
    if( rc != SUCCEED ) return( Error );
 
829
 
 
830
    return( ProcessMedlineArticle( db, rec, 0 ) );
 
831
}
 
832
 
 
833
/*
 
834
*               GetMedlinePub(DBPROCESSdb,intui,intflags,MedArtrec)
 
835
*/
 
836
int     GetMedlinePub( DBPROCESS *db, int ui, int flags, MedArt *rec )
 
837
{
 
838
    RETCODE     rc;
 
839
 
 
840
 
 
841
    dbfreebuf( db );
 
842
MACRO_before_exec
 
843
    rc = RunSybase( db, "execute mr_get_pub %d, %d", ui, flags );
 
844
MACRO_after_exec(GetMedlinePub)
 
845
    if( rc != SUCCEED ) return( Error );
 
846
 
 
847
    return( ProcessMedlineArticle( db, rec, 1 ) );
 
848
}