~ubuntu-branches/ubuntu/breezy/ncbi-tools6/breezy

« back to all changes in this revision

Viewing changes to api/gbparint.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
/* gbparint.c
 
2
* ===========================================================================
 
3
*
 
4
*                            PUBLIC DOMAIN NOTICE                          
 
5
*               National Center for Biotechnology Information
 
6
*                                                                          
 
7
*  This software/database is a "United States Government Work" under the   
 
8
*  terms of the United States Copyright Act.  It was written as part of    
 
9
*  the author's official duties as a United States Government employee and 
 
10
*  thus cannot be copyrighted.  This software/database is freely available 
 
11
*  to the public for use. The National Library of Medicine and the U.S.    
 
12
*  Government have not placed any restriction on its use or reproduction.  
 
13
*                                                                          
 
14
*  Although all reasonable efforts have been taken to ensure the accuracy  
 
15
*  and reliability of the software and data, the NLM and the U.S.          
 
16
*  Government do not and cannot warrant the performance or results that    
 
17
*  may be obtained by using this software or data. The NLM and the U.S.    
 
18
*  Government disclaim all warranties, express or implied, including       
 
19
*  warranties of performance, merchantability or fitness for any particular
 
20
*  purpose.                                                                
 
21
*                                                                          
 
22
*  Please cite the author in any work or product based on this material.   
 
23
*
 
24
* ===========================================================================
 
25
*
 
26
* File Name:  gbparint.c
 
27
*
 
28
* Author:  Karl Sirotkin
 
29
*
 
30
* $Log: gbparint.c,v $
 
31
* Revision 6.5  2001/06/07 17:00:54  tatiana
 
32
* added gi option in Nlm_gbparselex()
 
33
*
 
34
* Revision 6.4  2000/03/20 23:38:39  aleksey
 
35
* Finally submitted the changes which have been made by serge bazhin
 
36
* and been kept in my local directory.
 
37
*
 
38
* These changes allow to establish user callback functions
 
39
* in 'Asn2ffJobPtr' structure which are called within
 
40
* 'SeqEntryToFlatAjp' function call.
 
41
* The new members are:
 
42
* user_data       - pointer to a user context for passing data
 
43
* ajp_count_index - user defined function
 
44
* ajp_print_data  - user defined function
 
45
* ajp_print_index - user defined function
 
46
*
 
47
* Revision 6.3  1999/04/06 19:42:55  bazhin
 
48
* Changes, related to flat2asn's ACCESSION.VERSION parsing.
 
49
*
 
50
* Revision 6.2  1999/04/02 21:15:07  tatiana
 
51
* accession.version added
 
52
*
 
53
* Revision 6.1  1997/10/24 21:28:39  bazhin
 
54
* Is able to distinguish and process "gap(...)" tokens inside
 
55
* of location entries. Made for CONTIG line join contents.
 
56
*
 
57
* Revision 6.0  1997/08/25 18:06:05  madden
 
58
* Revision changed to 6.0
 
59
*
 
60
* Revision 5.3  1997/06/19 18:38:01  vakatov
 
61
* [WIN32,MSVC++]  Adopted for the "NCBIOBJ.LIB" DLL'ization
 
62
*
 
63
* Revision 5.2  1997/02/06 00:16:14  tatiana
 
64
* dealing with 2+6 accession
 
65
*
 
66
 * Revision 5.1  1997/01/27  19:16:17  tatiana
 
67
 * accept two-letter prefix in accession number
 
68
 *
 
69
 * Revision 5.0  1996/05/28  13:23:23  ostell
 
70
 * Set to revision 5.0
 
71
 *
 
72
 * Revision 4.2  1996/05/21  21:12:05  tatiana
 
73
 * bullet proof in gbparseint()
 
74
 *
 
75
 * Revision 4.1  1995/07/31  19:02:10  tatiana
 
76
 * fix seq_id->choice
 
77
 *
 
78
 * Revision 1.8  1995/05/15  21:46:05  ostell
 
79
 * added Log line
 
80
 *
 
81
*
 
82
*
 
83
*/
 
84
 
 
85
#include "parsegb.h"
 
86
#include "gbparlex.h"
 
87
#include "errdefn.h"
 
88
#include <sequtil.h>
 
89
#include <edutil.h>
 
90
 
 
91
#define TAKE_FIRST 1
 
92
#define TAKE_SECOND 2
 
93
 
 
94
void Nlm_gbgap PROTO((ValNodePtr PNTR currentPt, ValNodePtr PNTR retval));
 
95
 
 
96
/*--------- do_Nlm_gbparse_error () ---------------*/
 
97
 
 
98
NLM_EXTERN void
 
99
do_Nlm_gbparse_error (CharPtr msg, CharPtr details)
 
100
{
 
101
        Int4 len = StringLen(msg) +7;
 
102
        CharPtr errmsg, temp;
 
103
 
 
104
        len += StringLen(details);
 
105
        temp = errmsg= MemNew((size_t)len);
 
106
        temp = StringMove(temp, msg);
 
107
        temp = StringMove(temp, " at ");
 
108
        temp = StringMove(temp, details);
 
109
 
 
110
        ErrPostStr(SEV_ERROR, ERR_FEATURE_LocationParsing, errmsg);
 
111
 
 
112
        MemFree(errmsg);
 
113
}
 
114
#define MAKE_THREAD_SAFE
 
115
#ifndef MAKE_THREAD_SAFE
 
116
static Nlm_gbparse_errfunc Err_func = do_Nlm_gbparse_error;
 
117
static Nlm_gbparse_rangefunc Range_func = NULL;
 
118
static Pointer Nlm_gbparse_range_data = NULL;
 
119
#define MACRO_THREAD_SAVE_STATIC
 
120
 
 
121
#else
 
122
 
 
123
#include <ncbithr.h>
 
124
 
 
125
static TNlmTls Err_func_tls=NULL;
 
126
static TNlmTls Range_func_tls=NULL;
 
127
static TNlmTls Nlm_gbparse_range_data_tls=NULL;
 
128
 
 
129
#define MACRO_THREAD_SAVE_STATIC \
 
130
        Nlm_gbparse_errfunc Err_func = NULL; \
 
131
        Nlm_gbparse_rangefunc Range_func = NULL; \
 
132
        Pointer Nlm_gbparse_range_data = NULL; \
 
133
        if(Err_func_tls) NlmTlsGetValue(Err_func_tls,(VoidPtr PNTR)&Err_func); \
 
134
        if(!Err_func) Err_func = do_Nlm_gbparse_error; \
 
135
        if(Range_func_tls) NlmTlsGetValue(Range_func_tls,(VoidPtr PNTR)&Range_func); \
 
136
        if(Nlm_gbparse_range_data_tls) NlmTlsGetValue(Nlm_gbparse_range_data_tls,(VoidPtr PNTR)&Nlm_gbparse_range_data); 
 
137
#endif
 
138
 
 
139
/*------------------ Nlm_gbcheck_range()-------------*/
 
140
static void
 
141
Nlm_gbcheck_range(Int4 num, SeqIdPtr idp, Boolean PNTR keep_rawPt, int PNTR num_errsPt, ValNodePtr head, ValNodePtr current)
 
142
{
 
143
        Int4 len;
 
144
        MACRO_THREAD_SAVE_STATIC;
 
145
        if (Range_func != NULL){
 
146
                len = (*Range_func)(Nlm_gbparse_range_data, idp);
 
147
                if (len > 0)
 
148
                if (num <0 || num >= len){
 
149
                        Nlm_gbparse_error("range error",  head, current);
 
150
                        * keep_rawPt = TRUE;
 
151
                        (*num_errsPt) ++;
 
152
                }
 
153
        }
 
154
}
 
155
 
 
156
/*----------- Nlm_install_gbparse_error_handler ()-------------*/
 
157
 
 
158
NLM_EXTERN void
 
159
Nlm_install_gbparse_error_handler(Nlm_gbparse_errfunc new_func)
 
160
{
 
161
#ifdef MAKE_THREAD_SAFE
 
162
        NlmTlsSetValue(&Err_func_tls, (VoidPtr PNTR) new_func, NULL);
 
163
#else
 
164
        Err_func = new_func;
 
165
#endif
 
166
}
 
167
 
 
168
/*----------- Nlm_install_gbparse_range_func ()-------------*/
 
169
 
 
170
NLM_EXTERN void
 
171
Nlm_install_gbparse_range_func(Pointer data, Nlm_gbparse_rangefunc new_func)
 
172
{
 
173
#ifdef MAKE_THREAD_SAFE
 
174
        NlmTlsSetValue(&Range_func_tls, (VoidPtr PNTR) new_func,NULL);
 
175
        NlmTlsSetValue(&Nlm_gbparse_range_data_tls,data,NULL);
 
176
#else
 
177
        Range_func = new_func;
 
178
        Nlm_gbparse_range_data = data;
 
179
#endif
 
180
 
 
181
}
 
182
 
 
183
/*--------- Nlm_gbparse_error()-----------*/
 
184
 
 
185
NLM_EXTERN void
 
186
Nlm_gbparse_error(CharPtr front, ValNodePtr head, ValNodePtr current)
 
187
{
 
188
        CharPtr details;
 
189
 
 
190
        MACRO_THREAD_SAVE_STATIC;
 
191
 
 
192
        details = Nlm_gbparse_point (head, current);
 
193
        Err_func (front,details); 
 
194
        MemFree(details);
 
195
}
 
196
 
 
197
/*------ Nlm_gbparse_point ()----*/
 
198
 
 
199
NLM_EXTERN CharPtr 
 
200
Nlm_gbparse_point (ValNodePtr head, ValNodePtr current)
 
201
{
 
202
        CharPtr temp, retval = NULL;
 
203
        int len = 0;
 
204
        ValNodePtr now;
 
205
 
 
206
        for ( now = head; now ; now = now -> next){
 
207
                switch ( now-> choice){
 
208
                        case GBPARSE_INT_JOIN :
 
209
                                len += 4;
 
210
                                break;
 
211
                        case GBPARSE_INT_COMPL :
 
212
                                len += 10;
 
213
                                break;
 
214
                        case GBPARSE_INT_LEFT :
 
215
                        case GBPARSE_INT_RIGHT :
 
216
                        case GBPARSE_INT_CARET :
 
217
                        case GBPARSE_INT_GT :
 
218
                        case GBPARSE_INT_LT :
 
219
                        case GBPARSE_INT_COMMA :
 
220
                        case GBPARSE_INT_SINGLE_DOT :
 
221
                                len ++;
 
222
                                break;
 
223
                        case GBPARSE_INT_DOT_DOT :
 
224
                                len += 2;
 
225
                                break;
 
226
                        case GBPARSE_INT_ACCESION :
 
227
                        case GBPARSE_INT_NUMBER :
 
228
                                len += StringLen ( now -> data.ptrvalue);
 
229
                                break;
 
230
                        case GBPARSE_INT_ORDER :
 
231
                        case GBPARSE_INT_GROUP :
 
232
                                len += 5;
 
233
                                break;
 
234
                        case GBPARSE_INT_ONE_OF :
 
235
                        case GBPARSE_INT_ONE_OF_NUM:
 
236
                                len += 6;
 
237
                                break;
 
238
                        case GBPARSE_INT_REPLACE :
 
239
                                len += 7;
 
240
                                break;
 
241
                        case GBPARSE_INT_STRING:
 
242
                                len += StringLen(now ->data.ptrvalue) + 1;
 
243
                                break;
 
244
                        case GBPARSE_INT_UNKNOWN :
 
245
                        default:
 
246
                                break;
 
247
                }
 
248
                len ++; /* for space */
 
249
                
 
250
                
 
251
                if ( now == current)
 
252
                        break;
 
253
        }
 
254
        
 
255
 
 
256
        if (len > 0){
 
257
                temp = retval = MemNew(len+1);
 
258
                for ( now = head; now ; now = now -> next){
 
259
                        switch ( now-> choice){
 
260
                                case GBPARSE_INT_JOIN :
 
261
                                        temp = StringMove(temp,"join");
 
262
                                        break;
 
263
                                case GBPARSE_INT_COMPL :
 
264
                                        temp = StringMove(temp,"complement");
 
265
                                        break;
 
266
                                case GBPARSE_INT_LEFT :
 
267
                                        temp = StringMove(temp,"(");
 
268
                                        break;
 
269
                                case GBPARSE_INT_RIGHT :
 
270
                                        temp = StringMove(temp,")");
 
271
                                        break;
 
272
                                case GBPARSE_INT_CARET :
 
273
                                        temp = StringMove(temp,"^");
 
274
                                        break;
 
275
                                case GBPARSE_INT_DOT_DOT :
 
276
                                        temp = StringMove(temp,"..");
 
277
                                        break;
 
278
                                case GBPARSE_INT_ACCESION :
 
279
                                case GBPARSE_INT_NUMBER :
 
280
                                case GBPARSE_INT_STRING:
 
281
                                        temp = StringMove(temp,now -> data.ptrvalue);
 
282
                                        break;
 
283
                                case GBPARSE_INT_GT :
 
284
                                        temp = StringMove(temp,">");
 
285
                                        break;
 
286
                                case GBPARSE_INT_LT :
 
287
                                        temp = StringMove(temp,"<");
 
288
                                        break;
 
289
                                case GBPARSE_INT_COMMA :
 
290
                                        temp = StringMove(temp,",");
 
291
                                        break;
 
292
                                case GBPARSE_INT_ORDER :
 
293
                                        temp = StringMove(temp,"order");
 
294
                                        break;
 
295
                                case GBPARSE_INT_SINGLE_DOT :
 
296
                                        temp = StringMove(temp,".");
 
297
                                        break;
 
298
                                case GBPARSE_INT_GROUP :
 
299
                                        temp = StringMove(temp,"group");
 
300
                                        break;
 
301
                                case GBPARSE_INT_ONE_OF :
 
302
                                case GBPARSE_INT_ONE_OF_NUM:
 
303
                                        temp = StringMove(temp,"one-of");
 
304
                                        break;
 
305
                                case GBPARSE_INT_REPLACE :
 
306
                                        temp = StringMove(temp,"replace");
 
307
                                        break;
 
308
                                case GBPARSE_INT_UNKNOWN :
 
309
                                default:
 
310
                                        break;
 
311
                        }
 
312
                                temp = StringMove(temp," ");
 
313
                        if ( now == current)
 
314
                                break;
 
315
                }
 
316
        }
 
317
 
 
318
        return retval;
 
319
}
 
320
 
 
321
/*--------- Nlm_find_one_of_num()------------*/
 
322
/*
 
323
 
 
324
Consider these for locations:
 
325
             misc_signal     join(57..one-of(67,75),one-of(100,110)..200)
 
326
     misc_signal     join(57..one-of(67,75),one-of(100,110..120),200)
 
327
     misc_signal     join(57..one-of(67,75),one-of(100,110..115)..200)
 
328
 
 
329
     misc_signal     join(57..one-of(67,75),one-of(100,110),200)
 
330
 
 
331
In the first three, the one-of() is functioning as an alternative set
 
332
of numbers, in the last, as an alternative set of locations (even
 
333
though the locations are points).  
 
334
[yes the one-of(100,110..115).. is illegal]
 
335
 
 
336
  here is one more case:one-of(18,30)..470 so if the location
 
337
  starts with a one-of, it also needs to be checked.
 
338
 
 
339
To deal with this, the GBPARSE_INT_ONE_OF token type will be changed
 
340
by the following function to GBPARSE_INT_ONE_OF_NUM, in the three cases.
 
341
 
 
342
note that this change is not necessary in this case:
 
343
                join(100..200,300..one-of(400,500)), as after a ".." token,
 
344
    it has to be a number.
 
345
 
 
346
*/
 
347
 
 
348
static void
 
349
Nlm_find_one_of_num(ValNodePtr head_token)
 
350
{
 
351
        ValNodePtr current, scanner;
 
352
 
 
353
        current = head_token;
 
354
        if (current -> choice == GBPARSE_INT_ONE_OF){
 
355
                        scanner= current -> next;
 
356
/*-------(is first token after ")" a ".."?----*/
 
357
                        for (;scanner!=NULL; scanner = scanner -> next){
 
358
                                if (scanner -> choice == GBPARSE_INT_RIGHT){
 
359
                                        scanner = scanner -> next;
 
360
                                        if (scanner != NULL){
 
361
                                                if (scanner -> choice == GBPARSE_INT_DOT_DOT){
 
362
/*---- this is it ! ! */
 
363
                                                        current -> choice = GBPARSE_INT_ONE_OF_NUM;
 
364
                                                }
 
365
                                        }
 
366
                                        break;
 
367
                                }
 
368
                        }
 
369
        }
 
370
        for (current = head_token; current != NULL; current = current -> next){
 
371
                if ( current -> choice == GBPARSE_INT_COMMA || 
 
372
                        current -> choice == GBPARSE_INT_LEFT ){
 
373
                        scanner= current -> next;
 
374
                        if ( scanner != NULL){
 
375
                                if (scanner -> choice == GBPARSE_INT_ONE_OF){
 
376
/*-------(is first token after ")" a ".."?----*/
 
377
                                        for (;scanner!=NULL; scanner = scanner -> next){
 
378
                                                if (scanner -> choice == GBPARSE_INT_RIGHT){
 
379
                                                        scanner = scanner -> next;
 
380
                                                        if (scanner != NULL){
 
381
                                                                if (scanner -> choice == GBPARSE_INT_DOT_DOT){
 
382
/*---- this is it ! ! */
 
383
                                                                        current -> next -> choice 
 
384
                                                                                = GBPARSE_INT_ONE_OF_NUM;
 
385
                                                                }
 
386
                                                        }
 
387
                                                        break;
 
388
                                                }
 
389
                                        }
 
390
                                }
 
391
                        }
 
392
                }
 
393
        }
 
394
 
 
395
}
 
396
 
 
397
/*---------- Nlm_gbparseint()-----*/
 
398
 
 
399
NLM_EXTERN SeqLocPtr
 
400
Nlm_gbparseint(CharPtr raw_intervals, Boolean PNTR keep_rawPt, Boolean PNTR sitesPt, int PNTR num_errsPt, SeqIdPtr seq_id)
 
401
{
 
402
        SeqLocPtr retval = NULL;
 
403
        ValNodePtr head_token, current_token;
 
404
        int paren_count = 0;
 
405
        Boolean go_again;
 
406
 
 
407
        * keep_rawPt = FALSE;
 
408
        * sitesPt = FALSE;
 
409
 
 
410
        head_token = NULL;
 
411
        (*num_errsPt) = gbparselex(raw_intervals, & head_token);
 
412
 
 
413
        if (head_token == NULL) {
 
414
                *num_errsPt = 1;
 
415
                return NULL;
 
416
        }
 
417
        if ( ! (*num_errsPt)){
 
418
                current_token = head_token;
 
419
                Nlm_find_one_of_num(head_token);
 
420
 
 
421
        do {
 
422
                go_again= FALSE;
 
423
                if (current_token)
 
424
                switch ( current_token -> choice){
 
425
                        case  GBPARSE_INT_JOIN : case  GBPARSE_INT_ORDER :
 
426
                        case  GBPARSE_INT_GROUP : case  GBPARSE_INT_ONE_OF :
 
427
                        case GBPARSE_INT_COMPL:
 
428
                        retval = Nlm_gbloc(keep_rawPt,  & paren_count, sitesPt, & current_token,  
 
429
                                head_token, (num_errsPt), seq_id);
 
430
/* need to check that out of tokens here */
 
431
                        retval = Nlm_gbparse_better_be_done(num_errsPt, current_token, 
 
432
                                        head_token, retval, keep_rawPt,  paren_count);
 
433
                                break;
 
434
                        case GBPARSE_INT_STRING:
 
435
                                Nlm_gbparse_error("string in loc", 
 
436
                                        head_token, current_token);
 
437
                                        * keep_rawPt = TRUE;  (* num_errsPt) ++;
 
438
/*  no break on purpose */
 
439
                        case  GBPARSE_INT_UNKNOWN :
 
440
                        default: 
 
441
                        case  GBPARSE_INT_RIGHT :
 
442
                        case  GBPARSE_INT_DOT_DOT :
 
443
                        case  GBPARSE_INT_COMMA :
 
444
                        case  GBPARSE_INT_SINGLE_DOT :
 
445
                                        
 
446
                                        Nlm_gbparse_error("illegal initial token", 
 
447
                                                head_token, current_token);
 
448
                                                * keep_rawPt = TRUE;  (* num_errsPt) ++;
 
449
                                current_token = current_token -> next;
 
450
                                break;
 
451
 
 
452
                        case  GBPARSE_INT_ACCESION :
 
453
/*--- no warn, but strange ---*/
 
454
/*-- no break on purpose ---*/
 
455
 
 
456
                        case  GBPARSE_INT_CARET : case  GBPARSE_INT_GT :
 
457
                        case  GBPARSE_INT_LT : case  GBPARSE_INT_NUMBER :
 
458
                        case  GBPARSE_INT_LEFT :
 
459
 
 
460
                        case GBPARSE_INT_ONE_OF_NUM:
 
461
 
 
462
                        retval = Nlm_gbint(keep_rawPt,  & current_token,
 
463
                                head_token, (num_errsPt), seq_id);
 
464
/* need to check that out of tokens here */
 
465
                        retval = Nlm_gbparse_better_be_done(num_errsPt, current_token, 
 
466
                                        head_token, retval, keep_rawPt,  paren_count);
 
467
                                break;
 
468
 
 
469
                        case  GBPARSE_INT_REPLACE :
 
470
                        retval = Nlm_gbreplace(keep_rawPt,  & paren_count, sitesPt, & current_token,  
 
471
                                head_token, (num_errsPt), seq_id);
 
472
                                * keep_rawPt = TRUE;
 
473
/*---all errors handled within this function ---*/
 
474
                                break;
 
475
                        case GBPARSE_INT_SITES :
 
476
                                * sitesPt = TRUE;
 
477
                                go_again = TRUE;
 
478
                                current_token = current_token -> next;
 
479
                                break;
 
480
                }
 
481
        }while (go_again && current_token);
 
482
        }else{
 
483
                * keep_rawPt = TRUE;
 
484
        }
 
485
        
 
486
        if ( head_token)
 
487
                ValNodeFreeData(head_token);
 
488
 
 
489
        if ( (*num_errsPt)){
 
490
                SeqLocFree(retval);
 
491
                retval = NULL;
 
492
        }
 
493
        return retval;
 
494
}
 
495
 
 
496
/*---------- Nlm_gbparseint_ver()-----*/
 
497
 
 
498
NLM_EXTERN SeqLocPtr Nlm_gbparseint_ver(CharPtr raw_intervals,
 
499
                                        Boolean PNTR keep_rawPt,
 
500
                                        Boolean PNTR sitesPt,
 
501
                                        int PNTR num_errsPt,
 
502
                                        SeqIdPtr seq_id, Boolean accver)
 
503
{
 
504
        SeqLocPtr retval = NULL;
 
505
        ValNodePtr head_token, current_token;
 
506
        int paren_count = 0;
 
507
        Boolean go_again;
 
508
 
 
509
        * keep_rawPt = FALSE;
 
510
        * sitesPt = FALSE;
 
511
 
 
512
        head_token = NULL;
 
513
        (*num_errsPt) = Nlm_gbparselex_ver(raw_intervals, &head_token, accver);
 
514
 
 
515
        if (head_token == NULL) {
 
516
                *num_errsPt = 1;
 
517
                return NULL;
 
518
        }
 
519
        if ( ! (*num_errsPt)){
 
520
                current_token = head_token;
 
521
                Nlm_find_one_of_num(head_token);
 
522
 
 
523
        do {
 
524
                go_again= FALSE;
 
525
                if (current_token)
 
526
                switch ( current_token -> choice){
 
527
                        case  GBPARSE_INT_JOIN : case  GBPARSE_INT_ORDER :
 
528
                        case  GBPARSE_INT_GROUP : case  GBPARSE_INT_ONE_OF :
 
529
                        case GBPARSE_INT_COMPL:
 
530
                        retval = Nlm_gbloc_ver(keep_rawPt,  & paren_count, sitesPt, & current_token,  
 
531
                                head_token, (num_errsPt), seq_id, accver);
 
532
/* need to check that out of tokens here */
 
533
                        retval = Nlm_gbparse_better_be_done(num_errsPt, current_token, 
 
534
                                        head_token, retval, keep_rawPt,  paren_count);
 
535
                                break;
 
536
                        case GBPARSE_INT_STRING:
 
537
                                Nlm_gbparse_error("string in loc", 
 
538
                                        head_token, current_token);
 
539
                                        * keep_rawPt = TRUE;  (* num_errsPt) ++;
 
540
/*  no break on purpose */
 
541
                        case  GBPARSE_INT_UNKNOWN :
 
542
                        default: 
 
543
                        case  GBPARSE_INT_RIGHT :
 
544
                        case  GBPARSE_INT_DOT_DOT :
 
545
                        case  GBPARSE_INT_COMMA :
 
546
                        case  GBPARSE_INT_SINGLE_DOT :
 
547
                                        
 
548
                                        Nlm_gbparse_error("illegal initial token", 
 
549
                                                head_token, current_token);
 
550
                                                * keep_rawPt = TRUE;  (* num_errsPt) ++;
 
551
                                current_token = current_token -> next;
 
552
                                break;
 
553
 
 
554
                        case  GBPARSE_INT_ACCESION :
 
555
/*--- no warn, but strange ---*/
 
556
/*-- no break on purpose ---*/
 
557
 
 
558
                        case  GBPARSE_INT_CARET : case  GBPARSE_INT_GT :
 
559
                        case  GBPARSE_INT_LT : case  GBPARSE_INT_NUMBER :
 
560
                        case  GBPARSE_INT_LEFT :
 
561
 
 
562
                        case GBPARSE_INT_ONE_OF_NUM:
 
563
 
 
564
                        retval = Nlm_gbint_ver(keep_rawPt,  & current_token,
 
565
                                head_token, (num_errsPt), seq_id, accver);
 
566
/* need to check that out of tokens here */
 
567
                        retval = Nlm_gbparse_better_be_done(num_errsPt, current_token, 
 
568
                                        head_token, retval, keep_rawPt,  paren_count);
 
569
                                break;
 
570
 
 
571
                        case  GBPARSE_INT_REPLACE :
 
572
                        retval = Nlm_gbreplace_ver(keep_rawPt,  & paren_count, sitesPt, & current_token,  
 
573
                                head_token, (num_errsPt), seq_id, accver);
 
574
                                * keep_rawPt = TRUE;
 
575
/*---all errors handled within this function ---*/
 
576
                                break;
 
577
                        case GBPARSE_INT_SITES :
 
578
                                * sitesPt = TRUE;
 
579
                                go_again = TRUE;
 
580
                                current_token = current_token -> next;
 
581
                                break;
 
582
                }
 
583
        }while (go_again && current_token);
 
584
        }else{
 
585
                * keep_rawPt = TRUE;
 
586
        }
 
587
        
 
588
        if ( head_token)
 
589
                ValNodeFreeData(head_token);
 
590
 
 
591
        if ( (*num_errsPt)){
 
592
                SeqLocFree(retval);
 
593
                retval = NULL;
 
594
        }
 
595
        return retval;
 
596
}
 
597
 
 
598
/*---------- Nlm_gbloc()-----*/
 
599
 
 
600
NLM_EXTERN SeqLocPtr
 
601
Nlm_gbloc(Boolean PNTR keep_rawPt, int PNTR parenPt, Boolean PNTR sitesPt, ValNodePtr PNTR currentPt, ValNodePtr head_token, int PNTR num_errPt, SeqIdPtr seq_id)
 
602
{
 
603
        SeqLocPtr retval =NULL;
 
604
        Boolean add_nulls=FALSE;
 
605
        ValNodePtr current_token = * currentPt;
 
606
        Boolean did_complement= FALSE;
 
607
        Boolean go_again ;
 
608
 
 
609
        do {
 
610
                go_again= FALSE;
 
611
                switch ( current_token -> choice){
 
612
                        case  GBPARSE_INT_COMPL :
 
613
                        *currentPt = (* currentPt) -> next;
 
614
                        if ( (*currentPt) == NULL){
 
615
                                Nlm_gbparse_error("unexpected end of usable tokens",
 
616
                                        head_token, *currentPt);
 
617
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
618
                                goto FATAL;
 
619
                        }
 
620
                        if ( (* currentPt) -> choice != GBPARSE_INT_LEFT){
 
621
                                        Nlm_gbparse_error("Missing \'(\'", /* paran match  ) */
 
622
                                                head_token, * currentPt);
 
623
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
624
                                        goto FATAL;
 
625
                        }else{
 
626
                                (*parenPt) ++; *currentPt = (* currentPt) -> next;
 
627
                                if ( ! * currentPt){
 
628
                                                Nlm_gbparse_error("illegal null contents",
 
629
                                                        head_token, *currentPt);
 
630
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
631
                                        goto FATAL;
 
632
                                }else{
 
633
                                        if (  (* currentPt) -> choice == GBPARSE_INT_RIGHT){ /* paran match ( */
 
634
                                                Nlm_gbparse_error("Premature \')\'",
 
635
                                                        head_token, *currentPt);
 
636
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
637
                                                goto FATAL;
 
638
                                        }else{
 
639
                                                retval =  Nlm_gbloc (keep_rawPt, parenPt, sitesPt, currentPt, 
 
640
                                                        head_token, num_errPt,seq_id) ;
 
641
                                                SeqLocRevCmp ( retval);
 
642
                                                did_complement= TRUE;
 
643
                                                if ( * currentPt){
 
644
                                                        if ( (* currentPt) -> choice != GBPARSE_INT_RIGHT){
 
645
                                                                        Nlm_gbparse_error("Missing \')\'",
 
646
                                                                                head_token, *currentPt);
 
647
                                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
648
                                                                        goto FATAL;
 
649
                                                        }else{
 
650
                                                                (*parenPt) --; *currentPt = (* currentPt) -> next;
 
651
                                                        }
 
652
                                                }else{
 
653
                                                        Nlm_gbparse_error("Missing \')\'",
 
654
                                                                head_token, *currentPt);
 
655
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
656
                                                        goto FATAL;
 
657
                                                }
 
658
                                        }
 
659
                                }
 
660
                        }
 
661
                                break;
 
662
/* REAL LOCS */
 
663
                        case GBPARSE_INT_JOIN : retval =ValNodeNew(NULL); retval -> choice = SEQLOC_MIX; break;
 
664
                        case  GBPARSE_INT_ORDER : retval =ValNodeNew(NULL); retval -> choice = SEQLOC_MIX; add_nulls=TRUE;break;
 
665
                        case  GBPARSE_INT_GROUP : * keep_rawPt = TRUE; retval =ValNodeNew(NULL); retval -> choice = SEQLOC_MIX;
 
666
                                break;
 
667
                        case  GBPARSE_INT_ONE_OF : retval =ValNodeNew(NULL); retval -> choice = SEQLOC_EQUIV; break;
 
668
 
 
669
/* ERROR */
 
670
                        case GBPARSE_INT_STRING:
 
671
                                Nlm_gbparse_error("string in loc", 
 
672
                                        head_token, current_token);
 
673
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
674
                                        goto FATAL;
 
675
/*--- no break on purpose---*/
 
676
                        case  GBPARSE_INT_UNKNOWN : default: 
 
677
                        case  GBPARSE_INT_RIGHT : case  GBPARSE_INT_DOT_DOT:case  GBPARSE_INT_COMMA :
 
678
                        case  GBPARSE_INT_SINGLE_DOT :
 
679
                                Nlm_gbparse_error("illegal initial loc token",
 
680
                                        head_token, *currentPt);
 
681
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
682
                                        goto FATAL;
 
683
 
 
684
/* Interval, occurs on recursion */
 
685
                        case GBPARSE_INT_GAP:
 
686
                                Nlm_gbgap(currentPt, &retval);
 
687
                                break;
 
688
                        case  GBPARSE_INT_ACCESION :
 
689
                        case  GBPARSE_INT_CARET : case  GBPARSE_INT_GT :
 
690
                        case  GBPARSE_INT_LT : case  GBPARSE_INT_NUMBER :
 
691
                        case  GBPARSE_INT_LEFT :
 
692
 
 
693
                        case GBPARSE_INT_ONE_OF_NUM:
 
694
 
 
695
                        retval = Nlm_gbint(keep_rawPt, currentPt, 
 
696
                                head_token, num_errPt, seq_id);
 
697
                                break;
 
698
 
 
699
                        case  GBPARSE_INT_REPLACE :
 
700
/*-------illegal at this level --*/
 
701
                                Nlm_gbparse_error("illegal replace",
 
702
                                        head_token, *currentPt);
 
703
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
704
                                        goto FATAL;
 
705
                        case GBPARSE_INT_SITES :
 
706
                                * sitesPt = TRUE;
 
707
                                go_again = TRUE;
 
708
                                (*currentPt) = (*currentPt) -> next;
 
709
                                break;
 
710
                }
 
711
        } while (go_again && *currentPt);
 
712
 
 
713
        if ( !  (* num_errPt)) if (retval && retval->choice != SEQLOC_NULL) 
 
714
        if ( retval -> choice != SEQLOC_INT && retval -> choice != SEQLOC_PNT
 
715
                        && ! did_complement){ 
 
716
/*--------
 
717
 * ONLY THE CHOICE has been set. the "join", etc. only has been noted
 
718
 *----*/
 
719
                *currentPt = (* currentPt) -> next;
 
720
                if ( ! * currentPt){
 
721
                                Nlm_gbparse_error("unexpected end of interval tokens",
 
722
                                        head_token, *currentPt);
 
723
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
724
                                        goto FATAL;
 
725
                }else{
 
726
                        if ( (* currentPt) -> choice != GBPARSE_INT_LEFT){
 
727
                                        Nlm_gbparse_error("Missing \'(\'",
 
728
                                                head_token, *currentPt); /* paran match  ) */
 
729
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
730
                                        goto FATAL;
 
731
                        }else{
 
732
                                (*parenPt) ++; *currentPt = (* currentPt) -> next;
 
733
                                if ( ! * currentPt){
 
734
                                                Nlm_gbparse_error("illegal null contents",
 
735
                                                        head_token, *currentPt);
 
736
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
737
                                                goto FATAL;
 
738
                                }else{
 
739
                                        if (  (* currentPt) -> choice == GBPARSE_INT_RIGHT){ /* paran match ( */
 
740
                                                Nlm_gbparse_error("Premature \')\'" ,
 
741
                                                        head_token, *currentPt);
 
742
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
743
                                        goto FATAL;
 
744
                                        }else{
 
745
 
 
746
                                                ValNodePtr last= NULL, next_loc = NULL;
 
747
 
 
748
                                                while ( ! *num_errPt && * currentPt){
 
749
                                                        if ( (* currentPt) -> choice == GBPARSE_INT_RIGHT){
 
750
                                                                while  ((* currentPt) -> choice == GBPARSE_INT_RIGHT){ 
 
751
                                                                        (*parenPt) --;
 
752
                                                                        *currentPt = (* currentPt) -> next;
 
753
                                                                        if ( ! *currentPt)
 
754
                                                                                break;
 
755
                                                                }
 
756
                                                                break;
 
757
                                                        }
 
758
                                                        if ( ! * currentPt){
 
759
                                                                break;
 
760
                                                        }
 
761
                                                        next_loc = Nlm_gbloc(keep_rawPt, parenPt,sitesPt,  
 
762
                                                                currentPt, head_token, num_errPt,
 
763
                                                                seq_id);
 
764
                                                        if( retval -> data.ptrvalue == NULL)
 
765
                                                                retval -> data.ptrvalue = next_loc;
 
766
                                                        if ( last)
 
767
                                                                last -> next = next_loc;
 
768
                                                        last = next_loc;
 
769
                                                        if ( ! * currentPt){
 
770
                                                                break;
 
771
                                                        }
 
772
                                                        if ( ! * currentPt){
 
773
                                                                break;
 
774
                                                        }
 
775
                                                        if ((* currentPt) -> choice == GBPARSE_INT_RIGHT){
 
776
                                                                break;
 
777
                                                        }
 
778
                                                        if (  (* currentPt) -> choice == GBPARSE_INT_COMMA){
 
779
                                                                *currentPt = (* currentPt) -> next;
 
780
                                                                if(add_nulls){
 
781
                                                                        next_loc = ValNodeNew(last);
 
782
                                                                        next_loc -> choice = SEQLOC_NULL;
 
783
                                                                        last -> next = next_loc;
 
784
                                                                        last = next_loc;
 
785
                                                                }
 
786
                                                        }else{
 
787
                                                                Nlm_gbparse_error("Illegal token after interval",
 
788
                                                                        head_token, *currentPt);
 
789
                                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
790
                                                                goto FATAL;
 
791
                                                        }
 
792
                                                }
 
793
                                        }
 
794
                                }
 
795
                                if ( (*currentPt) == NULL){
 
796
                                        Nlm_gbparse_error("unexpected end of usable tokens",
 
797
                                                head_token, *currentPt);
 
798
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
799
                                        goto FATAL;
 
800
                                }else{
 
801
                                        if ( (* currentPt) -> choice != GBPARSE_INT_RIGHT){
 
802
                                                        Nlm_gbparse_error("Missing \')\'" /* paran match  ) */,
 
803
                                                                         head_token, *currentPt);
 
804
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
805
                                                goto FATAL;
 
806
                                        }else{
 
807
                                                (*parenPt) --; *currentPt = (* currentPt) -> next;
 
808
                                        }
 
809
                                }
 
810
                        }
 
811
                }
 
812
        }
 
813
 
 
814
FATAL:
 
815
        if ( (* num_errPt)){
 
816
                if (retval){
 
817
                        SeqLocFree(retval); 
 
818
                        retval =ValNodeNew(NULL);
 
819
                        retval -> choice = SEQLOC_WHOLE;
 
820
                        retval -> data.ptrvalue = SeqIdDup(seq_id);
 
821
                }
 
822
        }
 
823
        
 
824
        return retval;
 
825
}
 
826
 
 
827
/*---------- Nlm_gbloc_ver()-----*/
 
828
 
 
829
NLM_EXTERN SeqLocPtr Nlm_gbloc_ver(Boolean PNTR keep_rawPt, int PNTR parenPt,
 
830
                               Boolean PNTR sitesPt, ValNodePtr PNTR currentPt,
 
831
                               ValNodePtr head_token, int PNTR num_errPt,
 
832
                               SeqIdPtr seq_id, Boolean accver)
 
833
{
 
834
        SeqLocPtr retval =NULL;
 
835
        Boolean add_nulls=FALSE;
 
836
        ValNodePtr current_token = * currentPt;
 
837
        Boolean did_complement= FALSE;
 
838
        Boolean go_again ;
 
839
 
 
840
        do {
 
841
                go_again= FALSE;
 
842
                switch ( current_token -> choice){
 
843
                        case  GBPARSE_INT_COMPL :
 
844
                        *currentPt = (* currentPt) -> next;
 
845
                        if ( (*currentPt) == NULL){
 
846
                                Nlm_gbparse_error("unexpected end of usable tokens",
 
847
                                        head_token, *currentPt);
 
848
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
849
                                goto FATAL;
 
850
                        }
 
851
                        if ( (* currentPt) -> choice != GBPARSE_INT_LEFT){
 
852
                                        Nlm_gbparse_error("Missing \'(\'", /* paran match  ) */
 
853
                                                head_token, * currentPt);
 
854
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
855
                                        goto FATAL;
 
856
                        }else{
 
857
                                (*parenPt) ++; *currentPt = (* currentPt) -> next;
 
858
                                if ( ! * currentPt){
 
859
                                                Nlm_gbparse_error("illegal null contents",
 
860
                                                        head_token, *currentPt);
 
861
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
862
                                        goto FATAL;
 
863
                                }else{
 
864
                                        if (  (* currentPt) -> choice == GBPARSE_INT_RIGHT){ /* paran match ( */
 
865
                                                Nlm_gbparse_error("Premature \')\'",
 
866
                                                        head_token, *currentPt);
 
867
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
868
                                                goto FATAL;
 
869
                                        }else{
 
870
                                                retval =  Nlm_gbloc_ver (keep_rawPt, parenPt, sitesPt, currentPt, 
 
871
                                                        head_token, num_errPt,seq_id, accver) ;
 
872
                                                SeqLocRevCmp ( retval);
 
873
                                                did_complement= TRUE;
 
874
                                                if ( * currentPt){
 
875
                                                        if ( (* currentPt) -> choice != GBPARSE_INT_RIGHT){
 
876
                                                                        Nlm_gbparse_error("Missing \')\'",
 
877
                                                                                head_token, *currentPt);
 
878
                                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
879
                                                                        goto FATAL;
 
880
                                                        }else{
 
881
                                                                (*parenPt) --; *currentPt = (* currentPt) -> next;
 
882
                                                        }
 
883
                                                }else{
 
884
                                                        Nlm_gbparse_error("Missing \')\'",
 
885
                                                                head_token, *currentPt);
 
886
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
887
                                                        goto FATAL;
 
888
                                                }
 
889
                                        }
 
890
                                }
 
891
                        }
 
892
                                break;
 
893
/* REAL LOCS */
 
894
                        case GBPARSE_INT_JOIN : retval =ValNodeNew(NULL); retval -> choice = SEQLOC_MIX; break;
 
895
                        case  GBPARSE_INT_ORDER : retval =ValNodeNew(NULL); retval -> choice = SEQLOC_MIX; add_nulls=TRUE;break;
 
896
                        case  GBPARSE_INT_GROUP : * keep_rawPt = TRUE; retval =ValNodeNew(NULL); retval -> choice = SEQLOC_MIX;
 
897
                                break;
 
898
                        case  GBPARSE_INT_ONE_OF : retval =ValNodeNew(NULL); retval -> choice = SEQLOC_EQUIV; break;
 
899
 
 
900
/* ERROR */
 
901
                        case GBPARSE_INT_STRING:
 
902
                                Nlm_gbparse_error("string in loc", 
 
903
                                        head_token, current_token);
 
904
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
905
                                        goto FATAL;
 
906
/*--- no break on purpose---*/
 
907
                        case  GBPARSE_INT_UNKNOWN : default: 
 
908
                        case  GBPARSE_INT_RIGHT : case  GBPARSE_INT_DOT_DOT:case  GBPARSE_INT_COMMA :
 
909
                        case  GBPARSE_INT_SINGLE_DOT :
 
910
                                Nlm_gbparse_error("illegal initial loc token",
 
911
                                        head_token, *currentPt);
 
912
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
913
                                        goto FATAL;
 
914
 
 
915
/* Interval, occurs on recursion */
 
916
                        case GBPARSE_INT_GAP:
 
917
                                Nlm_gbgap(currentPt, &retval);
 
918
                                break;
 
919
                        case  GBPARSE_INT_ACCESION :
 
920
                        case  GBPARSE_INT_CARET : case  GBPARSE_INT_GT :
 
921
                        case  GBPARSE_INT_LT : case  GBPARSE_INT_NUMBER :
 
922
                        case  GBPARSE_INT_LEFT :
 
923
 
 
924
                        case GBPARSE_INT_ONE_OF_NUM:
 
925
 
 
926
                        retval = Nlm_gbint_ver(keep_rawPt, currentPt, 
 
927
                                head_token, num_errPt, seq_id, accver);
 
928
                                break;
 
929
 
 
930
                        case  GBPARSE_INT_REPLACE :
 
931
/*-------illegal at this level --*/
 
932
                                Nlm_gbparse_error("illegal replace",
 
933
                                        head_token, *currentPt);
 
934
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
935
                                        goto FATAL;
 
936
                        case GBPARSE_INT_SITES :
 
937
                                * sitesPt = TRUE;
 
938
                                go_again = TRUE;
 
939
                                (*currentPt) = (*currentPt) -> next;
 
940
                                break;
 
941
                }
 
942
        } while (go_again && *currentPt);
 
943
 
 
944
        if ( !  (* num_errPt)) if (retval && retval->choice != SEQLOC_NULL) 
 
945
        if ( retval -> choice != SEQLOC_INT && retval -> choice != SEQLOC_PNT
 
946
                        && ! did_complement){ 
 
947
/*--------
 
948
 * ONLY THE CHOICE has been set. the "join", etc. only has been noted
 
949
 *----*/
 
950
                *currentPt = (* currentPt) -> next;
 
951
                if ( ! * currentPt){
 
952
                                Nlm_gbparse_error("unexpected end of interval tokens",
 
953
                                        head_token, *currentPt);
 
954
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
955
                                        goto FATAL;
 
956
                }else{
 
957
                        if ( (* currentPt) -> choice != GBPARSE_INT_LEFT){
 
958
                                        Nlm_gbparse_error("Missing \'(\'",
 
959
                                                head_token, *currentPt); /* paran match  ) */
 
960
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
961
                                        goto FATAL;
 
962
                        }else{
 
963
                                (*parenPt) ++; *currentPt = (* currentPt) -> next;
 
964
                                if ( ! * currentPt){
 
965
                                                Nlm_gbparse_error("illegal null contents",
 
966
                                                        head_token, *currentPt);
 
967
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
968
                                                goto FATAL;
 
969
                                }else{
 
970
                                        if (  (* currentPt) -> choice == GBPARSE_INT_RIGHT){ /* paran match ( */
 
971
                                                Nlm_gbparse_error("Premature \')\'" ,
 
972
                                                        head_token, *currentPt);
 
973
                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
974
                                        goto FATAL;
 
975
                                        }else{
 
976
 
 
977
                                                ValNodePtr last= NULL, next_loc = NULL;
 
978
 
 
979
                                                while ( ! *num_errPt && * currentPt){
 
980
                                                        if ( (* currentPt) -> choice == GBPARSE_INT_RIGHT){
 
981
                                                                while  ((* currentPt) -> choice == GBPARSE_INT_RIGHT){ 
 
982
                                                                        (*parenPt) --;
 
983
                                                                        *currentPt = (* currentPt) -> next;
 
984
                                                                        if ( ! *currentPt)
 
985
                                                                                break;
 
986
                                                                }
 
987
                                                                break;
 
988
                                                        }
 
989
                                                        if ( ! * currentPt){
 
990
                                                                break;
 
991
                                                        }
 
992
                                                        next_loc = Nlm_gbloc_ver(keep_rawPt, parenPt,sitesPt,  
 
993
                                                                currentPt, head_token, num_errPt,
 
994
                                                                seq_id, accver);
 
995
                                                        if( retval -> data.ptrvalue == NULL)
 
996
                                                                retval -> data.ptrvalue = next_loc;
 
997
                                                        if ( last)
 
998
                                                                last -> next = next_loc;
 
999
                                                        last = next_loc;
 
1000
                                                        if ( ! * currentPt){
 
1001
                                                                break;
 
1002
                                                        }
 
1003
                                                        if ( ! * currentPt){
 
1004
                                                                break;
 
1005
                                                        }
 
1006
                                                        if ((* currentPt) -> choice == GBPARSE_INT_RIGHT){
 
1007
                                                                break;
 
1008
                                                        }
 
1009
                                                        if (  (* currentPt) -> choice == GBPARSE_INT_COMMA){
 
1010
                                                                *currentPt = (* currentPt) -> next;
 
1011
                                                                if(add_nulls){
 
1012
                                                                        next_loc = ValNodeNew(last);
 
1013
                                                                        next_loc -> choice = SEQLOC_NULL;
 
1014
                                                                        last -> next = next_loc;
 
1015
                                                                        last = next_loc;
 
1016
                                                                }
 
1017
                                                        }else{
 
1018
                                                                Nlm_gbparse_error("Illegal token after interval",
 
1019
                                                                        head_token, *currentPt);
 
1020
                                                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1021
                                                                goto FATAL;
 
1022
                                                        }
 
1023
                                                }
 
1024
                                        }
 
1025
                                }
 
1026
                                if ( (*currentPt) == NULL){
 
1027
                                        Nlm_gbparse_error("unexpected end of usable tokens",
 
1028
                                                head_token, *currentPt);
 
1029
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1030
                                        goto FATAL;
 
1031
                                }else{
 
1032
                                        if ( (* currentPt) -> choice != GBPARSE_INT_RIGHT){
 
1033
                                                        Nlm_gbparse_error("Missing \')\'" /* paran match  ) */,
 
1034
                                                                         head_token, *currentPt);
 
1035
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1036
                                                goto FATAL;
 
1037
                                        }else{
 
1038
                                                (*parenPt) --; *currentPt = (* currentPt) -> next;
 
1039
                                        }
 
1040
                                }
 
1041
                        }
 
1042
                }
 
1043
        }
 
1044
 
 
1045
FATAL:
 
1046
        if ( (* num_errPt)){
 
1047
                if (retval){
 
1048
                        SeqLocFree(retval); 
 
1049
                        retval =ValNodeNew(NULL);
 
1050
                        retval -> choice = SEQLOC_WHOLE;
 
1051
                        retval -> data.ptrvalue = SeqIdDup(seq_id);
 
1052
                }
 
1053
        }
 
1054
        
 
1055
        return retval;
 
1056
}
 
1057
 
 
1058
/**********************************************************/
 
1059
void Nlm_gbgap(ValNodePtr PNTR currentPt, ValNodePtr PNTR retval)
 
1060
{
 
1061
    ValNodePtr vnp_first;
 
1062
    ValNodePtr vnp_second;
 
1063
    ValNodePtr vnp_third;
 
1064
    SeqLocPtr  vvv;
 
1065
 
 
1066
    vnp_first = (*currentPt)->next;
 
1067
    if(vnp_first == NULL || vnp_first->choice != GBPARSE_INT_LEFT)
 
1068
        return;
 
1069
 
 
1070
    vnp_second = vnp_first->next;
 
1071
    if(vnp_second == NULL || (vnp_second->choice != GBPARSE_INT_NUMBER &&
 
1072
       vnp_second->choice != GBPARSE_INT_RIGHT))
 
1073
        return;
 
1074
 
 
1075
    if(vnp_second->choice == GBPARSE_INT_RIGHT)
 
1076
    {
 
1077
        (*retval) = ValNodeNew(*retval);
 
1078
        (*retval)->choice = SEQLOC_NULL;
 
1079
    }
 
1080
    else
 
1081
    {
 
1082
        vnp_third = vnp_second->next;
 
1083
        if(vnp_third == NULL || vnp_third->choice != GBPARSE_INT_RIGHT)
 
1084
            return;
 
1085
 
 
1086
        vvv = GapToSeqLoc(atoi((CharPtr) vnp_second->data.ptrvalue));
 
1087
        if(vvv == NULL)
 
1088
            return;
 
1089
 
 
1090
        if(*retval == NULL)
 
1091
            (*retval) = vvv;
 
1092
        else
 
1093
        {
 
1094
            (*retval)->next = vvv;
 
1095
            (*retval) = (*retval)->next;
 
1096
        }
 
1097
 
 
1098
        (*currentPt) = (*currentPt)->next;
 
1099
    }
 
1100
 
 
1101
    (*currentPt) = (*currentPt)->next;
 
1102
    (*currentPt) = (*currentPt)->next;
 
1103
    (*currentPt) = (*currentPt)->next;
 
1104
}
 
1105
 
 
1106
/*--------------- Nlm_gbint ()--------------------*/
 
1107
 
 
1108
NLM_EXTERN SeqLocPtr /* sometimes returns points */
 
1109
 
 
1110
Nlm_gbint(Boolean PNTR keep_rawPt, ValNodePtr PNTR currentPt, ValNodePtr head_token, int PNTR num_errPt, SeqIdPtr seq_id)
 
1111
{
 
1112
        SeqLocPtr retnode = ValNodeNew(NULL);
 
1113
        SeqIntPtr retint = SeqIntNew();
 
1114
        TextSeqIdPtr tp;
 
1115
        IntFuzzPtr fuzz=NULL;
 
1116
        SeqIdPtr idp = NULL;
 
1117
        Boolean took_choice=FALSE;
 
1118
 
 
1119
        retnode -> choice = SEQLOC_INT;
 
1120
 
 
1121
                if ( (* currentPt) -> choice == GBPARSE_INT_ACCESION){
 
1122
                        idp = ValNodeNew(NULL);
 
1123
                        if (seq_id){
 
1124
                                if (
 
1125
                                        seq_id -> choice == SEQID_GENBANK
 
1126
                                         || seq_id -> choice == SEQID_EMBL
 
1127
                                         || seq_id -> choice == SEQID_DDBJ
 
1128
                                ){
 
1129
                                        idp -> choice = seq_id -> choice;
 
1130
                                        took_choice = TRUE;
 
1131
                                }
 
1132
                        }
 
1133
                        if (! took_choice){
 
1134
                                idp -> choice = SEQID_GENBANK;
 
1135
                        }
 
1136
                        tp = TextSeqIdNew();
 
1137
                        idp -> data.ptrvalue = tp;
 
1138
                        tp -> accession = StringSave ( (* currentPt) ->data.ptrvalue);
 
1139
                         *currentPt  =  (* currentPt)  -> next;
 
1140
                        if ( !  *currentPt ){
 
1141
                                        Nlm_gbparse_error("Nothing after accession",
 
1142
                                                head_token, *currentPt);
 
1143
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1144
 
 
1145
                                        SeqIdFree(idp);
 
1146
                                        idp = NULL;
 
1147
 
 
1148
                                        goto FATAL;
 
1149
                        }
 
1150
                }else{
 
1151
                        idp = SeqIdDup (seq_id);        
 
1152
                }
 
1153
                if ( (* currentPt) -> choice == GBPARSE_INT_LT){
 
1154
                                fuzz = IntFuzzNew();
 
1155
                                fuzz -> choice = 4;
 
1156
                                fuzz ->a = 2;
 
1157
                         *currentPt  =  (* currentPt)  -> next;
 
1158
                        if ( !  *currentPt ){
 
1159
                                        Nlm_gbparse_error("Nothing after \'<\'",
 
1160
                                                head_token, *currentPt);
 
1161
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1162
                                        goto FATAL;
 
1163
                        }
 
1164
                }
 
1165
                if ( ! (* num_errPt))
 
1166
                switch ( (*currentPt ) -> choice){
 
1167
                        case  GBPARSE_INT_ACCESION :
 
1168
                                if ( idp){
 
1169
                                        Nlm_gbparse_error("duplicate accessions",
 
1170
                                                head_token, *currentPt);
 
1171
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1172
                                        goto FATAL;
 
1173
                                }
 
1174
                                break;
 
1175
                        case  GBPARSE_INT_CARET : 
 
1176
                                        Nlm_gbparse_error("caret (^) before number" ,
 
1177
                                                head_token, *currentPt);
 
1178
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1179
                                        goto FATAL;
 
1180
                        case  GBPARSE_INT_LT : 
 
1181
                                if ( idp){
 
1182
                                        Nlm_gbparse_error("duplicate \'<\'",
 
1183
                                                head_token, *currentPt);
 
1184
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1185
                                        goto FATAL;
 
1186
                                }
 
1187
                                break;
 
1188
                        case  GBPARSE_INT_GT :
 
1189
                        case  GBPARSE_INT_NUMBER :
 
1190
                        case  GBPARSE_INT_LEFT :
 
1191
 
 
1192
                        case GBPARSE_INT_ONE_OF_NUM:
 
1193
 
 
1194
                                retint -> if_from = fuzz;
 
1195
                                retint -> id = idp;
 
1196
                                retnode -> data.ptrvalue = retint;
 
1197
                                Nlm_gbload_number (& ( retint -> from), & (retint -> if_from),
 
1198
                                        keep_rawPt, currentPt, head_token, 
 
1199
                                        num_errPt,TAKE_FIRST);
 
1200
                                Nlm_gbcheck_range(retint -> from, idp, keep_rawPt, num_errPt, head_token, *currentPt);
 
1201
                if ( ! (* num_errPt) ){
 
1202
                if ( * currentPt){
 
1203
                                Boolean in_caret = FALSE;
 
1204
                switch ( (*currentPt ) -> choice){
 
1205
                                SeqPntPtr point;
 
1206
 
 
1207
                                default: case GBPARSE_INT_JOIN: case GBPARSE_INT_COMPL: 
 
1208
                                case GBPARSE_INT_SINGLE_DOT:case GBPARSE_INT_ORDER: case GBPARSE_INT_GROUP:
 
1209
                                case GBPARSE_INT_ACCESION:
 
1210
                                        Nlm_gbparse_error("problem with 2nd number",
 
1211
                                                head_token, *currentPt);;
 
1212
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1213
                                        goto FATAL;
 
1214
                                case GBPARSE_INT_COMMA: case GBPARSE_INT_RIGHT: /* valid thing to leave on*/
 
1215
/*--------------but have a point, not an interval----*/
 
1216
                                        Nlm_gbpintpnt(retnode, & retint);
 
1217
                                        break;
 
1218
                                case GBPARSE_INT_GT: case GBPARSE_INT_LT:
 
1219
                                        Nlm_gbparse_error("Missing \'..\'",
 
1220
                                                head_token, *currentPt);;
 
1221
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1222
                                        goto FATAL;
 
1223
                                case GBPARSE_INT_CARET:
 
1224
                                if (retint -> if_from){
 
1225
                                        Nlm_gbparse_error("\'<\' then \'^\'",
 
1226
                                        head_token, *currentPt);
 
1227
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1228
                                        goto FATAL;
 
1229
                                }
 
1230
                                retint -> if_from = IntFuzzNew();
 
1231
                                retint -> if_from -> choice = 4;
 
1232
                                retint -> if_from ->a = 4;
 
1233
                                retint -> if_to = IntFuzzNew();
 
1234
                                retint -> if_to -> choice = 4;
 
1235
                                retint -> if_to ->a = 4;
 
1236
                                in_caret = TRUE;
 
1237
/*---no break on purpose ---*/
 
1238
                                case GBPARSE_INT_DOT_DOT:
 
1239
                         *currentPt  =  (* currentPt)  -> next;
 
1240
                        if ( (*currentPt) == NULL){
 
1241
                                Nlm_gbparse_error("unexpected end of usable tokens",
 
1242
                                        head_token, *currentPt);
 
1243
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1244
                                goto FATAL;
 
1245
                        }
 
1246
/*--no break on purpose here ---*/
 
1247
                                case GBPARSE_INT_NUMBER:
 
1248
                                case GBPARSE_INT_LEFT:
 
1249
 
 
1250
                                case GBPARSE_INT_ONE_OF_NUM:  /* unlikely, but ok */
 
1251
 
 
1252
                                if ( (* currentPt) -> choice == GBPARSE_INT_RIGHT){
 
1253
                                                if (retint -> if_from){
 
1254
                                                        Nlm_gbparse_error("\'^\' then \'>\'",
 
1255
                                                                head_token, *currentPt);
 
1256
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1257
                                                        goto FATAL;
 
1258
                                                }
 
1259
                                }
 
1260
                                Nlm_gbload_number (& ( retint -> to), & (retint -> if_to),
 
1261
                                        keep_rawPt, currentPt, head_token, 
 
1262
                                        num_errPt, TAKE_SECOND);
 
1263
                                Nlm_gbcheck_range(retint -> to, idp, keep_rawPt, num_errPt, head_token, *currentPt);
 
1264
/*----------
 
1265
 *  The caret location implies a place (point) between two location.
 
1266
 *  This is not exactly captured by the ASN.1, but pretty close
 
1267
 *-------*/
 
1268
                                if (in_caret){
 
1269
                                        Int4 to = retint -> to;
 
1270
        
 
1271
                                        point = Nlm_gbpintpnt(retnode, & retint);
 
1272
                                        if ( point -> point +1 == to){
 
1273
                                                point -> point = to; /* was essentailly correct */
 
1274
                                        }else{
 
1275
                                                point -> fuzz -> choice = 2; /* range */
 
1276
                                                point -> fuzz -> a = to; /* max */
 
1277
                                                point -> fuzz ->b = point -> point;
 
1278
                                        }
 
1279
                                }
 
1280
                                if (retint != NULL)
 
1281
                                if (retint -> from == retint -> to &&
 
1282
                                                ! retint -> if_from &&
 
1283
                                                ! retint -> if_to){
 
1284
/*-------if interval really a point, make is so ----*/
 
1285
                                        Nlm_gbpintpnt(retnode, & retint);
 
1286
                                }
 
1287
                                } /* end switch */
 
1288
                                }else{
 
1289
                                        Nlm_gbpintpnt(retnode, & retint);
 
1290
                                }
 
1291
                        }else{
 
1292
                                goto FATAL;
 
1293
                        }
 
1294
                                break;
 
1295
                        default:
 
1296
                                        Nlm_gbparse_error("No number when expected",
 
1297
                                                head_token, *currentPt);
 
1298
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1299
                                        goto FATAL;
 
1300
                        
 
1301
                }
 
1302
 
 
1303
 
 
1304
RETURN:
 
1305
                return retnode;
 
1306
 
 
1307
FATAL:
 
1308
                if (retint && (* num_errPt)){
 
1309
                        SeqIntFree(retint);
 
1310
                        retint = NULL;
 
1311
                }
 
1312
                ValNodeFree(retnode);
 
1313
                retnode = NULL;
 
1314
                goto RETURN;
 
1315
}
 
1316
 
 
1317
/*--------------- Nlm_gbint_ver ()--------------------*/
 
1318
 
 
1319
NLM_EXTERN SeqLocPtr /* sometimes returns points */
 
1320
 
 
1321
Nlm_gbint_ver(Boolean PNTR keep_rawPt, ValNodePtr PNTR currentPt,
 
1322
          ValNodePtr head_token, int PNTR num_errPt, SeqIdPtr seq_id,
 
1323
          Boolean accver)
 
1324
{
 
1325
        SeqLocPtr retnode = ValNodeNew(NULL);
 
1326
        SeqIntPtr retint = SeqIntNew();
 
1327
        TextSeqIdPtr tp;
 
1328
        IntFuzzPtr fuzz=NULL;
 
1329
        SeqIdPtr idp = NULL;
 
1330
        Boolean took_choice=FALSE;
 
1331
        CharPtr p;
 
1332
 
 
1333
        retnode -> choice = SEQLOC_INT;
 
1334
 
 
1335
                if ( (* currentPt) -> choice == GBPARSE_INT_ACCESION){
 
1336
                        idp = ValNodeNew(NULL);
 
1337
                        if (seq_id){
 
1338
                                if (
 
1339
                                        seq_id -> choice == SEQID_GENBANK
 
1340
                                         || seq_id -> choice == SEQID_EMBL
 
1341
                                         || seq_id -> choice == SEQID_DDBJ
 
1342
                                ){
 
1343
                                        idp -> choice = seq_id -> choice;
 
1344
                                        took_choice = TRUE;
 
1345
                                }
 
1346
                        }
 
1347
                        if (! took_choice){
 
1348
                                idp -> choice = SEQID_GENBANK;
 
1349
                        }
 
1350
                        tp = TextSeqIdNew();
 
1351
                        idp -> data.ptrvalue = tp;
 
1352
                        if(accver == FALSE)
 
1353
                        {
 
1354
                                tp->accession = StringSave((*currentPt)->data.ptrvalue);
 
1355
                        }
 
1356
                        else
 
1357
                        {
 
1358
                                p = StringChr((*currentPt)->data.ptrvalue, '.');
 
1359
                                if(p == NULL)
 
1360
                                {
 
1361
                                        tp->accession = StringSave((*currentPt)->data.ptrvalue);
 
1362
                                        Nlm_gbparse_error("Missing accession's version",
 
1363
                                                          head_token, *currentPt);
 
1364
                                }
 
1365
                                else
 
1366
                                {
 
1367
                                        *p = '\0';
 
1368
                                        tp->accession = StringSave((*currentPt)->data.ptrvalue);
 
1369
                                        tp->version = atoi(p + 1);
 
1370
                                        *p = '.';
 
1371
                                }
 
1372
                        }
 
1373
                        *currentPt  =  (* currentPt)  -> next;
 
1374
                        if ( !  *currentPt ){
 
1375
                                        Nlm_gbparse_error("Nothing after accession",
 
1376
                                                head_token, *currentPt);
 
1377
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1378
 
 
1379
                                        SeqIdFree(idp);
 
1380
                                        idp = NULL;
 
1381
 
 
1382
                                        goto FATAL;
 
1383
                        }
 
1384
                }else{
 
1385
                        idp = SeqIdDup (seq_id);        
 
1386
                }
 
1387
                if ( (* currentPt) -> choice == GBPARSE_INT_LT){
 
1388
                                fuzz = IntFuzzNew();
 
1389
                                fuzz -> choice = 4;
 
1390
                                fuzz ->a = 2;
 
1391
                         *currentPt  =  (* currentPt)  -> next;
 
1392
                        if ( !  *currentPt ){
 
1393
                                        Nlm_gbparse_error("Nothing after \'<\'",
 
1394
                                                head_token, *currentPt);
 
1395
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1396
                                        goto FATAL;
 
1397
                        }
 
1398
                }
 
1399
                if ( ! (* num_errPt))
 
1400
                switch ( (*currentPt ) -> choice){
 
1401
                        case  GBPARSE_INT_ACCESION :
 
1402
                                if ( idp){
 
1403
                                        Nlm_gbparse_error("duplicate accessions",
 
1404
                                                head_token, *currentPt);
 
1405
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1406
                                        goto FATAL;
 
1407
                                }
 
1408
                                break;
 
1409
                        case  GBPARSE_INT_CARET : 
 
1410
                                        Nlm_gbparse_error("caret (^) before number" ,
 
1411
                                                head_token, *currentPt);
 
1412
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1413
                                        goto FATAL;
 
1414
                        case  GBPARSE_INT_LT : 
 
1415
                                if ( idp){
 
1416
                                        Nlm_gbparse_error("duplicate \'<\'",
 
1417
                                                head_token, *currentPt);
 
1418
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1419
                                        goto FATAL;
 
1420
                                }
 
1421
                                break;
 
1422
                        case  GBPARSE_INT_GT :
 
1423
                        case  GBPARSE_INT_NUMBER :
 
1424
                        case  GBPARSE_INT_LEFT :
 
1425
 
 
1426
                        case GBPARSE_INT_ONE_OF_NUM:
 
1427
 
 
1428
                                retint -> if_from = fuzz;
 
1429
                                retint -> id = idp;
 
1430
                                retnode -> data.ptrvalue = retint;
 
1431
                                Nlm_gbload_number (& ( retint -> from), & (retint -> if_from),
 
1432
                                        keep_rawPt, currentPt, head_token, 
 
1433
                                        num_errPt,TAKE_FIRST);
 
1434
                                Nlm_gbcheck_range(retint -> from, idp, keep_rawPt, num_errPt, head_token, *currentPt);
 
1435
                if ( ! (* num_errPt) ){
 
1436
                if ( * currentPt){
 
1437
                                Boolean in_caret = FALSE;
 
1438
                switch ( (*currentPt ) -> choice){
 
1439
                                SeqPntPtr point;
 
1440
 
 
1441
                                default: case GBPARSE_INT_JOIN: case GBPARSE_INT_COMPL: 
 
1442
                                case GBPARSE_INT_SINGLE_DOT:case GBPARSE_INT_ORDER: case GBPARSE_INT_GROUP:
 
1443
                                case GBPARSE_INT_ACCESION:
 
1444
                                        Nlm_gbparse_error("problem with 2nd number",
 
1445
                                                head_token, *currentPt);;
 
1446
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1447
                                        goto FATAL;
 
1448
                                case GBPARSE_INT_COMMA: case GBPARSE_INT_RIGHT: /* valid thing to leave on*/
 
1449
/*--------------but have a point, not an interval----*/
 
1450
                                        Nlm_gbpintpnt(retnode, & retint);
 
1451
                                        break;
 
1452
                                case GBPARSE_INT_GT: case GBPARSE_INT_LT:
 
1453
                                        Nlm_gbparse_error("Missing \'..\'",
 
1454
                                                head_token, *currentPt);;
 
1455
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1456
                                        goto FATAL;
 
1457
                                case GBPARSE_INT_CARET:
 
1458
                                if (retint -> if_from){
 
1459
                                        Nlm_gbparse_error("\'<\' then \'^\'",
 
1460
                                        head_token, *currentPt);
 
1461
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1462
                                        goto FATAL;
 
1463
                                }
 
1464
                                retint -> if_from = IntFuzzNew();
 
1465
                                retint -> if_from -> choice = 4;
 
1466
                                retint -> if_from ->a = 4;
 
1467
                                retint -> if_to = IntFuzzNew();
 
1468
                                retint -> if_to -> choice = 4;
 
1469
                                retint -> if_to ->a = 4;
 
1470
                                in_caret = TRUE;
 
1471
/*---no break on purpose ---*/
 
1472
                                case GBPARSE_INT_DOT_DOT:
 
1473
                         *currentPt  =  (* currentPt)  -> next;
 
1474
                        if ( (*currentPt) == NULL){
 
1475
                                Nlm_gbparse_error("unexpected end of usable tokens",
 
1476
                                        head_token, *currentPt);
 
1477
                                * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1478
                                goto FATAL;
 
1479
                        }
 
1480
/*--no break on purpose here ---*/
 
1481
                                case GBPARSE_INT_NUMBER:
 
1482
                                case GBPARSE_INT_LEFT:
 
1483
 
 
1484
                                case GBPARSE_INT_ONE_OF_NUM:  /* unlikely, but ok */
 
1485
 
 
1486
                                if ( (* currentPt) -> choice == GBPARSE_INT_RIGHT){
 
1487
                                                if (retint -> if_from){
 
1488
                                                        Nlm_gbparse_error("\'^\' then \'>\'",
 
1489
                                                                head_token, *currentPt);
 
1490
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1491
                                                        goto FATAL;
 
1492
                                                }
 
1493
                                }
 
1494
                                Nlm_gbload_number (& ( retint -> to), & (retint -> if_to),
 
1495
                                        keep_rawPt, currentPt, head_token, 
 
1496
                                        num_errPt, TAKE_SECOND);
 
1497
                                Nlm_gbcheck_range(retint -> to, idp, keep_rawPt, num_errPt, head_token, *currentPt);
 
1498
/*----------
 
1499
 *  The caret location implies a place (point) between two location.
 
1500
 *  This is not exactly captured by the ASN.1, but pretty close
 
1501
 *-------*/
 
1502
                                if (in_caret){
 
1503
                                        Int4 to = retint -> to;
 
1504
        
 
1505
                                        point = Nlm_gbpintpnt(retnode, & retint);
 
1506
                                        if ( point -> point +1 == to){
 
1507
                                                point -> point = to; /* was essentailly correct */
 
1508
                                        }else{
 
1509
                                                point -> fuzz -> choice = 2; /* range */
 
1510
                                                point -> fuzz -> a = to; /* max */
 
1511
                                                point -> fuzz ->b = point -> point;
 
1512
                                        }
 
1513
                                }
 
1514
                                if (retint != NULL)
 
1515
                                if (retint -> from == retint -> to &&
 
1516
                                                ! retint -> if_from &&
 
1517
                                                ! retint -> if_to){
 
1518
/*-------if interval really a point, make is so ----*/
 
1519
                                        Nlm_gbpintpnt(retnode, & retint);
 
1520
                                }
 
1521
                                } /* end switch */
 
1522
                                }else{
 
1523
                                        Nlm_gbpintpnt(retnode, & retint);
 
1524
                                }
 
1525
                        }else{
 
1526
                                goto FATAL;
 
1527
                        }
 
1528
                                break;
 
1529
                        default:
 
1530
                                        Nlm_gbparse_error("No number when expected",
 
1531
                                                head_token, *currentPt);
 
1532
                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1533
                                        goto FATAL;
 
1534
                        
 
1535
                }
 
1536
 
 
1537
 
 
1538
RETURN:
 
1539
                return retnode;
 
1540
 
 
1541
FATAL:
 
1542
                if (retint && (* num_errPt)){
 
1543
                        SeqIntFree(retint);
 
1544
                        retint = NULL;
 
1545
                }
 
1546
                ValNodeFree(retnode);
 
1547
                retnode = NULL;
 
1548
                goto RETURN;
 
1549
}
 
1550
 
 
1551
/*------------------- Nlm_gbpintpnt()-----------*/
 
1552
 
 
1553
NLM_EXTERN SeqPntPtr
 
1554
Nlm_gbpintpnt(SeqLocPtr retnode, SeqIntPtr PNTR retintPt)
 
1555
{
 
1556
        SeqPntPtr point;
 
1557
                point = SeqPntNew();
 
1558
                point -> point = (*retintPt) -> from;
 
1559
                point -> id = (*retintPt) -> id;
 
1560
                (*retintPt) -> id = NULL;
 
1561
                point -> fuzz = (*retintPt) -> if_from;
 
1562
                (*retintPt) -> if_from = NULL;
 
1563
                SeqIntFree((*retintPt));
 
1564
                (*retintPt) = NULL;
 
1565
                retnode -> choice = SEQLOC_PNT;
 
1566
                retnode -> data.ptrvalue = point;
 
1567
        return point;
 
1568
}
 
1569
 
 
1570
/*----- Nlm_gbload_number() -----*/
 
1571
 
 
1572
NLM_EXTERN void
 
1573
Nlm_gbload_number (Int4 PNTR numPt, IntFuzzPtr PNTR fuzzPt, Boolean PNTR keep_rawPt, ValNodePtr PNTR currentPt, ValNodePtr head_token, int PNTR num_errPt, int take_which)
 
1574
{
 
1575
        int num_found=0;
 
1576
        int fuzz_err =0;
 
1577
        Boolean strange_sin_dot = FALSE;
 
1578
 
 
1579
                if ((*currentPt ) -> choice == GBPARSE_INT_CARET){
 
1580
                        Nlm_gbparse_error("duplicate carets",
 
1581
                                        head_token, *currentPt);
 
1582
                        (*keep_rawPt) = TRUE; (*num_errPt) ++;
 
1583
                         *currentPt  =  (* currentPt)  -> next;
 
1584
                        fuzz_err = 1;
 
1585
                }else if ((*currentPt ) -> choice == GBPARSE_INT_GT ||
 
1586
                                (*currentPt ) -> choice == GBPARSE_INT_LT){
 
1587
                        if ( ! * fuzzPt){
 
1588
                                * fuzzPt = IntFuzzNew();
 
1589
                        }
 
1590
                        (* fuzzPt) -> choice = 4;
 
1591
                        if ((*currentPt ) -> choice == GBPARSE_INT_GT ){
 
1592
                                (* fuzzPt) -> a = 1; /* 'a' serves as "lim" for choice 4 */
 
1593
                        }else{
 
1594
                                (* fuzzPt) -> a = 2;
 
1595
                        }
 
1596
                         *currentPt  =  (* currentPt)  -> next;
 
1597
                }else if ((*currentPt ) -> choice == GBPARSE_INT_LEFT){
 
1598
                        strange_sin_dot = TRUE;
 
1599
                         *currentPt  =  (* currentPt)  -> next;
 
1600
                                if ((*currentPt ) -> choice == GBPARSE_INT_NUMBER){
 
1601
                                        if ( ! * fuzzPt){
 
1602
                                                * fuzzPt = IntFuzzNew();
 
1603
                                        }
 
1604
                                        (* fuzzPt)  -> b  = atoi((*currentPt ) -> data.ptrvalue)-1;
 
1605
                                        (* fuzzPt) -> choice = 2;
 
1606
                                        if ( take_which == TAKE_FIRST ){
 
1607
                                                * numPt = (* fuzzPt)  -> b;
 
1608
                                        }
 
1609
                                         *currentPt  =  (* currentPt)  -> next;
 
1610
                                        num_found=1;
 
1611
                                }else{
 
1612
                                        fuzz_err =1;
 
1613
                                }
 
1614
                                if ((*currentPt ) -> choice != GBPARSE_INT_SINGLE_DOT ){
 
1615
                                        fuzz_err =1;
 
1616
                                }else{
 
1617
                                         *currentPt  =  (* currentPt)  -> next;
 
1618
                                        if ((*currentPt ) -> choice == GBPARSE_INT_NUMBER){
 
1619
                                                (* fuzzPt)  -> a  = atoi((*currentPt ) -> data.ptrvalue)-1;
 
1620
                                                if ( take_which ==  TAKE_SECOND ){
 
1621
                                                        * numPt = (* fuzzPt)  -> a;
 
1622
                                                }
 
1623
                                                 *currentPt  =  (* currentPt)  -> next;
 
1624
                                        }else{
 
1625
                                                fuzz_err =1;
 
1626
                                        }
 
1627
                                        if ((*currentPt ) -> choice == GBPARSE_INT_RIGHT){
 
1628
                                                 *currentPt  =  (* currentPt)  -> next;
 
1629
                                        }else{
 
1630
                                                fuzz_err =1;
 
1631
                                        }
 
1632
                                }
 
1633
                                        
 
1634
                }else if ((*currentPt ) -> choice != GBPARSE_INT_NUMBER) {
 
1635
/* this prevents endless cycling, unconditionally */
 
1636
                if ((*currentPt ) -> choice != GBPARSE_INT_ONE_OF 
 
1637
                        && (*currentPt ) -> choice !=  GBPARSE_INT_ONE_OF_NUM)
 
1638
                         *currentPt  =  (* currentPt)  -> next;
 
1639
                        num_found = -1;
 
1640
                }
 
1641
 
 
1642
                if ( ! strange_sin_dot){
 
1643
                        if ( ! * currentPt){
 
1644
                                        Nlm_gbparse_error("unexpected end of interval tokens",
 
1645
                                                head_token, *currentPt);
 
1646
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1647
                        }else{
 
1648
                                 if ((*currentPt ) -> choice == GBPARSE_INT_NUMBER){
 
1649
                                        * numPt = atoi((*currentPt ) -> data.ptrvalue)-1;
 
1650
                                         *currentPt  =  (* currentPt)  -> next;
 
1651
                                        num_found=1;
 
1652
                                }
 
1653
                        }
 
1654
                }
 
1655
 
 
1656
        if ( fuzz_err){
 
1657
                                        Nlm_gbparse_error("Incorrect uncertainty",
 
1658
                                                head_token, *currentPt);
 
1659
                                        (*keep_rawPt) = TRUE; (*num_errPt) ++;
 
1660
        }
 
1661
        if ( num_found != 1){
 
1662
                                        (*keep_rawPt) = TRUE; 
 
1663
/****************
 
1664
 *
 
1665
 *  10..one-of(13,15) type syntax here
 
1666
 *
 
1667
 ***************/
 
1668
                if ((*currentPt ) -> choice == GBPARSE_INT_ONE_OF 
 
1669
                                || (*currentPt ) -> choice == GBPARSE_INT_ONE_OF_NUM){
 
1670
                        Boolean one_of_ok = TRUE;
 
1671
                        Boolean at_end_one_of = FALSE;
 
1672
 
 
1673
                        *currentPt  =  (* currentPt)  -> next;
 
1674
                        if ((*currentPt ) -> choice != GBPARSE_INT_LEFT){
 
1675
                                one_of_ok = FALSE;
 
1676
                        }else{
 
1677
                                *currentPt  =  (* currentPt)  -> next;
 
1678
                        }
 
1679
                        if (one_of_ok &&  (*currentPt ) -> choice == GBPARSE_INT_NUMBER){
 
1680
                                        * numPt = atoi((*currentPt ) -> data.ptrvalue)-1;
 
1681
                                         *currentPt  =  (* currentPt)  -> next;
 
1682
                        }else{
 
1683
                                one_of_ok = FALSE;
 
1684
                        }
 
1685
                        while  (one_of_ok && ! at_end_one_of &&  *currentPt != NULL){
 
1686
                                switch ( (*currentPt ) -> choice){
 
1687
                                        default:
 
1688
                                                one_of_ok = FALSE;
 
1689
                                                break;
 
1690
                                        case GBPARSE_INT_COMMA:
 
1691
                                        case GBPARSE_INT_NUMBER:
 
1692
                                         *currentPt  =  (* currentPt)  -> next;
 
1693
                                        break;
 
1694
                                        case GBPARSE_INT_RIGHT:
 
1695
                                         *currentPt  =  (* currentPt)  -> next;
 
1696
                                        at_end_one_of = TRUE;
 
1697
                                        break;
 
1698
                                }
 
1699
                        }
 
1700
                        if ( ! one_of_ok && ! at_end_one_of){
 
1701
                                while (! at_end_one_of && *currentPt != NULL){
 
1702
                                        if ((*currentPt ) -> choice == GBPARSE_INT_RIGHT){
 
1703
                                                at_end_one_of = TRUE;
 
1704
                                        }
 
1705
                                 *currentPt  =  (* currentPt)  -> next;
 
1706
                                }
 
1707
                        }
 
1708
 
 
1709
                        if ( ! one_of_ok){
 
1710
                                Nlm_gbparse_error("bad one-of() syntax as number",
 
1711
                                        head_token, *currentPt);
 
1712
                                (*num_errPt) ++;
 
1713
                        }
 
1714
                }else{
 
1715
                        Nlm_gbparse_error("Number not found when expected",
 
1716
                                head_token, *currentPt);
 
1717
                        (*num_errPt) ++;
 
1718
                }
 
1719
        }
 
1720
}
 
1721
 
 
1722
/*----------------- Nlm_gbparse_better_be_done()-------------*/
 
1723
NLM_EXTERN SeqLocPtr
 
1724
Nlm_gbparse_better_be_done(int PNTR num_errsPt, ValNodePtr current_token, ValNodePtr head_token, SeqLocPtr ret_so_far, Boolean PNTR keep_rawPt, int paren_count)
 
1725
{
 
1726
        SeqLocPtr retval = ret_so_far;
 
1727
 
 
1728
                if ( current_token)
 
1729
                while (current_token -> choice == GBPARSE_INT_RIGHT){
 
1730
                        paren_count --; 
 
1731
                        current_token =  current_token -> next;
 
1732
                        if ( ! current_token){
 
1733
                                if ( paren_count){
 
1734
                                        char par_msg[40];
 
1735
                                        sprintf(par_msg, "mismatched parentheses (%d)", paren_count);
 
1736
                                        Nlm_gbparse_error(par_msg,
 
1737
                                        head_token, current_token);
 
1738
                                        *keep_rawPt = TRUE;
 
1739
                                        (*num_errsPt) ++;
 
1740
                                }
 
1741
                                break;
 
1742
                        }
 
1743
                }
 
1744
                if ( paren_count){
 
1745
                                        Nlm_gbparse_error("text after last legal right parenthesis",
 
1746
                                        head_token, current_token);
 
1747
                                        *keep_rawPt = TRUE;
 
1748
                                        (*num_errsPt) ++;
 
1749
                }
 
1750
 
 
1751
                if (current_token){
 
1752
                        Nlm_gbparse_error("text after end",
 
1753
                                        head_token, current_token);
 
1754
                        *keep_rawPt = TRUE;
 
1755
                        (*num_errsPt) ++;
 
1756
                }
 
1757
        return retval;
 
1758
}
 
1759
 
 
1760
/*-------- Nlm_gbreplace() --------*/
 
1761
 
 
1762
NLM_EXTERN SeqLocPtr 
 
1763
Nlm_gbreplace (Boolean PNTR keep_rawPt, int PNTR parenPt, Boolean PNTR sitesPt, ValNodePtr PNTR currentPt, ValNodePtr head_token, int PNTR num_errPt, SeqIdPtr seq_id)
 
1764
{
 
1765
        SeqLocPtr retval = NULL;
 
1766
 
 
1767
                * keep_rawPt = TRUE;
 
1768
                 *currentPt  =  (* currentPt)  -> next;
 
1769
 
 
1770
                if ((*currentPt ) -> choice == GBPARSE_INT_LEFT){
 
1771
                         *currentPt  =  (* currentPt)  -> next;
 
1772
                        retval = Nlm_gbloc (keep_rawPt, parenPt, sitesPt, currentPt, head_token, 
 
1773
                                num_errPt,seq_id);
 
1774
                        if ( ! * currentPt){
 
1775
                                        Nlm_gbparse_error("unexpected end of interval tokens",
 
1776
                                                head_token, *currentPt);
 
1777
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1778
                        }else{
 
1779
                                
 
1780
                                if ((*currentPt ) -> choice != GBPARSE_INT_COMMA){
 
1781
                                                Nlm_gbparse_error("Missing comma after first location in replace",
 
1782
                                                head_token, *currentPt);
 
1783
                                                (* num_errPt) ++;
 
1784
                                }
 
1785
                        }
 
1786
                }else{
 
1787
                                        Nlm_gbparse_error("Missing \'(\'" /* paran match  ) */
 
1788
                                                , head_token, *currentPt);
 
1789
                                        (* num_errPt) ++;
 
1790
                }
 
1791
        return retval;
 
1792
}
 
1793
 
 
1794
 
 
1795
 
 
1796
/*-------- Nlm_gbreplace_ver() --------*/
 
1797
 
 
1798
NLM_EXTERN SeqLocPtr Nlm_gbreplace_ver(Boolean PNTR keep_rawPt, int PNTR parenPt,
 
1799
                                   Boolean PNTR sitesPt,
 
1800
                                   ValNodePtr PNTR currentPt,
 
1801
                                   ValNodePtr head_token, int PNTR num_errPt,
 
1802
                                   SeqIdPtr seq_id, Boolean accver)
 
1803
{
 
1804
        SeqLocPtr retval = NULL;
 
1805
 
 
1806
                * keep_rawPt = TRUE;
 
1807
                 *currentPt  =  (* currentPt)  -> next;
 
1808
 
 
1809
                if ((*currentPt ) -> choice == GBPARSE_INT_LEFT){
 
1810
                         *currentPt  =  (* currentPt)  -> next;
 
1811
                        retval = Nlm_gbloc_ver (keep_rawPt, parenPt, sitesPt, currentPt, head_token, 
 
1812
                                num_errPt,seq_id, accver);
 
1813
                        if ( ! * currentPt){
 
1814
                                        Nlm_gbparse_error("unexpected end of interval tokens",
 
1815
                                                head_token, *currentPt);
 
1816
                                                        * keep_rawPt = TRUE;  (* num_errPt) ++;
 
1817
                        }else{
 
1818
                                
 
1819
                                if ((*currentPt ) -> choice != GBPARSE_INT_COMMA){
 
1820
                                                Nlm_gbparse_error("Missing comma after first location in replace",
 
1821
                                                head_token, *currentPt);
 
1822
                                                (* num_errPt) ++;
 
1823
                                }
 
1824
                        }
 
1825
                }else{
 
1826
                                        Nlm_gbparse_error("Missing \'(\'" /* paran match  ) */
 
1827
                                                , head_token, *currentPt);
 
1828
                                        (* num_errPt) ++;
 
1829
                }
 
1830
        return retval;
 
1831
}
 
1832
 
 
1833
 
 
1834
 
 
1835
char Saved_ch;
 
1836
 
 
1837
#define Nlm_lex_error_MACRO(msg)\
 
1838
                if (*current_col){\
 
1839
                Saved_ch = *(current_col +1);\
 
1840
                *(current_col +1) = '\0';\
 
1841
                }else{\
 
1842
                Saved_ch='\0';\
 
1843
                }\
 
1844
                Nlm_gbparse_error(msg, & forerrmacro, & forerrmacro);\
 
1845
                if (Saved_ch)\
 
1846
                *(current_col +1) = Saved_ch;
 
1847
 
 
1848
/*------------- gbparselex()-----------------------*/
 
1849
 
 
1850
NLM_EXTERN int
 
1851
Nlm_gbparselex(CharPtr linein, ValNodePtr PNTR lexed)
 
1852
{       
 
1853
        CharPtr current_col=0, points_at_term_null,spare, line_use = NULL;
 
1854
        int dex;
 
1855
        int retval = 0, len;
 
1856
        ValNodePtr current_token = NULL, last_token = NULL;
 
1857
        Boolean skip_new_token=FALSE;
 
1858
        Boolean die_now=FALSE;
 
1859
        ValNode forerrmacro;
 
1860
 
 
1861
        forerrmacro.choice =GBPARSE_INT_ACCESION ;
 
1862
 
 
1863
        if (*linein     ){
 
1864
                len = StringLen(linein);
 
1865
                line_use = MemNew(len + 1);
 
1866
                StringCpy(line_use, linein);
 
1867
                if ( * lexed){
 
1868
                                Nlm_lex_error_MACRO( "Lex list not cleared on entry to Nlm_gbparselex")
 
1869
                        ValNodeFree( * lexed);
 
1870
                        * lexed = NULL;
 
1871
                }
 
1872
                current_col = line_use ;
 
1873
                forerrmacro.data.ptrvalue = line_use;
 
1874
/*---------
 
1875
 *   Clear terminal white space
 
1876
 *---------*/
 
1877
                points_at_term_null = line_use + len;
 
1878
                spare = points_at_term_null - 1;
 
1879
                while (*spare == ' '  || *spare == '\n' || *spare == '\r' || *spare == '~') {
 
1880
                        *spare-- = '\0';
 
1881
                        points_at_term_null --;
 
1882
                }
 
1883
 
 
1884
 
 
1885
                while (current_col < points_at_term_null && ! die_now) {
 
1886
                        if ( ! skip_new_token){
 
1887
                                last_token = current_token;
 
1888
                                current_token = ValNodeNew(current_token);
 
1889
                                if ( ! * lexed)
 
1890
                                        * lexed = current_token;
 
1891
                        }
 
1892
                        switch ( *current_col){
 
1893
 
 
1894
                        case '\"':
 
1895
                                skip_new_token = FALSE;
 
1896
                                current_token -> choice = GBPARSE_INT_STRING;
 
1897
                                for (spare = current_col +1; spare < points_at_term_null; 
 
1898
                                                spare ++) {
 
1899
                                        if ( *spare == '\"'){
 
1900
                                                break;
 
1901
                                        }
 
1902
                                }
 
1903
                                if (spare >= points_at_term_null){
 
1904
                                                Nlm_lex_error_MACRO( "unterminated string")
 
1905
                                                retval ++;
 
1906
                                }else{
 
1907
                                        len = spare-current_col + 1;
 
1908
                                        current_token -> data.ptrvalue = 
 
1909
                                                MemNew(len +2);
 
1910
                                        StringNCpy(current_token -> data.ptrvalue,
 
1911
                                                current_col,len);
 
1912
                                        current_col += len;
 
1913
                                }
 
1914
                                        break;
 
1915
/*------
 
1916
 *  NUMBER
 
1917
 *------*/
 
1918
                        case '0': case '1': case '2': case '3': case '4':
 
1919
                        case '5': case '6': case '7': case '8': case '9':
 
1920
                                skip_new_token = FALSE;
 
1921
                                current_token -> choice = GBPARSE_INT_NUMBER;
 
1922
                                for (dex=0, spare = current_col; isdigit(*spare); spare ++){
 
1923
                                        dex ++ ;
 
1924
                                }
 
1925
                                current_token -> data.ptrvalue = MemNew(dex+1);
 
1926
                                StringNCpy(current_token -> data.ptrvalue, current_col, dex);
 
1927
                                current_col += dex -1;
 
1928
                                break;
 
1929
/*------
 
1930
 *  JOIN
 
1931
 *------*/
 
1932
                        case 'j':
 
1933
                                skip_new_token = FALSE;
 
1934
                                current_token -> choice = GBPARSE_INT_JOIN;
 
1935
                                if (StringNCmp(current_col,"join",(unsigned) 4)!=0){
 
1936
                                        Nlm_lex_error_MACRO( "\"join\" misspelled")
 
1937
                                        retval += 10;
 
1938
                                        for(;*current_col && *current_col != '('; current_col++)
 
1939
                                                ; /* vi match )   empty body*/ 
 
1940
                                        current_col -- ;  /* back up 'cause ++ follows */
 
1941
                                }else{
 
1942
                                        current_col += 3;
 
1943
                                }
 
1944
                                break;
 
1945
                        
 
1946
/*------
 
1947
 *  ORDER and ONE-OF
 
1948
 *------*/
 
1949
                        case 'o':
 
1950
                                skip_new_token = FALSE;
 
1951
                                if (StringNCmp(current_col,"order",(unsigned) 5)!=0){
 
1952
                                        if (StringNCmp(current_col,"one-of",(unsigned) 6)!=0){
 
1953
                                        Nlm_lex_error_MACRO( "\"order\" or \"one-of\" misspelled")
 
1954
                                                retval ++;
 
1955
                                                for(;*current_col && *current_col != '('; current_col++)
 
1956
                                                        ; /* vi match )   empty body*/ 
 
1957
                                                current_col -- ;  /* back up 'cause ++ follows */
 
1958
                                        }else{
 
1959
                                                current_token -> choice = GBPARSE_INT_ONE_OF ;
 
1960
                                                current_col += 5;
 
1961
                                        }
 
1962
                                }else{
 
1963
                                        current_token -> choice = GBPARSE_INT_ORDER;
 
1964
                                        current_col += 4;
 
1965
                                }
 
1966
                                break;
 
1967
 
 
1968
/*------
 
1969
 *  REPLACE
 
1970
 *------*/
 
1971
                        case 'r' :
 
1972
                                skip_new_token = FALSE;
 
1973
                                current_token -> choice = GBPARSE_INT_REPLACE ;
 
1974
                                if (StringNCmp(current_col,"replace",(unsigned) 6)!=0){
 
1975
                                        Nlm_lex_error_MACRO( "\"replace\" misspelled")
 
1976
                                        retval ++;
 
1977
                                        for(;*current_col && *current_col != '('; current_col++)
 
1978
                                                ; /* vi match )   empty body*/ 
 
1979
                                        current_col -- ;  /* back up 'cause ++ follows */
 
1980
                                }else{
 
1981
                                        current_col += 6;
 
1982
                                }
 
1983
                                break;
 
1984
                        
 
1985
/*------
 
1986
 *  GAP or GROUP or GI
 
1987
 *------*/
 
1988
                        case 'g':
 
1989
                                skip_new_token = FALSE;
 
1990
                                if(StringNCmp(current_col, "gap", 3) == 0 &&
 
1991
                                   (current_col[3] == '(' ||
 
1992
                                    current_col[3] == ' ' ||
 
1993
                                    current_col[3] == '\t' ||
 
1994
                                    current_col[3] == '\0'))
 
1995
                                {
 
1996
                                    current_token->choice = GBPARSE_INT_GAP;
 
1997
                                    current_col += 2;
 
1998
                                    current_token->data.ptrvalue = MemNew(4);
 
1999
                                    StringCpy(current_token->data.ptrvalue, "gap");
 
2000
                                    break;
 
2001
                                }
 
2002
                                if(StringNCmp(current_col, "gi|", 3) == 0) {
 
2003
                                    current_token->choice = GBPARSE_INT_ACCESION;
 
2004
                                    current_col += 3;
 
2005
                                        for (; IS_DIGIT(*current_col); current_col++) ;
 
2006
                                    break;
 
2007
                                }
 
2008
                                current_token -> choice = GBPARSE_INT_GROUP;
 
2009
                                if (StringNCmp(current_col,"group",(unsigned) 5)!=0){
 
2010
                                        Nlm_lex_error_MACRO("\"group\" misspelled")
 
2011
                                        retval ++;
 
2012
                                        for(;*current_col && *current_col != '('; current_col++)
 
2013
                                                ; /* vi match )   empty body*/ 
 
2014
                                        current_col -- ;  /* back up 'cause ++ follows */
 
2015
                                }else{
 
2016
                                        current_col += 4;
 
2017
                                }
 
2018
                                break;
 
2019
                        
 
2020
/*------
 
2021
 *  COMPLEMENT
 
2022
 *------*/
 
2023
                        case 'c':
 
2024
                                skip_new_token = FALSE;
 
2025
                                current_token -> choice = GBPARSE_INT_COMPL;
 
2026
                                if (StringNCmp(current_col,"complement",(unsigned) 10)!=0){
 
2027
                                        Nlm_lex_error_MACRO("\"complement\" misspelled")
 
2028
                                        retval += 10;
 
2029
                                        for(;*current_col && *current_col != '('; current_col++)
 
2030
                                                ; /* vi match )   empty body*/ 
 
2031
                                        current_col -- ;  /* back up 'cause ++ follows */
 
2032
                                }else{
 
2033
                                        current_col += 9;
 
2034
                                }
 
2035
                                break;
 
2036
 
 
2037
/*-------
 
2038
 * internal bases ignored
 
2039
 *---------*/
 
2040
                        case 'b':
 
2041
                        if (StringNCmp(current_col,"bases",(unsigned) 5)!=0){
 
2042
                                goto ACCESSION;
 
2043
                        }else{
 
2044
                                skip_new_token = TRUE;
 
2045
                                current_col += 4;
 
2046
                        }
 
2047
                                break;
 
2048
 
 
2049
/*------
 
2050
 *  ()^.,<>  (bases (sites
 
2051
 *------*/
 
2052
                        case '(':
 
2053
                                if (StringNCmp(current_col,"(base",(unsigned) 5)==0){
 
2054
                                        skip_new_token = FALSE;
 
2055
                                        current_token -> choice = GBPARSE_INT_JOIN;
 
2056
                                        current_col += 4;
 
2057
                                        if (*current_col != '\0')
 
2058
                                        if ( * (current_col +1) == 's')
 
2059
                                                current_col ++;
 
2060
                                        last_token = current_token;
 
2061
                                        current_token = ValNodeNew(current_token);
 
2062
                                        current_token -> choice = GBPARSE_INT_LEFT;
 
2063
                                }else if (StringNCmp(current_col,"(sites",(unsigned) 5)==0){
 
2064
                                        skip_new_token = FALSE;
 
2065
                                        current_col += 5;
 
2066
                                        if (*current_col != '\0')
 
2067
                                        if ( * (current_col +1) == ')'){
 
2068
                                                current_col ++;
 
2069
                                                current_token -> choice = GBPARSE_INT_SITES;
 
2070
                                        }else{
 
2071
                                                current_token -> choice = GBPARSE_INT_SITES;
 
2072
                                                last_token = current_token;
 
2073
                                                current_token = ValNodeNew(current_token);
 
2074
                                                current_token -> choice = GBPARSE_INT_JOIN;
 
2075
                                                last_token = current_token;
 
2076
                                                current_token = ValNodeNew(current_token);
 
2077
                                                current_token -> choice = GBPARSE_INT_LEFT;
 
2078
                                                if (*current_col != '\0'){
 
2079
                                                        if ( * (current_col +1) == ';'){
 
2080
                                                                current_col ++;
 
2081
                                                        }else if (StringNCmp(current_col +1," ;", (unsigned) 2) ==0){
 
2082
                                                                current_col += 2;
 
2083
                                                        }
 
2084
                                                }
 
2085
                                        }
 
2086
                                }else{
 
2087
                                        skip_new_token = FALSE;
 
2088
                                        current_token -> choice = GBPARSE_INT_LEFT;
 
2089
                                }
 
2090
                                break;
 
2091
 
 
2092
                        case ')':
 
2093
                                skip_new_token = FALSE;
 
2094
                                current_token -> choice = GBPARSE_INT_RIGHT;
 
2095
                        
 
2096
                                break;
 
2097
 
 
2098
                        case '^':
 
2099
                                skip_new_token = FALSE;
 
2100
                                current_token -> choice = GBPARSE_INT_CARET;
 
2101
                                break;
 
2102
 
 
2103
                        case '-':
 
2104
                                skip_new_token = FALSE;
 
2105
                                current_token -> choice = GBPARSE_INT_DOT_DOT ;
 
2106
                                break;
 
2107
                        case '.':
 
2108
                                skip_new_token = FALSE;
 
2109
                                if (StringNCmp(current_col,"..",(unsigned) 2)!=0){
 
2110
                                        current_token -> choice = GBPARSE_INT_SINGLE_DOT ;
 
2111
                                }else{
 
2112
                                        current_token -> choice = GBPARSE_INT_DOT_DOT;
 
2113
                                        current_col ++ ;
 
2114
                                }
 
2115
                                break;
 
2116
 
 
2117
                        case '>':
 
2118
                                skip_new_token = FALSE;
 
2119
                                current_token -> choice = GBPARSE_INT_GT;
 
2120
                                break;
 
2121
 
 
2122
                        case '<':
 
2123
                                skip_new_token = FALSE;
 
2124
                                current_token -> choice = GBPARSE_INT_LT;
 
2125
 
 
2126
                                break;
 
2127
 
 
2128
                        case ';':
 
2129
                        case ',':
 
2130
                                skip_new_token = FALSE;
 
2131
                                current_token -> choice = GBPARSE_INT_COMMA;
 
2132
                                break;
 
2133
 
 
2134
                        case ' ': case '\t': case '\n': case '\r': case '~':
 
2135
                                skip_new_token = TRUE;
 
2136
                                break;
 
2137
        
 
2138
                        case 't' :
 
2139
                        if (StringNCmp(current_col,"to",(unsigned) 2)!=0){
 
2140
                                goto ACCESSION;
 
2141
                        }else{
 
2142
                                skip_new_token = FALSE;
 
2143
                                current_token -> choice = GBPARSE_INT_DOT_DOT;
 
2144
                                current_col ++ ;
 
2145
                                break;
 
2146
                        }
 
2147
                                
 
2148
                        case 's' :
 
2149
                        if (StringNCmp(current_col,"site",(unsigned) 4)!=0){
 
2150
                                goto ACCESSION;
 
2151
                        }else{
 
2152
                                skip_new_token = FALSE;
 
2153
                                current_token -> choice = GBPARSE_INT_SITES;
 
2154
                                current_col += 3 ;
 
2155
                                if (*current_col != '\0')
 
2156
                                if ( * (current_col +1) == 's')
 
2157
                                        current_col ++;
 
2158
                                if (*current_col != '\0'){
 
2159
                                        if ( * (current_col +1) == ';'){
 
2160
                                                current_col ++;
 
2161
                                        }else if (StringNCmp(current_col +1," ;", (unsigned) 2) ==0){
 
2162
                                                current_col += 2;
 
2163
                                        }
 
2164
                                }
 
2165
                                break;
 
2166
                        }
 
2167
                                
 
2168
 
 
2169
 ACCESSION:
 
2170
                        default:
 
2171
        /*-------
 
2172
 * all GenBank accessions start with a capital letter
 
2173
 * and then have numbers
 
2174
        ------*/
 
2175
/* new accessions start with 2 capital letters !!  1997 */
 
2176
/* new accessions have .version !!  2/15/1999 */
 
2177
                                skip_new_token = FALSE;
 
2178
                                current_token -> choice = GBPARSE_INT_ACCESION;
 
2179
                                if (IS_ALPHA(*(current_col + 1))) {
 
2180
                                        spare = current_col + 2;
 
2181
                                        dex = 2;
 
2182
                                } else {
 
2183
                                        spare = current_col + 1;
 
2184
                                        dex = 1;
 
2185
                                }
 
2186
                                for (; isdigit(*spare); spare ++){
 
2187
                                        dex ++ ;
 
2188
                                }
 
2189
                                if (*spare == '.') {
 
2190
                                        dex ++ ;
 
2191
                                        for (spare++; isdigit(*spare); spare ++){
 
2192
                                                dex ++ ;
 
2193
                                        }
 
2194
                                }
 
2195
                                if (*spare != ':'){
 
2196
                                        Nlm_lex_error_MACRO( "ACCESSION missing \":\"" )
 
2197
                                        retval += 10;
 
2198
                                        current_col --;
 
2199
                                }
 
2200
                                current_token -> data.ptrvalue = MemNew(dex+1);
 
2201
                                StringNCpy(current_token -> data.ptrvalue, current_col, dex);
 
2202
                                current_col += dex ;
 
2203
 
 
2204
 
 
2205
                }
 
2206
        /*--move to past last "good" character---*/
 
2207
                                current_col ++;
 
2208
                        }
 
2209
                        if ( ! * lexed && current_token){
 
2210
                                * lexed = current_token;
 
2211
                        }
 
2212
                        if (skip_new_token && current_token) { 
 
2213
/*---------
 
2214
 *   last node points to a null (blank or white space token)
 
2215
 *-----------*/
 
2216
                                if (last_token){
 
2217
                                        last_token -> next = NULL;
 
2218
                                }else{
 
2219
                                        * lexed = NULL;
 
2220
                                }
 
2221
                                ValNodeFree(current_token);
 
2222
                        }
 
2223
        }
 
2224
        if ( line_use)
 
2225
                MemFree(line_use);
 
2226
 
 
2227
        return retval;
 
2228
}                                       
 
2229
 
 
2230
 
 
2231
/*------------- Nlm_gbparselex_ver() -----------------------*/
 
2232
 
 
2233
NLM_EXTERN int
 
2234
Nlm_gbparselex_ver(CharPtr linein, ValNodePtr PNTR lexed, Boolean accver)
 
2235
{       
 
2236
        CharPtr current_col=0, points_at_term_null,spare, line_use = NULL;
 
2237
        int dex;
 
2238
        int retval = 0, len;
 
2239
        ValNodePtr current_token = NULL, last_token = NULL;
 
2240
        Boolean skip_new_token=FALSE;
 
2241
        Boolean die_now=FALSE;
 
2242
        ValNode forerrmacro;
 
2243
 
 
2244
        forerrmacro.choice =GBPARSE_INT_ACCESION ;
 
2245
 
 
2246
        if (*linein     ){
 
2247
                len = StringLen(linein);
 
2248
                line_use = MemNew(len + 1);
 
2249
                StringCpy(line_use, linein);
 
2250
                if ( * lexed){
 
2251
                                Nlm_lex_error_MACRO( "Lex list not cleared on entry to Nlm_gbparselex_ver")
 
2252
                        ValNodeFree( * lexed);
 
2253
                        * lexed = NULL;
 
2254
                }
 
2255
                current_col = line_use ;
 
2256
                forerrmacro.data.ptrvalue = line_use;
 
2257
/*---------
 
2258
 *   Clear terminal white space
 
2259
 *---------*/
 
2260
                points_at_term_null = line_use + len;
 
2261
                spare = points_at_term_null - 1;
 
2262
                while (*spare == ' '  || *spare == '\n' || *spare == '\r' || *spare == '~') {
 
2263
                        *spare-- = '\0';
 
2264
                        points_at_term_null --;
 
2265
                }
 
2266
 
 
2267
 
 
2268
                while (current_col < points_at_term_null && ! die_now) {
 
2269
                        if ( ! skip_new_token){
 
2270
                                last_token = current_token;
 
2271
                                current_token = ValNodeNew(current_token);
 
2272
                                if ( ! * lexed)
 
2273
                                        * lexed = current_token;
 
2274
                        }
 
2275
                        switch ( *current_col){
 
2276
 
 
2277
                        case '\"':
 
2278
                                skip_new_token = FALSE;
 
2279
                                current_token -> choice = GBPARSE_INT_STRING;
 
2280
                                for (spare = current_col +1; spare < points_at_term_null; 
 
2281
                                                spare ++) {
 
2282
                                        if ( *spare == '\"'){
 
2283
                                                break;
 
2284
                                        }
 
2285
                                }
 
2286
                                if (spare >= points_at_term_null){
 
2287
                                                Nlm_lex_error_MACRO( "unterminated string")
 
2288
                                                retval ++;
 
2289
                                }else{
 
2290
                                        len = spare-current_col + 1;
 
2291
                                        current_token -> data.ptrvalue = 
 
2292
                                                MemNew(len +2);
 
2293
                                        StringNCpy(current_token -> data.ptrvalue,
 
2294
                                                current_col,len);
 
2295
                                        current_col += len;
 
2296
                                }
 
2297
                                        break;
 
2298
/*------
 
2299
 *  NUMBER
 
2300
 *------*/
 
2301
                        case '0': case '1': case '2': case '3': case '4':
 
2302
                        case '5': case '6': case '7': case '8': case '9':
 
2303
                                skip_new_token = FALSE;
 
2304
                                current_token -> choice = GBPARSE_INT_NUMBER;
 
2305
                                for (dex=0, spare = current_col; isdigit(*spare); spare ++){
 
2306
                                        dex ++ ;
 
2307
                                }
 
2308
                                current_token -> data.ptrvalue = MemNew(dex+1);
 
2309
                                StringNCpy(current_token -> data.ptrvalue, current_col, dex);
 
2310
                                current_col += dex -1;
 
2311
                                break;
 
2312
/*------
 
2313
 *  JOIN
 
2314
 *------*/
 
2315
                        case 'j':
 
2316
                                skip_new_token = FALSE;
 
2317
                                current_token -> choice = GBPARSE_INT_JOIN;
 
2318
                                if (StringNCmp(current_col,"join",(unsigned) 4)!=0){
 
2319
                                        Nlm_lex_error_MACRO( "\"join\" misspelled")
 
2320
                                        retval += 10;
 
2321
                                        for(;*current_col && *current_col != '('; current_col++)
 
2322
                                                ; /* vi match )   empty body*/ 
 
2323
                                        current_col -- ;  /* back up 'cause ++ follows */
 
2324
                                }else{
 
2325
                                        current_col += 3;
 
2326
                                }
 
2327
                                break;
 
2328
                        
 
2329
/*------
 
2330
 *  ORDER and ONE-OF
 
2331
 *------*/
 
2332
                        case 'o':
 
2333
                                skip_new_token = FALSE;
 
2334
                                if (StringNCmp(current_col,"order",(unsigned) 5)!=0){
 
2335
                                        if (StringNCmp(current_col,"one-of",(unsigned) 6)!=0){
 
2336
                                        Nlm_lex_error_MACRO( "\"order\" or \"one-of\" misspelled")
 
2337
                                                retval ++;
 
2338
                                                for(;*current_col && *current_col != '('; current_col++)
 
2339
                                                        ; /* vi match )   empty body*/ 
 
2340
                                                current_col -- ;  /* back up 'cause ++ follows */
 
2341
                                        }else{
 
2342
                                                current_token -> choice = GBPARSE_INT_ONE_OF ;
 
2343
                                                current_col += 5;
 
2344
                                        }
 
2345
                                }else{
 
2346
                                        current_token -> choice = GBPARSE_INT_ORDER;
 
2347
                                        current_col += 4;
 
2348
                                }
 
2349
                                break;
 
2350
 
 
2351
/*------
 
2352
 *  REPLACE
 
2353
 *------*/
 
2354
                        case 'r' :
 
2355
                                skip_new_token = FALSE;
 
2356
                                current_token -> choice = GBPARSE_INT_REPLACE ;
 
2357
                                if (StringNCmp(current_col,"replace",(unsigned) 6)!=0){
 
2358
                                        Nlm_lex_error_MACRO( "\"replace\" misspelled")
 
2359
                                        retval ++;
 
2360
                                        for(;*current_col && *current_col != '('; current_col++)
 
2361
                                                ; /* vi match )   empty body*/ 
 
2362
                                        current_col -- ;  /* back up 'cause ++ follows */
 
2363
                                }else{
 
2364
                                        current_col += 6;
 
2365
                                }
 
2366
                                break;
 
2367
                        
 
2368
/*------
 
2369
 *  GAP or GROUP or GI
 
2370
 *------*/
 
2371
                        case 'g':
 
2372
                                skip_new_token = FALSE;
 
2373
                                if(StringNCmp(current_col, "gap", 3) == 0 &&
 
2374
                                   (current_col[3] == '(' ||
 
2375
                                    current_col[3] == ' ' ||
 
2376
                                    current_col[3] == '\t' ||
 
2377
                                    current_col[3] == '\0'))
 
2378
                                {
 
2379
                                    current_token->choice = GBPARSE_INT_GAP;
 
2380
                                    current_col += 2;
 
2381
                                    current_token->data.ptrvalue = MemNew(4);
 
2382
                                    StringCpy(current_token->data.ptrvalue, "gap");
 
2383
                                    break;
 
2384
                                }
 
2385
                                if(StringNCmp(current_col, "gi|", 3) == 0) {
 
2386
                                    current_token->choice = GBPARSE_INT_ACCESION;
 
2387
                                    current_col += 3;
 
2388
                                        for (; IS_DIGIT(*current_col); current_col++) ;
 
2389
                                    break;
 
2390
                                }
 
2391
                                current_token -> choice = GBPARSE_INT_GROUP;
 
2392
                                if (StringNCmp(current_col,"group",(unsigned) 5)!=0){
 
2393
                                        Nlm_lex_error_MACRO("\"group\" misspelled")
 
2394
                                        retval ++;
 
2395
                                        for(;*current_col && *current_col != '('; current_col++)
 
2396
                                                ; /* vi match )   empty body*/ 
 
2397
                                        current_col -- ;  /* back up 'cause ++ follows */
 
2398
                                }else{
 
2399
                                        current_col += 4;
 
2400
                                }
 
2401
                                break;
 
2402
                        
 
2403
/*------
 
2404
 *  COMPLEMENT
 
2405
 *------*/
 
2406
                        case 'c':
 
2407
                                skip_new_token = FALSE;
 
2408
                                current_token -> choice = GBPARSE_INT_COMPL;
 
2409
                                if (StringNCmp(current_col,"complement",(unsigned) 10)!=0){
 
2410
                                        Nlm_lex_error_MACRO("\"complement\" misspelled")
 
2411
                                        retval += 10;
 
2412
                                        for(;*current_col && *current_col != '('; current_col++)
 
2413
                                                ; /* vi match )   empty body*/ 
 
2414
                                        current_col -- ;  /* back up 'cause ++ follows */
 
2415
                                }else{
 
2416
                                        current_col += 9;
 
2417
                                }
 
2418
                                break;
 
2419
 
 
2420
/*-------
 
2421
 * internal bases ignored
 
2422
 *---------*/
 
2423
                        case 'b':
 
2424
                        if (StringNCmp(current_col,"bases",(unsigned) 5)!=0){
 
2425
                                goto ACCESSION;
 
2426
                        }else{
 
2427
                                skip_new_token = TRUE;
 
2428
                                current_col += 4;
 
2429
                        }
 
2430
                                break;
 
2431
 
 
2432
/*------
 
2433
 *  ()^.,<>  (bases (sites
 
2434
 *------*/
 
2435
                        case '(':
 
2436
                                if (StringNCmp(current_col,"(base",(unsigned) 5)==0){
 
2437
                                        skip_new_token = FALSE;
 
2438
                                        current_token -> choice = GBPARSE_INT_JOIN;
 
2439
                                        current_col += 4;
 
2440
                                        if (*current_col != '\0')
 
2441
                                        if ( * (current_col +1) == 's')
 
2442
                                                current_col ++;
 
2443
                                        last_token = current_token;
 
2444
                                        current_token = ValNodeNew(current_token);
 
2445
                                        current_token -> choice = GBPARSE_INT_LEFT;
 
2446
                                }else if (StringNCmp(current_col,"(sites",(unsigned) 5)==0){
 
2447
                                        skip_new_token = FALSE;
 
2448
                                        current_col += 5;
 
2449
                                        if (*current_col != '\0')
 
2450
                                        if ( * (current_col +1) == ')'){
 
2451
                                                current_col ++;
 
2452
                                                current_token -> choice = GBPARSE_INT_SITES;
 
2453
                                        }else{
 
2454
                                                current_token -> choice = GBPARSE_INT_SITES;
 
2455
                                                last_token = current_token;
 
2456
                                                current_token = ValNodeNew(current_token);
 
2457
                                                current_token -> choice = GBPARSE_INT_JOIN;
 
2458
                                                last_token = current_token;
 
2459
                                                current_token = ValNodeNew(current_token);
 
2460
                                                current_token -> choice = GBPARSE_INT_LEFT;
 
2461
                                                if (*current_col != '\0'){
 
2462
                                                        if ( * (current_col +1) == ';'){
 
2463
                                                                current_col ++;
 
2464
                                                        }else if (StringNCmp(current_col +1," ;", (unsigned) 2) ==0){
 
2465
                                                                current_col += 2;
 
2466
                                                        }
 
2467
                                                }
 
2468
                                        }
 
2469
                                }else{
 
2470
                                        skip_new_token = FALSE;
 
2471
                                        current_token -> choice = GBPARSE_INT_LEFT;
 
2472
                                }
 
2473
                                break;
 
2474
 
 
2475
                        case ')':
 
2476
                                skip_new_token = FALSE;
 
2477
                                current_token -> choice = GBPARSE_INT_RIGHT;
 
2478
                        
 
2479
                                break;
 
2480
 
 
2481
                        case '^':
 
2482
                                skip_new_token = FALSE;
 
2483
                                current_token -> choice = GBPARSE_INT_CARET;
 
2484
                                break;
 
2485
 
 
2486
                        case '-':
 
2487
                                skip_new_token = FALSE;
 
2488
                                current_token -> choice = GBPARSE_INT_DOT_DOT ;
 
2489
                                break;
 
2490
                        case '.':
 
2491
                                skip_new_token = FALSE;
 
2492
                                if (StringNCmp(current_col,"..",(unsigned) 2)!=0){
 
2493
                                        current_token -> choice = GBPARSE_INT_SINGLE_DOT ;
 
2494
                                }else{
 
2495
                                        current_token -> choice = GBPARSE_INT_DOT_DOT;
 
2496
                                        current_col ++ ;
 
2497
                                }
 
2498
                                break;
 
2499
 
 
2500
                        case '>':
 
2501
                                skip_new_token = FALSE;
 
2502
                                current_token -> choice = GBPARSE_INT_GT;
 
2503
                                break;
 
2504
 
 
2505
                        case '<':
 
2506
                                skip_new_token = FALSE;
 
2507
                                current_token -> choice = GBPARSE_INT_LT;
 
2508
 
 
2509
                                break;
 
2510
 
 
2511
                        case ';':
 
2512
                        case ',':
 
2513
                                skip_new_token = FALSE;
 
2514
                                current_token -> choice = GBPARSE_INT_COMMA;
 
2515
                                break;
 
2516
 
 
2517
                        case ' ': case '\t': case '\n': case '\r': case '~':
 
2518
                                skip_new_token = TRUE;
 
2519
                                break;
 
2520
        
 
2521
                        case 't' :
 
2522
                        if (StringNCmp(current_col,"to",(unsigned) 2)!=0){
 
2523
                                goto ACCESSION;
 
2524
                        }else{
 
2525
                                skip_new_token = FALSE;
 
2526
                                current_token -> choice = GBPARSE_INT_DOT_DOT;
 
2527
                                current_col ++ ;
 
2528
                                break;
 
2529
                        }
 
2530
                                
 
2531
                        case 's' :
 
2532
                        if (StringNCmp(current_col,"site",(unsigned) 4)!=0){
 
2533
                                goto ACCESSION;
 
2534
                        }else{
 
2535
                                skip_new_token = FALSE;
 
2536
                                current_token -> choice = GBPARSE_INT_SITES;
 
2537
                                current_col += 3 ;
 
2538
                                if (*current_col != '\0')
 
2539
                                if ( * (current_col +1) == 's')
 
2540
                                        current_col ++;
 
2541
                                if (*current_col != '\0'){
 
2542
                                        if ( * (current_col +1) == ';'){
 
2543
                                                current_col ++;
 
2544
                                        }else if (StringNCmp(current_col +1," ;", (unsigned) 2) ==0){
 
2545
                                                current_col += 2;
 
2546
                                        }
 
2547
                                }
 
2548
                                break;
 
2549
                        }
 
2550
                                
 
2551
 
 
2552
 ACCESSION:
 
2553
                        default:
 
2554
        /*-------
 
2555
 * all GenBank accessions start with a capital letter
 
2556
 * and then have numbers
 
2557
        ------*/
 
2558
/* new accessions start with 2 capital letters !!  1997 */
 
2559
/* new accessions have .version !!  2/15/1999 */
 
2560
                                skip_new_token = FALSE;
 
2561
                                current_token -> choice = GBPARSE_INT_ACCESION;
 
2562
                                if (IS_ALPHA(*(current_col + 1))) {
 
2563
                                        spare = current_col + 2;
 
2564
                                        dex = 2;
 
2565
                                } else {
 
2566
                                        spare = current_col + 1;
 
2567
                                        dex = 1;
 
2568
                                }
 
2569
                                for (; isdigit(*spare); spare ++){
 
2570
                                        dex ++ ;
 
2571
                                }
 
2572
                                if (accver != FALSE && *spare == '.') {
 
2573
                                        dex ++ ;
 
2574
                                        for (spare++; isdigit(*spare); spare ++){
 
2575
                                                dex ++ ;
 
2576
                                        }
 
2577
                                }
 
2578
                                if (*spare != ':'){
 
2579
                                        Nlm_lex_error_MACRO( "ACCESSION missing \":\"" )
 
2580
                                        retval += 10;
 
2581
                                        current_col --;
 
2582
                                }
 
2583
                                current_token -> data.ptrvalue = MemNew(dex+1);
 
2584
                                StringNCpy(current_token -> data.ptrvalue, current_col, dex);
 
2585
                                current_col += dex ;
 
2586
 
 
2587
 
 
2588
                }
 
2589
        /*--move to past last "good" character---*/
 
2590
                                current_col ++;
 
2591
                        }
 
2592
                        if ( ! * lexed && current_token){
 
2593
                                * lexed = current_token;
 
2594
                        }
 
2595
                        if (skip_new_token && current_token) { 
 
2596
/*---------
 
2597
 *   last node points to a null (blank or white space token)
 
2598
 *-----------*/
 
2599
                                if (last_token){
 
2600
                                        last_token -> next = NULL;
 
2601
                                }else{
 
2602
                                        * lexed = NULL;
 
2603
                                }
 
2604
                                ValNodeFree(current_token);
 
2605
                        }
 
2606
        }
 
2607
        if ( line_use)
 
2608
                MemFree(line_use);
 
2609
 
 
2610
        return retval;
 
2611
}                                       
 
2612
 
 
2613
 
 
2614
/*---- non_white()----*/
 
2615
 
 
2616
NLM_EXTERN CharPtr
 
2617
Nlm_non_white(CharPtr ch)
 
2618
{
 
2619
   while (isspace(*++ch))if (! *ch) break;
 
2620
      ;
 
2621
   return ch;
 
2622
}
 
2623
 
 
2624
/*------ gbparse_lexfree()-------*/
 
2625
 
 
2626
NLM_EXTERN ValNodePtr
 
2627
Nlm_gbparse_lexfree(ValNodePtr anp)
 
2628
{
 
2629
        ValNodePtr next;
 
2630
 
 
2631
   while (anp != NULL)
 
2632
   {
 
2633
      next = anp->next;
 
2634
                        if ( anp -> choice == GBPARSE_INT_NUMBER || 
 
2635
                                        anp -> choice == GBPARSE_INT_ACCESION){
 
2636
                                MemFree(anp->data.ptrvalue);
 
2637
                        }
 
2638
                        MemFree(anp);
 
2639
      anp = next;
 
2640
   }
 
2641
 
 
2642
        return NULL;
 
2643
}