Subversion Repositories Kolibri OS

Rev

Rev 3045 | 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;
3113 leency 32
	char bukva[2];
2568 leency 33
	int errornum;
3113 leency 34
	dword fsize, tj;
35
	static dword buff;
2568 leency 36
	//читаем файл
3113 leency 37
	IF (onload==1)
38
	{
39
		free(buff);
40
		buff = malloc(12000);
41
		copystr(".ini", #program_path+strlen(#program_path));
42
	}
43
 
2904 leency 44
	ReadFile(0, 12000, buff, #program_path);
3113 leency 45
	IF (EAX<>6) ReadFile(0, 12000, buff, "/sys/File managers/Eolite.ini");
2568 leency 46
	IF (EAX<>6) //если файла с настройками тупо нет печалька
47
	{
3045 leency 48
		IF (onload==1) notify("Eolite.ini not found. Defaults will be used.");
2568 leency 49
		IF (onload==0) goto RUN_AS_PROGRAM;
50
	}
51
	fsize=EBX;
52
	//парсим его
53
	for (tj=0; tj
54
	{
55
		bukva = ESBYTE[buff+tj];
56
		switch (bukva)
57
		{
58
			case ';':
59
				InfType=COMMENT;
60
				break;
61
			case '[':
62
				InfType=SECTION;
63
				section='';
64
				break;
65
			case ']':
66
				InfType=PARAM;
67
				break;
68
			case '=':
69
				InfType=OPTION;
70
				break;
71
			case 0x0a:
72
			case 0x0d:
73
				InfType=PARAM;
2833 leency 74
				IF (!strcmp(#parametr,"SelectionColor")) selection_col=StrToCol(#option);
2662 leency 75
				IF (!strcmp(#parametr,"LineHeight")) BUTTON_HEIGHT=StrToInt(#option);
76
				IF (!strcmp(#parametr,"ShowDeviceName")) show_dev_name=StrToInt(#option);
2568 leency 77
 
2662 leency 78
				/*if (!strcmp(#section,"UserDirectories")) && (parametr) && (onload)
79
				{
80
					copystr(#parametr, #disk_list[disc_num].Item);
81
					disc_num++;
82
				}*/
83
 
2875 leency 84
				IF (parametr) && (!strcmp(#file_name+strchr(#file_name,'.'),#parametr)) {
2568 leency 85
					errornum=RunProgram(#option,#file_path);
86
					IF (errornum<0) //если ошибочка вышла при запуске
87
					{
88
						//WriteDebug(#option);
2814 leency 89
						Write_Error(errornum);
2568 leency 90
					}
91
					return;
92
				}
93
				parametr=option='';
94
				break;
95
			default:
96
				IF (InfType==SECTION) copystr(#bukva,#section+strlen(#section));
97
				IF (InfType==PARAM) copystr(#bukva,#parametr+strlen(#parametr));
98
				IF (InfType==OPTION) copystr(#bukva,#option+strlen(#option));
99
		}
100
	}
101
	RUN_AS_PROGRAM:
102
	IF (file_path) errornum=RunProgram(#file_path,'');
103
	IF (errornum<0) //если ошибочка вышла при запуске
104
	{
2814 leency 105
		Write_Error(errornum);
2568 leency 106
	}
107
}
108
 
109
 
2814 leency 110
void Write_Error(int error_number)
2568 leency 111
{
2814 leency 112
	char error[256];
2820 leency 113
 
2568 leency 114
	if (error_number<0) error_number=-1*error_number;
2820 leency 115
 
116
	if (error_number<33)
117
		copystr(ERROR_TEXT[error_number], #error);
118
	else
119
		{
120
			copystr(IntToStr(error_number), #error);
121
			copystr(" - Unknown error number O_o", #error+strlen(#error));
122
		}
2814 leency 123
	if (curbtn>=0) Line_ReDraw(0xFF0000, curbtn);
124
	Pause(5);
3045 leency 125
	notify(#error);
2814 leency 126
	//DrawBar(192,onTop(0, BUTTON_HEIGHT+7),onLeft(27,192),BUTTON_HEIGHT,0xFF0000);
127
	//WriteText(205,onTop(-5, BUTTON_HEIGHT+7),0x80,0xFFFFFF,#error,0);
2820 leency 128
}