Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma tabsize 0
- #define MAX_KEY 50
- #define MAX_LINE 100
- #define MAX_VALUE 128
- #define MAX_FILE_NAME 55
- new File:qFile,
- qFileName[MAX_FILE_NAME],
- qKey[MAX_LINE][MAX_KEY],
- qValue[MAX_LINE][MAX_VALUE],
- qLines;
- forward Float:qini_FloatGet(key[]);
- stock qini_Create(file[])
- {
- if(fexist(file)) return false;
- new File:cFile = fopen(file,io_write);
- return fclose(cFile);
- }
- stock qini_Remove(file[]){
- if(!fexist(file)) return false;
- fremove(file);
- for(new i;i < qLines;i++){
- qKey[i][0] = 0;
- qValue[i][0] = 0;
- }
- qLines = 0;
- return true;
- }
- stock qini_Int(key[],value){
- new str[120];
- format(str,120,"%d",value);
- qini_Set(key,str);
- return true;
- }
- stock qini_IntGet(key[]) return strval(qini_Get(key));
- stock qini_Float(key[],Float:value){
- new str[120];
- format(str,120,"%f",value);
- qini_Set(key,str);
- return true;
- }
- Float:qini_FloatGet(key[]){
- return floatstr(qini_Get(key));
- }
- stock qini_Bool(key[],value){
- new str[120];
- format(str,120,"%d",value);
- qini_Set(key,str);
- }
- stock bool:qini_BoolGet(key[]){
- return bool:strval(qini_Get(key));
- }
- stock qini_Open(file[]){
- new qstr[180];
- qFile = fopen(file,io_read);
- format(qFileName,MAX_FILE_NAME,file);
- new qline = -1;
- new end;
- while(fread(qFile,qstr)){
- qline++;
- DelChar(qstr);
- end = chrfind('=',qstr);
- strmid(qKey[qline],qstr,0,end);
- strmid(qValue[qline],qstr,end+1,strlen(qstr));
- qLines++;
- }
- // printf("Pocet riadkov %d",qLines);
- return fclose(qFile);
- }
- stock qini_Set(key[],value[]){
- new qline = -1;
- new bool:findet = false;
- while((qline < qLines) && (qline < MAX_LINE)){
- qline++;
- if(!qKey[qline][0]) continue;
- if(strcmp(key,qKey[qline],false) == 0){
- format(qValue[qline],MAX_VALUE,value);
- // printf("%s | %s | %s | %d | %d",qValue[qline],key,qKey[qline],qline,qLines);
- findet = true;
- break;
- }
- }
- if(!findet){
- qLines++;
- format(qKey[qLines],MAX_KEY,key);
- format(qValue[qLines],MAX_VALUE,value);
- // printf("!!!!!!!!!!!!!!!!!!!!!!!!!%s=%s!!!!!!!!!!!!!!!!!!!!!!!!!!",qKey[qLines],qValue[qLines]);
- }
- }
- stock qini_Get(key[]){
- new qline = -1;
- while((qline < qLines) && (qline < MAX_LINE)){
- qline++;
- if(!strcmp(key,qKey[qline],false)){
- return qValue[qline];
- }
- }
- return qValue[0];
- }
- stock qini_Close(){
- new qline = -1;
- new qstr[180];
- qFile = fopen(qFileName,io_write);
- while((qline < qLines) && (qline < MAX_LINE)){
- qline++;
- if(!strlen(qKey[qline]) || !strlen(qValue[qline])) continue;
- format(qstr,180,"%s=%s\r\n",qKey[qline],qValue[qline]);
- fwrite(qFile, qstr);
- }
- for(new i;i < qLines;i++){
- qKey[i][0] = 0;
- qValue[i][0] = 0;
- }
- qLines = 0;
- fclose(qFile);
- }
- stock DelChar(tstring[])
- {
- new ln = strlen(tstring);
- if(tstring[ln-2] == '\r')tstring[ln-2] = '\0';
- if(tstring[ln-1] == '\n')tstring[ln-1] = '\0';
- }
- stock hash(str2[]) { // by DracoBlue
- new tmpdasdsa[249];
- tmpdasdsa[0]=0;
- valstr(tmpdasdsa,num_hash(str2));
- return tmpdasdsa;
- }
- stock num_hash(buf[]) // by DracoBlue
- {
- new length=strlen(buf);
- new s1 = 1;
- new s2 = 0;
- new n;
- for (n=0; n<length; n++) {
- s1 = (s1 + buf[n]) % 65521;
- s2 = (s2 + s1) % 65521;
- }
- return (s2 << 16) + s1;
- }
- chrfind(n,h[],s=0) {
- new l=strlen(h);
- while(s<l)
- {
- if(h[s]==n)
- return s;s++;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement