#if defined _dfile_included
#endinput
#endif
#define _dfile_included
#pragma library dfile
/**/
stock FixNumber[20];
/* Criar */
#define DFile_Create(%0) \
if(!fexist(%0)) fclose(fopen(%0,io_write))
/* Remover */
#define DFile_Remove(%0) \
if(fexist(%0)) fremove(%0)
/* Verificar Existencia */
#define DFile_Exists(%0) \
fexist(%0)
/* Getagem */
#define DFile_GetInt(%0,%1) \
strval(DFile_Get(%0, %1))
#define DFile_GetString(%0,%1) \
DFile_Get(%0, %1)
#define DFile_GetBool(%0,%1) \
DFile_Get(%0, %1)
#define DFile_GetFloat(%0,%1) \
floatstr(DFile_Get(%0, %1))
/* Setagem */
#define DFile_SetInt(%0,%1,%2) \
format(FixNumber, sizeof(FixNumber), "%d", %2), DFile_SetEx(%0, %1, FixNumber)
#define DFile_SetString(%0,%1,%2) \
DFile_SetEx(%0, %1, %2)
#define DFile_SetBool(%0,%1,%2) \
DFile_SetEx(%0, %1, %2 ? "true" : "false" )
#define DFile_SetFloat(%0,%1,%2) \
format(FixNumber, sizeof(FixNumber), "%f", %2), DFile_SetEx(%0, %1, FixNumber)
new _@strwritec[1000], _@strtoread[200], _@strtowrite[128];
stock DFile_SetEx(file[], tag[], value[])
{
static File:_@filetowrite, _@idx;
format(_@strtowrite, sizeof(_@strtowrite), "%s=%s\r\n", tag, value);
if(!fexist(file))
return
_@filetowrite = fopen(file, io_write),
fwrite(_@filetowrite, _@strtowrite),
fclose(_@filetowrite)
;
_@filetowrite = fopen(file, io_read);
while(fread(_@filetowrite, _@strtoread))
{
if(~(_@idx = strfind(_@strtoread, "=")))
{
_@strtoread[_@idx] = EOS;
if(strcmp(_@strtoread, tag))
{
_@strtoread[_@idx] = '=';
strcat(_@strwritec, _@strtoread);
}
}
}
fclose(_@filetowrite);
_@filetowrite = fopen(file, io_write);
strcat(_@strwritec, _@strtowrite);
fwrite(_@filetowrite, _@strwritec);
return fclose(_@filetowrite), _@strwritec[0] = EOS, _@strtoread[0] = EOS, _@strtowrite[0] = EOS;
}
stock DFile_Get(file[], tag[])
{
new _@read_s[128], _@idx;
if(!file[0]) return _@read_s;
if(!fexist(file)) return _@read_s;
if(!tag[0]) return _@read_s;
new File: _@arq = fopen(file, io_read);
while (fread(_@arq, _@read_s))
{
if(~(_@idx = strfind(_@read_s, "=", false)))
{
_@read_s[_@idx] = '\0';
if (strcmp(_@read_s, tag) == 0)
{
fclose(_@arq),
format(_@read_s, sizeof(_@read_s), "%s", _@read_s[++_@idx]);
return _@read_s;
}
}
}
return _@read_s;
}
Muito bom Dan, demorou um pouco mais saiu.
Continue assim esforзado, obrigado pelos crйditos, mas eu quase nem fiz nada. KK Abraзos ! ![]() |
stock DFile_Get(file[], tag[])
{
new _@read_s[128], _@idx;
if(!file[0]) return _@read_s;
if(!fexist(file)) return _@read_s;
if(!tag[0]) return _@read_s;
new File: _@arq = fopen(file, io_read);
while (fread(_@arq, _@read_s))
{
if(~(_@idx = strfind(_@read_s, "=", false)))
{
_@read_s[_@idx] = '\0';
if (strcmp(_@read_s, tag) == 0)
{
format(_@read_s, sizeof(_@read_s), "%s", _@read_s[++_@idx]);
fclose(_@arq);
return _@read_s;
}
}
}
return _@read_s;
}
Fiz uma pequena correзгo no seu do read, havia um erro ali na hora de ler as tags, ele sу lia a primeira tag...
Tambйm fiz algumas alteraзхes, se quiser considera-las, a vontade. Read: pawn Код:
|
Willian, caso aconteзa de a funзгo ser procurada para encontrar o valor de uma tag inexistente, nгo vai acontecer de ao invйs de retornar null, retornar uma parte da linha?
|
_@read_s[_@idx] = '\0';
toda vez que for ler uma linha vai voltar para null... se nгo achar ira retornar null. |
Vai igualar a EOS caso encontre o caractere =. Caso nгo, vai ficar como o conteъdo da linha. E caso encontre, se a tag nгo for igual, vai retornar o conteъdo contido antes do caractere. Nгo testei o cуdigo, й a impressгo que me dб ao olhar. Posso estar enganado.
|