1820 lines
48 KiB
C
1820 lines
48 KiB
C
![]() |
#include "version.h"
|
|||
|
#include <sys/types.h>
|
|||
|
#include <sys/socket.h>
|
|||
|
#include <sys/time.h>
|
|||
|
#include <sys/stat.h>
|
|||
|
|
|||
|
#include <netinet/in.h>
|
|||
|
#include <arpa/inet.h>
|
|||
|
#include <stdio.h>
|
|||
|
#include <string.h>
|
|||
|
#include <stdlib.h>
|
|||
|
#include <unistd.h>
|
|||
|
#include <dirent.h>
|
|||
|
#include <netdb.h>
|
|||
|
#include <errno.h>
|
|||
|
#include <ctype.h>
|
|||
|
#include "common.h"
|
|||
|
#include "util.h"
|
|||
|
#include "configfile.h"
|
|||
|
#include <assert.h>
|
|||
|
#define IS_2BYTEWORD( _a_ ) ( (char)(0x80) <= (_a_) && (_a_) <= (char)(0xFF) )
|
|||
|
|
|||
|
/*-----------------------------------------
|
|||
|
<EFBFBD>깴<EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>
|
|||
|
¦<EFBFBD>ѡ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD>缰 ٯ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD>ʽ<EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
windows , macintosh , unix<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ɱƥ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
|
|||
|
windows : \r\n
|
|||
|
macintosh : \n\r
|
|||
|
unix : \n
|
|||
|
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ
|
|||
|
macintosh : \r
|
|||
|
ƥ<EFBFBD>ʣ<EFBFBD>
|
|||
|
<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ة<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>깴<EFBFBD><EFBFBD> ٯԪ<EFBFBD><EFBFBD>ئ<EFBFBD>ʻ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD>ʾ<EFBFBD>
|
|||
|
-----------------------------------------*/
|
|||
|
void chompex( char *buf )
|
|||
|
{
|
|||
|
while( *buf ){
|
|||
|
if( *buf == '\r' || *buf == '\n' ){
|
|||
|
*buf='\0';
|
|||
|
}
|
|||
|
buf++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* <EFBFBD>깴<EFBFBD><EFBFBD>1 ٯë<EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
----------------------------------------*/
|
|||
|
void chop( char* src )
|
|||
|
{
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD> <EFBFBD><EFBFBD> ٯë<EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
int length = strlen( src );
|
|||
|
if( length == 0 ) return;
|
|||
|
src[length-1] = '\0';
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* <EFBFBD>깴<EFBFBD><EFBFBD> ٯë<EFBFBD><EFBFBD><EFBFBD>£۹<EFBFBD><EFBFBD><EFBFBD> ٯë <EFBFBD><EFBFBD>϶<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD>缰 ٯ
|
|||
|
* delim <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>NULL ٯƥ<EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
void dchop( char* src , char* del)
|
|||
|
{
|
|||
|
int dellen, srclen;
|
|||
|
int i;
|
|||
|
BOOL delete=FALSE;
|
|||
|
|
|||
|
/*
|
|||
|
* src<EFBFBD><EFBFBD> Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʃ<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>1 ٯ<EFBFBD>年<EFBFBD><EFBFBD> del <EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ۹<EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD>ݼ<EFBFBD> ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
srclen = strlen( src );
|
|||
|
dellen = strlen( del );
|
|||
|
if( srclen == 0 || dellen == 0 ) return;
|
|||
|
|
|||
|
for( i = 0 ; i < dellen ; i ++ ){
|
|||
|
if( src[srclen-1] == del[i] ){
|
|||
|
delete = TRUE;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/* <20><>Ի<EFBFBD><D4BB>Ի */
|
|||
|
if( delete )src[srclen - 1] = '\0';
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* dchop<EFBFBD><EFBFBD><EFBFBD>ѣ<EFBFBD> <EFBFBD>ټ<EFBFBD> ٯë<EFBFBD><EFBFBD><EFBFBD>£۹<EFBFBD><EFBFBD><EFBFBD> ٯë <EFBFBD><EFBFBD>϶<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD>缰 ٯ
|
|||
|
* delim <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>NULL ٯƥ<EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
void pohcd( char* src , char* del)
|
|||
|
{
|
|||
|
int dellen, srclen;
|
|||
|
int i;
|
|||
|
BOOL delete=FALSE;
|
|||
|
|
|||
|
/*
|
|||
|
* src<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʃ<EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>1 ٯ<EFBFBD>年<EFBFBD><EFBFBD> del <EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ۹<EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD>ݼ<EFBFBD> ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
srclen = strlen( src );
|
|||
|
dellen = strlen( del );
|
|||
|
if( srclen == 0 || dellen == 0 ) return;
|
|||
|
|
|||
|
for( i = 0 ; i < dellen ; i ++ ){
|
|||
|
if( src[0] == del[i] ){
|
|||
|
delete = TRUE;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD> */
|
|||
|
if( delete )
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ NULL ٯ<><D9AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE> */
|
|||
|
for( i = 0 ; i < srclen ; i ++ )
|
|||
|
src[i] = src[i+1];
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* ٯ <EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD>ֳ<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʃ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src char* Ʃ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* include char* ֳ<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD> <EFBFBD>ٱ<EFBFBD>ֳ<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>src<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD> -1
|
|||
|
----------------------------------------*/
|
|||
|
int charInclude( char* src, char* include )
|
|||
|
{
|
|||
|
int i,j;
|
|||
|
int srclen,includelen;
|
|||
|
|
|||
|
srclen = strlen( src );
|
|||
|
includelen = strlen( include );
|
|||
|
|
|||
|
for( i = 0 ; i < srclen ; i ++ ){
|
|||
|
for( j = 0 ; j < includelen ; j ++ )
|
|||
|
if( src[i] == include[j] )
|
|||
|
return i;
|
|||
|
}
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*------------------------------------------------------------
|
|||
|
* EUC<EFBFBD><EFBFBD>2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>strncpy
|
|||
|
* freeBSD <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> strncpy ë<EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD>廯<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ľë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱհ<EFBFBD><EFBFBD>*dest++ <EFBFBD>羮<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>컥
|
|||
|
* ئ<EFBFBD>м<EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>У۾<EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ئԻ ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ة
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* dest char* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* src char* ĩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* n size_t Ӯ<EFBFBD><EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* dest
|
|||
|
------------------------------------------------------------*/
|
|||
|
char* strncpy2( char* dest, const char* src, size_t n )
|
|||
|
{
|
|||
|
if( n > 0 ){
|
|||
|
char* d = dest;
|
|||
|
const char* s = src;
|
|||
|
int i;
|
|||
|
for( i=0; i<n ; i++ ){
|
|||
|
if( *(s+i) == 0 ){
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> NULL ٯë ľ<><C4BE> */
|
|||
|
*(d+i) = '\0';
|
|||
|
return dest;
|
|||
|
}
|
|||
|
if( *(s+i) & 0x80 ){
|
|||
|
*(d+i) = *(s+i);
|
|||
|
i++;
|
|||
|
if( i>=n ){
|
|||
|
*(d+i-1)='\0';
|
|||
|
break;
|
|||
|
}
|
|||
|
*(d+i) = *(s+i);
|
|||
|
}else
|
|||
|
*(d+i) = *(s+i);
|
|||
|
}
|
|||
|
}
|
|||
|
return dest;
|
|||
|
}
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dest <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ëƩ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* dest <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* n <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD>缰 ٯ
|
|||
|
----------------------------------------*/
|
|||
|
void strcpysafe( char* dest ,size_t n ,const char* src )
|
|||
|
{
|
|||
|
/*
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dest <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* strcpy, strncpy ƥ<EFBFBD><EFBFBD> dest <EFBFBD><EFBFBD>Ի <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ƹ<EFBFBD><EFBFBD>½ʧ<EFBFBD>ͱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* <EFBFBD><EFBFBD>ľë ʲ<EFBFBD>б<EFBFBD>, strncpy <EFBFBD><EFBFBD>ؤ<EFBFBD>»<EFBFBD> strlen( src ) <EFBFBD><EFBFBD> n <EFBFBD><EFBFBD>Ի
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ巴, dest <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> NULL ٯ<EFBFBD>練ئ<EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>.
|
|||
|
*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD> dest <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի src <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD><EFBFBD>ݱ巴
|
|||
|
* n-1 ƥ strncpy ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* n <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD>ƾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>¼<EFBFBD>ƥ <EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>У<EFBFBD>
|
|||
|
*
|
|||
|
*/
|
|||
|
// Nuke +1 (08/25): Danger if src=0
|
|||
|
if (!src) {
|
|||
|
*dest = '\0';
|
|||
|
return;
|
|||
|
}
|
|||
|
if( n <= 0 ) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><D8A6> */
|
|||
|
return;
|
|||
|
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5> n >= 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
/* NULL ٯë<D9AF><C3AB> <20>ƻ<EFBFBD> ʤ<><CAA4><EFBFBD><EFBFBD> */
|
|||
|
else if( n < strlen( src ) + 1 ){
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻥<EFBFBD><EFBFBD>Իئ<EFBFBD>м<EFBFBD>ƥ n - 1(NULL ٯ)
|
|||
|
* ƥ strncpy ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
strncpy2( dest , src , n-1 );
|
|||
|
dest[n-1]='\0';
|
|||
|
}else
|
|||
|
strcpy( dest , src );
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD> length <EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƽ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ëƩ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* dest <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* n <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* length <EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾<EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
void strncpysafe( char* dest , const size_t n ,
|
|||
|
const char* src ,const int length )
|
|||
|
{
|
|||
|
/*
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dest <EFBFBD><EFBFBD> length <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* strcpy, strncpy ƥ<EFBFBD><EFBFBD> dest <EFBFBD><EFBFBD>Ի <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<EFBFBD><EFBFBD>ƹ<EFBFBD><EFBFBD>½ʧ<EFBFBD>ͱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>strlen( src ) <EFBFBD><EFBFBD> length <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>лõ<EFBFBD>
|
|||
|
* ( <EFBFBD>˱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) <EFBFBD><EFBFBD> dest <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* strcpysafe <EFBFBD><EFBFBD> Ԫ<EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
int Short;
|
|||
|
Short = min( strlen( src ) , length );
|
|||
|
|
|||
|
/* NULL ٯ ë<><C3AB> <20><><EFBFBD><EFBFBD> ʤ */
|
|||
|
if( n < Short + 1 ){
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻥<EFBFBD><EFBFBD>Իئ<EFBFBD>м<EFBFBD>ƥ n - 1(NULL ٯ)
|
|||
|
* ƥ strncpy ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
strncpy2( dest , src , n-1 );
|
|||
|
dest[n-1]='\0';
|
|||
|
|
|||
|
}else if( n <= 0 ){
|
|||
|
return;
|
|||
|
}else{
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뷴<EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>ؤ<EFBFBD>¼<EFBFBD>ƥ Short ƥstrncpyë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ئ<EFBFBD><EFBFBD> src <EFBFBD>巴 Short <EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> NULL <EFBFBD><EFBFBD>ئ<EFBFBD>м<EFBFBD>ƥ<EFBFBD><EFBFBD>
|
|||
|
* dest <EFBFBD>巴 ܰ<EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
strncpy2( dest , src , Short );
|
|||
|
dest[Short]= '\0';
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/*------------------------------------------------------------
|
|||
|
* strcatë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD><EFBFBD><EFBFBD><EFBFBD>м<EFBFBD>ƥ<EFBFBD><EFBFBD> ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src char* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD> ٯ
|
|||
|
* size int src <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>( Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾<EFBFBD>ƥ<EFBFBD><EFBFBD>
|
|||
|
* ئ<EFBFBD>ʻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> )
|
|||
|
* ap char* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* src ( ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
------------------------------------------------------------*/
|
|||
|
char* strcatsafe( char* src, int size, char* ap )
|
|||
|
{
|
|||
|
strcpysafe( src + strlen( src ) , size - strlen(src), ap );
|
|||
|
return src;
|
|||
|
}
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* ٯ <EFBFBD><EFBFBD> ë ʤ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD> Ԫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƾ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD> by ringo
|
|||
|
* char *s1 , *s2 : ʤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* 0 <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ئԪ
|
|||
|
* 1 : <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD>NPC<EFBFBD><EFBFBD> ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݩ <EFBFBD><EFBFBD>֧<EFBFBD>ʷֹ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
int strcmptail( char *s1 , char *s2 )
|
|||
|
{
|
|||
|
int i;
|
|||
|
int len1 = strlen( s1 );
|
|||
|
int len2 = strlen( s2 );
|
|||
|
|
|||
|
for(i=0;;i++){
|
|||
|
int ind1 = len1 - 1 - i;
|
|||
|
int ind2 = len2 - 1 - i;
|
|||
|
if( ind1 < 0 || ind2 < 0 ) return 0;
|
|||
|
if( s1[ind1] != s2[ind2] ) return 1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* ٯ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>̤<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°<EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* NPC<EFBFBD><EFBFBD> ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݩ <EFBFBD><EFBFBD>֧<EFBFBD>ʷֹ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD>ؤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>Ȭ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ة<EFBFBD><EFBFBD> <EFBFBD>ʣ<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* hoge char* ݩ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* ݩ <EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>ѣ<EFBFBD>
|
|||
|
*
|
|||
|
* <EFBFBD><EFBFBD>
|
|||
|
* "ringo ( <20><><EFBFBD>۰<EFBFBD><DBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ) <20><> 100"
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* "ringo ( <20><><EFBFBD>۰<EFBFBD><DBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ) <20><> <20><>100"
|
|||
|
* <EFBFBD><EFBFBD>100<EFBFBD><EFBFBD>ئ<EFBFBD>£ۻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC<EFBFBD><EFBFBD>ئԻ<EFBFBD>ѣ<EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
#define DECIMALCHARNUM 10
|
|||
|
#define FIGURECHARNUM 3
|
|||
|
#define SPECIALCHARNUM 2
|
|||
|
char *UTIL_decimalchar[DECIMALCHARNUM] = {"0","1","2",
|
|||
|
"3", "4","5",
|
|||
|
"6","7","8","9"};
|
|||
|
char *UTIL_figurechar[FIGURECHARNUM] = {"","",""};
|
|||
|
char *UTIL_specialchar[SPECIALCHARNUM] = {"",""};
|
|||
|
|
|||
|
/*
|
|||
|
* ٯ <EFBFBD><EFBFBD><EFBFBD>գ<EFBFBD><EFBFBD>Ѱ<EFBFBD>ë <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ë <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD>euc<EFBFBD>ã<EFBFBD>
|
|||
|
*
|
|||
|
* : in "<EFBFBD>Ȿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>300<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
|
|||
|
* out "7<EFBFBD><EFBFBD>"
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* char *in: ٯ
|
|||
|
* char *out:<EFBFBD><EFBFBD> ٯ
|
|||
|
* int outsiz:<EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD>Ѱ<EFBFBD>ë <EFBFBD><EFBFBD> <EFBFBD>л<EFBFBD>ؤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD><EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ը<EFBFBD>
|
|||
|
*/
|
|||
|
static int findNumberString( char *in, char *out, int outsiz )
|
|||
|
{
|
|||
|
int len,i,j,k, findflag, numstrflag;
|
|||
|
char tmp[3];
|
|||
|
|
|||
|
len = strlen(in);
|
|||
|
if( len == 0 ) return 0;
|
|||
|
|
|||
|
numstrflag=0;
|
|||
|
findflag = 0;
|
|||
|
for( i=0,j=0;in[i]!='\0'&& j<outsiz-2;i++ ){
|
|||
|
findflag = 0;
|
|||
|
if( in[i] & 0x80 ){
|
|||
|
/* EUC<55><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
tmp[0] = in[i];
|
|||
|
tmp[1] = in[i+1];
|
|||
|
tmp[2] = '\0';
|
|||
|
}else{
|
|||
|
/* ASCII<49><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
tmp[0] = in[i];
|
|||
|
tmp[1] = '\0';
|
|||
|
}
|
|||
|
for( k=0;k<DECIMALCHARNUM;k++ ){
|
|||
|
if( strstr( UTIL_decimalchar[k], tmp ) ){
|
|||
|
numstrflag = 1;
|
|||
|
findflag = 1;
|
|||
|
}
|
|||
|
}
|
|||
|
for( k=0;k<FIGURECHARNUM;k++ ){
|
|||
|
if( strstr( UTIL_figurechar[k], tmp ) ){
|
|||
|
numstrflag = 1;
|
|||
|
findflag = 1;
|
|||
|
}
|
|||
|
}
|
|||
|
for( k=0;k<SPECIALCHARNUM;k++ ){
|
|||
|
if( strstr( UTIL_specialchar[k], tmp ) ){
|
|||
|
numstrflag = 1;
|
|||
|
findflag = 1;
|
|||
|
}
|
|||
|
}
|
|||
|
if( findflag ){
|
|||
|
if( in[i] & 0x80 ){
|
|||
|
out[j] = tmp[0];
|
|||
|
out[j+1] = tmp[1];
|
|||
|
j+=2;
|
|||
|
i++;
|
|||
|
}else{
|
|||
|
out[j] = tmp[0];
|
|||
|
j+=1;
|
|||
|
}
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
if( numstrflag ){
|
|||
|
out[j] = '\0';
|
|||
|
return j;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
if( findflag ){
|
|||
|
out[j] = '\0';
|
|||
|
return j;
|
|||
|
}else{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
* ٯ ëint<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
*/
|
|||
|
int numstrIsKanji( char *str );
|
|||
|
int decimalstrToInt( char *str );
|
|||
|
int kanjistrToInt( char *str );
|
|||
|
|
|||
|
int textToInt( char *str )
|
|||
|
{
|
|||
|
char numstr[256];
|
|||
|
if( !findNumberString(str,numstr,sizeof(numstr)) ) return 0;
|
|||
|
|
|||
|
if( numstrIsKanji(numstr) ) return kanjistrToInt(numstr);
|
|||
|
else return decimalstrToInt(numstr);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD>Ѱ<EFBFBD>ë <EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ֿئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë
|
|||
|
* ¦<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٯë <EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD>½<EFBFBD><EFBFBD>ֳ<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>У<EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ֿئ<EFBFBD>ը<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֿئ<EFBFBD>ը<EFBFBD>
|
|||
|
* str <EFBFBD><EFBFBD>"һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߯Ի<EFBFBD><EFBFBD>1
|
|||
|
* str <EFBFBD><EFBFBD>"123"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߯Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
*/
|
|||
|
int numstrIsKanji( char *str )
|
|||
|
{
|
|||
|
int i,j;
|
|||
|
char tmp[3];
|
|||
|
|
|||
|
for( i=0;str[i]!='\0';i++ ){
|
|||
|
if( str[i] & 0x80 ){
|
|||
|
tmp[0] = str[i];
|
|||
|
tmp[1] = str[i+1];
|
|||
|
tmp[2] = '\0';
|
|||
|
i++;
|
|||
|
}else{
|
|||
|
tmp[0] = str[i];
|
|||
|
tmp[1] = '\0';
|
|||
|
}
|
|||
|
for( j=0;j<FIGURECHARNUM;j++ ){
|
|||
|
if( strstr(UTIL_figurechar[j],tmp) ){
|
|||
|
return 1;
|
|||
|
}
|
|||
|
}
|
|||
|
for( j=0;j<SPECIALCHARNUM;j++ ){
|
|||
|
if( strstr(UTIL_specialchar[j],tmp) ){
|
|||
|
return 1;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return 0;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܷƥ<EFBFBD>Ѱ<EFBFBD>ë <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ ëint<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* char *str ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD>
|
|||
|
*/
|
|||
|
int decimalstrToInt( char *str )
|
|||
|
{
|
|||
|
|
|||
|
double val;
|
|||
|
char tmp[3];
|
|||
|
int i,j;
|
|||
|
|
|||
|
val = 0;
|
|||
|
for( i=0;str[i]!='\0';i++ ){
|
|||
|
if( str[i] & 0x80 ){
|
|||
|
tmp[0] = str[i];
|
|||
|
tmp[1] = str[i+1];
|
|||
|
tmp[2] = '\0';
|
|||
|
i++;
|
|||
|
}else{
|
|||
|
tmp[0] = str[i];
|
|||
|
tmp[1] = '\0';
|
|||
|
}
|
|||
|
for( j=0;j<DECIMALCHARNUM;j++ ){
|
|||
|
if( strstr(UTIL_decimalchar[j],tmp) ){
|
|||
|
val = val*10+j;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if( val > 0x7fffffff ) return 0x7fffffff;
|
|||
|
else return (int)val;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*
|
|||
|
* ֿƥ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* char *str <EFBFBD>Ѱ<EFBFBD>ë <EFBFBD><EFBFBD> ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD> <EFBFBD>Ѱ<EFBFBD>
|
|||
|
*
|
|||
|
* str<EFBFBD><EFBFBD>"һ<EFBFBD><EFBFBD>4ǧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߯Ի<EFBFBD><EFBFBD> 140000000
|
|||
|
*/
|
|||
|
int kanjistrToInt( char *str )
|
|||
|
{
|
|||
|
double val,tmpval;
|
|||
|
char tmp[3];
|
|||
|
int num,i,j,numflag;
|
|||
|
|
|||
|
numflag = 0;
|
|||
|
num = 1;
|
|||
|
tmpval = 0;
|
|||
|
val = 0;
|
|||
|
for( i=0;str[i]!='\0';i++ ){
|
|||
|
if( str[i] & 0x80 ){
|
|||
|
tmp[0] = str[i];
|
|||
|
tmp[1] = str[i+1];
|
|||
|
tmp[2] = '\0';
|
|||
|
i++;
|
|||
|
}else{
|
|||
|
tmp[0] = str[i];
|
|||
|
tmp[1] = '\0';
|
|||
|
}
|
|||
|
for( j=0;j<SPECIALCHARNUM;j++ ){
|
|||
|
if( strstr(UTIL_specialchar[j],tmp ) ){
|
|||
|
if( numflag == 1 ) tmpval += num;
|
|||
|
if( j == 0 ) val += tmpval*10000;
|
|||
|
else if( j == 1 ) val += tmpval*100000000;
|
|||
|
num = 1;
|
|||
|
numflag = 0;
|
|||
|
tmpval = 0;
|
|||
|
goto nextchar;
|
|||
|
}
|
|||
|
}
|
|||
|
for( j=0;j<FIGURECHARNUM;j++ ){
|
|||
|
if( strstr(UTIL_figurechar[j],tmp) ){
|
|||
|
if( j == 0 ) tmpval += num*10;
|
|||
|
else if( j == 1 ) tmpval += num*100;
|
|||
|
else if( j == 2 ) tmpval += num*1000;
|
|||
|
num = 1;
|
|||
|
numflag = 0;
|
|||
|
goto nextchar;
|
|||
|
}
|
|||
|
}
|
|||
|
for( j=0;j<DECIMALCHARNUM;j++ ){
|
|||
|
if( strstr(UTIL_decimalchar[j],tmp) ){
|
|||
|
num = j;
|
|||
|
numflag = 1;
|
|||
|
goto nextchar;
|
|||
|
}
|
|||
|
}
|
|||
|
nextchar:
|
|||
|
continue;
|
|||
|
}
|
|||
|
if( numflag == 1 ) tmpval += num;
|
|||
|
val += tmpval;
|
|||
|
|
|||
|
if( val > 0x7fffffff ) return 0x7fffffff;
|
|||
|
else return (int)val;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* ٯ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>̤<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>°<EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* NPC<EFBFBD><EFBFBD> ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݩ <EFBFBD><EFBFBD>֧<EFBFBD>ʷֹ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD>ؤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>Ȭ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ة<EFBFBD><EFBFBD> <EFBFBD>ʣ<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* hoge char* ݩ <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* ݩ <EFBFBD><EFBFBD><EFBFBD>װ<EFBFBD><EFBFBD>ѣ<EFBFBD>
|
|||
|
*
|
|||
|
* <EFBFBD><EFBFBD>
|
|||
|
* "ringo ( <20><><EFBFBD>۰<EFBFBD><DBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ) <20><> 100"
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>100<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* "ringo ( <20><><EFBFBD>۰<EFBFBD><DBB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ) <20><> <20><>100"
|
|||
|
* <EFBFBD><EFBFBD>100<EFBFBD><EFBFBD>ئ<EFBFBD>£ۻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>NPC<EFBFBD><EFBFBD>ئԻ<EFBFBD>ѣ<EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
int texttoiTail( char *hoge)
|
|||
|
{
|
|||
|
return 0; /* <20><>ʲ<EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ף۹<D7A3><DBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD> */
|
|||
|
}
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* ٯ ë<EFBFBD><EFBFBD>ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD>ѱ<EFBFBD> ľ<EFBFBD><EFBFBD>߯<EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* arg <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* number <EFBFBD><EFBFBD> ëҽ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* base <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* type ¦<EFBFBD>Ѽ<EFBFBD><EFBFBD><EFBFBD>( CTYPE <EFBFBD><EFBFBD> common.h <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> )
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* TRUE(1) <EFBFBD><EFBFBD>
|
|||
|
* FALSE(0) strtol<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ձ巴<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD>number<EFBFBD><EFBFBD>strtol<EFBFBD><EFBFBD>߯Ի<EFBFBD><EFBFBD>ƥؤ<EFBFBD><EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
BOOL strtolchecknum( char* arg , void* number,int base ,CTYPE type)
|
|||
|
{
|
|||
|
char* buf;
|
|||
|
int num;
|
|||
|
|
|||
|
num = strtol( arg, &buf, base);
|
|||
|
|
|||
|
switch( type ){
|
|||
|
case CHAR:
|
|||
|
*(char*)number = (char)num;
|
|||
|
break;
|
|||
|
case SHORT:
|
|||
|
*(short*)number = (short)num;
|
|||
|
break;
|
|||
|
case INT:
|
|||
|
*(int*)number = num;
|
|||
|
break;
|
|||
|
case DOUBLE:
|
|||
|
*(double*)number = (double)num;
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if( strlen( buf ) >= 1 )
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD>Ի ٯ<EFBFBD><EFBFBD>ؤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>Ƿ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>
|
|||
|
*/
|
|||
|
return FALSE;
|
|||
|
|
|||
|
return TRUE;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dels ƥ϶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯë<EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ب<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥؤ<EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ب<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD>ئ<EFBFBD>У<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD>ʽ<EFBFBD>ľ<EFBFBD><EFBFBD> ٯ
|
|||
|
* char* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ( ٯ ƥ϶<EFBFBD>õ<EFBFBD>)
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* ئ<EFBFBD><EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
void deleteCharFromString( char* src , char* dels )
|
|||
|
{
|
|||
|
int index=0; /* ƥ<><C6A5>ؤ<EFBFBD><D8A4>Ի<EFBFBD><D4BB> ٯ ƥ<><C6A5> index */
|
|||
|
int delength; /* dels <20><>Ӯ<EFBFBD><D3AE>ëɬ<C3AB><C9AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>պʧ<D5BA><CAA7><EFBFBD><EFBFBD> */
|
|||
|
int i=0,j;/* i <20><> src ë<><C3AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> j <20><> dels ë<><C3AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> */
|
|||
|
|
|||
|
delength= strlen( dels );
|
|||
|
|
|||
|
while( src[i] != '\0' ){
|
|||
|
if( src[i] == BACKSLASH )
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>بئ<EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD>ݼ<EFBFBD> ٯ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
src[index++] = src[++i]; /* substitute next char */
|
|||
|
|
|||
|
else{
|
|||
|
for( j = 0 ; j < delength ; j ++ ){
|
|||
|
if( src[i] == dels[j] )
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD>֣۷<EFBFBD><EFBFBD>Ȼ<EFBFBD> i <EFBFBD><EFBFBD> 1 ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
goto incrementi;
|
|||
|
}
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>϶<EFBFBD>ý<EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>м<EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
*/
|
|||
|
src[index++] = src[i];
|
|||
|
}
|
|||
|
incrementi:
|
|||
|
i++;
|
|||
|
}
|
|||
|
|
|||
|
src[index] = '\0';
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD> dels ƥ϶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯë<EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD>ʽ<EFBFBD>ľ<EFBFBD><EFBFBD> ٯ
|
|||
|
* char* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ( ٯ ƥ϶<EFBFBD>õ<EFBFBD>)
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* ئ<EFBFBD><EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
void deleteCharFromStringNoEscape( char* src , char* dels )
|
|||
|
{
|
|||
|
int index=0; /* ƥ<><C6A5>ؤ<EFBFBD><D8A4>Ի<EFBFBD><D4BB> ٯ ƥ<><C6A5> index */
|
|||
|
int delength; /* dels <20><>Ӯ<EFBFBD><D3AE>ëɬ<C3AB><C9AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD>Ʒ<EFBFBD><C6B7><EFBFBD>պʧ<D5BA><CAA7><EFBFBD><EFBFBD> */
|
|||
|
int i=0,j;/* i <20><> src ë<><C3AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> j <20><> dels ë<><C3AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> */
|
|||
|
|
|||
|
delength= strlen( dels );
|
|||
|
|
|||
|
while( src[i] != '\0' ){
|
|||
|
for( j = 0 ; j < delength ; j ++ ){
|
|||
|
if( src[i] == dels[j] )
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD>֣۷<EFBFBD><EFBFBD>Ȼ<EFBFBD> i <EFBFBD><EFBFBD> 1 ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
goto incrementi;
|
|||
|
}
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>϶<EFBFBD>ý<EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>м<EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
*/
|
|||
|
src[index++] = src[i];
|
|||
|
incrementi:
|
|||
|
i++;
|
|||
|
}
|
|||
|
|
|||
|
src[index] = '\0';
|
|||
|
}
|
|||
|
|
|||
|
/*------------------------------------------------------------
|
|||
|
* ϶<EFBFBD>ý<EFBFBD>ľ<EFBFBD><EFBFBD> ٯë϶<EFBFBD>ý<EFBFBD>ľ<EFBFBD><EFBFBD> ٯƥ <EFBFBD>微<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src char* <EFBFBD>ʽ<EFBFBD>ľ<EFBFBD><EFBFBD> ٯ
|
|||
|
* oldc char <EFBFBD>ʽ<EFBFBD>ľ<EFBFBD><EFBFBD> ٯ
|
|||
|
* newc char <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* src
|
|||
|
------------------------------------------------------------*/
|
|||
|
char* replaceString( char* src, char oldc ,char newc )
|
|||
|
{
|
|||
|
char* cp=src;
|
|||
|
|
|||
|
do{
|
|||
|
if( *cp == oldc ) *cp=newc;
|
|||
|
}while( *cp++ );
|
|||
|
return src;
|
|||
|
}
|
|||
|
|
|||
|
typedef struct tagEscapeChar
|
|||
|
{
|
|||
|
char escapechar;
|
|||
|
char escapedchar;
|
|||
|
}EscapeChar;
|
|||
|
static EscapeChar escapeChar[]=
|
|||
|
{
|
|||
|
{ '\n', 'n' },
|
|||
|
{ ',', 'c' },
|
|||
|
{ '|', 'z' },
|
|||
|
{ '\\', 'y' },
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
char makeCharFromEscaped( char c )//add this function,because the second had it
|
|||
|
{
|
|||
|
int i;
|
|||
|
|
|||
|
for( i = 0; i < sizeof( escapeChar )/sizeof( escapeChar[0] ); i++ )
|
|||
|
{
|
|||
|
if( escapeChar[i].escapedchar == c )
|
|||
|
{
|
|||
|
c = escapeChar[i].escapechar;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
return c;
|
|||
|
}
|
|||
|
/*----------------------------------------
|
|||
|
* makeEscapeStringƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD> ٯ ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src char* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD> ٯ <EFBFBD>۳<EFBFBD>ľ<EFBFBD><EFBFBD>̤<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* src ë߯<EFBFBD>ʣ<EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
----------------------------------------*/
|
|||
|
char *makeStringFromEscaped( char* src )
|
|||
|
{//ttom this function all change,beside copy from the second
|
|||
|
|
|||
|
int i;
|
|||
|
// CoolFish: Fix bug 2001/10/13
|
|||
|
// int srclen = strlen( src );
|
|||
|
int srclen = 0;
|
|||
|
int searchindex=0;
|
|||
|
|
|||
|
// CoolFish: Fix bug 2001/10/13
|
|||
|
if (!src) return NULL;
|
|||
|
srclen = strlen(src);
|
|||
|
|
|||
|
for( i = 0; i < srclen; i ++ )
|
|||
|
{
|
|||
|
// for 2Byte Word
|
|||
|
if( IS_2BYTEWORD( src[i] ) ){
|
|||
|
src[searchindex++] = src[i++];
|
|||
|
src[searchindex++] = src[i];
|
|||
|
}else
|
|||
|
if( src[i] == '\\' )
|
|||
|
{
|
|||
|
// <20>ݼ<EFBFBD> ٯ<><D9AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
i++;
|
|||
|
src[searchindex++] = makeCharFromEscaped( src[i] );
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
src[searchindex++] = src[i];
|
|||
|
}
|
|||
|
}
|
|||
|
src[searchindex] = '\0';
|
|||
|
|
|||
|
return src;
|
|||
|
}
|
|||
|
|
|||
|
char* makeEscapeString( char* src , char* dest, int sizeofdest)
|
|||
|
{ //ttom this function all change, copy from the second
|
|||
|
int i;
|
|||
|
int srclen = 0;
|
|||
|
int destindex=0;
|
|||
|
|
|||
|
// CoolFish: Fix bug 2001/10/13
|
|||
|
if (!src) return NULL;
|
|||
|
srclen = strlen(src);
|
|||
|
|
|||
|
for( i = 0 ; i < srclen ; i ++ ){
|
|||
|
BOOL dirty=FALSE;
|
|||
|
int j;
|
|||
|
char escapechar='\0';
|
|||
|
if( destindex + 1 >= sizeofdest )break;
|
|||
|
if( IS_2BYTEWORD( src[i] ) ){
|
|||
|
if( destindex + 2 >= sizeofdest )break;
|
|||
|
|
|||
|
dest[destindex] = src[i];
|
|||
|
dest[destindex+1] = src[i+1];
|
|||
|
destindex += 2;
|
|||
|
i ++;
|
|||
|
continue;
|
|||
|
}
|
|||
|
for( j = 0; j<sizeof(escapeChar)/sizeof(escapeChar[0]); j++){
|
|||
|
if( src[i] == escapeChar[j].escapechar ){
|
|||
|
dirty=TRUE;
|
|||
|
escapechar= escapeChar[j].escapedchar;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if( dirty == TRUE ){
|
|||
|
if( destindex + 2 < sizeofdest ){
|
|||
|
dest[destindex] = '\\';
|
|||
|
dest[destindex+1] = escapechar;
|
|||
|
destindex+=2;
|
|||
|
dirty=TRUE;
|
|||
|
continue;
|
|||
|
}else{
|
|||
|
dest[destindex] = '\0';
|
|||
|
return dest;
|
|||
|
}
|
|||
|
}else{
|
|||
|
dest[destindex] = src[i];
|
|||
|
destindex++;
|
|||
|
}
|
|||
|
}
|
|||
|
dest[destindex] = '\0';
|
|||
|
return dest;
|
|||
|
}
|
|||
|
|
|||
|
//this function copy all from the second
|
|||
|
char * ScanOneByte( char *src, char delim ){
|
|||
|
// Nuke
|
|||
|
if (!src) return NULL;
|
|||
|
|
|||
|
// ٯ <20><>ئ<EFBFBD><D8A6>ئ<EFBFBD><D8A6><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD>
|
|||
|
for( ;src[0] != '\0'; src ++ ){
|
|||
|
// <20><>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><C3AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if( IS_2BYTEWORD( src[0] ) ){
|
|||
|
// <20><>ʣ<EFBFBD>֣۹<D6A3><DBB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
// <20><EFBFBD><D7B7>ƨ<EFBFBD><C6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƾ<EFBFBD>ئ<EFBFBD><D8A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><D8A6>
|
|||
|
if( src[1] != 0 ){
|
|||
|
src ++;
|
|||
|
}
|
|||
|
continue;
|
|||
|
}
|
|||
|
// ʣ<><CAA3><EFBFBD><EFBFBD><EFBFBD>ף۳<D7A3><DBB3><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD> ٯ<><D9AF> ʤ
|
|||
|
if( src[0] == delim ){
|
|||
|
return src;
|
|||
|
}
|
|||
|
}
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>έ<EFBFBD><CEAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><D8A6><EFBFBD><EFBFBD><EFBFBD>ף<EFBFBD>
|
|||
|
return NULL;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* delim ƥ϶<EFBFBD>ý<EFBFBD>ľ<EFBFBD><EFBFBD> ٯ ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի ٯ<EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD>
|
|||
|
* index <EFBFBD><EFBFBD> ë <EFBFBD>£<EFBFBD>index<EFBFBD><EFBFBD>1ƥ<EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* ٯ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD>缰 ٯ
|
|||
|
* delim <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>NULL ٯƥ<EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* index <EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ë<EFBFBD><EFBFBD><EFBFBD>¾<EFBFBD>
|
|||
|
* buf <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ ëɡ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* buflen <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ ëɡ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* ؤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> TRUE(1);
|
|||
|
* ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> FALSE(0);
|
|||
|
* ex
|
|||
|
* getStringFromIndexWithDelim( "aho=hoge","=",1,buf,sizeof(buf) );
|
|||
|
* buf ... aho
|
|||
|
*
|
|||
|
* getStringFromIndexWithDelim( "aho=hoge","=",2,buf,sizeof(buf) );
|
|||
|
* buf ... hoge
|
|||
|
* <EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD>£<EFBFBD>
|
|||
|
*
|
|||
|
* getStringFromIndexWithDelim( "aho=hoge","=",3,buf,sizeof(buf) );
|
|||
|
* ߯Ի<EFBFBD><EFBFBD> FALSE
|
|||
|
----------------------------------------*/
|
|||
|
BOOL getStringFromIndexWithDelim_body( char* src ,char* delim ,int index,
|
|||
|
char* buf , int buflen ,
|
|||
|
char *file, int line )
|
|||
|
{//ttom this function all change,copy from the second
|
|||
|
int i; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> */
|
|||
|
int length =0; /* <20><>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ <20><>Ӯ<EFBFBD><D3AE> */
|
|||
|
int addlen=0; /* <20><><EFBFBD><EFBFBD>ľ<EFBFBD><C4BE>Ӯ<EFBFBD><D3AE> */
|
|||
|
int oneByteMode = 0; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD> */
|
|||
|
|
|||
|
if( strlen( delim ) == 1 ){ // <20><><EFBFBD><EFBFBD><F1BBA5A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>ը<EFBFBD><D5A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
oneByteMode = 1;// <20><><EFBFBD><EFBFBD><EFBFBD>˨<EFBFBD><CBA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<><D9AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><D8A6>
|
|||
|
}
|
|||
|
for( i = 0 ; i < index ; i ++ ){
|
|||
|
char* last;
|
|||
|
src += addlen;/* <20>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӯ<EFBFBD><D3AE>ë<EFBFBD><C3AB><EFBFBD><EFBFBD> */
|
|||
|
|
|||
|
if( oneByteMode ){
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD>
|
|||
|
last = ScanOneByte( src, delim[0] );
|
|||
|
}else{
|
|||
|
last = strstr( src , delim ); /* έ<><CEAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
}
|
|||
|
if( last == NULL ){
|
|||
|
/*
|
|||
|
* <EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD> return<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
strcpysafe( buf , buflen, src );
|
|||
|
|
|||
|
if( i == index - 1 )
|
|||
|
/*<2A>нﵤ<D0BD><EFB5A4><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
return TRUE;
|
|||
|
|
|||
|
/*<2A>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><D8A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>ټ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ <EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
length = last - src;
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD>ݼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> delim <EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
addlen= length + strlen( delim );
|
|||
|
}
|
|||
|
strncpysafe( buf, buflen , src,length );
|
|||
|
|
|||
|
return TRUE;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*------------------------------------------------------------
|
|||
|
* ٯ "a,b,c,d" ë¦<EFBFBD>ѱ<EFBFBD>ҽ <EFBFBD><EFBFBD><EFBFBD>£۷<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ئԻ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѣ<EFBFBD><EFBFBD>ػ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src char* <EFBFBD>缰 ٯ
|
|||
|
* int1 int* int<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(aëҽ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* int2 int* int<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(bëҽ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* int3 int* int<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(cëҽ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* int4 int* int<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(dëҽ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* ئ<EFBFBD><EFBFBD>
|
|||
|
------------------------------------------------------------*/
|
|||
|
void getFourIntsFromString(char* src,int* int1,int* int2,int* int3,
|
|||
|
int* int4)
|
|||
|
{
|
|||
|
int ret;
|
|||
|
char string[128];
|
|||
|
|
|||
|
ret = getStringFromIndexWithDelim( src,"," ,1,string,sizeof(string));
|
|||
|
if( ret == FALSE )*int1=0;
|
|||
|
else *int1 = atoi(string);
|
|||
|
|
|||
|
ret = getStringFromIndexWithDelim( src, ",",2,string,sizeof(string) );
|
|||
|
if( ret == FALSE )*int2=0;
|
|||
|
else *int2 = atoi(string);
|
|||
|
|
|||
|
ret = getStringFromIndexWithDelim( src, ",",3,string,sizeof(string) );
|
|||
|
if( ret == FALSE )*int3=0;
|
|||
|
else *int3 = atoi(string);
|
|||
|
|
|||
|
ret = getStringFromIndexWithDelim( src, ",",4,string,sizeof(string) );
|
|||
|
if( ret == FALSE )*int4=0;
|
|||
|
else *int4 = atoi(string);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------------
|
|||
|
* src <EFBFBD><EFBFBD> ƥdelsƥ϶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* 1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>继<EFBFBD>£<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ب<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>£<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>بë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ƥ<EFBFBD><EFBFBD>ئ<EFBFBD>У<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* dels <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ( ٯ ƥ϶<EFBFBD>õ<EFBFBD>)
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* ئ<EFBFBD><EFBFBD>
|
|||
|
---------------------------------------------*/
|
|||
|
void deleteSequentChar( char* src , char* dels )
|
|||
|
{
|
|||
|
int length; /* src <20><>Ӯ<EFBFBD><D3AE> */
|
|||
|
int delength; /* dels <20><>Ӯ<EFBFBD><D3AE> */
|
|||
|
int i,j; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> */
|
|||
|
int index=0; /* <20><><EFBFBD><EFBFBD> ٯ <20><> index */
|
|||
|
char backchar='\0'; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ */
|
|||
|
|
|||
|
length = strlen( src );
|
|||
|
delength = strlen( dels );
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
for( i = 0 ; i < length ; i ++ ){
|
|||
|
if( src[i] == BACKSLASH ){
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ب<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>( BACKSLASH<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݼ<EFBFBD> ٯ )
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
src[index++]=src[i++];
|
|||
|
if( i >= length ){
|
|||
|
print( "*\n");
|
|||
|
break;
|
|||
|
}
|
|||
|
src[index++]=src[i];
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
backchar = '\0';
|
|||
|
continue;
|
|||
|
}
|
|||
|
if( src[i] == backchar )
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD>У۹<EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>ئ<EFBFBD>£<EFBFBD>
|
|||
|
*/
|
|||
|
continue;
|
|||
|
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ backchar <EFBFBD><EFBFBD> NULL ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
backchar = '\0';
|
|||
|
for( j = 0 ; j < delength ; j ++ ){
|
|||
|
if( src[i] == dels[j] ){
|
|||
|
/*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ <EFBFBD>֣<EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ continue <EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD>DZ巽Ի
|
|||
|
* <EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƥ<EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>
|
|||
|
*/
|
|||
|
backchar=src[i];
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
src[index++]=src[i];
|
|||
|
}
|
|||
|
src[index++]='\0';
|
|||
|
}
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* hash<EFBFBD><EFBFBD>ë߯<EFBFBD>ʣ<EFBFBD> ٯ <EFBFBD>弰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>ƥʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ة<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ة<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* s ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* int ˦<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ب<EFBFBD><EFBFBD>
|
|||
|
*----------------------------------------*/
|
|||
|
#define PRIME 211
|
|||
|
int hashpjw ( char* s )
|
|||
|
{
|
|||
|
char *p;
|
|||
|
unsigned int h= 0 ,g;
|
|||
|
for( p = s ; *p ; p ++ ){
|
|||
|
h = ( h<< 4 ) + (*p);
|
|||
|
if( (g = h & 0xf0000000) != 0){
|
|||
|
h = h ^ (g>>24);
|
|||
|
h = h ^ g;
|
|||
|
}
|
|||
|
}
|
|||
|
return h % PRIME;
|
|||
|
}
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë߯<EFBFBD><EFBFBD>( TCP )
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* port <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><EFBFBD>̡<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* -1 <EFBFBD>¡<EFBFBD>
|
|||
|
* 1. socket<EFBFBD>˵<EFBFBD> ة<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>P<EFBFBD>¡<EFBFBD>
|
|||
|
* 2. bind<EFBFBD>˵<EFBFBD> ة<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>P<EFBFBD>¡<EFBFBD>
|
|||
|
* 3. listen<EFBFBD>˵<EFBFBD> ة<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>P<EFBFBD>¡<EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
int bindlocalhost( int port )
|
|||
|
{
|
|||
|
struct sockaddr_in sin; /*<2A><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
int sfd; /*ĩ<><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ū<EFBFBD><C5AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
int rc; /*<2A><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
|
|||
|
/*AF_INET<45><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> SOCK_STREAM */
|
|||
|
sfd = socket( AF_INET, SOCK_STREAM, 0 );
|
|||
|
if( sfd == -1 ){
|
|||
|
print( "%s\n" , strerror(errno ) );
|
|||
|
return -1;
|
|||
|
}
|
|||
|
if( getReuseaddr() ) {
|
|||
|
int sendbuff;
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|||
|
setsockopt( sfd, SOL_SOCKET, SO_REUSEADDR,
|
|||
|
(char *)&sendbuff, sizeof( sendbuff));
|
|||
|
}
|
|||
|
|
|||
|
/*0<><30><EFBFBD><EFBFBD>ʧ<EFBFBD>ƻ<EFBFBD><C6BB><EFBFBD>ëҽ */
|
|||
|
memset( &sin ,0, sizeof( struct sockaddr_in ) );
|
|||
|
sin.sin_family=AF_INET;
|
|||
|
sin.sin_port = htons( port );
|
|||
|
sin.sin_addr.s_addr = INADDR_ANY;
|
|||
|
|
|||
|
rc = bind( sfd , (struct sockaddr*)&sin, sizeof(struct sockaddr_in));
|
|||
|
if( rc == -1 ){
|
|||
|
print( "%s\n" , strerror(errno ) );
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
rc = listen( sfd , 5 );
|
|||
|
if( rc == -1 ){
|
|||
|
print( "%s\n" , strerror(errno ) );
|
|||
|
return -1;
|
|||
|
}
|
|||
|
return sfd;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>( TCP )
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* hostname <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* (xx.xxx.xxx.xxxƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>xxx.co.jp<EFBFBD>羮ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
* port <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̡<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ū<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>( -1 <EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD>¡<EFBFBD> )
|
|||
|
----------------------------------------*/
|
|||
|
int connectHost( char* hostname , unsigned short port )
|
|||
|
{
|
|||
|
struct sockaddr_in sock; /*connect<63><74><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
struct hostent* hoste; /*hostname<6D><65>hostent*/
|
|||
|
int fd; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĩ<EFBFBD><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ū<EFBFBD><C5AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
int lr; /*<2A><><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
|
|||
|
memset( &sock , 0 , sizeof( struct sockaddr_in ) );
|
|||
|
sock.sin_family = AF_INET;
|
|||
|
sock.sin_port = htons( port );
|
|||
|
|
|||
|
/* dot notation <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ëƩ<C3AB><C6A9><EFBFBD><EFBFBD> */
|
|||
|
sock.sin_addr.s_addr = inet_addr( hostname );
|
|||
|
if( sock.sin_addr.s_addr == -1 ){
|
|||
|
/*
|
|||
|
*<EFBFBD>¡<EFBFBD> dot notation ƥ<EFBFBD><EFBFBD>ئ<EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD> ɧ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ݩ裻<EFBFBD> ۢ<EFBFBD>֣<EFBFBD>
|
|||
|
* dnsë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ֳ<EFBFBD><EFBFBD><EFBFBD>ƥ֧<EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD>£<EFBFBD>
|
|||
|
*/
|
|||
|
hoste = gethostbyname( hostname );
|
|||
|
if( hoste == NULL ){
|
|||
|
print( "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>DNS<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD>\n" );
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
memcpy((void*)&sock.sin_addr.s_addr ,
|
|||
|
hoste->h_addr , sizeof(struct in_addr) );
|
|||
|
}
|
|||
|
|
|||
|
/*ĩ<><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><C3AB><EFBFBD><EFBFBD>*/
|
|||
|
fd = socket( AF_INET, SOCK_STREAM , 0 );
|
|||
|
if( fd == -1 ){
|
|||
|
print("Cannot Create Socket(%s errno:%d)\n"
|
|||
|
,strerror( errno ) ,errno );
|
|||
|
return -1;
|
|||
|
}
|
|||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
lr = connect(fd,(struct sockaddr*)&sock,sizeof(struct sockaddr_in));
|
|||
|
if( lr != 0 ){
|
|||
|
print("Cannot connect. (%s errno:%d)\n"
|
|||
|
,strerror( errno ) ,errno );
|
|||
|
return -1;
|
|||
|
}
|
|||
|
return fd;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뼰 <EFBFBD><EFBFBD>ݱ<EFBFBD>淤į<EFBFBD><EFBFBD>ؤ<EFBFBD>¾<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ة<EFBFBD><EFBFBD> <EFBFBD>ʣ<EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* char* Ʃ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD>ٱ<EFBFBD>έ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD>淤į<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ʧ<EFBFBD>ͱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>Ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* existsNewLinwCharacter( "aho\nhoge\n" )
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߯Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3 <EFBFBD><EFBFBD>ئ<EFBFBD>£۳<EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>
|
|||
|
* -1 ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
----------------------------------------*/
|
|||
|
int existsNewLineCharacter( char* line )
|
|||
|
{
|
|||
|
#if 1
|
|||
|
char* old = line;
|
|||
|
do{
|
|||
|
if( *line == NEWLINE)return line-old;
|
|||
|
}while( *(line++) );
|
|||
|
#else
|
|||
|
int i; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>*/
|
|||
|
int length = strlen( line ); /*Ʃ<><C6A9><EFBFBD><EFBFBD> ٯ <20><>Ӯ<EFBFBD><D3AE>*/
|
|||
|
for( i = 0 ; i < length ; i ++ ){
|
|||
|
if( line[i] == NEWLINE )
|
|||
|
return i;
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
return -1;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/*----------------------------------------
|
|||
|
* ٯ <EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ë裻<EFBFBD>ľ<EFBFBD>£<EFBFBD>
|
|||
|
* nindex( string , c , 1 ) <EFBFBD><EFBFBD> index( string , c ) <EFBFBD><EFBFBD> equivalent ƥؤ<EFBFBD>£<EFBFBD>
|
|||
|
* number<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD>߯Ի<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>string<EFBFBD><EFBFBD> Ԫƥؤ<EFBFBD>£<EFBFBD>
|
|||
|
*
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* string char* Ʃ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* c int Ʃ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ
|
|||
|
* number int <EFBFBD><EFBFBD><EFBFBD><EFBFBD> į
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* NULL <EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ף<EFBFBD>
|
|||
|
----------------------------------------*/
|
|||
|
char* nindex( char* string, int c , int number )
|
|||
|
{
|
|||
|
int i; /*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>*/
|
|||
|
int num=0;
|
|||
|
int length = strlen( string ); /*Ʃ<><C6A9><EFBFBD><EFBFBD> ٯ <20><>Ӯ<EFBFBD><D3AE>*/
|
|||
|
if( number <= 0 )return string;
|
|||
|
for( i = 0 ; i < length ; i ++ ){
|
|||
|
if( string[i] == c )num++;
|
|||
|
if( number == num ) return &string[i];
|
|||
|
}
|
|||
|
return NULL;
|
|||
|
}
|
|||
|
|
|||
|
BOOL rrd( char* dirname , STRING64* buf ,int bufsize, int* index)
|
|||
|
{
|
|||
|
DIR* d;
|
|||
|
char dirn[1024];
|
|||
|
|
|||
|
d = opendir( dirname );
|
|||
|
if( d == NULL )return FALSE;
|
|||
|
|
|||
|
while( 1 ){
|
|||
|
struct dirent* dent;
|
|||
|
struct stat st;
|
|||
|
dent = readdir( d );
|
|||
|
if( dent == NULL ){
|
|||
|
if( errno == EBADF ){
|
|||
|
errorprint;
|
|||
|
closedir(d);
|
|||
|
return FALSE;
|
|||
|
}else
|
|||
|
/* successful */
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
/* . ƥ<><C6A5><EFBFBD><EFBFBD><EFBFBD>°<EFBFBD><C2B0><EFBFBD><EFBFBD>̻ﷴ <20><>ئ<EFBFBD><D8A6> */
|
|||
|
if( dent->d_name[0] == '.' )continue;
|
|||
|
|
|||
|
snprintf(dirn, sizeof(dirn), "%s/%s" , dirname,dent->d_name );
|
|||
|
if( stat( dirn , &st ) == -1 )continue;
|
|||
|
if( S_ISDIR( st.st_mode ) ){
|
|||
|
if( rrd( dirn , buf ,bufsize, index) == FALSE ){
|
|||
|
closedir(d);
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
}else{
|
|||
|
if( *index >= bufsize )
|
|||
|
break;
|
|||
|
|
|||
|
strcpysafe( buf[*index].string , sizeof( buf[*index].string ), dirn );
|
|||
|
(*index)++;
|
|||
|
}
|
|||
|
}
|
|||
|
closedir(d);
|
|||
|
return TRUE;
|
|||
|
}
|
|||
|
|
|||
|
int rgetFileName( char* dirname , STRING64* string, int size)
|
|||
|
{
|
|||
|
int index=0;
|
|||
|
if( rrd( dirname , string ,size ,&index ) == FALSE )return -1;
|
|||
|
else return index;
|
|||
|
}
|
|||
|
|
|||
|
BOOL checkStringsUnique( char** strings, int num ,int verbose)
|
|||
|
{
|
|||
|
int i,j;
|
|||
|
for( i = 0 ; i < num - 1; i ++ ){
|
|||
|
for( j = i+1 ; j < num ; j ++){
|
|||
|
if( !strcmp( strings[i] ,strings[j] )){
|
|||
|
if( verbose )
|
|||
|
print( "Overlapp string is %s\n", strings[i] );
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return TRUE;
|
|||
|
}
|
|||
|
|
|||
|
BOOL PointInRect( RECT* rect, POINT* p )
|
|||
|
{
|
|||
|
if( rect->x <= p->x && p->x <= rect->x + rect->width &&
|
|||
|
rect->y <= p->y && p->y <= rect->y + rect->height )
|
|||
|
return TRUE;
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
BOOL CoordinateInRect( RECT* rect, int x, int y)
|
|||
|
{
|
|||
|
POINT p={x,y};
|
|||
|
return PointInRect(rect,&p);
|
|||
|
}
|
|||
|
|
|||
|
int clipRect( RECT *rect1, RECT *rect2, RECT *ret )
|
|||
|
{
|
|||
|
if( rect1->x > rect2->x + rect2->width -1
|
|||
|
|| rect2->x > rect1->x + rect1->width -1
|
|||
|
|| rect1->y > rect2->y + rect2->height -1
|
|||
|
|| rect2->y > rect1->y + rect1->height -1 )
|
|||
|
return 0;
|
|||
|
ret->x = max( rect1->x, rect2->x );
|
|||
|
ret->y = max( rect1->y, rect2->y );
|
|||
|
ret->width = min( rect1->x+rect1->width, rect2->x+rect2->width ) - ret->x;
|
|||
|
ret->height = min( rect1->y+rect1->height, rect2->y+rect2->height ) - ret->y;
|
|||
|
return 1;
|
|||
|
}
|
|||
|
|
|||
|
BOOL isstring1or0( char* string )
|
|||
|
{
|
|||
|
if( strcasecmp(string,"TRUE" ) == 0 )return TRUE;
|
|||
|
if( strcasecmp(string,"FALSE") == 0 )return FALSE;
|
|||
|
if( strcasecmp(string,"1" ) == 0 )return TRUE;
|
|||
|
if( strcasecmp(string,"0" ) == 0 )return FALSE;
|
|||
|
if( strcasecmp(string,"ON" ) == 0 )return TRUE;
|
|||
|
if( strcasecmp(string,"OFF" ) == 0 )return FALSE;
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
|
|||
|
void easyGetTokenFromString( char *src,int count,char*output,int len )
|
|||
|
{
|
|||
|
int i;
|
|||
|
int counter = 0;
|
|||
|
|
|||
|
if( len <= 0 )return;
|
|||
|
|
|||
|
|
|||
|
#define ISSPACETAB( c ) ( (c) == ' ' || (c) == '\t' )
|
|||
|
|
|||
|
for(i=0;;i++){
|
|||
|
if( src[i]=='\0'){
|
|||
|
output[0] = '\0';
|
|||
|
return;
|
|||
|
}
|
|||
|
if( i > 0 && ! ISSPACETAB( src[i-1] ) &&
|
|||
|
! ISSPACETAB( src[i] ) ){
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
if( ! ISSPACETAB( src[i]) ){
|
|||
|
counter++;
|
|||
|
if( counter == count){
|
|||
|
/* copy it */
|
|||
|
int j;
|
|||
|
for(j=0;j<len-1;j++){
|
|||
|
if( src[i+j] == '\0' ||
|
|||
|
ISSPACETAB( src[i+j] ) ){
|
|||
|
break;
|
|||
|
}
|
|||
|
output[j]=src[i+j];
|
|||
|
}
|
|||
|
output[j]='\0';
|
|||
|
return;
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*------------------------------------------------------------
|
|||
|
* ˲<EFBFBD><EFBFBD>ƥ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD>继<EFBFBD>£<EFBFBD> by ringo
|
|||
|
* Ǿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* double val1 , val2 : <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؤ<EFBFBD>з<EFBFBD>ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* double d : <EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
*
|
|||
|
* -d<0----- val1 ---0<d<1------- val2 ------d>1----
|
|||
|
*
|
|||
|
*
|
|||
|
------------------------------------------------------------*/
|
|||
|
float linearDiv( float val1 , float val2 , float d )
|
|||
|
{
|
|||
|
return val1 + ( val2 - val1 ) * ( d );
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*------------------------------------------------------------
|
|||
|
* ٯ <EFBFBD><EFBFBD>ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>ئ ٯëlen ٯ<EFBFBD><EFBFBD>Ի<EFBFBD><EFBFBD><EFBFBD>ƻ<EFBFBD><EFBFBD>¼<EFBFBD>ĸةئ
|
|||
|
* ٯ ë<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>NPC<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>ĸة<EFBFBD>ɵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϸ<EFBFBD><EFBFBD><EFBFBD>年<EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* char *cand : <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ռ<EFBFBD><EFBFBD>٣<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ٯ<EFBFBD><EFBFBD>
|
|||
|
* char *out : <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* int len : <EFBFBD><EFBFBD> <EFBFBD><EFBFBD>Ӯ<EFBFBD><EFBFBD>
|
|||
|
------------------------------------------------------------*/
|
|||
|
void makeRandomString( char *cand , char *out , int len )
|
|||
|
{
|
|||
|
int i;
|
|||
|
int l = strlen( cand );
|
|||
|
|
|||
|
for(i=0;i<len;i++){
|
|||
|
out[i] = cand[ rand() % l];
|
|||
|
}
|
|||
|
out[i] = '\0';
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*------------------------------------------------------------
|
|||
|
* ¦<EFBFBD>ѱ<EFBFBD>϶<EFBFBD>ý<EFBFBD>ľ<EFBFBD>װ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>̻ﻥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̻ᆴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ëƩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* filename char* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD>
|
|||
|
* ߯Ի<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD> TRUE(1)
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD>ƥئ<EFBFBD><EFBFBD> FALSE(0)
|
|||
|
------------------------------------------------------------*/
|
|||
|
BOOL isExistFile( char* filename )
|
|||
|
{
|
|||
|
/* fopen ƥƩ<C6A5><C6A9><EFBFBD><EFBFBD> */
|
|||
|
FILE* fp;
|
|||
|
fp = fopen( filename, "w" );
|
|||
|
if( fp ){
|
|||
|
fclose( fp );
|
|||
|
return TRUE;
|
|||
|
}else
|
|||
|
return FALSE;
|
|||
|
}
|
|||
|
/*------------------------------------------------------------
|
|||
|
* 10<EFBFBD><EFBFBD> 62<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* a int <EFBFBD>缰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* out char * ɡ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* outlen int ɡ <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뼰 <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* Ի<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD> out<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD> NULL
|
|||
|
------------------------------------------------------------*/
|
|||
|
char *cnv10to62( int a, char *out, int outlen )
|
|||
|
{
|
|||
|
#if 1
|
|||
|
int i, j;
|
|||
|
char base[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
|
|||
|
int tmp[64];
|
|||
|
int src;
|
|||
|
int minus;
|
|||
|
int baselen = sizeof( base)-1;
|
|||
|
if( a < 0 ){
|
|||
|
minus = 1;
|
|||
|
a *= -1;
|
|||
|
} else {
|
|||
|
minus = 0;
|
|||
|
}
|
|||
|
/* special case */
|
|||
|
if( a < baselen) {
|
|||
|
if( minus ){
|
|||
|
*(out) = '-';
|
|||
|
*(out+1) = base[a];
|
|||
|
*(out+2) = '\0';
|
|||
|
return (out);
|
|||
|
} else {
|
|||
|
*out = base[a];
|
|||
|
*(out+1) = '\0';
|
|||
|
return( out);
|
|||
|
}
|
|||
|
}
|
|||
|
src = a;
|
|||
|
for( i = 0; src >= baselen; i ++ ) {
|
|||
|
tmp[i] = src % baselen;
|
|||
|
src /= baselen;
|
|||
|
}
|
|||
|
i--;
|
|||
|
if( minus ){
|
|||
|
*out = '-';
|
|||
|
*(out+1) = base[src];
|
|||
|
for( j = 2; i >= 0; i --, j ++ ) {
|
|||
|
if( j > outlen - 2 ) return NULL;
|
|||
|
*(out+j) = base[tmp[i]];
|
|||
|
}
|
|||
|
} else {
|
|||
|
*out = base[src];
|
|||
|
for( j = 1; i >= 0; i --, j ++ ) {
|
|||
|
if( j > outlen - 2 ) return NULL;
|
|||
|
*(out+j) = base[tmp[i]];
|
|||
|
}
|
|||
|
}
|
|||
|
*(out+j) = '\0';
|
|||
|
return( out);
|
|||
|
#else
|
|||
|
/* <20><><EFBFBD><EFBFBD> */
|
|||
|
#define CNV_NUMBER 62
|
|||
|
int i, j;
|
|||
|
char base[] = { "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
|
|||
|
int tmp[64];
|
|||
|
int src;
|
|||
|
if( a < 0 ) return( NULL);
|
|||
|
if( a < CNV_NUMBER) {
|
|||
|
*out = base[a];
|
|||
|
*(out+1) = '\0';
|
|||
|
return( out);
|
|||
|
}
|
|||
|
src = a;
|
|||
|
for( i = 0; src >= CNV_NUMBER; i ++ ) {
|
|||
|
tmp[i] = src % CNV_NUMBER;
|
|||
|
src /= CNV_NUMBER;
|
|||
|
}
|
|||
|
i--;
|
|||
|
*out = base[src];
|
|||
|
for( j = 1; i >= 0; i --, j ++ ) {
|
|||
|
if( j > outlen - 2 ) return NULL;
|
|||
|
*(out+j) = base[tmp[i]];
|
|||
|
}
|
|||
|
*(out+j) = '\0';
|
|||
|
return( out);
|
|||
|
#undef CNV_NUMBER
|
|||
|
#endif
|
|||
|
}
|
|||
|
/*
|
|||
|
* ܸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ƥ<EFBFBD><EFBFBD><EFBFBD>Ѱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD>ƻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¾<EFBFBD>Ʃ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* -1 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>е<EFBFBD> ئ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* ¦<EFBFBD><EFBFBD>
|
|||
|
* src *int Ʃ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>缰
|
|||
|
* srclen int src <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* Ի<EFBFBD><EFBFBD> <EFBFBD><EFBFBD> ؤԻ TRUE
|
|||
|
* ئ<EFBFBD><EFBFBD> FALSE
|
|||
|
*/
|
|||
|
BOOL checkRedundancy( int *src, int srclen)
|
|||
|
{
|
|||
|
int i,j;
|
|||
|
int ret = FALSE;
|
|||
|
|
|||
|
for( i = 0; i < srclen; i ++ ) {
|
|||
|
if( *(src + i) != -1 ) {
|
|||
|
for( j = i+1; j < srclen; j ++ ) {
|
|||
|
if( *(src +i) == *( src+j) ) {
|
|||
|
ret = TRUE;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return ret;
|
|||
|
}
|
|||
|
void
|
|||
|
shuffle_ints( int num, int *a, int t )
|
|||
|
{
|
|||
|
int i;
|
|||
|
for(i=0;i<t; i++ )
|
|||
|
{
|
|||
|
int x = random() % num;
|
|||
|
int y = random() % num;
|
|||
|
int s;
|
|||
|
s = a[x];
|
|||
|
a[x] = a[y];
|
|||
|
a[y] = s;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
static unsigned char BitTable[] = /* <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><CCAB>ë<EFBFBD>ѱ<EFBFBD><D1B1><EFBFBD><EFBFBD><EFBFBD> <20><>Ƥ<EFBFBD><C6A4> */
|
|||
|
{
|
|||
|
0x00 , 0x80 , 0x40 , 0xC0 , 0x20 , 0xA0 , 0x60 , 0xE0 ,
|
|||
|
0x10 , 0x90 , 0x50 , 0xD0 , 0x30 , 0xB0 , 0x70 , 0xF0 ,
|
|||
|
0x08 , 0x88 , 0x48 , 0xC8 , 0x28 , 0xA8 , 0x68 , 0xE8 ,
|
|||
|
0x18 , 0x98 , 0x58 , 0xD8 , 0x38 , 0xB8 , 0x78 , 0xF8 ,
|
|||
|
0x04 , 0x84 , 0x44 , 0xC4 , 0x24 , 0xA4 , 0x64 , 0xE4 ,
|
|||
|
0x14 , 0x94 , 0x54 , 0xD4 , 0x34 , 0xB4 , 0x74 , 0xF4 ,
|
|||
|
0x0C , 0x8C , 0x4C , 0xCC , 0x2C , 0xAC , 0x6C , 0xEC ,
|
|||
|
0x1C , 0x9C , 0x5C , 0xDC , 0x3C , 0xBC , 0x7C , 0xFC ,
|
|||
|
0x02 , 0x82 , 0x42 , 0xC2 , 0x22 , 0xA2 , 0x62 , 0xE2 ,
|
|||
|
0x12 , 0x92 , 0x52 , 0xD2 , 0x32 , 0xB2 , 0x72 , 0xF2 ,
|
|||
|
0x0A , 0x8A , 0x4A , 0xCA , 0x2A , 0xAA , 0x6A , 0xEA ,
|
|||
|
0x1A , 0x9A , 0x5A , 0xDA , 0x3A , 0xBA , 0x7A , 0xFA ,
|
|||
|
0x06 , 0x86 , 0x46 , 0xC6 , 0x26 , 0xA6 , 0x66 , 0xE6 ,
|
|||
|
0x16 , 0x96 , 0x56 , 0xD6 , 0x36 , 0xB6 , 0x76 , 0xF6 ,
|
|||
|
0x0E , 0x8E , 0x4E , 0xCE , 0x2E , 0xAE , 0x6E , 0xEE ,
|
|||
|
0x1E , 0x9E , 0x5E , 0xDE , 0x3E , 0xBE , 0x7E , 0xFE ,
|
|||
|
0x01 , 0x81 , 0x41 , 0xC1 , 0x21 , 0xA1 , 0x61 , 0xE1 ,
|
|||
|
0x11 , 0x91 , 0x51 , 0xD1 , 0x31 , 0xB1 , 0x71 , 0xF1 ,
|
|||
|
0x09 , 0x89 , 0x49 , 0xC9 , 0x29 , 0xA9 , 0x69 , 0xE9 ,
|
|||
|
0x19 , 0x99 , 0x59 , 0xD9 , 0x39 , 0xB9 , 0x79 , 0xF9 ,
|
|||
|
0x05 , 0x85 , 0x45 , 0xC5 , 0x25 , 0xA5 , 0x65 , 0xE5 ,
|
|||
|
0x15 , 0x95 , 0x55 , 0xD5 , 0x35 , 0xB5 , 0x75 , 0xF5 ,
|
|||
|
0x0D , 0x8D , 0x4D , 0xCD , 0x2D , 0xAD , 0x6D , 0xED ,
|
|||
|
0x1D , 0x9D , 0x5D , 0xDD , 0x3D , 0xBD , 0x7D , 0xFD ,
|
|||
|
0x03 , 0x83 , 0x43 , 0xC3 , 0x23 , 0xA3 , 0x63 , 0xE3 ,
|
|||
|
0x13 , 0x93 , 0x53 , 0xD3 , 0x33 , 0xB3 , 0x73 , 0xF3 ,
|
|||
|
0x0B , 0x8B , 0x4B , 0xCB , 0x2B , 0xAB , 0x6B , 0xEB ,
|
|||
|
0x1B , 0x9B , 0x5B , 0xDB , 0x3B , 0xBB , 0x7B , 0xFB ,
|
|||
|
0x07 , 0x87 , 0x47 , 0xC7 , 0x27 , 0xA7 , 0x67 , 0xE7 ,
|
|||
|
0x17 , 0x97 , 0x57 , 0xD7 , 0x37 , 0xB7 , 0x77 , 0xF7 ,
|
|||
|
0x0F , 0x8F , 0x4F , 0xCF , 0x2F , 0xAF , 0x6F , 0xEF ,
|
|||
|
0x1F , 0x9F , 0x5F , 0xDF , 0x3F , 0xBF , 0x7F , 0xFF
|
|||
|
};
|
|||
|
static unsigned short crctab16[] = /* crc<72>x<EFBFBD><78><EFBFBD><EFBFBD>ң<EFBFBD><D2A3><EFBFBD><EFBFBD>Ƥ<EFBFBD><C6A4> */
|
|||
|
{
|
|||
|
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
|
|||
|
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
|
|||
|
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
|
|||
|
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
|
|||
|
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
|
|||
|
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
|
|||
|
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
|
|||
|
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
|
|||
|
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
|
|||
|
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
|
|||
|
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
|
|||
|
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
|
|||
|
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
|
|||
|
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
|
|||
|
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
|
|||
|
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
|
|||
|
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
|
|||
|
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
|
|||
|
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
|
|||
|
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
|
|||
|
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
|
|||
|
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
|||
|
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
|
|||
|
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
|
|||
|
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
|
|||
|
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
|
|||
|
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
|
|||
|
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
|
|||
|
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
|
|||
|
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
|
|||
|
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
|
|||
|
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0,
|
|||
|
};
|
|||
|
unsigned short CheckCRC( unsigned char *p , int size )
|
|||
|
{
|
|||
|
unsigned short crc = 0;
|
|||
|
int i;
|
|||
|
|
|||
|
for( i = 0 ; i < size ; i ++ ){
|
|||
|
crc = ( crctab16[ ( crc >> 8 ) & 0xFF ]
|
|||
|
^ ( crc << 8 ) ^ BitTable[ p[ i ] ] );
|
|||
|
}
|
|||
|
return crc;
|
|||
|
}
|
|||
|
|
|||
|
// Add Code By Shan 2001.06.16
|
|||
|
INLINE double time_diff(struct timeval subtrahend,
|
|||
|
struct timeval subtractor)
|
|||
|
{
|
|||
|
return( (subtrahend.tv_sec - subtractor.tv_sec)
|
|||
|
+ (subtrahend.tv_usec
|
|||
|
- subtractor.tv_usec ) / (double)1E6 );
|
|||
|
}
|
|||
|
|
|||
|
char *strcpy_s(char *des, size_t n, const char *src)
|
|||
|
{
|
|||
|
assert(des != NULL && src != NULL);
|
|||
|
|
|||
|
if(des == NULL || src == NULL || n == 0)
|
|||
|
{
|
|||
|
return NULL;
|
|||
|
}
|
|||
|
|
|||
|
char *TM_RetChar = des;
|
|||
|
int i = 0;
|
|||
|
|
|||
|
while( (*des++ = *src++) )
|
|||
|
{
|
|||
|
i++;
|
|||
|
if( i >= n )
|
|||
|
{
|
|||
|
i--;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
TM_RetChar[i] = '\0';
|
|||
|
return TM_RetChar;
|
|||
|
}
|
|||
|
|
|||
|
char *replace(char *source,char *sub,char *rep)
|
|||
|
{
|
|||
|
char *result;
|
|||
|
/*pc1 <20>Ǹ<EFBFBD><C7B8>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD>result<6C><74>ɨ<EFBFBD><C9A8>ָ<EFBFBD><D6B8>*/
|
|||
|
/*pc2 <20><>ɨ<EFBFBD><C9A8> source <20>ĸ<EFBFBD><C4B8><EFBFBD>ָ<EFBFBD><D6B8>*/
|
|||
|
/*pc3 Ѱ<><D1B0><EFBFBD>Ӵ<EFBFBD>ʱ,Ϊ<><CEAA><EFBFBD><EFBFBD><EFBFBD>仯<EFBFBD>е<EFBFBD>source<63>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ӵ<EFBFBD><D3B4><EFBFBD><EFBFBD><EFBFBD>,<2C><>ָ<EFBFBD><D6B8>sub<75><62>ɨ<EFBFBD><C9A8>ָ<EFBFBD><D6B8> */
|
|||
|
/*<2A>ҵ<EFBFBD>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD>,Ϊ<>˸<EFBFBD><CBB8>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ָ<EFBFBD><D6B8>rep<65><70>ɨ<EFBFBD><C9A8>ָ<EFBFBD><D6B8>*/
|
|||
|
char *pc1, *pc2, *pc3;
|
|||
|
int isource, isub, irep;
|
|||
|
isub =strlen(sub); /*<2A>Ա<EFBFBD><D4B1>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>*/
|
|||
|
irep =strlen(rep); /*<2A>滻<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>*/
|
|||
|
isource=strlen(source);/*Դ<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>*/
|
|||
|
if(NULL == *sub)
|
|||
|
return strdup(source);
|
|||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>Ŀռ<C4BF>*/
|
|||
|
result = (char *)malloc(( (irep > isub) ? (float)strlen(source) / isub* irep+ 1:isource ) * sizeof(char));
|
|||
|
pc1 = result; /*Ϊpc1<63><31><EFBFBD>θ<EFBFBD><CEB8>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><D7BC>*/
|
|||
|
while(*source != NULL)
|
|||
|
{
|
|||
|
/*Ϊ<><CEAA><EFBFBD><EFBFBD>source<63><65>sub<75>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><D7BC>,Ϊpc2,pc3 <20><><EFBFBD><EFBFBD>ֵ*/
|
|||
|
pc2 = source;
|
|||
|
pc3 = sub;
|
|||
|
/* <20><>ѭ<EFBFBD><D1AD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD>
|
|||
|
* *pc2<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> *pc3<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>
|
|||
|
* pc2 <EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>β
|
|||
|
* pc3 <EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>β<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD>Ӵ<EFBFBD>,source<EFBFBD><EFBFBD><EFBFBD><EFBFBD>sub<EFBFBD><EFBFBD><EFBFBD>ȣ<EFBFBD>
|
|||
|
*****************************************************/
|
|||
|
while(*pc2 == *pc3 && *pc3 != NULL && *pc2 != NULL)
|
|||
|
pc2++, pc3++;
|
|||
|
/* <20><><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD>Ӵ<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
if(NULL == *pc3)
|
|||
|
{
|
|||
|
pc3 = rep;
|
|||
|
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
while(*pc3 != NULL)
|
|||
|
*pc1++ = *pc3++;
|
|||
|
pc2--;
|
|||
|
source = pc2;
|
|||
|
/* <20><><EFBFBD><EFBFBD> source<63><65>sub<75><62><EFBFBD>ȵ<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* pc2 <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> sub <EFBFBD>д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>λ<EFBFBD>á<EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>source ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
}
|
|||
|
else /*<2A><><EFBFBD><EFBFBD>û<EFBFBD>ҵ<EFBFBD><D2B5>Ӵ<EFBFBD>,<2C><><EFBFBD>渴<EFBFBD><E6B8B4>source<63><65>ָ<EFBFBD><D6B8><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
|||
|
*pc1++ = *source;
|
|||
|
source++; /* <20><>source<63><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ַ<EFBFBD>*/
|
|||
|
}
|
|||
|
*pc1 = NULL;
|
|||
|
return result;
|
|||
|
}
|
|||
|
|
|||
|
int getHash ( char* s )
|
|||
|
{
|
|||
|
int i;
|
|||
|
int h=0;
|
|||
|
|
|||
|
for(i=0;; i++){
|
|||
|
if( s[i] == 0 ){
|
|||
|
break;
|
|||
|
}
|
|||
|
h += s[i];
|
|||
|
}
|
|||
|
return h;
|
|||
|
}
|
|||
|
|
|||
|
//int RAND (int x,int y)
|
|||
|
//{
|
|||
|
// srand((int)time(0));
|
|||
|
// return (x-1)+1+(int)( (double)(y-(x-1))*rand()/(RAND_MAX+1.0));
|
|||
|
//}
|