root/_BazaLib/BL_Tools.cpp

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ASSERT
  2. Debug_Error
  3. Debug_Alert
  4. Debug_Info
  5. RemoveList
  6. RemoveList
  7. DeleteItemAt
  8. LastItem
  9. FirstItem
  10. DeleteItem
  11. AddItem
  12. AddItem
  13. AddItem
  14. DeleteItems
  15. AddList
  16. AddList
  17. AddList
  18. AddItem
  19. AddItem
  20. AddItem
  21. AddItem
  22. AddItem
  23. StringAt
  24. Int32
  25. Float
  26. RTrim
  27. LTrim
  28. ComparePos
  29. CountChar
  30. SetDigits
  31. GetFromMessage
  32. LengthUTF8
  33. RemoveUTF8
  34. AppendUTF8
  35. StringUTF8
  36. InsertUTF8
  37. PCharCharPosInBytes_UTF8
  38. PCharCharsInBytes_UTF8
  39. PCharFindLastChar
  40. BL_System_TranslError
  41. BL_System_TypeToString
  42. BL_Int_Swap
  43. BL_Load_SIconFromMIME
  44. BL_Get_SList_FromMessage

   1 /*
   2 ===============================================
   3 Project:        BeFar
   4 File:           BL_Tools.cpp
   5 Desc:           Provides some usefull functions
   6 Author:         Baza,some minor changes by Nexus
   7 Created:        20.11.99
   8 Modified:       07.01.2000
   9 ===============================================
  10 */
  11 
  12 #include <string.h>
  13 #include <stdio.h>
  14 #include <stdlib.h>
  15 #include <Application.h>
  16 #include <Alert.h>
  17 
  18 #include "../_BazaLib/BL_Tools.h"
  19 #include "../_BazaLib/BL_File.h"
  20 
  21 
  22 void
  23 ASSERT(bool b_True,const char *pc_Message)    /* [previous][next][first][last][top][bottom][index][help] */
  24 {
  25         if(b_True) return;
  26         Debug_Error(pc_Message?pc_Message:"ASSERT!");
  27         exit(-1);
  28 }
  29 
  30 
  31 void
  32 Debug_Error(const char * pc_Message, status_t err)    /* [previous][next][first][last][top][bottom][index][help] */
  33 {
  34         ASSERT(pc_Message);
  35         BL_String s(pc_Message),s1;
  36         BL_System_TranslError(err,s1);
  37 
  38         //      write log //
  39         {
  40                 BL_File oFile("errors.log",B_WRITE_ONLY|B_OPEN_AT_END|B_CREATE_FILE);           
  41                 BL_String s2(s);
  42                 s2<<"  ";
  43                 s2<<s1;
  44                 oFile.WriteString(&s2);
  45         }
  46         //
  47         s<<" \n error : ";      
  48         s<<s1;  
  49         printf(s.String());
  50         printf("\n");   
  51         (new BAlert("", s.String(), "Quit"))->Go();
  52         be_app->PostMessage(B_QUIT_REQUESTED);
  53 }
  54 
  55 void
  56 Debug_Alert(const char * message)    /* [previous][next][first][last][top][bottom][index][help] */
  57 {
  58         (new BAlert("", message, "Quit"))->Go();
  59 }
  60 
  61 void
  62 Debug_Info(const char * message)     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64         printf("%s\n", message);
  65 }
  66 
  67 BL_Collection::BL_Collection(bool b_DeleteItems)
  68 {
  69         bDeleteItems = b_DeleteItems;   
  70         iItemsType = BL_COLLECTION_ITEMS_IS_VOID;
  71 }
  72 
  73 BL_Collection::~BL_Collection()
  74 {
  75         if(bDeleteItems) DeleteItems();
  76 }
  77 
  78 void            
  79 BL_Collection::RemoveList(BL_Collection *plo_Item)    /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81         ASSERT(plo_Item);
  82         RemoveList(*plo_Item);  
  83 }
  84 void            
  85 BL_Collection::RemoveList(BL_Collection &lo_Item)    /* [previous][next][first][last][top][bottom][index][help] */
  86 {
  87         for(int32 i=0;i<lo_Item.CountItems();i++){
  88                 RemoveItem(lo_Item.ItemAt(i) );
  89         }
  90 }       
  91 
  92 void            
  93 BL_Collection::DeleteItemAt(int i_Index)    /* [previous][next][first][last][top][bottom][index][help] */
  94 {
  95         void *puItem = ItemAt(i_Index);
  96         DeleteItem(puItem);
  97 }
  98 
  99 void*           
 100 BL_Collection::LastItem()    /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         ASSERT(CountItems()!=0);
 103         return ItemAt(CountItems()-1);
 104 }
 105 
 106 void*           
 107 BL_Collection::FirstItem()    /* [previous][next][first][last][top][bottom][index][help] */
 108 {
 109         ASSERT(CountItems()!=0);
 110         return ItemAt(0);
 111 }
 112 
 113 void            
 114 BL_Collection::DeleteItem(void *pu_Item)    /* [previous][next][first][last][top][bottom][index][help] */
 115 {
 116         ASSERT(pu_Item);
 117         RemoveItem(pu_Item);
 118 
 119 /*      
 120         if(is_kind_of(pu_Item,BString)){
 121                 BString* ps = cast_as(pu_Item,BString);
 122                 delete ps;      
 123         }else
 124                 ASSERT(false);
 125 */
 126                 
 127         switch(iItemsType){
 128         case BL_COLLECTION_ITEMS_IS_STRING:{
 129                 BL_String* ps = (BL_String*)pu_Item;
 130                 printf("\t\tDeleteItem:BL_String:%s\n", ps->String());
 131                 printf("TATA:%s\n", ps->String());
 132                 ps->SetTo("");
 133                 DELETE(ps);
 134                 break;}
 135         case BL_COLLECTION_ITEMS_IS_LIST:{
 136                 BList* pl = (BList*)pu_Item;
 137                 DELETE(pl);
 138                 break;} 
 139         case BL_COLLECTION_ITEMS_IS_BLOBJECT:{
 140                 delete (BL_Object*)pu_Item;
 141                 break;}
 142         case BL_COLLECTION_ITEMS_IS_VOID:{
 143                 delete (void*)pu_Item;
 144                 break;}
 145         };      
 146 }
 147 
 148 bool            
 149 BL_Collection::AddItem(BString *ps_Item, int32 atIndex)    /* [previous][next][first][last][top][bottom][index][help] */
 150 {       
 151         ASSERT(ps_Item);
 152         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType
 153                 || BL_COLLECTION_ITEMS_IS_STRING==iItemsType);
 154                 
 155         iItemsType = BL_COLLECTION_ITEMS_IS_STRING;
 156         return BList::AddItem((void*)ps_Item,atIndex);
 157 }
 158 
 159 bool            
 160 BL_Collection::AddItem(void *pu_Item, int32 atIndex)    /* [previous][next][first][last][top][bottom][index][help] */
 161 {
 162         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType);
 163         return BList::AddItem(pu_Item,atIndex); 
 164 }
 165 
 166 bool            
 167 BL_Collection::AddItem(BL_Object *po_Item, int32 atIndex)    /* [previous][next][first][last][top][bottom][index][help] */
 168 {
 169         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType
 170                 || BL_COLLECTION_ITEMS_IS_BLOBJECT==iItemsType);                                
 171         iItemsType = BL_COLLECTION_ITEMS_IS_BLOBJECT;   
 172         
 173         return BList::AddItem((void*)po_Item,atIndex);
 174 }
 175 
 176 
 177 void            
 178 BL_Collection::DeleteItems()    /* [previous][next][first][last][top][bottom][index][help] */
 179 { 
 180         void *pu;
 181         while(true){
 182                 pu = ItemAt(0);
 183                 if(!pu) break;                          
 184                 DeleteItem(pu);
 185         }
 186 }
 187 
 188 
 189 bool            
 190 BL_Collection::AddList(BL_Collection *pl_List,int i_Index)    /* [previous][next][first][last][top][bottom][index][help] */
 191 {
 192         ASSERT(pl_List);
 193         if(pl_List->CountItems()==0) return true;       
 194         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType || iItemsType==pl_List->iItemsType);
 195         
 196         iItemsType = pl_List->iItemsType;
 197         return BList::AddList(pl_List,i_Index);
 198 }
 199 
 200 bool            
 201 BL_Collection::AddList(BList *pl_List)    /* [previous][next][first][last][top][bottom][index][help] */
 202 {
 203         ASSERT(pl_List);
 204         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType);
 205         
 206         return BList::AddList(pl_List);
 207 }
 208 
 209 bool            
 210 BL_Collection::AddList(BL_Collection *pl_List)    /* [previous][next][first][last][top][bottom][index][help] */
 211 {
 212         ASSERT(pl_List);
 213         if(pl_List->CountItems()==0) return true;       
 214         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType || iItemsType==pl_List->iItemsType);
 215         
 216         iItemsType = pl_List->iItemsType;
 217         return BList::AddList(pl_List);
 218 }
 219 
 220 bool    
 221 BL_Collection::AddItem(void *pu_Item)    /* [previous][next][first][last][top][bottom][index][help] */
 222 {       
 223         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType);
 224         return BList::AddItem(pu_Item);
 225 }
 226 
 227 bool
 228 BL_Collection::AddItem(BString * ps_Item)    /* [previous][next][first][last][top][bottom][index][help] */
 229 {
 230         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType
 231                 || BL_COLLECTION_ITEMS_IS_STRING==iItemsType);
 232         BString* ps = (BString*)ps_Item;
 233         printf("\t\tAddItem:BString:%s\n", ps->String());
 234         
 235         iItemsType = BL_COLLECTION_ITEMS_IS_STRING;
 236         return BList::AddItem((void*)ps_Item);
 237 }
 238 
 239 bool
 240 BL_Collection::AddItem(BL_String * ps_Item)    /* [previous][next][first][last][top][bottom][index][help] */
 241 {
 242         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType
 243                 || BL_COLLECTION_ITEMS_IS_STRING==iItemsType);
 244         BL_String* ps = (BL_String*)ps_Item;
 245         printf("\t\tAddItem:BL_String:%s\n", ps->String());
 246         
 247         iItemsType = BL_COLLECTION_ITEMS_IS_STRING;
 248         return BList::AddItem((void*)ps_Item);
 249 }
 250 
 251 bool
 252 BL_Collection::AddItem(BList * pl_Item)    /* [previous][next][first][last][top][bottom][index][help] */
 253 {
 254         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType
 255                 || BL_COLLECTION_ITEMS_IS_LIST==iItemsType);
 256                 
 257         iItemsType = BL_COLLECTION_ITEMS_IS_LIST;
 258         return BList::AddItem((void*)pl_Item);
 259 }
 260 
 261 bool
 262 BL_Collection::AddItem(BL_Object * po_Item)    /* [previous][next][first][last][top][bottom][index][help] */
 263 {
 264         ASSERT(BL_COLLECTION_ITEMS_IS_VOID==iItemsType
 265                 || BL_COLLECTION_ITEMS_IS_BLOBJECT==iItemsType);                
 266 
 267         iItemsType = BL_COLLECTION_ITEMS_IS_BLOBJECT;
 268         return BList::AddItem((void*)po_Item);
 269 }
 270 
 271 BL_String*
 272 BL_Collection::StringAt(int i_Index)    /* [previous][next][first][last][top][bottom][index][help] */
 273 {
 274         return (BL_String*)ItemAt(i_Index);
 275 }
 276 
 277 BL_List::BL_List(bool b_DeleteItems)
 278         :BL_Collection(b_DeleteItems)
 279 {
 280 }
 281 
 282 ////////////////////////////////////////////////////////////////////////////
 283 
 284 BL_String::BL_String()
 285 {
 286 }
 287 
 288 BL_String::BL_String(const BString & s_Source)
 289 :BString(s_Source)
 290 {
 291 }
 292 
 293 BL_String::BL_String(const char *pc_Text)
 294 :BString(pc_Text)
 295 {
 296 }
 297 
 298 BL_String::~BL_String()
 299 {
 300 }
 301 
 302 int32
 303 BL_String::Int32()    /* [previous][next][first][last][top][bottom][index][help] */
 304 {
 305         return atoi(String());
 306 }
 307 
 308 float
 309 BL_String::Float()    /* [previous][next][first][last][top][bottom][index][help] */
 310 {
 311         return atof(String());
 312 }
 313 
 314 void            
 315 BL_String::RTrim(char c_Byte)    /* [previous][next][first][last][top][bottom][index][help] */
 316 {
 317         while(ByteAt(Length()-1)==c_Byte){
 318                 Remove(Length()-1,1);
 319         }
 320 }
 321 
 322 void            
 323 BL_String::LTrim(char c_Byte)    /* [previous][next][first][last][top][bottom][index][help] */
 324 {
 325         while(ByteAt(0)==c_Byte){
 326                 Remove(0,1);
 327         }
 328 }
 329 
 330 int                     
 331 BL_String::ComparePos(BL_String & s_Friend,int i_SelfPos,int i_FriendPos)    /* [previous][next][first][last][top][bottom][index][help] */
 332 {
 333         const char *pc1,*pc2;
 334 // sz: 09.05.2009 - incompatibility with Haiku API      
 335 //      pc1 = _privateData+i_SelfPos;
 336 //      pc2 = s_Friend._privateData+i_FriendPos;
 337         pc1 = String()+i_SelfPos;
 338         pc2 = s_Friend.String()+i_FriendPos;
 339         return ( strcmp(pc1,pc2) );
 340 }
 341 
 342 void            
 343 BL_String::operator=(int64 i_Value)
 344 {
 345         SetTo("");
 346         *this<<i_Value;
 347 }
 348 
 349 void            
 350 BL_String::operator=(const char* pc_Value)
 351 {
 352         SetTo(pc_Value);
 353 }
 354 
 355 int32 
 356 BL_String::CountChar(char c_Value)    /* [previous][next][first][last][top][bottom][index][help] */
 357 {
 358         int32 iCount=0;
 359         // sz: 09.05.2009 - incompat with Haiku API
 360         //char *pc = _privateData;
 361         const char *pc = String();
 362         while(pc[0]!='\0'){
 363                 if(pc[0]==c_Value) iCount++;
 364                 pc++;
 365         }       
 366         return(iCount);
 367 }
 368 
 369 void            
 370 BL_String::operator=(BString & s_Value)
 371 {
 372         SetTo(s_Value);
 373 }
 374 
 375 BL_String*
 376 BL_String::SetDigits(char c_Digit,char c_DecPointChar)    /* [previous][next][first][last][top][bottom][index][help] */
 377 {
 378         BString sResult;
 379         /* check for zero  */
 380         if(Length()==0){
 381                 SetTo("0");
 382                 return this;
 383         }
 384         /* check for dec_point */
 385         // sz: 09.05.2009 - incompat with Haiku API!
 386         //char *pc,*pcZero = strchr(_privateData,c_DecPointChar);
 387         char *pcZero = strchr(String(),c_DecPointChar);
 388         if(pcZero) pcZero[0]='\0';
 389         // sz: 09.05.2009 - incompat with Haiku API!
 390         //pc = _privateData;
 391         char* pc = (char*)String();
 392         /* set digits */
 393         int     iLen = strlen(pc);
 394         char    c1;
 395         for(int i = (iLen % 3), i1=0; i<=iLen; i+=3){
 396                 if(i==0) continue;
 397                 c1 = pc[i];
 398                 pc[i] = '\0';
 399                 sResult << (pc+i1);
 400                 pc[i] = c1;
 401                 i1 = i;
 402                 if(i!=iLen) sResult << c_Digit;
 403         }
 404         /* set dec */
 405         if(pcZero){
 406                 pcZero[0] = c_DecPointChar;
 407                 sResult << (pcZero+1);
 408         }
 409         /* finish */
 410         SetTo(sResult);
 411         
 412         return this;
 413 }
 414 
 415 status_t        
 416 BL_String::GetFromMessage(BMessage *po_Message,const char *pc_Name)    /* [previous][next][first][last][top][bottom][index][help] */
 417 {
 418         if(!po_Message || !pc_Name) return B_ERROR;
 419         
 420         const char *pc=NULL;
 421         status_t uRes = po_Message->FindString(pc_Name,&pc);
 422         if(uRes!=B_OK) return uRes;
 423         if(!pc) return B_ERROR;
 424         
 425         SetTo(pc);
 426         return B_OK;
 427 }
 428 
 429 int32           
 430 BL_String::LengthUTF8() const       /* [previous][next][first][last][top][bottom][index][help] */
 431 {
 432 
 433         int32 iLen=0;
 434         for(int i=0;i<BString::Length();i++){
 435                 if(ByteAt(i)&128)       i++;
 436                 iLen++;
 437         }
 438         return iLen;
 439 }
 440 
 441 void
 442 BL_String::RemoveUTF8(int32 i_FromChar, int32 i_CharsCount)    /* [previous][next][first][last][top][bottom][index][help] */
 443 {
 444         //
 445         int32 iFromChar=0;
 446         int32 iFromByte=0;
 447         for(int32 i=0;i<BString::Length();i++){                         
 448                 if(iFromChar==i_FromChar) break;
 449                 
 450                 if(ByteAt(iFromByte)&128){
 451                         i++;                    
 452                         iFromByte++;
 453                 }
 454                 iFromChar++;
 455                 iFromByte++;
 456         }       
 457         //
 458         int32 iCharsCount=0;    
 459         int32 iBytes = 0;
 460         for(int32 i = iFromByte;i<BString::Length();i++){                               
 461                 if(iCharsCount==i_CharsCount) break;                            
 462                 iCharsCount++;
 463                 if(ByteAt(i)&128){
 464                         i++;
 465                         iBytes++;
 466                 }
 467                 iBytes++;
 468                 printf("          i=%i iBytes=%i\n",i,iBytes);                          
 469         }
 470         printf("RemoveUTF8(%i,%i)  >  Remove(%i,%i)  OldBytesCount=%i\n",i_FromChar,i_CharsCount,iFromByte,iBytes,Length());
 471         BString::Remove(iFromByte,iBytes);      
 472 }
 473 
 474 void            
 475 BL_String::AppendUTF8(const char *source, int32 i_CharsCount)    /* [previous][next][first][last][top][bottom][index][help] */
 476 {
 477         int32 iBytes=PCharCharsInBytes_UTF8(source,i_CharsCount);
 478 //      printf("AppendUTF8(%i)  >  Append(%i)\n",i_CharsCount,iBytes,source);
 479         Append(source,iBytes);                  
 480 }
 481 
 482 const char* 
 483 BL_String::StringUTF8(int32 i_FromChar)const    /* [previous][next][first][last][top][bottom][index][help] */
 484 {       
 485         int32 iByte = PCharCharPosInBytes_UTF8(String(),i_FromChar);
 486 //      printf("StringUTF8(%i)  >  String(%i)\n",i_FromChar,iByte);
 487         return String() + iByte;
 488 }       
 489 
 490 void
 491 BL_String::InsertUTF8(const char *pc_Value, int32 i_CharsCount,int32 i_CharPos)    /* [previous][next][first][last][top][bottom][index][help] */
 492 {
 493         int32 iValueBytes = PCharCharsInBytes_UTF8(pc_Value,i_CharsCount);
 494         int32 iCharPos = PCharCharPosInBytes_UTF8(String(),i_CharPos);
 495         BString::Insert(pc_Value,iValueBytes,iCharPos);
 496 }
 497 
 498 ////////////////////////////////////////////////////////////////////////
 499 
 500 int32 
 501 PCharCharPosInBytes_UTF8(const char *pc_Source,int32 i_Char)    /* [previous][next][first][last][top][bottom][index][help] */
 502 {
 503         ASSERT(pc_Source && (i_Char>=0));
 504         
 505         int32 iChar=0;
 506         int32 iByte=0;
 507         for(uint32 i=0;i<strlen(pc_Source);i++){
 508                 if(iChar==i_Char) break;
 509                 
 510                 if(pc_Source[i]&128){
 511                         i++;
 512                         iByte++;
 513                         uint8 c=pc_Source[i-1];
 514                         printf("> %i\n",c);
 515                 }
 516                 iChar++;                
 517                 iByte++;
 518         }       
 519         return iByte;
 520 }
 521 
 522 int32 
 523 PCharCharsInBytes_UTF8(const char *pc_Source,int32 i_Chars)    /* [previous][next][first][last][top][bottom][index][help] */
 524 {
 525         ASSERT(pc_Source && (i_Chars>=0));
 526         
 527         int32 iChars=0;
 528         int32 iBytes=0;
 529         for(uint32 i=0;i<strlen(pc_Source);i++){                
 530                 
 531                 if(pc_Source[i]&128){
 532                         i++;
 533                         iBytes++;
 534                 }
 535                 iChars++;               
 536                 iBytes++;
 537                 
 538                 if(iChars==i_Chars) break;
 539         }       
 540         return iBytes;
 541 }
 542 //////////////////////////////////////////////////
 543 
 544 char* 
 545 PCharFindLastChar(char *pc_Line,char c_Char)    /* [previous][next][first][last][top][bottom][index][help] */
 546 {
 547         char *pcLast = NULL,*pc = pc_Line;      
 548         while(true){
 549                 pc = strchr(pc,c_Char);
 550                 if(!pc) break;
 551                 pcLast = pc++;
 552         }
 553         return pcLast;
 554 }
 555 
 556 void
 557 BL_System_TranslError(status_t u_Error,BL_String & s_Text)    /* [previous][next][first][last][top][bottom][index][help] */
 558 {
 559         switch(u_Error){
 560         /*--------- GENERAL ERRORS---------*/
 561         case B_OK:
 562                 s_Text = "B_OK";
 563                 break;
 564         case B_TIMED_OUT:
 565                 s_Text = "B_TIMED_OUT";
 566                 break;
 567         case B_BAD_VALUE:
 568                 s_Text = "B_BAD_VALUE";
 569                 break;
 570         case  B_IO_ERROR:
 571                 s_Text = "B_IO_ERROR";
 572                 break;
 573         case  B_BAD_INDEX:
 574                 s_Text = "B_BAD_INDEX";
 575                 break;          
 576         case  B_BAD_TYPE:
 577                 s_Text = " B_BAD_TYPE";
 578                 break;                          
 579         case B_MISMATCHED_VALUES:
 580                 s_Text = "B_MISMATCHED_VALUES";
 581                 break;                                                          
 582         case B_NAME_NOT_FOUND:
 583                 s_Text = "B_NAME_NOT_FOUND";
 584                 break;                                                                                                                                                                          
 585         case B_INTERRUPTED:
 586                 s_Text = "B_INTERRUPTED";
 587                 break;                                                                                                          
 588         case B_CANCELED:
 589                 s_Text = "B_CANCELED";
 590                 break;                                                                                                                          
 591         case B_NO_INIT:
 592                 s_Text = "B_NO_INIT";
 593                 break;                                                                                                                                          
 594         case B_BUSY:
 595                 s_Text = "B_BUSY";
 596                 break;  
 597         case B_NOT_ALLOWED:
 598                 s_Text = "B_NOT_ALLOWED";
 599                 break;                                                                                                                                                                                          
 600         case B_WOULD_BLOCK:
 601                 s_Text = "B_INTERRUPTED";
 602                 break;                                                                                                                          
 603         case B_NAME_IN_USE:
 604                 s_Text = "B_NAME_IN_USE";
 605                 break;
 606         case B_FILE_EXISTS:
 607                 s_Text = "B_FILE_EXISTS";
 608                 break;          
 609         case B_ENTRY_NOT_FOUND:
 610                 s_Text = "B_ENTRY_NOT_FOUND";
 611                 break;
 612         case B_PERMISSION_DENIED:
 613                 s_Text = "B_PERMISSION_DENIED";
 614                 break;                          
 615         case B_NO_MEMORY:
 616                 s_Text = "B_NO_MEMORY";
 617                 break;                                          
 618         case B_BAD_PORT_ID:
 619                 s_Text = "B_BAD_PORT_ID";
 620                 break;
 621         case B_NO_MORE_PORTS:
 622                 s_Text = "B_NO_MORE_PORTS";
 623                 break;
 624         case B_ERROR:
 625                 s_Text = "B_ERROR";
 626                 break;                                                          
 627         /*----------------*/
 628         default:
 629                 s_Text = "uknown error";
 630         };
 631 }
 632 
 633 void
 634 BL_System_TypeToString(uint32 i_Type,BL_String & s)    /* [previous][next][first][last][top][bottom][index][help] */
 635 {
 636                 switch(i_Type){
 637                 case B_ANY_TYPE:
 638                         s="B_ANY_TYPE";
 639                         break;
 640                 case B_ASCII_TYPE:
 641                         s="B_ASCII_TYPE";
 642                         break;
 643                 case B_CHAR_TYPE:
 644                         s="B_CHAR_TYPE";                        
 645                         break;          
 646                 case B_COLOR_8_BIT_TYPE:
 647                         s="B_COLOR_8_BIT_TYPE";
 648                         break;
 649                 case B_GRAYSCALE_8_BIT_TYPE:
 650                         s="B_GRAYSCALE_8_BIT_TYPE";
 651                         break;
 652                 case B_MIME_TYPE:
 653                         s="B_MIME_TYPE";
 654                         break;
 655                 case B_MONOCHROME_1_BIT_TYPE:
 656                         s="B_MONOCHROME_1_BIT_TYPE";
 657                         break;
 658                 case B_INT8_TYPE:
 659                         s="B_INT8_TYPE";
 660                         break;                                  
 661                 case B_INT16_TYPE:
 662                         s="B_INT16_TYPE";                       
 663                         break;                  
 664                 case B_INT32_TYPE:
 665                         s="B_INT32_TYPE";
 666                         break;  
 667                 case B_INT64_TYPE:
 668                         s="B_INT64_TYPE";
 669                         break;  
 670                 case B_UINT8_TYPE:
 671                         s="B_UINT8_TYPE";
 672                         break;  
 673                 case B_UINT16_TYPE:
 674                         s="B_UINT16_TYPE";                      
 675                         break;                  
 676                 case B_UINT32_TYPE:
 677                         s="B_UINT32_TYPE";
 678                         break;  
 679                 case B_UINT64_TYPE:
 680                         s="B_UINT64_TYPE";
 681                         break;  
 682                 case B_FLOAT_TYPE:
 683                         s="B_FLOAT_TYPE";
 684                         break;          
 685                 case B_DOUBLE_TYPE:
 686                         s="B_DOUBLE_TYPE";
 687                         break;          
 688                 case B_BOOL_TYPE:
 689                         s="B_BOOL_TYPE";
 690                         break;  
 691                 case B_OFF_T_TYPE:
 692                         s="B_OFF_T_TYPE";
 693                         break;  
 694                 case B_SIZE_T_TYPE:
 695                         s="B_SIZE_T_TYPE";
 696                         break;
 697                 case B_SSIZE_T_TYPE:
 698                         s="B_SSIZE_T_TYPE";
 699                         break;          
 700                 case B_POINTER_TYPE:
 701                         s="B_POINTER_TYPE";
 702                         break;
 703                 case B_OBJECT_TYPE:
 704                         s="B_OBJECT_TYPE";
 705                         break;          
 706                 case B_RAW_TYPE:
 707                         s="B_RAW_TYPE";
 708                 case B_MESSAGE_TYPE:
 709                         s="B_MESSAGE_TYPE";
 710                         break;          
 711                 case B_MESSENGER_TYPE:
 712                         s="B_MESSENGER_TYPE";
 713                         break;
 714                 case B_POINT_TYPE:
 715                         s="B_POINT_TYPE";
 716                         break;  
 717                 case B_RECT_TYPE:
 718                         s="B_RECT_TYPE";
 719                         break;
 720 /*              case B_PATH_TYPE:
 721                         s="B_PATH_TYPE";
 722                         break;*/
 723                 case B_REF_TYPE:
 724                         s="B_REF_TYPE";
 725                         break;
 726                 case B_RGB_COLOR_TYPE:
 727                         s="B_RGB_COLOR_TYPE";
 728                         break;
 729                 case B_RGB_32_BIT_TYPE:
 730                         s="B_RGB_32_BIT_TYPE";
 731                         break;                  
 732                 case B_PATTERN_TYPE:
 733                         s="B_PATTERN_TYPE";
 734                         break;
 735                 case B_STRING_TYPE:
 736                         s="B_STRING_TYPE";
 737                         break;
 738                 case B_TIME_TYPE:
 739                         s="B_TIME_TYPE";
 740                         break;
 741                 default:{
 742                         char c[5];
 743                         uint32  *pi;
 744                         pi = (uint32*)c;
 745                         *pi=i_Type;     
 746                         BL_Int_Swap(pi);
 747                         c[4] = '\0';                                            
 748                         s=c;    
 749                         break;}
 750                 };
 751 }
 752 
 753 void BL_Int_Swap(void *pi)    /* [previous][next][first][last][top][bottom][index][help] */
 754 {
 755         int8 *pb,b;
 756         pb = (int8*)pi;
 757         b = pb[0];
 758         pb[0] = pb[1];
 759         pb[1] = b;
 760 }
 761 
 762 //////////////////////////////////////////////////////////////
 763 #include <Bitmap.h>
 764 #include <Mime.h>
 765 
 766 BBitmap*
 767 BL_Load_SIconFromMIME(const char *pc_MIME)    /* [previous][next][first][last][top][bottom][index][help] */
 768 {
 769         ASSERT(pc_MIME);
 770         BBitmap* poSIcon = NULL ;
 771         BMimeType       oMimeType;
 772         if(B_OK==oMimeType.SetTo(pc_MIME)){
 773                 poSIcon = new BBitmap(BRect(0,0,15,15),B_CMAP8);
 774                 if(B_OK!=oMimeType.GetIcon(poSIcon,B_MINI_ICON)){
 775                         DELETE(poSIcon);
 776                 }
 777         }
 778         return poSIcon;
 779 }
 780 //////////////////////////////////////////////////////////////
 781 void
 782 BL_Get_SList_FromMessage(BMessage & o_Message,const char *pc_Name,BL_List & ls_Result)    /* [previous][next][first][last][top][bottom][index][help] */
 783 {
 784         ASSERT(pc_Name);
 785         ls_Result.DeleteItems();
 786         //
 787         int i=0;
 788         const char *pc=NULL;
 789         while(B_OK==o_Message.FindString(pc_Name,i++,&pc)){
 790                 ls_Result.AddItem(new BL_String(pc));
 791         }
 792 }
 793 //////////////////////////////////////////////////////////////

/* [previous][next][first][last][top][bottom][index][help] */