Annotation of researchv8dc/cmd/refer/refer1.c, revision 1.1

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

unix.superglobalmegacorp.com

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