Locate a variable by name; returns NULL if unknown */
| 1432 | |
| 1433 | /* Locate a variable by name; returns NULL if unknown */ |
| 1434 | static Variable * |
| 1435 | lookupVariable(CState *st, char *name) |
| 1436 | { |
| 1437 | Variable key; |
| 1438 | |
| 1439 | /* On some versions of Solaris, bsearch of zero items dumps core */ |
| 1440 | if (st->nvariables <= 0) |
| 1441 | return NULL; |
| 1442 | |
| 1443 | /* Sort if we have to */ |
| 1444 | if (!st->vars_sorted) |
| 1445 | { |
| 1446 | qsort((void *) st->variables, st->nvariables, sizeof(Variable), |
| 1447 | compareVariableNames); |
| 1448 | st->vars_sorted = true; |
| 1449 | } |
| 1450 | |
| 1451 | /* Now we can search */ |
| 1452 | key.name = name; |
| 1453 | return (Variable *) bsearch((void *) &key, |
| 1454 | (void *) st->variables, |
| 1455 | st->nvariables, |
| 1456 | sizeof(Variable), |
| 1457 | compareVariableNames); |
| 1458 | } |
| 1459 | |
| 1460 | /* Get the value of a variable, in string form; returns NULL if unknown */ |
| 1461 | static char * |
no outgoing calls
no test coverage detected