Subversion Repositories Kolibri OS

Rev

Rev 3434 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3363 leency 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);
3432 leency 19
		if (!GetFile(#buff, #fsize, abspath("Eolite.ini"))) notify("Eolite.ini not found. Defaults will be used.");
3363 leency 20
	}
21
	for (tj=0; tj
22
	{
23
		bukva = ESBYTE[buff+tj];
24
		switch (bukva)
25
		{
4049 leency 26
			case ';': InfType=COMMENT; break;
27
			case '[': InfType=SECTION; section=NULL; break;
28
			case ']': InfType=PARAM; break;
29
			case '=': InfType=OPTION; break;
3363 leency 30
			case 0x0a:
31
			case 0x0d:
32
				InfType=PARAM;
33
				IF (!strcmp(#parametr,"SelectionColor")) edit2.shift_color=col_selec=StrToCol(#option);
3434 leency 34
				IF (!strcmp(#parametr,"LineHeight")) files.line_h = atoi(#option);
3363 leency 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);
4049 leency 40
					IF (errornum<0) Write_Error(errornum);
3363 leency 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);
4049 leency 54
		if (errornum==-31) menu_action(201); else if (errornum<0) Write_Error(errornum);
55
		return;
3363 leency 56
	}
57
}
58
 
59
 
60
void Write_Error(int error_number)
61
{
3434 leency 62
	if (files.current>=0) Line_ReDraw(0xFF0000, files.current);
3363 leency 63
	pause(5);
3434 leency 64
	notify(get_error(error_number));
3363 leency 65
}
66
 
67
 
68
dword StrToCol(char* htmlcolor)
69
{
3433 leency 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;
3363 leency 82
}