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[] = "@(#)unexpand.c	5.1 (Berkeley) 5/31/85";
  15: #endif not lint
  16: 
  17: /*
  18:  * unexpand - put tabs into a file replacing blanks
  19:  */
  20: #include <stdio.h>
  21: 
  22: char    genbuf[BUFSIZ];
  23: char    linebuf[BUFSIZ];
  24: int all;
  25: 
  26: main(argc, argv)
  27:     int argc;
  28:     char *argv[];
  29: {
  30:     register char *cp;
  31: 
  32:     argc--, argv++;
  33:     if (argc > 0 && argv[0][0] == '-') {
  34:         if (strcmp(argv[0], "-a") != 0) {
  35:             fprintf(stderr, "usage: unexpand [ -a ] file ...\n");
  36:             exit(1);
  37:         }
  38:         all++;
  39:         argc--, argv++;
  40:     }
  41:     do {
  42:         if (argc > 0) {
  43:             if (freopen(argv[0], "r", stdin) == NULL) {
  44:                 perror(argv[0]);
  45:                 exit(1);
  46:             }
  47:             argc--, argv++;
  48:         }
  49:         while (fgets(genbuf, BUFSIZ, stdin) != NULL) {
  50:             for (cp = linebuf; *cp; cp++)
  51:                 continue;
  52:             if (cp > linebuf)
  53:                 cp[-1] = 0;
  54:             tabify(all);
  55:             printf("%s", linebuf);
  56:         }
  57:     } while (argc > 0);
  58:     exit(0);
  59: }
  60: 
  61: tabify(c)
  62:     char c;
  63: {
  64:     register char *cp, *dp;
  65:     register int dcol;
  66:     int ocol;
  67: 
  68:     ocol = 0;
  69:     dcol = 0;
  70:     cp = genbuf, dp = linebuf;
  71:     for (;;) {
  72:         switch (*cp) {
  73: 
  74:         case ' ':
  75:             dcol++;
  76:             break;
  77: 
  78:         case '\t':
  79:             dcol += 8;
  80:             dcol &= ~07;
  81:             break;
  82: 
  83:         default:
  84:             while (((ocol + 8) &~ 07) <= dcol) {
  85:                 if (ocol + 1 == dcol)
  86:                     break;
  87:                 *dp++ = '\t';
  88:                 ocol += 8;
  89:                 ocol &= ~07;
  90:             }
  91:             while (ocol < dcol) {
  92:                 *dp++ = ' ';
  93:                 ocol++;
  94:             }
  95:             if (*cp == 0 || c == 0) {
  96:                 strcpy(dp, cp);
  97:                 return;
  98:             }
  99:             *dp++ = *cp;
 100:             ocol++, dcol++;
 101:         }
 102:         cp++;
 103:     }
 104: }

Defined functions

main defined in line 26; never used
tabify defined in line 61; used 1 times
  • in line 54

Defined variables

all defined in line 24; used 2 times
copyright defined in line 8; never used
genbuf defined in line 22; used 2 times
linebuf defined in line 23; used 4 times
sccsid defined in line 14; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2122
Valid CSS Valid XHTML 1.0 Strict