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 */
227c478bd9Sstevel@tonic-gate /*
23f928ce67Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27f928ce67Sceastha /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28f928ce67Sceastha /* All Rights Reserved */
29f928ce67Sceastha
307c478bd9Sstevel@tonic-gate #include <locale.h>
317c478bd9Sstevel@tonic-gate #include "stdio.h"
327c478bd9Sstevel@tonic-gate #include "errno.h"
337c478bd9Sstevel@tonic-gate #include "string.h"
347c478bd9Sstevel@tonic-gate #include "sys/types.h"
357c478bd9Sstevel@tonic-gate #include "sys/stat.h"
367c478bd9Sstevel@tonic-gate #include "stdlib.h"
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate #include "lp.h"
397c478bd9Sstevel@tonic-gate #include "access.h"
407c478bd9Sstevel@tonic-gate #include "form.h"
417c478bd9Sstevel@tonic-gate #include "msgs.h"
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #define WHO_AM_I I_AM_LPFORMS
447c478bd9Sstevel@tonic-gate #include "oam.h"
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate #define OPT_LIST "f:F:xlLA:u:W:Q:P:d"
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate #define TMPDIR "/usr/tmp"
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate typedef int (*Action)();
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate #if defined(__STDC__)
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate static int add_form ( char * , FILE * , FALERT * , char * );
557c478bd9Sstevel@tonic-gate static int add_alert ( char * , FILE * , FALERT * , char * );
567c478bd9Sstevel@tonic-gate static int delete_form ( char * );
577c478bd9Sstevel@tonic-gate static int list_form ( char * );
587c478bd9Sstevel@tonic-gate static int list_alert ( char * );
597c478bd9Sstevel@tonic-gate static int list_both ( char * );
607c478bd9Sstevel@tonic-gate static int any_alert ( char * , FILE * , FALERT * );
617c478bd9Sstevel@tonic-gate static int quiet_alert ( char * );
627c478bd9Sstevel@tonic-gate static int notify_spooler ( int , int , char * );
637c478bd9Sstevel@tonic-gate static int onerror ( int , int , int );
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate static Action set_action ( int (*)() , char * );
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate #else
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate static int add_form();
707c478bd9Sstevel@tonic-gate static int add_alert();
717c478bd9Sstevel@tonic-gate static int delete_form();
727c478bd9Sstevel@tonic-gate static int list_form();
737c478bd9Sstevel@tonic-gate static int list_alert();
747c478bd9Sstevel@tonic-gate static int list_both();
757c478bd9Sstevel@tonic-gate static int any_alert();
767c478bd9Sstevel@tonic-gate static int quiet_alert();
777c478bd9Sstevel@tonic-gate static int notify_spooler();
787c478bd9Sstevel@tonic-gate static int onerror();
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate static Action set_action();
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate /**
857c478bd9Sstevel@tonic-gate ** usage()
867c478bd9Sstevel@tonic-gate **/
877c478bd9Sstevel@tonic-gate
usage()887c478bd9Sstevel@tonic-gate void usage ()
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate (void) printf (gettext(
917c478bd9Sstevel@tonic-gate "usage:\n"
927c478bd9Sstevel@tonic-gate "\n"
937c478bd9Sstevel@tonic-gate " (add or change form)\n"
947c478bd9Sstevel@tonic-gate " lpforms -f form-name [options]\n"
957c478bd9Sstevel@tonic-gate " [-F path-name | - | -P paper [-d] | -d ] (form definition)\n"
967c478bd9Sstevel@tonic-gate " -F path-name (initialize from file)\n"
977c478bd9Sstevel@tonic-gate " - (initialize from stdin)\n"
987c478bd9Sstevel@tonic-gate " -P paper [-d] (initialize with paper (as default))\n"
997c478bd9Sstevel@tonic-gate " -d (create form with paper of same name)\n"
1007c478bd9Sstevel@tonic-gate " [-u allow:user-list | deny:user-list] (who's allowed to use)\n"
1017c478bd9Sstevel@tonic-gate " [-A mail | write | shell-command] (alert definition)\n"
1027c478bd9Sstevel@tonic-gate " [-Q threshold] (# needed for alert)\n"
1037c478bd9Sstevel@tonic-gate " [-W interval] (minutes between alerts)\n"
1047c478bd9Sstevel@tonic-gate "\n"
1057c478bd9Sstevel@tonic-gate " (list form)\n"
1067c478bd9Sstevel@tonic-gate " lpforms -f form-name -l\n"
1077c478bd9Sstevel@tonic-gate " lpforms -f form-name -L (verbose for -P forms)\n"
1087c478bd9Sstevel@tonic-gate "\n"
1097c478bd9Sstevel@tonic-gate " (delete form)\n"
1107c478bd9Sstevel@tonic-gate " lpforms -f form-name -x\n"
1117c478bd9Sstevel@tonic-gate "\n"
1127c478bd9Sstevel@tonic-gate " (define alert for forms with no alert yet)\n"
1137c478bd9Sstevel@tonic-gate " lpforms -f any -A {mail | write | shell-command}\n"
1147c478bd9Sstevel@tonic-gate "\n"
1157c478bd9Sstevel@tonic-gate " (define alert for all forms)\n"
1167c478bd9Sstevel@tonic-gate " lpforms -f all -A {mail | write | shell-command}\n"
1177c478bd9Sstevel@tonic-gate "\n"
1187c478bd9Sstevel@tonic-gate " (examine alerting)\n"
1197c478bd9Sstevel@tonic-gate " lpforms -f form-name -A list\n"
1207c478bd9Sstevel@tonic-gate "\n"
1217c478bd9Sstevel@tonic-gate " (stop alerting)\n"
1227c478bd9Sstevel@tonic-gate " lpforms -f form-name -A quiet (temporarily)\n"
1237c478bd9Sstevel@tonic-gate " lpforms -f form-name -A none (for good)"
1247c478bd9Sstevel@tonic-gate "\n"
1257c478bd9Sstevel@tonic-gate ));
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate return;
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate static char *P = NULL;
1317c478bd9Sstevel@tonic-gate static int d = 0;
1327c478bd9Sstevel@tonic-gate static int L = 0;
1337c478bd9Sstevel@tonic-gate /**
1347c478bd9Sstevel@tonic-gate ** main()
1357c478bd9Sstevel@tonic-gate **/
1367c478bd9Sstevel@tonic-gate
137f928ce67Sceastha int
main(int argc,char * argv[])138f928ce67Sceastha main(int argc, char *argv[])
1397c478bd9Sstevel@tonic-gate {
1407c478bd9Sstevel@tonic-gate extern int optind;
1417c478bd9Sstevel@tonic-gate extern int opterr;
1427c478bd9Sstevel@tonic-gate extern int optopt;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate extern char * optarg;
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate int c;
1477c478bd9Sstevel@tonic-gate int cnt = 0;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate char * form = 0;
1507c478bd9Sstevel@tonic-gate char * u = 0;
1517c478bd9Sstevel@tonic-gate char * cp;
1527c478bd9Sstevel@tonic-gate char * rest;
153*268ffd3aSRichard Lowe char stroptsw[] = "-X";
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate Action action = 0;
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate FILE *input = 0;
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate FORM fbuf;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate FALERT alert = { (char *)0, -1, -1 };
1627c478bd9Sstevel@tonic-gate
1637c478bd9Sstevel@tonic-gate struct stat statbuf;
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate (void) setlocale (LC_ALL, "");
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1697c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
1707c478bd9Sstevel@tonic-gate #endif
1717c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate if (!is_user_admin()) {
1747c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_NOTADM);
1757c478bd9Sstevel@tonic-gate exit (1);
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate
1787c478bd9Sstevel@tonic-gate opterr = 0;
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, OPT_LIST)) != -1) {
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * These options take values; "getopt()" passes values
1847c478bd9Sstevel@tonic-gate * that begin with a dash without checking if they're
1857c478bd9Sstevel@tonic-gate * options. If a value is missing, we want to complain
1867c478bd9Sstevel@tonic-gate * about it.
1877c478bd9Sstevel@tonic-gate */
1887c478bd9Sstevel@tonic-gate switch (c) {
1897c478bd9Sstevel@tonic-gate case 'W':
1907c478bd9Sstevel@tonic-gate case 'Q':
1917c478bd9Sstevel@tonic-gate /*
1927c478bd9Sstevel@tonic-gate * These options take numeric values, which might
1937c478bd9Sstevel@tonic-gate * be negative. Negative values are handled later,
1947c478bd9Sstevel@tonic-gate * but here we just screen them.
1957c478bd9Sstevel@tonic-gate */
1967c478bd9Sstevel@tonic-gate (void)strtol (optarg, &rest, 10);
1977c478bd9Sstevel@tonic-gate if (!rest || (!*rest && rest != optarg))
1987c478bd9Sstevel@tonic-gate break;
1997c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
2007c478bd9Sstevel@tonic-gate case 'f':
2017c478bd9Sstevel@tonic-gate case 'F':
2027c478bd9Sstevel@tonic-gate case 'A':
2037c478bd9Sstevel@tonic-gate case 'u':
2047c478bd9Sstevel@tonic-gate if (!*optarg) {
205*268ffd3aSRichard Lowe stroptsw[1] = c;
206*268ffd3aSRichard Lowe LP_ERRMSG1 (ERROR, E_LP_NULLARG, stroptsw);
2077c478bd9Sstevel@tonic-gate exit (1);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate if (*optarg == '-') {
210*268ffd3aSRichard Lowe stroptsw[1] = c;
211*268ffd3aSRichard Lowe LP_ERRMSG1 (ERROR, E_LP_OPTARG, stroptsw);
2127c478bd9Sstevel@tonic-gate exit (1);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate break;
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate switch (c) {
2187c478bd9Sstevel@tonic-gate
2197c478bd9Sstevel@tonic-gate case 'f':
2207c478bd9Sstevel@tonic-gate if (form)
2217c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_LP_2MANY, 'f');
2227c478bd9Sstevel@tonic-gate form = optarg;
2237c478bd9Sstevel@tonic-gate if (!syn_name(form)) {
2247c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_NOTNAME, form);
2257c478bd9Sstevel@tonic-gate exit (1);
2267c478bd9Sstevel@tonic-gate } else if (!*form)
2277c478bd9Sstevel@tonic-gate form = NAME_ALL;
2287c478bd9Sstevel@tonic-gate break;
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate case 'F':
2317c478bd9Sstevel@tonic-gate if (input)
2327c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_LP_2MANY, 'F');
2337c478bd9Sstevel@tonic-gate if (!(input = fopen(optarg, "r"))) {
2347c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_FOR_OPEN, optarg);
2357c478bd9Sstevel@tonic-gate exit (1);
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate action = set_action(add_form, "-F");
2387c478bd9Sstevel@tonic-gate break;
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate case 'A':
2417c478bd9Sstevel@tonic-gate if (STREQU(NAME_LIST, optarg))
2427c478bd9Sstevel@tonic-gate action = set_action(list_alert, "\"-A list\"");
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate else if (STREQU(NAME_QUIET, optarg))
2457c478bd9Sstevel@tonic-gate action = set_action(quiet_alert, "\"-A quiet\"");
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate else {
2487c478bd9Sstevel@tonic-gate if (STREQU(MAIL, optarg) || STREQU(WRITE, optarg))
2497c478bd9Sstevel@tonic-gate alert.shcmd = makestr(optarg, " ", getname(), (char *)0);
2507c478bd9Sstevel@tonic-gate else
2517c478bd9Sstevel@tonic-gate alert.shcmd = strdup(optarg);
2527c478bd9Sstevel@tonic-gate action = set_action(add_alert, "-A");
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate break;
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate case 'Q':
2577c478bd9Sstevel@tonic-gate if (alert.Q != -1)
2587c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_LP_2MANY, 'Q');
2597c478bd9Sstevel@tonic-gate if (STREQU(NAME_ANY, optarg))
2607c478bd9Sstevel@tonic-gate alert.Q = 1;
2617c478bd9Sstevel@tonic-gate else {
2627c478bd9Sstevel@tonic-gate alert.Q = strtol(optarg, &rest, 10);
2637c478bd9Sstevel@tonic-gate if (alert.Q < 0) {
2647c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_NEGARG, 'Q');
2657c478bd9Sstevel@tonic-gate exit (1);
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate if (rest && *rest) {
2687c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_GARBNMB, 'Q');
2697c478bd9Sstevel@tonic-gate exit (1);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate if (alert.Q == 0) {
2727c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_ZEROARG, 'Q');
2737c478bd9Sstevel@tonic-gate exit (1);
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate action = set_action(add_alert, "-Q");
2777c478bd9Sstevel@tonic-gate break;
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate case 'W':
2807c478bd9Sstevel@tonic-gate if (alert.W != -1)
2817c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_LP_2MANY, 'W');
2827c478bd9Sstevel@tonic-gate if (STREQU(NAME_ONCE, optarg))
2837c478bd9Sstevel@tonic-gate alert.W = 0;
2847c478bd9Sstevel@tonic-gate else {
2857c478bd9Sstevel@tonic-gate alert.W = strtol(optarg, &rest, 10);
2867c478bd9Sstevel@tonic-gate if (alert.W < 0) {
2877c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_NEGARG, 'W');
2887c478bd9Sstevel@tonic-gate exit (1);
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate if (rest && *rest) {
2917c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_GARBNMB, 'W');
2927c478bd9Sstevel@tonic-gate exit (1);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate }
2957c478bd9Sstevel@tonic-gate action = set_action(add_alert, "-W");
2967c478bd9Sstevel@tonic-gate break;
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate case 'u':
2997c478bd9Sstevel@tonic-gate if (u)
3007c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_LP_2MANY, 'u');
3017c478bd9Sstevel@tonic-gate u = strdup(optarg);
3027c478bd9Sstevel@tonic-gate action = set_action(add_form, "-u");
3037c478bd9Sstevel@tonic-gate break;
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate case 'x':
3067c478bd9Sstevel@tonic-gate action = set_action(delete_form, "-x");
3077c478bd9Sstevel@tonic-gate break;
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate case 'L':
3107c478bd9Sstevel@tonic-gate L = 1;
3117c478bd9Sstevel@tonic-gate action = set_action(list_form, "-L");
3127c478bd9Sstevel@tonic-gate break;
3137c478bd9Sstevel@tonic-gate case 'l':
3147c478bd9Sstevel@tonic-gate action = set_action(list_form, "-l");
3157c478bd9Sstevel@tonic-gate break;
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate case 'd':
3187c478bd9Sstevel@tonic-gate d = 1;
3197c478bd9Sstevel@tonic-gate action = set_action(add_form, "-d");
3207c478bd9Sstevel@tonic-gate break;
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate case 'P':
3237c478bd9Sstevel@tonic-gate if (P)
3247c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_LP_2MANY, 'P');
3257c478bd9Sstevel@tonic-gate action = set_action(add_form, "-P");
3267c478bd9Sstevel@tonic-gate P = strdup(optarg);
3277c478bd9Sstevel@tonic-gate break;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate default:
3307c478bd9Sstevel@tonic-gate if (optopt == '?') {
3317c478bd9Sstevel@tonic-gate usage ();
3327c478bd9Sstevel@tonic-gate exit (0);
3337c478bd9Sstevel@tonic-gate }
334*268ffd3aSRichard Lowe stroptsw[1] = optopt;
3357c478bd9Sstevel@tonic-gate if (strchr(OPT_LIST, optopt))
336*268ffd3aSRichard Lowe LP_ERRMSG1 (ERROR, E_LP_OPTARG, stroptsw);
3377c478bd9Sstevel@tonic-gate else
338*268ffd3aSRichard Lowe LP_ERRMSG1 (ERROR, E_LP_OPTION, stroptsw);
3397c478bd9Sstevel@tonic-gate exit (1);
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate }
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate
3447c478bd9Sstevel@tonic-gate if (!form) {
3457c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_FORMNAME);
3467c478bd9Sstevel@tonic-gate exit (1);
3477c478bd9Sstevel@tonic-gate }
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate if (STREQU(NAME_ANY, form))
3507c478bd9Sstevel@tonic-gate action = set_action(any_alert, "\"-f any\"");
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate if (optind < argc && STREQU(argv[optind], "-")) {
3537c478bd9Sstevel@tonic-gate action = set_action(add_form, "-");
3547c478bd9Sstevel@tonic-gate input = stdin;
3557c478bd9Sstevel@tonic-gate optind++;
3567c478bd9Sstevel@tonic-gate }
3577c478bd9Sstevel@tonic-gate if (optind < argc)
3587c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_EXTRAARG, argv[optind]);
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate if (!action) {
3617c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_NOACT);
3627c478bd9Sstevel@tonic-gate exit (1);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate if (action == any_alert && STREQU(alert.shcmd, NAME_NONE)) {
3667c478bd9Sstevel@tonic-gate LP_ERRMSG (WARNING, E_FOR_ANYDEL);
3677c478bd9Sstevel@tonic-gate exit (0);
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate /*
3717c478bd9Sstevel@tonic-gate * We must have a shell command for the alert if:
3727c478bd9Sstevel@tonic-gate *
3737c478bd9Sstevel@tonic-gate * (1) we're adding a new form and the -W or -Q options
3747c478bd9Sstevel@tonic-gate * have been given, or
3757c478bd9Sstevel@tonic-gate *
3767c478bd9Sstevel@tonic-gate * (2) the -f any option was given.
3777c478bd9Sstevel@tonic-gate */
3787c478bd9Sstevel@tonic-gate if (
3797c478bd9Sstevel@tonic-gate (
3807c478bd9Sstevel@tonic-gate action == add_form
3817c478bd9Sstevel@tonic-gate && !alert.shcmd
3827c478bd9Sstevel@tonic-gate && (alert.Q != -1 || alert.W != -1)
3837c478bd9Sstevel@tonic-gate && !STREQU(NAME_ALL, form)
3847c478bd9Sstevel@tonic-gate && getform(form, &fbuf, (FALERT *)0, (FILE **)0) != 0
3857c478bd9Sstevel@tonic-gate )
3867c478bd9Sstevel@tonic-gate || action == any_alert && !alert.shcmd
3877c478bd9Sstevel@tonic-gate ) {
3887c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_NOSHCMDERR);
3897c478bd9Sstevel@tonic-gate return (1);
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate if (P && (! STREQU(P,form))) {
3937c478bd9Sstevel@tonic-gate while (P && (cnt++ < 2)) {
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate * two times should do it unless user has edited
3967c478bd9Sstevel@tonic-gate * files directly
3977c478bd9Sstevel@tonic-gate */
3987c478bd9Sstevel@tonic-gate if (getform(P, &fbuf, (FALERT *)0, (FILE **)0) != -1) {
3997c478bd9Sstevel@tonic-gate if (!fbuf.paper) {
4007c478bd9Sstevel@tonic-gate LP_ERRMSG3(ERROR, E_FOR_ALSO_SEP_FORM,
4017c478bd9Sstevel@tonic-gate form, P, P);
4027c478bd9Sstevel@tonic-gate return (1);
4037c478bd9Sstevel@tonic-gate } else if (!STREQU(fbuf.paper, P))
4047c478bd9Sstevel@tonic-gate P = Strdup(fbuf.paper);
4057c478bd9Sstevel@tonic-gate else
4067c478bd9Sstevel@tonic-gate break; /* we found a good paper */
4077c478bd9Sstevel@tonic-gate } else {
4087c478bd9Sstevel@tonic-gate int result;
4097c478bd9Sstevel@tonic-gate int saveD;
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate saveD = d;
4127c478bd9Sstevel@tonic-gate d = 1;
4137c478bd9Sstevel@tonic-gate result = ((*action)(P, NULL, &alert, u));
4147c478bd9Sstevel@tonic-gate d = saveD;
4157c478bd9Sstevel@tonic-gate return (result ? result :
4167c478bd9Sstevel@tonic-gate ((*action)(form, input, &alert, u)));
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate }
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate if (d && !P)
4227c478bd9Sstevel@tonic-gate P = Strdup(form);
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate return ((*action)(form, input, &alert, u));
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate
4277c478bd9Sstevel@tonic-gate /**
4287c478bd9Sstevel@tonic-gate ** add_alert()
4297c478bd9Sstevel@tonic-gate ** add_form()
4307c478bd9Sstevel@tonic-gate **/
4317c478bd9Sstevel@tonic-gate
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate * "add_alert()" exists just to simplify the checking of mixed
4347c478bd9Sstevel@tonic-gate * options in "set_action()".
4357c478bd9Sstevel@tonic-gate */
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate static int
4387c478bd9Sstevel@tonic-gate #if defined(__STDC__)
add_alert(char * form,FILE * input,FALERT * p_new_alert,char * u)4397c478bd9Sstevel@tonic-gate add_alert (
4407c478bd9Sstevel@tonic-gate char * form,
4417c478bd9Sstevel@tonic-gate FILE * input,
4427c478bd9Sstevel@tonic-gate FALERT * p_new_alert,
4437c478bd9Sstevel@tonic-gate char * u
4447c478bd9Sstevel@tonic-gate )
4457c478bd9Sstevel@tonic-gate #else
4467c478bd9Sstevel@tonic-gate add_alert (form, input, new_alert, u)
4477c478bd9Sstevel@tonic-gate char * form;
4487c478bd9Sstevel@tonic-gate FILE * input;
4497c478bd9Sstevel@tonic-gate FALERT * p_new_alert;
4507c478bd9Sstevel@tonic-gate char * u;
4517c478bd9Sstevel@tonic-gate #endif
4527c478bd9Sstevel@tonic-gate {
4537c478bd9Sstevel@tonic-gate return (add_form(form, input, p_new_alert, u));
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate
4567c478bd9Sstevel@tonic-gate static int
4577c478bd9Sstevel@tonic-gate #if defined(__STDC__)
add_form(char * form,FILE * input,FALERT * p_new_alert,char * u)4587c478bd9Sstevel@tonic-gate add_form (
4597c478bd9Sstevel@tonic-gate char * form,
4607c478bd9Sstevel@tonic-gate FILE * input,
4617c478bd9Sstevel@tonic-gate FALERT * p_new_alert,
4627c478bd9Sstevel@tonic-gate char * u
4637c478bd9Sstevel@tonic-gate )
4647c478bd9Sstevel@tonic-gate #else
4657c478bd9Sstevel@tonic-gate add_form (form, input, new_alert, u)
4667c478bd9Sstevel@tonic-gate char * form;
4677c478bd9Sstevel@tonic-gate FILE * input;
4687c478bd9Sstevel@tonic-gate FALERT * p_new_alert;
4697c478bd9Sstevel@tonic-gate char * u;
4707c478bd9Sstevel@tonic-gate #endif
4717c478bd9Sstevel@tonic-gate {
4727c478bd9Sstevel@tonic-gate int fld;
4737c478bd9Sstevel@tonic-gate int which_set[FO_MAX];
4747c478bd9Sstevel@tonic-gate int new_form = 0;
4757c478bd9Sstevel@tonic-gate int nform;
4767c478bd9Sstevel@tonic-gate int return_code;
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate char * all_list[] = { NAME_ALL, 0 };
4797c478bd9Sstevel@tonic-gate char ** u_allow = 0;
4807c478bd9Sstevel@tonic-gate char ** u_deny = 0;
4817c478bd9Sstevel@tonic-gate
4827c478bd9Sstevel@tonic-gate FILE * align_fp = 0;
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate FORM fbuf;
4857c478bd9Sstevel@tonic-gate FORM new_fbuf;
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate FALERT alert;
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gate /*
4917c478bd9Sstevel@tonic-gate * Read the input configuration (if any) and parse it into a form,
4927c478bd9Sstevel@tonic-gate * storing it in the form buffer "fbuf". Keep track of
4937c478bd9Sstevel@tonic-gate * which fields have been given, to avoid overwriting unchanged
4947c478bd9Sstevel@tonic-gate * fields later.
4957c478bd9Sstevel@tonic-gate */
4967c478bd9Sstevel@tonic-gate if (input) {
4977c478bd9Sstevel@tonic-gate for (fld = 0; fld < FO_MAX; fld++)
4987c478bd9Sstevel@tonic-gate which_set[fld] = 0;
4997c478bd9Sstevel@tonic-gate
5007c478bd9Sstevel@tonic-gate if (rdform(form, &new_fbuf, fileno(input), onerror,
5017c478bd9Sstevel@tonic-gate which_set) == -1) {
5027c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_FOR_UNKNOWN, "(input)", PERROR);
5037c478bd9Sstevel@tonic-gate return (1);
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate for (fld = 0; fld < FO_MAX; fld++)
5067c478bd9Sstevel@tonic-gate if (which_set[fld])
5077c478bd9Sstevel@tonic-gate break;
5087c478bd9Sstevel@tonic-gate if (fld >= FO_MAX)
5097c478bd9Sstevel@tonic-gate LP_ERRMSG (WARNING, E_FOR_EMPTYFILE);
5107c478bd9Sstevel@tonic-gate
5117c478bd9Sstevel@tonic-gate /*
5127c478bd9Sstevel@tonic-gate * Read the alignment pattern (if any) into a temporary
5137c478bd9Sstevel@tonic-gate * file so that it can be used for (potentially) many
5147c478bd9Sstevel@tonic-gate * forms.
5157c478bd9Sstevel@tonic-gate */
5167c478bd9Sstevel@tonic-gate if (which_set[FO_ALIGN]) {
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate size_t n;
5197c478bd9Sstevel@tonic-gate
5207c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate if ((align_fp = tmpfile()) == NULL) {
5257c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_CTMPFILE);
5267c478bd9Sstevel@tonic-gate exit (1);
5277c478bd9Sstevel@tonic-gate }
5287c478bd9Sstevel@tonic-gate
5297c478bd9Sstevel@tonic-gate while ((n = fread(buf, 1, BUFSIZ, input)))
5307c478bd9Sstevel@tonic-gate fwrite (buf, 1, n, align_fp);
5317c478bd9Sstevel@tonic-gate }
5327c478bd9Sstevel@tonic-gate }
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate /*
5357c478bd9Sstevel@tonic-gate * Parse the user allow/deny list (if any).
5367c478bd9Sstevel@tonic-gate */
5377c478bd9Sstevel@tonic-gate if (u) {
5387c478bd9Sstevel@tonic-gate
5397c478bd9Sstevel@tonic-gate char * cp;
5407c478bd9Sstevel@tonic-gate char * type;
5417c478bd9Sstevel@tonic-gate
5427c478bd9Sstevel@tonic-gate
5437c478bd9Sstevel@tonic-gate type = strtok(u, ":");
5447c478bd9Sstevel@tonic-gate cp = strtok((char *)0, ":");
5457c478bd9Sstevel@tonic-gate
5467c478bd9Sstevel@tonic-gate if (STREQU(type, NAME_ALLOW) && cp) {
5477c478bd9Sstevel@tonic-gate if (!(u_allow = getlist(cp, LP_WS, LP_SEP)))
5487c478bd9Sstevel@tonic-gate LP_ERRMSG1 (
5497c478bd9Sstevel@tonic-gate WARNING,
5507c478bd9Sstevel@tonic-gate E_LP_MISSING,
5517c478bd9Sstevel@tonic-gate NAME_ALLOW
5527c478bd9Sstevel@tonic-gate );
5537c478bd9Sstevel@tonic-gate
5547c478bd9Sstevel@tonic-gate } else if (STREQU(type, NAME_DENY) && cp) {
5557c478bd9Sstevel@tonic-gate if (!(u_deny = getlist(cp, LP_WS, LP_SEP)))
5567c478bd9Sstevel@tonic-gate LP_ERRMSG1 (
5577c478bd9Sstevel@tonic-gate WARNING,
5587c478bd9Sstevel@tonic-gate E_LP_MISSING,
5597c478bd9Sstevel@tonic-gate NAME_DENY
5607c478bd9Sstevel@tonic-gate );
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate } else {
5637c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_UALLOWDENY);
5647c478bd9Sstevel@tonic-gate exit (1);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate }
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate /*
5697c478bd9Sstevel@tonic-gate * The following loop gets either a particular form or
5707c478bd9Sstevel@tonic-gate * all forms (one at a time). The value of "return_code"
5717c478bd9Sstevel@tonic-gate * controls the loop and is also the value to use in the
5727c478bd9Sstevel@tonic-gate * "return()" at the end.
5737c478bd9Sstevel@tonic-gate */
5747c478bd9Sstevel@tonic-gate nform = 0;
5757c478bd9Sstevel@tonic-gate return_code = -1;
5767c478bd9Sstevel@tonic-gate while (return_code == -1) {
5777c478bd9Sstevel@tonic-gate
5787c478bd9Sstevel@tonic-gate /*
5797c478bd9Sstevel@tonic-gate * If we are adding/changing a single form, set
5807c478bd9Sstevel@tonic-gate * the loop control to get us out.
5817c478bd9Sstevel@tonic-gate */
5827c478bd9Sstevel@tonic-gate if (!STREQU(NAME_ALL, form))
5837c478bd9Sstevel@tonic-gate return_code = 0;
5847c478bd9Sstevel@tonic-gate
5857c478bd9Sstevel@tonic-gate nform++;
5867c478bd9Sstevel@tonic-gate
5877c478bd9Sstevel@tonic-gate if (P) {
5887c478bd9Sstevel@tonic-gate memset ((char *)&fbuf, 0, sizeof(FORM));
5897c478bd9Sstevel@tonic-gate fbuf.name = strdup(form);
5907c478bd9Sstevel@tonic-gate fbuf.plen.val = DPLEN;
5917c478bd9Sstevel@tonic-gate fbuf.plen.sc = 0;
5927c478bd9Sstevel@tonic-gate fbuf.pwid.val = DPWIDTH;
5937c478bd9Sstevel@tonic-gate fbuf.pwid.sc = 0;
5947c478bd9Sstevel@tonic-gate fbuf.lpi.val = DLPITCH;
5957c478bd9Sstevel@tonic-gate fbuf.lpi.sc = 0;
5967c478bd9Sstevel@tonic-gate fbuf.cpi.val = DCPITCH;
5977c478bd9Sstevel@tonic-gate fbuf.cpi.sc = 0;
5987c478bd9Sstevel@tonic-gate fbuf.np = DNP;
5997c478bd9Sstevel@tonic-gate fbuf.chset = strdup(DCHSET);
6007c478bd9Sstevel@tonic-gate fbuf.mandatory = 0;
6017c478bd9Sstevel@tonic-gate fbuf.rcolor = strdup(DRCOLOR);
6027c478bd9Sstevel@tonic-gate fbuf.conttype = strdup(DCONTYP);
6037c478bd9Sstevel@tonic-gate fbuf.paper = P;
6047c478bd9Sstevel@tonic-gate fbuf.isDefault = d;
6057c478bd9Sstevel@tonic-gate alert.shcmd = 0;
6067c478bd9Sstevel@tonic-gate alert.W = alert.Q = -1;
6077c478bd9Sstevel@tonic-gate new_form = 1;
6087c478bd9Sstevel@tonic-gate
6097c478bd9Sstevel@tonic-gate } else if (getform(form, &fbuf, &alert, (FILE **)0) == -1)
6107c478bd9Sstevel@tonic-gate switch (errno) {
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate case ENOENT:
6137c478bd9Sstevel@tonic-gate /*
6147c478bd9Sstevel@tonic-gate * This is a problem only if it occurs
6157c478bd9Sstevel@tonic-gate * immediately on trying to get ``all''.
6167c478bd9Sstevel@tonic-gate */
6177c478bd9Sstevel@tonic-gate if (STREQU(NAME_ALL, form)) {
6187c478bd9Sstevel@tonic-gate if (nform > 1)
6197c478bd9Sstevel@tonic-gate return_code = 0;
6207c478bd9Sstevel@tonic-gate else {
6217c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_NOFORMS);
6227c478bd9Sstevel@tonic-gate return_code = 1;
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate continue;
6257c478bd9Sstevel@tonic-gate }
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate /*
6287c478bd9Sstevel@tonic-gate * We're adding a new form,
6297c478bd9Sstevel@tonic-gate * so set up default values.
6307c478bd9Sstevel@tonic-gate */
6317c478bd9Sstevel@tonic-gate memset ((char *)&fbuf, 0, sizeof(FORM));
6327c478bd9Sstevel@tonic-gate fbuf.name = strdup(form);
6337c478bd9Sstevel@tonic-gate fbuf.plen.val = DPLEN;
6347c478bd9Sstevel@tonic-gate fbuf.plen.sc = 0;
6357c478bd9Sstevel@tonic-gate fbuf.pwid.val = DPWIDTH;
6367c478bd9Sstevel@tonic-gate fbuf.pwid.sc = 0;
6377c478bd9Sstevel@tonic-gate fbuf.lpi.val = DLPITCH;
6387c478bd9Sstevel@tonic-gate fbuf.lpi.sc = 0;
6397c478bd9Sstevel@tonic-gate fbuf.cpi.val = DCPITCH;
6407c478bd9Sstevel@tonic-gate fbuf.cpi.sc = 0;
6417c478bd9Sstevel@tonic-gate fbuf.np = DNP;
6427c478bd9Sstevel@tonic-gate fbuf.chset = strdup(DCHSET);
6437c478bd9Sstevel@tonic-gate fbuf.mandatory = 0;
6447c478bd9Sstevel@tonic-gate fbuf.rcolor = strdup(DRCOLOR);
6457c478bd9Sstevel@tonic-gate fbuf.conttype = strdup(DCONTYP);
6467c478bd9Sstevel@tonic-gate alert.shcmd = 0;
6477c478bd9Sstevel@tonic-gate alert.W = alert.Q = -1;
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate new_form = 1;
6507c478bd9Sstevel@tonic-gate break;
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate default:
6537c478bd9Sstevel@tonic-gate /*
6547c478bd9Sstevel@tonic-gate * Don't know if we'll have a good name
6557c478bd9Sstevel@tonic-gate * in the "all" case on getting here, so
6567c478bd9Sstevel@tonic-gate * punt on naming the form in the error
6577c478bd9Sstevel@tonic-gate * message.
6587c478bd9Sstevel@tonic-gate */
6597c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_GETFORM, form, PERROR);
6607c478bd9Sstevel@tonic-gate return_code = 1;
6617c478bd9Sstevel@tonic-gate continue;
6627c478bd9Sstevel@tonic-gate }
6637c478bd9Sstevel@tonic-gate
6647c478bd9Sstevel@tonic-gate /*
6657c478bd9Sstevel@tonic-gate * Copy just those items that were given in the input.
6667c478bd9Sstevel@tonic-gate */
6677c478bd9Sstevel@tonic-gate if (!input && new_form && !P) {
6687c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_NOFORM, form);
6697c478bd9Sstevel@tonic-gate return (1);
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate if (input)
6727c478bd9Sstevel@tonic-gate for (fld = 0; fld < FO_MAX; fld++)
6737c478bd9Sstevel@tonic-gate if (which_set[fld]) switch(fld) {
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate case FO_PLEN:
6767c478bd9Sstevel@tonic-gate fbuf.plen = new_fbuf.plen;
6777c478bd9Sstevel@tonic-gate break;
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate case FO_PWID:
6807c478bd9Sstevel@tonic-gate fbuf.pwid = new_fbuf.pwid;
6817c478bd9Sstevel@tonic-gate break;
6827c478bd9Sstevel@tonic-gate
6837c478bd9Sstevel@tonic-gate case FO_CPI:
6847c478bd9Sstevel@tonic-gate fbuf.cpi = new_fbuf.cpi;
6857c478bd9Sstevel@tonic-gate break;
6867c478bd9Sstevel@tonic-gate
6877c478bd9Sstevel@tonic-gate case FO_LPI:
6887c478bd9Sstevel@tonic-gate fbuf.lpi = new_fbuf.lpi;
6897c478bd9Sstevel@tonic-gate break;
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate case FO_NP:
6927c478bd9Sstevel@tonic-gate fbuf.np = new_fbuf.np;
6937c478bd9Sstevel@tonic-gate break;
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate case FO_CHSET:
6967c478bd9Sstevel@tonic-gate fbuf.chset = new_fbuf.chset;
6977c478bd9Sstevel@tonic-gate fbuf.mandatory = new_fbuf.mandatory;
6987c478bd9Sstevel@tonic-gate break;
6997c478bd9Sstevel@tonic-gate
7007c478bd9Sstevel@tonic-gate case FO_RCOLOR:
7017c478bd9Sstevel@tonic-gate fbuf.rcolor = new_fbuf.rcolor;
7027c478bd9Sstevel@tonic-gate break;
7037c478bd9Sstevel@tonic-gate
7047c478bd9Sstevel@tonic-gate case FO_CMT:
7057c478bd9Sstevel@tonic-gate fbuf.comment = new_fbuf.comment;
7067c478bd9Sstevel@tonic-gate break;
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate case FO_ALIGN:
7097c478bd9Sstevel@tonic-gate fbuf.conttype = new_fbuf.conttype;
7107c478bd9Sstevel@tonic-gate rewind (align_fp);
7117c478bd9Sstevel@tonic-gate break;
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate case FO_PAPER:
7147c478bd9Sstevel@tonic-gate fbuf.paper = new_fbuf.paper;
7157c478bd9Sstevel@tonic-gate fbuf.isDefault = new_fbuf.isDefault;
7167c478bd9Sstevel@tonic-gate break;
7177c478bd9Sstevel@tonic-gate
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate /*
7217c478bd9Sstevel@tonic-gate * Set just those alert elements that were given.
7227c478bd9Sstevel@tonic-gate * However, complain about those form(s) that don't have
7237c478bd9Sstevel@tonic-gate * a shell command yet, and none was given, yet -W or -Q
7247c478bd9Sstevel@tonic-gate * were given.
7257c478bd9Sstevel@tonic-gate */
7267c478bd9Sstevel@tonic-gate if (
7277c478bd9Sstevel@tonic-gate !alert.shcmd && !p_new_alert->shcmd
7287c478bd9Sstevel@tonic-gate && (p_new_alert->W != -1 || p_new_alert->Q != -1)
7297c478bd9Sstevel@tonic-gate )
7307c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_NOSHCMDWARN, fbuf.name);
7317c478bd9Sstevel@tonic-gate else {
7327c478bd9Sstevel@tonic-gate if (p_new_alert->shcmd)
7337c478bd9Sstevel@tonic-gate alert.shcmd = p_new_alert->shcmd;
7347c478bd9Sstevel@tonic-gate if (p_new_alert->Q != -1)
7357c478bd9Sstevel@tonic-gate alert.Q = p_new_alert->Q;
7367c478bd9Sstevel@tonic-gate if (p_new_alert->W != -1)
7377c478bd9Sstevel@tonic-gate alert.W = p_new_alert->W;
7387c478bd9Sstevel@tonic-gate }
7397c478bd9Sstevel@tonic-gate
7407c478bd9Sstevel@tonic-gate /*
7417c478bd9Sstevel@tonic-gate * Create/update the form.
7427c478bd9Sstevel@tonic-gate */
7437c478bd9Sstevel@tonic-gate #define P_FBUF (new_form || input? &fbuf : (FORM *)0)
7447c478bd9Sstevel@tonic-gate if (putform(fbuf.name, P_FBUF, &alert, &align_fp) == -1) {
7457c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_PUTFORM, fbuf.name, PERROR);
7467c478bd9Sstevel@tonic-gate return_code = 1;
7477c478bd9Sstevel@tonic-gate continue;
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate
7507c478bd9Sstevel@tonic-gate /*
7517c478bd9Sstevel@tonic-gate * Allow/deny users.
7527c478bd9Sstevel@tonic-gate */
7537c478bd9Sstevel@tonic-gate if (new_form && allow_user_form(all_list, fbuf.name) == -1) {
7547c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_ACCESSINFO, PERROR);
7557c478bd9Sstevel@tonic-gate return_code = 1;
7567c478bd9Sstevel@tonic-gate continue;
7577c478bd9Sstevel@tonic-gate }
7587c478bd9Sstevel@tonic-gate if (u_allow && allow_user_form(u_allow, fbuf.name) == -1) {
7597c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_ACCESSINFO, PERROR);
7607c478bd9Sstevel@tonic-gate return_code = 1;
7617c478bd9Sstevel@tonic-gate continue;
7627c478bd9Sstevel@tonic-gate }
7637c478bd9Sstevel@tonic-gate if (u_deny && deny_user_form(u_deny, fbuf.name) == -1) {
7647c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_ACCESSINFO, PERROR);
7657c478bd9Sstevel@tonic-gate return_code = 1;
7667c478bd9Sstevel@tonic-gate continue;
7677c478bd9Sstevel@tonic-gate }
7687c478bd9Sstevel@tonic-gate
7697c478bd9Sstevel@tonic-gate notify_spooler (S_LOAD_FORM, R_LOAD_FORM, fbuf.name);
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate }
7727c478bd9Sstevel@tonic-gate
7737c478bd9Sstevel@tonic-gate if (align_fp)
7747c478bd9Sstevel@tonic-gate close_lpfile (align_fp);
7757c478bd9Sstevel@tonic-gate
7767c478bd9Sstevel@tonic-gate return (return_code);
7777c478bd9Sstevel@tonic-gate }
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate /**
7807c478bd9Sstevel@tonic-gate ** list_form()
7817c478bd9Sstevel@tonic-gate ** list_alert()
7827c478bd9Sstevel@tonic-gate ** list_both()
7837c478bd9Sstevel@tonic-gate **/
7847c478bd9Sstevel@tonic-gate
7857c478bd9Sstevel@tonic-gate #if defined(__STDC__)
7867c478bd9Sstevel@tonic-gate
787f928ce67Sceastha static int list ( char * , void (*)() );
788f928ce67Sceastha static void _list_form ( FORM * , FALERT * , FILE * );
789f928ce67Sceastha static void _list_alert ( FORM * , FALERT * );
790f928ce67Sceastha static void _list_both ( FORM * , FALERT * , FILE * );
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate #else
7937c478bd9Sstevel@tonic-gate
7947c478bd9Sstevel@tonic-gate static int list();
795f928ce67Sceastha static void _list_form();
796f928ce67Sceastha static void _list_alert();
797f928ce67Sceastha static void _list_both();
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate #endif
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate static int
8027c478bd9Sstevel@tonic-gate #if defined(__STDC__)
list_form(char * form)8037c478bd9Sstevel@tonic-gate list_form (
8047c478bd9Sstevel@tonic-gate char *form
8057c478bd9Sstevel@tonic-gate )
8067c478bd9Sstevel@tonic-gate #else
8077c478bd9Sstevel@tonic-gate list_form (form)
8087c478bd9Sstevel@tonic-gate char *form;
8097c478bd9Sstevel@tonic-gate #endif
8107c478bd9Sstevel@tonic-gate {
8117c478bd9Sstevel@tonic-gate return (list(form, _list_form));
8127c478bd9Sstevel@tonic-gate }
8137c478bd9Sstevel@tonic-gate
8147c478bd9Sstevel@tonic-gate static int
8157c478bd9Sstevel@tonic-gate #if defined(__STDC__)
list_alert(char * form)8167c478bd9Sstevel@tonic-gate list_alert (
8177c478bd9Sstevel@tonic-gate char *form
8187c478bd9Sstevel@tonic-gate )
8197c478bd9Sstevel@tonic-gate #else
8207c478bd9Sstevel@tonic-gate list_alert (form)
8217c478bd9Sstevel@tonic-gate char *form;
8227c478bd9Sstevel@tonic-gate #endif
8237c478bd9Sstevel@tonic-gate {
8247c478bd9Sstevel@tonic-gate return (list(form, _list_alert));
8257c478bd9Sstevel@tonic-gate }
8267c478bd9Sstevel@tonic-gate
8277c478bd9Sstevel@tonic-gate static int
8287c478bd9Sstevel@tonic-gate #if defined(__STDC__)
list_both(char * form)8297c478bd9Sstevel@tonic-gate list_both (
8307c478bd9Sstevel@tonic-gate char *form
8317c478bd9Sstevel@tonic-gate )
8327c478bd9Sstevel@tonic-gate #else
8337c478bd9Sstevel@tonic-gate list_both (form)
8347c478bd9Sstevel@tonic-gate char *form;
8357c478bd9Sstevel@tonic-gate #endif
8367c478bd9Sstevel@tonic-gate {
8377c478bd9Sstevel@tonic-gate return (list(form, _list_both));
8387c478bd9Sstevel@tonic-gate }
8397c478bd9Sstevel@tonic-gate
8407c478bd9Sstevel@tonic-gate static int
8417c478bd9Sstevel@tonic-gate #if defined(__STDC__)
list(char * form,void (* subaction)())8427c478bd9Sstevel@tonic-gate list (
8437c478bd9Sstevel@tonic-gate char *form,
844f928ce67Sceastha void (*subaction)()
8457c478bd9Sstevel@tonic-gate )
8467c478bd9Sstevel@tonic-gate #else
8477c478bd9Sstevel@tonic-gate list (form, subaction)
8487c478bd9Sstevel@tonic-gate char *form;
849f928ce67Sceastha void (*subaction)();
8507c478bd9Sstevel@tonic-gate #endif
8517c478bd9Sstevel@tonic-gate {
8527c478bd9Sstevel@tonic-gate FORM fbuf;
8537c478bd9Sstevel@tonic-gate
8547c478bd9Sstevel@tonic-gate FALERT alert;
8557c478bd9Sstevel@tonic-gate
8567c478bd9Sstevel@tonic-gate FILE * align_fp;
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate char *nl;
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate if (STREQU(NAME_ALL, form)) {
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate nl = "";
8647c478bd9Sstevel@tonic-gate while (getform(form, &fbuf, &alert, &align_fp) == 0) {
8657c478bd9Sstevel@tonic-gate printf (gettext("%sForm name: %s\n"), nl, fbuf.name);
8667c478bd9Sstevel@tonic-gate (*subaction) (&fbuf, &alert, align_fp);
8677c478bd9Sstevel@tonic-gate nl = "\n";
8687c478bd9Sstevel@tonic-gate }
8697c478bd9Sstevel@tonic-gate
8707c478bd9Sstevel@tonic-gate switch (errno) {
8717c478bd9Sstevel@tonic-gate case ENOENT:
8727c478bd9Sstevel@tonic-gate return (0);
8737c478bd9Sstevel@tonic-gate default:
8747c478bd9Sstevel@tonic-gate /*
8757c478bd9Sstevel@tonic-gate * Don't know if we'll have a good name
8767c478bd9Sstevel@tonic-gate * in the "all" case on getting here, so
8777c478bd9Sstevel@tonic-gate * punt on naming the form in the error
8787c478bd9Sstevel@tonic-gate * message.
8797c478bd9Sstevel@tonic-gate */
8807c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_GETFORM, form, PERROR);
8817c478bd9Sstevel@tonic-gate return (1);
8827c478bd9Sstevel@tonic-gate }
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate } else {
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate if (getform(form, &fbuf, &alert, &align_fp) == 0) {
8877c478bd9Sstevel@tonic-gate (*subaction) (&fbuf, &alert, align_fp);
8887c478bd9Sstevel@tonic-gate return (0);
8897c478bd9Sstevel@tonic-gate }
8907c478bd9Sstevel@tonic-gate
8917c478bd9Sstevel@tonic-gate switch (errno) {
8927c478bd9Sstevel@tonic-gate case ENOENT:
8937c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_NOFORM, form);
8947c478bd9Sstevel@tonic-gate return (1);
8957c478bd9Sstevel@tonic-gate default:
8967c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_GETFORM, form, PERROR);
8977c478bd9Sstevel@tonic-gate return (1);
8987c478bd9Sstevel@tonic-gate }
8997c478bd9Sstevel@tonic-gate
9007c478bd9Sstevel@tonic-gate }
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate
9037c478bd9Sstevel@tonic-gate /**
9047c478bd9Sstevel@tonic-gate ** _list_form()
9057c478bd9Sstevel@tonic-gate **/
9067c478bd9Sstevel@tonic-gate
907f928ce67Sceastha static void
9087c478bd9Sstevel@tonic-gate #if defined(__STDC__)
_list_form(FORM * pf,FALERT * palert,FILE * align_fp)9097c478bd9Sstevel@tonic-gate _list_form (
9107c478bd9Sstevel@tonic-gate FORM * pf,
9117c478bd9Sstevel@tonic-gate FALERT * palert,
9127c478bd9Sstevel@tonic-gate FILE * align_fp
9137c478bd9Sstevel@tonic-gate )
9147c478bd9Sstevel@tonic-gate #else
9157c478bd9Sstevel@tonic-gate _list_form (pf, palert, align_fp)
9167c478bd9Sstevel@tonic-gate FORM * pf;
9177c478bd9Sstevel@tonic-gate FALERT * palert;
9187c478bd9Sstevel@tonic-gate FILE * align_fp;
9197c478bd9Sstevel@tonic-gate #endif
9207c478bd9Sstevel@tonic-gate {
9217c478bd9Sstevel@tonic-gate size_t n;
9227c478bd9Sstevel@tonic-gate
9237c478bd9Sstevel@tonic-gate char buf[BUFSIZ];
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate int which_set[FO_MAX];
9267c478bd9Sstevel@tonic-gate int fld,whichVal;
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate whichVal = (pf->paper && (L == 0) ? 0 : 1);
9307c478bd9Sstevel@tonic-gate for (fld = 0; fld < FO_MAX; fld++)
9317c478bd9Sstevel@tonic-gate which_set[fld] = whichVal;
9327c478bd9Sstevel@tonic-gate if (!align_fp)
9337c478bd9Sstevel@tonic-gate which_set[FO_ALIGN] = 0;
9347c478bd9Sstevel@tonic-gate if (pf->paper)
9357c478bd9Sstevel@tonic-gate which_set[FO_PAPER] = 1;
9367c478bd9Sstevel@tonic-gate wrform (pf->name, pf, 1, onerror, which_set);
9377c478bd9Sstevel@tonic-gate if (align_fp)
9387c478bd9Sstevel@tonic-gate while ((n = fread(buf, 1, BUFSIZ, align_fp)))
9397c478bd9Sstevel@tonic-gate write (1, buf, n);
9407c478bd9Sstevel@tonic-gate }
9417c478bd9Sstevel@tonic-gate
9427c478bd9Sstevel@tonic-gate /**
9437c478bd9Sstevel@tonic-gate ** _list_alert()
9447c478bd9Sstevel@tonic-gate **/
9457c478bd9Sstevel@tonic-gate
946f928ce67Sceastha static void
9477c478bd9Sstevel@tonic-gate #if defined(__STDC__)
_list_alert(FORM * ignore,FALERT * palert)9487c478bd9Sstevel@tonic-gate _list_alert (
9497c478bd9Sstevel@tonic-gate FORM * ignore,
9507c478bd9Sstevel@tonic-gate FALERT * palert
9517c478bd9Sstevel@tonic-gate )
9527c478bd9Sstevel@tonic-gate #else
9537c478bd9Sstevel@tonic-gate _list_alert (ignore, palert)
9547c478bd9Sstevel@tonic-gate FORM * ignore;
9557c478bd9Sstevel@tonic-gate FALERT * palert;
9567c478bd9Sstevel@tonic-gate #endif
9577c478bd9Sstevel@tonic-gate {
9587c478bd9Sstevel@tonic-gate printalert (stdout, palert, 0);
9597c478bd9Sstevel@tonic-gate }
9607c478bd9Sstevel@tonic-gate
9617c478bd9Sstevel@tonic-gate /**
9627c478bd9Sstevel@tonic-gate ** _list_both()
9637c478bd9Sstevel@tonic-gate **/
9647c478bd9Sstevel@tonic-gate
965f928ce67Sceastha static void
9667c478bd9Sstevel@tonic-gate #if defined(__STDC__)
_list_both(FORM * pf,FALERT * palert,FILE * align_fp)9677c478bd9Sstevel@tonic-gate _list_both (
9687c478bd9Sstevel@tonic-gate FORM * pf,
9697c478bd9Sstevel@tonic-gate FALERT * palert,
9707c478bd9Sstevel@tonic-gate FILE * align_fp
9717c478bd9Sstevel@tonic-gate )
9727c478bd9Sstevel@tonic-gate #else
9737c478bd9Sstevel@tonic-gate _list_both (pf, palert, align_fp)
9747c478bd9Sstevel@tonic-gate FORM * pf;
9757c478bd9Sstevel@tonic-gate FALERT * palert;
9767c478bd9Sstevel@tonic-gate FILE * align_fp;
9777c478bd9Sstevel@tonic-gate #endif
9787c478bd9Sstevel@tonic-gate {
9797c478bd9Sstevel@tonic-gate _list_alert (pf, palert);
9807c478bd9Sstevel@tonic-gate _list_form (pf, palert, align_fp);
9817c478bd9Sstevel@tonic-gate }
9827c478bd9Sstevel@tonic-gate
9837c478bd9Sstevel@tonic-gate /**
9847c478bd9Sstevel@tonic-gate ** any_alert()
9857c478bd9Sstevel@tonic-gate **/
9867c478bd9Sstevel@tonic-gate
9877c478bd9Sstevel@tonic-gate static int
9887c478bd9Sstevel@tonic-gate #if defined(__STDC__)
any_alert(char * form,FILE * ignore,FALERT * p_new_alert)9897c478bd9Sstevel@tonic-gate any_alert (
9907c478bd9Sstevel@tonic-gate char * form,
9917c478bd9Sstevel@tonic-gate FILE * ignore,
9927c478bd9Sstevel@tonic-gate FALERT * p_new_alert
9937c478bd9Sstevel@tonic-gate )
9947c478bd9Sstevel@tonic-gate #else
9957c478bd9Sstevel@tonic-gate any_alert (form, ignore, p_new_alert)
9967c478bd9Sstevel@tonic-gate char * form;
9977c478bd9Sstevel@tonic-gate FILE * ignore;
9987c478bd9Sstevel@tonic-gate FALERT * p_new_alert;
9997c478bd9Sstevel@tonic-gate #endif
10007c478bd9Sstevel@tonic-gate {
10017c478bd9Sstevel@tonic-gate FORM fbuf;
10027c478bd9Sstevel@tonic-gate
10037c478bd9Sstevel@tonic-gate FALERT alert;
10047c478bd9Sstevel@tonic-gate
10057c478bd9Sstevel@tonic-gate
10067c478bd9Sstevel@tonic-gate while (getform(NAME_ALL, &fbuf, &alert, (FILE **)0) == 0)
10077c478bd9Sstevel@tonic-gate if (!alert.shcmd)
10087c478bd9Sstevel@tonic-gate if (putform(fbuf.name, (FORM *)0, p_new_alert, (FILE **)0) == -1) {
10097c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_PUTFORM, fbuf.name, PERROR);
10107c478bd9Sstevel@tonic-gate return (1);
10117c478bd9Sstevel@tonic-gate }
10127c478bd9Sstevel@tonic-gate
10137c478bd9Sstevel@tonic-gate return (0);
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate /**
10177c478bd9Sstevel@tonic-gate ** delete_form()
10187c478bd9Sstevel@tonic-gate ** quiet_alert()
10197c478bd9Sstevel@tonic-gate **/
10207c478bd9Sstevel@tonic-gate
10217c478bd9Sstevel@tonic-gate #if defined(__STDC__)
10227c478bd9Sstevel@tonic-gate
10237c478bd9Sstevel@tonic-gate static int dq ( char * , int (*)() );
10247c478bd9Sstevel@tonic-gate static int _delete_form ( char * );
10257c478bd9Sstevel@tonic-gate static int _quiet_alert ( char * );
10267c478bd9Sstevel@tonic-gate
10277c478bd9Sstevel@tonic-gate #else
10287c478bd9Sstevel@tonic-gate
10297c478bd9Sstevel@tonic-gate static int dq();
10307c478bd9Sstevel@tonic-gate static int _delete_form();
10317c478bd9Sstevel@tonic-gate static int _quiet_alert();
10327c478bd9Sstevel@tonic-gate
10337c478bd9Sstevel@tonic-gate #endif
10347c478bd9Sstevel@tonic-gate
10357c478bd9Sstevel@tonic-gate static int
10367c478bd9Sstevel@tonic-gate #if defined(__STDC__)
delete_form(char * form)10377c478bd9Sstevel@tonic-gate delete_form (
10387c478bd9Sstevel@tonic-gate char *form
10397c478bd9Sstevel@tonic-gate )
10407c478bd9Sstevel@tonic-gate #else
10417c478bd9Sstevel@tonic-gate delete_form (form)
10427c478bd9Sstevel@tonic-gate char *form;
10437c478bd9Sstevel@tonic-gate #endif
10447c478bd9Sstevel@tonic-gate {
10457c478bd9Sstevel@tonic-gate return (dq(form, _delete_form));
10467c478bd9Sstevel@tonic-gate }
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gate static int
10497c478bd9Sstevel@tonic-gate #if defined(__STDC__)
quiet_alert(char * form)10507c478bd9Sstevel@tonic-gate quiet_alert (
10517c478bd9Sstevel@tonic-gate char * form
10527c478bd9Sstevel@tonic-gate )
10537c478bd9Sstevel@tonic-gate #else
10547c478bd9Sstevel@tonic-gate quiet_alert (form)
10557c478bd9Sstevel@tonic-gate char * form;
10567c478bd9Sstevel@tonic-gate #endif
10577c478bd9Sstevel@tonic-gate {
10587c478bd9Sstevel@tonic-gate return (dq(form, _quiet_alert));
10597c478bd9Sstevel@tonic-gate }
10607c478bd9Sstevel@tonic-gate
10617c478bd9Sstevel@tonic-gate static int
10627c478bd9Sstevel@tonic-gate #if defined(__STDC__)
dq(char * form,int (* subaction)())10637c478bd9Sstevel@tonic-gate dq (
10647c478bd9Sstevel@tonic-gate char *form,
10657c478bd9Sstevel@tonic-gate int (*subaction)()
10667c478bd9Sstevel@tonic-gate )
10677c478bd9Sstevel@tonic-gate #else
10687c478bd9Sstevel@tonic-gate dq (form, subaction)
10697c478bd9Sstevel@tonic-gate char *form;
10707c478bd9Sstevel@tonic-gate int (*subaction)();
10717c478bd9Sstevel@tonic-gate #endif
10727c478bd9Sstevel@tonic-gate {
10737c478bd9Sstevel@tonic-gate FORM fbuf;
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gate
10767c478bd9Sstevel@tonic-gate if (STREQU(NAME_ANY, form) || STREQU(NAME_NONE, form)) {
10777c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_ANYNONE);
10787c478bd9Sstevel@tonic-gate exit (1);
10797c478bd9Sstevel@tonic-gate }
10807c478bd9Sstevel@tonic-gate
10817c478bd9Sstevel@tonic-gate if (STREQU(NAME_ALL, form)) {
10827c478bd9Sstevel@tonic-gate
10837c478bd9Sstevel@tonic-gate while (getform(form, &fbuf, (FALERT *)0, (FILE **)0) == 0)
10847c478bd9Sstevel@tonic-gate if ((*subaction)(fbuf.name) == 1)
10857c478bd9Sstevel@tonic-gate return (1);
10867c478bd9Sstevel@tonic-gate
10877c478bd9Sstevel@tonic-gate switch (errno) {
10887c478bd9Sstevel@tonic-gate case ENOENT:
10897c478bd9Sstevel@tonic-gate return (0);
10907c478bd9Sstevel@tonic-gate default:
10917c478bd9Sstevel@tonic-gate /*
10927c478bd9Sstevel@tonic-gate * Don't know if we'll have a good name
10937c478bd9Sstevel@tonic-gate * in the "all" case on getting here, so
10947c478bd9Sstevel@tonic-gate * punt on naming the form in the error
10957c478bd9Sstevel@tonic-gate * message.
10967c478bd9Sstevel@tonic-gate */
10977c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_GETFORM, form, PERROR);
10987c478bd9Sstevel@tonic-gate return (1);
10997c478bd9Sstevel@tonic-gate }
11007c478bd9Sstevel@tonic-gate
11017c478bd9Sstevel@tonic-gate } else {
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate if (getform(form, &fbuf, (FALERT *)0, (FILE **)0) == 0)
11047c478bd9Sstevel@tonic-gate return ((*subaction)(fbuf.name));
11057c478bd9Sstevel@tonic-gate
11067c478bd9Sstevel@tonic-gate switch (errno) {
11077c478bd9Sstevel@tonic-gate case ENOENT:
11087c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_NOFORM, form);
11097c478bd9Sstevel@tonic-gate return (1);
11107c478bd9Sstevel@tonic-gate default:
11117c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_GETFORM, form, PERROR);
11127c478bd9Sstevel@tonic-gate return (1);
11137c478bd9Sstevel@tonic-gate }
11147c478bd9Sstevel@tonic-gate }
11157c478bd9Sstevel@tonic-gate }
11167c478bd9Sstevel@tonic-gate
11177c478bd9Sstevel@tonic-gate static int
11187c478bd9Sstevel@tonic-gate #if defined(__STDC__)
_delete_form(char * form)11197c478bd9Sstevel@tonic-gate _delete_form (
11207c478bd9Sstevel@tonic-gate char *form
11217c478bd9Sstevel@tonic-gate )
11227c478bd9Sstevel@tonic-gate #else
11237c478bd9Sstevel@tonic-gate _delete_form (form)
11247c478bd9Sstevel@tonic-gate char *form;
11257c478bd9Sstevel@tonic-gate #endif
11267c478bd9Sstevel@tonic-gate {
11277c478bd9Sstevel@tonic-gate switch (notify_spooler(S_UNLOAD_FORM, R_UNLOAD_FORM, form)) {
11287c478bd9Sstevel@tonic-gate
11297c478bd9Sstevel@tonic-gate case -1:
11307c478bd9Sstevel@tonic-gate if (anyrequests()) {
11317c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_MOPENREQX);
11327c478bd9Sstevel@tonic-gate return (1);
11337c478bd9Sstevel@tonic-gate }
11347c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
11357c478bd9Sstevel@tonic-gate
11367c478bd9Sstevel@tonic-gate case MNODEST:
11377c478bd9Sstevel@tonic-gate if (delform(form) == -1) {
11387c478bd9Sstevel@tonic-gate if (errno == ENOENT) {
11397c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_NOFORM, form);
11407c478bd9Sstevel@tonic-gate return (1);
11417c478bd9Sstevel@tonic-gate } else {
11427c478bd9Sstevel@tonic-gate LP_ERRMSG2 (
11437c478bd9Sstevel@tonic-gate ERROR,
11447c478bd9Sstevel@tonic-gate E_FOR_UNKNOWN,
11457c478bd9Sstevel@tonic-gate form,
11467c478bd9Sstevel@tonic-gate PERROR
11477c478bd9Sstevel@tonic-gate );
11487c478bd9Sstevel@tonic-gate return (1);
11497c478bd9Sstevel@tonic-gate }
11507c478bd9Sstevel@tonic-gate }
11517c478bd9Sstevel@tonic-gate break;
11527c478bd9Sstevel@tonic-gate
11537c478bd9Sstevel@tonic-gate case MOK:
11547c478bd9Sstevel@tonic-gate if (delform(form) == -1) {
11557c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_DELSTRANGE);
11567c478bd9Sstevel@tonic-gate return (1);
11577c478bd9Sstevel@tonic-gate }
11587c478bd9Sstevel@tonic-gate break;
11597c478bd9Sstevel@tonic-gate }
11607c478bd9Sstevel@tonic-gate return (0);
11617c478bd9Sstevel@tonic-gate }
11627c478bd9Sstevel@tonic-gate
11637c478bd9Sstevel@tonic-gate static int
11647c478bd9Sstevel@tonic-gate #if defined(__STDC__)
_quiet_alert(char * form)11657c478bd9Sstevel@tonic-gate _quiet_alert (
11667c478bd9Sstevel@tonic-gate char * form
11677c478bd9Sstevel@tonic-gate )
11687c478bd9Sstevel@tonic-gate #else
11697c478bd9Sstevel@tonic-gate _quiet_alert (form)
11707c478bd9Sstevel@tonic-gate char * form;
11717c478bd9Sstevel@tonic-gate #endif
11727c478bd9Sstevel@tonic-gate {
11737c478bd9Sstevel@tonic-gate char *msgbuf;
11747c478bd9Sstevel@tonic-gate
11757c478bd9Sstevel@tonic-gate int mtype;
11767c478bd9Sstevel@tonic-gate
11777c478bd9Sstevel@tonic-gate int size;
11787c478bd9Sstevel@tonic-gate
11797c478bd9Sstevel@tonic-gate short status;
11807c478bd9Sstevel@tonic-gate
11817c478bd9Sstevel@tonic-gate /*
11827c478bd9Sstevel@tonic-gate * If the attempt to open a message queue to the
11837c478bd9Sstevel@tonic-gate * Spooler fails, assume it isn't running and just
11847c478bd9Sstevel@tonic-gate * return--don't say anything, `cause the user may
11857c478bd9Sstevel@tonic-gate * know. Any other failure deserves an error message.
11867c478bd9Sstevel@tonic-gate */
11877c478bd9Sstevel@tonic-gate
11887c478bd9Sstevel@tonic-gate if (mopen() == -1)
11897c478bd9Sstevel@tonic-gate return (0);
11907c478bd9Sstevel@tonic-gate
11917c478bd9Sstevel@tonic-gate size = putmessage (NULL, S_QUIET_ALERT, form, QA_FORM);
11927c478bd9Sstevel@tonic-gate msgbuf = malloc(size);
11937c478bd9Sstevel@tonic-gate putmessage (msgbuf, S_QUIET_ALERT, form, QA_FORM);
11947c478bd9Sstevel@tonic-gate
11957c478bd9Sstevel@tonic-gate if (msend(msgbuf) == -1) {
11967c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_MSEND);
11977c478bd9Sstevel@tonic-gate mclose ();
11987c478bd9Sstevel@tonic-gate return (1);
11997c478bd9Sstevel@tonic-gate }
12007c478bd9Sstevel@tonic-gate
12017c478bd9Sstevel@tonic-gate if (mrecv(msgbuf, size) == -1) {
12027c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_MRECV);
12037c478bd9Sstevel@tonic-gate mclose ();
12047c478bd9Sstevel@tonic-gate return (1);
12057c478bd9Sstevel@tonic-gate }
12067c478bd9Sstevel@tonic-gate
12077c478bd9Sstevel@tonic-gate mtype = getmessage(msgbuf, R_QUIET_ALERT, &status);
12087c478bd9Sstevel@tonic-gate free (msgbuf);
12097c478bd9Sstevel@tonic-gate mclose ();
12107c478bd9Sstevel@tonic-gate if (mtype != R_QUIET_ALERT) {
12117c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_BADREPLY);
12127c478bd9Sstevel@tonic-gate return (1);
12137c478bd9Sstevel@tonic-gate }
12147c478bd9Sstevel@tonic-gate
12157c478bd9Sstevel@tonic-gate switch (status) {
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gate case MOK:
12187c478bd9Sstevel@tonic-gate break;
12197c478bd9Sstevel@tonic-gate
12207c478bd9Sstevel@tonic-gate case MNODEST: /* not quite, but not a lie either */
12217c478bd9Sstevel@tonic-gate case MERRDEST:
12227c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_LP_NOQUIET, form);
12237c478bd9Sstevel@tonic-gate break;
12247c478bd9Sstevel@tonic-gate
12257c478bd9Sstevel@tonic-gate case MNOPERM: /* taken care of up front */
12267c478bd9Sstevel@tonic-gate default:
12277c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, status);
12287c478bd9Sstevel@tonic-gate return (1);
12297c478bd9Sstevel@tonic-gate /*NOTREACHED*/
12307c478bd9Sstevel@tonic-gate }
12317c478bd9Sstevel@tonic-gate
12327c478bd9Sstevel@tonic-gate return (0);
12337c478bd9Sstevel@tonic-gate }
12347c478bd9Sstevel@tonic-gate
12357c478bd9Sstevel@tonic-gate /**
12367c478bd9Sstevel@tonic-gate ** set_action() - CHECK FOR AMBIGUOUS ACTIONS
12377c478bd9Sstevel@tonic-gate **/
12387c478bd9Sstevel@tonic-gate
12397c478bd9Sstevel@tonic-gate static Action
12407c478bd9Sstevel@tonic-gate #if defined(__STDC__)
set_action(Action action,char * option)12417c478bd9Sstevel@tonic-gate set_action (
12427c478bd9Sstevel@tonic-gate Action action,
12437c478bd9Sstevel@tonic-gate char * option
12447c478bd9Sstevel@tonic-gate )
12457c478bd9Sstevel@tonic-gate #else
12467c478bd9Sstevel@tonic-gate set_action (action, option)
12477c478bd9Sstevel@tonic-gate Action action;
12487c478bd9Sstevel@tonic-gate char * option;
12497c478bd9Sstevel@tonic-gate #endif
12507c478bd9Sstevel@tonic-gate {
12517c478bd9Sstevel@tonic-gate static Action prev_action = 0;
12527c478bd9Sstevel@tonic-gate
12537c478bd9Sstevel@tonic-gate static char * prev_option;
12547c478bd9Sstevel@tonic-gate
12557c478bd9Sstevel@tonic-gate
12567c478bd9Sstevel@tonic-gate if (
12577c478bd9Sstevel@tonic-gate action == list_form && prev_action == list_alert
12587c478bd9Sstevel@tonic-gate || action == list_alert && prev_action == list_form
12597c478bd9Sstevel@tonic-gate )
12607c478bd9Sstevel@tonic-gate action = list_both;
12617c478bd9Sstevel@tonic-gate
12627c478bd9Sstevel@tonic-gate else if (
12637c478bd9Sstevel@tonic-gate action == add_form && prev_action == add_alert
12647c478bd9Sstevel@tonic-gate || action == add_alert && prev_action == add_form
12657c478bd9Sstevel@tonic-gate )
12667c478bd9Sstevel@tonic-gate action = add_form;
12677c478bd9Sstevel@tonic-gate
12687c478bd9Sstevel@tonic-gate else if (
12697c478bd9Sstevel@tonic-gate action == any_alert && prev_action == add_alert
12707c478bd9Sstevel@tonic-gate || action == add_alert && prev_action == any_alert
12717c478bd9Sstevel@tonic-gate )
12727c478bd9Sstevel@tonic-gate action = any_alert;
12737c478bd9Sstevel@tonic-gate
12747c478bd9Sstevel@tonic-gate else if (prev_action && prev_action != action) {
12757c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_LP_AMBIG, option, prev_option);
12767c478bd9Sstevel@tonic-gate exit (1);
12777c478bd9Sstevel@tonic-gate }
12787c478bd9Sstevel@tonic-gate
12797c478bd9Sstevel@tonic-gate OK: prev_action = action;
12807c478bd9Sstevel@tonic-gate prev_option = option;
12817c478bd9Sstevel@tonic-gate return (action);
12827c478bd9Sstevel@tonic-gate }
12837c478bd9Sstevel@tonic-gate
12847c478bd9Sstevel@tonic-gate /**
12857c478bd9Sstevel@tonic-gate ** notify_spooler() - NOTIFY SPOOLER OF ACTION ON FORMS DB
12867c478bd9Sstevel@tonic-gate **/
12877c478bd9Sstevel@tonic-gate
12887c478bd9Sstevel@tonic-gate static int
12897c478bd9Sstevel@tonic-gate #if defined(__STDC__)
notify_spooler(int sendmsg,int replymsg,char * form)12907c478bd9Sstevel@tonic-gate notify_spooler (
12917c478bd9Sstevel@tonic-gate int sendmsg,
12927c478bd9Sstevel@tonic-gate int replymsg,
12937c478bd9Sstevel@tonic-gate char * form
12947c478bd9Sstevel@tonic-gate )
12957c478bd9Sstevel@tonic-gate #else
12967c478bd9Sstevel@tonic-gate notify_spooler (sendmsg, replymsg, form)
12977c478bd9Sstevel@tonic-gate int sendmsg;
12987c478bd9Sstevel@tonic-gate int replymsg;
12997c478bd9Sstevel@tonic-gate char * form;
13007c478bd9Sstevel@tonic-gate #endif
13017c478bd9Sstevel@tonic-gate {
13027c478bd9Sstevel@tonic-gate char * msgbuf;
13037c478bd9Sstevel@tonic-gate
13047c478bd9Sstevel@tonic-gate int mtype;
13057c478bd9Sstevel@tonic-gate int size;
13067c478bd9Sstevel@tonic-gate
13077c478bd9Sstevel@tonic-gate short status;
13087c478bd9Sstevel@tonic-gate
13097c478bd9Sstevel@tonic-gate /*
13107c478bd9Sstevel@tonic-gate * If the attempt to open a message queue to the
13117c478bd9Sstevel@tonic-gate * Spooler fails, assume it isn't running and just
13127c478bd9Sstevel@tonic-gate * return--don't say anything, `cause the user may
13137c478bd9Sstevel@tonic-gate * know. Any other failure deserves an error message.
13147c478bd9Sstevel@tonic-gate */
13157c478bd9Sstevel@tonic-gate
13167c478bd9Sstevel@tonic-gate if (mopen() == -1)
13177c478bd9Sstevel@tonic-gate return (-1);
13187c478bd9Sstevel@tonic-gate
13197c478bd9Sstevel@tonic-gate size = putmessage((char *)0, sendmsg, form);
13207c478bd9Sstevel@tonic-gate msgbuf = malloc(size);
13217c478bd9Sstevel@tonic-gate putmessage (msgbuf, sendmsg, form);
13227c478bd9Sstevel@tonic-gate
13237c478bd9Sstevel@tonic-gate if (msend(msgbuf) == -1) {
13247c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_MSEND);
13257c478bd9Sstevel@tonic-gate mclose ();
13267c478bd9Sstevel@tonic-gate exit (1);
13277c478bd9Sstevel@tonic-gate }
13287c478bd9Sstevel@tonic-gate if (mrecv(msgbuf, size) == -1) {
13297c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_MRECV);
13307c478bd9Sstevel@tonic-gate mclose ();
13317c478bd9Sstevel@tonic-gate exit (1);
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate mclose ();
13347c478bd9Sstevel@tonic-gate
13357c478bd9Sstevel@tonic-gate mtype = getmessage(msgbuf, replymsg, &status);
13367c478bd9Sstevel@tonic-gate free (msgbuf);
13377c478bd9Sstevel@tonic-gate if (mtype != replymsg) {
13387c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_BADREPLY);
13397c478bd9Sstevel@tonic-gate exit (1);
13407c478bd9Sstevel@tonic-gate }
13417c478bd9Sstevel@tonic-gate
13427c478bd9Sstevel@tonic-gate if (status == MOK)
13437c478bd9Sstevel@tonic-gate return (MOK);
13447c478bd9Sstevel@tonic-gate
13457c478bd9Sstevel@tonic-gate if (sendmsg == S_LOAD_FORM)
13467c478bd9Sstevel@tonic-gate switch (status) {
13477c478bd9Sstevel@tonic-gate case MNOSPACE:
13487c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_FOR_NOSPACE);
13497c478bd9Sstevel@tonic-gate break;
13507c478bd9Sstevel@tonic-gate case MNOPERM:
13517c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_NOTADM);
13527c478bd9Sstevel@tonic-gate break;
13537c478bd9Sstevel@tonic-gate
13547c478bd9Sstevel@tonic-gate /*
13557c478bd9Sstevel@tonic-gate * The following two error conditions should have
13567c478bd9Sstevel@tonic-gate * already been trapped, so treat them as bad status
13577c478bd9Sstevel@tonic-gate * should they occur.
13587c478bd9Sstevel@tonic-gate */
13597c478bd9Sstevel@tonic-gate case MNODEST:
13607c478bd9Sstevel@tonic-gate case MERRDEST:
13617c478bd9Sstevel@tonic-gate default:
13627c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_LP_BADSTATUS, status);
13637c478bd9Sstevel@tonic-gate break;
13647c478bd9Sstevel@tonic-gate }
13657c478bd9Sstevel@tonic-gate
13667c478bd9Sstevel@tonic-gate if (sendmsg == S_UNLOAD_FORM)
13677c478bd9Sstevel@tonic-gate switch (status) {
13687c478bd9Sstevel@tonic-gate case MBUSY:
13697c478bd9Sstevel@tonic-gate LP_ERRMSG1 (ERROR, E_FOR_FORMBUSY, form);
13707c478bd9Sstevel@tonic-gate break;
13717c478bd9Sstevel@tonic-gate case MNODEST:
13727c478bd9Sstevel@tonic-gate return (MNODEST);
13737c478bd9Sstevel@tonic-gate case MNOPERM:
13747c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_NOTADM);
13757c478bd9Sstevel@tonic-gate break;
13767c478bd9Sstevel@tonic-gate default:
13777c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_BADSTATUS);
13787c478bd9Sstevel@tonic-gate break;
13797c478bd9Sstevel@tonic-gate }
13807c478bd9Sstevel@tonic-gate
13817c478bd9Sstevel@tonic-gate exit (1);
13827c478bd9Sstevel@tonic-gate }
13837c478bd9Sstevel@tonic-gate
13847c478bd9Sstevel@tonic-gate /**
13857c478bd9Sstevel@tonic-gate ** onerror()
13867c478bd9Sstevel@tonic-gate **/
13877c478bd9Sstevel@tonic-gate
13887c478bd9Sstevel@tonic-gate static int
13897c478bd9Sstevel@tonic-gate #if defined(__STDC__)
onerror(int Errno,int lp_errno,int linenum)13907c478bd9Sstevel@tonic-gate onerror (
13917c478bd9Sstevel@tonic-gate int Errno,
13927c478bd9Sstevel@tonic-gate int lp_errno,
13937c478bd9Sstevel@tonic-gate int linenum
13947c478bd9Sstevel@tonic-gate )
13957c478bd9Sstevel@tonic-gate #else
13967c478bd9Sstevel@tonic-gate onerror (Errno, lp_errno, linenum)
13977c478bd9Sstevel@tonic-gate int Errno;
13987c478bd9Sstevel@tonic-gate int lp_errno;
13997c478bd9Sstevel@tonic-gate int linenum;
14007c478bd9Sstevel@tonic-gate #endif
14017c478bd9Sstevel@tonic-gate {
14027c478bd9Sstevel@tonic-gate static int nerrors = 0;
14037c478bd9Sstevel@tonic-gate
14047c478bd9Sstevel@tonic-gate
14057c478bd9Sstevel@tonic-gate if (Errno == EBADF) {
14067c478bd9Sstevel@tonic-gate switch (lp_errno) {
14077c478bd9Sstevel@tonic-gate case LP_EBADSDN:
14087c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_BADSCALE, linenum);
14097c478bd9Sstevel@tonic-gate break;
14107c478bd9Sstevel@tonic-gate case LP_EBADINT:
14117c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_BADINT, linenum);
14127c478bd9Sstevel@tonic-gate break;
14137c478bd9Sstevel@tonic-gate case LP_EBADNAME:
14147c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_NOTNAME, linenum);
14157c478bd9Sstevel@tonic-gate break;
14167c478bd9Sstevel@tonic-gate case LP_EBADARG:
14177c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_BADCHSETQUALIFIER, linenum);
14187c478bd9Sstevel@tonic-gate break;
14197c478bd9Sstevel@tonic-gate case LP_ETRAILIN:
14207c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_TRAILIN, linenum);
14217c478bd9Sstevel@tonic-gate break;
14227c478bd9Sstevel@tonic-gate case LP_EBADCTYPE:
14237c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_NOTCTYPE, linenum);
14247c478bd9Sstevel@tonic-gate break;
14257c478bd9Sstevel@tonic-gate case LP_EBADHDR:
14267c478bd9Sstevel@tonic-gate LP_ERRMSG1 (WARNING, E_FOR_BADHDR, linenum);
14277c478bd9Sstevel@tonic-gate break;
14287c478bd9Sstevel@tonic-gate }
14297c478bd9Sstevel@tonic-gate if (nerrors++ >= 5) {
14307c478bd9Sstevel@tonic-gate LP_ERRMSG (ERROR, E_LP_GARBAGE);
14317c478bd9Sstevel@tonic-gate return (-1);
14327c478bd9Sstevel@tonic-gate }
14337c478bd9Sstevel@tonic-gate return (0);
14347c478bd9Sstevel@tonic-gate } else {
14357c478bd9Sstevel@tonic-gate LP_ERRMSG2 (ERROR, E_FOR_UNKNOWN, "(stdin)", PERROR);
14367c478bd9Sstevel@tonic-gate return (-1);
14377c478bd9Sstevel@tonic-gate }
14387c478bd9Sstevel@tonic-gate }
1439