122065Sdist /* 2*36167Sbostic * Copyright (c) 1980 The Regents of the University of California. 3*36167Sbostic * All rights reserved. 4*36167Sbostic * 5*36167Sbostic * Redistribution and use in source and binary forms are permitted 6*36167Sbostic * provided that the above copyright notice and this paragraph are 7*36167Sbostic * duplicated in all such forms and that any documentation, 8*36167Sbostic * advertising materials, and other materials related to such 9*36167Sbostic * distribution and use acknowledge that the software was developed 10*36167Sbostic * by the University of California, Berkeley. The name of the 11*36167Sbostic * University may not be used to endorse or promote products derived 12*36167Sbostic * from this software without specific prior written permission. 13*36167Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*36167Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*36167Sbostic * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1622065Sdist */ 178760Smckusick 1822065Sdist #ifndef lint 19*36167Sbostic char copyright[] = 20*36167Sbostic "@(#) Copyright (c) 1980 The Regents of the University of California.\n\ 21*36167Sbostic All rights reserved.\n"; 22*36167Sbostic #endif /* not lint */ 2322065Sdist 24*36167Sbostic #ifndef lint 25*36167Sbostic static char sccsid[] = "@(#)vfontedpr.c 5.3 (Berkeley) 10/25/88"; 26*36167Sbostic #endif /* not lint */ 27*36167Sbostic 281841Sroot #include <ctype.h> 291841Sroot #include <stdio.h> 301841Sroot #include <sys/types.h> 311841Sroot #include <sys/stat.h> 321841Sroot 332199Sroot #define boolean int 342199Sroot #define TRUE 1 352199Sroot #define FALSE 0 362199Sroot #define NIL 0 373882Spresott #define STANDARD 0 383882Spresott #define ALTERNATE 1 392199Sroot 401841Sroot /* 411841Sroot * Vfontedpr. 421841Sroot * 432199Sroot * Dave Presotto 1/12/81 (adapted from an earlier version by Bill Joy) 441862Sroot * 451841Sroot */ 461862Sroot 471862Sroot #define STRLEN 10 /* length of strings introducing things */ 481862Sroot #define PNAMELEN 40 /* length of a function/procedure name */ 492199Sroot #define PSMAX 20 /* size of procedure name stacking */ 501862Sroot 512199Sroot /* regular expression routines */ 521862Sroot 532199Sroot char *expmatch(); /* match a string to an expression */ 542199Sroot char *STRNCMP(); /* a different kindof strncmp */ 552199Sroot char *convexp(); /* convert expression to internal form */ 5617500Sralph char *tgetstr(); 571862Sroot 582199Sroot boolean isproc(); 591862Sroot 601862Sroot 612199Sroot char *ctime(); 621862Sroot 632199Sroot /* 642199Sroot * The state variables 652199Sroot */ 661862Sroot 672199Sroot boolean incomm; /* in a comment of the primary type */ 682199Sroot boolean instr; /* in a string constant */ 692199Sroot boolean inchr; /* in a string constant */ 702199Sroot boolean nokeyw = FALSE; /* no keywords being flagged */ 712199Sroot boolean index = FALSE; /* form an index */ 722199Sroot boolean filter = FALSE; /* act as a filter (like eqn) */ 732199Sroot boolean pass = FALSE; /* when acting as a filter, pass indicates 742199Sroot * whether we are currently processing 752199Sroot * input. 762199Sroot */ 772199Sroot boolean prccont; /* continue last procedure */ 783882Spresott int comtype; /* type of comment */ 792199Sroot int margin; 802199Sroot int psptr; /* the stack index of the current procedure */ 812199Sroot char pstack[PSMAX][PNAMELEN+1]; /* the procedure name stack */ 822199Sroot int plstack[PSMAX]; /* the procedure nesting level stack */ 832199Sroot int blklevel; /* current nesting level */ 842199Sroot char *defsfile = "/usr/lib/vgrindefs"; /* name of language definitions file */ 852199Sroot char pname[BUFSIZ+1]; 861862Sroot 872199Sroot /* 882199Sroot * The language specific globals 892199Sroot */ 901862Sroot 912199Sroot char *language = "c"; /* the language indicator */ 922199Sroot char *l_keywds[BUFSIZ/2]; /* keyword table address */ 932199Sroot char *l_prcbeg; /* regular expr for procedure begin */ 942199Sroot char *l_combeg; /* string introducing a comment */ 952199Sroot char *l_comend; /* string ending a comment */ 963882Spresott char *l_acmbeg; /* string introducing a comment */ 973882Spresott char *l_acmend; /* string ending a comment */ 982199Sroot char *l_blkbeg; /* string begining of a block */ 992199Sroot char *l_blkend; /* string ending a block */ 1002199Sroot char *l_strbeg; /* delimiter for string constant */ 1012199Sroot char *l_strend; /* delimiter for string constant */ 1022199Sroot char *l_chrbeg; /* delimiter for character constant */ 1032199Sroot char *l_chrend; /* delimiter for character constant */ 1042199Sroot char l_escape; /* character used to escape characters */ 1052199Sroot boolean l_toplex; /* procedures only defined at top lex level */ 1061878Sroot 1071862Sroot /* 1082199Sroot * global variables also used by expmatch 1091862Sroot */ 1102199Sroot boolean _escaped; /* if last character was an escape */ 1112199Sroot char *_start; /* start of the current string */ 1122199Sroot boolean l_onecase; /* upper and lower case are equivalent */ 1131862Sroot 1142199Sroot #define ps(x) printf("%s", x) 1151862Sroot 1162199Sroot main(argc, argv) 1172199Sroot int argc; 1182199Sroot char *argv[]; 1192199Sroot { 1202199Sroot int lineno; 1212199Sroot char *fname = ""; 1222199Sroot char *ptr; 1232199Sroot struct stat stbuf; 1242199Sroot char buf[BUFSIZ]; 1252199Sroot char strings[2 * BUFSIZ]; 1262199Sroot char defs[2 * BUFSIZ]; 1272199Sroot int needbp = 0; 1281862Sroot 1292199Sroot argc--, argv++; 1302199Sroot do { 1312199Sroot char *cp; 1322199Sroot int i; 1331878Sroot 1342199Sroot if (argc > 0) { 1352199Sroot if (!strcmp(argv[0], "-h")) { 1362199Sroot if (argc == 1) { 1372199Sroot printf("'ds =H\n"); 1382199Sroot argc = 0; 1392199Sroot goto rest; 1402199Sroot } 1412199Sroot printf("'ds =H %s\n", argv[1]); 1423393Spresott argc--, argv++; 1433393Spresott argc--, argv++; 1442199Sroot if (argc > 0) 1452199Sroot continue; 1462199Sroot goto rest; 1472199Sroot } 1481862Sroot 1492199Sroot /* act as a filter like eqn */ 1502199Sroot if (!strcmp(argv[0], "-f")) { 1512199Sroot filter++; 1522199Sroot argv[0] = argv[argc-1]; 1532199Sroot argv[argc-1] = "-"; 1542199Sroot continue; 1552199Sroot } 1561862Sroot 1572199Sroot /* take input from the standard place */ 1582199Sroot if (!strcmp(argv[0], "-")) { 1592199Sroot argc = 0; 1602199Sroot goto rest; 1612199Sroot } 1621878Sroot 1632199Sroot /* build an index */ 1642199Sroot if (!strcmp(argv[0], "-x")) { 1652199Sroot index++; 1662199Sroot argv[0] = "-n"; 1672199Sroot } 1681841Sroot 1692199Sroot /* indicate no keywords */ 1702199Sroot if (!strcmp(argv[0], "-n")) { 1712199Sroot nokeyw++; 1722199Sroot argc--, argv++; 1732199Sroot continue; 1742199Sroot } 1751862Sroot 1762199Sroot /* specify the font size */ 1772199Sroot if (!strncmp(argv[0], "-s", 2)) { 1782199Sroot i = 0; 1792199Sroot cp = argv[0] + 2; 1802199Sroot while (*cp) 1812199Sroot i = i * 10 + (*cp++ - '0'); 1822199Sroot printf("'ps %d\n'vs %d\n", i, i+1); 1832199Sroot argc--, argv++; 1842199Sroot continue; 1852199Sroot } 1861841Sroot 1872199Sroot /* specify the language */ 1882199Sroot if (!strncmp(argv[0], "-l", 2)) { 1892199Sroot language = argv[0]+2; 1902199Sroot argc--, argv++; 1912199Sroot continue; 1922199Sroot } 1931841Sroot 1942199Sroot /* specify the language description file */ 1952199Sroot if (!strncmp(argv[0], "-d", 2)) { 1962199Sroot defsfile = argv[1]; 1972199Sroot argc--, argv++; 1982199Sroot argc--, argv++; 1992199Sroot continue; 2002199Sroot } 2011862Sroot 2022199Sroot /* open the file for input */ 2032199Sroot if (freopen(argv[0], "r", stdin) == NULL) { 2042199Sroot perror(argv[0]); 2052199Sroot exit(1); 2062199Sroot } 2072199Sroot if (index) 2082199Sroot printf("'ta 4i 4.25i 5.5iR\n'in .5i\n"); 2092199Sroot fname = argv[0]; 2102199Sroot argc--, argv++; 2112199Sroot } 2122199Sroot rest: 2131862Sroot 2142199Sroot /* 2152199Sroot * get the language definition from the defs file 2162199Sroot */ 2172199Sroot i = tgetent (defs, language, defsfile); 2182199Sroot if (i == 0) { 2192199Sroot fprintf (stderr, "no entry for language %s\n", language); 2202199Sroot exit (0); 2212199Sroot } else if (i < 0) { 2222199Sroot fprintf (stderr, "cannot find vgrindefs file %s\n", defsfile); 2232199Sroot exit (0); 2242199Sroot } 2252199Sroot cp = strings; 2262199Sroot if (tgetstr ("kw", &cp) == NIL) 2272199Sroot nokeyw = TRUE; 2282199Sroot else { 2292199Sroot char **cpp; 2301878Sroot 2312199Sroot cpp = l_keywds; 2322199Sroot cp = strings; 2332199Sroot while (*cp) { 2342199Sroot while (*cp == ' ' || *cp =='\t') 2352199Sroot *cp++ = NULL; 2362199Sroot if (*cp) 2372199Sroot *cpp++ = cp; 2382199Sroot while (*cp != ' ' && *cp != '\t' && *cp) 2392199Sroot cp++; 2402199Sroot } 2412199Sroot *cpp = NIL; 2422199Sroot } 2432199Sroot cp = buf; 2442199Sroot l_prcbeg = convexp (tgetstr ("pb", &cp)); 2452199Sroot cp = buf; 2462199Sroot l_combeg = convexp (tgetstr ("cb", &cp)); 2472199Sroot cp = buf; 2482199Sroot l_comend = convexp (tgetstr ("ce", &cp)); 2492199Sroot cp = buf; 2503882Spresott l_acmbeg = convexp (tgetstr ("ab", &cp)); 2513882Spresott cp = buf; 2523882Spresott l_acmend = convexp (tgetstr ("ae", &cp)); 2533882Spresott cp = buf; 2542199Sroot l_strbeg = convexp (tgetstr ("sb", &cp)); 2552199Sroot cp = buf; 2562199Sroot l_strend = convexp (tgetstr ("se", &cp)); 2572199Sroot cp = buf; 2582199Sroot l_blkbeg = convexp (tgetstr ("bb", &cp)); 2592199Sroot cp = buf; 2602199Sroot l_blkend = convexp (tgetstr ("be", &cp)); 2612199Sroot cp = buf; 2622199Sroot l_chrbeg = convexp (tgetstr ("lb", &cp)); 2632199Sroot cp = buf; 2642199Sroot l_chrend = convexp (tgetstr ("le", &cp)); 2652199Sroot l_escape = '\\'; 2662199Sroot l_onecase = tgetflag ("oc"); 2672199Sroot l_toplex = tgetflag ("tl"); 2683882Spresott 2692199Sroot /* initialize the program */ 2701878Sroot 2712199Sroot incomm = FALSE; 2722199Sroot instr = FALSE; 2732199Sroot inchr = FALSE; 2742199Sroot _escaped = FALSE; 2752199Sroot blklevel = 0; 2762199Sroot for (psptr=0; psptr<PSMAX; psptr++) { 2772199Sroot pstack[psptr][0] = NULL; 2782199Sroot plstack[psptr] = 0; 2792199Sroot } 2802199Sroot psptr = -1; 2812199Sroot ps("'-F\n"); 2822199Sroot if (!filter) { 2832199Sroot printf(".ds =F %s\n", fname); 2843393Spresott ps("'wh 0 vH\n"); 2853393Spresott ps("'wh -1i vF\n"); 2862199Sroot } 2872199Sroot if (needbp) { 2882199Sroot needbp = 0; 2892199Sroot printf(".()\n"); 2902199Sroot printf(".bp\n"); 2912199Sroot } 29229570Sdonn if (!filter) { 29329570Sdonn fstat(fileno(stdin), &stbuf); 29429570Sdonn cp = ctime(&stbuf.st_mtime); 29529570Sdonn cp[16] = '\0'; 29629570Sdonn cp[24] = '\0'; 29729570Sdonn printf(".ds =M %s %s\n", cp+4, cp+20); 29829570Sdonn } 2991878Sroot 3002199Sroot /* 3012199Sroot * MAIN LOOP!!! 3022199Sroot */ 3032199Sroot while (fgets(buf, sizeof buf, stdin) != NULL) { 3042199Sroot if (buf[0] == '\f') { 3052199Sroot printf(".bp\n"); 3062199Sroot } 3072199Sroot if (buf[0] == '.') { 3082199Sroot printf("%s", buf); 3092199Sroot if (!strncmp (buf+1, "vS", 2)) 3102199Sroot pass = TRUE; 3112199Sroot if (!strncmp (buf+1, "vE", 2)) 3122199Sroot pass = FALSE; 3132199Sroot continue; 3142199Sroot } 3152199Sroot prccont = FALSE; 3162199Sroot if (!filter || pass) 3172199Sroot putScp(buf); 3182199Sroot else 3192199Sroot printf("%s", buf); 3202199Sroot if (prccont && (psptr >= 0)) { 3212199Sroot ps("'FC "); 3222199Sroot ps(pstack[psptr]); 3232199Sroot ps("\n"); 3242199Sroot } 3252199Sroot #ifdef DEBUG 3262199Sroot printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr); 3272199Sroot #endif 3282199Sroot margin = 0; 3292199Sroot } 3302199Sroot needbp = 1; 3312199Sroot } while (argc > 0); 3322199Sroot exit(0); 3331841Sroot } 3341841Sroot 3351841Sroot #define isidchr(c) (isalnum(c) || (c) == '_') 3361841Sroot 3371841Sroot putScp(os) 3382199Sroot char *os; 3391841Sroot { 3402199Sroot register char *s = os; /* pointer to unmatched string */ 3412199Sroot char dummy[BUFSIZ]; /* dummy to be used by expmatch */ 3422199Sroot char *comptr; /* end of a comment delimiter */ 3433882Spresott char *acmptr; /* end of a comment delimiter */ 3442199Sroot char *strptr; /* end of a string delimiter */ 3452199Sroot char *chrptr; /* end of a character const delimiter */ 3462199Sroot char *blksptr; /* end of a lexical block start */ 3472199Sroot char *blkeptr; /* end of a lexical block end */ 3481841Sroot 3492199Sroot _start = os; /* remember the start for expmatch */ 3502199Sroot _escaped = FALSE; 3512199Sroot if (nokeyw || incomm || instr) 3522199Sroot goto skip; 3532199Sroot if (isproc(s)) { 3542199Sroot ps("'FN "); 3552199Sroot ps(pname); 3562293Sroot ps("\n"); 3572199Sroot if (psptr < PSMAX) { 3582199Sroot ++psptr; 3592199Sroot strncpy (pstack[psptr], pname, PNAMELEN); 3602199Sroot pstack[psptr][PNAMELEN] = NULL; 3612199Sroot plstack[psptr] = blklevel; 3622199Sroot } 3632199Sroot } 3641841Sroot skip: 3652199Sroot do { 3662199Sroot /* check for string, comment, blockstart, etc */ 3672199Sroot if (!incomm && !instr && !inchr) { 3682199Sroot 3692199Sroot blkeptr = expmatch (s, l_blkend, dummy); 3702199Sroot blksptr = expmatch (s, l_blkbeg, dummy); 3712199Sroot comptr = expmatch (s, l_combeg, dummy); 3723882Spresott acmptr = expmatch (s, l_acmbeg, dummy); 3732199Sroot strptr = expmatch (s, l_strbeg, dummy); 3742199Sroot chrptr = expmatch (s, l_chrbeg, dummy); 3752199Sroot 3762199Sroot /* start of a comment? */ 3772199Sroot if (comptr != NIL) 3782199Sroot if ((comptr < strptr || strptr == NIL) 3793882Spresott && (comptr < acmptr || acmptr == NIL) 3802199Sroot && (comptr < chrptr || chrptr == NIL) 3812199Sroot && (comptr < blksptr || blksptr == NIL) 3822199Sroot && (comptr < blkeptr || blkeptr == NIL)) { 3832199Sroot putKcp (s, comptr-1, FALSE); 3842199Sroot s = comptr; 3852199Sroot incomm = TRUE; 3863882Spresott comtype = STANDARD; 3872199Sroot if (s != os) 3882199Sroot ps ("\\c"); 3892199Sroot ps ("\\c\n'+C\n"); 3902199Sroot continue; 3911841Sroot } 3921878Sroot 3933882Spresott /* start of a comment? */ 3943882Spresott if (acmptr != NIL) 3953882Spresott if ((acmptr < strptr || strptr == NIL) 3963882Spresott && (acmptr < chrptr || chrptr == NIL) 3973882Spresott && (acmptr < blksptr || blksptr == NIL) 3983882Spresott && (acmptr < blkeptr || blkeptr == NIL)) { 3993882Spresott putKcp (s, acmptr-1, FALSE); 4003882Spresott s = acmptr; 4013882Spresott incomm = TRUE; 4023882Spresott comtype = ALTERNATE; 4033882Spresott if (s != os) 4043882Spresott ps ("\\c"); 4053882Spresott ps ("\\c\n'+C\n"); 4063882Spresott continue; 4073882Spresott } 4083882Spresott 4092199Sroot /* start of a string? */ 4102199Sroot if (strptr != NIL) 4112199Sroot if ((strptr < chrptr || chrptr == NIL) 4122212Sroot && (strptr < blksptr || blksptr == NIL) 4132212Sroot && (strptr < blkeptr || blkeptr == NIL)) { 4142199Sroot putKcp (s, strptr-1, FALSE); 4152199Sroot s = strptr; 4162199Sroot instr = TRUE; 4172199Sroot continue; 4182199Sroot } 4191878Sroot 4202199Sroot /* start of a character string? */ 4212199Sroot if (chrptr != NIL) 4222212Sroot if ((chrptr < blksptr || blksptr == NIL) 4232212Sroot && (chrptr < blkeptr || blkeptr == NIL)) { 4242199Sroot putKcp (s, chrptr-1, FALSE); 4252199Sroot s = chrptr; 4262199Sroot inchr = TRUE; 4272199Sroot continue; 4281841Sroot } 4291878Sroot 4302199Sroot /* end of a lexical block */ 4312199Sroot if (blkeptr != NIL) { 4322199Sroot if (blkeptr < blksptr || blksptr == NIL) { 4332199Sroot putKcp (s, blkeptr - 1, FALSE); 4342199Sroot s = blkeptr; 4352199Sroot blklevel--; 4362199Sroot if (psptr >= 0 && plstack[psptr] >= blklevel) { 4371878Sroot 4382199Sroot /* end of current procedure */ 4391841Sroot if (s != os) 4402199Sroot ps ("\\c"); 4412199Sroot ps ("\\c\n'-F\n"); 4422199Sroot blklevel = plstack[psptr]; 4431878Sroot 4442199Sroot /* see if we should print the last proc name */ 4452199Sroot if (--psptr >= 0) 4462199Sroot prccont = TRUE; 4472199Sroot else 4482199Sroot psptr = -1; 4492199Sroot } 4502199Sroot continue; 4511841Sroot } 4522199Sroot } 4531878Sroot 4542199Sroot /* start of a lexical block */ 4552199Sroot if (blksptr != NIL) { 4562199Sroot putKcp (s, blksptr - 1, FALSE); 4572199Sroot s = blksptr; 4582199Sroot blklevel++; 4592199Sroot continue; 4602199Sroot } 4612199Sroot 4622199Sroot /* check for end of comment */ 4632199Sroot } else if (incomm) { 4643882Spresott comptr = expmatch (s, l_comend, dummy); 4653882Spresott acmptr = expmatch (s, l_acmend, dummy); 4663882Spresott if (((comtype == STANDARD) && (comptr != NIL)) || 4673882Spresott ((comtype == ALTERNATE) && (acmptr != NIL))) { 4683882Spresott if (comtype == STANDARD) { 4693882Spresott putKcp (s, comptr-1, TRUE); 4703882Spresott s = comptr; 4713882Spresott } else { 4723882Spresott putKcp (s, acmptr-1, TRUE); 4733882Spresott s = acmptr; 4743882Spresott } 4752199Sroot incomm = FALSE; 4762199Sroot ps("\\c\n'-C\n"); 4772199Sroot continue; 4782199Sroot } else { 47917500Sralph putKcp (s, s + strlen(s) -1, TRUE); 4802199Sroot s = s + strlen(s); 4812199Sroot continue; 4822199Sroot } 4832199Sroot 4842199Sroot /* check for end of string */ 4852199Sroot } else if (instr) { 4862199Sroot if ((strptr = expmatch (s, l_strend, dummy)) != NIL) { 4872199Sroot putKcp (s, strptr-1, TRUE); 4882199Sroot s = strptr; 4892199Sroot instr = FALSE; 4902199Sroot continue; 4912199Sroot } else { 4922199Sroot putKcp (s, s+strlen(s)-1, TRUE); 4932199Sroot s = s + strlen(s); 4942199Sroot continue; 4952199Sroot } 4962199Sroot 4972199Sroot /* check for end of character string */ 4982199Sroot } else if (inchr) { 4992199Sroot if ((chrptr = expmatch (s, l_chrend, dummy)) != NIL) { 5002199Sroot putKcp (s, chrptr-1, TRUE); 5012199Sroot s = chrptr; 5022199Sroot inchr = FALSE; 5032199Sroot continue; 5042199Sroot } else { 5052199Sroot putKcp (s, s+strlen(s)-1, TRUE); 5062199Sroot s = s + strlen(s); 5072199Sroot continue; 5082199Sroot } 5091841Sroot } 5102199Sroot 5112199Sroot /* print out the line */ 5122199Sroot putKcp (s, s + strlen(s) -1, FALSE); 5132199Sroot s = s + strlen(s); 5142199Sroot } while (*s); 5151841Sroot } 5161841Sroot 5172199Sroot putKcp (start, end, force) 5182199Sroot char *start; /* start of string to write */ 5192199Sroot char *end; /* end of string to write */ 5202199Sroot boolean force; /* true if we should force nokeyw */ 5212199Sroot { 5222199Sroot int i; 5232320Sroot int xfld = 0; 5242199Sroot 5252199Sroot while (start <= end) { 5262320Sroot if (index) { 5272320Sroot if (*start == ' ' || *start == '\t') { 5282320Sroot if (xfld == 0) 5292320Sroot printf(""); 5302320Sroot printf("\t"); 5312320Sroot xfld = 1; 5322320Sroot while (*start == ' ' || *start == '\t') 5332320Sroot start++; 5342320Sroot continue; 5352320Sroot } 5362320Sroot } 5372199Sroot 5382199Sroot /* take care of nice tab stops */ 5392199Sroot if (*start == '\t') { 5402199Sroot while (*start == '\t') 5412199Sroot start++; 5422199Sroot i = tabs(_start, start) - margin / 8; 5432199Sroot printf("\\h'|%dn'", i * 10 + 1 - margin % 8); 5442199Sroot continue; 5452199Sroot } 5462199Sroot 5472199Sroot if (!nokeyw && !force) 5482199Sroot if ((*start == '#' || isidchr(*start)) 5492199Sroot && (start == _start || !isidchr(start[-1]))) { 5502199Sroot i = iskw(start); 5512199Sroot if (i > 0) { 5522199Sroot ps("\\*(+K"); 5532199Sroot do 5542199Sroot putcp(*start++); 5552199Sroot while (--i > 0); 5562199Sroot ps("\\*(-K"); 5572199Sroot continue; 5582199Sroot } 5592199Sroot } 5602199Sroot 5612199Sroot putcp (*start++); 5622199Sroot } 5632199Sroot } 5642199Sroot 5652199Sroot 5661841Sroot tabs(s, os) 5672199Sroot char *s, *os; 5681841Sroot { 5691841Sroot 5702199Sroot return (width(s, os) / 8); 5711841Sroot } 5721841Sroot 5731841Sroot width(s, os) 5741841Sroot register char *s, *os; 5751841Sroot { 5761841Sroot register int i = 0; 5771841Sroot 5781841Sroot while (s < os) { 5791841Sroot if (*s == '\t') { 5801841Sroot i = (i + 8) &~ 7; 5811841Sroot s++; 5821841Sroot continue; 5831841Sroot } 5841841Sroot if (*s < ' ') 5851841Sroot i += 2; 5861841Sroot else 5871841Sroot i++; 5881841Sroot s++; 5891841Sroot } 5901841Sroot return (i); 5911841Sroot } 5921841Sroot 5931841Sroot putcp(c) 5941841Sroot register int c; 5951841Sroot { 5961841Sroot 5971841Sroot switch(c) { 5981841Sroot 5992199Sroot case 0: 6002199Sroot break; 6012199Sroot 6022199Sroot case '\f': 6032199Sroot break; 6042199Sroot 6051841Sroot case '{': 6061841Sroot ps("\\*(+K{\\*(-K"); 6071841Sroot break; 6081841Sroot 6091841Sroot case '}': 6101841Sroot ps("\\*(+K}\\*(-K"); 6111841Sroot break; 6121841Sroot 6131841Sroot case '\\': 6141841Sroot ps("\\e"); 6151841Sroot break; 6161841Sroot 6171841Sroot case '_': 6181841Sroot ps("\\*_"); 6191841Sroot break; 6201841Sroot 6211841Sroot case '-': 6221841Sroot ps("\\*-"); 6231841Sroot break; 6241841Sroot 6251841Sroot case '`': 6261841Sroot ps("\\`"); 6271841Sroot break; 6281841Sroot 6291841Sroot case '\'': 6301841Sroot ps("\\'"); 6311841Sroot break; 6321841Sroot 6331841Sroot case '.': 6341841Sroot ps("\\&."); 6351841Sroot break; 6361841Sroot 6372418Sroot case '*': 6382418Sroot ps("\\fI*\\fP"); 6392418Sroot break; 6402418Sroot 6412199Sroot case '/': 6422418Sroot ps("\\fI\\h'\\w' 'u-\\w'/'u'/\\fP"); 6432199Sroot break; 6442199Sroot 6451841Sroot default: 6461841Sroot if (c < 040) 6471841Sroot putchar('^'), c |= '@'; 6481841Sroot case '\t': 6491841Sroot case '\n': 6501841Sroot putchar(c); 6511841Sroot } 6521841Sroot } 6531841Sroot 6542199Sroot /* 6552199Sroot * look for a process beginning on this line 6561878Sroot */ 6572199Sroot boolean 6582199Sroot isproc(s) 6592199Sroot char *s; 6601878Sroot { 6612199Sroot pname[0] = NULL; 6622199Sroot if (!l_toplex || blklevel == 0) 6632199Sroot if (expmatch (s, l_prcbeg, pname) != NIL) { 6642199Sroot return (TRUE); 6652199Sroot } 6662199Sroot return (FALSE); 6671878Sroot } 6681878Sroot 6692199Sroot 6701878Sroot /* iskw - check to see if the next word is a keyword 6711878Sroot */ 6721878Sroot 6731841Sroot iskw(s) 6741841Sroot register char *s; 6751841Sroot { 6762199Sroot register char **ss = l_keywds; 6771841Sroot register int i = 1; 6781841Sroot register char *cp = s; 6791841Sroot 6801841Sroot while (++cp, isidchr(*cp)) 6811841Sroot i++; 6821841Sroot while (cp = *ss++) 6832199Sroot if (!STRNCMP(s,cp,i) && !isidchr(cp[i])) 6841841Sroot return (i); 6851841Sroot return (0); 6861841Sroot } 687