xref: /csrg-svn/usr.bin/vgrind/vfontedpr.c (revision 3882)
11841Sroot #include <ctype.h>
21841Sroot #include <stdio.h>
31841Sroot #include <sys/types.h>
41841Sroot #include <sys/stat.h>
51841Sroot 
62199Sroot #define boolean int
72199Sroot #define TRUE 1
82199Sroot #define FALSE 0
92199Sroot #define NIL 0
10*3882Spresott #define STANDARD 0
11*3882Spresott #define ALTERNATE 1
122199Sroot 
131841Sroot /*
141841Sroot  * Vfontedpr.
151841Sroot  *
162199Sroot  * Dave Presotto 1/12/81 (adapted from an earlier version by Bill Joy)
171862Sroot  *
181841Sroot  */
191862Sroot 
201862Sroot #define STRLEN 10		/* length of strings introducing things */
211862Sroot #define PNAMELEN 40		/* length of a function/procedure name */
222199Sroot #define PSMAX 20		/* size of procedure name stacking */
231862Sroot 
242199Sroot /* regular expression routines */
251862Sroot 
262199Sroot char	*expmatch();		/* match a string to an expression */
272199Sroot char	*STRNCMP();		/* a different kindof strncmp */
282199Sroot char	*convexp();		/* convert expression to internal form */
291862Sroot 
302199Sroot boolean	isproc();
311862Sroot 
321862Sroot 
332199Sroot char	*ctime();
341862Sroot 
352199Sroot /*
362199Sroot  *	The state variables
372199Sroot  */
381862Sroot 
392199Sroot boolean	incomm;			/* in a comment of the primary type */
402199Sroot boolean	instr;			/* in a string constant */
412199Sroot boolean	inchr;			/* in a string constant */
422199Sroot boolean	nokeyw = FALSE;		/* no keywords being flagged */
432199Sroot boolean	index = FALSE;		/* form an index */
442199Sroot boolean filter = FALSE;		/* act as a filter (like eqn) */
452199Sroot boolean pass = FALSE;		/* when acting as a filter, pass indicates
462199Sroot 				 * whether we are currently processing
472199Sroot 				 * input.
482199Sroot 				 */
492199Sroot boolean prccont;		/* continue last procedure */
50*3882Spresott int	comtype;		/* type of comment */
512199Sroot int	margin;
522199Sroot int	psptr;			/* the stack index of the current procedure */
532199Sroot char	pstack[PSMAX][PNAMELEN+1];	/* the procedure name stack */
542199Sroot int	plstack[PSMAX];		/* the procedure nesting level stack */
552199Sroot int	blklevel;		/* current nesting level */
562199Sroot char	*defsfile = "/usr/lib/vgrindefs";	/* name of language definitions file */
572199Sroot char	pname[BUFSIZ+1];
581862Sroot 
592199Sroot /*
602199Sroot  *	The language specific globals
612199Sroot  */
621862Sroot 
632199Sroot char	*language = "c";	/* the language indicator */
642199Sroot char	*l_keywds[BUFSIZ/2];	/* keyword table address */
652199Sroot char	*l_prcbeg;		/* regular expr for procedure begin */
662199Sroot char	*l_combeg;		/* string introducing a comment */
672199Sroot char	*l_comend;		/* string ending a comment */
68*3882Spresott char	*l_acmbeg;		/* string introducing a comment */
69*3882Spresott char	*l_acmend;		/* string ending a comment */
702199Sroot char	*l_blkbeg;		/* string begining of a block */
712199Sroot char	*l_blkend;		/* string ending a block */
722199Sroot char    *l_strbeg;		/* delimiter for string constant */
732199Sroot char    *l_strend;		/* delimiter for string constant */
742199Sroot char    *l_chrbeg;		/* delimiter for character constant */
752199Sroot char    *l_chrend;		/* delimiter for character constant */
762199Sroot char	l_escape;		/* character used to  escape characters */
772199Sroot boolean	l_toplex;		/* procedures only defined at top lex level */
781878Sroot 
791862Sroot /*
802199Sroot  *  global variables also used by expmatch
811862Sroot  */
822199Sroot boolean _escaped;		/* if last character was an escape */
832199Sroot char *_start;			/* start of the current string */
842199Sroot boolean	l_onecase;		/* upper and lower case are equivalent */
851862Sroot 
862199Sroot #define	ps(x)	printf("%s", x)
871862Sroot 
882199Sroot main(argc, argv)
892199Sroot     int argc;
902199Sroot     char *argv[];
912199Sroot {
922199Sroot     int lineno;
932199Sroot     char *fname = "";
942199Sroot     char *ptr;
952199Sroot     struct stat stbuf;
962199Sroot     char buf[BUFSIZ];
972199Sroot     char strings[2 * BUFSIZ];
982199Sroot     char defs[2 * BUFSIZ];
992199Sroot     int needbp = 0;
1001862Sroot 
1012199Sroot     argc--, argv++;
1022199Sroot     do {
1032199Sroot 	char *cp;
1042199Sroot 	int i;
1051878Sroot 
1062199Sroot 	if (argc > 0) {
1072199Sroot 	    if (!strcmp(argv[0], "-h")) {
1082199Sroot 		if (argc == 1) {
1092199Sroot 		    printf("'ds =H\n");
1102199Sroot 		    argc = 0;
1112199Sroot 		    goto rest;
1122199Sroot 		}
1132199Sroot 		printf("'ds =H %s\n", argv[1]);
1143393Spresott 		argc--, argv++;
1153393Spresott 		argc--, argv++;
1162199Sroot 		if (argc > 0)
1172199Sroot 		    continue;
1182199Sroot 		goto rest;
1192199Sroot 	    }
1201862Sroot 
1212199Sroot 	    /* act as a filter like eqn */
1222199Sroot 	    if (!strcmp(argv[0], "-f")) {
1232199Sroot 		filter++;
1242199Sroot 		argv[0] = argv[argc-1];
1252199Sroot 		argv[argc-1] = "-";
1262199Sroot 		continue;
1272199Sroot 	    }
1281862Sroot 
1292199Sroot 	    /* take input from the standard place */
1302199Sroot 	    if (!strcmp(argv[0], "-")) {
1312199Sroot 		argc = 0;
1322199Sroot 		goto rest;
1332199Sroot 	    }
1341878Sroot 
1352199Sroot 	    /* build an index */
1362199Sroot 	    if (!strcmp(argv[0], "-x")) {
1372199Sroot 		index++;
1382199Sroot 		argv[0] = "-n";
1392199Sroot 	    }
1401841Sroot 
1412199Sroot 	    /* indicate no keywords */
1422199Sroot 	    if (!strcmp(argv[0], "-n")) {
1432199Sroot 		nokeyw++;
1442199Sroot 		argc--, argv++;
1452199Sroot 		continue;
1462199Sroot 	    }
1471862Sroot 
1482199Sroot 	    /* specify the font size */
1492199Sroot 	    if (!strncmp(argv[0], "-s", 2)) {
1502199Sroot 		i = 0;
1512199Sroot 		cp = argv[0] + 2;
1522199Sroot 		while (*cp)
1532199Sroot 		    i = i * 10 + (*cp++ - '0');
1542199Sroot 		printf("'ps %d\n'vs %d\n", i, i+1);
1552199Sroot 		argc--, argv++;
1562199Sroot 		continue;
1572199Sroot 	    }
1581841Sroot 
1592199Sroot 	    /* specify the language */
1602199Sroot 	    if (!strncmp(argv[0], "-l", 2)) {
1612199Sroot 		language = argv[0]+2;
1622199Sroot 		argc--, argv++;
1632199Sroot 		continue;
1642199Sroot 	    }
1651841Sroot 
1662199Sroot 	    /* specify the language description file */
1672199Sroot 	    if (!strncmp(argv[0], "-d", 2)) {
1682199Sroot 		defsfile = argv[1];
1692199Sroot 		argc--, argv++;
1702199Sroot 		argc--, argv++;
1712199Sroot 		continue;
1722199Sroot 	    }
1731862Sroot 
1742199Sroot 	    /* open the file for input */
1752199Sroot 	    if (freopen(argv[0], "r", stdin) == NULL) {
1762199Sroot 		perror(argv[0]);
1772199Sroot 		exit(1);
1782199Sroot 	    }
1792199Sroot 	    if (index)
1802199Sroot 		printf("'ta 4i 4.25i 5.5iR\n'in .5i\n");
1812199Sroot 	    fname = argv[0];
1822199Sroot 	    argc--, argv++;
1832199Sroot 	}
1842199Sroot     rest:
1851862Sroot 
1862199Sroot 	/*
1872199Sroot 	 *  get the  language definition from the defs file
1882199Sroot 	 */
1892199Sroot 	i = tgetent (defs, language, defsfile);
1902199Sroot 	if (i == 0) {
1912199Sroot 	    fprintf (stderr, "no entry for language %s\n", language);
1922199Sroot 	    exit (0);
1932199Sroot 	} else  if (i < 0) {
1942199Sroot 	    fprintf (stderr,  "cannot find vgrindefs file %s\n", defsfile);
1952199Sroot 	    exit (0);
1962199Sroot 	}
1972199Sroot 	cp = strings;
1982199Sroot 	if (tgetstr ("kw", &cp) == NIL)
1992199Sroot 	    nokeyw = TRUE;
2002199Sroot 	else  {
2012199Sroot 	    char **cpp;
2021878Sroot 
2032199Sroot 	    cpp = l_keywds;
2042199Sroot 	    cp = strings;
2052199Sroot 	    while (*cp) {
2062199Sroot 		while (*cp == ' ' || *cp =='\t')
2072199Sroot 		    *cp++ = NULL;
2082199Sroot 		if (*cp)
2092199Sroot 		    *cpp++ = cp;
2102199Sroot 		while (*cp != ' ' && *cp  != '\t' && *cp)
2112199Sroot 		    cp++;
2122199Sroot 	    }
2132199Sroot 	    *cpp = NIL;
2142199Sroot 	}
2152199Sroot 	cp = buf;
2162199Sroot 	l_prcbeg = convexp (tgetstr ("pb", &cp));
2172199Sroot 	cp = buf;
2182199Sroot 	l_combeg = convexp (tgetstr ("cb", &cp));
2192199Sroot 	cp = buf;
2202199Sroot 	l_comend = convexp (tgetstr ("ce", &cp));
2212199Sroot 	cp = buf;
222*3882Spresott 	l_acmbeg = convexp (tgetstr ("ab", &cp));
223*3882Spresott 	cp = buf;
224*3882Spresott 	l_acmend = convexp (tgetstr ("ae", &cp));
225*3882Spresott 	cp = buf;
2262199Sroot 	l_strbeg = convexp (tgetstr ("sb", &cp));
2272199Sroot 	cp = buf;
2282199Sroot 	l_strend = convexp (tgetstr ("se", &cp));
2292199Sroot 	cp = buf;
2302199Sroot 	l_blkbeg = convexp (tgetstr ("bb", &cp));
2312199Sroot 	cp = buf;
2322199Sroot 	l_blkend = convexp (tgetstr ("be", &cp));
2332199Sroot 	cp = buf;
2342199Sroot 	l_chrbeg = convexp (tgetstr ("lb", &cp));
2352199Sroot 	cp = buf;
2362199Sroot 	l_chrend = convexp (tgetstr ("le", &cp));
2372199Sroot 	l_escape = '\\';
2382199Sroot 	l_onecase = tgetflag ("oc");
2392199Sroot 	l_toplex = tgetflag ("tl");
240*3882Spresott 
2412199Sroot 	/* initialize the program */
2421878Sroot 
2432199Sroot 	incomm = FALSE;
2442199Sroot 	instr = FALSE;
2452199Sroot 	inchr = FALSE;
2462199Sroot 	_escaped = FALSE;
2472199Sroot 	blklevel = 0;
2482199Sroot 	for (psptr=0; psptr<PSMAX; psptr++) {
2492199Sroot 	    pstack[psptr][0] = NULL;
2502199Sroot 	    plstack[psptr] = 0;
2512199Sroot 	}
2522199Sroot 	psptr = -1;
2532199Sroot 	ps("'-F\n");
2542199Sroot 	if (!filter) {
2552199Sroot 	    printf(".ds =F %s\n", fname);
2562199Sroot 	    fstat(fileno(stdin), &stbuf);
2572199Sroot 	    cp = ctime(&stbuf.st_mtime);
2582199Sroot 	    cp[16] = '\0';
2592199Sroot 	    cp[24] = '\0';
2602199Sroot 	    printf(".ds =M %s %s\n", cp+4, cp+20);
2613393Spresott 	    ps("'wh 0 vH\n");
2623393Spresott 	    ps("'wh -1i vF\n");
2632199Sroot 	}
2642199Sroot 	if (needbp) {
2652199Sroot 	    needbp = 0;
2662199Sroot 	    printf(".()\n");
2672199Sroot 	    printf(".bp\n");
2682199Sroot 	}
2691878Sroot 
2702199Sroot 	/*
2712199Sroot 	 *	MAIN LOOP!!!
2722199Sroot 	 */
2732199Sroot 	while (fgets(buf, sizeof buf, stdin) != NULL) {
2742199Sroot 	    if (buf[0] == '\f') {
2752199Sroot 		printf(".bp\n");
2762199Sroot 	    }
2772199Sroot 	    if (buf[0] == '.') {
2782199Sroot 		printf("%s", buf);
2792199Sroot 		if (!strncmp (buf+1, "vS", 2))
2802199Sroot 		    pass = TRUE;
2812199Sroot 		if (!strncmp (buf+1, "vE", 2))
2822199Sroot 		    pass = FALSE;
2832199Sroot 		continue;
2842199Sroot 	    }
2852199Sroot 	    prccont = FALSE;
2862199Sroot 	    if (!filter || pass)
2872199Sroot 		putScp(buf);
2882199Sroot 	    else
2892199Sroot 		printf("%s", buf);
2902199Sroot 	    if (prccont && (psptr >= 0)) {
2912199Sroot 		ps("'FC ");
2922199Sroot 		ps(pstack[psptr]);
2932199Sroot 		ps("\n");
2942199Sroot 	    }
2952199Sroot #ifdef DEBUG
2962199Sroot 	    printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr);
2972199Sroot #endif
2982199Sroot 	    margin = 0;
2992199Sroot 	}
3002199Sroot 	needbp = 1;
3012199Sroot     } while (argc > 0);
3022199Sroot     exit(0);
3031841Sroot }
3041841Sroot 
3051841Sroot #define isidchr(c) (isalnum(c) || (c) == '_')
3061841Sroot 
3071841Sroot putScp(os)
3082199Sroot     char *os;
3091841Sroot {
3102199Sroot     register char *s = os;		/* pointer to unmatched string */
3112199Sroot     char dummy[BUFSIZ];			/* dummy to be used by expmatch */
3122199Sroot     char *comptr;			/* end of a comment delimiter */
313*3882Spresott     char *acmptr;			/* end of a comment delimiter */
3142199Sroot     char *strptr;			/* end of a string delimiter */
3152199Sroot     char *chrptr;			/* end of a character const delimiter */
3162199Sroot     char *blksptr;			/* end of a lexical block start */
3172199Sroot     char *blkeptr;			/* end of a lexical block end */
3181841Sroot 
3192199Sroot     _start = os;			/* remember the start for expmatch */
3202199Sroot     _escaped = FALSE;
3212199Sroot     if (nokeyw || incomm || instr)
3222199Sroot 	goto skip;
3232199Sroot     if (isproc(s)) {
3242199Sroot 	ps("'FN ");
3252199Sroot 	ps(pname);
3262293Sroot         ps("\n");
3272199Sroot 	if (psptr < PSMAX) {
3282199Sroot 	    ++psptr;
3292199Sroot 	    strncpy (pstack[psptr], pname, PNAMELEN);
3302199Sroot 	    pstack[psptr][PNAMELEN] = NULL;
3312199Sroot 	    plstack[psptr] = blklevel;
3322199Sroot 	}
3332199Sroot     }
3341841Sroot skip:
3352199Sroot     do {
3362199Sroot 	/* check for string, comment, blockstart, etc */
3372199Sroot 	if (!incomm && !instr && !inchr) {
3382199Sroot 
3392199Sroot 	    blkeptr = expmatch (s, l_blkend, dummy);
3402199Sroot 	    blksptr = expmatch (s, l_blkbeg, dummy);
3412199Sroot 	    comptr = expmatch (s, l_combeg, dummy);
342*3882Spresott 	    acmptr = expmatch (s, l_acmbeg, dummy);
3432199Sroot 	    strptr = expmatch (s, l_strbeg, dummy);
3442199Sroot 	    chrptr = expmatch (s, l_chrbeg, dummy);
3452199Sroot 
3462199Sroot 	    /* start of a comment? */
3472199Sroot 	    if (comptr != NIL)
3482199Sroot 		if ((comptr < strptr || strptr == NIL)
349*3882Spresott 		  && (comptr < acmptr || acmptr == NIL)
3502199Sroot 		  && (comptr < chrptr || chrptr == NIL)
3512199Sroot 		  && (comptr < blksptr || blksptr == NIL)
3522199Sroot 		  && (comptr < blkeptr || blkeptr == NIL)) {
3532199Sroot 		    putKcp (s, comptr-1, FALSE);
3542199Sroot 		    s = comptr;
3552199Sroot 		    incomm = TRUE;
356*3882Spresott 		    comtype = STANDARD;
3572199Sroot 		    if (s != os)
3582199Sroot 			ps ("\\c");
3592199Sroot 		    ps ("\\c\n'+C\n");
3602199Sroot 		    continue;
3611841Sroot 		}
3621878Sroot 
363*3882Spresott 	    /* start of a comment? */
364*3882Spresott 	    if (acmptr != NIL)
365*3882Spresott 		if ((acmptr < strptr || strptr == NIL)
366*3882Spresott 		  && (acmptr < chrptr || chrptr == NIL)
367*3882Spresott 		  && (acmptr < blksptr || blksptr == NIL)
368*3882Spresott 		  && (acmptr < blkeptr || blkeptr == NIL)) {
369*3882Spresott 		    putKcp (s, acmptr-1, FALSE);
370*3882Spresott 		    s = acmptr;
371*3882Spresott 		    incomm = TRUE;
372*3882Spresott 		    comtype = ALTERNATE;
373*3882Spresott 		    if (s != os)
374*3882Spresott 			ps ("\\c");
375*3882Spresott 		    ps ("\\c\n'+C\n");
376*3882Spresott 		    continue;
377*3882Spresott 		}
378*3882Spresott 
3792199Sroot 	    /* start of a string? */
3802199Sroot 	    if (strptr != NIL)
3812199Sroot 		if ((strptr < chrptr || chrptr == NIL)
3822212Sroot 		  && (strptr < blksptr || blksptr == NIL)
3832212Sroot 		  && (strptr < blkeptr || blkeptr == NIL)) {
3842199Sroot 		    putKcp (s, strptr-1, FALSE);
3852199Sroot 		    s = strptr;
3862199Sroot 		    instr = TRUE;
3872199Sroot 		    continue;
3882199Sroot 		}
3891878Sroot 
3902199Sroot 	    /* start of a character string? */
3912199Sroot 	    if (chrptr != NIL)
3922212Sroot 		if ((chrptr < blksptr || blksptr == NIL)
3932212Sroot 		  && (chrptr < blkeptr || blkeptr == NIL)) {
3942199Sroot 		    putKcp (s, chrptr-1, FALSE);
3952199Sroot 		    s = chrptr;
3962199Sroot 		    inchr = TRUE;
3972199Sroot 		    continue;
3981841Sroot 		}
3991878Sroot 
4002199Sroot 	    /* end of a lexical block */
4012199Sroot 	    if (blkeptr != NIL) {
4022199Sroot 		if (blkeptr < blksptr || blksptr == NIL) {
4032199Sroot 		    putKcp (s, blkeptr - 1, FALSE);
4042199Sroot 		    s = blkeptr;
4052199Sroot 		    blklevel--;
4062199Sroot 		    if (psptr >= 0 && plstack[psptr] >= blklevel) {
4071878Sroot 
4082199Sroot 			/* end of current procedure */
4091841Sroot 			if (s != os)
4102199Sroot 			    ps ("\\c");
4112199Sroot 			ps ("\\c\n'-F\n");
4122199Sroot 			blklevel = plstack[psptr];
4131878Sroot 
4142199Sroot 			/* see if we should print the last proc name */
4152199Sroot 			if (--psptr >= 0)
4162199Sroot 			    prccont = TRUE;
4172199Sroot 			else
4182199Sroot 			    psptr = -1;
4192199Sroot 		    }
4202199Sroot 		    continue;
4211841Sroot 		}
4222199Sroot 	    }
4231878Sroot 
4242199Sroot 	    /* start of a lexical block */
4252199Sroot 	    if (blksptr != NIL) {
4262199Sroot 		putKcp (s, blksptr - 1, FALSE);
4272199Sroot 		s = blksptr;
4282199Sroot 		blklevel++;
4292199Sroot 		continue;
4302199Sroot 	    }
4312199Sroot 
4322199Sroot 	/* check for end of comment */
4332199Sroot 	} else if (incomm) {
434*3882Spresott 	    comptr = expmatch (s, l_comend, dummy);
435*3882Spresott 	    acmptr = expmatch (s, l_acmend, dummy);
436*3882Spresott 	    if (((comtype == STANDARD) && (comptr != NIL)) ||
437*3882Spresott 	        ((comtype == ALTERNATE) && (acmptr != NIL))) {
438*3882Spresott 		if (comtype == STANDARD) {
439*3882Spresott 		    putKcp (s, comptr-1, TRUE);
440*3882Spresott 		    s = comptr;
441*3882Spresott 		} else {
442*3882Spresott 		    putKcp (s, acmptr-1, TRUE);
443*3882Spresott 		    s = acmptr;
444*3882Spresott 		}
4452199Sroot 		incomm = FALSE;
4462199Sroot 		ps("\\c\n'-C\n");
4472199Sroot 		continue;
4482199Sroot 	    } else {
4492199Sroot 		putKcp (s, s + strlen(s) -1);
4502199Sroot 		s = s + strlen(s);
4512199Sroot 		continue;
4522199Sroot 	    }
4532199Sroot 
4542199Sroot 	/* check for end of string */
4552199Sroot 	} else if (instr) {
4562199Sroot 	    if ((strptr = expmatch (s, l_strend, dummy)) != NIL) {
4572199Sroot 		putKcp (s, strptr-1, TRUE);
4582199Sroot 		s = strptr;
4592199Sroot 		instr = FALSE;
4602199Sroot 		continue;
4612199Sroot 	    } else {
4622199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4632199Sroot 		s = s + strlen(s);
4642199Sroot 		continue;
4652199Sroot 	    }
4662199Sroot 
4672199Sroot 	/* check for end of character string */
4682199Sroot 	} else if (inchr) {
4692199Sroot 	    if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) {
4702199Sroot 		putKcp (s, chrptr-1, TRUE);
4712199Sroot 		s = chrptr;
4722199Sroot 		inchr = FALSE;
4732199Sroot 		continue;
4742199Sroot 	    } else {
4752199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4762199Sroot 		s = s + strlen(s);
4772199Sroot 		continue;
4782199Sroot 	    }
4791841Sroot 	}
4802199Sroot 
4812199Sroot 	/* print out the line */
4822199Sroot 	putKcp (s, s + strlen(s) -1, FALSE);
4832199Sroot 	s = s + strlen(s);
4842199Sroot     } while (*s);
4851841Sroot }
4861841Sroot 
4872199Sroot putKcp (start, end, force)
4882199Sroot     char	*start;		/* start of string to write */
4892199Sroot     char	*end;		/* end of string to write */
4902199Sroot     boolean	force;		/* true if we should force nokeyw */
4912199Sroot {
4922199Sroot     int i;
4932320Sroot     int xfld = 0;
4942199Sroot 
4952199Sroot     while (start <= end) {
4962320Sroot 	if (index) {
4972320Sroot 	    if (*start == ' ' || *start == '\t') {
4982320Sroot 		if (xfld == 0)
4992320Sroot 		    printf("");
5002320Sroot 		printf("\t");
5012320Sroot 		xfld = 1;
5022320Sroot 		while (*start == ' ' || *start == '\t')
5032320Sroot 		    start++;
5042320Sroot 		continue;
5052320Sroot 	    }
5062320Sroot 	}
5072199Sroot 
5082199Sroot 	/* take care of nice tab stops */
5092199Sroot 	if (*start == '\t') {
5102199Sroot 	    while (*start == '\t')
5112199Sroot 		start++;
5122199Sroot 	    i = tabs(_start, start) - margin / 8;
5132199Sroot 	    printf("\\h'|%dn'", i * 10 + 1 - margin % 8);
5142199Sroot 	    continue;
5152199Sroot 	}
5162199Sroot 
5172199Sroot 	if (!nokeyw && !force)
5182199Sroot 	    if ((*start == '#' || isidchr(*start))
5192199Sroot 	    && (start == _start || !isidchr(start[-1]))) {
5202199Sroot 		i = iskw(start);
5212199Sroot 		if (i > 0) {
5222199Sroot 		    ps("\\*(+K");
5232199Sroot 		    do
5242199Sroot 			putcp(*start++);
5252199Sroot 		    while (--i > 0);
5262199Sroot 		    ps("\\*(-K");
5272199Sroot 		    continue;
5282199Sroot 		}
5292199Sroot 	    }
5302199Sroot 
5312199Sroot 	putcp (*start++);
5322199Sroot     }
5332199Sroot }
5342199Sroot 
5352199Sroot 
5361841Sroot tabs(s, os)
5372199Sroot     char *s, *os;
5381841Sroot {
5391841Sroot 
5402199Sroot     return (width(s, os) / 8);
5411841Sroot }
5421841Sroot 
5431841Sroot width(s, os)
5441841Sroot 	register char *s, *os;
5451841Sroot {
5461841Sroot 	register int i = 0;
5471841Sroot 
5481841Sroot 	while (s < os) {
5491841Sroot 		if (*s == '\t') {
5501841Sroot 			i = (i + 8) &~ 7;
5511841Sroot 			s++;
5521841Sroot 			continue;
5531841Sroot 		}
5541841Sroot 		if (*s < ' ')
5551841Sroot 			i += 2;
5561841Sroot 		else
5571841Sroot 			i++;
5581841Sroot 		s++;
5591841Sroot 	}
5601841Sroot 	return (i);
5611841Sroot }
5621841Sroot 
5631841Sroot putcp(c)
5641841Sroot 	register int c;
5651841Sroot {
5661841Sroot 
5671841Sroot 	switch(c) {
5681841Sroot 
5692199Sroot 	case 0:
5702199Sroot 		break;
5712199Sroot 
5722199Sroot 	case '\f':
5732199Sroot 		break;
5742199Sroot 
5751841Sroot 	case '{':
5761841Sroot 		ps("\\*(+K{\\*(-K");
5771841Sroot 		break;
5781841Sroot 
5791841Sroot 	case '}':
5801841Sroot 		ps("\\*(+K}\\*(-K");
5811841Sroot 		break;
5821841Sroot 
5831841Sroot 	case '\\':
5841841Sroot 		ps("\\e");
5851841Sroot 		break;
5861841Sroot 
5871841Sroot 	case '_':
5881841Sroot 		ps("\\*_");
5891841Sroot 		break;
5901841Sroot 
5911841Sroot 	case '-':
5921841Sroot 		ps("\\*-");
5931841Sroot 		break;
5941841Sroot 
5951841Sroot 	case '`':
5961841Sroot 		ps("\\`");
5971841Sroot 		break;
5981841Sroot 
5991841Sroot 	case '\'':
6001841Sroot 		ps("\\'");
6011841Sroot 		break;
6021841Sroot 
6031841Sroot 	case '.':
6041841Sroot 		ps("\\&.");
6051841Sroot 		break;
6061841Sroot 
6072418Sroot 	case '*':
6082418Sroot 		ps("\\fI*\\fP");
6092418Sroot 		break;
6102418Sroot 
6112199Sroot 	case '/':
6122418Sroot 		ps("\\fI\\h'\\w' 'u-\\w'/'u'/\\fP");
6132199Sroot 		break;
6142199Sroot 
6151841Sroot 	default:
6161841Sroot 		if (c < 040)
6171841Sroot 			putchar('^'), c |= '@';
6181841Sroot 	case '\t':
6191841Sroot 	case '\n':
6201841Sroot 		putchar(c);
6211841Sroot 	}
6221841Sroot }
6231841Sroot 
6242199Sroot /*
6252199Sroot  *	look for a process beginning on this line
6261878Sroot  */
6272199Sroot boolean
6282199Sroot isproc(s)
6292199Sroot     char *s;
6301878Sroot {
6312199Sroot     pname[0] = NULL;
6322199Sroot     if (!l_toplex || blklevel == 0)
6332199Sroot 	if (expmatch (s, l_prcbeg, pname) != NIL) {
6342199Sroot 	    return (TRUE);
6352199Sroot 	}
6362199Sroot     return (FALSE);
6371878Sroot }
6381878Sroot 
6392199Sroot 
6401878Sroot /*  iskw -	check to see if the next word is a keyword
6411878Sroot  */
6421878Sroot 
6431841Sroot iskw(s)
6441841Sroot 	register char *s;
6451841Sroot {
6462199Sroot 	register char **ss = l_keywds;
6471841Sroot 	register int i = 1;
6481841Sroot 	register char *cp = s;
6491841Sroot 
6501841Sroot 	while (++cp, isidchr(*cp))
6511841Sroot 		i++;
6521841Sroot 	while (cp = *ss++)
6532199Sroot 		if (!STRNCMP(s,cp,i) && !isidchr(cp[i]))
6541841Sroot 			return (i);
6551841Sroot 	return (0);
6561841Sroot }
657