5 changed files with 168 additions and 343 deletions
-
58src/frontend/com_chdir.c
-
28src/frontend/com_echo.c
-
24src/frontend/com_rehash.c
-
58src/frontend/com_shell.c
-
343src/parser/cshpar.c
@ -0,0 +1,58 @@ |
|||||
|
#include <config.h> |
||||
|
#include <ngspice.h> |
||||
|
|
||||
|
#include <wordlist.h> |
||||
|
|
||||
|
#include "quote.h" |
||||
|
#include "streams.h" |
||||
|
|
||||
|
|
||||
|
void |
||||
|
com_chdir(wordlist *wl) |
||||
|
{ |
||||
|
char *s; |
||||
|
struct passwd *pw; |
||||
|
extern struct passwd *getpwuid(uid_t); |
||||
|
char localbuf[257]; |
||||
|
int copied = 0; |
||||
|
|
||||
|
s = NULL; |
||||
|
|
||||
|
if (wl == NULL) { |
||||
|
|
||||
|
s = getenv("HOME"); |
||||
|
|
||||
|
#ifdef HAVE_PWD_H |
||||
|
if (s == NULL) { |
||||
|
pw = getpwuid(getuid()); |
||||
|
if (pw == NULL) { |
||||
|
fprintf(cp_err, "Can't get your password entry\n"); |
||||
|
return; |
||||
|
} |
||||
|
s = pw->pw_dir; |
||||
|
} |
||||
|
#endif |
||||
|
} else { |
||||
|
s = cp_unquote(wl->wl_word); |
||||
|
copied = 1; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
if (*s && chdir(s) == -1) |
||||
|
perror(s); |
||||
|
|
||||
|
if (copied) |
||||
|
tfree(s); |
||||
|
|
||||
|
#ifdef HAVE_GETCWD |
||||
|
s = getcwd(localbuf, sizeof(localbuf)); |
||||
|
if (s) |
||||
|
printf("Current directory: %s\n", s); |
||||
|
else |
||||
|
fprintf(cp_err, "Can't get current working directory.\n"); |
||||
|
#endif |
||||
|
|
||||
|
return; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
#include <config.h> |
||||
|
#include <ngspice.h> |
||||
|
#include <wordlist.h> |
||||
|
#include <bool.h> |
||||
|
|
||||
|
#include "quote.h" |
||||
|
#include "streams.h" |
||||
|
|
||||
|
void |
||||
|
com_echo(wordlist *wlist) |
||||
|
{ |
||||
|
bool nl = TRUE; |
||||
|
|
||||
|
if (wlist && eq(wlist->wl_word, "-n")) { |
||||
|
wlist = wlist->wl_next; |
||||
|
nl = FALSE; |
||||
|
} |
||||
|
|
||||
|
while (wlist) { |
||||
|
fputs(cp_unquote(wlist->wl_word), cp_out); |
||||
|
if (wlist->wl_next) |
||||
|
fputs(" ", cp_out); |
||||
|
wlist = wlist->wl_next; |
||||
|
} |
||||
|
if (nl) |
||||
|
fputs("\n", cp_out); |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,24 @@ |
|||||
|
#include <config.h> |
||||
|
#include <ngspice.h> |
||||
|
|
||||
|
#include <wordlist.h> |
||||
|
#include <cpextern.h> |
||||
|
|
||||
|
|
||||
|
void |
||||
|
com_rehash(wordlist *wl) |
||||
|
{ |
||||
|
char *s; |
||||
|
|
||||
|
if (!cp_dounixcom) { |
||||
|
fprintf(cp_err, "Error: unixcom not set.\n"); |
||||
|
return; |
||||
|
} |
||||
|
s = getenv("PATH"); |
||||
|
if (s) |
||||
|
cp_rehash(s, TRUE); |
||||
|
else |
||||
|
fprintf(cp_err, "Error: no PATH in environment.\n"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,58 @@ |
|||||
|
#include <config.h> |
||||
|
#include <ngspice.h> |
||||
|
#include <wordlist.h> |
||||
|
|
||||
|
#include <cpextern.h> |
||||
|
|
||||
|
|
||||
|
/* Fork a shell. */ |
||||
|
|
||||
|
void |
||||
|
com_shell(wordlist *wl) |
||||
|
{ |
||||
|
char *com, *shell = NULL; |
||||
|
|
||||
|
shell = getenv("SHELL"); |
||||
|
if (shell == NULL) |
||||
|
shell = "/bin/csh"; |
||||
|
|
||||
|
cp_ccon(FALSE); |
||||
|
|
||||
|
#ifdef HAVE_VFORK_H |
||||
|
/* XXX Needs to switch process groups. Also, worry about suspend */ |
||||
|
/* Only bother for efficiency */ |
||||
|
pid = vfork(); |
||||
|
if (pid == 0) { |
||||
|
fixdescriptors(); |
||||
|
if (wl == NULL) { |
||||
|
execl(shell, shell, 0); |
||||
|
_exit(99); |
||||
|
} else { |
||||
|
com = wl_flatten(wl); |
||||
|
execl("/bin/sh", "sh", "-c", com, 0); |
||||
|
} |
||||
|
} else { |
||||
|
/* XXX Better have all these signals */ |
||||
|
svint = signal(SIGINT, SIG_DFL); |
||||
|
svquit = signal(SIGQUIT, SIG_DFL); |
||||
|
svtstp = signal(SIGTSTP, SIG_DFL); |
||||
|
/* XXX Sig on proc group */ |
||||
|
do { |
||||
|
r = wait((union wait *) NULL); |
||||
|
} while ((r != pid) && pid != -1); |
||||
|
signal(SIGINT, (SIGNAL_FUNCTION) svint); |
||||
|
signal(SIGQUIT, (SIGNAL_FUNCTION) svquit); |
||||
|
signal(SIGTSTP, (SIGNAL_FUNCTION) svtstp); |
||||
|
} |
||||
|
#else |
||||
|
/* Easier to forget about changing the io descriptors. */ |
||||
|
if (wl) { |
||||
|
com = wl_flatten(wl); |
||||
|
system(com); |
||||
|
} else |
||||
|
system(shell); |
||||
|
#endif |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue