adapt behavior of lammps-shell when passing filename without -in/-i flag

To better handle the case of file association. We now split the path into
a directory and basename string and change the current working directory
to that directory and read the file with the basename.
This simplifies the .desktop file and makes the LAMMPS shell behave as
expected on Windows, too.
This commit is contained in:
Axel Kohlmeyer
2020-10-23 20:42:24 -04:00
parent b931501711
commit 1382559dbe
2 changed files with 7 additions and 5 deletions

View File

@ -719,10 +719,12 @@ int main(int argc, char **argv)
// handle the special case where the first argument is not a flag but a file
// this happens for example when using file type associations on Windows.
// in this case we save the pointer and remove it from argv.
char *input_file = nullptr;
// we also get the directory name and switch to that folder
std::string input_file;
if ((argc > 1) && (argv[1][0] != '-')) {
--argc;
input_file = argv[1];
input_file = utils::path_basename(argv[1]);
chdir(utils::path_dirname(input_file).c_str());
for (int i = 1; i < argc; ++i) argv[i] = argv[i+1];
}
@ -733,8 +735,8 @@ int main(int argc, char **argv)
init_commands();
// pre-load an input file that was provided on the command line
if (input_file) {
lammps_file(lmp, input_file);
if (!input_file.empty()) {
lammps_file(lmp, input_file.c_str());
} else {
for (int i = 0; i < argc; ++i) {
if ((strcmp(argv[i], "-in") == 0) || (strcmp(argv[i], "-i") == 0)) {