Jspice3
dir.c File Reference
#include "spice.h"
#include "sced.h"
#include "scedmacs.h"
#include <time.h>
#include <sys/types.h>
Include dependency graph for dir.c:

Go to the source code of this file.

Data Structures

struct  list
 

Functions

char * CopyString (char *s)
 
static void format_lines ()
 
static void display_lines ()
 
static void list_free ()
 
static void list_sort ()
 
static int lcomp ()
 
static struct listsymfiles ()
 
void Dir ()
 
static void format_lines (struct list *li)
 
static void display_lines (struct list *wl)
 
static void list_free (struct list *wl)
 
static void list_sort (struct list *wl)
 
static int lcomp (char **s, char **t)
 
static struct listsymfiles (char *dir)
 

Variables

char * MenuDIR
 

Function Documentation

char* CopyString ( char *  s)

Definition at line 36 of file dir.c.

39 {
40  char *t;
41 
42  if (s) {
43  t = tmalloc(strlen(s)+1);
44  if (t == NULL) MallocFailed();
45  strcpy(t,s);
46  return (t);
47  }
48  return (s);
49 }
char * strcpy()
Definition: cddefs.h:119
char * tmalloc()
void MallocFailed()
Definition: scedintr.c:857
#define NULL
Definition: spdefs.h:121
Definition: cddefs.h:192
void Dir ( )

Definition at line 76 of file dir.c.

78 {
79  char *path;
80  char *c,*s;
81  struct list *wl,*wx,*wx0 = NULL;
82  char buf[BSIZE_SP];
83 
84 
86  path = PGetPath();
87 
88  for (s = path;;) {
89 
90  while (isspace(*s)) s++;
91  if (*s == '\0')
92  break;
93 
94  c = buf;
95  while (!isspace(*s) && *s != '\0')
96  *c++ = *s++;
97  *c = '\0';
98  /* buf contains the directory path */
99 
100  wl = symfiles(buf);
101 
102  list_sort(wl);
103  format_lines(wl);
104  if (wx0 == NULL)
105  wx = wx0 = alloc(list);
106  else {
107  wx->l_next = alloc(list);
108  wx = wx->l_next;
109  }
110  if (wx == NULL) MallocFailed();
111  strcat(buf," :");
112  if (!wl)
113  strcat(buf, "\n no symbol files found\n ");
114  wx->l_word = CopyString(buf);
115  wx->l_next = wl;
116  while (wx->l_next) wx = wx->l_next;
117  }
118  display_lines(wx0);
119  list_free(wx0);
120  if (!dispdev->windows)
123 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
static void display_lines()
char * MenuDIR
Definition: scedintr.c:73
Definition: cddefs.h:119
DISPDEVICE * dispdev
Definition: display.c:112
Definition: library.c:18
char * CopyString(char *s)
Definition: dir.c:36
#define alloc(type)
Definition: cdmacs.h:21
bool windows
Definition: plotdev.h:61
void MallocFailed()
Definition: scedintr.c:857
void MenuDeselect()
struct list * l_next
Definition: dir.c:55
#define NULL
Definition: spdefs.h:121
char * l_word
Definition: dir.c:54
static void list_sort()
static double c
Definition: vectors.c:16
void RedisplaySCED()
static void format_lines()
Definition: dir.c:53
static void list_free()
GRAPH * currentgraph
Definition: graphdb.c:21
static struct list * symfiles()
char * PGetPath()
Definition: paths.c:67
static char * path
Definition: paths.c:13
void MenuSelect()
static void display_lines ( )
static
static void display_lines ( struct list wl)
static

Definition at line 191 of file dir.c.

195 {
196  (void)EnableMore(True);
197  for (; wl; wl = wl->l_next)
198  if (MoreLine(wl->l_word)) break;
199 
200  (void)EnableMore(False);
201  if (!dispdev->windows) {
202  ShowPrompt("Hit any key to continue.");
203  (void)FBGetchar(ERASE);
204  ErasePrompt();
205  }
206 }
void ErasePrompt()
Definition: viewport.c:538
int MoreLine()
#define ERASE
Definition: scedmacs.h:11
DISPDEVICE * dispdev
Definition: display.c:112
bool windows
Definition: plotdev.h:61
struct list * l_next
Definition: dir.c:55
#define True
Definition: scedstub.c:16
short FBGetchar()
char * l_word
Definition: dir.c:54
int EnableMore()
#define False
Definition: scedstub.c:15
void ShowPrompt(char *str)
Definition: scedstub.c:71
static void format_lines ( )
static
static void format_lines ( struct list li)
static

Definition at line 127 of file dir.c.

131 {
132  struct list *wl;
133  int width, colw, nfiles = 0;
134  int i, j, k, fpc;
135  char *buf, *b, **ptr;
136 
137  if (li == NULL) return;
138  if (!dispdev->windows) {
139  width = View->kvLargeCoarseViewport->kaWidth - 8;
140  width /= gi_fntwidth;
141  }
142  else
143  width = 70;
144  buf = tmalloc(width+1);
145 
146  colw = 0;
147  for (wl = li; wl; wl = wl->l_next) {
148  i = strlen(wl->l_word);
149  if (i > colw) colw = i;
150  nfiles++;
151  }
152  colw += 2;
153  width /= colw; /* width = number of columns */
154  fpc = nfiles/width + 1; /* fpc = max number files/column */
155  ptr = (char**)tmalloc(nfiles*sizeof(char*));
156  for (i = 0, wl = li; wl; i++, wl = wl->l_next) {
157  *(ptr+i) = wl->l_word;
158  }
159 
160  wl = li;
161  for (i = 0; i < fpc; i++) {
162  b = buf;
163  for (j = 0; j < width; j++) {
164  k = j*fpc + i;
165  if (k >= nfiles)
166  break;
167  sprintf(b,"%-*s", colw, *(ptr+k));
168  b = buf + strlen(buf);
169  }
170  free(wl->l_word);
171  wl->l_word = CopyString(buf);
172  if (!wl->l_next) {
173  wl->l_next = alloc(list);
174  if (!wl->l_next)
175  MallocFailed();
176  wl->l_next->l_next = NULL;
177  }
178  wl = wl->l_next;
179  }
180  wl->l_word = CopyString(" ");
181  if (wl->l_next)
182  list_free(wl->l_next);
183  wl->l_next = NULL;
184 
185  free((char*)ptr);
186  free(buf);
187 }
static char buf[MAXPROMPT]
Definition: arg.c:18
DISPDEVICE * dispdev
Definition: display.c:112
Definition: library.c:18
char * CopyString(char *s)
Definition: dir.c:36
#define alloc(type)
Definition: cdmacs.h:21
struct ka * kvLargeCoarseViewport
Definition: sced.h:151
bool windows
Definition: plotdev.h:61
char * tmalloc()
void MallocFailed()
Definition: scedintr.c:857
struct list * l_next
Definition: dir.c:55
#define NULL
Definition: spdefs.h:121
char * l_word
Definition: dir.c:54
struct kv * View
Definition: init.c:17
char * ptr
Definition: output.c:153
Definition: dir.c:53
static void list_free()
#define gi_fntwidth
Definition: scedmacs.h:56
double kaWidth
Definition: sced.h:114
void free()
static int lcomp ( )
static
static int lcomp ( char **  s,
char **  t 
)
static

Definition at line 256 of file dir.c.

259 {
260  return (strcmp(*s,*t));
261 }
Definition: cddefs.h:119
Definition: cddefs.h:192
static void list_free ( )
static
static void list_free ( struct list wl)
static

Definition at line 210 of file dir.c.

213 {
214  struct list *nw;
215 
216  for (; wl; wl = nw) {
217  nw = wl->l_next;
218  free(wl->l_word);
219  tfree(wl);
220  }
221  return;
222 }
struct list * l_next
Definition: dir.c:55
#define tfree(x)
Definition: cdmacs.h:22
char * l_word
Definition: dir.c:54
Definition: dir.c:53
void free()
static void list_sort ( )
static
static void list_sort ( struct list wl)
static

Definition at line 226 of file dir.c.

230 {
231  int i = 0;
232  struct list *ww;
233  char **stuff;
234 
235  for (i = 0, ww = wl; ww; i++, ww = ww->l_next) ;
236  if (i < 2)
237  return;
238  stuff = (char **) tmalloc(i * sizeof (char *));
239  if (stuff == NULL) MallocFailed();
240  for (i = 0, ww = wl; ww; i++, ww = ww->l_next)
241  stuff[i] = ww->l_word;
242  qsort((char *) stuff, i, sizeof (char *),
243 #if __STDC__
244  (int(*)(const void*,const void*))lcomp);
245 #else
246  lcomp);
247 #endif
248  for (i = 0, ww = wl; ww; i++, ww = ww->l_next)
249  ww->l_word = stuff[i];
250  free(stuff);
251  return;
252 }
char * tmalloc()
void MallocFailed()
Definition: scedintr.c:857
struct list * l_next
Definition: dir.c:55
#define NULL
Definition: spdefs.h:121
static int lcomp()
qsort()
Definition: string.c:375
Definition: netlist.c:477
Definition: dir.c:53
void free()
static struct list* symfiles ( )
static
static struct list* symfiles ( char *  dir)
static

Definition at line 265 of file dir.c.

268 {
269  DIR *wdir;
270  struct direct *de;
271  struct list *wl, *wl0 = NULL;
272  char buf[BSIZE_SP];
273  FILE *fp;
274  int i;
275 
276  if (!(wdir = opendir(dir)))
277  return (NULL);
278 
279  while ((de = readdir(wdir)) != NULL) {
280 
281  sprintf(buf,"%s%c%s",dir,DIR_TERM,de->d_name);
282  fp = fopen(buf,"r");
283  if (fp == NULL)
284  continue;
285 
286  /* is it a symbol file? */
287 
288  for (i = 0; i <7; i++)
289  buf[i] = getc(fp);
290  buf[i] = '\0';
291  fclose(fp);
292 
293  if (strcmp(buf,"(Symbol"))
294  continue;
295 
296  if (wl0 == NULL) {
297  wl = wl0 = alloc(list);
298  }
299  else {
300  wl->l_next = alloc(list);
301  wl = wl->l_next;
302  }
303  wl->l_word = CopyString(de->d_name);
304  wl->l_next = NULL;
305  }
306  closedir(wdir);
307  return (wl0);
308 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
Definition: library.c:18
char * CopyString(char *s)
Definition: dir.c:36
#define alloc(type)
Definition: cdmacs.h:21
struct list * l_next
Definition: dir.c:55
#define NULL
Definition: spdefs.h:121
char * l_word
Definition: dir.c:54
Definition: dir.c:53

Variable Documentation

char* MenuDIR

Definition at line 73 of file scedintr.c.