Changeset 6327
- Timestamp:
- Feb 6, 2006, 11:42:18 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/lib.shell/variable.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/lib.shell/variable.c
r3689 r6327 97 97 } 98 98 99 static char variable_true[] = "1"; 100 static char variable_false[] = "0"; 101 99 102 char *get_variable_ptr (char *name) { 100 103 101 104 int i; 102 105 char *local, *MacroName; 106 107 if (name == NULL) return (NULL); 108 if (*name == 0) return (NULL); 109 110 /* check for the existence of the given name (after ?) */ 111 /* return a string which should not be freed */ 112 if (*name == '?') { 113 value = get_variable_ptr (name[1]); 114 if (value == NULL) { 115 return variable_false; 116 } 117 return variable_true; 118 } 103 119 104 120 MacroName = GetMacroName (); … … 128 144 int i; 129 145 char *local, *MacroName; 146 char *value; 147 148 if (name == NULL) return (NULL); 149 if (*name == 0) return (NULL); 150 151 /* check for the existence of the given name (after ?) */ 152 /* return a string which can be freed */ 153 if (*name == '?') { 154 value = get_variable_ptr (name[1]); 155 if (value == NULL) { 156 value = strcreate (variable_false); 157 return value; 158 } 159 value = strcreate (variable_true); 160 return value; 161 } 130 162 131 163 MacroName = GetMacroName (); … … 149 181 } 150 182 return (NULL); 183 } 184 185 /* return TRUE / FALSE if name is an existant variable */ 186 int get_variable_exists (char *name) { 187 188 int i; 189 char *local, *MacroName; 190 191 MacroName = GetMacroName (); 192 193 /* look for local variable first */ 194 ALLOCATE (local, char, strlen(name) + strlen(MacroName) + 2); 195 sprintf (local, "%s.%s", MacroName, name); 196 for (i = 0; i < Nvariables; i++) { /* find the variable mentioned */ 197 if (!strcmp(local, variables[i].name)) { 198 free (local); 199 return (TRUE); 200 } 201 } 202 free (local); 203 204 /* look for global variable */ 205 for (i = 0; i < Nvariables; i++) { /* find the variable mentioned */ 206 if (!strcmp(name, variables[i].name)) { 207 return (TRUE); 208 } 209 } 210 return (FALSE); 151 211 } 152 212
Note:
See TracChangeset
for help on using the changeset viewer.
