parse.c revision f928ce67ef743c33ea27c573c9c7e2d4a4833cbd
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include "string.h"
#include "stdlib.h"
#include "lp.h"
#include "printers.h"
#define WHO_AM_I I_AM_LPSTAT
#include "oam.h"
#include "lpstat.h"
#include <locale.h>
typedef struct execute {
char *list;
void (*func)();
int inquire_type;
} EXECUTE;
static int r = 0;
int D = 0,
remote_cmd = 0;
unsigned int verbosity = 0;
extern char *optarg;
extern int getopt(),
static void usage ( void );
#if defined(CAN_DO_MODULES)
#define OPT_LIST "a:c:do:p:rstu:v:f:TDS:lLRHP:"
#else
#define OPT_LIST "a:c:do:p:rstu:v:f:TDS:lLRP:"
#endif
{ \
}
/**
** parse() - PARSE COMMAND LINE OPTIONS
**/
/*
* This routine parses the command line, builds a linked list of
* function calls desired, then executes them in the order they
* were received. This is necessary as we must apply -l to all
* options. So, we could either stash the calls away, or go
* through parsing twice. I chose to build the linked list.
*/
void
{
int optsw;
int ac;
int need_mount = 0;
char ** av;
char * p;
char ** list;
/*
* Add a fake value to the end of the "argv" list, to
* catch the case that a valued-option comes last.
*/
opterr = 0;
switch(optsw) {
/*
* These option letters MAY take a value. Check the value;
* if it begins with a '-', assume it's really the next
* argument.
*/
case 'a':
case 'c':
case 'o':
case 'p':
case 'u':
case 'v':
case 'f':
case 'P':
case 'S':
if (*optarg == '-') {
/*
* This will work if we were given
*
* -x -foo
*
* but would fail if we were given
*
* -x-foo
*/
optind--;
}
break;
}
switch(optsw) {
case 'a': /* acceptance status */
break;
case 'c': /* class to printer mapping */
break;
case 'd': /* default destination */
break;
case 'D': /* Description of printers */
D = 1;
break;
case 'f': /* do forms */
need_mount = 1;
break;
case 'P': /* do forms */
break;
#if defined(CAN_DO_MODULES)
case 'H': /* show modules pushed for printer */
break;
#endif
case 'l': /* verbose output */
break;
case 'L': /* Local only */
remote_cmd = 0;
break;
case 'o': /* output for destinations */
break;
case 'p': /* printer status */
break;
case 'R': /* show rank in queue */
break;
case 'r': /* is scheduler running? */
r = 1;
break;
case 's': /* configuration summary */
r = 1;
need_mount = 1;
break;
case 'S': /* character set info */
need_mount = 1;
break;
case 't': /* print all info */
r = 1;
need_mount = 1;
break;
case 'T': /* (trace) special debugging output */
break;
case 'u': /* output by user */
break;
case 'v': /* printers to devices mapping */
break;
default:
if (optopt == '?') {
usage ();
done (0);
}
else
done(1);
break;
}
}
#ifdef NEVER
if (getenv("LPSTAT_NO_REMOTE"))
remote_cmd = 0;
#endif /* NEVER */
/*
* Note: "argc" here, not "ac", to skip our fake option.
* We could use either "argv" or "av", since for the range
* of interest they're the same.
*/
list = 0;
done(1);
}
if (list)
startup ();
/*
Linked list is completed, load up mount info if
needed then do the requests
*/
if (need_mount) {
}
else
}
return;
}
/**
** usage() - PRINT USAGE MESSAGE
**/
static void
usage(void)
{
#if defined(CAN_DO_MODULES)
"usage:\n"
" lpstat [options] [request-ids]\n"
" [-a printers,classes] (show acceptance status)\n"
" [-c classes] (show available classes)\n"
" [-d] (show default destination)\n"
" [-D] (-p only: describe printers)\n"
" [-f forms] (show available forms)\n"
" [-l] (be verbose)\n"
" [-o printers,classes,req-ids] (show status of requests)\n"
" [-p printers] (show available printers)\n"
" [-P] (show paper types)\n"
" [-R] (show rank in queue)\n"
" [-r] (show status of Spooler)\n"
" [-s] (show summary status)\n"
" [-S char-sets,print-wheels] (show available \"fonts\")\n"
" [-t] (show status of everything)\n"
" [-u users] (show status of user requests)\n"
" [-v printers [-H]] (show devices used by printers)\n"
" (\"all\" allowed with -a,-c,-f,-o,-p,-S,-u,-v options)\n"));
#else
"usage:\n"
" lpstat [options] [request-ids]\n"
" [-a printers,classes] (show acceptance status)\n"
" [-c classes] (show available classes)\n"
" [-d] (show default destination)\n"
" [-D] (-p only: describe printers)\n"
" [-f forms] (show available forms)\n"
" [-l] (be verbose)\n"
" [-o printers,classes,req-ids] (show status of requests)\n"
" [-p printers] (show available printers)\n"
" [-P] (show paper types)\n"
" [-R] (show rank in queue)\n"
" [-r] (show status of Spooler)\n"
" [-s] (show summary status)\n"
" [-S char-sets,print-wheels] (show available \"fonts\")\n"
" [-t] (show status of everything)\n"
" [-u users] (show status of user requests)\n"
" [-v printers] (show devices used by printers)\n"
" (\"all\" allowed with -a,-c,-f,-o,-p,-S,-u,-v options)\n"));
#endif
return;
}