Add const keyword to grub_env_get and gettextize week days.

* grub-core/hook/datehook.c (grub_datetime_names): Make const.
	(grub_read_hook_datetime): Return const char *.
	* grub-core/kern/env.c (grub_env_get): Return const char *. All users
	updated.
	* grub-core/normal/datetime.c (grub_weekday_names): Make const.
	Mark for gettext.
	(grub_get_weekday_name): Return const char *. Call gettext.
	* grub-core/script/argv.c (grub_script_argv_append): Receive const
	char * and len as the argument. All users updated.
	(grub_script_argv_split_append): Receive const char *.
	* include/grub/datetime.h (grub_get_weekday_name): Update proto.
	* include/grub/env.h (grub_env_get): Likewise.
	(grub_env_read_hook_t): Return const char *.
	* include/grub/script_sh.h (grub_script_argv_append): Update proto.
	(grub_script_argv_split_append): Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2011-11-11 20:34:37 +01:00
parent 9aed8a7178
commit d35d0d3753
20 changed files with 91 additions and 64 deletions

View file

@ -1,3 +1,23 @@
2011-11-11 Vladimir Serbinenko <phcoder@gmail.com>
Add const keyword to grub_env_get and gettextize week days.
* grub-core/hook/datehook.c (grub_datetime_names): Make const.
(grub_read_hook_datetime): Return const char *.
* grub-core/kern/env.c (grub_env_get): Return const char *. All users
updated.
* grub-core/normal/datetime.c (grub_weekday_names): Make const.
Mark for gettext.
(grub_get_weekday_name): Return const char *. Call gettext.
* grub-core/script/argv.c (grub_script_argv_append): Receive const
char * and len as the argument. All users updated.
(grub_script_argv_split_append): Receive const char *.
* include/grub/datetime.h (grub_get_weekday_name): Update proto.
* include/grub/env.h (grub_env_get): Likewise.
(grub_env_read_hook_t): Return const char *.
* include/grub/script_sh.h (grub_script_argv_append): Update proto.
(grub_script_argv_split_append): Likewise.
2011-11-11 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/main.c (grub_normal_execute): Remove leftover call.

View file

@ -363,7 +363,7 @@ uninstall_int13_handler (void)
static int
grub_get_root_biosnumber_drivemap (void)
{
char *biosnum;
const char *biosnum;
int ret = -1;
grub_device_t dev;

View file

@ -344,7 +344,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)),
int bsd_part = -1;
{
grub_device_t dev;
char *hdbiasstr;
const char *hdbiasstr;
int hdbias = 0;
hdbiasstr = grub_env_get ("legacy_hdbias");
if (hdbiasstr)

View file

@ -43,7 +43,7 @@ open_envblk_file (char *filename)
if (! filename)
{
char *prefix;
const char *prefix;
prefix = grub_env_get ("prefix");
if (prefix)
@ -346,7 +346,7 @@ grub_cmd_save_env (grub_extcmd_context_t ctxt, int argc, char **args)
while (argc)
{
char *value;
const char *value;
value = grub_env_get (args[0]);
if (value)

View file

@ -436,7 +436,7 @@ wildcard_expand (const char *s, char ***strs)
else if (*start == '/') /* no device part */
{
char *root;
const char *root;
char *prefix;
root = grub_env_get ("root");

View file

@ -294,7 +294,7 @@ grub_mofile_open_lang (const char *locale_dir, const char *locale)
static void
grub_gettext_init_ext (const char *locale)
{
char *locale_dir;
const char *locale_dir;
if (!locale)
return;

View file

@ -26,7 +26,7 @@
GRUB_MOD_LICENSE ("GPLv3+");
static char *grub_datetime_names[] =
static const char *grub_datetime_names[] =
{
"YEAR",
"MONTH",
@ -37,7 +37,7 @@ static char *grub_datetime_names[] =
"WEEKDAY",
};
static char *
static const char *
grub_read_hook_datetime (struct grub_env_var *var,
const char *val __attribute__ ((unused)))
{

View file

@ -697,7 +697,7 @@ grub_dl_load (const char *name)
{
char *filename;
grub_dl_t mod;
char *grub_dl_dir = grub_env_get ("prefix");
const char *grub_dl_dir = grub_env_get ("prefix");
mod = grub_dl_get (name);
if (mod)

View file

@ -132,7 +132,7 @@ grub_env_set (const char *name, const char *val)
return grub_errno;
}
char *
const char *
grub_env_get (const char *name)
{
struct grub_env_var *var;

View file

@ -123,7 +123,7 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
void add_var (grub_parser_state_t newstate)
{
char *val;
const char *val;
/* Check if a variable was being read in and the end of the name
was reached. */

View file

@ -24,7 +24,7 @@
static int
grub_get_root_biosnumber_default (void)
{
char *biosnum;
const char *biosnum;
int ret = -1;
grub_device_t dev;

View file

@ -320,7 +320,7 @@ grub_linux_setup_video (struct linux_kernel_params *params)
void *framebuffer;
grub_err_t err;
grub_video_driver_id_t driver_id;
char *gfxlfbvar = grub_env_get ("gfxpayloadforcelfb");
const char *gfxlfbvar = grub_env_get ("gfxpayloadforcelfb");
driver_id = grub_video_get_driver_id ();
@ -418,14 +418,15 @@ grub_linux_boot (void)
struct linux_kernel_params *params;
int e820_num;
grub_err_t err = 0;
char *modevar, *tmp;
const char *modevar;
char *tmp;
struct grub_relocator32_state state;
params = real_mode_mem;
#ifdef GRUB_MACHINE_IEEE1275
{
char *bootpath;
const char *bootpath;
grub_ssize_t len;
bootpath = grub_env_get ("root");

View file

@ -700,7 +700,7 @@ grub_cpu_xnu_fill_devicetree (void)
return grub_errno;
/* First see if user supplies the value. */
char *fsbvar = grub_env_get ("fsb");
const char *fsbvar = grub_env_get ("fsb");
if (! fsbvar)
*((grub_uint64_t *) curval->data) = 0;
else

View file

@ -18,16 +18,17 @@
*/
#include <grub/datetime.h>
#include <grub/i18n.h>
static char *grub_weekday_names[] =
static const char *grub_weekday_names[] =
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
N_("Sunday"),
N_("Monday"),
N_("Tuesday"),
N_("Wednesday"),
N_("Thursday"),
N_("Friday"),
N_("Saturday"),
};
int
@ -42,10 +43,10 @@ grub_get_weekday (struct grub_datetime *datetime)
return (datetime->day + y + y / 4 - y / 100 + y / 400 + (31 * m / 12)) % 7;
}
char *
const char *
grub_get_weekday_name (struct grub_datetime *datetime)
{
return grub_weekday_names[grub_get_weekday (datetime)];
return _ (grub_weekday_names[grub_get_weekday (datetime)]);
}
#define SECPERMIN 60

View file

@ -79,7 +79,7 @@ grub_menu_get_entry (grub_menu_t menu, int no)
int
grub_menu_get_timeout (void)
{
char *val;
const char *val;
int timeout;
val = grub_env_get ("timeout");
@ -124,7 +124,7 @@ grub_menu_set_timeout (int timeout)
static int
get_and_remove_first_entry_number (const char *name)
{
char *val;
const char *val;
char *tail;
int entry;

View file

@ -66,7 +66,8 @@ grub_script_argv_make (struct grub_script_argv *argv, int argc, char **args)
struct grub_script_argv r = { 0, 0, 0 };
for (i = 0; i < argc; i++)
if (grub_script_argv_next (&r) || grub_script_argv_append (&r, args[i]))
if (grub_script_argv_next (&r)
|| grub_script_argv_append (&r, args[i], grub_strlen (args[i])))
{
grub_script_argv_free (&r);
return 1;
@ -99,23 +100,23 @@ grub_script_argv_next (struct grub_script_argv *argv)
/* Append `s' to the last argument. */
int
grub_script_argv_append (struct grub_script_argv *argv, const char *s)
grub_script_argv_append (struct grub_script_argv *argv, const char *s,
grub_size_t slen)
{
int a;
int b;
grub_size_t a;
char *p = argv->args[argv->argc - 1];
if (! s)
return 0;
a = p ? grub_strlen (p) : 0;
b = grub_strlen (s);
p = grub_realloc (p, round_up_exp ((a + b + 1) * sizeof (char)));
p = grub_realloc (p, round_up_exp ((a + slen + 1) * sizeof (char)));
if (! p)
return 1;
grub_strcpy (p + a, s);
grub_memcpy (p + a, s, slen);
p[a+slen] = 0;
argv->args[argv->argc - 1] = p;
return 0;
@ -123,10 +124,9 @@ grub_script_argv_append (struct grub_script_argv *argv, const char *s)
/* Split `s' and append words as multiple arguments. */
int
grub_script_argv_split_append (struct grub_script_argv *argv, char *s)
grub_script_argv_split_append (struct grub_script_argv *argv, const char *s)
{
char ch;
char *p;
const char *p;
int errors = 0;
if (! s)
@ -138,10 +138,7 @@ grub_script_argv_split_append (struct grub_script_argv *argv, char *s)
while (*s && ! grub_isspace (*s))
s++;
ch = *s;
*s = '\0';
errors += grub_script_argv_append (argv, p);
*s = ch;
errors += grub_script_argv_append (argv, p, s - p);
while (*s && grub_isspace (*s))
s++;

View file

@ -193,7 +193,7 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
if (! grub_env_special (name))
{
char *v = grub_env_get (name);
const char *v = grub_env_get (name);
if (v && v[0])
{
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
@ -202,20 +202,20 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
goto fail;
}
else
if (grub_script_argv_append (&result, v))
if (grub_script_argv_append (&result, v, grub_strlen (v)))
goto fail;
}
}
else if (! scope)
{
if (grub_script_argv_append (&result, 0))
if (grub_script_argv_append (&result, 0, 0))
goto fail;
}
else if (grub_strcmp (name, "#") == 0)
{
char buffer[ERRNO_DIGITS_MAX + 1];
grub_snprintf (buffer, sizeof (buffer), "%u", scope->argv.argc);
if (grub_script_argv_append (&result, buffer))
if (grub_script_argv_append (&result, buffer, grub_strlen (buffer)))
goto fail;
}
else if (grub_strcmp (name, "*") == 0)
@ -231,10 +231,11 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
}
else
{
if (i != 0 && grub_script_argv_append (&result, " "))
if (i != 0 && grub_script_argv_append (&result, " ", 1))
goto fail;
if (grub_script_argv_append (&result, scope->argv.args[i]))
if (grub_script_argv_append (&result, scope->argv.args[i],
grub_strlen (scope->argv.args[i])))
goto fail;
}
}
@ -251,7 +252,8 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
goto fail;
}
else
if (grub_script_argv_append (&result, scope->argv.args[i]))
if (grub_script_argv_append (&result, scope->argv.args[i],
grub_strlen (scope->argv.args[i])))
goto fail;
}
}
@ -270,7 +272,9 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
goto fail;
}
else
if (grub_script_argv_append (&result, scope->argv.args[num - 1]))
if (grub_script_argv_append (&result, scope->argv.args[num - 1],
grub_strlen (scope->argv.args[num - 1])
))
goto fail;
}
}
@ -309,7 +313,7 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
char *p = 0;
if (! grub_wildcard_translator || escape_type == 0)
return grub_script_argv_append (&result, s);
return grub_script_argv_append (&result, s, grub_strlen (s));
if (escape_type > 0)
p = grub_wildcard_translator->escape (s);
@ -319,7 +323,7 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
if (! p)
return 1;
r = grub_script_argv_append (&result, p);
r = grub_script_argv_append (&result, p, grub_strlen (p));
grub_free (p);
return r;
}
@ -344,7 +348,8 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
if (arg->type == GRUB_SCRIPT_ARG_TYPE_VAR)
{
if (grub_script_argv_append (&result, values[i]))
if (grub_script_argv_append (&result, values[i],
grub_strlen (values[i])))
goto fail;
}
else
@ -359,16 +364,18 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
break;
case GRUB_SCRIPT_ARG_TYPE_BLOCK:
if (grub_script_argv_append (&result, "{") ||
grub_script_argv_append (&result, arg->str) ||
grub_script_argv_append (&result, "}"))
if (grub_script_argv_append (&result, "{", 1)
|| grub_script_argv_append (&result, arg->str,
grub_strlen (arg->str))
|| grub_script_argv_append (&result, "}", 1))
goto fail;
result.script = arg->script;
break;
case GRUB_SCRIPT_ARG_TYPE_TEXT:
if (grub_strlen (arg->str) &&
grub_script_argv_append (&result, arg->str))
grub_script_argv_append (&result, arg->str,
grub_strlen (arg->str)))
goto fail;
break;
@ -680,7 +687,7 @@ grub_err_t
grub_script_execute_cmdif (struct grub_script_cmd *cmd)
{
int ret;
char *result;
const char *result;
struct grub_script_cmdif *cmdif = (struct grub_script_cmdif *) cmd;
/* Check if the commands results in a true or a false. The value is

View file

@ -46,7 +46,7 @@ grub_err_t grub_set_datetime (struct grub_datetime *datetime);
#endif
int grub_get_weekday (struct grub_datetime *datetime);
char *grub_get_weekday_name (struct grub_datetime *datetime);
const char *grub_get_weekday_name (struct grub_datetime *datetime);
void grub_unixtime2datetime (grub_int32_t nix,
struct grub_datetime *datetime);

View file

@ -26,7 +26,7 @@
struct grub_env_var;
typedef char *(*grub_env_read_hook_t) (struct grub_env_var *var,
typedef const char *(*grub_env_read_hook_t) (struct grub_env_var *var,
const char *val);
typedef char *(*grub_env_write_hook_t) (struct grub_env_var *var,
const char *val);
@ -43,7 +43,7 @@ struct grub_env_var
};
grub_err_t EXPORT_FUNC(grub_env_set) (const char *name, const char *val);
char *EXPORT_FUNC(grub_env_get) (const char *name);
const char *EXPORT_FUNC(grub_env_get) (const char *name);
void EXPORT_FUNC(grub_env_unset) (const char *name);
void EXPORT_FUNC(grub_env_iterate) (int (*func) (struct grub_env_var *var));
struct grub_env_var *EXPORT_FUNC(grub_env_find) (const char *name);

View file

@ -245,8 +245,9 @@ void grub_script_mem_free (struct grub_script_mem *mem);
void grub_script_argv_free (struct grub_script_argv *argv);
int grub_script_argv_make (struct grub_script_argv *argv, int argc, char **args);
int grub_script_argv_next (struct grub_script_argv *argv);
int grub_script_argv_append (struct grub_script_argv *argv, const char *s);
int grub_script_argv_split_append (struct grub_script_argv *argv, char *s);
int grub_script_argv_append (struct grub_script_argv *argv, const char *s,
grub_size_t slen);
int grub_script_argv_split_append (struct grub_script_argv *argv, const char *s);
struct grub_script_arglist *
grub_script_create_arglist (struct grub_parser_param *state);