~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to commands/cat.c

Tags: upstream-1.98+20100705
ImportĀ upstreamĀ versionĀ 1.98+20100705

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <grub/term.h>
24
24
#include <grub/misc.h>
25
25
#include <grub/gzio.h>
26
 
#include <grub/command.h>
 
26
#include <grub/extcmd.h>
27
27
#include <grub/i18n.h>
28
28
 
 
29
static const struct grub_arg_option options[] =
 
30
  {
 
31
    {"dos", -1, 0, N_("Accept DOS-style CR/NL line endings."), 0, 0},
 
32
    {0, 0, 0, 0, 0, 0}
 
33
  };
 
34
 
29
35
static grub_err_t
30
 
grub_cmd_cat (grub_command_t cmd __attribute__ ((unused)),
31
 
              int argc, char **args)
32
 
 
 
36
grub_cmd_cat (grub_extcmd_t cmd, int argc, char **args)
33
37
{
 
38
  struct grub_arg_list *state = cmd->state;
 
39
  int dos = 0;
34
40
  grub_file_t file;
35
41
  char buf[GRUB_DISK_SECTOR_SIZE];
36
42
  grub_ssize_t size;
37
43
  int key = 0;
38
44
 
 
45
  if (state[0].set)
 
46
    dos = 1;
 
47
 
39
48
  if (argc != 1)
40
49
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");
41
50
 
53
62
          unsigned char c = buf[i];
54
63
 
55
64
          if ((grub_isprint (c) || grub_isspace (c)) && c != '\r')
56
 
            grub_putchar (c);
 
65
            grub_printf ("%c", c);
 
66
          else if (dos && c == '\r' && i + 1 < size && buf[i + 1] == '\n')
 
67
            {
 
68
              grub_printf ("\n");
 
69
              i++;
 
70
            }
57
71
          else
58
72
            {
59
73
              grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
67
81
        ;
68
82
    }
69
83
 
70
 
  grub_putchar ('\n');
 
84
  grub_xputs ("\n");
71
85
  grub_refresh ();
72
86
  grub_file_close (file);
73
87
 
74
88
  return 0;
75
89
}
76
90
 
77
 
static grub_command_t cmd;
 
91
static grub_extcmd_t cmd;
78
92
 
79
93
GRUB_MOD_INIT(cat)
80
94
{
81
 
  cmd = grub_register_command_p1 ("cat", grub_cmd_cat,
82
 
                                  N_("FILE"), N_("Show the contents of a file."));
 
95
  cmd = grub_register_extcmd ("cat", grub_cmd_cat, GRUB_COMMAND_FLAG_BOTH,
 
96
                              N_("FILE"), N_("Show the contents of a file."),
 
97
                              options);
83
98
}
84
99
 
85
100
GRUB_MOD_FINI(cat)
86
101
{
87
 
  grub_unregister_command (cmd);
 
102
  grub_unregister_extcmd (cmd);
88
103
}