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

1.1       root        1: # include "stdio.h"
                      2: # include "ctype.h"
                      3: # include "assert.h"
                      4: # define SEP 001
                      5: # define SAME 1
                      6: # define DIFFERENT 0
                      7: main(argc,argv)
                      8:        char *argv[];
                      9: {
                     10: char bf[2000],*p, *s;
                     11: char oname[100], tname[100];
                     12: int ct, type, ntype;
                     13: oname[0] = 0;
                     14: ct = type = 0;
                     15: while (gets(bf))
                     16:        {
                     17:        p=bf;
                     18:        gname(tname,p);
                     19:        /* if a date we don't care about month */
                     20:        datetrim(tname);
                     21:        if (compare(tname, oname) != SAME)
                     22:                {
                     23:                if (ct > 0)
                     24:                        printf(".ct %d\n", ct);
                     25:                printf(".nn %s\n", tname);
                     26:                ct = 0;
                     27:                type = 0;
                     28:                }
                     29:        strcpy (oname, tname);
                     30:        ntype = gtype(p);
                     31:        if (ntype != type)
                     32:                printf(".ty %d\n", ntype);
                     33:        type = ntype;
                     34:        while (*p++ != SEP);
                     35:        for (s=p; *s; s++)
                     36:                {
                     37:                assert (s<bf+2000);
                     38:                if (*s == SEP)
                     39:                        *s = '\n';
                     40:                }
                     41:        while (*p=='\n')p++;
                     42:        puts(".br\n.[");
                     43:        puts(p);
                     44:        puts(".]");
                     45:        ct++;
                     46:        }
                     47: if (ct>0) printf(".ct %d\n",ct);
                     48: }
                     49: 
                     50: gname(buf, s)
                     51:        char *buf, *s;
                     52: {
                     53:        int c;
                     54: for ( ; (c= *s) && c != SEP && c != '*'; s++)
                     55:        *buf++ = (c != '_' ? c : ' ');
                     56: *buf=0;
                     57: }
                     58: gtype(s)
                     59:        char *s;
                     60: {
                     61: while (*s && *s!= '*')
                     62:        s++;
                     63: return (*s ? s[1] - '0' : 0);
                     64: }
                     65: compare(s1, s2)
                     66:        char *s1, *s2;
                     67: {
                     68: /* compare last names */
                     69: while (*s1++== *s2++)
                     70:        {
                     71:        if (*s1==0) return(SAME);
                     72:        if (*s1==' ') break;
                     73:        }
                     74: if (*s1 != ' ' || *s2 != ' ') return(DIFFERENT);
                     75: while (*s1==' ') s1++;
                     76: while (*s2==' ') s2++;
                     77: #/* compare first initials */
                     78: if (*s1++ != *s2++) return (DIFFERENT);
                     79: while (*s1==' ') s1++;
                     80: while (*s2==' ') s2++;
                     81: /* if no middle initials OK */
                     82: if (*s1==0 || *s2==0) return(SAME);
                     83: /* but if middle initials must be same */
                     84: if (*s1==*s2) return(SAME);
                     85: return (DIFFERENT);
                     86: }
                     87: datetrim(p)
                     88:        char *p;
                     89: {
                     90: if (isdigit(p[0])&& isdigit(p[1]))
                     91:        {
                     92:        while(isdigit(*p))p++;
                     93:        *p=0;
                     94:        }
                     95: }

unix.superglobalmegacorp.com

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