root/trunk/serx3.c

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

essage first commit

Line 
1/* ------------------------------ serc.c ---------------------------------- */
2
3
4/* Copyright (c) 1990 - 1994 Adalberto Otranto Tardelli. All rights reserved.
5 * Written by A.O.Tardelli 7/90
6 * Redistribution and use in source and binary forms are freely permitted
7 * provided that the above copyright notice and attribution and date of work
8 * and this paragraph are duplicated in all such forms.
9 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
10 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
11 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 * This program performs a MicroISIS master file dump, formatted display,
13 * search and record limits, pattern changes, data base join, field update,
14 * master file update and ISO-2709 processing. Input can also be a plain file.
15 * A description of this program is available in CISIS Interface Application -
16 * MX Program. Sao Paulo, BIREME - Latin American and Caribbean Center on
17 * Health Sciences Information/PAHO-WHO, April 1991. 12p. See also:
18 * - http://www.bireme.br (IsisFamily/CisisUtilities)
19 * - ftp://ftp.bireme.br/cisis
20 * Currently works with CISIS Interface 4.01 and BorlandC 5.02 or
21 * MSVC 6.0 for win32/console application, and for Linux/gcc, HPUX/CC and
22 * Sun/CC, among other platforms.  AOT, 21/02/2001.
23*/
24
25/*
26..Client program that makes a connection for a byte stream socket in the Internet namespace.
27*/
28/*
29*/
30
31#include <stdio.h>
32#include <ctype.h>                                                        .
33#include <string.h>
34#include <time.h>
35
36#include "cisis.h"      /* CISIS Interface header file */
37#include "cirun.h"      /* CISIS Interface runtime declarations */
38//#include "cihsh.h"      /* CISIS Interface hashing & binary table search */
39
40#if !PC
41#include "ciupdsocx.c"  /* CISIS socket mainclient() */
42#endif
43
44#if GCC
45#define PGCC  1
46#else
47#define uint16_t unsigned short
48#endif
49
50#define PORT            1417
51#define MESSAGE         "wtrig2 ... text=..."
52#define SERVERHOST      "serverofi.bireme.br"
53
54
55#define TAG1   1
56#define TAG2   2
57#define TAG23  2
58
59#define FATRAP__WT 1
60
61void serc_syntax(void);
62void serc_syntax()
63{
64}
65
66
67int
68main(int argc, char *argv[])
69{
70    RECSTRU *recp; /* mandatory for defines REC RDB MF0 MFR DIR, FIELDP */
71    LONGX irec=0;
72
73    LONGX maxmfrl=MAXMFRL;   // default
74
75    char serverhost[CIMPL]; //=SERVERHOST;
76    uint16_t port=PORT;
77    LONGX xval;
78
79    char *wwwcgip=NULL;     // allocated in cicgi0
80    char *parmwtmsg=NULL;   // wtrig2 command line - calling argument wtrig2
81    char *wtmsg=NULL;   // wtrig2 command line - allocated if not parmwtmsg
82
83    char *parmhtmsg=NULL;   // http command line - calling argument http
84    char *htmsg=NULL;       // http command line - allocated if not parmhtmsg
85
86    char *parmxtmsg=NULL;   // xttt command line - calling argument xttt
87    char *xtmsg=NULL;       // xttt command line - allocated if not parmxtmsg
88
89    int debug=0;
90    char force[BUFSIZ+CIMPL] = { '\0' };
91    int outfmthtml=0;
92
93    char *txtvp="";        // text parameter
94    int txtvlen=0;         // text parameter
95    char *txt1vp="";        // text1 parameter
96    int txt1vlen=0;         // text1 parameter
97
98    char *p,*q,*x;
99    char *hhp;
100//    char *hdatap;
101
102    int len,y;
103    char *np,*vp;
104    int nlen,vlen;
105    int npairs; //=0;
106
107    char *buffer;//=NULL    // reply from mainserver/wtrig2
108    int buffersize;
109
110    char *cgimsg=NULL;      // reply from mainserver/wtrig2
111    LONGX cgimsgsize;
112
113    char *databuff;//=NULL    // reply from mainserver/wtrig2
114    int databuffsize;
115
116    char *textbuff;//=NULL    // reply from mainserver/wtrig2
117    int textbuffsize;
118    char *tbp;
119
120    char *pcmdp;
121    char *procp;
122    char *pftxp;
123   
124    LONGX dbmfn=1;
125    int dbtag=1;
126    int dbocc=1;
127    int dboc2=0;
128    char dbname[CIMPL+1] = { '\0' };
129
130    int rc; //=0;
131    int i;
132   
133    int mustclose=0;
134   
135    time_t secs_now;
136    time_t secs_start,secs_end;
137    struct tm *tp;
138
139#if FATRAP__WT
140    int     z_xerrno;
141    int     z_errcod;
142    char    z_iomsg[MAXFATML+1];
143    jmp_buf z_jumper;
144    int     z_jumprc;
145#endif
146
147#if FATRAP__WT
148     /* save/notrap */
149     strcpy(z_iomsg,fatal_iomsg); memcpy(z_jumper,fatal_jumper,sizeof(fatal_jumper)); z_errcod=fatal_errcod;
150     z_xerrno=dbxopt_errno;
151     /* trap cisis fatal() */
152     strcpy(fatal_iomsg,"trap");
153     /* disable dbxopen msg */
154     dbxopt_errno=0;
155     z_jumprc = setjmp(fatal_jumper);
156     if (z_jumprc != 0) {
157         /* error */
158         if (outfmthtml) {
159             printf("error type=\"fatal\" in=\"serx\" code=\"%d\" error=\"%s\"\n",fatal_errcod,fatal_iomsg);
160             if (mustclose) printf("</pre></body></html>\n");
161         }
162         else {
163             printf("<error type=\"fatal\" in=\"serx\" code=\"%d\">%s</error>\n",fatal_errcod,fatal_iomsg);
164             if (mustclose) {
165                 printf("</request>\n");
166                 printf("</serc>\n");
167             }
168         }
169         /* restore/notrap */  //strcpy(fatal_iomsg,"");
170         memcpy(fatal_jumper,z_jumper,sizeof(fatal_jumper)); strcpy(fatal_iomsg,z_iomsg);
171         fatal_errcod=z_errcod;
172         dbxopt_errno=z_xerrno;
173         return (-1);
174     }
175
176#endif
177
178    /* init
179    */
180    strcpy(serverhost,SERVERHOST);
181
182    /* get secs_ for elapsed */
183    secs_start=time(&secs_now);
184    tp=localtime(&secs_start);
185
186    /* go
187    */
188    for (i=1; i < argc; i++) {
189        p=argv[i];
190        if (strcmp(p,"hello") == 0) {
191            //serc_syntax();
192            printf("%s",cicopyr("Utility SERC"));
193            printf("\n");
194            printf("serc [hello] [debug] [cipar=<file>] \n");
195            printf("     [port=1417|<port>] \n");
196            printf("     [host=localhost|<host>]  \n");
197            printf("     \"wtrig2 c=col [maxrel=n] [minsim=0.n] [text1=x] [text=x]\" \n");
198            printf("     [db=x] [mfn=n] [tag=n] [occ=n] [oc2=n] [proc.n=text] [pft.n=text] [pcmd.n=text] \n");
199            printf("\n");
200            exit(1);
201        }
202        if (strncmp(p,"force=",6) == 0) {
203            int len=strlen(force);
204            if (len) force[len]='&';
205            else     strcpy(force,"QUERY_STRING=\"");
206            strcat(force,p+6);
207            strcat(force,"\"");
208            continue;
209        }
210        if (strcmp(p,"debug") == 0) {
211            debug=1;
212            continue;
213        }
214        if (strncmp(p,"cipar=",6) == 0) {
215            if ((dbxcipfp=fopen(p+6,"r")) == NULL) fatal(p);
216            continue;
217        }
218        if (strncmp(p,"port=",5) == 0) {
219            if (sscanf(p+5,"%"_LD_,&xval) != 1) fatal(p);
220            port=(uint16_t)xval;
221            continue;
222        }
223        if (strncmp(p,"host=",5) == 0) {
224            if (!*(p+5)) fatal(p);
225            strcpy(serverhost,p+5);
226            continue;
227        }
228        if (strncmp(p,"wtrig2 ",6) == 0) {
229            parmwtmsg=p;
230            continue;
231        }
232        if (strncmp(p,"xttp ",5) == 0) {
233            parmxtmsg=p;
234            continue;
235        }
236        parmhtmsg=p;
237        //if (strncmp(p,"http ",5) == 0) {
238        //    continue;
239        //}
240        //printf("Content-type: text/plain\n\n");
241        //fatal(p);
242    }
243   
244   
245        if (*force) {
246            putenv("REQUEST_METHOD=GET");
247            putenv(force);
248//putenv("QUERY_STRING=wtrig2=on&c=lilrelff&text1=Jose+Meio+Silva&text=titulo+1%0D%0A%0D%0Atitulo+2%0D%0Atitulo+3%0D%0A&maxrel=3&minsim=0.20&serc.go=submit");
249//putenv("QUERY_STRING=wtrig2=on&collection=lilrelff&text1=Jos%E9+da+Silva+Junior&text=Publica%E7%E3o+eletr%F4nica+hoje%0D%0AElectronic+publishing+today%0D%0AOn+the+Virtual+Health+Library&maxrel=3&minsim=0.20&serc.go=submit");
250//putenv("QUERY_STRING=procs=on&cipar=serx.cip&db=xdb&pft=1");
251//putenv("QUERY_STRING=wtrig2=on&cipar=similar/jdlilacs.cip&collection=lilrelff&text1=Jose+da+Silva+Junior&text=Publicacao+eletronica+hoje%0D%0AElectronic+publishing+today%0D%0AOn+the+Virtual+Health+Library&maxrel=3&minsim=0.20&serc.goxml=submit");
252//wtrig2=on&c=xLILACS&port=1818&minsim=0.40&text=SUS%20UNIC
253#if 0
254./serx "force=wtrig2=on c=xLILACS port=1818 minsim=0.40 text=SUS%20UNIC"
255
256./serx "force=wtrig2=on c=xLILACS port=1715 minsim=0.40 text=SUS%20UNIC"
257
258./serwx port=1715 cipar=serw.cip tell
259
260cd ..
261./serx port=1715 "wtrig2 c=xLILACS minsim=0.70 maxrel=200 tell=1 text=AIEPI"
262
263./serx port=1714 "wtrig2 c=xLILACS minsim=0.10 maxrel=10 tell=1 trace1 text=AIEPI"
264
265./serx port=1714 "wtrig2 c=xLILACS minsim=0.10 maxrel=200 tell=1 text=AIEPI"
266
267./serx port=1714 "wtrig2 c=xLILACS minsim=0.10 maxrel=200 tell=1 text=AIEPI"
268wtrig2=on&c=xLILACS&port=1714&minsim=0.30&maxrel=8&text=diabetes%20melli
269
270"wtrig2 c=xLILACS minsim=0.10 maxrel=200 tell=1 text=AIEPI"
271
272http://serverofi.bireme.br/cgi-bin/similar/serc?wtrig2=on&port=1715&c=xLILACS&text=AIEPI&maxrel=50&minsim=0.30
273http://serverofi.bireme.br/cgi-bin/serx?wtrig2=on&port=1714&c=xLILACS&text1=.&text=AIEPI&maxrel=10&minsim=0.30
274 
275
276export REQUEST_METHOD=GET
277export QUERY_STRING="port=1715&wtrig2=on&c=xLILACS&minsim=0.10&maxrel=10&tell=1&&text=AIEPI"
278./serx
279
280
281
282
283./serc port=1714 "wtrig2 c=xLILACS minsim=0.10 maxrel=20 tell=1 text=AIEPI"
284
285./serx port=1714 "wtrig2 c=xLILACS minsim=0.10 maxrel=20 tell=1 text=AIEPI"
286
287http://serverofi.bireme.br/cgi-bin/serx?port=1715&wtrig2=on&c=xLILACS&minsim=0.10&maxrel=20&tell=1&text=AIEPI
288
289 cd similar/
290 ./serc port=1715 "wtrig2 c=xLILACS minsim=0.10 maxrel=20 tell=1 trace1 text=AIEPI"
291 cd ..
292 ./serx port=1715 "wtrig2 c=xLILACS minsim=0.10 maxrel=20 tell=1 text=AIEPI"
293
294
295nohup ./serwx port=1727 cipar=serw.cip tell &
296sleep 1
297cd ..
298./serx port=1727 "wtrig2 c=xLILACS minsim=0.10 maxrel=27 tell=1 text=AIEPI"
299cd similar
300
301http://serverofi.bireme.br/cgi-bin/serx?port=1727&wtrig2=on&c=xLILACS&minsim=0.01&maxrel=50&tell=1&text=AIEPI
302
303#endif
304        }
305
306       
307    /* setup alloc
308    */
309    p=dbxcipar(NULL,"maxmfrl",'='); if (dbxcipok) sscanf(p,"%"_LD_,&maxmfrl);
310    if (maxmfrl < (LONGX)MSNVSPLT || (RECHSIZE+maxmfrl) > ALLOMAXV) maxmfrl=MAXMFRL;
311    rec_maxmfrl=maxmfrl;
312    //fmt_fsiz=maxmfrl;
313    cgimsgsize=maxmfrl;
314    buffersize=(int)maxmfrl;
315
316    // alloc reply buffer / move nul to 1st byte
317    buffer=loadfile(NULL,'@',"",NULL,(LONGX)buffersize,'\0');
318    if (!buffer) fatal("serc/alloc/buffer");
319
320    // alloc reply databuff / move nul to 1st byte
321    databuff=loadfile(NULL,'@',"",NULL,(LONGX)databuffsize=buffersize,'\0');
322    if (!databuff) fatal("serc/alloc/databuff");
323
324    // alloc reply textbuff / move nul to 1st byte
325    textbuff=loadfile(NULL,'@',"",NULL,(LONGX)textbuffsize=buffersize,'\0');
326    if (!textbuff) fatal("serc/alloc/textbuff");
327
328    /* reply header
329    */
330    if (outfmthtml) {
331        printf("Content-type: text/html\n\n");
332        printf("<html><body><pre>\n");
333    }
334    else {
335        //printf("Content-type: text/plain\n\n");
336        printf("Content-type: text/xml\n\n");
337        printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n");
338        printf("<serc cisis=\"CIFFI\" version=\"4.4a\" date=\"%04d%02d%02d\" time=\"%02d%02d%02d\">\n",
339            1900+tp->tm_year,tp->tm_mon+1,tp->tm_mday,tp->tm_hour,tp->tm_min,tp->tm_sec);
340        printf("<request>\n");
341    }
342    mustclose=1;
343
344    /* setup wtrig2 parms
345    */
346    if (!parmwtmsg) {
347        /* get CGI data
348        */
349        p=getenv("REQUEST_METHOD"); if (debug) if (p) printf("<debug getenv=\"REQUEST_METHOD\"><![CDATA[ %s ]]></debug>\n",p);
350        q=getenv("QUERY_STRING");   if (debug) if (q) printf("<debug getenv=\"QUERY_STRING\"><![CDATA[ %s ]]></debug>\n",q);
351        if (p) cicgi0(NULL, NULL, &wwwcgip, (UWORD)2000, "tag");  // H1 10 ^ndbn^vcdsH1 10 ^ncount^v2H1 7 ^nnow^vH1 10 ^nbtell^v0H1 20 ^nbool^vplants*waterH1 15 ^npft^vmfn/v24/
352        if (debug) if (!wwwcgip) printf("+++ wwwcgip=%s<br />\n","void");
353
354        //internal parms - execute
355        if (wwwcgip) {
356            np=strstr(wwwcgip,"^ndebug^v");
357            if (np) {
358                for (xval=0,p=np+9; *p && isdigit(*p); p++) xval=xval*10+(int)(*p)-(int)'0';
359                debug=(int)xval;
360            }
361           
362            np=strstr(wwwcgip,"^ncipar^v");
363            if (np) {
364                for (vlen=0,vp=p=np+9; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
365                if (vlen) { char c=vp[vlen]; vp[vlen]='\0'; if ((dbxcipfp=fopen(vp,"r")) == NULL) fatal(vp); vp[vlen]=c; }
366            }
367            if (!dbxcipfp) if ((dbxcipfp=fopen("serx.cip","r")) == NULL) fatal("serx.cip");
368           
369            np=strstr(wwwcgip,"^nport^v");
370            if (np) {
371                for (xval=0,p=np+8; *p && isdigit(*p); p++) xval=xval*10+(int)(*p)-(int)'0';
372                port=(uint16_t)xval;
373            }
374            np=strstr(wwwcgip,"^nhost^v");
375            if (np) {
376                for (vlen=0,vp=p=np+8; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
377                if (vlen) { memcpy(serverhost,vp,vlen); serverhost[vlen]='\0'; }
378            }                                         
379        } // end wwwcgip
380
381       
382        //drive mainserver to procs
383        if (wwwcgip) if (strstr(wwwcgip,"^nprocs^von") || strstr(wwwcgip,"^ntagtext^v") || strstr(wwwcgip,"^ntagtext1^v")
384             || strstr(wwwcgip,"^ndb^v") || strstr(wwwcgip,"^nmfn^v") || strstr(wwwcgip,"^ntag^v") 
385             || strstr(wwwcgip,"^nocc^v") || strstr(wwwcgip,"^noc2^v") 
386             || strstr(wwwcgip,"^npcmd^v") || strstr(wwwcgip,"^nproc^v") || strstr(wwwcgip,"^npft^v") ) {
387
388            if (debug) printf("+++ wwwcgip=%s<br />\n",wwwcgip);
389
390            np=strstr(wwwcgip,"^ndb^v");
391            if (np) {
392                for (vlen=0,p=np+6; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
393                memcpy(dbname,np+6,vlen); dbname[vlen]='\0';
394            }
395            np=strstr(wwwcgip,"^nmfn^v");
396            if (np) {
397                for (dbmfn=0,p=np+7; *p && isdigit(*p); p++) dbmfn=dbmfn*10+(int)(*p)-(int)'0';
398            }
399            np=strstr(wwwcgip,"^ntag^v");
400            if (np) {
401                for (dbtag=0,p=np+7; *p && isdigit(*p); p++) dbtag=dbtag*10+(int)(*p)-(int)'0';
402            }
403            np=strstr(wwwcgip,"^nocc^v");
404            if (np) {
405                for (dbocc=0,p=np+7; *p && isdigit(*p); p++) dbocc=dbocc*10+(int)(*p)-(int)'0';
406            }
407            np=strstr(wwwcgip,"^noc2^v");
408            if (np) {
409                for (dboc2=0,p=np+7; *p && isdigit(*p); p++) dboc2=dboc2*10+(int)(*p)-(int)'0';
410            }
411           
412            //read
413            if (!dbname[0]) strcpy(dbname,"null");
414            if (dbmfn <= 0) dbmfn=1;
415            RECORD(irec,dbname,dbmfn);
416//            if (RECrc != RCNORMAL || MFRstatus != ACTIVE) {
417//                RECrc=RCNORMAL; MFRstatus=ACTIVE; MFRnvf=0;
418//            }
419
420            //sort dir entries
421            if (fldupdat(irec,"S")) fatal("mxget/read/S");
422           
423            //convert entities
424            if (fldupdat(irec,"Gserxgiz0")) fatal("mxget/read/Gserxgiz0");
425           
426            //add cgi data
427            if (fldupdat(irec,wwwcgip)) fatal("mxget/read/wwwcgip");
428
429            textbuff[0]='\0'; tbp=textbuff;
430            np=strstr(wwwcgip,"^ntagtext^v");
431            if (np) {
432                for (vlen=0,p=vp=np+11; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
433                if (isdigit(*vp)) {
434                    int iocc=1,tag=atoi(vp);
435                    for (; *recfield(tbp+strlen(tbp),irec,tag,iocc,""); iocc++) {
436                        strcat(tbp,". ");
437                    }
438                }
439                else {
440                    char k=vp[vlen];
441                    vp[vlen]='\0';
442                    rc=recfmt(irec,textbuffsize,vp,tbp,textbuffsize);
443                    vp[vlen]=k;
444                    if (rc < 0) fatal("mxget/tagtext/recfmt");
445                }
446                txtvlen=strlen(tbp);
447                if (txtvlen) { txtvp=tbp; tbp+=txtvlen; }
448                *++tbp='\0';
449            }
450            np=strstr(wwwcgip,"^ntagtext1^v");
451            if (np) {
452                for (vlen=0,p=vp=np+12; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
453                if (isdigit(*txt1vp)) {
454                    int iocc=1,tag=atoi(txt1vp);
455                    for (; *recfield(tbp+strlen(tbp),irec,tag,iocc,""); iocc++) {
456                        strcat(tbp,"\n");
457                    }
458                }
459                else {
460                    int rc;
461                    char k=vp[vlen];
462                    vp[vlen]='\0';
463                    rc=recfmt(irec,textbuffsize,vp,tbp,textbuffsize);
464                    vp[vlen]=k;
465                    if (rc < 0) fatal("mxget/tagtext/recfmt");
466                }
467                txt1vlen=strlen(tbp);
468                if (txt1vlen) { txt1vp=tbp; tbp+=txt1vlen; }
469                *++tbp='\0'; 
470            }
471
472            pcmdp=strstr(wwwcgip,"^npcmd^v");
473            procp=strstr(wwwcgip,"^nproc^v");
474            pftxp=strstr(wwwcgip,"^npft^v");
475
476            *buffer='\0';           
477
478            //default is dump field 1
479            if (!txtvlen) if (!txt1vlen)
480            if (!pcmdp) if (!procp) if (!pftxp) {
481                int xdir,len=0;
482                int tag=1;
483                int occ=1;
484                int oc2=occ;
485                if (dbtag>0) tag=dbtag;
486                if (dbocc>0) {occ=dbocc; oc2=occ;}
487                if (dboc2>0) {oc2=dboc2; if (oc2<occ) oc2=occ;}
488                for (; occ <= oc2; occ++) {
489                    xdir=fieldx(irec,tag,occ);
490                    if (xdir < 0) break;
491                    memcpy(buffer,FIELDP(xdir),len=DIRlen(xdir)); buffer[len]='\0';
492                    printf("%s\n",buffer);
493                }
494            }
495           
496            np=strstr(wwwcgip,"^nproc^v");
497            if (np) {
498                for (vlen=0,p=vp=np+8; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
499                if (vlen) {
500                    char k=vp[vlen];
501                    vp[vlen]='\0';
502                    rc=recfmt(irec,databuffsize,vp,databuff,databuffsize);
503                    vp[vlen]=k;
504                    if (rc < 0) fatal("mxget/procs/proc/recfmt");                   
505                    if (fldupdat(irec,databuff)) fatal("mxget/procs/proc/fldupdat");           
506                }
507            }
508            np=strstr(wwwcgip,"^npcmd^v");
509            if (np) {
510                for (vlen=0,p=vp=np+8; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
511                if (vlen) {
512                    char k=vp[vlen];
513                    vp[vlen]='\0';
514                    if (fldupdat(irec,vp)) fatal("mxget/procs/pcmd");           
515                    vp[vlen]=k;
516                }
517            }
518           
519            np=strstr(wwwcgip,"^npft^v");
520            if (np) {
521                for (vlen=0,p=vp=np+7; *p; p++) if (strncmp(p,"H2000 ",6) == 0) break; else vlen++;
522                *buffer='\0';
523                if (strncmp(vp,"all",3) == 0) {
524                    int xdir,loop;
525                    int xocc=0,lastag=0;
526                    sprintf(buffer+strlen(buffer),"<file name=\"%s\">",dbname);
527                    sprintf(buffer+strlen(buffer),"<record mfn=\"%"_LD_"\" mfrl=\"%"_LD_"\" nvf=\"%d\" status=\"%s\">",
528                                MFRmfn,(LONGX)MFRmfrl,MFRnvf,(MFRstatus == ACTIVE) ? "active" : "deleted");
529                    if (MFRstatus == ACTIVE) { 
530                        sprintf(buffer+strlen(buffer),"<fields>\n");
531                        for (xdir=0, loop=MFRnvf; loop--; xdir++) {
532                            int xtag=DIRtag(xdir);
533                            if (!debug) if (xtag == 2000) continue;
534                            if (xtag == lastag) xocc++; else { lastag=xtag; xocc=1; }
535                            sprintf(buffer+strlen(buffer),"<field tag=\"%u\" occ=\"%d\">",DIRtag(xdir),xocc);
536                            memcpy(buffer+strlen(buffer),FIELDP(xdir),DIRlen(xdir));
537                            sprintf(buffer+strlen(buffer),"</field>\n");
538                        }
539                        sprintf(buffer+strlen(buffer),"</fields>\n");
540                    }
541                    sprintf(buffer+strlen(buffer),"</record>\n");
542                    sprintf(buffer+strlen(buffer),"</file>\n");
543                }
544                else 
545                if (isdigit(*vp)) {
546                    int iocc=1,tag=atoi(vp);
547                    for (; *recfield(buffer+strlen(buffer),irec,tag,iocc,""); iocc++) {
548                        strcat(buffer,"\n");
549                    }
550                }
551                else {
552                    char k=vp[vlen];
553                    vp[vlen]='\0';
554                    rc=recfmt(irec,buffersize,vp,buffer,buffersize);
555                    vp[vlen]=k;
556                    if (rc < 0) fatal("mxget/procs/pft/recfmt");                   
557                }
558                printf("%s\n",buffer);
559            }
560           
561            //check proc.n parms
562
563            /* loop throught cgi data pairs ^nproc.n^v[fldupdat_cmds]
564            */
565
566        } //end drive mainserver to procs
567
568
569        //drive mainserver to wtrig2
570        if (wwwcgip) if (strstr(wwwcgip,"^nwtrig2^von")) {
571
572            if (debug) printf("+++ wwwcgip=%s<br />\n",wwwcgip);
573
574            // alloc cgi message
575            cgimsg=loadfile(NULL,'@',"",NULL,cgimsgsize,'\0');
576            if (!cgimsg) fatal("serc/alloc/cgimsg");
577            x=cgimsg;
578
579            /* loop throught cgi data pairs ^nNam^v[Val]
580            */
581            // H1.len.^nNam^v[Val]
582            // <--y--><---len---->
583            for (p=wwwcgip, npairs=0; strncmp(p,"H2000 ",6) == 0; ) {
584           
585                hhp=p;
586                p+=6; y=6;
587                for (len=0; isdigit(*p); p++, y++)
588                    len=10*len+(int)(*p)-(int)'0';
589                p++; y++;
590                // ^nNam^v[Val]
591                p+=2;
592                // Nam^v[Val]
593                np=p;
594                for (nlen=0; *p; p++) if (*p == SFLDCHR) break; else nlen++;
595                // ^v[Val]
596                p+=2;
597                // [Val]
598                vp=p;
599                p=hhp+y+len;
600                npairs++;
601                //
602                np[nlen]='\0';                        // Nam dlm
603                vlen=len-nlen-2-2;                    // memcpy
604                if (debug) printf("+++ pair %d: %s[%d+%d,%d,%d]<br />\n",npairs,hhp,y,len,nlen,vlen);
605                if (vlen < 0) fatal("serc/vlen");
606
607                  //start wtrig2 parms
608                  if (strcmp(np,"wtrig2") == 0) {
609                      wtmsg=x;                           //trig move parms from now on
610                      sprintf(x,"wtrig2"); x+=strlen(x); //drive
611                      continue;
612                  }
613                  // text1= text= parms
614                  if (strcmp(np,"text") == 0) {
615                      txtvp=vp; txtvlen=vlen;
616                      continue;
617                  }
618                  if (strcmp(np,"text1") == 0) {
619                      txt1vp=vp; txt1vlen=vlen;
620                      continue;
621                  }
622                  // normalize c= d= parms
623                  if (strcmp(np,"c") == 0 || strcmp(np,"collection") == 0) {
624                      np="c";
625                      if (vlen) if (strstr(vp,"^p")) {
626                          char *p=strstr(vp,"^p")+2;                         
627                          port=(uint16_t)atoi(p); 
628                          vlen-=2; for (; isdigit(*p); p++) vlen--;
629                      }
630                  }
631                  if (strcmp(np,"d") == 0 || strcmp(np,"document") == 0) {
632                      np="d";
633                  }
634                  //move wtrig2/other parms - w2p0.c now discart non-w2 parms
635                  if (wtmsg) {
636                      if (!vlen) { sprintf(x," %s" ,np); x+=strlen(x); }
637                      else       { sprintf(x," %s=",np); x+=strlen(x); memcpy(x,vp,vlen); x+=vlen; }
638                  }
639                  else if (debug) printf("+++ pair %d: %s[%d+%d,%d,%d] - ignored <br />\n",npairs,hhp,y,len,nlen,vlen);
640
641            } // end loop
642
643            *x='\0';
644            if (*p) fatal("serc/wwwcgip");
645
646        } //end drive mainserver to wtrig2
647
648    } /* end if !parmwtmsg */
649
650
651
652    /* Run
653    */
654    *buffer='\0';
655
656    // drive mainserver to wtrig2
657    if (parmwtmsg || wtmsg) {
658
659       int cmd=debug;
660       char *message=parmwtmsg;
661       int maxrds=1;
662
663       if (wtmsg) {  //cgi overrides parms!
664           char *x=wtmsg+strlen(wtmsg);
665           message=wtmsg;
666           if (txt1vlen) {
667             sprintf(x," text1="); x+=strlen(x); memcpy(x,txt1vp,txt1vlen); x+=txt1vlen; *x='\0';
668           }
669           if (txtvlen) {
670             sprintf(x," text=" ); x+=strlen(x); memcpy(x,txtvp,txtvlen);   x+=txtvlen;  *x='\0';
671           }
672       } /* end wtmsg */
673
674       if (debug) printf("serc: message=%s<br />\n",message);
675       if (message) {
676           if (debug || cmd >= 3) printf("serc: \"%s\" %s %d [%d read]\n",message,serverhost,port,maxrds);
677#if !PC
678           rc=mainclient(cmd, message, serverhost, port, buffer, buffersize, maxrds);
679#else
680           rc=0;
681#endif
682           if (debug || cmd >= 3) if (rc < 0) printf("serc: failure %d \n", rc);
683       }
684
685    } /* end parmwtmsg || wtmsg */
686
687
688
689    /* get secs_ for elapsed */
690    secs_end=time(&secs_now);
691
692    //reply..
693    if (outfmthtml) {
694        printf("%s",buffer);
695    } else {
696        printf("%s",buffer);
697        printf("</request>\n");
698        printf("<elapsed>%"_LD_"</elapsed>\n",(LONGX)secs_end-secs_start);
699    }
700
701   
702    // reply trailer
703    if (outfmthtml) 
704        printf("</pre></body></html>\n");
705    else
706        printf("</serc>\n");
707
708
709    /* release working areas
710    */
711    //if (databuff)  FREE(databuff);
712    //if (textbuff)  FREE(textbuff);
713    //if (buffer)  FREE(buffer);
714    //if (cgimsg)  FREE(cgimsg);
715    //if (wwwcgip) FREE(wwwcgip);
716
717    /* Done
718    */
719    return 0;
720}
721
722/*
723*/
724
725
726#if 0
727mxff null count=0            create=serxgiz0
728mxff null count=1   -all now append=serxgiz0 "proc='a1|&|a2|&amp;| '"
729mxff null count=1   -all now append=serxgiz0 "proc='a1|22|a11|hex|a2|&quot;|'"
730mxff null count=1   -all now append=serxgiz0 "proc='a1|<|a2|&lt;|'"
731mxff null count=1   -all now append=serxgiz0 "proc='a1|>|a2|&gt;|'"
732mxff serxgiz0 -all now iso=serxgiz0.iso
733
734mxff iso=serxgiz0.iso -all now create=serxgiz0
735#endif
736
737
738#if 0
739
740
741<!--
742<option value="DeCS^         ^vc:\fsp\decs\decs^         ^cc:\fsp\fapd^               ^tconcepts^  ^iDescritores em Ci&ecirc;ncias da Sa&uacute;de">DeCS</option>
743<option value="DeCSap^       ^vc:\fsp\decs\decs^         ^cc:\fsp\fapdtk^             ^tconcepts^  ^iDescritores em Ci&ecirc;ncias da Sa&uacute;de / 1+1+50">DeCSap</option>
744<option value="LILACStk^     ^vc:\ofix\lilacs^           ^cc:\ofix\rel.lil\m3ff^      ^tarticles^  ^iLiteratura Latino-Americana e do Caribe em Ci�ias da Sa� TI+JD+87">LILACStk</option>
745<option value="LILACSaids^   ^vc:\fapesp\aids\list_aids^ ^cc:\fapesp\aids\xlilaids^   ^tarticles^  ^iLiteratura Latino-Americana e do Caribe em Ci�ias da Sa� AIDS / TI+AB">LILACSaids</option>
746<option value="LILACSaidstk^ ^vc:\fapesp\aids\list_aids^ ^cc:\fapesp\aids\xlilaidstk^ ^tarticles^  ^iLiteratura Latino-Americana e do Caribe em Ci�ias da Sa� AIDS / TI+KW">LILACSaidstk</option>
747<option value="MEDLINEaids^  ^vc:\fapesp\regina\medline_aids^ ^cc:\fapesp\regina\xmdlaids^   ^tarticles^  ^iNational Library of Medline MEDLINE / AIDS / TI[+AB]">MEDLINEaids</option>
748<option value="MEDLINEaidstk^^vc:\fapesp\regina\medline_aids^ ^cc:\fapesp\regina\xmdlaidstk^ ^tarticles^  ^iNational Library of Medline MEDLINE / AIDS / TI+KW">MEDLINEaidstk</option>
749<option value="SciELO^       ^vc:\ofix\xart^             ^cc:\ofix\xartha1^           ^tarticles^  ^iScientific Electronic Library Online / TI+KW+AB">SciELO</option>
750<option value="SciELOtk^     ^vc:\ofix\xart^             ^cc:\ofix\xartha1tk^         ^tarticles^  ^iScientific Electronic Library Online / TI+KW">SciELOtk</option>
751<option value="InstCNPq^     ^vc:\ofix\co-lil\instv2^    ^cc:\ofix\co-lil\instv4ff^         ^tinstitutions^  ^iTabela de Institui�s do CNPq/Lattes">InstCNPq</option>
752 -->
753
754<option value="VisaLegis.Summary^d1901">VisaLegis - Summary</option>
755<option value="SciELO.br">SciELO Brasil - Autor/T&iacute;tulo</option>
756<option value="LILACS">LILACS Regional - T&iacute;tulo/JDs/Descritores</option>
757<option value="SciELO.br.TiKw^p1717" selected>SciELO Brasil -T&iacute;tulo/Keywords</option>
758
759<option value="DeCS.i^p1701">DeCS Ingl�- Termo/Sin�os/Hist�os</option>
760<option value="DeCS.e^p1702">DeCS Espanhol - Termo/Sin�os/Hist�os</option>
761<option value="DeCS.p^p1703">DeCS Portugu�- Termo/Sin�os/Hist�os</option>
762<option value="DeCS.c^p1704">DeCS Hier�uico - C�os hier�uicos</option>
763
764OFI:/home/galvao/www/site/bvs/cgi-bin/similar>./psw
765cdrom    12574     1  0 Oct07 ?        00:02:21 ./serw port=1701 cipar=serw.cip
766cdrom    12579     1  0 Oct07 ?        00:00:15 ./serw port=1702 cipar=serw.cip
767cdrom    12596     1  0 Oct07 ?        00:00:15 ./serw port=1703 cipar=serw.cip
768cdrom    12607     1  0 Oct07 ?        00:00:12 ./serw port=1704 cipar=serw.cip
769cdrom    20968     1  0 Oct07 ?        00:00:31 ./serw port=1717 cipar=serw.cip  SciELO.br.TiKw
770cdrom     8116     1  0 Oct10 ?        00:00:00 ./serw port=1900 cipar=serw.cip 
771cdrom    11861     1 71 20:28 pts/2    00:03:50 ./serw port=1417 cipar=serw.cip  SciELO.br        LILACS
772cdrom    12028 12020  0 20:33 pts/2    00:00:00 grep serw
773
774http://serverofi.bireme.br/cgi-bin/serx?wtrig2=on&c=SciELO.br&tagtext=v10^n,x1,v10^s,x1,v12^*&db=SciELO.br&mfn=20197&pft=all
775
776http://serverofi.bireme.br/cgi-bin/serx?wtrig2=onx&c=SciELO.br.TiKw&port=1717&minsim=0.30&db=SciELO.br&pft=all&tagtext=v12[1]^*&mfn=4
777
778#endif
Note: See TracBrowser for help on using the browser.