mirror of
https://git.code.sf.net/p/ngspice/ngspice
synced 2026-08-22 05:47:42 +02:00
frontend/device.c, com_alter_common(), #1/4 rewrite for readability
This commit is contained in:
+7
-11
@@ -1124,9 +1124,10 @@ com_alter_common(wordlist *wl, int do_model)
|
|||||||
/* DIE 2009_02_06 */
|
/* DIE 2009_02_06 */
|
||||||
char *argument;
|
char *argument;
|
||||||
char **arglist;
|
char **arglist;
|
||||||
int i = 0, step = 0, n, wlen, maxelem = 3;
|
int step = 0, n, wlen, maxelem = 3;
|
||||||
wordlist *wl2 = NULL, *wlin, *rhs;
|
wordlist *wl2 = NULL, *wlin, *rhs;
|
||||||
bool eqfound = FALSE;
|
bool eqfound = FALSE;
|
||||||
|
char *eqptr = NULL;
|
||||||
|
|
||||||
if (!ft_curckt) {
|
if (!ft_curckt) {
|
||||||
fprintf(cp_err, "Error: no circuit loaded\n");
|
fprintf(cp_err, "Error: no circuit loaded\n");
|
||||||
@@ -1152,16 +1153,14 @@ com_alter_common(wordlist *wl, int do_model)
|
|||||||
while (wl) {
|
while (wl) {
|
||||||
argument = wl->wl_word;
|
argument = wl->wl_word;
|
||||||
/* searching for '=' ... */
|
/* searching for '=' ... */
|
||||||
i = 0;
|
eqptr = strchr(argument, '=');
|
||||||
while (argument[i] != '=' && argument[i] != '\0')
|
|
||||||
i++;
|
|
||||||
|
|
||||||
/* argument may be '=', then do nothing
|
/* argument may be '=', then do nothing
|
||||||
or =token
|
or =token
|
||||||
or token=
|
or token=
|
||||||
or token1=token2
|
or token1=token2
|
||||||
...and if found split argument into three chars and make a new wordlist */
|
...and if found split argument into three chars and make a new wordlist */
|
||||||
if (argument[i] != '\0') {
|
if (eqptr) {
|
||||||
/* We found '=' */
|
/* We found '=' */
|
||||||
eqfound = TRUE;
|
eqfound = TRUE;
|
||||||
if (strlen(argument) == 1) {
|
if (strlen(argument) == 1) {
|
||||||
@@ -1170,16 +1169,13 @@ com_alter_common(wordlist *wl, int do_model)
|
|||||||
wl2 = wlin;
|
wl2 = wlin;
|
||||||
} else if (strlen(argument) > 1) {
|
} else if (strlen(argument) > 1) {
|
||||||
arglist = TMALLOC(char*, 4);
|
arglist = TMALLOC(char*, 4);
|
||||||
arglist[3] = NULL;
|
|
||||||
arglist[0] = TMALLOC(char, i + 1);
|
|
||||||
arglist[2] = TMALLOC(char, strlen(&argument[i + 1]) + 1);
|
|
||||||
/* copy argument */
|
/* copy argument */
|
||||||
strncpy(arglist[0], argument, (size_t) i);
|
arglist[0] = copy_substring(argument, eqptr);
|
||||||
arglist[0][i] = '\0';
|
|
||||||
/* copy equal sign */
|
/* copy equal sign */
|
||||||
arglist[1] = copy("=");
|
arglist[1] = copy("=");
|
||||||
/* copy expression */
|
/* copy expression */
|
||||||
strncpy(arglist[2], &argument[i+1], strlen(&argument[i+1])+1);
|
arglist[2] = copy(eqptr + 1);
|
||||||
|
arglist[3] = NULL;
|
||||||
|
|
||||||
/* create a new wordlist from array arglist */
|
/* create a new wordlist from array arglist */
|
||||||
wl2 = wl_build(arglist);
|
wl2 = wl_build(arglist);
|
||||||
|
|||||||
Reference in New Issue
Block a user