updated on Thu Jan 19 00:16:31 UTC 2012
[aur-mirror.git] / mingetty / mingetty-utf8.patch
blobc269039ac3e8774d5649503bf2aef0aac67347e4
1 diff -Nru mingetty-1.07.orig/mingetty.c mingetty-1.07/mingetty.c
2 --- mingetty-1.07.orig/mingetty.c 2004-01-03 15:15:56.000000000 +0200
3 +++ mingetty-1.07/mingetty.c 2006-11-22 22:13:26.967910100 +0200
4 @@ -16,10 +16,15 @@
5 * - autologin only at first login
6 * - /etc/mingetty.conf that can be used instead of /etc/inittab for
7 * command line options
8 - * - Can UTF-8 setup be done within mingetty?
9 + * - Can UTF-8 setup be done within mingetty? Let's try now :-) (VinzC)
10 * - Also add /bin/login-type functionality in here?
13 +/* Additional comments: Vincent Cadet <vcadet@hotmail.com> (2006-11-21)
14 + * - Attempt to make mingetty support UTF-8. Modifications were imported
15 + * from Suse migetty.c 0.9.6s.
16 + */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 @@ -39,6 +44,19 @@
22 #include <syslog.h>
23 #include <sys/utsname.h>
24 #include <time.h>
25 +#include <locale.h>
26 +#include <iconv.h>
27 +#include <wctype.h>
28 +#include <sys/kd.h>
29 +#include <sys/ttydefaults.h>
31 +#ifndef IUTF8
32 +# ifndef ASM_IUTF8
33 +# error ASM_IUTF8 input flag not defined - Cannot define IUTF8
34 +# else
35 +# define IUTF8 ASM_IUTF8
36 +# endif
37 +#endif
39 /* name of this program (argv[0]) */
40 static char *progname;
41 @@ -74,6 +92,8 @@
42 static char *autologin = NULL;
43 /* try to read a char before dropping to login prompt */
44 static int loginpause = 0;
45 +/* terminal mode */
46 +static int mode = K_RAW;
48 /* error() - output error messages */
49 static void error (const char *fmt, ...)
50 @@ -187,10 +207,21 @@
51 if (fd > 2)
52 close (fd);
54 + /* Detect mode of current keyboard setup, e.g. for UTF-8 */
55 + if (ioctl(0, KDGKBMODE, &mode) < 0)
56 + mode = K_RAW;
58 /* Write a reset string to the terminal. This is very linux-specific
59 and should be checked for other systems. */
60 if (noclear == 0)
61 - write (0, "\033c", 2);
62 + /* don't write a full reset (ESC c) because this leaves the
63 + unicode mode again if the terminal was in unicode mode
64 + and also undos the ESC sequences in CONSOLE_MAGIC which
65 + are needed for some languages/console-fonts.
66 + Just put the cursor to the home position (ESC [ H),
67 + erase everything below the cursor (ESC [ J), and set the
68 + scrolling region to the full window (ESC [ r) */
69 + write (0, "\033[r\033[H\033[J", 9);
71 sigaction (SIGHUP, &sa_old, NULL);
73 @@ -292,32 +323,75 @@
75 static char *get_logname (void)
77 - static char logname[40];
78 + static char logname[4*UT_NAMESIZE];
79 char *bp;
80 unsigned char c;
81 + int ascii;
82 + iconv_t ic;
84 tcflush (0, TCIFLUSH); /* flush pending input */
86 + /* Check for UTF-8 mode */
87 + switch(mode) {
88 + case K_UNICODE:
89 + ascii = 0;
90 + setlocale(LC_CTYPE, "en_US.UTF-8");
91 + break;
92 + case K_RAW:
93 + case K_MEDIUMRAW:
94 + case K_XLATE:
95 + default:
96 + ascii = 1;
97 + setlocale(LC_CTYPE, "POSIX");
98 + break;
99 + }
101 for (*logname = 0; *logname == 0;) {
102 do_prompt (1);
103 for (bp = logname;;) {
104 if (read (0, &c, 1) < 1) {
105 - if (errno == EINTR || errno == EIO
106 - || errno == ENOENT)
107 + if (errno == EINTR || errno == EAGAIN) {
108 + usleep(1000);
109 + continue;
111 + if (errno == EIO || errno == ENOENT)
112 exit (EXIT_SUCCESS);
113 error ("%s: read: %s", tty, strerror (errno));
115 if (c == '\n' || c == '\r') {
116 *bp = 0;
117 break;
118 - } else if (!isprint (c))
119 - error ("%s: invalid character 0x%x in login"
120 - " name", tty, c);
123 + if (ascii && !isprint (c))
124 + error ("%s: invalid character 0x%x in login name", tty, c);
125 else if ((size_t)(bp - logname) >= sizeof (logname) - 1)
126 error ("%s: too long login name", tty);
127 - else
128 - *bp++ = c;
130 + *bp++ = c;
134 + if (!ascii && (ic = iconv_open("WCHAR_T", "UTF-8"))) {
135 + char tmpbuf[4*sizeof(logname)], *op, *lp;
136 + size_t len = bp - logname;
137 + size_t out = sizeof(tmpbuf) - 1;
138 + size_t wcl;
139 + wint_t *wcp;
141 + op = tmpbuf;
142 + lp = logname;
143 + if ((wcl = iconv(ic , &lp, &len, &op, &out)) == (size_t)-1)
144 + error ("%s: invalid character conversion for login name", tty);
145 + iconv_close(ic);
147 + wcp = (wint_t*)tmpbuf;
148 + wcp[wcl] = (wint_t)0;
149 + while (*wcp) {
150 + if (!iswprint(*wcp++))
151 + error ("%s: invalid character for login name found", tty);
154 return logname;