| 1 |
/* |
| 2 |
* Copyright(C) 1999-2025 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <cstdlib> // for exit, EXIT_SUCCESS, getenv |
| 10 |
#include <fmt/core.h> |
| 11 |
#include <iostream> // for operator<<, basic_ostream, etc |
| 12 |
#include <stdio.h> |
| 13 |
#include <string> // for char_traits, string |
| 14 |
|
| 15 |
#include "Ioss_GetLongOpt.h" |
| 16 |
#include "Ioss_Utils.h" |
| 17 |
#include "modify_interface.h" |
| 18 |
|
| 19 |
Modify::Interface::Interface() { enroll_options(); } |
| 20 |
|
| 21 |
void Modify::Interface::enroll_options() |
| 22 |
{ |
| 23 |
options_.usage("[options] basename"); |
| 24 |
|
| 25 |
options_.enroll("help", Ioss::GetLongOption::OptType::NoValue, "Print this summary and exit", |
| 26 |
nullptr); |
| 27 |
|
| 28 |
options_.enroll("db_type", Ioss::GetLongOption::OptType::MandatoryValue, |
| 29 |
"Database Type: generated" |
| 30 |
#if defined(SEACAS_HAVE_PAMGEN) |
| 31 |
", pamgen" |
| 32 |
#endif |
| 33 |
#if defined(SEACAS_HAVE_EXODUS) |
| 34 |
", exodus" |
| 35 |
#endif |
| 36 |
#if defined(SEACAS_HAVE_CGNS) |
| 37 |
", cgns" |
| 38 |
#endif |
| 39 |
#if defined(SEACAS_HAVE_DATAWAREHOUSE) |
| 40 |
", data_warehouse" |
| 41 |
#endif |
| 42 |
".", |
| 43 |
"unknown"); |
| 44 |
options_.enroll("in_type", Ioss::GetLongOption::OptType::MandatoryValue, "(alias for db_type)", |
| 45 |
nullptr, nullptr, true); |
| 46 |
|
| 47 |
options_.enroll("allow_modifications", Ioss::GetLongOption::OptType::NoValue, |
| 48 |
"By default, io_modify will only allow creation of new assemblies.\n" |
| 49 |
"\t\tIf this option is specified, then can modify assemblies that already exist " |
| 50 |
"in database.\n" |
| 51 |
"\t\tThis will cause the database to be rewritten. Without this option, it is " |
| 52 |
"updated in place.", |
| 53 |
nullptr, nullptr, true); |
| 54 |
options_.enroll("version", Ioss::GetLongOption::OptType::NoValue, "Print version and exit", |
| 55 |
nullptr); |
| 56 |
|
| 57 |
options_.enroll("copyright", Ioss::GetLongOption::OptType::NoValue, |
| 58 |
"Show copyright and license data.", nullptr); |
| 59 |
} |
| 60 |
|
| 61 |
bool Modify::Interface::parse_options(int argc, char **argv) |
| 62 |
{ |
| 63 |
// Get options from environment variable also... |
| 64 |
char *options = getenv("IO_MODIFY_OPTIONS"); |
| 65 |
if (options != nullptr) { |
| 66 |
fmt::print( |
| 67 |
stderr, |
| 68 |
"\nThe following options were specified via the IO_MODIFY_OPTIONS environment variable:\n" |
| 69 |
"\t{}\n\n", |
| 70 |
options); |
| 71 |
options_.parse(options, Ioss::GetLongOption::basename(*argv)); |
| 72 |
} |
| 73 |
|
| 74 |
int option_index = options_.parse(argc, argv); |
| 75 |
if (option_index < 1) { |
| 76 |
return false; |
| 77 |
} |
| 78 |
|
| 79 |
if (options_.retrieve("help") != nullptr) { |
| 80 |
options_.usage(std::cerr); |
| 81 |
fmt::print(stderr, "\n\tCan also set options via IO_MODIFY_OPTIONS environment variable.\n\n"); |
| 82 |
fmt::print(stderr, |
| 83 |
"\tDocumentation: " |
| 84 |
"https://sandialabs.github.io/seacas-docs/sphinx/html/index.html#io-modify\n\n"); |
| 85 |
fmt::print(stderr, "\t->->-> Send email to [email protected] for {} support.<-<-<-\n", |
| 86 |
options_.program_name()); |
| 87 |
exit(EXIT_SUCCESS); |
| 88 |
} |
| 89 |
|
| 90 |
if (options_.retrieve("version") != nullptr) { |
| 91 |
// Version is printed up front, just exit... |
| 92 |
exit(0); |
| 93 |
} |
| 94 |
|
| 95 |
allowModification_ = options_.retrieve("allow_modifications") != nullptr; |
| 96 |
filetype_ = options_.get_option_value("db_type", filetype_); |
| 97 |
|
| 98 |
if (options_.retrieve("copyright") != nullptr) { |
| 99 |
Ioss::Utils::copyright(std::cerr, "2020-2022"); |
| 100 |
exit(EXIT_SUCCESS); |
| 101 |
} |
| 102 |
|
| 103 |
// Parse remaining options as directory paths. |
| 104 |
if (option_index < argc) { |
| 105 |
filename_ = argv[option_index]; |
| 106 |
} |
| 107 |
else { |
| 108 |
fmt::print(stderr, "\nERROR: filename not specified\n\n"); |
| 109 |
return false; |
| 110 |
} |
| 111 |
|
| 112 |
if (filetype_ == "unknown") { |
| 113 |
filetype_ = Ioss::Utils::get_type_from_file(filename_); |
| 114 |
} |
| 115 |
|
| 116 |
return true; |
| 117 |
} |