home *** CD-ROM | disk | FTP | other *** search
- /* Program Pager.c -- print text file on 2 sides of paper
-
- Programmer: Dick Taylor, 99 Valley View Rd, Glastonbury CT 06033 USA
- Date: April 1991
-
- History: I wrote this program to print Anders Bjerin's C Manual from
- the Fred Fish disk collection.
-
- Preparation: I make a separate run of Pager for each chapter. In CLI
- I use JOIN to combine the chapter text with all examples for that chapter,
- to make one text file in ram:. If you wish to improve the readability
- of this JOIN'ed file, you could edit it to add a few blank lines between
- the examples.
-
- To run: Use CLI to start Pager. At start of execution, you are prompted
- to enter--
- 1) Input file name
- 2) Number of lines printed per page. I use 60 for 8 1/2 x 11 inch pages.
- 3) First page number. Obviously start with 1 for chapter 1. For
- following chapters, I recommend that you always use an odd number,
- so that the page numbers will appear on the outside page corner.
- This means that sometimes you will need to skip an even number
- following the end of the previous chapter.
-
- On the first pass, Pager prints the first page and every second following
- page--usually the odd page numbers, while the second page and every second
- following are saved in a temporary file in ram:--usually the even numbers.
- At the end of this step, the program pauses and prompts you to take out the
- printer paper, turn it over, position it to start printing on the back of
- the first page. Then you start it running again.
-
- Assumption: Line 1 of the text file is the chapter title. This will be
- printed at the top of each page, along with the page number.
- */
-
- #include <stdio.h>
- #include <exec/types.h>
-
- #define LINESIZE 81
- #define TITLESIZE 25
-
- main ()
- {
- int line_ct = 0, PageNum, FirstPageNum, i, NumLinesPage;
- FILE *in_file, *printer, *temp_file, *fopen();
- char buff[LINESIZE], in_name[25], title[TITLESIZE];
- char static TempName[] = "ram:Even#Pages";
- char SwPrinter = TRUE; /* Printer switch, T=printer, F=temp*/
-
-
- printf ("Enter input file name:\n");
- scanf (" %24s", in_name);
- in_file = fopen(in_name, "r");
- if (in_file == NULL)
- {printf ("Cannot open input file, terminate\n"); exit(1); }
-
- printf ("Enter number of lines per printed page:\n");
- printf ("(Use 60 for 8 1/2 x 11 inch page size.)\n");
- scanf (" %d", &NumLinesPage);
-
- printf ("Enter page number of first page to be printed:\n");
- scanf (" %d", &PageNum);
- FirstPageNum = PageNum;
-
- printer = fopen("prt:", "w");
- if (printer == NULL)
- {printf ("Cannot open printer, terminate\n"); exit(2); }
-
- temp_file = fopen(TempName, "w");
- if (temp_file == NULL)
- {printf ("Cannot open temp file for write, terminate\n"); exit(3); }
-
- fgets(title,TITLESIZE,in_file); /* Read title = 1st line of input file*/
-
- for (i=0; i<25; ++i) /* Remove 'newline' from title[] */
- if (title[i] == '\n') title[i] = ' ';
-
- fprintf(printer,"%27c %-24s %18c Page %2d\n\n",' ',title,' ',PageNum);
-
- fgets(buff,LINESIZE,in_file); /* Read a line of input */
-
- while (! feof(in_file)) /* Loop to read input file */
- {
- line_ct += 1; /* Increm line count */
- if (line_ct >= NumLinesPage || buff[0] == '\f')
- {
- line_ct = 0;
- PageNum += 1; /* Increm page count */
- if (SwPrinter)
- {
- SwPrinter = FALSE; /* Set switch to temp file */
- if (PageNum > FirstPageNum + 1)
- fprintf(temp_file,"\fPage %2d %19c %-24s\n\n",PageNum,' ',title);
- /* Page eject,print page no. & blank line */
- else
- fprintf(temp_file,"Page %2d %19c %-24s\n\n",PageNum,' ',title);
- /* page 2 -- No page eject, Print page no. & blank line */
- }
- else
- {
- SwPrinter = TRUE;
- fprintf(printer,"\f%27c %-24s %18c Page %2d\n\n",' ',title,' ',PageNum);
- /* print page no. & blank line */
- }
- }
-
- /* If have a form feed char, then replace with a blank char, */
- /* because form feed already used with title line. */
- if (buff[0] == '\f')
- buff[0] = ' ';
-
- if (SwPrinter) fputs (buff,printer); /* Send line to printer */
- else fputs (buff,temp_file); /* Send line to temp file */
-
- fgets(buff,LINESIZE,in_file); /* Read a line of input */
- }
-
- fprintf(printer,"\f"); /* Final page eject on first part --odd */
- /* page no's-- to keep printer sychronized*/
- fclose(in_file);
- printf ("Completed read of input file\n");
- fclose(temp_file);
-
- printf ("\nPause to reverse printer paper.\n");
- printf ("Remove paper from printer, turn it over, and position\n");
- printf (" it so that next page will print on back of first page.\n");
- printf ("When ready to continue, press 1 (or any number), and RETURN.\n");
- scanf (" %d",&i);
-
- temp_file = fopen (TempName, "r");
- if (temp_file == NULL)
- {printf ("Cannot open temp file for read, terminate\n"); exit(4); }
-
- fgets (buff, LINESIZE, temp_file);
-
- while (! feof(temp_file)) /* Read-print loop for temp file--even #'s*/
- {
- fputs(buff, printer);
- fgets(buff, LINESIZE, temp_file);
- }
-
- fprintf(printer,"\f"); /* Final page eject on second part --even */
- /* page no's-- to keep printer sychronized*/
- fclose (temp_file);
- fclose (printer);
- printf ("Finish execution\n");
- }
-