1 /* Yash: yet another shell */
2 /* variable.h: deals with shell variables and parameters */
3 /* (C) 2007-2020 magicant */
4 
5 /* This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17 
18 
19 #ifndef YASH_VARIABLE_H
20 #define YASH_VARIABLE_H
21 
22 #include <stddef.h>
23 #include "xgetopt.h"
24 
25 
26 extern char **environ;
27 
28 /* variable names */
29 #define VAR_CDPATH                    "CDPATH"
30 #define VAR_COLUMNS                   "COLUMNS"
31 #define VAR_COMMAND_NOT_FOUND_HANDLER "COMMAND_NOT_FOUND_HANDLER"
32 #define VAR_DIRSTACK                  "DIRSTACK"
33 #define VAR_ECHO_STYLE                "ECHO_STYLE"
34 #define VAR_ENV                       "ENV"
35 #define VAR_FCEDIT                    "FCEDIT"
36 #define VAR_HANDLED                   "HANDLED"
37 #define VAR_HISTFILE                  "HISTFILE"
38 #define VAR_HISTRMDUP                 "HISTRMDUP"
39 #define VAR_HISTSIZE                  "HISTSIZE"
40 #define VAR_HOME                      "HOME"
41 #define VAR_IFS                       "IFS"
42 #define VAR_LANG                      "LANG"
43 #define VAR_LC_ALL                    "LC_ALL"
44 #define VAR_LC_COLLATE                "LC_COLLATE"
45 #define VAR_LC_CTYPE                  "LC_CTYPE"
46 #define VAR_LC_MESSAGES               "LC_MESSAGES"
47 #define VAR_LC_MONETARY               "LC_MONETARY"
48 #define VAR_LC_NUMERIC                "LC_NUMERIC"
49 #define VAR_LC_TIME                   "LC_TIME"
50 #define VAR_LINENO                    "LINENO"
51 #define VAR_LINES                     "LINES"
52 #define VAR_MAIL                      "MAIL"
53 #define VAR_MAILCHECK                 "MAILCHECK"
54 #define VAR_MAILPATH                  "MAILPATH"
55 #define VAR_NLSPATH                   "NLSPATH"
56 #define VAR_OLDPWD                    "OLDPWD"
57 #define VAR_OPTARG                    "OPTARG"
58 #define VAR_OPTIND                    "OPTIND"
59 #define VAR_PATH                      "PATH"
60 #define VAR_PPID                      "PPID"
61 #define VAR_PROMPT_COMMAND            "PROMPT_COMMAND"
62 #define VAR_PS1                       "PS1"
63 #define VAR_PS2                       "PS2"
64 #define VAR_PS4                       "PS4"
65 #define VAR_PWD                       "PWD"
66 #define VAR_RANDOM                    "RANDOM"
67 #define VAR_TARGETWORD                "TARGETWORD"
68 #define VAR_TERM                      "TERM"
69 #define VAR_WORDS                     "WORDS"
70 #define VAR_YASH_AFTER_CD             "YASH_AFTER_CD"
71 #define VAR_YASH_LE_TIMEOUT           "YASH_LE_TIMEOUT"
72 #define VAR_YASH_LOADPATH             "YASH_LOADPATH"
73 #define VAR_YASH_VERSION              "YASH_VERSION"
74 #define L                             L""
75 
76 struct variable_T;
77 struct assign_T;
78 struct command_T;
79 
80 typedef enum path_T {
81     PA_PATH, PA_CDPATH, PA_LOADPATH,
82     PA_count,
83 } path_T;
84 
85 extern void init_environment(void);
86 extern void init_variables(void);
87 
88 extern char *get_exported_value(const wchar_t *name)
89     __attribute__((nonnull,malloc,warn_unused_result));
90 
91 typedef enum scope_T {
92     SCOPE_GLOBAL, SCOPE_LOCAL, SCOPE_TEMP,
93 } scope_T;
94 extern _Bool set_variable(
95 	const wchar_t *name, wchar_t *value, scope_T scope, _Bool export)
96     __attribute__((nonnull(1)));
97 extern struct variable_T *set_array(
98 	const wchar_t *name, size_t count, void **values,
99 	scope_T scope, _Bool export)
100     __attribute__((nonnull));
101 extern _Bool set_array_element(
102 	const wchar_t *name, size_t index, wchar_t *value)
103     __attribute__((nonnull));
104 extern void set_positional_parameters(void *const *values)
105     __attribute__((nonnull));
106 extern _Bool do_assignments(
107 	const struct assign_T *assigns, _Bool temp, _Bool export);
108 
109 struct get_variable_T {
110     enum { GV_NOTFOUND, GV_SCALAR, GV_ARRAY, GV_ARRAY_CONCAT, } type;
111     size_t count;
112     void **values;
113     _Bool freevalues;
114 };
115 extern const wchar_t *getvar(const wchar_t *name)
116     __attribute__((pure,nonnull));
117 extern struct get_variable_T get_variable(const wchar_t *name)
118     __attribute__((nonnull,warn_unused_result));
119 extern void save_get_variable_values(struct get_variable_T *gv)
120     __attribute__((nonnull));
121 
122 extern void open_new_environment(_Bool temp);
123 extern void close_current_environment(void);
124 
125 extern void update_lineno(unsigned long lineno);
126 
127 extern char **decompose_paths(const wchar_t *paths)
128     __attribute__((malloc,warn_unused_result));
129 extern char *const *get_path_array(path_T name);
130 
131 extern _Bool define_function(const wchar_t *name, struct command_T *body)
132     __attribute__((nonnull));
133 extern struct command_T *get_function(const wchar_t *name)
134     __attribute__((nonnull));
135 
136 #if YASH_ENABLE_DIRSTACK
137 extern _Bool parse_dirstack_index(
138 	const wchar_t *restrict indexstr, size_t *restrict indexp,
139 	const wchar_t **restrict entryp, _Bool printerror)
140     __attribute__((nonnull));
141 #endif
142 
143 extern int typeset_builtin(int argc, void **argv)
144     __attribute__((nonnull));
145 #if YASH_ENABLE_HELP
146 extern const char typeset_help[], typeset_syntax[], export_help[],
147        export_syntax[], local_help[], local_syntax[], readonly_help[],
148        readonly_syntax[];
149 #endif
150 extern const struct xgetopt_T typeset_options[];
151 #define local_options (&typeset_options[2])
152 
153 extern int array_builtin(int argc, void **argv)
154     __attribute__((nonnull));
155 #if YASH_ENABLE_HELP
156 extern const char array_help[], array_syntax[];
157 #endif
158 extern const struct xgetopt_T array_options[];
159 
160 extern int unset_builtin(int argc, void **argv)
161     __attribute__((nonnull));
162 #if YASH_ENABLE_HELP
163 extern const char unset_help[], unset_syntax[];
164 #endif
165 extern const struct xgetopt_T unset_options[];
166 
167 extern int shift_builtin(int argc, void **argv)
168     __attribute__((nonnull));
169 #if YASH_ENABLE_HELP
170 extern const char shift_help[], shift_syntax[];
171 #endif
172 extern const struct xgetopt_T shift_options[];
173 
174 extern int getopts_builtin(int argc, void **argv)
175     __attribute__((nonnull));
176 #if YASH_ENABLE_HELP
177 extern const char getopts_help[], getopts_syntax[];
178 #endif
179 
180 extern int read_builtin(int argc, void **argv)
181     __attribute__((nonnull));
182 #if YASH_ENABLE_HELP
183 extern const char read_help[], read_syntax[];
184 #endif
185 extern const struct xgetopt_T read_options[];
186 
187 extern int pushd_builtin(int argc, void **argv)
188     __attribute__((nonnull));
189 #if YASH_ENABLE_HELP
190 extern const char pushd_help[], pushd_syntax[];
191 #endif
192 extern const struct xgetopt_T pushd_options[];
193 #if YASH_ENABLE_DIRSTACK
194 # define cd_options  (&pushd_options[1])
195 # define pwd_options (&pushd_options[2])
196 #else
197 # define cd_options  pushd_options
198 # define pwd_options (&pushd_options[1])
199 #endif
200 
201 extern int popd_builtin(int argc, void **argv)
202     __attribute__((nonnull));
203 #if YASH_ENABLE_HELP
204 extern const char popd_help[], popd_syntax[];
205 #endif
206 
207 extern int dirs_builtin(int argc, void **argv)
208     __attribute__((nonnull));
209 #if YASH_ENABLE_HELP
210 extern const char dirs_help[], dirs_syntax[];
211 #endif
212 extern const struct xgetopt_T dirs_options[];
213 
214 
215 #endif /* YASH_VARIABLE_H */
216 
217 
218 /* vim: set ts=8 sts=4 sw=4 noet tw=80: */
219