Annotation of researchv10no/cmd/refer/ml1.c, revision 1.1

1.1     ! root        1: # include "stdio.h"
        !             2: # include "assert.h"
        !             3: # include "ctype.h"
        !             4: # define SEP 001
        !             5: # define MAXLIN 100
        !             6: # define MAXCH 4000
        !             7: # define control(s) ((s)=='%')
        !             8: int authsplit =1; /* separate line for each author */
        !             9: char *lasbl(), *artskip(), *lmin();
        !            10: int typesplit =1; /* separate line for each type */
        !            11: int nlines =0;
        !            12: char *ln[MAXLIN];
        !            13: char date[20], mdate[20];
        !            14: int beenhere[5];
        !            15: char *kdate, stitle[50], *auth;
        !            16: char *keys= "A%D.T"; /* key to be author, kind of pub, date, title */
        !            17: main (argc,argv)
        !            18:        char *argv[];
        !            19: {
        !            20: FILE *f;
        !            21: char bf[MAXCH], *p, *r;
        !            22: int j, k, m,d, type, skip, comment;
        !            23: /* type: 1 TM 2 RP 3 Patent 4 Pat. applc */
        !            24: assert (argc>0);
        !            25: argc--; argv++;
        !            26: while (argc-->0)
        !            27:        {
        !            28:        assert(*argv!=0);
        !            29:        if (argv[0][0] == '-')
        !            30:                switch ( (*argv++)[1])
        !            31:                        {
        !            32:                        case 's': /* no split */
        !            33:                                authsplit=0; continue;
        !            34:                        case 't': /* no type split */
        !            35:                                typesplit= 0; continue;
        !            36:                        case 'k': /* key string */
        !            37:                                keys = *argv++; argc--; continue;
        !            38:                        default: continue;
        !            39:                        }
        !            40:        f = fopen(*argv++, "r");
        !            41:        assert (f!=NULL);
        !            42:        for(;;)
        !            43:                {
        !            44:                /* read this input file */
        !            45:                ln[nlines=0] = bf;
        !            46:                comment=0;
        !            47:                for(;;)
        !            48:                        /* obtain item */
        !            49:                        {
        !            50:                        m=(int)fgets(p=ln[nlines], bf+MAXCH-p, f);
        !            51:                        if (m==NULL)break;
        !            52:                        if (*p=='\n') break;
        !            53:                        if (control(p[0]) && p[1]=='X')
        !            54:                                {
        !            55:                                comment=1;
        !            56:                                continue;
        !            57:                                }
        !            58:                        if (comment && !control(p[0]))
        !            59:                                continue;
        !            60:                        comment = 0;
        !            61:                        while (*p++);
        !            62:                        if (p[-2]=='\n') p[-2] = 0;
        !            63:                        assert(nlines<MAXLIN);
        !            64:                        assert(p<bf+MAXCH);
        !            65:                        ln [ ++nlines ] = p;
        !            66:                        }
        !            67:                if (nlines==0 && m==NULL) break;
        !            68:                /* item read */
        !            69:                if (nlines==0) continue;
        !            70:                /* now get date, etc. */
        !            71:                strcpy(date,"1980");
        !            72:                stitle[0]=0;
        !            73:                for(d=0; d<nlines; d++)
        !            74:                        {
        !            75:                        p = ln[d];
        !            76:                        if (!control(p[0])) continue;
        !            77:                        switch(p[1])
        !            78:                                {
        !            79:                                case 'D':
        !            80:                                        r = lasbl(p, 'D');
        !            81:                                        if (isdigit(*r))
        !            82:                                                sprintf(date, "%s.%02d", r, mon(p+3));
        !            83:                                        break;
        !            84:                                case 'M':
        !            85:                                        for (p=p+2;*p;p++)
        !            86:                                                if (isdigit(*p))
        !            87:                                                        {
        !            88:                                                        sprintf(mdate, "19%c%c.%02d", p[0],p[1], atoi(lmin(p)));
        !            89:                                                        break;
        !            90:                                                        }
        !            91:                                        break;
        !            92:                                case 'T':
        !            93:                                        sprintf(stitle,"%.10s", artskip(p+3));
        !            94:                                        break;
        !            95:                                }
        !            96:                        }
        !            97:                for(d=0; d<5; d++)
        !            98:                        beenhere[d]=0;
        !            99:                if (typesplit)
        !           100:                        for(d=0; d<nlines; d++)
        !           101:                                {
        !           102:                                p=ln[d];
        !           103:                                if (control(p[0]))switch(p[1])
        !           104:                                        {
        !           105:                                        case 'B':
        !           106:                                        case 'J': case 'I':
        !           107:                                        case 'R': type = 2; doit(type); break;
        !           108:                                        case 'M': type =1; doit(type); break;
        !           109:                                        case 'p': type = 3; doit(type); break;
        !           110:                                        case 'a': type = 4; doit(type); break;
        !           111:                                        }
        !           112:                                }
        !           113:                else
        !           114:                        doit(0);
        !           115:                if (m==NULL) break;
        !           116:                }
        !           117:        fclose(f);
        !           118:        }
        !           119: }
        !           120: doit(type)
        !           121: {
        !           122: int j; char *p;
        !           123: if (beenhere[type]) return;
        !           124: beenhere[type]=1;
        !           125: kdate = (type==1) ? mdate: date;
        !           126: j= atoi(kdate);
        !           127: if (type==1 && (j<1960 || j >1990)) kdate=date;
        !           128: for(j=0; j<nlines; j++)
        !           129:        {
        !           130:        p=ln[j];
        !           131:        if (!control(p[0]) || p[1] != 'A') continue;
        !           132:        auth=p;
        !           133:        pline(type);
        !           134:        if (authsplit==0) break;
        !           135:        }
        !           136: }
        !           137: pline(type)
        !           138: {
        !           139: char *pk, *p, *s;
        !           140: int j, c;
        !           141: for (pk=keys; c= *pk; pk++)
        !           142:        {
        !           143:        switch(c)
        !           144:                {
        !           145:                case 'A':
        !           146:                        auprint(auth); break;
        !           147:                case '%':
        !           148:                        printf("*%d_", type); break;
        !           149:                case 'T':
        !           150:                        /* printf("%s_", stitle); break; */ fputs(stitle, stdout); putchar('_'); break;
        !           151:                case 'M':
        !           152:                        for(j=0; j<nlines; j++)
        !           153:                                {
        !           154:                                p=ln[j];
        !           155:                                if (control(p[0]))
        !           156:                                        if (p[1]=='M')
        !           157:                                                {
        !           158:                                                printf("%s_",p+3);
        !           159:                                                break;
        !           160:                                                }
        !           161:                                }
        !           162:                        break;
        !           163:                case 'D':
        !           164:                        /* if D is followed by . we want month otherwise not. */
        !           165:                        c = pk[1];
        !           166:                        if (c=='.') pk++;
        !           167:                        else
        !           168:                                {
        !           169:                                for(s=kdate; *s && *s != '.'; s++)
        !           170:                                                ;
        !           171:                                *s=0;
        !           172:                                }
        !           173:                        /* printf("%s_", kdate); */ fputs(kdate, stdout); putchar('_'); break;
        !           174:                }
        !           175:        }
        !           176: itdump(type);
        !           177: putchar('\n');
        !           178: }
        !           179: static char xxx[50];
        !           180: char *
        !           181: lasbl(pin, fl)
        !           182:        char *pin;
        !           183: {
        !           184: char *s, *p, px[100];
        !           185: char *t;
        !           186: int inparen=0, normal;
        !           187: strcpy (s=p=px, pin);
        !           188: while (*p)p++;
        !           189: p--;
        !           190: for (; p>s; p--)
        !           191:        {
        !           192:        normal = (p[-1] != '\\');
        !           193:        if (p[0]==')' && normal) inparen++;
        !           194:        if (*p=='(' && normal) inparen--;
        !           195:        if (*p=='(' && normal)
        !           196:                while (*--p == ' ');
        !           197:        if (inparen==0 && *p==' ')
        !           198:                {
        !           199:                if (p[-1]==',' && fl =='A') /* Jr or II */
        !           200:                        {
        !           201:                        *--p=0;
        !           202:                        continue;
        !           203:                        }
        !           204:                t=xxx; p++;
        !           205:                while (*p && *p!=' ') *t++ = *p++;
        !           206:                *t=0; return(xxx);
        !           207:                }
        !           208:        }
        !           209: fprintf(stderr, "s is %s\n",s);
        !           210: assert(0);
        !           211: }
        !           212: static char *mp[12] ={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
        !           213: "Aug", "Sep", "Oct", "Nov", "Dec"};
        !           214: mon (s)
        !           215:        char *s;
        !           216: {
        !           217:        int i;
        !           218: for(i=0; i<12; i++)
        !           219:        if (mat3(s, mp[i])) return(i+1);
        !           220: return(0);
        !           221: }
        !           222: mat3(s,t)
        !           223:        char *s, *t;
        !           224: {
        !           225: int k;
        !           226: for(k=0; k<3; k++)
        !           227:        if (s[k] != t[k]) return(0);
        !           228: return(1);
        !           229: }
        !           230: char *
        !           231: lmin(s)
        !           232:        char *s;
        !           233: {
        !           234: char *p;
        !           235: for(p=s; *p; p++);
        !           236: while (*--p != '-' && p>s);
        !           237: return(p+1);
        !           238: }
        !           239: char *
        !           240: artskip(s)
        !           241:        char *s;
        !           242: {
        !           243: if (s[0]=='A' && s[1]== 'n' && s[2] == ' ')
        !           244:        return(s+3);
        !           245: if (s[0]=='A' && s[1]==' ')
        !           246:        return(s+2);
        !           247: if (s[0]=='T' && s[1]=='h' && s[2]=='e' && s[3] == ' ')
        !           248:        return(s+4);
        !           249: return(s);
        !           250: }
        !           251: itdump(type) /* print item */
        !           252: {
        !           253: int k, skip=0;
        !           254: char *p;
        !           255: for(k=0; k<nlines; k++)
        !           256:        {
        !           257:        p = ln[k];
        !           258:        if (skip && !control(p[0])) continue;
        !           259:        if (type==1 && control(p[0])) 
        !           260:                switch(p[1])
        !           261:                        {
        !           262:                        case 'J': case 'D':
        !           263:                        case 'R': case 'I':
        !           264:                        case 'K': case 'B':
        !           265:                                skip=1;
        !           266:                                continue;
        !           267:                        }
        !           268:        if (control(p[0]))
        !           269:                switch(p[1])
        !           270:                        {
        !           271:                        case 'X': case ']': case '[':
        !           272:                        skip=1;
        !           273:                        continue;
        !           274:                        }
        !           275:        skip=0;
        !           276:        /* printf("%c%s", SEP, p); */
        !           277:        putchar(SEP);
        !           278:        fputs(p, stdout);
        !           279:        }
        !           280: }
        !           281: auprint(p) /* dump author */
        !           282:        char *p;
        !           283: {
        !           284: int k;
        !           285: printf("%s_%c_", lasbl(p, 'A'), p[3]);
        !           286: for(k=7; p[k] == '.'; p += 3) /* lots of initials */
        !           287:        printf("%c_", p[k-1]);
        !           288: }

unix.superglobalmegacorp.com

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