Browse Source

Command 'cd' now switches to the home directory also for MS Windows.

A new command 'getcwd' just prints the current working directory
without changing it.
pre-master-46
Holger Vogt 8 years ago
parent
commit
f07c73b6a5
  1. 20
      src/frontend/com_chdir.c
  2. 1
      src/frontend/com_chdir.h
  3. 8
      src/frontend/commands.c

20
src/frontend/com_chdir.c

@ -32,6 +32,8 @@ com_chdir(wordlist *wl)
if (wl == NULL) { if (wl == NULL) {
s = getenv("HOME"); s = getenv("HOME");
if (!s)
s = getenv("USERPROFILE");
#ifdef HAVE_PWD_H #ifdef HAVE_PWD_H
if (s == NULL) { if (s == NULL) {
@ -65,3 +67,21 @@ com_chdir(wordlist *wl)
#endif #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
}

1
src/frontend/com_chdir.h

@ -8,5 +8,6 @@
#include "ngspice/wordlist.h" #include "ngspice/wordlist.h"
void com_chdir(wordlist *wl); void com_chdir(wordlist *wl);
void com_getcwd(wordlist *wl);
#endif #endif

8
src/frontend/commands.c

@ -511,6 +511,10 @@ struct comm spcp_coms[] = {
{ 1, 0, 0, 0 }, E_DEFHMASK, 0, 1, { 1, 0, 0, 0 }, E_DEFHMASK, 0, 1,
NULL, NULL,
"[directory] : Change working directory." } , "[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, { "version", com_version, FALSE, FALSE,
{ 0, 0, 0, 0 }, E_DEFHMASK, 0, LOTS, { 0, 0, 0, 0 }, E_DEFHMASK, 0, LOTS,
NULL, NULL,
@ -920,6 +924,10 @@ struct comm nutcp_coms[] = {
{ 1, 0, 0, 0 }, E_DEFHMASK, 0, 1, { 1, 0, 0, 0 }, E_DEFHMASK, 0, 1,
NULL, NULL,
"[directory] : Change working directory." } , "[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, { "version", com_version, FALSE, FALSE,
{ 0, 0, 0, 0 }, E_DEFHMASK, 0, LOTS, { 0, 0, 0, 0 }, E_DEFHMASK, 0, LOTS,
NULL, NULL,

Loading…
Cancel
Save