root/tags/5.52/ifkeys.c

Revision 4, 3.2 kB (checked in by heitor.barbieri, 2 years ago)

Versão 5.52 do cisis (28/04/2010)

Line 
1#include <stdio.h>
2#include <string.h>
3
4
5#if 1
6#include "cisis.h"   /* CISIS Interface header file */
7#include "cirun.h"   /* CISIS Interface runtime declarations */
8#else
9#include "\cisis\include\cisis.h"   /* CISIS Interface header file */
10#include "\cisis\include\cirun.h"   /* CISIS Interface runtime declarations */
11#endif
12
13#define MAXTAG 9999
14LONGX vtag[MAXTAG+1];
15
16void main(argc,argv)
17int argc;
18char *argv[];
19{
20        TRMSTRU *trmp;  /* mandatory for defines TRM */
21        LONGX itag,mtag;
22        int parmtags=0;
23        int parmdiac=0;
24        LONGX parmtell=0L;
25        LONGX itrm,count=0;
26        unsigned char *dbnp,*k1p="",*k2p=NULL,k1[LE2+1],k2[LE2+1];
27        unsigned char *p;
28        int loop,i;
29
30        if (argc < 2) {
31            printf("%s",cicopyr("Utility IFKEYS"));
32            printf(" \n");
33            printf("ifkeys <dbname> [from=<key>] [to=<key>] [+tags] \n");
34            printf(" \n");
35            printf(" <dbname>   input inverted file \n");
36            printf(" from=<key> starting key \n");
37            printf(" to=<key>   ending key \n");
38            printf(" +tags      output tag information \n");
39            printf(" tell=<n>   produce a message every each <n> keys \n");
40            printf(" \n");
41            printf(" Displays the dictionary terms preceeded by the");
42            printf(" total number of postings \n");
43            printf(" \n");
44            exit(1);
45#if 0
46     2|    24|PLACE
47     2|    24|PLAINS
48     1|    24|PLAN
49     1|    24|PLANKTON
50     1|    69|PLANKTON
51     1|    24|PLANNING
52#endif
53        }
54        dbnp=argv[i=1];
55        for (i++; i < argc; i++) {
56            p=argv[i];
57            if (strncmp(p,"key1=",5) == 0 || strncmp(p,"from=",5) == 0) {
58                for (p+=5,k1p=k1; *p; ) *k1p++ = isisuctab[*p++];
59                *k1p='\0'; k1p=k1;
60                continue;
61            }
62            if (strncmp(p,"key2=",5) == 0 || strncmp(p,"to=",3) == 0) {
63                if (strncmp(p,"key2=",5) == 0) p+=5; else p+=3;
64                for (k2p=k2; *p; ) *k2p++ = isisuctab[*p++];
65                *k2p='\0'; k2p=k2;
66                for (loop=strlen(k2p), p=k2p+loop; loop <= LE2; )
67                    k2[loop++]= *highv;
68                continue;
69            }
70            if (strcmp(p,"+tags") == 0) {
71                parmtags=1;
72                continue;
73            }
74            if (strcmp(p,"+diac") == 0) {
75                parmdiac=1;
76                continue;
77            }
78            if (strncmp(p,"tell=",5) == 0) {
79                if (sscanf(p+5,"%ld",&parmtell) != 1) fatal(p);
80                continue;
81            }
82            fatal(p);
83        }
84       
85        for (itag=0; itag <= MAXTAG ; itag++) vtag[itag]=0;
86       
87        for (TERM(itrm=ntrms,dbnp,k1p); TRMrc != RCEOF; ) {
88
89                if (parmtell)
90                    if (!(++count % parmtell))
91                        fprintf(stderr,"+++ %ld %s\n",count,TRMkey);
92
93                loop=(TRMlcase) ? LE2 : LE1;
94                for (p=TRMkey+loop-1; loop--; p--)
95                        if (*p == '\0' || *p == ' ')
96                                *p = '\0';
97                        else
98                                break;
99
100                if (parmtags) {
101                    mtag=0;
102                    while (posting(itrm,TRMpost+1) > 0L)
103                        if (TRMptag <= 0 || TRMptag >= MAXTAG)
104                            vtag[0]++;
105                        else {
106                            vtag[TRMptag]++;
107                            if (mtag < TRMptag) mtag=TRMptag;
108                        }
109                    for (itag=0; itag <= mtag; itag++)
110                        if (vtag[itag]) {
111                            printf("%6ld|%5ld|%s\n",
112                                vtag[itag],(LONGX)itag,TRMkey);
113                            vtag[itag]=0;
114                        }
115                }
116                else {
117                    if (parmdiac) {
118                        for (p=TRMkey; *p; p++)
119                            if (*p >= 128) {
120                                printf("%6ld|%s\n",TRMxytotp,TRMkey);
121                                break;
122                            }
123                    }
124                    else 
125                        printf("%6ld|%s\n",TRMxytotp,TRMkey);
126                }
127
128                NXTERM(itrm);
129                if (k2p)
130                    if (strcmp(TRMkey,k2p) > 0)
131                        break;
132        }
133        exit(0); /* 20/07/98 */
134}
Note: See TracBrowser for help on using the browser.