Annotation of researchv10no/cmd/refer/refer1.c, revision 1.1.1.1

1.1       root        1: # include "signal.h"
                      2: # ifdef SVR2
                      3: typedef int    (*SIG_TYP)();
                      4: # endif
                      5: # include "refer..c"
                      6: main(argc,argv)
                      7:        char *argv[];
                      8: {
                      9: char line[LLINE], *s;
                     10: int nodeflt =0;
                     11: 
                     12: signals();
                     13: while (argc>1 &&argv[1][0] == '-')
                     14:        {
                     15:        switch(argv[1][1])
                     16:                {
                     17:                case 'e':
                     18:                        endpush++; break;
                     19:                case 'l': 
                     20:                        labels++;
                     21:                        s = argv[1]+2;
                     22:                        nmlen = atoi(s);
                     23:                        for ( ; *s; s++)
                     24:                                if (*s == ',' || *s =='_' || *s =='"')
                     25:                                        break;
                     26:                        if (*s==0) break;
                     27:                        switch(*s++)
                     28:                                {
                     29:                                case ',': labblkflg=0; break;
                     30:                                case '_': labblkflg=" "; break;
                     31:                                case '"':
                     32:                                        labblkflg=s;
                     33:                                        while (*s && *s != '"')
                     34:                                                s++;
                     35:                                        *s++= 0; break;
                     36:                                }
                     37:                        dtlen = atoi(s);
                     38:                        break;
                     39:                case 'k':
                     40:                        keywant = (argv[1][2] ? argv[1][2] : 'L');
                     41:                        labels++;
                     42:                        break;
                     43:                case 's':
                     44:                        sort++;
                     45:                        if (argv[1][2])
                     46:                                keystr= argv[1]+2;
                     47:                        break;
                     48:                case 'p':
                     49:                        argc--; argv++;
                     50:                        *search++ = argv[1];
                     51:                        if (search-rdata>NSERCH)
                     52:                                err("too many -p options (%d)", NSERCH);
                     53:                        break;
                     54:                case 'n':
                     55:                        nodeflt=1;
                     56:                        break;
                     57:                case 'B':
                     58:                        nobracket++; /* falls through */
                     59:                case 'b':
                     60:                        bare = (argv[1][2] == '1') ? 1 : 2;
                     61:                        break;
                     62:                case 'c':
                     63:                        smallcaps = argv[1]+2;
                     64:                        break;
                     65:                case 'a':
                     66:                        authrev = atoi (argv[1]+2);
                     67:                        if (authrev<=0)
                     68:                                authrev = 1000;
                     69:                        for(s=argv[1]+2; isdigit(*s); s++)
                     70:                                ;
                     71:                        if (*s==',') nocomma++;
                     72:                        break;
                     73:                case 'd': /* reduce date to year only */
                     74:                        yearonly=1;
                     75:                        break;
                     76:                case 'A': /* these fields get appended */
                     77:                        appfld = argv[1]+2;
                     78:                        break;
                     79:                case 'I': /* these fields get ignored */
                     80:                        ignfld = argv[1]+2;
                     81:                        break;
                     82:                case 'P': /* preserve original: no .ds's */
                     83:                        preserve = 1;
                     84:                        break;
                     85:                case '%': pagecit=1; break;
                     86:                case 'L':
                     87:                        labsepstr= argv[1]+2; break;
                     88:                case 'r':
                     89:                        recycle = 1; break; /* recycle numbers at each $LIST$ */
                     90:                }
                     91:        argc--; argv++;
                     92:        }
                     93: if (nodeflt==0)
                     94:        *search++ = "/usr/dict/papers/Ind";
                     95: 
                     96: if (sort)
                     97:        endpush=1;
                     98: 
                     99: 
                    100: if (endpush)
                    101:        sprintf(tfile, "/tmp/rj%da", getpid());
                    102: if (sort)
                    103:        {
                    104:        sprintf(ofile,"/tmp/rj%db", getpid());
                    105:        sprintf(tdfile, "/tmp/rj%de", getpid());
                    106:        ftemp = fopen(ofile, "w");
                    107:        if (ftemp==NULL)
                    108:                {
                    109:                fprintf(stderr, "Can't open scratch file\n");
                    110:                exit(1);
                    111:                }
                    112:        }
                    113: 
                    114: do
                    115:        {
                    116:        if (argc>1)
                    117:                {
                    118:                if (in!=stdin)
                    119:                        fclose(in);
                    120:                Iline=0;
                    121:                if (strcmp(argv[1], "-")==SAME){
                    122:                        in = stdin;
                    123:                        printf(".lf 1 -\n");
                    124:                }
                    125:                else{
                    126:                        in = fopen(Ifile=argv[1], "r");
                    127:                        printf(".lf 1 %s\n",Ifile);
                    128:                }
                    129:                argc--; argv++;
                    130:                if (in==NULL)
                    131:                        {
                    132:                        err("Can't read %s", Ifile);
                    133:                        continue;
                    134:                        }
                    135:                }
                    136:        while (input(line))
                    137:                {
                    138:                Iline++;
                    139: # ifdef D1
                    140:                fprintf(stderr, "line %.20s\n",line);
                    141: # endif
                    142:                if (prefix(".[", line) || (nobracket && line[0]!='\n'))
                    143:                        {
                    144:                        if (endpush && (fo==NULL || fo == stdout))
                    145:                                {
                    146:                                fo = fopen(tfile, "w");
                    147: # if D1
                    148:                                fprintf(stderr, "opened %s as %o\n",tfile,fo);
                    149: # endif
                    150:                                if (fo==NULL)
                    151:                                        {
                    152:                                        fprintf(stderr,"Can't open scratch file");
                    153:                                        exit(1);
                    154:                                        }
                    155:                                sep = 002; /* separate records without confusing sort..*/
                    156:                                }
                    157:                        doref(line);
                    158:                        }
                    159:                else
                    160:                        output(line);
                    161: # if D1
                    162:                fprintf(stderr, "past output/doref\n");
                    163: # endif
                    164:                }
                    165:        }
                    166:        while (argc>1);
                    167: # if D1
                    168: fprintf(stderr, "before dumpold, endpush %d fo %o\n",endpush, fo);
                    169: # endif
                    170: widelab();
                    171: if (endpush && (fo!=NULL && fo != stdout))
                    172:        dumpold();
                    173: output("");
                    174: fflush (ftemp);
                    175: if (sort)
                    176:        recopy(ofile);
                    177: clfgrep();
                    178: # ifndef D1
                    179: cleanup();
                    180: # endif
                    181: exit(0);
                    182: }
                    183: 
                    184: extern int intr();
                    185: signals()
                    186: {
                    187:        SIG_TYP oldint;
                    188: oldint = signal(SIGINT, intr);
                    189: if (oldint== (SIG_TYP)1)
                    190:        signal (SIGINT, 1);
                    191: signal (SIGHUP, intr);
                    192: signal (SIGPIPE, intr);
                    193: signal (SIGTERM, intr);
                    194: }
                    195: 
                    196: intr()
                    197: {
                    198:        int oldsig;
                    199: signal(SIGINT, 1);
                    200: cleanup();
                    201: exit(1);
                    202: }
                    203: cleanup()
                    204: {
                    205: if (tfile[0]) unlink(tfile);
                    206: if (gfile[0]) unlink(gfile);
                    207: if (ofile[0]) unlink(ofile);
                    208: if (hidenam[0]) unlink(hidenam);
                    209: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.