Browse Source

add new function gettok_node_br which adds braces { } on its list

of ignored characters.
pre-master-46
Holger Vogt 6 months ago
parent
commit
537116424f
  1. 1
      src/include/ngspice/ngspice.h
  2. 51
      src/misc/string.c

1
src/include/ngspice/ngspice.h

@ -236,6 +236,7 @@ extern FILE *newfopen(const char *fn, const char* md);
void findtok_noparen(char **p_str, char **p_token, char **p_token_end); void findtok_noparen(char **p_str, char **p_token, char **p_token_end);
extern char *gettok_noparens(char **s); extern char *gettok_noparens(char **s);
extern char *gettok_node(char **s); extern char *gettok_node(char **s);
extern char *gettok_node_br(char **s);
extern char *gettok_iv(char **s); extern char *gettok_iv(char **s);
extern char *nexttok(const char *s); extern char *nexttok(const char *s);
extern char *nexttok_noparens(const char *s); extern char *nexttok_noparens(const char *s);

51
src/misc/string.c

@ -861,6 +861,57 @@ gettok_node(char **s)
return copy_substring(token, token_e); return copy_substring(token, token_e);
} }
/*-------------------------------------------------------------------------*
* gettok_node_br acts like gettok_node, including braces { }.
*-------------------------------------------------------------------------*/
char*
gettok_node_br(char** s)
{
char c;
const char* token, * token_e;
if (*s == NULL)
return NULL;
while (isspace_c(**s) ||
(**s == '(') ||
(**s == ')') ||
(**s == '{') ||
(**s == '}') ||
(**s == ',')
)
(*s)++; /* iterate over whitespace and ( , ) */
if (!**s)
return NULL; /* return NULL if we come to end of line */
token = *s;
while ((c = **s) != '\0' &&
!isspace_c(c) &&
(**s != '(') &&
(**s != ')') &&
(**s != '{') &&
(**s != '}') &&
(**s != ',')
) /* collect chars until whitespace or ( , ) */
(*s)++;
token_e = *s;
/* Now iterate up to next non-whitespace char */
while (isspace_c(**s) ||
(**s == '(') ||
(**s == ')') ||
(**s == '{') ||
(**s == '}') ||
(**s == ',')
)
(*s)++; /* iterate over whitespace and ( , ) */
return copy_substring(token, token_e);
}
/*-------------------------------------------------------------------------* /*-------------------------------------------------------------------------*
* get_l_paren iterates the pointer forward in a string until it hits * get_l_paren iterates the pointer forward in a string until it hits

Loading…
Cancel
Save