root/trunk/mdlif.c

Revision 389, 26.5 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1/* ----------------------------------------------------------------------
2   mdlif.c    -   NLM Medlars II - Access points translation / decoding
3----------------------------------------------------------------------- */
4
5#include <stdio.h>
6#include <string.h>
7#include <ctype.h>
8
9#include "cisis.h"      /* CISIS Interface */
10#include "cirun.h"      /* runtime area and defines by AOT */
11
12int argnext = 1;
13
14int  parmcontrol=0,parmleader=0,parmfields=0;
15LONGX parmfrom=1,parmto=0,parmloop=1;
16int  parmwait=0; /* =1; */
17LONGX parmcount=LONGX_MAX, parmtell=0;
18int  parmtest=0;
19FILE *fptest=NULL;
20
21
22#define ENBSSMH2        1
23#define ENBSSMH3        1
24
25#define MINTAG           15
26#define MAXTAG          969
27
28int nlmtag[MAXTAG+1];
29
30
31#define SVCHR           0x1e
32#define EVCHR           0x1e
33#define SSCHR           0x1d
34
35#define QQCHR           '/'
36
37
38#define NLMTAGAU        372
39#define NLMTAGEM        383
40#define NLMTAGLR        102
41#define NLMTAGJC        320
42#define NLMTAGTI        352
43#define NLMTAGUI        350
44#define NLMTAGCU        103
45#define NLMTAGMH        351
46#define NLMTAGTA        305
47#define NLMTAGTT        380
48#define NLMTAGAB        370
49#define NLMTAGLA        306
50#define NLMTAGPS        379
51#define NLMTAGDP        354
52#define NLMTAGRN        261             /* cdrom */
53#define NLMTAGLI        329             /* cdrom */
54#define NLMTAGSB        324             /* cdrom */
55#define NLMTAGIS        301             /* cdrom */
56#define NLMTAGCY        307             /* cdrom */
57#define NLMTAGZN        308             /* cdrom */
58#define NLMTAGPT        360             /* Publication Type -1991 */
59#define NLMTAGAD        378             /* Address */
60#define NLMTAGGS        328             /* Gene Symbol */
61#define NLMTAGVI        381             /* Volume */
62#define NLMTAGIP        373             /* Issue\Part\Supplement */
63
64#define NEWTAGTI_130    130
65
66/* TOXLINE - AOT/MB/FJL 14/06/2000 */
67/* Novos campos para I/F */
68#define NLMTAGCN        529     /*                       */
69#define NLMTAGKW        634     /*                       */
70#define NLMTAGSA        550     /*                       */
71#define NLMTAGYR        504     /*                       */
72/* Campos em outros tags */
73#define TOXTAGEM        100     /* x 383 - agora com 6 digitos   */
74
75
76unsigned char ebc2asc[256];
77unsigned char ebc2dia[256];
78int newlen;
79
80
81int parmcopy = 1;
82
83int parmascii= 0;
84
85#if BEFORE20000320
86int parmDP = 0;
87#else
88int parmDP = -1;
89#endif
90unsigned short int DP1,DP2;
91
92int parmappd = 0;
93
94int parmABy = 0;
95int parmABn = 0;
96
97int parmTOX = 0;
98
99
100RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
101
102#define FLDUPDLM        0x01
103
104unsigned char dbname[CIMPL+1],dbnout[CIMPL+1],buffup[MAXMFRL+MAXMFRL];
105
106unsigned char *dbnamep,*dbnoutp,*batchp,*lastp;
107
108LONGX count = 0;
109
110#if ANSI
111int qqlist(unsigned char *p,int loop2,int iocc);
112#else
113int qqlist();
114#endif
115
116void main(argc,argv)
117int argc;
118char *argv[];
119{
120    LONGX irec,upcrec,upirec,mfn;
121    int rc;
122
123    int minus1,plus1;
124
125    unsigned char *p,*q,c;
126    int i,j,xdir,loop1,loop2,tag,iocc;
127
128for (i=0; i<MAXTAG; )
129  nlmtag[i++]=0;
130nlmtag[NLMTAGAU] = 1;
131nlmtag[NLMTAGEM] = 1;
132nlmtag[NLMTAGLR] = 1;
133nlmtag[NLMTAGJC] = 1;
134nlmtag[NLMTAGTI] = 1;
135nlmtag[NLMTAGUI] = 1;
136nlmtag[NLMTAGCU] = 1;
137nlmtag[NLMTAGMH] = 1;
138nlmtag[NLMTAGTA] = 1;
139nlmtag[NLMTAGTT] = 1;
140nlmtag[NLMTAGAB] = 1;
141nlmtag[NLMTAGLA] = 1;
142nlmtag[NLMTAGPS] = 1;
143nlmtag[NLMTAGDP] = 1;
144nlmtag[NLMTAGRN] = 1;
145nlmtag[NLMTAGLI] = 1;
146nlmtag[NLMTAGSB] = 1;
147nlmtag[NLMTAGIS] = 1;
148nlmtag[NLMTAGCY] = 1;
149nlmtag[NLMTAGZN] = 1;
150nlmtag[NLMTAGPT] = 1;
151nlmtag[NLMTAGAD] = 1;
152nlmtag[NLMTAGGS] = 1;
153nlmtag[NLMTAGVI] = 1;
154nlmtag[NLMTAGIP] = 1;
155
156for (i=0; i<256; )
157  ebc2asc[i++]=' ';
158                                           for (i=0; i<256; )
159                                             ebc2dia[i++]=0;
160
161ebc2asc[0x40]=' ';                         ebc2dia[0x40]=' ';
162ebc2asc[0x4a]=' '; /* cedilla */           ebc2dia[0x4a]=0;
163ebc2asc[0x4b]='.';                         ebc2dia[0x4b]='.';
164ebc2asc[0x4c]='<';                         ebc2dia[0x4c]='<';
165ebc2asc[0x4d]='(';                         ebc2dia[0x4d]='(';
166ebc2asc[0x4f]='|';                         ebc2dia[0x4f]='|';
167ebc2asc[0x4e]='+';                         ebc2dia[0x4e]='+';
168ebc2asc[0x50]='&';                         ebc2dia[0x50]='&';
169ebc2asc[0x51]=SVCHR;                       ebc2dia[0x51]=SVCHR;
170ebc2asc[0x52]=EVCHR;                       ebc2dia[0x52]=EVCHR;
171ebc2asc[0x53]=SSCHR;                       ebc2dia[0x53]=SSCHR;
172ebc2asc[0x5a]='!';                         ebc2dia[0x5a]='!';
173ebc2asc[0x5b]='$';                         ebc2dia[0x5b]='$';
174ebc2asc[0x5c]='*';                         ebc2dia[0x5c]='*';
175ebc2asc[0x5d]=')';                         ebc2dia[0x5d]=')';
176ebc2asc[0x5e]=';';                         ebc2dia[0x5e]=';';
177ebc2asc[0x5f]='^'; /* not sign */          ebc2dia[0x5f]='^';
178ebc2asc[0x60]='-';                         ebc2dia[0x60]='-';
179ebc2asc[0x61]='/';                         ebc2dia[0x61]='/';
180ebc2asc[0x69]='|';                         ebc2dia[0x69]='|';
181ebc2asc[0x6a]='|';                         ebc2dia[0x6a]='|';
182ebc2asc[0x6b]=',';                         ebc2dia[0x6b]=',';
183ebc2asc[0x6c]='%';                         ebc2dia[0x6c]='%';
184ebc2asc[0x6d]='_';                         ebc2dia[0x6d]='_';
185ebc2asc[0x6e]='>';                         ebc2dia[0x6e]='>';
186ebc2asc[0x6f]='?';                         ebc2dia[0x6f]='?';
187ebc2asc[0x7a]=':';                         ebc2dia[0x7a]=':';
188ebc2asc[0x7b]='#';                         ebc2dia[0x7b]='#';
189ebc2asc[0x7c]='@';                         ebc2dia[0x7c]='@';
190ebc2asc[0x7d]='\'';                        ebc2dia[0x7d]='\'';
191ebc2asc[0x7e]='=';                         ebc2dia[0x7e]='=';
192#if BEFORE990715
193ebc2asc[0x7f]='�';                         ebc2dia[0x7f]='�';
194#else
195ebc2asc[0x7f]=' ';                         ebc2dia[0x7f]=' ';
196#endif
197ebc2asc[0x80]=' '; /* afs delimiter */     ebc2dia[0x80]=0;
198ebc2asc[0x81]='a';                         ebc2dia[0x81]='a';
199ebc2asc[0x82]='b';                         ebc2dia[0x82]='b';
200ebc2asc[0x83]='c';                         ebc2dia[0x83]='c';
201ebc2asc[0x84]='d';                         ebc2dia[0x84]='d';
202ebc2asc[0x85]='e';                         ebc2dia[0x85]='e';
203ebc2asc[0x86]='f';                         ebc2dia[0x86]='f';
204ebc2asc[0x87]='g';                         ebc2dia[0x87]='g';
205ebc2asc[0x88]='h';                         ebc2dia[0x88]='h';
206ebc2asc[0x89]='i';                         ebc2dia[0x89]='i';
207ebc2asc[0x8a]='i'; /* dotless i */         ebc2dia[0x8a]='i';
208ebc2asc[0x8e]='l'; /* lower polish l */    ebc2dia[0x8e]='l';
209ebc2asc[0x91]='j';                         ebc2dia[0x91]='j';
210ebc2asc[0x92]='k';                         ebc2dia[0x92]='k';
211ebc2asc[0x93]='l';                         ebc2dia[0x93]='l';
212ebc2asc[0x94]='m';                         ebc2dia[0x94]='m';
213ebc2asc[0x95]='n';                         ebc2dia[0x95]='n';
214ebc2asc[0x96]='o';                         ebc2dia[0x96]='o';
215ebc2asc[0x97]='p';                         ebc2dia[0x97]='p';
216ebc2asc[0x98]='q';                         ebc2dia[0x98]='q';
217ebc2asc[0x99]='r';                         ebc2dia[0x99]='r';
218#if BEFORE990715
219ebc2asc[0x9d]='�';                         ebc2dia[0x9d]='�';
220#else
221ebc2asc[0x9d]=' ';                         ebc2dia[0x9d]=' ';
222#endif
223ebc2asc[0x9f]=' '; /* circumflex */        ebc2dia[0x9f]=0;
224#if BEFORE990715
225ebc2asc[0xa0]='�'; /* trademark symbol */  ebc2dia[0xa0]='�';
226#else
227ebc2asc[0xa0]=' '; /* trademark symbol */  ebc2dia[0xa0]=' ';
228#endif
229ebc2asc[0xa1]=' '; /* angstrom */          ebc2dia[0xa1]=0;
230ebc2asc[0xa2]='s';                         ebc2dia[0xa2]='s';
231ebc2asc[0xa3]='t';                         ebc2dia[0xa3]='t';
232ebc2asc[0xa4]='u';                         ebc2dia[0xa4]='u';
233ebc2asc[0xa5]='v';                         ebc2dia[0xa5]='v';
234ebc2asc[0xa6]='w';                         ebc2dia[0xa6]='w';
235ebc2asc[0xa7]='x';                         ebc2dia[0xa7]='x';
236ebc2asc[0xa8]='y';                         ebc2dia[0xa8]='y';
237ebc2asc[0xa9]='z';                         ebc2dia[0xa9]='z';
238ebc2asc[0xab]=' '; /* um laut */           ebc2dia[0xab]=0;
239ebc2asc[0xac]=' '; /* tilde */             ebc2dia[0xac]=0;
240ebc2asc[0xad]='[';                         ebc2dia[0xad]='[';
241ebc2asc[0xaf]=' '; /* grave */             ebc2dia[0xaf]=0;
242ebc2asc[0xb9]='o'; /* lower polish o */    ebc2dia[0xb9]='o';
243ebc2asc[0xbb]=' '; /* breve */             ebc2dia[0xbb]=0;
244ebc2asc[0xbc]=' '; /* acute */             ebc2dia[0xbc]=0;
245ebc2asc[0xbd]=']';                         ebc2dia[0xbd]=']';
246ebc2asc[0xbf]='-'; /* macron */            ebc2dia[0xbf]='-';
247ebc2asc[0xc0]='{';                         ebc2dia[0xc0]='{';
248ebc2asc[0xc1]='A';                         ebc2dia[0xc1]='A';
249ebc2asc[0xc2]='B';                         ebc2dia[0xc2]='B';
250ebc2asc[0xc3]='C';                         ebc2dia[0xc3]='C';
251ebc2asc[0xc4]='D';                         ebc2dia[0xc4]='D';
252ebc2asc[0xc5]='E';                         ebc2dia[0xc5]='E';
253ebc2asc[0xc6]='F';                         ebc2dia[0xc6]='F';
254ebc2asc[0xc7]='G';                         ebc2dia[0xc7]='G';
255ebc2asc[0xc8]='H';                         ebc2dia[0xc8]='H';
256ebc2asc[0xc9]='I';                         ebc2dia[0xc9]='I';
257ebc2asc[0xd1]='J';                         ebc2dia[0xd1]='J';
258ebc2asc[0xd2]='K';                         ebc2dia[0xd2]='K';
259ebc2asc[0xd3]='L';                         ebc2dia[0xd3]='L';
260ebc2asc[0xd4]='M';                         ebc2dia[0xd4]='M';
261ebc2asc[0xd5]='N';                         ebc2dia[0xd5]='N';
262ebc2asc[0xd6]='O';                         ebc2dia[0xd6]='O';
263ebc2asc[0xd7]='P';                         ebc2dia[0xd7]='P';
264ebc2asc[0xd8]='Q';                         ebc2dia[0xd8]='Q';
265ebc2asc[0xd9]='R';                         ebc2dia[0xd9]='R';
266ebc2asc[0xe0]='\\';                        ebc2dia[0xe0]='\\';
267ebc2asc[0xe2]='S';                         ebc2dia[0xe2]='S';
268ebc2asc[0xe3]='T';                         ebc2dia[0xe3]='T';
269ebc2asc[0xe4]='U';                         ebc2dia[0xe4]='U';
270ebc2asc[0xe5]='V';                         ebc2dia[0xe5]='V';
271ebc2asc[0xe6]='W';                         ebc2dia[0xe6]='W';
272ebc2asc[0xe7]='X';                         ebc2dia[0xe7]='X';
273ebc2asc[0xe8]='Y';                         ebc2dia[0xe8]='Y';
274ebc2asc[0xe9]='Z';                         ebc2dia[0xe9]='Z';
275ebc2asc[0xf0]='0';                         ebc2dia[0xf0]='0';
276ebc2asc[0xf1]='1';                         ebc2dia[0xf1]='1';
277ebc2asc[0xf2]='2';                         ebc2dia[0xf2]='2';
278ebc2asc[0xf3]='3';                         ebc2dia[0xf3]='3';
279ebc2asc[0xf4]='4';                         ebc2dia[0xf4]='4';
280ebc2asc[0xf5]='5';                         ebc2dia[0xf5]='5';
281ebc2asc[0xf6]='6';                         ebc2dia[0xf6]='6';
282ebc2asc[0xf7]='7';                         ebc2dia[0xf7]='7';
283ebc2asc[0xf8]='8';                         ebc2dia[0xf8]='8';
284ebc2asc[0xf9]='9';                         ebc2dia[0xf9]='9';
285
286
287    argnext=1;
288    if (argc < 3) {
289        if (argc == 2 && strcmp(argv[1],"what") == 0) {
290            printf("%s",cicopyr("?Utility MDL/MDLIF"));
291            printf("\n");
292            exit(1);
293        }
294        printf("%s",cicopyr("Utility MDL/MDLIF"));
295        printf("\n");
296        printf("mdlif <dbname> [create=]<dbnout> [<option> [...]] \n");
297        printf("\n");
298        printf("options: {+/-}{control/leader/fields} \n");
299        printf("         {from/to/loop/count/tell}=<n> \n");
300        printf("         DP=<aa> \n");
301        printf("         AB={YES|NO} \n");
302        printf("         TOXLINE \n");
303        printf("         [APPEND] \n");
304        printf("         now[ait] \n");
305        printf("\n");
306        printf("(version 14/06/2000)\n");
307        printf("\n");
308        exit(1);
309    }
310
311    dbnamep=argv[argnext++];
312    dbnoutp=argv[argnext++];
313
314
315    minus1=plus1=0;
316
317    for (i=argnext; i<argc; i++) {
318        p=argv[i];
319
320        if (*p == '-') {
321            minus1++;
322            if (minus1 == 1)
323                parmcontrol=parmleader=parmfields=1;
324        }
325
326        if (strcmp(p,"-control") == 0) {
327            parmcontrol=0;
328            continue;
329        }
330        if (strcmp(p,"-leader") == 0) {
331            parmleader=0;
332            continue;
333        }
334        if (strcmp(p,"-fields") == 0) {
335            parmfields=0;
336            continue;
337        }
338
339        if (*p == '+') {
340            plus1++;
341            if (plus1 == 1) {
342                parmcontrol=parmleader=parmfields=0;
343            }
344        }
345
346        if (strcmp(p,"+control") == 0) {
347            parmcontrol=1;
348            continue;
349        }
350        if (strcmp(p,"+leader") == 0) {
351            parmleader=1;
352            continue;
353        }
354        if (strcmp(p,"+fields") == 0) {
355            parmfields=1;
356            continue;
357        }
358
359        if (strncmp(p,"from=",5) == 0) {
360            if (sscanf(p+5,"%"_LD_,&parmfrom) != 1)
361                fatal(p);
362            continue;
363        }
364        if (strncmp(p,"to=",3) == 0) {
365            if (sscanf(p+3,"%"_LD_,&parmto) != 1)
366                fatal(p);
367            continue;
368        }
369        if (strncmp(p,"loop=",5) == 0) {
370            if (sscanf(p+5,"%"_LD_,&parmloop) != 1)
371                fatal(p);
372            continue;
373        }
374
375        if (strcmp(p,"nowait") == 0 || strcmp(p,"now") == 0) {
376            parmwait=0;
377            continue;
378        }
379
380        if (!strncmp(argv[i],"count=",6)) {
381            p=argv[i]+6;
382            if ((sscanf(p,"%"_LD_,&parmcount)) != 1)
383                fatal(p);
384            continue;
385        }
386        if (!strncmp(argv[i],"tell=",5)) {
387            p=argv[i]+5;
388            if ((sscanf(p,"%"_LD_,&parmtell)) != 1)
389                fatal(p);
390            continue;
391        }
392
393        if (!strncmp(argv[i],"DP=",3)) {
394            p=argv[i]+3;
395            if ((sscanf(p,"%d",&parmDP)) != 1)
396                fatal(p);
397#if BEFORE20000310             
398            if (parmDP < 48 || parmDP > 99)
399                fatal("parmDP 48..99");
400#endif
401            DP1=parmDP/10; DP2=parmDP-DP1*10;
402            printf("+++ parmDP=%d%d",DP1,DP2);
403            DP1|=0xF0; /* EBCDIC '0' */
404            DP2|=0xF0; /*            */
405            printf("=%02x%02x \n",DP1,DP2);
406            continue;
407        }
408
409        if (!strncmp(argv[i],"AB=NO",5)) {
410           parmABn=1;
411           nlmtag[NLMTAGAB] = 0;
412           nlmtag[NLMTAGAU] = 0;
413           printf("+++ parmABn=%d parmABy=%d \n",parmABn,parmABy);
414           continue;
415        }
416
417        if (!strncmp(argv[i],"AB=YES",6)) {
418           parmABy=1;
419           for (j=0; j<MAXTAG; ) nlmtag[j++]=0;
420           nlmtag[NLMTAGUI] = 1;
421           nlmtag[NLMTAGAB] = 1;
422           nlmtag[NLMTAGAU] = 1;
423           printf("+++ parmABn=%d parmABy=%d \n",parmABn,parmABy);
424           continue;
425        }
426
427        if (!strncmp(argv[i],"APPEND",6)) {
428           parmappd=1;
429           printf("+++ APPEND \n");
430           continue;
431        }
432
433        if (!strncmp(argv[i],"test=",5)) {
434            p=argv[i]+5;
435            if ((sscanf(p,"%d",&parmtest)) != 1)
436                fatal(p);
437            continue;
438        }
439
440        if (strcmp(p,"asciinomore") == 0) {
441            parmascii=1;
442            continue;
443        }
444
445        /* TOXLINE - AOT/MB/FJL 14/06/2000 */
446        if (!strcmp(argv[i],"TOXLINE")) {
447            parmTOX=1;
448            nlmtag[NLMTAGCN] = 1;
449            nlmtag[NLMTAGKW] = 1;
450            nlmtag[NLMTAGSA] = 1;
451            nlmtag[NLMTAGYR] = 1;
452            nlmtag[TOXTAGEM] = 1;
453            printf("+++ TOXLINE \n");
454            continue;
455        }
456
457        fatal(p);
458    }
459
460
461    printf("+++ input data base:  %s%s\n",dbnamep,(parmascii)?" ascii":" ");
462    printf("+++ output data base: %s\n",dbnoutp);
463
464    if (parmtest)
465        if ((fptest=fopen("xmdlif","w")) == NULL)
466            fatal("xmdlif");
467
468
469    /*
470        inicializa bases de dados
471    */
472    if (strncmp(dbnoutp,"create=",7) == 0) rc=recisis0((dbnoutp+=7));
473
474    /*
475        ve entrada
476    */
477    RECORD((irec=nrecs),dbnamep,0L);
478    if (!parmto) parmto=MF0nxtmfn-1;
479    if (parmcontrol) prtcontrol(recp,dbnamep);
480
481    /*
482        ve saida
483    */
484    RECORD((upcrec=nrecs),dbnoutp,0L);
485    if (parmcontrol) prtcontrol(recp,dbnoutp);
486
487    /*
488        loop principal
489    */
490    for (upirec=nrecs, mfn=parmfrom; mfn<=parmto; mfn+=parmloop) {
491
492        RECORD(irec,dbnamep,mfn);
493
494        if (RECrc != RCNORMAL)
495            continue;
496
497#if BEFORE20000320
498        if (parmDP) {
499#else
500        if (parmDP >= 0) {
501#endif
502            xdir=fieldx(irec,NLMTAGDP,1);
503            if (xdir >= 0) {
504                if (DIRlen(xdir) >= 4) {
505                    p=FIELDP(xdir);
506                    if (*(p+2) != DP1) continue;
507                    if (*(p+3) != DP2) continue;
508                }
509            }
510            else {         
511                  if (!parmappd) continue;
512            }
513        }
514
515        if (parmleader) prtleader(recp,0L);
516
517        batchp=buffup; *batchp=NULL;
518
519        for (xdir=tag=0, loop1=MFRnvf; loop1--; xdir++) {
520
521            if (DIRtag(xdir) < MINTAG || DIRtag(xdir) > MAXTAG) {
522                printf("*** mfn=%"_LD_" tag=%d \n",
523                    MFRmfn,DIRtag(xdir));
524                fatal("mdlif/tag");
525            }
526
527            if (nlmtag[DIRtag(xdir)] == 0)
528                continue;
529
530            if (DIRtag(xdir) != tag) {
531                tag=DIRtag(xdir);
532                iocc=1;
533            }
534            else
535                iocc++;
536
537            newlen=DIRlen(xdir);
538            if (parmascii == 0) {
539                p=q=FIELDP(xdir);
540                for (loop2=DIRlen(xdir); loop2--; p++) {
541                    c = *p;
542                    *q = ebc2asc[c];
543                    if (ebc2dia[c] == 0) {
544                        newlen--;
545if (parmtest >= 2) {
546 fprintf(fptest,"ebc2dia - tag=%d  iocc=%d  in char=%c=%02x newlen=%d",
547  DIRtag(xdir),iocc,*q,c,newlen);
548 fprintf(fptest,"\n");
549}
550                    }
551                    else {
552                        q++;
553                    }
554                }
555            }
556
557
558#if Y
559*batchp=NULL;
560puts("for xdir++  "); getchar();
561puts(buffup);
562#endif
563
564if (parmfields)
565 if (parmtest >= 1) {
566        printf("%3d %d >",DIRtag(xdir),iocc);
567        for (q=FIELDP(xdir), loop2=newlen; loop2--; q++)
568            printf("%c",*q);
569        printf("<\n");
570 }
571
572
573            if (DIRtag(xdir) != NLMTAGMH && DIRtag(xdir) != NLMTAGRN) {
574
575                if (DIRtag(xdir) == NLMTAGTI && fieldn(irec,NLMTAGTT,1))
576                    sprintf(batchp,"A%3d%c",NEWTAGTI_130,FLDUPDLM);
577                else
578                    sprintf(batchp,"A%3d%c",DIRtag(xdir),FLDUPDLM);
579                batchp+=5;
580
581                for (p=FIELDP(xdir), loop2=newlen; loop2; ) {
582                    if (*p == SVCHR || *p == EVCHR || *p == SSCHR) {
583                        printf("*** mfn=%"_LD_" tag=%d occ=%d ...",
584                            MFRmfn,DIRtag(xdir),iocc);
585                        /* for (; loop2--; p++)
586                            printf("%c",*p);
587                        printf(".\n");
588                        break;  */
589                        p++;
590                        loop2--;
591                    }
592                    if (loop2) {
593                        *batchp++ = *p; p++;
594                        loop2--;
595                    }
596                }
597                *batchp++ = FLDUPDLM;
598                iocc=0;
599                continue; /* next dir entry */
600            }
601
602            if (DIRtag(xdir) == NLMTAGRN) {
603                sprintf(batchp,"A%3d%c",DIRtag(xdir),FLDUPDLM);
604                batchp+=5;
605                *batchp++ = '^'; *batchp++ = 'a';
606                p=FIELDP(xdir); loop2=newlen;
607                if (*(p+loop2-1) == ')')
608                    loop2--;
609                for (; loop2; ) {
610                    if (*p == '(')
611                        break;
612                    loop2--;
613                    *batchp++ = *p; p++;
614                }
615                if (*(batchp-1) == ' ') { batchp--; }
616                if (*p == '(') { loop2--; p++; }
617                *batchp++ = '^'; *batchp++ = 'b';
618                for (; loop2--; ) {
619                     *batchp++ = *p; p++;
620                }
621                *batchp++ = FLDUPDLM;
622
623                continue;
624            }
625
626            sprintf(lastp=batchp,"A%3d%c",880,FLDUPDLM); batchp+=5; /*secund.*/
627
628            *batchp++ = '^'; *batchp++ = 'h';
629
630            for (p=FIELDP(xdir), loop2=newlen; loop2; ) {
631                if (*p == SSCHR) {
632                    break;
633                }
634                *batchp++ = *p; p++;
635                loop2--;
636            }
637
638
639            if (*p != SSCHR) {
640                /* fatal("1\\SS\\2"); */
641                printf("1\\SS\\2 - mfn=%"_LD_" tag=%d occ=%d\n",
642                    MFRmfn,DIRtag(xdir),iocc);
643                *batchp++ = FLDUPDLM;
644                continue;
645            }
646            p++; loop2--;
647#if ENBSSMH2
648            *batchp++ = '^'; *batchp++ = 'c';
649            *batchp++ = *p;
650#endif
651            p++; loop2--;
652
653
654            if (*p != SSCHR) {
655                /* fatal("2\\SS\\3"); */
656                printf("2\\SS\\3 - mfn=%"_LD_" tag=%d occ=%d\n",
657                    MFRmfn,DIRtag(xdir),iocc);
658                *batchp++ = FLDUPDLM;
659                continue;
660            }
661            p++; loop2--;
662#if ENBSSMH3
663            *batchp++ = '^'; *batchp++ = 'i';
664            *batchp++ = *p;
665#endif
666            p++; loop2--;
667            *batchp++ = FLDUPDLM;               /*end required subelements*/
668
669            if (loop2 < 0) {
670                printf("loop2<0 - mfn=%"_LD_" tag=%d occ=%d loop2=%d \n",
671                    MFRmfn,DIRtag(xdir),iocc,loop2);
672                continue;
673            }
674
675            if (*p == SSCHR) {
676                p++; loop2--;
677                batchp--;           /* erase FLDUPDLM required subelements */
678                loop2=qqlist(p,loop2,iocc);
679                *batchp++ = FLDUPDLM;
680                continue;
681            }
682
683            if (loop2) {
684if (parmtest >= 3) {
685    fprintf(fptest,"ev/sv - mfn=%"_LD_" occ=%d loop2=%d ?",MFRmfn,iocc,loop2);
686    for (q=p; loop2--; q++)
687        fprintf(fptest,"%c",*q);
688    fprintf(fptest,"?\n");
689}
690                if (*p != SVCHR && *p != EVCHR) {
691                    printf("loop2 - mfn=%"_LD_" tag=%d occ=%d loop2=%d \n",
692                        MFRmfn,DIRtag(xdir),iocc,loop2);
693                }
694            }
695        }
696
697#if Y
698*batchp=NULL;
699puts("end xdir++  "); getchar();
700puts(buffup);
701#endif
702
703        if (parmABn)
704            if (fieldn(irec,NLMTAGAB,1)) {
705                sprintf(batchp,"A%3d%c%s%c",NLMTAGAB,FLDUPDLM,"Y",FLDUPDLM);
706                batchp+=strlen(batchp);
707            }
708
709        *batchp=NULL;
710
711        RECORD(upirec,dbnoutp,VMF0nxtmfn(upcrec)); /* get null PDEL record */
712        MFRstatus=ACTIVE;
713
714        p=fldupdat(upirec,buffup);
715        if (p) {
716            printf("*** fldupdat='%s'\n",p);
717            fatal("mdlif/fldupdat");
718        }
719
720if (parmfields) {
721        tag=NULL; iocc=1;
722        for (xdir=0, loop1=MFRnvf; loop1--; xdir++) {
723            if (DIRtag(xdir) == tag) {
724                iocc++;
725            }
726            else {
727                tag=DIRtag(xdir);
728                iocc=1;
729            }
730            printf("%6"_LD_"|%3d|%3d|",MFRmfn,DIRtag(xdir),iocc);
731            for (q=FIELDP(xdir), loop2=DIRlen(xdir); loop2--; q++)
732#if SHOWHEX
733                if (*q < ' ' || *q > '}') printf("|x%02x|",*q); else
734#endif
735                printf("%c",*q);
736            printf("|\n");
737        }
738}
739
740
741if (parmcopy) {
742        rc=recupdat(upcrec,upirec);
743        if (rc) {
744            printf("*** recupdat=%d\n",rc);
745            fatal("mdlif/recupdat");
746        }
747}
748
749        count++;
750        if (parmtell)
751            if (!(count % parmtell)) {
752              if (parmtest >= 2)
753                fprintf(fptest,
754                  "%7"_LD_"|%6"_LD_"|%5d/%5d|%5d/%5d|%5d/%5d(%3d/%3d)|%5d/%5d|%6"_LD_"\n",
755                        count,
756                        VMFRmfn(irec),VMFRmfrl(irec),MFRmfrl,
757                        LEADER,LEADER,
758                        VMFRbase(irec)-LEADER,MFRbase-LEADER,
759                        VMFRnvf(irec),MFRnvf,
760                        VMFRmfrl(irec)-VMFRbase(irec),MFRmfrl-MFRbase,
761                        MFRmfn);
762
763              fprintf(stderr,
764                    "+++ %"_LD_" recs mfn=%6"_LD_"  mfrl=%d  =  %d + %d (%3d) + %d\n",
765                        count,
766                        MFRmfn,MFRmfrl,
767                        LEADER,MFRbase-LEADER,MFRnvf,MFRmfrl-MFRbase);
768            }
769
770        if (parmwait) {
771            printf("..");
772            if (getchar() != '\n')
773                break;
774        }
775
776        if (count >= parmcount)
777            break;
778    }
779
780    exit(0);
781}
782
783
784int qqlist(p,loop2,iocc)
785unsigned char *p;
786int loop2;
787int iocc;
788{
789        unsigned char *thisp;
790        unsigned char *q;
791        int qlen,n;
792
793
794        for (*batchp=NULL, qlen=strlen(lastp); loop2; ) {
795
796#if X
797printf("+++ p   : loop2=%d - '",loop2);
798for (n=loop2, q=p; n--; q++)
799 putchar(*q);
800puts("'\n");
801#endif
802
803            if (*p == '*') {
804                *(lastp+1)='8';
805                *(lastp+2)='7'; /* principal */
806                *(lastp+3)='0';
807                p++; loop2--;           /*skip 1 input char*/
808#if X
809printf("+++ * on: loop2=%d - '",loop2);
810for (n=loop2, q=p; n--; q++)
811 putchar(*q);
812puts("'\n");
813#endif
814
815            }
816            else {
817                *(lastp+1)='8';
818                *(lastp+2)='8'; /* secundario */
819                *(lastp+3)='0';
820            }
821#if X
822printf("+++ * ok: loop2=%d - '",loop2);
823for (n=loop2, q=p; n--; q++)
824 putchar(*q);
825puts("'\n");
826#endif
827
828
829            if (loop2) {
830                if (*p != QQCHR && *p != SVCHR && *p != EVCHR) {
831#if X
832printf("+++ qq  : loop2=%d - '",loop2);
833for (n=loop2, q=p; n--; q++)
834 putchar(*q);
835puts("'\n");
836#endif
837
838                    if (loop2 < 2) {
839                        printf("loop<2 - mfn=%"_LD_"/%d loop2=%d chr=%02x=%c \n",
840                            MFRmfn,iocc,loop2,*p,*p);
841                        return(loop2);
842                    }
843                    q=p+1;
844                    if (!isalpha(*p) || !isalpha(*q)) {
845                        printf("letter - mfn=%"_LD_"/%d loop2=%d chr=%02x=%c \n",
846                            MFRmfn,iocc,loop2,*p,*p);
847                        return(loop2);
848                    }
849                    *batchp++ = '^'; *batchp++ = 'q';
850                    *batchp++ = *p; p++;
851                    *batchp++ = *p; p++;
852                    loop2-=2;
853#if X
854printf("+++ ok  : loop2=%d - '",loop2);
855for (n=loop2, q=p; n--; q++)
856 putchar(*q);
857puts("'\n");
858#endif
859
860                }
861            }
862
863            if (loop2 > 0)
864                if (*p == QQCHR) {
865
866                    *batchp++ = FLDUPDLM;
867
868                    for (thisp=lastp, lastp=batchp, n=qlen; n-- ; )
869                        *batchp++ = *thisp++;
870                    p++; loop2--;   /* skip 1 input char */
871#if X
872printf("+++ more: loop2=%d - '",loop2);
873for (n=loop2, q=p; n--; q++)
874 putchar(*q);
875puts("'\n");
876#endif
877                    continue;
878                }
879
880            break;
881        }
882
883#if Z
884*batchp=NULL;
885puts("end qqls++  "); getchar();
886puts(buffup);
887#endif
888
889        return(loop2);
890}
Note: See TracBrowser for help on using the browser.