メインページ | アルファベット順一覧 | 構成 | ファイル一覧 | 構成メンバ | ファイルメンバ | 関連ページ

dkcOSIndependent.c

説明を見る。
00001 
00007 #define DKUTIL_C_OS_INDEPENDENT_C
00008 
00009 #include "dkcOSIndependent.h"
00010 #include "dkcDefined.h"
00011 
00012 #include "dkcQueue.h"
00013 
00014 
00015 #include <assert.h>
00016 #include <math.h>
00017 
00018 int WINAPI dkcIsNativePathString(const char *s,size_t size){
00019 
00020     size_t i=0;
00021     if(s==NULL) return edk_FAILED;
00022     for(;i<size;i++){
00023         if(dkcmIS_INVALID_PATH_CHAR(s[i]))
00024         {
00025             return FALSE;
00026         }
00027     }
00028     return TRUE;
00029 }
00030 
00031 
00032 int WINAPI dkcErrorMessage(const char *expression,
00033                                          const char *filename,size_t line,const char *message,...)
00034 {
00035     char s[1024];
00036     char ss[1024 * 2];
00037     
00038     int va_list_result;
00039     va_list Valist;
00040 
00041     NULL_CHAR_ARRAY(s);
00042     NULL_CHAR_ARRAY(ss);
00043     
00044     if(message){
00045         SET_VA_LIST_C(Valist,va_list_result,s,sizeof(s),message);
00046     }else{
00047         //SET_VA_LIST(s,sizeof(s),"No message");
00048         _snprintf(s,sizeof(s),"No message\n");
00049     }
00050 
00051     _snprintf(ss,sizeof(ss),
00052         "DKUTIL_ASSERT(%s):\nfile:%s / \n line:%d / \n message: %s",
00053         expression,filename,line,s);
00054 
00055 
00056 
00057 #ifdef NDEBUG//release
00058 #   ifdef WIN32
00059         ODS(ss);
00060     //::MessageBox(NULL,ss,"ERROR ASSERTION !!",MB_OK);
00061     {
00062         LPCTSTR name="ERROR_TEMP.txt";
00063         {
00064             //ファイルをオープン
00065             FILE *fp;
00066             if(NULL != (fp = fopen( name , "at" ))){
00067             
00068                 // エラーログファイルに書き出す
00069                 fputs( ss , fp ) ;
00070                 fclose( fp ) ;
00071                 Sleep(800);
00072             }
00073         }
00074         ShellExecute(NULL, "open",name, NULL, NULL, SW_SHOWNORMAL);
00075         //Sleep(1000);
00076         //DeleteFile(name);
00077     }
00078     MB("このテキストをこのソフトの開発者に渡せば、バグ発見の近道なります。\n \
00079         開発者に知らせるときはこのテキストを転記してあげましょう。");
00080     if(IDYES==MessageBox(NULL,
00081         "このままこのソフトを起動しつづけると、更なるエラーが発生する可能性があります。\n終了しますか?",
00082         "あってはいけない エラー!!!",
00083         MB_YESNO))
00084     {
00085         exit(edk_FAILED);
00086         //terminate();
00087     }else{
00088     }
00089 #   else    //else of win32
00090     
00091     fprintf(stderr,ss);
00092     exit(edk_FAILED);
00093 
00094 #   endif //end of win32
00095 
00096 #else //debug
00097 
00098 #   ifdef WIN32
00099         ODS(ss);
00100     fprintf(stderr,ss);
00101     //_CrtDebugBreak();
00102     DebugBreak();
00103 #   else //else of win32
00104 
00105     fprintf(stderr,ss);
00106     Debugger();
00107 
00108 #   endif //end of win32
00109 #endif//end of NDEBUG
00110     //assert(ss);
00111     
00112     return TRUE;
00113 }
00114 DKC_INLINE void *dkcAllocateFill(size_t size,BYTE fill){
00115     void *p = dkcAllocateFast(size);
00116     if(NULL==p) return NULL;
00117     memset(p,fill,size);
00118     return p;
00119 }
00120 DKC_INLINE void *dkcAllocateFast(size_t size){
00121     return malloc(size);
00122 }
00123 DKC_INLINE void* dkcAllocate(size_t size){
00124     return dkcAllocateFill(size,0); 
00125 /*void *ptr;
00126     ptr = dkcAllocateFast(size);
00127     if(NULL==ptr) return NULL;
00128     memset(ptr,0,size);
00129     return ptr;
00130     */
00131 }
00132 
00133 DKC_INLINE int  dkcFree(void **p){
00134     if(!*p) return edk_FAILED;
00135     free(*p);
00136     *p = NULL;
00137     return edk_SUCCEEDED;
00138 }
00139 BOOL dkcIs_foepn_mode(const char *s){
00140     /* wrtb+ */
00141     const char *ms= "wrtb+";
00142     size_t slen = strlen(s);
00143     size_t mslen = strlen(ms);
00144     size_t i,j;
00145     int flag = FALSE;
00146     for(i=0;i<slen;i++){
00147         for(j=0;j<mslen;j++){
00148             if(ms[j]==s[i]){
00149                 flag = TRUE;
00150                 break;
00151             }
00152         }
00153         if(TRUE!=flag){
00154             return FALSE;
00155         }else{
00156             flag = FALSE;
00157         }
00158     }
00159     return TRUE;
00160 }
00161 /*
00162 struct dkcDoublePoint{
00163     double x,y;
00164 }DKC_DOUBLE_POINT;
00165 
00166 int calc(DKC_DOUBLE_POINT *pa,size_t nums){
00167     pa->x   
00168 
00169 }*/
00170 /*
00171 double calc(double StartX,double StartY,double EndX,double EndY)
00172 {
00173     return  StartY - ((EndY - StartY) / (EndX - StartX)) * StartX;
00174 }
00175 */
00176 size_t dkcReallocateSizeFunction(size_t OldSize,size_t ExpandSize){
00177     //y=-25.43035 * pow(x,2) + 116.7214
00178     //y = -0.00000018 * pow(x,2) + 0.00019
00179     //y = -99.9999 * pow(OldSize,2) + 104857600;
00180     //y = 0.105263 * x * x + 10.52631
00181     //double x;
00182 //  size_t size;
00183     if(OldSize <= 1024 * 5){//5KB以内なら2倍
00184         return OldSize * 2;
00185     }else if(OldSize >= 1024 * 1024 * 10 || 0==OldSize)
00186     {//10MB以上なら + ExpandSize
00187         return OldSize + ExpandSize;
00188     }
00189     //それ以外ならExpandSize * 3
00190     return OldSize + ExpandSize * 3; 
00191     //return OldSize * 2;//ひでぇ関数だ。
00192 }
00193 
00194 int WINAPI dkcReallocate(void **NewPtr,size_t NewSize,
00195     void **OldPtr)
00196 {
00197     return dkcReallocateEx(realloc,NewPtr,NewSize,OldPtr);
00198 }
00199 
00200 int WINAPI dkcReallocateEx(
00201     DKC_REALLOC_F_TYPE your_realloc,void **NewPtr,size_t NewSize,
00202     void **OldPtr
00203 )
00204 {
00205     void *ptr = NULL;
00206 
00207     if(NULL== your_realloc  /*|| NULL == *OldPtr ||
00208         0==OldSize*/
00209     ){
00210         return edk_ArgumentException;//アホ引数入れるな!!
00211     }
00212 
00213     ptr = your_realloc(*OldPtr,NewSize);
00214     if(NULL==ptr) return edk_FAILED;
00215 
00216     //更新
00217     *OldPtr = NULL;
00218     *NewPtr = ptr;
00219     
00220     return edk_SUCCEEDED;
00221 }
00222 
00223 
00224 
00225 int WINAPI dkcReallocateAutoExpand(
00226     DKC_REALLOC_F_TYPE your_realloc,void **NewPtr,
00227     void **OldPtr,size_t OldSize,size_t *reallocated_size
00228     )
00229 {
00230     void *ptr = NULL;
00231     size_t want_size = OldSize / 8;
00232     size_t ra_size = dkcReallocateSizeFunction(OldSize,
00233          (want_size <= 20) ? 20 : want_size
00234     );
00235     size_t div = 8;
00236     size_t tmp_ra = ra_size / div;
00237     size_t i;
00238     if(NULL== your_realloc /*|| NULL==*NewPtr*/ || NULL == *OldPtr ||
00239         0==OldSize  || NULL==reallocated_size   
00240     ){
00241         return edk_ArgumentException;//アホ引数入れるな!!
00242     }
00243 
00244     for(i=0;i<div;i++){
00245         ptr = your_realloc(*OldPtr,ra_size);
00246         if(NULL==ptr){
00247             if(OldSize > (ra_size -= tmp_ra)){//とりあえずtmp_ra分を引く。
00248                 break;//こら望みなしだわ
00249             }
00250             continue;
00251         }else{
00252             break;
00253         }
00254     }
00255     if(NULL==ptr) return edk_FAILED;
00256 
00257     //更新
00258     *NewPtr = ptr;  
00259     *OldPtr = NULL;
00260 
00261     *reallocated_size = ra_size;
00262 
00263     return edk_SUCCEEDED;
00264 }
00265 
00266 static int WINAPI dkcLoadFile(void *data,size_t size,const char *fname,const char *mode,size_t *readsize){//="rb"
00267     FILE *fp ;
00268     if(NULL==readsize || NULL==data || NULL==fname || NULL==mode){
00269         return edk_FAILED;
00270     }
00271     fp = fopen( fname , mode ) ;//rb
00272     if(fp==NULL)return edk_FAILED;
00273     *readsize = fread( data , 1 , size , fp ) ;
00274     //fread( data , sizeof(size)  , 1 , fp ) ;
00275     fclose( fp ) ;
00276 
00277     return edk_SUCCEEDED;
00278 
00279 }
00280 static int WINAPI dkcSaveFile(const void *data,size_t size,const char *fname,const char *mode)
00281 {
00282     FILE *fp;
00283     if(NULL==fname || NULL==mode){
00284         return edk_FAILED;
00285     }
00286     fp = fopen( fname , mode ) ;//wb
00287     if(fp==NULL) return edk_FAILED;
00288     fwrite( data , size  , 1 , fp ) ;
00289     //fwrite( data , sizeof(size)  , 1 , fp ) ;
00290     fclose( fp ) ;
00291     return edk_SUCCEEDED;
00292 }
00293 
00294 
00295 DKC_EXTERN FILE * WINAPI dkcFOpen(const char *filename,const char *mode){
00296     return fopen(filename,mode);
00297 }
00298 
00299 DKC_EXTERN int WINAPI dkcFClose(FILE **ptr){
00300     if(NULL==ptr || NULL==*ptr) return edk_ArgumentException;
00301     fclose(*ptr);
00302     *ptr = NULL;
00303     return edk_SUCCEEDED;
00304 }
00305 DKC_EXTERN size_t WINAPI dkcFReadAll(void *buffer,size_t size,FILE *fp)
00306 {
00307     size_t count;
00308     size_t tc,tsize;
00309     BYTE *tbuffer;
00310 
00311     //read size
00312     tsize = size;
00313     //temp variable
00314     tc = 0;
00315     //offset counter
00316     count = 0;
00317     //byte type pointer
00318     tbuffer = (BYTE *)buffer;
00319     for(;;)
00320     {
00321         //error check
00322         if(ferror(fp) ){
00323             break;
00324         }
00325         if(feof(fp)){
00326             break;
00327         }
00328         //read
00329         tc = fread(&tbuffer[count],1,tsize,fp);
00330         //update
00331         tsize -= tc;
00332         count += tc;
00333 
00334         if(count == size){
00335             break;
00336         }
00337 #   ifdef DEBUG
00338         //ありえないエラーチェック
00339         dkcmNOT_ASSERT(count > size);
00340 #   else
00341         if(count > size){
00342             break;
00343         }
00344 #   endif
00345     }
00346     return count;
00347 }
00348 
00349 DKC_EXTERN size_t WINAPI dkcFWriteAll(void *buffer,size_t size,FILE *fp){
00350     size_t count;
00351     size_t tc,tsize;
00352     BYTE *tbuffer;
00353 
00354     //read size
00355     tsize = size;
00356     //temp variable
00357     tc = 0;
00358     //offset counter
00359     count = 0;
00360     //byte type pointer
00361     tbuffer = (BYTE *)buffer;
00362     for(;;)
00363     {
00364         //error check
00365         if(ferror(fp) ){
00366             break;
00367         }
00368         if(feof(fp)){
00369             break;
00370         }
00371         //read
00372         tc = fwrite(&tbuffer[count],1,tsize,fp);
00373         //update
00374         tsize -= tc;
00375         count += tc;
00376 
00377         if(count == size){
00378             break;
00379         }
00380 #   ifdef DEBUG
00381         //ありえないエラーチェック
00382         dkcmNOT_ASSERT(count > size);
00383 #   else
00384         if(count > size){
00385             break;
00386         }
00387 #   endif
00388     }
00389     return count;
00390 
00391 }
00392 
00393 
00394 //fopenのファイル関数を使ってバイナリセーブを行う。
00395 int WINAPI dkcSaveBinary(const void *data,size_t size,const char *fname){//="wb"
00396     return dkcSaveFile(data,size,fname,"wb");
00397 }
00398 
00399 BOOL WINAPI dkcCreateEmptyFile(const char *filename){
00400     FILE *fp;
00401     fp = fopen( filename , "wb" ) ;//wb
00402     if(fp==NULL) return FALSE;
00403     fclose( fp ) ;
00404     return TRUE;
00405 }
00406 
00407 
00408 int WINAPI dkcLoadBinary(void *data,size_t size,const char *fname,size_t *readsize){//="rb"
00409     return dkcLoadFile(data,size,fname,"rb",readsize);
00410 }
00411 
00412 int WINAPI dkcSaveText(const char *text,size_t length,const char *fname){
00413     return dkcSaveFile(text,length,fname,"wt");
00414 }
00415 int WINAPI dkcLoadText(char *text,size_t length,const char *fname,size_t *readsize){
00416     return dkcLoadFile(text,length,fname,"rt",readsize);
00417 }
00418 
00419 void WINAPI dkcSwapFast(void *p1,void *p2,size_t size)
00420 {
00421     void *p = malloc(size);
00422     dkcmNOT_ASSERT(NULL==p);
00423     memcpy(p,p1,size);
00424     memcpy(p1,p2,size);
00425     memcpy(p2,p,size);
00426     free(p);
00427 }
00428 /*
00429 template<typename TYPE_T>
00430 inline void dkcSwapT(TYPE_T *p1,TYPE_T *p2,size_t size){
00431     size_t i;
00432     char buf;
00433     size_t mod_ = size % sizeof(TYPE_T);
00434     size_t cnt = size / sizeof(TYPE_T);
00435     for(i=0;i<cnt;i++){
00436         SWAP_NUM(p1[i],p2[i]);
00437     }
00438     for(i=0;i<mod_;i++){
00439         buf = (((BYTE *)p1)[size - mod_ + i]);
00440         (((BYTE *)p1)[size - mod_ + i]) = 
00441             (((BYTE *)p2)[size - mod_ + i]) ;
00442         (((BYTE *)p2)[size - mod_ + i]) = buf;
00443     }
00444 
00445 }
00446 
00447 
00448 void WINAPI dkcSwapFast(int *p1,int *p2,size_t size)
00449 {
00450     size_t i;
00451     char buf;
00452     size_t mod_ = size % sizeof(int);
00453     size_t cnt = size / sizeof(int);
00454     for(i=0;i<cnt;i++){
00455         SWAP_NUM(p1[i],p2[i]);
00456     }
00457     for(i=0;i<mod_;i++){
00458         buf = (((BYTE *)p1)[size - mod_ + i]);
00459         (((BYTE *)p1)[size - mod_ + i]) = 
00460             (((BYTE *)p2)[size - mod_ + i]) ;
00461         (((BYTE *)p2)[size - mod_ + i]) = buf;
00462     }
00463 }*/
00464 
00465 #ifdef _MSC_VER
00466 #   pragma warning(disable:4244)
00467 #endif
00468 
00469 void WINAPI dkcSwap64(ULONGLONG *p1,ULONGLONG *p2,size_t size){
00470     size_t i;
00471     BYTE buf;
00472     size_t mod_ = size % sizeof(ULONGLONG);
00473     size_t cnt = size / sizeof(ULONGLONG);
00474     //char *tp1 = (char *)p1,*tp2 = (char *)p2;
00475     for(i=0;i<cnt;i++){
00476         SWAP_NUM(p1[i],p2[i]);
00477     }
00478     for(i=0;i<mod_;i++){
00479         
00480         //SWAP_NUM((char)tp1[size - mod_ + 1],(char)tp2[size - mod_ + i]);
00481         /*a = b - a ;\
00482     b -= a ;\
00483     a += b
00484         */
00485         /*( ( ((char *) p2)[size - mod_ + i]))
00486             = (char)( ( ((char *) p2)[size - mod_ + i])) - 
00487             (char)( ( ((char *) p1)[size - mod_ + i]));
00488         
00489         ( ( ((char *) p2)[size - mod_ + i])) -= ( ( ((char *) p1)[size - mod_ + i]));
00490 
00491         ( ( ((char *) p1)[size - mod_ + i])) += ( ( ((char *) p2)[size - mod_ + i]));
00492             */
00493         
00494         
00495         buf = (((BYTE *)p1)[size - mod_ + i]);
00496         (((BYTE *)p1)[size - mod_ + i]) = 
00497             (((BYTE *)p2)[size - mod_ + i]) ;
00498         (((BYTE *)p2)[size - mod_ + i]) = buf;
00499         
00500     }
00501 
00502 }
00503 
00504 void WINAPI dkcSwap(void *p1,void *p2,size_t size)
00505 {
00506     dkcSwap64((ULONGLONG *)p1,(ULONGLONG *)p2,size);
00507 }
00508 
00509 
00510 
00511 DKC_INLINE void WINAPI dkcTwoDWORDToULONGLONG(ULONGLONG *dest,DWORD high,DWORD low){
00512     //*dest = (ULONGLONG)((high << 32) + low);
00513     *dest = (ULONGLONG)high << 32;
00514     *dest += low;
00515         //( high * MAXDWORD ) + low;
00516 }
00517 
00518 DKC_INLINE void WINAPI dkcULONGLONGToTwoDWORD(DWORD *dhigh,DWORD *dlow,ULONGLONG src){
00519     DWORD *o = (DWORD *)&src;
00520     dkcmNOT_ASSERT(sizeof(DWORD) * 2 != sizeof(ULONGLONG));
00521     //エンディアン問題をどうにかしよう!
00522     *dhigh = o[0];
00523     *dlow = o[1];
00524 }
00525 
00526 DKC_INLINE void WINAPI dkcLONGLONGToTwoLONG(LONG *high,LONG *low,LONGLONG src){
00527     LONG *o = (LONG *)&src;
00528     dkcmNOT_ASSERT(sizeof(LONG) * 2 != sizeof(LONGLONG));
00529     *high = o[0];
00530     *low = o[1];
00531 }
00532 
00533 DKC_INLINE void WINAPI dkcTwoLONGToLONGLONG(LONGLONG *dest,LONG high,LONG low){
00534     //*dest = (ULONGLONG)((high << 32) + low);
00535     *dest = (LONGLONG)high << 32;
00536     *dest += low;
00537 
00538 }
00539 
00540 /*
00541 //まずい、これは難しい。
00542 DKC_INLINE int WINAPI dkcDataReplace(BYTE *dest,size_t destsize,
00543                                                                          const BYTE *src,size_t srcsize,
00544                                                                          const BYTE *target_data,size_t target_data_size,
00545                                                                          const BYTE *replace_data,size_t replace_data_size)
00546 {
00547     
00548     size_t i;
00549 
00550     //とりあえず、20個 で offsetはsize_t分
00551     DKC_QUEUE *pq = dkcAllocQueue(20,sizeof(size_t));
00552     if(NULL==pq){
00553         return edk_OutOfMemory;
00554     }
00555 
00556     //まずは置換場所を探す
00557     for(i=0;i<srcsize;i++){
00558         memcmp(&src[i],
00559 
00560 
00561 
00562 
00563 
00564 }*/
00565 
00566 
00567 
00568 #ifdef _MSC_VER
00569 #   pragma warning(default:4244)
00570 
00571 #include <crtdbg.h>
00572 
00573 void WINAPI dkcCheckMemoryLeak(BOOL flag){
00574     if(flag){
00575         _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
00576     }else{
00577         _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF);
00578     }
00579 }
00580 
00581 #else
00582 
00583 void WINAPI dkcCheckMemoryLeak(BOOL flag){
00584 
00585 }
00586 #endif
00587 
00588 const char *WINAPI dkcGetPathSep(){
00589 #ifdef WIN32
00590     static char target[3]={dkcdPATH_SEP,'/','\0'};
00591 #else
00592     static char target[3]={dkcdPATH_SEP,'\0'};
00593 #endif
00594     return target;
00595 }
00596 #ifdef _MSC_VER
00597 BOOL WINAPI dkcIsMMX(void)
00598 {
00599     BOOL flag = FALSE;
00600 
00601     __asm{
00602         push    edx
00603         push    ecx
00604         pushfd
00605         pop     eax
00606         xor     eax, 00200000h
00607         push    eax
00608         popfd
00609         pushfd
00610         pop     ebx
00611         cmp     eax, ebx
00612         jnz     non_mmx
00613         mov     eax, 0
00614         cpuid
00615         cmp     eax, 0
00616         jz      non_mmx
00617         mov     eax, 1
00618         cpuid
00619         and     edx, 00800000h
00620         jz      non_mmx
00621         mov     flag, TRUE
00622     non_mmx:
00623         pop     ecx
00624         pop     edx
00625     }
00626     return flag;
00627 }
00628 #else
00629 BOOL WINAPI dkcIsMMX(void){
00630   return FALSE;
00631 }
00632 #endif
00633 
00634 
00635 DKC_INLINE USHORT dkcReverseEndian16(USHORT x){
00636     return (USHORT)((x >> 8) | (x << 8));
00637 }
00638 
00639 DKC_INLINE DWORD dkcReverseEndian32(DWORD x){
00640     return (x << 24) | ((x & 0x0000ff00) << 8) | ((x & 0x00ff0000) >> 8) | (x >> 24);
00641 }
00642 
00643 DKC_INLINE ULONGLONG dkcReverseEndian64(ULONGLONG x) {
00644 
00645     return (
00646         (ULONGLONG)dkcReverseEndian32((DWORD)(x & 0x00000000ffffffff)) << 32)
00647         | 
00648         dkcReverseEndian32((DWORD)(x >> 32)
00649     );
00650 
00651 }
00652 DKC_INLINE  BOOL dkcIsLittleEndian(){
00653     int x=1;
00654     return (BOOL)((*(char*)&x));
00655 }
00656 
00657 
00658 DKC_INLINE BOOL dkcCheckOverflowULONG(ULONG a1,ULONG a2){
00659     ULONG maxv = ULONG_MAX;
00660   ULONG halfv = maxv / 2 ;
00661   ULONG x = a1,y = a2;
00662   if(x < y){
00663     SWAP_NUM(x,y);
00664   }
00665   if(x > halfv + 1){
00666     if(y >= halfv){
00667       return TRUE;
00668     }
00669   }
00670   return FALSE;
00671 }
00672 
00673 
00674 static void *get_offset(void *p,size_t offset){
00675     BYTE *oo = (BYTE *)p;
00676     
00677     return (void *)&(oo[offset]);
00678 }
00679 
00685 int WINAPI dkcSelect(void *dest,const void *a_src,size_t n,int k,size_t width ,DKC_COMPARE_TYPE less)
00686 {
00687 
00688     int i,j,left, right;
00689 
00690     void *x = malloc(width);
00691     void *a = malloc(n * width);
00692     if(NULL==x || NULL==a){
00693         return edk_ArgumentException;
00694     }
00695     if(n > INT_MAX){
00696         return edk_FAILED;
00697     }
00698     
00699 
00700     memcpy(a,a_src,width * n);
00701 
00702 
00703     left = 0;  right = n - 1;
00704 
00705     while (left < right) 
00706     {
00707 
00708         memcpy(x,   (const void *)get_offset(a,k * width),width);
00709         i = left;
00710         j = right;
00711 
00712         for ( ; ; ) {
00713 
00714             while( less(get_offset(a,i * width),x) > 0){
00715             //while( *(int *)get_offset(a,i * width) < *(int *)x){
00716                 i++;
00717             }
00718 
00719             while( less(x,get_offset(a,j * width)) > 0){
00720             //while( *(int *)x < *(int *)get_offset(a,j * width) ){
00721                 j--;
00722             }
00723 
00724             if (i > j){
00725                 break;
00726             }
00727             
00728 
00729             dkcSwapFast(
00730                 get_offset(a,i * width),
00731                 get_offset(a,j * width),
00732                 width
00733                 );
00734             
00735             i++;
00736             j--;
00737         }
00738         if (j < k){
00739             left  = i;
00740         }
00741         if (k < i){
00742             right = j;
00743         }
00744     }
00745 
00746     //ゲットする
00747     {
00748         //printf("%d",*(int *)get_offset(a,k * width));
00749 
00750         memcpy(dest,(const void *)get_offset(a,k * width),width);
00751 
00752     }
00753     free(x);
00754     free(a);
00755 
00756     return edk_SUCCEEDED;
00757 
00758 }
00759 
00760 
00761 DKC_INLINE int WINAPI dkcSelectMax(void *a,const void *a_src, size_t n,size_t width ,DKC_COMPARE_TYPE less){
00762     if(n-1 > INT_MAX){
00763         return edk_FAILED;
00764     }
00765     return dkcSelect(a,a_src,n,(int)n-1,width,less);
00766 }
00767 DKC_INLINE int WINAPI dkcSelectMin(void *a,const void *a_src, size_t n,size_t width ,DKC_COMPARE_TYPE less){
00768     return dkcSelect(a,a_src,n,(int)0,width,less);
00769 }
00770 #if 0
00771 int WINAPI dkcSelect(void *dest,const void *a_src,size_t n,size_t k,size_t width ,DKC_COMPARE_TYPE less)
00772 {
00773     //int i, j, left, right;
00774     size_t i,j,left, right;
00775     //keytype x, t;
00776     //size_t x,t;
00777     void *x = malloc(width);
00778     void *a = malloc(n * width);
00779     if(NULL==x || NULL==a){
00780         return edk_ArgumentException;
00781     }
00782     
00783     //void *t = malloc(width);
00784     memcpy(a,a_src,width * n);
00785 
00786 
00787     left = 0;  right = n - 1;
00788     /*
00789     x = a[k];  i = left;  j = right;
00790         for ( ; ; ) {
00791             while (a[i] < x) i++;
00792             while (x < a[j]) j--;
00793             if (i > j) break;
00794             t = a[i];  a[i] = a[j];  a[j] = t;
00795             i++;  j--;
00796         }
00797         if (j < k) left  = i;
00798         if (k < i) right = j;
00799     */
00800     while (left < right) 
00801     {
00802         //x = a[k];  i = left;  j = right;
00803         //offset_temp = (BYTE *)a;
00804     
00805         //memcpy(x, (const void *)&offset_temp[k * width],width);
00806         memcpy(x,   (const void *)get_offset(a,k * width),width);
00807         i = left;
00808         j = right;
00809 
00810         for ( ; ; ) {
00811             //while (a[i] < x) i++;
00812             //while(less(a[i],x)) i++;
00813 //#error less じゃなくて greater でも、qsortと同じ仕様にするため・・・。スマン
00814             //while( less(get_offset(a,i * width),x) < 0){
00815             while( less(get_offset(a,i * width),x) ){
00816                 i++;
00817             }
00818 
00819             /*void *p = get_offset(a,i * width);
00820             BYTE *ma = (BYTE *)get_offset(a,n * width);
00821             dkcmNOT_ASSERT(p < a);
00822             dkcmNOT_ASSERT(p > ((BYTE *)a) + n * width);
00823             dkcmNOT_ASSERT((ma - (BYTE *)p) % width != 0);
00824             while(less(p,x) > 0){
00825                 i++;
00826                 p = get_offset(a,i * width);
00827                 ma = (BYTE *)get_offset(a,n * width);
00828                 dkcmNOT_ASSERT(p < a);
00829                 dkcmNOT_ASSERT(p > ma - width);
00830                 dkcmNOT_ASSERT((ma - p) % width != 0);
00831             }*/
00832 
00833             //while (x < a[j]) j--;
00834             //while(less(x,a[j]) j--;
00835             //while( less(x,get_offset(a,j * width)) < 0){
00836             while( less(x,get_offset(a,j * width)) ){
00837                 j--;
00838             }
00839 
00840             if (i > j){
00841                 break;
00842             }
00843             
00844             //t = a[i];  a[i] = a[j];  a[j] = t;
00845             //dkcSwap(&a[i],&a[j],width);
00846             dkcSwap(
00847                 get_offset(a,i * width),
00848                 get_offset(a,j * width),
00849                 width
00850                 );
00851             
00852             i++;
00853             j--;
00854         }
00855         if (j < k){
00856             left  = i;
00857         }
00858         if (k < i){
00859             right = j;
00860         }
00861     }
00862 
00863     //ゲットする
00864     {
00865         printf("%d",*(int *)get_offset(a,k * width));
00866         //memcpy(,  (const void *)get_offset(a,k * width),width);
00867         //memcpy(dest,(const void *)get_offset(a,k * width),width);
00868         memcpy(dest,x,width);
00869     }
00870     free(x);
00871     free(a);
00872     //free(t);
00873     return edk_SUCCEEDED;
00874     //return a[k];
00875 }
00876 #endif
00877 
00878 DKC_INLINE int dkcRotateShiftRightMemoryLogic(void *d,size_t size,size_t n,void *workbuff,size_t worksize)
00879 {
00880     BYTE *dest = (BYTE *)d;
00881     size_t temp;
00882 
00883     if(n > worksize){
00884         return edk_FAILED;
00885     }
00886     for(;;){
00887         if(n < size){
00888             break;
00889         }
00890         n -= size;
00891     }
00892     temp = size - n;
00893     memcpy(workbuff,dest + temp,n);
00894     memmove(dest + n,dest,temp);
00895     memcpy(dest,workbuff,n);
00896     return edk_SUCCEEDED;
00897 
00898 }
00899 
00900 int WINAPI dkcRotateShiftRightMemory(void *d,size_t size,size_t num){
00901     //size_t i = 0;
00902     void *pd = NULL;
00903     int r = edk_FAILED;
00904 
00905     pd = malloc(num);
00906     if(NULL==pd){
00907         return edk_OutOfMemory;
00908     }
00909     if(DKUTIL_SUCCEEDED(dkcRotateShiftRightMemoryLogic(d,size,num,pd,num))){
00910         r = edk_SUCCEEDED;
00911     }
00912 
00913     free(pd);
00914     
00915     return r;
00916 
00917 }

dkutil_cに対してTue Dec 7 01:09:56 2004に生成されました。 doxygen 1.3.6