home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / pbmtoiw / part01 < prev    next >
Encoding:
Text File  |  1993-11-13  |  19.4 KB  |  741 lines

  1. Newsgroups: comp.sources.misc
  2. From: tommasso@hacktic.nl (Thomas Okken)
  3. Subject: v40i130:  pbmtoiw - convert portable bitmap to Apple Imagewriter graphics, Part01/01
  4. Message-ID: <1993Nov14.032205.1697@sparky.sterling.com>
  5. X-Md4-Signature: 4ea3c8f8cc223a7bc97eb98d9b4b504b
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Hack-Tic, networking for the masses
  8. Date: Sun, 14 Nov 1993 03:22:05 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: tommasso@hacktic.nl (Thomas Okken)
  12. Posting-number: Volume 40, Issue 130
  13. Archive-name: pbmtoiw/part01
  14. Environment: pbm
  15.  
  16. Pbmtoiw reads a portable bitmap and converts it to graphics codes for the
  17. Apple Imagewriter printer. You can use it to print a bitmap by saying
  18. "pbmtoiw picture.pbm | lpr".
  19. I tested it with an Imageriter I; I see no reason why it shouldn't work with
  20. the Imagewriter II as well.
  21.  
  22.  - Thomas.
  23. ---
  24. #! /bin/sh
  25. # This is a shell archive.  Remove anything before this line, then feed it
  26. # into a shell via "sh file" or similar.  To overwrite existing files,
  27. # type "sh file -c".
  28. # Contents:  README iw.setup pbmtoiw.1 pbmtoiw.c
  29. # Wrapped by kent@sparky on Sat Nov 13 21:19:44 1993
  30. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
  31. echo If this archive is complete, you will see the following message:
  32. echo '          "shar: End of archive 1 (of 1)."'
  33. if test -f 'README' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'README'\"
  35. else
  36.   echo shar: Extracting \"'README'\" \(991 characters\)
  37.   sed "s/^X//" >'README' <<'END_OF_FILE'
  38. XPbmtoiw reads a portable bitmap and converts it to graphics codes for the
  39. XApple Imagewriter printer. You can use it to print a bitmap by saying
  40. X"pbmtoiw picture.pbm | lpr".
  41. X
  42. XBuild/install instructions:
  43. X* If you don't like "/usr/local/lib/iw.setup" as the configuration file,
  44. X  change the #define in pbmtoiw.c.
  45. X* Compile pbmtoiw.c: "cc -o pbmtoiw pbmtoiw.c". Any C compiler should work,
  46. X  ANSI is not required. Optimize to taste.
  47. X* Put the executable and the manpage in useful places. "/usr/bin" and
  48. X  "/usr/man/man1" would be obvious choices on most systems.
  49. X* Change the configuration file to match your preferences. The manpage tells
  50. X  you how. The default file supplied here is set for 12" paper, 1" of tear-off
  51. X  margin around the paper, and don't leave tear-off margin between vertically
  52. X  adjacent pages (i.e., join pages = 1).
  53. X  Put the configuration file where the #define (from the first step) says
  54. X  it is.
  55. X
  56. XWritten by Thomas Okken (thomas@animal.hobby.nl or tommasso@hacktic.nl).
  57. END_OF_FILE
  58.   if test 991 -ne `wc -c <'README'`; then
  59.     echo shar: \"'README'\" unpacked with wrong size!
  60.   fi
  61.   # end of 'README'
  62. fi
  63. if test -f 'iw.setup' -a "${1}" != "-c" ; then 
  64.   echo shar: Will not clobber existing file \"'iw.setup'\"
  65. else
  66.   echo shar: Extracting \"'iw.setup'\" \(9 characters\)
  67.   sed "s/^X//" >'iw.setup' <<'END_OF_FILE'
  68. X864 72 1
  69. END_OF_FILE
  70.   if test 9 -ne `wc -c <'iw.setup'`; then
  71.     echo shar: \"'iw.setup'\" unpacked with wrong size!
  72.   fi
  73.   # end of 'iw.setup'
  74. fi
  75. if test -f 'pbmtoiw.1' -a "${1}" != "-c" ; then 
  76.   echo shar: Will not clobber existing file \"'pbmtoiw.1'\"
  77. else
  78.   echo shar: Extracting \"'pbmtoiw.1'\" \(1514 characters\)
  79.   sed "s/^X//" >'pbmtoiw.1' <<'END_OF_FILE'
  80. X.TH pbmtoiw 1 "11 November 1993"
  81. X.SH NAME
  82. Xpbmtoiw - convert a portable bitmap into Apple Imagewriter graphics
  83. X.SH SYNOPSIS
  84. X.B pbmtoiw
  85. X.RI [-< hres >x< vres >]
  86. X.RI [ pbmfile ]
  87. X.SH DESCRIPTION
  88. XReads a portable bitmap as input.
  89. XProduces Apple Imagewriter graphics escape sequences as output.
  90. X.PP
  91. XNote that there is no iwtopbm tool - this transformation is one way.
  92. X.SH OPTIONS
  93. X.TP
  94. X.RI -< hres >x< vres >
  95. XSpecifies the horizontal and vertical resolutions at which to print, in
  96. Xdpi. Possible values for
  97. X.I hres
  98. Xare 72, 80, 96, 107, 120, 136, 144 and 160; for
  99. X.I vres
  100. Xyou can choose between 72 (non-interleaved) and 144 (interleaved).
  101. XThe default is hres = vres = 72 dpi.
  102. X.SH CONFIGURATION
  103. XSince paper sizes are not the same everywhere,
  104. X.B pbmtoiw
  105. Xneeds to know what paper size you actually use. It gets this information
  106. Xfrom the
  107. X.B iw.setup
  108. Xfile. This file contains one line of text, containing three numbers.
  109. XThe first is the total page height, from perforation to perforation. The
  110. Xsecond is the amount of space to be left blank around the perforation.
  111. XThe third is a boolean, specifying whether vertically adjacent pages
  112. Xshould be printed as one, across the perforation: 0 = don't join pages,
  113. X1 = join pages.
  114. X.PP
  115. XThe page height and the amount of space around the perforation are specified
  116. Xin units of 1/72".
  117. X.SH FILES
  118. X.PD 0
  119. X.TP 20
  120. X.B /usr/local/lib/iw.setup
  121. Xpaper geometry configuration file
  122. X
  123. X.SH "SEE ALSO"
  124. X.BR pbm (5)
  125. X
  126. X.SH AUTHOR
  127. XCopyright (C) 1993 by Thomas Okken (thomas@animal.hobby.nl or
  128. Xtommasso@hacktic.nl).
  129. END_OF_FILE
  130.   if test 1514 -ne `wc -c <'pbmtoiw.1'`; then
  131.     echo shar: \"'pbmtoiw.1'\" unpacked with wrong size!
  132.   fi
  133.   # end of 'pbmtoiw.1'
  134. fi
  135. if test -f 'pbmtoiw.c' -a "${1}" != "-c" ; then 
  136.   echo shar: Will not clobber existing file \"'pbmtoiw.c'\"
  137. else
  138.   echo shar: Extracting \"'pbmtoiw.c'\" \(13607 characters\)
  139.   sed "s/^X//" >'pbmtoiw.c' <<'END_OF_FILE'
  140. X/* pbmtoiw -- Convert a portable bitmap into Apple Imagewriter printer
  141. X          graphics. Use: "pbmtoiw [-<hres>x<vres>] [pbmfile]". Hres is one
  142. X          of 72, 80, 96, 107, 120, 136, 144 or 160; vres is 72 or 144. The
  143. X          default is "-72x72". If the pbmfile argument is absent, pbmtoiw
  144. X          reads standard input. The Imagewriter graphics are always sent to
  145. X          standard output. */
  146. X
  147. X#include <stdio.h>
  148. X#include <ctype.h>
  149. X#include <malloc.h>
  150. X
  151. X/* -------------------------------------------------------------------------
  152. X   Some miscellaneous defines
  153. X   ------------------------------------------------------------------------- */
  154. X
  155. X#define SETUP_FILE "/usr/local/lib/iw.setup"
  156. X#define FIELDLENGTH 10
  157. X#define FALSE 0
  158. X#define TRUE 1
  159. X#define PBM_ASCII 0
  160. X#define PBM_RAW 1
  161. X
  162. X/* -------------------------------------------------------------------------
  163. X   These globals are initialized by read_setup_file()
  164. X   ------------------------------------------------------------------------- */
  165. X
  166. Xint paper_height, tearoff_margin, join_pages;
  167. X
  168. X/* -------------------------------------------------------------------------
  169. X   These globals are initialized by read_command_line()
  170. X   ------------------------------------------------------------------------- */
  171. X
  172. XFILE *input_file;
  173. Xint pix_per_line, interleaved;
  174. Xchar esc_char;
  175. X
  176. X/* -------------------------------------------------------------------------
  177. X   These globals are used to parse the "-<hres>x<vres>" option
  178. X   ------------------------------------------------------------------------- */
  179. X
  180. X#define NUM_RESOLUTIONS 16
  181. X#define MAX_PIX_PER_LINE 1280
  182. X
  183. Xchar *RES_OPTION[] =
  184. X{
  185. X    "72x72", "80x72", "96x72", "107x72", "120x72", "136x72", "144x72",
  186. X    "160x72", "72x144", "80x144", "96x144", "107x144", "120x144",
  187. X    "136x144", "144x144", "160x144"
  188. X};
  189. X
  190. Xint PIX_PER_LINE[] =
  191. X{
  192. X    576, 640, 768, 856, 960, 1088, 1152, 1280,
  193. X    576, 640, 768, 856, 960, 1088, 1152, 1280
  194. X};
  195. X
  196. Xint INTERLEAVED[] =
  197. X{
  198. X    FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
  199. X    TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE
  200. X};
  201. X
  202. Xchar ESC_CHAR[] = "nNEeqQpPnNEeqQpP";
  203. X
  204. X/* -------------------------------------------------------------------------
  205. X   Other globals
  206. X   ------------------------------------------------------------------------- */
  207. X
  208. Xint image_type, image_width, image_height, original_height, bytes_per_line;
  209. Xunsigned char *bitmap;
  210. Xint delayed_feed = 0;
  211. X
  212. X
  213. X/* -------------------------------------------------------------------------
  214. X   Read paper setup parameters from file
  215. X   ------------------------------------------------------------------------- */
  216. X
  217. Xvoid read_setup_file()
  218. X{
  219. X    FILE *setup_file;
  220. X    int n;
  221. X
  222. X    if ((setup_file = fopen(SETUP_FILE, "r")) == NULL)
  223. X    {
  224. X        fprintf(stderr, "pbmtoiw: can't open %s\n", SETUP_FILE);
  225. X        exit(1);
  226. X    }
  227. X    n = fscanf(setup_file, "%d %d %d", &paper_height, &tearoff_margin,
  228. X                                &join_pages);
  229. X    fclose(setup_file);
  230. X    if (n != 3)
  231. X    {
  232. X        fprintf(stderr, "pbmtoiw: error reading %s\n", SETUP_FILE);
  233. X        exit(1);
  234. X    }
  235. X}
  236. X
  237. X/* -------------------------------------------------------------------------
  238. X   Free education
  239. X   ------------------------------------------------------------------------- */
  240. X
  241. Xvoid syntax_abort()
  242. X{
  243. X    fputs("usage: pbmtoiw [-<hres>x<vres>] [pbmfile]\n", stderr);
  244. X    fputs("       hres = 72, 80, 96, 107, 120, 136, 144 or 160\n", stderr);
  245. X    fputs("       vres = 72 or 144\n", stderr);
  246. X    fputs("       default: hres = vres = 72\n", stderr);
  247. X    exit(1);
  248. X}
  249. X
  250. X/* -------------------------------------------------------------------------
  251. X   Parse command line arguments
  252. X   ------------------------------------------------------------------------- */
  253. X
  254. Xvoid read_command_line(argc, argv)
  255. X    int argc;
  256. X    char *argv[];
  257. X{
  258. X    int i, res_opt = FALSE, res_index = 0, file_arg = 0;
  259. X
  260. X    for (i = 1; i < argc; i++)
  261. X        if (argv[i][0] == '-')
  262. X        {
  263. X            if (res_opt)
  264. X                syntax_abort();
  265. X            res_index = 0;
  266. X            while (res_index < NUM_RESOLUTIONS &&
  267. X                strcmp(argv[i] + 1, RES_OPTION[res_index]))
  268. X                res_index++;
  269. X            if (res_index == NUM_RESOLUTIONS)
  270. X                syntax_abort();
  271. X            res_opt = TRUE;
  272. X        }
  273. X        else
  274. X        {
  275. X            if (file_arg)
  276. X                syntax_abort();
  277. X            file_arg = i;
  278. X        }
  279. X
  280. X    pix_per_line = PIX_PER_LINE[res_index];
  281. X    interleaved = INTERLEAVED[res_index];
  282. X    esc_char = ESC_CHAR[res_index];
  283. X
  284. X    if (file_arg)
  285. X    {
  286. X        input_file = fopen(argv[file_arg], "r");
  287. X        if (input_file == NULL)
  288. X        {
  289. X            fprintf(stderr, "pbmtoiw: can't open %s\n",
  290. X                            argv[file_arg]);
  291. X            exit(1);
  292. X        }
  293. X    }
  294. X    else
  295. X        input_file = stdin;
  296. X}
  297. X
  298. X/* -------------------------------------------------------------------------
  299. X   Read a character from the PBM stream, skipping comments
  300. X   ------------------------------------------------------------------------- */
  301. X
  302. Xint get_a_char()
  303. X{
  304. X    int c, comment = FALSE;
  305. X
  306. X    do
  307. X    {
  308. X        if ((c = getc(input_file)) == EOF)
  309. X        {
  310. X            fputs("pbmtoiw: unexpected end of file\n", stderr);
  311. X            exit(1);
  312. X        }
  313. X        if (c == '#')
  314. X            comment = TRUE;
  315. X        else if (c == '\n' || c == '\r')
  316. X            comment = FALSE;
  317. X    }
  318. X    while (comment);
  319. X    return c;
  320. X}
  321. X
  322. X/* -------------------------------------------------------------------------
  323. X   Read a whitespace-delimited string from the PBM stream
  324. X   ------------------------------------------------------------------------- */
  325. X
  326. Xvoid get_a_string(s, n)
  327. X    char *s;
  328. X    int n;
  329. X{
  330. X    int pos = 0, c;
  331. X
  332. X    do
  333. X        c = get_a_char();
  334. X    while (isspace(c));
  335. X    s[pos] = c;
  336. X    do
  337. X    {
  338. X        c = get_a_char();
  339. X        if (pos < n - 1)
  340. X            s[++pos] = c;
  341. X    }
  342. X    while (!isspace(c));
  343. X    s[pos] = 0;
  344. X}
  345. X
  346. X/* -------------------------------------------------------------------------
  347. X   Read a non-blank character from the PBM stream, skipping comments
  348. X   ------------------------------------------------------------------------- */
  349. X
  350. Xint get_a_nonspace_char()
  351. X{
  352. X    int c;
  353. X
  354. X    while (isspace(c = get_a_char()));
  355. X    return c;
  356. X}
  357. X
  358. X/* -------------------------------------------------------------------------
  359. X   Read PBM header
  360. X   ------------------------------------------------------------------------- */
  361. X
  362. Xvoid read_header()
  363. X{
  364. X    char field[FIELDLENGTH];
  365. X
  366. X    /* Get image type */
  367. X    get_a_string(field, FIELDLENGTH);
  368. X    if (!strcmp(field, "P1"))
  369. X        image_type = PBM_ASCII;
  370. X    else if (!strcmp(field, "P4"))
  371. X        image_type = PBM_RAW;
  372. X    else
  373. X    {
  374. X        fputs("pbmtoiw: unsupported image type\n", stderr);
  375. X        exit(1);
  376. X    }
  377. X    
  378. X    /* Get image dimensions */
  379. X    get_a_string(field, FIELDLENGTH);
  380. X    image_width = atoi(field);
  381. X    get_a_string(field, FIELDLENGTH);
  382. X    original_height = atoi(field);
  383. X
  384. X    /* Vertical padding to simplify printing algorithm */
  385. X    if (interleaved)
  386. X        image_height = (original_height + 15) & -16;
  387. X    else
  388. X        image_height = (original_height + 7) & -8;
  389. X}
  390. X
  391. X/* -------------------------------------------------------------------------
  392. X   Allocate memory for bitmap image
  393. X   ------------------------------------------------------------------------- */
  394. X
  395. Xvoid alloc_bitmap()
  396. X{
  397. X    int bitmap_size;
  398. X
  399. X    /* Lines are padded out to an even byte boundary */
  400. X    bytes_per_line = ((image_width + 15) >> 3) & -2;
  401. X
  402. X    /* Allocate bitmap and initialize it to all zeros */
  403. X    bitmap_size = bytes_per_line * image_height;
  404. X    bitmap = (unsigned char *) malloc(bitmap_size);
  405. X    if (bitmap == NULL)
  406. X    {
  407. X        fputs("pbmtoiw: out of memory\n", stderr);
  408. X        exit(1);
  409. X    }
  410. X    memset(bitmap, 0, bitmap_size);
  411. X}
  412. X
  413. X/* -------------------------------------------------------------------------
  414. X   Read ascii PBM file
  415. X   ------------------------------------------------------------------------- */
  416. X
  417. Xvoid read_pbm_ascii()
  418. X{
  419. X    unsigned char in_chr, cur_chr, cur_bit;
  420. X    int row, column, pos = 0;
  421. X
  422. X    pos = 0;
  423. X    for (row = 0; row < original_height; row++)
  424. X    {
  425. X        cur_bit = 0x80;
  426. X        cur_chr = 0;
  427. X        for (column = 0; column < image_width; column++)
  428. X        {
  429. X            in_chr = get_a_nonspace_char();
  430. X            if (in_chr == '1')
  431. X                cur_chr |= cur_bit;
  432. X            else if (in_chr != '0')
  433. X            {
  434. X                fputs("pbmtoiw: pbm format error\n", stderr);
  435. X                exit(1);
  436. X            }
  437. X            cur_bit >>= 1;
  438. X            if (!cur_bit)
  439. X            {
  440. X                bitmap[pos++] = cur_chr;
  441. X                cur_bit = 0x80;
  442. X                cur_chr = 0;
  443. X            }
  444. X        }
  445. X        if (cur_bit != 0x80)
  446. X            bitmap[pos++] = cur_chr;
  447. X        if (pos & 1)
  448. X            pos++;
  449. X    }
  450. X}
  451. X
  452. X/* -------------------------------------------------------------------------
  453. X   Read raw PBM file
  454. X   ------------------------------------------------------------------------- */
  455. X
  456. Xvoid read_pbm_raw()
  457. X{
  458. X    int row, count, pos = 0, bytes_per_pbm_line;
  459. X
  460. X    bytes_per_pbm_line = (image_width + 7) >> 3;
  461. X    for (row = 0; row < original_height; row++)
  462. X    {
  463. X        count = fread(&bitmap[pos], 1, bytes_per_pbm_line, input_file);
  464. X        if (count != bytes_per_pbm_line)
  465. X        {
  466. X            fputs("pbmtoiw: pbm format error\n", stderr);
  467. X            exit(1);
  468. X        }
  469. X        pos += bytes_per_line;
  470. X    }
  471. X}
  472. X
  473. X/* -------------------------------------------------------------------------
  474. X   Slurp bitmap into core
  475. X   ------------------------------------------------------------------------- */
  476. X
  477. Xvoid read_file()
  478. X{
  479. X    switch (image_type)
  480. X    {
  481. X        case PBM_ASCII:
  482. X        read_pbm_ascii();
  483. X        break;
  484. X
  485. X        case PBM_RAW:
  486. X        read_pbm_raw();
  487. X        break;
  488. X
  489. X        default:
  490. X        fputs("pbmtoiw: this can't happen\n", stderr);
  491. X        exit(1);
  492. X    }
  493. X}
  494. X
  495. X/* -------------------------------------------------------------------------
  496. X   Perform all delayed paper feed actions
  497. X   ------------------------------------------------------------------------- */
  498. X
  499. Xvoid position_paper()
  500. X{
  501. X    int a, b;
  502. X    static int lf_pitch = 0;
  503. X
  504. X    if (delayed_feed)
  505. X    {
  506. X        a = delayed_feed >> 6;
  507. X        b = delayed_feed & 63;
  508. X        if (a)
  509. X        {
  510. X            if (lf_pitch != 64)
  511. X            {
  512. X                fputs("\033T64", stdout);
  513. X                lf_pitch = 64;
  514. X            }
  515. X            while (a--)
  516. X                fputs("\r\n", stdout);
  517. X        }
  518. X        if (b)
  519. X        {
  520. X            if (lf_pitch != b)
  521. X            {
  522. X                printf("\033T%02u", b);
  523. X                lf_pitch = b;
  524. X            }
  525. X            fputs("\r\n", stdout);
  526. X        }
  527. X        delayed_feed = 0;
  528. X    }
  529. X}
  530. X
  531. X/* -------------------------------------------------------------------------
  532. X   Skip n pixels vertically
  533. X   ------------------------------------------------------------------------- */
  534. X
  535. Xvoid skip_pixels(n)
  536. X    int n;
  537. X{
  538. X    delayed_feed += interleaved ? n : n << 1;
  539. X}
  540. X
  541. X/* -------------------------------------------------------------------------
  542. X   Print one line of the bitmap (one pass of the print head)
  543. X   ------------------------------------------------------------------------- */
  544. X
  545. Xvoid print_line(x, y, width, feed)
  546. X    int x, y, width, feed;
  547. X{
  548. X    int out_pos, i, first_nonblank = -1, last_nonblank, num_chars;
  549. X    unsigned char bitmask, *in_char[8], out_char;
  550. X    unsigned char pixbuf[MAX_PIX_PER_LINE];
  551. X
  552. X    /* Find bits to print in bitmap */
  553. X    in_char[0] = bitmap + (x >> 3) + y * bytes_per_line;
  554. X    for (i = 1; i < 8; i++)
  555. X        in_char[i] = in_char[i - 1] + (bytes_per_line << interleaved);
  556. X
  557. X    /* Shuffle bits for printer output */
  558. X    bitmask = 0x80;
  559. X    for (out_pos = 0; out_pos < width; out_pos++)
  560. X    {
  561. X        out_char = 0;
  562. X        for (i = 0; i < 8; i++)
  563. X        {
  564. X            out_char >>= 1;
  565. X            if (*in_char[i] & bitmask)
  566. X                out_char |= 0x80;
  567. X        }
  568. X        pixbuf[out_pos] = out_char;
  569. X        if (out_char)
  570. X        {
  571. X            if (first_nonblank == -1)
  572. X                first_nonblank = out_pos;
  573. X            last_nonblank = out_pos;
  574. X        }
  575. X        bitmask >>= 1;
  576. X        if (!bitmask)
  577. X        {
  578. X            bitmask = 0x80;
  579. X            for (i = 0; i < 8; i++)
  580. X                in_char[i]++;
  581. X        }
  582. X    }
  583. X
  584. X    /* Now print them. If there is anything to print, that is */
  585. X    if (first_nonblank == -1)
  586. X    {
  587. X        delayed_feed += feed;
  588. X        return;
  589. X    }
  590. X    position_paper();
  591. X    if (first_nonblank)
  592. X        printf("\033F%04u", first_nonblank);
  593. X    num_chars = last_nonblank - first_nonblank + 1;
  594. X    printf("\033G%04u", num_chars);
  595. X    fwrite(&pixbuf[first_nonblank], 1, num_chars, stdout);
  596. X    delayed_feed = feed;
  597. X}
  598. X
  599. X/* -------------------------------------------------------------------------
  600. X   Print one page from the bitmap
  601. X   ------------------------------------------------------------------------- */
  602. X
  603. Xvoid print_page(x, y, width, height)
  604. X    int x, y, width, height;
  605. X{
  606. X    int cur_y;
  607. X
  608. X    /* Print lines */
  609. X    cur_y = y;
  610. X    if (interleaved)
  611. X        while (cur_y < y + height)
  612. X        {
  613. X            print_line(x, cur_y, width, 1);
  614. X            print_line(x, cur_y + 1, width, 15);
  615. X            cur_y += 16;
  616. X        }
  617. X    else
  618. X    {
  619. X        while (cur_y < y + height)
  620. X        {
  621. X            print_line(x, cur_y, width, 16);
  622. X            cur_y += 8;
  623. X        }
  624. X    }
  625. X}
  626. X
  627. X/* -------------------------------------------------------------------------
  628. X   Print the bitmap!
  629. X   ------------------------------------------------------------------------- */
  630. X
  631. Xvoid print_bitmap()
  632. X{
  633. X    int max_height, x, y, print_width, print_height;
  634. X    int image_ready, column_ready;
  635. X
  636. X    max_height = (paper_height - tearoff_margin) & -8;
  637. X    tearoff_margin = paper_height - max_height;
  638. X    if (interleaved)
  639. X    {
  640. X        paper_height <<= 1;
  641. X        tearoff_margin <<= 1;
  642. X        max_height <<= 1;
  643. X    }
  644. X    else
  645. X        fputs("\033>", stdout);
  646. X
  647. X    fputc('\033', stdout);
  648. X    fputc(esc_char, stdout);
  649. X
  650. X    x = 0;
  651. X    print_width = pix_per_line;
  652. X    image_ready = FALSE;
  653. X    while (!image_ready)
  654. X    {
  655. X        if (x + print_width >= image_width)
  656. X        {
  657. X            print_width = image_width - x;
  658. X            image_ready = TRUE;
  659. X        }
  660. X
  661. X        if (join_pages)
  662. X        {
  663. X            y = 0;
  664. X            print_page(x, y, print_width, image_height);
  665. X            skip_pixels(paper_height -
  666. X                    image_height % paper_height);
  667. X        }
  668. X        else
  669. X        {
  670. X            y = 0;
  671. X            print_height = max_height;
  672. X            column_ready = FALSE;
  673. X            while (!column_ready)
  674. X            {
  675. X                if (y + print_height >= image_height)
  676. X                {
  677. X                    print_height = image_height - y;
  678. X                    column_ready = TRUE;
  679. X                }
  680. X                print_page(x, y, print_width, print_height);
  681. X                skip_pixels(paper_height - print_height);
  682. X                y += max_height;
  683. X            }
  684. X        }
  685. X
  686. X        x += pix_per_line;
  687. X    }
  688. X    position_paper();
  689. X}
  690. X
  691. X/* -------------------------------------------------------------------------
  692. X   Final cleanup
  693. X   ------------------------------------------------------------------------- */
  694. X
  695. Xvoid cleanup()
  696. X{
  697. X    free(bitmap);
  698. X    fputs("\033c", stdout);
  699. X}
  700. X
  701. X/* -------------------------------------------------------------------------
  702. X   The Function Of Supreme Importance
  703. X   ------------------------------------------------------------------------- */
  704. X
  705. Xvoid main(argc, argv)
  706. X    int argc;
  707. X    char *argv[];
  708. X{
  709. X    read_setup_file();
  710. X    read_command_line(argc, argv);
  711. X    read_header();
  712. X    alloc_bitmap();
  713. X    read_file();
  714. X    print_bitmap();
  715. X    cleanup();
  716. X    exit(0);
  717. X}
  718. END_OF_FILE
  719.   if test 13607 -ne `wc -c <'pbmtoiw.c'`; then
  720.     echo shar: \"'pbmtoiw.c'\" unpacked with wrong size!
  721.   fi
  722.   # end of 'pbmtoiw.c'
  723. fi
  724. echo shar: End of archive 1 \(of 1\).
  725. cp /dev/null ark1isdone
  726. MISSING=""
  727. for I in 1 ; do
  728.     if test ! -f ark${I}isdone ; then
  729.     MISSING="${MISSING} ${I}"
  730.     fi
  731. done
  732. if test "${MISSING}" = "" ; then
  733.     echo You have the archive.
  734.     rm -f ark[1-9]isdone
  735. else
  736.     echo You still must unpack the following archives:
  737.     echo "        " ${MISSING}
  738. fi
  739. exit 0
  740. exit 0 # Just in case...
  741.