Subversion Repositories Kolibri OS

Rev

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