?? util.c
字號:
{ int i; /*伙□皿 醒*/ int num=0; int length = strlen( string ); /*譬屯月 儂 及贏今*/ 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; } /* . 匹銨引月白央奶伙反 引卅中 */ 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; } } }}/*------------------------------------------------------------ * 瞬滇匹 坌鰾毛手午戶月[ by ringo * 薔及啖 迕 * * double val1 , val2 : 仇及襖及丐中分毛午月 * double d : 坌 * * * -d<0----- val1 ---0<d<1------- val2 ------d>1---- * * ------------------------------------------------------------*/float linearDiv( float val1 , float val2 , float d ){ return val1 + ( val2 - val1 ) * ( d );}/*------------------------------------------------------------ * 儂 及卅井井日 啦卅 儂毛len 儂午曰分仄化仿件母丞卅 * 儂 毛勾仁月[NPC及仿件母丞由旦伐□玉戲岳卞勾井勻化月 * * char *cand : 仇仇井日薊少[跳 及 儂[ * char *out : 請 田永白央 * int len : 請 及贏今 ------------------------------------------------------------*/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';}/*------------------------------------------------------------ * 婁醒卞隙爛今木兇白央奶伙互白央奶伙井升丹毛譬屯月 * 婁醒 * filename char* 白央奶伙 * 忒曰襖 * 白央奶伙 TRUE(1) * 白央奶伙匹卅中 FALSE(0) ------------------------------------------------------------*/BOOL isExistFile( char* filename ){ /* fopen 匹譬屯月 */ FILE* fp; fp = fopen( filename, "w" ); if( fp ){ fclose( fp ); return TRUE; }else return FALSE;}/*------------------------------------------------------------ * 10褡 62褡 晶 * 婁醒 * a int 葭及ㄠㄟ褡 * out char * 傘 田永白央□ * outlen int 傘 田永白央及 五今 * 曰襖 * 岳 out及失玉伊旦 * 撩 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/* 衙中 */#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}/* * 芨尹日木兇 及 匹]醒襖互褐 仄化中月井譬屯月楮醒 * -1 反覆擂陸午中丹 卅楮醒 * * 婁醒 * src *int 譬屯月葭及 * srclen int src 及 五今 * * 曰襖 褐 丐曰 TRUE * 卅仄 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;}voidshuffle_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[] = /* 申永玄及岈太賜毛菅卞允月 □皮伙 */{ 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{及煌遙 □皮伙 */{ 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.16INLINE double time_diff(struct timeval subtrahend, struct timeval subtractor){ return( (subtrahend.tv_sec - subtractor.tv_sec) + (subtrahend.tv_usec - subtractor.tv_usec ) / (double)1E6 );}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -