1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright (c) 1998 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <stdio.h> 30*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 32*7c478bd9Sstevel@tonic-gate #include <stdarg.h> 33*7c478bd9Sstevel@tonic-gate #include <unistd.h> 34*7c478bd9Sstevel@tonic-gate #include <string.h> 35*7c478bd9Sstevel@tonic-gate #include <syslog.h> 36*7c478bd9Sstevel@tonic-gate #include <locale.h> 37*7c478bd9Sstevel@tonic-gate #ifndef SUNOS_4 38*7c478bd9Sstevel@tonic-gate #include <libintl.h> 39*7c478bd9Sstevel@tonic-gate #endif 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #include <print/ns.h> 42*7c478bd9Sstevel@tonic-gate #include <print/misc.h> 43*7c478bd9Sstevel@tonic-gate #include <print/list.h> 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate extern char *optarg; 46*7c478bd9Sstevel@tonic-gate extern int optind, opterr, optopt; 47*7c478bd9Sstevel@tonic-gate extern char *getenv(const char *); 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate static void 51*7c478bd9Sstevel@tonic-gate Usage(char *name) 52*7c478bd9Sstevel@tonic-gate { 53*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 54*7c478bd9Sstevel@tonic-gate gettext("Usage: %s [-k key] [list|(printer) ...]\n"), 55*7c478bd9Sstevel@tonic-gate name); 56*7c478bd9Sstevel@tonic-gate exit(1); 57*7c478bd9Sstevel@tonic-gate } 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate static int 60*7c478bd9Sstevel@tonic-gate display_kvp(char *key, char *value) 61*7c478bd9Sstevel@tonic-gate { 62*7c478bd9Sstevel@tonic-gate int rc = -1; 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate if (value != NULL) { 65*7c478bd9Sstevel@tonic-gate rc = 0; 66*7c478bd9Sstevel@tonic-gate (void) printf("\n\t%s=%s", key, value); 67*7c478bd9Sstevel@tonic-gate } else 68*7c478bd9Sstevel@tonic-gate (void) printf(gettext("\n\t%s - undefined"), key); 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate return (rc); 71*7c478bd9Sstevel@tonic-gate } 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate static int 75*7c478bd9Sstevel@tonic-gate display_value(ns_printer_t *printer, char *name, char **keys) 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate int rc = -1; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate if (printer != NULL) { 80*7c478bd9Sstevel@tonic-gate rc = 0; 81*7c478bd9Sstevel@tonic-gate (void) printf("%s:", name); 82*7c478bd9Sstevel@tonic-gate if (keys != NULL) { 83*7c478bd9Sstevel@tonic-gate while (*keys != NULL) { 84*7c478bd9Sstevel@tonic-gate char *string = ns_get_value_string(*keys, 85*7c478bd9Sstevel@tonic-gate printer); 86*7c478bd9Sstevel@tonic-gate rc += display_kvp(*keys, string); 87*7c478bd9Sstevel@tonic-gate keys++; 88*7c478bd9Sstevel@tonic-gate } 89*7c478bd9Sstevel@tonic-gate } else { 90*7c478bd9Sstevel@tonic-gate ns_kvp_t **list = printer->attributes; 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate for (list = printer->attributes; 93*7c478bd9Sstevel@tonic-gate (list != NULL && *list != NULL); list++) { 94*7c478bd9Sstevel@tonic-gate char *string; 95*7c478bd9Sstevel@tonic-gate if (((*list)->key[0] == '\t') || 96*7c478bd9Sstevel@tonic-gate ((*list)->key[0] == ' ')) 97*7c478bd9Sstevel@tonic-gate continue; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate string = ns_get_value_string((*list)->key, 100*7c478bd9Sstevel@tonic-gate printer); 101*7c478bd9Sstevel@tonic-gate rc += display_kvp((*list)->key, string); 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate (void) printf("\n"); 105*7c478bd9Sstevel@tonic-gate } else 106*7c478bd9Sstevel@tonic-gate (void) printf(gettext("%s: Not Found\n"), name); 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate return (rc); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate /* 113*7c478bd9Sstevel@tonic-gate * main() calls the appropriate routine to parse the command line arguments 114*7c478bd9Sstevel@tonic-gate * and then calls the local remove routine, followed by the remote remove 115*7c478bd9Sstevel@tonic-gate * routine to remove jobs. 116*7c478bd9Sstevel@tonic-gate */ 117*7c478bd9Sstevel@tonic-gate int 118*7c478bd9Sstevel@tonic-gate main(int ac, char *av[]) 119*7c478bd9Sstevel@tonic-gate { 120*7c478bd9Sstevel@tonic-gate char *program; 121*7c478bd9Sstevel@tonic-gate int c; 122*7c478bd9Sstevel@tonic-gate char **keys = NULL; 123*7c478bd9Sstevel@tonic-gate char *ns = NULL; 124*7c478bd9Sstevel@tonic-gate int exit_code = 0; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 129*7c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 130*7c478bd9Sstevel@tonic-gate #endif 131*7c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate if ((program = strrchr(av[0], '/')) == NULL) 134*7c478bd9Sstevel@tonic-gate program = av[0]; 135*7c478bd9Sstevel@tonic-gate else 136*7c478bd9Sstevel@tonic-gate program++; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate openlog(program, LOG_PID, LOG_LPR); 139*7c478bd9Sstevel@tonic-gate while ((c = getopt(ac, av, "k:t:n:")) != EOF) 140*7c478bd9Sstevel@tonic-gate switch (c) { 141*7c478bd9Sstevel@tonic-gate case 'k': 142*7c478bd9Sstevel@tonic-gate case 't': 143*7c478bd9Sstevel@tonic-gate keys = (char **)list_append((void **)keys, 144*7c478bd9Sstevel@tonic-gate (void *)optarg); 145*7c478bd9Sstevel@tonic-gate break; 146*7c478bd9Sstevel@tonic-gate case 'n': 147*7c478bd9Sstevel@tonic-gate ns = optarg; 148*7c478bd9Sstevel@tonic-gate break; 149*7c478bd9Sstevel@tonic-gate default: 150*7c478bd9Sstevel@tonic-gate Usage(program); 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate if (optind >= ac) 154*7c478bd9Sstevel@tonic-gate Usage(program); 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gate ns = normalize_ns_name(ns); 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate while (optind < ac) { 159*7c478bd9Sstevel@tonic-gate char *name = av[optind++]; 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate if (strcmp(name, "list") == 0) { 162*7c478bd9Sstevel@tonic-gate ns_printer_t **printers = ns_printer_get_list(ns); 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate while (printers != NULL && *printers != NULL) { 165*7c478bd9Sstevel@tonic-gate exit_code += display_value(*printers, 166*7c478bd9Sstevel@tonic-gate (*printers)->name, keys); 167*7c478bd9Sstevel@tonic-gate printers++; 168*7c478bd9Sstevel@tonic-gate } 169*7c478bd9Sstevel@tonic-gate } else 170*7c478bd9Sstevel@tonic-gate exit_code = display_value(ns_printer_get_name(name, ns), 171*7c478bd9Sstevel@tonic-gate name, keys); 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate } 175*7c478bd9Sstevel@tonic-gate return (exit_code); 176*7c478bd9Sstevel@tonic-gate } 177