📄 conv.c
字号:
/* * @(#)conv.c 1.14 01/08/21 * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the confidential and proprietary information of Sun * Microsystems, Inc. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Sun. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */#include <stdlib.h>#include "global.h"#include "defaultLCDUI.h"#include "conv.h"extern LcConvMethods getLcGenConvMethods(char *encoding);#ifdef UNIXextern LcConvMethodsRec SJISConvRec;extern LcConvMethodsRec EUCJPConvRec;#define NUM_LCCONV 3static LcConvMethods lcConv[NUM_LCCONV] = {/* 0 */ &SJISConvRec,/* 1 */ &EUCJPConvRec,/* 2 */ NULL, /* depositary for a platform general converter */};#endif#ifdef WINDOWS#define NUM_LCCONV 1static LcConvMethods lcConv[NUM_LCCONV] = {/* 0 */ NULL, /* depositary for a platform general converter */};#endifstatic intgetLcConvMethodsIDByEncoding(char *encoding){ if (encoding && *encoding) { int i; for (i = 0; i < NUM_LCCONV; i++) { if (lcConv[i] == NULL) { break; } if (strcmp(lcConv[i]->encoding, encoding) == 0) { return i; } } if (i < NUM_LCCONV) { lcConv[i] = getLcGenConvMethods(encoding); if (lcConv[i] != NULL) { return i; } } } return -1;}static intgetLcConvMethodsID(unicode *uc, int len){ char enc[16]; int i; for (i = 0; i < len; i++) { enc[i] = (char) uc[i]; } enc[i] = 0; return getLcConvMethodsIDByEncoding(enc);}voidJava_com_sun_cldc_i18n_j2me_Conv_getHandler(){ INSTANCE str = popStackAsType(INSTANCE); if (str == NULL) { pushStack(0); } else { SHORTARRAY c = (SHORTARRAY) (str->data[0].cellp); int offset = str->data[1].cell; int length = str->data[2].cell; pushStack(getLcConvMethodsID((unicode *)(c->sdata + offset), length)); }}voidJava_com_sun_cldc_i18n_j2me_Conv_getMaxByteLength(){ int id = popStack(); pushStack(lcConv[id] ? lcConv[id]->byteMaxLen() : 0);}voidJava_com_sun_cldc_i18n_j2me_Conv_getByteLength(){ int length = popStack(); int offset = popStack(); BYTEARRAY b = popStackAsType(BYTEARRAY); int id = popStack(); char *buf = (char *) (b->bdata) + offset; pushStack(lcConv[id] ? lcConv[id]->byteLen((const unsigned char *) buf, length) : 0);}voidJava_com_sun_cldc_i18n_j2me_Conv_byteToChar(){ int outLength = popStack(); int outOffset = popStack(); SHORTARRAY output = popStackAsType(SHORTARRAY); int inLength = popStack(); int inOffset = popStack(); BYTEARRAY input = popStackAsType(BYTEARRAY); int id = popStack(); char *inBuf = (char *) (input->bdata) + inOffset; unicode *outBuf = (unicode *) (output->sdata) + outOffset; pushStack(lcConv[id] ? lcConv[id]->nativeToUnicode((const unsigned char *) inBuf, inLength, outBuf, outLength): 0);}voidJava_com_sun_cldc_i18n_j2me_Conv_charToByte(){ int outLength = popStack(); int outOffset = popStack(); BYTEARRAY output = popStackAsType(BYTEARRAY); int inLength = popStack(); int inOffset = popStack(); SHORTARRAY input = popStackAsType(SHORTARRAY); int id = popStack(); unicode *inBuf = (unicode *) input->sdata + inOffset; char *outBuf = (char *) output->bdata + outOffset; pushStack(lcConv[id] ? lcConv[id]->unicodeToNative((const unicode *) inBuf, inLength, (unsigned char*) outBuf, outLength): 0);}voidJava_com_sun_cldc_i18n_j2me_Conv_sizeOfByteInUnicode(){ int length = popStack(); int offset = popStack(); BYTEARRAY b = popStackAsType(BYTEARRAY); int id = popStack(); char *buf = (char *) (b->bdata) + offset; pushStack(lcConv[id] ? lcConv[id]->sizeOfByteInUnicode((const unsigned char *)buf, offset, length) : 0);}voidJava_com_sun_cldc_i18n_j2me_Conv_sizeOfUnicodeInByte(){ int length = popStack(); int offset = popStack(); SHORTARRAY c = popStackAsType(SHORTARRAY); int id = popStack(); unicode *buf = (unicode *) (c->sdata) + offset; pushStack(lcConv[id] ? lcConv[id]->sizeOfUnicodeInByte((const unicode *)buf, offset, length) : 0);}#if 0 /* DEBUG_METHOD */voidJava_com_sun_cldc_i18n_j2me_Conv_println(){ INSTANCE str = popStackAsType(INSTANCE); int id = popStack(); if (lcConv[id] && str != NULL) { SHORTARRAY c = (SHORTARRAY) (str->data[0].cellp); int offset = str->data[1].cell; int length = str->data[2].cell; unicode *buf = (unicode *) (c->sdata) + offset; int outlen = length * lcConv[id]->byteMaxLen() + 1; char *out = (char *) malloc(outlen); int len = lcConv[id]->unicodeToNative((const unicode *) buf, length, (unsigned char*) out, outlen); out[len] = 0; printf("%s\n", out); }}#endifLcConvMethodsgetLcConvMethods(char *encoding){ int index = getLcConvMethodsIDByEncoding(encoding); if (index != -1) { return lcConv[index]; } return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -