xref: /csrg-svn/usr.bin/vgrind/vfontedpr.c (revision 22065)
1*22065Sdist /*
2*22065Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22065Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22065Sdist  * specifies the terms and conditions for redistribution.
5*22065Sdist  */
68760Smckusick 
7*22065Sdist #ifndef lint
8*22065Sdist static char sccsid[] = "@(#)vfontedpr.c	5.1 (Berkeley) 06/05/85";
9*22065Sdist #endif not lint
10*22065Sdist 
111841Sroot #include <ctype.h>
121841Sroot #include <stdio.h>
131841Sroot #include <sys/types.h>
141841Sroot #include <sys/stat.h>
151841Sroot 
162199Sroot #define boolean int
172199Sroot #define TRUE 1
182199Sroot #define FALSE 0
192199Sroot #define NIL 0
203882Spresott #define STANDARD 0
213882Spresott #define ALTERNATE 1
222199Sroot 
231841Sroot /*
241841Sroot  * Vfontedpr.
251841Sroot  *
262199Sroot  * Dave Presotto 1/12/81 (adapted from an earlier version by Bill Joy)
271862Sroot  *
281841Sroot  */
291862Sroot 
301862Sroot #define STRLEN 10		/* length of strings introducing things */
311862Sroot #define PNAMELEN 40		/* length of a function/procedure name */
322199Sroot #define PSMAX 20		/* size of procedure name stacking */
331862Sroot 
342199Sroot /* regular expression routines */
351862Sroot 
362199Sroot char	*expmatch();		/* match a string to an expression */
372199Sroot char	*STRNCMP();		/* a different kindof strncmp */
382199Sroot char	*convexp();		/* convert expression to internal form */
3917500Sralph char	*tgetstr();
401862Sroot 
412199Sroot boolean	isproc();
421862Sroot 
431862Sroot 
442199Sroot char	*ctime();
451862Sroot 
462199Sroot /*
472199Sroot  *	The state variables
482199Sroot  */
491862Sroot 
502199Sroot boolean	incomm;			/* in a comment of the primary type */
512199Sroot boolean	instr;			/* in a string constant */
522199Sroot boolean	inchr;			/* in a string constant */
532199Sroot boolean	nokeyw = FALSE;		/* no keywords being flagged */
542199Sroot boolean	index = FALSE;		/* form an index */
552199Sroot boolean filter = FALSE;		/* act as a filter (like eqn) */
562199Sroot boolean pass = FALSE;		/* when acting as a filter, pass indicates
572199Sroot 				 * whether we are currently processing
582199Sroot 				 * input.
592199Sroot 				 */
602199Sroot boolean prccont;		/* continue last procedure */
613882Spresott int	comtype;		/* type of comment */
622199Sroot int	margin;
632199Sroot int	psptr;			/* the stack index of the current procedure */
642199Sroot char	pstack[PSMAX][PNAMELEN+1];	/* the procedure name stack */
652199Sroot int	plstack[PSMAX];		/* the procedure nesting level stack */
662199Sroot int	blklevel;		/* current nesting level */
672199Sroot char	*defsfile = "/usr/lib/vgrindefs";	/* name of language definitions file */
682199Sroot char	pname[BUFSIZ+1];
691862Sroot 
702199Sroot /*
712199Sroot  *	The language specific globals
722199Sroot  */
731862Sroot 
742199Sroot char	*language = "c";	/* the language indicator */
752199Sroot char	*l_keywds[BUFSIZ/2];	/* keyword table address */
762199Sroot char	*l_prcbeg;		/* regular expr for procedure begin */
772199Sroot char	*l_combeg;		/* string introducing a comment */
782199Sroot char	*l_comend;		/* string ending a comment */
793882Spresott char	*l_acmbeg;		/* string introducing a comment */
803882Spresott char	*l_acmend;		/* string ending a comment */
812199Sroot char	*l_blkbeg;		/* string begining of a block */
822199Sroot char	*l_blkend;		/* string ending a block */
832199Sroot char    *l_strbeg;		/* delimiter for string constant */
842199Sroot char    *l_strend;		/* delimiter for string constant */
852199Sroot char    *l_chrbeg;		/* delimiter for character constant */
862199Sroot char    *l_chrend;		/* delimiter for character constant */
872199Sroot char	l_escape;		/* character used to  escape characters */
882199Sroot boolean	l_toplex;		/* procedures only defined at top lex level */
891878Sroot 
901862Sroot /*
912199Sroot  *  global variables also used by expmatch
921862Sroot  */
932199Sroot boolean _escaped;		/* if last character was an escape */
942199Sroot char *_start;			/* start of the current string */
952199Sroot boolean	l_onecase;		/* upper and lower case are equivalent */
961862Sroot 
972199Sroot #define	ps(x)	printf("%s", x)
981862Sroot 
992199Sroot main(argc, argv)
1002199Sroot     int argc;
1012199Sroot     char *argv[];
1022199Sroot {
1032199Sroot     int lineno;
1042199Sroot     char *fname = "";
1052199Sroot     char *ptr;
1062199Sroot     struct stat stbuf;
1072199Sroot     char buf[BUFSIZ];
1082199Sroot     char strings[2 * BUFSIZ];
1092199Sroot     char defs[2 * BUFSIZ];
1102199Sroot     int needbp = 0;
1111862Sroot 
1122199Sroot     argc--, argv++;
1132199Sroot     do {
1142199Sroot 	char *cp;
1152199Sroot 	int i;
1161878Sroot 
1172199Sroot 	if (argc > 0) {
1182199Sroot 	    if (!strcmp(argv[0], "-h")) {
1192199Sroot 		if (argc == 1) {
1202199Sroot 		    printf("'ds =H\n");
1212199Sroot 		    argc = 0;
1222199Sroot 		    goto rest;
1232199Sroot 		}
1242199Sroot 		printf("'ds =H %s\n", argv[1]);
1253393Spresott 		argc--, argv++;
1263393Spresott 		argc--, argv++;
1272199Sroot 		if (argc > 0)
1282199Sroot 		    continue;
1292199Sroot 		goto rest;
1302199Sroot 	    }
1311862Sroot 
1322199Sroot 	    /* act as a filter like eqn */
1332199Sroot 	    if (!strcmp(argv[0], "-f")) {
1342199Sroot 		filter++;
1352199Sroot 		argv[0] = argv[argc-1];
1362199Sroot 		argv[argc-1] = "-";
1372199Sroot 		continue;
1382199Sroot 	    }
1391862Sroot 
1402199Sroot 	    /* take input from the standard place */
1412199Sroot 	    if (!strcmp(argv[0], "-")) {
1422199Sroot 		argc = 0;
1432199Sroot 		goto rest;
1442199Sroot 	    }
1451878Sroot 
1462199Sroot 	    /* build an index */
1472199Sroot 	    if (!strcmp(argv[0], "-x")) {
1482199Sroot 		index++;
1492199Sroot 		argv[0] = "-n";
1502199Sroot 	    }
1511841Sroot 
1522199Sroot 	    /* indicate no keywords */
1532199Sroot 	    if (!strcmp(argv[0], "-n")) {
1542199Sroot 		nokeyw++;
1552199Sroot 		argc--, argv++;
1562199Sroot 		continue;
1572199Sroot 	    }
1581862Sroot 
1592199Sroot 	    /* specify the font size */
1602199Sroot 	    if (!strncmp(argv[0], "-s", 2)) {
1612199Sroot 		i = 0;
1622199Sroot 		cp = argv[0] + 2;
1632199Sroot 		while (*cp)
1642199Sroot 		    i = i * 10 + (*cp++ - '0');
1652199Sroot 		printf("'ps %d\n'vs %d\n", i, i+1);
1662199Sroot 		argc--, argv++;
1672199Sroot 		continue;
1682199Sroot 	    }
1691841Sroot 
1702199Sroot 	    /* specify the language */
1712199Sroot 	    if (!strncmp(argv[0], "-l", 2)) {
1722199Sroot 		language = argv[0]+2;
1732199Sroot 		argc--, argv++;
1742199Sroot 		continue;
1752199Sroot 	    }
1761841Sroot 
1772199Sroot 	    /* specify the language description file */
1782199Sroot 	    if (!strncmp(argv[0], "-d", 2)) {
1792199Sroot 		defsfile = argv[1];
1802199Sroot 		argc--, argv++;
1812199Sroot 		argc--, argv++;
1822199Sroot 		continue;
1832199Sroot 	    }
1841862Sroot 
1852199Sroot 	    /* open the file for input */
1862199Sroot 	    if (freopen(argv[0], "r", stdin) == NULL) {
1872199Sroot 		perror(argv[0]);
1882199Sroot 		exit(1);
1892199Sroot 	    }
1902199Sroot 	    if (index)
1912199Sroot 		printf("'ta 4i 4.25i 5.5iR\n'in .5i\n");
1922199Sroot 	    fname = argv[0];
1932199Sroot 	    argc--, argv++;
1942199Sroot 	}
1952199Sroot     rest:
1961862Sroot 
1972199Sroot 	/*
1982199Sroot 	 *  get the  language definition from the defs file
1992199Sroot 	 */
2002199Sroot 	i = tgetent (defs, language, defsfile);
2012199Sroot 	if (i == 0) {
2022199Sroot 	    fprintf (stderr, "no entry for language %s\n", language);
2032199Sroot 	    exit (0);
2042199Sroot 	} else  if (i < 0) {
2052199Sroot 	    fprintf (stderr,  "cannot find vgrindefs file %s\n", defsfile);
2062199Sroot 	    exit (0);
2072199Sroot 	}
2082199Sroot 	cp = strings;
2092199Sroot 	if (tgetstr ("kw", &cp) == NIL)
2102199Sroot 	    nokeyw = TRUE;
2112199Sroot 	else  {
2122199Sroot 	    char **cpp;
2131878Sroot 
2142199Sroot 	    cpp = l_keywds;
2152199Sroot 	    cp = strings;
2162199Sroot 	    while (*cp) {
2172199Sroot 		while (*cp == ' ' || *cp =='\t')
2182199Sroot 		    *cp++ = NULL;
2192199Sroot 		if (*cp)
2202199Sroot 		    *cpp++ = cp;
2212199Sroot 		while (*cp != ' ' && *cp  != '\t' && *cp)
2222199Sroot 		    cp++;
2232199Sroot 	    }
2242199Sroot 	    *cpp = NIL;
2252199Sroot 	}
2262199Sroot 	cp = buf;
2272199Sroot 	l_prcbeg = convexp (tgetstr ("pb", &cp));
2282199Sroot 	cp = buf;
2292199Sroot 	l_combeg = convexp (tgetstr ("cb", &cp));
2302199Sroot 	cp = buf;
2312199Sroot 	l_comend = convexp (tgetstr ("ce", &cp));
2322199Sroot 	cp = buf;
2333882Spresott 	l_acmbeg = convexp (tgetstr ("ab", &cp));
2343882Spresott 	cp = buf;
2353882Spresott 	l_acmend = convexp (tgetstr ("ae", &cp));
2363882Spresott 	cp = buf;
2372199Sroot 	l_strbeg = convexp (tgetstr ("sb", &cp));
2382199Sroot 	cp = buf;
2392199Sroot 	l_strend = convexp (tgetstr ("se", &cp));
2402199Sroot 	cp = buf;
2412199Sroot 	l_blkbeg = convexp (tgetstr ("bb", &cp));
2422199Sroot 	cp = buf;
2432199Sroot 	l_blkend = convexp (tgetstr ("be", &cp));
2442199Sroot 	cp = buf;
2452199Sroot 	l_chrbeg = convexp (tgetstr ("lb", &cp));
2462199Sroot 	cp = buf;
2472199Sroot 	l_chrend = convexp (tgetstr ("le", &cp));
2482199Sroot 	l_escape = '\\';
2492199Sroot 	l_onecase = tgetflag ("oc");
2502199Sroot 	l_toplex = tgetflag ("tl");
2513882Spresott 
2522199Sroot 	/* initialize the program */
2531878Sroot 
2542199Sroot 	incomm = FALSE;
2552199Sroot 	instr = FALSE;
2562199Sroot 	inchr = FALSE;
2572199Sroot 	_escaped = FALSE;
2582199Sroot 	blklevel = 0;
2592199Sroot 	for (psptr=0; psptr<PSMAX; psptr++) {
2602199Sroot 	    pstack[psptr][0] = NULL;
2612199Sroot 	    plstack[psptr] = 0;
2622199Sroot 	}
2632199Sroot 	psptr = -1;
2642199Sroot 	ps("'-F\n");
2652199Sroot 	if (!filter) {
2662199Sroot 	    printf(".ds =F %s\n", fname);
2672199Sroot 	    fstat(fileno(stdin), &stbuf);
2682199Sroot 	    cp = ctime(&stbuf.st_mtime);
2692199Sroot 	    cp[16] = '\0';
2702199Sroot 	    cp[24] = '\0';
2712199Sroot 	    printf(".ds =M %s %s\n", cp+4, cp+20);
2723393Spresott 	    ps("'wh 0 vH\n");
2733393Spresott 	    ps("'wh -1i vF\n");
2742199Sroot 	}
2752199Sroot 	if (needbp) {
2762199Sroot 	    needbp = 0;
2772199Sroot 	    printf(".()\n");
2782199Sroot 	    printf(".bp\n");
2792199Sroot 	}
2801878Sroot 
2812199Sroot 	/*
2822199Sroot 	 *	MAIN LOOP!!!
2832199Sroot 	 */
2842199Sroot 	while (fgets(buf, sizeof buf, stdin) != NULL) {
2852199Sroot 	    if (buf[0] == '\f') {
2862199Sroot 		printf(".bp\n");
2872199Sroot 	    }
2882199Sroot 	    if (buf[0] == '.') {
2892199Sroot 		printf("%s", buf);
2902199Sroot 		if (!strncmp (buf+1, "vS", 2))
2912199Sroot 		    pass = TRUE;
2922199Sroot 		if (!strncmp (buf+1, "vE", 2))
2932199Sroot 		    pass = FALSE;
2942199Sroot 		continue;
2952199Sroot 	    }
2962199Sroot 	    prccont = FALSE;
2972199Sroot 	    if (!filter || pass)
2982199Sroot 		putScp(buf);
2992199Sroot 	    else
3002199Sroot 		printf("%s", buf);
3012199Sroot 	    if (prccont && (psptr >= 0)) {
3022199Sroot 		ps("'FC ");
3032199Sroot 		ps(pstack[psptr]);
3042199Sroot 		ps("\n");
3052199Sroot 	    }
3062199Sroot #ifdef DEBUG
3072199Sroot 	    printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr);
3082199Sroot #endif
3092199Sroot 	    margin = 0;
3102199Sroot 	}
3112199Sroot 	needbp = 1;
3122199Sroot     } while (argc > 0);
3132199Sroot     exit(0);
3141841Sroot }
3151841Sroot 
3161841Sroot #define isidchr(c) (isalnum(c) || (c) == '_')
3171841Sroot 
3181841Sroot putScp(os)
3192199Sroot     char *os;
3201841Sroot {
3212199Sroot     register char *s = os;		/* pointer to unmatched string */
3222199Sroot     char dummy[BUFSIZ];			/* dummy to be used by expmatch */
3232199Sroot     char *comptr;			/* end of a comment delimiter */
3243882Spresott     char *acmptr;			/* end of a comment delimiter */
3252199Sroot     char *strptr;			/* end of a string delimiter */
3262199Sroot     char *chrptr;			/* end of a character const delimiter */
3272199Sroot     char *blksptr;			/* end of a lexical block start */
3282199Sroot     char *blkeptr;			/* end of a lexical block end */
3291841Sroot 
3302199Sroot     _start = os;			/* remember the start for expmatch */
3312199Sroot     _escaped = FALSE;
3322199Sroot     if (nokeyw || incomm || instr)
3332199Sroot 	goto skip;
3342199Sroot     if (isproc(s)) {
3352199Sroot 	ps("'FN ");
3362199Sroot 	ps(pname);
3372293Sroot         ps("\n");
3382199Sroot 	if (psptr < PSMAX) {
3392199Sroot 	    ++psptr;
3402199Sroot 	    strncpy (pstack[psptr], pname, PNAMELEN);
3412199Sroot 	    pstack[psptr][PNAMELEN] = NULL;
3422199Sroot 	    plstack[psptr] = blklevel;
3432199Sroot 	}
3442199Sroot     }
3451841Sroot skip:
3462199Sroot     do {
3472199Sroot 	/* check for string, comment, blockstart, etc */
3482199Sroot 	if (!incomm && !instr && !inchr) {
3492199Sroot 
3502199Sroot 	    blkeptr = expmatch (s, l_blkend, dummy);
3512199Sroot 	    blksptr = expmatch (s, l_blkbeg, dummy);
3522199Sroot 	    comptr = expmatch (s, l_combeg, dummy);
3533882Spresott 	    acmptr = expmatch (s, l_acmbeg, dummy);
3542199Sroot 	    strptr = expmatch (s, l_strbeg, dummy);
3552199Sroot 	    chrptr = expmatch (s, l_chrbeg, dummy);
3562199Sroot 
3572199Sroot 	    /* start of a comment? */
3582199Sroot 	    if (comptr != NIL)
3592199Sroot 		if ((comptr < strptr || strptr == NIL)
3603882Spresott 		  && (comptr < acmptr || acmptr == NIL)
3612199Sroot 		  && (comptr < chrptr || chrptr == NIL)
3622199Sroot 		  && (comptr < blksptr || blksptr == NIL)
3632199Sroot 		  && (comptr < blkeptr || blkeptr == NIL)) {
3642199Sroot 		    putKcp (s, comptr-1, FALSE);
3652199Sroot 		    s = comptr;
3662199Sroot 		    incomm = TRUE;
3673882Spresott 		    comtype = STANDARD;
3682199Sroot 		    if (s != os)
3692199Sroot 			ps ("\\c");
3702199Sroot 		    ps ("\\c\n'+C\n");
3712199Sroot 		    continue;
3721841Sroot 		}
3731878Sroot 
3743882Spresott 	    /* start of a comment? */
3753882Spresott 	    if (acmptr != NIL)
3763882Spresott 		if ((acmptr < strptr || strptr == NIL)
3773882Spresott 		  && (acmptr < chrptr || chrptr == NIL)
3783882Spresott 		  && (acmptr < blksptr || blksptr == NIL)
3793882Spresott 		  && (acmptr < blkeptr || blkeptr == NIL)) {
3803882Spresott 		    putKcp (s, acmptr-1, FALSE);
3813882Spresott 		    s = acmptr;
3823882Spresott 		    incomm = TRUE;
3833882Spresott 		    comtype = ALTERNATE;
3843882Spresott 		    if (s != os)
3853882Spresott 			ps ("\\c");
3863882Spresott 		    ps ("\\c\n'+C\n");
3873882Spresott 		    continue;
3883882Spresott 		}
3893882Spresott 
3902199Sroot 	    /* start of a string? */
3912199Sroot 	    if (strptr != NIL)
3922199Sroot 		if ((strptr < chrptr || chrptr == NIL)
3932212Sroot 		  && (strptr < blksptr || blksptr == NIL)
3942212Sroot 		  && (strptr < blkeptr || blkeptr == NIL)) {
3952199Sroot 		    putKcp (s, strptr-1, FALSE);
3962199Sroot 		    s = strptr;
3972199Sroot 		    instr = TRUE;
3982199Sroot 		    continue;
3992199Sroot 		}
4001878Sroot 
4012199Sroot 	    /* start of a character string? */
4022199Sroot 	    if (chrptr != NIL)
4032212Sroot 		if ((chrptr < blksptr || blksptr == NIL)
4042212Sroot 		  && (chrptr < blkeptr || blkeptr == NIL)) {
4052199Sroot 		    putKcp (s, chrptr-1, FALSE);
4062199Sroot 		    s = chrptr;
4072199Sroot 		    inchr = TRUE;
4082199Sroot 		    continue;
4091841Sroot 		}
4101878Sroot 
4112199Sroot 	    /* end of a lexical block */
4122199Sroot 	    if (blkeptr != NIL) {
4132199Sroot 		if (blkeptr < blksptr || blksptr == NIL) {
4142199Sroot 		    putKcp (s, blkeptr - 1, FALSE);
4152199Sroot 		    s = blkeptr;
4162199Sroot 		    blklevel--;
4172199Sroot 		    if (psptr >= 0 && plstack[psptr] >= blklevel) {
4181878Sroot 
4192199Sroot 			/* end of current procedure */
4201841Sroot 			if (s != os)
4212199Sroot 			    ps ("\\c");
4222199Sroot 			ps ("\\c\n'-F\n");
4232199Sroot 			blklevel = plstack[psptr];
4241878Sroot 
4252199Sroot 			/* see if we should print the last proc name */
4262199Sroot 			if (--psptr >= 0)
4272199Sroot 			    prccont = TRUE;
4282199Sroot 			else
4292199Sroot 			    psptr = -1;
4302199Sroot 		    }
4312199Sroot 		    continue;
4321841Sroot 		}
4332199Sroot 	    }
4341878Sroot 
4352199Sroot 	    /* start of a lexical block */
4362199Sroot 	    if (blksptr != NIL) {
4372199Sroot 		putKcp (s, blksptr - 1, FALSE);
4382199Sroot 		s = blksptr;
4392199Sroot 		blklevel++;
4402199Sroot 		continue;
4412199Sroot 	    }
4422199Sroot 
4432199Sroot 	/* check for end of comment */
4442199Sroot 	} else if (incomm) {
4453882Spresott 	    comptr = expmatch (s, l_comend, dummy);
4463882Spresott 	    acmptr = expmatch (s, l_acmend, dummy);
4473882Spresott 	    if (((comtype == STANDARD) && (comptr != NIL)) ||
4483882Spresott 	        ((comtype == ALTERNATE) && (acmptr != NIL))) {
4493882Spresott 		if (comtype == STANDARD) {
4503882Spresott 		    putKcp (s, comptr-1, TRUE);
4513882Spresott 		    s = comptr;
4523882Spresott 		} else {
4533882Spresott 		    putKcp (s, acmptr-1, TRUE);
4543882Spresott 		    s = acmptr;
4553882Spresott 		}
4562199Sroot 		incomm = FALSE;
4572199Sroot 		ps("\\c\n'-C\n");
4582199Sroot 		continue;
4592199Sroot 	    } else {
46017500Sralph 		putKcp (s, s + strlen(s) -1, TRUE);
4612199Sroot 		s = s + strlen(s);
4622199Sroot 		continue;
4632199Sroot 	    }
4642199Sroot 
4652199Sroot 	/* check for end of string */
4662199Sroot 	} else if (instr) {
4672199Sroot 	    if ((strptr = expmatch (s, l_strend, dummy)) != NIL) {
4682199Sroot 		putKcp (s, strptr-1, TRUE);
4692199Sroot 		s = strptr;
4702199Sroot 		instr = FALSE;
4712199Sroot 		continue;
4722199Sroot 	    } else {
4732199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4742199Sroot 		s = s + strlen(s);
4752199Sroot 		continue;
4762199Sroot 	    }
4772199Sroot 
4782199Sroot 	/* check for end of character string */
4792199Sroot 	} else if (inchr) {
4802199Sroot 	    if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) {
4812199Sroot 		putKcp (s, chrptr-1, TRUE);
4822199Sroot 		s = chrptr;
4832199Sroot 		inchr = FALSE;
4842199Sroot 		continue;
4852199Sroot 	    } else {
4862199Sroot 		putKcp (s, s+strlen(s)-1, TRUE);
4872199Sroot 		s = s + strlen(s);
4882199Sroot 		continue;
4892199Sroot 	    }
4901841Sroot 	}
4912199Sroot 
4922199Sroot 	/* print out the line */
4932199Sroot 	putKcp (s, s + strlen(s) -1, FALSE);
4942199Sroot 	s = s + strlen(s);
4952199Sroot     } while (*s);
4961841Sroot }
4971841Sroot 
4982199Sroot putKcp (start, end, force)
4992199Sroot     char	*start;		/* start of string to write */
5002199Sroot     char	*end;		/* end of string to write */
5012199Sroot     boolean	force;		/* true if we should force nokeyw */
5022199Sroot {
5032199Sroot     int i;
5042320Sroot     int xfld = 0;
5052199Sroot 
5062199Sroot     while (start <= end) {
5072320Sroot 	if (index) {
5082320Sroot 	    if (*start == ' ' || *start == '\t') {
5092320Sroot 		if (xfld == 0)
5102320Sroot 		    printf("");
5112320Sroot 		printf("\t");
5122320Sroot 		xfld = 1;
5132320Sroot 		while (*start == ' ' || *start == '\t')
5142320Sroot 		    start++;
5152320Sroot 		continue;
5162320Sroot 	    }
5172320Sroot 	}
5182199Sroot 
5192199Sroot 	/* take care of nice tab stops */
5202199Sroot 	if (*start == '\t') {
5212199Sroot 	    while (*start == '\t')
5222199Sroot 		start++;
5232199Sroot 	    i = tabs(_start, start) - margin / 8;
5242199Sroot 	    printf("\\h'|%dn'", i * 10 + 1 - margin % 8);
5252199Sroot 	    continue;
5262199Sroot 	}
5272199Sroot 
5282199Sroot 	if (!nokeyw && !force)
5292199Sroot 	    if ((*start == '#' || isidchr(*start))
5302199Sroot 	    && (start == _start || !isidchr(start[-1]))) {
5312199Sroot 		i = iskw(start);
5322199Sroot 		if (i > 0) {
5332199Sroot 		    ps("\\*(+K");
5342199Sroot 		    do
5352199Sroot 			putcp(*start++);
5362199Sroot 		    while (--i > 0);
5372199Sroot 		    ps("\\*(-K");
5382199Sroot 		    continue;
5392199Sroot 		}
5402199Sroot 	    }
5412199Sroot 
5422199Sroot 	putcp (*start++);
5432199Sroot     }
5442199Sroot }
5452199Sroot 
5462199Sroot 
5471841Sroot tabs(s, os)
5482199Sroot     char *s, *os;
5491841Sroot {
5501841Sroot 
5512199Sroot     return (width(s, os) / 8);
5521841Sroot }
5531841Sroot 
5541841Sroot width(s, os)
5551841Sroot 	register char *s, *os;
5561841Sroot {
5571841Sroot 	register int i = 0;
5581841Sroot 
5591841Sroot 	while (s < os) {
5601841Sroot 		if (*s == '\t') {
5611841Sroot 			i = (i + 8) &~ 7;
5621841Sroot 			s++;
5631841Sroot 			continue;
5641841Sroot 		}
5651841Sroot 		if (*s < ' ')
5661841Sroot 			i += 2;
5671841Sroot 		else
5681841Sroot 			i++;
5691841Sroot 		s++;
5701841Sroot 	}
5711841Sroot 	return (i);
5721841Sroot }
5731841Sroot 
5741841Sroot putcp(c)
5751841Sroot 	register int c;
5761841Sroot {
5771841Sroot 
5781841Sroot 	switch(c) {
5791841Sroot 
5802199Sroot 	case 0:
5812199Sroot 		break;
5822199Sroot 
5832199Sroot 	case '\f':
5842199Sroot 		break;
5852199Sroot 
5861841Sroot 	case '{':
5871841Sroot 		ps("\\*(+K{\\*(-K");
5881841Sroot 		break;
5891841Sroot 
5901841Sroot 	case '}':
5911841Sroot 		ps("\\*(+K}\\*(-K");
5921841Sroot 		break;
5931841Sroot 
5941841Sroot 	case '\\':
5951841Sroot 		ps("\\e");
5961841Sroot 		break;
5971841Sroot 
5981841Sroot 	case '_':
5991841Sroot 		ps("\\*_");
6001841Sroot 		break;
6011841Sroot 
6021841Sroot 	case '-':
6031841Sroot 		ps("\\*-");
6041841Sroot 		break;
6051841Sroot 
6061841Sroot 	case '`':
6071841Sroot 		ps("\\`");
6081841Sroot 		break;
6091841Sroot 
6101841Sroot 	case '\'':
6111841Sroot 		ps("\\'");
6121841Sroot 		break;
6131841Sroot 
6141841Sroot 	case '.':
6151841Sroot 		ps("\\&.");
6161841Sroot 		break;
6171841Sroot 
6182418Sroot 	case '*':
6192418Sroot 		ps("\\fI*\\fP");
6202418Sroot 		break;
6212418Sroot 
6222199Sroot 	case '/':
6232418Sroot 		ps("\\fI\\h'\\w' 'u-\\w'/'u'/\\fP");
6242199Sroot 		break;
6252199Sroot 
6261841Sroot 	default:
6271841Sroot 		if (c < 040)
6281841Sroot 			putchar('^'), c |= '@';
6291841Sroot 	case '\t':
6301841Sroot 	case '\n':
6311841Sroot 		putchar(c);
6321841Sroot 	}
6331841Sroot }
6341841Sroot 
6352199Sroot /*
6362199Sroot  *	look for a process beginning on this line
6371878Sroot  */
6382199Sroot boolean
6392199Sroot isproc(s)
6402199Sroot     char *s;
6411878Sroot {
6422199Sroot     pname[0] = NULL;
6432199Sroot     if (!l_toplex || blklevel == 0)
6442199Sroot 	if (expmatch (s, l_prcbeg, pname) != NIL) {
6452199Sroot 	    return (TRUE);
6462199Sroot 	}
6472199Sroot     return (FALSE);
6481878Sroot }
6491878Sroot 
6502199Sroot 
6511878Sroot /*  iskw -	check to see if the next word is a keyword
6521878Sroot  */
6531878Sroot 
6541841Sroot iskw(s)
6551841Sroot 	register char *s;
6561841Sroot {
6572199Sroot 	register char **ss = l_keywds;
6581841Sroot 	register int i = 1;
6591841Sroot 	register char *cp = s;
6601841Sroot 
6611841Sroot 	while (++cp, isidchr(*cp))
6621841Sroot 		i++;
6631841Sroot 	while (cp = *ss++)
6642199Sroot 		if (!STRNCMP(s,cp,i) && !isidchr(cp[i]))
6651841Sroot 			return (i);
6661841Sroot 	return (0);
6671841Sroot }
668