put the asterix and colon the right way round
[reactos.git] / posix / apps / baresh / sh.c
1 /* $Id: sh.c,v 1.3 2002/10/29 04:44:59 rex Exp $
2 *
3 * baresh - Bare Shell for the PSX subsystem.
4 * Copyright (c) 2002 Emanuele Aliberti
5 * License: GNU GPL v2
6 */
7 #include <stdio.h>
8 #include <sys/types.h>
9 #include <dirent.h>
10
11 #define INPUT_BUFFER_SIZE 128
12
13 int run=1;
14
15 void cmd_exit(char*buf)
16 {
17 run=0;
18 }
19
20 void cmd_pwd(char * buf)
21 {
22 char pwd[1024];
23
24 getcwd(pwd,sizeof pwd);
25 printf("%s\n",pwd);
26 }
27
28 void cmd_ls(char*buf)
29 {
30 char pwd[1024];
31 DIR * dir;
32 struct dirent * entry;
33
34 getcwd(pwd,sizeof pwd);
35 dir=opendir(pwd);
36 while (NULL!=(entry=readdir(dir)))
37 {
38 printf("%s\n",entry->d_name);
39 }
40 closedir(dir);
41 }
42
43 int main(int argc,char*argv[])
44 {
45 char buf[INPUT_BUFFER_SIZE];
46
47 while (run)
48 {
49 printf("# ");
50 if (gets(buf))
51 {
52 if (!strcmp("exit",buf)) cmd_exit(buf);
53 else if (!strcmp("pwd",buf)) cmd_pwd(buf);
54 else if (!strcmp("ls",buf)) cmd_ls(buf);
55 else printf("%s: unknown command\n",argv[0]);
56 }
57 }
58 return 0;
59 }
60 /* EOF */