3 * $Id: sw_env.h,v 1.2 1999/07/27 13:38:27 mdw Exp $
5 * Mangling of environment variables
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of sw-tools.
14 * sw-tools is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * sw-tools is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with sw-tools; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.2 1999/07/27 13:38:27 mdw
33 * Cauterized out the low-level environment operations and put them in
36 * Revision 1.1.1.1 1999/06/02 16:53:35 mdw
48 /*----- Header files ------------------------------------------------------*/
52 #include <mLib/dstr.h>
56 /*----- Important constants -----------------------------------------------*/
59 ENV_OK
= 0, /* Parsed OK */
60 ENV_EOF
, /* End-of-file encountered */
61 ENV_VCHAR
, /* Bad character in variable name */
62 ENV_SUBST
, /* Bad parameter substitution */
63 ENV_QUOTE
, /* Mismatched quote */
64 ENV_BRACE
, /* Missing brace character */
65 ENV_SYSTEM
, /* System error (see @errno@) */
66 ENV_INTERNAL
/* Internal error */
70 EVF_INCSPC
= 1, /* Allow spaces in values */
71 EVF_BACKTICK
= 2, /* Make backtick self-delimiting */
72 EVF_SKIP
= 4, /* Skipping this section of text */
73 EVF_INITSPC
= 8 /* Allow and ignore leading space */
76 /*----- Functions provided ------------------------------------------------*/
78 /* --- @env_error@ --- *
80 * Arguments: @int e@ = error code
82 * Returns: String representation of error.
84 * Use: Transforms an error into something a user can understand.
87 extern const char *env_error(int /*e*/);
89 /* --- @env_var@ --- *
91 * Arguments: @sym_table *t@ = pointer to symbol table
92 * @FILE *fp@ = pointer to stream to read from
93 * @dstr *d@ = pointer to output variable
95 * Returns: One of the @ENV_@ constants.
97 * Use: Scans a variable name from the input stream.
100 extern int env_var(sym_table */
*t*/
, FILE */
*fp*/
, dstr */
*d*/
);
102 /* --- @env_value@ --- *
104 * Arguments: @sym_table *t@ = pointer to symbol table
105 * @FILE *fp@ = pointer to stream to read from
106 * @dstr *d@ = pointer to output variable
107 * @unsigned f@ = various interesting flags
109 * Returns: 0 if OK, @EOF@ if end-of-file encountered, or >0 on error.
111 * Use: Scans a value from the input stream. The value read may be
112 * quoted in a Bourne-shell sort of a way, and contain Bourne-
113 * shell-like parameter substitutions. Some substitutions
114 * aren't available because they're too awkward to implement.
117 extern int env_value(sym_table */
*t*/
, FILE */
*fp*/
,
118 dstr */
*d*/
, unsigned /*f*/);
120 /* --- @env_read@ --- *
122 * Arguments: @sym_table *t@ = pointer to symbol table
123 * @FILE *fp@ = file handle to read
124 * @unsigned f@ = various flags
126 * Returns: Zero if OK, @EOF@ for end-of-file, or error code.
128 * Use: Reads the environment assignment statements in the file.
131 extern int env_read(sym_table */
*t*/
, FILE */
*fp*/
, unsigned /*f*/);
133 /* --- @env_file@ --- *
135 * Arguments: @sym_table *t@ = pointer to symbol table
136 * @const char *name@ = pointer to filename
138 * Returns: Zero if OK, or an error code.
140 * Use: Reads a named file of environment assignments.
143 extern int env_file(sym_table */
*t*/
, const char */
*name*/
);
145 /*----- That's all, folks -------------------------------------------------*/