-
Notifications
You must be signed in to change notification settings - Fork 0
/
extendVarValue.c
46 lines (39 loc) · 1.05 KB
/
extendVarValue.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "node.h"
#include "defines.h"
bool extendVarValue (struct node *head, char *set_resetName, char *getVarValue, char *extendWith, int extendingPosition)
{
char finalValue[100], extendTemp[100];
// create a node to track the place
struct node *place;
place = head;
// find the value that is needed to extend with
while(TRUE){
if (place == NULL) {
return FALSE;
}
else if (strcmp(place->name,getVarValue) != 0 && place->next == NULL) {
return FALSE;
}
else if (strcmp(place->name,getVarValue) == 0) {
strcpy(finalValue, place->value);
break;
}
else {
place = (node*) nshNext(place);
}
}
// create the new variable value
if (extendingPosition == varValueInFront) {
strcat(finalValue, extendWith);
}
else {//(extendingPosition == varValueInBack)
strcpy(finalValue, (strcat(extendWith, finalValue)));
}
// Insert it into the list (insert OR replace)
extendWith = finalValue;
nshInsert(head, set_resetName, extendWith, VARIABLE);
return TRUE;
}