opts.c revision 78eb75caca75144af27b7903ffed3fb549faab2f
/*
* 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.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*/
#include <stdio.h>
#include <libintl.h>
#include <stdlib.h>
#include <ctype.h>
#include <strings.h>
#include <time.h>
#include <errno.h>
#include "err.h"
#include "lut.h"
#include "fn.h"
#include "opts.h"
/* forward declarations for private functions */
/* info created by opts_parse(), private to this module */
struct opts {
};
/*
* opts_init -- set current options parsing table
*/
void
{
while (numentries-- > 0) {
table++;
}
}
/*
* opt_info -- fetch the optinfo struct for the given option
*/
static struct optinfo *
opt_info(int c)
{
char lhs[2];
lhs[0] = c;
}
/*
* opts_parse -- parse an argv-style list of options
*
* prints a message to stderr and calls err(EF_FILE|EF_JMP, ...) on error
*/
struct opts *
{
int dashdash = 0;
char *ptr;
/* no words to process, just return empty opts struct */
return (ret);
/* foreach word... */
/* found a cmdarg */
continue;
}
if (*++ptr == '\0')
if (*ptr == '-') {
/* (here's where support for --longname would go) */
dashdash++;
continue;
}
/* see if option was in our parsing table */
/* see if context allows this option */
"Option '%c' not allowed on "
"command line", *ptr);
"Option '%c' not allowed in "
"configuration file", *ptr);
/* for boolean options, we have all the info we need */
continue;
}
/* option expects argument */
if (*++ptr == '\0' &&
"Option '%c' requires an argument",
break;
}
}
return (ret);
}
/*
* opts_free -- free a struct opts previously allocated by opts_parse()
*/
void
{
if (opts) {
}
}
/*
* opts_set -- set an option
*/
void
{
}
/*
* opts_setcmdarg -- add a cmdarg to the list of op_cmdargs
*/
static void
{
}
/*
* opts_count -- return count of the options in *options that are set
*/
int
{
int count = 0;
char lhs[2];
count++;
}
return (count);
}
/*
* opts_optarg -- return the optarg for the given option, NULL if not set
*/
const char *
{
}
/*
* opts_optarg_int -- return the int value for the given option
*/
int
{
}
/*
* opts_cmdargs -- return list of op_cmdargs
*/
struct fn_list *
{
return (opts->op_cmdargs);
}
static void
{
}
/*
* opts_merge -- merge two option lists together
*/
struct opts *
{
return (ret);
}
/*
* opts_parse_ctime -- parse a ctime format optarg
*/
int
opts_parse_ctime(const char *o, const char *optarg)
{
int ret;
"Option '%c' requires ctime-style time", *o);
errno = 0;
return (ret);
}
/*
* opts_parse_atopi -- parse a positive integer format optarg
*/
int
opts_parse_atopi(const char *o, const char *optarg)
{
optarg++;
if (*optarg)
"Option '%c' requires non-negative number", *o);
return (ret);
}
/*
* opts_parse_atopi -- parse a size format optarg into bytes
*/
int
opts_parse_bytes(const char *o, const char *optarg)
{
optarg++;
switch (*optarg) {
case 'g':
case 'G':
ret *= 1024;
/*FALLTHROUGH*/
case 'm':
case 'M':
ret *= 1024;
/*FALLTHROUGH*/
case 'k':
case 'K':
ret *= 1024;
/*FALLTHROUGH*/
case 'b':
case 'B':
return (ret);
}
"Option '%c' requires number with suffix from [bkmg]", *o);
/*NOTREACHED*/
return (0);
}
/*
* opts_parse_seconds -- parse a time format optarg into seconds
*/
int
opts_parse_seconds(const char *o, const char *optarg)
{
int ret;
return (OPTP_NOW);
return (OPTP_NEVER);
optarg++;
switch (*optarg) {
case 'h':
case 'H':
return (ret);
case 'd':
case 'D':
return (ret);
case 'w':
case 'W':
return (ret);
case 'm':
case 'M':
return (ret);
case 'y':
case 'Y':
return (ret);
}
"Option '%c' requires number with suffix from [hdwmy]", *o);
/*NOTREACHED*/
return (0);
}
/* info passed between opts_print() and printer() */
struct printerinfo {
int isswitch;
char *exclude;
};
/* helper function for opts_print() */
static void
{
char *s = (char *)rhs;
return;
}
if (s && *s) {
}
}
/*
* opts_printword -- print a word, quoting as necessary
*/
void
{
char *q = "";
q = "\"";
word);
else
q = "'";
} else
}
/*
* opts_print -- print options to stream, leaving out those in "exclude"
*/
void
{
struct printerinfo pi;
}
}
#ifdef TESTMODULE
/* table that drives argument parsing */
};
/*
* test main for opts module, usage: a.out options...
*/
{
argv++;
if (SETJMP)
err(0, "opts parsing failed");
else
printf("options:");
printf("\n");
err_done(0);
}
#endif /* TESTMODULE */