// Include bCini6
#define bCini6_Open fopen
#define bCini6_Exists fexist
#define bCini6_Write fwrite
#define bCini6_Read fread
#define bCini6_Close fclose
#define bCini6_Create(%0) if(!bCini6_Exists(%0)) bCini6_Close(bCini6_Open(%0,io_write)) && bCini6_OpenArchive(%0)
#define bCini6_Delete(%0) if(bCini6_Exists(%0)) fremove(%0)
// Include definitions
#define bCini6_Lines 100
#define bCini6_Capacity 64
#define bCini6_Separator "="
#define bCini6_Console_Fail "O arquivo nгo existe! "
#define bCini6_Console_Up "Console do arquivo "
// Variables
stock bCini6_Archive_Line_Value[bCini6_Lines][bCini6_Capacity];
stock bCini6_Archive_Value[bCini6_Lines][bCini6_Capacity];
stock bCini6_Archive_Name[bCini6_Capacity];
stock bCini6_Archive_Lines;
stock bCini6_Archive_Line_ID;
stock bool:bCini6_Archive_Has_Been_Used;
// Functions
stock Include_bCini6[bCini6_Capacity];
#define bCini6_SetInt(%0,%1,%2) format(Include_bCini6,sizeof(Include_bCini6),"%d",%2) && bCini6_SetText(%0,%1,Include_bCini6)
#define bCini6_SetBool(%0,%1,%2) format(Include_bCini6,sizeof(Include_bCini6),"%d",%2) && bCini6_SetText(%0,%1,Include_bCini6)
#define bCini6_SetFloat(%0,%1,%2) format(Include_bCini6,sizeof(Include_bCini6),"%f",%2) && bCini6_SetText(%0,%1,Include_bCini6)
#define bCini6_CleanArchive(%0) if(bCini6_Exists(%0)) bCini6_OpenArchive(%0); for(new i; i < bCini6_Archive_Lines; ++i) bCini6_DeleteSet(%0,bCini6_Archive_Line_Value[i])
#define bCini6_Log(%0,%1) new File:bCini6_Archive = bCini6_Open(%0,io_append); bCini6_Write(bCini6_Archive,%1) && bCini6_Close(bCini6_Archive)
stock bCini6_SetText(archive[],line[],value[])
{
if(bCini6_Archive_Lines == bCini6_Lines)
{
return 1;
}
if(!bCini6_Exists(archive))
{
bCini6_Create(archive);
}
if(!line[0])
{
strcat(line,"(null)",7);
}
if(!value[0])
{
strcat(value,"(null)",7);
}
bCini6_OpenArchive(archive);
new bCini6_1,bCini6_2,bCini6_Archive[bCini6_Capacity];
format(bCini6_Archive,sizeof(bCini6_Archive),"%s%s%s\r\n",line,bCini6_Separator,value);
bCini6_1 = strlen(bCini6_Archive);
bCini6_2 = strlen(value);
if(!bCini6_IsSet(archive,line))
{
strmid(bCini6_Archive_Line_Value[bCini6_Archive_Lines],bCini6_Archive,0,bCini6_1,bCini6_1+1);
strmid(bCini6_Archive_Value[bCini6_Archive_Lines],value,0,bCini6_2,bCini6_2+1);
++bCini6_Archive_Lines;
}
else
{
strmid(bCini6_Archive_Line_Value[bCini6_Archive_Line_ID],bCini6_Archive,0,bCini6_1,bCini6_1+1);
strmid(bCini6_Archive_Value[bCini6_Archive_Line_ID],value,0,bCini6_2,bCini6_2+1);
}
bCini6_Archive_Has_Been_Used = true;
return 1;
}
stock bCini6_ReadText(archive[],line[])
{
if(!bCini6_Exists(archive) || !bCini6_IsSet(archive,line) || !line[0])
{
return bCini6_Archive_Value[bCini6_Archive_Lines];
}
return bCini6_Archive_Value[bCini6_Archive_Line_ID];
}
stock bCini6_ReadInt(archive[],line[])
{
if(!bCini6_Exists(archive) || !bCini6_IsSet(archive,line) || !line[0])
{
return strval(bCini6_Archive_Value[bCini6_Archive_Lines]);
}
return strval(bCini6_Archive_Value[bCini6_Archive_Line_ID]);
}
#define bCini6_ReadFloat(%0,%1) floatstr(bCini6_ReadText(%0,%1))
stock bCini6_ReadBool(archive[],line[])
{
if(!bCini6_Exists(archive) || !bCini6_IsSet(archive,line) || !line[0])
{
return bool:strval(bCini6_Archive_Value[bCini6_Archive_Lines]);
}
return bool:strval(bCini6_Archive_Value[bCini6_Archive_Line_ID]);
}
stock bCini6_IsSet(archive[],line[])
{
if(!bCini6_Exists(archive) || !line[0])
{
return 0;
}
new bCini6_Line_Set[bCini6_Capacity];
bCini6_OpenArchive(archive);
bCini6_Archive_Line_ID = bCini6_Archive_Lines;
for(new i; i < bCini6_Archive_Lines; ++i)
{
if(bCini6_Archive_Line_Value[i][0])
{
strmid(bCini6_Line_Set,bCini6_Archive_Line_Value[i],0,strfind(bCini6_Archive_Line_Value[i],bCini6_Separator),bCini6_Capacity);
if(strcmp(bCini6_Line_Set,line,true) == 0)
{
bCini6_Archive_Line_ID = i;
return 1;
}
}
}
return 0;
}
stock bCini6_DeleteSet(archive[],line[])
{
if(!bCini6_Exists(archive) || !bCini6_IsSet(archive,line))
{
return 1;
}
bCini6_Archive_Line_Value[bCini6_Archive_Line_ID][0] = 0;
bCini6_Archive_Value[bCini6_Archive_Line_ID][0] = 0;
bCini6_Archive_Has_Been_Used = true;
return 1;
}
stock bCini6_Console(archive[])
{
if(!bCini6_Exists(archive))
{
printf("%s(%s)",bCini6_Console_Fail,archive);
return 1;
}
bCini6_OpenArchive(archive);
printf("%s%s:\r\n",bCini6_Console_Up,archive);
for(new i; i < bCini6_Archive_Lines; ++i)
{
if(bCini6_Archive_Line_Value[i][0])
{
print(bCini6_Archive_Line_Value[i]);
}
}
return 1;
}
stock bCini6_Copy(archive[],archive2[],bool:delete_archive)
{
if(!bCini6_Exists(archive))
{
return 1;
}
bCini6_OpenArchive(archive);
new File:bCini6_Archive_Used = bCini6_Open(archive2,io_write);
for(new i; i < bCini6_Archive_Lines; ++i)
{
if(bCini6_Archive_Line_Value[i][0])
{
bCini6_Write(bCini6_Archive_Used,bCini6_Archive_Line_Value[i]);
bCini6_Archive_Line_Value[i][0] = 0;
bCini6_Archive_Value[i][0] = 0;
}
}
bCini6_Close(bCini6_Archive_Used);
if(delete_archive)
{
bCini6_Delete(archive);
}
return 1;
}
// Open & Close
stock bCini6_OpenArchive(archive[])
{
if(!bCini6_Exists(archive) || bCini6_Archive_Name[0] && strcmp(bCini6_Archive_Name[0],archive,true) == 0)
{
return 1;
}
bCini6_CloseArchive();
new bCini6_1,i,bCini6_Archive[bCini6_Capacity],File:bCini6_Archive_Used = bCini6_Open(archive,io_read);
bCini6_1 = strlen(archive);
strmid(bCini6_Archive_Name,archive,0,bCini6_1,bCini6_1+1);
bCini6_Archive_Lines = 1;
while(bCini6_Read(bCini6_Archive_Used,bCini6_Archive))
{
if(bCini6_Archive[0])
{
if(bCini6_Archive[0] >= 256)
{
strdel(bCini6_Archive,0,1);
}
i = strlen(bCini6_Archive);
strmid(bCini6_Archive_Line_Value[bCini6_Archive_Lines],bCini6_Archive,0,i,i+1);
if(bCini6_Archive[i-1] == '\r' || bCini6_Archive[i-1] == '\n')
{
bCini6_Archive[i-1] = 0;
}
if(bCini6_Archive[i-2] == '\r' || bCini6_Archive[i-2] == '\n')
{
bCini6_Archive[i-2] = 0;
}
i = strlen(bCini6_Archive);
strmid(bCini6_Archive_Value[bCini6_Archive_Lines],bCini6_Archive,strfind(bCini6_Archive,bCini6_Separator)+1,i,i+1);
++bCini6_Archive_Lines;
}
}
bCini6_Close(bCini6_Archive_Used);
return 1;
}
stock bCini6_CloseArchive()
{
if(!bCini6_Exists(bCini6_Archive_Name) || !bCini6_Archive_Has_Been_Used)
{
if(bCini6_Archive_Has_Been_Used)
{
for(new i; i < bCini6_Archive_Lines; ++i)
{
if(bCini6_Archive_Line_Value[i][0])
{
bCini6_Archive_Line_Value[i][0] = 0;
bCini6_Archive_Value[i][0] = 0;
}
}
bCini6_Archive_Has_Been_Used = false;
}
bCini6_Archive_Name[0] = 0;
bCini6_Archive_Lines = 0;
return 1;
}
if(bCini6_Archive_Has_Been_Used)
{
new File:bCini6_Archive_Used = bCini6_Open(bCini6_Archive_Name,io_write);
for(new i; i < bCini6_Archive_Lines; ++i)
{
if(bCini6_Archive_Line_Value[i][0])
{
bCini6_Write(bCini6_Archive_Used,bCini6_Archive_Line_Value[i]);
bCini6_Archive_Line_Value[i][0] = 0;
bCini6_Archive_Value[i][0] = 0;
}
}
bCini6_Close(bCini6_Archive_Used);
bCini6_Archive_Has_Been_Used = false;
}
bCini6_Archive_Name[0] = 0;
bCini6_Archive_Lines = 0;
return 1;
}
// End of the include
This forum requires that you wait 120 seconds between posts. Please try again in 28 seconds.
Obrigado pelos crйditos Biel, pretendo olhar direitinho a sua include mais tarde...
|