121551Sdist /* 221551Sdist * Copyright (c) 1980 Regents of the University of California. 332749Sbostic * All rights reserved. 432749Sbostic * 5*42723Sbostic * %sccs.include.redist.c% 621551Sdist */ 721551Sdist 821551Sdist #ifndef lint 921551Sdist char copyright[] = 1021551Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 1121551Sdist All rights reserved.\n"; 1232749Sbostic #endif /* not lint */ 1321551Sdist 1421551Sdist #ifndef lint 15*42723Sbostic static char sccsid[] = "@(#)colrm.c 5.4 (Berkeley) 06/01/90"; 1632749Sbostic #endif /* not lint */ 1721551Sdist 18986Sbill #include <stdio.h> 19986Sbill /* 20986Sbill COLRM removes unwanted columns from a file 21986Sbill Jeff Schriebman UC Berkeley 11-74 22986Sbill */ 23986Sbill 24986Sbill 25986Sbill main(argc,argv) 26986Sbill char **argv; 27986Sbill { 2816659Sralph register c, ct, first, last; 29986Sbill 3016659Sralph first = 0; 3116659Sralph last = 0; 3216659Sralph if (argc > 1) 33986Sbill first = getn(*++argv); 3416659Sralph if (argc > 2) 35986Sbill last = getn(*++argv); 36986Sbill 37986Sbill start: 38986Sbill ct = 0; 39986Sbill loop1: 405791Sroot c = getc(stdin); 415791Sroot if (feof(stdin)) 42986Sbill goto fin; 431358Sbill if (c == '\t') 4416659Sralph ct = (ct + 8) & ~7; 451358Sbill else if (c == '\b') 461358Sbill ct = ct ? ct - 1 : 0; 471358Sbill else 481358Sbill ct++; 4916659Sralph if (c == '\n') { 5016659Sralph putc(c, stdout); 51986Sbill goto start; 52986Sbill } 5316659Sralph if (!first || ct < first) { 5416659Sralph putc(c, stdout); 55986Sbill goto loop1; 56986Sbill } 57986Sbill 58986Sbill /* Loop getting rid of characters */ 5916659Sralph while (!last || ct < last) { 605791Sroot c = getc(stdin); 615791Sroot if (feof(stdin)) 62986Sbill goto fin; 6316659Sralph if (c == '\n') { 6416659Sralph putc(c, stdout); 65986Sbill goto start; 66986Sbill } 6716659Sralph if (c == '\t') 6816659Sralph ct = (ct + 8) & ~7; 6916659Sralph else if (c == '\b') 7016659Sralph ct = ct ? ct - 1 : 0; 7116659Sralph else 7216659Sralph ct++; 73986Sbill } 74986Sbill 75986Sbill /* Output last of the line */ 765791Sroot for (;;) { 775791Sroot c = getc(stdin); 785791Sroot if (feof(stdin)) 795791Sroot break; 8016659Sralph putc(c, stdout); 8116659Sralph if (c == '\n') 82986Sbill goto start; 83986Sbill } 84986Sbill fin: 85986Sbill fflush(stdout); 8632749Sbostic exit(0); 87986Sbill } 88986Sbill 89986Sbill getn(ap) 90986Sbill char *ap; 91986Sbill { 92986Sbill register int n,c; 93986Sbill register char *p; 94986Sbill 95986Sbill p = ap; 96986Sbill n = 0; 97986Sbill while ((c = *p++) >= '0' && c <= '9') 98986Sbill n = n*10 + c - '0'; 99986Sbill return(n); 100986Sbill } 101