home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <ctype.h>
- #include "defs.h"
-
- #define MIDX 285 /* center of output page */
- #define MIDY 396
-
- ixrect *pr;
- har *progname;
- har *filename;
- nt small, large, mail, special, nopipe;
- har *title;
-
- #ifdef STANDALONE
- ain(argc, argv, envp)
- #else
- as2lw_main(argc, argv, envp)
- #endif
- int argc;
- char **argv;
- char **envp;
- {
- int c, x = 0, y = 0, r = 0;
- register int i, j;
- double sx = 1.0, sy = 1.0, atof();
- char *hex();
- char buf1[BUFSIZ];
- FILE *pd;
-
- small = TRUE;
- large = mail = special = nopipe = FALSE;
-
- progname = strsave(argv[0]);
- parse_profile(&argc, argv, envp);
-
- title = NULL;
-
- while ((gc = getopt(argc, argv, "mslt:T")) != EOF)
- switch (gc) {
- case 'm':
- mail = TRUE;
- break;
- case 's':
- small = TRUE;
- break;
- case 'l':
- large = TRUE;
- break;
- case 't':
- title = strsave(optarg);
- break;
- case 'T':
- special = TRUE;
- nopipe = TRUE;
- break;
- case '?':
- errflag++;
- break;
- }
-
- if (errflag)
- error((char *) 0, "Usage: %s: [-s] [-l] [-m] [-t title] [-T] [infile]\n", progname);
-
- for (stream = 0; optind < argc; stream++, optind++)
- if (stream == 0 && strcmp(argv[optind], "-") != 0)
- if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
- error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
-
- if ((pr = pr_load(stdin, NULL)) == NULL)
- error(PR_IO_ERR_RASREAD);
-
- if (pr->pr_depth > 8)
- error("Cannot print images with depth greater than 8 bits");
-
- if (!nopipe) {
- if ((pd = popen(strcat("lpr -Plw -v", ((mail) ? " -m" : "")), "w")) == NULL)
- error("Cannot open pipe to lpr");
- } else
- pd = stdout;
-
- fprintf(pd, "%%!PS-Adobe-1.0\n"); /* PostScript magic strings */
- fprintf(pd, "/picstr %d string def\n", pr->pr_size.x);
-
- if (title) {
- fprintf(pd, "/Helvetica-Bold findfont\n");
- fprintf(pd, "12 scalefont setfont\n");
- fprintf(pd, "285 (%s) stringwidth pop 2 div sub 720 moveto\n", title);
- fprintf(pd, "(%s) show\n", title);
- }
- if (small || large) {
- sx = 7.91 * 300 / pr->pr_size.x;
- sy = 8.5 * 300 / pr->pr_size.y; /* avoid title area */
- if (large) {
- sx /= 2.;
- sy /= 2.;
- }
- sx = sy = (sx > sy) ? sy : sx;
- x = -sx * pr->pr_size.x * 72 / 300 / 2;
- y = -sy * pr->pr_size.y * 72 / 300 / 2;
- }
- if (special)
- fprintf(pd, " 0 0 translate\n");
- else
- fprintf(pd, "%d %d translate\n", MIDX + x, MIDY - 36 + y);
-
- fprintf(pd, "%d %d scale\n", (int) (pr->pr_size.x / 300.0 * 72.0 * sx), (int) (pr->pr_size.y / 300.0 * 72.0 * sy));
- fprintf(pd, "%d %d 8\n", pr->pr_size.x, pr->pr_size.y);
- fprintf(pd, "[ %d 0 0 -%d 0 %d ]\n", pr->pr_size.x, pr->pr_size.y, pr->pr_size.y);
- fprintf(pd, "{currentfile\npicstr readhexstring pop}\nimage\n");
-
- for (j = 0; j < pr->pr_size.y; j++)
- for (i = 0; i < pr->pr_size.x; i++) {
- if (nopipe && !(i % 40))
- fputs("\n", pd);
- fputs(hex(pr_get(pr, i, j)), pd);
- }
-
- if (!special)
- fprintf(pd, "showpage\n");
- if (!nopipe)
- pclose(pd);
- }
-
- har *
- ex(d)
- {
- static char a[10];
-
- sprintf(a, "%02x", d);
- return (a);
- }
-