mirror of
https://git.code.sf.net/p/ngspice/ngspice
synced 2026-08-22 05:47:42 +02:00
string.c, #5/6, cleanup
This commit is contained in:
+30
-61
@@ -111,20 +111,15 @@ tprintf(const char *fmt, ...)
|
|||||||
int
|
int
|
||||||
substring(const char *sub, const char *str)
|
substring(const char *sub, const char *str)
|
||||||
{
|
{
|
||||||
const char *s, *t;
|
for (; *str; str++)
|
||||||
|
|
||||||
while (*str) {
|
|
||||||
if (*str == *sub) {
|
if (*str == *sub) {
|
||||||
t = str;
|
const char *s = sub, *t = str;
|
||||||
for (s = sub; *s; s++) {
|
for (; *s; s++, t++)
|
||||||
if (!*t || (*s != *t++))
|
if (!*t || (*s != *t))
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (*s == '\0')
|
if (*s == '\0')
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
str++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -166,13 +161,9 @@ scannum(char *str)
|
|||||||
int
|
int
|
||||||
cieq(const char *p, const char *s)
|
cieq(const char *p, const char *s)
|
||||||
{
|
{
|
||||||
while (*p) {
|
for (; *p; p++, s++)
|
||||||
if ((isupper_c(*p) ? tolower_c(*p) : *p) !=
|
if (tolower_c(*p) != tolower_c(*s))
|
||||||
(isupper_c(*s) ? tolower_c(*s) : *s))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
p++;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return *s == '\0';
|
return *s == '\0';
|
||||||
}
|
}
|
||||||
@@ -183,13 +174,9 @@ cieq(const char *p, const char *s)
|
|||||||
int
|
int
|
||||||
ciprefix(const char *p, const char *s)
|
ciprefix(const char *p, const char *s)
|
||||||
{
|
{
|
||||||
while (*p) {
|
for (; *p; p++, s++)
|
||||||
if ((isupper_c(*p) ? tolower_c(*p) : *p) !=
|
if (tolower_c(*p) != tolower_c(*s))
|
||||||
(isupper_c(*s) ? tolower_c(*s) : *s))
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
p++;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -198,24 +185,22 @@ ciprefix(const char *p, const char *s)
|
|||||||
void
|
void
|
||||||
strtolower(char *str)
|
strtolower(char *str)
|
||||||
{
|
{
|
||||||
if (str)
|
if (!str)
|
||||||
while (*str) {
|
return;
|
||||||
if (isupper_c(*str))
|
|
||||||
*str = tolower_c(*str);
|
for (; *str; str++)
|
||||||
str++;
|
*str = tolower_c(*str);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
strtoupper(char *str)
|
strtoupper(char *str)
|
||||||
{
|
{
|
||||||
if (str)
|
if (!str)
|
||||||
while (*str) {
|
return;
|
||||||
if (islower_c(*str))
|
|
||||||
*str = toupper_c(*str);
|
for (; *str; str++)
|
||||||
str++;
|
*str = toupper_c(*str);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -239,13 +224,9 @@ cinprefix(char *p, char *s, int n)
|
|||||||
if (!p || !s)
|
if (!p || !s)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (*p) {
|
for (; *p; p++, s++, n--)
|
||||||
if ((isupper_c(*p) ? tolower_c(*p) : *p) != (isupper_c(*s) ? tolower_c(*s) : *s))
|
if (tolower_c(*p) != tolower_c(*s))
|
||||||
return 0;
|
return 0;
|
||||||
p++;
|
|
||||||
s++;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n <= 0;
|
return n <= 0;
|
||||||
}
|
}
|
||||||
@@ -265,13 +246,9 @@ cimatch(char *p, char *s)
|
|||||||
if (!p || !s)
|
if (!p || !s)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (*p) {
|
for (; *p; p++, s++, n++)
|
||||||
if ((isupper_c(*p) ? tolower_c(*p) : *p) != (isupper_c(*s) ? tolower_c(*s) : *s))
|
if (tolower_c(*p) != tolower_c(*s))
|
||||||
return n;
|
return n;
|
||||||
p++;
|
|
||||||
s++;
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@@ -367,7 +344,7 @@ gettok_iv(char **s)
|
|||||||
SPICE_DSTRING buf; /* allow any length string */
|
SPICE_DSTRING buf; /* allow any length string */
|
||||||
|
|
||||||
paren = 0;
|
paren = 0;
|
||||||
while ((isspace_c(**s)) || (**s == '='))
|
while (isspace_c(**s) || (**s == '='))
|
||||||
(*s)++;
|
(*s)++;
|
||||||
|
|
||||||
if ((!**s) || ((**s != 'v') && (**s != 'i') && (**s != 'V') && (**s != 'I')))
|
if ((!**s) || ((**s != 'v') && (**s != 'i') && (**s != 'V') && (**s != 'I')))
|
||||||
@@ -495,26 +472,23 @@ gettok_char(char **s, char p, bool inc_p, bool nested)
|
|||||||
else
|
else
|
||||||
q = '(';
|
q = '(';
|
||||||
/* add string in front of q, excluding q */
|
/* add string in front of q, excluding q */
|
||||||
while ((c = **s) != '\0' && (**s != q)) {
|
while ((c = **s) != '\0' && (**s != q))
|
||||||
(*s)++;
|
(*s)++;
|
||||||
}
|
|
||||||
/* return if nested bracket found, excluding its character */
|
/* return if nested bracket found, excluding its character */
|
||||||
while ((c = **s) != '\0') {
|
while ((c = **s) != '\0') {
|
||||||
if (c == q)
|
if (c == q)
|
||||||
count++;
|
count++;
|
||||||
else if (c == p)
|
else if (c == p)
|
||||||
count--;
|
count--;
|
||||||
if (count == 0) {
|
if (count == 0)
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
(*s)++;
|
(*s)++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* just look for p and return string, excluding p */
|
/* just look for p and return string, excluding p */
|
||||||
while ((c = **s) != '\0' && (**s != p)) {
|
while ((c = **s) != '\0' && (**s != p))
|
||||||
(*s)++;
|
(*s)++;
|
||||||
}
|
|
||||||
|
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
/* p not found */
|
/* p not found */
|
||||||
@@ -565,9 +539,8 @@ gettok_node(char **s)
|
|||||||
(**s != '(') &&
|
(**s != '(') &&
|
||||||
(**s != ')') &&
|
(**s != ')') &&
|
||||||
(**s != ',')
|
(**s != ',')
|
||||||
) { /* collect chars until whitespace or ( , ) */
|
) /* collect chars until whitespace or ( , ) */
|
||||||
(*s)++;
|
(*s)++;
|
||||||
}
|
|
||||||
|
|
||||||
token_e = *s;
|
token_e = *s;
|
||||||
|
|
||||||
@@ -643,18 +616,16 @@ stripWhiteSpacesInsideParens(char *str)
|
|||||||
i++;
|
i++;
|
||||||
|
|
||||||
spice_dstring_init(&buf);
|
spice_dstring_init(&buf);
|
||||||
for (i = i; str[i] != '\0'; i++) {
|
for (; str[i]; i++)
|
||||||
if (str[i] != '(') {
|
if (str[i] != '(') {
|
||||||
spice_dstring_append_char(&buf, str[i]);
|
spice_dstring_append_char(&buf, str[i]);
|
||||||
} else {
|
} else {
|
||||||
spice_dstring_append_char(&buf, str[i]);
|
spice_dstring_append_char(&buf, str[i]);
|
||||||
while ((str[i++] != ')')) {
|
while (str[i++] != ')')
|
||||||
if (str[i] != ' ')
|
if (str[i] != ' ')
|
||||||
spice_dstring_append_char(&buf, str[i]);
|
spice_dstring_append_char(&buf, str[i]);
|
||||||
}
|
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
token = copy(spice_dstring_value(&buf));
|
token = copy(spice_dstring_value(&buf));
|
||||||
spice_dstring_free(&buf);
|
spice_dstring_free(&buf);
|
||||||
@@ -679,11 +650,9 @@ is_arith_char(char c)
|
|||||||
bool
|
bool
|
||||||
str_has_arith_char(char *s)
|
str_has_arith_char(char *s)
|
||||||
{
|
{
|
||||||
while (*s && *s != '\0') {
|
for (; *s; s++)
|
||||||
if (is_arith_char(*s))
|
if (is_arith_char(*s))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
s++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user