Subversion Repositories Kolibri OS

Rev

Rev 3434 | 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.                                
  37.                                 IF (parametr) && (!strcmp(#file_name+strrchr(#file_name,'.'),#parametr)) && (!onload)
  38.                                 {
  39.                                         errornum=RunProgram(#option,#file_path);
  40.                                         IF (errornum<0) Write_Error(errornum);
  41.                                         return;
  42.                                 }
  43.                                 parametr=option=NULL;
  44.                                 break;
  45.                         default:
  46.                                 IF (InfType==SECTION) chrcat(#section, bukva);
  47.                                 IF (InfType==PARAM) chrcat(#parametr, bukva);
  48.                                 IF (InfType==OPTION) chrcat(#option, bukva);
  49.                 }
  50.         }
  51.         if (file_path) && (!onload)
  52.         {
  53.                 errornum=RunProgram(#file_path,NULL);
  54.                 if (errornum==-31) menu_action(201); else if (errornum<0) Write_Error(errornum);
  55.                 return;
  56.         }
  57. }
  58.  
  59.  
  60. void Write_Error(int error_number)
  61. {
  62.         if (files.current>=0) Line_ReDraw(0xFF0000, files.current);
  63.         pause(5);
  64.         notify(get_error(error_number));
  65. }
  66.  
  67.  
  68. dword StrToCol(char* htmlcolor)
  69. {
  70.   dword j, color=0;
  71.   char ch=0x00;
  72.  
  73.   FOR (j=0; j<6; j++)
  74.   {
  75.     ch=ESBYTE[htmlcolor+j];
  76.     IF ((ch>='0') && (ch<='9')) ch -= '0';
  77.     IF ((ch>='A') && (ch<='F')) ch -= 'A'-10;
  78.     IF ((ch>='a') && (ch<='f')) ch -= 'a'-10;
  79.     color = color*0x10 + ch;
  80.   }
  81.    return color;
  82. }