| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflsymb.h" char ** symb2strt_ ( const SYMTAB *symtab, /* Symbol table to export */ const char *filename, /* Name of source file making call */ size_t lineno) /* Line number in calling source */
Exports the symbol table as an array of strings of the format "name=value". Returns a pointer to the array. The array is allocated dynamically. The array ends with a NULL string. To free the table, call strtfree(). If there was not enough memory to allocate the table, returns NULL. See also symb2env(). Do not call this function directly: pass through the symb2strt macro.
{ SYMBOL *symbol; /* Pointer to symbol */ char **strings, /* Returned string array */ *name_and_value; /* Name=value string */ int string_nbr; /* Index into symbol_array */ if (!symtab) return (NULL); /* Return NULL if argument is null */ /* Allocate the array of pointers with one slot for the final NULL */ strings = mem alloc (NULL, sizeof (char *) * (symtab-> size + 1), filename, lineno); if (strings) { string_nbr = 0; for (symbol = symtab-> symbols; symbol; symbol = symbol-> next) { /* Allocate space for "name=value" plus final null char */ int n_and_v_len = 0; n_and_v_len = strlen (symbol-> name) + strlen (symbol-> value) + 2; name_and_value = mem alloc (NULL, n_and_v_len, filename, lineno); if (name_and_value) /* Fail-safe if no memory left */ snprintf (name_and_value, n_and_v_len, "%s=%s", symbol-> name, symbol-> value); strings [string_nbr++] = name_and_value; } strings [string_nbr] = NULL; /* Store final null pointer */ } return (strings); }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |