1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)colrm.c	5.1 (Berkeley) 5/31/85";
  15: #endif not lint
  16: 
  17: #include <stdio.h>
  18: /*
  19: COLRM removes unwanted columns from a file
  20: 	Jeff Schriebman  UC Berkeley 11-74
  21: */
  22: 
  23: 
  24: main(argc,argv)
  25: char **argv;
  26: {
  27:     register c, ct, first, last;
  28: 
  29:     first = 0;
  30:     last = 0;
  31:     if (argc > 1)
  32:         first = getn(*++argv);
  33:     if (argc > 2)
  34:         last = getn(*++argv);
  35: 
  36: start:
  37:     ct = 0;
  38: loop1:
  39:     c = getc(stdin);
  40:     if (feof(stdin))
  41:         goto fin;
  42:     if (c == '\t')
  43:         ct = (ct + 8) & ~7;
  44:     else if (c == '\b')
  45:         ct = ct ? ct - 1 : 0;
  46:     else
  47:         ct++;
  48:     if (c == '\n') {
  49:         putc(c, stdout);
  50:         goto start;
  51:     }
  52:     if (!first || ct < first) {
  53:         putc(c, stdout);
  54:         goto loop1;
  55:     }
  56: 
  57: /* Loop getting rid of characters */
  58:     while (!last || ct < last) {
  59:         c = getc(stdin);
  60:         if (feof(stdin))
  61:             goto fin;
  62:         if (c == '\n') {
  63:             putc(c, stdout);
  64:             goto start;
  65:         }
  66:         if (c == '\t')
  67:             ct = (ct + 8) & ~7;
  68:         else if (c == '\b')
  69:             ct = ct ? ct - 1 : 0;
  70:         else
  71:             ct++;
  72:     }
  73: 
  74: /* Output last of the line */
  75:     for (;;) {
  76:         c = getc(stdin);
  77:         if (feof(stdin))
  78:             break;
  79:         putc(c, stdout);
  80:         if (c == '\n')
  81:             goto start;
  82:     }
  83: fin:
  84:     fflush(stdout);
  85: }
  86: 
  87: getn(ap)
  88: char *ap;
  89: {
  90:     register int n,c;
  91:     register char *p;
  92: 
  93:     p = ap;
  94:     n = 0;
  95:     while ((c = *p++) >= '0' && c <= '9')
  96:         n = n*10 + c - '0';
  97:     return(n);
  98: }

Defined functions

getn defined in line 87; used 2 times
main defined in line 24; never used

Defined variables

copyright defined in line 8; never used
sccsid defined in line 14; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 433
Valid CSS Valid XHTML 1.0 Strict