From: Robert Millan <rmh@aybabtu.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: merging of gettext branch
Date: Sun, 22 Nov 2009 00:09:04 +0100 [thread overview]
Message-ID: <20091121230904.GA29740@thorin> (raw)
In-Reply-To: <20091121221410.GA26442@pina.cat>
On Sat, Nov 21, 2009 at 10:14:10PM +0000, Carles Pina i Estany wrote:
> @@ -179,7 +185,7 @@
> pkglib_MODULES += fshelp.mod fat.mod ufs1.mod ufs2.mod ext2.mod ntfs.mod \
> ntfscomp.mod minix.mod hfs.mod jfs.mod iso9660.mod xfs.mod \
> affs.mod sfs.mod hfsplus.mod reiserfs.mod cpio.mod tar.mod \
> - udf.mod afs.mod afs_be.mod befs.mod befs_be.mod
> + udf.mod afs.mod afs_be.mod befs.mod befs_be.mod gettext.mod
>
> # For fshelp.mod.
> fshelp_mod_SOURCES = fs/fshelp.c
> @@ -610,6 +616,11 @@
> bufio_mod_CFLAGS = $(COMMON_CFLAGS)
> bufio_mod_LDFLAGS = $(COMMON_LDFLAGS)
>
> +# For gettext.mod.
> +gettext_mod_SOURCES = gettext/gettext.c
> +gettext_mod_CFLAGS = $(COMMON_CFLAGS)
> +gettext_mod_LDFLAGS = $(COMMON_LDFLAGS)
I haven't switched the old declarations, but for new modules please use
something like:
pkglib_MODULES += gettext.mod
gettext_mod_SOURCES = gettext/gettext.c
gettext_mod_CFLAGS = $(COMMON_CFLAGS)
gettext_mod_LDFLAGS = $(COMMON_LDFLAGS)
this way it is easier to move declarations around, etc.
> +static grub_file_t grub_mofile_open (const char *name);
We usually skip declarations for static functions (when all its users are
placed after its implementation, of course).
> +#define GETTEXT_MAGIC_NUMBER 0
> +#define GETTEXT_FILE_FORMAT 4
> +#define GETTEXT_NUMBER_OF_STRINGS 8
> +#define GETTEXT_OFFSET_ORIGINAL 12
> +#define GETTEXT_OFFSET_TRANSLATION 16
These would look much prettier with some tabs ;-)
> + grub_file_seek (fd_mo, offset);
> + grub_file_read (fd_mo, translation, length);
You do a lot of grub_file_seek + grub_file_read throurough the code. Maybe
grub_file_pread() would be more appropiate? (for space saving)
> + grub_free(current_string);
> + min=current;
> [...]
> + current = (max+min)/2;
> [...]
> + ret = grub_malloc(grub_strlen(orig) + 1);
> + grub_strcpy(ret,orig);
Missing spaces (between function name and parenthesis, around '=', etc).
I suggest you use indent(1), this will automatically adjust to our coding
style.
> + /*
> + Do we want .mo.gz files? Then, the code:
> + file = grub_gzio_open (io, 0); // 0: transparent
> + if (! file)
> + {
> + grub_printf("Problems opening the file\n");
> + grub_file_close (io);
> + return 0;
> + }
> + */
Uhm I wonder if we could answer this question before the code is merged; what
does everyone think about .mo.gz?
> + locale_dir = grub_env_get ("locale_dir");
This needs to be checked for NULL.
> + // mo_file e.g.: /boot/grub/locale/ca.mo
Please use C-style comments (/* */).
> + mo_file = grub_malloc (grub_strlen (locale_dir) + sizeof ("/") + grub_strlen (lang) + sizeof(".mo"));
Note that sizeof ("/") equals 2 ('/' + '\0').
> + grub_dprintf("gettext", "Will try to open file: %s " ,mo_file);
> +
> + fd_mo = grub_mofile_open(mo_file);
In this case I think error handling would be more useful than debug print (i.e.
if file can't be opened, rise an error).
> + /* Testing:
> + grub_register_command ("_", grub_cmd_translate, GRUB_COMMAND_FLAG_BOTH,
> + "_", "internalization support trans", 0);
> + */
We could define this interface unconditionally, but it'd be more consistent
as `gettext' command (like the one in GNU gettext package).
> === added file 'include/grub/i18n_grub.h'
> --- include/grub/i18n_grub.h 1970-01-01 00:00:00 +0000
> +++ include/grub/i18n_grub.h 2009-11-19 21:32:05 +0000
> [...]
> +#ifndef GRUB_I18N_GRUB_H
> +#define GRUB_I18N_GRUB_H 1
> +
> +# define _(str) grub_gettext(str)
> +
> +#endif /* GRUB_I18N_GRUB_H */
You can use <grub/i18n.h> for this (in fact it already defines _ to a
noop stub for non-util and would just need to be modified).
> +const char *EXPORT_FUNC(grub_gettext_dummy) (const char *s);
> +extern const char *(*EXPORT_VAR(grub_gettext)) (const char *s);// = grub_gettext_dummy;
This could be in i18n.h too (except the comment ;-)).
Btw, is it necessary to export grub_gettext_dummy symbol? If we avoid it
it's a few less bytes in kernel :-)
> +# Gettext variables and module
> +cat << EOF
> +set locale_dir=${locale_dir}
> +set lang=${grub_lang}
> +insmod gettext
> +EOF
We could avoid loading the module at all for non-utf8 capable setups (when
this happens, grub-mkconfig exports LANG=C, so this can be easily detected).
--
Robert Millan
The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
how) you may access your data; but nobody's threatening your freedom: we
still allow you to remove your data and not access it at all."
next prev parent reply other threads:[~2009-11-21 23:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-21 21:27 merging of gettext branch Carles Pina i Estany
2009-11-21 21:33 ` Carles Pina i Estany
2009-11-21 22:00 ` Robert Millan
2009-11-21 22:14 ` Carles Pina i Estany
2009-11-21 23:09 ` Robert Millan [this message]
2009-11-21 23:18 ` Vladimir 'φ-coder/phcoder' Serbinenko
2009-11-21 23:40 ` Robert Millan
2009-11-22 12:47 ` Carles Pina i Estany
2009-11-22 12:46 ` Carles Pina i Estany
2009-11-22 17:07 ` Carles Pina i Estany
2009-11-22 18:45 ` Carles Pina i Estany
2009-11-22 21:26 ` Robert Millan
2009-11-22 22:27 ` Carles Pina i Estany
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20091121230904.GA29740@thorin \
--to=rmh@aybabtu.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.