/* * log.c * * The printing functions are modified here to make sure that * everything printed is saved to disk as well as printed to the * printer. In addition, there is a function to print out the * last chunk of data. */ /*** *** Include files ***/ /*lint -e579 */ /*lint -esym(123,__size) */ #include #include #include #include #include #include #include #include #include "pragmas.h" #include "pinewood.h" /*** *** Local data ***/ #define NL 50 /* Number of lines */ #define NC 150 /* Number of columns */ static FILE *Log = NULL; /* Log file */ static char Memory[NL][NC]; /* Memory image of things */ static int Nline = 0; /* Current line number */ /*** *** External functions ***/ /* * xfclose * * Close the files. */ void xfclose(FILE *printer) { fclose(printer); fclose(Log); Log = NULL; } /* * xfopen * * Open a file and return the pointer. The print routines ensure * that the pointer is non-NULL, so the user code need not worry * about it (and shouldn't so that the disk version also gets * dealt with). */ FILE * xfopen(char *fname, char *mode) { Nline = 0; Log = fopen("print.log", "a"); return (fopen(fname, mode)); } /* * xfprintf * * Write data to the printer. */ void xfprintf(FILE *printer, char *fmt, ...) { va_list argptr; va_start(argptr, fmt); if (Log != NULL) vfprintf(Log, fmt, argptr); va_end(argptr); va_start(argptr, fmt); if (printer != NULL) vfprintf(printer, fmt, argptr); va_end(argptr); va_start(argptr, fmt); if (Nline < NL) vsprintf(Memory[Nline++], fmt, argptr); va_end(argptr); } /* * xreprint * * Reprint the last block to the printer. */ void xreprint(void) { int line; FILE *printer; if ((printer = fopen(PRINTER, "a")) != NULL) { for (line = 0; line < Nline; line++) fprintf(printer, "%s", Memory[line]); fclose(printer); } }