122065Sdist /* 236167Sbostic * Copyright (c) 1980 The Regents of the University of California. 336167Sbostic * All rights reserved. 436167Sbostic * 536167Sbostic * Redistribution and use in source and binary forms are permitted 636167Sbostic * provided that the above copyright notice and this paragraph are 736167Sbostic * duplicated in all such forms and that any documentation, 836167Sbostic * advertising materials, and other materials related to such 936167Sbostic * distribution and use acknowledge that the software was developed 1036167Sbostic * by the University of California, Berkeley. The name of the 1136167Sbostic * University may not be used to endorse or promote products derived 1236167Sbostic * from this software without specific prior written permission. 1336167Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1436167Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1536167Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622065Sdist */ 178760Smckusick 1822065Sdist #ifndef lint 1936167Sbostic char copyright[] = 2036167Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ 2136167Sbostic All rights reserved.\n"; 2236167Sbostic #endif /* not lint */ 2322065Sdist 2436167Sbostic #ifndef lint 25*37561Sbostic static char sccsid[] = "@(#)vfontedpr.c 5.4 (Berkeley) 05/01/89"; 2636167Sbostic #endif /* not lint */ 2736167Sbostic 28*37561Sbostic #include <sys/types.h> 29*37561Sbostic #include <sys/stat.h> 301841Sroot #include <ctype.h> 311841Sroot #include <stdio.h> 32*37561Sbostic #include "pathnames.h" 331841Sroot 342199Sroot #define boolean int 352199Sroot #define TRUE 1 362199Sroot #define FALSE 0 372199Sroot #define NIL 0 383882Spresott #define STANDARD 0 393882Spresott #define ALTERNATE 1 402199Sroot 411841Sroot /* 421841Sroot * Vfontedpr. 431841Sroot * 442199Sroot * Dave Presotto 1/12/81 (adapted from an earlier version by Bill Joy) 451862Sroot * 461841Sroot */ 471862Sroot 481862Sroot #define STRLEN 10 /* length of strings introducing things */ 491862Sroot #define PNAMELEN 40 /* length of a function/procedure name */ 502199Sroot #define PSMAX 20 /* size of procedure name stacking */ 511862Sroot 522199Sroot /* regular expression routines */ 531862Sroot 542199Sroot char *expmatch(); /* match a string to an expression */ 552199Sroot char *STRNCMP(); /* a different kindof strncmp */ 562199Sroot char *convexp(); /* convert expression to internal form */ 5717500Sralph char *tgetstr(); 581862Sroot 592199Sroot boolean isproc(); 601862Sroot 611862Sroot 622199Sroot char *ctime(); 631862Sroot 642199Sroot /* 652199Sroot * The state variables 662199Sroot */ 671862Sroot 682199Sroot boolean incomm; /* in a comment of the primary type */ 692199Sroot boolean instr; /* in a string constant */ 702199Sroot boolean inchr; /* in a string constant */ 712199Sroot boolean nokeyw = FALSE; /* no keywords being flagged */ 722199Sroot boolean index = FALSE; /* form an index */ 732199Sroot boolean filter = FALSE; /* act as a filter (like eqn) */ 742199Sroot boolean pass = FALSE; /* when acting as a filter, pass indicates 752199Sroot * whether we are currently processing 762199Sroot * input. 772199Sroot */ 782199Sroot boolean prccont; /* continue last procedure */ 793882Spresott int comtype; /* type of comment */ 802199Sroot int margin; 812199Sroot int psptr; /* the stack index of the current procedure */ 822199Sroot char pstack[PSMAX][PNAMELEN+1]; /* the procedure name stack */ 832199Sroot int plstack[PSMAX]; /* the procedure nesting level stack */ 842199Sroot int blklevel; /* current nesting level */ 85*37561Sbostic char *defsfile = _PATH_VGRINDEFS; /* name of language definitions file */ 862199Sroot char pname[BUFSIZ+1]; 871862Sroot 882199Sroot /* 892199Sroot * The language specific globals 902199Sroot */ 911862Sroot 922199Sroot char *language = "c"; /* the language indicator */ 932199Sroot char *l_keywds[BUFSIZ/2]; /* keyword table address */ 942199Sroot char *l_prcbeg; /* regular expr for procedure begin */ 952199Sroot char *l_combeg; /* string introducing a comment */ 962199Sroot char *l_comend; /* string ending a comment */ 973882Spresott char *l_acmbeg; /* string introducing a comment */ 983882Spresott char *l_acmend; /* string ending a comment */ 992199Sroot char *l_blkbeg; /* string begining of a block */ 1002199Sroot char *l_blkend; /* string ending a block */ 1012199Sroot char *l_strbeg; /* delimiter for string constant */ 1022199Sroot char *l_strend; /* delimiter for string constant */ 1032199Sroot char *l_chrbeg; /* delimiter for character constant */ 1042199Sroot char *l_chrend; /* delimiter for character constant */ 1052199Sroot char l_escape; /* character used to escape characters */ 1062199Sroot boolean l_toplex; /* procedures only defined at top lex level */ 1071878Sroot 1081862Sroot /* 1092199Sroot * global variables also used by expmatch 1101862Sroot */ 1112199Sroot boolean _escaped; /* if last character was an escape */ 1122199Sroot char *_start; /* start of the current string */ 1132199Sroot boolean l_onecase; /* upper and lower case are equivalent */ 1141862Sroot 1152199Sroot #define ps(x) printf("%s", x) 1161862Sroot 1172199Sroot main(argc, argv) 1182199Sroot int argc; 1192199Sroot char *argv[]; 1202199Sroot { 1212199Sroot int lineno; 1222199Sroot char *fname = ""; 1232199Sroot char *ptr; 1242199Sroot struct stat stbuf; 1252199Sroot char buf[BUFSIZ]; 1262199Sroot char strings[2 * BUFSIZ]; 1272199Sroot char defs[2 * BUFSIZ]; 1282199Sroot int needbp = 0; 1291862Sroot 1302199Sroot argc--, argv++; 1312199Sroot do { 1322199Sroot char *cp; 1332199Sroot int i; 1341878Sroot 1352199Sroot if (argc > 0) { 1362199Sroot if (!strcmp(argv[0], "-h")) { 1372199Sroot if (argc == 1) { 1382199Sroot printf("'ds =H\n"); 1392199Sroot argc = 0; 1402199Sroot goto rest; 1412199Sroot } 1422199Sroot printf("'ds =H %s\n", argv[1]); 1433393Spresott argc--, argv++; 1443393Spresott argc--, argv++; 1452199Sroot if (argc > 0) 1462199Sroot continue; 1472199Sroot goto rest; 1482199Sroot } 1491862Sroot 1502199Sroot /* act as a filter like eqn */ 1512199Sroot if (!strcmp(argv[0], "-f")) { 1522199Sroot filter++; 1532199Sroot argv[0] = argv[argc-1]; 1542199Sroot argv[argc-1] = "-"; 1552199Sroot continue; 1562199Sroot } 1571862Sroot 1582199Sroot /* take input from the standard place */ 1592199Sroot if (!strcmp(argv[0], "-")) { 1602199Sroot argc = 0; 1612199Sroot goto rest; 1622199Sroot } 1631878Sroot 1642199Sroot /* build an index */ 1652199Sroot if (!strcmp(argv[0], "-x")) { 1662199Sroot index++; 1672199Sroot argv[0] = "-n"; 1682199Sroot } 1691841Sroot 1702199Sroot /* indicate no keywords */ 1712199Sroot if (!strcmp(argv[0], "-n")) { 1722199Sroot nokeyw++; 1732199Sroot argc--, argv++; 1742199Sroot continue; 1752199Sroot } 1761862Sroot 1772199Sroot /* specify the font size */ 1782199Sroot if (!strncmp(argv[0], "-s", 2)) { 1792199Sroot i = 0; 1802199Sroot cp = argv[0] + 2; 1812199Sroot while (*cp) 1822199Sroot i = i * 10 + (*cp++ - '0'); 1832199Sroot printf("'ps %d\n'vs %d\n", i, i+1); 1842199Sroot argc--, argv++; 1852199Sroot continue; 1862199Sroot } 1871841Sroot 1882199Sroot /* specify the language */ 1892199Sroot if (!strncmp(argv[0], "-l", 2)) { 1902199Sroot language = argv[0]+2; 1912199Sroot argc--, argv++; 1922199Sroot continue; 1932199Sroot } 1941841Sroot 1952199Sroot /* specify the language description file */ 1962199Sroot if (!strncmp(argv[0], "-d", 2)) { 1972199Sroot defsfile = argv[1]; 1982199Sroot argc--, argv++; 1992199Sroot argc--, argv++; 2002199Sroot continue; 2012199Sroot } 2021862Sroot 2032199Sroot /* open the file for input */ 2042199Sroot if (freopen(argv[0], "r", stdin) == NULL) { 2052199Sroot perror(argv[0]); 2062199Sroot exit(1); 2072199Sroot } 2082199Sroot if (index) 2092199Sroot printf("'ta 4i 4.25i 5.5iR\n'in .5i\n"); 2102199Sroot fname = argv[0]; 2112199Sroot argc--, argv++; 2122199Sroot } 2132199Sroot rest: 2141862Sroot 2152199Sroot /* 2162199Sroot * get the language definition from the defs file 2172199Sroot */ 2182199Sroot i = tgetent (defs, language, defsfile); 2192199Sroot if (i == 0) { 2202199Sroot fprintf (stderr, "no entry for language %s\n", language); 2212199Sroot exit (0); 2222199Sroot } else if (i < 0) { 2232199Sroot fprintf (stderr, "cannot find vgrindefs file %s\n", defsfile); 2242199Sroot exit (0); 2252199Sroot } 2262199Sroot cp = strings; 2272199Sroot if (tgetstr ("kw", &cp) == NIL) 2282199Sroot nokeyw = TRUE; 2292199Sroot else { 2302199Sroot char **cpp; 2311878Sroot 2322199Sroot cpp = l_keywds; 2332199Sroot cp = strings; 2342199Sroot while (*cp) { 2352199Sroot while (*cp == ' ' || *cp =='\t') 2362199Sroot *cp++ = NULL; 2372199Sroot if (*cp) 2382199Sroot *cpp++ = cp; 2392199Sroot while (*cp != ' ' && *cp != '\t' && *cp) 2402199Sroot cp++; 2412199Sroot } 2422199Sroot *cpp = NIL; 2432199Sroot } 2442199Sroot cp = buf; 2452199Sroot l_prcbeg = convexp (tgetstr ("pb", &cp)); 2462199Sroot cp = buf; 2472199Sroot l_combeg = convexp (tgetstr ("cb", &cp)); 2482199Sroot cp = buf; 2492199Sroot l_comend = convexp (tgetstr ("ce", &cp)); 2502199Sroot cp = buf; 2513882Spresott l_acmbeg = convexp (tgetstr ("ab", &cp)); 2523882Spresott cp = buf; 2533882Spresott l_acmend = convexp (tgetstr ("ae", &cp)); 2543882Spresott cp = buf; 2552199Sroot l_strbeg = convexp (tgetstr ("sb", &cp)); 2562199Sroot cp = buf; 2572199Sroot l_strend = convexp (tgetstr ("se", &cp)); 2582199Sroot cp = buf; 2592199Sroot l_blkbeg = convexp (tgetstr ("bb", &cp)); 2602199Sroot cp = buf; 2612199Sroot l_blkend = convexp (tgetstr ("be", &cp)); 2622199Sroot cp = buf; 2632199Sroot l_chrbeg = convexp (tgetstr ("lb", &cp)); 2642199Sroot cp = buf; 2652199Sroot l_chrend = convexp (tgetstr ("le", &cp)); 2662199Sroot l_escape = '\\'; 2672199Sroot l_onecase = tgetflag ("oc"); 2682199Sroot l_toplex = tgetflag ("tl"); 2693882Spresott 2702199Sroot /* initialize the program */ 2711878Sroot 2722199Sroot incomm = FALSE; 2732199Sroot instr = FALSE; 2742199Sroot inchr = FALSE; 2752199Sroot _escaped = FALSE; 2762199Sroot blklevel = 0; 2772199Sroot for (psptr=0; psptr<PSMAX; psptr++) { 2782199Sroot pstack[psptr][0] = NULL; 2792199Sroot plstack[psptr] = 0; 2802199Sroot } 2812199Sroot psptr = -1; 2822199Sroot ps("'-F\n"); 2832199Sroot if (!filter) { 2842199Sroot printf(".ds =F %s\n", fname); 2853393Spresott ps("'wh 0 vH\n"); 2863393Spresott ps("'wh -1i vF\n"); 2872199Sroot } 2882199Sroot if (needbp) { 2892199Sroot needbp = 0; 2902199Sroot printf(".()\n"); 2912199Sroot printf(".bp\n"); 2922199Sroot } 29329570Sdonn if (!filter) { 29429570Sdonn fstat(fileno(stdin), &stbuf); 29529570Sdonn cp = ctime(&stbuf.st_mtime); 29629570Sdonn cp[16] = '\0'; 29729570Sdonn cp[24] = '\0'; 29829570Sdonn printf(".ds =M %s %s\n", cp+4, cp+20); 29929570Sdonn } 3001878Sroot 3012199Sroot /* 3022199Sroot * MAIN LOOP!!! 3032199Sroot */ 3042199Sroot while (fgets(buf, sizeof buf, stdin) != NULL) { 3052199Sroot if (buf[0] == '\f') { 3062199Sroot printf(".bp\n"); 3072199Sroot } 3082199Sroot if (buf[0] == '.') { 3092199Sroot printf("%s", buf); 3102199Sroot if (!strncmp (buf+1, "vS", 2)) 3112199Sroot pass = TRUE; 3122199Sroot if (!strncmp (buf+1, "vE", 2)) 3132199Sroot pass = FALSE; 3142199Sroot continue; 3152199Sroot } 3162199Sroot prccont = FALSE; 3172199Sroot if (!filter || pass) 3182199Sroot putScp(buf); 3192199Sroot else 3202199Sroot printf("%s", buf); 3212199Sroot if (prccont && (psptr >= 0)) { 3222199Sroot ps("'FC "); 3232199Sroot ps(pstack[psptr]); 3242199Sroot ps("\n"); 3252199Sroot } 3262199Sroot #ifdef DEBUG 3272199Sroot printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr); 3282199Sroot #endif 3292199Sroot margin = 0; 3302199Sroot } 3312199Sroot needbp = 1; 3322199Sroot } while (argc > 0); 3332199Sroot exit(0); 3341841Sroot } 3351841Sroot 3361841Sroot #define isidchr(c) (isalnum(c) || (c) == '_') 3371841Sroot 3381841Sroot putScp(os) 3392199Sroot char *os; 3401841Sroot { 3412199Sroot register char *s = os; /* pointer to unmatched string */ 3422199Sroot char dummy[BUFSIZ]; /* dummy to be used by expmatch */ 3432199Sroot char *comptr; /* end of a comment delimiter */ 3443882Spresott char *acmptr; /* end of a comment delimiter */ 3452199Sroot char *strptr; /* end of a string delimiter */ 3462199Sroot char *chrptr; /* end of a character const delimiter */ 3472199Sroot char *blksptr; /* end of a lexical block start */ 3482199Sroot char *blkeptr; /* end of a lexical block end */ 3491841Sroot 3502199Sroot _start = os; /* remember the start for expmatch */ 3512199Sroot _escaped = FALSE; 3522199Sroot if (nokeyw || incomm || instr) 3532199Sroot goto skip; 3542199Sroot if (isproc(s)) { 3552199Sroot ps("'FN "); 3562199Sroot ps(pname); 3572293Sroot ps("\n"); 3582199Sroot if (psptr < PSMAX) { 3592199Sroot ++psptr; 3602199Sroot strncpy (pstack[psptr], pname, PNAMELEN); 3612199Sroot pstack[psptr][PNAMELEN] = NULL; 3622199Sroot plstack[psptr] = blklevel; 3632199Sroot } 3642199Sroot } 3651841Sroot skip: 3662199Sroot do { 3672199Sroot /* check for string, comment, blockstart, etc */ 3682199Sroot if (!incomm && !instr && !inchr) { 3692199Sroot 3702199Sroot blkeptr = expmatch (s, l_blkend, dummy); 3712199Sroot blksptr = expmatch (s, l_blkbeg, dummy); 3722199Sroot comptr = expmatch (s, l_combeg, dummy); 3733882Spresott acmptr = expmatch (s, l_acmbeg, dummy); 3742199Sroot strptr = expmatch (s, l_strbeg, dummy); 3752199Sroot chrptr = expmatch (s, l_chrbeg, dummy); 3762199Sroot 3772199Sroot /* start of a comment? */ 3782199Sroot if (comptr != NIL) 3792199Sroot if ((comptr < strptr || strptr == NIL) 3803882Spresott && (comptr < acmptr || acmptr == NIL) 3812199Sroot && (comptr < chrptr || chrptr == NIL) 3822199Sroot && (comptr < blksptr || blksptr == NIL) 3832199Sroot && (comptr < blkeptr || blkeptr == NIL)) { 3842199Sroot putKcp (s, comptr-1, FALSE); 3852199Sroot s = comptr; 3862199Sroot incomm = TRUE; 3873882Spresott comtype = STANDARD; 3882199Sroot if (s != os) 3892199Sroot ps ("\\c"); 3902199Sroot ps ("\\c\n'+C\n"); 3912199Sroot continue; 3921841Sroot } 3931878Sroot 3943882Spresott /* start of a comment? */ 3953882Spresott if (acmptr != NIL) 3963882Spresott if ((acmptr < strptr || strptr == NIL) 3973882Spresott && (acmptr < chrptr || chrptr == NIL) 3983882Spresott && (acmptr < blksptr || blksptr == NIL) 3993882Spresott && (acmptr < blkeptr || blkeptr == NIL)) { 4003882Spresott putKcp (s, acmptr-1, FALSE); 4013882Spresott s = acmptr; 4023882Spresott incomm = TRUE; 4033882Spresott comtype = ALTERNATE; 4043882Spresott if (s != os) 4053882Spresott ps ("\\c"); 4063882Spresott ps ("\\c\n'+C\n"); 4073882Spresott continue; 4083882Spresott } 4093882Spresott 4102199Sroot /* start of a string? */ 4112199Sroot if (strptr != NIL) 4122199Sroot if ((strptr < chrptr || chrptr == NIL) 4132212Sroot && (strptr < blksptr || blksptr == NIL) 4142212Sroot && (strptr < blkeptr || blkeptr == NIL)) { 4152199Sroot putKcp (s, strptr-1, FALSE); 4162199Sroot s = strptr; 4172199Sroot instr = TRUE; 4182199Sroot continue; 4192199Sroot } 4201878Sroot 4212199Sroot /* start of a character string? */ 4222199Sroot if (chrptr != NIL) 4232212Sroot if ((chrptr < blksptr || blksptr == NIL) 4242212Sroot && (chrptr < blkeptr || blkeptr == NIL)) { 4252199Sroot putKcp (s, chrptr-1, FALSE); 4262199Sroot s = chrptr; 4272199Sroot inchr = TRUE; 4282199Sroot continue; 4291841Sroot } 4301878Sroot 4312199Sroot /* end of a lexical block */ 4322199Sroot if (blkeptr != NIL) { 4332199Sroot if (blkeptr < blksptr || blksptr == NIL) { 4342199Sroot putKcp (s, blkeptr - 1, FALSE); 4352199Sroot s = blkeptr; 4362199Sroot blklevel--; 4372199Sroot if (psptr >= 0 && plstack[psptr] >= blklevel) { 4381878Sroot 4392199Sroot /* end of current procedure */ 4401841Sroot if (s != os) 4412199Sroot ps ("\\c"); 4422199Sroot ps ("\\c\n'-F\n"); 4432199Sroot blklevel = plstack[psptr]; 4441878Sroot 4452199Sroot /* see if we should print the last proc name */ 4462199Sroot if (--psptr >= 0) 4472199Sroot prccont = TRUE; 4482199Sroot else 4492199Sroot psptr = -1; 4502199Sroot } 4512199Sroot continue; 4521841Sroot } 4532199Sroot } 4541878Sroot 4552199Sroot /* start of a lexical block */ 4562199Sroot if (blksptr != NIL) { 4572199Sroot putKcp (s, blksptr - 1, FALSE); 4582199Sroot s = blksptr; 4592199Sroot blklevel++; 4602199Sroot continue; 4612199Sroot } 4622199Sroot 4632199Sroot /* check for end of comment */ 4642199Sroot } else if (incomm) { 4653882Spresott comptr = expmatch (s, l_comend, dummy); 4663882Spresott acmptr = expmatch (s, l_acmend, dummy); 4673882Spresott if (((comtype == STANDARD) && (comptr != NIL)) || 4683882Spresott ((comtype == ALTERNATE) && (acmptr != NIL))) { 4693882Spresott if (comtype == STANDARD) { 4703882Spresott putKcp (s, comptr-1, TRUE); 4713882Spresott s = comptr; 4723882Spresott } else { 4733882Spresott putKcp (s, acmptr-1, TRUE); 4743882Spresott s = acmptr; 4753882Spresott } 4762199Sroot incomm = FALSE; 4772199Sroot ps("\\c\n'-C\n"); 4782199Sroot continue; 4792199Sroot } else { 48017500Sralph putKcp (s, s + strlen(s) -1, TRUE); 4812199Sroot s = s + strlen(s); 4822199Sroot continue; 4832199Sroot } 4842199Sroot 4852199Sroot /* check for end of string */ 4862199Sroot } else if (instr) { 4872199Sroot if ((strptr = expmatch (s, l_strend, dummy)) != NIL) { 4882199Sroot putKcp (s, strptr-1, TRUE); 4892199Sroot s = strptr; 4902199Sroot instr = FALSE; 4912199Sroot continue; 4922199Sroot } else { 4932199Sroot putKcp (s, s+strlen(s)-1, TRUE); 4942199Sroot s = s + strlen(s); 4952199Sroot continue; 4962199Sroot } 4972199Sroot 4982199Sroot /* check for end of character string */ 4992199Sroot } else if (inchr) { 5002199Sroot if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) { 5012199Sroot putKcp (s, chrptr-1, TRUE); 5022199Sroot s = chrptr; 5032199Sroot inchr = FALSE; 5042199Sroot continue; 5052199Sroot } else { 5062199Sroot putKcp (s, s+strlen(s)-1, TRUE); 5072199Sroot s = s + strlen(s); 5082199Sroot continue; 5092199Sroot } 5101841Sroot } 5112199Sroot 5122199Sroot /* print out the line */ 5132199Sroot putKcp (s, s + strlen(s) -1, FALSE); 5142199Sroot s = s + strlen(s); 5152199Sroot } while (*s); 5161841Sroot } 5171841Sroot 5182199Sroot putKcp (start, end, force) 5192199Sroot char *start; /* start of string to write */ 5202199Sroot char *end; /* end of string to write */ 5212199Sroot boolean force; /* true if we should force nokeyw */ 5222199Sroot { 5232199Sroot int i; 5242320Sroot int xfld = 0; 5252199Sroot 5262199Sroot while (start <= end) { 5272320Sroot if (index) { 5282320Sroot if (*start == ' ' || *start == '\t') { 5292320Sroot if (xfld == 0) 5302320Sroot printf(""); 5312320Sroot printf("\t"); 5322320Sroot xfld = 1; 5332320Sroot while (*start == ' ' || *start == '\t') 5342320Sroot start++; 5352320Sroot continue; 5362320Sroot } 5372320Sroot } 5382199Sroot 5392199Sroot /* take care of nice tab stops */ 5402199Sroot if (*start == '\t') { 5412199Sroot while (*start == '\t') 5422199Sroot start++; 5432199Sroot i = tabs(_start, start) - margin / 8; 5442199Sroot printf("\\h'|%dn'", i * 10 + 1 - margin % 8); 5452199Sroot continue; 5462199Sroot } 5472199Sroot 5482199Sroot if (!nokeyw && !force) 5492199Sroot if ((*start == '#' || isidchr(*start)) 5502199Sroot && (start == _start || !isidchr(start[-1]))) { 5512199Sroot i = iskw(start); 5522199Sroot if (i > 0) { 5532199Sroot ps("\\*(+K"); 5542199Sroot do 5552199Sroot putcp(*start++); 5562199Sroot while (--i > 0); 5572199Sroot ps("\\*(-K"); 5582199Sroot continue; 5592199Sroot } 5602199Sroot } 5612199Sroot 5622199Sroot putcp (*start++); 5632199Sroot } 5642199Sroot } 5652199Sroot 5662199Sroot 5671841Sroot tabs(s, os) 5682199Sroot char *s, *os; 5691841Sroot { 5701841Sroot 5712199Sroot return (width(s, os) / 8); 5721841Sroot } 5731841Sroot 5741841Sroot width(s, os) 5751841Sroot register char *s, *os; 5761841Sroot { 5771841Sroot register int i = 0; 5781841Sroot 5791841Sroot while (s < os) { 5801841Sroot if (*s == '\t') { 5811841Sroot i = (i + 8) &~ 7; 5821841Sroot s++; 5831841Sroot continue; 5841841Sroot } 5851841Sroot if (*s < ' ') 5861841Sroot i += 2; 5871841Sroot else 5881841Sroot i++; 5891841Sroot s++; 5901841Sroot } 5911841Sroot return (i); 5921841Sroot } 5931841Sroot 5941841Sroot putcp(c) 5951841Sroot register int c; 5961841Sroot { 5971841Sroot 5981841Sroot switch(c) { 5991841Sroot 6002199Sroot case 0: 6012199Sroot break; 6022199Sroot 6032199Sroot case '\f': 6042199Sroot break; 6052199Sroot 6061841Sroot case '{': 6071841Sroot ps("\\*(+K{\\*(-K"); 6081841Sroot break; 6091841Sroot 6101841Sroot case '}': 6111841Sroot ps("\\*(+K}\\*(-K"); 6121841Sroot break; 6131841Sroot 6141841Sroot case '\\': 6151841Sroot ps("\\e"); 6161841Sroot break; 6171841Sroot 6181841Sroot case '_': 6191841Sroot ps("\\*_"); 6201841Sroot break; 6211841Sroot 6221841Sroot case '-': 6231841Sroot ps("\\*-"); 6241841Sroot break; 6251841Sroot 6261841Sroot case '`': 6271841Sroot ps("\\`"); 6281841Sroot break; 6291841Sroot 6301841Sroot case '\'': 6311841Sroot ps("\\'"); 6321841Sroot break; 6331841Sroot 6341841Sroot case '.': 6351841Sroot ps("\\&."); 6361841Sroot break; 6371841Sroot 6382418Sroot case '*': 6392418Sroot ps("\\fI*\\fP"); 6402418Sroot break; 6412418Sroot 6422199Sroot case '/': 6432418Sroot ps("\\fI\\h'\\w' 'u-\\w'/'u'/\\fP"); 6442199Sroot break; 6452199Sroot 6461841Sroot default: 6471841Sroot if (c < 040) 6481841Sroot putchar('^'), c |= '@'; 6491841Sroot case '\t': 6501841Sroot case '\n': 6511841Sroot putchar(c); 6521841Sroot } 6531841Sroot } 6541841Sroot 6552199Sroot /* 6562199Sroot * look for a process beginning on this line 6571878Sroot */ 6582199Sroot boolean 6592199Sroot isproc(s) 6602199Sroot char *s; 6611878Sroot { 6622199Sroot pname[0] = NULL; 6632199Sroot if (!l_toplex || blklevel == 0) 6642199Sroot if (expmatch (s, l_prcbeg, pname) != NIL) { 6652199Sroot return (TRUE); 6662199Sroot } 6672199Sroot return (FALSE); 6681878Sroot } 6691878Sroot 6702199Sroot 6711878Sroot /* iskw - check to see if the next word is a keyword 6721878Sroot */ 6731878Sroot 6741841Sroot iskw(s) 6751841Sroot register char *s; 6761841Sroot { 6772199Sroot register char **ss = l_keywds; 6781841Sroot register int i = 1; 6791841Sroot register char *cp = s; 6801841Sroot 6811841Sroot while (++cp, isidchr(*cp)) 6821841Sroot i++; 6831841Sroot while (cp = *ss++) 6842199Sroot if (!STRNCMP(s,cp,i) && !isidchr(cp[i])) 6851841Sroot return (i); 6861841Sroot return (0); 6871841Sroot } 688