| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflenv.h" char ** symb2env ( const SYMTAB *symtab)
Returns an environment block from the supplied symbol table. The returned block is an array of strings, terminated by a null pointer. Each string is allocated independently using mem_alloc(). Returns NULL if there was not enough memory to allocate the block. Normalises the environment variable names as follows: converts all letters to uppercase, and non- alphanumeric characters to underlines. To free the array, use strtfree(). See also symb2strt().
{ MEMTRN *memtrn; /* Memory transation */ SYMBOL *symbol; /* Pointer to symbol */ char **strings, /* Returned string array */ *name_and_value, /* Name=value string */ *nameptr; /* Pointer into name */ 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 */ memtrn = mem new trans (); strings = memt_alloc (memtrn, 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 = memt_alloc (memtrn, (strlen (symbol-> name) + strlen (symbol-> value) + 2)); if (!name_and_value) /* Quit if no memory left */ { mem rollback (memtrn); return (NULL); } /* Get symbol name in uppercase, using underlines */ strcpy (name_and_value, symbol-> name); for (nameptr = name_and_value; *nameptr; nameptr++) if (isalnum (*nameptr)) *nameptr = toupper (*nameptr); else *nameptr = '_'; strcat (name_and_value, "="); strcat (name_and_value, symbol-> value); strings [string_nbr++] = name_and_value; } strings [string_nbr] = NULL; /* Store final null pointer */ } mem commit (memtrn); return (strings); }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |