~ubuntu-branches/debian/sid/grub2/sid-200907171837

« back to all changes in this revision

Viewing changes to term/terminfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2006-01-05 15:20:40 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060105152040-1ab076d4n3y2o5yf
Tags: 1.92-1
* New upstream release.
  - Add support for GPT partition table format.
  - Add a new command "play" to play an audio file on PC.
  - Add support for Linux/ADFS partition table format.
  - Add support for BASH-like scripting.
  - Add support for Apple HFS+ filesystems.
* 01_fix_grub-install.patch: Added. Fix grub-install to use
  /bin/grub-mkimage instead of /sbin/grub-mkimage. Closes: #338824
* Do not use CDBS tarball mode anymore. Closes: #344272  

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* terminfo.c - simple terminfo module */
 
2
/*
 
3
 *  GRUB  --  GRand Unified Bootloader
 
4
 *  Copyright (C) 2003,2004,2005  Free Software Foundation, Inc.
 
5
 *
 
6
 *  This program 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 this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
/*
 
22
 * This file contains various functions dealing with different
 
23
 * terminal capabilities. For example, vt52 and vt100.
 
24
 */
 
25
 
 
26
#include <grub/types.h>
 
27
#include <grub/misc.h>
 
28
#include <grub/mm.h>
 
29
#include <grub/err.h>
 
30
#include <grub/dl.h>
 
31
#include <grub/normal.h>
 
32
#include <grub/term.h>
 
33
#include <grub/terminfo.h>
 
34
#include <grub/tparm.h>
 
35
 
 
36
struct terminfo
 
37
{
 
38
  char *name;
 
39
 
 
40
  char *gotoxy;
 
41
  char *cls;
 
42
  char *reverse_video_on;
 
43
  char *reverse_video_off;
 
44
  char *cursor_on;
 
45
  char *cursor_off;
 
46
};
 
47
 
 
48
static struct terminfo term;
 
49
 
 
50
/* Get current terminfo name.  */
 
51
char *
 
52
grub_terminfo_get_current (void)
 
53
{
 
54
  return term.name;
 
55
}
 
56
 
 
57
/* Free *PTR and set *PTR to NULL, to prevent double-free.  */
 
58
static void
 
59
grub_terminfo_free (char **ptr)
 
60
{
 
61
  grub_free (*ptr);
 
62
  *ptr = 0;
 
63
}
 
64
 
 
65
/* Set current terminfo type.  */
 
66
grub_err_t
 
67
grub_terminfo_set_current (const char *str)
 
68
{
 
69
  /* TODO
 
70
   * Lookup user specified terminfo type. If found, set term variables
 
71
   * as appropriate. Otherwise return an error.
 
72
   *
 
73
   * How should this be done?
 
74
   *  a. A static table included in this module.
 
75
   *     - I do not like this idea.
 
76
   *  b. A table stored in the configuration directory.
 
77
   *     - Users must convert their terminfo settings if we have not already.
 
78
   *  c. Look for terminfo files in the configuration directory.
 
79
   *     - /usr/share/terminfo is 6.3M on my system.
 
80
   *     - /usr/share/terminfo is not on most users boot partition.
 
81
   *     + Copying the terminfo files you want to use to the grub
 
82
   *       configuration directory is easier then (b).
 
83
   *  d. Your idea here.
 
84
   */
 
85
 
 
86
  /* Free previously allocated memory.  */
 
87
  grub_terminfo_free (&term.name);
 
88
  grub_terminfo_free (&term.gotoxy);
 
89
  grub_terminfo_free (&term.cls);
 
90
  grub_terminfo_free (&term.reverse_video_on);
 
91
  grub_terminfo_free (&term.reverse_video_off);
 
92
  grub_terminfo_free (&term.cursor_on);
 
93
  grub_terminfo_free (&term.cursor_off);
 
94
  
 
95
  if (grub_strcmp ("vt100", str) == 0)
 
96
    {
 
97
      term.name              = grub_strdup ("vt100");
 
98
      term.gotoxy            = grub_strdup ("\e[%i%p1%d;%p2%dH");
 
99
      term.cls               = grub_strdup ("\e[H\e[J");
 
100
      term.reverse_video_on  = grub_strdup ("\e[7m");
 
101
      term.reverse_video_off = grub_strdup ("\e[m");
 
102
      term.cursor_on         = grub_strdup ("\e[?25l");
 
103
      term.cursor_off        = grub_strdup ("\e[?25h");
 
104
      return grub_errno;
 
105
    }
 
106
  
 
107
  return grub_error (GRUB_ERR_BAD_ARGUMENT, "unknown terminfo type.");
 
108
}
 
109
 
 
110
/* Wrapper for grub_putchar to write strings.  */
 
111
static void
 
112
putstr (const char *str)
 
113
{
 
114
  while (*str)
 
115
    grub_putchar (*str++);
 
116
}
 
117
 
 
118
/* Move the cursor to the given position starting with "0".  */
 
119
void
 
120
grub_terminfo_gotoxy (grub_uint8_t x, grub_uint8_t y)
 
121
{
 
122
  putstr (grub_terminfo_tparm (term.gotoxy, y, x));
 
123
}
 
124
 
 
125
/* Clear the screen.  */
 
126
void
 
127
grub_terminfo_cls (void)
 
128
{
 
129
  putstr (grub_terminfo_tparm (term.cls));
 
130
}
 
131
 
 
132
/* Set reverse video mode on.  */
 
133
void
 
134
grub_terminfo_reverse_video_on (void)
 
135
{
 
136
  putstr (grub_terminfo_tparm (term.reverse_video_on));
 
137
}
 
138
 
 
139
/* Set reverse video mode off.  */
 
140
void
 
141
grub_terminfo_reverse_video_off (void)
 
142
{
 
143
  putstr (grub_terminfo_tparm (term.reverse_video_off));
 
144
}
 
145
 
 
146
/* Show cursor.  */
 
147
void
 
148
grub_terminfo_cursor_on (void)
 
149
{
 
150
  putstr (grub_terminfo_tparm (term.cursor_on));
 
151
}
 
152
 
 
153
/* Hide cursor.  */
 
154
void
 
155
grub_terminfo_cursor_off (void)
 
156
{
 
157
  putstr (grub_terminfo_tparm (term.cursor_off));
 
158
}
 
159
 
 
160
/* GRUB Command.  */
 
161
 
 
162
static grub_err_t
 
163
grub_cmd_terminfo (struct grub_arg_list *state __attribute__ ((unused)),
 
164
                int argc, char **args)
 
165
{
 
166
  if (argc == 0)
 
167
  {
 
168
    grub_printf ("Current terminfo type: %s\n", grub_terminfo_get_current());
 
169
    return GRUB_ERR_NONE;
 
170
  }
 
171
  else if (argc != 1)
 
172
    return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many parameters.");
 
173
  else
 
174
    return grub_terminfo_set_current (args[0]);
 
175
}
 
176
 
 
177
GRUB_MOD_INIT(terminfo)
 
178
{
 
179
  (void) mod;                   /* To stop warning. */
 
180
  grub_register_command ("terminfo", grub_cmd_terminfo, GRUB_COMMAND_FLAG_BOTH,
 
181
                         "terminfo [TERM]", "Set terminfo type.", 0);
 
182
  grub_terminfo_set_current ("vt100");
 
183
}
 
184
 
 
185
GRUB_MOD_FINI(terminfo)
 
186
{
 
187
  grub_unregister_command ("terminfo");
 
188
}