Annotation of researchv8dc/cmd/wwb/syl.c, revision 1.1

1.1     ! root        1: /* NOTICE-NOT TO BE DISCLOSED OUTSIDE BELL SYS EXCEPT UNDER WRITTEN AGRMT */
        !             2: /* Writer's Workbench version 2.0, January 1981 */
        !             3: #include <stdio.h>
        !             4: #include <ctype.h>
        !             5: #define MAXCHAR 50
        !             6: #define isvowel(c)     (c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        !             7: char a[MAXCHAR],b[MAXCHAR];
        !             8: 
        !             9: main(argc,argv)
        !            10: int argc;
        !            11: char *argv[];
        !            12: {
        !            13:        register int nsyl,var;
        !            14:        if(argc == 3){
        !            15:                if(*argv[1] != '-'){
        !            16:                        fprintf(stderr,"Usage: syl [-integer] filename\n");
        !            17:                        exit(1);
        !            18:                }
        !            19:                var = *(argv[1]+1);
        !            20:                if(!isdigit(var)){
        !            21:                        fprintf(stderr,"Usage: syl [-integer] filename\n");
        !            22:                        exit(1);
        !            23:                }
        !            24:                var = atoi(argv[1]+1);
        !            25:        }
        !            26:        else var = 0;
        !            27:        while(getword()!=EOF){
        !            28:                if(a[0] == '\0')continue;
        !            29:                change();
        !            30:                nsyl=estimate();
        !            31:                if(nsyl >= var)
        !            32:                        printf("%d-%s\n",nsyl,a);
        !            33:        }
        !            34: 
        !            35: }
        !            36: getword(){
        !            37:        int skip,c2;
        !            38:        int ret;
        !            39:        register char *aptr;
        !            40:        char last;
        !            41:        ret = skip = 0;
        !            42:        for(aptr=a;aptr<&a[MAXCHAR];aptr++){
        !            43:                *aptr = getchar();
        !            44:                if(*aptr == EOF){
        !            45:                        ret=EOF;
        !            46:                        break;
        !            47:                }
        !            48:                if(isdigit(*aptr)){
        !            49:                        skip = 1;
        !            50:                        continue;
        !            51:                }
        !            52:                if(isspace(*aptr)) break;
        !            53:                if(!isalnum(*aptr)){
        !            54:                        last = *(aptr-1);
        !            55:                        switch(*aptr){
        !            56:                        case '-':
        !            57:                                if(((c2=getchar())=='o' && last=='o')||
        !            58:                                    (c2=='e' &&  last=='e'))
        !            59:                                        ungetc(c2,stdin);
        !            60:                                else if(skip==0){
        !            61:                                        ungetc(c2,stdin);
        !            62:                                        goto found;
        !            63:                                }
        !            64:                                else{
        !            65:                                        ungetc(c2,stdin);
        !            66:                                        goto found;
        !            67:                                }
        !            68:                                break;
        !            69:                        case '\'':
        !            70:                                if(last=='x' || last=='c' ||last=='s'
        !            71:                                     || last=='h' ||(*(aptr-2)=='g' && last=='e'))
        !            72:                                        *aptr='\'';
        !            73:                                else if ((c2=getchar())=='t' &&  last=='n'){
        !            74:                                        ungetc(c2,stdin);
        !            75:                                        *aptr='\'';
        !            76:                                }
        !            77:                                else{
        !            78:                                        ungetc(c2,stdin);
        !            79:                                        aptr--;
        !            80:                                }
        !            81:                                break;
        !            82:                        case ',':
        !            83:                        case ';':
        !            84:                        case '?':
        !            85:                        case '!':
        !            86:                        case ':':
        !            87:                        case '~':
        !            88:                        case '/':
        !            89:                                goto found;
        !            90:                        default:
        !            91:                                aptr--;
        !            92:                        }
        !            93:                }
        !            94:        }
        !            95: found:
        !            96:        *aptr= '\0';
        !            97:        return(ret);
        !            98: }
        !            99: 
        !           100: change()
        !           101: {
        !           102:        register char *aptr, *bptr;
        !           103: 
        !           104:        char temp;
        !           105:        for(aptr=a, bptr=b;*aptr!='\0';aptr++,bptr++){
        !           106:                switch(*aptr){
        !           107:                case 'a':
        !           108:                case 'A':
        !           109:                case 'Y':
        !           110:                case 'E':
        !           111:                case 'O':
        !           112:                case 'I':
        !           113:                case 'U':
        !           114:                case 'o':
        !           115:                case '\'':
        !           116:                        *bptr='V';
        !           117:                        break;
        !           118: 
        !           119:                case 'e':
        !           120:                        if(*(aptr+1)=='a'){
        !           121:                                if(scmp("creat",(aptr-2)) && *(aptr+3) != 'u')
        !           122:                                        *bptr = 'S';
        !           123:                                else if(scmp("reac",(aptr-1)) && *(aptr+3) != 'h')
        !           124:                                        *bptr='S';
        !           125:                                else if(*(aptr+2) == '\0')*bptr = 'S';
        !           126:                                else if(*(aptr+2) == 's' && *(aptr+3) == '\0')
        !           127:                                        *bptr = 'S';
        !           128:                                else if(scmp("reali",(aptr-1)))*bptr='S';
        !           129:                                else *bptr='V';
        !           130:                        }
        !           131:                        else if(*(aptr+1)=='o'){
        !           132:                                if(aptr == &a[1] && (*(aptr-1) == 'd' || *(aptr-1) == 'r'))
        !           133:                                        *bptr = 'S';
        !           134:                                else if(aptr == &a[2] && (*(aptr-2) == 'p' && *(aptr-1) == 'r'))
        !           135:                                        *bptr= 'S';
        !           136:                                else if(*(aptr+2)=='u') *bptr='S';
        !           137:                                else if(*(aptr+2) == '0') *bptr='S';
        !           138:                                else *bptr='V';
        !           139:                        }
        !           140:                        else if(*(bptr-2)=='C' && *(aptr-2)!='l' &&
        !           141:                            *(aptr-1)=='l') *bptr='V';
        !           142:                        else if( *(aptr+1)=='l' &&*(aptr+2)=='y' )
        !           143:                                 *bptr='C';
        !           144:                        else if(scmp("liness",aptr+1))*bptr='C';
        !           145:                        else if(scmp("lihood",aptr+1))*bptr='C';
        !           146:                        else if(scmp("ful",aptr+1))*bptr = 'C';
        !           147:                        else if(scmp("nless",aptr+1))*bptr = 'C';
        !           148:                        else if(scmp("ment",aptr+1))*bptr = 'C';
        !           149:                        else if(scmp("ship",aptr+1))*bptr='C';
        !           150:                        else *bptr='V';
        !           151:                        break;
        !           152: 
        !           153:                case 'i':
        !           154:                        if(*(aptr+1)=='e'){
        !           155:                                if(*(aptr+2)=='r') *bptr='S';
        !           156:                                else if(*(aptr+2)=='t') *bptr='S';
        !           157:                                else if(scmp("icient",aptr-2))*bptr='V';
        !           158:                                else if(scmp("nient",aptr-1))*bptr='V';
        !           159:                                else if(*(aptr+2)=='n' && *(aptr+3)=='t')
        !           160:                                        *bptr='S';
        !           161:                                else if(scmp("icienc",aptr-2))*bptr='V';
        !           162:                                else if(scmp("nienc",aptr-1))*bptr='V';
        !           163:                                else if(*(aptr+2)=='n' && *(aptr+3)=='c')
        !           164:                                        *bptr='S';
        !           165:                                else *bptr='V';
        !           166:                        }
        !           167:                        else if(*(aptr+1)=='o'){
        !           168:                                if(*(aptr-1)=='v' && *(aptr+2)=='r') *bptr='V';
        !           169:                                else if(*(aptr-1)=='r') *bptr='S';
        !           170:                                else if(*(aptr+2)=='u') *bptr='S';
        !           171:                                else if(*(aptr-1)=='v' || *(aptr-1)=='V')
        !           172:                                        *bptr='S';
        !           173:                                else if(*(aptr+2) == '\0') *bptr='S';
        !           174:                                else *bptr='V';
        !           175:                        }
        !           176:                        else if(*(aptr+1)=='a'){
        !           177:                                if((*(aptr-1)=='c' || *(aptr-1)=='t') &&
        !           178:                                          *(aptr-2)=='o') *bptr='S';
        !           179:                                else if (*(aptr-1)=='c' || *(aptr-1)=='t')
        !           180:                                        *bptr='V';
        !           181:                                else *bptr='S';
        !           182:                        }
        !           183:                        else *bptr='V';
        !           184:                        break;
        !           185:                case 'u':
        !           186:                        if(*(aptr-1) == 'q' || *(aptr-1) == 'Q')
        !           187:                                *bptr = 'C';
        !           188:                        else if( (*(aptr-1) == 'g' || *(aptr-1) == 'G') &&
        !           189:                            (isvowel(*(aptr+1))||*(aptr+1) == 'y')) *bptr='C';
        !           190:                        else if(*(aptr+1)=='a'){
        !           191:                                if(*(aptr-1)=='t' || *(aptr-1)=='d' ||
        !           192:                                        *(aptr-1)=='s') *bptr='S';
        !           193:                                else if(*(aptr+2)=='t') *bptr='S';
        !           194:                                else *bptr='V';
        !           195:                        }
        !           196:                        else if(*(aptr+1)=='e'){
        !           197:                                if(*(aptr-1)=='l') *bptr='S';
        !           198:                                else if(*(aptr-2)=='g' && *(aptr-1)=='r')
        !           199:                                        *bptr='S';
        !           200:                                else *bptr='V';
        !           201:                        }
        !           202:                        else *bptr='V';
        !           203:                        break;
        !           204:                case 'y':
        !           205:                        if((aptr>a&& *(aptr+1) != '\0') && *(bptr-1) == 'V'
        !           206:                                && (isvowel(*(aptr+1))))
        !           207:                                *bptr='C';
        !           208:                        else *bptr='V';
        !           209:                        break;
        !           210:                case 'n':
        !           211:                        if(*(aptr-1)=='i' && *(aptr+1)=='g'){
        !           212:                                *(bptr-1)='C';
        !           213:                                *bptr='V';
        !           214:                        }
        !           215:                        else *bptr='C';
        !           216:                        break;
        !           217:                default:
        !           218:                        *bptr='C';
        !           219:                }
        !           220:        }
        !           221: 
        !           222:        *bptr='\0';
        !           223:                        /*sitting on last char*/
        !           224:        aptr--;
        !           225:        bptr--;
        !           226:        if(*(aptr-1)=='e' && *aptr=='d'){
        !           227:                if(*(aptr-2)=='t' || *(aptr-2) == 'd'||(*(bptr-3)=='C' && *(aptr-2)=='l'
        !           228:                    && *(aptr-3) !='l')){
        !           229:                        *(bptr) = *(bptr-2) = 'C';
        !           230:                        *(bptr-1)='V';
        !           231:                }
        !           232:                else{
        !           233:                        *bptr = *(bptr-1)= 'C';
        !           234:                }
        !           235:                return;
        !           236:        }
        !           237:        temp = *(aptr-2);
        !           238:        if((temp=='s'||temp=='g'|| temp== 'h'|| temp=='c'|| temp=='z')  && (*(aptr-1)=='e' &&  *aptr=='s')){
        !           239:                *bptr = *(bptr-2)='C';
        !           240:                *(bptr-1)='V';
        !           241:                return;
        !           242:        }
        !           243:        if(*(bptr-3)=='C' && temp=='l' && *(aptr-1)=='e' && *aptr=='s'){
        !           244:                *bptr = *(bptr-2)='C';
        !           245:                *(bptr-1)='V';
        !           246:                return;
        !           247:        }
        !           248:        if(*(aptr-1)=='e' && *aptr=='s'){
        !           249:                *bptr = *(bptr-1) = 'C';
        !           250:                return;
        !           251:        }
        !           252:        if(*(bptr-2)=='C' && *(aptr-1)=='l' && *aptr=='e'){
        !           253:                *bptr='V';
        !           254:                *(bptr-1)='C';
        !           255:                return;
        !           256:        }
        !           257:        if(*aptr=='e') *bptr='C';
        !           258: 
        !           259: }
        !           260: 
        !           261: estimate()
        !           262: {
        !           263:        register char *bptr;
        !           264:        int k,f,i;
        !           265:        k=0;
        !           266:        f=1;
        !           267:        for(bptr=b;*bptr!='\0';bptr++){
        !           268:                if(f==1 && *bptr=='V'){
        !           269:                        f=2;
        !           270:                        k++;
        !           271:                }
        !           272:                if(f==1 && *bptr=='S') k++;
        !           273:                if(f==2 && *bptr=='C') f=1;
        !           274:                else if(f==2 && *bptr=='S'){
        !           275:                        f=1;
        !           276:                        k++;
        !           277:                }
        !           278:        }
        !           279:        if(k>0) return(k);
        !           280:        else return(1);
        !           281: }
        !           282: 
        !           283: scmp(s1,s2)
        !           284: char *s1,*s2;
        !           285: {
        !           286:        char *s, *p;
        !           287:        for(s=s1, p=s2;*s != '\0';s++,p++){
        !           288:                if(*s != *p)return(0);
        !           289:        }
        !           290:        return(1);
        !           291: }

unix.superglobalmegacorp.com

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