1: #include <stdio.h>
   2: /*
   3:  * sidebyside -- make wide listings by placing pages side by side
   4:  */
   5: int width = 90;
   6: 
   7: #define LINELN 440
   8: #define EJLINE  86
   9: #define LMARG   10
  10: 
  11: char    screen[EJLINE][LINELN];
  12: char    ul[EJLINE][LINELN];
  13: char    anyul[EJLINE];
  14: int frame;
  15: int origin;
  16: int outline;
  17: int outcol;
  18: 
  19: main(argc, argv)
  20:     int argc;
  21:     char *argv[];
  22: {
  23: 
  24:     argc--, argv++;
  25:     while (argc > 0 && argv[0][0] == '-') {
  26:         switch (argv[0][1]) {
  27: 
  28:         case 'w':
  29:             width = atoi(argv[0]+2);
  30:             break;
  31: 
  32:         default:
  33:             fprintf(stderr, "usage: sidebyside [ -wwidth ] file ...\n");
  34:             break;
  35:         }
  36:         argc--, argv++;
  37:     }
  38:     clear(screen, EJLINE * LINELN);
  39:     origin = LMARG;
  40:     outcol = LMARG;
  41:     cutmark(LMARG);
  42:     do {
  43:         if (argc > 0) {
  44:             if (freopen(argv[0], "r", stdin) == NULL) {
  45:                 perror(argv[0]);
  46:                 argc--, argv++;
  47:                 continue;
  48:             }
  49:             argc--, argv++;
  50:         }
  51:         process();
  52:     } while (argc > 0);
  53:     exit(0);
  54: }
  55: 
  56: process()
  57: {
  58:     char linebuf[BUFSIZ];
  59:     register char *cp;
  60:     register int c;
  61: 
  62:     while (fgets(linebuf, sizeof linebuf, stdin)) {
  63:         for (cp = linebuf; c = *cp; cp++) switch (c) {
  64: 
  65:         case '\t':
  66:             do {
  67:                 int ooutcol = outcol;
  68:                 outchar(' ');
  69:                 if (outcol == ooutcol)
  70:                     break;
  71:             } while ((outcol - origin) % 8 != 0);
  72:             break;
  73: 
  74:         case '\b':
  75:             if (outcol > origin)
  76:                 outcol--;
  77:             break;
  78: 
  79:         case '\r':
  80:             outcol = origin + LMARG;
  81:             break;
  82: 
  83:         case '\f':
  84:             outline = EJLINE - 1;
  85:             /* fall into ... */
  86: 
  87:         case '\n':
  88:             outline++;
  89:             if (outline == EJLINE) {
  90:                 origin += width;
  91:                 if (origin + width > LINELN) {
  92:                     cutmark(origin);
  93:                     oflush();
  94:                     break;
  95:                 }
  96: /*
  97: 				if (origin * 2 + LMARG < LINELN && origin * 3 > LINELN) {
  98: 					cutmark(origin);
  99: 					origin += LMARG;
 100: 				}
 101: */
 102:                 outline = 0;
 103:                 cutmark(origin);
 104:             }
 105:             outcol = origin;
 106:             break;
 107: 
 108:         default:
 109:             outchar(c);
 110:             break;
 111:         }
 112:     }
 113:     if (outline || origin != LMARG) {
 114:         cutmark(origin + width);
 115:         oflush();
 116:     }
 117: }
 118: 
 119: outchar(c)
 120:     register int c;
 121: {
 122:     register char *cp = screen[outline];
 123:     register char *up;
 124:     register int d;
 125: 
 126:     if (c < 040 || c >= 0177)
 127:         return;
 128:     if (outcol < LINELN) {
 129:         cp += outcol;
 130:         d = *cp;
 131:         if (d == ' ') {
 132:             *cp = c;
 133:             outcol++;
 134:             return;
 135:         }
 136:         if (d == '_' || c == '_') {
 137:             if (c == d) {
 138:                 outcol++;
 139:                 return;
 140:             }
 141:             if (anyul[outline] == 0)
 142:                 clear(ul[outline], LINELN);
 143:             anyul[outline] = 1;
 144:             ul[outline][outcol] = '_';
 145:             if (c == '_')
 146:                 c = d;
 147:         }
 148:         *cp = c;
 149:         outcol++;
 150:     }
 151: }
 152: 
 153: oflush()
 154: {
 155:     register char *cp, *dp;
 156:     register int i, j, oc, dc, c;
 157: 
 158:     frame++;
 159: /*
 160: 	if (frame > 1) {
 161: 		printf("\n\n\n");
 162: 		for (j = 0; j < LINELN; j++)
 163: 			putchar('_');
 164: 		printf("\n");
 165: 	}
 166: */
 167:     printf("\n");
 168:     for (i = 0; i < EJLINE; i++) {
 169:         putline(screen[i]);
 170:         if (anyul[i]) {
 171:             putchar('\r');
 172:             putline(ul[i]);
 173:             anyul[i] = 0;
 174:         }
 175:         putchar('\n');
 176:     }
 177:     for (i = 0; i < LINELN; i++)
 178:         putchar('_');
 179:     putchar('\n');
 180:     clear(screen, EJLINE * LINELN);
 181:     outline = 0;
 182:     outcol = LMARG;
 183:     origin = LMARG;
 184:     cutmark(LMARG);
 185: }
 186: 
 187: clear(cp, i)
 188:     register char *cp;
 189:     register int i;
 190: {
 191: 
 192:     if (i > 0)
 193:         do
 194:             *cp++ = ' ';
 195:         while (--i);
 196: }
 197: 
 198: cutmark(o)
 199:     register int o;
 200: {
 201:     register int i;
 202: 
 203:     screen[0][o - LMARG] = '|';
 204:     screen[1][o - LMARG] = '|';
 205:     screen[EJLINE - 1][o - LMARG] = '|';
 206:     screen[EJLINE - 2][o - LMARG] = '|';
 207: }
 208: 
 209: putline(cp)
 210:     register char *cp;
 211: {
 212:     register int j = LINELN;
 213:     register int c, oc, dc;
 214: 
 215:     oc = dc = 0;
 216:     do {
 217:         if ((c = *cp++) == ' ') {
 218:             dc++;
 219:             continue;
 220:         }
 221:         while (((oc + 8) &~ 7) < dc) {
 222:             putchar('\t');
 223:             oc = (oc + 8) &~ 7;
 224:         }
 225:         while (oc < dc) {
 226:             putchar(' ');
 227:             oc++;
 228:         }
 229:         putchar(c);
 230:         oc++, dc++;
 231:     } while (--j != 0);
 232: }

Defined functions

clear defined in line 187; used 3 times
cutmark defined in line 198; used 5 times
main defined in line 19; never used
oflush defined in line 153; used 2 times
outchar defined in line 119; used 2 times
process defined in line 56; used 1 times
  • in line 51
putline defined in line 209; used 2 times

Defined variables

anyul defined in line 13; used 4 times
frame defined in line 14; used 1 times
origin defined in line 15; used 12 times
outcol defined in line 17; used 15 times
outline defined in line 16; used 11 times
screen defined in line 11; used 8 times
ul defined in line 12; used 3 times
width defined in line 5; used 4 times

Defined macros

EJLINE defined in line 8; used 10 times
LINELN defined in line 7; used 9 times
LMARG defined in line 9; used 12 times
Last modified: 1982-08-07
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1319
Valid CSS Valid XHTML 1.0 Strict