Annotation of researchv10dc/cmd/wwb/odouble.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include "cbtype.h"
        !             3: char *getl();
        !             4: char *filename;
        !             5: int lineno;
        !             6: char *beg1, *beg2;
        !             7: char left = '\0';
        !             8: char right = '\0';
        !             9: main(argc,argv)
        !            10: char *argv[];
        !            11: {
        !            12:        int doub = 0;
        !            13: 
        !            14:        if(argc <= 1){
        !            15:                filename = "stdin";
        !            16:                doub = work();
        !            17:        }
        !            18:        else {
        !            19:                while(argc > 1){
        !            20:                        argc--; argv++;
        !            21:                        if(freopen(argv[0], "r", stdin) == NULL){
        !            22:                                fprintf(stderr,"DOUBLE CANNOT OPEN FILE %s\n",argv[0]);
        !            23:                                continue;
        !            24:                        }
        !            25:                        filename = argv[0];
        !            26:                        doub += work();
        !            27:                }
        !            28:        }
        !            29:        exit(doub);
        !            30: }
        !            31: char buf1[512];
        !            32: char buf2[512];
        !            33: int toggle;
        !            34: char *p1, *p2;
        !            35: char word[80], prev[80];
        !            36: char delim[] = "delim";
        !            37: work()
        !            38: {
        !            39:        char *b;
        !            40:        int doub;
        !            41:        int flag, lend;
        !            42:        int skip;
        !            43:        int l;
        !            44:        doub = 0;
        !            45:        lend = 1;
        !            46:        lineno = 1;
        !            47:        skip = 0;
        !            48:        beg1 = p1 = getl(buf1);
        !            49:        toggle = 1;
        !            50:         strcpy(prev,"qqxz");
        !            51:        while((flag=getword()) != 0){
        !            52:                if(flag == 2)
        !            53:                        if(toggle == 1)b=beg2;
        !            54:                        else b=beg1;
        !            55:                else if(toggle == 1)b = beg1;
        !            56:                else b = beg2;
        !            57:                if(*b == '.'){
        !            58:                        if(strcmp(word,"TS") == 0 || strcmp(word,"EQ")== 0 ||
        !            59:                            strcmp(word,"DS") == 0 || strcmp(word,"PS") == 0){
        !            60:                                skip++;
        !            61:                                continue;
        !            62:                        }
        !            63:                        else if(strcmp(word, "TE") == 0|| strcmp(word,"EN") == 0 ||
        !            64:                              strcmp(word,"DE") == 0 ||strcmp(word,"PE") == 0){
        !            65:                                if(--skip < 0)skip = 0;
        !            66:                                continue;
        !            67:                        }
        !            68:                }
        !            69:                if(strcmp(word, delim) == 0 && skip){
        !            70:                        getdel();
        !            71:                        continue;
        !            72:                }
        !            73:                 if (strcmp(word, prev) ==0 && skip == 0){
        !            74:                         if(word[1]=='\0' && word[0] !='a')
        !            75:                                 ;
        !            76:                        else {
        !            77:                                if(lend == 1 && flag != 3){
        !            78:                                        if(flag == 2)l=lineno-1;
        !            79:                                        else l=lineno;
        !            80:                                        printf("%s twice line %d file %s\n",prev,l,filename);
        !            81:                                        if(flag == toggle)
        !            82:                                                printf("%s\n",buf1);
        !            83:                                        else printf("%s\n",buf2);
        !            84:                                }
        !            85:                                else {
        !            86:                                        printf("%s twice beginning line %d file %s\n",prev,lineno-1,filename);
        !            87:                                        if(toggle == 2)printf("%s%s\n",buf1,buf2);
        !            88:                                        else printf("%s%s\n",buf2,buf1);
        !            89:                                }
        !            90:                                 doub++;
        !            91:                                flag = 1;
        !            92:                         }
        !            93:                 }
        !            94:                 strcpy(prev,word);
        !            95:                lend = flag;
        !            96:         }
        !            97:         return(doub);
        !            98: }
        !            99: getword()
        !           100: {
        !           101:        int c;
        !           102:        char *p, *w;
        !           103:        int reset;
        !           104:        int ret;
        !           105:        int skip;
        !           106:        ret = 1;
        !           107:        reset=skip=0;
        !           108:        w = word;
        !           109:        if(toggle == 1)p=p1;
        !           110:        else p=p2;
        !           111: rest:
        !           112:        while(*p != '\n'){
        !           113:                if(*p == left){
        !           114:                        if(skip == 1 && *p == right)skip = 0;
        !           115:                        else {
        !           116:                                skip = 1;
        !           117:                                strcpy(prev,"qqxz");
        !           118:                        }
        !           119:                        p++;
        !           120:                        continue;
        !           121:                }
        !           122:                if(*p == right){
        !           123:                        skip = 0;
        !           124:                        p++;
        !           125:                        continue;
        !           126:                }
        !           127:                if(skip){
        !           128:                        p++;
        !           129:                        continue;
        !           130:                }
        !           131:                if(isalpha(*p) ||(w > word &&(*p == '-' || *p == '\''|| isdigit(*p))))
        !           132:                        *w++ = *p++;
        !           133:                else if(w == word){
        !           134:                        if(*p == '\\'){
        !           135:                                p++;
        !           136:                                if(*p == '(')p+=2;
        !           137:                                strcpy(prev,"qqxz");
        !           138:                                ret=1;
        !           139:                                reset=1;
        !           140:                        }
        !           141:                        if(isdigit(*p) || isop(*p)|| *p == '/' || *p == '('){
        !           142:                                strcpy(prev,"qqxz");
        !           143:                                ret=1;
        !           144:                                reset=1;
        !           145:                        }
        !           146:                        p++;
        !           147:                }
        !           148:                else {
        !           149:                        *w = '\0';
        !           150:                        if(toggle == 1)p1 = p;
        !           151:                        else p2 = p;
        !           152:                        return(ret);
        !           153:                }
        !           154:         }
        !           155:        lineno++;
        !           156:        if(toggle == 1){
        !           157:                beg2 = p = p2 = getl(buf2);
        !           158:                toggle = 2;
        !           159:        }
        !           160:        else {
        !           161:                beg1 = p = p1 = getl(buf1);
        !           162:                toggle = 1;
        !           163:        }
        !           164:        if(p == EOF)return(0);
        !           165:        if(w == word){
        !           166:                if(reset == 0)ret = 3;
        !           167:                goto rest;
        !           168:        }
        !           169:        *w = '\0';
        !           170:        return(2);
        !           171: }
        !           172: char *
        !           173: getl(p)
        !           174: char *p;
        !           175: {
        !           176:        int c;
        !           177:        char *q;
        !           178:        q = p;
        !           179:        while((*q++ = c = getchar()) != '\n'){
        !           180:                if(q >= p + 511){
        !           181:                        printf("out of buffer space\n");
        !           182:                        exit(1);
        !           183:                }
        !           184:                if(c == EOF)
        !           185:                        return((char *)c);
        !           186:        }
        !           187:        *q = '\0';
        !           188:        return(p);
        !           189: }
        !           190: getdel(){
        !           191:        char *p;
        !           192:        if(toggle == 1)p=p1;
        !           193:        else p=p2;
        !           194:        while(*p == ' ')p++;
        !           195:        left = *p++;
        !           196:        right = *p++;
        !           197:        if(toggle == 1)p1=p;
        !           198:        else p2=p;
        !           199: }

unix.superglobalmegacorp.com

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