| iMatix home page | << | < | > | >> |
![]() Version 1.91 |
#include "sflsymb.h" char ** symb2strt ( const SYMTAB *symtab) /* Symbol table to export */
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().
{ 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 (sizeof (char *) * (symtab-> size + 1)); if (strings) { string_nbr = 0; for (symbol = symtab-> symbols; symbol; symbol = symbol-> next) { /* Allocate space for "name=value" plus final null char */ name_and_value = mem_alloc (strlen (symbol-> name) + strlen (symbol-> value) + 2); if (name_and_value) /* Fail-safe if no memory left */ sprintf (name_and_value, "%s=%s", symbol-> name, symbol-> value); strings [string_nbr++] = name_and_value; } strings [string_nbr] = NULL; /* Store final null pointer */ } return (strings); }
| << | < | > | >> |
![]() |