# /* * * * The information in this document is subject to change * without notice and should not be construed as a commitment * by Digital Equipment Corporation or by DECUS. * * Neither Digital Equipment Corporation, DECUS, nor the authors * assume any responsibility for the use or reliability of this * document or the described software. * * Copyright (C) 1980, DECUS * * * General permission to copy or modify, but not for profit, is * hereby granted, provided that the above copyright notice is * included and reference made to the fact that reproduction * privileges were granted by DECUS. * */ /* * mc.c * Convert a file to multi column * format. */ #include #define WMAX 132 #define HMAX 60 int wmax = WMAX; int hmax = HMAX; int ncol = 2; int row; int col; int lmax; char line[128]; char page[HMAX][WMAX]; main(argc, argv) char *argv[]; { register char *p; register c, i; int nf; FILE *fp; nf = argc-1; for(i=1; i= argc) usage(); ncol = atoi(argv[i]); if(ncol == 0) bad(ncol, "column"); argv[i] = 0; --nf; break; case 'h': case 'H': if(++i >= argc) usage(); hmax = atoi(argv[i]); if(hmax > HMAX) bad(hmax, "height"); argv[i] = 0; --nf; break; case 'w': case 'W': if(++i >= argc) usage(); wmax = atoi(argv[i]); if(wmax > WMAX) bad(wmax, "width"); argv[i] = 0; --nf; break; default: usage(); } } } lmax = wmax/ncol - 1; if(lmax < 1) error("Unreasonable -c or -w.\n"); if(nf == 0) process(stdin); else for(i=1; i= hmax) { if(++col >= ncol) { output(); col = 0; blank(); } row = 0; } p1 = line; p2 = &page[row][(wmax*col)/ncol]; while(c = *p1++) *p2++ = c; } output(); } output() { register char *p1, *p2; register i; if(row==0 && col==0) return; putchar('\f'); for(i=0; ip1 && p2[-1]==' ') --p2; while(p1 < p2) putchar(*p1++); putchar('\n'); } } blank() { register char *p1, *p2; register i; for(i=0; i=' ' && c<='~') { *p++ = c; ++h; } } *p = 0; line[lmax] = 0; return(c == '\n'); } bad(n, s) char *s; { error("%d: bad %s specification.\n", n, s); } usage() { error("Usage: mc [-c #] [-h #] [-w #] [file ...].\n"); }