1*2264Sjacobs /* 2*2264Sjacobs * CDDL HEADER START 3*2264Sjacobs * 4*2264Sjacobs * The contents of this file are subject to the terms of the 5*2264Sjacobs * Common Development and Distribution License (the "License"). 6*2264Sjacobs * You may not use this file except in compliance with the License. 7*2264Sjacobs * 8*2264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*2264Sjacobs * or http://www.opensolaris.org/os/licensing. 10*2264Sjacobs * See the License for the specific language governing permissions 11*2264Sjacobs * and limitations under the License. 12*2264Sjacobs * 13*2264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 14*2264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*2264Sjacobs * If applicable, add the following below this CDDL HEADER, with the 16*2264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 17*2264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 18*2264Sjacobs * 19*2264Sjacobs * CDDL HEADER END 20*2264Sjacobs */ 21*2264Sjacobs 22*2264Sjacobs /* 23*2264Sjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*2264Sjacobs * Use is subject to license terms. 25*2264Sjacobs * 26*2264Sjacobs */ 27*2264Sjacobs 28*2264Sjacobs /* $Id: lpc.c 146 2006-03-24 00:26:54Z njacobs $ */ 29*2264Sjacobs 30*2264Sjacobs #pragma ident "%Z%%M% %I% %E% SMI" 31*2264Sjacobs 32*2264Sjacobs #include <stdio.h> 33*2264Sjacobs #include <stdlib.h> 34*2264Sjacobs #include <unistd.h> 35*2264Sjacobs #include <string.h> 36*2264Sjacobs #include <locale.h> 37*2264Sjacobs #include <libintl.h> 38*2264Sjacobs #include <papi.h> 39*2264Sjacobs #include "common.h" 40*2264Sjacobs 41*2264Sjacobs typedef int (cmd_handler_t)(papi_service_t, char **); 42*2264Sjacobs 43*2264Sjacobs static papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 44*2264Sjacobs 45*2264Sjacobs /* ARGSUSED0 */ 46*2264Sjacobs static int 47*2264Sjacobs lpc_exit(papi_service_t svc, char **args) 48*2264Sjacobs { 49*2264Sjacobs exit(0); 50*2264Sjacobs /* NOTREACHED */ 51*2264Sjacobs return (0); 52*2264Sjacobs } 53*2264Sjacobs 54*2264Sjacobs static int 55*2264Sjacobs lpc_status(papi_service_t svc, char **args) 56*2264Sjacobs { 57*2264Sjacobs papi_status_t status; 58*2264Sjacobs papi_printer_t p = NULL; 59*2264Sjacobs char *pattrs[] = { "printer-state", "printer-state-reasons", 60*2264Sjacobs "printer-is-accepting-jobs", NULL }; 61*2264Sjacobs char *destination = args[1]; 62*2264Sjacobs 63*2264Sjacobs status = papiPrinterQuery(svc, destination, pattrs, NULL, &p); 64*2264Sjacobs if (status == PAPI_OK) { 65*2264Sjacobs papi_attribute_t **list = papiPrinterGetAttributeList(p); 66*2264Sjacobs char accepting = 0; 67*2264Sjacobs int32_t state = 0; 68*2264Sjacobs 69*2264Sjacobs printf("%s:\n", destination); 70*2264Sjacobs 71*2264Sjacobs (void) papiAttributeListGetBoolean(list, NULL, 72*2264Sjacobs "printer-is-accepting-jobs", &accepting); 73*2264Sjacobs printf(gettext("\tqueueing is %s\n"), 74*2264Sjacobs (accepting ? gettext("enabled") : gettext("disabled"))); 75*2264Sjacobs 76*2264Sjacobs (void) papiAttributeListGetInteger(list, NULL, 77*2264Sjacobs "printer-state", &state); 78*2264Sjacobs printf("\tprinting is %s\n", 79*2264Sjacobs ((state != 0x05) ? gettext("enabled") : 80*2264Sjacobs gettext("disabled"))); 81*2264Sjacobs 82*2264Sjacobs if (state != 0x03) { /* !idle */ 83*2264Sjacobs papi_job_t *jobs = NULL; 84*2264Sjacobs int i = 0; 85*2264Sjacobs 86*2264Sjacobs (void) papiPrinterListJobs(svc, destination, NULL, 87*2264Sjacobs PAPI_LIST_JOBS_ALL, 0, &jobs); 88*2264Sjacobs if (jobs != NULL) { 89*2264Sjacobs for (i = 0; jobs[i] != NULL; i++); 90*2264Sjacobs papiJobListFree(jobs); 91*2264Sjacobs } 92*2264Sjacobs printf(gettext("\t%d entries in spool area\n"), i); 93*2264Sjacobs } else 94*2264Sjacobs printf(gettext("\tno entries\n")); 95*2264Sjacobs 96*2264Sjacobs if (state == 0x04) 97*2264Sjacobs printf(gettext("\tdaemon present\n")); 98*2264Sjacobs 99*2264Sjacobs } else { 100*2264Sjacobs fprintf(stderr, "%s: %s\n", destination, 101*2264Sjacobs verbose_papi_message(svc, status)); 102*2264Sjacobs return (-1); 103*2264Sjacobs } 104*2264Sjacobs 105*2264Sjacobs papiPrinterFree(p); 106*2264Sjacobs 107*2264Sjacobs return (0); 108*2264Sjacobs } 109*2264Sjacobs 110*2264Sjacobs static int 111*2264Sjacobs lpc_abort(papi_service_t svc, char **args) 112*2264Sjacobs { 113*2264Sjacobs papi_status_t status; 114*2264Sjacobs char *destination = args[1]; 115*2264Sjacobs 116*2264Sjacobs if (destination == NULL) { 117*2264Sjacobs fprintf(stderr, gettext("Usage: abort (destination)\n")); 118*2264Sjacobs return (-1); 119*2264Sjacobs } 120*2264Sjacobs 121*2264Sjacobs status = papiPrinterPause(svc, destination, "paused via lpc abort"); 122*2264Sjacobs if (status == PAPI_OK) { 123*2264Sjacobs printf(gettext("%s: processing disabled after current job\n"), 124*2264Sjacobs destination); 125*2264Sjacobs } else { 126*2264Sjacobs fprintf(stderr, "%s: %s\n", destination, 127*2264Sjacobs verbose_papi_message(svc, status)); 128*2264Sjacobs } 129*2264Sjacobs 130*2264Sjacobs return (0); 131*2264Sjacobs } 132*2264Sjacobs 133*2264Sjacobs static int 134*2264Sjacobs lpc_clean(papi_service_t svc, char **args) 135*2264Sjacobs { 136*2264Sjacobs papi_status_t status; 137*2264Sjacobs papi_job_t *jobs = NULL; 138*2264Sjacobs char *destination = args[1]; 139*2264Sjacobs 140*2264Sjacobs if (destination == NULL) { 141*2264Sjacobs fprintf(stderr, gettext("Usage: clean (destination)\n")); 142*2264Sjacobs return (-1); 143*2264Sjacobs } 144*2264Sjacobs 145*2264Sjacobs status = papiPrinterPurgeJobs(svc, destination, &jobs); 146*2264Sjacobs if (status != PAPI_OK) { 147*2264Sjacobs fprintf(stderr, gettext("clean: %s: %s\n"), destination, 148*2264Sjacobs verbose_papi_message(svc, status)); 149*2264Sjacobs return (-1); 150*2264Sjacobs } 151*2264Sjacobs 152*2264Sjacobs if (jobs != NULL) { 153*2264Sjacobs int i; 154*2264Sjacobs 155*2264Sjacobs for (i = 0; jobs[i] != NULL; i++) 156*2264Sjacobs printf(gettext("\t%s-%d: cancelled\n"), destination, 157*2264Sjacobs papiJobGetId(jobs[i])); 158*2264Sjacobs 159*2264Sjacobs papiJobListFree(jobs); 160*2264Sjacobs } 161*2264Sjacobs 162*2264Sjacobs return (0); 163*2264Sjacobs } 164*2264Sjacobs 165*2264Sjacobs static int 166*2264Sjacobs lpc_disable(papi_service_t svc, char **args) 167*2264Sjacobs { 168*2264Sjacobs papi_status_t status; 169*2264Sjacobs char *destination = args[1]; 170*2264Sjacobs 171*2264Sjacobs if (destination == NULL) { 172*2264Sjacobs fprintf(stderr, gettext("Usage: disable: (destination)\n")); 173*2264Sjacobs return (-1); 174*2264Sjacobs } 175*2264Sjacobs 176*2264Sjacobs status = papiPrinterDisable(svc, destination, NULL); 177*2264Sjacobs if (status != PAPI_OK) { 178*2264Sjacobs fprintf(stderr, gettext("disable: %s: %s\n"), destination, 179*2264Sjacobs verbose_papi_message(svc, status)); 180*2264Sjacobs return (-1); 181*2264Sjacobs } 182*2264Sjacobs 183*2264Sjacobs return (0); 184*2264Sjacobs } 185*2264Sjacobs 186*2264Sjacobs static int 187*2264Sjacobs lpc_enable(papi_service_t svc, char **args) 188*2264Sjacobs { 189*2264Sjacobs papi_status_t status; 190*2264Sjacobs char *destination = args[1]; 191*2264Sjacobs 192*2264Sjacobs if (destination == NULL) { 193*2264Sjacobs fprintf(stderr, gettext("Usage: enable: (destination)\n")); 194*2264Sjacobs return (-1); 195*2264Sjacobs } 196*2264Sjacobs 197*2264Sjacobs status = papiPrinterEnable(svc, destination); 198*2264Sjacobs if (status != PAPI_OK) { 199*2264Sjacobs fprintf(stderr, gettext("enable: %s: %s\n"), destination, 200*2264Sjacobs verbose_papi_message(svc, status)); 201*2264Sjacobs return (-1); 202*2264Sjacobs } 203*2264Sjacobs 204*2264Sjacobs return (0); 205*2264Sjacobs } 206*2264Sjacobs 207*2264Sjacobs static int 208*2264Sjacobs lpc_restart(papi_service_t svc, char **args) 209*2264Sjacobs { 210*2264Sjacobs int rc = 0; 211*2264Sjacobs 212*2264Sjacobs rc += lpc_disable(svc, args); 213*2264Sjacobs rc += lpc_enable(svc, args); 214*2264Sjacobs 215*2264Sjacobs return (rc); 216*2264Sjacobs } 217*2264Sjacobs 218*2264Sjacobs static int 219*2264Sjacobs lpc_start(papi_service_t svc, char **args) 220*2264Sjacobs { 221*2264Sjacobs papi_status_t status; 222*2264Sjacobs char *destination = args[1]; 223*2264Sjacobs 224*2264Sjacobs if (destination == NULL) { 225*2264Sjacobs fprintf(stderr, gettext("Usage: start (destination)\n")); 226*2264Sjacobs return (-1); 227*2264Sjacobs } 228*2264Sjacobs 229*2264Sjacobs status = papiPrinterResume(svc, destination); 230*2264Sjacobs if (status != PAPI_OK) { 231*2264Sjacobs fprintf(stderr, gettext("start: %s: %s\n"), destination, 232*2264Sjacobs verbose_papi_message(svc, status)); 233*2264Sjacobs return (-1); 234*2264Sjacobs } 235*2264Sjacobs 236*2264Sjacobs return (0); 237*2264Sjacobs } 238*2264Sjacobs 239*2264Sjacobs static int 240*2264Sjacobs lpc_stop(papi_service_t svc, char **args) 241*2264Sjacobs { 242*2264Sjacobs papi_status_t status; 243*2264Sjacobs char *destination = args[1]; 244*2264Sjacobs 245*2264Sjacobs if (destination == NULL) { 246*2264Sjacobs fprintf(stderr, gettext("Usage: stop (destination)\n")); 247*2264Sjacobs return (-1); 248*2264Sjacobs } 249*2264Sjacobs 250*2264Sjacobs status = papiPrinterPause(svc, destination, "paused via lpc"); 251*2264Sjacobs if (status != PAPI_OK) { 252*2264Sjacobs fprintf(stderr, gettext("stop: %s: %s\n"), destination, 253*2264Sjacobs verbose_papi_message(svc, status)); 254*2264Sjacobs return (-1); 255*2264Sjacobs } 256*2264Sjacobs 257*2264Sjacobs return (0); 258*2264Sjacobs } 259*2264Sjacobs 260*2264Sjacobs static int 261*2264Sjacobs lpc_topq(papi_service_t svc, char **args) 262*2264Sjacobs { 263*2264Sjacobs papi_status_t status; 264*2264Sjacobs char *destination = args[1]; 265*2264Sjacobs int32_t id = atoi(args[2]); 266*2264Sjacobs 267*2264Sjacobs if (destination == NULL) { 268*2264Sjacobs fprintf(stderr, gettext("Usage: topq (destination) (id)\n")); 269*2264Sjacobs return (-1); 270*2264Sjacobs } 271*2264Sjacobs 272*2264Sjacobs status = papiJobPromote(svc, destination, id); 273*2264Sjacobs if (status != PAPI_OK) { 274*2264Sjacobs fprintf(stderr, gettext("topq: %s %d: %s\n"), destination, id, 275*2264Sjacobs verbose_papi_message(svc, status)); 276*2264Sjacobs return (-1); 277*2264Sjacobs } 278*2264Sjacobs 279*2264Sjacobs return (0); 280*2264Sjacobs } 281*2264Sjacobs 282*2264Sjacobs static int 283*2264Sjacobs lpc_up(papi_service_t svc, char **args) 284*2264Sjacobs { 285*2264Sjacobs int rc = 0; 286*2264Sjacobs 287*2264Sjacobs rc += lpc_enable(svc, args); 288*2264Sjacobs rc += lpc_start(svc, args); 289*2264Sjacobs 290*2264Sjacobs return (rc); 291*2264Sjacobs } 292*2264Sjacobs 293*2264Sjacobs static int 294*2264Sjacobs lpc_down(papi_service_t svc, char **args) 295*2264Sjacobs { 296*2264Sjacobs int rc = 0; 297*2264Sjacobs 298*2264Sjacobs rc += lpc_disable(svc, args); 299*2264Sjacobs rc += lpc_stop(svc, args); 300*2264Sjacobs 301*2264Sjacobs return (rc); 302*2264Sjacobs } 303*2264Sjacobs 304*2264Sjacobs static int lpc_help(papi_service_t svc, char **args); /* forward reference */ 305*2264Sjacobs 306*2264Sjacobs static char help_help[] = "get help on commands"; 307*2264Sjacobs static char help_exit[] = "exit lpc"; 308*2264Sjacobs static char help_status[] = "show status of daemon and queue"; 309*2264Sjacobs static char help_abort[] = 310*2264Sjacobs "disable print queue terminating any active job processing"; 311*2264Sjacobs static char help_clean[] = "remove all jobs from a queue"; 312*2264Sjacobs static char help_disable[] = "turn off spooling to a queue"; 313*2264Sjacobs static char help_down[] = 314*2264Sjacobs "turn off queueing and printing for a queue and set a reason"; 315*2264Sjacobs static char help_enable[] = "turn on spooling to a queue"; 316*2264Sjacobs static char help_restart[] = "restart job processing for a queue"; 317*2264Sjacobs static char help_start[] = "turn on printing from a queue"; 318*2264Sjacobs static char help_stop[] = "turn off printing from a queue"; 319*2264Sjacobs static char help_up[] = "turn on queueing and printing for a queue"; 320*2264Sjacobs static char help_topq[] = "put a job at the top of the queue"; 321*2264Sjacobs 322*2264Sjacobs static struct { 323*2264Sjacobs char *cmd; 324*2264Sjacobs int (*handler)(papi_service_t svc, char **args); 325*2264Sjacobs char *help_string; 326*2264Sjacobs int num_args; 327*2264Sjacobs } cmd_tab[] = { 328*2264Sjacobs { "?", lpc_help, help_help, 0 }, 329*2264Sjacobs { "help", lpc_help, help_help, 0 }, 330*2264Sjacobs { "exit", lpc_exit, help_exit, 0 }, 331*2264Sjacobs { "quit", lpc_exit, help_exit, 0 }, 332*2264Sjacobs { "status", lpc_status, help_status, 1 }, 333*2264Sjacobs { "abort", lpc_abort, help_abort, 1 }, 334*2264Sjacobs { "clean", lpc_clean, help_clean, 1 }, 335*2264Sjacobs { "disable", lpc_disable, help_disable, 1 }, 336*2264Sjacobs { "down", lpc_down, help_down, 2 }, 337*2264Sjacobs { "enable", lpc_enable, help_enable, 1 }, 338*2264Sjacobs { "restart", lpc_restart, help_restart, 1 }, 339*2264Sjacobs { "start", lpc_start, help_start, 1 }, 340*2264Sjacobs { "stop", lpc_stop, help_stop, 1 }, 341*2264Sjacobs { "up", lpc_up, help_up, 1 }, 342*2264Sjacobs { "topq", lpc_topq, help_topq, 2 }, 343*2264Sjacobs { NULL, NULL, NULL, 0 } 344*2264Sjacobs }; 345*2264Sjacobs 346*2264Sjacobs static int 347*2264Sjacobs lpc_handler(char *cmd, cmd_handler_t **handler) 348*2264Sjacobs { 349*2264Sjacobs int i; 350*2264Sjacobs 351*2264Sjacobs for (i = 0; cmd_tab[i].cmd != NULL; i++) 352*2264Sjacobs if (strcmp(cmd, cmd_tab[i].cmd) == 0) { 353*2264Sjacobs *handler = cmd_tab[i].handler; 354*2264Sjacobs return (cmd_tab[i].num_args); 355*2264Sjacobs } 356*2264Sjacobs return (-1); 357*2264Sjacobs } 358*2264Sjacobs 359*2264Sjacobs static char * 360*2264Sjacobs lpc_helptext(char *cmd) 361*2264Sjacobs { 362*2264Sjacobs int i; 363*2264Sjacobs 364*2264Sjacobs for (i = 0; cmd_tab[i].cmd != NULL; i++) 365*2264Sjacobs if (strcmp(cmd, cmd_tab[i].cmd) == 0) 366*2264Sjacobs return (gettext(cmd_tab[i].help_string)); 367*2264Sjacobs return (NULL); 368*2264Sjacobs } 369*2264Sjacobs 370*2264Sjacobs /* ARGSUSED0 */ 371*2264Sjacobs static int 372*2264Sjacobs lpc_help(papi_service_t svc, char **args) 373*2264Sjacobs { 374*2264Sjacobs if (args[1] == NULL) { 375*2264Sjacobs int i; 376*2264Sjacobs 377*2264Sjacobs printf(gettext("Commands are:\n\n")); 378*2264Sjacobs for (i = 0; cmd_tab[i].cmd != NULL; i++) { 379*2264Sjacobs printf("\t%s", cmd_tab[i].cmd); 380*2264Sjacobs if ((i % 7) == 6) 381*2264Sjacobs printf("\n"); 382*2264Sjacobs } 383*2264Sjacobs if ((i % 7) != 6) 384*2264Sjacobs printf("\n"); 385*2264Sjacobs } else { 386*2264Sjacobs char *helptext = lpc_helptext(args[1]); 387*2264Sjacobs 388*2264Sjacobs if (helptext == NULL) 389*2264Sjacobs helptext = gettext("no such command"); 390*2264Sjacobs 391*2264Sjacobs printf("%s: %s\n", args[1], helptext); 392*2264Sjacobs } 393*2264Sjacobs 394*2264Sjacobs return (0); 395*2264Sjacobs } 396*2264Sjacobs 397*2264Sjacobs static int 398*2264Sjacobs process_one(int (*handler)(papi_service_t, char **), char **av, int expected) 399*2264Sjacobs { 400*2264Sjacobs int rc = -1; 401*2264Sjacobs papi_status_t status = PAPI_OK; 402*2264Sjacobs papi_service_t svc = NULL; 403*2264Sjacobs char *printer = av[1]; 404*2264Sjacobs 405*2264Sjacobs if ((printer != NULL) && (expected != 0)) { 406*2264Sjacobs status = papiServiceCreate(&svc, printer, NULL, NULL, 407*2264Sjacobs cli_auth_callback, encryption, NULL); 408*2264Sjacobs if (status != PAPI_OK) { 409*2264Sjacobs fprintf(stderr, gettext( 410*2264Sjacobs "Failed to contact service for %s: %s\n"), 411*2264Sjacobs printer, verbose_papi_message(svc, status)); 412*2264Sjacobs } 413*2264Sjacobs } 414*2264Sjacobs 415*2264Sjacobs if (status == PAPI_OK) 416*2264Sjacobs rc = handler(svc, av); 417*2264Sjacobs 418*2264Sjacobs if (svc != NULL) 419*2264Sjacobs papiServiceDestroy(svc); 420*2264Sjacobs 421*2264Sjacobs return (rc); 422*2264Sjacobs } 423*2264Sjacobs 424*2264Sjacobs static int 425*2264Sjacobs process_all(int (*handler)(papi_service_t, char **), char **av, int expected) 426*2264Sjacobs { 427*2264Sjacobs papi_status_t status; 428*2264Sjacobs papi_service_t svc = NULL; 429*2264Sjacobs char **printers; 430*2264Sjacobs int rc = 0; 431*2264Sjacobs 432*2264Sjacobs status = papiServiceCreate(&svc, NULL, NULL, NULL, NULL, 433*2264Sjacobs encryption, NULL); 434*2264Sjacobs if (status != PAPI_OK) { 435*2264Sjacobs fprintf(stderr, gettext("Failed to contact service: %s\n"), 436*2264Sjacobs verbose_papi_message(svc, status)); 437*2264Sjacobs return (-1); 438*2264Sjacobs } 439*2264Sjacobs 440*2264Sjacobs if ((printers = interest_list(svc)) != NULL) { 441*2264Sjacobs int i; 442*2264Sjacobs 443*2264Sjacobs for (i = 0; printers[i] != NULL; i++) { 444*2264Sjacobs av[1] = printers[i]; 445*2264Sjacobs rc += process_one(handler, av, expected); 446*2264Sjacobs } 447*2264Sjacobs } 448*2264Sjacobs 449*2264Sjacobs papiServiceDestroy(svc); 450*2264Sjacobs 451*2264Sjacobs return (rc); 452*2264Sjacobs } 453*2264Sjacobs 454*2264Sjacobs static int 455*2264Sjacobs process(int ac, char **av) 456*2264Sjacobs { 457*2264Sjacobs int (*handler)(papi_service_t, char **) = NULL; 458*2264Sjacobs int num_args = -1; 459*2264Sjacobs 460*2264Sjacobs char *printer = av[1]; 461*2264Sjacobs int rc = -1; 462*2264Sjacobs 463*2264Sjacobs if ((num_args = lpc_handler(av[0], &handler)) < 0) { 464*2264Sjacobs printf(gettext("%s: invalid command\n"), av[0]); 465*2264Sjacobs return (-1); 466*2264Sjacobs } 467*2264Sjacobs 468*2264Sjacobs if (((printer != NULL) && (strcmp(printer, "all") != 0)) || 469*2264Sjacobs (num_args <= ac)) 470*2264Sjacobs rc = process_one(handler, av, num_args); 471*2264Sjacobs else 472*2264Sjacobs rc = process_all(handler, av, num_args); 473*2264Sjacobs 474*2264Sjacobs return (rc); 475*2264Sjacobs } 476*2264Sjacobs 477*2264Sjacobs static void 478*2264Sjacobs usage(char *program) 479*2264Sjacobs { 480*2264Sjacobs char *name; 481*2264Sjacobs 482*2264Sjacobs if ((name = strrchr(program, '/')) == NULL) 483*2264Sjacobs name = program; 484*2264Sjacobs else 485*2264Sjacobs name++; 486*2264Sjacobs 487*2264Sjacobs fprintf(stdout, 488*2264Sjacobs gettext("Usage: %s [ command [ parameter...]]\n"), 489*2264Sjacobs name); 490*2264Sjacobs exit(1); 491*2264Sjacobs } 492*2264Sjacobs 493*2264Sjacobs static void 494*2264Sjacobs lpc_shell() 495*2264Sjacobs { 496*2264Sjacobs for (;;) { 497*2264Sjacobs char line[256]; 498*2264Sjacobs char **av = NULL; 499*2264Sjacobs int ac = 0; 500*2264Sjacobs 501*2264Sjacobs /* prompt */ 502*2264Sjacobs fprintf(stdout, "lpc> "); 503*2264Sjacobs fflush(stdout); 504*2264Sjacobs 505*2264Sjacobs /* get command */ 506*2264Sjacobs if (fgets(line, sizeof (line), stdin) == NULL) 507*2264Sjacobs exit(1); 508*2264Sjacobs if ((av = strsplit(line, " \t\n")) != NULL) 509*2264Sjacobs for (ac = 0; av[ac] != NULL; ac++); 510*2264Sjacobs 511*2264Sjacobs (void) process(ac, av); 512*2264Sjacobs free(av); 513*2264Sjacobs } 514*2264Sjacobs } 515*2264Sjacobs 516*2264Sjacobs int 517*2264Sjacobs main(int ac, char *av[]) 518*2264Sjacobs { 519*2264Sjacobs int result = 0; 520*2264Sjacobs int c; 521*2264Sjacobs 522*2264Sjacobs (void) setlocale(LC_ALL, ""); 523*2264Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 524*2264Sjacobs 525*2264Sjacobs while ((c = getopt(ac, av, "E")) != EOF) 526*2264Sjacobs switch (c) { 527*2264Sjacobs case 'E': 528*2264Sjacobs encryption = PAPI_ENCRYPT_ALWAYS; 529*2264Sjacobs break; 530*2264Sjacobs default: 531*2264Sjacobs usage(av[0]); 532*2264Sjacobs } 533*2264Sjacobs 534*2264Sjacobs if (optind == ac) 535*2264Sjacobs lpc_shell(); 536*2264Sjacobs else 537*2264Sjacobs result = process(optind - 2, &av[optind]); 538*2264Sjacobs 539*2264Sjacobs return (result); 540*2264Sjacobs } 541