3 * Things used to handle special requests (eg. manual feed) globally or on a per
4 * page basis. Requests are passed through to the translator using the -R option.
5 * The argument to -R can be "request", "request:page", or "request:page:file".
6 * If page is omitted (as in the first form) or set to 0 request will be applied
7 * to the global environment. In all other cases it applies only to the selected
8 * page. If a file is given, page must be supplied, and the lookup is in that file
9 * rather than *requestfile.
16 #include "gen.h" /* general purpose definitions */
17 #include "request.h" /* a few special definitions */
18 #include "path.h" /* for the default request file */
20 static Request request
[MAXREQUEST
]; /* next page or global request */
21 static int nextreq
= 0; /* goes in request[nextreq] */
22 static char *requestfile
= REQUESTFILE
; /* default lookup file */
25 * Save the request until we get to appropriate page - don't even bother with
26 * the lookup right now. Format of *want string is "request", "request:page", or
27 * "request:page:file", and we assume we can change the string here as needed.
28 * If page is omitted or given as 0 the request will be done globally. If *want
29 * includes a file, request and page must also be given, and in that case *file
30 * will be used for the lookup.
32 * want: grab code for this stuff
34 void saverequest(char *want
)
36 char *page
; /* and save it for this page */
39 if (nextreq
< MAXREQUEST
) {
40 request
[nextreq
].want
= strtok(want
, ": ");
41 if ((page
= strtok(NULL
, ": ")) == NULL
)
42 request
[nextreq
].page
= 0;
44 request
[nextreq
].page
= atoi(page
);
45 if ((request
[nextreq
].file
= strtok(NULL
, ": ")) == NULL
)
46 request
[nextreq
].file
= requestfile
;
49 error(NON_FATAL
, "too many requests - ignoring %s", want
);
54 * Looks for *want in the request file and if it's found the associated value
55 * is copied to the output file. Keywords (ie. the *want strings) begin an @ in
56 * the first column of file, while the values (ie. the stuff that's copied to
57 * the output file) starts on the next line and extends to the next keyword or
60 * want: look for this string
62 * fp_out: and write the value out here
64 void dumprequest(char *want
, char *file
, FILE *fp_out
)
66 char buf
[100]; /* line buffer for reading *file */
69 if ((fp_in
= fopen(file
, "r")) != NULL
) {
70 while (fgets(buf
, sizeof(buf
), fp_in
) != NULL
) {
71 if (buf
[0] == '@' && strncmp(want
, &buf
[1], strlen(want
)) == 0) {
72 while (fgets(buf
, sizeof(buf
), fp_in
) != NULL
) {
73 if (buf
[0] == '#' || buf
[0] == '%')
75 else if (buf
[0] != '@')
76 fprintf(fp_out
, "%s", buf
);
87 * Writes out all the requests that have been saved for page. Page 0 refers to
88 * the global environment and is done during initial setup.
90 * page: write everything for this page
91 * fp_out: to this file
93 void writerequest(int page
, FILE *fp_out
)
95 int i
; /* loop index */
96 for (i
= 0; i
< nextreq
; i
++)
97 if (request
[i
].page
== page
)
98 dumprequest(request
[i
].want
, request
[i
].file
, fp_out
);