1: /* permuted title index */
   2: 
   3: char    *tfil "/tmp/p.tmp";
   4: char    *sw[] {
   5:     "a",
   6:     "an",
   7:     "and",
   8:     "as",
   9:     "for",
  10:     "is",
  11:     "of",
  12:     "on",
  13:     "or",
  14:     "the",
  15:     "to",
  16:     "up",
  17:     0};
  18: char    line[200];
  19: int ch;
  20: int ptflg;
  21: int llen    72;
  22: 
  23: main(argc, argv)
  24: int argc;
  25: char *argv[];
  26: {
  27:     extern fin, fout;
  28:     extern onintr();
  29:     int f;
  30: 
  31:     if(argc>1 && *argv[1]=='-') {
  32:         llen = 100;
  33:         ptflg++;
  34:         argc--;
  35:         argv++;
  36:     }
  37:     if(argc<2) {
  38:         printf("arg count\n");
  39:         exit();
  40:     }
  41:     fin = open(argv[1]);
  42:     if(fin < 0) {
  43:         printf("%s: cannot open\n", argv[1]);
  44:         exit();
  45:     }
  46:     f = creat(tfil, 0600);
  47:     if(f < 0) {
  48:         printf("cannot create %s\n", tfil);
  49:         exit();
  50:     }
  51:     fout = f;
  52:     if ((signal(2, 1) & 01) ==0)
  53:         signal(2, onintr);
  54:     pass1();
  55:     flush();
  56:     close(fin);
  57:     fin = 0;
  58:     close(fout);
  59:     fout = 1;
  60:     f = fork();
  61:     if(f < 0) {
  62:         printf("try again\n");
  63:         exit();
  64:     }
  65:     if(f == 0) {
  66:         execl("/bin/sort", "sort", "-d", "-o", tfil, tfil, 0);
  67:         execl("/usr/bin/sort", "sort", "-d", "-o", tfil, tfil, 0);
  68:         printf("someone moved sort\n");
  69:         exit();
  70:     }
  71:     while(wait() != f);
  72:     fin = open(tfil, 0);
  73:     if(fin < 0) {
  74:         printf("cannot reopen %s\n", tfil);
  75:         exit();
  76:     }
  77:     if (argc>=3)
  78:         f = creat(argv[2], 0666);
  79:     else
  80:         f = dup(1);
  81:     if(f < 0) {
  82:         printf("%s: cannot open\n", argv[2]);
  83:         exit();
  84:     }
  85:     fout = f;
  86:     pass2();
  87:     flush();
  88:     onintr();
  89: }
  90: 
  91: onintr()
  92: {
  93:     unlink(tfil);
  94:     exit();
  95: }
  96: 
  97: pass1()
  98: {
  99:     int n, c, i, ll, j, k, cc, ccc;
 100: 
 101: loop:
 102:     if ((c=getchar())=='\0')
 103:         return;
 104:     n = 0;
 105:     i = 0;
 106:     while(c!='\n' && c!='\0') {
 107:         if(c == '(')
 108:             c = 0177;
 109:         if(c==' ' || c=='\t') {
 110:             i++;
 111:             c = getchar();
 112:             continue;
 113:         }
 114:         if(i) {
 115:             i = 0;
 116:             if(n<=llen) line[n++] = ' ';
 117:         }
 118:         if (n<=llen) line[n++] = c;
 119:         c = getchar();
 120:     }
 121:     ll = n;
 122:     line[n++] = 0;
 123:     i = -1;
 124: l1:
 125:     while((cc=line[++i])==' ');
 126:     n = i;
 127:     j = 0;
 128:     while(sw[j]) {
 129:         i = n;
 130:         k = 0;
 131:         while ((cc=sw[j][k++])==line[i++]);
 132:         if(cc==0 && ((ccc=line[--i])==' '||ccc==0))
 133:             goto l1;
 134:         j++;
 135:     }
 136:     i = n;
 137:     while (c=line[n++]) putchar(c);
 138:     putchar('~');
 139:     n = 0;
 140:     while (n<i) {
 141:         c = line[n++];
 142:         if (c!=' ' || n!=i)
 143:             putchar(c);
 144:     }
 145:     putchar('\n');
 146:     while((c=line[i++])!=0 && c!=' ');
 147:     --i;
 148:     if (c) goto l1;
 149:     goto loop;
 150: }
 151: 
 152: pass2()
 153: {
 154:     int i, n, c, tilde, llen2, nbfore, nafter;
 155: 
 156: 
 157:     llen2 = llen/2+6;
 158: loop:
 159:     if ((c=getchar())=='\0')
 160:         return;
 161:     n = nbfore = nafter = 0;
 162:     tilde = -1;
 163:     while(c!='\n' && c!='\0') {
 164:         if(c == 0177)
 165:             c = '(';
 166:         if (n<=llen) line[n] = c;
 167:         if (c=='~') tilde = n;
 168:         if (tilde>=0) nafter++; else nbfore++;
 169:         n++;
 170:         c = getchar();
 171:     }
 172:     if (tilde<0)
 173:         tilde = n++;
 174:     nafter--;
 175:     if (nbfore>llen2) {
 176:         i = tilde;
 177:         while (nbfore > llen2)
 178:             while(line[--i]!=' ' && i>=0) nbfore--;
 179:         if (i<0) goto l1;
 180:         line[tilde] = 0200;
 181:         nafter =+ (tilde-i+2);
 182:         tilde = i;
 183:     }
 184:     if (nafter >= llen-llen2) {
 185:         i = tilde;
 186:         while(nafter-- >= llen-llen2)
 187:             while(line[++i]!=' ' && i<n) nafter--;
 188:         if (i>=n) goto l1;
 189:         line[tilde] = 0200;
 190:         nafter++;
 191:         tilde = i;
 192:     }
 193: l1:
 194:     if(!ptflg) {
 195:         for(i=llen-llen2-nafter; i>=8; i =- 8)
 196:             putchar('\t');
 197:         while(--i>=0)
 198:             putchar(' ');
 199:     } else
 200:         printf(".xx \"");
 201:     i = tilde;
 202:     while (++i<n) p1char(line[i]);
 203:     if(!ptflg)
 204:         printf("  "); else
 205:         printf("\" \"");
 206:     i = -1;
 207:     while(++i<tilde) p1char(line[i]);
 208:     if(ptflg)
 209:         putchar('"');
 210:     putchar('\n');
 211:     goto loop;
 212: }
 213: 
 214: p1char(c)
 215: {
 216:     if ((c&0377) == 0200) {
 217:         putchar('.');
 218:         putchar('.');
 219:         c = '.';
 220:     }
 221:     putchar(c);
 222: }

Defined functions

main defined in line 23; never used
onintr defined in line 91; used 3 times
p1char defined in line 214; used 2 times
pass1 defined in line 97; used 1 times
  • in line 54
pass2 defined in line 152; used 1 times
  • in line 86

Defined variables

ch defined in line 19; never used
line defined in line 18; used 16 times
llen defined in line 21; used 8 times
ptflg defined in line 20; used 4 times
sw defined in line 4; used 2 times
tfil defined in line 3; used 9 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1154
Valid CSS Valid XHTML 1.0 Strict