Rev 3245 | Rev 4106 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3245 | Rev 3988 | ||
---|---|---|---|
1 | #include "all.h" |
1 | #include "all.h" |
2 | 2 | ||
3 | /// =========================================================== |
3 | /// =========================================================== |
4 | 4 | ||
5 | int dir_check(char dir[]) |
5 | int dir_check(char dir[]) |
6 | { |
6 | { |
7 | kol_struct70 k70; |
7 | kol_struct70 k70; |
8 | int result; |
8 | int result; |
9 | 9 | ||
10 | k70.p00 = 1; |
10 | k70.p00 = 1; |
11 | k70.p04 = 0; |
11 | k70.p04 = 0; |
12 | k70.p08 = 0; |
12 | k70.p08 = 0; |
13 | k70.p12 = 2*1024*1024; // 2 MB |
13 | k70.p12 = 2*1024*1024; // 2 MB |
14 | k70.p16 = (unsigned) malloc(2*1024*1024); |
14 | k70.p16 = (unsigned) malloc(2*1024*1024); |
15 | k70.p20 = 0; |
15 | k70.p20 = 0; |
16 | k70.p21 = dir; |
16 | k70.p21 = dir; |
17 | 17 | ||
18 | result = kol_file_70(&k70); |
18 | result = kol_file_70(&k70); |
19 | 19 | ||
20 | free((void*)k70.p16); |
20 | free((void*)k70.p16); |
21 | 21 | ||
22 | if ( (0 == result)||(6 == result) ) |
22 | if ( (0 == result)||(6 == result) ) |
23 | return TRUE; |
23 | return TRUE; |
24 | else |
24 | else |
25 | return FALSE; |
25 | return FALSE; |
26 | 26 | ||
27 | } |
27 | } |
28 | 28 | ||
29 | /// =========================================================== |
29 | /// =========================================================== |
30 | 30 | ||
31 | void dir_truncate(char dir[]) |
31 | void dir_truncate(char dir[]) |
32 | { |
32 | { |
33 | int i; |
33 | int i; |
34 | i = strlen(dir)-1; |
34 | i = strlen(dir)-1; |
35 | for (;;i--) |
35 | for (;;i--) |
36 | if ('/' == dir[i]) |
36 | if ('/' == dir[i]) |
37 | { |
37 | { |
38 | dir[i+1] = 0; |
38 | dir[i+1] = 0; |
39 | break; |
39 | break; |
40 | } |
40 | } |
41 | } |
41 | } |
42 | 42 | ||
43 | /// =========================================================== |
43 | /// =========================================================== |
44 | 44 | ||
45 | int file_check(char file[]) |
45 | int file_check(char file[]) |
46 | { |
46 | { |
47 | kol_struct70 k70; |
47 | kol_struct70 k70; |
48 | int result; |
48 | int result; |
49 | 49 | ||
50 | k70.p00 = 0; |
50 | k70.p00 = 0; |
51 | k70.p04 = 0; |
51 | k70.p04 = 0; |
52 | k70.p08 = 0; |
52 | k70.p08 = 0; |
53 | k70.p12 = 0; |
53 | k70.p12 = 0; |
54 | k70.p16 = 0; |
54 | k70.p16 = 0; |
55 | k70.p20 = 0; |
55 | k70.p20 = 0; |
56 | k70.p21 = file; |
56 | k70.p21 = file; |
57 | 57 | ||
58 | result = kol_file_70(&k70); |
58 | result = kol_file_70(&k70); |
59 | 59 | ||
60 | if (0 == result) |
60 | if (0 == result) |
61 | return TRUE; |
61 | return TRUE; |
62 | else |
62 | else |
63 | return FALSE; |
63 | return FALSE; |
64 | } |
64 | } |
65 | 65 | ||
66 | /// =========================================================== |
66 | /// =========================================================== |
67 | 67 | ||
68 | void file_not_found(char file[]) |
68 | void file_not_found(char file[]) |
69 | { |
69 | { |
70 | #if LANG_ENG |
70 | #if LANG_ENG |
71 | printf (" File '%s' not found.\n\r", file); |
71 | printf (" File '%s' not found.\n\r", file); |
72 | #elif LANG_RUS |
72 | #elif LANG_RUS |
73 | printf (" ©« '%s' ¥ ©¤¥.\n\r", file); |
73 | printf (" ©« '%s' ¥ ©¤¥.\n\r", file); |
74 | #endif |
74 | #endif |
75 | } |
75 | } |
76 | 76 | ||
77 | /// =========================================================== |
77 | /// =========================================================== |
78 | 78 | ||
79 | int iswhite(char c) |
79 | int iswhite(char c) |
80 | { |
80 | { |
81 | return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c)); |
81 | return ((' ' == c) || ('\t' == c) || (13 == c) || (10 == c)); |
82 | } |
82 | } |
83 | 83 | ||
84 | /// =========================================================== |
84 | /// =========================================================== |
85 | 85 | ||
86 | void trim(char string[]) |
86 | void trim(char string[]) |
87 | { |
87 | { |
88 | int i, j; |
88 | int i, j; |
89 | 89 | ||
90 | for (i=0; ;i++) |
90 | for (i=0; ;i++) |
91 | if ( !iswhite(string[i]) ) |
91 | if ( !iswhite(string[i]) ) |
92 | break; |
92 | break; |
93 | j = 0; |
93 | j = 0; |
94 | for (;;i++, j++) |
94 | for (;;i++, j++) |
95 | { |
95 | { |
96 | string[j] = string[i]; |
96 | string[j] = string[i]; |
97 | if ('\0' == string[i] ) |
97 | if ('\0' == string[i] ) |
98 | break; |
98 | break; |
99 | } |
99 | } |
100 | 100 | ||
101 | for (i=0; ;i++) |
101 | for (i=0; ;i++) |
102 | if ('\0' == string[i]) |
102 | if ('\0' == string[i]) |
103 | break; |
103 | break; |
104 | i--; |
104 | i--; |
105 | for (;i>0;--i) |
105 | for (;i>0;--i) |
106 | if ( iswhite(string[i]) ) |
106 | if ( iswhite(string[i]) ) |
107 | string[i] = '\0'; |
107 | string[i] = '\0'; |
108 | else |
108 | else |
109 | break; |
109 | break; |
110 | } |
110 | } |
111 | 111 | ||
112 | /// =========================================================== |
112 | /// =========================================================== |
113 | 113 | ||
114 | void kol_main() |
114 | void kol_main() |
115 | { |
115 | { |
116 | 116 | ||
117 | NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]); |
117 | NUM_OF_CMD = sizeof(COMMANDS)/sizeof(COMMANDS[0]); |
118 | 118 | ||
119 | strcpy(title, "SHELL "); |
119 | strcpy(title, "SHELL "); |
120 | strcat(title, SHELL_VERSION); |
120 | strcat(title, SHELL_VERSION); |
121 | CONSOLE_INIT(title); |
121 | CONSOLE_INIT(title); |
122 | 122 | ||
123 | strcpy(cur_dir, PATH); |
123 | strcpy(cur_dir, PATH); |
124 | dir_truncate(cur_dir); |
124 | dir_truncate(cur_dir); |
125 | 125 | ||
126 | con_set_cursor_height(con_get_font_height()-1); |
126 | con_set_cursor_height(con_get_font_height()-1); |
127 | 127 | ||
128 | ALIASES = malloc(128*1024); |
128 | ALIASES = malloc(128*1024); |
129 | 129 | ||
130 | if (strlen(PARAM) > 0) |
- | |
131 | strcpy(CMD, PARAM); |
130 | if (PARAM[0] == 0) strcpy(CMD, ".shell"); |
132 | else |
131 | else |
- | 132 | { |
|
- | 133 | if (PARAM[0] == '/') |
|
- | 134 | { |
|
- | 135 | strcpy(cur_dir, PARAM); |
|
- | 136 | *strrchr(cur_dir, '/')=0; |
|
- | 137 | } |
|
133 | strcpy(CMD, ".shell"); |
138 | strcpy(CMD, PARAM); |
- | 139 | } |
|
134 | 140 | ||
135 | command_execute(); |
141 | command_execute(); |
136 | 142 | ||
137 | for (;;) |
143 | for (;;) |
138 | { |
144 | { |
139 | printf ("# "); |
145 | printf ("# "); |
140 | command_get(); |
146 | command_get(); |
141 | command_execute(); |
147 | command_execute(); |
142 | } |
148 | } |
143 | 149 | ||
144 | _exit(0); |
150 | _exit(0); |
145 | kol_exit(); |
151 | kol_exit(); |
146 | } |
152 | } |
147 | 153 | ||
148 | /// =========================================================== |
154 | /// =========================================================== |