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.

800 lines
24 KiB

  1. /*
  2. * lppage.c - page formatting
  3. */
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <ctype.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #include <direct.h>
  11. #include <tools.h>
  12. #include <time.h>
  13. #include "lpr.h"
  14. #define ESC '\033'
  15. BOOL fPageTop = TRUE; /* TRUE => printer at top of page */
  16. BOOL fFirstFile = TRUE; /* TRUE => first file to be printed */
  17. /* information for formated page */
  18. BOOL fInit; /* TRUE => valid info in page */
  19. int iPage; /* current page being processed */
  20. int rowLine; /* row for next line */
  21. int iLine; /* number of current line */
  22. char szFFile[MAX_PATH]; /* full path of file being displayed */
  23. char szFTime[50]; /* ascii timestamp for file */
  24. char szUsr[MAX_PATH]; /* name of user */
  25. char szCompany[] = COMPANY;
  26. char szConf[] = CONFIDENTIAL;
  27. extern USHORT usCodePage;
  28. /* Specifics about ctime */
  29. #define cchDateMax 16
  30. #define cchTimeMax 10
  31. /* Maximum length in a short file name */
  32. /* Shape of the banner */
  33. #define crowBanner 30
  34. #define ccolBanner 102
  35. void BannerSz(szFName, cBanOut)
  36. char *szFName;
  37. int cBanOut; /* number to output; will be > 0 */
  38. {
  39. #define CenterCol(sz) (col + ((ccolBanner - (strlen(sz) << 3)) >> 1))
  40. #define cchFShort 12
  41. #define cchPShort 28
  42. #define cchUsrShort 12 /* length username block can be on banner */
  43. int row; /* Position of the banner */
  44. int col;
  45. char szDate[cchDateMax];
  46. char szTime[cchTimeMax];
  47. char szPath[MAX_PATH];
  48. char szConfid[sizeof(szCompany) + sizeof(szConf)];
  49. char szFNShort[cchFShort + 1]; /* To shorten the file name */
  50. /* only up to 12 chars. */
  51. char szUsrShort[cchUsrShort + 1];/* Need to shorten the username also! */
  52. char szBuffer[30];
  53. if (!fPostScript) {
  54. row = ((fLaser ? rowLJBanMax : rowMac) - crowBanner - 10)/2;
  55. col = ((fLaser ? colLJBanMax : colLPMax) - ccolBanner)/2;
  56. }
  57. szFNShort[cchFShort] = '\0' ;
  58. strncpy(szFNShort, szFName, cchFShort);
  59. szUsrShort[cchUsrShort] = '\0' ;
  60. strncpy(szUsrShort, szUsr, cchUsrShort);
  61. _getcwd(szPath, sizeof(szPath));
  62. _strupr(szPath);
  63. _strupr(szFNShort);
  64. SzDateSzTime(szDate, szTime);
  65. if (fPostScript) {
  66. int iPathLen = strlen (szFFile);
  67. while ((szFFile[iPathLen] != '\\') && (iPathLen>0)) {
  68. iPathLen--;
  69. }
  70. OutLPR("\n", 0);
  71. /* The 'strings' we are sending out, need to use OutLPRPS just in case
  72. * they contain \, (, or )...
  73. */
  74. // Assign a jobname
  75. OutLPR ("statusdict begin statusdict /jobname (PPR: ", 0);
  76. OutLPRPS (szUsr, 0);
  77. OutLPR (" - ", 0);
  78. OutLPRPS (szFNShort, 0);
  79. OutLPR (") put end \n", 0);
  80. if( fHDuplex || fVDuplex )
  81. {
  82. OutLPR( "statusdict begin ", 0 );
  83. OutLPR( fHDuplex ? "true" : "false", 0 );
  84. OutLPR( " settumble true setduplexmode end\n", 0);
  85. }
  86. // Define some of the data we will be wanting access to
  87. OutLPR ("/UserName (", 0); OutLPRPS (szUsr, 0); OutLPR (") def \n", 0);
  88. OutLPR ("/FileName (", 0); OutLPRPS (szFNShort ,0); OutLPR (") def \n", 0);
  89. OutLPR ("/PathName (", 0); OutLPRPS (szFFile, iPathLen); OutLPR (") def \n", 0);
  90. OutLPR ("/UserPath (", 0); OutLPRPS (szPath ,0); OutLPR (") def \n", 0);
  91. OutLPR ("/Date (", 0); OutLPRPS (szDate, 0); OutLPR (") def \n", 0);
  92. OutLPR ("/Time (", 0); OutLPRPS (szTime ,0); OutLPR (") def \n", 0);
  93. OutLPR ("/FTime (", 0); OutLPRPS (szFTime,0); OutLPR (") def \n", 0);
  94. OutLPR ("/Label ",0);
  95. OutLPR ((fLabel ? "true" : "false"), 0);
  96. OutLPR (" def \n", 0);
  97. if (fConfidential) {
  98. OutLPR ("/MSConfidential true def\n", 0);
  99. OutLPR ("/Stamp (", 0);
  100. if (szStamp && strlen(szStamp) > 0) {
  101. OutLPR (szStamp, 0);
  102. } else {
  103. strcpy(szConfid, szCompany);
  104. strcat(szConfid, " ");
  105. strcat(szConfid, szConf);
  106. OutLPR (szConfid, 0);
  107. }
  108. OutLPR (") def \n", 0);
  109. }
  110. if (szStamp != NULL) {
  111. OutLPR ("/MSConfidential true def\n", 0);
  112. OutLPR ("/Stamp (", 0);
  113. OutLPRPS (szStamp, 0);
  114. OutLPR (") def \n", 0);
  115. }
  116. // Width of 'gutter' in characters
  117. sprintf (szBuffer, "/Gutter %d def \n", colGutter);
  118. OutLPR (szBuffer, 0);
  119. // The total column width in characters
  120. sprintf (szBuffer, "/ColWidth %d def \n", colWidth);
  121. OutLPR (szBuffer, 0);
  122. // Number of character rows per page
  123. sprintf (szBuffer, "/RowCount %d def \n", rowMac);
  124. OutLPR (szBuffer, 0);
  125. // The character column text should start in
  126. sprintf (szBuffer, "/ColText %d def \n", colText);
  127. OutLPR (szBuffer, 0);
  128. // Number of columns per page
  129. sprintf (szBuffer, "/Columns %d def\n", cCol);
  130. OutLPR (szBuffer, 0);
  131. /* ... Ok, now lets get started! */
  132. if (cBanOut > 0) OutLPR ("BannerPage\n", 0);
  133. cBanOut--;
  134. /* print more banners if neccessary ?? */
  135. while (cBanOut-- > 0) {
  136. OutLPR ("BannerPage % Extra Banners??\n", 0);
  137. }
  138. } else {
  139. FillRectangle(' ', 0, 0, row + crowBanner, col + ccolBanner + 1);
  140. HorzLine('_', row, col + 1, col + ccolBanner);
  141. HorzLine('_', row + 5, col, col + ccolBanner);
  142. HorzLine('_', row + 16, col, col + ccolBanner);
  143. HorzLine('_', row + 29, col, col + ccolBanner);
  144. VertLine('|', col, row + 1, row + crowBanner);
  145. VertLine('|', col + ccolBanner, row + 1, row + crowBanner);
  146. WriteSzCoord("User:", row + 2, col + 15);
  147. WriteSzCoord(szUsr, row + 2, col + 30);
  148. WriteSzCoord("File Name:", row + 3, col + 15);
  149. WriteSzCoord(szFNShort, row + 3, col + 30);
  150. WriteSzCoord("Directory:", row + 3, col + 58);
  151. WriteSzCoord(szPath, row + 3, col + 73);
  152. WriteSzCoord("Date Printed:", row + 4, col + 15);
  153. WriteSzCoord("Time Printed:", row + 4, col + 58);
  154. WriteSzCoord(szDate, row + 4, col + 30);
  155. WriteSzCoord(szTime, row + 4, col + 73);
  156. block_flush(szUsrShort, row + 8, CenterCol(szUsrShort));
  157. block_flush(szFNShort, row + 20, CenterCol(szFNShort));
  158. if (fConfidential)
  159. {
  160. strcpy(szConfid, szCompany);
  161. strcat(szConfid, " ");
  162. strcat(szConfid, szConf);
  163. WriteSzCoord(szConfid, row+18, col + (ccolBanner-strlen(szConfid))/2);
  164. }
  165. if (szStamp != NULL)
  166. WriteSzCoord(szStamp, row+28, col + (ccolBanner-strlen(szStamp))/2);
  167. /* move to top of page */
  168. if (!fPageTop)
  169. OutLPR(fPostScript ? "showpage\n" : "\r\f", 0);
  170. if (fLaser)
  171. {
  172. if (fVDuplex || fHDuplex)
  173. OutLPR(SELECTFRONTPAGE,0);
  174. OutLPR(BEGINBANNER, 0);
  175. }
  176. if (fPostScript)
  177. OutLPR("beginbanner\n", 0);
  178. OutRectangle(0, 0, row + crowBanner, col + ccolBanner + 1);
  179. cBanOut--;
  180. /* print more banners if neccessary */
  181. while (cBanOut-- > 0) {
  182. OutLPR(fPostScript ? "showpage\n" : "\r\f", 0);
  183. if (fPostScript)
  184. OutLPR("beginbanner\n", 0);
  185. OutRectangle(0, 0, row + crowBanner, col + ccolBanner + 1);
  186. }
  187. } /* End of PostScript check */
  188. fPageTop = FALSE;
  189. }
  190. void SzDateSzTime(szDate, szTime)
  191. /* fill sz's with date & time */
  192. char *szDate, *szTime;
  193. {
  194. char *szt;
  195. char sz[26];
  196. time_t tT;
  197. time(&tT);
  198. szt = ctime(&tT);
  199. /* convert ctime format into Date & Time */
  200. strcpy(sz, szt);
  201. sz[10] = sz[19] = sz[24] = '\0'; /* break into DAY:TIME:YEAR */
  202. strcpy(szDate, &sz[0]);
  203. strcat(szDate, " ");
  204. strcat(szDate, &sz[20]);
  205. strcpy(szTime, &sz[11]);
  206. } /* SzDateSzTime */
  207. void FlushPage()
  208. /* FlushPage - dump a completed page to the printer */
  209. {
  210. if (!fInit)
  211. {
  212. if (!fPostScript) {
  213. if (!fPageTop)
  214. OutLPR("\r\f", 0);
  215. else if (!fLaser && fLabel)
  216. OutLPR("\n\n", 0); /* align printout on LP */
  217. }
  218. OutRectangle(0,0,rowMac,colMac);
  219. fPageTop = FALSE;
  220. }
  221. }
  222. void InitPage()
  223. /* fill in the page image with a blanks (and frame, if needed) */
  224. /* mark punch holes in to row for laserprinters in landscape mode, */
  225. /* so that PlaceTop() can avoid these spots when placing strings */
  226. {
  227. int iCol;
  228. fInit = TRUE;
  229. FillRectangle(' ', 0, 0, rowMac, colMac);
  230. if (!fPostScript)
  231. if (fBorder)
  232. {
  233. /* Draw border around page */
  234. HorzLine('_', 0 , 1, colMac - 1);
  235. HorzLine('_', rowMac - 1, 1, colMac - 1);
  236. VertLine('|', 0 , 1, rowMac);
  237. VertLine('|', colMac - 1, 1, rowMac);
  238. /* Fill in column separators */
  239. for (iCol = 0; iCol < cCol - 1; iCol++)
  240. VertLine('|', ColBeginIcol(iCol, colWidth) + colWidth, 1, rowMac-1);
  241. /* mark punch holes */
  242. if (fLabel && !fPortrait && (fPostScript || fLaser) )
  243. {
  244. if (fLaser)
  245. {
  246. HorzLine('\0', 0, 11, 19);
  247. HorzLine('\0', 0, 83, 92);
  248. HorzLine('\0', 0, 154, 162);
  249. }
  250. else
  251. {
  252. HorzLine('\0', 0, 11, 19);
  253. HorzLine('\0', 0, 77, 86);
  254. HorzLine('\0', 0, 144, 152);
  255. }
  256. }
  257. }
  258. }
  259. void RestoreTopRow()
  260. /* replace the zero bytes put in by InitPage() with underscores */
  261. {
  262. register char *pch;
  263. for (pch = &page[0][0]; pch<&page[0][colMac-1]; pch++)
  264. if (*pch=='\0' || (*pch==' ' && (*(pch-1)=='_' || *(pch+1)=='_')))
  265. *pch = '_';
  266. }
  267. void PlaceTop(szLabel, ichAim, ichMin, ichMax)
  268. char *szLabel;
  269. int ichAim, ichMin, ichMax;
  270. {
  271. int cchLab, cTry, dich, ichLim1, ichLim2;
  272. register int ich;
  273. register char *pch;
  274. BOOL fBackward;
  275. cchLab = strlen(szLabel);
  276. dich = (fBackward = ichAim<=(colMac-cchLab)/2) ? -1 : 1;
  277. for (cTry=0; cTry<2; cTry++)
  278. {
  279. if (fBackward)
  280. ichLim1 = (ichLim2=ichAim) + cchLab - 1;
  281. else
  282. ichLim2 = (ichLim1=ichAim+1) + cchLab - 1;
  283. for (pch= &page[0][ich=ichLim1];
  284. ich<ichMax && ich>ichMin;
  285. pch += dich, ich += dich)
  286. {
  287. if (*pch != '_')
  288. {
  289. ichLim1 = ich + dich;
  290. ichLim2 = ich + (fBackward ? -cchLab : cchLab);
  291. }
  292. else
  293. {
  294. if (ich==ichLim2) /* found spot, write string */
  295. {
  296. WriteSzCoord(szLabel, 0, min(ichLim1, ichLim2));
  297. return;
  298. }
  299. }
  300. }
  301. /* if no spot found, try the other direction */
  302. dich = -dich;
  303. fBackward = !fBackward;
  304. }
  305. }
  306. void PlaceNumber(iCol)
  307. int iCol;
  308. {
  309. int ichAim, ichMin, ichMax, cchN;
  310. char szN[8];
  311. sprintf(szN, " %d ", iPage + iCol + 1);
  312. ichMin = ColBeginIcol(iCol,colWidth);
  313. ichAim = ichMin + (colWidth - (cchN=strlen(szN)) )/2;
  314. ichMax = ichMin + colWidth - cchN - 1;
  315. PlaceTop(szN, ichAim, ichMin, ichMax);
  316. }
  317. void LabelPage()
  318. /* place page labels on page */
  319. {
  320. int col;
  321. char szT[11];
  322. char * szHeader;
  323. szHeader = szBanner ? szBanner : szFFile;
  324. if (fLabel)
  325. {
  326. if (fPortrait)
  327. {
  328. /* move top line over if gutter is being used */
  329. col = colGutter;
  330. /* place in szFTime */
  331. WriteSzCoord(szFTime, 0, col);
  332. col += strlen(szFTime)+2;
  333. /* place in file name after szFTime */
  334. WriteSzCoord(szHeader, 0, col);
  335. col += (strlen(szHeader)+2);
  336. /* place page numbers on page */
  337. sprintf(szT, "Page %d", iPage + 1);
  338. WriteSzCoord(szT, 0, col);
  339. col += (strlen(szT)+2);
  340. /* place user name on page */
  341. WriteSzCoord(szUsr, 0, col);
  342. col += (strlen(szUsr)+4);
  343. if (fConfidential)
  344. {
  345. WriteSzCoord(szCompany, 0, col);
  346. col += (strlen(szCompany)+1);
  347. WriteSzCoord(szConf, 0, col);
  348. }
  349. if (szStamp!=NULL)
  350. {
  351. WriteSzCoord(szStamp, 0, col);
  352. col += (strlen(szStamp)+4);
  353. }
  354. }
  355. else
  356. {
  357. int iCol;
  358. if (fConfidential)
  359. {
  360. PlaceTop(szCompany, colMac/2-strlen(szCompany)-1, 0, colMac-1);
  361. PlaceTop(szConf, colMac/2, 0, colMac-1);
  362. }
  363. if (szStamp!=NULL)
  364. PlaceTop(szStamp, colMac-strlen(szStamp)-1, 0, colMac-1);
  365. /* place page numbers on columns */
  366. for (iCol = 0; iCol < cCol; iCol++)
  367. PlaceNumber(iCol);
  368. RestoreTopRow();
  369. /* place in centered file name */
  370. WriteSzCoord(szHeader, rowMac-1, (colMac - strlen (szHeader))/2);
  371. /* place in right-justified szFTime */
  372. WriteSzCoord(szFTime, rowMac-1, colMac - 2 - strlen(szFTime));
  373. /* place in name in lower left hand corner */
  374. WriteSzCoord(szUsr,rowMac-1,2);
  375. }
  376. }
  377. }
  378. void AdvancePage()
  379. /* advance the counters to a succeeding page. Flush if necessary. */
  380. {
  381. if (fBorder || fLabel)
  382. rowLine = (fPortrait ? 3 : 1);
  383. else
  384. rowLine = 0;
  385. iPage++;
  386. /* if we have moved to a new printer page, flush and reinit */
  387. if ( fPostScript || ((iPage % cCol) == 0))
  388. {
  389. FlushPage();
  390. InitPage();
  391. if (!fPostScript)
  392. LabelPage();
  393. }
  394. }
  395. void XoutNonPrintSz(sz)
  396. /* replace non-printing characters in sz with dots; don't replace LF, CR, FF
  397. or HT.
  398. */
  399. register char *sz;
  400. {
  401. if (usCodePage != 0) {
  402. return;
  403. }
  404. while (*sz != '\0') {
  405. if ( !isascii(*sz)
  406. || ( !isprint(*sz) &&
  407. *sz != LF && *sz != CR && *sz != HT && *sz != FF &&
  408. *sz != *sz != ' ')) {
  409. *sz = '.';
  410. }
  411. sz++;
  412. }
  413. }
  414. void LineOut(sz, fNewLine)
  415. /* LineOut - place a line of text into the page buffer. The line is broken
  416. * into pieces that are at most colWidth long and are placed into separate
  417. * lines in the page. Lines that contain form-feeds are broken into pieces
  418. * also. Form-feeds cause advance to the next page. Handle paging. Handle
  419. * flushing of the internal buffer.
  420. *
  421. * sz character pointer to string for output. We modify this string
  422. * during the operation, but restore it at the end.
  423. *
  424. * fNewLine TRUE ==> this the start of a new input line (should number it)
  425. */
  426. register char *sz;
  427. BOOL fNewLine;
  428. {
  429. register char *pch;
  430. /* if there is a form feed, recurse to do the part before it */
  431. while (*(pch = sz + strcspn(sz, "\f")) != '\0')
  432. {
  433. if (pch != sz)
  434. {
  435. *pch = '\0'; /* temporarily fix to NULL */
  436. LineOut(sz, fNewLine);
  437. fNewLine = FALSE; /* Not a new line after a Form Feed */
  438. *pch = FF; /* reset to form feed */
  439. }
  440. if (fPostScript) {
  441. OutLPR ("\f\n\0", 0);
  442. } else {
  443. AdvancePage();
  444. }
  445. sz = pch + 1; /* point to first char after form feed */
  446. }
  447. if (fNewLine)
  448. iLine++;
  449. /* if the current line is beyond end of page, advance to next page */
  450. if (rowLine == rowPage)
  451. AdvancePage();
  452. fInit = FALSE;
  453. if (fNewLine && fNumber) {
  454. char szLN[cchLNMax + 1];
  455. sprintf(szLN, LINUMFORMAT, iLine);
  456. if (fPostScript) {
  457. OutLPR (szLN, 0);
  458. } else {
  459. WriteSzCoord(szLN, rowLine, ColBeginIcol(iPage % cCol,colWidth)+colGutter);
  460. }
  461. }
  462. XoutNonPrintSz(sz);
  463. /* if the line can fit, drop it in */
  464. if (strlen(sz) <= (unsigned int)(colWidth - colText))
  465. if (fPostScript) {
  466. OutLPR (sz, 0);
  467. OutLPR ("\n\000",0);
  468. } else
  469. WriteSzCoord(sz, rowLine++, ColBeginIcol(iPage % cCol,colWidth) + colText);
  470. else
  471. {
  472. /* drop in the first part and call LineOut for the remainder */
  473. char ch = sz[colWidth - colText];
  474. sz[colWidth - colText] = '\0';
  475. if (fPostScript) {
  476. OutLPR (sz, 0);
  477. OutLPR ("\n\000",0);
  478. /*WriteSzCoord(sz, rowLine++, ColBeginIcol(0, colWidth) + colText);*/
  479. } else
  480. WriteSzCoord(sz, rowLine++, ColBeginIcol(iPage % cCol,colWidth) + colText);
  481. sz[colWidth - colText] = ch;
  482. LineOut(sz + colWidth - colText, FALSE );
  483. }
  484. }
  485. void RawOut(szBuf, cb)
  486. /* print line of raw output */
  487. char * szBuf;
  488. int cb;
  489. {
  490. fPageTop = (szBuf[cb - 1] == FF);
  491. OutLPR(szBuf, cb);
  492. }
  493. BOOL FilenamX(szSrc, szDst)
  494. /* copy a filename.ext part from source to dest if present.
  495. return true if one is found
  496. */
  497. char *szSrc, *szDst;
  498. {
  499. #define szSeps "\\/:"
  500. register char *p, *p1;
  501. p = szSrc-1;
  502. while (*(p += 1+strcspn(p1=p+1, szSeps)) != '\0')
  503. ;
  504. /* p1 points after last / or at bos */
  505. strcpy(szDst, p1);
  506. return strlen(szDst) != 0;
  507. }
  508. int
  509. FileOut(szGiven)
  510. /* FileOut - print out an entire file.
  511. *
  512. * szGiven name of file to display.
  513. */
  514. char *szGiven;
  515. {
  516. FILE *pfile;
  517. int cDots = 0;
  518. long lcbStartLPR = 0l;
  519. char rgbLine[cchLineMax];
  520. char szFBase[MAX_PATH];
  521. char rgchBuf[2];
  522. /* open/secure input file */
  523. if (!*szGiven || !strcmp(szGiven, "-"))
  524. {
  525. pfile = stdin;
  526. strcpy(szFFile, szBanner ? szBanner : "<stdin>");
  527. strcpy(szFBase, szFFile);
  528. szFTime[0] = '\0';
  529. szGiven = NULL;
  530. }
  531. else if ((pfile = fopen(szGiven, szROBin)) != NULL)
  532. {
  533. struct _stat st;
  534. /* The file has been opened, now lets construct a string that
  535. * tells us exactly what we opened...
  536. */
  537. rootpath (szGiven, szFFile);
  538. _strupr(szFFile);
  539. FilenamX(szGiven, szFBase);
  540. if (_stat(szGiven, &st) == -1)
  541. Fatal("file status not obtainable : [%s]", szGiven, NULL);
  542. strcpy(szFTime, ctime(&st.st_mtime));
  543. *(szFTime + strlen(szFTime) - 1) = '\0';
  544. }
  545. else
  546. {
  547. Error("error opening input file %s", szGiven);
  548. return(FALSE);
  549. }
  550. /* need to get user name to be printed in lower left corner of each */
  551. /* page and on banner. */
  552. QueryUserName(szUsr);
  553. if (!fSilent) { // Print progress indicator
  554. fprintf(stderr, "PRINTING %s ", szFBase);
  555. }
  556. /* check to see if user forgot -r flag and this is a binary file */
  557. if (!fRaw && pfile != stdin)
  558. {
  559. fread((char *)rgchBuf, sizeof(char), 2, pfile);
  560. if (rgchBuf[0] == ESC && strchr("&(*E", rgchBuf[1]) != 0)
  561. {
  562. fprintf(stderr, "ppr: warning: file is binary; setting raw mode flag");
  563. fRaw = TRUE;
  564. }
  565. if (fseek(pfile, 0L, SEEK_SET) == -1)
  566. fprintf(stderr, "ppr: seek failed"); /* reposition the file pointer to start of file */
  567. }
  568. if (fPostScript) {
  569. if (!fFirstFile) {
  570. OutLPR ("\034\n\000", 0); /* File Separator */
  571. if (cBanner < 0) /* we at least need to set up the file stuff */
  572. BannerSz (szBanner ? szBanner : szFBase, 0);
  573. }
  574. }
  575. /* print banner(s) if any */
  576. if (cBanner > 0)
  577. BannerSz(szBanner ? szBanner : szFBase, cBanner);
  578. else if (cBanner < 0 && fFirstFile)
  579. BannerSz(szBanner ? szBanner : szFBase, -cBanner);
  580. else if (cBanner==0 && fPostScript)
  581. BannerSz(szBanner ? szBanner : szFBase, 0);
  582. fFirstFile = FALSE;
  583. /* always start contents of file at top of page */
  584. if (!fPageTop)
  585. {
  586. if (!fPostScript)
  587. OutLPR(fPostScript ? "showpage\n" : "\r\f", 0);
  588. fPageTop = TRUE;
  589. }
  590. if (fLaser)
  591. {
  592. /* start output mode for laserjet */
  593. if (fVDuplex || fHDuplex)
  594. /* always start output on front page */
  595. OutLPR(SELECTFRONTPAGE,0);
  596. if (fPortrait)
  597. OutLPR(BEGINPORTRAIT, 0);
  598. else
  599. OutLPR(aszSymSet[usSymSet], 0);
  600. }
  601. if (fPostScript) {
  602. OutLPR (fPortrait ? (fPCondensed ? "QuadPage\n" : "Portrait\n") : "Landscape\n", 0);
  603. OutLPR ("PrintFile\n", 0);
  604. }
  605. /* for PostScript we start the mode before each page */
  606. lcbStartLPR = lcbOutLPR;
  607. cDots = 0;
  608. if (fRaw)
  609. {
  610. int cb;
  611. /* read file and write directly to printer */
  612. while ((cb = fread(rgbLine, 1, cchLineMax, pfile)) > 0)
  613. {
  614. RawOut(rgbLine, cb);
  615. if (!fSilent && cDots < (lcbOutLPR-lcbStartLPR) / 1024L)
  616. {
  617. for (; cDots < (lcbOutLPR-lcbStartLPR) / 1024L; cDots++)
  618. fputc('.', stderr);
  619. }
  620. }
  621. }
  622. else
  623. {
  624. /* initialize file information */
  625. iLine = 0;
  626. /* initialize page information */
  627. iPage = -1;
  628. rowLine = rowPage;
  629. fInit = TRUE;
  630. /* read and process each line */
  631. while (fgetl(rgbLine, cchLineMax, pfile)) {
  632. LineOut(rgbLine, TRUE);
  633. if (!fSilent && cDots < (lcbOutLPR-lcbStartLPR) / 1024L) {
  634. for (; cDots < (lcbOutLPR-lcbStartLPR) / 1024L; cDots++) {
  635. fputc('.', stderr);
  636. }
  637. }
  638. }
  639. /* flush out remainder if any */
  640. FlushPage();
  641. }
  642. if (!fPageTop && (fForceFF || fPostScript) && (!fPostScript || !fRaw))
  643. {
  644. if (!fPostScript)
  645. OutLPR(fPostScript ? "showpage\n" : "\r\f", 0);
  646. fPageTop = TRUE;
  647. }
  648. fclose(pfile);
  649. if (!fSilent) /* finish PRINTING message with CRLF when done*/
  650. fprintf(stderr, "%dk\n", (lcbOutLPR-lcbStartLPR)/1024);
  651. if (fDelete && szGiven)
  652. {
  653. if (fSilent)
  654. _unlink(szGiven);
  655. else
  656. {
  657. fprintf(stderr, "DELETING %s...", szGiven);
  658. if (!_unlink(szGiven))
  659. fprintf(stderr, "OK\n");
  660. else
  661. fprintf(stderr, "FAILED: file not deleted\n");
  662. }
  663. }
  664. return TRUE;
  665. }