00001 //--- 00002 // 00003 // This file is part of sedflux. 00004 // 00005 // sedflux is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // sedflux is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with sedflux; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 // 00019 //--- 00020 00021 #ifndef __EH_GET_OPT_H__ 00022 #define __EH_GET_OPT_H__ 00023 00024 #include <stdio.h> 00025 #include <glib.h> 00026 #include <utils/eh_types.h> 00027 #include <utils/eh_symbol_table.h> 00028 00029 typedef struct 00030 { 00031 Eh_symbol_table args; 00032 Eh_symbol_table defaults; 00033 } 00034 Eh_args; 00035 00036 // create a new Eh_args. 00037 Eh_args *eh_create_args(void ); 00038 00039 // destroy a Eh_args. 00040 // args : the Eh_args to destroy (args can be NULL). 00041 void eh_destroy_args( Eh_args *args ); 00042 00043 // parse the command line options and initialize an arg table. 00044 // argc : the number of command line arguments. 00045 // argv : a list of the command line arguments. 00046 Eh_args *eh_opts_init( int argc, char *argv[] ); 00047 00048 // read the default values from the eh resource file. first read values 00049 // from ~/.ehrc and the ./.ehrc. values in ./.ehrc take precedence over 00050 // values in ~/.ehrc. 00051 // prog_name : the name of the current program. the .ehrc files are 00052 // : scanned for records labeled with prog_name. 00053 Eh_symbol_table eh_get_opt_defaults( const char *prog_name ); 00054 00055 // lookup the value of a command line option. 00056 // args : an argument table returned by eh_opts_init. 00057 // key : the name of the option to look for. 00058 char *eh_args_lookup(Eh_args *t, char *key); 00059 00060 // insert a value into an arg table. 00061 // args : an argument table returned by eh_opts_init. 00062 // key : the name of the command line option. 00063 // value : the value of the option. 00064 void eh_args_insert(Eh_args *t, char *key, char *value); 00065 00066 // insert a default value into an arg table. 00067 // args : an argument table returned by eh_opts_init. 00068 // key : the name of the command line option. 00069 // value : the value of the option. 00070 void eh_args_insert_default(Eh_args *t, char *key, char *value); 00071 00072 // check the command line options. 00073 // args : an argument table returned by eh_opts_init. 00074 // required : a null terminated list of required options or NULL if none required. 00075 // possible : a null terminated list of all the possible option of NULL to ignore 00076 // : the check. 00077 // help_mesage : a help message to print to stderr if an error is encountered, or if 00078 // : help=yes is supplied on the command line. null if no error message. 00079 gboolean eh_check_opts( Eh_args* args, char **required , char **possible , char **help_message ); 00080 00081 // get the value (expresed as a string) given by the command line option, label or 00082 // NULL if not given. 00083 // args : an argument table returned by eh_opts_init. 00084 // label : the command line option. 00085 char *eh_get_opt( Eh_args *args , char *label ); 00086 00087 // get the value (expresed as a string) given as a default value from a .ehrc file or 00088 // NULL if not given. 00089 // args : an argument table returned by eh_opts_init. 00090 // label : the default option. 00091 char *eh_get_opt_default( Eh_args *args , char *label ); 00092 00093 // get the n-th argument on the command line. an argument is different from an option 00094 // as it is not of the form label=value; instead it is just a value. 00095 // args : an argument table returned by eh_opts_init. 00096 // n : the argument to return. 00097 char *eh_get_arg_n( Eh_args *args , int n ); 00098 00099 // print the current and default value of a command line option. 00100 // args : an argument table returned by eh_opts_init. 00101 // label : the command line option. 00102 void eh_print_opt( Eh_args *args , char *label ); 00103 00104 // get the string value given by the command line option, label. 00105 // args : an argument table returned by eh_opts_init. 00106 // label : the command line option. 00107 // default_val : the default value 00108 char *eh_get_opt_str( Eh_args *args , char *label , char *default_val ); 00109 00110 // get the int value given by the command line option, label. 00111 // args : an argument table returned by eh_opts_init. 00112 // label : the command line option. 00113 // default_val : the default value 00114 int eh_get_opt_int( Eh_args *args , char *label , int default_val ); 00115 00116 // get the boolean value given by the command line option, label. possible values 00117 // are yes or no. 00118 // args : an argument table returned by eh_opts_init. 00119 // label : the command line option. 00120 // default_val : the default value 00121 gboolean eh_get_opt_bool( Eh_args *args , char *label , gboolean default_val ); 00122 00123 // get the key given by the command line option, label. 00124 // args : an argument table returned by eh_opts_init. 00125 // label : the command line option. 00126 // default_val : the default value 00127 // keys : the possible key that can be given for the option. 00128 int eh_get_opt_key( Eh_args *args , char *label , int default_val , char *keys[] ); 00129 00130 // get the double value given by the command line option, label. 00131 // args : an argument table returned by eh_opts_init. 00132 // label : the command line option. 00133 // default_val : the default value 00134 double eh_get_opt_dbl( Eh_args *args , char *label , double default_val ); 00135 00136 // print a message to the file pointer, fp 00137 // fp : a file pointer. 00138 // message : a null terminated list of text line to print. a new line character is 00139 // : added to the end of each line weather there is already one there or not. 00140 gint eh_print_message( FILE *fp , char *message[] ); 00141 00142 void eh_print_all_opts( Eh_args *args , char *prog_name , FILE *fp ); 00143 00144 #endif 00145