1 /******************************************************************************
5 * $Date: 2007/03/26 01:00:38 $
9 * Revision 2.0 2007/03/26 01:00:38 hachti
10 * *** empty log message ***
13 ******************************************************************************/
16 * Program configuration management
24 #include <sys/types.h>
28 #include "configuration_manager.hh"
31 /* Global configuration data */
35 int cfg_outfile_set
=0;
36 int cfg_config_file_set
=0;
39 int cfg_output_info
=0;
40 int cfg_output_called
=0;
41 int cfg_output_exported
=0;
42 int cfg_output_unsatisfied
=0;
43 int cfg_split_objects
=0;
44 int cfg_split_objects_numbered
=0;
45 int cfg_split_blocks
=0;
46 int cfg_ignore_block_errors
=0;
47 int cfg_ignore_checksum_errors
=0;
48 //int cfg_pause_on_checksum_error=0;
49 int cfg_ignore_unknown_block_errors
=0;
50 int cfg_ignore_object_integrity_errors
=0;
51 int cfg_list_contents
=1;
57 int in_fd
=0; //! File descriptor for data input
58 int out_fd
=1; //! File descriptor for text output
60 void do_config(int argc
, char ** args
){
62 string cfg_config_file
;
63 configuration_manager
ar("ldc2");
65 /* Here come the configuration switches */
66 ar
.add_option_switch("h","help",
67 "Output this help text and exit.",
68 &cfg_do_help
,false,true);
70 ar
.add_option_switch("a","output_info",
71 "Print tape data information",
72 &cfg_output_info
,true,true);
74 ar
.add_option_switch("c","output_called",
75 "Print all called symbols from the object(s).",
76 &cfg_output_called
,true,true);
78 ar
.add_option_switch("e","output_exported",
79 "Print all exported symbols from the object(s).",
80 &cfg_output_exported
,true,true);
82 ar
.add_option_switch("u","output_unsatisfied",
83 "List all unsatisfied symbols.",
84 &cfg_output_unsatisfied
,true,true);
86 ar
.add_option_switch("s","split_objects",
87 "Split input data into distinct object files.",
88 &cfg_split_objects
,true,true);
90 ar
.add_option_switch("S","split_objects_numbered",
91 "Split input data into distinct numbered files",
92 &cfg_split_objects_numbered
,true,true);
94 ar
.add_option_switch("B","split_blocks",
95 "Split tape into named and numbered block files",
96 &cfg_split_blocks
,true,true);
98 ar
.add_option_switch("b","ignore_block_errors",
99 "Ignore block integrity errors. This will output broken blocks,too",
100 &cfg_ignore_block_errors
,true,true);
102 ar
.add_option_switch("k","ignore_checksum_errors",
103 "Ignore block checksum errors. Errors will be converted to warnings.",
104 &cfg_ignore_checksum_errors
,true,true);
106 // ar.add_option_switch("p","pause_on_checksum_error",
107 // "Wait for user input on checksum error.",
108 // &cfg_pause_on_checksum_error,true,true);
110 ar
.add_option_switch("n","ignore_unknown_block_errors",
111 "Ignore errors caused by unknown block types. Errors will be converted to warnings.",
112 &cfg_ignore_unknown_block_errors
,true,true);
114 ar
.add_option_switch("g","ignore_object_integrity_errors",
115 "Ignore errors caused by objects without proper end block. \
116 Errors will be converted to warnings.",
117 &cfg_ignore_object_integrity_errors
,true,true);
119 ar
.add_option_switch("v","verbose",
120 "Be a bit more verbose. This overrides -q.",
121 &cfg_verbose
,true,true);
123 ar
.add_option_switch("q","quiet",
124 "Be quiet. All warning messages are suppressed.",
125 &cfg_quiet
,true,true);
127 ar
.add_option_switch("V","version",
128 "Output version information and exit.",
129 &cfg_version
,false,true);
131 ar
.add_option_value("i","in_file",
132 "specify input file",
133 &cfg_infile_set
,&cfg_infile
,
134 "<input-file>",true,false);
136 ar
.add_option_value("o","out_file",
137 "Specify output file.",
138 &cfg_outfile_set
,&cfg_outfile
,
139 "<output_file>",true,true);
141 ar
.add_argument("File from where data is read",
142 &cfg_infile_set
,&cfg_infile
,
145 ar
.add_argument("File to where output is redirected",
146 &cfg_outfile_set
,&cfg_outfile
,
149 ar
.add_option_value("F","cfg_config_file",
150 "Use the specified configuration file.",
151 &cfg_config_file_set
,&cfg_config_file
,
152 "<file-name>",false,true);
155 // If there's a config file mentioned in the environment, take it!
156 char * env_ldc_config
=getenv("LDC_CONFIG");
158 if (cfg_verbose
) fprintf(stderr
,"Using config file: \"%s\"\n",env_ldc_config
);
159 if(dump_vector_fp(ar
.read_file(env_ldc_config
),stderr
)){
160 dump_vector_fp(ar
.get_help(),stderr
);
165 // Process command line first time
166 if(dump_vector_fp(ar
.read_args(argc
,args
),stderr
)){
167 dump_vector_fp(ar
.get_help(),stderr
);
172 dump_vector_fp(ar
.get_help(),stderr
);
176 // If user has a config file, use it.
177 if (cfg_config_file_set
){
179 fprintf(stderr
,"Using config file: \"%s\"\n",cfg_config_file
.c_str());
180 if(dump_vector_fp(ar
.read_file(cfg_config_file
),stderr
)){
181 dump_vector_fp(ar
.get_help(),stderr
);
185 // Process command line a second time to override values from config file.
186 if(dump_vector_fp(ar
.read_args(argc
,args
),stderr
)||cfg_do_help
){
187 dump_vector_fp(ar
.get_help(),stderr
);
192 if (cfg_infile_set
==1){
194 fprintf(stderr
,"Opening file for input: \"%s\"\n",cfg_infile
.c_str());
195 in_fd
=open(cfg_infile
.c_str(),O_RDONLY
);
197 fprintf(stderr
,"Error: could not open file \"%s\" for reading!\n",
203 if (cfg_outfile_set
==1){
205 fprintf(stderr
,"Opening file for output: \"%s\"\n",cfg_outfile
.c_str());
206 out_fd
=open(cfg_outfile
.c_str(),O_CREAT
|O_WRONLY
|O_TRUNC
,0666);
208 fprintf(stderr
,"Error: could not open file \"%s\" for writing!\n",
209 cfg_outfile
.c_str());
214 // Verbose overrides quiet:
215 if (cfg_verbose
)cfg_quiet
=0;
217 // The configuration implications according to /cfg007/
218 // if (in_fd==0) cfg_pause_on_checksum_error=0;
219 // if (cfg_pause_on_checksum_error==1) cfg_ignore_checksum_errors=1;
221 if (cfg_output_info
||cfg_output_called
||cfg_output_exported
||
222 cfg_output_unsatisfied
) cfg_list_contents
=0;