From 3ddc4b986a8d595b88e93ea935e6cd333f1b3357 Mon Sep 17 00:00:00 2001 From: Jim Monte Date: Tue, 17 Dec 2019 01:44:36 -0500 Subject: [PATCH] Modified search for init file so that it searches both and if both are defined. --- src/main.c | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index f452ecb3a..92e627f81 100644 --- a/src/main.c +++ b/src/main.c @@ -1143,24 +1143,39 @@ int main(int argc, char **argv) /* load user's initialisation file try accessing the initialisation file in the current directory if that fails try the alternate name */ - if (FALSE == read_initialisation_file("", INITSTR) && - FALSE == read_initialisation_file("", ALT_INITSTR)) { - /* if that failed try in the user's home directory - if their HOME environment variable is set */ - char *homedir = getenv("HOME"); - if (homedir == (char *) NULL) { /* no HOME env variable */ - /* If there is no HOME environment (e.g. MS Windows), - * try user's profile directory */ - homedir = getenv("USERPROFILE"); + do { + if (read_initialisation_file("", INITSTR) != FALSE) { + break; + } + if (read_initialisation_file("", ALT_INITSTR) != FALSE) { + break; } - if (homedir) { /* Found a home location */ - if (FALSE == read_initialisation_file(homedir, INITSTR)) { - (void) read_initialisation_file(homedir, ALT_INITSTR); + { + const char * const home = getenv("HOME"); + if (home) { + if (read_initialisation_file(home, INITSTR) != FALSE) { + break; + } + if (read_initialisation_file(home, ALT_INITSTR) != FALSE) { + break; + } } } - } /* end of case init file not found in current directory */ - } /* end of case that init file is to be read */ + + { + const char * const usr = getenv("USERPROFILE"); + if (usr) { + if (read_initialisation_file(usr, INITSTR) != FALSE) { + break; + } + if (read_initialisation_file(usr, ALT_INITSTR) != FALSE) { + break; + } + } + } + } while (0); + } /* end of case that init file is read */ if (!ft_batchmode) { com_version(NULL);