softIoc re-add -D

This commit is contained in:
Michael Davidsaver
2019-11-22 21:05:13 -08:00
parent 90ef40e62b
commit a7cb9524c2

View File

@@ -96,10 +96,11 @@ void errIf(int ret, const std::string& msg)
throw std::runtime_error(msg);
}
bool lazy_dbd_loaded;
void lazy_dbd(const std::string& dbd_file) {
static bool loaded;
if(loaded) return;
loaded = true;
if(lazy_dbd_loaded) return;
lazy_dbd_loaded = true;
errIf(dbLoadDatabase(dbd_file.c_str(), NULL, NULL),
std::string("Failed to load DBD file: ")+dbd_file);
@@ -142,7 +143,7 @@ int main(int argc, char *argv[])
int opt;
while ((opt = getopt(argc, argv, "ha:d:m:Ssx:")) != -1) {
while ((opt = getopt(argc, argv, "ha:D:d:m:Ssx:")) != -1) {
switch (opt) {
case 'h': /* Print usage */
usage(argv[0], dbd_file);
@@ -164,6 +165,12 @@ int main(int argc, char *argv[])
throw std::bad_alloc();
std::cout<<"asSetFilename(\""<<optarg<<"\")\n";
break;
case 'D':
if(lazy_dbd_loaded) {
throw std::runtime_error("-D specified too late. softIoc.dbd already loaded.\n");
}
dbd_file = optarg;
break;
case 'd':
lazy_dbd(dbd_file);
errIf(dbLoadRecords(optarg, macros.c_str()),