Subversion Repositories Kolibri OS

Rev

Rev 4394 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //INI parser in C--, GPL licence.
  2. //Leency - 2012
  3.  
  4. #define COMMENT 0
  5. #define SECTION 1
  6. #define PARAM   2
  7. #define OPTION  3
  8.  
  9.  
  10. void GetIni(byte onload)
  11. {
  12.         byte section[32], parametr[32], option[256], InfType=0;
  13.         char bukva[2];
  14.         int errornum, tj;
  15.         static dword buff, fsize;
  16.         if (onload==1)
  17.         {
  18.                 free(buff);
  19.                 if (!GetFile(#buff, #fsize, abspath("Eolite.ini"))) notify("Eolite.ini not found. Defaults will be used.");
  20.         }
  21.         for (tj=0; tj<fsize; tj++;)
  22.         {  
  23.                 bukva = ESBYTE[buff+tj];
  24.                 switch (bukva)
  25.                 {
  26.                         case ';': InfType=COMMENT; break;                              
  27.                         case '[': InfType=SECTION; section=NULL; break;
  28.                         case ']': InfType=PARAM; break;
  29.                         case '=': InfType=OPTION; break;
  30.                         case 0x0a:
  31.                         case 0x0d:
  32.                                 InfType=PARAM;
  33.                                 if (!strcmp(#parametr,"SelectionColor")) edit2.shift_color=col_selec=StrToCol(#option);
  34.                                 if (!strcmp(#parametr,"LineHeight")) files.line_h = atoi(#option);
  35.                                 if (!strcmp(#parametr,"ShowDeviceName")) show_dev_name=atoi(#option);
  36.                                 if (!strcmp(#parametr,"RealFileNamesCase")) real_files_names_case=atoi(#option);
  37.                                 if (!strcmp(#parametr,"DrwRamDiskSpace")) drw_ram_disk_space=atoi(#option);
  38.                                
  39.                                 if (parametr) && (!strcmpi(#file_name+strrchr(#file_name,'.'),#parametr)) && (!onload)
  40.                                 {
  41.                                         errornum = RunProgram(#option,#file_path);
  42.                                         if (errornum<0)
  43.                                         {
  44.                                                 if (errornum==-5) ShowOpenWithDialog(); else Write_Error(errornum);
  45.                                         }
  46.                                         return;
  47.                                 }
  48.                                 parametr=option=NULL;
  49.                                 break;
  50.                         default:
  51.                                 IF (InfType==SECTION) chrcat(#section, bukva);
  52.                                 IF (InfType==PARAM) chrcat(#parametr, bukva);
  53.                                 IF (InfType==OPTION) chrcat(#option, bukva);
  54.                 }
  55.         }
  56.         if (file_path) && (!onload)
  57.         {
  58.                 errornum = RunProgram(#file_path,NULL);
  59.                 if (errornum==-31) menu_action(201); else if (errornum<0) Write_Error(errornum);
  60.                 return;
  61.         }
  62. }
  63.  
  64.  
  65. void Write_Error(int error_number)
  66. {
  67.         if (files.current>=0) Line_ReDraw(0xFF0000, files.current);
  68.         pause(5);
  69.         notify(get_error(error_number));
  70. }
  71.  
  72.  
  73. dword StrToCol(char* htmlcolor)
  74. {
  75.   dword j, color=0;
  76.   char ch=0x00;
  77.  
  78.   FOR (j=0; j<6; j++)
  79.   {
  80.     ch=ESBYTE[htmlcolor+j];
  81.     IF ((ch>='0') && (ch<='9')) ch -= '0';
  82.     IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
  83.     IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
  84.     color = color*0x10 + ch;
  85.   }
  86.    return color;
  87. }