ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/mgfilt.c
Revision: 1.3
Committed: Thu May 11 20:17:31 1995 UTC (28 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +17 -3 lines
Log Message:
added default handling of undefined entities

File Contents

# Content
1 /* Copyright (c) 1995 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Filter MGF stream, removing entities that won't be understood
9 */
10
11 #include <stdio.h>
12 #include "parser.h"
13
14
15 int
16 put_entity(ac, av) /* general output routine */
17 register int ac;
18 register char **av;
19 {
20 while (ac-- > 0) {
21 fputs(*av++, stdout);
22 putchar(ac ? ' ' : '\n');
23 }
24 return(MG_OK);
25 }
26
27
28 main(argc, argv) /* first argument is understood entities, comma-sep. */
29 int argc;
30 char *argv[];
31 {
32 char *cp1, *cp2;
33 int i, en;
34
35 if (argc < 2) {
36 fprintf(stderr, "Usage: %s entity,list [file ..]\n", argv[0]);
37 exit(1);
38 }
39 for (cp1 = cp2 = argv[1]; *cp1; cp1 = cp2) {
40 while (*cp2) {
41 if (*cp2 == ',') {
42 *cp2++ = '\0';
43 break;
44 }
45 cp2++;
46 }
47 en = mg_entity(cp1);
48 if (en < 0) {
49 fprintf(stderr, "%s: %s: no such entity\n",
50 argv[0], cp1);
51 exit(1);
52 }
53 mg_ehand[en] = put_entity;
54 }
55 mg_init();
56 if (argc < 3) {
57 if (mg_load((char *)NULL) != MG_OK)
58 exit(1);
59 if (mg_nunknown)
60 printf("%s %s: %u unknown entities on input\n",
61 mg_ename[MG_E_COMMENT],
62 argv[0], mg_nunknown);
63 exit(0);
64 }
65 for (i = 2; i < argc; i++) {
66 if (mg_load(argv[i]) != MG_OK)
67 exit(1);
68 if (mg_nunknown) {
69 printf("%s %s: %u unknown entities\n",
70 mg_ename[MG_E_COMMENT],
71 argv[i], mg_nunknown);
72 mg_nunknown = 0;
73 }
74 }
75 exit(0);
76 }