ref: 3325081e41360a5dfc98ee155456d89c1e34822a
parent: a9772f9e5984dc19f9de0930c9fc74529477c70c
author: Ali Gholami Rudi <[email protected]>
date: Sat Sep 7 17:38:37 EDT 2013
roff: add -F and -M to change font and macro directories
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,9 @@
+# neatroff's default font and macro directories
+FDIR=/root/troff/home/font
+MDIR=/root/troff/home/tmac
+
CC = cc
-CFLAGS = -Wall -O2 -DTROFFROOT=\"/root/troff/home\"
+CFLAGS = -Wall -O2 "-DTROFFFDIR=\"$(FDIR)\"" "-DTROFFMDIR=\"$(MDIR)\""
LDFLAGS =
all: roff
--- a/dev.c
+++ b/dev.c
@@ -5,6 +5,7 @@
#include "roff.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 */
@@ -25,7 +26,7 @@
static void dev_prologue(void)
{
- out("x T utf\n");
+ out("x T %s\n", dev_dev);
out("x res %d %d %d\n", dev_res, dev_hor, dev_ver);
out("x init\n");
}
@@ -34,7 +35,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;
@@ -47,7 +48,7 @@
return pos;
}
-int dev_open(char *dir)
+int dev_open(char *dir, char *dev)
{
char path[PATHLEN];
char tok[ILNLEN];
@@ -54,7 +55,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] == '#') {
--- a/roff.c
+++ b/roff.c
@@ -26,30 +26,57 @@
va_end(ap);
}
+static char *usage =
+ "Usage: neatcc [options] input\n"
+ "Options:\n"
+ " -mx \tinclude macro x\n"
+ " -C \tenable compatibility mode\n"
+ " -Tdev \tset output device\n"
+ " -Fdir \tset font directory (" TROFFFDIR ")\n"
+ " -Mdir \tset macro directory (" TROFFMDIR ")\n";
+
int main(int argc, char **argv)
{
- int i;
+ char fontdir[PATHLEN] = TROFFFDIR;
+ char macrodir[PATHLEN] = TROFFMDIR;
+ char dev[PATHLEN] = "utf";
char path[PATHLEN];
+ int i;
int ret;
- dev_open(TROFFROOT "/font/devutf");
- env_init();
- tr_init();
- g_init();
for (i = 1; i < argc; i++) {
- if (argv[i][0] != '-' || !argv[i][0])
+ if (argv[i][0] != '-' || !argv[i][1])
break;
- if (argv[i][1] == 'C')
+ switch (argv[i][1]) {
+ case 'C':
n_cp = 1;
- if (argv[i][1] == 'm') {
- sprintf(path, TROFFROOT "/tmac/tmac.%s", argv[i] + 2);
+ break;
+ case 'm':
+ sprintf(path, "%s/tmac.%s", macrodir, argv[i] + 2);
in_queue(path);
+ break;
+ case 'F':
+ strcpy(fontdir, argv[i][2] ? argv[i] + 2 : argv[++i]);
+ break;
+ case 'M':
+ strcpy(macrodir, argv[i][2] ? argv[i] + 2 : argv[++i]);
+ break;
+ case 'T':
+ strcpy(dev, argv[i][2] ? argv[i] + 2 : argv[++i]);
+ break;
+ default:
+ printf("%s", usage);
+ return 0;
}
}
+ dev_open(fontdir, dev);
+ env_init();
+ tr_init();
+ g_init();
if (i == argc)
in_queue(NULL); /* reading from standard input */
for (; i < argc; i++)
in_queue(!strcmp("-", argv[i]) ? NULL : argv[i]);
- str_set(REG('.', 'P'), TROFFROOT);
+ str_set(REG('.', 'P'), macrodir);
out("s%d\n", n_s);
out("f%d\n", n_f);
ret = render();
--- a/roff.h
+++ b/roff.h
@@ -124,7 +124,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);
int dev_pos(char *id);