Date: Fri, 26 Jun 1998 21:28:39 +0200 (MET DST) From: Luigi Rizzo <luigi@labinfo.iet.unipi.it> To: current@FreeBSD.ORG Cc: itojun@itojun.org Subject: mgp patches Message-ID: <199806261928.VAA06254@labinfo.iet.unipi.it>
next in thread | raw e-mail | index | archive | help
(maybe people in -current is interested... i have Bcc-ed to
multimedia as well)
i have spent a few hours on mgp, found a few bugs, and implemented
a new feature which I find extremely useful. In a separate mail
will post some suggestions for possible extensions:
BUGS:
* the check for ".ps" in ispsfilename() looked for the last 4
char instead of 3 (fixed)
* running a process on the last page results in the process being
killed immediately. I have no idea on how to fix this.
* %tab N will likely result in a coredump if N >= MAXTAB (32)
(easy fix in grammar.y, did not bother though)
NEW FEATURE
* I have extended the "tab" attribute to define styles with names
instead of numbers, e.g.
%tab style_name center, ...
The style can be invoked by starting the line with &style_name
instead of a set of tabs. This is implemented by extending the
tab_control[] array with MAXSTYLE fields dedicated to the new styles
(max 100 currently, but it is a compile-time option that can be made
larger if necessary).
This is not as flexible as a global macro definition but I don't
know better...
Diffs attached. Itojun, do you think we can update the port or apply
the change directly to the distribution ?
cheers
luigi
diff -ubwr ../mgp-1.03a/draw.c ./draw.c
--- ../mgp-1.03a/draw.c Mon Mar 23 13:09:52 1998
+++ ./draw.c Fri Jun 26 20:41:34 1998
@@ -110,7 +110,7 @@
p++;
if (4 < p - p0 && strcasecmp(p - 4, ".eps") == 0)
return 1;
- if (3 < p - p0 && strcasecmp(p - 4, ".ps") == 0)
+ if (3 < p - p0 && strcasecmp(p - 3, ".ps") == 0)
return 1;
return 0;
}
diff -ubwr ../mgp-1.03a/globals.c ./globals.c
--- ../mgp-1.03a/globals.c Fri Feb 13 07:47:58 1998
+++ ./globals.c Fri Jun 26 13:42:34 1998
@@ -43,7 +43,7 @@
u_char *page_data[MAXPAGE][MAXLINE];
struct ctrl *page_control[MAXPAGE][MAXLINE];
struct ctrl *default_control[MAXLINE];
-struct ctrl *tab_control[MAXTAB];
+struct ctrl *tab_control[MAXTAB+MAXSTYLE];
struct ctrl *init_control[MAXLINE];
u_int mgp_flag;
diff -ubwr ../mgp-1.03a/grammar.y ./grammar.y
--- ../mgp-1.03a/grammar.y Tue Mar 24 18:07:03 1998
+++ ./grammar.y Fri Jun 26 14:18:33 1998
@@ -572,6 +572,7 @@
{ $$ = gen_icon($2, $3, $4); }
;
tabcmd: KW_TAB NUM { $$ = gen_int(CTL_TAB, $2); }
+ | KW_TAB ID { $$ = gen_str(CTL_TAB, $2); }
;
defaultcmd: KW_DEFAULT NUM
{ $$ = gen_int(CTL_DEFAULT, $2); }
diff -ubwr ../mgp-1.03a/mgp.h ./mgp.h
--- ../mgp-1.03a/mgp.h Mon Mar 23 13:29:10 1998
+++ ./mgp.h Fri Jun 26 13:42:14 1998
@@ -109,6 +109,7 @@
#define MAXDIREC 16
#define MAXARG 32
#define MAXTAB 32
+#define MAXSTYLE 100
#define SP_NONE 0
#define SP_SHRINK 1
@@ -385,7 +386,7 @@
#endif
extern struct ctrl *page_control[MAXPAGE][MAXLINE];
extern struct ctrl *default_control[MAXLINE];
-extern struct ctrl *tab_control[MAXTAB];
+extern struct ctrl *tab_control[MAXTAB+MAXSTYLE];
extern struct ctrl *init_control[MAXLINE];
extern u_int mgp_flag;
Only in .: mgp.o
Only in .: mgp2ps
diff -ubwr ../mgp-1.03a/parse.c ./parse.c
--- ../mgp-1.03a/parse.c Mon Mar 23 12:23:16 1998
+++ ./parse.c Fri Jun 26 14:21:28 1998
@@ -98,7 +98,7 @@
page_control[page][line] = NULL;
}
}
- for (line = 0; line < MAXTAB; line++) {
+ for (line = 0; line < MAXTAB + MAXSTYLE; line++) {
if (!tab_control[line])
continue;
ctlfree(tab_control[line]);
@@ -229,11 +229,27 @@
break;
case CTL_TAB:
- ch = &tab_control[root->cti_value - 1];
+ {
+ int i = root->cti_value - 1 ;
+ if ( i >= MAXTAB ) {
+ /* must be a string, find a free entry */
+ for (i = MAXTAB ; i < MAXTAB+MAXSTYLE ; i++)
+ if (tab_control[i] == NULL)
+ break;
+ if (i == MAXTAB+MAXSTYLE ) {
+ fprintf(stderr, "%s:%d: too many styles\n",
+ filename, lineno);
+ exit(-1);
+ }
+ }
+ ch = &tab_control[i];
if (*ch)
ctlappend(*ch, root->ct_next);
- else
+ else if (i< MAXTAB)
*ch = root->ct_next;
+ else
+ *ch = root; /* keep name as well */
+ }
break;
default:
@@ -547,7 +563,7 @@
}
/* CTL_PREFIX in tab_control should be CTL_TABPREFIX. */
- for (l = 0; l < MAXTAB; l++) {
+ for (l = 0; l < MAXTAB+ MAXSTYLE; l++) {
for (cp = tab_control[l]; cp; cp = cp->ct_next) {
if (cp->ct_op == CTL_PREFIX)
cp->ct_op = CTL_TABPREFIX;
@@ -882,7 +898,26 @@
ctlcopy(tab_control[tab_depth]));
}
}
+ /* special: style escape */
+ if (p && *p == '&') {
+ char *p0 = p ;
+ int i ;
+ for ( ; *p && *p >32 && *p <127; p++ ) ;
+ *p = '\0';
+ cp->ctc_value = p+1 ;
+ for (i=MAXTAB; i < MAXTAB+MAXSTYLE ; i++) {
+ if (tab_control[i] &&
+ strcmp(p0+1, tab_control[i]->cti_value)==0)
+ break ;
+ }
+ if (i == MAXTAB+MAXSTYLE)
+ fprintf(stderr, "style %s not found\n", p0+1);
+ else {
+ ctlinsert(&cp1->ct_next,
+ ctlcopy(tab_control[i]->ct_next));
+ }
+ }
}
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199806261928.VAA06254>
