-
Notifications
You must be signed in to change notification settings - Fork 3
/
aotmsa2mfn.c
2499 lines (2121 loc) · 89.7 KB
/
aotmsa2mfn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* =============================================================================
AOTMSA2 Adalberto Otranto Tardelli / Meide da Silva Ancao
Application 1
by AOT, 05/01/2002
Reads BIREME's Medline
by AOT, 09/03/2003
aotmsa2.c CI/tabula casos segundo variavel/variaveis de controle
-----------------------------------------------------------------------------
aotmsa2 <action>[,...] [<option> [...]]
actions: C - get parameters from cgi
1 - display header MDL:
TA - search amdl
tabulate amdl (v351/)
store F tab and W tab
DA - read F tab and W tab
display formA results
options: bool=<expr>
cip=<> c:/2001x300/usersaot/cip.cip
decs=<> decs
amdl=<> amdl351 | MEDLINE*.def
atmdl=<> atmdl (000001..039999)
name=<> c:\windows\temp\tmp1.$$$
pft=<> aotmsa2A.pft
atmdl99 amdl351.maxmfn
{from||loop|count|tell|setno}=<n>
-----------------------------------------------------------------------------
============================================================================= */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include "cisis.h" /* CISIS Interface header file */
#include "cirun.h" /* CISIS Interface runtime declarations */
#include "cib70.h" /* CISIS Interface search engine */
#if 1 /* ANSITABS */
/* ---------------------------------------------------------------------- ansiuc.tab -- */
unsigned char ansiuctab[256]=
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
144,145,146,147,148,149,150,151,152,153,138,155,140,157,158,159,
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
65, 65, 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73,
68, 78, 79, 79, 79, 79, 79,215,216, 85, 85, 85, 85, 89,222,223,
65, 65, 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73,
208, 78, 79, 79, 79, 79, 79,247,216, 85, 85, 85, 85,221,222,221
};
/* ---------------------------------------------------------------------- ansiac.tab -- */
unsigned char ansiactab[] = {
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99,100,101,102,103,104,
105,106,107,108,109,110,111,112,113,114,115,116,117,
118,119,120,121,122,128,129,130,131,132,133,134,135,136,137,138,139,140,141,
142,143,144,145,146,147,148,149,150,151,152,153,154,
160,161,162,163,164,165,168,192,193,194,195,196,199,200,201,202,203,204,205,
206,207,209,210,211,212,213,214,217,218,219,220,221,
224,225,226,227,228,231,232,233,234,235,236,237,238,239,241,242,243,244,245,
246,249,250,251,252,253,255
,000
};
/* ------------------------------------------------------------------------------------ */
#endif /* 0000 */
#define CLASSES 40000 /* default */
#define TAG351 351 /* DecsMfn tag - MH by serverw::\bases\mdl.006\aot\get*\ */
#define TAG020 20 /* DecsCateg tag - standard A00.000.000.000...000 - currently up to 39 chrs */
#define MAXCATLEN 47 /* 111.222.333.444.555.666.777.888.999.000.111.222 */
#define DECSTAGNAME(x) ( \
(toupper(*x) == 'I') ? 1 : \
(toupper(*x) == 'E') ? 2 : \
(toupper(*x) == 'P') ? 3 : 1 )
#define TAG022 22 /* DecsCDallCategs tag */
#define TAG005 5 /* DecsCDCateg1MFN tag */
#define ATMDLTAG999 999 /* atmdl/999999 tag 999 = amdl351.maxmfn */
typedef struct tabfreqf_entry {
LONGX v351;
LONGX freq; /* = docs de TT em xA */
} TABFREQF_ENTRY;
typedef struct tabfreqd_entry {
LONGX v351;
// LONGX delta;
char delca[MAXCATLEN+1];
LONGX gmfn;
} TABFREQD_ENTRY;
typedef struct tabfreqw_entry {
LONGX v351;
float peso;
LONGX docsTTxA; /* v999[1] = docs de TT em xA */
LONGX docsTTamdl; /* v999[2] = docs de TT em amdl = postings de TT em amdl */
// LONGX docsTOTxA; /* v9991[1] = docs de xA - nao vazios */
// LONGX docsTOTamdl; /* v9991[2] = docs de amdl */
float frelTTxA; /* v1991[1] = frelTTxA = docs de TT em xA / docs de xA */
float frelTTamdl; /* v1991[2] = frelTTamdl = docs de TT em amdl / docs de amdl */
//see peso float pesoTTxA; /* v2991[1] = frelTTxA / frelTTamdl */
// char pesoTTxAout[4]; /* v2221[1] = 'out' se peso < 1 */
} TABFREQW_ENTRY;
/* prototypes */
#if ANSI
int rutfreqF(LONGX *tabcntA, int ntabs, LONGX drec, LONGX *tabcntArankF, TABFREQF_ENTRY **tabfreqFp);
int outfreqF(int ntabs, char *dbnoutp, LONGX *tabcntArankW, LONGX *tabcntArankD, TABFREQF_ENTRY *tabfreqFp);
int rutfreqW(TABFREQF_ENTRY *tabfreqF, int ntabs, char *amdlname, LONGX docsTOTxA, LONGX docsTOTamdl, LONGX *tabcntArankF, LONGX *tabcntArankW, TABFREQW_ENTRY **tabfreqWp, LONGX *tabcntMDL, LONGX *gtabcntA);
int outfreqW(int ntabs, char *dbnoutp, LONGX docsTOTxA, LONGX docsTOTamdl, LONGX *tabcntArankF, LONGX *tabcntArankD, TABFREQD_ENTRY *tabfreqD, TABFREQW_ENTRY *tabfreqW);
int rutfreqD(TABFREQF_ENTRY *tabfreqF, int ntabs, LONGX *tabcntArankF, LONGX *tabcntArankW, LONGX *tabcntArankD, TABFREQD_ENTRY **tabfreqDp, LONGX *tabcntGMDL, LONGX *gtabcntA);
int outfreqD(int ntabs, char *dbnoutp, LONGX *tabcntArankF, LONGX *tabcntArankW, TABFREQD_ENTRY *tabfreqD);
char *recsfldv(char *areap, char *fldp, FFI fldlen, char *defaultp);
#else
int rutfreqF();
int outfreqF();
int rutfreqW();
int outfreqW();
int rutfreqD();
int outfreqD();
char *recsfldv();
#endif
/* <========================= */
LONGX ddrec;
char *ddecsdbnp;
/* <========================= */
/* tabs here */
int ntabs=0; /* numero de entradas de tabcntA/tabcntArankx */
LONGX tabcntA [CLASSES+1]; /* indexed by DecsMfn */ /* avoid -1 */
LONGX tabcntArankF[CLASSES+1]; /* indexed by DecsMfn */
LONGX tabcntArankW[CLASSES+1]; /* indexed by DecsMfn */
LONGX tabcntArankD[CLASSES+1]; /* indexed by DecsMfn */
int gntabs=0; /* numero de entradas de gtabcntA */
LONGX gtabcntA [CLASSES+1]; /* indexed by DecsMfn */
LONGX tabcntMDL [CLASSES+1]; /* indexed by DecsMfn */
LONGX tabcntGMDL [CLASSES+1]; /* indexed by DecsMfn */
#define MAXTABV05 42099
LONGX vcategmfn[26][10][10]; /* indexed by [A][0][0] */ /* 10K */
int ntabv05=0; /* avail */
LONGX vtabv05[MAXTABV05]; /* indexed by vtabv05xrf[DecsMnf] */
int vtabv05xrf[CLASSES+1]; /* starting index 0..MAXTABV05-1 */
int vtabv05len[CLASSES+1]; /* number of entries */
/* tabs here */
void main(argc,argv_main)
int argc;
char *argv_main[];
{
#define MAXARGS 512
char *argv[MAXARGS+1];
int i,argnext=1;
void *ciapip = NULL;
RECSTRU *recp;
LONGX irec=0L;
unsigned char *p,*q;
LONGX vtime[100]; /* watch */
char *vtimid[100]; /* watch */
int ntimes=0; /* watch */
int parmtime=0;
int parmloadmdl=1;
int parmgroup=0;
LONGX mydrec=0L;
char parmsortx='\0'; /* actual sort parameter */
int parmshowgrp1=0; /* show group01.w information */ /* 1 */
int parmshowcat1=0; /* show first cat1 - name */ /* c */
int parmshowtree=0; /* show hierarchy?? lines */ /* t */
int parmshowzero=0; /* don't show condition lines */ /* z */
#define ENVASIZE 8000
char envarea[ENVASIZE];
char *usernamp="aot";
char *parmaid=NULL;
/* ---------------------------------------------------------------------- */
LONGX boolridx=0L;
LONGX booldbcrec=0L; /* b5_exp usa booldbcrec condicionado a namedbnp */
LONGX boolhits=0;
LONGX boolh;
LONGX booltell=0L; /* 0L = no msg; 1L = tell; 2L = tell+root */
LONGX booltlir=0L; /* b70 invx */
b7_CIB7 *cib7p=NULL;
B7HITLIST *hitlistp; /* hit processing */
LONGX *mfnlistp; /* hit processing */
char booltmpnam[128]={'\0'}; /* b72 MFQTHMEM tmp file */
/* ---------------------------------------------------------------------- */
/* tabs here */
TABFREQF_ENTRY *tabfreqF=NULL; /* indexed by rankF */
TABFREQW_ENTRY *tabfreqW=NULL; /* indexed by rankW */
TABFREQD_ENTRY *tabfreqD=NULL; /* indexed by rankD */
LONGX docsTOTxA; /* v9991[1] = docs de xA - nao vazios */
LONGX docsTOTamdl; /* v9991[2] = docs de amdl */
LONGX count1=0L; /* registros lidos */
LONGX count2=0L; /* casos tabulados */
LONGX drec=0L;
char *gidbnp=NULL;
int parmtrace=0;
/*nu LONGX parmfrom=1,parmto=999999999L,parmcount=0; */
/* -------------------------------------------------------------------------- */
char *deffnamp=NULL;
char *deffmhxp=NULL;
char deffbuffup[ENVASIZE];
char *cipfnamp=NULL;
char *decsdbnp=NULL;
char *amdldbnp=NULL;
char *atmdldbnp=NULL;
char *tmp1dbnp=NULL;
char *pftfnamp=NULL;
char *langp=NULL;
LONGX parmloopTA=0;
LONGX parmtellTA=0;
LONGX parmfromDA=0;
LONGX parmcountDA=0;
char *parmsortp=NULL;
char *parmdownp=NULL;
char *namedbnp=NULL; /* b7x query dbn */
char *boolqryp=NULL; /* bool= */
LONGX boolsetno=0; /* b7x set no. */
int parmatmdl99=0;
char *prmloopTA =NULL;
char *prmfromDA =NULL;
char *prmcountDA=NULL;
char *prmboolset=NULL;
char *prmatmdl99=NULL;
char *actionp=NULL;
int actionCG=0;
int actionDD=0;
int actionTA=0;
int actionDA=0;
int parmdown=0;
/* -------------------------------------------------------------------------- */
char namedbnarea[BUFSIZ];
char dbnoutF[BUFSIZ];
char dbnoutW[BUFSIZ];
char dbnoutD[BUFSIZ];
/* -------------------------------------------------------------------------- */
#if CICGI
char *cgipfxp="tag";
UWORD cgitag=2000;
char *wwwp=NULL;
LONGX wrec;
#endif
/* here we go..
*/
#if CIAPI
ciapip = cisisApplication( MAXNREC,MAXNTRM );/* mandatory for CIAPI definitions */
#endif /* CIAPI */
/* get calling arguments
*/
for (i=0; i < argc; i++) argv[i]=argv_main[i];
/* set watch
*/
vtimid[ntimes]="start"; time(&vtime[ntimes++]); /* watch */
/* set ansiuc & ansiac
*/
#if 1 /* ANSITABS */
memmove(isisuctab,ansiuctab,sizeof(ansiuctab));
memset(isiswctab,0x00,256);
for (isiswctot=0; ansiactab[isiswctot]; isiswctot=isiswctot+1) isiswctab[ansiactab[isiswctot]]=1;
#endif /* 0000 */
/* check if trace is present */
for (i=0; i < argc; i++) {
p=argv[i];
if (strncmp(p,"trace?",6) == 0 || strncmp(p,"trace=",6) == 0) {
if (sscanf(p+6,"%d",&parmtrace) != 1) fatal(p);
if (parmtrace) {
printf("+++trace: trace='%.11s\n'",p);
printf("Content-type: text/plain\n\n");
printf("+++trace: \n");
}
break;
}
}
#ifndef FORCECGI
#define FORCECGI 0
#endif
#if FORCECGI
putenv("REQUEST_METHOD=GET");
/*
putenv("QUERY_STRING=lang=p&action=C%2CTA%2CDA&amdl=amdl351&bool=009068&bool=034268&bool=034269&loop=100&sort=f&from=1&count=20&x=39&y=3");
*/
putenv("QUERY_STRING=lang=p&action=C,TA,DA&amdl=MEDLINE_6687.def&loop=1&bool=006621&sort=f&from=1&count=20");
#endif
/* get CGI data
*/
#if CICGI
RECORD(wrec=nrecs,"null",1L); RECrc=RCNORMAL; MFRstatus=ACTIVE;
wwwp=NULL; cicgi0(&argc, argv, &wwwp, cgitag, cgipfxp);
if (wwwp) {
DIRSTRU *dirp;
int xdir,iocc,loop;
if (fldupdat(wrec,wwwp)) fatal(wwwp);
/* check if trace is present */
for (parmtrace=0, dirp=MFRdir, xdir=0, loop=MFRnvf; loop--; dirp++, xdir++)
if (dirp->tag == cgitag) {
p=FIELDP(xdir);
if (strncmp(p,"^ntrace^v",2+5+2) == 0) {
parmtrace=1;
if (parmtrace) {
printf("+++trace: trace='%.11s\n'",p);
printf("Content-type: text/plain\n\n");
printf("+++trace: \n");
break;
}
}
}
/* check if cgi is enabled */
for (actionCG=0, dirp=MFRdir, xdir=0, loop=MFRnvf; loop--; dirp++, xdir++)
if (dirp->tag == cgitag) {
p=FIELDP(xdir);
if (strncmp(p,"^naction^vC",2+6+2+1) == 0) {
actionCG=1;
if (parmtrace) printf("+++trace: action='%.11s'\n",p);
break;
}
}
if (actionCG) { /* cgi is enabled */
for (dirp=MFRdir, xdir=iocc=0, loop=MFRnvf; loop--; dirp++, xdir++) {
if (dirp->tag == cgitag) {
FFI plen;
p=FIELDP(xdir); plen=dirp->len; iocc++;
/* get CGI by name
*/
if (strncmp(p,"^ncip^v" , 3+4) == 0) cipfnamp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^ndecs^v" , 4+4) == 0) decsdbnp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^namdl^v" , 4+4) == 0) amdldbnp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^natmdl^v" , 5+4) == 0) atmdldbnp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^ntmp1^v" , 4+4) == 0) tmp1dbnp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^npft^v" , 3+4) == 0) pftfnamp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^nlang^v" , 4+4) == 0) langp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^nloop^v" , 4+4) == 0) { prmloopTA =recsfldv(NULL,p,plen,""); parmloopTA =atol(prmloopTA ); }
if (strncmp(p,"^nfrom^v" , 4+4) == 0) { prmfromDA =recsfldv(NULL,p,plen,""); parmfromDA =atol(prmfromDA ); }
if (strncmp(p,"^ncount^v" , 5+4) == 0) { prmcountDA=recsfldv(NULL,p,plen,""); parmcountDA=atol(prmcountDA); }
if (strncmp(p,"^nsort^v" , 4+4) == 0) parmsortp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^ndown^v" , 4+4) == 0) parmdownp =recsfldv(NULL,p,plen,"");
q=NULL;
if (strncmp(p,"^nbool^v" , 4+4) == 0) q =recsfldv(NULL,p,plen,"");
if (q) {
if (boolqryp) {
sprintf(envarea,"%s or %s",boolqryp,q);
boolqryp=strdup(envarea);
}
else boolqryp=q;
}
if (strncmp(p,"^nname^v" , 4+4) == 0) namedbnp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^natmdl99^v", 7+4) == 0) { prmatmdl99=recsfldv(NULL,p,plen,""); parmatmdl99=atoi(prmatmdl99); }
if (strncmp(p,"^naction^v" , 6+4) == 0) actionp =recsfldv(NULL,p,plen,"");
if (strncmp(p,"^nsetno^v" , 5+4) == 0) { prmboolset=recsfldv(NULL,p,plen,""); boolsetno=atol(prmboolset); }
} /* end if (dirp->tag == cgitag) */
} /* end for (dirp=MFRdir) */
} /* end if (cgi is enabled */
} /* end if (wwwp) */
#endif /* CICGI */
/* set default values
*/
#if 0
PATH_DATA=/iah/online/
PATH_CGI-BIN=/users/www/cgi-bin/iah/
#endif
#if UNIX
if (!cipfnamp) cipfnamp = "/users/www/aot/aotmsa2/cip.cip";
if (!decsdbnp) decsdbnp = "decs";
if (!amdldbnp) amdldbnp = "/users/www/data/iah/online/MEDLINE_2001.def";
#else
if (!cipfnamp) cipfnamp = "c:/2001x300/usersaot/cip.cip";
if (!decsdbnp) decsdbnp = "decs";
if (!amdldbnp) amdldbnp = "amdl351";
#endif
if (!atmdldbnp) atmdldbnp = "atmdl";
if (!tmp1dbnp) tmp1dbnp = NULL;
if (!pftfnamp) pftfnamp = "aotmsa2A.pft";
if (!langp) langp = "p";
if (!parmloopTA) parmloopTA = 1;
if (!parmtellTA) parmtellTA = 0; /* */
if (!parmfromDA) parmfromDA = 1;
if (!parmcountDA) parmcountDA = 0;
if (!parmsortp) parmsortp = "f";
if (!parmdownp) parmdownp = "0";
if (!parmatmdl99) parmatmdl99 = 0;
if (!actionp) {actionCG = 0;
actionDD = 0;
actionTA = 0;
actionDA = 0; }
if (!boolsetno) boolsetno = 0;
dbnoutF[0]='\0'; /* .f */
dbnoutW[0]='\0'; /* .w */
dbnoutD[0]='\0'; /* .w */
if (argc < 2 && !wwwp) {
printf("%s",cicopyr("Application AOTMSA2"));
printf(" \n");
printf("aotmsa2 <action>[,...] [<option> [...]] \n");
printf(" \n");
printf("actions: C - get parameters from cgi \n");
printf(" TA - search amdl \n");
printf(" tabulate amdl (v351/) \n");
printf(" store tableF and tableW \n");
printf(" DA - read tableF or tableW \n");
printf(" display formA results \n");
printf(" \n");
printf("options: loop=<n> \n");
printf(" from|count=<n> \n");
printf(" sort={f|w} \n");
printf(" btell|tell=<n> \n");
printf(" bool=<expr> [setno=<n>] \n");
printf(" atmdl99 \n");
printf(" \n");
printf(" cip , %s \n", cipfnamp );
printf(" decs , %s \n", decsdbnp );
printf(" amdl , %s \n", amdldbnp );
printf(" atmdl , %s \n", atmdldbnp );
printf(" tmp1 , %s \n", tmp1dbnp );
printf(" pft , %s \n", pftfnamp );
printf(" lang , %s \n", langp );
printf(" loop , %"_LD_" \n", parmloopTA );
printf(" from , %"_LD_" \n", parmfromDA );
printf(" count , %"_LD_" \n", parmcountDA );
printf(" sort , %s \n", parmsortp );
printf(" down , %s \n", parmdownp );
printf(" bool , %s \n", boolqryp );
printf(" name , %s \n", namedbnp );
printf(" atmdl99, %d \n", parmatmdl99 );
printf(" action , %s \n", actionp );
printf(" setno , %"_LD_" \n", boolsetno );
printf(" \n");
exit(1);
}
/*
get options
*/
for (; argnext < argc; argnext++) {
p=argv[argnext];
if (strncmp(p,"cip?",4) == 0 || strncmp(p,"cip=",4) == 0) {
cipfnamp=p+4;
continue;
}
if (strncmp(p,"decs?",5) == 0 || strncmp(p,"decs=",5) == 0) {
decsdbnp=p+5;
continue;
}
if (strncmp(p,"amdl?",5) == 0 || strncmp(p,"amdl=",5) == 0) {
amdldbnp=p+5;
continue;
}
if (strncmp(p,"atmdl?",6) == 0 || strncmp(p,"atmdl=",6) == 0) {
atmdldbnp=p+6;
continue;
}
if (strncmp(p,"tmp1?",5) == 0 || strncmp(p,"tmp1=",5) == 0) {
tmp1dbnp=p+5;
continue;
}
if (strncmp(p,"pft?",4) == 0 || strncmp(p,"pft=",4) == 0) {
pftfnamp=p+4;
continue;
}
if (strncmp(p,"loop?",5) == 0 || strncmp(p,"loop=",5) == 0) {
if (sscanf(p+5,"%"_LD_,&parmloopTA) != 1) fatal(p);
continue;
}
if (strncmp(p,"from?",5) == 0 || strncmp(p,"from=",5) == 0) {
if (sscanf(p+5,"%"_LD_,&parmfromDA) != 1) fatal(p);
continue;
}
if (strncmp(p,"count?",6) == 0 || strncmp(p,"count=",6) == 0) {
if (sscanf(p+6,"%"_LD_,&parmcountDA) != 1) fatal(p);
continue;
}
if (strncmp(p,"sort?",5) == 0 || strncmp(p,"sort=",5) == 0) {
parmsortp=p+5;
continue;
}
if (strncmp(p,"down?",5) == 0 || strncmp(p,"down=",5) == 0) {
parmdownp=p+5;
if (sscanf(parmdownp,"%d",&parmdown) != 1) fatal(p);
continue;
}
if (!strncmp(p,"bool=",5)) {
q=loadfile(gidbnp,'@',p+5,NULL,0L,'\n');
if (!q) fatal(p);
if (boolqryp) {
sprintf(envarea,"%s or %s",boolqryp,q);
boolqryp=strdup(envarea);
}
else boolqryp=q;
continue;
}
if (strncmp(p,"name?",5) == 0 || strncmp(p,"name=",5) == 0) {
namedbnp=p+5;
strcpy(namedbnarea,namedbnp);
continue;
}
if (strcmp(p,"atmdl99") == 0) {
parmatmdl99=1;
continue;
}
if (strncmp(p,"action?",7) == 0 || strncmp(p,"action=",7) == 0) {
actionp=q=p+7;
if (!*q) fatal(p);
continue;
}
if (strncmp(p,"setno?",6) == 0 || strncmp(p,"setno=",6) == 0) {
if (sscanf(p+6,"%"_LD_,&boolsetno) != 1) fatal(p);
continue;
}
/* offer */
if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) {
if (sscanf(p+5,"%"_LD_,&parmtellTA) != 1) fatal(p);
continue;
}
if (strncmp(p,"btell?",6) == 0 || strncmp(p,"btell=",6) == 0) {
if (sscanf(p+6,"%"_LD_,&booltell) != 1) fatal(p);
continue;
}
if (strcmp(p,"trace") == 0) {
parmtrace=1;
continue;
}
fatal(p);
}
/* actions */
if (actionp) {
for (q=actionp; *q; ) {
if (*q == 'C' && strncmp(q,"C" ,1) == 0)
{ /*actionCG=1;*/ if (*(q+=1) == ',') q++; continue; }
if (isdigit(*q))
{ actionDD=(int)(*q)-(int)'0'; if (*(q+=1) == ',') q++; continue; }
if (*q == 'T' && strncmp(q,"TA",2) == 0)
{ actionTA=1; if (*(q+=2) == ',') q++; continue; }
if (*q == 'D' && strncmp(q,"DA",2) == 0)
{ actionDA=1; if (*(q+=2) == ',') q++; continue; }
if (*q) fatal(p);
}
}
if (parmsortp) {
q=parmsortp;
if (*q == 'g') { parmgroup=1; q++; parmsortp=q; }
if (*q == '1') { parmshowgrp1=1; q++; }
if (*q == 'c') { parmshowcat1=1; q++; }
if (*q == 't') { parmshowtree=1; q++; }
if (*q == 'z') { parmshowzero=1; q++; }
if (strcmp(q,"f") && strcmp(q,"w") && strcmp(q,"d")) fatal(parmsortp);
parmsortx= *q;
}
#if 0
for (q=parmsortp; *q; q++) {
if (*q == 'g') { parmgroup=1; parmsortp=q+1; }
if (*q == '1') { parmshowgrp1=1; }
if (*q == 'c') { parmshowcat1=1; }
if (*q == 't') { parmshowtree=1; }
if (*q == 'z') { parmshowzero=1; }
if (*q == 'f' || *q == 'w' || *q == 'd') { parmsortx= *q; }
}
#endif
if (parmtrace) {
if (amdldbnp) printf("+++trace: amdldbnp=%s\n",amdldbnp);
if (tmp1dbnp) printf("+++trace: tmp1dbnp=%s\n",tmp1dbnp);
printf("+++trace: actionp=%s\n",actionp);
printf("+++trace: actionDD=%d\n",actionDD);
printf("+++trace: actionTA=%d\n",actionTA);
printf("+++trace: actionDA=%d\n",actionDA);
printf("+++trace: sort=%s\n",parmsortp);
printf("+++trace: group=%d\n",parmgroup);
}
/* Common setup
*/
/* get MEDLINE*.def parameters
*/
if (strlen(amdldbnp) > 4) if (strcmp(amdldbnp+strlen(amdldbnp)-4,".def") == 0) {
char loadname[1+BUFSIZ];
char *defarea;
deffnamp=amdldbnp;
sprintf(loadname,"@%s",deffnamp);
defarea=loadfile(gidbnp,'@',loadname,NULL,0L,'\n');
if (!defarea) {
printf("Content-type: text/plain\n\n");
printf("file %s not found \n",deffnamp);
exit(120);
}
/*
FILE DATABASE.*=/base2/mdl/back3/mdl8590.*
FILE MH.*=/base1/mdl/back3/mdlmh%lang%.*
FILE M.*=/base1/mdl/back3/mdlmh.*
*/
p=strstr(defarea,"FILE DATABASE.*=");
if (p) if (strstr((p+=strlen("FILE DATABASE.*="))+1,".*")) {
*(strstr(p+1,".*"))='\0';
amdldbnp=strdup(p);
if (parmtrace) printf("+++trace: amdldbnp=%s\n",amdldbnp);
}
p=strstr(defarea,"FILE MH.*=");
if (p) if (strstr((p+=strlen("FILE MH.*="))+1,"%lang%.*")) {
*(strstr(p+1,"%lang%.*"))='\0'; strcat(p,langp);
deffmhxp=strdup(p);
if (parmtrace) printf("+++trace: deffmhxp=%s\n",deffmhxp);
}
/* free(defarea); */
}
/* set cipar */
if ((dbxcipfp=fopen(cipfnamp,"r")) == NULL) fatal(cipfnamp);
/* rec_maxmfrl */
p=dbxcipar(NULL,"maxmfrl",'='); if (dbxcipok) { sscanf(p,"%"_LD_,&rec_maxmfrl); }
/* set tempfile */
if (tmp1dbnp) strcpy(booltmpnam,tmp1dbnp);
/* set query db */
if (namedbnp) {
if (strncmp(namedbnp,"create=",7) == 0) {
namedbnp+=7;
recisis0(namedbnp);
} else {
int xfd;
dbxopt_fatal=0; xfd=dbxopen("",namedbnp,xx1extp);
if (xfd > 0) CLOSE(xfd); else recisis0(namedbnp);
}
RECORD(boolridx=nrecs,namedbnp,0L);
if (boolsetno < 1 || boolsetno > MF0nxtmfn-1) boolsetno=MF0nxtmfn-1; /* last set */
}
else {
if (!dbxtmpnm("CI_TEMPDIR", 0, namedbnarea)) fatal("aotmsa2/dbxtmpnm");
namedbnp=namedbnarea;
if (parmtrace) printf("+++trace: namedbnp=%s\n",namedbnp);
recisis0(namedbnp);
boolsetno=1L; /* set#1 */
}
/* make output file names
*/
sprintf(dbnoutF,"%s%s",namedbnp,".f");
sprintf(dbnoutW,"%s%s",namedbnp,".w");
sprintf(dbnoutD,"%s%s",namedbnp,".d");
parmdown=atoi(parmdownp);
if (parmdown < 0x00 || parmdown > 0xFF) parmdown=0;
/* ======================= ============= ================== */
/* ======================= ============= ================== */
if (actionTA) {
/* Tabulate A
*/
/* init docsTOTamdl - number of docs in Cluster MDL */
/* init reading */
if (!irec) irec=nrecs;
RECORD(irec,amdldbnp,0L);
docsTOTamdl=MF0nxtmfn-1;
if (parmatmdl99) {
RECSTRU *recp;
TRMSTRU *trmp;
LONGX /*nu irec,*/itrm;
char *p;
TERM(itrm=ntrms,atmdldbnp,"999999"); if (TRMrc != RCNORMAL) fatal("aotmsa2/atmdl/TERM");
RECORD(/*nu irec=*/nrecs,atmdldbnp,posting(itrm,1)); if (TRMrc != RCNORMAL) fatal("aotmsa2/atmdl/RECORD");
p=recfield(NULL,boolridx,ATMDLTAG999,1,"");
docsTOTamdl = atol(p); if (docsTOTamdl < 1) fatal("aotmsa2/atmdl/999999");
}
/* init docsTOTxa - number of docs in Cluster A */
docsTOTxA=docsTOTamdl;
vtimid[ntimes]="search"; time(&vtime[ntimes++]); /* watch */
/*
Search "bool=" parameter
*/
if (boolqryp) { /* mxbool/boolh */
RECSTRU *recp;
char *p;
LONGX mfn;
int errno;
LONGX asize=strlen(amdldbnp) + /* field MFQTDBN0=11 (may be longer than 128+4+1) */
strlen(boolqryp) + /* the expression */
2*strlen(boolqryp) + /* the terms + pseudo operators _1termX+11X */
BUFSIZ+strlen(amdldbnp) + /* field MFQSWDBN=20 + a diferent db */
24*(strlen(B7DELADD)+3*B7UPLEN) + /* 2 duzias de control fields */ /* DxxAxx|xxx| */
strlen(boolqryp)+4 + /* tmpfile .%03x */
BUFSIZ; /* por si las moscas */
char *buffup=loadfile(NULL,'@',"",NULL,asize,'\0');
cib7p=b7_cib7(cib7p,ciapip);
/* initialize ridx and b7_xxx() parameters and run b7_run()
*/
for (boolridx=nrecs, mfn=1; ; mfn++) { /* get actual maxmfn */
RECORD(boolridx,amdldbnp,mfn);
if (RECrc == RCEOF) fatal(amdldbnp);
if (RECrc == RCNORMAL) break;
}
if (namedbnp) {
if (!booldbcrec) booldbcrec=nrecs;
/*RECORD(booldbcrec,namedbnp,0L); */ /* b7_exp faz "record(crec,qrydbnp,0L)"
(se houver "qrydbnp")
*/
/*<R>
vrecp[boolridx]->recdbxp=RECdbxp;
*/ /* VRECdbxp(boolridx)=RECdbxp; */ /* b7_exp faz "RECdbxp = dbxstorp(qrydbnp)" */
}
else {
VRECdbxp(boolridx)=NULL; /* nao usa base de log */
VMFRmfn(boolridx)=0L;
}
/* run b7_exp() / b7_run() / b7_hit(0)
*/
p=b7_exp(cib7p,boolridx,amdldbnp,boolqryp,buffup,namedbnp,booldbcrec,&errno);
if (p || errno) printf("Expression syntax error %d: '%s'\n",errno,p);
else {
LONGX bufsiz;
/* .. sprintf(buffup,"%s.%03x",RDBname,(int)b7setno) .. */
char *hitfnamp="null";
if (booltmpnam[0]) hitfnamp=booltmpnam;
sprintf(buffup,"D%dA%d|%s|",MFQTHMEM,MFQTHMEM,hitfnamp);
if (fldupdat(boolridx,buffup) != NULL) fatal("aotmsa2/fldupdat/boolridx");
/* b7_run faz "trirecp=vrep[tlirec]" */
if (!booltlir) record(booltlir=nrecs,"null",1L);
/* set default index to actual INDEX MH= */
if (deffmhxp) {
char buffup[BUFSIZ+CIMPL];
sprintf(buffup,"A101|^p*^y%s|",deffmhxp);
if (fldupdat(booltlir,buffup)) fatal("aotmsa2/booltlir/fldupdat");
}
/* alloc buffer for 20000 hits = 80Kbytes */
bufsiz=20000*sizeof(LONGX);
if (b7bufferp) b7_hbfree(cib7p,&b7bufferp);
b7_hballoc(cib7p,bufsiz,&b7bufferp);
deffbuffup[0]='\0';
#if 1
/* translate DecsMfn to MH
*/
if (deffmhxp) {
char *batchp=deffbuffup;
size_t left=sizeof(deffbuffup);
int xdir;
sprintf(batchp,"D%dA%d|",MFQTOBJ0,MFQTOBJ0); batchp+=strlen(batchp);
if ((xdir=fieldx(boolridx,MFQTOBJ0,1)) >= 0) {
char *b7p;
LONGX v351;
for (b7p=(unsigned char *)FIELDP(xdir); *b7p; ) {
if (*b7p == OPRXEND) break;
if (*b7p != ZLDV) {
*batchp++ = *b7p++; /* move other */ left--;
continue;
}
*batchp++ = *b7p++; /* move b7opr */ left--;
*batchp++ = *b7p++; /* move postlen */ left--;
v351=atol(b7p);
while (*b7p != OPRNULL) b7p++; /* skip DecsMfn */
if (v351) {
if (!drec) drec=nrecs;
record(drec,decsdbnp,v351);
recfield(batchp,drec,DECSTAGNAME(langp),1,""); batchp[LE2]='\0'; /* move MH */
while (*batchp) { *batchp=isisuctab[*batchp]; batchp++; left--; }
}
*batchp++ = *b7p++; /* move OPRNULL */ left--;
} /* end for (b7p) */
*batchp++ = *b7p++; /* move OPRXEND */
} /* end if (xdir) */
sprintf(batchp,"|" ); /*nu batchp+=strlen(batchp); */
} /* end if (deffmhxp) */
#endif
/* run search */
p=b7_run(cib7p,boolridx,amdldbnp,buffup,asize,
booltell,isisuctab,deffbuffup/*btch0p*/,booltlir,booldbcrec,&errno);
if (p || errno) printf("Execution error %d: '%s'\n",errno,p);
else {
boolhits=b7bufferp->ndocs; /* b7_hit(cib7p,boolridx,0L,b7setno); */
if (booltell) printf("Hits=%"_LD_"\n",boolhits);
}
}
if (p || errno) fatal("Expression execution error");
/* set# */
boolsetno=b7setno; /* last mfn */
/* set docsTOTxa - number of docs in Cluster A */
docsTOTxA=boolhits;
} /* mxbool/boolh */
vtimid[ntimes]="set"; time(&vtime[ntimes++]); /* watch */
/* init tabcntMDL
*/
if (parmloadmdl) {
/* loadcnt(amdldbnp,treecase,tabcntMDL,CLASSES);
AMDL351 CNT 52 12-21-01 9:54p amdl351.cnt
AMDL351 N01 21,216 12-21-01 10:00p amdl351.n01
AMDL351 N02 0 12-21-01 10:00p amdl351.n02
AMDL351 LY1 269,064 12-21-01 9:55p amdl351.ly1
AMDL351 LY2 0 12-21-01 9:55p amdl351.ly2
AMDL351 IYP 48,611,328 12-21-01 9:55p amdl351.iyp
*/
int treecase=0;
INVMAP *invp;
LONGX punt,punt2;
char lparea[sizeof(L1STRU)];
L1STRU *l1p=(L1STRU *)lparea;
int loop;
char *keyp;
int v351;
LONGX ndocs;
LONGX tell=0;
memset(tabcntMDL,0x00,sizeof(tabcntMDL));
invsetup(amdldbnp,0L,0L,0L);
invp=dbxstorp(amdldbnp)->dbxifmap;
if (parmtellTA) tell=(punt2=invp->cn[treecase].fmaxpos)/10+1;
if (parmtrace) fprintf(stderr,"+++ punt2=%"_LD_"\n",punt2);
/* for each leaf */
for (punt=1; punt; punt=l1p->ps) {
leafread(lparea,invp,treecase,punt,0); /* read a leaf */
/* for each term */
for (loop=0; loop < l1p->ock; loop++) {
keyp=l1p->idx[loop].key;
v351=atoi(keyp); /* LE1 */
ndocs=l1p->idx[loop].info2;
tabcntMDL[v351]=ndocs;
}
if (parmtrace) if (tell) if (punt%tell==0) fprintf(stderr,"+++ punt=%"_LD_"\n",punt);
}
memset(tabcntGMDL,0x00,sizeof(tabcntGMDL));
if (parmgroup) {
RECSTRU *recp;
LONGX irec=nrecs;
LONGX mfn;
char x351[6+1];
LONGX v351;
DIRSTRU *dirp;
int xdir,loop;
for (mfn=1; ; mfn++) {
RECORD(irec,"group01.f",mfn);
if (RECrc == RCEOF) break;
if (RECrc != RCNORMAL) continue;
/* get total records for each group */
#define G01TAG999 999
#define G01TAG001 1
for (dirp=MFRdir, xdir=0, loop=MFRnvf; loop--; dirp++, xdir++) {
if (dirp->tag == G01TAG999) {
LONGX ndocs=0;
char *p=FIELDP(xdir);
int loop;
for (loop=dirp->len; loop--; p++) ndocs=ndocs*10+((int)(*p)-(int)'0');
recfield(x351,irec,G01TAG001,1,""); v351=atol(x351);
tabcntGMDL[v351]=ndocs;
#if 0
printf("+++tabcntGMDL[%"_LD_"]=%"_LD_"\n",v351,tabcntGMDL[v351]);
getchar();
#endif
break;
} /* end tag == 999 */
} /* end for dirp */
} /* end for mfn */
}
/* VTABV05*/
memset(vcategmfn,0x00,sizeof(vcategmfn));
memset(vtabv05len,0x00,sizeof(vcategmfn)); ntabv05=0;
}
/* init mxtb
*/
memset(tabcntA,0x00,sizeof(tabcntA));
memset(gtabcntA,0x00,sizeof(gtabcntA));
/* create output
*/
recisis0(dbnoutF);
recisis0(dbnoutW);
recisis0(dbnoutD);
vtimid[ntimes]="loop"; time(&vtime[ntimes++]); /* watch */
/*
loop principal
*/
#define MAXN20 30
#define MAXZ20 12 /* hoje=10 (1*3+9*4=39) */
#define MAXL20 (MAXZ20*4)
#define MAXNVG 30
#define MAXN05 30
for (boolh=1; boolh <= boolhits; boolh+=parmloopTA) {
LONGX mfn;
int v351,v351nocc,xdir,loop;
DIRSTRU *dirp;
char area[BUFSIZ];
LONGX vgmfns[MAXNVG];
int nvgs=0;
int ivg;
/* hit processing */