root/trunk/freewrt/package/busybox/patches/100-chkuterm.patch
| Revision 3390, 5.3 kB (checked in by tg, 5 years ago) |
|---|
-
busybox-1.4.2/console-tools/Config.in
old new 5 5 6 6 menu "Console Utilities" 7 7 8 config CHKUTERM 9 bool "chkuterm" 10 default n 11 help 12 This programme determines whether the current terminal 13 is in UTF-8 mode. 14 8 15 config CHVT 9 16 bool "chvt" 10 17 default n -
busybox-1.4.2/console-tools/chkuterm.c
old new 1 /* From: $MirOS: ports/sysutils/chkuterm/dist/chkuterm.c,v 1.11 2007/05/10 13:02:22 tg Exp $ */ 2 3 /*- 4 * Copyright (c) 2006, 2007 5 * Thorsten Glaser <tg@mirbsd.de> 6 * 7 * Provided that these terms and disclaimer and all copyright notices 8 * are retained or reproduced in an accompanying document, permission 9 * is granted to deal in this work without restriction, including un- 10 * limited rights to use, publicly perform, distribute, sell, modify, 11 * merge, give away, or sublicence. 12 * 13 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 14 * the utmost extent permitted by applicable law, neither express nor 15 * implied; without malicious intent or gross negligence. In no event 16 * may a licensor, author or contributor be held liable for indirect, 17 * direct, other damage, loss, or other issues arising in any way out 18 * of dealing in the work, even if advised of the possibility of such 19 * damage or existence of a defect, except proven that it results out 20 * of said person's immediate fault when using the work as intended. 21 */ 22 23 #include "busybox.h" 24 #include <err.h> 25 26 #if 0 27 __RCSID("$miros: src/usr.sbin/wsconfig/wsconfig.c,v 1.16 2007/05/10 13:02:21 tg Exp $"); 28 __RCSID("$MirOS: ports/sysutils/chkuterm/dist/chkuterm.c,v 1.11 2007/05/10 13:02:22 tg Exp $"); 29 __RCSID("$miros: ports/misc/screen/patches/patch-screen_c,v 1.12 2007/05/10 13:02:23 tg Exp $"); 30 #endif 31 32 /* query string sent to the terminal for LC_CTYPE detection */ 33 /* XXX is U+20AC U+002E ok or some other char better? Think EUC, SJIS, etc. */ 34 const char ctype_qstr[] = "\030\032\r\xE2\x82\xAC.\033[6n"; 35 36 int 37 chkuterm_main(int argc, char *argv[]) 38 { 39 const char *wsdev, *est; 40 char ch; 41 int wsfd, rv = 0; 42 int nr = 0; 43 struct termios tio, otio; 44 fd_set fds; 45 struct timeval tv; 46 FILE *wsf; 47 48 wsdev = "/dev/tty"; 49 50 /* apparently O_RDONLY wouldn't matter but we stay safe */ 51 if ((est = ttyname(STDIN_FILENO)) != NULL && !strcmp(wsdev, est)) 52 wsfd = STDIN_FILENO; 53 else if ((est = ttyname(STDOUT_FILENO)) != NULL && !strcmp(wsdev, est)) 54 wsfd = STDOUT_FILENO; 55 else 56 if ((wsfd = open(wsdev, O_RDWR, 0)) < 0) 57 err(2, "open %s", wsdev); 58 wsf = fdopen(wsfd, "rb+"); 59 60 tcdrain(wsfd); 61 if (tcgetattr(wsfd, &otio)) 62 err(3, "tcgetattr"); 63 tio = otio; 64 cfmakeraw(&tio); 65 if (tcflush(wsfd, TCIOFLUSH)) 66 warn("tcflush"); 67 rv = /* error */ 3; 68 if (tcsetattr(wsfd, TCSANOW, &tio)) { 69 warn("tcsetattr\r"); 70 goto tios_err; 71 } 72 tv.tv_sec = 0; 73 tv.tv_usec = 75; 74 select(0, NULL, NULL, NULL, &tv); /* sleep 75 msec */ 75 if ((size_t)write(wsfd, ctype_qstr, strlen(ctype_qstr)) != 76 strlen(ctype_qstr)) { 77 warn("write\r"); 78 goto noin; 79 } 80 select(0, NULL, NULL, NULL, &tv); /* sleep 75 msec */ 81 FD_ZERO(&fds); 82 FD_SET(wsfd, &fds); 83 tv.tv_sec = 2; 84 tv.tv_usec = 0; 85 if (select(wsfd + 1, &fds, NULL, NULL, &tv) <= 0) 86 goto noin; 87 nr = read(wsfd, &ch, 1); 88 rv = /* unknown */ 1; 89 if (wsf != NULL && nr == 1 && ch == 033) { 90 unsigned zeile, spalte; 91 92 if (fscanf(wsf, "[%u;%u", &zeile, &spalte) == 2) 93 switch (spalte) { 94 case 1: /* EUC-JP, EUC-KR kterm */ 95 case 5: /* Shift-JIS kterm */ 96 break; 97 case 3: /* UTF-8 xterm, screen */ 98 rv = 0; 99 break; 100 case 4: /* ISO-8859-1 xterm, screen */ 101 rv = 2; 102 break; 103 default: 104 rv = 0x1000 | spalte; 105 break; 106 } 107 } 108 noin: 109 write(wsfd, "\r \r", 8); 110 tios_err: 111 if (tcflush(wsfd, TCIOFLUSH)) 112 warn("tcflush"); 113 if (tcsetattr(wsfd, TCSANOW, &otio)) 114 err(3, "tcsetattr"); 115 if (rv & 0x1000) { 116 /* unknown charset */ 117 printf("# unknown column %d\n", rv & 0xFFF); 118 rv = 1; 119 } 120 printf("LC_CTYPE=%s; export LC_CTYPE\n", 121 rv == 0 ? "en_US.UTF-8" : "C"); 122 if (rv > 2) 123 puts("# warning: problems occured!\n"); 124 125 if (wsf == NULL) 126 close(wsfd); 127 else 128 fclose(wsf); 129 return (rv); 130 }
Note: See TracBrowser for help on using the browser.


