~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to api/findrepl.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
* RCS Modification History:
45
45
* -------------------------
46
46
* $Log: findrepl.c,v $
 
47
* Revision 6.21  2006/01/17 17:50:01  bollin
 
48
* allow FindReplaceInEntity to search for a string made up of whitespace, as
 
49
* long as whole_word is not specified
 
50
*
 
51
* Revision 6.20  2006/01/10 18:13:56  kans
 
52
* FindReplAligns does not have case for SAS_DISC, since visit function recursively presents these components separately
 
53
*
 
54
* Revision 6.19  2006/01/09 21:15:03  bollin
 
55
* allow punctuation to terminate a word in find replace
 
56
*
 
57
* Revision 6.18  2006/01/04 21:26:57  kans
 
58
* FSA hit does not need code from validator unstructured source test, cleaned up variable names
 
59
*
 
60
* Revision 6.17  2006/01/04 20:39:41  kans
 
61
* added FindStringsInEntity using finite state machine, general cleanup of code
 
62
*
 
63
* Revision 6.16  2005/12/29 21:42:06  kans
 
64
* only call callback if text was found or replaced
 
65
*
 
66
* Revision 6.15  2005/12/29 20:54:41  kans
 
67
* FindReplaceInEntity takes callback and userdata
 
68
*
47
69
* Revision 6.14  2005/09/21 14:39:09  bollin
48
70
* fixed bug in FindReplace where if the whole-word flag was specified but
49
71
* the substring was found in a not-whole-word context earlier in the string
83
105
* using NUM_SEQID, added TPA ids to arrays
84
106
*
85
107
* Revision 6.2  2000/11/03 20:36:00  kans
86
 
* FindReplaceInEntity replaces FindInEntity and FindInEntityX - complete redesign, no longer using AsnExpOptExplore because of the difficulty of replacing with a larger string (TF + JK)
 
108
* FindReplaceInEntity replaces FindInEntity and FindInEntityX - complete redesign,
 
109
* no longer using AsnExpOptExplore because of the difficulty of replacing with a
 
110
* larger string (TF + JK)
87
111
*
88
112
* Revision 6.1  1999/03/05 23:31:07  kans
89
113
* FindInEntityX was not initializing flen, replen
98
122
* added whole_word parameter to FindInEntity and FindInEntityX, and protected
99
123
* against multiple ObjMgrAlsoSelects on a single itemID
100
124
*
101
 
 * Revision 5.1  1996/09/06  20:20:41  kans
102
 
 * keeps going even if ObjMgrTypeFind returns NULL (e.g., on OBJ_BIOSEQ_SEG),
103
 
 * and adds a case_counts parameter for case sensitive/insensitive searches.
104
 
 *
105
 
 * Revision 5.0  1996/05/28  13:23:23  ostell
106
 
 * Set to revision 5.0
107
 
 *
108
 
 * Revision 1.7  1996/02/28  04:53:06  ostell
109
 
 * fix to prevernt recursion on substring replaces
110
 
 *
111
 
 * Revision 1.6  1996/02/26  20:24:05  kans
112
 
 * replace needs MemCopy instead of StringMove (JO), and set dirty flag
113
 
 *
114
 
 * Revision 1.5  1996/01/03  23:06:32  ostell
115
 
 * support for longer replaces, controlled updating
116
 
 *
117
 
 * Revision 1.3  1996/01/02  18:40:07  ostell
118
 
 * simplified code.
119
 
 *
120
 
 * Revision 1.2  1996/01/01  00:05:14  kans
121
 
 * replaced StringStr with StringISearch to ignore case
122
 
 *
123
 
 * Revision 1.1  1995/12/31  18:13:14  kans
124
 
 * Initial revision
125
 
 *
 
125
* Revision 5.1  1996/09/06  20:20:41  kans
 
126
* keeps going even if ObjMgrTypeFind returns NULL (e.g., on OBJ_BIOSEQ_SEG),
 
127
* and adds a case_counts parameter for case sensitive/insensitive searches.
 
128
*
 
129
* Revision 5.0  1996/05/28  13:23:23  ostell
 
130
* Set to revision 5.0
 
131
*
 
132
* Revision 1.7  1996/02/28  04:53:06  ostell
 
133
* fix to prevernt recursion on substring replaces
 
134
*
 
135
* Revision 1.6  1996/02/26  20:24:05  kans
 
136
* replace needs MemCopy instead of StringMove (JO), and set dirty flag
 
137
*
 
138
* Revision 1.5  1996/01/03  23:06:32  ostell
 
139
* support for longer replaces, controlled updating
 
140
*
 
141
* Revision 1.3  1996/01/02  18:40:07  ostell
 
142
* simplified code.
 
143
*
 
144
* Revision 1.2  1996/01/01  00:05:14  kans
 
145
* replaced StringStr with StringISearch to ignore case
 
146
*
 
147
* Revision 1.1  1995/12/31  18:13:14  kans
 
148
* Initial revision
 
149
*
126
150
* Revision 1.1.1.1  1995/10/19 18:42:10  sad
127
151
* Initial version
128
152
*
137
161
#include <subutil.h>
138
162
#include <findrepl.h>
139
163
 
140
 
/* internal structure passed to callbacks */
 
164
/* callback type for search/replace functions */
 
165
 
 
166
typedef void (*FindReplFunc) (CharPtr PNTR strp, Pointer fspdata);
 
167
 
 
168
/* internal data structure */
141
169
 
142
170
typedef struct findstruct {
143
 
  Uint2    entityID;
144
 
  CharPtr  find_string;
145
 
  CharPtr  replace_string;
146
 
  Boolean  case_counts;
147
 
  Boolean  whole_word;
148
 
  Boolean  do_replace;
149
 
  Boolean  select_item;
150
 
  Int2     send_update;
151
 
  Boolean  did_find;
152
 
  Boolean  did_replace;
153
 
  Boolean  dirty;
154
 
  Boolean  descFilter [SEQDESCR_MAX];
155
 
  Boolean  featFilter [FEATDEF_MAX];
156
 
  Boolean  seqidFilter [NUM_SEQID];
157
 
  int      d [256];
158
 
  size_t   subLen;
 
171
  Uint2         entityID;
 
172
  FindReplFunc  func;
 
173
  FindReplProc  callback;
 
174
  Pointer       userdata;
 
175
 
 
176
  CharPtr       find_string;
 
177
  CharPtr       replace_string;
 
178
  Boolean       case_counts;
 
179
  Boolean       whole_word;
 
180
  Int4          findLen;
 
181
  Int4          replaceLen;
 
182
 
 
183
  Boolean       select_item;
 
184
  Int2          send_update;
 
185
  Boolean       did_find;
 
186
  Boolean       did_replace;
 
187
  Boolean       dirty;
 
188
 
 
189
  Boolean       descFilter [SEQDESCR_MAX];
 
190
  Boolean       featFilter [FEATDEF_MAX];
 
191
  Boolean       seqidFilter [NUM_SEQID];
 
192
 
 
193
  int           d [256];
 
194
  TextFsaPtr    fsa;
159
195
} FindStruct, PNTR FindStructPtr;
160
196
 
161
 
#define PID_NOTSET 0
162
 
#define PID_DBTAG  1
163
 
#define PID_NAME   2
164
 
#define PID_ML     3
165
 
#define PID_STR    4
166
 
 
167
 
#define NAMESTD_LAST     0
168
 
#define NAMESTD_FIRST    1
169
 
#define NAMESTD_MIDDLE   2
170
 
#define NAMESTD_FULL     3
171
 
#define NAMESTD_INITIALS 4
172
 
#define NAMESTD_SUFFIX   5
173
 
#define NAMESTD_TITLE    6
174
 
 
175
 
#define AUTHLIST_STRUCTURED 1
176
 
#define AUTHLIST_ML         2
177
 
#define AUTHLIST_STRING     3
178
 
  
179
197
#define FINDREPL_BUFFER_MAX  1000000
180
198
 
 
199
/* BOYER-MOORE SEARCH FUNCTIONS */
 
200
 
181
201
/* StringSearch and StringISearch use the Boyer-Moore algorithm, as described
182
202
   in Niklaus Wirth, Algorithms and Data Structures, Prentice- Hall, Inc.,
183
203
   Englewood Cliffs, NJ., 1986, p. 69.  The original had an error, where
226
246
  return NULL;
227
247
}
228
248
 
229
 
/* passed subLen and d array to avoid repeated initialization of the Boyer-Moore
230
 
   displacement table */
 
249
/* passed subLen and d array to avoid repeated initialization
 
250
   of the Boyer-Moore displacement table */
231
251
 
232
252
static CharPtr SearchForString (
233
253
  CharPtr str,
251
271
  ptr = FindSubString (str, sub, case_counts, strLen, subLen, d);
252
272
  if (ptr == NULL) return NULL;
253
273
 
254
 
  if (whole_word) {
255
 
    while (keep_looking && ptr != NULL)
256
 
    {
257
 
      keep_looking = FALSE;
258
 
      if (ptr > str) {
259
 
        tmp = ptr - 1;
260
 
        if (! IS_WHITESP (*tmp))
261
 
        {
262
 
          keep_looking = TRUE;
263
 
        }
264
 
      }
265
 
      if (!keep_looking)
266
 
      {
267
 
        tmp = ptr + StringLen (sub);
268
 
        if (*tmp != '\0' && (! IS_WHITESP (*tmp)))
269
 
        {
270
 
          keep_looking = TRUE;
271
 
        }
272
 
      }
273
 
      if (keep_looking)
274
 
      {
275
 
        ptr = FindSubString (ptr + subLen, sub, case_counts, strLen, subLen, d);
276
 
      }
 
274
  if (! whole_word) return ptr;
 
275
 
 
276
  while (keep_looking && ptr != NULL) {
 
277
    keep_looking = FALSE;
 
278
    if (ptr > str) {
 
279
      tmp = ptr - 1;
 
280
      if (! IS_WHITESP (*tmp)) {
 
281
        keep_looking = TRUE;
 
282
      }
 
283
    }
 
284
    if (! keep_looking) {
 
285
      tmp = ptr + StringLen (sub);
 
286
      if (*tmp != '\0' && (! IS_WHITESP (*tmp)) && (! ispunct (*tmp))) {
 
287
        keep_looking = TRUE;
 
288
      }
 
289
    }
 
290
    if (keep_looking) {
 
291
      ptr = FindSubString (ptr + subLen, sub, case_counts, strLen, subLen, d);
277
292
    }
278
293
  }
279
294
 
280
295
  return ptr;
281
296
}
282
297
 
283
 
/*=======================================================================*/
284
 
/*                                                                       */
285
 
/* FindReplString () - Does a search and replace in a given string.      */
286
 
/*                                                                       */
287
 
/*    Main Parameters:                                                   */
288
 
/*                                                                       */
289
 
/*         strp : The string to operate on. Passed as a pointer to       */
290
 
/*                a string so that it can be replaced by the             */
291
 
/*                resulting string.                                      */
292
 
/*                                                                       */
293
 
/*         fsp->find_string : The substring that is being replaced       */
294
 
/*                            in strp.                                   */
295
 
/*                                                                       */
296
 
/*         fsp->replace_string : The substring that is replacing         */
297
 
/*                               find_string in strp.                    */
298
 
/*                                                                       */
299
 
/*=======================================================================*/
300
 
 
301
 
static Boolean FindReplString (
302
 
  CharPtr PNTR strp,
303
 
  FindStructPtr fsp
304
 
)
305
 
 
306
 
{
307
 
  Boolean wasChanged;
308
 
  Int4    replaceLen;
309
 
  Int4    findLen;
310
 
  Int4    searchLen;
311
 
  Int4    buffSize;
312
 
  CharPtr workingBuffer;
313
 
  CharPtr searchString;
314
 
  CharPtr substringPtr;
315
 
 
316
 
  if (strp == NULL || fsp == NULL) return FALSE;
317
 
 
318
 
  replaceLen = StringLen (fsp->replace_string);
319
 
  findLen    = StringLen (fsp->find_string);
320
 
  searchLen  = StringLen (*strp);
321
 
 
322
 
  searchString = *strp;
 
298
static void BoyerMooreFindString (
 
299
  CharPtr PNTR strp,
 
300
  Pointer userdata
 
301
)
 
302
 
 
303
{
 
304
  FindStructPtr  fsp;
 
305
  CharPtr        searchString;
 
306
 
 
307
  if (strp == NULL || userdata == NULL) return;
 
308
  fsp = (FindStructPtr) userdata;
 
309
 
 
310
  searchString = *strp;
 
311
  if (SearchForString (searchString, fsp->find_string, fsp->case_counts,
 
312
                       fsp->whole_word, fsp->findLen, fsp->d) != NULL) {
 
313
    fsp->did_find = TRUE;
 
314
  }
 
315
}
 
316
 
 
317
static void BoyerMooreReplaceString (
 
318
  CharPtr PNTR strp,
 
319
  Pointer userdata
 
320
)
 
321
 
 
322
{
 
323
  Int4           buffSize;
 
324
  FindStructPtr  fsp;
 
325
  Int4           searchLen;
 
326
  CharPtr        searchString;
 
327
  CharPtr        substringPtr;
 
328
  Boolean        wasChanged;
 
329
  CharPtr        workingBuffer;
 
330
 
 
331
  if (strp == NULL || userdata == NULL) return;
 
332
  fsp = (FindStructPtr) userdata;
 
333
 
 
334
  searchString = *strp;
 
335
  searchLen  = StringLen (searchString);
 
336
 
323
337
  wasChanged = FALSE;
324
338
 
325
 
  if (! fsp->do_replace) {
326
 
    if (SearchForString (searchString, fsp->find_string,
327
 
          fsp->case_counts, fsp->whole_word,
328
 
          findLen, fsp->d) != NULL) {
329
 
 
330
 
      fsp->did_find = TRUE;
331
 
    }
332
 
    return TRUE;
333
 
  }
334
 
 
335
339
  /*------------------------------------------------*/
336
340
  /* Make a guess of how big a working buffer we'll */
337
341
  /* need based on a worst case scenario.           */
347
351
  /*                                                */
348
352
  /*------------------------------------------------*/
349
353
 
350
 
  if (replaceLen > findLen)
351
 
    {
352
 
      buffSize = searchLen + ((searchLen/findLen) * (replaceLen - findLen));
353
 
      if (buffSize > FINDREPL_BUFFER_MAX)
 
354
  if (fsp->replaceLen > fsp->findLen) {
 
355
      buffSize = searchLen + ((searchLen/fsp->findLen) * (fsp->replaceLen - fsp->findLen));
 
356
      if (buffSize > FINDREPL_BUFFER_MAX) {
354
357
        buffSize = FINDREPL_BUFFER_MAX;
355
 
    }
356
 
  else
 
358
      }
 
359
  } else {
357
360
    buffSize = searchLen;
 
361
  }
358
362
 
359
363
  workingBuffer = (CharPtr) MemNew (buffSize + 2);
360
 
  if (workingBuffer == NULL)
361
 
    return FALSE;
 
364
  if (workingBuffer == NULL) return;
362
365
 
363
366
  workingBuffer[0] = '\0';
364
367
 
369
372
  /*----------------------------------------*/
370
373
 
371
374
  while ((substringPtr = SearchForString (searchString, fsp->find_string,
372
 
          fsp->case_counts, fsp->whole_word,
373
 
          findLen, fsp->d)) != NULL)
374
 
    {
375
 
      wasChanged = TRUE;
376
 
      substringPtr[0] = '\0';
377
 
 
378
 
      if (StringLen (workingBuffer) + StringLen (searchString) > buffSize)
379
 
        return FALSE;
380
 
 
381
 
      StringCat (workingBuffer, searchString);
382
 
      StringCat (workingBuffer, fsp->replace_string);
383
 
      substringPtr[0] = 'x';
384
 
      searchString = substringPtr + findLen;
385
 
    }
386
 
 
387
 
  if (searchString != NULL)
388
 
    StringCat (workingBuffer, searchString);
 
375
          fsp->case_counts, fsp->whole_word, fsp->findLen, fsp->d)) != NULL) {
 
376
    wasChanged = TRUE;
 
377
    substringPtr [0] = '\0';
 
378
 
 
379
    if (StringLen (workingBuffer) + StringLen (searchString) > buffSize) return;
 
380
 
 
381
    StringCat (workingBuffer, searchString);
 
382
    StringCat (workingBuffer, fsp->replace_string);
 
383
    substringPtr [0] = 'x';
 
384
    searchString = substringPtr + fsp->findLen;
 
385
  }
 
386
 
 
387
  if (searchString != NULL) {
 
388
    StringCat (workingBuffer, searchString);
 
389
  }
389
390
 
390
391
  /*-------------------------------------*/
391
392
  /* If any replacements were made, then */
392
393
  /* swap in the new string for the old. */
393
394
  /*-------------------------------------*/
394
395
 
395
 
  if (wasChanged)
396
 
    {
397
 
      MemFree (*strp);
398
 
      (*strp) = workingBuffer;
 
396
  if (wasChanged) {
 
397
    MemFree (*strp);
 
398
    (*strp) = workingBuffer;
399
399
 
400
 
      fsp->did_replace = TRUE;
401
 
      fsp->dirty = TRUE;
402
 
    }
403
 
  else
 
400
    fsp->did_replace = TRUE;
 
401
    fsp->dirty = TRUE;
 
402
  } else {
404
403
    MemFree (workingBuffer);
405
 
 
406
 
  /*---------------------*/
407
 
  /* Return successfully */
408
 
  /*---------------------*/
409
 
 
410
 
  return TRUE;
 
404
  }
 
405
}
 
406
 
 
407
/* FINITE-STATE AUTOMATON SEARCH FUNCTION */
 
408
 
 
409
static void FSAFindStrings (
 
410
  CharPtr PNTR strp,
 
411
  Pointer userdata
 
412
)
 
413
 
 
414
{
 
415
  Char           ch;
 
416
  FindStructPtr  fsp;
 
417
  CharPtr        ptr;
 
418
  CharPtr        searchString;
 
419
  Int2           state;
 
420
  ValNodePtr     matches;
 
421
 
 
422
  if (strp == NULL || userdata == NULL) return;
 
423
  fsp = (FindStructPtr) userdata;
 
424
 
 
425
  searchString = *strp;
 
426
  if (searchString == NULL) return;
 
427
 
 
428
  state = 0;
 
429
  ptr = searchString;
 
430
  ch = *ptr;
 
431
 
 
432
  while (ch != '\0') {
 
433
    matches = NULL;
 
434
    state = TextFsaNext (fsp->fsa, state, ch, &matches);
 
435
    if (matches != NULL) {
 
436
      fsp->did_find = TRUE;
 
437
      return;
 
438
    }
 
439
    ptr++;
 
440
    ch = *ptr;
 
441
  }
 
442
}
 
443
 
 
444
/* MASTER SEARCH FUNCTION CALLS DESIGNATED FUNC CALLBACK */
 
445
 
 
446
/*=======================================================================*/
 
447
/*                                                                       */
 
448
/* FindReplString () - Does a search and replace in a given string.      */
 
449
/*                                                                       */
 
450
/*    Main Parameters:                                                   */
 
451
/*                                                                       */
 
452
/*         strp : The string to operate on. Passed as a pointer to       */
 
453
/*                a string so that it can be replaced by the             */
 
454
/*                resulting string.                                      */
 
455
/*                                                                       */
 
456
/*         fsp->find_string : The substring that is being replaced       */
 
457
/*                            in strp.                                   */
 
458
/*                                                                       */
 
459
/*         fsp->replace_string : The substring that is replacing         */
 
460
/*                               find_string in strp.                    */
 
461
/*                                                                       */
 
462
/*=======================================================================*/
 
463
 
 
464
static void FindReplString (
 
465
  CharPtr PNTR strp,
 
466
  FindStructPtr fsp
 
467
)
 
468
 
 
469
{
 
470
  if (strp == NULL || fsp == NULL || fsp->func == NULL) return;
 
471
 
 
472
  fsp->func (strp, (Pointer) fsp);
411
473
}
412
474
 
413
475
/*=======================================================================*/
464
526
 
465
527
static void FindReplAffil (
466
528
  AffilPtr pAffil,
467
 
  FindStructPtr pFindStruct
 
529
  FindStructPtr fsp
468
530
)
469
531
 
470
532
{
471
 
  if (pAffil == NULL)
472
 
    return;
 
533
  if (pAffil == NULL) return;
473
534
 
474
535
  if (pAffil->choice == 1) {
475
 
    FindReplString (&(pAffil->affil)      , pFindStruct);
 
536
    FindReplString (&(pAffil->affil)      , fsp);
476
537
  } else {
477
 
    FindReplString (&(pAffil->affil)      , pFindStruct);
478
 
    FindReplString (&(pAffil->div)        , pFindStruct);
479
 
    FindReplString (&(pAffil->city)       , pFindStruct);
480
 
    FindReplString (&(pAffil->sub)        , pFindStruct);
481
 
    FindReplString (&(pAffil->country)    , pFindStruct);
482
 
    FindReplString (&(pAffil->street)     , pFindStruct);
483
 
    FindReplString (&(pAffil->email)      , pFindStruct);
484
 
    FindReplString (&(pAffil->fax)        , pFindStruct);
485
 
    FindReplString (&(pAffil->phone)      , pFindStruct);
486
 
    FindReplString (&(pAffil->postal_code), pFindStruct);
 
538
    FindReplString (&(pAffil->affil)      , fsp);
 
539
    FindReplString (&(pAffil->div)        , fsp);
 
540
    FindReplString (&(pAffil->city)       , fsp);
 
541
    FindReplString (&(pAffil->sub)        , fsp);
 
542
    FindReplString (&(pAffil->country)    , fsp);
 
543
    FindReplString (&(pAffil->street)     , fsp);
 
544
    FindReplString (&(pAffil->email)      , fsp);
 
545
    FindReplString (&(pAffil->fax)        , fsp);
 
546
    FindReplString (&(pAffil->phone)      , fsp);
 
547
    FindReplString (&(pAffil->postal_code), fsp);
487
548
  }
488
549
}
489
550
 
493
554
/*                                                                       */
494
555
/*=======================================================================*/
495
556
 
 
557
#define NAMESTD_LAST     0
 
558
#define NAMESTD_FIRST    1
 
559
#define NAMESTD_MIDDLE   2
 
560
#define NAMESTD_FULL     3
 
561
#define NAMESTD_INITIALS 4
 
562
#define NAMESTD_SUFFIX   5
 
563
#define NAMESTD_TITLE    6
 
564
 
 
565
#define PID_NOTSET 0
 
566
#define PID_DBTAG  1
 
567
#define PID_NAME   2
 
568
#define PID_ML     3
 
569
#define PID_STR    4
 
570
 
496
571
static void FindReplAuthor (
497
572
  AuthorPtr pAuthor,
498
 
  FindStructPtr pFindStruct
 
573
  FindStructPtr fsp
499
574
)
500
575
 
501
576
{
503
578
  CharPtr    pNameStr;
504
579
  ValNodePtr pDbxref;
505
580
 
506
 
  if (pAuthor == NULL)
507
 
    return;
 
581
  if (pAuthor == NULL) return;
508
582
 
509
 
  FindReplAffil (pAuthor->affil, pFindStruct);
 
583
  FindReplAffil (pAuthor->affil, fsp);
510
584
  
511
 
  switch (pAuthor->name->choice)
512
 
    {
 
585
  switch (pAuthor->name->choice) {
513
586
    case PID_NOTSET :
514
587
      break;
515
588
    case PID_DBTAG :
516
589
      pDbxref = pAuthor->name->data;
517
 
      FindReplDbxrefs (pDbxref, pFindStruct);
 
590
      FindReplDbxrefs (pDbxref, fsp);
518
591
      break;
519
592
    case PID_NAME :
520
593
      pNameStandard = pAuthor->name->data;
521
 
      if (pNameStandard != NULL)
522
 
      {
523
 
        FindReplString (&(pNameStandard->names [NAMESTD_LAST])    , pFindStruct);
524
 
        FindReplString (&(pNameStandard->names [NAMESTD_FIRST])   , pFindStruct);
525
 
        FindReplString (&(pNameStandard->names [NAMESTD_MIDDLE])  , pFindStruct);
526
 
        FindReplString (&(pNameStandard->names [NAMESTD_FULL])    , pFindStruct);
527
 
        FindReplString (&(pNameStandard->names [NAMESTD_INITIALS]), pFindStruct);
528
 
        FindReplString (&(pNameStandard->names [NAMESTD_SUFFIX])  , pFindStruct);
529
 
        FindReplString (&(pNameStandard->names [NAMESTD_TITLE])   , pFindStruct);
 
594
      if (pNameStandard != NULL) {
 
595
        FindReplString (&(pNameStandard->names [NAMESTD_LAST])    , fsp);
 
596
        FindReplString (&(pNameStandard->names [NAMESTD_FIRST])   , fsp);
 
597
        FindReplString (&(pNameStandard->names [NAMESTD_MIDDLE])  , fsp);
 
598
        FindReplString (&(pNameStandard->names [NAMESTD_FULL])    , fsp);
 
599
        FindReplString (&(pNameStandard->names [NAMESTD_INITIALS]), fsp);
 
600
        FindReplString (&(pNameStandard->names [NAMESTD_SUFFIX])  , fsp);
 
601
        FindReplString (&(pNameStandard->names [NAMESTD_TITLE])   , fsp);
530
602
      }
531
603
      break;
532
604
    case PID_ML :
533
605
    case PID_STR :
534
606
      pNameStr = pAuthor->name->data;
535
 
      FindReplString (&pNameStr, pFindStruct);
 
607
      FindReplString (&pNameStr, fsp);
536
608
      break;
537
609
    default:
538
610
      break;
545
617
/*                                                                       */
546
618
/*=======================================================================*/
547
619
 
 
620
#define AUTHLIST_STRUCTURED 1
 
621
#define AUTHLIST_ML         2
 
622
#define AUTHLIST_STRING     3
 
623
  
548
624
static void FindReplAuthlist (
549
625
  AuthListPtr alp,
550
626
  FindStructPtr fsp
555
631
  CharPtr    szAuthor;
556
632
  AuthorPtr  pAuthor;
557
633
 
558
 
  if (alp == NULL)
559
 
    return;
 
634
  if (alp == NULL) return;
560
635
 
561
636
  FindReplAffil (alp->affil, fsp);
562
637
  vnpNames = alp->names;
563
 
  while (vnpNames != NULL)
564
 
    {
565
 
      if (alp->choice == AUTHLIST_STRUCTURED)
566
 
      {
567
 
        pAuthor = (AuthorPtr) vnpNames->data.ptrvalue;
568
 
        if (pAuthor != NULL)
569
 
          FindReplAuthor (pAuthor, fsp);
570
 
      }
571
 
      else
572
 
      {
573
 
        szAuthor = (CharPtr) vnpNames->data.ptrvalue;
574
 
        if (szAuthor != NULL)
575
 
          {
576
 
            FindReplString (&szAuthor, fsp);
577
 
            vnpNames->data.ptrvalue = szAuthor;
578
 
          }
579
 
      }
580
 
      vnpNames = vnpNames->next;
 
638
  while (vnpNames != NULL) {
 
639
    if (alp->choice == AUTHLIST_STRUCTURED) {
 
640
      pAuthor = (AuthorPtr) vnpNames->data.ptrvalue;
 
641
      if (pAuthor != NULL) {
 
642
        FindReplAuthor (pAuthor, fsp);
 
643
      }
 
644
    } else {
 
645
      szAuthor = (CharPtr) vnpNames->data.ptrvalue;
 
646
      if (szAuthor != NULL) {
 
647
        FindReplString (&szAuthor, fsp);
 
648
        vnpNames->data.ptrvalue = szAuthor;
 
649
      }
581
650
    }
 
651
    vnpNames = vnpNames->next;
 
652
  }
582
653
}
583
654
 
584
655
/*=======================================================================*/
589
660
 
590
661
static void FindReplCitRetract (
591
662
  CitRetractPtr pCitRetract,
592
 
  FindStructPtr pFindStruct
 
663
  FindStructPtr fsp
593
664
)
594
665
 
595
666
{
596
 
  if (pCitRetract == NULL)
597
 
    return;
 
667
  if (pCitRetract == NULL) return;
598
668
 
599
 
  FindReplString (&(pCitRetract->exp), pFindStruct);
 
669
  FindReplString (&(pCitRetract->exp), fsp);
600
670
}
601
671
 
602
672
/*=======================================================================*/
607
677
 
608
678
static void FindReplImprint (
609
679
  ImprintPtr pImprint,
610
 
  FindStructPtr pFindStruct
 
680
  FindStructPtr fsp
611
681
)
612
682
 
613
683
{
614
 
 
615
 
  /*------------------*/
616
 
  /* Check parameters */
617
 
  /*------------------*/
618
 
 
619
 
  if (pImprint == NULL)
620
 
    return;
621
 
 
622
 
  /*-------------------------*/
623
 
  /* Do the find and replace */
624
 
  /*-------------------------*/
625
 
 
626
 
  FindReplString (&(pImprint->volume)   , pFindStruct);
627
 
  FindReplString (&(pImprint->issue)    , pFindStruct);
628
 
  FindReplString (&(pImprint->pages)    , pFindStruct);
629
 
  FindReplString (&(pImprint->section)  , pFindStruct);
630
 
  FindReplString (&(pImprint->part_sup) , pFindStruct);
631
 
  FindReplString (&(pImprint->language) , pFindStruct);
632
 
  FindReplString (&(pImprint->part_supi), pFindStruct);
633
 
 
634
 
  FindReplAffil (pImprint->pub, pFindStruct);
635
 
  FindReplCitRetract (pImprint->retract, pFindStruct);
 
684
  if (pImprint == NULL) return;
 
685
 
 
686
  FindReplString (&(pImprint->volume)   , fsp);
 
687
  FindReplString (&(pImprint->issue)    , fsp);
 
688
  FindReplString (&(pImprint->pages)    , fsp);
 
689
  FindReplString (&(pImprint->section)  , fsp);
 
690
  FindReplString (&(pImprint->part_sup) , fsp);
 
691
  FindReplString (&(pImprint->language) , fsp);
 
692
  FindReplString (&(pImprint->part_supi), fsp);
 
693
 
 
694
  FindReplAffil (pImprint->pub, fsp);
 
695
  FindReplCitRetract (pImprint->retract, fsp);
636
696
}
637
697
 
638
698
/*=======================================================================*/
643
703
 
644
704
static void FindReplCitBook (
645
705
  CitBookPtr pCitBook,
646
 
  FindStructPtr pFindStruct
 
706
  FindStructPtr fsp
647
707
)
648
708
 
649
709
{
650
710
  AffilPtr    afp;
651
 
  ValNodePtr  vnp;
652
711
  CharPtr     tmpStr;
 
712
  ValNodePtr  vnp;
653
713
 
654
714
  if (pCitBook == NULL) return;
655
715
 
656
 
  FindReplStringList (pCitBook->title, pFindStruct);
657
 
  FindReplImprint (pCitBook->imp, pFindStruct);
658
 
  FindReplAuthlist (pCitBook->authors, pFindStruct);
659
 
  FindReplStringList (pCitBook->title, pFindStruct);
660
 
  FindReplStringList (pCitBook->coll, pFindStruct);
 
716
  FindReplStringList (pCitBook->title, fsp);
 
717
  FindReplImprint (pCitBook->imp, fsp);
 
718
  FindReplAuthlist (pCitBook->authors, fsp);
 
719
  FindReplStringList (pCitBook->title, fsp);
 
720
  FindReplStringList (pCitBook->coll, fsp);
661
721
 
662
722
  if (pCitBook->othertype == 1) {
663
723
    for (vnp = (ValNodePtr) pCitBook->otherdata; vnp != NULL; vnp = vnp->next) {
664
724
      switch (vnp->choice) {
665
725
        case 1 :
666
 
          FindReplString ((CharPtr PNTR) &(vnp->data.ptrvalue), pFindStruct);
 
726
          FindReplString ((CharPtr PNTR) &(vnp->data.ptrvalue), fsp);
667
727
          break;
668
728
        case 3 :
669
729
          afp = (AffilPtr) vnp->data.ptrvalue;
670
 
          FindReplAffil (afp, pFindStruct);
 
730
          FindReplAffil (afp, fsp);
671
731
          break;
672
732
        default :
673
733
          break;
675
735
    }
676
736
  } else if (pCitBook->othertype == 2) {
677
737
    tmpStr = (CharPtr) pCitBook->otherdata;
678
 
    FindReplString (&tmpStr, pFindStruct);
 
738
    FindReplString (&tmpStr, fsp);
679
739
    pCitBook->otherdata = tmpStr;
680
740
  }
681
741
}
682
742
 
683
743
static void FindReplCitArt (
684
744
  CitArtPtr pCitArt,
685
 
  FindStructPtr pFindStruct
 
745
  FindStructPtr fsp
686
746
)
687
747
 
688
748
{
689
 
  CitJourPtr pCitJournal;
690
 
  CitBookPtr pCitBook;
691
 
 
692
 
  if (pCitArt == NULL)
693
 
    return;
694
 
 
695
 
  FindReplAuthlist (pCitArt->authors, pFindStruct);
 
749
  CitBookPtr  pCitBook;
 
750
  CitJourPtr  pCitJournal;
 
751
 
 
752
  if (pCitArt == NULL) return;
 
753
 
 
754
  FindReplAuthlist (pCitArt->authors, fsp);
696
755
  if (pCitArt->fromptr != NULL) {
697
756
    switch (pCitArt->from) {
698
757
    case 1 :
699
758
      pCitJournal = (CitJourPtr) pCitArt->fromptr;
700
 
      FindReplStringList (pCitArt->title, pFindStruct);
701
 
      FindReplImprint (pCitJournal->imp, pFindStruct);
 
759
      FindReplStringList (pCitArt->title, fsp);
 
760
      FindReplImprint (pCitJournal->imp, fsp);
702
761
      break;
703
762
    case 2 :
704
763
    case 3 :
705
764
      pCitBook = (CitBookPtr) pCitArt->fromptr;
706
 
      FindReplCitBook (pCitBook, pFindStruct);
 
765
      FindReplCitBook (pCitBook, fsp);
707
766
      break;
708
767
    default :
709
768
      break;
719
778
 
720
779
static void FindReplMedlineEntry (
721
780
  MedlineEntryPtr pMedlineEntry,
722
 
  FindStructPtr pFindStruct
 
781
  FindStructPtr fsp
723
782
)
724
783
 
725
784
{
728
787
  MedlineRnPtr    pRn;
729
788
  CharPtr         tmpStr;
730
789
 
731
 
  if (pMedlineEntry == NULL)
732
 
    return;
 
790
  if (pMedlineEntry == NULL) return;
733
791
 
734
 
  FindReplCitArt(pMedlineEntry->cit, pFindStruct);
735
 
  FindReplString (&(pMedlineEntry->abstract), pFindStruct);
 
792
  FindReplCitArt(pMedlineEntry->cit, fsp);
 
793
  FindReplString (&(pMedlineEntry->abstract), fsp);
736
794
 
737
795
  pRn = pMedlineEntry->substance;
738
 
  while (pRn != NULL)
739
 
    {
740
 
      FindReplString (&(pRn->cit), pFindStruct);
741
 
      FindReplString (&(pRn->name), pFindStruct);
742
 
      pRn = pRn->next;
743
 
    }
 
796
  while (pRn != NULL) {
 
797
    FindReplString (&(pRn->cit), fsp);
 
798
    FindReplString (&(pRn->name), fsp);
 
799
    pRn = pRn->next;
 
800
  }
744
801
 
745
802
  pMesh = pMedlineEntry->mesh;
746
 
  while (pMesh != NULL)
747
 
    {
748
 
      FindReplString (&(pMesh->term), pFindStruct);
749
 
      pMesh = pMesh->next;
750
 
    }
751
 
 
752
 
  if (pMedlineEntry->xref != NULL)
753
 
    {
754
 
      tmpStr = (CharPtr) pMedlineEntry->xref->data.ptrvalue;
755
 
      FindReplString (&tmpStr, pFindStruct);
756
 
      pMedlineEntry->xref->data.ptrvalue = tmpStr;
757
 
    }
758
 
 
759
 
  if (pMedlineEntry->idnum != NULL)
760
 
    {
761
 
      tmpStr = (CharPtr) pMedlineEntry->idnum->data.ptrvalue;
762
 
      FindReplString (&tmpStr, pFindStruct);
763
 
      pMedlineEntry->idnum->data.ptrvalue = tmpStr;
764
 
    }
765
 
 
766
 
  if (pMedlineEntry->pub_type != NULL)
767
 
    {
768
 
      tmpStr = (CharPtr) pMedlineEntry->pub_type->data.ptrvalue;
769
 
      FindReplString (&tmpStr, pFindStruct);
770
 
      pMedlineEntry->pub_type->data.ptrvalue = tmpStr;
771
 
    }
772
 
 
773
 
  if (pMedlineEntry->gene != NULL)
774
 
    {
775
 
      tmpStr = (CharPtr) pMedlineEntry->gene->data.ptrvalue;
776
 
      FindReplString (&tmpStr, pFindStruct);
777
 
      pMedlineEntry->gene->data.ptrvalue = tmpStr;
778
 
    }
 
803
  while (pMesh != NULL) {
 
804
    FindReplString (&(pMesh->term), fsp);
 
805
    pMesh = pMesh->next;
 
806
  }
 
807
 
 
808
  if (pMedlineEntry->xref != NULL) {
 
809
    tmpStr = (CharPtr) pMedlineEntry->xref->data.ptrvalue;
 
810
    FindReplString (&tmpStr, fsp);
 
811
    pMedlineEntry->xref->data.ptrvalue = tmpStr;
 
812
  }
 
813
 
 
814
  if (pMedlineEntry->idnum != NULL) {
 
815
    tmpStr = (CharPtr) pMedlineEntry->idnum->data.ptrvalue;
 
816
    FindReplString (&tmpStr, fsp);
 
817
    pMedlineEntry->idnum->data.ptrvalue = tmpStr;
 
818
  }
 
819
 
 
820
  if (pMedlineEntry->pub_type != NULL) {
 
821
    tmpStr = (CharPtr) pMedlineEntry->pub_type->data.ptrvalue;
 
822
    FindReplString (&tmpStr, fsp);
 
823
    pMedlineEntry->pub_type->data.ptrvalue = tmpStr;
 
824
  }
 
825
 
 
826
  if (pMedlineEntry->gene != NULL) {
 
827
    tmpStr = (CharPtr) pMedlineEntry->gene->data.ptrvalue;
 
828
    FindReplString (&tmpStr, fsp);
 
829
    pMedlineEntry->gene->data.ptrvalue = tmpStr;
 
830
  }
779
831
 
780
832
  pField = pMedlineEntry->mlfield;
781
 
  while (pField != NULL)
782
 
    {
783
 
      FindReplString (&(pField->str), pFindStruct);
784
 
      pField = pField->next;
785
 
    }
 
833
  while (pField != NULL) {
 
834
    FindReplString (&(pField->str), fsp);
 
835
    pField = pField->next;
 
836
  }
786
837
}
787
838
 
788
839
/*=======================================================================*/
822
873
  }
823
874
  if (vnp->data.ptrvalue == NULL) return;
824
875
 
825
 
  switch (vnp->choice)
826
 
    {
 
876
  switch (vnp->choice) {
827
877
    case PUB_Gen :
828
878
      cgp = (CitGenPtr) vnp->data.ptrvalue;
829
879
      FindReplAuthlist (cgp->authors, fsp);
832
882
      FindReplString (&(cgp->issue), fsp);
833
883
      FindReplString (&(cgp->pages), fsp);
834
884
      FindReplString (&(cgp->title), fsp);
835
 
      if (cgp->journal != NULL)
836
 
      {
 
885
      if (cgp->journal != NULL) {
837
886
        tmpStr = (CharPtr) cgp->journal->data.ptrvalue;
838
887
        FindReplString (&tmpStr, fsp);
839
888
        cgp->journal->data.ptrvalue = tmpStr;
854
903
      break;
855
904
    case PUB_Journal :
856
905
      cjp = (CitJourPtr) vnp->data.ptrvalue;
857
 
      if (cjp->title != NULL)
858
 
      {
 
906
      if (cjp->title != NULL) {
859
907
        tmpStr = (CharPtr) cjp->title->data.ptrvalue;
860
908
        FindReplString (&tmpStr, fsp);
861
909
        cjp->title->data.ptrvalue = tmpStr;
869
917
    case PUB_Proc :
870
918
      cbp = (CitBookPtr) vnp->data.ptrvalue;
871
919
      cpvnp = cbp->otherdata;
872
 
      while (cpvnp != NULL)
873
 
      {
874
 
        if (cpvnp->choice == 1)
875
 
          {
876
 
            tmpStr = (CharPtr) cpvnp->data.ptrvalue;
877
 
            FindReplString (&tmpStr, fsp);
878
 
            cpvnp->data.ptrvalue = tmpStr;
879
 
          }
880
 
        else if (cpvnp->choice == 3)
 
920
      while (cpvnp != NULL) {
 
921
        if (cpvnp->choice == 1) {
 
922
          tmpStr = (CharPtr) cpvnp->data.ptrvalue;
 
923
          FindReplString (&tmpStr, fsp);
 
924
          cpvnp->data.ptrvalue = tmpStr;
 
925
        } else if (cpvnp->choice == 3) {
881
926
          FindReplAffil((AffilPtr) cpvnp->data.ptrvalue, fsp);
 
927
        }
882
928
        cpvnp = cpvnp->next;
883
929
      }
884
930
      break;
1021
1067
 
1022
1068
static void FindReplPatentSeqId (
1023
1069
  PatentSeqIdPtr pPatentSeqId,
1024
 
  FindStructPtr pFindStruct
 
1070
  FindStructPtr fsp
1025
1071
)
1026
1072
 
1027
1073
{
1028
 
  if (pPatentSeqId == NULL)
1029
 
    return;
1030
 
 
1031
 
  if (pPatentSeqId->cit == NULL)
1032
 
    return;
1033
 
 
1034
 
  FindReplString (&(pPatentSeqId->cit->country), pFindStruct);
1035
 
  FindReplString (&(pPatentSeqId->cit->number), pFindStruct);
1036
 
  FindReplString (&(pPatentSeqId->cit->app_number), pFindStruct);
1037
 
  FindReplString (&(pPatentSeqId->cit->doc_type), pFindStruct);
 
1074
  if (pPatentSeqId == NULL) return;
 
1075
  if (pPatentSeqId->cit == NULL) return;
 
1076
 
 
1077
  FindReplString (&(pPatentSeqId->cit->country), fsp);
 
1078
  FindReplString (&(pPatentSeqId->cit->number), fsp);
 
1079
  FindReplString (&(pPatentSeqId->cit->app_number), fsp);
 
1080
  FindReplString (&(pPatentSeqId->cit->doc_type), fsp);
1038
1081
}
1039
1082
 
1040
1083
/*=======================================================================*/
1045
1088
 
1046
1089
static void FindReplTextSeqId (
1047
1090
  TextSeqIdPtr pTextSeqId, 
1048
 
  FindStructPtr pFindStruct
 
1091
  FindStructPtr fsp
1049
1092
)
1050
1093
 
1051
1094
{
1052
 
  if (pTextSeqId == NULL)
1053
 
    return;
 
1095
  if (pTextSeqId == NULL) return;
1054
1096
 
1055
 
  FindReplString (&(pTextSeqId->name), pFindStruct);
1056
 
  FindReplString (&(pTextSeqId->accession), pFindStruct);
1057
 
  FindReplString (&(pTextSeqId->release), pFindStruct);
 
1097
  FindReplString (&(pTextSeqId->name), fsp);
 
1098
  FindReplString (&(pTextSeqId->accession), fsp);
 
1099
  FindReplString (&(pTextSeqId->release), fsp);
1058
1100
1059
1101
 
1060
1102
/*=======================================================================*/
1065
1107
 
1066
1108
static void FindReplGiim (
1067
1109
  GiimPtr pGiim, 
1068
 
  FindStructPtr pFindStruct
 
1110
  FindStructPtr fsp
1069
1111
)
1070
1112
 
1071
1113
{
1072
 
  if (pGiim == NULL)
1073
 
    return;
 
1114
  if (pGiim == NULL) return;
1074
1115
 
1075
 
  FindReplString (&(pGiim->db), pFindStruct);
1076
 
  FindReplString (&(pGiim->release), pFindStruct);
 
1116
  FindReplString (&(pGiim->db), fsp);
 
1117
  FindReplString (&(pGiim->release), fsp);
1077
1118
1078
1119
 
1079
1120
/*=======================================================================*/
1084
1125
 
1085
1126
static void FindReplPDBSeqId (
1086
1127
  PDBSeqIdPtr pPDBSeqId, 
1087
 
  FindStructPtr pFindStruct
 
1128
  FindStructPtr fsp
1088
1129
)
1089
1130
 
1090
1131
{
1091
 
  if (pPDBSeqId == NULL)
1092
 
    return;
 
1132
  if (pPDBSeqId == NULL) return;
1093
1133
 
1094
 
  FindReplString (&(pPDBSeqId->mol), pFindStruct);
 
1134
  FindReplString (&(pPDBSeqId->mol), fsp);
1095
1135
}
1096
1136
 
1097
1137
/*=======================================================================*/
1102
1142
 
1103
1143
static void FindReplObjectId (
1104
1144
  ObjectIdPtr pObjectId, 
1105
 
  FindStructPtr pFindStruct
 
1145
  FindStructPtr fsp
1106
1146
)
1107
1147
 
1108
1148
{
1109
 
  if (pObjectId == NULL)
1110
 
    return;
 
1149
  if (pObjectId == NULL) return;
1111
1150
 
1112
 
  FindReplString (&(pObjectId->str), pFindStruct);
 
1151
  FindReplString (&(pObjectId->str), fsp);
1113
1152
}
1114
1153
 
1115
1154
/*=======================================================================*/
1127
1166
  FindStructPtr  fsp;
1128
1167
  Uint1          subtype;
1129
1168
 
1130
 
  /*------------------*/
1131
 
  /* Check parameters */
1132
 
  /*------------------*/
1133
 
 
1134
 
  if (sip == NULL)
1135
 
    return;
1136
 
 
 
1169
  if (sip == NULL) return;
1137
1170
  fsp = (FindStructPtr) userdata;
1138
 
  if (fsp == NULL)
1139
 
    return;
1140
1171
 
1141
 
  /*-----------------------------------*/
1142
 
  /* Check to see if we're supposed to */
1143
 
  /* process this subtype or not.      */
1144
 
  /*-----------------------------------*/
 
1172
  /* check subtype against filter */
1145
1173
 
1146
1174
  subtype = sip->choice;
1147
 
  if (subtype >= NUM_SEQID)
1148
 
    return;
1149
 
  if (! fsp->seqidFilter [subtype])
1150
 
    return;
1151
 
 
1152
 
  /*------------------------------*/
1153
 
  /* Do search/replace on all the */
1154
 
  /* different SeqId types.       */
1155
 
  /*------------------------------*/
1156
 
 
1157
 
  switch (subtype)
1158
 
    {
 
1175
  if (subtype >= NUM_SEQID) return;
 
1176
  if (! fsp->seqidFilter [subtype]) return;
 
1177
 
 
1178
  switch (subtype) {
1159
1179
    case SEQID_NOT_SET :
1160
1180
      break;
1161
1181
    case SEQID_LOCAL :
1216
1236
  if (fsp->select_item && (fsp->did_find || fsp->did_replace)) {
1217
1237
    ObjMgrAlsoSelect (fsp->entityID, itemID, itemtype, 0, NULL);
1218
1238
  }
 
1239
  if (fsp->callback != NULL && (fsp->did_find || fsp->did_replace)) {
 
1240
    fsp->callback (fsp->entityID, itemID, itemtype, fsp->userdata);
 
1241
  }
1219
1242
}
1220
1243
 
1221
1244
/*=======================================================================*/
1233
1256
  FindStructPtr  fsp;
1234
1257
  SeqIdPtr       sip;
1235
1258
 
 
1259
  if (bsp == NULL) return;
 
1260
 
1236
1261
  fsp = (FindStructPtr) userdata;
1237
1262
  fsp->did_find = FALSE;
1238
1263
  fsp->did_replace = FALSE;
1241
1266
    FindReplSeqId (sip, userdata);
1242
1267
  }
1243
1268
 
1244
 
  SeqMgrReplaceInBioseqIndex(bsp);
 
1269
  if (fsp->did_replace) {
 
1270
    SeqMgrReplaceInBioseqIndex (bsp);
 
1271
  }
1245
1272
 
1246
1273
  FindReplSendMessages (fsp, bsp->idx.itemID, bsp->idx.itemtype);
1247
1274
}
1265
1292
  SeqLocPtr      slp;
1266
1293
  StdSegPtr      ssp;
1267
1294
 
 
1295
  if (sap == NULL) return;
 
1296
 
1268
1297
  fsp = (FindStructPtr) userdata;
1269
1298
  fsp->did_find = FALSE;
1270
1299
  fsp->did_replace = FALSE;
1274
1303
 
1275
1304
  if (sap->segs == NULL) return;
1276
1305
 
 
1306
  /* SAS_DISC recursively presented by visit function, so removed here */
 
1307
 
1277
1308
  switch (sap->segtype) {
1278
1309
    case SAS_DENDIAG :
1279
1310
      ddp = (DenseDiagPtr) sap->segs;
1297
1328
        }
1298
1329
      }
1299
1330
      break;
1300
 
    case SAS_DISC :
1301
 
      /* recursive */
1302
 
      for (sap = (SeqAlignPtr) sap->segs; sap != NULL; sap = sap->next) {
1303
 
        FindReplAligns (sap, userdata);
1304
 
      }
1305
 
      break;
1306
1331
    default :
1307
1332
      break;
1308
1333
  }
1324
1349
{
1325
1350
  FindStructPtr  fsp;
1326
1351
 
 
1352
  if (sgp == NULL) return;
 
1353
 
1327
1354
  fsp = (FindStructPtr) userdata;
1328
1355
  fsp->did_find = FALSE;
1329
1356
  fsp->did_replace = FALSE;
1359
1386
  Uint1          subtype;
1360
1387
  tRNAPtr        trp;
1361
1388
 
 
1389
  if (sfp == NULL) return;
 
1390
 
1362
1391
  fsp = (FindStructPtr) userdata;
1363
1392
  fsp->did_find = FALSE;
1364
1393
  fsp->did_replace = FALSE;
1498
1527
  PubdescPtr     pdp;
1499
1528
  Uint1          subtype;
1500
1529
 
 
1530
  if (sdp == NULL) return;
 
1531
 
1501
1532
  fsp = (FindStructPtr) userdata;
1502
1533
  fsp->did_find = FALSE;
1503
1534
  fsp->did_replace = FALSE;
1613
1644
  if (ssp == NULL) return;
1614
1645
  sub = ssp->sub;
1615
1646
  if (sub == NULL) return;
 
1647
 
1616
1648
  fsp->did_find = FALSE;
1617
1649
  fsp->did_replace = FALSE;
1618
1650
 
1644
1676
  FindReplSendMessages (fsp, ssp->idx.itemID, ssp->idx.itemtype);
1645
1677
}
1646
1678
 
 
1679
/* EXTERNAL FIND-REPLACE FUNCTIONS */
 
1680
 
1647
1681
/*=======================================================================*/
1648
1682
/*                                                                       */
1649
1683
/*  FindReplaceInEntity() - New find/replace function.                   */
1662
1696
  BoolPtr descFilter,
1663
1697
  BoolPtr featFilter,
1664
1698
  BoolPtr seqidFilter,
1665
 
  Boolean do_seqid_local
 
1699
  Boolean do_seqid_local,
 
1700
  FindReplProc callback,
 
1701
  Pointer userdata
1666
1702
)
1667
1703
 
1668
1704
{
1672
1708
  ObjMgrDataPtr  omdp;
1673
1709
  SeqEntryPtr    sep = NULL;
1674
1710
  SeqSubmitPtr   ssp = NULL;
 
1711
  size_t         subLen;
1675
1712
 
1676
 
  if (entityID == 0 || StringHasNoText (find_string)) return;
 
1713
  if (entityID == 0 || find_string == NULL 
 
1714
      || (whole_word && StringHasNoText (find_string))) return;
1677
1715
 
1678
1716
  omdp = ObjMgrGetData (entityID);
1679
1717
  if (omdp != NULL) {
1698
1736
  MemSet ((Pointer) &fs, 0, sizeof (FindStruct));
1699
1737
 
1700
1738
  fs.entityID = entityID;
 
1739
  if (do_replace) {
 
1740
    fs.func = BoyerMooreReplaceString;
 
1741
  } else {
 
1742
    fs.func = BoyerMooreFindString;
 
1743
  }
 
1744
  fs.callback = callback;
 
1745
  fs.userdata = userdata;
 
1746
 
1701
1747
  fs.find_string = find_string;
1702
1748
  fs.replace_string = replace_string;
1703
1749
  fs.case_counts = case_counts;
1704
1750
  fs.whole_word = whole_word;
1705
 
  fs.do_replace = do_replace;
 
1751
  fs.findLen = StringLen (find_string);
 
1752
  fs.replaceLen = StringLen (replace_string);
 
1753
 
1706
1754
  fs.select_item = select_item;
1707
1755
  fs.send_update = send_update;
1708
 
 
1709
1756
  fs.did_find = FALSE;
1710
1757
  fs.did_replace = FALSE;
1711
1758
  fs.dirty = FALSE;
1712
1759
 
1713
1760
  /* build Boyer-Moore displacement array in advance */
1714
1761
 
1715
 
  fs.subLen = StringLen (find_string);
 
1762
  subLen = StringLen (find_string);
1716
1763
 
1717
1764
  for (ch = 0; ch < 256; ch++) {
1718
 
    fs.d [ch] = fs.subLen;
 
1765
    fs.d [ch] = subLen;
1719
1766
  }
1720
 
  for (j = 0; j < (int) (fs.subLen - 1); j++) {
 
1767
  for (j = 0; j < (int) (subLen - 1); j++) {
1721
1768
    ch = (int) (case_counts ? find_string [j] : TO_UPPER (find_string [j]));
1722
1769
    if (ch >= 0 && ch <= 255) {
1723
 
      fs.d [ch] = fs.subLen - j - 1;
1724
 
    }
1725
 
  }
1726
 
 
1727
 
  /* if desc or feat filter arrays not supplied, default to all TRUE */
1728
 
 
1729
 
  if (descFilter != NULL) {
1730
 
    MemCopy ((Pointer) &fs.descFilter, (Pointer) descFilter, sizeof (fs.descFilter));
1731
 
  } else {
1732
 
    MemSet ((Pointer) &fs.descFilter, (int) TRUE, sizeof (fs.descFilter));
1733
 
  }
1734
 
 
1735
 
  if (featFilter != NULL) {
1736
 
    MemCopy ((Pointer) &fs.featFilter, (Pointer) featFilter, sizeof (fs.featFilter));
1737
 
  } else {
1738
 
    MemSet ((Pointer) &fs.featFilter, (int) TRUE, sizeof (fs.featFilter));
1739
 
  }
1740
 
 
1741
 
  /* if seqid filter array not supplied, default to all FALSE */
1742
 
 
1743
 
  if (seqidFilter != NULL) {
1744
 
    MemCopy ((Pointer) &fs.seqidFilter, (Pointer) seqidFilter, sizeof (fs.seqidFilter));
1745
 
  } else if (do_seqid_local) {
1746
 
    MemSet ((Pointer) &fs.seqidFilter, (int) FALSE, sizeof (fs.seqidFilter));
1747
 
    fs.seqidFilter [SEQID_LOCAL] = TRUE;
1748
 
  } else {
1749
 
    MemSet ((Pointer) &fs.seqidFilter, (int) FALSE, sizeof (fs.seqidFilter));
1750
 
  }
1751
 
 
1752
 
  /* ensure feature subtype is set in sfp->idx block */
1753
 
 
1754
 
  AssignIDsInEntity (entityID, 0, NULL);
1755
 
 
1756
 
  /* visit callbacks that find/replace specific fields */
1757
 
 
1758
 
  VisitBioseqsInSep (sep, (Pointer) &fs, FindReplBioseqs);
1759
 
 
1760
 
  VisitFeaturesInSep (sep, (Pointer) &fs, FindReplFeats);
1761
 
 
1762
 
  VisitAlignmentsInSep (sep, (Pointer) &fs, FindReplAligns);
1763
 
 
1764
 
  VisitGraphsInSep (sep, (Pointer) &fs, FindReplGraphs);
1765
 
 
1766
 
  VisitDescriptorsInSep (sep, (Pointer) &fs, FindReplDescs);
1767
 
 
1768
 
  if (ssp != NULL) {
1769
 
    FindReplSubmitBlock (ssp, &fs);
1770
 
  }
 
1770
      fs.d [ch] = subLen - j - 1;
 
1771
    }
 
1772
  }
 
1773
 
 
1774
  /* if desc or feat filter arrays not supplied, default to all TRUE */
 
1775
 
 
1776
  if (descFilter != NULL) {
 
1777
    MemCopy ((Pointer) &fs.descFilter, (Pointer) descFilter, sizeof (fs.descFilter));
 
1778
  } else {
 
1779
    MemSet ((Pointer) &fs.descFilter, (int) TRUE, sizeof (fs.descFilter));
 
1780
  }
 
1781
 
 
1782
  if (featFilter != NULL) {
 
1783
    MemCopy ((Pointer) &fs.featFilter, (Pointer) featFilter, sizeof (fs.featFilter));
 
1784
  } else {
 
1785
    MemSet ((Pointer) &fs.featFilter, (int) TRUE, sizeof (fs.featFilter));
 
1786
  }
 
1787
 
 
1788
  /* if seqid filter array not supplied, default to all FALSE */
 
1789
 
 
1790
  if (seqidFilter != NULL) {
 
1791
    MemCopy ((Pointer) &fs.seqidFilter, (Pointer) seqidFilter, sizeof (fs.seqidFilter));
 
1792
  } else if (do_seqid_local) {
 
1793
    MemSet ((Pointer) &fs.seqidFilter, (int) FALSE, sizeof (fs.seqidFilter));
 
1794
    fs.seqidFilter [SEQID_LOCAL] = TRUE;
 
1795
  } else {
 
1796
    MemSet ((Pointer) &fs.seqidFilter, (int) FALSE, sizeof (fs.seqidFilter));
 
1797
  }
 
1798
 
 
1799
  /* ensure feature subtype is set in sfp->idx block */
 
1800
 
 
1801
  AssignIDsInEntity (entityID, 0, NULL);
 
1802
 
 
1803
  /* visit callbacks that find/replace specific fields */
 
1804
 
 
1805
  VisitBioseqsInSep (sep, (Pointer) &fs, FindReplBioseqs);
 
1806
 
 
1807
  VisitFeaturesInSep (sep, (Pointer) &fs, FindReplFeats);
 
1808
 
 
1809
  VisitAlignmentsInSep (sep, (Pointer) &fs, FindReplAligns);
 
1810
 
 
1811
  VisitGraphsInSep (sep, (Pointer) &fs, FindReplGraphs);
 
1812
 
 
1813
  VisitDescriptorsInSep (sep, (Pointer) &fs, FindReplDescs);
 
1814
 
 
1815
  if (ssp != NULL) {
 
1816
    FindReplSubmitBlock (ssp, &fs);
 
1817
  }
 
1818
 
 
1819
  /* send select message, if applicable */
 
1820
 
 
1821
  if (fs.send_update == UPDATE_ONCE && fs.dirty) {
 
1822
    ObjMgrSetDirtyFlag (entityID, TRUE);
 
1823
    ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
 
1824
  }
 
1825
}
 
1826
 
 
1827
/*=======================================================================*/
 
1828
/*                                                                       */
 
1829
/*  FindStringsInEntity() - Multi-string find function.                  */
 
1830
/*                                                                       */
 
1831
/*=======================================================================*/
 
1832
 
 
1833
NLM_EXTERN void FindStringsInEntity (
 
1834
  Uint2 entityID,
 
1835
  CharPtr PNTR find_strings,
 
1836
  Boolean case_counts,
 
1837
  Boolean whole_word,
 
1838
  Boolean select_item,
 
1839
  Int2 send_update,
 
1840
  BoolPtr descFilter,
 
1841
  BoolPtr featFilter,
 
1842
  BoolPtr seqidFilter,
 
1843
  Boolean do_seqid_local,
 
1844
  FindReplProc callback,
 
1845
  Pointer userdata
 
1846
)
 
1847
 
 
1848
{
 
1849
  FindStruct     fs;
 
1850
  int            j;
 
1851
  ObjMgrDataPtr  omdp;
 
1852
  SeqEntryPtr    sep = NULL;
 
1853
  SeqSubmitPtr   ssp = NULL;
 
1854
 
 
1855
  if (entityID == 0 || find_strings == NULL) return;
 
1856
 
 
1857
  omdp = ObjMgrGetData (entityID);
 
1858
  if (omdp != NULL) {
 
1859
    switch (omdp->datatype) {
 
1860
      case OBJ_SEQSUB :
 
1861
        ssp = (SeqSubmitPtr) omdp->dataptr;
 
1862
        if (ssp != NULL && ssp->datatype == 1) {
 
1863
          sep = (SeqEntryPtr) ssp->data;
 
1864
        }
 
1865
        break;
 
1866
      case OBJ_BIOSEQ :
 
1867
        sep = (SeqEntryPtr) omdp->choice;
 
1868
      case OBJ_BIOSEQSET :
 
1869
        sep = (SeqEntryPtr) omdp->choice;
 
1870
      default :
 
1871
        break;
 
1872
    }
 
1873
  }
 
1874
  /* sep = GetTopSeqEntryForEntityID (entityID); */
 
1875
  if (sep == NULL) return;
 
1876
 
 
1877
  MemSet ((Pointer) &fs, 0, sizeof (FindStruct));
 
1878
 
 
1879
  fs.entityID = entityID;
 
1880
  fs.func = FSAFindStrings;
 
1881
  fs.callback = callback;
 
1882
  fs.userdata = userdata;
 
1883
 
 
1884
  fs.find_string = NULL;
 
1885
  fs.replace_string = NULL;
 
1886
  fs.case_counts = case_counts;
 
1887
  fs.whole_word = whole_word;
 
1888
  fs.findLen = 0;
 
1889
  fs.replaceLen = 0;
 
1890
 
 
1891
  fs.select_item = select_item;
 
1892
  fs.send_update = send_update;
 
1893
  fs.did_find = FALSE;
 
1894
  fs.did_replace = FALSE;
 
1895
  fs.dirty = FALSE;
 
1896
 
 
1897
  /* build finite state machine in advance */
 
1898
 
 
1899
  fs.fsa = TextFsaNew ();
 
1900
 
 
1901
  for (j = 0; find_strings [j] != NULL; j++) {
 
1902
    TextFsaAdd (fs.fsa, find_strings [j]);
 
1903
  }
 
1904
 
 
1905
  /* if desc or feat filter arrays not supplied, default to all TRUE */
 
1906
 
 
1907
  if (descFilter != NULL) {
 
1908
    MemCopy ((Pointer) &fs.descFilter, (Pointer) descFilter, sizeof (fs.descFilter));
 
1909
  } else {
 
1910
    MemSet ((Pointer) &fs.descFilter, (int) TRUE, sizeof (fs.descFilter));
 
1911
  }
 
1912
 
 
1913
  if (featFilter != NULL) {
 
1914
    MemCopy ((Pointer) &fs.featFilter, (Pointer) featFilter, sizeof (fs.featFilter));
 
1915
  } else {
 
1916
    MemSet ((Pointer) &fs.featFilter, (int) TRUE, sizeof (fs.featFilter));
 
1917
  }
 
1918
 
 
1919
  /* if seqid filter array not supplied, default to all FALSE */
 
1920
 
 
1921
  if (seqidFilter != NULL) {
 
1922
    MemCopy ((Pointer) &fs.seqidFilter, (Pointer) seqidFilter, sizeof (fs.seqidFilter));
 
1923
  } else if (do_seqid_local) {
 
1924
    MemSet ((Pointer) &fs.seqidFilter, (int) FALSE, sizeof (fs.seqidFilter));
 
1925
    fs.seqidFilter [SEQID_LOCAL] = TRUE;
 
1926
  } else {
 
1927
    MemSet ((Pointer) &fs.seqidFilter, (int) FALSE, sizeof (fs.seqidFilter));
 
1928
  }
 
1929
 
 
1930
  /* ensure feature subtype is set in sfp->idx block */
 
1931
 
 
1932
  AssignIDsInEntity (entityID, 0, NULL);
 
1933
 
 
1934
  /* visit callbacks that find/replace specific fields */
 
1935
 
 
1936
  VisitBioseqsInSep (sep, (Pointer) &fs, FindReplBioseqs);
 
1937
 
 
1938
  VisitFeaturesInSep (sep, (Pointer) &fs, FindReplFeats);
 
1939
 
 
1940
  VisitAlignmentsInSep (sep, (Pointer) &fs, FindReplAligns);
 
1941
 
 
1942
  VisitGraphsInSep (sep, (Pointer) &fs, FindReplGraphs);
 
1943
 
 
1944
  VisitDescriptorsInSep (sep, (Pointer) &fs, FindReplDescs);
 
1945
 
 
1946
  if (ssp != NULL) {
 
1947
    FindReplSubmitBlock (ssp, &fs);
 
1948
  }
 
1949
 
 
1950
  /* clean up finite state machine */
 
1951
 
 
1952
  TextFsaFree (fs.fsa);
1771
1953
 
1772
1954
  /* send select message, if applicable */
1773
1955
 
1795
1977
  int         ch;
1796
1978
  FindStruct  fs;
1797
1979
  int         j;
 
1980
  size_t      subLen;
1798
1981
 
1799
1982
  if (strp == NULL || StringHasNoText (find_string)) return;
1800
1983
 
1801
1984
  MemSet ((Pointer) &fs, 0, sizeof (FindStruct));
1802
1985
 
1803
1986
  fs.entityID = 0;
 
1987
  fs.func = BoyerMooreReplaceString;
 
1988
  fs.callback = NULL;
 
1989
  fs.userdata = NULL;
 
1990
 
1804
1991
  fs.find_string = find_string;
1805
1992
  fs.replace_string = replace_string;
1806
1993
  fs.case_counts = case_counts;
1807
1994
  fs.whole_word = whole_word;
1808
 
  fs.do_replace = TRUE;
 
1995
  fs.findLen = StringLen (find_string);
 
1996
  fs.replaceLen = StringLen (replace_string);
 
1997
 
1809
1998
  fs.select_item = FALSE;
1810
 
  fs.send_update = FALSE;
1811
 
 
 
1999
  fs.send_update = UPDATE_NEVER;
1812
2000
  fs.did_find = FALSE;
1813
2001
  fs.did_replace = FALSE;
1814
2002
  fs.dirty = FALSE;
1815
2003
 
1816
2004
  /* build Boyer-Moore displacement array in advance */
1817
2005
 
1818
 
  fs.subLen = StringLen (find_string);
 
2006
  subLen = StringLen (find_string);
1819
2007
 
1820
2008
  for (ch = 0; ch < 256; ch++) {
1821
 
    fs.d [ch] = fs.subLen;
 
2009
    fs.d [ch] = subLen;
1822
2010
  }
1823
 
  for (j = 0; j < (int) (fs.subLen - 1); j++) {
 
2011
  for (j = 0; j < (int) (subLen - 1); j++) {
1824
2012
    ch = (int) (case_counts ? find_string [j] : TO_UPPER (find_string [j]));
1825
2013
    if (ch >= 0 && ch <= 255) {
1826
 
      fs.d [ch] = fs.subLen - j - 1;
 
2014
      fs.d [ch] = subLen - j - 1;
1827
2015
    }
1828
2016
  }
1829
2017