~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to commands/help.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mto: (17.3.1 squeeze) (1.9.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060105152040-b72i5pq1a82z22yi
Tags: upstream-1.92
ImportĀ upstreamĀ versionĀ 1.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* help.c - command to show a help text.  */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2005  Free Software Foundation, Inc.
 
5
 *
 
6
 *  GRUB is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with GRUB; if not, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <grub/normal.h>
 
22
#include <grub/dl.h>
 
23
#include <grub/arg.h>
 
24
#include <grub/misc.h>
 
25
 
 
26
/* XXX: This has to be changed into a function so the screen can be
 
27
   optimally used.  */
 
28
#define TERM_WIDTH      80
 
29
 
 
30
static grub_err_t
 
31
grub_cmd_help (struct grub_arg_list *state __attribute__ ((unused)), int argc,
 
32
               char **args)
 
33
 
 
34
{
 
35
  int cnt = 0;
 
36
  char *currarg;
 
37
  
 
38
  auto int print_command_info (grub_command_t cmd);
 
39
  auto int print_command_help (grub_command_t cmd);
 
40
 
 
41
  int print_command_info (grub_command_t cmd)
 
42
    {
 
43
      if (grub_command_find (cmd->name))
 
44
        {
 
45
          if (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)
 
46
            {
 
47
              char description[TERM_WIDTH / 2];
 
48
              int desclen = grub_strlen (cmd->summary);
 
49
              
 
50
              /* Make a string with a length of TERM_WIDTH / 2 - 1 filled
 
51
                 with the description followed by spaces.  */
 
52
              grub_memset (description, ' ', TERM_WIDTH / 2 - 1);
 
53
              description[TERM_WIDTH / 2 - 1] = '\0';
 
54
              grub_memcpy (description, cmd->summary,
 
55
                           (desclen < TERM_WIDTH / 2 - 1 
 
56
                            ? desclen : TERM_WIDTH / 2 - 1));
 
57
              
 
58
              grub_printf ("%s%s", description, (cnt++) % 2 ? "\n" : " ");
 
59
            }
 
60
        }
 
61
      return 0;
 
62
    }
 
63
 
 
64
  int print_command_help (grub_command_t cmd)
 
65
    {
 
66
      if (grub_command_find (cmd->name))
 
67
        {
 
68
          if (! grub_strncmp (cmd->name, currarg, grub_strlen (currarg)))
 
69
            {
 
70
              if (cnt++ > 0)
 
71
                grub_printf ("\n\n");
 
72
              
 
73
              grub_arg_show_help (cmd);
 
74
            }
 
75
        }
 
76
      return 0;
 
77
    }
 
78
  
 
79
  if (argc == 0)
 
80
    grub_iterate_commands (print_command_info);
 
81
  else
 
82
    {
 
83
      int i;
 
84
      
 
85
      for (i = 0; i < argc; i++)
 
86
        {
 
87
          currarg = args[i];
 
88
          grub_iterate_commands (print_command_help);     
 
89
        }
 
90
    }
 
91
  
 
92
  return 0;
 
93
}
 
94
 
 
95
 
 
96
 
 
97
GRUB_MOD_INIT(help)
 
98
{
 
99
  (void)mod;                    /* To stop warning. */
 
100
  grub_register_command ("help", grub_cmd_help, GRUB_COMMAND_FLAG_CMDLINE,
 
101
                         "help [PATTERN ...]", "Show a help message.", 0);
 
102
}
 
103
 
 
104
GRUB_MOD_FINI(help)
 
105
{
 
106
  grub_unregister_command ("help");
 
107
}