Annotation of researchv8dc/cmd/wwb/chunk.c, revision 1.1.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: #define min(a,b)       (a>b?b:a)
                      5: #define MAXWORDS 200
                      6: #define MAXCHAR 2000
                      7: #define MAJOR 7
                      8: char buf[MAXCHAR];
                      9: char *bptr;
                     10: struct word{
                     11:        int brklvl;
                     12:        char *string;
                     13: };
                     14: struct word line[MAXWORDS];
                     15: struct word *fst;
                     16: struct word *lst;
                     17: 
                     18: main(){
                     19:        int l;
                     20: struct word *ptr;
                     21:        do{
                     22:                lst=fst= &line[0];
                     23:                bptr = buf;
                     24:                l=readline();
                     25:                findbrk();
                     26:                if(fst != lst){
                     27:                        divide();
                     28:                        writes();
                     29:                }
                     30:        } while(l != EOF);
                     31: }
                     32: 
                     33: 
                     34: readline()
                     35: {
                     36:        int flag;
                     37:        do{
                     38:                lst->string = bptr;
                     39:                flag=getword();
                     40:                if(lst->string == bptr)
                     41:                        break;
                     42:                lst++;
                     43:        } while(flag == 1 && lst <= &line[MAXWORDS]);
                     44:        return(flag);
                     45: }
                     46: 
                     47: 
                     48: getword()
                     49: {
                     50:        int c,i;
                     51:        int ret;
                     52:        lst->brklvl = 0;
                     53:        ret = 1;
                     54:        for(i=0;i < MAXCHAR-1; ++i){
                     55:                c= *bptr++ = getchar();
                     56:                switch(c){
                     57:                case '.':
                     58:                case '?':
                     59:                case '!':
                     60:                        lst->brklvl=5;
                     61:                        ret = 0;
                     62:                        goto done;
                     63:                case ';':
                     64:                case ':':
                     65:                        lst->brklvl=4;
                     66:                        goto done;
                     67:                case ',':
                     68:                        lst->brklvl=3;
                     69:                        goto done;
                     70:                case ' ':
                     71:                case '\t':
                     72:                case '\n':
                     73:                        --bptr;
                     74:                        if(bptr==lst->string) {
                     75:                                break;
                     76:                        }
                     77:                        lst->brklvl=0;
                     78:                        goto done;
                     79:                case EOF:
                     80:                        --bptr;
                     81:                        if(bptr==lst->string){
                     82:                                lst->brklvl=0;
                     83:                                return(EOF);
                     84:                        }
                     85:                        lst->brklvl=0;
                     86:                        ret = EOF;
                     87:                        goto done;
                     88: 
                     89:                }
                     90:        }
                     91: done:
                     92:        *bptr++='\0';
                     93:        return(ret);
                     94: }
                     95: 
                     96: 
                     97: int m[6] = {7,7,7,5,5,0};
                     98: divide()
                     99: {
                    100:        struct word *ptr;
                    101:        int i,pc,ba[3][20],j,np,ct,nct,jct;
                    102:        i=0;
                    103:        j=1;
                    104:        for(ptr=fst;ptr <lst;ptr++){
                    105:                if(ptr->brklvl != 0){
                    106:                        ba[0][i]=j;
                    107:                        ba[1][i]=ptr->brklvl;
                    108:                        i++;
                    109:                }
                    110:                j++;
                    111:        }
                    112:        pc = i;
                    113:        for(np=pc-1;np>0;np--) ba[2][np]=ba[0][np]-ba[0][np-1];
                    114:        ba[2][0]=ba[0][0];
                    115: 
                    116:        ct=0;
                    117:        for (i=0;i<pc-1;i++){
                    118:                ct=ct+ba[2][i];
                    119:                while (ct >7){
                    120:                        if (ct <= 10) {
                    121:                                (fst+(ba[0][i]-1))->brklvl=6;
                    122:                                ct=0;
                    123:                        }
                    124:                        else {
                    125:                                nct = ct/2;
                    126:                                if (nct > 7) nct =7;
                    127:                                (fst + (ba[0][i] - ct + nct) )->brklvl = 6;
                    128:                                ct = ct - nct;
                    129:                        }
                    130:                }
                    131:                if(ct >2){
                    132:                        jct=0;
                    133:                        for(j=i+1;j<pc;j++){
                    134:                                jct=jct+ba[2][j];
                    135:                                if(jct >min(m[ba[1][i]],7-ct)){
                    136:                                        (fst+(ba[0][i]-1))->brklvl=6;
                    137:                                        ct=0;
                    138:                                        break;
                    139:                                }
                    140:                                else if(ba[1][i] <=ba[1][j]) break;
                    141:                        }
                    142:                }
                    143:        }
                    144: }
                    145: writes()
                    146: {
                    147:        struct word *ptr;
                    148:        for(ptr=fst;ptr <lst; ptr++){
                    149:                printf("%s ",ptr->string);
                    150:                if(ptr->brklvl>=5)putchar('\n');
                    151:        }
                    152: }
                    153: 
                    154: char *wds[]={
                    155:        "and",
                    156:        "is",
                    157:        "at",
                    158:        "but",
                    159:        "or",
                    160:        "if",
                    161:        "because",
                    162:        "since",
                    163:        "to",   /* beginning of minor wds*/
                    164:        "in",
                    165:        "that",
                    166:        "for",
                    167:        "with",
                    168:        "on",
                    169:        "by",
                    170:        "from",
                    171:        "which",
                    172:        "would",
                    173:        "when",
                    174:        "what",
                    175:        "into",
                    176:        "than",
                    177:        "could",
                    178:        "may",
                    179:        "where",
                    180:        "through",
                    181:        "how",
                    182:        "between",
                    183:        "without",
                    184:        "why",
                    185:        "among",
                    186:        "beside",
                    187:        "besides",
                    188:        0
                    189: };
                    190: 
                    191: findbrk(){
                    192:        struct word *ptr;
                    193:        int ret;
                    194:        char **p;
                    195:        ret=0;
                    196:        for(ptr=fst; ptr< lst; ptr++){
                    197:                for(p=wds;*p!=0;p++){
                    198:                        if(strcmp(ptr->string,*p)== 0){
                    199:                                if((ptr-1)->brklvl!=3){
                    200:                                        if(p > &wds[MAJOR])
                    201:                                                (ptr-1)->brklvl=1;
                    202:                                        else (ptr-1)->brklvl = 2;
                    203:                                }
                    204:                                ret=1;
                    205:                                break;
                    206:                        }   
                    207:                }
                    208:        }
                    209:        return(ret);
                    210: }
                    211: 

unix.superglobalmegacorp.com

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