home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume9 / mpage / part01 / mp_glob.c < prev    next >
C/C++ Source or Header  |  1989-12-26  |  9KB  |  254 lines

  1. # include <stdio.h>
  2. # include <sys/types.h>
  3.  
  4. # ifndef lint
  5. static char *rcs_id =
  6.     "@(#) $Header: mp_glob.c,v 2.7 89/08/09 11:44:01 mark Exp $";
  7. # endif
  8.  
  9. # include "mp_head.h"
  10.  
  11. /*
  12.  * mpage:    a program to reduce pages of print so that several pages
  13.  *           of output appear on one printed page.
  14.  *
  15.  * Written by:
  16.  *   ...!uunet!\                       Mark Hahn, Sr Systems Engineer
  17.  *              >pyrdc!mark            Pyramid Technology Corporation
  18.  * ...!pyramid!/                       Vienna, Va    (703)848-2050
  19.  *
  20.  *
  21.  * Copyright (c) 1988 Mark P. Hahn, Herndon, Virginia
  22.  *  
  23.  *     Permission is granted to anyone to make or distribute verbatim
  24.  *     copies of this document as received, in any medium, provided
  25.  *     that this copyright notice notice is preserved, and that the
  26.  *     distributor grants the recipient permission for further
  27.  *     redistribution as permitted by this notice.
  28.  *
  29.  */
  30.  
  31. /* $Log:    mp_glob.c,v $
  32.  * Revision 2.7  89/08/09  11:44:01  mark
  33.  * change the defaults so that outlines are normally printed
  34.  * 
  35.  * Revision 2.6  89/05/25  10:42:37  mark
  36.  * changes to print a page count on stderr after the print job is queued.
  37.  * 
  38.  * Revision 2.5  89/05/25  09:50:29  mark
  39.  * turned off all debugging.
  40.  * 
  41.  * Revision 2.4  89/05/25  08:58:21  mark
  42.  * rearranged the rcs header keywords for better readability.
  43.  * 
  44.  * Revision 2.3  89/05/22  14:40:49  mark
  45.  * Fixed the type-o in the rcs identification string
  46.  * 
  47.  * Revision 2.2  89/05/22  14:37:51  mark
  48.  * Added rcs identification usable with the "what" program
  49.  * 
  50.  * Revision 2.1  89/05/22  14:31:18  mark
  51.  * New Major Revision
  52.  * 
  53.  * Revision 1.1  89/05/22  14:21:16  mark
  54.  * Initial revision
  55.  *  */
  56.  
  57. /*
  58.  * to turn on debugging, define the preprocessor macro DEBUG and set
  59.  * the variable Debug_flag to the sum of the sections to debug.
  60.  */
  61. # ifdef DEBUG
  62. int Debug_flag = DB_PSMPAGE;
  63. # endif DEBUG
  64.  
  65. /*
  66.  * some basic PS parameters
  67.  */
  68. int ps_width = 612;    /* number of points in the X direction (8.5 inches) */
  69. int ps_height = 792;    /* number of points in the Y direction (11 inches) */
  70.  
  71. /*
  72.  * outlines for various page orientations and number of output pages to
  73.  * put on printed pages
  74.  */
  75. int outline_1();
  76. int outline_2();
  77. int outline_4();
  78. int outline_8();
  79.  
  80. /*
  81.  * the structures describe where to put the reduced pages of output on the
  82.  * printed page.
  83.  */
  84. /* base point for one page, normal aspect */
  85. struct pagepoints one_normal[] = {
  86.     { xbase1, ybase1 },
  87.     {  0,  0 }
  88. };
  89. /* base points for two pages, normal aspect */
  90. struct pagepoints two_normal[] = {
  91.     { xbase1, ytop4 },    { xbase1 , ytop2 },
  92.     {  0,  0 }
  93. };
  94. /* base points for four pages, normal aspect, running reduced pages
  95.  * read from left to right */
  96. struct pagepoints lr_four_normal[] = {
  97.       { xbase1, ybase3 },    { xbase2, ybase3 },
  98.     { xbase1, ybase1 },    { xbase2, ybase1 },
  99.     {  0,  0 }
  100. };
  101. /* base points for four pages, normal aspect, running reduced pages
  102.  * read from top to bottom (up/down) */
  103. struct pagepoints ud_four_normal[] = {
  104.       { xbase1, ybase3 },    { xbase1, ybase1 },
  105.     { xbase2, ybase3 },    { xbase2, ybase1 },
  106.     {  0,  0 }
  107. };
  108. /* base points for eight pages, normal aspect, running reduced pages
  109.  * read from left to right */
  110. struct pagepoints lr_eight_normal[] = {
  111.     { xbase2, ytop4 },    { xbase2, ytop3 },
  112.     { xbase2, ytop2 },    { xbase2, ytop1 },
  113.     { xbase1, ytop4 },    { xbase1, ytop3 },
  114.     { xbase1, ytop2 },    { xbase1, ytop1 },
  115.     {  0,  0 }
  116. };
  117. /* base points for eight pages, normal aspect, running reduced pages
  118.  * read from top to bottom (up/down) */
  119. struct pagepoints ud_eight_normal[] = {
  120.     { xbase2, ytop4 },    { xbase1, ytop4 },
  121.     { xbase2, ytop3 },    { xbase1, ytop3 },
  122.     { xbase2, ytop2 },    { xbase1, ytop2 },
  123.     { xbase2, ytop1 },    { xbase1, ytop1 },
  124.     {  0,  0 }
  125. };
  126. /* base point for one page, in landscape */
  127. struct pagepoints one_landscape[] = {
  128.       { xbase1, ytop4 },
  129.     {  0,  0 }
  130. };
  131. /* base points for two pages, in landscape */
  132. struct pagepoints two_landscape[] = {
  133.       { xbase1, ybase3 },    { xbase1, ybase1 },
  134.     {  0,  0 }
  135. };
  136. /* base points for four pages, in landscape, running reduced pages
  137.  * read from left to right */
  138. struct pagepoints lr_four_landscape[] = {
  139.       { xbase2, ytop4 },    { xbase2, ytop2 },
  140.     { xbase1, ytop4 },    { xbase1, ytop2 },
  141.     {  0,  0 }
  142. };
  143. /* base points for four pages, in landscape, running reduced pages
  144.  * read from top to bottom (up/down) */
  145. struct pagepoints ud_four_landscape[] = {
  146.       { xbase2, ytop4 },    { xbase1, ytop4 },
  147.       { xbase2, ytop2 },    { xbase1, ytop2 },
  148.     {  0,  0 }
  149. };
  150. /* base points for eight pages, in landscape, running reduced pages
  151.  * read from left to right */
  152. struct pagepoints lr_eight_landscape[] = {
  153.     { xbase1, ybase4 },    { xbase2, ybase4 },
  154.     { xbase1, ybase3 },    { xbase2, ybase3 },
  155.     { xbase1, ybase2 },    { xbase2, ybase2 },
  156.     { xbase1, ybase1 },    { xbase2, ybase1 },
  157.     {  0,  0 }
  158. };
  159. /* base points for eight pages, in landscape, running reduced pages
  160.  * read from top to bottom (up/down) */
  161. struct pagepoints ud_eight_landscape[] = {
  162.     { xbase1, ybase4 },    { xbase1, ybase3 },
  163.     { xbase1, ybase2 },    { xbase1, ybase1 },
  164.     { xbase2, ybase4 },    { xbase2, ybase3 },
  165.     { xbase2, ybase2 },    { xbase2, ybase1 },
  166.     {  0,  0 }
  167. };
  168.  
  169. /* list of sheets (printed page formats) for
  170.  * left to right reading, in normal aspect */
  171. struct sheet lr_normal[] = {
  172. /* 0 */    80, 66, xwid1, yht1,    0, outline_1, one_normal,
  173. /* 1 */    80, 66, yht2,  xwid1, -90, outline_2, two_normal,
  174. /* 2 */    80, 66, xwid2, yht2,    0, outline_4, lr_four_normal,
  175. /* 3 */    80, 66, yht4,  xwid2, -90, outline_8, lr_eight_normal,
  176. };
  177.  
  178. /* list of sheets (printed page formats) for
  179.  * top to bottom reading, in normal aspect */
  180. struct sheet ud_normal[] = {
  181. /* 0 */    80, 66, xwid1, yht1,    0, outline_1, one_normal,
  182. /* 1 */    80, 66, yht2,  xwid1, -90, outline_2, two_normal,
  183. /* 2 */    80, 66, xwid2, yht2,    0, outline_4, ud_four_normal,
  184. /* 3 */    80, 66, yht4,  xwid2, -90, outline_8, ud_eight_normal,
  185. };
  186.  
  187. /* list of sheets (printed page formats) for
  188.  * left to right reading, in landscape */
  189. struct sheet lr_landscape[] = {
  190. /* 0 */    132, 52, yht1,  xwid1, -90, outline_1, one_landscape,
  191. /* 1 */    132, 52, xwid1, yht2,    0, outline_2, two_landscape,
  192. /* 2 */    132, 52, yht2,  xwid2, -90, outline_4, lr_four_landscape,
  193. /* 3 */    132, 52, xwid2, yht4,    0, outline_8, lr_eight_landscape,
  194. };
  195.  
  196. /* list of sheets (printed page formats) for
  197.  * top to bottom reading, in landscape */
  198. struct sheet ud_landscape[] = {
  199. /* 0 */    132, 52, yht1,  xwid1, -90, outline_1, one_landscape,
  200. /* 1 */    132, 52, xwid1, yht2,    0, outline_2, two_landscape,
  201. /* 2 */    132, 52, yht2,  xwid2, -90, outline_4, ud_four_landscape,
  202. /* 3 */    132, 52, xwid2, yht4,    0, outline_8, ud_eight_landscape,
  203. };
  204.  
  205. /* array of sheet lists for left to right reading printed pages */
  206. struct sheet *left_right[] = {
  207.     lr_normal,
  208.     lr_landscape
  209.   };
  210.  
  211. /* arrays for top to bottom reading printed pages */
  212. struct sheet *up_down[] = {
  213.     ud_normal,
  214.     ud_landscape
  215.   };
  216.  
  217. /*
  218.  * Variables for holding the chosen options,  The defaults are set here.
  219.  * the sheetlist pointer is set to point to the array for either up/down
  220.  * or left/right reading.  This array is index by sheetorder, and then
  221.  * sheetindex.  sheetindex encodes the number of reduced pages per printed
  222.  * page and indexes into the sheet list (0 = 1 page, 1 = two pages, 2 =
  223.  * four pages, 3 = eight pages).
  224.  */
  225. struct sheet **sheetlist;/* array of sheet lists (up/down or left/right) */
  226. int sheetaspect = NORMAL;/* either normal or landscape */
  227. int sheetorder = UPDOWN;/* up/down or left/right flag */
  228. int sheetindex = 2;    /* index to number of pages of output per printed */
  229. int pg_sheetmargin = 20;/* non-printable border on sheet */
  230. int pg_pagemargin = 4;  /* border for pages */
  231. int fsize = 12;        /* font scale size */
  232. int opt_pr = 0;        /* boolean, if true use pr(1) to format output */
  233. int opt_lines = 0;    /* number of lines to fit on an reduced page */
  234. int opt_width = 0;    /* number of columns to fit on an reduced page */
  235. int opt_doheader = 0;    /* have a head for pr's -h option */
  236. int opt_a4 = 0;        /* default to US paper */
  237. int opt_outline = 1;    /* don't normally outline the pages */
  238. int opt_verbose = 1;    /* by default, print a count of pages produced */
  239. char opt_header[LINESIZE]; /* the header for pr's -h option */
  240. char outcommand[LINESIZE]; /* the command which is the output filter */
  241. # ifndef DEBUG
  242. char printer[LINESIZE] = "PostScript";    /* the printer(argument to lpr -P??) */
  243. # else
  244. char printer[LINESIZE] = "";    /* the printer (argument to lpr -P??) */
  245. # endif DEBUG
  246. /*
  247.  * various global information
  248.  */
  249. char MPAGE[] = "mpage";    /* program name */
  250. int ps_pagenum = 0;    /* current page count */
  251. char usage[] =        /* usage string */
  252. "mpage [-aulnp1248] [-Llines] [-Wwidth] [-hheader] [-Pprinter] [files...]\n";
  253.  
  254.