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> 2011-11-11 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/normal/main.c (grub_normal_execute): Remove leftover call. * grub-core/normal/main.c (grub_normal_execute): Remove leftover call.

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -697,7 +697,7 @@ grub_dl_load (const char *name)
{ {
char *filename; char *filename;
grub_dl_t mod; 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); mod = grub_dl_get (name);
if (mod) if (mod)

View file

@ -132,7 +132,7 @@ grub_env_set (const char *name, const char *val)
return grub_errno; return grub_errno;
} }
char * const char *
grub_env_get (const char *name) grub_env_get (const char *name)
{ {
struct grub_env_var *var; 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) 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 /* Check if a variable was being read in and the end of the name
was reached. */ was reached. */

View file

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

View file

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

View file

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

View file

@ -18,16 +18,17 @@
*/ */
#include <grub/datetime.h> #include <grub/datetime.h>
#include <grub/i18n.h>
static char *grub_weekday_names[] = static const char *grub_weekday_names[] =
{ {
"Sunday", N_("Sunday"),
"Monday", N_("Monday"),
"Tuesday", N_("Tuesday"),
"Wednesday", N_("Wednesday"),
"Thursday", N_("Thursday"),
"Friday", N_("Friday"),
"Saturday", N_("Saturday"),
}; };
int 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; 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) 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 #define SECPERMIN 60

View file

@ -79,7 +79,7 @@ grub_menu_get_entry (grub_menu_t menu, int no)
int int
grub_menu_get_timeout (void) grub_menu_get_timeout (void)
{ {
char *val; const char *val;
int timeout; int timeout;
val = grub_env_get ("timeout"); val = grub_env_get ("timeout");
@ -124,7 +124,7 @@ grub_menu_set_timeout (int timeout)
static int static int
get_and_remove_first_entry_number (const char *name) get_and_remove_first_entry_number (const char *name)
{ {
char *val; const char *val;
char *tail; char *tail;
int entry; 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 }; struct grub_script_argv r = { 0, 0, 0 };
for (i = 0; i < argc; i++) 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); grub_script_argv_free (&r);
return 1; return 1;
@ -99,23 +100,23 @@ grub_script_argv_next (struct grub_script_argv *argv)
/* Append `s' to the last argument. */ /* Append `s' to the last argument. */
int 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; grub_size_t a;
int b;
char *p = argv->args[argv->argc - 1]; char *p = argv->args[argv->argc - 1];
if (! s) if (! s)
return 0; return 0;
a = p ? grub_strlen (p) : 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) if (! p)
return 1; return 1;
grub_strcpy (p + a, s); grub_memcpy (p + a, s, slen);
p[a+slen] = 0;
argv->args[argv->argc - 1] = p; argv->args[argv->argc - 1] = p;
return 0; 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. */ /* Split `s' and append words as multiple arguments. */
int 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; const char *p;
char *p;
int errors = 0; int errors = 0;
if (! s) if (! s)
@ -138,10 +138,7 @@ grub_script_argv_split_append (struct grub_script_argv *argv, char *s)
while (*s && ! grub_isspace (*s)) while (*s && ! grub_isspace (*s))
s++; s++;
ch = *s; errors += grub_script_argv_append (argv, p, s - p);
*s = '\0';
errors += grub_script_argv_append (argv, p);
*s = ch;
while (*s && grub_isspace (*s)) while (*s && grub_isspace (*s))
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)) if (! grub_env_special (name))
{ {
char *v = grub_env_get (name); const char *v = grub_env_get (name);
if (v && v[0]) if (v && v[0])
{ {
if (type == GRUB_SCRIPT_ARG_TYPE_VAR) 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; goto fail;
} }
else else
if (grub_script_argv_append (&result, v)) if (grub_script_argv_append (&result, v, grub_strlen (v)))
goto fail; goto fail;
} }
} }
else if (! scope) else if (! scope)
{ {
if (grub_script_argv_append (&result, 0)) if (grub_script_argv_append (&result, 0, 0))
goto fail; goto fail;
} }
else if (grub_strcmp (name, "#") == 0) else if (grub_strcmp (name, "#") == 0)
{ {
char buffer[ERRNO_DIGITS_MAX + 1]; char buffer[ERRNO_DIGITS_MAX + 1];
grub_snprintf (buffer, sizeof (buffer), "%u", scope->argv.argc); 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; goto fail;
} }
else if (grub_strcmp (name, "*") == 0) else if (grub_strcmp (name, "*") == 0)
@ -231,10 +231,11 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
} }
else else
{ {
if (i != 0 && grub_script_argv_append (&result, " ")) if (i != 0 && grub_script_argv_append (&result, " ", 1))
goto fail; 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; goto fail;
} }
} }
@ -251,7 +252,8 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
goto fail; goto fail;
} }
else 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; goto fail;
} }
} }
@ -270,7 +272,9 @@ grub_script_env_get (const char *name, grub_script_arg_type_t type)
goto fail; goto fail;
} }
else 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; goto fail;
} }
} }
@ -309,7 +313,7 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
char *p = 0; char *p = 0;
if (! grub_wildcard_translator || escape_type == 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) if (escape_type > 0)
p = grub_wildcard_translator->escape (s); p = grub_wildcard_translator->escape (s);
@ -319,7 +323,7 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
if (! p) if (! p)
return 1; return 1;
r = grub_script_argv_append (&result, p); r = grub_script_argv_append (&result, p, grub_strlen (p));
grub_free (p); grub_free (p);
return r; 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 (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; goto fail;
} }
else else
@ -359,16 +364,18 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
break; break;
case GRUB_SCRIPT_ARG_TYPE_BLOCK: case GRUB_SCRIPT_ARG_TYPE_BLOCK:
if (grub_script_argv_append (&result, "{") || if (grub_script_argv_append (&result, "{", 1)
grub_script_argv_append (&result, arg->str) || || grub_script_argv_append (&result, arg->str,
grub_script_argv_append (&result, "}")) grub_strlen (arg->str))
|| grub_script_argv_append (&result, "}", 1))
goto fail; goto fail;
result.script = arg->script; result.script = arg->script;
break; break;
case GRUB_SCRIPT_ARG_TYPE_TEXT: case GRUB_SCRIPT_ARG_TYPE_TEXT:
if (grub_strlen (arg->str) && 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; goto fail;
break; break;
@ -680,7 +687,7 @@ grub_err_t
grub_script_execute_cmdif (struct grub_script_cmd *cmd) grub_script_execute_cmdif (struct grub_script_cmd *cmd)
{ {
int ret; int ret;
char *result; const char *result;
struct grub_script_cmdif *cmdif = (struct grub_script_cmdif *) cmd; struct grub_script_cmdif *cmdif = (struct grub_script_cmdif *) cmd;
/* Check if the commands results in a true or a false. The value is /* 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 #endif
int grub_get_weekday (struct grub_datetime *datetime); 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, void grub_unixtime2datetime (grub_int32_t nix,
struct grub_datetime *datetime); struct grub_datetime *datetime);

View file

@ -26,8 +26,8 @@
struct grub_env_var; 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); const char *val);
typedef char *(*grub_env_write_hook_t) (struct grub_env_var *var, typedef char *(*grub_env_write_hook_t) (struct grub_env_var *var,
const char *val); 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); 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_unset) (const char *name);
void EXPORT_FUNC(grub_env_iterate) (int (*func) (struct grub_env_var *var)); 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); 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); 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_make (struct grub_script_argv *argv, int argc, char **args);
int grub_script_argv_next (struct grub_script_argv *argv); 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_append (struct grub_script_argv *argv, const char *s,
int grub_script_argv_split_append (struct grub_script_argv *argv, char *s); grub_size_t slen);
int grub_script_argv_split_append (struct grub_script_argv *argv, const char *s);
struct grub_script_arglist * struct grub_script_arglist *
grub_script_create_arglist (struct grub_parser_param *state); grub_script_create_arglist (struct grub_parser_param *state);