Blame


1 61f5c35c 2004-05-15 devnull /*
2 61f5c35c 2004-05-15 devnull *
3 61f5c35c 2004-05-15 devnull * Things used to handle special requests (eg. manual feed) globally or on a per
4 61f5c35c 2004-05-15 devnull * page basis. Requests are passed through to the translator using the -R option.
5 61f5c35c 2004-05-15 devnull * The argument to -R can be "request", "request:page", or "request:page:file".
6 61f5c35c 2004-05-15 devnull * If page is omitted (as in the first form) or set to 0 request will be applied
7 61f5c35c 2004-05-15 devnull * to the global environment. In all other cases it applies only to the selected
8 61f5c35c 2004-05-15 devnull * page. If a file is given, page must be supplied, and the lookup is in that file
9 61f5c35c 2004-05-15 devnull * rather than *requestfile.
10 61f5c35c 2004-05-15 devnull *
11 61f5c35c 2004-05-15 devnull */
12 61f5c35c 2004-05-15 devnull
13 61f5c35c 2004-05-15 devnull #include <stdio.h>
14 b855148c 2004-05-16 devnull #include <stdlib.h>
15 b855148c 2004-05-16 devnull #include <string.h>
16 b855148c 2004-05-16 devnull #include <unistd.h>
17 61f5c35c 2004-05-15 devnull
18 61f5c35c 2004-05-15 devnull #include "gen.h" /* general purpose definitions */
19 b855148c 2004-05-16 devnull #include "ext.h"
20 61f5c35c 2004-05-15 devnull #include "request.h" /* a few special definitions */
21 61f5c35c 2004-05-15 devnull #include "path.h" /* for the default request file */
22 61f5c35c 2004-05-15 devnull
23 61f5c35c 2004-05-15 devnull Request request[MAXREQUEST]; /* next page or global request */
24 61f5c35c 2004-05-15 devnull int nextreq = 0; /* goes in request[nextreq] */
25 61f5c35c 2004-05-15 devnull char *requestfile = REQUESTFILE; /* default lookup file */
26 61f5c35c 2004-05-15 devnull
27 e8fb1d3e 2004-05-17 devnull void dumprequest(char *want, char *file, FILE *fp_out);
28 e8fb1d3e 2004-05-17 devnull extern void error(int errtype, char *fmt, ...);
29 e8fb1d3e 2004-05-17 devnull
30 61f5c35c 2004-05-15 devnull /*****************************************************************************/
31 61f5c35c 2004-05-15 devnull
32 b855148c 2004-05-16 devnull void
33 61f5c35c 2004-05-15 devnull saverequest(want)
34 61f5c35c 2004-05-15 devnull
35 61f5c35c 2004-05-15 devnull char *want; /* grab code for this stuff */
36 61f5c35c 2004-05-15 devnull
37 61f5c35c 2004-05-15 devnull {
38 61f5c35c 2004-05-15 devnull
39 61f5c35c 2004-05-15 devnull char *page; /* and save it for this page */
40 61f5c35c 2004-05-15 devnull char *strtok();
41 61f5c35c 2004-05-15 devnull
42 61f5c35c 2004-05-15 devnull /*
43 61f5c35c 2004-05-15 devnull *
44 61f5c35c 2004-05-15 devnull * Save the request until we get to appropriate page - don't even bother with
45 61f5c35c 2004-05-15 devnull * the lookup right now. Format of *want string is "request", "request:page", or
46 61f5c35c 2004-05-15 devnull * "request:page:file", and we assume we can change the string here as needed.
47 61f5c35c 2004-05-15 devnull * If page is omitted or given as 0 the request will be done globally. If *want
48 61f5c35c 2004-05-15 devnull * includes a file, request and page must also be given, and in that case *file
49 61f5c35c 2004-05-15 devnull * will be used for the lookup.
50 61f5c35c 2004-05-15 devnull *
51 61f5c35c 2004-05-15 devnull */
52 61f5c35c 2004-05-15 devnull
53 61f5c35c 2004-05-15 devnull if ( nextreq < MAXREQUEST ) {
54 61f5c35c 2004-05-15 devnull request[nextreq].want = strtok(want, ": ");
55 61f5c35c 2004-05-15 devnull if ( (page = strtok(NULL, ": ")) == NULL )
56 61f5c35c 2004-05-15 devnull request[nextreq].page = 0;
57 61f5c35c 2004-05-15 devnull else request[nextreq].page = atoi(page);
58 61f5c35c 2004-05-15 devnull if ( (request[nextreq].file = strtok(NULL, ": ")) == NULL )
59 61f5c35c 2004-05-15 devnull request[nextreq].file = requestfile;
60 61f5c35c 2004-05-15 devnull nextreq++;
61 61f5c35c 2004-05-15 devnull } else error(NON_FATAL, "too many requests - ignoring %s", want);
62 61f5c35c 2004-05-15 devnull
63 61f5c35c 2004-05-15 devnull } /* End of saverequest */
64 61f5c35c 2004-05-15 devnull
65 61f5c35c 2004-05-15 devnull /*****************************************************************************/
66 b855148c 2004-05-16 devnull extern void dumprequest();
67 61f5c35c 2004-05-15 devnull
68 b855148c 2004-05-16 devnull void
69 61f5c35c 2004-05-15 devnull writerequest(page, fp_out)
70 61f5c35c 2004-05-15 devnull
71 61f5c35c 2004-05-15 devnull int page; /* write everything for this page */
72 61f5c35c 2004-05-15 devnull FILE *fp_out; /* to this file */
73 61f5c35c 2004-05-15 devnull
74 61f5c35c 2004-05-15 devnull {
75 61f5c35c 2004-05-15 devnull
76 61f5c35c 2004-05-15 devnull int i; /* loop index */
77 61f5c35c 2004-05-15 devnull
78 61f5c35c 2004-05-15 devnull /*
79 61f5c35c 2004-05-15 devnull *
80 61f5c35c 2004-05-15 devnull * Writes out all the requests that have been saved for page. Page 0 refers to
81 61f5c35c 2004-05-15 devnull * the global environment and is done during initial setup.
82 61f5c35c 2004-05-15 devnull *
83 61f5c35c 2004-05-15 devnull */
84 61f5c35c 2004-05-15 devnull
85 61f5c35c 2004-05-15 devnull for ( i = 0; i < nextreq; i++ )
86 61f5c35c 2004-05-15 devnull if ( request[i].page == page )
87 61f5c35c 2004-05-15 devnull dumprequest(request[i].want, request[i].file, fp_out);
88 61f5c35c 2004-05-15 devnull
89 61f5c35c 2004-05-15 devnull } /* End of writerequest */
90 61f5c35c 2004-05-15 devnull
91 61f5c35c 2004-05-15 devnull /*****************************************************************************/
92 61f5c35c 2004-05-15 devnull
93 b855148c 2004-05-16 devnull void
94 61f5c35c 2004-05-15 devnull dumprequest(want, file, fp_out)
95 61f5c35c 2004-05-15 devnull
96 61f5c35c 2004-05-15 devnull char *want; /* look for this string */
97 61f5c35c 2004-05-15 devnull char *file; /* in this file */
98 61f5c35c 2004-05-15 devnull FILE *fp_out; /* and write the value out here */
99 61f5c35c 2004-05-15 devnull
100 61f5c35c 2004-05-15 devnull {
101 61f5c35c 2004-05-15 devnull
102 61f5c35c 2004-05-15 devnull char buf[100]; /* line buffer for reading *file */
103 61f5c35c 2004-05-15 devnull FILE *fp_in;
104 61f5c35c 2004-05-15 devnull
105 61f5c35c 2004-05-15 devnull /*
106 61f5c35c 2004-05-15 devnull *
107 61f5c35c 2004-05-15 devnull * Looks for *want in the request file and if it's found the associated value
108 61f5c35c 2004-05-15 devnull * is copied to the output file. Keywords (ie. the *want strings) begin an @ in
109 61f5c35c 2004-05-15 devnull * the first column of file, while the values (ie. the stuff that's copied to
110 61f5c35c 2004-05-15 devnull * the output file) starts on the next line and extends to the next keyword or
111 61f5c35c 2004-05-15 devnull * to the end of file.
112 61f5c35c 2004-05-15 devnull *
113 61f5c35c 2004-05-15 devnull */
114 61f5c35c 2004-05-15 devnull
115 61f5c35c 2004-05-15 devnull if ( (fp_in = fopen(file, "r")) != NULL ) {
116 61f5c35c 2004-05-15 devnull while ( fgets(buf, sizeof(buf), fp_in) != NULL )
117 61f5c35c 2004-05-15 devnull if ( buf[0] == '@' && strncmp(want, &buf[1], strlen(want)) == 0 )
118 61f5c35c 2004-05-15 devnull while ( fgets(buf, sizeof(buf), fp_in) != NULL )
119 61f5c35c 2004-05-15 devnull if ( buf[0] == '#' || buf[0] == '%' )
120 61f5c35c 2004-05-15 devnull continue;
121 61f5c35c 2004-05-15 devnull else if ( buf[0] != '@' )
122 61f5c35c 2004-05-15 devnull fprintf(fp_out, "%s", buf);
123 61f5c35c 2004-05-15 devnull else break;
124 61f5c35c 2004-05-15 devnull fclose(fp_in);
125 61f5c35c 2004-05-15 devnull } /* End if */
126 61f5c35c 2004-05-15 devnull
127 61f5c35c 2004-05-15 devnull } /* End of dumprequest */
128 61f5c35c 2004-05-15 devnull
129 61f5c35c 2004-05-15 devnull /*****************************************************************************/
130 61f5c35c 2004-05-15 devnull