/****************************************************************/ /* nd.c */ /* A program to output a non-document textfile, page by page */ /*with a header containing FILENAME, PAGE# and each line also */ /*numbered. */ /* */ /* Usage: A>nd d:filename.ext [$] */ /* ^ ^ */ /* / | */ /* Source file OPTIONS */ /* */ /* OPTIONS: L - No line numbers */ /* P - Pause between pages */ /* D - Draft mode (no header, pica type) */ /* H - No header */ /****************************************************************/ /* main() master control for nd.c */ /* getParams() finds line parameters and acts on them */ /* abort() inform user of ERROR and return */ /* openFile() opens Source file */ /* sendHeader() sends header string to Epson printer */ /* getLine() reads line from SOURCE file */ /* printLine() prints line to line printer */ /****************************************************************/ /* 88Feb05 BKB Version 1.1.0 release */ /* 88Jan30 BKB Code initiated */ /****************************************************************/ #define TRUE 1 #define FALSE 0 #define ERROR -1 #define SAME 0 #define FLAG char #define MAXLINES 60 #define FORMFEED 12 #define EOF 26 #define ESC 27 #define PICA 18 /* Change these values if not using Epson */ #define CONDENSED 15 /* compatible.. */ #define VERSION "1.1.0" #define DATE "88Feb05" char line[120], fBuf[1024], fBuf2[1024], filename[15]; FLAG done, formal, pagePause, lineNos, headerOut; int fileLine, pageLine, filePage; main(argc, argv) int argc; char *argv[]; { done = FALSE; if (getParams(argc, argv) == ERROR) return; if (openFile(filename) == ERROR) { fClose(fBuf); return; } fileLine = pageLine = filePage = 1; if (formal) sendHeader(); while (!done) { if (getLine() == ERROR) done = TRUE; else { printf("Printing page#%d line#%d\r", filePage, pageLine); printLine(); fileLine++; pageLine++; if (pageLine > MAXLINES) { pageLine = 1; filePage++; lprintf("%c", FORMFEED); if (pagePause) { printf("ready next page, press RETURN: \r"); if (getChar() == ESC) return; } printf(" \r"); if (formal) sendHeader(); } /* new page */ } /* got line */ } /* while not done */ lprintf("%c", FORMFEED); /* make it pretty */ if (formal) lprintf("%c", PICA); /* return to normality */ fClose(fBuf); printf("\n Exiting..."); } /****************************************************************/ /* getParams() */ /****************************************************************/ getParams(c, v) int c; char *v[]; { char on, temp[6]; int i; printf("\nND version %s (%s)\n\n", VERSION, DATE); lineNos = formal = headerOut = TRUE; /* initialize defaults */ pagePause = FALSE; if (c < 2) { abort(); return(ERROR); } strCpy(filename, v[1]); if (c == 2) return(TRUE); on = 3; while (on <= c) { if (index(v[on-1], "$") != ERROR) { /* found options list */ strCpy(temp, v[on-1]); /* easier to work with */ for (i=1; i <= (strLen(temp)-1); i++) { switch(toUpper(temp[i])) { case 'L': if (!lineNos) break; printf("Line numbers OFF\n"); lineNos = FALSE; break; case 'P': if (pagePause) break; printf("Page pause ON\n"); pagePause = TRUE; break; case 'D': if (!formal) break; printf("Draft mode ON\n"); formal = FALSE; break; case 'H': if (!headerOut) break; printf("Header OFF\n"); headerOut = FALSE; break; default: printf("?option '$%c' unknown -- Ignored\n", temp[i]); } /* switch */ } /* for */ } /* if */ on++; } /* while */ return(TRUE); } /****************************************************************/ /* abort() */ /****************************************************************/ abort() { printf(" Illegal parameters passed!\n\n"); printf("Proper usage: A>nd d:fname.ext [$LPDH]\n"); printf(" ^ ^\n"); printf(" / |\n"); printf(" Source file options\n\n"); } /****************************************************************/ /* openFile() */ /****************************************************************/ openFile(fn1) char *fn1; { if (index(fn1, "*") != ERROR || index(fn1, "?") != ERROR) { printf("\n\007 Wildcards not allowed!\n"); return(ERROR); } if ((fOpen(fn1, fBuf)) == ERROR) { printf("\007\n Can not open %s!\n", fn1); return(ERROR); } return(TRUE); } /****************************************************************/ /* sendHeader() */ /****************************************************************/ sendHeader() { lprintf("%c", PICA); /* go to PICA for the header */ if (headerOut) { lprintf(" ND file: %s Page: %d\n\n", filename, filePage); } lprintf("%c", CONDENSED); /* go back to CONDENSED */ } /****************************************************************/ /* getLine() */ /****************************************************************/ getLine() { if (fscanf(fBuf, "%s", line) == ERROR) return(ERROR); if (line[0] == '\0') strCpy(line, "\n"); return(TRUE); } /****************************************************************/ /* printLine() */ /****************************************************************/ printLine() { if (formal && lineNos) lprintf(" %4d: %s", fileLine, line); else lprintf("%s", line); return(TRUE); }