| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Fiddling with environment variables |
| 4 | * |
| 5 | * (c) 1999 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 9 | * |
| 10 | * This file is part of the mLib utilities library. |
| 11 | * |
| 12 | * mLib is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU Library General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of the |
| 15 | * License, or (at your option) any later version. |
| 16 | * |
| 17 | * mLib is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU Library General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Library General Public |
| 23 | * License along with mLib; if not, write to the Free |
| 24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 25 | * MA 02111-1307, USA. |
| 26 | */ |
| 27 | |
| 28 | #ifndef MLIB_ENV_H |
| 29 | #define MLIB_ENV_H |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | /*----- Header files ------------------------------------------------------*/ |
| 36 | |
| 37 | #ifndef MLIB_SYM_H |
| 38 | # include "sym.h" |
| 39 | #endif |
| 40 | |
| 41 | /*----- Functions provided ------------------------------------------------*/ |
| 42 | |
| 43 | /* --- @env_get@ --- * |
| 44 | * |
| 45 | * Arguments: @sym_table *t@ = pointer to a symbol table |
| 46 | * @const char *name@ = pointer to variable name to look up |
| 47 | * |
| 48 | * Returns: Pointer to corresponding value string, or null. |
| 49 | * |
| 50 | * Use: Looks up an environment variable in the table and returns its |
| 51 | * value. If the variable can't be found, a null pointer is |
| 52 | * returned. |
| 53 | */ |
| 54 | |
| 55 | extern char *env_get(sym_table */*t*/, const char */*name*/); |
| 56 | |
| 57 | /* --- @env_put@ --- * |
| 58 | * |
| 59 | * Arguments: @sym_table *t@ = pointer to a symbol table |
| 60 | * @const char *name@ = pointer to variable name to set |
| 61 | * @const char *value@ = pointer to value string to assign |
| 62 | * |
| 63 | * Returns: --- |
| 64 | * |
| 65 | * Use: Assigns a value to a variable. If the @name@ contains an |
| 66 | * equals character, then it's assumed to be of the form |
| 67 | * `VAR=VALUE' and @value@ argument is ignored. Otherwise, if |
| 68 | * @value@ is null, the variable is deleted. Finally, the |
| 69 | * normal case: @name@ is a plain name, and @value@ is a normal |
| 70 | * string causes the variable to be assigned the value in the |
| 71 | * way you'd expect. |
| 72 | */ |
| 73 | |
| 74 | extern void env_put(sym_table */*t*/, |
| 75 | const char */*name*/, const char */*value*/); |
| 76 | |
| 77 | /* --- @env_import@ --- * |
| 78 | * |
| 79 | * Arguments: @sym_table *t@ = pointer to a symbol table |
| 80 | * @char **env@ = pointer to an environment list |
| 81 | * |
| 82 | * Returns: --- |
| 83 | * |
| 84 | * Use: Inserts all of the environment variables listed into a symbol |
| 85 | * table for rapid access. Equivalent to a lot of calls to |
| 86 | * @env_put@. |
| 87 | */ |
| 88 | |
| 89 | extern void env_import(sym_table */*t*/, char **/*env*/); |
| 90 | |
| 91 | /* --- @env_export@ --- * |
| 92 | * |
| 93 | * Arguments: @sym_table *t@ = pointer to a symbol table |
| 94 | * |
| 95 | * Returns: A big environment list. |
| 96 | * |
| 97 | * Use: Extracts an environment table from a symbol table |
| 98 | * representation of an environment. The table and all of the |
| 99 | * strings are in one big block allocated from the heap. |
| 100 | */ |
| 101 | |
| 102 | extern char **env_export(sym_table */*t*/); |
| 103 | |
| 104 | /* --- @env_destroy@ --- * |
| 105 | * |
| 106 | * Arguments: @sym_table *t@ = pointer to symbol table |
| 107 | * |
| 108 | * Returns: --- |
| 109 | * |
| 110 | * Use: Destroys all the variables in the symbol table. |
| 111 | */ |
| 112 | |
| 113 | extern void env_destroy(sym_table */*t*/); |
| 114 | |
| 115 | /*----- That's all, folks -------------------------------------------------*/ |
| 116 | |
| 117 | #ifdef __cplusplus |
| 118 | } |
| 119 | #endif |
| 120 | |
| 121 | #endif |