Jspice3
wlist.c File Reference
#include "spice.h"
#include "cpstd.h"
#include "suffix.h"
Include dependency graph for wlist.c:

Go to the source code of this file.

Functions

static int wlcomp ()
 
int wl_length (wordlist *wlist)
 
void wl_free (wordlist *wlist)
 
wordlistwl_copy (wordlist *wlist)
 
wordlistwl_splice (wordlist *elt, wordlist *list)
 
void wl_print (wordlist *wlist, FILE *fp)
 
wordlistwl_build (v)
 
char ** wl_mkvec (wordlist *wl)
 
wordlistwl_append (wordlist *wlist, wordlist *nwl)
 
wordlistwl_reverse (wordlist *wl)
 
char * wl_flatten (wordlist *wl)
 
wordlistwl_nthelem (int i, wordlist *wl)
 
void wl_sort (wordlist *wl)
 
static int wlcomp (char **s, char **t)
 
wordlistwl_range (wordlist *wl, int low, int up)
 

Function Documentation

wordlist* wl_append ( wordlist wlist,
wordlist nwl 
)

Definition at line 181 of file wlist.c.

184 {
185  wordlist *wl;
186  if (wlist == NULL)
187  return (nwl);
188  if (nwl == NULL)
189  return (wlist);
190  for (wl = wlist; wl->wl_next; wl = wl->wl_next);
191  wl->wl_next = nwl;
192  nwl->wl_prev = wl;
193  return (wlist);
194 }
Definition: library.c:18
struct wordlist * wl_prev
Definition: cpstd.h:24
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
wordlist* wl_build ( )

Definition at line 134 of file wlist.c.

137 {
138  wordlist *wlist, *wl = NULL, *cwl;
139 
140  while (*v) {
141  cwl = alloc(struct wordlist);
142  cwl->wl_prev = wl;
143  if (wl)
144  wl->wl_next = cwl;
145  else
146  wlist = cwl;
147  cwl->wl_word = copy(*v);
148  wl = cwl;
149  v++;
150  }
151  return (wlist);
152 }
Definition: library.c:18
#define alloc(type)
Definition: cdmacs.h:21
char * copy()
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
wordlist* wl_copy ( wordlist wlist)

Definition at line 62 of file wlist.c.

65 {
66  register wordlist *wl, *nwl = NULL, *w;
67 
68  for (wl = wlist; wl; wl = wl->wl_next) {
69  if (nwl == NULL) {
70  nwl = w = alloc(struct wordlist);
71  }
72  else {
73  w->wl_next = alloc(struct wordlist);
74  w->wl_next->wl_prev = w;
75  w = w->wl_next;
76  }
77  w->wl_word = copy(wl->wl_word);
78  }
79  return (nwl);
80 }
Definition: cddefs.h:169
Definition: library.c:18
#define alloc(type)
Definition: cdmacs.h:21
char * copy()
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
char* wl_flatten ( wordlist wl)

Definition at line 222 of file wlist.c.

224 {
225  char *buf;
226  wordlist *tw;
227  int i = 0;
228 
229  for (tw = wl; tw; tw = tw->wl_next)
230  i += strlen(tw->wl_word) + 1;
231  buf = tmalloc(i + 1);
232 
233  while (wl != NULL) {
234  (void) strcat(buf, wl->wl_word);
235  if (wl->wl_next)
236  (void) strcat(buf, " ");
237  wl = wl->wl_next;
238  }
239  return (buf);
240 }
static char buf[MAXPROMPT]
Definition: arg.c:18
char * tmalloc()
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
void wl_free ( wordlist wlist)

Definition at line 43 of file wlist.c.

46 {
47  wordlist *wl, *nw;
48 
49  for (wl = wlist; wl; wl = nw) {
50  nw = wl->wl_next;
51  tfree(wl->wl_word);
52  tfree(wl);
53  }
54  return;
55 }
Definition: library.c:18
#define tfree(x)
Definition: cdmacs.h:22
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
int wl_length ( wordlist wlist)

Definition at line 26 of file wlist.c.

29 {
30  register int i = 0;
31  register wordlist *wl;
32 
33  for (wl = wlist; wl; wl = wl->wl_next)
34  i++;
35  return (i);
36 }
Definition: library.c:18
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char** wl_mkvec ( wordlist wl)

Definition at line 159 of file wlist.c.

162 {
163  int len, i;
164  char **v;
165 
166  len = wl_length(wl);
167  v = (char **) tmalloc((len + 1) * sizeof (char **));
168  for (i = 0; i < len; i++) {
169  v[i] = copy(wl->wl_word);
170  wl = wl->wl_next;
171  }
172  v[i] = NULL;
173  return (v);
174 }
int wl_length(wordlist *wlist)
Definition: wlist.c:26
char * copy()
char * tmalloc()
#define NULL
Definition: spdefs.h:121
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
wordlist* wl_nthelem ( int  i,
wordlist wl 
)

Definition at line 249 of file wlist.c.

253 {
254  register wordlist *ww = wl;
255 
256  while ((i-- > 0) && ww->wl_next)
257  ww = ww->wl_next;
258  return (ww);
259 }
Definition: cpstd.h:21
Definition: netlist.c:477
struct wordlist * wl_next
Definition: cpstd.h:23
void wl_print ( wordlist wlist,
FILE *  fp 
)

Definition at line 114 of file wlist.c.

118 {
119  wordlist *wl;
120 
121  for (wl = wlist; wl; wl = wl->wl_next) {
122  cp_printword(wl->wl_word, fp);
123  if (wl->wl_next)
124  (void) putc(' ', fp);
125  }
126  return;
127 }
Definition: library.c:18
void cp_printword()
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
wordlist* wl_range ( wordlist wl,
int  low,
int  up 
)

Definition at line 307 of file wlist.c.

311 {
312  int i;
313  wordlist *tt;
314  bool rev = false;
315 
316  if (low > up) {
317  i = up;
318  up = low;
319  low = i;
320  rev = true;
321  }
322  up -= low;
323  while (wl && (low > 0)) {
324  tt = wl->wl_next;
325  tfree(wl->wl_word);
326  tfree(wl);
327  wl = tt;
328  if (wl)
329  wl->wl_prev = NULL;
330  low--;
331  }
332  tt = wl;
333  while (tt && (up > 0)) {
334  tt = tt->wl_next;
335  up--;
336  }
337  if (tt && tt->wl_next) {
338  wl_free(tt->wl_next);
339  tt->wl_next = NULL;
340  }
341  if (rev)
342  wl = wl_reverse(wl);
343  return (wl);
344 }
wordlist * wl_reverse(wordlist *wl)
Definition: wlist.c:201
Definition: xforms.c:16
void wl_free(wordlist *wlist)
Definition: wlist.c:43
struct wordlist * wl_prev
Definition: cpstd.h:24
#define tfree(x)
Definition: cdmacs.h:22
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
wordlist* wl_reverse ( wordlist wl)

Definition at line 201 of file wlist.c.

204 {
205  wordlist *w, *t;
206 
207  for (w = wl; ; w = t) {
208  t = w->wl_next;
209  w->wl_next = w->wl_prev;
210  w->wl_prev = t;
211  if (t == NULL)
212  break;
213  }
214  return (w);
215 }
Definition: cddefs.h:169
struct wordlist * wl_prev
Definition: cpstd.h:24
#define NULL
Definition: spdefs.h:121
Definition: cpstd.h:21
struct wordlist * wl_next
Definition: cpstd.h:23
Definition: cddefs.h:192
void wl_sort ( wordlist wl)

Definition at line 266 of file wlist.c.

269 {
270  register int i = 0;
271  register wordlist *ww = wl;
272  char **stuff;
273 
274  for (i = 0; ww; i++)
275  ww = ww->wl_next;
276  if (i < 2)
277  return;
278  stuff = (char **) tmalloc(i * sizeof (char *));
279  for (i = 0, ww = wl; ww; i++, ww = ww->wl_next)
280  stuff[i] = ww->wl_word;
281  qsort((char *) stuff, i, sizeof (char *),
282 #ifdef __STDC__
283  (int(*)(const void*,const void*))wlcomp);
284 #else
285  wlcomp);
286 #endif
287  for (i = 0, ww = wl; ww; i++, ww = ww->wl_next)
288  ww->wl_word = stuff[i];
289  tfree(stuff);
290  return;
291 }
if(TDesc==NULL)
Definition: cd.c:1326
char * tmalloc()
#define tfree(x)
Definition: cdmacs.h:22
Definition: cpstd.h:21
qsort()
Definition: string.c:375
Definition: netlist.c:477
struct wordlist * wl_next
Definition: cpstd.h:23
static int wlcomp()
wordlist* wl_splice ( wordlist elt,
wordlist list 
)

Definition at line 89 of file wlist.c.

92 {
93  if (list)
94  list->wl_prev = elt->wl_prev;
95  if (elt->wl_prev)
96  elt->wl_prev->wl_next = list;
97  if (list) {
98  while (list->wl_next)
99  list = list->wl_next;
100  list->wl_next = elt->wl_next;
101  }
102  if (elt->wl_next)
103  elt->wl_next->wl_prev = list;
104  tfree(elt->wl_word);
105  tfree(elt);
106  return (list);
107 }
struct wordlist * wl_prev
Definition: cpstd.h:24
#define tfree(x)
Definition: cdmacs.h:22
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
static int wlcomp ( )
static
static int wlcomp ( char **  s,
char **  t 
)
static

Definition at line 295 of file wlist.c.

298 {
299  return (strcmp(*s, *t));
300 }
Definition: cddefs.h:119
Definition: cddefs.h:192