1 |
/* |
/* |
2 |
* PUPA -- Preliminary Universal Programming Architecture for GRUB |
* PUPA -- Preliminary Universal Programming Architecture for GRUB |
3 |
* Copyright (C) 2002 Free Software Foundation, Inc. |
* Copyright (C) 2002 Free Software Foundation, Inc. |
4 |
* Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org> |
* Copyright (C) 2002,2003 Yoshinori K. Okuji <okuji@enbug.org> |
5 |
* |
* |
6 |
* PUPA is free software; you can redistribute it and/or modify |
* PUPA is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
58 |
break; |
break; |
59 |
} |
} |
60 |
|
|
61 |
void |
pupa_err_t |
62 |
pupa_term_set_current (pupa_term_t term) |
pupa_term_set_current (pupa_term_t term) |
63 |
{ |
{ |
64 |
|
if (pupa_cur_term && pupa_cur_term->fini) |
65 |
|
if ((pupa_cur_term->fini) () != PUPA_ERR_NONE) |
66 |
|
return pupa_errno; |
67 |
|
|
68 |
|
if (term->init) |
69 |
|
if ((term->init) () != PUPA_ERR_NONE) |
70 |
|
return pupa_errno; |
71 |
|
|
72 |
pupa_cur_term = term; |
pupa_cur_term = term; |
73 |
|
pupa_cls (); |
74 |
|
return PUPA_ERR_NONE; |
75 |
} |
} |
76 |
|
|
77 |
pupa_term_t |
pupa_term_t |
80 |
return pupa_cur_term; |
return pupa_cur_term; |
81 |
} |
} |
82 |
|
|
83 |
|
/* Put a Unicode character. */ |
84 |
void |
void |
85 |
pupa_putchar (int c) |
pupa_putcode (pupa_uint32_t code) |
86 |
{ |
{ |
87 |
if (c == '\t' && pupa_cur_term->getxy) |
if (code == '\t' && pupa_cur_term->getxy) |
88 |
{ |
{ |
89 |
int n; |
int n; |
90 |
|
|
91 |
n = 8 - ((pupa_getxy () >> 8) & 7); |
n = 8 - ((pupa_getxy () >> 8) & 7); |
92 |
while (n--) |
while (n--) |
93 |
pupa_putchar (' '); |
pupa_putcode (' '); |
94 |
|
|
95 |
return; |
return; |
96 |
} |
} |
97 |
|
|
98 |
(pupa_cur_term->putchar) (c); |
(pupa_cur_term->putchar) (code); |
99 |
|
|
100 |
if (c == '\n') |
if (code == '\n') |
101 |
pupa_putchar ('\r'); |
pupa_putcode ('\r'); |
102 |
|
} |
103 |
|
|
104 |
|
/* Put a character. C is one byte of a UTF-8 stream. |
105 |
|
This function gathers bytes until a valid Unicode character is found. */ |
106 |
|
void |
107 |
|
pupa_putchar (int c) |
108 |
|
{ |
109 |
|
static pupa_uint32_t code = 0; |
110 |
|
static int count = 0; |
111 |
|
|
112 |
|
if (count) |
113 |
|
{ |
114 |
|
if ((c & 0xc0) != 0x80) |
115 |
|
{ |
116 |
|
/* invalid */ |
117 |
|
code = '@'; |
118 |
|
count = 0; |
119 |
|
} |
120 |
|
else |
121 |
|
{ |
122 |
|
code <<= 6; |
123 |
|
code |= (c & 0x3f); |
124 |
|
count--; |
125 |
|
} |
126 |
|
} |
127 |
|
else |
128 |
|
{ |
129 |
|
if ((c & 0x80) == 0x00) |
130 |
|
code = c; |
131 |
|
else if ((c & 0xe0) == 0xc0) |
132 |
|
{ |
133 |
|
count = 1; |
134 |
|
code = c & 0x1f; |
135 |
|
} |
136 |
|
else if ((c & 0xf0) == 0xe0) |
137 |
|
{ |
138 |
|
count = 2; |
139 |
|
code = c & 0x0f; |
140 |
|
} |
141 |
|
else if ((c & 0xf8) == 0xf0) |
142 |
|
{ |
143 |
|
count = 3; |
144 |
|
code = c & 0x07; |
145 |
|
} |
146 |
|
else if ((c & 0xfc) == 0xf8) |
147 |
|
{ |
148 |
|
count = 4; |
149 |
|
code = c & 0x03; |
150 |
|
} |
151 |
|
else if ((c & 0xfe) == 0xfc) |
152 |
|
{ |
153 |
|
count = 5; |
154 |
|
code = c & 0x01; |
155 |
|
} |
156 |
|
else |
157 |
|
/* invalid */ |
158 |
|
code = '?'; |
159 |
|
} |
160 |
|
|
161 |
|
if (count) |
162 |
|
/* Not finished yet. */ |
163 |
|
return; |
164 |
|
|
165 |
|
pupa_putcode (code); |
166 |
} |
} |
167 |
|
|
168 |
int |
int |