pscopy(), pscopy_up(), use `char *stop' argument

instead of `int length' argument
This commit is contained in:
rlar 2018-02-20 21:12:14 +01:00
parent e21d48a267
commit 751d377d3e
4 changed files with 30 additions and 59 deletions

View File

@ -9,8 +9,8 @@
#include "ngspice/bool.h" #include "ngspice/bool.h"
char *pscopy(SPICE_DSTRINGPTR s, const char *str, int leng); char *pscopy(SPICE_DSTRINGPTR s, const char *str, const char *stop);
char *pscopy_up(SPICE_DSTRINGPTR s, const char *str, int leng); char *pscopy_up(SPICE_DSTRINGPTR s, const char *str, const char *stop);
void scopyd(SPICE_DSTRINGPTR a, SPICE_DSTRINGPTR b); void scopyd(SPICE_DSTRINGPTR a, SPICE_DSTRINGPTR b);
void scopys(SPICE_DSTRINGPTR a, const char *b); void scopys(SPICE_DSTRINGPTR a, const char *b);
void scopy_up(SPICE_DSTRINGPTR a, const char *str); void scopy_up(SPICE_DSTRINGPTR a, const char *str);

View File

@ -168,69 +168,40 @@ scopy_lower(SPICE_DSTRINGPTR dstr_p, const char *str) /* returns success flag */
char * char *
pscopy(SPICE_DSTRINGPTR dstr_p, const char *t, int leng) pscopy(SPICE_DSTRINGPTR dstr_p, const char *t, const char *stop)
/* partial string copy, with C-based start - Because we now have a 0 based
* start and string may copy outselves, we may need to restore the first
* character of the original dstring because resetting string will wipe
* out first character. */
{ {
int i; /* counter */ int i;
int stop; /* stop value */ char *s_p;
char *s_p; /* value of dynamic string */
stop = (int) strlen(t); if (!stop)
stop = strchr(t, '\0');
if (0 < stop) { /* nothing! */ s_p = _spice_dstring_setlength(dstr_p, (int)(stop - t));
if (leng > stop) for (i = 0; t < stop;)
leng = stop; s_p[i++] = *t++;
s_p = _spice_dstring_setlength(dstr_p, leng); s_p[i] = '\0';
for (i = 0; i < leng; i++)
s_p[i] = t[i];
s_p[leng] = '\0';
} else {
s_p = _spice_dstring_setlength(dstr_p, 0);
s_p[0] = '\0';
}
return s_p; return s_p;
} }
char * char *
pscopy_up(SPICE_DSTRINGPTR dstr_p, const char *t, int leng) pscopy_up(SPICE_DSTRINGPTR dstr_p, const char *t, const char *stop)
/* partial string copy to upper case, with C convention for start. */
{ {
int i; /* counter */ int i;
int stop; /* stop value */ char *s_p;
char *s_p; /* value of dynamic string */
stop = (int) strlen(t); if (!stop)
stop = strchr(t, '\0');
if (0 < stop) { /* nothing! */ s_p = _spice_dstring_setlength(dstr_p, (int)(stop - t));
if (leng > stop) for (i = 0; t < stop;)
leng = stop; s_p[i++] = toupper_c(*t++);
s_p = _spice_dstring_setlength(dstr_p, leng); s_p[i] = '\0';
for (i = 0; i < leng; i++)
s_p[i] = toupper_c(t[i]);
s_p[leng] = '\0';
} else {
s_p = _spice_dstring_setlength(dstr_p, 0);
s_p[0] = '\0';
}
return s_p; return s_p;
} }

View File

@ -84,7 +84,7 @@ stripsomespace(SPICE_DSTRINGPTR dstr_p, bool incontrol)
i++; i++;
if ((i > 0) && s[i] && strchr(markers, s[i])) if ((i > 0) && s[i] && strchr(markers, s[i]))
pscopy(dstr_p, s + i, (int) strlen(s + i)); pscopy(dstr_p, s + i, NULL);
} }
@ -115,7 +115,7 @@ stripbraces(SPICE_DSTRINGPTR dstr_p)
j_ptr++; j_ptr++;
} }
pscopy(&tstr, s, (int) (brace - s)); pscopy(&tstr, s, brace);
if (brace[-1] > ' ') if (brace[-1] > ' ')
cadd(&tstr, ' '); cadd(&tstr, ' ');
@ -303,7 +303,7 @@ transform(dico_t *dico, SPICE_DSTRINGPTR dstr_p, bool incontrol)
/* split off any "params" tail */ /* split off any "params" tail */
params = strstr(t, "PARAMS:"); params = strstr(t, "PARAMS:");
if (params) if (params)
pscopy(dstr_p, s, (int)(params - t)); pscopy(dstr_p, s, s + (params - t));
spice_dstring_free(&tstr); spice_dstring_free(&tstr);
category = 'S'; category = 'S';
} else if (ci_prefix(".CONTROL", s)) { } else if (ci_prefix(".CONTROL", s)) {
@ -705,7 +705,7 @@ nupa_copy(struct card *deck)
while ((ls > 0) && (s[ls - 1] <= ' ')) while ((ls > 0) && (s[ls - 1] <= ' '))
ls--; ls--;
pscopy(&u, s, ls); /* strip trailing space, CrLf and so on */ pscopy(&u, s, s + ls); /* strip trailing space, CrLf and so on */
dicoS->srcline = linenum; dicoS->srcline = linenum;
if ((!inexpansionS) && (linenum >= 0) && (linenum <= dynmaxline)) { if ((!inexpansionS) && (linenum >= 0) && (linenum <= dynmaxline)) {

View File

@ -532,7 +532,7 @@ defsubckt(dico_t *dico, struct card *card, nupa_type categ)
if (s_end > s) { if (s_end > s) {
SPICE_DSTRING ustr; /* temp user string */ SPICE_DSTRING ustr; /* temp user string */
spice_dstring_init(&ustr); spice_dstring_init(&ustr);
pscopy_up(&ustr, s, (int) (s_end - s)); pscopy_up(&ustr, s, s_end);
err = nupa_define(dico, spice_dstring_value(&ustr), ' ', categ, 0.0, w, NULL); err = nupa_define(dico, spice_dstring_value(&ustr), ' ', categ, 0.0, w, NULL);
spice_dstring_free(&ustr); spice_dstring_free(&ustr);
} else { } else {
@ -556,7 +556,7 @@ findsubckt(dico_t *dico, const char * const s)
spice_dstring_init(&ustr); spice_dstring_init(&ustr);
pscopy_up(&ustr, name_b, (int) (name_e - name_b)); pscopy_up(&ustr, name_b, name_e);
entry = entrynb(dico, spice_dstring_value(&ustr)); entry = entrynb(dico, spice_dstring_value(&ustr));
if (entry && (entry->tp == NUPA_SUBCKT)) { if (entry && (entry->tp == NUPA_SUBCKT)) {
@ -1383,7 +1383,7 @@ getexpress(nupa_type *type, SPICE_DSTRINGPTR tstr_p, const char *s)
tpe = NUPA_REAL; tpe = NUPA_REAL;
} }
pscopy(tstr_p, s, (int) (p - s)); pscopy(tstr_p, s, p);
if (*p == '}') if (*p == '}')
p++; p++;
@ -1547,7 +1547,7 @@ nupa_subcktcall(dico_t *dico, char *s, char * const x, char * const inst_name)
if (i2) { if (i2) {
const char *optr, *jptr; const char *optr, *jptr;
pscopy(&tstr, i2 + 7, (int) strlen(i2 + 7)); pscopy(&tstr, i2 + 7, NULL);
/* search identifier to the left of '=' assignments */ /* search identifier to the left of '=' assignments */
@ -1652,7 +1652,7 @@ nupa_subcktcall(dico_t *dico, char *s, char * const x, char * const inst_name)
if (alfanum(*kp) || *kp == '.') { if (alfanum(*kp) || *kp == '.') {
/* number, identifier */ /* number, identifier */
jp = skip_non_ws(kp); jp = skip_non_ws(kp);
pscopy(&ustr, kp, (int) (jp - kp)); pscopy(&ustr, kp, jp);
} else if (*kp == '{') { } else if (*kp == '{') {
jp = getexpress(NULL, &ustr, jp); jp = getexpress(NULL, &ustr, jp);
} else { } else {
@ -1667,7 +1667,7 @@ nupa_subcktcall(dico_t *dico, char *s, char * const x, char * const inst_name)
char *dollar = strchr(idlist_p, '$'); char *dollar = strchr(idlist_p, '$');
if (dollar) { if (dollar) {
/* replace dollar with expression string u */ /* replace dollar with expression string u */
pscopy(&vstr, idlist_p, (int) (dollar - idlist_p)); pscopy(&vstr, idlist_p, dollar);
sadd(&vstr, u_p); sadd(&vstr, u_p);
sadd(&vstr, dollar + 1); sadd(&vstr, dollar + 1);
scopyd(&idlist, &vstr); scopyd(&idlist, &vstr);