usage: Print metavariables in SHOUTY letters.
[sw-tools] / src / sw_env.h
CommitLineData
3315e8b3 1/* -*-c-*-
2 *
9796a787 3 * $Id: sw_env.h,v 1.3 2004/04/08 01:52:19 mdw Exp $
3315e8b3 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
3315e8b3 29#ifndef SW_ENV_H
30#define SW_ENV_H
31
32#ifdef __cplusplus
33 extern "C" {
34#endif
35
36/*----- Header files ------------------------------------------------------*/
37
38#include <stdio.h>
39
40#include <mLib/dstr.h>
436d5c73 41#include <mLib/env.h>
3315e8b3 42#include <mLib/sym.h>
43
44/*----- Important constants -----------------------------------------------*/
45
46enum {
47 ENV_OK = 0, /* Parsed OK */
48 ENV_EOF, /* End-of-file encountered */
49 ENV_VCHAR, /* Bad character in variable name */
50 ENV_SUBST, /* Bad parameter substitution */
51 ENV_QUOTE, /* Mismatched quote */
52 ENV_BRACE, /* Missing brace character */
53 ENV_SYSTEM, /* System error (see @errno@) */
54 ENV_INTERNAL /* Internal error */
55};
56
57enum {
58 EVF_INCSPC = 1, /* Allow spaces in values */
59 EVF_BACKTICK = 2, /* Make backtick self-delimiting */
60 EVF_SKIP = 4, /* Skipping this section of text */
61 EVF_INITSPC = 8 /* Allow and ignore leading space */
62};
63
64/*----- Functions provided ------------------------------------------------*/
65
3315e8b3 66/* --- @env_error@ --- *
67 *
68 * Arguments: @int e@ = error code
69 *
70 * Returns: String representation of error.
71 *
72 * Use: Transforms an error into something a user can understand.
73 */
74
75extern const char *env_error(int /*e*/);
76
77/* --- @env_var@ --- *
78 *
79 * Arguments: @sym_table *t@ = pointer to symbol table
80 * @FILE *fp@ = pointer to stream to read from
81 * @dstr *d@ = pointer to output variable
82 *
83 * Returns: One of the @ENV_@ constants.
84 *
85 * Use: Scans a variable name from the input stream.
86 */
87
88extern int env_var(sym_table */*t*/, FILE */*fp*/, dstr */*d*/);
89
90/* --- @env_value@ --- *
91 *
92 * Arguments: @sym_table *t@ = pointer to symbol table
93 * @FILE *fp@ = pointer to stream to read from
94 * @dstr *d@ = pointer to output variable
95 * @unsigned f@ = various interesting flags
96 *
97 * Returns: 0 if OK, @EOF@ if end-of-file encountered, or >0 on error.
98 *
99 * Use: Scans a value from the input stream. The value read may be
100 * quoted in a Bourne-shell sort of a way, and contain Bourne-
101 * shell-like parameter substitutions. Some substitutions
102 * aren't available because they're too awkward to implement.
103 */
104
105extern int env_value(sym_table */*t*/, FILE */*fp*/,
106 dstr */*d*/, unsigned /*f*/);
107
108/* --- @env_read@ --- *
109 *
110 * Arguments: @sym_table *t@ = pointer to symbol table
111 * @FILE *fp@ = file handle to read
112 * @unsigned f@ = various flags
113 *
114 * Returns: Zero if OK, @EOF@ for end-of-file, or error code.
115 *
116 * Use: Reads the environment assignment statements in the file.
117 */
118
119extern int env_read(sym_table */*t*/, FILE */*fp*/, unsigned /*f*/);
120
121/* --- @env_file@ --- *
122 *
123 * Arguments: @sym_table *t@ = pointer to symbol table
124 * @const char *name@ = pointer to filename
125 *
126 * Returns: Zero if OK, or an error code.
127 *
128 * Use: Reads a named file of environment assignments.
129 */
130
131extern int env_file(sym_table */*t*/, const char */*name*/);
132
133/*----- That's all, folks -------------------------------------------------*/
134
135#ifdef __cplusplus
136 }
137#endif
138
139#endif