/* * WIDTH.C written by H.Moran * * Show any lines from the specified file which exceed the specified * (or default) length. Also show the length of line for such lines. * Default is MAXWIDTH characters, which is currently 44 because * that is what will permit 5 columns on an MX-100 using compressed print. * * Intended for determining what makes sense as a column width * when using MPRINT.C. One of these days I'll expand TABs before counting * characters on general principles. I haven't missed this feature yet. * * Last Update: 10/9/83 hrm */ #include "bdscio.h" #define REV_DATE "10/9/83" #define MAXWIDTH 44 #define PROC int /* PROCedure i.e. function returning no value */ PROC main(argc, argv) int argc; char **argv; { FILE infile; char linbuf[500]; int maxwidth, width, wideline; int i, j, l; maxwidth = 44; if ( argc < 2 || argc > 3 ) usage(); if ( argc == 3 && (maxwidth=atoi(argv[2])) < 0 ) usage(); if ( fopen(argv[1], &infile) == ERROR ) { printf("Can't open %s\n", argv[1]); exit(1); } for ( i = 1; fgets(linbuf, &infile); i++ ) { if ( (width = strlen(linbuf)) > maxwidth ) { if ( linbuf[width-1] == '\n' ) /* '\n' consumes no print width */ --width; if ( width <= maxwidth ) continue; printf("%4d:<%4d> ", i, width); for ( j = 0, l = strlen(linbuf); j < l; ++j ) putchar(linbuf[j]); } } fclose(&infile); } /* * usage() * * Tell the man how this program is invoked, then abort. */ PROC usage() { printf("Usage:\n\twidth []\n\n"); printf("Default width if not specified is %d\n", MAXWIDTH); printf("This shows (on CON:) any lines which exceed the specified\n"); printf("or default width along with their actual width in"); printf(" characters.\n"); printf("TABS count as 1 character; the trailing NEWLINE as 0\n"); printf("\nLast Revision Date: %s\n", REV_DATE); exit(1); }