H:/Class/11756/HLab/sphinxbase-0.4/src/libsphinxbase/util/cmd_ln.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "cmd_ln.h"
#include "err.h"
#include "ckd_alloc.h"
#include "hash_table.h"
#include "case.h"

Classes

struct  cmd_ln_val_s
struct  cmd_ln_s

Defines

#define ARG_MAX_LENGTH   512

Typedefs

typedef struct cmd_ln_val_s cmd_ln_val_t

Functions

void cmd_ln_val_free (cmd_ln_val_t *val)
cmd_ln_tcmd_ln_get (void)
void cmd_ln_appl_enter (int argc, char *argv[], const char *default_argfn, const arg_t *defn)
void cmd_ln_appl_exit ()
cmd_ln_tcmd_ln_parse_r (cmd_ln_t *inout_cmdln, const arg_t *defn, int32 argc, char *argv[], int strict)
cmd_ln_tcmd_ln_init (cmd_ln_t *inout_cmdln, const arg_t *defn, int32 strict,...)
int cmd_ln_parse (const arg_t *defn, int32 argc, char *argv[], int strict)
cmd_ln_tcmd_ln_parse_file_r (cmd_ln_t *inout_cmdln, const arg_t *defn, const char *filename, int32 strict)
int cmd_ln_parse_file (const arg_t *defn, const char *filename, int32 strict)
void cmd_ln_print_help_r (cmd_ln_t *cmdln, FILE *fp, arg_t const *defn)
int cmd_ln_exists_r (cmd_ln_t *cmdln, const char *name)
anytype_tcmd_ln_access_r (cmd_ln_t *cmdln, const char *name)
char const * cmd_ln_str_r (cmd_ln_t *cmdln, char const *name)
long cmd_ln_int_r (cmd_ln_t *cmdln, char const *name)
double cmd_ln_float_r (cmd_ln_t *cmdln, char const *name)
void cmd_ln_set_str_r (cmd_ln_t *cmdln, char const *name, char const *str)
void cmd_ln_set_int_r (cmd_ln_t *cmdln, char const *name, long iv)
void cmd_ln_set_float_r (cmd_ln_t *cmdln, char const *name, double fv)
cmd_ln_tcmd_ln_retain (cmd_ln_t *cmdln)
int cmd_ln_free_r (cmd_ln_t *cmdln)
void cmd_ln_free (void)

Variables

cmd_ln_tglobal_cmdln

Define Documentation

#define ARG_MAX_LENGTH   512

Typedef Documentation

typedef struct cmd_ln_val_s cmd_ln_val_t

Function Documentation

anytype_t* cmd_ln_access_r ( cmd_ln_t cmdln,
char const *  name 
)

Access the generic type union for a command line argument.

void cmd_ln_appl_enter ( int  argc,
char *  argv[],
char const *  default_argfn,
const arg_t defn 
)

Old application initialization routine for Sphinx3 code.

Deprecated:
This is deprecated in favor of the re-entrant API.
Parameters:
argc In: Number of actual arguments
argv In: Number of actual arguments
default_argfn In: default argument file name
defn Command-line argument definition
void cmd_ln_appl_exit ( void   ) 

Finalization routine corresponding to cmd_ln_appl_enter().

Deprecated:
This is deprecated in favor of the re-entrant API.
int cmd_ln_exists_r ( cmd_ln_t cmdln,
char const *  name 
)

Re-entrant version of cmd_ln_exists().

Returns:
True if the command line argument exists (i.e. it was one of the arguments defined in the call to cmd_ln_parse_r().
double cmd_ln_float_r ( cmd_ln_t cmdln,
char const *  name 
)

Retrieve a floating-point number from a command-line object.

Parameters:
cmdln Command-line object.
name the command-line flag to retrieve.
Returns:
the float value associated with name, or 0.0 if name does not exist. You must use cmd_ln_exists_r() to distinguish between cases where a value is legitimately zero and where the corresponding flag is unknown.
void cmd_ln_free ( void   ) 

Free the global command line, if any exists.

Deprecated:
Use the re-entrant API instead.
int cmd_ln_free_r ( cmd_ln_t cmdln  ) 

Release a command-line argument set and all associated strings.

Returns:
new reference count (0 if freed completely)
cmd_ln_t* cmd_ln_get ( void   ) 

Retrieve the global cmd_ln_t object used by non-re-entrant functions.

Deprecated:
This is deprecated in favor of the re-entrant API.
Returns:
global cmd_ln_t object.
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.

This function creates a cmd_ln_t from a NULL-terminated list of argument strings. For example, to create the equivalent of passing "-hmm foodir -dsratio 2 -lm bar.lm" on the command-line:

config = cmd_ln_init(NULL, defs, TRUE, "-hmm", "foodir", "-dsratio", "2", "-lm", "bar.lm", NULL);

Note that for simplicity, all arguments are passed as strings, regardless of the actual underlying type.

Parameters:
inout_cmdln Previous command-line to update, or NULL to create a new one.
defn Array of argument name definitions, or NULL to allow any arguments.
strict Whether to fail on duplicate or unknown arguments.
Returns:
A cmd_ln_t* containing the results of command line parsing, or NULL on failure.
long cmd_ln_int_r ( cmd_ln_t cmdln,
char const *  name 
)

Retrieve an integer from a command-line object.

Parameters:
cmdln Command-line object.
name the command-line flag to retrieve.
Returns:
the integer value associated with name, or 0 if name does not exist. You must use cmd_ln_exists_r() to distinguish between cases where a value is legitimately zero and where the corresponding flag is unknown.
int cmd_ln_parse ( const arg_t defn,
int32  argc,
char *  argv[],
int32  strict 
)

Non-reentrant version of cmd_ln_parse().

Deprecated:
This is deprecated in favor of the re-entrant API function cmd_ln_parse_r().
Returns:
0 if successful, <0 if error.
Parameters:
defn In: Array of argument name definitions
argc In: Number of actual arguments
argv In: Actual arguments
strict In: Fail on duplicate or unknown arguments, or no arguments?
int 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_ln_parse().

Deprecated:
This is deprecated in favor of the re-entrant API function cmd_ln_parse_file_r().
Returns:
0 if successful, <0 on error.
Parameters:
defn In: Array of argument name definitions
filename In: A file that contains all the arguments
strict In: Fail on duplicate or unknown arguments, or no arguments?
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_ln_parse().

Returns:
A cmd_ln_t containing the results of command line parsing, or NULL on failure.
Parameters:
inout_cmdln In/Out: Previous command-line to update, or NULL to create a new one.
defn In: Array of argument name definitions
filename In: A file that contains all the arguments
strict In: Fail on duplicate or unknown arguments, or no arguments?
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.

Parse the given list of arguments (name-value pairs) according to the given definitions. Argument values can be retrieved in future using cmd_ln_access(). argv[0] is assumed to be the program name and skipped. Any unknown argument name causes a fatal error. The routine also prints the prevailing argument values (to stderr) after parsing.

Note:
It is currently assumed that the strings in argv are allocated statically, or at least that they will be valid as long as the cmd_ln_t returned from this function. Unpredictable behaviour will result if they are freed or otherwise become invalidated.
Returns:
A cmd_ln_t containing the results of command line parsing, or NULL on failure.
Parameters:
inout_cmdln In/Out: Previous command-line to update, or NULL to create a new one.
defn In: Array of argument name definitions
argc In: Number of actual arguments
argv In: Actual arguments
strict In: Fail on duplicate or unknown arguments, or no arguments?
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.

Parameters:
fp In: File to which to print
defn In: Array of argument name definitions
cmd_ln_t* cmd_ln_retain ( cmd_ln_t cmdln  ) 

Retain ownership of a command-line argument set.

Returns:
pointer to retained command-line argument set.
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.

Parameters:
cmdln Command-line object.
name The command-line flag to set.
fv Integer value to set.
void cmd_ln_set_int_r ( cmd_ln_t cmdln,
char const *  name,
long  iv 
)

Set an integer in a command-line object.

Parameters:
cmdln Command-line object.
name The command-line flag to set.
iv Integer value to set.
void cmd_ln_set_str_r ( cmd_ln_t cmdln,
char const *  name,
char const *  str 
)

Set a string in a command-line object.

Parameters:
cmdln Command-line object.
name The command-line flag to set.
str String value to set. The command-line object does not retain ownership of this pointer.
char const* cmd_ln_str_r ( cmd_ln_t cmdln,
char const *  name 
)

Retrieve a string from a command-line object.

The command-line object retains ownership of this string, so you should not attempt to free it manually.

Parameters:
cmdln Command-line object.
name the command-line flag to retrieve.
Returns:
the string value associated with name, or NULL if name does not exist. You must use cmd_ln_exists_r() to distinguish between cases where a value is legitimately NULL and where the corresponding flag is unknown.
void cmd_ln_val_free ( cmd_ln_val_t val  ) 

Variable Documentation

Global command-line, for non-reentrant API.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines
Generated on Sat May 8 14:21:41 2010 for HLab by  doxygen 1.6.3