Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

740 lines
28 KiB

  1. /*
  2. * LPPRINT.C - Printer handling for PPR
  3. *
  4. */
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <io.h>
  9. #include <fcntl.h>
  10. #include <windows.h>
  11. #include <tools.h>
  12. #include "lpr.h"
  13. char szPName[cchArgMax]; /* text of printer to open */
  14. char szNet[cchArgMax] = ""; /* network name of printer to open */
  15. char *szPDesc = NULL; /* printer description string */
  16. FILE *pfileLPR = NULL; /* file for output */
  17. extern BOOL fVerify; /* From LPR.C */
  18. extern USHORT usCodePage;
  19. void
  20. OutLPR(
  21. char *sz,
  22. int cb
  23. )
  24. {
  25. if (cb == 0)
  26. cb = strlen(sz);
  27. lcbOutLPR += cb; /* keep track of how much has been written to printer */
  28. if (fwrite(sz, 1, cb, pfileLPR) != (unsigned int)cb)
  29. Error("warning: error writing to printer");
  30. }
  31. /*
  32. * We need to add a little cheat, since some of our forced strings might have
  33. * special postscript characters in them, such as the file name for one...
  34. * We will call this function instead of OutLPR anytime that the string we are
  35. * outputing will be within '(...)', and might contain \, (, or ).
  36. * The code was borrowed from the original version of OutEncPS.
  37. */
  38. void
  39. OutLPRPS(
  40. /* output substring quoting all \, ( and ) */
  41. char *pchF,
  42. int cchF
  43. )
  44. {
  45. register char *pchT;
  46. int cchT;
  47. char rgbT[1+colMax*2+5];/* enough for every character to be encoded */
  48. pchT = rgbT;
  49. cchT = 0;
  50. if (cchF == 0)
  51. cchF = strlen(pchF);
  52. *pchT = (char)0;
  53. while (cchF-- > 0) {
  54. switch(*pchF++) {
  55. default:
  56. *pchT++ = *(pchF-1);
  57. cchT++;
  58. break;
  59. case '\\':
  60. *pchT++ = '\\';
  61. *pchT++ = '\\';
  62. cchT += 2;
  63. break;
  64. case '(':
  65. *pchT++ = '\\';
  66. *pchT++ = '(';
  67. cchT += 2;
  68. break;
  69. case ')':
  70. *pchT++ = '\\';
  71. *pchT++ = ')';
  72. cchT += 2;
  73. break;
  74. }
  75. }
  76. OutLPR(rgbT, cchT);
  77. }
  78. void
  79. DefaultPSHeader()
  80. {
  81. /* Don't install an error handler for now. If they need one, then they
  82. * should be installing one onto the printer permanently. SETERROR.PSF
  83. * is one they can use if they need to.
  84. */
  85. //OutLPR ("errordict begin\n",0); /* join */
  86. //OutLPR ("/handleerror {\n",0); /* join */
  87. //OutLPR ("$error begin\n",0); /* join */
  88. //OutLPR ("newerror {\n",0); /* join */
  89. //OutLPR ("/newerror false def\n",0); /* join */
  90. //OutLPR ("showpage\n",0); /* join */
  91. //OutLPR ("72 72 scale\n",0); /* join */
  92. //OutLPR ("/Helvetica findfont .2 scalefont setfont\n",0); /* join */
  93. //OutLPR (".25 10 moveto\n",0); /* join */
  94. //OutLPR ("(Error/ErrorName = ) show\n",0); /* join */
  95. //OutLPR ("errorname {\n",0); /* join */
  96. //OutLPR ("dup type\n",0); /* join */
  97. //OutLPR ("dup ([ ) show\n",0); /* join */
  98. //OutLPR ("(\n",0); /* join */
  99. //OutLPR ("neringtypeflow\n",0); /* join */
  100. //OutLPR (")\n",0); /* join */
  101. //OutLPR ("cvs show ( : ) show\n",0); /* join */
  102. //OutLPR ("/stringtype ne {\n",0); /* join */
  103. //OutLPR ("(\n",0); /* join */
  104. //OutLPR ("neringtypeflow\n",0); /* join */
  105. //OutLPR (")\n",0); /* join */
  106. //OutLPR ("cvs\n",0); /* join */
  107. //OutLPR ("} if\n",0); /* join */
  108. //OutLPR ("show\n",0); /* join */
  109. //OutLPR ("} exec\n",0); /* join */
  110. //OutLPR ("( ]; Error/Command = ) show\n",0); /* join */
  111. //OutLPR ("/command load {\n",0); /* join */
  112. //OutLPR ("dup type /stringtype ne {\n",0); /* join */
  113. //OutLPR ("(\n",0); /* join */
  114. //OutLPR ("neringtypeflow\n",0); /* join */
  115. //OutLPR (")\n",0); /* join */
  116. //OutLPR ("cvs\n",0); /* join */
  117. //OutLPR ("} if show\n",0); /* join */
  118. //OutLPR ("} exec\n",0); /* join */
  119. //OutLPR ("( %%) {\n",0); /* join */
  120. //OutLPR ("{\n",0); /* join */
  121. //OutLPR ("dup type /stringtype ne {\n",0); /* join */
  122. //OutLPR ("(\n",0); /* join */
  123. //OutLPR ("neringtypeflow\n",0); /* join */
  124. //OutLPR (")\n",0); /* join */
  125. //OutLPR ("cvs\n",0); /* join */
  126. //OutLPR ("} if\n",0); /* join */
  127. //OutLPR ("show\n",0); /* join */
  128. //OutLPR ("} exec (\n",0); /* join */
  129. //OutLPR (") show\n",0); /* join */
  130. //OutLPR ("} exec\n",0); /* join */
  131. //OutLPR ("/x .25 def\n",0); /* join */
  132. //OutLPR ("/y 10 def\n",0); /* join */
  133. //OutLPR ("\n",0); /* join */
  134. //OutLPR ("/y y .2 sub def\n",0); /* join */
  135. //OutLPR ("x y moveto\n",0); /* join */
  136. //OutLPR ("(Stack =) show\n",0); /* join */
  137. //OutLPR ("ostack {\n",0); /* join */
  138. //OutLPR ("/y y .2 sub def x 1 add y moveto\n",0); /* join */
  139. //OutLPR ("dup type /stringtype ne {\n",0); /* join */
  140. //OutLPR ("(\n",0); /* join */
  141. //OutLPR ("neringtypeflow\n",0); /* join */
  142. //OutLPR (")\n",0); /* join */
  143. //OutLPR ("cvs\n",0); /* join */
  144. //OutLPR ("} if\n",0); /* join */
  145. //OutLPR ("show\n",0); /* join */
  146. //OutLPR ("} forall\n",0); /* join */
  147. //OutLPR ("\n",0); /* join */
  148. //OutLPR ("showpage\n",0); /* join */
  149. //OutLPR ("} if % if (newerror)\n",0);
  150. //OutLPR ("end\n",0); /* join */
  151. //OutLPR ("} def\n",0); /* join */
  152. //OutLPR ("end\n",0); /* join */
  153. //OutLPR ("\n",0); /* join */
  154. /* End of error handler */
  155. OutLPR ("/inch {72 mul} def\n",0); /* join */
  156. OutLPR ("/White 1 def\n",0); /* join */
  157. OutLPR ("/Black 0 def\n",0); /* join */
  158. OutLPR ("/Gray .9 def\n",0); /* join */
  159. OutLPR ("newpath clippath closepath pathbbox\n",0); /* join */
  160. OutLPR ("/ury exch def\n",0); /* join */
  161. OutLPR ("/urx exch def\n",0); /* join */
  162. OutLPR ("/lly exch def\n",0); /* join */
  163. OutLPR ("/llx exch def\n",0); /* join */
  164. OutLPR ("/PrintWidth urx llx sub def\n",0); /* join */
  165. OutLPR ("/PrintHeight ury lly sub def\n",0); /* join */
  166. OutLPR ("/Mode 0 def\n",0); /* join */
  167. OutLPR ("/doBanner false def\n",0); /* join */
  168. OutLPR ("/MSConfidential false def\n",0); /* join */
  169. OutLPR ("/HeaderHeight 12 def\n",0); /* join */
  170. OutLPR ("/FooterHeight 12 def\n",0); /* join */
  171. OutLPR ("/FontHeight 12 def\n",0); /* join */
  172. OutLPR ("\n",0); /* join */
  173. OutLPR ("/szLine 256 string def\n",0); /* join */
  174. OutLPR ("/Font1 (Courier-Bold) def\n",0); /* join */
  175. OutLPR ("/Font2 (Times-Roman) def\n",0); /* join */
  176. OutLPR ("/Font3 (Helvetica-Bold) def\n",0); /* join */
  177. OutLPR ("Font1 cvn findfont setfont\n",0); /* join */
  178. OutLPR ("/LinesPerPage 62 def\n",0); /* join */
  179. OutLPR ("/AveCharWidth (0) stringwidth pop def\n",0); /* join */
  180. OutLPR ("/CharsPerLine AveCharWidth 86 mul def\n",0); /* join */
  181. OutLPR ("\n",0); /* join */
  182. OutLPR ("/sw { % Add Widths of mulitple strings\n",0);
  183. OutLPR ("stringwidth pop add\n",0); /* join */
  184. OutLPR ("} bind def\n",0); /* join */
  185. OutLPR ("\n",0); /* join */
  186. OutLPR ("/CenterString {\n",0); /* join */
  187. OutLPR ("/str exch def /width exch def\n",0); /* join */
  188. OutLPR ("width str stringwidth pop sub 2 div 0 rmoveto\n",0); /* join */
  189. OutLPR ("str\n",0); /* join */
  190. OutLPR ("} def\n",0); /* join */
  191. OutLPR ("\n",0); /* join */
  192. OutLPR ("/Box { % put a 'box' path into current path using width and height\n",0);
  193. OutLPR ("/h exch def\n",0); /* join */
  194. OutLPR ("/w exch def\n",0); /* join */
  195. OutLPR ("currentpoint\n",0); /* join */
  196. OutLPR ("/y exch def\n",0); /* join */
  197. OutLPR ("/x exch def\n",0); /* join */
  198. OutLPR ("x w add y lineto\n",0); /* join */
  199. OutLPR ("x w add y h add lineto\n",0); /* join */
  200. OutLPR ("x y h add lineto\n",0); /* join */
  201. OutLPR ("x y lineto\n",0); /* join */
  202. OutLPR ("} bind def\n",0); /* join */
  203. OutLPR ("\n",0); /* join */
  204. OutLPR ("/DoBannerPage {\n",0); /* join */
  205. OutLPR ("/doBanner false def\n",0); /* join */
  206. OutLPR ("Mode 1 eq {8.5 inch 0 inch translate 90 rotate} if\n",0); /* join */
  207. OutLPR ("2 setlinewidth 2 setmiterlimit\n",0); /* join */
  208. OutLPR ("\n",0); /* join */
  209. OutLPR ("% Banner Piece #1\n",0);
  210. OutLPR ("newpath\n",0); /* join */
  211. OutLPR ("0 PrintHeight moveto\n",0); /* join */
  212. OutLPR ("llx .5 inch add -1 inch rmoveto\n",0); /* join */
  213. OutLPR ("PrintWidth 1 inch sub .75 inch Box\n",0); /* join */
  214. OutLPR ("closepath stroke\n",0); /* join */
  215. OutLPR ("\n",0); /* join */
  216. OutLPR ("/XUnit PrintWidth 8 div def\n",0); /* join */
  217. OutLPR ("/XPos XUnit def\n",0); /* join */
  218. OutLPR ("/YPos PrintHeight .5 inch sub def\n",0); /* join */
  219. OutLPR ("/YInc .15 inch def\n",0); /* join */
  220. OutLPR ("Font2 cvn findfont YInc scalefont setfont\n",0); /* join */
  221. OutLPR ("XPos YPos moveto (User:) show /YPos YPos YInc sub def\n",0); /* join */
  222. OutLPR ("XPos YPos moveto (File Name:) show /YPos YPos YInc sub def\n",0); /* join */
  223. OutLPR ("XPos YPos moveto (Date Printed:) show /YPos YPos YInc sub def\n",0); /* join */
  224. OutLPR ("/XPos XUnit 4 mul def\n",0); /* join */
  225. OutLPR ("/YPos PrintHeight .5 inch sub YInc sub def\n",0); /* join */
  226. OutLPR ("XPos YPos moveto (Directory:) show /YPos YPos YInc sub def\n",0); /* join */
  227. OutLPR ("XPos YPos moveto (Time Printed:) show /YPos YPos YInc sub def\n",0); /* join */
  228. OutLPR ("\n",0); /* join */
  229. OutLPR ("Font1 cvn findfont YInc scalefont setfont\n",0); /* join */
  230. OutLPR ("/XPos XUnit 2 mul def\n",0); /* join */
  231. OutLPR ("/YPos PrintHeight .5 inch sub def\n",0); /* join */
  232. OutLPR ("XPos YPos moveto UserName show /YPos YPos YInc sub def\n",0); /* join */
  233. OutLPR ("XPos YPos moveto FileName show /YPos YPos YInc sub def\n",0); /* join */
  234. OutLPR ("XPos YPos moveto Date show /YPos YPos YInc sub def\n",0); /* join */
  235. OutLPR ("/XPos XUnit 5 mul def\n",0); /* join */
  236. OutLPR ("/YPos PrintHeight .5 inch sub YInc sub def\n",0); /* join */
  237. OutLPR ("XPos YPos moveto PathName show /YPos YPos YInc sub def\n",0); /* join */
  238. OutLPR ("XPos YPos moveto Time show\n",0); /* join */
  239. OutLPR ("\n",0); /* join */
  240. OutLPR ("% Banner Piece #2\n",0);
  241. OutLPR ("Font3 cvn findfont 1 inch scalefont setfont\n",0); /* join */
  242. OutLPR ("newpath\n",0); /* join */
  243. OutLPR ("llx PrintHeight 3 inch sub moveto\n",0); /* join */
  244. OutLPR ("PrintWidth UserName CenterString true charpath\n",0); /* join */
  245. OutLPR ("llx PrintHeight 5 inch sub moveto\n",0); /* join */
  246. OutLPR ("PrintWidth FileName CenterString true charpath\n",0); /* join */
  247. OutLPR ("closepath\n",0); /* join */
  248. OutLPR ("gsave\n",0); /* join */
  249. OutLPR ("Gray setgray fill\n",0); /* join */
  250. OutLPR ("grestore\n",0); /* join */
  251. OutLPR ("stroke\n",0); /* join */
  252. OutLPR ("\n",0); /* join */
  253. OutLPR ("MSConfidential {\n",0); /* join */
  254. OutLPR ("Font2 cvn findfont .5 inch scalefont setfont\n",0); /* join */
  255. OutLPR ("newpath\n",0); /* join */
  256. OutLPR ("llx PrintHeight 7 inch sub moveto\n",0); /* join */
  257. OutLPR ("PrintWidth Stamp CenterString show\n",0); /* join */
  258. OutLPR ("closepath\n",0); /* join */
  259. OutLPR ("} if\n",0); /* join */
  260. OutLPR ("\n",0); /* join */
  261. OutLPR ("showpage\n",0); /* join */
  262. OutLPR ("} def\n",0); /* join */
  263. OutLPR ("\n",0); /* join */
  264. OutLPR ("/BannerPage {\n",0); /* join */
  265. OutLPR ("/doBanner true def\n",0); /* join */
  266. OutLPR ("} def\n",0); /* join */
  267. OutLPR ("\n",0); /* join */
  268. OutLPR ("/Portrait {\n",0); /* join */
  269. OutLPR ("/LinesPerPage 66 def\n",0); /* join */
  270. OutLPR ("/CharsPerLine CharsPerLine Columns div def\n",0); /* join */
  271. OutLPR ("} def\n",0); /* join */
  272. OutLPR ("\n",0); /* join */
  273. OutLPR ("/QuadPage {\n",0); /* join */
  274. OutLPR ("/LinesPerPage 132 def\n",0); /* join */
  275. OutLPR ("/CharsPerLine CharsPerLine Columns 2 div div def\n",0); /* join */
  276. OutLPR ("} def\n",0); /* join */
  277. OutLPR ("\n",0); /* join */
  278. OutLPR ("/Landscape {\n",0); /* join */
  279. OutLPR ("/PrintHeight urx llx sub def\n",0); /* join */
  280. OutLPR ("/PrintWidth ury lly sub def\n",0); /* join */
  281. OutLPR ("/Mode 1 def\n",0); /* join */
  282. OutLPR ("/LinesPerPage 62 def\n",0); /* join */
  283. OutLPR ("/CharsPerLine CharsPerLine Columns 2 div div def\n",0); /* join */
  284. OutLPR ("} def\n",0); /* join */
  285. OutLPR ("\n",0); /* join */
  286. OutLPR ("/Init {\n",0); /* join */
  287. OutLPR ("100 0 {dup mul exch dup mul add 1 exch sub} setscreen\n",0); /* join */
  288. OutLPR ("PrintWidth Columns div .02 mul\n",0); /* join */
  289. OutLPR ("/BorderX exch def\n",0); /* join */
  290. OutLPR ("PrintWidth BorderX sub Columns div BorderX sub\n",0); /* join */
  291. OutLPR ("/PageWidth exch def\n",0); /* join */
  292. OutLPR ("PrintHeight HeaderHeight FooterHeight add sub\n",0); /* join */
  293. OutLPR ("/PageHeight exch def\n",0); /* join */
  294. OutLPR ("\n",0); /* join */
  295. OutLPR ("/FontHeight PageHeight LinesPerPage div def\n",0); /* join */
  296. OutLPR ("/FontWidth PageWidth CharsPerLine div def\n",0); /* join */
  297. OutLPR ("/PageNumber 1 def\n",0); /* join */
  298. OutLPR ("PageHeight FooterHeight add FontHeight sub\n",0); /* join */
  299. OutLPR ("/topY exch def\n",0); /* join */
  300. OutLPR ("/currentY topY def\n",0); /* join */
  301. OutLPR ("FooterHeight FontHeight add\n",0); /* join */
  302. OutLPR ("/bottomY exch def\n",0); /* join */
  303. OutLPR ("BorderX 1.25 mul\n",0); /* join */
  304. OutLPR ("/currentX exch def\n",0); /* join */
  305. OutLPR ("} def\n",0); /* join */
  306. OutLPR ("\n",0); /* join */
  307. OutLPR ("/PageBorder {\n",0); /* join */
  308. OutLPR ("% Gray backgound\n",0);
  309. OutLPR ("currentgray\n",0); /* join */
  310. OutLPR ("newpath clippath closepath Gray setgray fill\n",0); /* join */
  311. OutLPR ("setgray\n",0); /* join */
  312. OutLPR ("Label {\n", 0); /* join */
  313. OutLPR ("Font2 cvn findfont FooterHeight scalefont setfont\n",0); /* join */
  314. OutLPR ("% Left Justify UserName\n",0);
  315. OutLPR ("BorderX 2 moveto\n",0); /* join */
  316. OutLPR ("UserName show\n",0); /* join */
  317. OutLPR ("PrintWidth 2 div 2 moveto\n",0); /* join */
  318. OutLPR ("% Center File Name\n",0);
  319. OutLPR ("0 PathName sw (\\\\) sw FileName sw 2 div neg 0 rmoveto\n",0); /* join */
  320. OutLPR ("PathName show (\\\\) show FileName show\n",0); /* join */
  321. OutLPR ("% Right Justify Date\n",0);
  322. OutLPR ("PrintWidth BorderX sub 2 moveto\n",0); /* join */
  323. OutLPR ("FTime stringwidth pop neg 0 rmoveto FTime show\n",0); /* join */
  324. OutLPR ("} if\n", 0); /* join */
  325. OutLPR ("} def\n",0); /* join */
  326. OutLPR ("\n",0); /* join */
  327. OutLPR ("/Confidential {\n",0); /* join */
  328. OutLPR ("MSConfidential {\n",0); /* join */
  329. OutLPR ("gsave\n",0); /* join */
  330. OutLPR ("PageWidth 2 div PageHeight 2 div moveto Font2 cvn findfont\n",0); /* join */
  331. OutLPR ("setfont Stamp stringwidth pop PageWidth exch div dup 30\n",0); /* join */
  332. OutLPR ("rotate PageWidth 2 div neg 0 rmoveto scale\n",0); /* join */
  333. OutLPR ("Stamp true charpath closepath gsave Gray setgray fill\n", 0);
  334. OutLPR ("grestore 0 setlinewidth stroke\n",0);
  335. OutLPR ("grestore\n",0); /* join */
  336. OutLPR ("} if\n",0); /* join */
  337. OutLPR ("} def\n",0); /* join */
  338. OutLPR ("\n",0); /* join */
  339. OutLPR ("/NewPage {\n",0); /* join */
  340. OutLPR ("/currentY topY def\n",0); /* join */
  341. OutLPR ("Columns 1 gt PageNumber 1 sub Columns mod 0 ne and {\n",0); /* join */
  342. OutLPR ("% Don't do this on first column of page\n",0);
  343. OutLPR ("PageWidth BorderX add 0 translate\n",0); /* join */
  344. OutLPR ("} {\n",0); /* join */
  345. OutLPR ("% Do this only for first column of page\n",0);
  346. OutLPR ("llx lly translate\n",0); /* join */
  347. OutLPR ("Mode 1 eq { PrintHeight 0 translate 90 rotate } if\n",0); /* join */
  348. OutLPR ("PageBorder\n",0); /* join */
  349. OutLPR ("} ifelse\n",0); /* join */
  350. OutLPR ("newpath % Frame the page\n",0);
  351. OutLPR ("BorderX FooterHeight moveto\n",0); /* join */
  352. OutLPR ("PageWidth PageHeight Box\n",0); /* join */
  353. OutLPR ("closepath\n",0); /* join */
  354. OutLPR ("gsave\n",0); /* join */
  355. OutLPR ("White setgray fill\n",0); /* join */
  356. OutLPR ("grestore\n",0); /* join */
  357. OutLPR ("Black setgray stroke\n",0); /* join */
  358. OutLPR ("Confidential\n",0);
  359. OutLPR ("Font2 cvn findfont HeaderHeight scalefont setfont\n",0); /* join */
  360. OutLPR ("BorderX PageWidth 2 div add FooterHeight PageHeight add 2 add moveto\n",0); /* join */
  361. OutLPR ("Label {\n", 0); /* join */
  362. OutLPR ("PageNumber szLine cvs show\n",0); /* join */
  363. OutLPR ("} if\n", 0);
  364. OutLPR ("Font1 cvn findfont [FontWidth 0 0 FontHeight 0 0] makefont setfont\n",0); /* join */
  365. OutLPR ("/PageNumber PageNumber 1 add def\n",0); /* join */
  366. OutLPR ("} def\n",0); /* join */
  367. OutLPR ("\n",0); /* join */
  368. OutLPR ("/EndPage {\n",0); /* join */
  369. OutLPR ("Columns 1 eq PageNumber 1 sub Columns mod 0 eq or { showpage } if\n",0); /* join */
  370. OutLPR ("NewPage\n",0); /* join */
  371. OutLPR ("} def\n",0); /* join */
  372. OutLPR ("\n",0); /* join */
  373. OutLPR ("/PrintLine {\n",0); /* join */
  374. OutLPR ("dup dup length 0 gt {\n",0); /* join */
  375. OutLPR ("% Something there\n",0);
  376. OutLPR ("0 get 12 eq {\n",0); /* join */
  377. OutLPR ("% Form Feed\n",0);
  378. OutLPR ("EndPage\n",0); /* join */
  379. OutLPR ("}{\n",0); /* join */
  380. OutLPR ("currentX currentY moveto show\n",0); /* join */
  381. OutLPR ("/currentY currentY FontHeight sub def\n",0); /* join */
  382. OutLPR ("currentY bottomY le { EndPage } if\n",0); /* join */
  383. OutLPR ("} ifelse\n",0); /* join */
  384. OutLPR ("}{\n",0); /* join */
  385. OutLPR ("% Blank Line\n",0);
  386. OutLPR ("pop pop pop\n",0); /* join */
  387. OutLPR ("/currentY currentY FontHeight sub def\n",0); /* join */
  388. OutLPR ("currentY bottomY le { EndPage } if\n",0); /* join */
  389. OutLPR ("} ifelse\n",0); /* join */
  390. OutLPR ("}bind def\n",0); /* join */
  391. OutLPR ("\n",0); /* join */
  392. OutLPR ("\n",0); /* join */
  393. OutLPR ("/DebugOut {\n",0); /* join */
  394. OutLPR ("/num exch def\n",0); /* join */
  395. OutLPR ("/str exch def\n",0); /* join */
  396. OutLPR ("currentpoint\n",0); /* join */
  397. OutLPR ("str show\n",0); /* join */
  398. OutLPR ("num szLine cvs show\n",0); /* join */
  399. OutLPR ("moveto\n",0); /* join */
  400. OutLPR ("0 -11 rmoveto\n",0); /* join */
  401. OutLPR ("}bind def\n",0); /* join */
  402. OutLPR ("\n",0); /* join */
  403. OutLPR ("/PrintFile {\n",0); /* join */
  404. OutLPR ("Init % Initialize some values\n",0);
  405. OutLPR ("doBanner { DoBannerPage } if\n",0); /* join */
  406. OutLPR ("NewPage\n",0); /* join */
  407. OutLPR ("{\n",0); /* join */
  408. OutLPR ("currentfile szLine readline not {exit} if\n",0); /* join */
  409. OutLPR ("dup dup length 0 gt { 0 get 28 eq {exit} if } if\n",0); /* join */
  410. OutLPR ("PrintLine\n",0); /* join */
  411. OutLPR ("} loop\n",0); /* join */
  412. OutLPR ("showpage % Will this *ever* produce an unwanted blank page?\n",0);
  413. OutLPR ("} bind def\n",0); /* join */
  414. } /* DefaultPSHeader */
  415. void
  416. InitPrinter()
  417. {
  418. char *szHeader;
  419. char *szDirlist;
  420. char szFullname[MAX_PATH];
  421. BOOL fConcat = FALSE;
  422. FILE *psfFile;
  423. register char *pch;
  424. if (fLaser) {
  425. OutLPR(RESETPRINTER, 0);
  426. if (fVDuplex) {
  427. OutLPR(BEGINDUPLEXVERT,0);
  428. } else if (fHDuplex)
  429. OutLPR(BEGINDUPLEXHOR,0);
  430. } else if (fPostScript) {
  431. /* write the job setup for postscript */
  432. OutLPR("\n\004\n% ppr job\n", 0); /* ^D to flush previous job */
  433. if (!fPSF) {
  434. DefaultPSHeader();
  435. } else {
  436. szHeader = szPSF;
  437. if (*szHeader == '+') {
  438. szHeader++; // step over the '+'
  439. fConcat = TRUE;
  440. DefaultPSHeader();
  441. }
  442. /* Lets make an attempt to use environment variables... */
  443. if ((*szHeader == '$') && ((pch = strchr(++szHeader,':')) != NULL)) {
  444. *pch = (char)NULL;
  445. _strupr(szHeader);
  446. szDirlist = getenvOem(szHeader);
  447. // szDirlist = getenv(szHeader);
  448. *pch = ':';
  449. szHeader = ++pch;
  450. } else {
  451. szDirlist = NULL;
  452. }
  453. while (szDirlist) {
  454. szDirlist = SzFindPath(szDirlist,szFullname,szHeader);
  455. szHeader = szFullname;
  456. }
  457. /* ...end of attempt */
  458. if ((psfFile = fopen(szHeader, szROBin)) != NULL) {
  459. int cb;
  460. char psfLine[cchLineMax];
  461. char szFFile[MAX_PATH];
  462. rootpath (szHeader, szFFile);
  463. _strupr(szFFile);
  464. fprintf (stdout, "\nUsing PSF File: %s\n", szFFile);
  465. while ((cb = fread(psfLine, 1, cchLineMax, psfFile)) > 0)
  466. RawOut(psfLine, cb);
  467. } else {
  468. fprintf (stdout, "Error opening PSF file %s\n", szPSF);
  469. if (!fConcat) {
  470. fprintf (stdout, "Continuing with default header...\n");
  471. DefaultPSHeader();
  472. }
  473. }
  474. }
  475. }
  476. }
  477. void
  478. MyOpenPrinter()
  479. {
  480. if (strcmp(szPName, "-") == 0) {
  481. pfileLPR = stdout;
  482. _setmode((int)_fileno(pfileLPR), (int)O_BINARY);
  483. } else {
  484. if ((pfileLPR = fopen(szPName, szWOBin)) == NULL)
  485. Fatal("Error opening output file %s", szPName);
  486. }
  487. InitPrinter();
  488. }
  489. void
  490. FlushPrinter()
  491. {
  492. /* A FormFeed is sent before each page. For fForceFF, we also send
  493. one after the last page. For !fForceFF we move to the top of
  494. the page so that when the network software outputs \r\n\f, we do
  495. not get a blank page.
  496. NOTE: for !fForceFF we don't reset the printer or change modes back
  497. to portrait since that causes any unfinished page to be ejected.
  498. */
  499. if (fLaser) {
  500. if (fVDuplex || fHDuplex)
  501. OutLPR(BEGINSIMPLEX,0);
  502. else
  503. if (fForceFF)
  504. OutLPR(RESETPRINTER, 0);
  505. else
  506. OutLPR(MOVETOTOP, 0);
  507. }
  508. else if (fPostScript)
  509. OutLPR("\n\004\n", 0); /* ^D to flush */
  510. else
  511. OutLPR("\n\n",0); /* force last line on LP */
  512. }
  513. void
  514. MyClosePrinter()
  515. {
  516. if (pfileLPR == 0)
  517. return; /* already closed */
  518. FlushPrinter();
  519. if (pfileLPR != stdout)
  520. fclose(pfileLPR);
  521. pfileLPR = NULL;
  522. }
  523. /* Fill szBuf with first non-blank substring found in sz; return pointer
  524. to following non-blank. Note: ',' is considered a separator as are ' '
  525. and '\t' however, ',' is also considered a non-blank.
  526. */
  527. char *
  528. SzGetSzSz(
  529. char * sz,
  530. char * szBuf
  531. )
  532. {
  533. int cch;
  534. sz += strspn(sz, " \t");
  535. cch = strcspn(sz, " \t,");
  536. szBuf[0] = '\0';
  537. if (cch) /* count of 0 causes error on Xenix 286 */
  538. strncat(szBuf, sz, cch);
  539. sz += cch;
  540. sz += strspn(sz, " \t");
  541. return sz;
  542. }
  543. char *
  544. SzGetPrnName(
  545. char *sz,
  546. char *szBuf
  547. )
  548. {
  549. register char *pch;
  550. sz = SzGetSzSz(sz, szBuf);
  551. if (*(pch = szBuf+strlen(szBuf)-1) == ':')
  552. *pch = '\0'; /* Remove colon from end of printer name */
  553. return (sz);
  554. }
  555. /* get printer name and net redirection from a string
  556. *
  557. * Entry: sz - string to parse;
  558. * szPName contains printer name that user requested to use
  559. *
  560. * Return Value: TRUE if printer name found matches and thus
  561. * the rest of the string was processed;
  562. * FALSE if no match and thus string is ignored
  563. *
  564. * Global Variables Set:
  565. *
  566. * szPName - Physical printer port to use, or output file name
  567. * szNet - Network redirection name
  568. * szPass - Network password
  569. *
  570. * printer desc:
  571. * (DOS) [<name> [none | \\<machine>\<shortname> [<password>]]] [,<options>]
  572. * (Xenix) [ ( [ net[#] | lpr[#] | xenix[#] | alias[#] ] [<name>] ) |
  573. * ( dos[#] [<server> <shortname> [<password>] ) ] [,<options>]
  574. *
  575. * The optional network password must be separated from the network name
  576. * by some space (it may not contain space, TAB or comma).
  577. */
  578. BOOL
  579. FParseSz(
  580. char *sz
  581. )
  582. {
  583. char szT[cchArgMax];
  584. sz = SzGetPrnName(sz, szT); // Get first 'word', remove colon
  585. if (strcmpx(szT, szPName)) {
  586. // first word is not the printer name the user requested
  587. return (FALSE);
  588. }
  589. if (*sz != ',') {
  590. sz = SzGetSzSz(sz, szT); // Get next 'word'
  591. if (szT[strlen(szT)-1] == ':') {
  592. // Possible physical 'port'
  593. SzGetPrnName (szT, szPName);
  594. sz = SzGetSzSz(sz, szT);
  595. }
  596. if (*szT)
  597. strcpy(szNet, szT); // Network redirection name
  598. if (*sz != ',') {
  599. sz= SzGetSzSz(sz, szT);
  600. if (*szT)
  601. strcpy(szPass, szT); // Network Password
  602. }
  603. }
  604. /* We are setting printer info, display it if we were asked to */
  605. if (fVerify) {
  606. fprintf (stdout, "Local printer name : %s\n", szPName);
  607. fprintf (stdout, "Options specified : %s\n", sz);
  608. fprintf (stdout, "Remote printer name: %s\n", szNet);
  609. }
  610. DoOptSz(sz); // Now read any options that followed
  611. return (TRUE);
  612. }
  613. void
  614. SetupPrinter()
  615. /* determine printer name and options */
  616. {
  617. char rgbSW[cchArgMax];
  618. char szEName[cchArgMax]; /* name of printer in $PRINTER*/
  619. char *szT;
  620. FILE *pfile;
  621. BOOL fNoDest = TRUE;
  622. /* determine name of printer in $PRINTER (if one) */
  623. szEName[0] = '\0';
  624. if ((szT=getenvOem("PRINTER")) != NULL) {
  625. if (fVerify) {
  626. fprintf (stdout, "Using 'PRINTER' environment string:\n");
  627. }
  628. fNoDest = FALSE;
  629. SzGetPrnName(szT, szEName);
  630. }
  631. /* determine actual printer name to use; one of -p, $PRINTER, default */
  632. if (szPDesc != NULL) {
  633. fNoDest = FALSE;
  634. SzGetPrnName(szPDesc, szPName);
  635. } else {
  636. if (*szEName) {
  637. strcpy(szPName, szEName);
  638. } else {
  639. strcpy(szPName, PRINTER);
  640. }
  641. }
  642. /* if printer to use is the same as the one in $PRINTER, set up the
  643. options from $PRINTER (options from szPDesc below).
  644. */
  645. if (strcmpx(szPName, szEName) == 0) {
  646. if (szT)
  647. FParseSz(szT);
  648. } else {
  649. /* search parameter file */
  650. if ((pfile = swopen("$INIT:Tools.INI", "ppr")) != NULL) {
  651. /* 'PPR' tag found in '$INIT:TOOLS.INI' */
  652. while (swread(rgbSW, cchArgMax, pfile) != 0) {
  653. /* a switch line was read... */
  654. fNoDest = FALSE;
  655. szT = rgbSW + strspn(rgbSW, " \t"); // skip spaces, tabs
  656. /* a line "default=<printer>" sets szPName **
  657. ** if there is no environment setting **
  658. ** and no command line parameter -p */
  659. if (_strnicmp(szT, DEFAULT, strlen(DEFAULT))==0 &&
  660. szPDesc==NULL && *szEName == 0)
  661. {
  662. if ((szT = strchr(szT,'=')) != NULL) {
  663. SzGetSzSz(szT+1, szPName);
  664. FParseSz(szT+1);
  665. } else {
  666. fprintf(stderr, "ppr: warning: "
  667. "default setting in setup file incomplete\n");
  668. }
  669. } else {
  670. if (FParseSz(szT)) {
  671. break;
  672. }
  673. }
  674. }
  675. swclose(pfile);
  676. }
  677. }
  678. /* command line printer description overrides other settings */
  679. if (szPDesc != NULL)
  680. FParseSz(szPDesc);
  681. }