00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <Basics.H>
00042 #include <Text.H>
00043 #include <VestaConfig.H>
00044
00045 #if !defined(__sun__)
00046 extern "C" {
00047 #include <getopt.h>
00048 }
00049 #endif
00050
00051 using std::cerr;
00052 using std::cout;
00053 using std::endl;
00054
00055 Text program_name;
00056 extern const char *Version;
00057
00058 void
00059 Usage()
00060 {
00061 cerr << "Usage: " << program_name << endl <<
00062 " [-l location] [-L] [-V]" << endl <<
00063 " [-i] [-b] [-f]" << endl <<
00064 " [section name [section name ...]]" << endl << endl;
00065 exit(1);
00066 }
00067
00068 int
00069 main(int argc, char* argv[])
00070 {
00071 typedef enum { get_text, get_int, get_bool, get_float } get_t;
00072 try {
00073 Text location, section, name;
00074 bool default_location = true, print_location = false, print_value = true;
00075 bool print_version = false, print_sect = false;
00076 int c;
00077 get_t get_type = get_text;
00078
00079
00080
00081 program_name = argv[0];
00082 opterr = 0;
00083 for (;;) {
00084 c = getopt(argc, argv, "l:ibfLVs");
00085 if (c == EOF) break;
00086 switch (c) {
00087 case 'l':
00088 location = optarg;
00089 default_location = false;
00090 break;
00091 case 'i':
00092 get_type = get_int;
00093 break;
00094 case 'b':
00095 get_type = get_bool;
00096 break;
00097 case 'f':
00098 get_type = get_float;
00099 break;
00100 case 'L':
00101 print_location = true;
00102 break;
00103 case 'V':
00104 print_version = true;
00105 break;
00106 case 's':
00107 print_sect = true;
00108 break;
00109 case '?':
00110 default:
00111 Usage();
00112 }
00113 }
00114
00115 if (optind == argc) {
00116 if (!print_location && !print_version && !print_sect) {
00117 cerr << program_name << ": nothing to do\n" << endl;
00118 Usage();
00119 }
00120 print_value = false;
00121 } else if ((argc - optind) == 1) {
00122 if(!print_sect)
00123 Usage();
00124 print_value = false;
00125 } else if ((argc - optind) & 0x1) {
00126 Usage();
00127 }
00128
00129 if (!default_location) {
00130 VestaConfig::set_location(location);
00131 }
00132
00133 if (print_version) {
00134 cout << program_name << ": version " << Version << endl;
00135 }
00136
00137 if (print_location) {
00138 cout << VestaConfig::get_location() << endl;
00139 }
00140
00141 if(print_sect)
00142 {
00143 TextSeq result;
00144 if(argc > optind)
00145 result = VestaConfig::section_vars(argv[optind]);
00146 else
00147 result = VestaConfig::sections();
00148 while(result.size())
00149 {
00150 cout << result.remlo() << endl;
00151 }
00152 }
00153
00154 if(print_value)
00155 {
00156 for(;optind < argc;optind += 2) {
00157 section = argv[optind];
00158 name = argv[optind + 1];
00159 switch(get_type)
00160 {
00161 case get_text:
00162 cout << VestaConfig::get_Text(section, name) << endl;
00163 break;
00164 case get_int:
00165 cout << VestaConfig::get_int(section, name) << endl;
00166 break;
00167 case get_bool:
00168 cout << (VestaConfig::get_bool(section, name)
00169 ? "true" : "false")
00170 << endl;
00171 break;
00172 case get_float:
00173 cout << VestaConfig::get_float(section, name) << endl;
00174 break;
00175 }
00176 }
00177 }
00178
00179 } catch (VestaConfig::failure f) {
00180 cerr << program_name << ": " << f.msg << endl;
00181 exit(2);
00182 }
00183
00184 return 0;
00185 }
00186
00187