[net.sources] subfont - substitute fonts in troff

colonel@sunybcs.UUCP (Col. G. L. Sicherman) (11/04/86)

Did you ever try to ditroff a document from another installation, only
to have ditroff complain about non-existent fonts?  This is a little
lex program to make substitutions on font names.
----- CUT HERE -----
# This is a shell archive.  Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file".  (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# subfont.1 subfont.l

echo x - subfont.1
sed -e 's/^X//' > "subfont.1" << '//E*O*F subfont.1//'
X.TH SUBFONT 1 "31 October 1986" "" "Local UNIX Programmer's Manual"
X.SH NAME
Xsubfont \- substitute fonts in troff source
X.SH SYNOPSIS
X.B subfont
Xoldfont newfont [ oldfont newfont ... ]
X.SH DESCRIPTION
X.I Subfont
Xalters the names of fonts in
X.IR troff (1)
Xsource code.
XIt knows that the
X.B \ef
Xcommand requires a left parenthesis with two-character font names.
X.PP
X.I Subfont is
Xintended mainly for converting unavailable fonts in imported documents.
X.SH DIAGNOSTICS
XComplains if the number of arguments is odd, if an argument has
Xmore than two characters,
Xor if an
X.I oldfont
Xargument appears more than once.
X.SH "SEE ALSO"
Xtroff(1), ditroff(1)
X.SH BUGS
X.I Subfont
Xis no expert at
X.I troff.
XIn particular, it does not touch fonts specified by strings
Xor macro arguments,
Xnor does it understand copy mode.
XNo substitution is performed on
Xfreak commands like
X.BR \e\efI .
X.PP
X.I Subfont
Xought to recognize
X.IR tbl (1)
Xand
X.IR eqn (1)
Xfont specifiers, but it does not.
X.SH AUTHOR
XCol. Sicherman
//E*O*F subfont.1//

echo x - subfont.l
sed -e 's/^X//' > "subfont.l" << '//E*O*F subfont.l//'
XW	[ \t]
X%%
X^\.{W}*ft{W}.*$	subst(3);
X^\.{W}*fp{W}.*$	subst(4);
X\\\\		ECHO;
X\\f[^\\]	subst(1);
X\\f\([^\\].	subst(2);
X%%
X/*
X *	subfont - substitute fonts in troff source.
X *	the Colonel.  31 Oct 1986.
X */
X#define	WHITE	" \t"
X#define SKIPSP(s) {while (NULL!=index(WHITE,*s)) s++;}
X#define FINDSP(s) {while (*s && NULL==index(WHITE,*s)) s++;}
X
Xchar	*progname, **fontv;
Xchar	*strcpy(), *index();
Xint	fontc;
X
Xmain(argc,argv)
Xint	argc;
Xchar	**argv;
X{
X	progname = *argv;
X/*
X *	Hook for flags.
X */
X	while (--argc) {
X		if ('-'==**++argv) switch(*++*argv) {
X		default:
X			argbomb();
X		}
X		else break;
X	}
X	if ((fontc=argc)%2) argbomb();
X	fontv=argv;
X	argcheck();
X	while (yylex()) ;
X	exit(0);
X}
X
Xargcheck()
X{
X	int i, j;
X	for (i=0; i<fontc; i+=2) {
X		if (strlen(fontv[i])>2) longarg(fontv[i]);
X		if (strlen(fontv[i+1])>2) longarg(fontv[i+1]);
X		for (j=i+2; j<fontc; j+=2)
X			if (!strcmp(fontv[i],fontv[j])) duplarg(fontv[i]);
X	}
X}
X
Xlongarg(s)
Xchar *s;
X{
X	fprintf(stderr,"%s: bad font name \"%s\"\n",progname,s);
X	exit(1);
X}
X
Xduplarg(s)
Xchar *s;
X{
X	fprintf(stderr,"%s: duplicate font name \"%s\"\n",progname,s);
X	exit(1);
X}
X
Xsubst(n)
Xint n;
X{
X	char *p, *q;
X	char *rindex(), *find();
X	char hold[3];
X	int fi;
X	switch(n) {
X	case 3:
X	case 4:
X		p=yytext+1;
X		SKIPSP(p);
X		FINDSP(p);	/* skip the command */
X		SKIPSP(p);
X		if (n==4) {
X			FINDSP(p);	/* skip the font pos */
X			SKIPSP(p);
X		}
X		q=p;
X		FINDSP(q);	/* skip the font */
X		break;
X	default:
X		p=yytext+yyleng-n;
X		q=yytext+yyleng;
X	}
X	strncpy(hold,p,q-p);
X	hold[q-p]='\0';		/* make sure it ends */
X	for (fi=0; fi<fontc; fi+=2)
X	if (!strcmp(hold,fontv[fi])) {
X		p[0]='\0';
X/*
X *	Clobber left parenthesis if necessary.
X */
X		if (n==2 && strlen(fontv[fi+1])==1) p[-1]='\0';
X		fputs(yytext,stdout);
X/*
X *	Insert left parenthesis if necessary.
X */
X		if (n==1 && strlen(fontv[fi+1])==2) output('(');
X		fputs(fontv[fi+1],stdout);
X		fputs(q,stdout);
X		return;
X	}
X/*
X *	No match.
X */
X	fputs(yytext,stdout);
X}
X
Xargbomb() {
X	fprintf(stderr,"usage: %s font font [font font ...]\n",progname);
X	exit(1);
X}
//E*O*F subfont.l//

exit 0
-- 
Col. G. L. Sicherman
UU: ...{rocksvax|decvax}!sunybcs!colonel
CS: colonel@buffalo-cs
BI: colonel@sunybcs, csdsiche@sunyabvc