*/
#include <grub/mm.h>
+#include <grub/fs.h>
+#include <grub/env.h>
+#include <grub/file.h>
+#include <grub/device.h>
#include <grub/script_sh.h>
+#include <regex.h>
+
+#define ARG_ALLOCATION_UNIT (32 * sizeof (char))
+#define ARGV_ALLOCATION_UNIT (8 * sizeof (void*))
+
+ static unsigned
+ round_up_exp (unsigned v)
+ {
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+
+ if (sizeof (v) > 4)
+ v |= v >> 32;
+
+ v++;
+ v += (v == 0);
+
+ return v;
+ }
+
+static inline int regexop (char ch);
+static char ** merge (char **lhs, char **rhs);
+static char *make_dir (const char *prefix, const char *start, const char *end);
+static int make_regex (const char *regex_start, const char *regex_end,
+ regex_t *regexp);
+static void split_path (char *path, char **suffix_end, char **regex_end);
+static char ** match_devices (const regex_t *regexp);
+static char ** match_files (const char *prefix, const char *suffix_start,
+ const char *suffix_end, const regex_t *regexp);
+static char ** match_paths_with_escaped_suffix (char **paths,
+ const char *suffix_start,
+ const char *suffix_end,
+ const regex_t *regexp);
+static int expand (char *arg, struct grub_script_argv *argv);
+
void
grub_script_argv_free (struct grub_script_argv *argv)
{
return 0;
a = p ? grub_strlen (p) : 0;
- b = grub_strlen (s);
+ b = grub_strlen (s) * (type == APPEND_ESCAPED ? 2 : 1);
- p = grub_realloc (p, ALIGN_UP ((a + b + 1) * sizeof (char),
- ARG_ALLOCATION_UNIT));
+ p = grub_realloc (p, round_up_exp ((a + b + 1) * sizeof (char)));
if (! p)
return 1;