options.c revision 5c88ba20fc79ecf19255b4a04f03d77630b6d0e7
/*
* 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 "ctype.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#include <libintl.h>
#include "lp.h"
#include "printers.h"
#define WHO_AM_I I_AM_LPADMIN
#include "oam.h"
#include "lpadmin.h"
#ifdef LP_USE_PAPI_ATTR
#if defined(CAN_DO_MODULES)
#define OPT_LIST "A:ac:d:D:e:f:F:H:hi:I:lm:Mn:o:p:Q:r:S:s:T:u:U:v:W:x:t:P:"
#else
#define OPT_LIST "A:ac:d:D:e:f:F:hi:I:lm:Mn:o:p:Q:r:S:s:T:u:U:v:W:x:t:P:"
#endif
#else
#if defined(CAN_DO_MODULES)
#define OPT_LIST "A:ac:d:D:e:f:F:H:hi:I:lm:Mo:p:Q:r:S:s:T:u:U:v:W:x:t:P:"
#else
#define OPT_LIST "A:ac:d:D:e:f:F:hi:I:lm:Mo:p:Q:r:S:s:T:u:U:v:W:x:t:P:"
#endif
#endif
done (1); \
} else
done (1); \
else
extern char *optarg;
extern int optind,
extern double strtod();
extern long strtol();
int a = 0, /* alignment needed for mount */
#if defined(DIRECT_ACCESS)
C = 0, /* direct a.o.t. normal access */
#endif
filebreak = 0,
h = 0, /* hardwired terminal */
j = 0, /* do -F just for current job */
l = 0, /* login terminal */
M = 0, /* do mount */
t = 0, /* tray number*/
o = 0, /* some -o options given */
Q = -1, /* queue threshold for alert */
W = -1; /* alert interval */
char *A = 0, /* alert type */
*c = 0, /* class name */
*cpi = 0, /* string value of -o cpi= */
*d = 0, /* default destination */
*D = 0, /* description */
*e = 0, /* copy existing interface */
*P = 0, /* paper list */
*F = 0, /* fault recovery */
**H = 0, /* list of modules to push */
*i = 0, /* interface pathname */
**I = 0, /* content-type-list */
*length = 0, /* string value of -o length= */
*lpi = 0, /* string value of -o lpi= */
*m = 0, /* model name */
#ifdef LP_USE_PAPI_ATTR
#endif
*p = 0, /* printer name */
*r = 0, /* class to remove printer from */
*s = 0, /* system printer is on */
*stty_opt= 0, /* string value of -o stty= */
**o_options = 0,/* undefined lpadmin -o options */
**S = 0, /* -set/print-wheel list */
**T = 0, /* terminfo names */
*U = 0, /* dialer_info */
*v = 0, /* device pathname */
*width = 0, /* string value of -o width= */
*x = 0; /* destination to be deleted */
length_sdn = { 0, 0 },
lpi_sdn = { 0, 0 },
width_sdn = { 0, 0 };
static char *modp = modifications;
static void oparse();
static char * empty_list[] = { 0 };
/**
** options() - PARSE COMMAND LINE ARGUMENTS INTO OPTIONS
**/
int argc;
char *argv[];
{
int optsw,
ac,
Aflag = 0;
char *cp,
*rest,
**av;
#if defined(__STDC__)
typedef char * const * stupid; /* dumb-ass ANSI C */
#else
typedef char ** stupid;
#endif
/*
* 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 options MAY take a value. Check the value;
* if it begins with a '-', assume it's really the next
* option.
*/
case 'd':
case 'p': /* MR bl87-27863 */
case 'I':
#if defined(CAN_DO_MODULES)
case 'H':
#endif
if (*optarg == '-') {
/*
* This will work if we were given
*
* -x -foo
*
* but would fail if we were given
*
* -x-foo
*/
optind--;
switch (optsw) {
case 'd':
#if defined(CAN_DO_MODULES)
case 'H':
#endif
break;
case 'p':
break;
case 'I':
optarg = 0;
break;
}
}
break;
/*
* These options MUST have a value. Check the value;
* if it begins with a dash or is null, complain.
*/
case 'Q':
case 'W':
case 't':
/*
* These options take numeric values, which might
* be negative. Negative values are handled later,
* but here we just screen them.
*/
break;
/*FALLTHROUGH*/
case 'A':
case 'c':
case 'e':
case 'f':
case 'P':
case 'F':
case 'i':
case 'm':
#ifdef LP_USE_PAPI_ATTR
case 'n':
#endif
case 'o':
/* case 'p': */ /* MR bl87-27863 */
case 'r':
case 'S':
case 's':
case 'T':
case 'u':
case 'U':
case 'v':
case 'x':
/*
* These options also must have non-null args.
*/
if (!*optarg) {
done (1);
}
if (*optarg == '-') {
done (1);
}
if (optsw == 'A')
Aflag++;
break;
case 'D':
/*
* These options can have a null arg.
*/
if (*optarg == '-') {
done (1);
}
break;
}
switch (optsw) {
case 'a': /* alignment pattern needed for mount */
a = 1;
break;
case 'A': /* alert type */
if (A)
MALLOC(A);
Aflag++;
*modp++ = 'A';
break;
case 'c': /* class to insert printer p */
if (c)
MALLOC(c);
break;
#if defined(DIRECT_ACCESS)
case 'C':
C = 1;
break;
#endif
case 'd': /* system default destination */
if (d)
MALLOC(d);
break;
case 'D': /* description */
if (D)
MALLOC(D);
*modp++ = 'D';
break;
case 'e': /* existing printer interface */
if (e)
MALLOC(e);
*modp++ = 'e';
break;
if (f)
MALLOC(f);
break;
if (P)
MALLOC(P);
break;
case 'F': /* fault recovery */
if (F)
MALLOC(F);
*modp++ = 'F';
break;
#if defined(CAN_DO_MODULES)
case 'H':
if (H)
H = empty_list;
done(1);
}
*modp++ = 'H';
break;
#endif
case 'h': /* hardwired terminal */
h = 1;
*modp++ = 'h';
break;
case 'i': /* interface pathname */
if (i)
MALLOC(i);
*modp++ = 'i';
break;
case 'I': /* content-type-list */
if (I)
I = empty_list;
done (1);
}
*modp++ = 'I';
break;
#if defined(J_OPTION)
case 'j': /* fault recovery just for current job */
j = 1;
break;
#endif
case 'l': /* login terminal */
l = 1;
*modp++ = 'l';
break;
case 'm': /* model interface */
if (m)
MALLOC(m);
*modp++ = 'm';
break;
#ifdef LP_USE_PAPI_ATTR
case 'n': /* PPD file */
if (n_opt)
*modp++ = 'n';
break;
#endif
case 'M': /* a mount request */
M = 1;
break;
case 'o': /* several different options */
o = 1;
break;
case 'p': /* printer name */
if (p)
MALLOC(p);
break;
case 'Q':
if (Q != -1)
Q = 1;
else {
if (Q < 0) {
done (1);
}
done (1);
}
if (Q == 0) {
done (1);
}
}
*modp++ = 'Q';
break;
case 'r': /* class to remove p from */
if (r)
MALLOC(r);
break;
case 'S': /* char_set/print-wheels */
if (S)
done (1);
}
*modp++ = 'S';
break;
case 's':
if (s)
*cp = '\0';
s = Local_System;
if (cp) {
done(1);
} else
s = Local_System;
} else {
if (cp)
*cp = '!';
MALLOC(s);
}
/* 's' already used for stty 'R' for remote? */
*modp++ = 'R';
break;
case 't': /* tray number*/
if (t <= 0) {
done (1);
}
done (1);
}
break;
case 'T': /* terminfo names for p */
if (T)
done (1);
}
*modp++ = 'T';
break;
if (u)
MALLOC(u);
break;
case 'U': /* dialer_info */
if (U)
MALLOC(U);
*modp++ = 'U';
break;
case 'v': /* device pathname */
if (v)
MALLOC(v);
*modp++ = 'v';
break;
case 'W': /* alert interval */
if (W != -1)
W = 0;
else {
if (W < 0) {
done (1);
}
done (1);
}
}
*modp++ = 'W';
break;
case 'x': /* destination to be deleted */
if (x)
MALLOC(x);
break;
default:
if (optopt == '?') {
usage ();
done (0);
} else {
else
done (1);
}
}
}
if ((v) && (!Aflag)) {
if (!(A = strdup("write"))) {
done (1);
}
*modp++ = 'A';
}
return;
}
/**
** oparse() - PARSE -o OPTION
**/
char *optarg;
{
if (!list)
return;
if (banner != -1)
);
banner = BAN_ALWAYS;
*modp++ = 'b';
if (banner != -1)
);
*modp++ = 'b';
/* handle banner=(always|optional|never) */
char *ptr;
if (banner != -1)
);
/* like "banner", always print a banner */
banner = BAN_ALWAYS;
/* like "nobanner", print a banner unless requested */
/* never print a banner */
*modp++ = 'b';
if (length)
"length="
);
if (!*optarg) {
length_sdn.val = 0;
length_sdn.sc = 0;
} else {
done (1);
}
}
*modp++ = 'L';
if (width)
"width="
);
if (!*optarg) {
} else {
done (1);
}
}
*modp++ = 'w';
if (cpi)
if (!*optarg) {
} else {
done (1);
}
}
*modp++ = 'c';
if (lpi)
if (!*optarg) {
} else {
done (1);
}
}
*modp++ = 'M';
optarg += 5;
if (!*optarg)
stty_opt = 0;
else {
register int len
optarg++;
}
if (stty_opt)
else
}
*modp++ = 's';
filebreak = 1;
filebreak = 0;
/* added support for using -o to pass any key=value pair */
} else if (*optarg) {
}
*modp++ = 'o';
optarg++;
}
return;
}