1 /******************************************************************************
5 * $Date: 2007/12/23 15:25:11 $
9 * Revision 2.1 2007/12/23 15:25:11 hachti
10 * *** empty log message ***
12 * Revision 2.0 2007-03-26 01:00:38 hachti
13 * *** empty log message ***
16 ******************************************************************************/
19 * Program configuration management
27 #include <sys/types.h>
31 #include "configuration_manager.hh"
34 /* Global configuration data */
38 int cfg_outfile_set
=0;
39 int cfg_config_file_set
=0;
42 int cfg_output_info
=0;
43 int cfg_output_called
=0;
44 int cfg_output_exported
=0;
45 int cfg_output_unsatisfied
=0;
46 int cfg_split_objects
=0;
47 int cfg_split_objects_numbered
=0;
48 int cfg_split_blocks
=0;
49 int cfg_ignore_block_errors
=0;
50 int cfg_ignore_checksum_errors
=0;
51 //int cfg_pause_on_checksum_error=0;
52 int cfg_ignore_unknown_block_errors
=0;
53 int cfg_ignore_object_integrity_errors
=0;
54 int cfg_list_contents
=1;
57 int cfg_dump_block_contents
=0;
61 int in_fd
=0; //! File descriptor for data input
62 int out_fd
=1; //! File descriptor for text output
64 void do_config(int argc
, char ** args
){
66 string cfg_config_file
;
67 configuration_manager
ar("ldc2");
69 /* Here come the configuration switches */
70 ar
.add_option_switch("h","help",
71 "Output this help text and exit.",
72 &cfg_do_help
,false,true);
74 ar
.add_option_switch("a","output_info",
75 "Print tape data information",
76 &cfg_output_info
,true,true);
78 ar
.add_option_switch("c","output_called",
79 "Print all called symbols from the object(s).",
80 &cfg_output_called
,true,true);
82 ar
.add_option_switch("d","dump_block_contents",
83 "Dump block contents",
84 &cfg_dump_block_contents
,true,true);
86 ar
.add_option_switch("e","output_exported",
87 "Print all exported symbols from the object(s).",
88 &cfg_output_exported
,true,true);
90 ar
.add_option_switch("u","output_unsatisfied",
91 "List all unsatisfied symbols.",
92 &cfg_output_unsatisfied
,true,true);
94 ar
.add_option_switch("s","split_objects",
95 "Split input data into distinct object files.",
96 &cfg_split_objects
,true,true);
98 ar
.add_option_switch("S","split_objects_numbered",
99 "Split input data into distinct numbered files",
100 &cfg_split_objects_numbered
,true,true);
102 ar
.add_option_switch("B","split_blocks",
103 "Split tape into named and numbered block files",
104 &cfg_split_blocks
,true,true);
106 ar
.add_option_switch("b","ignore_block_errors",
107 "Ignore block integrity errors. This will output broken blocks,too",
108 &cfg_ignore_block_errors
,true,true);
110 ar
.add_option_switch("k","ignore_checksum_errors",
111 "Ignore block checksum errors. Errors will be converted to warnings.",
112 &cfg_ignore_checksum_errors
,true,true);
114 // ar.add_option_switch("p","pause_on_checksum_error",
115 // "Wait for user input on checksum error.",
116 // &cfg_pause_on_checksum_error,true,true);
118 ar
.add_option_switch("n","ignore_unknown_block_errors",
119 "Ignore errors caused by unknown block types. Errors will be converted to warnings.",
120 &cfg_ignore_unknown_block_errors
,true,true);
122 ar
.add_option_switch("g","ignore_object_integrity_errors",
123 "Ignore errors caused by objects without proper end block. \
124 Errors will be converted to warnings.",
125 &cfg_ignore_object_integrity_errors
,true,true);
127 ar
.add_option_switch("v","verbose",
128 "Be a bit more verbose. This overrides -q.",
129 &cfg_verbose
,true,true);
131 ar
.add_option_switch("q","quiet",
132 "Be quiet. All warning messages are suppressed.",
133 &cfg_quiet
,true,true);
135 ar
.add_option_switch("V","version",
136 "Output version information and exit.",
137 &cfg_version
,false,true);
139 ar
.add_option_value("i","in_file",
140 "specify input file",
141 &cfg_infile_set
,&cfg_infile
,
142 "<input-file>",true,false);
144 ar
.add_option_value("o","out_file",
145 "Specify output file.",
146 &cfg_outfile_set
,&cfg_outfile
,
147 "<output_file>",true,true);
149 ar
.add_argument("File from where data is read",
150 &cfg_infile_set
,&cfg_infile
,
153 ar
.add_argument("File to where output is redirected",
154 &cfg_outfile_set
,&cfg_outfile
,
157 ar
.add_option_value("F","cfg_config_file",
158 "Use the specified configuration file.",
159 &cfg_config_file_set
,&cfg_config_file
,
160 "<file-name>",false,true);
163 // If there's a config file mentioned in the environment, take it!
164 char * env_ldc_config
=getenv("LDC_CONFIG");
166 if (cfg_verbose
) fprintf(stderr
,"Using config file: \"%s\"\n",env_ldc_config
);
167 if(dump_vector_fp(ar
.read_file(env_ldc_config
),stderr
)){
168 dump_vector_fp(ar
.get_help(),stderr
);
173 // Process command line first time
174 if(dump_vector_fp(ar
.read_args(argc
,args
),stderr
)){
175 dump_vector_fp(ar
.get_help(),stderr
);
180 dump_vector_fp(ar
.get_help(),stderr
);
184 // If user has a config file, use it.
185 if (cfg_config_file_set
){
187 fprintf(stderr
,"Using config file: \"%s\"\n",cfg_config_file
.c_str());
188 if(dump_vector_fp(ar
.read_file(cfg_config_file
),stderr
)){
189 dump_vector_fp(ar
.get_help(),stderr
);
193 // Process command line a second time to override values from config file.
194 if(dump_vector_fp(ar
.read_args(argc
,args
),stderr
)||cfg_do_help
){
195 dump_vector_fp(ar
.get_help(),stderr
);
200 if (cfg_infile_set
==1){
202 fprintf(stderr
,"Opening file for input: \"%s\"\n",cfg_infile
.c_str());
203 in_fd
=open(cfg_infile
.c_str(),O_RDONLY
);
205 fprintf(stderr
,"Error: could not open file \"%s\" for reading!\n",
211 if (cfg_outfile_set
==1){
213 fprintf(stderr
,"Opening file for output: \"%s\"\n",cfg_outfile
.c_str());
214 out_fd
=open(cfg_outfile
.c_str(),O_CREAT
|O_WRONLY
|O_TRUNC
,0666);
216 fprintf(stderr
,"Error: could not open file \"%s\" for writing!\n",
217 cfg_outfile
.c_str());
222 // Verbose overrides quiet:
223 if (cfg_verbose
)cfg_quiet
=0;
225 // The configuration implications according to /cfg007/
226 // if (in_fd==0) cfg_pause_on_checksum_error=0;
227 // if (cfg_pause_on_checksum_error==1) cfg_ignore_checksum_errors=1;
229 if (cfg_output_info
||cfg_output_called
||cfg_output_exported
||
230 cfg_output_unsatisfied
) cfg_list_contents
=0;