whiplk

[INCLUDE] - w!ini(beta)

Nov 3rd, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.42 KB | None | 0 0
  1. /*
  2. *
  3. * --- w!ini ---
  4. * Por Willian Luigi
  5. *
  6. *
  7. *   - Functions:
  8. *
  9. *       i_create    (filename[])    - Cria um arquivo.
  10. *       i_open      (filename[], t) - Abre um arquivo para leitura(t = 0), ou escrita(t = 1).
  11. *       i_read      (tag[], str[])  - Lê o valor de uma tag e inseri na str.
  12. *       i_readBool  (tag[])         - Lê o valor de uma tag e retorna o bool.
  13. *       i_readFloat (tag[])         - Lê o valor de uma tag e retorna o float.
  14. *       i_readInt   (tag[])         - Lê o valor de uma tag e retorna o int.
  15. *       i_write     (tag[], val[])  - Escreve uma tag e um valor string.
  16. *       i_writeFloat(tag[], val[])  - Escreve uma tag e um valor float.
  17. *       i_writeInt  (tag[], val[])  - Escreve uma tag e um valor int.
  18. *       i_writeBool (tag[], val[])  - Escreve uma tag e um valor bool.
  19. *       i_save      ()              - Salva e fecha o arquivo aberto.
  20. *
  21. */
  22. #if defined _wini_included
  23. #endinput
  24. #endif
  25. #define _wini_included
  26. #pragma library wini
  27.  
  28. #define i_exist(%0)     fexist(%0)
  29. #define INI             stock
  30. #define read            (0)
  31. #define write           (1)
  32.  
  33. #define i_writeFloat(%0,%1) \
  34.         i_write(%0,#%1)
  35. #define i_writeInt(%0,%1) \
  36.         i_write(%0,#%1)
  37. #define i_writeBool(%0,%1) \
  38.         i_write(%0,%1?("true"):("false"))
  39. #define i_readFloat(%0) \
  40.         floatstr(_utils_r(%0))
  41. #define i_readInt(%0) \
  42.         strval(_utils_r(%0))
  43. #define i_readBool(%0) \
  44.         bool:(!strcmp(_utils_r(%0), "true"))
  45.  
  46. INI __PWOKFDAOCNODDIQIOEOHVPWURV[5000];
  47. INI File:_@file_name;
  48.  
  49. INI i_create (file[])
  50. {
  51.     if (!i_exist(file))
  52.     {
  53.         fclose(fopen(file, io_write));
  54.     }
  55. }
  56. INI i_open (file[], writting = 0)
  57. {
  58.     if (i_exist(file))
  59.     {
  60.         if (_@file_name)
  61.             fclose(_@file_name);
  62.  
  63.         _@file_name = fopen(file, io_read);
  64.  
  65.         if (_@file_name)
  66.         {
  67.             new _@tmp[128];
  68.             __PWOKFDAOCNODDIQIOEOHVPWURV[0] = '\0';
  69.  
  70.             while (fread(_@file_name, _@tmp))
  71.             {
  72.                 strcat(__PWOKFDAOCNODDIQIOEOHVPWURV, _@tmp);
  73.             }
  74.             fclose(_@file_name);
  75.  
  76.             if (writting)
  77.                 _@file_name = fopen(file, io_write);
  78.         }
  79.     }
  80. }
  81. INI i_save ()
  82. {
  83.     if (_@file_name)
  84.     {
  85.         fwrite(_@file_name, __PWOKFDAOCNODDIQIOEOHVPWURV);
  86.  
  87.         fclose(_@file_name);
  88.     }
  89. }
  90. INI i_write (tag[], val[])
  91. {
  92.     if (_@file_name)
  93.     {
  94.         if (!__PWOKFDAOCNODDIQIOEOHVPWURV[0])
  95.         {
  96.             format(__PWOKFDAOCNODDIQIOEOHVPWURV, sizeof(__PWOKFDAOCNODDIQIOEOHVPWURV), "%s=%s\r\n", tag, val);
  97.         }
  98.         else
  99.         {
  100.             new _@i = strfind(__PWOKFDAOCNODDIQIOEOHVPWURV, tag);
  101.  
  102.             if (_@i != -1)
  103.             {
  104.                 strdel(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], 1 + strlen(tag), strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n"));
  105.                 strins(__PWOKFDAOCNODDIQIOEOHVPWURV, val, _@i + 1 + strlen(tag));
  106.             }
  107.             else
  108.             {
  109.                 format(__PWOKFDAOCNODDIQIOEOHVPWURV, sizeof(__PWOKFDAOCNODDIQIOEOHVPWURV), "%s%s=%s\r\n", __PWOKFDAOCNODDIQIOEOHVPWURV, tag, val);
  110.             }
  111.         }
  112.     }
  113. }
  114. INI i_read (tag[], str[])
  115. {
  116.     if (_@file_name)
  117.     {
  118.         new _@i = strfind(__PWOKFDAOCNODDIQIOEOHVPWURV, tag);
  119.  
  120.         if (_@i != -1)
  121.         {
  122.             new _@len = strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n");
  123.             //strmid((str[0] = '\0', str), __PWOKFDAOCNODDIQIOEOHVPWURV[_@i], 1 + strlen(tag), strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n"), strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n") - 1 + strlen(tag));
  124.             strmid((str[0] = '\0', str), __PWOKFDAOCNODDIQIOEOHVPWURV[_@i], 1 + strlen(tag), _@len, _@len - 1 + strlen(tag));
  125.         }
  126.     }
  127. }
  128. INI _utils_r(tag[])
  129. {
  130.     new _@task[20];
  131.     i_read(tag, _@task);
  132.    
  133.     return _@task;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment