Mercurial > octave
comparison src/variables.cc @ 1277:db4f4009d6e8
[project @ 1995-04-24 20:35:06 by jwe]
author | jwe |
---|---|
date | Mon, 24 Apr 1995 20:35:06 +0000 |
parents | ffecaa9b9892 |
children | fcdf6c5d0302 |
comparison
equal
deleted
inserted
replaced
1276:cbdf7db98554 | 1277:db4f4009d6e8 |
---|---|
222 { | 222 { |
223 print_usage ("exist"); | 223 print_usage ("exist"); |
224 return retval; | 224 return retval; |
225 } | 225 } |
226 | 226 |
227 char *name = args(0).string_value (); | 227 char *name = strsave (args(0).string_value ()); |
228 | 228 |
229 if (error_state) | 229 if (error_state) |
230 { | 230 { |
231 error ("exist: expecting string argument"); | 231 error ("exist: expecting string argument"); |
232 delete [] name; | |
232 return retval; | 233 return retval; |
234 } | |
235 | |
236 char *struct_elts = strchr (name, '.'); | |
237 if (struct_elts) | |
238 { | |
239 *struct_elts = '\0'; | |
240 struct_elts++; | |
233 } | 241 } |
234 | 242 |
235 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); | 243 symbol_record *sr = curr_sym_tab->lookup (name, 0, 0); |
236 if (! sr) | 244 if (! sr) |
237 sr = global_sym_tab->lookup (name, 0, 0); | 245 sr = global_sym_tab->lookup (name, 0, 0); |
238 | 246 |
239 retval = 0.0; | 247 retval = 0.0; |
240 | 248 |
241 if (sr && sr->is_variable () && sr->is_defined ()) | 249 if (sr && sr->is_variable () && sr->is_defined ()) |
242 retval = 1.0; | 250 { |
251 retval = 1.0; | |
252 tree_fvc *def = sr->def (); | |
253 if (struct_elts) | |
254 { | |
255 retval = 0.0; | |
256 if (def->is_constant ()) | |
257 { | |
258 tree_constant *tmp = (tree_constant *) def; | |
259 tree_constant ult; | |
260 ult = tmp->lookup_map_element (struct_elts, 0, 1); | |
261 if (ult.is_defined ()) | |
262 retval = 1.0; | |
263 } | |
264 } | |
265 } | |
243 else if (sr && sr->is_function ()) | 266 else if (sr && sr->is_function ()) |
244 retval = 2.0; | 267 retval = 2.0; |
245 else | 268 else |
246 { | 269 { |
247 char *path = fcn_file_in_path (name); | 270 char *path = fcn_file_in_path (name); |
255 struct stat buf; | 278 struct stat buf; |
256 if (stat (name, &buf) == 0 && S_ISREG (buf.st_mode)) | 279 if (stat (name, &buf) == 0 && S_ISREG (buf.st_mode)) |
257 retval = 2.0; | 280 retval = 2.0; |
258 } | 281 } |
259 } | 282 } |
283 | |
284 delete [] name; | |
260 | 285 |
261 return retval; | 286 return retval; |
262 } | 287 } |
263 | 288 |
264 // XXX FIXME XXX -- should these really be here? | 289 // XXX FIXME XXX -- should these really be here? |