Subversion Repositories Kolibri OS

Rev

Rev 4394 | 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;
4409 leency 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);
3363 leency 38
 
4409 leency 39
				if (parametr) && (!strcmpi(#file_name+strrchr(#file_name,'.'),#parametr)) && (!onload)
3363 leency 40
				{
4225 punk_joker 41
					errornum = RunProgram(#option,#file_path);
42
					if (errornum<0)
43
					{
44
						if (errornum==-5) ShowOpenWithDialog(); else Write_Error(errornum);
45
					}
3363 leency 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
	{
4225 punk_joker 58
		errornum = RunProgram(#file_path,NULL);
4049 leency 59
		if (errornum==-31) menu_action(201); else if (errornum<0) Write_Error(errornum);
60
		return;
3363 leency 61
	}
62
}
63
 
64
 
65
void Write_Error(int error_number)
66
{
3434 leency 67
	if (files.current>=0) Line_ReDraw(0xFF0000, files.current);
3363 leency 68
	pause(5);
3434 leency 69
	notify(get_error(error_number));
3363 leency 70
}
71
 
72
 
73
dword StrToCol(char* htmlcolor)
74
{
3433 leency 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;
3363 leency 87
}