Jspice3
unixcom.c File Reference
#include "spice.h"
#include "cpdefs.h"
#include "scedio.h"
#include <sys/types.h>
Include dependency graph for unixcom.c:

Go to the source code of this file.

Macros

#define SHORT_SCEDIO
 

Functions

static void upd_hash ()
 
static void add_dir ()
 
void cp_rehash (char *pathlist, bool docc)
 
static void upd_hash (bool docc)
 
bool cp_unixcom (wordlist *wl)
 
static void add_dir (char *dir, bool docc, void **htab)
 
void cp_hstat ()
 

Variables

static void * hashtabp
 
static void * hashtabc
 
static void * hashtabs
 
static char * dirbuffer
 
static int dirlength
 
static int dirpos
 

Macro Definition Documentation

#define SHORT_SCEDIO

Definition at line 14 of file unixcom.c.

Function Documentation

static void add_dir ( )
static
static void add_dir ( char *  dir,
bool  docc,
void **  htab 
)
static

Definition at line 186 of file unixcom.c.

191 {
192  DIR *wdir;
193  struct direct *de;
194 
195  if (*htab == NULL)
196  *htab = htab_init();
197 
198  if (!(wdir = opendir(dir))) return;
199  while (de = readdir(wdir)) {
200  if (!is_exec(de->d_name,dir))
201  continue;
202  htab_add(de->d_name,(void*)copy(dir),*htab);
203  if (docc) {
204  /* Add to completion hash table. */
205  cp_addcomm(de->d_name,0L,0L,0L,0L);
206  }
207  }
208  closedir(wdir);
209 }
#define L
Definition: parse.c:442
char * copy()
bool is_exec(char *file, char *dir)
Definition: exec.c:79
void * htab_init()
Definition: hash.c:27
#define NULL
Definition: spdefs.h:121
void htab_add()
void cp_addcomm()
void cp_hstat ( )

Definition at line 215 of file unixcom.c.

216 {
217  htab_print(hashtabp,"i = %d, name = %s, path = %s\n");
218  htab_print(hashtabc,"i = %d, name = %s, path = %s\n");
219  htab_print(hashtabs,"i = %d, name = %s, path = %s\n");
220 }
static void * hashtabs
Definition: unixcom.c:39
static void * hashtabp
Definition: unixcom.c:37
static void * hashtabc
Definition: unixcom.c:38
void htab_print()
void cp_rehash ( char *  pathlist,
bool  docc 
)

Definition at line 50 of file unixcom.c.

54 {
55  int i, tabp;
56  char buf[BSIZE_SP];
57 
58  if (!pathlist) {
59  /* called from the cd command */
60  upd_hash(docc);
61  return;
62  }
63 
64  /* Clear out the old hash table. */
65  htab_free(hashtabp,true);
66  htab_free(hashtabc,true);
67  htab_free(hashtabs,true);
68 
69  if (docc) {
70  struct comm *c;
71  cp_ccrestart(false);
72  for (c = cp_coms; c->co_func; c++)
74  c->co_cctypes[1], c->co_cctypes[2],c->co_cctypes[3]);
75  }
76 
77  tabp = 0;
78  while (pathlist && *pathlist) {
79  i = 0;
80  while (*pathlist && *pathlist != ';' && *pathlist != ':')
81  buf[i++] = *pathlist++;
82  while (*pathlist == ';' || *pathlist == ':')
83  pathlist++;
84  buf[i] = '\0';
85  if (!strcmp(buf,".")) {
86  if (tabp)
87  continue;
88  tabp++;
89  }
90  if (tabp == 0)
91  add_dir(buf,docc,&hashtabp);
92  else if (tabp == 1) {
93  add_dir(buf,docc,&hashtabc);
94  tabp++;
95  }
96  else
97  add_dir(buf,docc,&hashtabs);
98  }
99  return;
100 }
static char buf[MAXPROMPT]
Definition: arg.c:18
static void add_dir()
#define BSIZE_SP
Definition: misc.h:19
static void * hashtabs
Definition: unixcom.c:39
struct comm * cp_coms
Definition: main.c:163
Definition: cpdefs.h:20
static void * hashtabp
Definition: unixcom.c:37
static void upd_hash()
static void * hashtabc
Definition: unixcom.c:38
void htab_free()
static double c
Definition: vectors.c:16
void cp_ccrestart()
void(* co_func)()
Definition: cpdefs.h:22
void cp_addcomm()
char * co_comname
Definition: cpdefs.h:21
long co_cctypes[4]
Definition: cpdefs.h:26
bool cp_unixcom ( wordlist wl)

Definition at line 128 of file unixcom.c.

132 {
133  int i;
134  bool ret;
135  char *name;
136  char *path;
137  char **argv;
138  char buf[BSIZE_SP];
139 
140  if (SCEDactive()) {
141  ShowPrompt("Can't do this from sced.");
142  return (true);
143  }
144 
145  if (!wl)
146  return (false);
147  name = wl->wl_word;
148  argv = wl_mkvec(wl);
149  if (cp_debug) {
150  printf("name: %s, argv: ", name);
151  wl_print(wl, stdout);
152  printf("\n");
153  }
154  if (strchr(name, DIR_TERM)) {
155  ret = tryexec(name, argv);
156  goto end;
157  }
158  path = (char*) htab_get(name,hashtabp);
159  if (path) {
160  (void) sprintf(buf,"%s%c%s",path,DIR_TERM,name);
161  ret = tryexec(buf, argv);
162  goto end;
163  }
164  path = (char*) htab_get(name,hashtabc);
165  if (path) {
166  (void) sprintf(buf,"%s",name);
167  ret = tryexec(buf, argv);
168  goto end;
169  }
170  path = (char*) htab_get(name,hashtabs);
171  if (path) {
172  (void) sprintf(buf,"%s%c%s",path,DIR_TERM,name);
173  ret = tryexec(buf, argv);
174  goto end;
175  }
176  ret = false;
177 end:
178  for (i = 0; argv[i]; i++)
179  tfree(argv[i]);
180  tfree(argv);
181  return (ret);
182 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
void wl_print()
static void * hashtabs
Definition: unixcom.c:39
static void * hashtabp
Definition: unixcom.c:37
static void * hashtabc
Definition: unixcom.c:38
char ** wl_mkvec()
#define tfree(x)
Definition: cdmacs.h:22
bool tryexec(char *name, argv)
Definition: exec.c:24
void * htab_get()
char * wl_word
Definition: cpstd.h:22
enum Active SCEDactive()
Definition: scedstub.c:63
static char * path
Definition: paths.c:13
bool cp_debug
Definition: cshpar.c:61
void ShowPrompt(char *str)
Definition: scedstub.c:71
static void upd_hash ( )
static
static void upd_hash ( bool  docc)
static

Definition at line 104 of file unixcom.c.

108 {
109  wordlist *wl, *wl0;
110 
111  wl0 = wl = (wordlist*)htab_wl(hashtabc);
112  while (wl) {
113  if (!htab_get(wl->wl_word,hashtabp) &&
114  !htab_get(wl->wl_word,hashtabs)) {
115  cp_remcomm(wl->wl_word);
116  }
117  wl = wl->wl_next;
118  }
119  wl_free(wl0);
120 
121  htab_free(hashtabc,true);
122  hashtabc = (void*)NULL;
123  add_dir(".",docc,&hashtabc);
124 }
static void add_dir()
static void * hashtabs
Definition: unixcom.c:39
Definition: library.c:18
void * htab_wl()
static void * hashtabp
Definition: unixcom.c:37
void wl_free()
static void * hashtabc
Definition: unixcom.c:38
void htab_free()
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
void * htab_get()
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
void cp_remcomm()

Variable Documentation

char* dirbuffer
static

Definition at line 40 of file unixcom.c.

int dirlength
static

Definition at line 41 of file unixcom.c.

int dirpos
static

Definition at line 41 of file unixcom.c.

void* hashtabc
static

Definition at line 38 of file unixcom.c.

void* hashtabp
static

Definition at line 37 of file unixcom.c.

void* hashtabs
static

Definition at line 39 of file unixcom.c.