# 2.11BSD#431 - /usr/src/ucb/fold.c

##### Functions

    main              X
    putch             X

##### Variables

    col               X
    copyright         X
    fold              X

       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[] = "@(#)fold.c	5.1 (Berkeley) 5/31/85";
      15: #endif not lint
      16:
      17: #include <stdio.h>
      18: /*
      19:  * fold - fold long lines for finite output devices
      20:  *
      21:  * Bill Joy UCB June 28, 1977
      22:  */
      23:
      24: int fold =  80;
      25:
      26: main(argc, argv)
      27:     int argc;
      28:     char *argv[];
      29: {
      30:     register c;
      31:     FILE *f;
      32:
      33:     argc--, argv++;
      34:     if (argc > 0 && argv[0][0] == '-') {
      35:         fold = 0;
      36:         argv[0]++;
      37:         while (*argv[0] >= '0' && *argv[0] <= '9')
      38:             fold *= 10, fold += *argv[0]++ - '0';
      39:         if (*argv[0]) {
      40:             printf("Bad number for fold\n");
      41:             exit(1);
      42:         }
      43:         argc--, argv++;
      44:     }
      45:     do {
      46:         if (argc > 0) {
      47:             if (freopen(argv[0], "r", stdin) == NULL) {
      48:                 perror(argv[0]);
      49:                 exit(1);
      50:             }
      51:             argc--, argv++;
      52:         }
      53:         for (;;) {
      54:             c = getc(stdin);
      55:             if (c == -1)
      56:                 break;
      57:             putch(c);
      58:         }
      59:     } while (argc > 0);
      60:     exit(0);
      61: }
      62:
      63: int col;
      64:
      65: putch(c)
      66:     register c;
      67: {
      68:     register ncol;
      69:
      70:     switch (c) {
      71:         case '\n':
      72:             ncol = 0;
      73:             break;
      74:         case '\t':
      75:             ncol = (col + 8) &~ 7;
      76:             break;
      77:         case '\b':
      78:             ncol = col ? col - 1 : 0;
      79:             break;
      80:         case '\r':
      81:             ncol = 0;
      82:             break;
      83:         default:
      84:             ncol = col + 1;
      85:     }
      86:     if (ncol > fold)
      87:         putchar('\n'), col = 0;
      88:     putchar(c);
      89:     switch (c) {
      90:         case '\n':
      91:             col = 0;
      92:             break;
      93:         case '\t':
      94:             col += 8;
      95:             col &= ~7;
      96:             break;
      97:         case '\b':
      98:             if (col)
      99:                 col--;
     100:             break;
     101:         case '\r':
     102:             col = 0;
     103:             break;
     104:         default:
     105:             col++;
     106:             break;
     107:     }
     108: }

#### Defined functions

main defined in line 26; never used
putch defined in line 65; used 1 times

- in line 57

#### Defined variables

col defined in line 63; used 12 times

- in line 75-78(3), 84-105(9)

copyright defined in line 8; never used
fold defined in line 24; used 4 times

- in line 35-38(3), 86

sccsid defined in line 14; never used

Last modified: 1987-02-17 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 499 |