* commands/cat.c (options): New variable.
(grub_cmd_cat): Parse options. If the --dos option is given, print DOS-style "\r\n" line endings as simple newlines (Debian bug #586358). (GRUB_MOD_INIT): Use extcmd. (GRUB_MOD_FINI): Likewise. * docs/grub.texi (cat): Document --dos.
This commit is contained in:
parent
412e09f355
commit
bbe346529e
3 changed files with 40 additions and 9 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
2010-06-28 Colin Watson <cjwatson@ubuntu.com>
|
||||||
|
|
||||||
|
* commands/cat.c (options): New variable.
|
||||||
|
(grub_cmd_cat): Parse options. If the --dos option is given, print
|
||||||
|
DOS-style "\r\n" line endings as simple newlines (Debian bug
|
||||||
|
#586358).
|
||||||
|
(GRUB_MOD_INIT): Use extcmd.
|
||||||
|
(GRUB_MOD_FINI): Likewise.
|
||||||
|
* docs/grub.texi (cat): Document --dos.
|
||||||
|
|
||||||
2010-06-28 Vladimir Serbinenko <phcoder@gmail.com>
|
2010-06-28 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
XEN with Linux grub-mkconfig support.
|
XEN with Linux grub-mkconfig support.
|
||||||
|
|
|
@ -23,19 +23,28 @@
|
||||||
#include <grub/term.h>
|
#include <grub/term.h>
|
||||||
#include <grub/misc.h>
|
#include <grub/misc.h>
|
||||||
#include <grub/gzio.h>
|
#include <grub/gzio.h>
|
||||||
#include <grub/command.h>
|
#include <grub/extcmd.h>
|
||||||
#include <grub/i18n.h>
|
#include <grub/i18n.h>
|
||||||
|
|
||||||
static grub_err_t
|
static const struct grub_arg_option options[] =
|
||||||
grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
|
{
|
||||||
int argc, char **args)
|
{"dos", -1, 0, N_("Accept DOS-style CR/NL line endings."), 0, 0},
|
||||||
|
{0, 0, 0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
static grub_err_t
|
||||||
|
grub_cmd_cat (grub_extcmd_t cmd, int argc, char **args)
|
||||||
{
|
{
|
||||||
|
struct grub_arg_list *state = cmd->state;
|
||||||
|
int dos = 0;
|
||||||
grub_file_t file;
|
grub_file_t file;
|
||||||
char buf[GRUB_DISK_SECTOR_SIZE];
|
char buf[GRUB_DISK_SECTOR_SIZE];
|
||||||
grub_ssize_t size;
|
grub_ssize_t size;
|
||||||
int key = 0;
|
int key = 0;
|
||||||
|
|
||||||
|
if (state[0].set)
|
||||||
|
dos = 1;
|
||||||
|
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
|
||||||
|
|
||||||
|
@ -54,6 +63,11 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
|
||||||
|
|
||||||
if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
|
if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
|
||||||
grub_putchar (c);
|
grub_putchar (c);
|
||||||
|
else if (dos && c == '\r' && buf[i + 1] == '\n')
|
||||||
|
{
|
||||||
|
grub_putchar ('\n');
|
||||||
|
i++;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
||||||
|
@ -74,15 +88,16 @@ grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static grub_command_t cmd;
|
static grub_extcmd_t cmd;
|
||||||
|
|
||||||
GRUB_MOD_INIT(cat)
|
GRUB_MOD_INIT(cat)
|
||||||
{
|
{
|
||||||
cmd = grub_register_command_p1 ("cat", grub_cmd_cat,
|
cmd = grub_register_extcmd ("cat", grub_cmd_cat, GRUB_COMMAND_FLAG_BOTH,
|
||||||
N_("FILE"), N_("Show the contents of a file."));
|
N_("FILE"), N_("Show the contents of a file."),
|
||||||
|
options);
|
||||||
}
|
}
|
||||||
|
|
||||||
GRUB_MOD_FINI(cat)
|
GRUB_MOD_FINI(cat)
|
||||||
{
|
{
|
||||||
grub_unregister_command (cmd);
|
grub_unregister_extcmd (cmd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1624,13 +1624,19 @@ a menu entry).
|
||||||
@node cat
|
@node cat
|
||||||
@subsection cat
|
@subsection cat
|
||||||
|
|
||||||
@deffn Command cat file
|
@deffn Command cat [@option{--dos}] file
|
||||||
Display the contents of the file @var{file}. This command may be useful
|
Display the contents of the file @var{file}. This command may be useful
|
||||||
to remind you of your OS's root partition:
|
to remind you of your OS's root partition:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
grub> @kbd{cat /etc/fstab}
|
grub> @kbd{cat /etc/fstab}
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
If the @option{--dos} option is used, then carriage return / new line pairs
|
||||||
|
will be displayed as a simple new line. Otherwise, the carriage return will
|
||||||
|
be displayed as a control character (@samp{<d>}) to make it easier to see
|
||||||
|
when boot problems are caused by a file formatted using DOS-style line
|
||||||
|
endings.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue