17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*f928ce67Sceastha /*
23*f928ce67Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*f928ce67Sceastha  * Use is subject to license terms.
25*f928ce67Sceastha  */
26*f928ce67Sceastha 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * Things used to handle special requests (eg. manual feed) globally or on a per
337c478bd9Sstevel@tonic-gate  * page basis. Requests are passed through to the translator using the -R option.
347c478bd9Sstevel@tonic-gate  * The argument to -R can be "request", "request:page", or "request:page:file".
357c478bd9Sstevel@tonic-gate  * If page is omitted (as in the first form) or set to 0 request will be applied
367c478bd9Sstevel@tonic-gate  * to the global environment. In all other cases it applies only to the selected
377c478bd9Sstevel@tonic-gate  * page. If a file is given, page must be supplied, and the lookup is in that file
387c478bd9Sstevel@tonic-gate  * rather than *requestfile.
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #include <stdio.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include "gen.h"			/* general purpose definitions */
467c478bd9Sstevel@tonic-gate #include "request.h"			/* a few special definitions */
477c478bd9Sstevel@tonic-gate #include "path.h"			/* for the default request file */
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate Request	request[MAXREQUEST];		/* next page or global request */
517c478bd9Sstevel@tonic-gate int	nextreq = 0;			/* goes in request[nextreq] */
527c478bd9Sstevel@tonic-gate char	*requestfile = REQUESTFILE;	/* default lookup file */
537c478bd9Sstevel@tonic-gate 
54*f928ce67Sceastha void dumprequest(char *, char *, FILE *);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*****************************************************************************/
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate 
59*f928ce67Sceastha void
saverequest(char * want)60*f928ce67Sceastha saverequest(char *want)
61*f928ce67Sceastha 	/* grab code for this stuff */
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate     char	*page;			/* and save it for this page */
647c478bd9Sstevel@tonic-gate     char	*strtok();
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  * Save the request until we get to appropriate page - don't even bother with
697c478bd9Sstevel@tonic-gate  * the lookup right now. Format of *want string is "request", "request:page", or
707c478bd9Sstevel@tonic-gate  * "request:page:file", and we assume we can change the string here as needed.
717c478bd9Sstevel@tonic-gate  * If page is omitted or given as 0 the request will be done globally. If *want
727c478bd9Sstevel@tonic-gate  * includes a file, request and page must also be given, and in that case *file
737c478bd9Sstevel@tonic-gate  * will be used for the lookup.
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate     if ( nextreq < MAXREQUEST )  {
797c478bd9Sstevel@tonic-gate 	request[nextreq].want = strtok(want, ": ");
807c478bd9Sstevel@tonic-gate 	if ( (page = strtok(NULL, ": ")) == NULL )
817c478bd9Sstevel@tonic-gate 	    request[nextreq].page = 0;
827c478bd9Sstevel@tonic-gate 	else request[nextreq].page = atoi(page);
837c478bd9Sstevel@tonic-gate 	if ( (request[nextreq].file = strtok(NULL, ": ")) == NULL )
847c478bd9Sstevel@tonic-gate 	    request[nextreq].file = requestfile;
857c478bd9Sstevel@tonic-gate 	nextreq++;
867c478bd9Sstevel@tonic-gate     } else error(NON_FATAL, "too many requests - ignoring %s", want);
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate }   /* End of saverequest */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*****************************************************************************/
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 
94*f928ce67Sceastha void
writerequest(int page,FILE * fp_out)95*f928ce67Sceastha writerequest(int page, FILE *fp_out)
96*f928ce67Sceastha 	/* page - write everything for this page */
97*f928ce67Sceastha 	/* fp_out - to this file */
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate     int		i;			/* loop index */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  *
1037c478bd9Sstevel@tonic-gate  * Writes out all the requests that have been saved for page. Page 0 refers to
1047c478bd9Sstevel@tonic-gate  * the global environment and is done during initial setup.
1057c478bd9Sstevel@tonic-gate  *
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate     for ( i = 0; i < nextreq; i++ )
1107c478bd9Sstevel@tonic-gate 	if ( request[i].page == page )
1117c478bd9Sstevel@tonic-gate 	    dumprequest(request[i].want, request[i].file, fp_out);
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate }   /* End of writerequest */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*****************************************************************************/
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 
119*f928ce67Sceastha void
dumprequest(char * want,char * file,FILE * fp_out)120*f928ce67Sceastha dumprequest(char *want, char *file, FILE *fp_out)
121*f928ce67Sceastha 	/* want - look for this string */
122*f928ce67Sceastha 	/* file - in this file */
123*f928ce67Sceastha 	/* fp_out - and write the value out here */
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate     char	buf[100];		/* line buffer for reading *file */
1267c478bd9Sstevel@tonic-gate     FILE	*fp_in;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  *
1307c478bd9Sstevel@tonic-gate  * Looks for *want in the request file and if it's found the associated value
1317c478bd9Sstevel@tonic-gate  * is copied to the output file. Keywords (ie. the *want strings) begin an @ in
1327c478bd9Sstevel@tonic-gate  * the first column of file, while the values (ie. the stuff that's copied to
1337c478bd9Sstevel@tonic-gate  * the output file) starts on the next line and extends to the next keyword or
1347c478bd9Sstevel@tonic-gate  * to the end of file.
1357c478bd9Sstevel@tonic-gate  *
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate     if ( (fp_in = fopen(file, "r")) != NULL )  {
1407c478bd9Sstevel@tonic-gate 	while ( fgets(buf, sizeof(buf), fp_in) != NULL )
1417c478bd9Sstevel@tonic-gate 	    if ( buf[0] == '@' && strncmp(want, &buf[1], strlen(want)) == 0 )
1427c478bd9Sstevel@tonic-gate 		while ( fgets(buf, sizeof(buf), fp_in) != NULL )
1437c478bd9Sstevel@tonic-gate 		    if ( buf[0] == '#' || buf[0] == '%' )
1447c478bd9Sstevel@tonic-gate 			continue;
1457c478bd9Sstevel@tonic-gate 		    else if ( buf[0] != '@' )
1467c478bd9Sstevel@tonic-gate 			fprintf(fp_out, "%s", buf);
1477c478bd9Sstevel@tonic-gate 		    else break;
1487c478bd9Sstevel@tonic-gate 	fclose(fp_in);
1497c478bd9Sstevel@tonic-gate     }	/* End if */
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate }   /* End of dumprequest */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*****************************************************************************/
1557c478bd9Sstevel@tonic-gate 
156