Subversion Repositories Kolibri OS

Rev

Rev 4394 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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