Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Thomas L. Quarles
Modified: 2000 AlansFixes
**********/
* and return a pointer to it in 'token'
*/
INPgetUTok: numbers and other elements in expressions
(called from INPevaluate)
*/
#include "ngspice/ngspice.h"
#include "ngspice/iferrmsg.h"
#include "ngspice/inpdefs.h"
#include "inpxx.h"
* INPgetTok -- this fcn extracts a generic input token from
* 'line' and returns a pointer to it in 'token'.
*------------------------------------------------------------------*/
int
INPgetTok(char **line, char **token, int gobble)
{
char *point;
int signstate;
if (!*line) {
*token = NULL;
return (E_PARMVAL);
}
or a separation char is found */
for (point = *line; *point != '\0'; point++) {
if (*point == ' ')
continue;
if (*point == '\t')
continue;
if (*point == '\r')
continue;
if (*point == '=')
continue;
if (*point == '(')
continue;
if (*point == ')')
continue;
if (*point == ',')
continue;
break;
}
*line = point;
separation character. */
signstate = 0;
for (point = *line; *point != '\0'; point++) {
if (*point == ' ')
break;
if (*point == '\t')
break;
if (*point == '\r')
break;
if (*point == '=')
break;
if (*point == '(')
break;
if (*point == ')')
break;
if (*point == ',')
break;
but it will get the "good" parses */
if ((*point == '+') || (*point == '-')) {
if (signstate == 1 || signstate == 3)
break;
signstate += 1;
continue;
}
if (*point == '*')
break;
if (*point == '/')
break;
if (*point == '^')
break;
if (isdigit_c(*point) || *point == '.') {
if (signstate > 1)
signstate = 3;
else
signstate = 1;
} else if (tolower_c(*point) == 'e' && signstate == 1)
signstate = 2;
else
signstate = 3;
}
if (point == *line && *point)
point++;
*token = copy_substring(*line, point);
if (!*token)
return (E_NOMEM);
*line = point;
for (; **line != '\0'; (*line)++) {
if (**line == ' ')
continue;
if (**line == '\t')
continue;
if (**line == '\r')
continue;
if ((**line == '=') && gobble)
continue;
if ((**line == ',') && gobble)
continue;
break;
}
#ifdef TRACE
#endif
return (OK);
}
* INPgetNetTok -- this fcn extracts an input netname token from
* 'line' and returns a pointer to it in 'token'.
* This fcn cloned from INPgetTok by SDB to enable
* complex netnames (e.g. netnames like '+VCC' and 'IN-').
* mailto:sdb@cloud9.net -- 4.7.2003
*------------------------------------------------------------------*/
int
INPgetNetTok(char **line, char **token, int gobble)
{
char *point;
or a separation char is found */
for (point = *line; *point != '\0'; point++) {
if (*point == ' ')
continue;
if (*point == '\t')
continue;
if (*point == '=')
continue;
if (*point == '(')
continue;
if (*point == ')')
continue;
if (*point == ',')
continue;
break;
}
*line = point;
separation character. INPgetNetTok is very liberal about
what it accepts. */
for (point = *line; *point != '\0'; point++) {
if (*point == ' ')
break;
if (*point == '\t')
break;
if (*point == '\r')
break;
if (*point == '=')
break;
if (*point == ',')
break;
if (*point == ')')
break;
}
if (point == *line && *point)
point++;
*token = copy_substring(*line, point);
if (!*token)
return (E_NOMEM);
*line = point;
for (; **line != '\0'; (*line)++) {
if (**line == ' ')
continue;
if (**line == '\t')
continue;
if (**line == '\r')
continue;
if ((**line == '=') && gobble)
continue;
if ((**line == ',') && gobble)
continue;
break;
}
#ifdef TRACE
#endif
return (OK);
}
* INPgetUTok -- this fcn extracts an input refdes token from
* 'line' and returns a pointer to it in 'token'.
*------------------------------------------------------------------*/
int
INPgetUTok(char **line, char **token, int gobble)
{
char *point, separator;
int signstate;
for (point = *line; *point != '\0'; point++) {
if (*point == ' ')
continue;
if (*point == '\t')
continue;
if (*point == '=')
continue;
if (*point == '(')
continue;
if (*point == ')')
continue;
if (*point == ',')
continue;
break;
}
if (*point == '"') {
separator = '"';
point++;
} else if (*point == '\'') {
separator = '\'';
point++;
} else
separator = '\0';
*line = point;
signstate = 0;
for (point = *line; *point != '\0'; point++) {
if (separator) {
if (*point == separator)
break;
else
continue;
}
if (*point == ' ')
break;
if (*point == '\t')
break;
if (*point == '=')
break;
if (*point == '(')
break;
if (*point == ')')
break;
if (*point == ',')
break;
get the "good" parses */
if (*point == '+' || *point == '-') {
if (signstate == 1 || signstate == 3)
break;
signstate += 1;
continue;
}
if (*point == '*')
break;
if (*point == '/')
break;
if (*point == '^')
break;
if (isdigit_c(*point) || *point == '.') {
if (signstate > 1)
signstate = 3;
else
signstate = 1;
} else if (tolower_c(*point) == 'e' && signstate == 1)
signstate = 2;
else
signstate = 3;
}
if (separator && *point == separator)
point--;
if (point == *line && *point)
point++;
*token = copy_substring(*line, point);
if (!*token)
return (E_NOMEM);
for (; *point != '\0'; point++) {
if (*point == separator)
continue;
if (*point == ' ')
continue;
if (*point == '\t')
continue;
if ((*point == '=') && gobble)
continue;
if ((*point == ',') && gobble)
continue;
break;
}
*line = point;
#ifdef TRACE
#endif
return (OK);
}