1: /*int	mbuf[1024];	/*INSTR*/
   2: int psw 1;
   3: int initf   1;
   4: 
   5: main(argc, argv)
   6:     char    *argv[];
   7: {
   8:     auto    f,fct,file;
   9: 
  10:     if(argc < 2) {
  11:         printf("Usage: cpost [-d] file1 file2 ...\n");
  12:         exit();
  13:     }
  14: 
  15:     if(*argv[1] == '-') {
  16:         fct = argv[1][1] - '0';
  17:         if((fct < 1) || (fct > 9)) {
  18:             printf("-d: 0 < d < 10\n");
  19:             exit();
  20:         }
  21:         argv++;
  22:         argc--;
  23:     } else {
  24:         fct = 1;
  25:     }
  26: 
  27:     f = 0;
  28:     while(++f < argc) {
  29:         file = open(argv[f], 0);
  30: 
  31:         edl(file, fct);
  32: 
  33:         close(file);
  34:         psw = 0;
  35:     }
  36:     flsh(0);
  37: 
  38:     exit();
  39: }
  40: 
  41: int lno 1;
  42: 
  43: edl(file)
  44: {
  45:     auto t,l;
  46:     char    static  buf[20],fld[20],line[200];
  47:     char    c;
  48: field:
  49:     t = -1;
  50:     while(((buf[++t] = get(file)) != '\t') && (buf[t] != -1))
  51:         if(buf[t] == '\0')  goto done;
  52: 
  53:     if((c = buf[t]) == -1)  c = ' ';
  54:     buf[t] = '\0';
  55:     if(comp(buf,fld)) {
  56:         lno++;
  57:         goto junk;
  58:     } else {
  59:         if(lno == 0) {
  60:             put(0,line,++l);
  61:         }
  62:         l = copy(buf,line);
  63:         copy(buf,fld);
  64:         line[--l] = c;
  65:         lno = 0;
  66:         goto fill;
  67:     }
  68: 
  69: fill:
  70:     while((line[++l] = get(file)) != '\n') {
  71:         if(line[l] == -1)   line[l] = ' ';
  72:         if(line[l] == '\0') goto done;
  73:     }
  74: 
  75:     goto field;
  76: 
  77: junk:
  78:     while((*line = get(file)) != '\n')
  79:         if(*line == '\0')   goto done;
  80: 
  81:     goto field;
  82: 
  83: done:
  84:     if(lno == 0)
  85:         put(0,line,++l);
  86:         lno = 1;
  87:     return(0);
  88: 
  89: }
  90: 
  91: 
  92: 
  93: gfld(file, buf)
  94:     char    *buf;
  95: {
  96:     char    c;
  97: 
  98:     buf--;
  99:     while(*++buf  = get(file)) {
 100:         if((*buf == '\t') || (*buf == '\n')) {
 101:             c = *buf;
 102:             *buf = '\0';
 103:             return(c);
 104:         } else {
 105:             continue;
 106:         }
 107:     }
 108:     return('\0');
 109: }
 110: 
 111: copy(a, b)
 112:     char    *a,*b;
 113: {
 114:     char    *c;
 115: 
 116:     b--;
 117:     c = --a;
 118:     while(*++b = *++a);
 119:     return(a - c);
 120: }
 121: 
 122: comp(a, b)
 123:     char    *a, *b;
 124: {
 125: /*	printf("comp: %s %s\n",a,b); /*DEBUG*/
 126:     a--;
 127:     b--;
 128:     while(*++a == *++b) {
 129:         if(*a == '\0')  return(1);
 130:     }
 131:     return(0);
 132: }
 133: 
 134: 
 135: char    buf[512];
 136: int nread   1;
 137: 
 138: get(ifile) int ifile;
 139: {
 140: 
 141:     char static *ibuf;
 142: 
 143:     if(--nread){
 144:         return(*ibuf++);
 145:     }
 146: 
 147:     if(nread = read(ifile,buf,512)){
 148:         if(nread < 0)goto err;
 149: 
 150:         ibuf = buf;
 151:         return(*ibuf++);
 152:     }
 153: 
 154:     nread = 1;
 155:     return(0);
 156: 
 157: err:
 158:     nread = 1;
 159:     printf("read error\n");
 160:     return(0);
 161: 
 162: }
 163: 
 164: 
 165: int tp[1]   1;
 166: int optr[4];
 167: char    bsp[512];
 168: 
 169: char    *obuf[1]    bsp;
 170: 
 171: int nflush;
 172: 
 173: put(fil,string,n)
 174:     char    *string;
 175: {
 176:     int i;
 177:     char    *o;
 178: 
 179: /*printf("%d %c %d\n",fil,*string,n);/*DEBUG*/
 180: 
 181:     string--;
 182: 
 183:     if((i = optr[fil] + n - 512) >= 0) {
 184:         n =- i;
 185:         o = &obuf[fil][optr[fil]] -1;
 186:         while(--n >= 0)
 187:             *++o = *++string;
 188:         optr[fil] = 512;
 189:         flsh(fil);
 190:         n = i;
 191:     }
 192: 
 193:     o = &obuf[fil][optr[fil]] - 1;
 194:     optr[fil] =+ n;
 195: 
 196:     while(--n >= 0) {
 197:         *++o = *++string;
 198:     }
 199:     return(0);
 200: }
 201: 
 202: flsh(fil)
 203: {
 204:     extern  tp[];
 205: 
 206:     if(optr[fil] <= 0)  return(optr[fil]);
 207: 
 208:     nflush++;
 209:     if(write(tp[fil],obuf[fil],optr[fil]) != optr[fil])
 210:         return(-1);
 211:     optr[fil] = 0;
 212:     return(0);
 213: }

Defined functions

comp defined in line 122; used 1 times
  • in line 55
copy defined in line 111; used 2 times
edl defined in line 43; used 1 times
  • in line 31
flsh defined in line 202; used 3 times
get defined in line 138; used 4 times
gfld defined in line 93; never used
main defined in line 5; never used
put defined in line 173; used 20 times

Defined variables

bsp defined in line 169; never used
buf defined in line 135; used 19 times
initf defined in line 3; never used
lno defined in line 41; used 5 times
nflush defined in line 171; used 1 times
nread defined in line 136; used 5 times
obuf defined in line 169; used 3 times
optr defined in line 166; used 10 times
psw defined in line 2; used 1 times
  • in line 34
tp defined in line 165; used 2 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 923
Valid CSS Valid XHTML 1.0 Strict