Subversion Repositories Kolibri OS

Rev

Rev 7802 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7802 Rev 8827
1
#include "all.h"
1
#include "all.h"
2
 
2
 
3
/// ===========================================================
-
 
4
 
-
 
5
int dir_check(char dir[])
3
int dir_check(char dir[])
6
/// just checks, if dir[] is really a directory
4
/// just checks, if dir[] is really a directory
7
{
5
{
8
kol_struct70	k70;
6
    kol_struct70	k70;
9
int		result;
7
    int		result;
10
 
8
 
11
k70.p00 = 1;
9
    k70.p00 = 1;
12
k70.p04 = 0;
10
    k70.p04 = 0;
13
//k70.p08 = 0;
11
    //k70.p08 = 0;
14
k70.p12 = 2; // enough to read . & ..
12
    k70.p12 = 2; // enough to read . & ..
15
k70.p16 = (unsigned)malloc(32+k70.p12*560);
13
    k70.p16 = (unsigned)malloc(32+k70.p12*560);
16
k70.p20 = 0;
14
    k70.p20 = 0;
17
k70.p21 = dir;
15
    k70.p21 = dir;
18
 
16
 
19
result = kol_file_70(&k70);
17
    result = kol_file_70(&k70);
20
 
18
 
21
free((void*)k70.p16);
19
    free((void*)k70.p16);
22
 
20
 
23
if ( (0 == result)||(6 == result) )  // 6 is possible ???
21
    if ( (0 == result)||(6 == result) )  // 6 is possible ???
24
	return TRUE;
22
        return TRUE;
25
else 
23
    else 
26
	return FALSE;
24
        return FALSE;
27
 
25
 
28
}
26
}
29
 
27
 
30
/// ===========================================================
-
 
31
 
-
 
32
void dir_truncate(char dir[])
28
void dir_truncate(char dir[])
33
{
29
{
34
int i;
30
    int i;
35
i = strlen(dir)-1;
31
    i = strlen(dir)-1;
36
for (;;i--)
32
    for (;;i--)
37
	if ('/' == dir[i])
33
        if ('/' == dir[i])
38
		{
34
            {
39
		dir[i+1] = 0;
35
            dir[i+1] = 0;
40
		break;
36
            break;
41
		}
37
            }
42
}
38
}
43
/// ===========================================================
39
 
44
 
-
 
45
void get_file_dir_loc(char *filepath, char *dir_path)
40
void get_file_dir_loc(char *filepath, char *dir_path)
46
{
41
{
47
	char *res = strrchr(filepath, '/');
42
    char *res = strrchr(filepath, '/');
48
	if (res == 0)
43
    if (res == 0)
49
	{
44
    {
50
		dir_path = '\0';
45
        dir_path = '\0';
51
		return;
46
        return;
52
	}
47
    }
53
	size_t pos = res - filepath;
48
    size_t pos = res - filepath;
54
	strncpy(dir_path, filepath, pos);
49
    strncpy(dir_path, filepath, pos);
55
	dir_path[pos] = '\0';
50
    dir_path[pos] = '\0';
56
}
51
}
57
 
52
 
58
/// ===========================================================
-
 
59
 
53
 
60
int file_check(char file[])
54
int file_check(char file[])
61
{
55
{
62
kol_struct70	k70;
56
    kol_struct70	k70;
63
int		result;
57
    int		result;
64
 
58
 
65
k70.p00 = 0;
59
    k70.p00 = 0;
66
k70.p04 = 0;
60
    k70.p04 = 0;
67
//k70.p08 = 0;
61
    //k70.p08 = 0;
68
k70.p12 = 0;
62
    k70.p12 = 0;
69
k70.p16 = 0;
63
    k70.p16 = 0;
70
k70.p20 = 0;
64
    k70.p20 = 0;
71
k70.p21 = file;
65
    k70.p21 = file;
72
 
66
 
73
result = kol_file_70(&k70);
67
    result = kol_file_70(&k70);
74
 
68
 
75
if (0 == result)
69
    if (0 == result)
76
	return TRUE;
70
        return TRUE;
77
else 
71
    else 
78
	return FALSE;
72
        return FALSE;
79
}
73
}
80
 
74
 
81
/// ===========================================================
-
 
82
 
75
 
83
void file_not_found(char file[])
-
 
84
{
-
 
85
#if LANG_ENG
76
void file_not_found(char file[]) {
86
	printf ("  File '%s' not found.\n\r", file);
-
 
87
#elif LANG_RUS
-
 
88
	printf ("  ” ©« '%s' ­¥ ­ ©¤¥­.\n\r", file);
-
 
89
#endif
77
    printf (FILE_NOT_FOUND_ERROR, file);
90
}
-
 
91
 
-
 
92
/// ===========================================================
-
 
93
 
78
}
94
int iswhite(char c)
-
 
95
{
-
 
96
return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c));
-
 
97
}
79
 
98
 
80
 
99
/// ===========================================================
81
int iswhite(char c) {return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c)); }
100
 
82
 
101
void trim(char string[])
83
void trim(char string[])
102
{
84
{
103
int i, j;
85
    int i, j;
104
 
86
 
105
for (i=0; ;i++)
87
    for (i=0; ;i++)
106
	if ( !iswhite(string[i]) )
88
        if ( !iswhite(string[i]) )
107
		break;
89
            break;
108
j = 0;
90
    j = 0;
109
for (;;i++, j++)
91
    for (;;i++, j++)
110
	{
92
        {
111
	string[j] = string[i];
93
        string[j] = string[i];
112
	if ('\0' == string[i] )
94
        if ('\0' == string[i] )
113
		break;
95
            break;
114
	}
96
        }
115
 
97
 
116
for (i=0; ;i++)
98
    for (i=0; ;i++)
117
	if ('\0' == string[i])
99
        if ('\0' == string[i])
118
		break;
100
            break;
119
i--;
101
    i--;
120
for (;i>0;--i)
102
    for (;i>0;--i)
121
	if ( iswhite(string[i]) )
103
        if ( iswhite(string[i]) )
122
		string[i] = '\0';
104
            string[i] = '\0';
123
	else
105
        else
124
		break;
106
            break;
125
}
107
}
126
 
108
 
127
/// ===========================================================
-
 
128
 
109
 
-
 
110
// entry point
129
void kol_main()
111
int main(int argc, char **argv)
-
 
112
{
-
 
113
    int i; for (i = 1; i < argc; i++) {
-
 
114
        strcat(cmdline, argv[i]);
-
 
115
        if (i != argc - 1) {
-
 
116
            strcat(cmdline, " ");
-
 
117
        }
130
{
118
    }
131
 
-
 
132
NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
119
 
133
 
120
    NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]);
134
strcpy(title, "SHELL ");
121
    strcpy(title, "SHELL ");
135
strcat(title, SHELL_VERSION);
122
    strcat(title, SHELL_VERSION);
136
CONSOLE_INIT(title);
123
    con_init_opt(-1, -1, -1, -1, title);
-
 
124
 
137
 
125
    //printf("argc = %d\ncmdline = '%s'\n", argc, cmdline);
138
if (sizeof (kol_struct70) != 25)
126
 
139
{
127
    if (sizeof (kol_struct70) != 25) {
140
	printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
128
        printf("Invalid struct align kol_struct70, need to fix compile options\n\r");
141
	kol_exit();
129
        kol_exit();
142
}
130
    }
143
 
131
 
144
 
-
 
145
//strcpy(cur_dir, PATH);
132
    //strcpy(cur_dir, PATH);
146
//dir_truncate(cur_dir);
133
    //dir_truncate(cur_dir);
147
getcwd(cur_dir, sizeof cur_dir);
134
    getcwd(cur_dir, sizeof cur_dir);
148
//printf("curdir %s\n", cur_dir);
135
    //printf("curdir %s\n", cur_dir);
149
 
136
 
150
con_set_cursor_height(con_get_font_height()-1);
137
    con_set_cursor_height(con_get_font_height()-1);
151
 
138
 
152
ALIASES = malloc(128*1024);
139
    ALIASES = malloc(128*1024);
153
 
140
 
154
if (!PARAM || PARAM[0] == 0)
141
    if (!cmdline || cmdline[0] == 0) {
155
{
-
 
156
   strcpy(CMD, PATH);
142
        strcpy(CMD, argv[0]);
157
   dir_truncate(CMD);
143
        dir_truncate(CMD);
158
   strcat(CMD, ".shell");
144
        strcat(CMD, ".shell");
159
   if ( !file_check(CMD) )
145
        if ( !file_check(CMD) )
160
       strcpy(CMD, "/sys/settings/.shell");
146
            strcpy(CMD, "/sys/settings/.shell");
161
}
147
    }
162
else
148
    else {
163
{
149
        if (cmdline[0] == '/')
164
	if (PARAM[0] == '/')
-
 
165
	{
150
        {
166
		strcpy(cur_dir, PARAM);
151
            strcpy(cur_dir, cmdline);
167
		*(strrchr(cur_dir, '/')+1)=0;
152
            *(strrchr(cur_dir, '/')+1)=0;
168
	}
153
        }
169
	strcpy(CMD, PARAM);
154
        strcpy(CMD, cmdline);
170
}
155
    }
171
 
156
 
172
command_execute();
157
    command_execute();
173
 
158
 
174
for (;;)
159
    for (;;) {
175
	{
-
 
176
	//printf("\033[32;1m"); 
160
        //printf("\033[32;1m"); 
177
	printf ("# ");
161
        printf ("# ");
178
	//printf("\033[0m"); 
162
        //printf("\033[0m"); 
179
	command_get();
163
        command_get();
180
	command_execute();
164
        command_execute();
181
	}
165
    }
182
 
166
 
183
_exit(0);
167
    con_exit(0);
184
kol_exit();
168
    kol_exit();
185
}
169
}
186
 
-
 
187
/// ===========================================================
-