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

« back to all changes in this revision

Viewing changes to normal/term.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2002,2003,2005,2007,2008,2009  Free Software Foundation, Inc.
4
 
 *
5
 
 *  GRUB is free software: you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation, either version 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  GRUB is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <grub/term.h>
20
 
#include <grub/misc.h>
21
 
#include <grub/mm.h>
22
 
#include <grub/file.h>
23
 
#include <grub/dl.h>
24
 
#include <grub/env.h>
25
 
#include <grub/normal.h>
26
 
 
27
 
/* The amount of lines counted by the pager.  */
28
 
static unsigned grub_more_lines;
29
 
 
30
 
/* If the more pager is active.  */
31
 
static int grub_more;
32
 
 
33
 
static void
34
 
process_newline (void)
35
 
{
36
 
  struct grub_term_output *cur;
37
 
  unsigned height = -1;
38
 
 
39
 
  FOR_ACTIVE_TERM_OUTPUTS(cur)
40
 
    if (grub_term_height (cur) < height)
41
 
      height = grub_term_height (cur);
42
 
  grub_more_lines++;
43
 
 
44
 
  if (grub_more && grub_more_lines >= height - 1)
45
 
    {
46
 
      char key;
47
 
      grub_uint16_t *pos;
48
 
 
49
 
      pos = grub_term_save_pos ();
50
 
 
51
 
      grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
52
 
      grub_printf ("--MORE--");
53
 
      grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
54
 
 
55
 
      key = grub_getkey ();
56
 
 
57
 
      /* Remove the message.  */
58
 
      grub_term_restore_pos (pos);
59
 
      grub_printf ("        ");
60
 
      grub_term_restore_pos (pos);
61
 
 
62
 
      /* Scroll one lines or an entire page, depending on the key.  */
63
 
      if (key == '\r' || key =='\n')
64
 
        grub_more_lines = height - 2;
65
 
      else
66
 
        grub_more_lines = 0;
67
 
    }
68
 
}
69
 
 
70
 
void
71
 
grub_set_more (int onoff)
72
 
{
73
 
  if (onoff == 1)
74
 
    grub_more++;
75
 
  else
76
 
    grub_more--;
77
 
 
78
 
  grub_more_lines = 0;
79
 
  grub_newline_hook = process_newline;
80
 
}
81
 
 
82
 
void
83
 
grub_puts_terminal (const char *str, struct grub_term_output *term)
84
 
{
85
 
  grub_uint32_t code;
86
 
  grub_ssize_t ret;
87
 
  const grub_uint8_t *ptr = (const grub_uint8_t *) str;
88
 
  const grub_uint8_t *end;
89
 
  end = (const grub_uint8_t *) (str + grub_strlen (str));
90
 
 
91
 
  while (*ptr)
92
 
    {
93
 
      ret = grub_utf8_to_ucs4 (&code, 1, ptr, end - ptr, &ptr);
94
 
      grub_putcode (code, term);        
95
 
    }
96
 
}
97
 
 
98
 
grub_uint16_t *
99
 
grub_term_save_pos (void)
100
 
{
101
 
  struct grub_term_output *cur;
102
 
  unsigned cnt = 0;
103
 
  grub_uint16_t *ret, *ptr;
104
 
  
105
 
  FOR_ACTIVE_TERM_OUTPUTS(cur)
106
 
    cnt++;
107
 
 
108
 
  ret = grub_malloc (cnt * sizeof (ret[0]));
109
 
  if (!ret)
110
 
    return NULL;
111
 
 
112
 
  ptr = ret;
113
 
  FOR_ACTIVE_TERM_OUTPUTS(cur)
114
 
    *ptr++ = grub_term_getxy (cur);
115
 
 
116
 
  return ret;
117
 
}
118
 
 
119
 
void
120
 
grub_term_restore_pos (grub_uint16_t *pos)
121
 
{
122
 
  struct grub_term_output *cur;
123
 
  grub_uint16_t *ptr = pos;
124
 
 
125
 
  if (!pos)
126
 
    return;
127
 
 
128
 
  FOR_ACTIVE_TERM_OUTPUTS(cur)
129
 
  {
130
 
    grub_term_gotoxy (cur, (*ptr & 0xff00) >> 8, *ptr & 0xff);
131
 
    ptr++;
132
 
  }
133
 
}
134
 
 
135
 
static void 
136
 
grub_terminal_autoload_free (void)
137
 
{
138
 
  struct grub_term_autoload *cur, *next;
139
 
  unsigned i;
140
 
  for (i = 0; i < 2; i++)
141
 
    for (cur = i ? grub_term_input_autoload : grub_term_output_autoload;
142
 
         cur; cur = next)
143
 
      {
144
 
        next = cur->next;
145
 
        grub_free (cur->name);
146
 
        grub_free (cur->modname);
147
 
        grub_free (cur);
148
 
      }
149
 
  grub_term_input_autoload = NULL;
150
 
  grub_term_output_autoload = NULL;
151
 
}
152
 
 
153
 
 
154
 
/* Read the file terminal.lst for auto-loading.  */
155
 
void
156
 
read_terminal_list (void)
157
 
{
158
 
  const char *prefix;
159
 
  char *filename;
160
 
  grub_file_t file;
161
 
  char *buf = NULL;
162
 
 
163
 
  prefix = grub_env_get ("prefix");
164
 
  if (!prefix)
165
 
    {
166
 
      grub_errno = GRUB_ERR_NONE;
167
 
      return;
168
 
    }
169
 
  
170
 
  filename = grub_xasprintf ("%s/terminal.lst", prefix);
171
 
  if (!filename)
172
 
    {
173
 
      grub_errno = GRUB_ERR_NONE;
174
 
      return;
175
 
    }
176
 
 
177
 
  file = grub_file_open (filename);
178
 
  if (!file)
179
 
    {
180
 
      grub_errno = GRUB_ERR_NONE;
181
 
      return;
182
 
    }
183
 
 
184
 
  /* Override previous terminal.lst.  */
185
 
  grub_terminal_autoload_free ();
186
 
 
187
 
  for (;; grub_free (buf))
188
 
    {
189
 
      char *p, *name;
190
 
      struct grub_term_autoload *cur;
191
 
      struct grub_term_autoload **target = NULL;
192
 
      
193
 
      buf = grub_file_getline (file);
194
 
        
195
 
      if (! buf)
196
 
        break;
197
 
 
198
 
      switch (buf[0])
199
 
        {
200
 
        case 'i':
201
 
          target = &grub_term_input_autoload;
202
 
          break;
203
 
 
204
 
        case 'o':
205
 
          target = &grub_term_output_autoload;
206
 
          break;
207
 
        }
208
 
      if (!target)
209
 
        continue;
210
 
      
211
 
      name = buf + 1;
212
 
            
213
 
      p = grub_strchr (name, ':');
214
 
      if (! p)
215
 
        continue;
216
 
      
217
 
      *p = '\0';
218
 
      while (*++p == ' ')
219
 
        ;
220
 
 
221
 
      cur = grub_malloc (sizeof (*cur));
222
 
      if (!cur)
223
 
        {
224
 
          grub_errno = GRUB_ERR_NONE;
225
 
          continue;
226
 
        }
227
 
      
228
 
      cur->name = grub_strdup (name);
229
 
      if (! name)
230
 
        {
231
 
          grub_errno = GRUB_ERR_NONE;
232
 
          grub_free (cur);
233
 
          continue;
234
 
        }
235
 
        
236
 
      cur->modname = grub_strdup (p);
237
 
      if (! cur->modname)
238
 
        {
239
 
          grub_errno = GRUB_ERR_NONE;
240
 
          grub_free (cur);
241
 
          grub_free (cur->name);
242
 
          continue;
243
 
        }
244
 
      cur->next = *target;
245
 
      *target = cur;
246
 
    }
247
 
  
248
 
  grub_file_close (file);
249
 
 
250
 
  grub_errno = GRUB_ERR_NONE;
251
 
}