cmd_ln.h
Go to the documentation of this file.
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
/* ====================================================================
* Copyright (c) 1999-2004 Carnegie Mellon University. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* This work was supported in part by funding from the Defense Advanced
* Research Projects Agency and the National Science Foundation of the
* United States of America, and the CMU Sphinx Speech Consortium.
*
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ====================================================================
*
*/
/*
* cmd_ln.h -- Command line argument parsing.
*
* **********************************************
* CMU ARPA Speech Project
*
* Copyright (c) 1999 Carnegie Mellon University.
* ALL RIGHTS RESERVED.
* **********************************************
*
* HISTORY
*
* 15-Jul-1997 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Added required arguments types.
*
* 07-Dec-96 M K Ravishankar (rkm@cs.cmu.edu) at Carnegie Mellon University
* Created, based on Eric's implementation. Basically, combined several
* functions into one, eliminated validation, and simplified the interface.
*/
#ifndef _LIBUTIL_CMD_LN_H_
#define _LIBUTIL_CMD_LN_H_
#include <stdio.h>
#include <stdarg.h>
/* Win32/WinCE DLL gunk */
#include <sphinxbase/sphinxbase_export.h>
#include <sphinxbase/prim_type.h>
#ifdef __cplusplus
extern "C" {
#endif
#if 0
/* Fool Emacs. */
}
#endif
typedef struct arg_s {
char const *name;
int type;
char const *deflt;
char const *doc;
} arg_t;
/* @{ */
#define ARG_REQUIRED (1<<0)
#define ARG_INTEGER (1<<1)
#define ARG_FLOATING (1<<2)
#define ARG_STRING (1<<3)
#define ARG_BOOLEAN (1<<4)
#define ARG_STRING_LIST (1<<5)
#define REQARG_INTEGER (ARG_INTEGER | ARG_REQUIRED)
#define REQARG_FLOATING (ARG_FLOATING | ARG_REQUIRED)
#define REQARG_STRING (ARG_STRING | ARG_REQUIRED)
#define REQARG_BOOLEAN (ARG_BOOLEAN | ARG_REQUIRED)
#define ARG_INT32 ARG_INTEGER
#define ARG_FLOAT32 ARG_FLOATING
#define ARG_FLOAT64 ARG_FLOATING
#define REQARG_INT32 (ARG_INT32 | ARG_REQUIRED)
#define REQARG_FLOAT32 (ARG_FLOAT32 | ARG_REQUIRED)
#define REQARG_FLOAT64 (ARG_FLOAT64 | ARG_REQUIRED)
/* @} */
#define ARG_STRINGIFY(s) ARG_STRINGIFY1(s)
#define ARG_STRINGIFY1(s) #s
typedef struct cmd_ln_s cmd_ln_t;
SPHINXBASE_EXPORT
cmd_ln_t *cmd_ln_init(cmd_ln_t *inout_cmdln, arg_t const *defn, int32 strict, ...);
SPHINXBASE_EXPORT
cmd_ln_t *cmd_ln_retain(cmd_ln_t *cmdln);
SPHINXBASE_EXPORT
int cmd_ln_free_r(cmd_ln_t *cmdln);
SPHINXBASE_EXPORT
cmd_ln_t *cmd_ln_parse_r(cmd_ln_t *inout_cmdln,
arg_t const *defn,
int32 argc,
char *argv[],
int32 strict
);
SPHINXBASE_EXPORT
cmd_ln_t *cmd_ln_parse_file_r(cmd_ln_t *inout_cmdln,
arg_t const *defn,
char const *filename,
int32 strict
);
SPHINXBASE_EXPORT
anytype_t *cmd_ln_access_r(cmd_ln_t *cmdln, char const *name);
SPHINXBASE_EXPORT
char const *cmd_ln_str_r(cmd_ln_t *cmdln, char const *name);
SPHINXBASE_EXPORT
char const **cmd_ln_str_list_r(cmd_ln_t *cmdln, char const *name);
SPHINXBASE_EXPORT
long cmd_ln_int_r(cmd_ln_t *cmdln, char const *name);
SPHINXBASE_EXPORT
double cmd_ln_float_r(cmd_ln_t *cmdln, char const *name);
#define cmd_ln_boolean_r(c,n) (cmd_ln_int_r(c,n) != 0)
SPHINXBASE_EXPORT
void cmd_ln_set_str_r(cmd_ln_t *cmdln, char const *name, char const *str);
SPHINXBASE_EXPORT
void cmd_ln_set_int_r(cmd_ln_t *cmdln, char const *name, long iv);
SPHINXBASE_EXPORT
void cmd_ln_set_float_r(cmd_ln_t *cmdln, char const *name, double fv);
#define cmd_ln_set_boolean_r(c,n,b) (cmd_ln_set_int_r(c,n,(b)!=0))
/*
* Compatibility macros
*/
#define cmd_ln_int32_r(c,n) (int32)cmd_ln_int_r(c,n)
#define cmd_ln_float32_r(c,n) (float32)cmd_ln_float_r(c,n)
#define cmd_ln_float64_r(c,n) (float64)cmd_ln_float_r(c,n)
#define cmd_ln_set_int32_r(c,n,i) cmd_ln_set_int_r(c,n,i)
#define cmd_ln_set_float32_r(c,n,f) cmd_ln_set_float_r(c,n,(double)f)
#define cmd_ln_set_float64_r(c,n,f) cmd_ln_set_float_r(c,n,(double)f)
SPHINXBASE_EXPORT
int cmd_ln_exists_r(cmd_ln_t *cmdln, char const *name);
SPHINXBASE_EXPORT
void cmd_ln_print_help_r (cmd_ln_t *cmdln,
FILE *fp,
const arg_t *defn
);
SPHINXBASE_EXPORT
int32 cmd_ln_parse(const arg_t *defn,
int32 argc,
char *argv[],
int32 strict
);
SPHINXBASE_EXPORT
int32 cmd_ln_parse_file(const arg_t *defn,
char const *filename,
int32 strict
);
SPHINXBASE_EXPORT
void cmd_ln_appl_enter(int argc,
char *argv[],
char const* default_argfn,
const arg_t *defn
);
SPHINXBASE_EXPORT
void cmd_ln_appl_exit(void);
SPHINXBASE_EXPORT
cmd_ln_t *cmd_ln_get(void);
#define cmd_ln_exists(name) cmd_ln_exists_r(cmd_ln_get(), name)
#define cmd_ln_access(name) cmd_ln_access_r(cmd_ln_get(), name)
#define cmd_ln_str(name) cmd_ln_str_r(cmd_ln_get(), name)
#define cmd_ln_str_list(name) cmd_ln_str_list_r(cmd_ln_get(), name)
#define cmd_ln_int32(name) (int32)cmd_ln_int_r(cmd_ln_get(), name)
#define cmd_ln_float32(name) (float32)cmd_ln_float_r(cmd_ln_get(), name)
#define cmd_ln_float64(name) (float64)cmd_ln_float_r(cmd_ln_get(), name)
#define cmd_ln_boolean(name) cmd_ln_boolean_r(cmd_ln_get(), name)
#define cmd_ln_set_str(n,s) cmd_ln_set_str_r(cmd_ln_get(),n,s)
#define cmd_ln_set_int32(n,i) cmd_ln_set_int_r(cmd_ln_get(),n,i)
#define cmd_ln_set_float32(n,f) cmd_ln_set_float_r(cmd_ln_get(),n,f)
#define cmd_ln_set_float64(n,f) cmd_ln_set_float_r(cmd_ln_get(),n,f)
#define cmd_ln_set_boolean(n,b) cmd_ln_set_boolean_r(cmd_ln_get(),n,b)
#define cmd_ln_print_help(f,d) cmd_ln_print_help_r(cmd_ln_get(),f,d)
SPHINXBASE_EXPORT
void cmd_ln_free (void);
#ifdef __cplusplus
}
#endif
#endif
arg_s::name
char const * name
Name of the command line switch.
Definition: cmd_ln.h:89
cmd_ln_retain
SPHINXBASE_EXPORT cmd_ln_t * cmd_ln_retain(cmd_ln_t *cmdln)
Retain ownership of a command-line argument set.
Definition: cmd_ln.c:1029
cmd_ln_float_r
SPHINXBASE_EXPORT double cmd_ln_float_r(cmd_ln_t *cmdln, char const *name)
Retrieve a floating-point number from a command-line object.
Definition: cmd_ln.c:979
cmd_ln_int_r
SPHINXBASE_EXPORT long cmd_ln_int_r(cmd_ln_t *cmdln, char const *name)
Retrieve an integer from a command-line object.
Definition: cmd_ln.c:969
cmd_ln_access_r
SPHINXBASE_EXPORT anytype_t * cmd_ln_access_r(cmd_ln_t *cmdln, char const *name)
Access the generic type union for a command line argument.
Definition: cmd_ln.c:938
arg_s::doc
char const * doc
Documentation/description string.
Definition: cmd_ln.h:92
cmd_ln_set_int_r
SPHINXBASE_EXPORT void cmd_ln_set_int_r(cmd_ln_t *cmdln, char const *name, long iv)
Set an integer in a command-line object.
Definition: cmd_ln.c:1005
cmd_ln_free_r
SPHINXBASE_EXPORT int cmd_ln_free_r(cmd_ln_t *cmdln)
Release a command-line argument set and all associated strings.
Definition: cmd_ln.c:1036
arg_s::type
int type
Type of the argument in question.
Definition: cmd_ln.h:90
cmd_ln_exists_r
SPHINXBASE_EXPORT int cmd_ln_exists_r(cmd_ln_t *cmdln, char const *name)
Re-entrant version of cmd_ln_exists().
Definition: cmd_ln.c:929
cmd_ln_parse_r
SPHINXBASE_EXPORT cmd_ln_t * cmd_ln_parse_r(cmd_ln_t *inout_cmdln, arg_t const *defn, int32 argc, char *argv[], int32 strict)
Parse a list of strings into argumetns.
Definition: cmd_ln.c:551
prim_type.h
Basic type definitions used in Sphinx.
cmd_ln_str_r
SPHINXBASE_EXPORT char const * cmd_ln_str_r(cmd_ln_t *cmdln, char const *name)
Retrieve a string from a command-line object.
Definition: cmd_ln.c:949
cmd_ln_str_list_r
SPHINXBASE_EXPORT char const ** cmd_ln_str_list_r(cmd_ln_t *cmdln, char const *name)
Retrieve an array of strings from a command-line object.
Definition: cmd_ln.c:959
cmd_ln_get
SPHINXBASE_EXPORT cmd_ln_t * cmd_ln_get(void)
Retrieve the global cmd_ln_t object used by non-re-entrant functions.
Definition: cmd_ln.c:488
cmd_ln_print_help_r
SPHINXBASE_EXPORT void cmd_ln_print_help_r(cmd_ln_t *cmdln, FILE *fp, const arg_t *defn)
Print a help message listing the valid argument names, and the associated attributes as given in defn...
Definition: cmd_ln.c:919
arg_s
Definition: cmd_ln.h:88
arg_s::deflt
char const * deflt
Default value (as a character string), or NULL if none.
Definition: cmd_ln.h:91
cmd_ln_s
Definition: cmd_ln.c:90
cmd_ln_init
SPHINXBASE_EXPORT cmd_ln_t * cmd_ln_init(cmd_ln_t *inout_cmdln, arg_t const *defn, int32 strict,...)
Create a cmd_ln_t from NULL-terminated list of arguments.
Definition: cmd_ln.c:718
cmd_ln_appl_exit
SPHINXBASE_EXPORT void cmd_ln_appl_exit(void)
Finalization routine corresponding to cmd_ln_appl_enter().
Definition: cmd_ln.c:544
cmd_ln_parse_file_r
SPHINXBASE_EXPORT cmd_ln_t * cmd_ln_parse_file_r(cmd_ln_t *inout_cmdln, arg_t const *defn, char const *filename, int32 strict)
Parse an arguments file by deliminating on " \r\t\n" and putting each tokens into an argv[] for cmd_l...
Definition: cmd_ln.c:773
arg_t
Argument definition structure.
cmd_ln_t
Opaque structure used to hold the results of command-line parsing.
cmd_ln_set_float_r
SPHINXBASE_EXPORT void cmd_ln_set_float_r(cmd_ln_t *cmdln, char const *name, double fv)
Set a floating-point number in a command-line object.
Definition: cmd_ln.c:1017
anytype_s
Union of basic types.
Definition: prim_type.h:107
cmd_ln_parse
SPHINXBASE_EXPORT int32 cmd_ln_parse(const arg_t *defn, int32 argc, char *argv[], int32 strict)
Non-reentrant version of cmd_ln_parse().
Definition: cmd_ln.c:755
cmd_ln_set_str_r
SPHINXBASE_EXPORT void cmd_ln_set_str_r(cmd_ln_t *cmdln, char const *name, char const *str)
Set a string in a command-line object.
Definition: cmd_ln.c:989
cmd_ln_free
SPHINXBASE_EXPORT void cmd_ln_free(void)
Free the global command line, if any exists.
Definition: cmd_ln.c:1072
cmd_ln_appl_enter
SPHINXBASE_EXPORT void cmd_ln_appl_enter(int argc, char *argv[], char const *default_argfn, const arg_t *defn)
Old application initialization routine for Sphinx3 code.
Definition: cmd_ln.c:494
cmd_ln_parse_file
SPHINXBASE_EXPORT int32 cmd_ln_parse_file(const arg_t *defn, char const *filename, int32 strict)
Parse an arguments file by deliminating on " \r\t\n" and putting each tokens into an argv[] for cmd_l...
Definition: cmd_ln.c:903