/* * * --- w!ini --- * Por Willian Luigi * * * - Functions: * * i_create (filename[]) - Cria um arquivo. * i_open (filename[], t) - Abre um arquivo para leitura(t = 0), ou escrita(t = 1). * i_read (tag[], str[]) - Lê o valor de uma tag e inseri na str. * i_readBool (tag[]) - Lê o valor de uma tag e retorna o bool. * i_readFloat (tag[]) - Lê o valor de uma tag e retorna o float. * i_readInt (tag[]) - Lê o valor de uma tag e retorna o int. * i_write (tag[], val[]) - Escreve uma tag e um valor string. * i_writeFloat(tag[], val[]) - Escreve uma tag e um valor float. * i_writeInt (tag[], val[]) - Escreve uma tag e um valor int. * i_writeBool (tag[], val[]) - Escreve uma tag e um valor bool. * i_save () - Salva e fecha o arquivo aberto. * */ #if defined _wini_included #endinput #endif #define _wini_included #pragma library wini #define i_exist(%0) fexist(%0) #define INI stock #define read (0) #define write (1) #define i_writeFloat(%0,%1) \ i_write(%0,#%1) #define i_writeInt(%0,%1) \ i_write(%0,#%1) #define i_writeBool(%0,%1) \ i_write(%0,%1?("true"):("false")) #define i_readFloat(%0) \ floatstr(_utils_r(%0)) #define i_readInt(%0) \ strval(_utils_r(%0)) #define i_readBool(%0) \ bool:(!strcmp(_utils_r(%0), "true")) INI __PWOKFDAOCNODDIQIOEOHVPWURV[5000]; INI File:_@file_name; INI i_create (file[]) { if (!i_exist(file)) { fclose(fopen(file, io_write)); } } INI i_open (file[], writting = 0) { if (i_exist(file)) { if (_@file_name) fclose(_@file_name); _@file_name = fopen(file, io_read); if (_@file_name) { new _@tmp[128]; __PWOKFDAOCNODDIQIOEOHVPWURV[0] = '\0'; while (fread(_@file_name, _@tmp)) { strcat(__PWOKFDAOCNODDIQIOEOHVPWURV, _@tmp); } fclose(_@file_name); if (writting) _@file_name = fopen(file, io_write); } } } INI i_save () { if (_@file_name) { fwrite(_@file_name, __PWOKFDAOCNODDIQIOEOHVPWURV); fclose(_@file_name); } } INI i_write (tag[], val[]) { if (_@file_name) { if (!__PWOKFDAOCNODDIQIOEOHVPWURV[0]) { format(__PWOKFDAOCNODDIQIOEOHVPWURV, sizeof(__PWOKFDAOCNODDIQIOEOHVPWURV), "%s=%s\r\n", tag, val); } else { new _@i = strfind(__PWOKFDAOCNODDIQIOEOHVPWURV, tag); if (_@i != -1) { strdel(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], 1 + strlen(tag), strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n")); strins(__PWOKFDAOCNODDIQIOEOHVPWURV, val, _@i + 1 + strlen(tag)); } else { format(__PWOKFDAOCNODDIQIOEOHVPWURV, sizeof(__PWOKFDAOCNODDIQIOEOHVPWURV), "%s%s=%s\r\n", __PWOKFDAOCNODDIQIOEOHVPWURV, tag, val); } } } } INI i_read (tag[], str[]) { if (_@file_name) { new _@i = strfind(__PWOKFDAOCNODDIQIOEOHVPWURV, tag); if (_@i != -1) { new _@len = strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n"); //strmid((str[0] = '\0', str), __PWOKFDAOCNODDIQIOEOHVPWURV[_@i], 1 + strlen(tag), strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n"), strfind(__PWOKFDAOCNODDIQIOEOHVPWURV[_@i], "\r\n") - 1 + strlen(tag)); strmid((str[0] = '\0', str), __PWOKFDAOCNODDIQIOEOHVPWURV[_@i], 1 + strlen(tag), _@len, _@len - 1 + strlen(tag)); } } } INI _utils_r(tag[]) { new _@task[20]; i_read(tag, _@task); return _@task; }