chiark / gitweb /
Cauterized out the low-level environment operations and put them in
[sw-tools] / src / sw_env.h
1 /* -*-c-*-
2  *
3  * $Id: sw_env.h,v 1.2 1999/07/27 13:38:27 mdw Exp $
4  *
5  * Mangling of environment variables
6  *
7  * (c) 1999 EBI
8  */
9
10 /*----- Licensing notice --------------------------------------------------* 
11  *
12  * This file is part of sw-tools.
13  *
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.
18  * 
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.
23  * 
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.
27  */
28
29 /*----- Revision history --------------------------------------------------* 
30  *
31  * $Log: sw_env.h,v $
32  * Revision 1.2  1999/07/27 13:38:27  mdw
33  * Cauterized out the low-level environment operations and put them in
34  * mLib.
35  *
36  * Revision 1.1.1.1  1999/06/02  16:53:35  mdw
37  * Initial import.
38  *
39  */
40
41 #ifndef SW_ENV_H
42 #define SW_ENV_H
43
44 #ifdef __cplusplus
45   extern "C" {
46 #endif
47
48 /*----- Header files ------------------------------------------------------*/
49
50 #include <stdio.h>
51
52 #include <mLib/dstr.h>
53 #include <mLib/env.h>
54 #include <mLib/sym.h>
55
56 /*----- Important constants -----------------------------------------------*/
57
58 enum {
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 */
67 };
68
69 enum {
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 */
74 };
75
76 /*----- Functions provided ------------------------------------------------*/
77
78 /* --- @env_error@ --- *
79  *
80  * Arguments:   @int e@ = error code
81  *
82  * Returns:     String representation of error.
83  *
84  * Use:         Transforms an error into something a user can understand.
85  */
86
87 extern const char *env_error(int /*e*/);
88
89 /* --- @env_var@ --- *
90  *
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
94  *
95  * Returns:     One of the @ENV_@ constants.
96  *
97  * Use:         Scans a variable name from the input stream.
98  */
99
100 extern int env_var(sym_table */*t*/, FILE */*fp*/, dstr */*d*/);
101
102 /* --- @env_value@ --- *
103  *
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
108  *
109  * Returns:     0 if OK, @EOF@ if end-of-file encountered, or >0 on error.
110  *
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.
115  */
116
117 extern int env_value(sym_table */*t*/, FILE */*fp*/,
118                      dstr */*d*/, unsigned /*f*/);
119
120 /* --- @env_read@ --- *
121  *
122  * Arguments:   @sym_table *t@ = pointer to symbol table
123  *              @FILE *fp@ = file handle to read
124  *              @unsigned f@ = various flags
125  *
126  * Returns:     Zero if OK, @EOF@ for end-of-file, or error code.
127  *
128  * Use:         Reads the environment assignment statements in the file.
129  */
130
131 extern int env_read(sym_table */*t*/, FILE */*fp*/, unsigned /*f*/);
132
133 /* --- @env_file@ --- *
134  *
135  * Arguments:   @sym_table *t@ = pointer to symbol table
136  *              @const char *name@ = pointer to filename
137  *
138  * Returns:     Zero if OK, or an error code.
139  *
140  * Use:         Reads a named file of environment assignments.
141  */
142
143 extern int env_file(sym_table */*t*/, const char */*name*/);
144
145 /*----- That's all, folks -------------------------------------------------*/
146
147 #ifdef __cplusplus
148   }
149 #endif
150
151 #endif