xref: /csrg-svn/usr.bin/vgrind/vfontedpr.c (revision 8760)
1*8760Smckusick static char sccsid[] = "@(#)vfontedpr.c	4.1	(Berkeley)	10/21/82";
2*8760Smckusick 
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 */
311862Sroot 
322199Sroot boolean	isproc();
331862Sroot 
341862Sroot 
352199Sroot char	*ctime();
361862Sroot 
372199Sroot /*
382199Sroot  *	The state variables
392199Sroot  */
401862Sroot 
412199Sroot boolean	incomm;			/* in a comment of the primary type */
422199Sroot boolean	instr;			/* in a string constant */
432199Sroot boolean	inchr;			/* in a string constant */
442199Sroot boolean	nokeyw = FALSE;		/* no keywords being flagged */
452199Sroot boolean	index = FALSE;		/* form an index */
462199Sroot boolean filter = FALSE;		/* act as a filter (like eqn) */
472199Sroot boolean pass = FALSE;		/* when acting as a filter, pass indicates
482199Sroot 				 * whether we are currently processing
492199Sroot 				 * input.
502199Sroot 				 */
512199Sroot boolean prccont;		/* continue last procedure */
523882Spresott int	comtype;		/* type of comment */
532199Sroot int	margin;
542199Sroot int	psptr;			/* the stack index of the current procedure */
552199Sroot char	pstack[PSMAX][PNAMELEN+1];	/* the procedure name stack */
562199Sroot int	plstack[PSMAX];		/* the procedure nesting level stack */
572199Sroot int	blklevel;		/* current nesting level */
582199Sroot char	*defsfile = "/usr/lib/vgrindefs";	/* name of language definitions file */
592199Sroot char	pname[BUFSIZ+1];
601862Sroot 
612199Sroot /*
622199Sroot  *	The language specific globals
632199Sroot  */
641862Sroot 
652199Sroot char	*language = "c";	/* the language indicator */
662199Sroot char	*l_keywds[BUFSIZ/2];	/* keyword table address */
672199Sroot char	*l_prcbeg;		/* regular expr for procedure begin */
682199Sroot char	*l_combeg;		/* string introducing a comment */
692199Sroot char	*l_comend;		/* string ending a comment */
703882Spresott char	*l_acmbeg;		/* string introducing a comment */
713882Spresott char	*l_acmend;		/* string ending a comment */
722199Sroot char	*l_blkbeg;		/* string begining of a block */
732199Sroot char	*l_blkend;		/* string ending a block */
742199Sroot char    *l_strbeg;		/* delimiter for string constant */
752199Sroot char    *l_strend;		/* delimiter for string constant */
762199Sroot char    *l_chrbeg;		/* delimiter for character constant */
772199Sroot char    *l_chrend;		/* delimiter for character constant */
782199Sroot char	l_escape;		/* character used to  escape characters */
792199Sroot boolean	l_toplex;		/* procedures only defined at top lex level */
801878Sroot 
811862Sroot /*
822199Sroot  *  global variables also used by expmatch
831862Sroot  */
842199Sroot boolean _escaped;		/* if last character was an escape */
852199Sroot char *_start;			/* start of the current string */
862199Sroot boolean	l_onecase;		/* upper and lower case are equivalent */
871862Sroot 
882199Sroot #define	ps(x)	printf("%s", x)
891862Sroot 
902199Sroot main(argc, argv)
912199Sroot     int argc;
922199Sroot     char *argv[];
932199Sroot {
942199Sroot     int lineno;
952199Sroot     char *fname = "";
962199Sroot     char *ptr;
972199Sroot     struct stat stbuf;
982199Sroot     char buf[BUFSIZ];
992199Sroot     char strings[2 * BUFSIZ];
1002199Sroot     char defs[2 * BUFSIZ];
1012199Sroot     int needbp = 0;
1021862Sroot 
1032199Sroot     argc--, argv++;
1042199Sroot     do {
1052199Sroot 	char *cp;
1062199Sroot 	int i;
1071878Sroot 
1082199Sroot 	if (argc > 0) {
1092199Sroot 	    if (!strcmp(argv[0], "-h")) {
1102199Sroot 		if (argc == 1) {
1112199Sroot 		    printf("'ds =H\n");
1122199Sroot 		    argc = 0;
1132199Sroot 		    goto rest;
1142199Sroot 		}
1152199Sroot 		printf("'ds =H %s\n", argv[1]);
1163393Spresott 		argc--, argv++;
1173393Spresott 		argc--, argv++;
1182199Sroot 		if (argc > 0)
1192199Sroot 		    continue;
1202199Sroot 		goto rest;
1212199Sroot 	    }
1221862Sroot 
1232199Sroot 	    /* act as a filter like eqn */
1242199Sroot 	    if (!strcmp(argv[0], "-f")) {
1252199Sroot 		filter++;
1262199Sroot 		argv[0] = argv[argc-1];
1272199Sroot 		argv[argc-1] = "-";
1282199Sroot 		continue;
1292199Sroot 	    }
1301862Sroot 
1312199Sroot 	    /* take input from the standard place */
1322199Sroot 	    if (!strcmp(argv[0], "-")) {
1332199Sroot 		argc = 0;
1342199Sroot 		goto rest;
1352199Sroot 	    }
1361878Sroot 
1372199Sroot 	    /* build an index */
1382199Sroot 	    if (!strcmp(argv[0], "-x")) {
1392199Sroot 		index++;
1402199Sroot 		argv[0] = "-n";
1412199Sroot 	    }
1421841Sroot 
1432199Sroot 	    /* indicate no keywords */
1442199Sroot 	    if (!strcmp(argv[0], "-n")) {
1452199Sroot 		nokeyw++;
1462199Sroot 		argc--, argv++;
1472199Sroot 		continue;
1482199Sroot 	    }
1491862Sroot 
1502199Sroot 	    /* specify the font size */
1512199Sroot 	    if (!strncmp(argv[0], "-s", 2)) {
1522199Sroot 		i = 0;
1532199Sroot 		cp = argv[0] + 2;
1542199Sroot 		while (*cp)
1552199Sroot 		    i = i * 10 + (*cp++ - '0');
1562199Sroot 		printf("'ps %d\n'vs %d\n", i, i+1);
1572199Sroot 		argc--, argv++;
1582199Sroot 		continue;
1592199Sroot 	    }
1601841Sroot 
1612199Sroot 	    /* specify the language */
1622199Sroot 	    if (!strncmp(argv[0], "-l", 2)) {
1632199Sroot 		language = argv[0]+2;
1642199Sroot 		argc--, argv++;
1652199Sroot 		continue;
1662199Sroot 	    }
1671841Sroot 
1682199Sroot 	    /* specify the language description file */
1692199Sroot 	    if (!strncmp(argv[0], "-d", 2)) {
1702199Sroot 		defsfile = argv[1];
1712199Sroot 		argc--, argv++;
1722199Sroot 		argc--, argv++;
1732199Sroot 		continue;
1742199Sroot 	    }
1751862Sroot 
1762199Sroot 	    /* open the file for input */
1772199Sroot 	    if (freopen(argv[0], "r", stdin) == NULL) {
1782199Sroot 		perror(argv[0]);
1792199Sroot 		exit(1);
1802199Sroot 	    }
1812199Sroot 	    if (index)
1822199Sroot 		printf("'ta 4i 4.25i 5.5iR\n'in .5i\n");
1832199Sroot 	    fname = argv[0];
1842199Sroot 	    argc--, argv++;
1852199Sroot 	}
1862199Sroot     rest:
1871862Sroot 
1882199Sroot 	/*
1892199Sroot 	 *  get the  language definition from the defs file
1902199Sroot 	 */
1912199Sroot 	i = tgetent (defs, language, defsfile);
1922199Sroot 	if (i == 0) {
1932199Sroot 	    fprintf (stderr, "no entry for language %s\n", language);
1942199Sroot 	    exit (0);
1952199Sroot 	} else  if (i < 0) {
1962199Sroot 	    fprintf (stderr,  "cannot find vgrindefs file %s\n", defsfile);
1972199Sroot 	    exit (0);
1982199Sroot 	}
1992199Sroot 	cp = strings;
2002199Sroot 	if (tgetstr ("kw", &cp) == NIL)
2012199Sroot 	    nokeyw = TRUE;
2022199Sroot 	else  {
2032199Sroot 	    char **cpp;
2041878Sroot 
2052199Sroot 	    cpp = l_keywds;
2062199Sroot 	    cp = strings;
2072199Sroot 	    while (*cp) {
2082199Sroot 		while (*cp == ' ' || *cp =='\t')
2092199Sroot 		    *cp++ = NULL;
2102199Sroot 		if (*cp)
2112199Sroot 		    *cpp++ = cp;
2122199Sroot 		while (*cp != ' ' && *cp  != '\t' && *cp)
2132199Sroot 		    cp++;
2142199Sroot 	    }
2152199Sroot 	    *cpp = NIL;
2162199Sroot 	}
2172199Sroot 	cp = buf;
2182199Sroot 	l_prcbeg = convexp (tgetstr ("pb", &cp));
2192199Sroot 	cp = buf;
2202199Sroot 	l_combeg = convexp (tgetstr ("cb", &cp));
2212199Sroot 	cp = buf;
2222199Sroot 	l_comend = convexp (tgetstr ("ce", &cp));
2232199Sroot 	cp = buf;
2243882Spresott 	l_acmbeg = convexp (tgetstr ("ab", &cp));
2253882Spresott 	cp = buf;
2263882Spresott 	l_acmend = convexp (tgetstr ("ae", &cp));
2273882Spresott 	cp = buf;
2282199Sroot 	l_strbeg = convexp (tgetstr ("sb", &cp));
2292199Sroot 	cp = buf;
2302199Sroot 	l_strend = convexp (tgetstr ("se", &cp));
2312199Sroot 	cp = buf;
2322199Sroot 	l_blkbeg = convexp (tgetstr ("bb", &cp));
2332199Sroot 	cp = buf;
2342199Sroot 	l_blkend = convexp (tgetstr ("be", &cp));
2352199Sroot 	cp = buf;
2362199Sroot 	l_chrbeg = convexp (tgetstr ("lb", &cp));
2372199Sroot 	cp = buf;
2382199Sroot 	l_chrend = convexp (tgetstr ("le", &cp));
2392199Sroot 	l_escape = '\\';
2402199Sroot 	l_onecase = tgetflag ("oc");
2412199Sroot 	l_toplex = tgetflag ("tl");
2423882Spresott 
2432199Sroot 	/* initialize the program */
2441878Sroot 
2452199Sroot 	incomm = FALSE;
2462199Sroot 	instr = FALSE;
2472199Sroot 	inchr = FALSE;
2482199Sroot 	_escaped = FALSE;
2492199Sroot 	blklevel = 0;
2502199Sroot 	for (psptr=0; psptr<PSMAX; psptr++) {
2512199Sroot 	    pstack[psptr][0] = NULL;
2522199Sroot 	    plstack[psptr] = 0;
2532199Sroot 	}
2542199Sroot 	psptr = -1;
2552199Sroot 	ps("'-F\n");
2562199Sroot 	if (!filter) {
2572199Sroot 	    printf(".ds =F %s\n", fname);
2582199Sroot 	    fstat(fileno(stdin), &stbuf);
2592199Sroot 	    cp = ctime(&stbuf.st_mtime);
2602199Sroot 	    cp[16] = '\0';
2612199Sroot 	    cp[24] = '\0';
2622199Sroot 	    printf(".ds =M %s %s\n", cp+4, cp+20);
2633393Spresott 	    ps("'wh 0 vH\n");
2643393Spresott 	    ps("'wh -1i vF\n");
2652199Sroot 	}
2662199Sroot 	if (needbp) {
2672199Sroot 	    needbp = 0;
2682199Sroot 	    printf(".()\n");
2692199Sroot 	    printf(".bp\n");
2702199Sroot 	}
2711878Sroot 
2722199Sroot 	/*
2732199Sroot 	 *	MAIN LOOP!!!
2742199Sroot 	 */
2752199Sroot 	while (fgets(buf, sizeof buf, stdin) != NULL) {
2762199Sroot 	    if (buf[0] == '\f') {
2772199Sroot 		printf(".bp\n");
2782199Sroot 	    }
2792199Sroot 	    if (buf[0] == '.') {
2802199Sroot 		printf("%s", buf);
2812199Sroot 		if (!strncmp (buf+1, "vS", 2))
2822199Sroot 		    pass = TRUE;
2832199Sroot 		if (!strncmp (buf+1, "vE", 2))
2842199Sroot 		    pass = FALSE;
2852199Sroot 		continue;
2862199Sroot 	    }
2872199Sroot 	    prccont = FALSE;
2882199Sroot 	    if (!filter || pass)
2892199Sroot 		putScp(buf);
2902199Sroot 	    else
2912199Sroot 		printf("%s", buf);
2922199Sroot 	    if (prccont && (psptr >= 0)) {
2932199Sroot 		ps("'FC ");
2942199Sroot 		ps(pstack[psptr]);
2952199Sroot 		ps("\n");
2962199Sroot 	    }
2972199Sroot #ifdef DEBUG
2982199Sroot 	    printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr);
2992199Sroot #endif
3002199Sroot 	    margin = 0;
3012199Sroot 	}
3022199Sroot 	needbp = 1;
3032199Sroot     } while (argc > 0);
3042199Sroot     exit(0);
3051841Sroot }
3061841Sroot 
3071841Sroot #define isidchr(c) (isalnum(c) || (c) == '_')
3081841Sroot 
3091841Sroot putScp(os)
3102199Sroot     char *os;
3111841Sroot {
3122199Sroot     register char *s = os;		/* pointer to unmatched string */
3132199Sroot     char dummy[BUFSIZ];			/* dummy to be used by expmatch */
3142199Sroot     char *comptr;			/* end of a comment delimiter */
3153882Spresott     char *acmptr;			/* end of a comment delimiter */
3162199Sroot     char *strptr;			/* end of a string delimiter */
3172199Sroot     char *chrptr;			/* end of a character const delimiter */
3182199Sroot     char *blksptr;			/* end of a lexical block start */
3192199Sroot     char *blkeptr;			/* end of a lexical block end */
3201841Sroot 
3212199Sroot     _start = os;			/* remember the start for expmatch */
3222199Sroot     _escaped = FALSE;
3232199Sroot     if (nokeyw || incomm || instr)
3242199Sroot 	goto skip;
3252199Sroot     if (isproc(s)) {
3262199Sroot 	ps("'FN ");
3272199Sroot 	ps(pname);
3282293Sroot         ps("\n");
3292199Sroot 	if (psptr < PSMAX) {
3302199Sroot 	    ++psptr;
3312199Sroot 	    strncpy (pstack[psptr], pname, PNAMELEN);
3322199Sroot 	    pstack[psptr][PNAMELEN] = NULL;
3332199Sroot 	    plstack[psptr] = blklevel;
3342199Sroot 	}
3352199Sroot     }
3361841Sroot skip:
3372199Sroot     do {
3382199Sroot 	/* check for string, comment, blockstart, etc */
3392199Sroot 	if (!incomm && !instr && !inchr) {
3402199Sroot 
3412199Sroot 	    blkeptr = expmatch (s, l_blkend, dummy);
3422199Sroot 	    blksptr = expmatch (s, l_blkbeg, dummy);
3432199Sroot 	    comptr = expmatch (s, l_combeg, dummy);
3443882Spresott 	    acmptr = expmatch (s, l_acmbeg, dummy);
3452199Sroot 	    strptr = expmatch (s, l_strbeg, dummy);
3462199Sroot 	    chrptr = expmatch (s, l_chrbeg, dummy);
3472199Sroot 
3482199Sroot 	    /* start of a comment? */
3492199Sroot 	    if (comptr != NIL)
3502199Sroot 		if ((comptr < strptr || strptr == NIL)
3513882Spresott 		  && (comptr < acmptr || acmptr == NIL)
3522199Sroot 		  && (comptr < chrptr || chrptr == NIL)
3532199Sroot 		  && (comptr < blksptr || blksptr == NIL)
3542199Sroot 		  && (comptr < blkeptr || blkeptr == NIL)) {
3552199Sroot 		    putKcp (s, comptr-1, FALSE);
3562199Sroot 		    s = comptr;
3572199Sroot 		    incomm = TRUE;
3583882Spresott 		    comtype = STANDARD;
3592199Sroot 		    if (s != os)
3602199Sroot 			ps ("\\c");
3612199Sroot 		    ps ("\\c\n'+C\n");
3622199Sroot 		    continue;
3631841Sroot 		}
3641878Sroot 
3653882Spresott 	    /* start of a comment? */
3663882Spresott 	    if (acmptr != NIL)
3673882Spresott 		if ((acmptr < strptr || strptr == NIL)
3683882Spresott 		  && (acmptr < chrptr || chrptr == NIL)
3693882Spresott 		  && (acmptr < blksptr || blksptr == NIL)
3703882Spresott 		  && (acmptr < blkeptr || blkeptr == NIL)) {
3713882Spresott 		    putKcp (s, acmptr-1, FALSE);
3723882Spresott 		    s = acmptr;
3733882Spresott 		    incomm = TRUE;
3743882Spresott 		    comtype = ALTERNATE;
3753882Spresott 		    if (s != os)
3763882Spresott 			ps ("\\c");
3773882Spresott 		    ps ("\\c\n'+C\n");
3783882Spresott 		    continue;
3793882Spresott 		}
3803882Spresott 
3812199Sroot 	    /* start of a string? */
3822199Sroot 	    if (strptr != NIL)
3832199Sroot 		if ((strptr < chrptr || chrptr == NIL)
3842212Sroot 		  && (strptr < blksptr || blksptr == NIL)
3852212Sroot 		  && (strptr < blkeptr || blkeptr == NIL)) {
3862199Sroot 		    putKcp (s, strptr-1, FALSE);
3872199Sroot 		    s = strptr;
3882199Sroot 		    instr = TRUE;
3892199Sroot 		    continue;
3902199Sroot 		}
3911878Sroot 
3922199Sroot 	    /* start of a character string? */
3932199Sroot 	    if (chrptr != NIL)
3942212Sroot 		if ((chrptr < blksptr || blksptr == NIL)
3952212Sroot 		  && (chrptr < blkeptr || blkeptr == NIL)) {
3962199Sroot 		    putKcp (s, chrptr-1, FALSE);
3972199Sroot 		    s = chrptr;
3982199Sroot 		    inchr = TRUE;
3992199Sroot 		    continue;
4001841Sroot 		}
4011878Sroot 
4022199Sroot 	    /* end of a lexical block */
4032199Sroot 	    if (blkeptr != NIL) {
4042199Sroot 		if (blkeptr < blksptr || blksptr == NIL) {
4052199Sroot 		    putKcp (s, blkeptr - 1, FALSE);
4062199Sroot 		    s = blkeptr;
4072199Sroot 		    blklevel--;
4082199Sroot 		    if (psptr >= 0 && plstack[psptr] >= blklevel) {
4091878Sroot 
4102199Sroot 			/* end of current procedure */
4111841Sroot 			if (s != os)
4122199Sroot 			    ps ("\\c");
4132199Sroot 			ps ("\\c\n'-F\n");
4142199Sroot 			blklevel = plstack[psptr];
4151878Sroot 
4162199Sroot 			/* see if we should print the last proc name */
4172199Sroot 			if (--psptr >= 0)
4182199Sroot 			    prccont = TRUE;
4192199Sroot 			else
4202199Sroot 			    psptr = -1;
4212199Sroot 		    }
4222199Sroot 		    continue;
4231841Sroot 		}
4242199Sroot 	    }
4251878Sroot 
4262199Sroot 	    /* start of a lexical block */
4272199Sroot 	    if (blksptr != NIL) {
4282199Sroot 		putKcp (s, blksptr - 1, FALSE);
4292199Sroot 		s = blksptr;
4302199Sroot 		blklevel++;
4312199Sroot 		continue;
4322199Sroot 	    }
4332199Sroot 
4342199Sroot 	/* check for end of comment */
4352199Sroot 	} else if (incomm) {
4363882Spresott 	    comptr = expmatch (s, l_comend, dummy);
4373882Spresott 	    acmptr = expmatch (s, l_acmend, dummy);
4383882Spresott 	    if (((comtype == STANDARD) && (comptr != NIL)) ||
4393882Spresott 	        ((comtype == ALTERNATE) && (acmptr != NIL))) {
4403882Spresott 		if (comtype == STANDARD) {
4413882Spresott 		    putKcp (s, comptr-1, TRUE);
4423882Spresott 		    s = comptr;
4433882Spresott 		} else {
4443882Spresott 		    putKcp (s, acmptr-1, TRUE);
4453882Spresott 		    s = acmptr;
4463882Spresott 		}
4472199Sroot 		incomm = FALSE;
4482199Sroot 		ps("\\c\n'-C\n");
4492199Sroot 		continue;
4502199Sroot 	    } else {
4512199Sroot 		putKcp (s, s + strlen(s) -1);
4522199Sroot 		s = s + strlen(s);
4532199Sroot 		continue;
4542199Sroot 	    }
4552199Sroot 
4562199Sroot 	/* check for end of string */
4572199Sroot 	} else if (instr) {
4582199Sroot 	    if ((strptr = expmatch (s, l_strend, dummy)) != NIL) {
4592199Sroot 		putKcp (s, strptr-1, TRUE);
4602199Sroot 		s = strptr;
4612199Sroot 		instr = FALSE;
4622199Sroot 		continue;
4632199Sroot 	    } else {
4642199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4652199Sroot 		s = s + strlen(s);
4662199Sroot 		continue;
4672199Sroot 	    }
4682199Sroot 
4692199Sroot 	/* check for end of character string */
4702199Sroot 	} else if (inchr) {
4712199Sroot 	    if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) {
4722199Sroot 		putKcp (s, chrptr-1, TRUE);
4732199Sroot 		s = chrptr;
4742199Sroot 		inchr = FALSE;
4752199Sroot 		continue;
4762199Sroot 	    } else {
4772199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4782199Sroot 		s = s + strlen(s);
4792199Sroot 		continue;
4802199Sroot 	    }
4811841Sroot 	}
4822199Sroot 
4832199Sroot 	/* print out the line */
4842199Sroot 	putKcp (s, s + strlen(s) -1, FALSE);
4852199Sroot 	s = s + strlen(s);
4862199Sroot     } while (*s);
4871841Sroot }
4881841Sroot 
4892199Sroot putKcp (start, end, force)
4902199Sroot     char	*start;		/* start of string to write */
4912199Sroot     char	*end;		/* end of string to write */
4922199Sroot     boolean	force;		/* true if we should force nokeyw */
4932199Sroot {
4942199Sroot     int i;
4952320Sroot     int xfld = 0;
4962199Sroot 
4972199Sroot     while (start <= end) {
4982320Sroot 	if (index) {
4992320Sroot 	    if (*start == ' ' || *start == '\t') {
5002320Sroot 		if (xfld == 0)
5012320Sroot 		    printf("");
5022320Sroot 		printf("\t");
5032320Sroot 		xfld = 1;
5042320Sroot 		while (*start == ' ' || *start == '\t')
5052320Sroot 		    start++;
5062320Sroot 		continue;
5072320Sroot 	    }
5082320Sroot 	}
5092199Sroot 
5102199Sroot 	/* take care of nice tab stops */
5112199Sroot 	if (*start == '\t') {
5122199Sroot 	    while (*start == '\t')
5132199Sroot 		start++;
5142199Sroot 	    i = tabs(_start, start) - margin / 8;
5152199Sroot 	    printf("\\h'|%dn'", i * 10 + 1 - margin % 8);
5162199Sroot 	    continue;
5172199Sroot 	}
5182199Sroot 
5192199Sroot 	if (!nokeyw && !force)
5202199Sroot 	    if ((*start == '#' || isidchr(*start))
5212199Sroot 	    && (start == _start || !isidchr(start[-1]))) {
5222199Sroot 		i = iskw(start);
5232199Sroot 		if (i > 0) {
5242199Sroot 		    ps("\\*(+K");
5252199Sroot 		    do
5262199Sroot 			putcp(*start++);
5272199Sroot 		    while (--i > 0);
5282199Sroot 		    ps("\\*(-K");
5292199Sroot 		    continue;
5302199Sroot 		}
5312199Sroot 	    }
5322199Sroot 
5332199Sroot 	putcp (*start++);
5342199Sroot     }
5352199Sroot }
5362199Sroot 
5372199Sroot 
5381841Sroot tabs(s, os)
5392199Sroot     char *s, *os;
5401841Sroot {
5411841Sroot 
5422199Sroot     return (width(s, os) / 8);
5431841Sroot }
5441841Sroot 
5451841Sroot width(s, os)
5461841Sroot 	register char *s, *os;
5471841Sroot {
5481841Sroot 	register int i = 0;
5491841Sroot 
5501841Sroot 	while (s < os) {
5511841Sroot 		if (*s == '\t') {
5521841Sroot 			i = (i + 8) &~ 7;
5531841Sroot 			s++;
5541841Sroot 			continue;
5551841Sroot 		}
5561841Sroot 		if (*s < ' ')
5571841Sroot 			i += 2;
5581841Sroot 		else
5591841Sroot 			i++;
5601841Sroot 		s++;
5611841Sroot 	}
5621841Sroot 	return (i);
5631841Sroot }
5641841Sroot 
5651841Sroot putcp(c)
5661841Sroot 	register int c;
5671841Sroot {
5681841Sroot 
5691841Sroot 	switch(c) {
5701841Sroot 
5712199Sroot 	case 0:
5722199Sroot 		break;
5732199Sroot 
5742199Sroot 	case '\f':
5752199Sroot 		break;
5762199Sroot 
5771841Sroot 	case '{':
5781841Sroot 		ps("\\*(+K{\\*(-K");
5791841Sroot 		break;
5801841Sroot 
5811841Sroot 	case '}':
5821841Sroot 		ps("\\*(+K}\\*(-K");
5831841Sroot 		break;
5841841Sroot 
5851841Sroot 	case '\\':
5861841Sroot 		ps("\\e");
5871841Sroot 		break;
5881841Sroot 
5891841Sroot 	case '_':
5901841Sroot 		ps("\\*_");
5911841Sroot 		break;
5921841Sroot 
5931841Sroot 	case '-':
5941841Sroot 		ps("\\*-");
5951841Sroot 		break;
5961841Sroot 
5971841Sroot 	case '`':
5981841Sroot 		ps("\\`");
5991841Sroot 		break;
6001841Sroot 
6011841Sroot 	case '\'':
6021841Sroot 		ps("\\'");
6031841Sroot 		break;
6041841Sroot 
6051841Sroot 	case '.':
6061841Sroot 		ps("\\&.");
6071841Sroot 		break;
6081841Sroot 
6092418Sroot 	case '*':
6102418Sroot 		ps("\\fI*\\fP");
6112418Sroot 		break;
6122418Sroot 
6132199Sroot 	case '/':
6142418Sroot 		ps("\\fI\\h'\\w' 'u-\\w'/'u'/\\fP");
6152199Sroot 		break;
6162199Sroot 
6171841Sroot 	default:
6181841Sroot 		if (c < 040)
6191841Sroot 			putchar('^'), c |= '@';
6201841Sroot 	case '\t':
6211841Sroot 	case '\n':
6221841Sroot 		putchar(c);
6231841Sroot 	}
6241841Sroot }
6251841Sroot 
6262199Sroot /*
6272199Sroot  *	look for a process beginning on this line
6281878Sroot  */
6292199Sroot boolean
6302199Sroot isproc(s)
6312199Sroot     char *s;
6321878Sroot {
6332199Sroot     pname[0] = NULL;
6342199Sroot     if (!l_toplex || blklevel == 0)
6352199Sroot 	if (expmatch (s, l_prcbeg, pname) != NIL) {
6362199Sroot 	    return (TRUE);
6372199Sroot 	}
6382199Sroot     return (FALSE);
6391878Sroot }
6401878Sroot 
6412199Sroot 
6421878Sroot /*  iskw -	check to see if the next word is a keyword
6431878Sroot  */
6441878Sroot 
6451841Sroot iskw(s)
6461841Sroot 	register char *s;
6471841Sroot {
6482199Sroot 	register char **ss = l_keywds;
6491841Sroot 	register int i = 1;
6501841Sroot 	register char *cp = s;
6511841Sroot 
6521841Sroot 	while (++cp, isidchr(*cp))
6531841Sroot 		i++;
6541841Sroot 	while (cp = *ss++)
6552199Sroot 		if (!STRNCMP(s,cp,i) && !isidchr(cp[i]))
6561841Sroot 			return (i);
6571841Sroot 	return (0);
6581841Sroot }
659