summaryrefslogtreecommitdiff
path: root/sys/src/cmd/postscript/p9bitpost/p9bitpost.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/postscript/p9bitpost/p9bitpost.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/postscript/p9bitpost/p9bitpost.c')
-rwxr-xr-xsys/src/cmd/postscript/p9bitpost/p9bitpost.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/sys/src/cmd/postscript/p9bitpost/p9bitpost.c b/sys/src/cmd/postscript/p9bitpost/p9bitpost.c
new file mode 100755
index 000000000..2816c5139
--- /dev/null
+++ b/sys/src/cmd/postscript/p9bitpost/p9bitpost.c
@@ -0,0 +1,105 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <memdraw.h>
+#include "pslib.h"
+
+#define HDLEN 60
+
+int dpi = -1;
+int debug = 0;
+int landscape = 0;
+char *file = "<stdin>";
+
+int paperlength = 11*72;
+int paperwidth = 612; /* 8.5*72 */
+
+void
+error(char *s)
+{
+ fprint(2, "p9bitpost: can't %s file %s: %r\n", s, file);
+ exits("error");
+}
+
+void
+main(int argc, char *argv[]) {
+ int i, fd = 0;
+ double xmag = 1.0, ymag = 1.0;
+ char *optstr, *Patch;
+ Memimage *memimage;
+
+ Patch = nil;
+ for (i=1; i<argc; i++) {
+ if (*argv[i] != '-') break;
+ switch(argv[i][1]) {
+ case 'b':
+ if (argv[i][2] == '\0')
+ dpi = atoi(argv[++i]);
+ else
+ dpi = atoi(&(argv[i][2]));
+ break;
+ case 'd':
+ debug = 1;
+ break;
+ case 'm':
+ if (argv[i][2] == '\0')
+ optstr = argv[++i];
+ else
+ optstr = &(argv[i][2]);
+ if ((optstr=strtok(optstr, " ,")) != 0)
+ xmag = ymag = atof(optstr);
+ if ((optstr=strtok(0, " ,")) != 0)
+ ymag = atof(optstr);
+ break;
+ case 'L':
+ landscape = 1;
+ break;
+ case 'P':
+ if (argv[i][2] == '\0')
+ Patch = argv[++i];
+ else
+ Patch = &(argv[i][2]);
+ break;
+ case 'p':
+ optstr = argv[++i];
+ if(optstr == nil)
+ goto Usage;
+ paperlength = 72*atof(optstr);
+ optstr = argv[++i];
+ if(optstr == nil)
+ goto Usage;
+ paperwidth = 72*atof(optstr);
+ if(paperlength < 72 || paperwidth < 72)
+ goto Usage;
+ break;
+ default:
+ Usage:
+ fprint(2, "usage: %s [-b dpi] [-m magnification] [-L] [-P postscript_patch_string] [-p paperlength paperwidth (in inches)] inputfile\n", argv[0]);
+ exits("usage");
+ }
+ }
+
+ if (i < argc) {
+ file = argv[i];
+ fd = open(file, OREAD);
+ if (fd < 0)
+ error("open");
+ }
+
+ memimageinit();
+ memimage = readmemimage(fd);
+ if(memimage == nil)
+ error("alloc memory for");
+
+ psinit(0, 0);
+ if(xmag != 1.0)
+ psopt("xmagnification", &xmag);
+ if(ymag != 1.0)
+ psopt("ymagnification", &ymag);
+ if(landscape)
+ psopt("landscape", &landscape);
+ if(Patch)
+ psopt("Patch", &Patch);
+ image2psfile(1, memimage, dpi);
+ exits("");
+}