Next: , Up: Symbol Table Access   [Contents][Index] Variable Access and Update by Name

The following routines provide the ability to access and update global awk-level variables by name. In compiler terminology, identifiers of different kinds are termed symbols, thus the “sym” in the routines’ names. The data structure which stores information about symbols is termed a symbol table.

awk_bool_t sym_lookup(const char *name,
                      awk_valtype_t wanted,
                      awk_value_t *result);

Fill in the awk_value_t structure pointed to by result with the value of the variable named by the string name, which is a regular C string. wanted indicates the type of value expected. Return true if the actual type matches wanted, false otherwise In the latter case, result->val_type indicates the actual type (see Table 16.1).

awk_bool_t sym_update(const char *name, awk_value_t *value);

Update the variable named by the string name, which is a regular C string. The variable is added to gawk’s symbol table if it is not there. Return true if everything worked, false otherwise.

Changing types (scalar to array or vice versa) of an existing variable is not allowed, nor may this routine be used to update an array. This routine cannot be used to update any of the predefined variables (such as ARGC or NF).

An extension can look up the value of gawk’s special variables. However, with the exception of the PROCINFO array, an extension cannot change any of those variables.

NOTE: It is possible for the lookup of PROCINFO to fail. This happens if the awk program being run does not reference PROCINFO; in this case gawk doesn’t bother to create the array and populate it.

Next: , Up: Symbol Table Access   [Contents][Index]