3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005 Free Software Foundation, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef GRUB_SCRIPT_HEADER
22 #define GRUB_SCRIPT_HEADER 1
24 #include <grub/types.h>
27 struct grub_script_mem
;
29 /* The generic header for each scripting command or structure. */
30 struct grub_script_cmd
32 /* This function is called to execute the command. */
33 grub_err_t (*exec
) (struct grub_script_cmd
*cmd
);
35 /* The next command. This can be used by the parent to form a chain
37 struct grub_script_cmd
*next
;
42 struct grub_script_mem
*mem
;
43 struct grub_script_cmd
*cmd
;
48 GRUB_SCRIPT_ARG_TYPE_STR
,
49 GRUB_SCRIPT_ARG_TYPE_VAR
50 } grub_script_arg_type_t
;
52 /* A part of an argument. */
53 struct grub_script_arg
55 grub_script_arg_type_t type
;
59 /* Next argument part. */
60 struct grub_script_arg
*next
;
63 /* A complete argument. It consists of a list of one or more `struct
65 struct grub_script_arglist
67 struct grub_script_arglist
*next
;
68 struct grub_script_arg
*arg
;
69 /* Only stored in the first link. */
73 /* A single command line. */
74 struct grub_script_cmdline
76 struct grub_script_cmd cmd
;
78 /* The arguments for this command. */
79 struct grub_script_arglist
*arglist
;
81 /* The command name of this command. XXX: Perhaps an argument
82 should be used for this so we can use variables as command
87 /* A block of commands, this can be used to group commands. */
88 struct grub_script_cmdblock
90 struct grub_script_cmd cmd
;
92 /* A chain of commands. */
93 struct grub_script_cmd
*cmdlist
;
96 /* An if statement. */
97 struct grub_script_cmdif
99 struct grub_script_cmd cmd
;
101 /* The command used to check if the if is true or false. */
102 struct grub_script_cmd
*bool;
104 /* The code executed in case the result if bool was true. */
105 struct grub_script_cmd
*true;
107 /* The code executed in case the result if bool was false. */
108 struct grub_script_cmd
*false;
111 /* A menu entry generate statement. */
112 struct grub_script_cmd_menuentry
114 struct grub_script_cmd cmd
;
116 /* The title of the menu entry. */
117 struct grub_script_arg
*title
;
119 /* The sourcecode the entry will be generated from. */
120 const char *sourcecode
;
122 /* Options. XXX: Not used yet. */
126 struct grub_script_arglist
*
127 grub_script_create_arglist (void);
129 struct grub_script_arglist
*
130 grub_script_add_arglist (struct grub_script_arglist
*list
,
131 struct grub_script_arg
*arg
);
132 struct grub_script_cmd
*
133 grub_script_create_cmdline (char *cmdname
,
134 struct grub_script_arglist
*arglist
);
135 struct grub_script_cmd
*
136 grub_script_create_cmdblock (void);
138 struct grub_script_cmd
*
139 grub_script_create_cmdif (struct grub_script_cmd
*bool,
140 struct grub_script_cmd
*true,
141 struct grub_script_cmd
*false);
143 struct grub_script_cmd
*
144 grub_script_create_cmdmenu (struct grub_script_arg
*title
,
148 struct grub_script_cmd
*
149 grub_script_add_cmd (struct grub_script_cmdblock
*cmdblock
,
150 struct grub_script_cmd
*cmd
);
151 struct grub_script_arg
*
152 grub_script_arg_add (struct grub_script_arg
*arg
,
153 grub_script_arg_type_t type
, char *str
);
155 struct grub_script
*grub_script_parse (char *script
,
156 grub_err_t (*getline
) (char **));
157 void grub_script_free (struct grub_script
*script
);
158 struct grub_script
*grub_script_create (struct grub_script_cmd
*cmd
,
159 struct grub_script_mem
*mem
);
161 void grub_script_lexer_init (char *s
, grub_err_t (*getline
) (char **));
162 void grub_script_lexer_ref (void);
163 void grub_script_lexer_deref (void);
164 void grub_script_lexer_record_start (void);
165 char *grub_script_lexer_record_stop (void);
167 /* Functions to track allocated memory. */
168 void *grub_script_malloc (grub_size_t size
);
169 struct grub_script_mem
*grub_script_mem_record (void);
170 struct grub_script_mem
*grub_script_mem_record_stop (struct grub_script_mem
*restore
);
172 /* Functions used by bison. */
173 int grub_script_yylex (void);
174 int grub_script_yyparse (void);
175 void grub_script_yyerror (char const *err
);
177 /* Commands to execute, don't use these directly. */
178 grub_err_t
grub_script_execute_cmdline (struct grub_script_cmd
*cmd
);
179 grub_err_t
grub_script_execute_cmdblock (struct grub_script_cmd
*cmd
);
180 grub_err_t
grub_script_execute_cmdif (struct grub_script_cmd
*cmd
);
181 grub_err_t
grub_script_execute_menuentry (struct grub_script_cmd
*cmd
);
183 /* Execute any GRUB pre-parsed command or script. */
184 grub_err_t
grub_script_execute (struct grub_script
*script
);
186 /* This variable points to the parsed command. This is used to
187 communicate with the bison code. */
188 extern struct grub_script_cmd
*grub_script_parsed
;
192 /* The function description. */
193 struct grub_script_function
198 /* The script function. */
199 struct grub_script
*func
;
204 /* The next element. */
205 struct grub_script_function
*next
;
209 typedef struct grub_script_function
*grub_script_function_t
;
211 grub_script_function_t
grub_script_function_create (char *functionname
,
212 struct grub_script
*cmd
);
213 void grub_script_function_remove (const char *name
);
214 grub_script_function_t
grub_script_function_find (char *functionname
);
215 int grub_script_function_iterate (int (*iterate
) (grub_script_function_t
));
216 int grub_script_function_call (grub_script_function_t func
,
217 int argc
, char **args
);
219 #endif /* ! GRUB_SCRIPT_HEADER */