diff --git a/src/frontend/com_chdir.c b/src/frontend/com_chdir.c index 4d33f4432..4beee8860 100644 --- a/src/frontend/com_chdir.c +++ b/src/frontend/com_chdir.c @@ -32,6 +32,8 @@ com_chdir(wordlist *wl) if (wl == NULL) { s = getenv("HOME"); + if (!s) + s = getenv("USERPROFILE"); #ifdef HAVE_PWD_H if (s == NULL) { @@ -65,3 +67,21 @@ com_chdir(wordlist *wl) #endif } + +/* just print the current working directory */ +void +com_getcwd(wordlist *wl) +{ + NG_IGNORE(wl); +#ifdef HAVE_GETCWD + char *s; + char localbuf[257]; + s = getcwd(localbuf, sizeof(localbuf)); + if (s) + printf("Current directory: %s\n", s); + else + fprintf(cp_err, "Can't get current working directory.\n"); +#else + fprintf(cp_err, "Error, function getcwd not available\n"); +#endif +} diff --git a/src/frontend/com_chdir.h b/src/frontend/com_chdir.h index ae3476667..527c6e474 100644 --- a/src/frontend/com_chdir.h +++ b/src/frontend/com_chdir.h @@ -8,5 +8,6 @@ #include "ngspice/wordlist.h" void com_chdir(wordlist *wl); +void com_getcwd(wordlist *wl); #endif diff --git a/src/frontend/commands.c b/src/frontend/commands.c index 69f539193..f180aeec5 100644 --- a/src/frontend/commands.c +++ b/src/frontend/commands.c @@ -511,6 +511,10 @@ struct comm spcp_coms[] = { { 1, 0, 0, 0 }, E_DEFHMASK, 0, 1, NULL, "[directory] : Change working directory." } , + { "getcwd", com_getcwd, FALSE, FALSE, + { 1, 0, 0, 0 }, E_DEFHMASK, 0, 1, + NULL, + "[directory] : Print current working directory." } , { "version", com_version, FALSE, FALSE, { 0, 0, 0, 0 }, E_DEFHMASK, 0, LOTS, NULL, @@ -920,6 +924,10 @@ struct comm nutcp_coms[] = { { 1, 0, 0, 0 }, E_DEFHMASK, 0, 1, NULL, "[directory] : Change working directory." } , + { "getcwd", com_getcwd, FALSE, FALSE, + { 1, 0, 0, 0 }, E_DEFHMASK, 0, 1, + NULL, + "[directory] : Print current working directory." } , { "version", com_version, FALSE, FALSE, { 0, 0, 0, 0 }, E_DEFHMASK, 0, LOTS, NULL,