1355b4669Sjacobs /* 2355b4669Sjacobs * CDDL HEADER START 3355b4669Sjacobs * 4355b4669Sjacobs * The contents of this file are subject to the terms of the 5355b4669Sjacobs * Common Development and Distribution License (the "License"). 6355b4669Sjacobs * You may not use this file except in compliance with the License. 7355b4669Sjacobs * 8355b4669Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9355b4669Sjacobs * or http://www.opensolaris.org/os/licensing. 10355b4669Sjacobs * See the License for the specific language governing permissions 11355b4669Sjacobs * and limitations under the License. 12355b4669Sjacobs * 13355b4669Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 14355b4669Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15355b4669Sjacobs * If applicable, add the following below this CDDL HEADER, with the 16355b4669Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 17355b4669Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 18355b4669Sjacobs * 19355b4669Sjacobs * CDDL HEADER END 20355b4669Sjacobs */ 21355b4669Sjacobs 22355b4669Sjacobs /* 23355b4669Sjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24355b4669Sjacobs * Use is subject to license terms. 25355b4669Sjacobs * 26355b4669Sjacobs */ 27355b4669Sjacobs 28355b4669Sjacobs /* $Id: lpc.c 146 2006-03-24 00:26:54Z njacobs $ */ 29355b4669Sjacobs 30355b4669Sjacobs #pragma ident "%Z%%M% %I% %E% SMI" 31355b4669Sjacobs 32355b4669Sjacobs #include <stdio.h> 33355b4669Sjacobs #include <stdlib.h> 34355b4669Sjacobs #include <unistd.h> 35355b4669Sjacobs #include <string.h> 36355b4669Sjacobs #include <locale.h> 37355b4669Sjacobs #include <libintl.h> 38355b4669Sjacobs #include <papi.h> 39355b4669Sjacobs #include "common.h" 40355b4669Sjacobs 41355b4669Sjacobs typedef int (cmd_handler_t)(papi_service_t, char **); 42355b4669Sjacobs 43355b4669Sjacobs static papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 44355b4669Sjacobs 45355b4669Sjacobs /* ARGSUSED0 */ 46355b4669Sjacobs static int 47355b4669Sjacobs lpc_exit(papi_service_t svc, char **args) 48355b4669Sjacobs { 49355b4669Sjacobs exit(0); 50355b4669Sjacobs /* NOTREACHED */ 51355b4669Sjacobs return (0); 52355b4669Sjacobs } 53355b4669Sjacobs 54355b4669Sjacobs static int 55355b4669Sjacobs lpc_status(papi_service_t svc, char **args) 56355b4669Sjacobs { 57355b4669Sjacobs papi_status_t status; 58355b4669Sjacobs papi_printer_t p = NULL; 59355b4669Sjacobs char *pattrs[] = { "printer-state", "printer-state-reasons", 60355b4669Sjacobs "printer-is-accepting-jobs", NULL }; 61355b4669Sjacobs char *destination = args[1]; 62355b4669Sjacobs 63355b4669Sjacobs status = papiPrinterQuery(svc, destination, pattrs, NULL, &p); 64355b4669Sjacobs if (status == PAPI_OK) { 65355b4669Sjacobs papi_attribute_t **list = papiPrinterGetAttributeList(p); 66355b4669Sjacobs char accepting = 0; 67355b4669Sjacobs int32_t state = 0; 68355b4669Sjacobs 69355b4669Sjacobs printf("%s:\n", destination); 70355b4669Sjacobs 71355b4669Sjacobs (void) papiAttributeListGetBoolean(list, NULL, 72355b4669Sjacobs "printer-is-accepting-jobs", &accepting); 73355b4669Sjacobs printf(gettext("\tqueueing is %s\n"), 74355b4669Sjacobs (accepting ? gettext("enabled") : gettext("disabled"))); 75355b4669Sjacobs 76355b4669Sjacobs (void) papiAttributeListGetInteger(list, NULL, 77355b4669Sjacobs "printer-state", &state); 78355b4669Sjacobs printf("\tprinting is %s\n", 79355b4669Sjacobs ((state != 0x05) ? gettext("enabled") : 80355b4669Sjacobs gettext("disabled"))); 81355b4669Sjacobs 82355b4669Sjacobs if (state != 0x03) { /* !idle */ 83355b4669Sjacobs papi_job_t *jobs = NULL; 84355b4669Sjacobs int i = 0; 85355b4669Sjacobs 86355b4669Sjacobs (void) papiPrinterListJobs(svc, destination, NULL, 87355b4669Sjacobs PAPI_LIST_JOBS_ALL, 0, &jobs); 88355b4669Sjacobs if (jobs != NULL) { 89355b4669Sjacobs for (i = 0; jobs[i] != NULL; i++); 90355b4669Sjacobs papiJobListFree(jobs); 91355b4669Sjacobs } 92355b4669Sjacobs printf(gettext("\t%d entries in spool area\n"), i); 93355b4669Sjacobs } else 94355b4669Sjacobs printf(gettext("\tno entries\n")); 95355b4669Sjacobs 96355b4669Sjacobs if (state == 0x04) 97355b4669Sjacobs printf(gettext("\tdaemon present\n")); 98355b4669Sjacobs 99355b4669Sjacobs } else { 100355b4669Sjacobs fprintf(stderr, "%s: %s\n", destination, 101355b4669Sjacobs verbose_papi_message(svc, status)); 102355b4669Sjacobs return (-1); 103355b4669Sjacobs } 104355b4669Sjacobs 105355b4669Sjacobs papiPrinterFree(p); 106355b4669Sjacobs 107355b4669Sjacobs return (0); 108355b4669Sjacobs } 109355b4669Sjacobs 110355b4669Sjacobs static int 111355b4669Sjacobs lpc_abort(papi_service_t svc, char **args) 112355b4669Sjacobs { 113355b4669Sjacobs papi_status_t status; 114355b4669Sjacobs char *destination = args[1]; 115355b4669Sjacobs 116355b4669Sjacobs if (destination == NULL) { 117355b4669Sjacobs fprintf(stderr, gettext("Usage: abort (destination)\n")); 118355b4669Sjacobs return (-1); 119355b4669Sjacobs } 120355b4669Sjacobs 121355b4669Sjacobs status = papiPrinterPause(svc, destination, "paused via lpc abort"); 122355b4669Sjacobs if (status == PAPI_OK) { 123355b4669Sjacobs printf(gettext("%s: processing disabled after current job\n"), 124355b4669Sjacobs destination); 125355b4669Sjacobs } else { 126355b4669Sjacobs fprintf(stderr, "%s: %s\n", destination, 127355b4669Sjacobs verbose_papi_message(svc, status)); 128355b4669Sjacobs } 129355b4669Sjacobs 130355b4669Sjacobs return (0); 131355b4669Sjacobs } 132355b4669Sjacobs 133355b4669Sjacobs static int 134355b4669Sjacobs lpc_clean(papi_service_t svc, char **args) 135355b4669Sjacobs { 136355b4669Sjacobs papi_status_t status; 137355b4669Sjacobs papi_job_t *jobs = NULL; 138355b4669Sjacobs char *destination = args[1]; 139355b4669Sjacobs 140355b4669Sjacobs if (destination == NULL) { 141355b4669Sjacobs fprintf(stderr, gettext("Usage: clean (destination)\n")); 142355b4669Sjacobs return (-1); 143355b4669Sjacobs } 144355b4669Sjacobs 145355b4669Sjacobs status = papiPrinterPurgeJobs(svc, destination, &jobs); 146355b4669Sjacobs if (status != PAPI_OK) { 147355b4669Sjacobs fprintf(stderr, gettext("clean: %s: %s\n"), destination, 148355b4669Sjacobs verbose_papi_message(svc, status)); 149355b4669Sjacobs return (-1); 150355b4669Sjacobs } 151355b4669Sjacobs 152355b4669Sjacobs if (jobs != NULL) { 153355b4669Sjacobs int i; 154355b4669Sjacobs 155355b4669Sjacobs for (i = 0; jobs[i] != NULL; i++) 156355b4669Sjacobs printf(gettext("\t%s-%d: cancelled\n"), destination, 157355b4669Sjacobs papiJobGetId(jobs[i])); 158355b4669Sjacobs 159355b4669Sjacobs papiJobListFree(jobs); 160355b4669Sjacobs } 161355b4669Sjacobs 162355b4669Sjacobs return (0); 163355b4669Sjacobs } 164355b4669Sjacobs 165355b4669Sjacobs static int 166355b4669Sjacobs lpc_disable(papi_service_t svc, char **args) 167355b4669Sjacobs { 168355b4669Sjacobs papi_status_t status; 169355b4669Sjacobs char *destination = args[1]; 170355b4669Sjacobs 171355b4669Sjacobs if (destination == NULL) { 172355b4669Sjacobs fprintf(stderr, gettext("Usage: disable: (destination)\n")); 173355b4669Sjacobs return (-1); 174355b4669Sjacobs } 175355b4669Sjacobs 176355b4669Sjacobs status = papiPrinterDisable(svc, destination, NULL); 177355b4669Sjacobs if (status != PAPI_OK) { 178355b4669Sjacobs fprintf(stderr, gettext("disable: %s: %s\n"), destination, 179355b4669Sjacobs verbose_papi_message(svc, status)); 180355b4669Sjacobs return (-1); 181355b4669Sjacobs } 182355b4669Sjacobs 183355b4669Sjacobs return (0); 184355b4669Sjacobs } 185355b4669Sjacobs 186355b4669Sjacobs static int 187355b4669Sjacobs lpc_enable(papi_service_t svc, char **args) 188355b4669Sjacobs { 189355b4669Sjacobs papi_status_t status; 190355b4669Sjacobs char *destination = args[1]; 191355b4669Sjacobs 192355b4669Sjacobs if (destination == NULL) { 193355b4669Sjacobs fprintf(stderr, gettext("Usage: enable: (destination)\n")); 194355b4669Sjacobs return (-1); 195355b4669Sjacobs } 196355b4669Sjacobs 197355b4669Sjacobs status = papiPrinterEnable(svc, destination); 198355b4669Sjacobs if (status != PAPI_OK) { 199355b4669Sjacobs fprintf(stderr, gettext("enable: %s: %s\n"), destination, 200355b4669Sjacobs verbose_papi_message(svc, status)); 201355b4669Sjacobs return (-1); 202355b4669Sjacobs } 203355b4669Sjacobs 204355b4669Sjacobs return (0); 205355b4669Sjacobs } 206355b4669Sjacobs 207355b4669Sjacobs static int 208355b4669Sjacobs lpc_restart(papi_service_t svc, char **args) 209355b4669Sjacobs { 210355b4669Sjacobs int rc = 0; 211355b4669Sjacobs 212355b4669Sjacobs rc += lpc_disable(svc, args); 213355b4669Sjacobs rc += lpc_enable(svc, args); 214355b4669Sjacobs 215355b4669Sjacobs return (rc); 216355b4669Sjacobs } 217355b4669Sjacobs 218355b4669Sjacobs static int 219355b4669Sjacobs lpc_start(papi_service_t svc, char **args) 220355b4669Sjacobs { 221355b4669Sjacobs papi_status_t status; 222355b4669Sjacobs char *destination = args[1]; 223355b4669Sjacobs 224355b4669Sjacobs if (destination == NULL) { 225355b4669Sjacobs fprintf(stderr, gettext("Usage: start (destination)\n")); 226355b4669Sjacobs return (-1); 227355b4669Sjacobs } 228355b4669Sjacobs 229355b4669Sjacobs status = papiPrinterResume(svc, destination); 230355b4669Sjacobs if (status != PAPI_OK) { 231355b4669Sjacobs fprintf(stderr, gettext("start: %s: %s\n"), destination, 232355b4669Sjacobs verbose_papi_message(svc, status)); 233355b4669Sjacobs return (-1); 234355b4669Sjacobs } 235355b4669Sjacobs 236355b4669Sjacobs return (0); 237355b4669Sjacobs } 238355b4669Sjacobs 239355b4669Sjacobs static int 240355b4669Sjacobs lpc_stop(papi_service_t svc, char **args) 241355b4669Sjacobs { 242355b4669Sjacobs papi_status_t status; 243355b4669Sjacobs char *destination = args[1]; 244355b4669Sjacobs 245355b4669Sjacobs if (destination == NULL) { 246355b4669Sjacobs fprintf(stderr, gettext("Usage: stop (destination)\n")); 247355b4669Sjacobs return (-1); 248355b4669Sjacobs } 249355b4669Sjacobs 250355b4669Sjacobs status = papiPrinterPause(svc, destination, "paused via lpc"); 251355b4669Sjacobs if (status != PAPI_OK) { 252355b4669Sjacobs fprintf(stderr, gettext("stop: %s: %s\n"), destination, 253355b4669Sjacobs verbose_papi_message(svc, status)); 254355b4669Sjacobs return (-1); 255355b4669Sjacobs } 256355b4669Sjacobs 257355b4669Sjacobs return (0); 258355b4669Sjacobs } 259355b4669Sjacobs 260355b4669Sjacobs static int 261355b4669Sjacobs lpc_topq(papi_service_t svc, char **args) 262355b4669Sjacobs { 263355b4669Sjacobs papi_status_t status; 264355b4669Sjacobs char *destination = args[1]; 265355b4669Sjacobs int32_t id = atoi(args[2]); 266355b4669Sjacobs 267355b4669Sjacobs if (destination == NULL) { 268355b4669Sjacobs fprintf(stderr, gettext("Usage: topq (destination) (id)\n")); 269355b4669Sjacobs return (-1); 270355b4669Sjacobs } 271355b4669Sjacobs 272355b4669Sjacobs status = papiJobPromote(svc, destination, id); 273355b4669Sjacobs if (status != PAPI_OK) { 274355b4669Sjacobs fprintf(stderr, gettext("topq: %s %d: %s\n"), destination, id, 275355b4669Sjacobs verbose_papi_message(svc, status)); 276355b4669Sjacobs return (-1); 277355b4669Sjacobs } 278355b4669Sjacobs 279355b4669Sjacobs return (0); 280355b4669Sjacobs } 281355b4669Sjacobs 282355b4669Sjacobs static int 283355b4669Sjacobs lpc_up(papi_service_t svc, char **args) 284355b4669Sjacobs { 285355b4669Sjacobs int rc = 0; 286355b4669Sjacobs 287355b4669Sjacobs rc += lpc_enable(svc, args); 288355b4669Sjacobs rc += lpc_start(svc, args); 289355b4669Sjacobs 290355b4669Sjacobs return (rc); 291355b4669Sjacobs } 292355b4669Sjacobs 293355b4669Sjacobs static int 294355b4669Sjacobs lpc_down(papi_service_t svc, char **args) 295355b4669Sjacobs { 296355b4669Sjacobs int rc = 0; 297355b4669Sjacobs 298355b4669Sjacobs rc += lpc_disable(svc, args); 299355b4669Sjacobs rc += lpc_stop(svc, args); 300355b4669Sjacobs 301355b4669Sjacobs return (rc); 302355b4669Sjacobs } 303355b4669Sjacobs 304355b4669Sjacobs static int lpc_help(papi_service_t svc, char **args); /* forward reference */ 305355b4669Sjacobs 306355b4669Sjacobs static char help_help[] = "get help on commands"; 307355b4669Sjacobs static char help_exit[] = "exit lpc"; 308355b4669Sjacobs static char help_status[] = "show status of daemon and queue"; 309355b4669Sjacobs static char help_abort[] = 310355b4669Sjacobs "disable print queue terminating any active job processing"; 311355b4669Sjacobs static char help_clean[] = "remove all jobs from a queue"; 312355b4669Sjacobs static char help_disable[] = "turn off spooling to a queue"; 313355b4669Sjacobs static char help_down[] = 314355b4669Sjacobs "turn off queueing and printing for a queue and set a reason"; 315355b4669Sjacobs static char help_enable[] = "turn on spooling to a queue"; 316355b4669Sjacobs static char help_restart[] = "restart job processing for a queue"; 317355b4669Sjacobs static char help_start[] = "turn on printing from a queue"; 318355b4669Sjacobs static char help_stop[] = "turn off printing from a queue"; 319355b4669Sjacobs static char help_up[] = "turn on queueing and printing for a queue"; 320355b4669Sjacobs static char help_topq[] = "put a job at the top of the queue"; 321355b4669Sjacobs 322355b4669Sjacobs static struct { 323355b4669Sjacobs char *cmd; 324355b4669Sjacobs int (*handler)(papi_service_t svc, char **args); 325355b4669Sjacobs char *help_string; 326355b4669Sjacobs int num_args; 327355b4669Sjacobs } cmd_tab[] = { 328355b4669Sjacobs { "?", lpc_help, help_help, 0 }, 329355b4669Sjacobs { "help", lpc_help, help_help, 0 }, 330355b4669Sjacobs { "exit", lpc_exit, help_exit, 0 }, 331355b4669Sjacobs { "quit", lpc_exit, help_exit, 0 }, 332355b4669Sjacobs { "status", lpc_status, help_status, 1 }, 333355b4669Sjacobs { "abort", lpc_abort, help_abort, 1 }, 334355b4669Sjacobs { "clean", lpc_clean, help_clean, 1 }, 335355b4669Sjacobs { "disable", lpc_disable, help_disable, 1 }, 336355b4669Sjacobs { "down", lpc_down, help_down, 2 }, 337355b4669Sjacobs { "enable", lpc_enable, help_enable, 1 }, 338355b4669Sjacobs { "restart", lpc_restart, help_restart, 1 }, 339355b4669Sjacobs { "start", lpc_start, help_start, 1 }, 340355b4669Sjacobs { "stop", lpc_stop, help_stop, 1 }, 341355b4669Sjacobs { "up", lpc_up, help_up, 1 }, 342355b4669Sjacobs { "topq", lpc_topq, help_topq, 2 }, 343355b4669Sjacobs { NULL, NULL, NULL, 0 } 344355b4669Sjacobs }; 345355b4669Sjacobs 346355b4669Sjacobs static int 347355b4669Sjacobs lpc_handler(char *cmd, cmd_handler_t **handler) 348355b4669Sjacobs { 349355b4669Sjacobs int i; 350355b4669Sjacobs 351355b4669Sjacobs for (i = 0; cmd_tab[i].cmd != NULL; i++) 352355b4669Sjacobs if (strcmp(cmd, cmd_tab[i].cmd) == 0) { 353355b4669Sjacobs *handler = cmd_tab[i].handler; 354355b4669Sjacobs return (cmd_tab[i].num_args); 355355b4669Sjacobs } 356355b4669Sjacobs return (-1); 357355b4669Sjacobs } 358355b4669Sjacobs 359355b4669Sjacobs static char * 360355b4669Sjacobs lpc_helptext(char *cmd) 361355b4669Sjacobs { 362355b4669Sjacobs int i; 363355b4669Sjacobs 364355b4669Sjacobs for (i = 0; cmd_tab[i].cmd != NULL; i++) 365355b4669Sjacobs if (strcmp(cmd, cmd_tab[i].cmd) == 0) 366355b4669Sjacobs return (gettext(cmd_tab[i].help_string)); 367355b4669Sjacobs return (NULL); 368355b4669Sjacobs } 369355b4669Sjacobs 370355b4669Sjacobs /* ARGSUSED0 */ 371355b4669Sjacobs static int 372355b4669Sjacobs lpc_help(papi_service_t svc, char **args) 373355b4669Sjacobs { 374355b4669Sjacobs if (args[1] == NULL) { 375355b4669Sjacobs int i; 376355b4669Sjacobs 377355b4669Sjacobs printf(gettext("Commands are:\n\n")); 378355b4669Sjacobs for (i = 0; cmd_tab[i].cmd != NULL; i++) { 379355b4669Sjacobs printf("\t%s", cmd_tab[i].cmd); 380355b4669Sjacobs if ((i % 7) == 6) 381355b4669Sjacobs printf("\n"); 382355b4669Sjacobs } 383355b4669Sjacobs if ((i % 7) != 6) 384355b4669Sjacobs printf("\n"); 385355b4669Sjacobs } else { 386355b4669Sjacobs char *helptext = lpc_helptext(args[1]); 387355b4669Sjacobs 388355b4669Sjacobs if (helptext == NULL) 389355b4669Sjacobs helptext = gettext("no such command"); 390355b4669Sjacobs 391355b4669Sjacobs printf("%s: %s\n", args[1], helptext); 392355b4669Sjacobs } 393355b4669Sjacobs 394355b4669Sjacobs return (0); 395355b4669Sjacobs } 396355b4669Sjacobs 397355b4669Sjacobs static int 398355b4669Sjacobs process_one(int (*handler)(papi_service_t, char **), char **av, int expected) 399355b4669Sjacobs { 400355b4669Sjacobs int rc = -1; 401355b4669Sjacobs papi_status_t status = PAPI_OK; 402355b4669Sjacobs papi_service_t svc = NULL; 403355b4669Sjacobs char *printer = av[1]; 404355b4669Sjacobs 405355b4669Sjacobs if ((printer != NULL) && (expected != 0)) { 406355b4669Sjacobs status = papiServiceCreate(&svc, printer, NULL, NULL, 407355b4669Sjacobs cli_auth_callback, encryption, NULL); 408355b4669Sjacobs if (status != PAPI_OK) { 409355b4669Sjacobs fprintf(stderr, gettext( 410355b4669Sjacobs "Failed to contact service for %s: %s\n"), 411355b4669Sjacobs printer, verbose_papi_message(svc, status)); 412355b4669Sjacobs } 413355b4669Sjacobs } 414355b4669Sjacobs 415355b4669Sjacobs if (status == PAPI_OK) 416355b4669Sjacobs rc = handler(svc, av); 417355b4669Sjacobs 418355b4669Sjacobs if (svc != NULL) 419355b4669Sjacobs papiServiceDestroy(svc); 420355b4669Sjacobs 421355b4669Sjacobs return (rc); 422355b4669Sjacobs } 423355b4669Sjacobs 424355b4669Sjacobs static int 425355b4669Sjacobs process_all(int (*handler)(papi_service_t, char **), char **av, int expected) 426355b4669Sjacobs { 427355b4669Sjacobs papi_status_t status; 428355b4669Sjacobs papi_service_t svc = NULL; 429355b4669Sjacobs char **printers; 430355b4669Sjacobs int rc = 0; 431355b4669Sjacobs 432355b4669Sjacobs status = papiServiceCreate(&svc, NULL, NULL, NULL, NULL, 433355b4669Sjacobs encryption, NULL); 434355b4669Sjacobs if (status != PAPI_OK) { 435355b4669Sjacobs fprintf(stderr, gettext("Failed to contact service: %s\n"), 436355b4669Sjacobs verbose_papi_message(svc, status)); 437355b4669Sjacobs return (-1); 438355b4669Sjacobs } 439355b4669Sjacobs 440355b4669Sjacobs if ((printers = interest_list(svc)) != NULL) { 441355b4669Sjacobs int i; 442355b4669Sjacobs 443355b4669Sjacobs for (i = 0; printers[i] != NULL; i++) { 444355b4669Sjacobs av[1] = printers[i]; 445355b4669Sjacobs rc += process_one(handler, av, expected); 446355b4669Sjacobs } 447355b4669Sjacobs } 448355b4669Sjacobs 449355b4669Sjacobs papiServiceDestroy(svc); 450355b4669Sjacobs 451355b4669Sjacobs return (rc); 452355b4669Sjacobs } 453355b4669Sjacobs 454355b4669Sjacobs static int 455355b4669Sjacobs process(int ac, char **av) 456355b4669Sjacobs { 457355b4669Sjacobs int (*handler)(papi_service_t, char **) = NULL; 458355b4669Sjacobs int num_args = -1; 459355b4669Sjacobs 460355b4669Sjacobs char *printer = av[1]; 461355b4669Sjacobs int rc = -1; 462355b4669Sjacobs 463355b4669Sjacobs if ((num_args = lpc_handler(av[0], &handler)) < 0) { 464355b4669Sjacobs printf(gettext("%s: invalid command\n"), av[0]); 465355b4669Sjacobs return (-1); 466355b4669Sjacobs } 467355b4669Sjacobs 468*b51e021dSjacobs if (((ac == 0) && (num_args != 0)) || 469*b51e021dSjacobs ((printer != NULL) && strcmp(printer, "all") == 0)) 470355b4669Sjacobs rc = process_all(handler, av, num_args); 471*b51e021dSjacobs else if (num_args < ac) { 472*b51e021dSjacobs int i; 473*b51e021dSjacobs char *argv[4]; 474*b51e021dSjacobs 475*b51e021dSjacobs memset(argv, 0, sizeof (argv)); 476*b51e021dSjacobs argv[0] = av[0]; 477*b51e021dSjacobs 478*b51e021dSjacobs if (strcmp(av[0], "topq") == 0) { 479*b51e021dSjacobs argv[1] = av[1]; 480*b51e021dSjacobs for (i = 2; i <= ac; i++) { 481*b51e021dSjacobs argv[2] = av[i]; 482*b51e021dSjacobs process_one(handler, argv, num_args); 483*b51e021dSjacobs } 484*b51e021dSjacobs } else 485*b51e021dSjacobs for (i = 1; i <= ac; i++) { 486*b51e021dSjacobs argv[1] = av[i]; 487*b51e021dSjacobs process_one(handler, argv, num_args); 488*b51e021dSjacobs } 489*b51e021dSjacobs } else 490*b51e021dSjacobs rc = process_one(handler, av, num_args); 491355b4669Sjacobs 492355b4669Sjacobs return (rc); 493355b4669Sjacobs } 494355b4669Sjacobs 495355b4669Sjacobs static void 496355b4669Sjacobs usage(char *program) 497355b4669Sjacobs { 498355b4669Sjacobs char *name; 499355b4669Sjacobs 500355b4669Sjacobs if ((name = strrchr(program, '/')) == NULL) 501355b4669Sjacobs name = program; 502355b4669Sjacobs else 503355b4669Sjacobs name++; 504355b4669Sjacobs 505355b4669Sjacobs fprintf(stdout, 506355b4669Sjacobs gettext("Usage: %s [ command [ parameter...]]\n"), 507355b4669Sjacobs name); 508355b4669Sjacobs exit(1); 509355b4669Sjacobs } 510355b4669Sjacobs 511355b4669Sjacobs static void 512355b4669Sjacobs lpc_shell() 513355b4669Sjacobs { 514355b4669Sjacobs for (;;) { 515355b4669Sjacobs char line[256]; 516355b4669Sjacobs char **av = NULL; 517355b4669Sjacobs int ac = 0; 518355b4669Sjacobs 519355b4669Sjacobs /* prompt */ 520355b4669Sjacobs fprintf(stdout, "lpc> "); 521355b4669Sjacobs fflush(stdout); 522355b4669Sjacobs 523355b4669Sjacobs /* get command */ 524355b4669Sjacobs if (fgets(line, sizeof (line), stdin) == NULL) 525355b4669Sjacobs exit(1); 526355b4669Sjacobs if ((av = strsplit(line, " \t\n")) != NULL) 527355b4669Sjacobs for (ac = 0; av[ac] != NULL; ac++); 528355b4669Sjacobs 529*b51e021dSjacobs (void) process(ac - 1, av); 530355b4669Sjacobs free(av); 531355b4669Sjacobs } 532355b4669Sjacobs } 533355b4669Sjacobs 534355b4669Sjacobs int 535355b4669Sjacobs main(int ac, char *av[]) 536355b4669Sjacobs { 537355b4669Sjacobs int result = 0; 538355b4669Sjacobs int c; 539355b4669Sjacobs 540355b4669Sjacobs (void) setlocale(LC_ALL, ""); 541355b4669Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 542355b4669Sjacobs 543355b4669Sjacobs while ((c = getopt(ac, av, "E")) != EOF) 544355b4669Sjacobs switch (c) { 545355b4669Sjacobs case 'E': 546355b4669Sjacobs encryption = PAPI_ENCRYPT_ALWAYS; 547355b4669Sjacobs break; 548355b4669Sjacobs default: 549355b4669Sjacobs usage(av[0]); 550355b4669Sjacobs } 551355b4669Sjacobs 552355b4669Sjacobs if (optind == ac) 553355b4669Sjacobs lpc_shell(); 554355b4669Sjacobs else 555*b51e021dSjacobs result = process(ac - optind - 1, &av[optind]); 556355b4669Sjacobs 557355b4669Sjacobs return (result); 558355b4669Sjacobs } 559