@@ -88,7 +88,8 @@ sp_process_stream(const std::string& filename, std::istream& is)
8888
8989// ! define identifiers for command line arguments
9090enum { OPT_HELP, OPT_VERBOSE, OPT_FILETYPE,
91- OPT_OUTPUT, OPT_CHECK_OUTPUT, OPT_DATABASE, OPT_RANGE };
91+ OPT_OUTPUT, OPT_CHECK_OUTPUT, OPT_DATABASE, OPT_RANGE,
92+ OPT_WORK_DIR };
9293
9394// ! define command line arguments
9495static CSimpleOpt::SOption sopt_list[] = {
@@ -100,6 +101,7 @@ static CSimpleOpt::SOption sopt_list[] = {
100101 { OPT_CHECK_OUTPUT, " -C" , SO_NONE },
101102 { OPT_DATABASE, " -D" , SO_REQ_SEP },
102103 { OPT_RANGE, " -R" , SO_REQ_SEP },
104+ { OPT_WORK_DIR, " -W" , SO_REQ_SEP },
103105 SO_END_OF_OPTIONS
104106};
105107
@@ -116,7 +118,8 @@ sp_process_usage(const std::string& progname)
116118 " -o <file> Output all processed files to this stream." << std::endl <<
117119 " -C Verify that -o output file matches processed data (for tests)." << std::endl <<
118120 " -D <type> Select SQL database type and file or database." << std::endl <<
119- " -R <name> Process only named RANGE in files." << std::endl);
121+ " -R <name> Process only named RANGE in files." << std::endl <<
122+ " -W <dir> Change working directory at start-up." << std::endl);
120123
121124 return EXIT_FAILURE;
122125}
@@ -131,6 +134,9 @@ sp_process(int argc, char* argv[])
131134 // database connection to establish
132135 std::string opt_db_conninfo;
133136
137+ // working directory
138+ std::string opt_work_dir;
139+
134140 // ! parse command line parameters using SimpleOpt
135141 CSimpleOpt args (argc, argv, sopt_list);
136142
@@ -169,9 +175,18 @@ sp_process(int argc, char* argv[])
169175 case OPT_RANGE:
170176 gopt_ranges.push_back (args.OptionArg ());
171177 break ;
178+
179+ case OPT_WORK_DIR:
180+ opt_work_dir = args.OptionArg ();
181+ break ;
172182 }
173183 }
174184
185+ if (!opt_work_dir.empty ()) {
186+ if (chdir (opt_work_dir.c_str ()) != 0 )
187+ OUT_THROW (" Error chdir() to work directory: " << strerror (errno));
188+ }
189+
175190 // make connection to the database
176191 if (!g_db_connect (opt_db_conninfo))
177192 OUT_THROW (" Fatal: could not connect to a SQL database" );
0 commit comments