xref: /csrg-svn/usr.bin/vgrind/vfontedpr.c (revision 17500)
1*17500Sralph static char sccsid[] = "@(#)vfontedpr.c	4.2	(Berkeley)	12/11/84";
28760Smckusick 
31841Sroot #include <ctype.h>
41841Sroot #include <stdio.h>
51841Sroot #include <sys/types.h>
61841Sroot #include <sys/stat.h>
71841Sroot 
82199Sroot #define boolean int
92199Sroot #define TRUE 1
102199Sroot #define FALSE 0
112199Sroot #define NIL 0
123882Spresott #define STANDARD 0
133882Spresott #define ALTERNATE 1
142199Sroot 
151841Sroot /*
161841Sroot  * Vfontedpr.
171841Sroot  *
182199Sroot  * Dave Presotto 1/12/81 (adapted from an earlier version by Bill Joy)
191862Sroot  *
201841Sroot  */
211862Sroot 
221862Sroot #define STRLEN 10		/* length of strings introducing things */
231862Sroot #define PNAMELEN 40		/* length of a function/procedure name */
242199Sroot #define PSMAX 20		/* size of procedure name stacking */
251862Sroot 
262199Sroot /* regular expression routines */
271862Sroot 
282199Sroot char	*expmatch();		/* match a string to an expression */
292199Sroot char	*STRNCMP();		/* a different kindof strncmp */
302199Sroot char	*convexp();		/* convert expression to internal form */
31*17500Sralph char	*tgetstr();
321862Sroot 
332199Sroot boolean	isproc();
341862Sroot 
351862Sroot 
362199Sroot char	*ctime();
371862Sroot 
382199Sroot /*
392199Sroot  *	The state variables
402199Sroot  */
411862Sroot 
422199Sroot boolean	incomm;			/* in a comment of the primary type */
432199Sroot boolean	instr;			/* in a string constant */
442199Sroot boolean	inchr;			/* in a string constant */
452199Sroot boolean	nokeyw = FALSE;		/* no keywords being flagged */
462199Sroot boolean	index = FALSE;		/* form an index */
472199Sroot boolean filter = FALSE;		/* act as a filter (like eqn) */
482199Sroot boolean pass = FALSE;		/* when acting as a filter, pass indicates
492199Sroot 				 * whether we are currently processing
502199Sroot 				 * input.
512199Sroot 				 */
522199Sroot boolean prccont;		/* continue last procedure */
533882Spresott int	comtype;		/* type of comment */
542199Sroot int	margin;
552199Sroot int	psptr;			/* the stack index of the current procedure */
562199Sroot char	pstack[PSMAX][PNAMELEN+1];	/* the procedure name stack */
572199Sroot int	plstack[PSMAX];		/* the procedure nesting level stack */
582199Sroot int	blklevel;		/* current nesting level */
592199Sroot char	*defsfile = "/usr/lib/vgrindefs";	/* name of language definitions file */
602199Sroot char	pname[BUFSIZ+1];
611862Sroot 
622199Sroot /*
632199Sroot  *	The language specific globals
642199Sroot  */
651862Sroot 
662199Sroot char	*language = "c";	/* the language indicator */
672199Sroot char	*l_keywds[BUFSIZ/2];	/* keyword table address */
682199Sroot char	*l_prcbeg;		/* regular expr for procedure begin */
692199Sroot char	*l_combeg;		/* string introducing a comment */
702199Sroot char	*l_comend;		/* string ending a comment */
713882Spresott char	*l_acmbeg;		/* string introducing a comment */
723882Spresott char	*l_acmend;		/* string ending a comment */
732199Sroot char	*l_blkbeg;		/* string begining of a block */
742199Sroot char	*l_blkend;		/* string ending a block */
752199Sroot char    *l_strbeg;		/* delimiter for string constant */
762199Sroot char    *l_strend;		/* delimiter for string constant */
772199Sroot char    *l_chrbeg;		/* delimiter for character constant */
782199Sroot char    *l_chrend;		/* delimiter for character constant */
792199Sroot char	l_escape;		/* character used to  escape characters */
802199Sroot boolean	l_toplex;		/* procedures only defined at top lex level */
811878Sroot 
821862Sroot /*
832199Sroot  *  global variables also used by expmatch
841862Sroot  */
852199Sroot boolean _escaped;		/* if last character was an escape */
862199Sroot char *_start;			/* start of the current string */
872199Sroot boolean	l_onecase;		/* upper and lower case are equivalent */
881862Sroot 
892199Sroot #define	ps(x)	printf("%s", x)
901862Sroot 
912199Sroot main(argc, argv)
922199Sroot     int argc;
932199Sroot     char *argv[];
942199Sroot {
952199Sroot     int lineno;
962199Sroot     char *fname = "";
972199Sroot     char *ptr;
982199Sroot     struct stat stbuf;
992199Sroot     char buf[BUFSIZ];
1002199Sroot     char strings[2 * BUFSIZ];
1012199Sroot     char defs[2 * BUFSIZ];
1022199Sroot     int needbp = 0;
1031862Sroot 
1042199Sroot     argc--, argv++;
1052199Sroot     do {
1062199Sroot 	char *cp;
1072199Sroot 	int i;
1081878Sroot 
1092199Sroot 	if (argc > 0) {
1102199Sroot 	    if (!strcmp(argv[0], "-h")) {
1112199Sroot 		if (argc == 1) {
1122199Sroot 		    printf("'ds =H\n");
1132199Sroot 		    argc = 0;
1142199Sroot 		    goto rest;
1152199Sroot 		}
1162199Sroot 		printf("'ds =H %s\n", argv[1]);
1173393Spresott 		argc--, argv++;
1183393Spresott 		argc--, argv++;
1192199Sroot 		if (argc > 0)
1202199Sroot 		    continue;
1212199Sroot 		goto rest;
1222199Sroot 	    }
1231862Sroot 
1242199Sroot 	    /* act as a filter like eqn */
1252199Sroot 	    if (!strcmp(argv[0], "-f")) {
1262199Sroot 		filter++;
1272199Sroot 		argv[0] = argv[argc-1];
1282199Sroot 		argv[argc-1] = "-";
1292199Sroot 		continue;
1302199Sroot 	    }
1311862Sroot 
1322199Sroot 	    /* take input from the standard place */
1332199Sroot 	    if (!strcmp(argv[0], "-")) {
1342199Sroot 		argc = 0;
1352199Sroot 		goto rest;
1362199Sroot 	    }
1371878Sroot 
1382199Sroot 	    /* build an index */
1392199Sroot 	    if (!strcmp(argv[0], "-x")) {
1402199Sroot 		index++;
1412199Sroot 		argv[0] = "-n";
1422199Sroot 	    }
1431841Sroot 
1442199Sroot 	    /* indicate no keywords */
1452199Sroot 	    if (!strcmp(argv[0], "-n")) {
1462199Sroot 		nokeyw++;
1472199Sroot 		argc--, argv++;
1482199Sroot 		continue;
1492199Sroot 	    }
1501862Sroot 
1512199Sroot 	    /* specify the font size */
1522199Sroot 	    if (!strncmp(argv[0], "-s", 2)) {
1532199Sroot 		i = 0;
1542199Sroot 		cp = argv[0] + 2;
1552199Sroot 		while (*cp)
1562199Sroot 		    i = i * 10 + (*cp++ - '0');
1572199Sroot 		printf("'ps %d\n'vs %d\n", i, i+1);
1582199Sroot 		argc--, argv++;
1592199Sroot 		continue;
1602199Sroot 	    }
1611841Sroot 
1622199Sroot 	    /* specify the language */
1632199Sroot 	    if (!strncmp(argv[0], "-l", 2)) {
1642199Sroot 		language = argv[0]+2;
1652199Sroot 		argc--, argv++;
1662199Sroot 		continue;
1672199Sroot 	    }
1681841Sroot 
1692199Sroot 	    /* specify the language description file */
1702199Sroot 	    if (!strncmp(argv[0], "-d", 2)) {
1712199Sroot 		defsfile = argv[1];
1722199Sroot 		argc--, argv++;
1732199Sroot 		argc--, argv++;
1742199Sroot 		continue;
1752199Sroot 	    }
1761862Sroot 
1772199Sroot 	    /* open the file for input */
1782199Sroot 	    if (freopen(argv[0], "r", stdin) == NULL) {
1792199Sroot 		perror(argv[0]);
1802199Sroot 		exit(1);
1812199Sroot 	    }
1822199Sroot 	    if (index)
1832199Sroot 		printf("'ta 4i 4.25i 5.5iR\n'in .5i\n");
1842199Sroot 	    fname = argv[0];
1852199Sroot 	    argc--, argv++;
1862199Sroot 	}
1872199Sroot     rest:
1881862Sroot 
1892199Sroot 	/*
1902199Sroot 	 *  get the  language definition from the defs file
1912199Sroot 	 */
1922199Sroot 	i = tgetent (defs, language, defsfile);
1932199Sroot 	if (i == 0) {
1942199Sroot 	    fprintf (stderr, "no entry for language %s\n", language);
1952199Sroot 	    exit (0);
1962199Sroot 	} else  if (i < 0) {
1972199Sroot 	    fprintf (stderr,  "cannot find vgrindefs file %s\n", defsfile);
1982199Sroot 	    exit (0);
1992199Sroot 	}
2002199Sroot 	cp = strings;
2012199Sroot 	if (tgetstr ("kw", &cp) == NIL)
2022199Sroot 	    nokeyw = TRUE;
2032199Sroot 	else  {
2042199Sroot 	    char **cpp;
2051878Sroot 
2062199Sroot 	    cpp = l_keywds;
2072199Sroot 	    cp = strings;
2082199Sroot 	    while (*cp) {
2092199Sroot 		while (*cp == ' ' || *cp =='\t')
2102199Sroot 		    *cp++ = NULL;
2112199Sroot 		if (*cp)
2122199Sroot 		    *cpp++ = cp;
2132199Sroot 		while (*cp != ' ' && *cp  != '\t' && *cp)
2142199Sroot 		    cp++;
2152199Sroot 	    }
2162199Sroot 	    *cpp = NIL;
2172199Sroot 	}
2182199Sroot 	cp = buf;
2192199Sroot 	l_prcbeg = convexp (tgetstr ("pb", &cp));
2202199Sroot 	cp = buf;
2212199Sroot 	l_combeg = convexp (tgetstr ("cb", &cp));
2222199Sroot 	cp = buf;
2232199Sroot 	l_comend = convexp (tgetstr ("ce", &cp));
2242199Sroot 	cp = buf;
2253882Spresott 	l_acmbeg = convexp (tgetstr ("ab", &cp));
2263882Spresott 	cp = buf;
2273882Spresott 	l_acmend = convexp (tgetstr ("ae", &cp));
2283882Spresott 	cp = buf;
2292199Sroot 	l_strbeg = convexp (tgetstr ("sb", &cp));
2302199Sroot 	cp = buf;
2312199Sroot 	l_strend = convexp (tgetstr ("se", &cp));
2322199Sroot 	cp = buf;
2332199Sroot 	l_blkbeg = convexp (tgetstr ("bb", &cp));
2342199Sroot 	cp = buf;
2352199Sroot 	l_blkend = convexp (tgetstr ("be", &cp));
2362199Sroot 	cp = buf;
2372199Sroot 	l_chrbeg = convexp (tgetstr ("lb", &cp));
2382199Sroot 	cp = buf;
2392199Sroot 	l_chrend = convexp (tgetstr ("le", &cp));
2402199Sroot 	l_escape = '\\';
2412199Sroot 	l_onecase = tgetflag ("oc");
2422199Sroot 	l_toplex = tgetflag ("tl");
2433882Spresott 
2442199Sroot 	/* initialize the program */
2451878Sroot 
2462199Sroot 	incomm = FALSE;
2472199Sroot 	instr = FALSE;
2482199Sroot 	inchr = FALSE;
2492199Sroot 	_escaped = FALSE;
2502199Sroot 	blklevel = 0;
2512199Sroot 	for (psptr=0; psptr<PSMAX; psptr++) {
2522199Sroot 	    pstack[psptr][0] = NULL;
2532199Sroot 	    plstack[psptr] = 0;
2542199Sroot 	}
2552199Sroot 	psptr = -1;
2562199Sroot 	ps("'-F\n");
2572199Sroot 	if (!filter) {
2582199Sroot 	    printf(".ds =F %s\n", fname);
2592199Sroot 	    fstat(fileno(stdin), &stbuf);
2602199Sroot 	    cp = ctime(&stbuf.st_mtime);
2612199Sroot 	    cp[16] = '\0';
2622199Sroot 	    cp[24] = '\0';
2632199Sroot 	    printf(".ds =M %s %s\n", cp+4, cp+20);
2643393Spresott 	    ps("'wh 0 vH\n");
2653393Spresott 	    ps("'wh -1i vF\n");
2662199Sroot 	}
2672199Sroot 	if (needbp) {
2682199Sroot 	    needbp = 0;
2692199Sroot 	    printf(".()\n");
2702199Sroot 	    printf(".bp\n");
2712199Sroot 	}
2721878Sroot 
2732199Sroot 	/*
2742199Sroot 	 *	MAIN LOOP!!!
2752199Sroot 	 */
2762199Sroot 	while (fgets(buf, sizeof buf, stdin) != NULL) {
2772199Sroot 	    if (buf[0] == '\f') {
2782199Sroot 		printf(".bp\n");
2792199Sroot 	    }
2802199Sroot 	    if (buf[0] == '.') {
2812199Sroot 		printf("%s", buf);
2822199Sroot 		if (!strncmp (buf+1, "vS", 2))
2832199Sroot 		    pass = TRUE;
2842199Sroot 		if (!strncmp (buf+1, "vE", 2))
2852199Sroot 		    pass = FALSE;
2862199Sroot 		continue;
2872199Sroot 	    }
2882199Sroot 	    prccont = FALSE;
2892199Sroot 	    if (!filter || pass)
2902199Sroot 		putScp(buf);
2912199Sroot 	    else
2922199Sroot 		printf("%s", buf);
2932199Sroot 	    if (prccont && (psptr >= 0)) {
2942199Sroot 		ps("'FC ");
2952199Sroot 		ps(pstack[psptr]);
2962199Sroot 		ps("\n");
2972199Sroot 	    }
2982199Sroot #ifdef DEBUG
2992199Sroot 	    printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr);
3002199Sroot #endif
3012199Sroot 	    margin = 0;
3022199Sroot 	}
3032199Sroot 	needbp = 1;
3042199Sroot     } while (argc > 0);
3052199Sroot     exit(0);
3061841Sroot }
3071841Sroot 
3081841Sroot #define isidchr(c) (isalnum(c) || (c) == '_')
3091841Sroot 
3101841Sroot putScp(os)
3112199Sroot     char *os;
3121841Sroot {
3132199Sroot     register char *s = os;		/* pointer to unmatched string */
3142199Sroot     char dummy[BUFSIZ];			/* dummy to be used by expmatch */
3152199Sroot     char *comptr;			/* end of a comment delimiter */
3163882Spresott     char *acmptr;			/* end of a comment delimiter */
3172199Sroot     char *strptr;			/* end of a string delimiter */
3182199Sroot     char *chrptr;			/* end of a character const delimiter */
3192199Sroot     char *blksptr;			/* end of a lexical block start */
3202199Sroot     char *blkeptr;			/* end of a lexical block end */
3211841Sroot 
3222199Sroot     _start = os;			/* remember the start for expmatch */
3232199Sroot     _escaped = FALSE;
3242199Sroot     if (nokeyw || incomm || instr)
3252199Sroot 	goto skip;
3262199Sroot     if (isproc(s)) {
3272199Sroot 	ps("'FN ");
3282199Sroot 	ps(pname);
3292293Sroot         ps("\n");
3302199Sroot 	if (psptr < PSMAX) {
3312199Sroot 	    ++psptr;
3322199Sroot 	    strncpy (pstack[psptr], pname, PNAMELEN);
3332199Sroot 	    pstack[psptr][PNAMELEN] = NULL;
3342199Sroot 	    plstack[psptr] = blklevel;
3352199Sroot 	}
3362199Sroot     }
3371841Sroot skip:
3382199Sroot     do {
3392199Sroot 	/* check for string, comment, blockstart, etc */
3402199Sroot 	if (!incomm && !instr && !inchr) {
3412199Sroot 
3422199Sroot 	    blkeptr = expmatch (s, l_blkend, dummy);
3432199Sroot 	    blksptr = expmatch (s, l_blkbeg, dummy);
3442199Sroot 	    comptr = expmatch (s, l_combeg, dummy);
3453882Spresott 	    acmptr = expmatch (s, l_acmbeg, dummy);
3462199Sroot 	    strptr = expmatch (s, l_strbeg, dummy);
3472199Sroot 	    chrptr = expmatch (s, l_chrbeg, dummy);
3482199Sroot 
3492199Sroot 	    /* start of a comment? */
3502199Sroot 	    if (comptr != NIL)
3512199Sroot 		if ((comptr < strptr || strptr == NIL)
3523882Spresott 		  && (comptr < acmptr || acmptr == NIL)
3532199Sroot 		  && (comptr < chrptr || chrptr == NIL)
3542199Sroot 		  && (comptr < blksptr || blksptr == NIL)
3552199Sroot 		  && (comptr < blkeptr || blkeptr == NIL)) {
3562199Sroot 		    putKcp (s, comptr-1, FALSE);
3572199Sroot 		    s = comptr;
3582199Sroot 		    incomm = TRUE;
3593882Spresott 		    comtype = STANDARD;
3602199Sroot 		    if (s != os)
3612199Sroot 			ps ("\\c");
3622199Sroot 		    ps ("\\c\n'+C\n");
3632199Sroot 		    continue;
3641841Sroot 		}
3651878Sroot 
3663882Spresott 	    /* start of a comment? */
3673882Spresott 	    if (acmptr != NIL)
3683882Spresott 		if ((acmptr < strptr || strptr == NIL)
3693882Spresott 		  && (acmptr < chrptr || chrptr == NIL)
3703882Spresott 		  && (acmptr < blksptr || blksptr == NIL)
3713882Spresott 		  && (acmptr < blkeptr || blkeptr == NIL)) {
3723882Spresott 		    putKcp (s, acmptr-1, FALSE);
3733882Spresott 		    s = acmptr;
3743882Spresott 		    incomm = TRUE;
3753882Spresott 		    comtype = ALTERNATE;
3763882Spresott 		    if (s != os)
3773882Spresott 			ps ("\\c");
3783882Spresott 		    ps ("\\c\n'+C\n");
3793882Spresott 		    continue;
3803882Spresott 		}
3813882Spresott 
3822199Sroot 	    /* start of a string? */
3832199Sroot 	    if (strptr != NIL)
3842199Sroot 		if ((strptr < chrptr || chrptr == NIL)
3852212Sroot 		  && (strptr < blksptr || blksptr == NIL)
3862212Sroot 		  && (strptr < blkeptr || blkeptr == NIL)) {
3872199Sroot 		    putKcp (s, strptr-1, FALSE);
3882199Sroot 		    s = strptr;
3892199Sroot 		    instr = TRUE;
3902199Sroot 		    continue;
3912199Sroot 		}
3921878Sroot 
3932199Sroot 	    /* start of a character string? */
3942199Sroot 	    if (chrptr != NIL)
3952212Sroot 		if ((chrptr < blksptr || blksptr == NIL)
3962212Sroot 		  && (chrptr < blkeptr || blkeptr == NIL)) {
3972199Sroot 		    putKcp (s, chrptr-1, FALSE);
3982199Sroot 		    s = chrptr;
3992199Sroot 		    inchr = TRUE;
4002199Sroot 		    continue;
4011841Sroot 		}
4021878Sroot 
4032199Sroot 	    /* end of a lexical block */
4042199Sroot 	    if (blkeptr != NIL) {
4052199Sroot 		if (blkeptr < blksptr || blksptr == NIL) {
4062199Sroot 		    putKcp (s, blkeptr - 1, FALSE);
4072199Sroot 		    s = blkeptr;
4082199Sroot 		    blklevel--;
4092199Sroot 		    if (psptr >= 0 && plstack[psptr] >= blklevel) {
4101878Sroot 
4112199Sroot 			/* end of current procedure */
4121841Sroot 			if (s != os)
4132199Sroot 			    ps ("\\c");
4142199Sroot 			ps ("\\c\n'-F\n");
4152199Sroot 			blklevel = plstack[psptr];
4161878Sroot 
4172199Sroot 			/* see if we should print the last proc name */
4182199Sroot 			if (--psptr >= 0)
4192199Sroot 			    prccont = TRUE;
4202199Sroot 			else
4212199Sroot 			    psptr = -1;
4222199Sroot 		    }
4232199Sroot 		    continue;
4241841Sroot 		}
4252199Sroot 	    }
4261878Sroot 
4272199Sroot 	    /* start of a lexical block */
4282199Sroot 	    if (blksptr != NIL) {
4292199Sroot 		putKcp (s, blksptr - 1, FALSE);
4302199Sroot 		s = blksptr;
4312199Sroot 		blklevel++;
4322199Sroot 		continue;
4332199Sroot 	    }
4342199Sroot 
4352199Sroot 	/* check for end of comment */
4362199Sroot 	} else if (incomm) {
4373882Spresott 	    comptr = expmatch (s, l_comend, dummy);
4383882Spresott 	    acmptr = expmatch (s, l_acmend, dummy);
4393882Spresott 	    if (((comtype == STANDARD) && (comptr != NIL)) ||
4403882Spresott 	        ((comtype == ALTERNATE) && (acmptr != NIL))) {
4413882Spresott 		if (comtype == STANDARD) {
4423882Spresott 		    putKcp (s, comptr-1, TRUE);
4433882Spresott 		    s = comptr;
4443882Spresott 		} else {
4453882Spresott 		    putKcp (s, acmptr-1, TRUE);
4463882Spresott 		    s = acmptr;
4473882Spresott 		}
4482199Sroot 		incomm = FALSE;
4492199Sroot 		ps("\\c\n'-C\n");
4502199Sroot 		continue;
4512199Sroot 	    } else {
452*17500Sralph 		putKcp (s, s + strlen(s) -1, TRUE);
4532199Sroot 		s = s + strlen(s);
4542199Sroot 		continue;
4552199Sroot 	    }
4562199Sroot 
4572199Sroot 	/* check for end of string */
4582199Sroot 	} else if (instr) {
4592199Sroot 	    if ((strptr = expmatch (s, l_strend, dummy)) != NIL) {
4602199Sroot 		putKcp (s, strptr-1, TRUE);
4612199Sroot 		s = strptr;
4622199Sroot 		instr = FALSE;
4632199Sroot 		continue;
4642199Sroot 	    } else {
4652199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4662199Sroot 		s = s + strlen(s);
4672199Sroot 		continue;
4682199Sroot 	    }
4692199Sroot 
4702199Sroot 	/* check for end of character string */
4712199Sroot 	} else if (inchr) {
4722199Sroot 	    if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) {
4732199Sroot 		putKcp (s, chrptr-1, TRUE);
4742199Sroot 		s = chrptr;
4752199Sroot 		inchr = FALSE;
4762199Sroot 		continue;
4772199Sroot 	    } else {
4782199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4792199Sroot 		s = s + strlen(s);
4802199Sroot 		continue;
4812199Sroot 	    }
4821841Sroot 	}
4832199Sroot 
4842199Sroot 	/* print out the line */
4852199Sroot 	putKcp (s, s + strlen(s) -1, FALSE);
4862199Sroot 	s = s + strlen(s);
4872199Sroot     } while (*s);
4881841Sroot }
4891841Sroot 
4902199Sroot putKcp (start, end, force)
4912199Sroot     char	*start;		/* start of string to write */
4922199Sroot     char	*end;		/* end of string to write */
4932199Sroot     boolean	force;		/* true if we should force nokeyw */
4942199Sroot {
4952199Sroot     int i;
4962320Sroot     int xfld = 0;
4972199Sroot 
4982199Sroot     while (start <= end) {
4992320Sroot 	if (index) {
5002320Sroot 	    if (*start == ' ' || *start == '\t') {
5012320Sroot 		if (xfld == 0)
5022320Sroot 		    printf("");
5032320Sroot 		printf("\t");
5042320Sroot 		xfld = 1;
5052320Sroot 		while (*start == ' ' || *start == '\t')
5062320Sroot 		    start++;
5072320Sroot 		continue;
5082320Sroot 	    }
5092320Sroot 	}
5102199Sroot 
5112199Sroot 	/* take care of nice tab stops */
5122199Sroot 	if (*start == '\t') {
5132199Sroot 	    while (*start == '\t')
5142199Sroot 		start++;
5152199Sroot 	    i = tabs(_start, start) - margin / 8;
5162199Sroot 	    printf("\\h'|%dn'", i * 10 + 1 - margin % 8);
5172199Sroot 	    continue;
5182199Sroot 	}
5192199Sroot 
5202199Sroot 	if (!nokeyw && !force)
5212199Sroot 	    if ((*start == '#' || isidchr(*start))
5222199Sroot 	    && (start == _start || !isidchr(start[-1]))) {
5232199Sroot 		i = iskw(start);
5242199Sroot 		if (i > 0) {
5252199Sroot 		    ps("\\*(+K");
5262199Sroot 		    do
5272199Sroot 			putcp(*start++);
5282199Sroot 		    while (--i > 0);
5292199Sroot 		    ps("\\*(-K");
5302199Sroot 		    continue;
5312199Sroot 		}
5322199Sroot 	    }
5332199Sroot 
5342199Sroot 	putcp (*start++);
5352199Sroot     }
5362199Sroot }
5372199Sroot 
5382199Sroot 
5391841Sroot tabs(s, os)
5402199Sroot     char *s, *os;
5411841Sroot {
5421841Sroot 
5432199Sroot     return (width(s, os) / 8);
5441841Sroot }
5451841Sroot 
5461841Sroot width(s, os)
5471841Sroot 	register char *s, *os;
5481841Sroot {
5491841Sroot 	register int i = 0;
5501841Sroot 
5511841Sroot 	while (s < os) {
5521841Sroot 		if (*s == '\t') {
5531841Sroot 			i = (i + 8) &~ 7;
5541841Sroot 			s++;
5551841Sroot 			continue;
5561841Sroot 		}
5571841Sroot 		if (*s < ' ')
5581841Sroot 			i += 2;
5591841Sroot 		else
5601841Sroot 			i++;
5611841Sroot 		s++;
5621841Sroot 	}
5631841Sroot 	return (i);
5641841Sroot }
5651841Sroot 
5661841Sroot putcp(c)
5671841Sroot 	register int c;
5681841Sroot {
5691841Sroot 
5701841Sroot 	switch(c) {
5711841Sroot 
5722199Sroot 	case 0:
5732199Sroot 		break;
5742199Sroot 
5752199Sroot 	case '\f':
5762199Sroot 		break;
5772199Sroot 
5781841Sroot 	case '{':
5791841Sroot 		ps("\\*(+K{\\*(-K");
5801841Sroot 		break;
5811841Sroot 
5821841Sroot 	case '}':
5831841Sroot 		ps("\\*(+K}\\*(-K");
5841841Sroot 		break;
5851841Sroot 
5861841Sroot 	case '\\':
5871841Sroot 		ps("\\e");
5881841Sroot 		break;
5891841Sroot 
5901841Sroot 	case '_':
5911841Sroot 		ps("\\*_");
5921841Sroot 		break;
5931841Sroot 
5941841Sroot 	case '-':
5951841Sroot 		ps("\\*-");
5961841Sroot 		break;
5971841Sroot 
5981841Sroot 	case '`':
5991841Sroot 		ps("\\`");
6001841Sroot 		break;
6011841Sroot 
6021841Sroot 	case '\'':
6031841Sroot 		ps("\\'");
6041841Sroot 		break;
6051841Sroot 
6061841Sroot 	case '.':
6071841Sroot 		ps("\\&.");
6081841Sroot 		break;
6091841Sroot 
6102418Sroot 	case '*':
6112418Sroot 		ps("\\fI*\\fP");
6122418Sroot 		break;
6132418Sroot 
6142199Sroot 	case '/':
6152418Sroot 		ps("\\fI\\h'\\w' 'u-\\w'/'u'/\\fP");
6162199Sroot 		break;
6172199Sroot 
6181841Sroot 	default:
6191841Sroot 		if (c < 040)
6201841Sroot 			putchar('^'), c |= '@';
6211841Sroot 	case '\t':
6221841Sroot 	case '\n':
6231841Sroot 		putchar(c);
6241841Sroot 	}
6251841Sroot }
6261841Sroot 
6272199Sroot /*
6282199Sroot  *	look for a process beginning on this line
6291878Sroot  */
6302199Sroot boolean
6312199Sroot isproc(s)
6322199Sroot     char *s;
6331878Sroot {
6342199Sroot     pname[0] = NULL;
6352199Sroot     if (!l_toplex || blklevel == 0)
6362199Sroot 	if (expmatch (s, l_prcbeg, pname) != NIL) {
6372199Sroot 	    return (TRUE);
6382199Sroot 	}
6392199Sroot     return (FALSE);
6401878Sroot }
6411878Sroot 
6422199Sroot 
6431878Sroot /*  iskw -	check to see if the next word is a keyword
6441878Sroot  */
6451878Sroot 
6461841Sroot iskw(s)
6471841Sroot 	register char *s;
6481841Sroot {
6492199Sroot 	register char **ss = l_keywds;
6501841Sroot 	register int i = 1;
6511841Sroot 	register char *cp = s;
6521841Sroot 
6531841Sroot 	while (++cp, isidchr(*cp))
6541841Sroot 		i++;
6551841Sroot 	while (cp = *ss++)
6562199Sroot 		if (!STRNCMP(s,cp,i) && !isidchr(cp[i]))
6571841Sroot 			return (i);
6581841Sroot 	return (0);
6591841Sroot }
660