Jspice3
exec.c File Reference
#include "spice.h"
#include "cpdefs.h"
#include "scedio.h"
Include dependency graph for exec.c:

Go to the source code of this file.

Macros

#define SHORT_SCEDIO
 

Functions

bool tryexec (char *name, argv)
 
bool is_exec (char *file, char *dir)
 

Macro Definition Documentation

#define SHORT_SCEDIO

Definition at line 10 of file exec.c.

Function Documentation

bool is_exec ( char *  file,
char *  dir 
)

Definition at line 79 of file exec.c.

83 {
84 #ifdef MSDOS
85  char *c;
86 
87  if ((c = index(file,'.')) == NULL)
88  return (false);
89  *c = '\0';
90  c++;
91  if (!cieq(c,"exe") && !cieq(c,"com") && !cieq(c,"bat"))
92  return (false);
93 #else
94  char buf[BSIZE_SP];
95 #ifdef HAVE_STAT
96  struct stat stbuf;
97 
98  (void)sprintf(buf,"%s%c%s",dir,DIR_TERM,file);
99  if (stat(buf,&stbuf) < 0)
100  return (false);
101  if (!(stbuf.st_mode & S_IFREG) || !(stbuf.st_mode & S_IXUSR))
102  return (false);
103 #else
104  (void)sprintf(buf,"%s%c%s",dir,DIR_TERM,file);
105  if (access(buf,1))
106  return (false);
107 #endif
108 #endif
109  return (true);
110 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
int cieq()
#define NULL
Definition: spdefs.h:121
int access(char *pth, int m)
Definition: libfuncs.c:75
static double c
Definition: vectors.c:16
char * index(char *s, char c) const
Definition: string.c:294
bool tryexec ( char *  name,
argv   
)

Definition at line 24 of file exec.c.

29 {
30 #ifdef HAVE_FORK
31  int status;
32  int pid, j;
33  RETSIGTYPE (*svint)( ), (*svquit)( ), (*svtstp)( );
34 
35  pid = fork( );
36  if (pid == 0) {
38  (void) execv(name, argv);
39  (void) _exit(120); /* A random value. */
40  /* NOTREACHED */
41  }
42  else {
43  svint = signal(SIGINT, SIG_DFL);
44  svquit = signal(SIGQUIT, SIG_DFL);
45  svtstp = signal(SIGTSTP, SIG_DFL);
46  do {
47  j = wait(&status);
48  } while (j != pid);
49  (void) signal(SIGINT, svint);
50  (void) signal(SIGQUIT, svquit);
51  (void) signal(SIGTSTP, svtstp);
52  }
53  if (WIFEXITED(status) && WEXITSTATUS(status) == 120)
54  return (false);
55  return (true);
56 #else
57  char *s;
58  wordlist *wl;
59 
60  argv++;
61  wl = alloc(wordlist);
62  wl->wl_word = copy(name);
63  if (*argv) {
64  wl->wl_next = wl_build(argv);
65  wl->wl_next->wl_prev = wl;
66  }
67  s = wl_flatten(wl);
68  wl_free(wl);
69  (void) system(s);
70  putc('\n',stdout);
71  tfree(s);
72  return (true);
73 
74 #endif
75 }
Definition: cddefs.h:119
int system(char *str)
Definition: libfuncs.c:85
Definition: library.c:18
#define alloc(type)
Definition: cdmacs.h:21
char * copy()
void wl_free()
struct wordlist * wl_prev
Definition: cpstd.h:24
void cp_fixdescriptors()
Definition: cshpar.c:454
#define tfree(x)
Definition: cdmacs.h:22
wordlist * wl_build()
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
char * wl_flatten()