shithub: neatpost

Download patch

ref: f2bd9dc3bbe0453855d163df286e5a5d93f6ec18
parent: 04e573dc6d38048eb0eaf997841f09f8118e1687
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Sep 7 17:23:49 EDT 2013

post: add -F to override troff device directory

--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,8 @@
+# neatpost's default font directory
+FDIR=/root/troff/home/font
+
 CC = cc
-CFLAGS = -Wall -O2 -DTROFFROOT=\"/root/troff/home\"
+CFLAGS = -Wall -O2 "-DTROFFFDIR=\"$(FDIR)\""
 LDFLAGS =
 
 all: post
--- a/dev.c
+++ b/dev.c
@@ -5,6 +5,7 @@
 #include "post.h"
 
 char dev_dir[PATHLEN];	/* device directory */
+char dev_dev[PATHLEN];	/* output device name */
 int dev_res;		/* device resolution */
 int dev_uwid;		/* device unitwidth */
 int dev_hor;		/* minimum horizontal movement */
@@ -27,7 +28,7 @@
 {
 	char path[PATHLEN];
 	struct font *fn;
-	sprintf(path, "%s/%s", dev_dir, name);
+	sprintf(path, "%s/dev%s/%s", dev_dir, dev_dev, name);
 	fn = font_open(path);
 	if (!fn)
 		return -1;
@@ -39,7 +40,7 @@
 	return pos;
 }
 
-int dev_open(char *dir)
+int dev_open(char *dir, char *dev)
 {
 	char path[PATHLEN];
 	char tok[ILNLEN];
@@ -46,7 +47,8 @@
 	int i;
 	FILE *desc;
 	strcpy(dev_dir, dir);
-	sprintf(path, "%s/DESC", dir);
+	strcpy(dev_dev, dev);
+	sprintf(path, "%s/dev%s/DESC", dir, dev);
 	desc = fopen(path, "r");
 	while (fscanf(desc, "%s", tok) == 1) {
 		if (tok[0] == '#') {
@@ -82,9 +84,9 @@
 			fscanf(desc, "%d", &dev_ver);
 			continue;
 		}
-		if (!strcmp("charset", tok)) {
+		if (!strcmp("charset", tok))
 			break;
-		}
+		skipline(desc);
 	}
 	fclose(desc);
 	return 0;
--- a/post.c
+++ b/post.c
@@ -211,27 +211,28 @@
 		drawmend(arg);
 }
 
-static char devpath[PATHLEN] = "devutf";
+static char devpath[PATHLEN] = TROFFFDIR;
+static char devname[PATHLEN] = "utf";
 
 static void postx(void)
 {
 	char cmd[128];
-	char dev[128];
+	char font[128];
 	int pos;
 	nextword(cmd);
 	switch (cmd[0]) {
 	case 'f':
 		pos = nextnum();
-		nextword(dev);
-		dev_mnt(pos, dev, dev);
+		nextword(font);
+		dev_mnt(pos, font, font);
 		outmnt(pos);
 		break;
 	case 'i':
-		dev_open(devpath);
+		dev_open(devpath, devname);
+		ps_header();
 		break;
 	case 'T':
-		nextword(dev);
-		sprintf(devpath, "%s/font/dev%s", TROFFROOT, dev);
+		nextword(devname);
 		break;
 	case 's':
 		break;
@@ -322,9 +323,12 @@
 		ps_pageend(o_pg);
 }
 
-int main(void)
+int main(int argc, char *argv[])
 {
-	ps_header();
+	int i;
+	for (i = 1; i < argc; i++)
+		if (argv[i][0] == '-' && argv[i][1] == 'F')
+			strcpy(devpath, argv[i][2] ? argv[i] + 2 : argv[++i]);
 	post();
 	ps_trailer(o_pg, o_fonts);
 	return 0;
--- a/post.h
+++ b/post.h
@@ -53,7 +53,7 @@
 };
 
 /* output device functions */
-int dev_open(char *path);
+int dev_open(char *dir, char *dev);
 void dev_close(void);
 int dev_mnt(int pos, char *id, char *name);
 struct font *dev_font(int fn);