Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / sh / main.c
blobaf6b1de526201d8368f8209bd1c446537d62ddda
1 /*
2 * ZeX/OS
3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <stdio.h>
23 #include <string.h>
24 #include <stdlib.h>
25 #include <unistd.h>
27 #define SHELL_VERSION "0.0.3"
29 char *cmdline;
30 int cmdline_len;
32 unsigned key_pressed (int keycode)
34 int scancode = getkey ();
36 if (scancode == keycode)
37 return 1;
39 if (scancode == keycode+128)
40 return 2;
41 else
42 return 0;
45 int init ()
47 cmdline = (char *) malloc (sizeof (char) * 64);
49 if (!cmdline) {
50 printf ("ERROR -> not enough memory !\n");
51 return 0;
54 cmdline_len = 0;
56 return 1;
59 int refresh_cmd ()
61 setcolor (7, 0);
62 printf (" $ ");
63 setcolor (15, 0);
65 return 1;
68 int check_cmd ()
70 if (!cmdline_len)
71 return 1;
73 printf ("\n");
75 /* exit app */
76 if (!strcmp (cmdline, "exit"))
77 return 0;
79 system (cmdline);
81 refresh_cmd ();
83 return 1;
86 int loop ()
88 int ret = 1;
89 unsigned char c;
91 c = getch ();
93 if (c && cmdline_len < 64) {
94 cmdline[cmdline_len] = (char) c;
96 if (c == '\n') {
97 cmdline[cmdline_len] = '\0';
98 ret = check_cmd ();
99 cmdline_len = 0;
100 } else {
101 if (c == '\b') {
102 if (cmdline_len > 0)
103 cmdline_len --;
104 } else
105 cmdline_len ++;
107 if (cmdline_len >= 0)
108 putch (c);
112 schedule ();
114 return ret;
117 int main (int argc, char **argv)
119 printf ("Shell v%s\n", SHELL_VERSION);
121 int ret = init ();
123 refresh_cmd ();
125 while (ret)
126 ret = loop ();
128 printf ("Bye !\n");
130 free (cmdline);
132 return 0;