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