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[] = "@(#)expand.c	5.1 (Berkeley) 5/31/85";
  15: #endif not lint
  16: 
  17: #include <stdio.h>
  18: /*
  19:  * expand - expand tabs to equivalent spaces
  20:  */
  21: int nstops;
  22: int tabstops[100];
  23: 
  24: main(argc, argv)
  25:     int argc;
  26:     char *argv[];
  27: {
  28:     register int c, column;
  29:     register int n;
  30: 
  31:     argc--, argv++;
  32:     do {
  33:         while (argc > 0 && argv[0][0] == '-') {
  34:             getstops(argv[0]);
  35:             argc--, argv++;
  36:         }
  37:         if (argc > 0) {
  38:             if (freopen(argv[0], "r", stdin) == NULL) {
  39:                 perror(argv[0]);
  40:                 exit(1);
  41:             }
  42:             argc--, argv++;
  43:         }
  44:         column = 0;
  45:         for (;;) {
  46:             c = getc(stdin);
  47:             if (c == -1)
  48:                 break;
  49:             switch (c) {
  50: 
  51:             case '\t':
  52:                 if (nstops == 0) {
  53:                     do {
  54:                         putchar(' ');
  55:                         column++;
  56:                     } while (column & 07);
  57:                     continue;
  58:                 }
  59:                 if (nstops == 1) {
  60:                     do {
  61:                         putchar(' ');
  62:                         column++;
  63:                     } while (((column - 1) % tabstops[0]) != (tabstops[0] - 1));
  64:                     continue;
  65:                 }
  66:                 for (n = 0; n < nstops; n++)
  67:                     if (tabstops[n] > column)
  68:                         break;
  69:                 if (n == nstops) {
  70:                     putchar(' ');
  71:                     column++;
  72:                     continue;
  73:                 }
  74:                 while (column < tabstops[n]) {
  75:                     putchar(' ');
  76:                     column++;
  77:                 }
  78:                 continue;
  79: 
  80:             case '\b':
  81:                 if (column)
  82:                     column--;
  83:                 putchar('\b');
  84:                 continue;
  85: 
  86:             default:
  87:                 putchar(c);
  88:                 column++;
  89:                 continue;
  90: 
  91:             case '\n':
  92:                 putchar(c);
  93:                 column = 0;
  94:                 continue;
  95:             }
  96:         }
  97:     } while (argc > 0);
  98:     exit(0);
  99: }
 100: 
 101: getstops(cp)
 102:     register char *cp;
 103: {
 104:     register int i;
 105: 
 106:     nstops = 0;
 107:     cp++;
 108:     for (;;) {
 109:         i = 0;
 110:         while (*cp >= '0' && *cp <= '9')
 111:             i = i * 10 + *cp++ - '0';
 112:         if (i <= 0 || i > 256) {
 113: bad:
 114:             fprintf(stderr, "Bad tab stop spec\n");
 115:             exit(1);
 116:         }
 117:         if (nstops > 0 && i <= tabstops[nstops-1])
 118:             goto bad;
 119:         tabstops[nstops++] = i;
 120:         if (*cp == 0)
 121:             break;
 122:         if (*cp++ != ',')
 123:             goto bad;
 124:     }
 125: }

Defined functions

getstops defined in line 101; used 1 times
  • in line 34
main defined in line 24; never used

Defined variables

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