Advertisement
Guest User

Fini V4

a guest
Apr 14th, 2011
1,805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.88 KB | None | 0 0
  1. /*////////////////////////////////////////////////////////////////////////////////
  2.  
  3.                      _ ____        _____          __  __
  4.                     (_)  _ \ ___  |_   _|__  __ _|  \/  |
  5.                     | | |_) / __|   | |/ _ \/ _` | |\/| |
  6.                     | |  __/\__ \   | |  __/ (_| | |  | |
  7.                     |_|_|   |___/   |_|\___|\__,_|_|  |_|
  8.  
  9.                         Intelligent Programming Style ®
  10.                        
  11.                          ____________________________
  12.                           [url]www.ips-team.blogspot.com[/url]
  13.                          [url]www.ips-team.forumeiros.com[/url]
  14.                          ____________________________
  15.                          
  16.                          Created By DraKiNs & SlashPT
  17.                          Thanks to [iPs]TeaM and Jhony
  18.  
  19. */////////////////////////////////////////////////////////////////////////////////
  20.  
  21.  
  22. //========= [ Configs of Read/Write Files ] ====================================
  23.  
  24. #define MaxLines    (999)
  25. #define MaxKeys     (064)
  26.  
  27. #define Fini_GetBool(%0)    (bool:strval(Fini_GetStr(%0)))
  28. #define Fini_GetValue(%0)   (strval(Fini_GetStr(%0)))
  29. #define Fini_Exists(%0)     (fexist(%0))
  30. #define Fini_GetFloat(%0)   floatstr(Fini_GetStr(%0))
  31. #define Fini_Remove(%0)     (fremove(%0))
  32.  
  33. //========= [ Variables of Set/Get Ini ] ========================================
  34.  
  35. new
  36.     sCacheKeys[MaxLines][MaxKeys],
  37.     sCacheValue[MaxLines][MaxKeys],
  38.     iLoop           = 0x0,
  39.     iFind           = 0x0,
  40.     iKeySet         = 0x0,
  41.     File:iFile      = File:0,
  42.     sTemp[MaxKeys]  = " ";
  43.    
  44.  
  45. //============ [ Functions ] ================================================
  46.  
  47. //Get ~ Read Functions
  48. stock Fini_GetStr(sKey[])
  49. {
  50.     iLoop = 0x0;
  51.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines))
  52.     {
  53.         if(!strcmp(sCacheKeys[iLoop],sKey,false))
  54.             return sCacheValue[iLoop];
  55.         ++iLoop;
  56.     }
  57.     return sCacheKeys[0];
  58. }
  59.  
  60. //Others Funcions
  61. stock   Fini_Create(sFile[])
  62. {
  63.     if(Fini_Exists(sFile)) return false;
  64.     iFile = fopen(sFile,io_write);
  65.     return fclose(iFile);
  66. }
  67.  
  68. stock Fini_OpenFile(sFile[])
  69. {
  70.     iFile = fopen(sFile,io_read),
  71.     iFind   = 0x0;
  72.     iLoop = 0x0;
  73.    
  74.     while(fread(iFile,sTemp))
  75.     {      
  76.         iFind   = strfind(sTemp,"=");
  77.         format(sCacheValue[iLoop],MaxKeys,sTemp[iFind + 1]);
  78.         sTemp[iFind] = EOS;
  79.         format(sCacheKeys[iLoop],MaxKeys,sTemp);
  80.         ++iLoop;
  81.     }
  82.     return fclose(iFile);
  83. }
  84.  
  85. stock Fini_SaveFile(sFile[])
  86. {
  87.     iFile = fopen(sFile,io_write),
  88.     sTemp[0] = EOS;
  89.  
  90.     iLoop = 0x0;
  91.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines))
  92.     {
  93.         format(sTemp,MaxKeys,"%s=%s\r\n",sCacheKeys[iLoop],sCacheValue[iLoop]);
  94.         fwrite(iFile,sTemp);
  95.         ++iLoop;
  96.     }
  97.     return fclose(iFile);
  98. }
  99.  
  100. stock Fini_CloseFile()
  101. {
  102.     sCacheKeys[0][0]    =   EOS;
  103.     sCacheValue[0][0]   =   EOS;
  104.     iLoop               =   0x0;
  105.     iFind               =   0x0;
  106.     iKeySet             =   0x0;
  107.     sTemp[0]            =   EOS;
  108.     return true;
  109. }
  110.  
  111. stock Fini_IsSet(sTag[])
  112. {
  113.     iLoop = 0x0;
  114.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines))
  115.     {
  116.         if(!strcmp(sCacheKeys[iLoop],sTag,false))
  117.         {
  118.             return true;
  119.         }
  120.         iLoop++;
  121.     }
  122.     return false;
  123. }
  124.  
  125. //Set ~ Write Functions
  126.  
  127. stock Fini_SetStr(sKey[],sValue[])
  128. {
  129.     iLoop = 0x0;
  130.     while((sCacheKeys[iLoop][0x0]) && (iLoop < MaxLines))
  131.     {
  132.         if(!strcmp(sCacheKeys[iLoop],sKey,false))
  133.         {
  134.             sCacheValue[iLoop][0] = EOS;
  135.             strcat(sCacheValue[iLoop],sValue);
  136.             iKeySet = 1;
  137.         }
  138.         ++iLoop;
  139.     }
  140.     if(!iKeySet)
  141.     {
  142.         while(sCacheKeys[iLoop][0]) iLoop++;
  143.         strcat(sCacheValue[iLoop],sValue);
  144.         strcat(sCacheKeys[iLoop],sKey);
  145.     }
  146.     return EOS;
  147. }
  148.  
  149. stock Fini_SetFloat(sTag[],Float:iVal)
  150. {
  151.     format(sTemp,MaxKeys,"%f",iVal);
  152.     return Fini_SetStr(sTag,sTemp);
  153. }
  154.  
  155. stock Fini_SetVal(sTag[],iVal)
  156. {
  157.     format(sTemp,MaxKeys,"%d",iVal);
  158.     return Fini_SetStr(sTag,sTemp);
  159. }
  160.  
  161. stock Fini_SetBool(sTag[],bool:iVal)
  162. {
  163.     format(sTemp,MaxKeys,"%d",iVal);
  164.     return Fini_SetStr(sTag,sTemp);
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement