Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2568 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
 
2820 leency 9
unsigned char *ERROR_TEXT[]={
10
"Code #0 - No error",
11
"Error #1 - Base or partition of a hard disk is not defined",
12
"Error #2 - Function isn't supported for this file system",
13
"Error #3 - Unknown file system",
14
"Error #4 - Reserved, is never returned",
15
"Error #5 - File or folder not found",
16
"Error #6 - End of file, EOF",
17
"Error #7 - Pointer lies outside of application memory",
18
"Error #8 - FAT table is destroyed",
19
"Error #9 - FAT table is destroyed",
20
"Error #10 - Access denied",
21
"Error #11 - Device error",
22
"", "", "", "", "", "", "", "", "",
23
"", "", "", "", "", "", "", "", "",
24
"Error #30 - Not enough memory",
25
"Error #31 - File is not executable",
26
"Error #32 - Too many processes",
27
0};
28
 
2568 leency 29
void GetIni(byte onload)
30
{
31
	byte section[32]='', parametr[32]='', option[256]='', InfType=0;
32
	word bukva[1];
33
	int errornum;
34
	dword buff, fsize, tj;
35
	//читаем файл
2904 leency 36
	free(buff);
37
	buff = malloc(12000);
2814 leency 38
	IF (onload==1) copystr(".ini", #program_path+strlen(#program_path));
2904 leency 39
	ReadFile(0, 12000, buff, #program_path);
2568 leency 40
	IF (EAX<>6) //если файла с настройками нет в папке с программой смотрим в папке по-умолчанию
2904 leency 41
		ReadFile(0, 12000, buff, "/sys/File managers/Eolite.ini");
2568 leency 42
	IF (EAX<>6) //если файла с настройками тупо нет печалька
43
	{
3045 leency 44
		IF (onload==1) notify("Eolite.ini not found. Defaults will be used.");
2568 leency 45
		IF (onload==0) goto RUN_AS_PROGRAM;
46
	}
47
	fsize=EBX;
48
	//парсим его
49
	for (tj=0; tj
50
	{
51
		bukva = ESBYTE[buff+tj];
52
		switch (bukva)
53
		{
54
			case ';':
55
				InfType=COMMENT;
56
				break;
57
			case '[':
58
				InfType=SECTION;
59
				section='';
60
				break;
61
			case ']':
62
				InfType=PARAM;
63
				break;
64
			case '=':
65
				InfType=OPTION;
66
				break;
67
			case 0x0a:
68
			case 0x0d:
69
				InfType=PARAM;
2833 leency 70
				IF (!strcmp(#parametr,"SelectionColor")) selection_col=StrToCol(#option);
2662 leency 71
				IF (!strcmp(#parametr,"LineHeight")) BUTTON_HEIGHT=StrToInt(#option);
72
				IF (!strcmp(#parametr,"ShowDeviceName")) show_dev_name=StrToInt(#option);
2568 leency 73
 
2662 leency 74
				/*if (!strcmp(#section,"UserDirectories")) && (parametr) && (onload)
75
				{
76
					copystr(#parametr, #disk_list[disc_num].Item);
77
					disc_num++;
78
				}*/
79
 
2875 leency 80
				IF (parametr) && (!strcmp(#file_name+strchr(#file_name,'.'),#parametr)) {
2568 leency 81
					errornum=RunProgram(#option,#file_path);
82
					IF (errornum<0) //если ошибочка вышла при запуске
83
					{
84
						//WriteDebug(#option);
2814 leency 85
						Write_Error(errornum);
2568 leency 86
					}
87
					return;
88
				}
89
				parametr=option='';
90
				break;
91
			default:
92
				IF (InfType==SECTION) copystr(#bukva,#section+strlen(#section));
93
				IF (InfType==PARAM) copystr(#bukva,#parametr+strlen(#parametr));
94
				IF (InfType==OPTION) copystr(#bukva,#option+strlen(#option));
95
		}
96
	}
97
	RUN_AS_PROGRAM:
98
	IF (file_path) errornum=RunProgram(#file_path,'');
99
	IF (errornum<0) //если ошибочка вышла при запуске
100
	{
2814 leency 101
		Write_Error(errornum);
2568 leency 102
	}
103
}
104
 
105
 
2814 leency 106
void Write_Error(int error_number)
2568 leency 107
{
2814 leency 108
	char error[256];
2820 leency 109
 
2568 leency 110
	if (error_number<0) error_number=-1*error_number;
2820 leency 111
 
112
	if (error_number<33)
113
		copystr(ERROR_TEXT[error_number], #error);
114
	else
115
		{
116
			copystr(IntToStr(error_number), #error);
117
			copystr(" - Unknown error number O_o", #error+strlen(#error));
118
		}
2814 leency 119
	if (curbtn>=0) Line_ReDraw(0xFF0000, curbtn);
120
	Pause(5);
3045 leency 121
	notify(#error);
2814 leency 122
	//DrawBar(192,onTop(0, BUTTON_HEIGHT+7),onLeft(27,192),BUTTON_HEIGHT,0xFF0000);
123
	//WriteText(205,onTop(-5, BUTTON_HEIGHT+7),0x80,0xFFFFFF,#error,0);
2820 leency 124
}