vfontedpr.c revision 1.9 1 1.9 itojun /* $NetBSD: vfontedpr.c,v 1.9 2003/07/12 13:37:15 itojun Exp $ */
2 1.3 jtc
3 1.1 cgd /*
4 1.3 jtc * Copyright (c) 1980, 1993
5 1.3 jtc * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.1 cgd * 3. All advertising materials mentioning features or use of this software
16 1.1 cgd * must display the following acknowledgement:
17 1.1 cgd * This product includes software developed by the University of
18 1.1 cgd * California, Berkeley and its contributors.
19 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
20 1.1 cgd * may be used to endorse or promote products derived from this software
21 1.1 cgd * without specific prior written permission.
22 1.1 cgd *
23 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 cgd * SUCH DAMAGE.
34 1.1 cgd */
35 1.1 cgd
36 1.6 lukem #include <sys/cdefs.h>
37 1.1 cgd #ifndef lint
38 1.6 lukem __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
39 1.6 lukem The Regents of the University of California. All rights reserved.\n");
40 1.1 cgd #endif /* not lint */
41 1.1 cgd
42 1.1 cgd #ifndef lint
43 1.3 jtc #if 0
44 1.3 jtc static char sccsid[] = "@(#)vfontedpr.c 8.1 (Berkeley) 6/6/93";
45 1.3 jtc #endif
46 1.9 itojun __RCSID("$NetBSD: vfontedpr.c,v 1.9 2003/07/12 13:37:15 itojun Exp $");
47 1.1 cgd #endif /* not lint */
48 1.1 cgd
49 1.1 cgd #include <sys/types.h>
50 1.1 cgd #include <sys/stat.h>
51 1.3 jtc #include <time.h>
52 1.1 cgd #include <ctype.h>
53 1.3 jtc #include <stdlib.h>
54 1.3 jtc #include <string.h>
55 1.1 cgd #include <stdio.h>
56 1.1 cgd #include "pathnames.h"
57 1.3 jtc #include "extern.h"
58 1.1 cgd
59 1.1 cgd #define FALSE 0
60 1.3 jtc #define TRUE !(FALSE)
61 1.1 cgd #define NIL 0
62 1.1 cgd #define STANDARD 0
63 1.1 cgd #define ALTERNATE 1
64 1.1 cgd
65 1.1 cgd /*
66 1.1 cgd * Vfontedpr.
67 1.1 cgd *
68 1.1 cgd * Dave Presotto 1/12/81 (adapted from an earlier version by Bill Joy)
69 1.1 cgd *
70 1.1 cgd */
71 1.1 cgd
72 1.1 cgd #define STRLEN 10 /* length of strings introducing things */
73 1.1 cgd #define PNAMELEN 40 /* length of a function/procedure name */
74 1.1 cgd #define PSMAX 20 /* size of procedure name stacking */
75 1.1 cgd
76 1.3 jtc static int iskw __P((char *));
77 1.3 jtc static boolean isproc __P((char *));
78 1.3 jtc static void putKcp __P((char *, char *, boolean));
79 1.3 jtc static void putScp __P((char *));
80 1.3 jtc static void putcp __P((int));
81 1.3 jtc static int tabs __P((char *, char *));
82 1.3 jtc static int width __P((char *, char *));
83 1.1 cgd
84 1.1 cgd /*
85 1.1 cgd * The state variables
86 1.1 cgd */
87 1.1 cgd
88 1.3 jtc static boolean filter = FALSE; /* act as a filter (like eqn) */
89 1.3 jtc static boolean inchr; /* in a string constant */
90 1.3 jtc static boolean incomm; /* in a comment of the primary type */
91 1.3 jtc static boolean idx = FALSE; /* form an index */
92 1.3 jtc static boolean instr; /* in a string constant */
93 1.3 jtc static boolean nokeyw = FALSE; /* no keywords being flagged */
94 1.3 jtc static boolean pass = FALSE; /*
95 1.3 jtc * when acting as a filter, pass indicates
96 1.1 cgd * whether we are currently processing
97 1.1 cgd * input.
98 1.1 cgd */
99 1.3 jtc
100 1.3 jtc static int blklevel; /* current nesting level */
101 1.3 jtc static int comtype; /* type of comment */
102 1.3 jtc static char *defsfile[2] = { _PATH_VGRINDEFS, 0 };
103 1.3 jtc /* name of language definitions file */
104 1.3 jtc static int margin;
105 1.3 jtc static int plstack[PSMAX]; /* the procedure nesting level stack */
106 1.5 pk static char pname[BUFSIZ+1];
107 1.3 jtc static boolean prccont; /* continue last procedure */
108 1.3 jtc static int psptr; /* the stack index of the current procedure */
109 1.3 jtc static char pstack[PSMAX][PNAMELEN+1]; /* the procedure name stack */
110 1.1 cgd
111 1.1 cgd /*
112 1.1 cgd * The language specific globals
113 1.1 cgd */
114 1.1 cgd
115 1.1 cgd char *l_acmbeg; /* string introducing a comment */
116 1.1 cgd char *l_acmend; /* string ending a comment */
117 1.1 cgd char *l_blkbeg; /* string begining of a block */
118 1.1 cgd char *l_blkend; /* string ending a block */
119 1.3 jtc char *l_chrbeg; /* delimiter for character constant */
120 1.3 jtc char *l_chrend; /* delimiter for character constant */
121 1.3 jtc char *l_combeg; /* string introducing a comment */
122 1.3 jtc char *l_comend; /* string ending a comment */
123 1.3 jtc char l_escape; /* character used to escape characters */
124 1.3 jtc char *l_keywds[BUFSIZ/2]; /* keyword table address */
125 1.3 jtc char *l_prcbeg; /* regular expr for procedure begin */
126 1.1 cgd char *l_strbeg; /* delimiter for string constant */
127 1.1 cgd char *l_strend; /* delimiter for string constant */
128 1.3 jtc boolean l_toplex; /* procedures only defined at top lex level */
129 1.3 jtc char *language = "c"; /* the language indicator */
130 1.1 cgd
131 1.6 lukem int main __P((int, char **));
132 1.6 lukem
133 1.1 cgd #define ps(x) printf("%s", x)
134 1.1 cgd
135 1.4 jtc int
136 1.1 cgd main(argc, argv)
137 1.1 cgd int argc;
138 1.1 cgd char *argv[];
139 1.1 cgd {
140 1.1 cgd char *fname = "";
141 1.1 cgd struct stat stbuf;
142 1.1 cgd char buf[BUFSIZ];
143 1.3 jtc char *defs;
144 1.1 cgd int needbp = 0;
145 1.1 cgd
146 1.1 cgd argc--, argv++;
147 1.1 cgd do {
148 1.1 cgd char *cp;
149 1.1 cgd int i;
150 1.1 cgd
151 1.1 cgd if (argc > 0) {
152 1.1 cgd if (!strcmp(argv[0], "-h")) {
153 1.1 cgd if (argc == 1) {
154 1.1 cgd printf("'ds =H\n");
155 1.1 cgd argc = 0;
156 1.1 cgd goto rest;
157 1.1 cgd }
158 1.1 cgd printf("'ds =H %s\n", argv[1]);
159 1.1 cgd argc--, argv++;
160 1.1 cgd argc--, argv++;
161 1.1 cgd if (argc > 0)
162 1.1 cgd continue;
163 1.1 cgd goto rest;
164 1.1 cgd }
165 1.1 cgd
166 1.1 cgd /* act as a filter like eqn */
167 1.1 cgd if (!strcmp(argv[0], "-f")) {
168 1.1 cgd filter++;
169 1.1 cgd argv[0] = argv[argc-1];
170 1.1 cgd argv[argc-1] = "-";
171 1.1 cgd continue;
172 1.1 cgd }
173 1.1 cgd
174 1.1 cgd /* take input from the standard place */
175 1.1 cgd if (!strcmp(argv[0], "-")) {
176 1.1 cgd argc = 0;
177 1.1 cgd goto rest;
178 1.1 cgd }
179 1.1 cgd
180 1.1 cgd /* build an index */
181 1.1 cgd if (!strcmp(argv[0], "-x")) {
182 1.3 jtc idx++;
183 1.1 cgd argv[0] = "-n";
184 1.1 cgd }
185 1.1 cgd
186 1.1 cgd /* indicate no keywords */
187 1.1 cgd if (!strcmp(argv[0], "-n")) {
188 1.1 cgd nokeyw++;
189 1.1 cgd argc--, argv++;
190 1.1 cgd continue;
191 1.1 cgd }
192 1.1 cgd
193 1.1 cgd /* specify the font size */
194 1.1 cgd if (!strncmp(argv[0], "-s", 2)) {
195 1.1 cgd i = 0;
196 1.1 cgd cp = argv[0] + 2;
197 1.1 cgd while (*cp)
198 1.1 cgd i = i * 10 + (*cp++ - '0');
199 1.1 cgd printf("'ps %d\n'vs %d\n", i, i+1);
200 1.1 cgd argc--, argv++;
201 1.1 cgd continue;
202 1.1 cgd }
203 1.1 cgd
204 1.1 cgd /* specify the language */
205 1.1 cgd if (!strncmp(argv[0], "-l", 2)) {
206 1.1 cgd language = argv[0]+2;
207 1.1 cgd argc--, argv++;
208 1.1 cgd continue;
209 1.1 cgd }
210 1.1 cgd
211 1.1 cgd /* specify the language description file */
212 1.1 cgd if (!strncmp(argv[0], "-d", 2)) {
213 1.3 jtc defsfile[0] = argv[1];
214 1.1 cgd argc--, argv++;
215 1.1 cgd argc--, argv++;
216 1.1 cgd continue;
217 1.1 cgd }
218 1.1 cgd
219 1.1 cgd /* open the file for input */
220 1.1 cgd if (freopen(argv[0], "r", stdin) == NULL) {
221 1.1 cgd perror(argv[0]);
222 1.1 cgd exit(1);
223 1.1 cgd }
224 1.3 jtc if (idx)
225 1.1 cgd printf("'ta 4i 4.25i 5.5iR\n'in .5i\n");
226 1.1 cgd fname = argv[0];
227 1.1 cgd argc--, argv++;
228 1.1 cgd }
229 1.1 cgd rest:
230 1.1 cgd
231 1.1 cgd /*
232 1.1 cgd * get the language definition from the defs file
233 1.1 cgd */
234 1.3 jtc i = cgetent(&defs, defsfile, language);
235 1.3 jtc if (i == -1) {
236 1.1 cgd fprintf (stderr, "no entry for language %s\n", language);
237 1.9 itojun exit(0);
238 1.5 pk } else if (i == -2) { fprintf(stderr,
239 1.3 jtc "cannot find vgrindefs file %s\n", defsfile[0]);
240 1.9 itojun exit(0);
241 1.5 pk } else if (i == -3) { fprintf(stderr,
242 1.5 pk "potential reference loop detected in vgrindefs file %s\n",
243 1.5 pk defsfile[0]);
244 1.3 jtc exit(0);
245 1.1 cgd }
246 1.3 jtc if (cgetustr(defs, "kw", &cp) == -1)
247 1.1 cgd nokeyw = TRUE;
248 1.1 cgd else {
249 1.1 cgd char **cpp;
250 1.1 cgd
251 1.1 cgd cpp = l_keywds;
252 1.1 cgd while (*cp) {
253 1.1 cgd while (*cp == ' ' || *cp =='\t')
254 1.5 pk *cp++ = '\0';
255 1.1 cgd if (*cp)
256 1.1 cgd *cpp++ = cp;
257 1.1 cgd while (*cp != ' ' && *cp != '\t' && *cp)
258 1.1 cgd cp++;
259 1.1 cgd }
260 1.1 cgd *cpp = NIL;
261 1.1 cgd }
262 1.3 jtc cgetustr(defs, "pb", &cp);
263 1.3 jtc l_prcbeg = convexp(cp);
264 1.3 jtc cgetustr(defs, "cb", &cp);
265 1.3 jtc l_combeg = convexp(cp);
266 1.3 jtc cgetustr(defs, "ce", &cp);
267 1.3 jtc l_comend = convexp(cp);
268 1.3 jtc cgetustr(defs, "ab", &cp);
269 1.3 jtc l_acmbeg = convexp(cp);
270 1.3 jtc cgetustr(defs, "ae", &cp);
271 1.3 jtc l_acmend = convexp(cp);
272 1.3 jtc cgetustr(defs, "sb", &cp);
273 1.3 jtc l_strbeg = convexp(cp);
274 1.3 jtc cgetustr(defs, "se", &cp);
275 1.3 jtc l_strend = convexp(cp);
276 1.3 jtc cgetustr(defs, "bb", &cp);
277 1.3 jtc l_blkbeg = convexp(cp);
278 1.3 jtc cgetustr(defs, "be", &cp);
279 1.3 jtc l_blkend = convexp(cp);
280 1.3 jtc cgetustr(defs, "lb", &cp);
281 1.3 jtc l_chrbeg = convexp(cp);
282 1.3 jtc cgetustr(defs, "le", &cp);
283 1.3 jtc l_chrend = convexp(cp);
284 1.1 cgd l_escape = '\\';
285 1.3 jtc l_onecase = (cgetcap(defs, "oc", ':') != NULL);
286 1.3 jtc l_toplex = (cgetcap(defs, "tl", ':') != NULL);
287 1.1 cgd
288 1.1 cgd /* initialize the program */
289 1.1 cgd
290 1.1 cgd incomm = FALSE;
291 1.1 cgd instr = FALSE;
292 1.1 cgd inchr = FALSE;
293 1.7 christos x_escaped = FALSE;
294 1.1 cgd blklevel = 0;
295 1.1 cgd for (psptr=0; psptr<PSMAX; psptr++) {
296 1.5 pk pstack[psptr][0] = '\0';
297 1.1 cgd plstack[psptr] = 0;
298 1.1 cgd }
299 1.1 cgd psptr = -1;
300 1.1 cgd ps("'-F\n");
301 1.1 cgd if (!filter) {
302 1.1 cgd printf(".ds =F %s\n", fname);
303 1.1 cgd ps("'wh 0 vH\n");
304 1.1 cgd ps("'wh -1i vF\n");
305 1.1 cgd }
306 1.1 cgd if (needbp) {
307 1.1 cgd needbp = 0;
308 1.1 cgd printf(".()\n");
309 1.1 cgd printf(".bp\n");
310 1.1 cgd }
311 1.1 cgd if (!filter) {
312 1.1 cgd fstat(fileno(stdin), &stbuf);
313 1.1 cgd cp = ctime(&stbuf.st_mtime);
314 1.1 cgd cp[16] = '\0';
315 1.1 cgd cp[24] = '\0';
316 1.1 cgd printf(".ds =M %s %s\n", cp+4, cp+20);
317 1.1 cgd }
318 1.1 cgd
319 1.1 cgd /*
320 1.1 cgd * MAIN LOOP!!!
321 1.1 cgd */
322 1.1 cgd while (fgets(buf, sizeof buf, stdin) != NULL) {
323 1.1 cgd if (buf[0] == '\f') {
324 1.1 cgd printf(".bp\n");
325 1.1 cgd }
326 1.1 cgd if (buf[0] == '.') {
327 1.1 cgd printf("%s", buf);
328 1.1 cgd if (!strncmp (buf+1, "vS", 2))
329 1.1 cgd pass = TRUE;
330 1.1 cgd if (!strncmp (buf+1, "vE", 2))
331 1.1 cgd pass = FALSE;
332 1.1 cgd continue;
333 1.1 cgd }
334 1.1 cgd prccont = FALSE;
335 1.1 cgd if (!filter || pass)
336 1.1 cgd putScp(buf);
337 1.8 hubertf else {
338 1.8 hubertf char *s=buf;
339 1.8 hubertf while (*s) {
340 1.8 hubertf if ( *s == '\\' )
341 1.8 hubertf /* escape backslashes */
342 1.8 hubertf putchar('\\');
343 1.8 hubertf putchar(*s);
344 1.8 hubertf s++;
345 1.8 hubertf }
346 1.8 hubertf }
347 1.1 cgd if (prccont && (psptr >= 0)) {
348 1.1 cgd ps("'FC ");
349 1.1 cgd ps(pstack[psptr]);
350 1.1 cgd ps("\n");
351 1.1 cgd }
352 1.1 cgd #ifdef DEBUG
353 1.1 cgd printf ("com %o str %o chr %o ptr %d\n", incomm, instr, inchr, psptr);
354 1.1 cgd #endif
355 1.1 cgd margin = 0;
356 1.1 cgd }
357 1.1 cgd needbp = 1;
358 1.1 cgd } while (argc > 0);
359 1.1 cgd exit(0);
360 1.1 cgd }
361 1.1 cgd
362 1.7 christos #define isidchr(c) (isalnum((unsigned char)(c)) || (c) == '_')
363 1.1 cgd
364 1.3 jtc static void
365 1.1 cgd putScp(os)
366 1.1 cgd char *os;
367 1.1 cgd {
368 1.6 lukem char *s = os; /* pointer to unmatched string */
369 1.1 cgd char dummy[BUFSIZ]; /* dummy to be used by expmatch */
370 1.1 cgd char *comptr; /* end of a comment delimiter */
371 1.1 cgd char *acmptr; /* end of a comment delimiter */
372 1.1 cgd char *strptr; /* end of a string delimiter */
373 1.1 cgd char *chrptr; /* end of a character const delimiter */
374 1.1 cgd char *blksptr; /* end of a lexical block start */
375 1.1 cgd char *blkeptr; /* end of a lexical block end */
376 1.1 cgd
377 1.7 christos x_start = os; /* remember the start for expmatch */
378 1.7 christos x_escaped = FALSE;
379 1.1 cgd if (nokeyw || incomm || instr)
380 1.1 cgd goto skip;
381 1.1 cgd if (isproc(s)) {
382 1.1 cgd ps("'FN ");
383 1.1 cgd ps(pname);
384 1.1 cgd ps("\n");
385 1.1 cgd if (psptr < PSMAX) {
386 1.1 cgd ++psptr;
387 1.9 itojun strlcpy(pstack[psptr], pname, sizeof(pstack[psptr]));
388 1.1 cgd plstack[psptr] = blklevel;
389 1.1 cgd }
390 1.5 pk }
391 1.1 cgd skip:
392 1.1 cgd do {
393 1.1 cgd /* check for string, comment, blockstart, etc */
394 1.1 cgd if (!incomm && !instr && !inchr) {
395 1.1 cgd
396 1.9 itojun blkeptr = expmatch(s, l_blkend, dummy);
397 1.9 itojun blksptr = expmatch(s, l_blkbeg, dummy);
398 1.9 itojun comptr = expmatch(s, l_combeg, dummy);
399 1.9 itojun acmptr = expmatch(s, l_acmbeg, dummy);
400 1.9 itojun strptr = expmatch(s, l_strbeg, dummy);
401 1.9 itojun chrptr = expmatch(s, l_chrbeg, dummy);
402 1.1 cgd
403 1.1 cgd /* start of a comment? */
404 1.1 cgd if (comptr != NIL)
405 1.1 cgd if ((comptr < strptr || strptr == NIL)
406 1.1 cgd && (comptr < acmptr || acmptr == NIL)
407 1.1 cgd && (comptr < chrptr || chrptr == NIL)
408 1.1 cgd && (comptr < blksptr || blksptr == NIL)
409 1.1 cgd && (comptr < blkeptr || blkeptr == NIL)) {
410 1.9 itojun putKcp(s, comptr-1, FALSE);
411 1.1 cgd s = comptr;
412 1.1 cgd incomm = TRUE;
413 1.1 cgd comtype = STANDARD;
414 1.1 cgd if (s != os)
415 1.9 itojun ps("\\c");
416 1.9 itojun ps("\\c\n'+C\n");
417 1.1 cgd continue;
418 1.1 cgd }
419 1.1 cgd
420 1.1 cgd /* start of a comment? */
421 1.1 cgd if (acmptr != NIL)
422 1.1 cgd if ((acmptr < strptr || strptr == NIL)
423 1.1 cgd && (acmptr < chrptr || chrptr == NIL)
424 1.1 cgd && (acmptr < blksptr || blksptr == NIL)
425 1.1 cgd && (acmptr < blkeptr || blkeptr == NIL)) {
426 1.9 itojun putKcp(s, acmptr-1, FALSE);
427 1.1 cgd s = acmptr;
428 1.1 cgd incomm = TRUE;
429 1.1 cgd comtype = ALTERNATE;
430 1.1 cgd if (s != os)
431 1.9 itojun ps("\\c");
432 1.9 itojun ps("\\c\n'+C\n");
433 1.1 cgd continue;
434 1.1 cgd }
435 1.1 cgd
436 1.1 cgd /* start of a string? */
437 1.1 cgd if (strptr != NIL)
438 1.1 cgd if ((strptr < chrptr || chrptr == NIL)
439 1.1 cgd && (strptr < blksptr || blksptr == NIL)
440 1.1 cgd && (strptr < blkeptr || blkeptr == NIL)) {
441 1.9 itojun putKcp(s, strptr-1, FALSE);
442 1.1 cgd s = strptr;
443 1.1 cgd instr = TRUE;
444 1.1 cgd continue;
445 1.1 cgd }
446 1.1 cgd
447 1.1 cgd /* start of a character string? */
448 1.1 cgd if (chrptr != NIL)
449 1.1 cgd if ((chrptr < blksptr || blksptr == NIL)
450 1.1 cgd && (chrptr < blkeptr || blkeptr == NIL)) {
451 1.9 itojun putKcp(s, chrptr-1, FALSE);
452 1.1 cgd s = chrptr;
453 1.1 cgd inchr = TRUE;
454 1.1 cgd continue;
455 1.1 cgd }
456 1.1 cgd
457 1.1 cgd /* end of a lexical block */
458 1.1 cgd if (blkeptr != NIL) {
459 1.1 cgd if (blkeptr < blksptr || blksptr == NIL) {
460 1.9 itojun putKcp(s, blkeptr - 1, FALSE);
461 1.1 cgd s = blkeptr;
462 1.1 cgd blklevel--;
463 1.1 cgd if (psptr >= 0 && plstack[psptr] >= blklevel) {
464 1.1 cgd
465 1.1 cgd /* end of current procedure */
466 1.1 cgd if (s != os)
467 1.9 itojun ps("\\c");
468 1.9 itojun ps("\\c\n'-F\n");
469 1.1 cgd blklevel = plstack[psptr];
470 1.1 cgd
471 1.1 cgd /* see if we should print the last proc name */
472 1.1 cgd if (--psptr >= 0)
473 1.1 cgd prccont = TRUE;
474 1.1 cgd else
475 1.1 cgd psptr = -1;
476 1.1 cgd }
477 1.1 cgd continue;
478 1.1 cgd }
479 1.1 cgd }
480 1.1 cgd
481 1.1 cgd /* start of a lexical block */
482 1.1 cgd if (blksptr != NIL) {
483 1.9 itojun putKcp(s, blksptr - 1, FALSE);
484 1.1 cgd s = blksptr;
485 1.1 cgd blklevel++;
486 1.1 cgd continue;
487 1.1 cgd }
488 1.1 cgd
489 1.1 cgd /* check for end of comment */
490 1.1 cgd } else if (incomm) {
491 1.9 itojun comptr = expmatch(s, l_comend, dummy);
492 1.9 itojun acmptr = expmatch(s, l_acmend, dummy);
493 1.1 cgd if (((comtype == STANDARD) && (comptr != NIL)) ||
494 1.1 cgd ((comtype == ALTERNATE) && (acmptr != NIL))) {
495 1.1 cgd if (comtype == STANDARD) {
496 1.9 itojun putKcp(s, comptr-1, TRUE);
497 1.1 cgd s = comptr;
498 1.1 cgd } else {
499 1.9 itojun putKcp(s, acmptr-1, TRUE);
500 1.1 cgd s = acmptr;
501 1.1 cgd }
502 1.1 cgd incomm = FALSE;
503 1.1 cgd ps("\\c\n'-C\n");
504 1.1 cgd continue;
505 1.1 cgd } else {
506 1.9 itojun putKcp(s, s + strlen(s) -1, TRUE);
507 1.1 cgd s = s + strlen(s);
508 1.1 cgd continue;
509 1.1 cgd }
510 1.1 cgd
511 1.1 cgd /* check for end of string */
512 1.1 cgd } else if (instr) {
513 1.9 itojun if ((strptr = expmatch(s, l_strend, dummy)) != NIL) {
514 1.9 itojun putKcp(s, strptr-1, TRUE);
515 1.1 cgd s = strptr;
516 1.1 cgd instr = FALSE;
517 1.1 cgd continue;
518 1.1 cgd } else {
519 1.9 itojun putKcp(s, s+strlen(s)-1, TRUE);
520 1.1 cgd s = s + strlen(s);
521 1.1 cgd continue;
522 1.1 cgd }
523 1.1 cgd
524 1.1 cgd /* check for end of character string */
525 1.1 cgd } else if (inchr) {
526 1.9 itojun if ((chrptr = expmatch(s, l_chrend, dummy)) != NIL) {
527 1.9 itojun putKcp(s, chrptr-1, TRUE);
528 1.1 cgd s = chrptr;
529 1.1 cgd inchr = FALSE;
530 1.1 cgd continue;
531 1.1 cgd } else {
532 1.9 itojun putKcp(s, s+strlen(s)-1, TRUE);
533 1.1 cgd s = s + strlen(s);
534 1.1 cgd continue;
535 1.1 cgd }
536 1.1 cgd }
537 1.1 cgd
538 1.1 cgd /* print out the line */
539 1.9 itojun putKcp(s, s + strlen(s) -1, FALSE);
540 1.1 cgd s = s + strlen(s);
541 1.1 cgd } while (*s);
542 1.1 cgd }
543 1.1 cgd
544 1.3 jtc static void
545 1.9 itojun putKcp(start, end, force)
546 1.1 cgd char *start; /* start of string to write */
547 1.1 cgd char *end; /* end of string to write */
548 1.1 cgd boolean force; /* true if we should force nokeyw */
549 1.1 cgd {
550 1.1 cgd int i;
551 1.1 cgd int xfld = 0;
552 1.1 cgd
553 1.1 cgd while (start <= end) {
554 1.3 jtc if (idx) {
555 1.1 cgd if (*start == ' ' || *start == '\t') {
556 1.5 pk if (xfld == 0)
557 1.1 cgd printf("");
558 1.1 cgd printf("\t");
559 1.1 cgd xfld = 1;
560 1.1 cgd while (*start == ' ' || *start == '\t')
561 1.1 cgd start++;
562 1.1 cgd continue;
563 1.1 cgd }
564 1.1 cgd }
565 1.1 cgd
566 1.1 cgd /* take care of nice tab stops */
567 1.1 cgd if (*start == '\t') {
568 1.1 cgd while (*start == '\t')
569 1.1 cgd start++;
570 1.7 christos i = tabs(x_start, start) - margin / 8;
571 1.1 cgd printf("\\h'|%dn'", i * 10 + 1 - margin % 8);
572 1.1 cgd continue;
573 1.1 cgd }
574 1.1 cgd
575 1.1 cgd if (!nokeyw && !force)
576 1.5 pk if ((*start == '#' || isidchr(*start))
577 1.7 christos && (start == x_start || !isidchr(start[-1]))) {
578 1.1 cgd i = iskw(start);
579 1.1 cgd if (i > 0) {
580 1.1 cgd ps("\\*(+K");
581 1.5 pk do
582 1.1 cgd putcp(*start++);
583 1.1 cgd while (--i > 0);
584 1.1 cgd ps("\\*(-K");
585 1.1 cgd continue;
586 1.1 cgd }
587 1.1 cgd }
588 1.1 cgd
589 1.9 itojun putcp(*start++);
590 1.1 cgd }
591 1.1 cgd }
592 1.1 cgd
593 1.1 cgd
594 1.3 jtc static int
595 1.1 cgd tabs(s, os)
596 1.1 cgd char *s, *os;
597 1.1 cgd {
598 1.1 cgd
599 1.1 cgd return (width(s, os) / 8);
600 1.1 cgd }
601 1.1 cgd
602 1.3 jtc static int
603 1.1 cgd width(s, os)
604 1.6 lukem char *s, *os;
605 1.1 cgd {
606 1.6 lukem int i = 0;
607 1.1 cgd
608 1.1 cgd while (s < os) {
609 1.1 cgd if (*s == '\t') {
610 1.1 cgd i = (i + 8) &~ 7;
611 1.1 cgd s++;
612 1.1 cgd continue;
613 1.1 cgd }
614 1.1 cgd if (*s < ' ')
615 1.1 cgd i += 2;
616 1.1 cgd else
617 1.1 cgd i++;
618 1.1 cgd s++;
619 1.1 cgd }
620 1.1 cgd return (i);
621 1.1 cgd }
622 1.1 cgd
623 1.3 jtc static void
624 1.1 cgd putcp(c)
625 1.6 lukem int c;
626 1.1 cgd {
627 1.1 cgd
628 1.1 cgd switch(c) {
629 1.1 cgd
630 1.1 cgd case 0:
631 1.1 cgd break;
632 1.1 cgd
633 1.1 cgd case '\f':
634 1.1 cgd break;
635 1.1 cgd
636 1.1 cgd case '{':
637 1.1 cgd ps("\\*(+K{\\*(-K");
638 1.1 cgd break;
639 1.1 cgd
640 1.1 cgd case '}':
641 1.1 cgd ps("\\*(+K}\\*(-K");
642 1.1 cgd break;
643 1.1 cgd
644 1.1 cgd case '\\':
645 1.1 cgd ps("\\e");
646 1.1 cgd break;
647 1.1 cgd
648 1.1 cgd case '_':
649 1.1 cgd ps("\\*_");
650 1.1 cgd break;
651 1.1 cgd
652 1.1 cgd case '-':
653 1.1 cgd ps("\\*-");
654 1.1 cgd break;
655 1.1 cgd
656 1.1 cgd case '`':
657 1.1 cgd ps("\\`");
658 1.1 cgd break;
659 1.1 cgd
660 1.1 cgd case '\'':
661 1.1 cgd ps("\\'");
662 1.1 cgd break;
663 1.1 cgd
664 1.1 cgd case '.':
665 1.1 cgd ps("\\&.");
666 1.1 cgd break;
667 1.1 cgd
668 1.1 cgd case '*':
669 1.1 cgd ps("\\fI*\\fP");
670 1.1 cgd break;
671 1.1 cgd
672 1.1 cgd case '/':
673 1.1 cgd ps("\\fI\\h'\\w' 'u-\\w'/'u'/\\fP");
674 1.1 cgd break;
675 1.1 cgd
676 1.1 cgd default:
677 1.1 cgd if (c < 040)
678 1.1 cgd putchar('^'), c |= '@';
679 1.1 cgd case '\t':
680 1.1 cgd case '\n':
681 1.1 cgd putchar(c);
682 1.1 cgd }
683 1.1 cgd }
684 1.1 cgd
685 1.1 cgd /*
686 1.1 cgd * look for a process beginning on this line
687 1.1 cgd */
688 1.3 jtc static boolean
689 1.1 cgd isproc(s)
690 1.1 cgd char *s;
691 1.1 cgd {
692 1.5 pk pname[0] = '\0';
693 1.1 cgd if (!l_toplex || blklevel == 0)
694 1.9 itojun if (expmatch(s, l_prcbeg, pname) != NIL) {
695 1.1 cgd return (TRUE);
696 1.1 cgd }
697 1.1 cgd return (FALSE);
698 1.1 cgd }
699 1.1 cgd
700 1.1 cgd
701 1.1 cgd /* iskw - check to see if the next word is a keyword
702 1.1 cgd */
703 1.1 cgd
704 1.3 jtc static int
705 1.1 cgd iskw(s)
706 1.6 lukem char *s;
707 1.1 cgd {
708 1.6 lukem char **ss = l_keywds;
709 1.6 lukem int i = 1;
710 1.6 lukem char *cp = s;
711 1.1 cgd
712 1.7 christos /*###705 [cc] warning: subscript has type `char'%%%*/
713 1.1 cgd while (++cp, isidchr(*cp))
714 1.1 cgd i++;
715 1.6 lukem while ((cp = *ss++) != NULL)
716 1.7 christos /*###708 [cc] warning: subscript has type `char'%%%*/
717 1.1 cgd if (!STRNCMP(s,cp,i) && !isidchr(cp[i]))
718 1.1 cgd return (i);
719 1.1 cgd return (0);
720 1.1 cgd }
721 1.3 jtc
722