summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Larson <slioch@eng-140.vyatta.com>2008-07-01 13:57:11 -0700
committerMichael Larson <slioch@eng-140.vyatta.com>2008-07-01 13:57:11 -0700
commitf1a011418dd1c6067655a5293ac0a943a2137924 (patch)
tree4271235952e89f65164a3e61c8672e011bbf1654
parent89690fab7e1b49ab8a97a5c9907982bec45e85d5 (diff)
parent4fd96a54d3c4c523ee9df1d6999f95142c68c5f4 (diff)
downloadvyatta-cfg-f1a011418dd1c6067655a5293ac0a943a2137924.tar.gz
vyatta-cfg-f1a011418dd1c6067655a5293ac0a943a2137924.zip
Merge branch 'hollywood' of http://git.vyatta.com/vyatta-cfg into hollywood
-rw-r--r--src/cli_new.c33
-rw-r--r--src/cli_val.h1
2 files changed, 31 insertions, 3 deletions
diff --git a/src/cli_new.c b/src/cli_new.c
index 26cc719..b66d83c 100644
--- a/src/cli_new.c
+++ b/src/cli_new.c
@@ -1926,24 +1926,51 @@ void subtract_values(char **lhs, const char *rhs)
if (lhs == NULL || *lhs == NULL || **lhs == '\0' || rhs == NULL || *rhs == '\0')
return;
+ /* calculate number of rhs entries */
rhs_copy = strdup(rhs);
- length = strlen(rhs) / 2;
+ line = strtok(rhs_copy, "\n\r");
+ while (line != NULL && *line != '\0') {
+ rhs_cnt++;
+ line = strtok(NULL, "\n\r");
+ }
+
+ /* strtok destroys the string. dup again. */
+ free(rhs_copy);
+ rhs_copy = strdup(rhs);
+
+ /* allocate enough space for all old entries (to be subtracted) */
+ length = rhs_cnt * sizeof(char *);
head = ptr = my_malloc(length, "subtract_values list1");
memset(head, 0, length);
+ /* parse the entries and put them in head[] */
line = strtok(rhs_copy, "\n\r");
while (line != NULL && *line != '\0') {
*ptr = line;
ptr++;
- rhs_cnt++;
line = strtok(NULL, "\n\r");
}
- length = strlen(*lhs) / 2;
+ /* calculate number of lhs entries */
+ {
+ char *lhs_copy = strdup(*lhs);
+ line = strtok(lhs_copy, "\n\r");
+ while (line != NULL && *line != '\0') {
+ lhs_cnt++;
+ line = strtok(NULL, "\n\r");
+ }
+ free(lhs_copy);
+ }
+
+ /* allocate enough space for all new entries */
+ length = lhs_cnt * sizeof(char *);
new_head = new_ptr = my_malloc(length, "subtract_values list2");
memset(new_head, 0, length);
+ /* reset length and lhs_cnt. they are now used for the "new" array (i.e.,
+ * after subtraction). */
length = 0;
+ lhs_cnt = 0;
line = strtok(*lhs, "\n\r");
while (line != NULL && *line != '\0') {
for (i = 0; i < rhs_cnt; i++) {
diff --git a/src/cli_val.h b/src/cli_val.h
index 520fa8e..56f6cee 100644
--- a/src/cli_val.h
+++ b/src/cli_val.h
@@ -214,6 +214,7 @@ extern int get_config_lock();
extern int out_fd;
extern FILE *out_stream;
+extern FILE *err_stream;
extern int initialize_output();