inpcom.c, change semantics of skip_back_non_ws() and skip_back_ws()

This commit is contained in:
rlar 2013-05-25 23:38:57 +02:00
parent 144452c96c
commit 30a88925da
1 changed files with 31 additions and 31 deletions

View File

@ -109,9 +109,9 @@ static char *get_quoted_token(char *string, char **token);
static void replace_token(char *string, char *token, int where, int total);
static void inp_add_series_resistor(struct line *deck);
static char *skip_back_non_ws(char *d) { while (*d && !isspace(*d)) d--; return d; }
static char *skip_back_non_ws(char *d) { --d; while (*d && !isspace(*d)) d--; return d + 1; }
static char *skip_back_ws(char *d) { --d; while (isspace(*d)) d--; return d + 1; }
static char *skip_non_ws(char *d) { while (*d && !isspace(*d)) d++; return d; }
static char *skip_back_ws(char *d) { while (isspace(*d)) d--; return d; }
static char *skip_ws(char *d) { while (isspace(*d)) d++; return d; }
static void tprint(struct line *deck);
@ -1001,7 +1001,7 @@ inp_chk_for_multi_in_vcvs(struct line *deck, int *line_number)
model_name = copy_substring(line, str_ptr1);
str_ptr1 = skip_ws(str_ptr1);
str_ptr2 = skip_back_ws(bool_ptr - 1) + 1;
str_ptr2 = skip_back_ws(bool_ptr);
keep = *str_ptr2;
*str_ptr2 = '\0';
node_str = strdup(str_ptr1);
@ -1017,17 +1017,17 @@ inp_chk_for_multi_in_vcvs(struct line *deck, int *line_number)
fprintf(stderr, "ERROR: mal formed line: %s\n", line);
controlled_exit(EXIT_FAILURE);
}
str_ptr2 = skip_back_ws(str_ptr2 - 1) + 1;
str_ptr2 = skip_back_ws(str_ptr2);
str_ptr1 = skip_ws(str_ptr1 + 1);
if (str_ptr2[-1] == '}') {
str_ptr2--;
while (*str_ptr2 != '{')
str_ptr2--;
xy_str1 = str_ptr2;
str_ptr2 = skip_back_ws(xy_str1 - 1) + 1;
str_ptr2 = skip_back_ws(xy_str1);
} else {
xy_str1 = skip_back_non_ws(str_ptr2 - 1) + 1;
str_ptr2 = skip_back_ws(xy_str1 - 1) + 1;
xy_str1 = skip_back_non_ws(str_ptr2);
str_ptr2 = skip_back_ws(xy_str1);
}
keep = *str_ptr2;
*str_ptr2 = '\0';
@ -1274,15 +1274,15 @@ get_instance_subckt(char *line)
// see if instance has parameters
if (equal_ptr) {
end_ptr = skip_back_ws(equal_ptr - 1) + 1;
end_ptr = skip_back_non_ws(end_ptr - 1) + 1;
end_ptr = skip_back_ws(equal_ptr);
end_ptr = skip_back_non_ws(end_ptr);
} else {
end_ptr = line + strlen(line);
}
end_ptr = skip_back_ws(end_ptr - 1) + 1;
end_ptr = skip_back_ws(end_ptr);
inst_name_ptr = skip_back_non_ws(end_ptr - 1) + 1;
inst_name_ptr = skip_back_non_ws(end_ptr);
return copy_substring(inst_name_ptr, end_ptr);
}
@ -1344,8 +1344,8 @@ get_adevice_model_name(char *line)
{
char *ptr_end, *ptr_beg;
ptr_end = skip_back_ws(line + strlen(line) - 1) + 1;
ptr_beg = skip_back_non_ws(ptr_end - 1) + 1;
ptr_end = skip_back_ws(line + strlen(line));
ptr_beg = skip_back_non_ws(ptr_end);
return copy_substring(ptr_beg, ptr_end);
}
@ -1695,7 +1695,7 @@ inp_fix_ternary_operator_str(char *line, bool all)
// get conditional
question = strchr(str_ptr, '?');
str_ptr2 = skip_back_ws(question - 1) + 1;
str_ptr2 = skip_back_ws(question);
if (str_ptr2[-1] == ')') {
count = 1;
str_ptr = str_ptr2 - 1;
@ -1742,9 +1742,9 @@ inp_fix_ternary_operator_str(char *line, bool all)
fprintf(stderr, "ERROR: problem parsing ternary string (finding ':') %s!\n", line);
controlled_exit(EXIT_FAILURE);
}
str_ptr2 = skip_back_ws(colon - 1) + 1;
str_ptr2 = skip_back_ws(colon);
} else if ((colon = strchr(str_ptr, ':')) != NULL) {
str_ptr2 = skip_back_ws(colon - 1) + 1;
str_ptr2 = skip_back_ws(colon);
} else {
fprintf(stderr, "ERROR: problem parsing ternary string (missing ':') %s!\n", line);
controlled_exit(EXIT_FAILURE);
@ -2041,8 +2041,8 @@ inp_fix_subckt(char *s)
/* go to beginning of first parameter word */
/* s will contain only subckt definition */
/* beg will point to start of param list */
beg = skip_back_ws(equal - 1) + 1;
beg = skip_back_non_ws(beg - 1) + 1;
beg = skip_back_ws(equal);
beg = skip_back_non_ws(beg);
beg[-1] = '\0';
head = alloc(struct line);
@ -2052,8 +2052,8 @@ inp_fix_subckt(char *s)
/* alternative patch to cope with spaces:
get expression between braces {...} */
ptr2 = skip_ws(ptr1 + 1);
ptr1 = skip_back_ws(ptr1 - 1) + 1;
ptr1 = skip_back_non_ws(ptr1 - 1) + 1;
ptr1 = skip_back_ws(ptr1);
ptr1 = skip_back_non_ws(ptr1);
/* ptr1 points to beginning of parameter */
/* if parameter is an expression and starts with '{', find closing '}'
@ -2415,14 +2415,14 @@ inp_get_subckt_name(char *s)
char *subckt_name, *end_ptr = strchr(s, '=');
if (end_ptr) {
end_ptr = skip_back_ws(end_ptr - 1) + 1;
end_ptr = skip_back_non_ws(end_ptr - 1) + 1;
end_ptr = skip_back_ws(end_ptr);
end_ptr = skip_back_non_ws(end_ptr);
} else {
end_ptr = s + strlen(s);
}
end_ptr = skip_back_ws(end_ptr - 1) + 1;
subckt_name = skip_back_non_ws(end_ptr - 1) + 1;
end_ptr = skip_back_ws(end_ptr);
subckt_name = skip_back_non_ws(end_ptr);
return copy_substring(subckt_name, end_ptr);
}
@ -2454,8 +2454,8 @@ inp_get_params(char *line, char *param_names[], char *param_values[])
is_expression = FALSE;
/* get parameter name */
end = skip_back_ws(equal_ptr - 1) + 1;
name = skip_back_non_ws(end - 1) + 1;
end = skip_back_ws(equal_ptr);
name = skip_back_non_ws(end);
param_names[num_params++] = copy_substring(name, end);
@ -2505,8 +2505,8 @@ inp_fix_inst_line(char *inst_line,
end = strchr(inst_line, '=');
if (end) {
end = skip_back_ws(end - 1) + 1;
end = skip_back_non_ws(end - 1) + 1;
end = skip_back_ws(end);
end = skip_back_non_ws(end);
end[-1] = '\0';
}
@ -3424,7 +3424,7 @@ get_param_name(char *line)
char keep;
if ((equal_ptr = strchr(line, '=')) != NULL) {
equal_ptr = skip_back_ws(equal_ptr - 1) + 1;
equal_ptr = skip_back_ws(equal_ptr);
beg = equal_ptr - 1;
while (!isspace(*beg) && beg != line)
@ -4054,8 +4054,8 @@ inp_split_multi_param_lines(struct line *deck, int line_num)
continue;
}
beg_param = skip_back_ws(equal_ptr - 1) + 1;
beg_param = skip_back_non_ws(beg_param - 1) + 1;
beg_param = skip_back_ws(equal_ptr);
beg_param = skip_back_non_ws(beg_param);
end_param = skip_ws(equal_ptr + 1);
while (*end_param != '\0' && (!isspace(*end_param) || get_expression || get_paren_expression)) {
if (*end_param == '{')