1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
|
/*
*
* UNICON - The Console Chinese & I18N
* Copyright (c) 1999-2002
*
* This file is part of UNICON, a console Chinese & I18N
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* See the file COPYING directory of this archive
* Author: see CREDITS
*/
#include <stdio.h>
#include <newt.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/time.h>
#include <errno.h>
#include <signal.h>
#if (__GNU_LIBRARY__ >= 6)
#include <sys/perm.h>
#else
#include <linux/types.h>
#include <linux/termios.h>
#endif
#include <linux/vt.h>
#include <termios.h>
#include <locale.h>
#include "unikey.h"
#define MAX_LANG 5
#define NEWT_KEY_ESC '\033'
/* font_type */
#define XL_DB_GB 0
#define XL_DB_BIG5 1
#define XL_DB_JIS 2
#define XL_DB_KSCM 3
#define XL_DB_GBK 4
typedef struct menuAction_T
{
char *name;
}
menuAction;
int inputmethod_notify = 0, lang = 0;
static char *menuLangs[MAX_LANG] =
{
"GB",
"BIG5",
"JIS",
"KSCM",
"GBK",
};
#define OK 1
#define CANCEL 0
int DoLangSelection ()
{
newtComponent mAnswer, form, checkbox, rb[MAX_LANG], ok, cancel;
struct newtExitStruct cevent;
char cbValue;
int i, reason;
inputmethod_notify = 0;
lang = 0;
newtInit();
newtCls();
newtOpenWindow(10, 5, 40, MAX_LANG + 8, "Unicon Configuration V 0.1");
checkbox = newtCheckbox(1, 1, "Change Input Method", ' ', " X", &cbValue);
rb[0] = newtRadiobutton(1, 3, menuLangs[0], 1, NULL);
for (i = 1; i < MAX_LANG; i++)
rb[i] = newtRadiobutton(1, 3 + i, menuLangs[i], 0, rb[i-1]);
ok = newtButton(1, 4 + MAX_LANG, "Ok");
cancel = newtButton(12, 4 + MAX_LANG, "Cancel");
form = newtForm(NULL, NULL, 0);
newtFormAddComponent(form, checkbox);
for (i = 0; i < MAX_LANG; i++)
newtFormAddComponent(form, rb[i]);
newtFormAddComponent(form, ok);
newtFormAddComponent(form, cancel);
newtFormAddHotKey (form, NEWT_KEY_ESC);
newtFormRun(form, &cevent);
newtFinished();
mAnswer=newtFormGetCurrent (form);
if (mAnswer == ok)
reason = OK;
else
reason = CANCEL;
if (reason == CANCEL)
return 0;
/* We cannot destroy the form until after we've found the current
radio button */
for (i = 1; i < MAX_LANG; i++)
if (newtRadioGetCurrent(rb[0]) == rb[i])
lang = i;
newtFormDestroy(form);
/* But the checkbox's value is stored locally */
if (cbValue == 'X')
inputmethod_notify = 1;
return 1;
}
void ChangeLocale (int coding)
{
switch (coding)
{
case XL_DB_GB:
setlocale (LC_ALL, "zh_CN.GBK");
break;
case XL_DB_BIG5:
setlocale (LC_ALL, "zh_CN.Big5");
break;
case XL_DB_JIS:
break;
case XL_DB_KSCM:
break;
case XL_DB_GBK:
setlocale (LC_ALL, "zh_CN.GBK");
break;
}
}
//only get the current tty no.
int GetCurrentTTY ()
{
int fd;
struct vt_stat vs;
fd = open("/dev/tty0", O_RDONLY);
if(ioctl(fd, VT_GETSTATE, &vs) == -1){
printf("Error get status.\n");
exit(1);
}
close(fd);
return vs.v_active - 1;
}
void ChangeCurrentTtyFont (int tty, int coding, int inputmethod_notify)
{
int file_desc = open ("/dev/unikey", 0);
VtFont_T aa;
int ret_val;
if (file_desc < 0) {
printf ("Can't open device file: %s\n", DEVICE_FILE_NAME);
exit(-1);
}
aa.tty = tty;
aa.font_type = coding;
aa.input_method_notify = inputmethod_notify;
ret_val = ioctl(file_desc, UNI_SET_CURRENT_FONT, &aa);
if (ret_val < 0) {
printf ("Set Current Font failed.\n");
exit(-1);
}
close(file_desc);
}
int TestFontExist (int coding)
{
switch (coding)
{
case XL_DB_GB:
case XL_DB_BIG5:
case XL_DB_JIS:
case XL_DB_KSCM:
case XL_DB_GBK:
}
return 1;
}
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#define IPPORT_LICENSE 8888
static void DoSendToServer (void *buf, int len)
{
int sockfd;
struct sockaddr_in name;
int opt = 1;
int i;
static int port = IPPORT_LICENSE;
printf ("DoSendToServer (buf = 0x%x, len = %d)\n", (long) buf, len);
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
setsockopt (sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt));
name.sin_family = PF_INET;
name.sin_addr.s_addr = INADDR_BROADCAST;
name.sin_port = htons(port++);
sendto (sockfd, buf, len, 0, (struct sockaddr *) &name, sizeof(name));
close(sockfd);
}
typedef struct __UniconCfg_T__
{
int tty;
int coding;
int input_method_notify;
} UniconCfg_T;
void NotifyServer (int tty, int coding)
{
UniconCfg_T aa;
aa.tty = tty;
aa.coding = coding;
printf ("DoSendToServer () \n");
DoSendToServer (&aa, sizeof (aa));
}
void Usages (char *name)
{
printf ("%s [--gb | --big5 | --gbk | --kscm | --jis \n", name);
printf (" [--notify_input_method]] \n");
printf (" [--tty 1-6] \n");
exit (0);
}
int main (int argc, char **argv)
{
int i, coding_int = XL_DB_GB;
int tty;
tty = GetCurrentTTY ();
if (argc == 1)
{
if (DoLangSelection () == 1)
{
if (TestFontExist (lang) == 0)
printf ("font does not exist\n");
else
{
ChangeLocale (lang);
ChangeCurrentTtyFont (tty, lang, inputmethod_notify);
}
}
// printf ("tty=%d, lang=%d, inputmethod_notify=%d\n",
// tty, lang, inputmethod_notify);
return 0;
}
i = 0;
while (--argc > 0)
{
i ++;
if (argv[i] == NULL)
break;
if (strcmp (argv[i], "--gb") == 0)
coding_int = XL_DB_GB;
else if (strcmp (argv[i], "--gbk") == 0)
coding_int = XL_DB_GBK;
else if (strcmp (argv[i], "--big5") == 0)
coding_int = XL_DB_BIG5;
else if (strcmp (argv[i], "--jis") == 0)
coding_int = XL_DB_JIS;
else if (strcmp (argv[i], "--kscm") == 0)
coding_int = XL_DB_KSCM;
else if (strcmp (argv[i], "--notify_input_method") == 0)
inputmethod_notify = 1;
else if (strcmp (argv[i], "--tty") == 0)
{
tty = atoi (argv[i + 1]) - 1;
i ++;
}
else
Usages (argv[0]);
}
ChangeLocale (coding_int);
ChangeCurrentTtyFont (tty, coding_int, inputmethod_notify);
return 0;
}
|