Annotation of coherent/a/tmp/smail/utils/nptx.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid = "@(#)nptx.c      2.5 (smail) 9/15/87";
                      3: #endif
                      4: 
                      5: #include <stdio.h>
                      6: #include <sys/types.h>
                      7: #include <sys/stat.h>
                      8: #include <pwd.h>
                      9: #include "defs.h"
                     10: #include <ctype.h>
                     11: 
                     12: char *malloc(), *index(), *fullname();
                     13: void nptx(), free(), dotspace();
                     14: 
                     15: enum edebug debug;     /* not used by nptx */
                     16: char *fnlist = NULL;   /* not used by nptx */
                     17: 
                     18: main()
                     19: {
                     20:        int i;
                     21:        char buf[SMLBUF], *p, *name, *last, *nick, *ctmp;
                     22: 
                     23:        while(gets(buf) != NULL) {
                     24:                /*  line should be in form
                     25:                **
                     26:                **  login       First Last
                     27:                ** or
                     28:                **  login       First Last(Nickname)
                     29:                **
                     30:                */
                     31:                if((p = index(buf, '\t')) == NULL) {
                     32:                        (void) fprintf(stderr, "format error: %s\n", buf);
                     33:                        continue;
                     34:                }
                     35: 
                     36:                *p++ = '\0';
                     37:                name = fullname(p);
                     38:                dotspace(name);
                     39: 
                     40:                if (last = rindex(name, '.')) {
                     41:                        last++;
                     42:                } else {
                     43:                        last = NULL;
                     44:                }
                     45: 
                     46:                if ((nick = index(p, '(')) != NULL) {
                     47:                        nick++;
                     48:                        if ((ctmp = index(nick, ')')) == NULL) {
                     49:                                nick = NULL;
                     50:                        } else {
                     51:                                *ctmp = '\0';
                     52:                        }
                     53:                }
                     54: 
                     55:                nptx(buf, name);
                     56: 
                     57:                if((last != NULL) && (nick != NULL)) {
                     58:                        i=strlen(nick) + strlen(last) + 2;
                     59:                        if((name = malloc(i)) != NULL) {
                     60:                                (void) strcpy(name, nick);
                     61:                                (void) strcat(name, ".");
                     62:                                (void) strcat(name, last);
                     63:                                dotspace(name);
                     64:                                nptx(buf, name);
                     65:                                free(name);
                     66:                        }
                     67:                }
                     68:        }
                     69:        return(0);
                     70: }
                     71: 
                     72: void
                     73: dotspace(s)
                     74: char *s;
                     75: {
                     76:        register char *p, *t;
                     77: 
                     78:        /* turn whitespace to '.' */
                     79:        for(p = s; *p != '\0'; p++) {
                     80:                if((*p == ' ') || (*p == '\t')) {
                     81:                        *p = '.';
                     82:                }
                     83:        }
                     84: 
                     85:        /* elide leading '.'s */
                     86:        for(p = s; *p == '.' ; p++)
                     87:                ;
                     88: 
                     89:        /* elide mulitple '.'s and all "'"s */
                     90:        for(t = s; *p != '\0'; p++, t++) {
                     91:                *t = *p;
                     92: 
                     93:                if(*t == '\'') {
                     94:                        t--;
                     95:                        continue;
                     96:                }
                     97: 
                     98:                if(*p == '.') {
                     99:                        while(*(++p) == '.')
                    100:                                ;
                    101:                        p--;
                    102:                }
                    103:        }
                    104:        *t = '\0';
                    105: 
                    106:        /* elide trailing '.' */
                    107:        if((t > s) && (*(--t) == '.')) *t = '\0';
                    108: }
                    109: 
                    110: void
                    111: nptx(login, name)
                    112: char *login, *name;
                    113: {
                    114:        int i,j,k,N,lim,mask;
                    115:        int ii,ji,ki,Ni,limi,maski;
                    116:        char nl[11][100], il[11][100];
                    117:        char *pi, *p, *rindex();
                    118:        char buf[100];
                    119:        char bufi[100];
                    120: 
                    121:        if((name == NULL) || (*name == '\0')) {
                    122:                return;
                    123:        }
                    124: 
                    125:        for(i=0; i < 10; i++) {
                    126:                if((p = rindex(name, '.')) == NULL) break;
                    127:                (void) strcpy(nl[i], p+1);
                    128:                *p = NULL;
                    129:        }
                    130:        (void) strcpy(nl[i], name);
                    131: 
                    132:        while((strcmpic(nl[i], "Mr"  ) == 0)
                    133:         ||   (strcmpic(nl[i], "Dr"  ) == 0)
                    134:         ||   (strcmpic(nl[i], "Mrs" ) == 0)
                    135:         ||   (strcmpic(nl[i], "Miss") == 0)
                    136:         ||   (strcmpic(nl[i], "Ms"  ) == 0)) {
                    137:                i--;
                    138:        }
                    139: 
                    140:        while((strcmpic(nl[0], "Jr") == 0)
                    141:         ||   (strcmpic(nl[0], "Sr") == 0)) {
                    142:                for(j=0; j < i; j++) {
                    143:                        (void) strcpy(nl[j], nl[j+1]);
                    144:                }
                    145:                i--;
                    146:        }
                    147: 
                    148:        N = i;
                    149:        lim = 1 << (N+1);
                    150:        for(mask = 1 << N ; mask < lim ; mask++) {
                    151:                buf[0] = '\0';
                    152:                for(j = 1, k = N; j < lim; j <<=1, k--) {
                    153:                        if(j & mask) {
                    154:                                (void) strcat(buf, nl[k]);
                    155:                                (void) strcat(buf, ".");
                    156:                        }
                    157:                }
                    158:                if((p = rindex(buf, '.')) != NULL) {
                    159:                        *p = '\0';
                    160:                }
                    161: 
                    162:                for(ii=0; ii < 10; ii++) {
                    163:                        if((pi = rindex(buf, '.')) == NULL) break;
                    164:                        (void) strcpy(il[ii], pi+1);
                    165:                        *pi = NULL;
                    166:                }
                    167:                (void) strcpy(il[ii], buf);
                    168:                Ni = ii;
                    169:                limi = 1 << (Ni+1);
                    170:                for(maski = 1 << Ni /* 0 */ ; maski < limi ; maski++) {
                    171:                        bufi[0] = '\0';
                    172:                        for(ji = 1, ki = Ni; ji < limi; ji <<=1, ki--) {
                    173:                                if(ji & maski) {
                    174:                                        (void) strcat(bufi, il[ki]);
                    175:                                } else {
                    176:                                        char init[3];
                    177:                                        init[0] = il[ki][0];
                    178:                                        init[1] = '\0';
                    179:                                        (void) strcat(bufi, init);
                    180:                                }
                    181:                                (void) strcat(bufi, ".");
                    182:                        }
                    183:                        if((pi = rindex(bufi, '.')) != NULL) {
                    184:                                *pi = '\0';
                    185:                        }
                    186: #ifdef DOT_REQD
                    187:                        if(index(bufi, '.') == NULL) {
                    188:                                continue;
                    189:                        }
                    190: #endif /* DOT_REQD */
                    191:                        (void) printf("%s\t%s\n",bufi, login); /* */
                    192:                }
                    193:        }
                    194: }

unix.superglobalmegacorp.com

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