2005-05-30 22:28:29 +02:00
|
|
|
/*************
|
|
|
|
|
* com_chdir.c
|
|
|
|
|
************/
|
|
|
|
|
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/ngspice.h"
|
2000-07-07 16:06:33 +02:00
|
|
|
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/wordlist.h"
|
2000-07-07 16:06:33 +02:00
|
|
|
|
2005-05-30 22:28:29 +02:00
|
|
|
#ifdef HAVE_PWD_H
|
|
|
|
|
#include <pwd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "com_chdir.h"
|
2000-07-07 16:06:33 +02:00
|
|
|
#include "quote.h"
|
2011-12-11 19:05:00 +01:00
|
|
|
#include "ngspice/cpextern.h"
|
2000-07-07 16:06:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
com_chdir(wordlist *wl)
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
2007-10-18 21:34:30 +02:00
|
|
|
#ifdef HAVE_PWD_H
|
2000-07-07 16:06:33 +02:00
|
|
|
struct passwd *pw;
|
2007-10-18 21:34:30 +02:00
|
|
|
#endif
|
2008-01-02 19:34:03 +01:00
|
|
|
#ifdef HAVE_GETCWD
|
2000-07-07 16:06:33 +02:00
|
|
|
char localbuf[257];
|
2008-01-02 19:34:03 +01:00
|
|
|
#endif
|
2000-07-07 16:06:33 +02:00
|
|
|
int copied = 0;
|
|
|
|
|
|
|
|
|
|
s = NULL;
|
|
|
|
|
|
|
|
|
|
if (wl == NULL) {
|
|
|
|
|
|
2012-09-20 20:30:53 +02:00
|
|
|
s = getenv("HOME");
|
2000-07-07 16:06:33 +02:00
|
|
|
|
|
|
|
|
#ifdef HAVE_PWD_H
|
2012-09-20 20:30:53 +02:00
|
|
|
if (s == NULL) {
|
|
|
|
|
pw = getpwuid(getuid());
|
|
|
|
|
if (pw == NULL) {
|
|
|
|
|
fprintf(cp_err, "Can't get your password entry\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
s = pw->pw_dir;
|
|
|
|
|
}
|
2000-07-07 16:06:33 +02:00
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
s = cp_unquote(wl->wl_word);
|
2012-09-20 20:30:53 +02:00
|
|
|
copied = 1;
|
2000-07-07 16:06:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-02 13:55:53 +01:00
|
|
|
if (s != NULL)
|
2008-01-02 19:34:03 +01:00
|
|
|
if (chdir(s) == -1)
|
|
|
|
|
perror(s);
|
2000-07-07 16:06:33 +02:00
|
|
|
|
|
|
|
|
if (copied)
|
2012-09-20 20:30:53 +02:00
|
|
|
tfree(s);
|
2000-07-07 16:06:33 +02:00
|
|
|
|
|
|
|
|
#ifdef HAVE_GETCWD
|
|
|
|
|
s = getcwd(localbuf, sizeof(localbuf));
|
|
|
|
|
if (s)
|
2012-09-20 20:30:53 +02:00
|
|
|
printf("Current directory: %s\n", s);
|
2000-07-07 16:06:33 +02:00
|
|
|
else
|
2012-09-20 20:30:53 +02:00
|
|
|
fprintf(cp_err, "Can't get current working directory.\n");
|
2000-07-07 16:06:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
}
|