📄 csmsread.c
字号:
/*
* CSmsRead.c
*
* main file for CSmsRead
*
* This wizard-generated code is based on code adapted from the
* stationery files distributed as part of the Palm OS SDK 4.0.
*
* Copyright (c) 1999-2000 Palm, Inc. or its subsidiaries.
* All rights reserved.
*/
#include <PalmOS.h>
#include <PalmOSGlue.h>
#include "CSmsRead.h"
#include "CSmsRead_Rsc.h"
/*
#include "tbl1.c"
#include "tbl2.c"
#include "tbl3.c"
#include "tbl4.c"
//*/
//*
extern UInt16 qtb1(UInt16 in);
extern UInt16 qtb2(UInt16 in);
extern UInt16 qtb3(UInt16 in);
extern UInt16 qtb4(UInt16 in);
extern UInt16 qtb5(UInt16 in);
extern UInt16 qtb6(UInt16 in);
extern UInt16 qtb7(UInt16 in);
extern UInt16 qtb8(UInt16 in);
extern UInt16 qtb9(UInt16 in);
extern UInt16 qtb10(UInt16 in);
extern UInt16 qtb11(UInt16 in);
extern UInt16 qtb12(UInt16 in);
extern UInt16 qtb13(UInt16 in);
extern UInt16 qtb14(UInt16 in);
extern UInt16 qtb15(UInt16 in);
extern UInt16 qtb16(UInt16 in);
extern UInt16 qtb17(UInt16 in);
extern UInt16 qtb18(UInt16 in);
extern UInt16 qtb19(UInt16 in);
extern UInt16 qtb0(UInt16 in);
//*/
extern const UInt16 unicodeTb0[];
extern const UInt16 unicodeTb1[];
extern const UInt16 unicodeTb2[];
extern const UInt16 unicodeTb3[];
extern const UInt16 unicodeTb4[];
extern const UInt16 unicodeTb5[];
extern const UInt16 unicodeTb6[];
extern const UInt16 unicodeTb7[];
extern const UInt16 unicodeTb8[];
extern const UInt16 unicodeTb9[];
extern const UInt16 unicodeTb10[];
extern const UInt16 unicodeTb11[];
extern const UInt16 unicodeTb12[];
extern const UInt16 unicodeTb13[];
extern const UInt16 unicodeTb14[];
extern const UInt16 unicodeTb15[];
extern const UInt16 unicodeTb16[];
extern const UInt16 unicodeTb17[];
extern const UInt16 unicodeTb18[];
extern const UInt16 unicodeTb19[];
/*********************************************************************
* Entry Points
*********************************************************************/
/*********************************************************************
* Global variables
*********************************************************************/
const UInt16 codemap[20][3]={
0,477,592,
593,610,710,
711,730,912,
913,1106,8207,
8208,8255,8363,
8364,8602,8711,
8712,8979,9311,
9312,9372,9471,
9472,9795,12287,
12288,12586,12689,
12690,12704,12831,
12832,12977,13197,
13198,13270,19967,
19968,34367,34367,
34368,40870,57343,
57344,59493,63732,
63733,64046,65071,
65072,65132,65280,
65281,65375,65503,
65504,65510,65535
};
const char phonePrefix[]="+86";
/*********************************************************************
* Internal Constants
*********************************************************************/
/* Define the minimum OS version we support */
#define ourMinVersion sysMakeROMVersion(3,0,0,sysROMStageDevelopment,0)
#define kPalmOS20Version sysMakeROMVersion(2,0,0,sysROMStageDevelopment,0)
/*********************************************************************
* Internal Functions
*********************************************************************/
/*
test();
static void showRec(int index)
{
MemHandle recordH;
char *recordP;
char *pointer;
int smsLen;
recordH = DmQueryRecord(gLibDB, index);
recordP = MemHandleLock(recordH);
pointer = recordP;
pointer+=18;
while(*pointer!=0)
{
pointer++;
}
pointer++;
while(*pointer!=0)
{
pointer++;
}
pointer+=5;
smsLen=*pointer;
FldInsert(field, pointer+1, smsLen);
MemHandleUnlock(recordH);
}
//*/
static void decodeRec(int index,BOOL needInvert)
{
MemHandle recordH;
unsigned char *recordP;
unsigned char *pointer;
unsigned char *basePointer;
const char * errstr="本机器中没有短消息信息!";
FormType * frmP;
DateTimeType smsDatatime;
BOOL isNeedDecode=true;
char smsBuf[200];
int smsDispLen=0;
char phoneNo[30];
char userName[20];
char datatime[24];
char recordPosStr[50];
int datatimeLen=0;
int smsLen;
UInt16 unicodeChar,asiicChar;
int k;
UInt32 secondTime;
maxRecord=DmNumRecords(gLibDB);
frmP=FrmGetActiveForm();
if(maxRecord==0)
{
FldInsert(field,errstr,24);
FrmCopyLabel(frmP,lbPosition,"Here is the lbPostion");
FrmCopyLabel(frmP,lbTime,"Here is the lbTime");
//FrmCopyLabel(frmP,lbPhone,"lbPhone is here");
FrmCopyLabel(frmP,lbName,"");
return;
}
FldDelete(phoneField, 0, 0xFFFF);
FldDrawField(phoneField);
if(index>=maxRecord)
{
index=maxRecord-1;
curRecord=index;
}
recordH = DmQueryRecord(gLibDB, index);
recordP = MemHandleLock(recordH);
pointer=recordP;
//show current record pos
for(k=0;k<50;k++)
{
recordPosStr[k]=0;
}
StrIToA(recordPosStr,curRecord+1);
k=0;
while(recordPosStr[k]!=0) k++;
recordPosStr[k]='/';
k++;
StrIToA(recordPosStr+k,maxRecord);
//while(recordPosStr[k]!=0) k++;
//judge auto encoding
if((pointer[4]==3)||pointer[4]==2)
{
if(pointer[6]==3)
{
isNeedDecode=false;
StrCat(recordPosStr," 发送提示");
}
else
{
isNeedDecode=true;
StrCat(recordPosStr," 收件箱 ");
}
}
else
{
isNeedDecode=false;
StrCat(recordPosStr," 其他位置");
}
//get time
pointer=recordP+10;
secondTime=*((UInt32 *)pointer);
TimSecondsToDateTime(secondTime,&smsDatatime);
//for(k=0;k<15;k++) datatime[k]=32;
DateToDOWDMFormat(smsDatatime.month,smsDatatime.day,smsDatatime.year,dfYMDLongWithDot,datatime);
for(k=7;k<18;k++) if(datatime[k]<32) datatime[k]=' ';
TimeToAscii(smsDatatime.hour,smsDatatime.minute,tfColon24h,datatime+15);
for(k=6;k<24;k++)
if(datatime[k]=='r') datatime[k]=' ';
FrmCopyLabel(frmP,lbTime,datatime);
//get phone number
pointer=recordP+18;
//*
k=0;
for(k=0;(k<3)&&(phonePrefix[k]==pointer[k]);k++)
{
}
if(k==3) pointer+=3;
//*/
k=0;
while(*pointer!=0)
{
phoneNo[k++]=*pointer;
pointer++;
}
phoneNo[k++]=0;
//FrmCopyLabel(frmP,lbPhone,phoneNo);
FldInsert(phoneField,phoneNo,StrLen(phoneNo));
pointer++;
//get phone username
k=0;
while(*pointer!=0)
{
userName[k++]=*pointer;
pointer++;
}
userName[k]=0;
FrmCopyLabel(frmP,lbName,userName);
pointer+=5;
smsLen=*pointer;
if(smsLen==0)
{
MemHandleUnlock(recordH);
return;
}
//search for invisible char to judge codeing
basePointer=pointer+1;
k=0;
if(isNeedDecode)for(k=0;k<smsLen;k++)
{
if((*basePointer>127)||*basePointer<32)
break;
basePointer++;
}
if(k==smsLen) isNeedDecode=false;
//define codeing stats
if(needInvert) isNeedDecode=!isNeedDecode;
if(isNeedDecode)
{
StrCat(recordPosStr," 已解码");
}
else
{
StrCat(recordPosStr," 未解码");
}
FrmCopyLabel(frmP,lbPosition,recordPosStr);
if(isNeedDecode)
{
pointer++;
basePointer=pointer;
while(pointer - basePointer < smsLen)
{
//unicodeChar=(*pointer);
//unicodeChar*=256;
//unicodeChar+=*(pointer+1);
unicodeChar=(*pointer)*256+*(pointer+1);
if(unicodeChar==0)
{
pointer++;
continue;
}
for(k=0;k<20;k++)
{
if(unicodeChar<=codemap[k][2])
{
if(unicodeChar>=codemap[k][1])
{
asiicChar=0;
break;
}
else
{
switch(k)
{
case 0:
asiicChar=qtb0(unicodeChar-codemap[k][0]);
break;
case 1:
asiicChar=qtb1(unicodeChar-codemap[k][0]);
break;
case 2:
asiicChar=qtb2(unicodeChar-codemap[k][0]);
break;
case 3:
asiicChar=qtb3(unicodeChar-codemap[k][0]);
break;
case 4:
asiicChar=qtb4(unicodeChar-codemap[k][0]);
break;
case 5:
asiicChar=qtb5(unicodeChar-codemap[k][0]);
break;
case 6:
asiicChar=qtb6(unicodeChar-codemap[k][0]);
break;
case 7:
asiicChar=qtb7(unicodeChar-codemap[k][0]);
break;
case 8:
asiicChar=qtb8(unicodeChar-codemap[k][0]);
break;
case 9:
asiicChar=qtb9(unicodeChar-codemap[k][0]);
break;
case 10:
asiicChar=qtb10(unicodeChar-codemap[k][0]);
break;
case 11:
asiicChar=qtb11(unicodeChar-codemap[k][0]);
break;
case 12:
asiicChar=qtb12(unicodeChar-codemap[k][0]);
break;
case 13:
asiicChar=qtb13(unicodeChar-codemap[k][0]);
break;
case 14:
asiicChar=qtb14(unicodeChar-codemap[k][0]);
break;
case 15:
asiicChar=qtb15(unicodeChar-codemap[k][0]);
break;
case 16:
asiicChar=qtb16(unicodeChar-codemap[k][0]);
break;
case 17:
asiicChar=qtb17(unicodeChar-codemap[k][0]);
break;
case 18:
asiicChar=qtb18(unicodeChar-codemap[k][0]);
break;
case 19:
asiicChar=qtb19(unicodeChar-codemap[k][0]);
break;
}
break;
}
}
}
if(asiicChar==0)
{
//could not find proper char...deal as asiic
if(unicodeChar==0xfeff)
{
pointer+=2;
}
else
{
if((char *)pointer!=0)
{
smsBuf[smsDispLen]=*((char *)pointer);
smsDispLen++;
//FldInsert(field,(char *)pointer,1);
}
pointer++;
}
}
else
{
if(*((char *)&asiicChar+1)!=0)
{
smsBuf[smsDispLen]=*((char *)&asiicChar+1);
smsDispLen++;
}
if(*((char *)&asiicChar)!=0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -