Skip to content

Commit 50893f2

Browse files
committed
post: allow passing device-dependent variables with -d option
1 parent 7651b53 commit 50893f2

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

post.c

+30-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* NEATPOST: NEATROFF'S POSTSCRIPT/PDF POSTPROCESSOR
33
*
4-
* Copyright (C) 2013-2020 Ali Gholami Rudi <ali at rudi dot ir>
4+
* Copyright (C) 2013-2025 Ali Gholami Rudi <ali at rudi dot ir>
55
*
66
* Permission to use, copy, modify, and/or distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -612,6 +612,15 @@ char *pdftext_static(char *s)
612612
return buf;
613613
}
614614

615+
static void cmdset(char *arg)
616+
{
617+
char *eq = strchr(arg, '=');
618+
if (eq != NULL) {
619+
*eq = '\0';
620+
outset(arg, eq + 1);
621+
}
622+
}
623+
615624
static char *usage =
616625
"Usage: neatpost [options] <input >output\n"
617626
"Options:\n"
@@ -620,28 +629,39 @@ static char *usage =
620629
" -t title\tspecify document title\n"
621630
" -w lwid \tdrawing line thickness in thousandths of an em (40)\n"
622631
" -l \tlandscape mode\n"
623-
" -n \talways draw glyphs by name (ps glyphshow)\n";
632+
" -n \talways draw glyphs by name (ps glyphshow)\n"
633+
" -d x=v \tset device-specific variables\n";
624634

625635
int main(int argc, char *argv[])
626636
{
627637
int i;
628638
int landscape = 0;
629639
if (getenv("NEATROFF_F") != NULL)
630640
snprintf(postdir, sizeof(postdir), "%s", getenv("NEATROFF_F"));
631-
for (i = 1; i < argc; i++) {
632-
if (argv[i][0] == '-' && argv[i][1] == 'F') {
641+
for (i = 1; i < argc && argv[i][0] == '-'; i++) {
642+
switch (argv[i][1]) {
643+
case 'F':
633644
strcpy(postdir, argv[i][2] ? argv[i] + 2 : argv[++i]);
634-
} else if (argv[i][0] == '-' && argv[i][1] == 'p') {
645+
break;
646+
case 'p':
635647
setpagesize(argv[i][2] ? argv[i] + 2 : argv[++i]);
636-
} else if (argv[i][0] == '-' && argv[i][1] == 'w') {
648+
break;
649+
case 'w':
637650
ps_linewidth = atoi(argv[i][2] ? argv[i] + 2 : argv[++i]);
638-
} else if (argv[i][0] == '-' && argv[i][1] == 'n') {
651+
break;
652+
case 'n':
639653
outgname(1);
640-
} else if (argv[i][0] == '-' && argv[i][1] == 't') {
654+
break;
655+
case 't':
641656
ps_title = argv[i][2] ? argv[i] + 2 : argv[++i];
642-
} else if (argv[i][0] == '-' && argv[i][1] == 'l') {
657+
break;
658+
case 'l':
643659
landscape = 1;
644-
} else {
660+
break;
661+
case 'd':
662+
cmdset(argv[i][2] ? argv[i] + 2 : argv[++i]);
663+
break;
664+
default:
645665
fprintf(stderr, "%s", usage);
646666
return 1;
647667
}

0 commit comments

Comments
 (0)