Jspice3
inpgtok.c
Go to the documentation of this file.
1 /***************************************************************************
2 JSPICE3 adaptation of Spice3e2 - Copyright (c) Stephen R. Whiteley 1992
3 Copyright 1990 Regents of the University of California. All rights reserved.
4 Authors: 1985 Thomas L. Quarles
5  1992 Stephen R. Whiteley
6 ****************************************************************************/
7 
8  /* get input token from 'line',
9  * and return a pointer to it in 'token'
10  */
11 
12 #include "spice.h"
13 #include "inpdefs.h"
14 #include "iferrmsg.h"
15 #include "misc.h"
16 
17 #define issep(c) ((c)==' '||(c)=='\t'||(c)=='='||(c)=='('||(c)==')'||(c)==',')
18 
19 int
20 INPgetTok(line,token,gobble)
21 
22 char ** line;
23 char ** token;
24 int gobble; /* eat non-whitespace trash AFTER token? */
25 {
26  char *point;
27 
28  /* scan along throwing away garbage characters */
29  for (point = *line; *point != '\0'; point++) {
30  if (issep(*point)) continue;
31  break;
32  }
33 
34  /* mark beginning of token */
35  *line = point;
36 
37  /* now find all good characters */
38  for (point = *line; *point != '\0'; point++) {
39  if (issep(*point)) break;
40  }
41  *token = (char *)tmalloc(1 + point - *line);
42  if (!*token)
43  return (E_NOMEM);
44  (void) strncpy(*token,*line,point - *line);
45  *(*token + (point - *line)) = '\0';
46  *line = point;
47 
48  /* gobble garbage to next token */
49  for ( ; **line != '\0'; (*line)++) {
50  if (**line == ' ') continue;
51  if (**line == '\t') continue;
52  if ((**line == '=') && gobble) continue;
53  if ((**line == ',') && gobble) continue;
54  break;
55  }
56  /* printf("found token (%s) and rest of line (%s)\n",*token,*line); */
57  return (OK);
58 }
#define OK
Definition: iferrmsg.h:17
char * tmalloc()
Definition: fteinp.h:14
int INPgetTok(char **line, char **token, int gobble)
Definition: inpgtok.c:20
#define E_NOMEM
Definition: iferrmsg.h:27
#define issep(c)
Definition: inpgtok.c:17