Jspice3
string.c File Reference
#include "spice.h"
#include "misc.h"
Include dependency graph for string.c:

Go to the source code of this file.

Functions

int prefix (char *p, char *s)
 
char * copy (char *str)
 
int substring (char *sub, char *str)
 
void appendc (char *s, char c)
 
int scannum (char *str)
 
int cieq (char *p, char *s)
 
int ciprefix (char *p, char *s)
 
void strtolower (char *str)
 
char * gettok (char **s)
 
int copytok (char *dst, char **s)
 
int copytok1 (char *dst, char **s)
 
void advtok (char **s)
 
char * index (char *s, char c) const
 
char * rindex (char *s, char c) const
 
void bcopy (char *from, char *to, int num)
 
int bzero (char *ptr, int num)
 
 qsort ()
 

Function Documentation

void advtok ( char **  s)

Definition at line 266 of file string.c.

269 {
270  int i = 0;
271 
272  if (s == NULL || *s == NULL)
273  return;
274  while (isspace(**s))
275  (*s)++;
276  if (!**s)
277  return;
278  while (**s && !isspace(**s))
279  (*s)++;
280  while (isspace(**s))
281  (*s)++;
282  return;
283 }
Definition: cddefs.h:119
#define NULL
Definition: spdefs.h:121
void appendc ( char *  s,
char  c 
)

Definition at line 88 of file string.c.

91 {
92  if (s) {
93  while (*s)
94  s++;
95  *s++ = c;
96  *s = '\0';
97  }
98  return;
99 }
Definition: cddefs.h:119
static double c
Definition: vectors.c:16
void bcopy ( char *  from,
char *  to,
int  num 
)

Definition at line 339 of file string.c.

343 {
344  while (num-- > 0)
345  *to++ = *from++;
346  return;
347 }
int bzero ( char *  ptr,
int  num 
)

Definition at line 357 of file string.c.

361 {
362  while (num-- > 0)
363  *ptr++ = '\0';
364  return (0);
365 }
char * ptr
Definition: output.c:153
int cieq ( char *  p,
char *  s 
)

Definition at line 126 of file string.c.

129 {
130  if (p == NULL || s == NULL)
131  return (false);
132  while (*p) {
133  if ((isupper(*p) ? tolower(*p) : *p) !=
134  (isupper(*s) ? tolower(*s) : *s))
135  return (false);
136  p++;
137  s++;
138  }
139  return (*s ? false : true);
140 }
Definition: cddefs.h:119
Definition: cddefs.h:215
#define NULL
Definition: spdefs.h:121
int ciprefix ( char *  p,
char *  s 
)

Definition at line 148 of file string.c.

151 {
152  if (p == NULL || s == NULL)
153  return (false);
154  while (*p) {
155  if ((isupper(*p) ? tolower(*p) : *p) !=
156  (isupper(*s) ? tolower(*s) : *s))
157  return (false);
158  p++;
159  s++;
160  }
161  return (true);
162 }
Definition: cddefs.h:119
Definition: cddefs.h:215
#define NULL
Definition: spdefs.h:121
char* copy ( char *  str)

Definition at line 41 of file string.c.

44 {
45  char *p;
46 
47  if (str == NULL)
48  return (NULL);
49  p = tmalloc(strlen(str) + 1);
50  (void) strcpy(p, str);
51  return(p);
52 }
char * strcpy()
FILE * p
Definition: proc2mod.c:48
char * tmalloc()
#define NULL
Definition: spdefs.h:121
int copytok ( char *  dst,
char**  s 
)

Definition at line 215 of file string.c.

218 {
219  if (s == NULL || *s == NULL)
220  return (0);
221  while (isspace(**s))
222  (*s)++;
223  if (!**s)
224  return (0);
225  while (**s && !isspace(**s))
226  *dst++ = *(*s)++;
227  *dst = '\0';
228  while (isspace(**s))
229  (*s)++;
230  return (1);
231 }
Definition: cddefs.h:119
#define NULL
Definition: spdefs.h:121
int copytok1 ( char *  dst,
char**  s 
)

Definition at line 241 of file string.c.

244 {
245  if (s == NULL || *s == NULL)
246  return (0);
247  while (isspace(**s))
248  (*s)++;
249  if (!**s)
250  return (0);
251  while (**s && !isspace(**s))
252  *dst++ = *(*s)++;
253  *dst++ = ' ';
254  *dst++ = '\0';
255  while (isspace(**s))
256  (*s)++;
257  return (1);
258 }
Definition: cddefs.h:119
#define NULL
Definition: spdefs.h:121
char* gettok ( char **  s)

Definition at line 187 of file string.c.

190 {
191  char buf[BSIZE_SP];
192  int i = 0;
193 
194  if (s == NULL || *s == NULL)
195  return (NULL);
196  while (isspace(**s))
197  (*s)++;
198  if (!**s)
199  return (NULL);
200  while (**s && !isspace(**s))
201  buf[i++] = *(*s)++;
202  buf[i] = '\0';
203  while (isspace(**s))
204  (*s)++;
205  return (copy(buf));
206 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
Definition: cddefs.h:119
char * copy(char *str)
Definition: string.c:41
#define NULL
Definition: spdefs.h:121
char* index ( char *  s,
char  c 
) const

Definition at line 294 of file string.c.

298 {
299  while ((*s != c) && (*s != '\0'))
300  s++;
301  if (*s == '\0')
302  return ((char *) 0);
303  else
304  return ((char*)s);
305 }
Definition: cddefs.h:119
Definition: cddefs.h:177
int prefix ( char *  p,
char *  s 
)

Definition at line 21 of file string.c.

24 {
25  if (p == NULL || s == NULL)
26  return (false);
27  while (*p && (*p == *s))
28  p++, s++;
29  if (!*p)
30  return (true);
31  else
32  return (false);
33 }
Definition: cddefs.h:119
Definition: cddefs.h:215
#define NULL
Definition: spdefs.h:121
qsort ( )

Definition at line 375 of file string.c.

375 {}
char* rindex ( char *  s,
char  c 
) const

Definition at line 313 of file string.c.

317 {
318  char *t;
319 
320  for (t = (char*)s; *t != '\0'; t++);
321  while ((*t != c) && (t != (char*)s))
322  t--;
323  if (t == (char*)s)
324  return ((char *) 0);
325  else
326  return (t);
327 }
Definition: cddefs.h:119
Definition: cddefs.h:177
Definition: cddefs.h:192
int scannum ( char *  str)

Definition at line 108 of file string.c.

111 {
112  int i = 0;
113 
114  if (str)
115  while (isdigit(*str))
116  i = i * 10 + *(str++) - '0';
117  return(i);
118 }
void strtolower ( char *  str)

Definition at line 170 of file string.c.

173 {
174  if (str)
175  while (*str) {
176  *str = tolower(*str);
177  str++;
178  }
179 }
int substring ( char *  sub,
char *  str 
)

Definition at line 60 of file string.c.

63 {
64  char *s;
65 
66  if (str == NULL || sub == NULL)
67  return (false);
68  while (*str) {
69  if (*str == *sub) {
70  for (s = sub; *s; s++) {
71  if (!*str || (*s != *str++))
72  break;
73  }
74  if (*s == '\0')
75  return (true);
76  }
77  str++;
78  }
79  return (false);
80 }
Definition: cddefs.h:119
#define NULL
Definition: spdefs.h:121