source: trunk/kernel/ksh/miniShell.c @ 10

Last change on this file since 10 was 1, checked in by alain, 8 years ago

First import

File size: 5.0 KB
RevLine 
[1]1/*
2   This file is part of MutekP.
3 
4   MutekP is free software; you can redistribute it and/or modify it
5   under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8 
9   MutekP is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   General Public License for more details.
13 
14   You should have received a copy of the GNU General Public License
15   along with MutekP; if not, write to the Free Software Foundation,
16   Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 
18   UPMC / LIP6 / SOC (c) 2008
19   Copyright Ghassan Almaless <ghassan.almaless@gmail.com>
20*/
21
22#include <system.h>
23#include <stdint.h>
24#include <string.h>
25#include <vfs.h>
26#include <thread.h>
27#include <kminiShell.h>
28#include <task.h>
29
30#define NR_THREADS  1
31
32uint8_t buffer[BUFFER_SIZE];
33
34struct vfs_file_s *root ;
35struct vfs_file_s *ms_n_cwd ;
36
37ms_args_t args;
38
39void print_args(ms_args_t *args)
40{
41  int i;
42
43  for(i=0; i < MS_MAX_ARG_LEN; i++)
44  {
45    ksh_print("idx %d:",i);
46    if(args->argv[i] != NULL)
47      ksh_print("|%s|\n", args->argv[i]);
48    else
49      ksh_print("NULL\n");
50  }
51
52  ksh_print("argc %d\n", args->argc);
53}
54
55
56typedef struct ksh_builtin_s
57{
58  char *name;
59  char *info;
60  ksh_cmd_t *cmd;
61}ksh_builtin_t;
62
63static error_t help_func(void *param);
64
65
66static ksh_builtin_t builtin_cmds[] = 
67  {
68    {"setty", "Set I/O Terminal Number", ksh_set_tty_func},
69    {"cd", "Change Directory", cd_func},
70    {"ls", "List Files In Directory", ls_func},
71    {"cp", "Copy File", cp_func},
72    {"cat", "Show File Contentes", cat_func},
73    {"ps", "Show Process (Tasks) State", ps_func},
74    {"exec", "Execute New Process", exec_func},
75    {"ppm", "Print Phyiscal Pages Manager", ppm_func},
76    {"cs", "CPUs Stats", ksh_cpu_state_func},
77    {"stat", "Show File System Instrumentation", show_instrumentation},
78    {"pwd", "Print Work Directory", pwd_func},
79    {"rm", "Remove File", rm_func},
80    {"kill", "Send the specified signal to the specified process", kill_func},
81    {"eomtkp", "Display SGI Image On Frame-Buffer", eomtkp_func},
82    {"clear", "Clear Some Lines", clear_func},
83    {"mkdir", "Make New Directory", mkdir_func},
84    {"mkfifo", "Make New Named FIFO File", mkfifo_func},
85    {"help", "Show Available commands", help_func},
86    {NULL,NULL,NULL}
87  };
88
89static error_t help_func(void *param)
90{
91  uint_t i;
92
93  ksh_print("Available Commands:\n");
94
95  for(i=0; builtin_cmds[i].name != NULL; i++)
96    ksh_print("%s: %s\n", builtin_cmds[i].name, builtin_cmds[i].info);
97
98  ksh_print("exit: Exit and synchronise panding disk wirtes if any\n");
99  return 0;
100}
101
102
103static error_t ksh_exec_cmd(char *cmd, ms_args_t *args)
104{
105  uint_t i;
106  error_t err;
107
108  for(i=0; builtin_cmds[i].name != NULL; i++)
109  {
110    if(!strcmp(cmd, builtin_cmds[i].name))
111    {
112      if((err=builtin_cmds[i].cmd(args)))
113        print_error_msg(err);
114      return 0;
115    }
116  }
117  return -1;
118}
119
120
121void* kMiniShelld(void *arg)
122{
123  ssize_t err;
124  struct task_s *task = current_task;
125  register char *cmd;
126
127  memset(&args,0,sizeof(args));
128  root = &task->vfs_root;
129  ms_n_cwd = &task->vfs_cwd; 
130
131#if 0
132  ksh_print("[%s]>",ms_n_cwd->n_name);
133  args.argc = 7;
134  strcpy(args.argv[0],"exec");
135  strcpy(args.argv[1],"/BIN/SHOWIMG.X");
136  strcpy(args.argv[2],"-p4");
137  strcpy(args.argv[3],"-i");
138  strcpy(args.argv[4],"/TMP/LENA.SGI");
139  strcpy(args.argv[5],"-o");
140  strcpy(args.argv[6],"/DEV/FB0");
141 
142  ksh_exec_cmd("exec", &args);
143#endif
144
145#if 0
146  ksh_print("[%s]>",ms_n_cwd->n_name);
147  args.argc = 7;
148  strcpy(args.argv[0],"exec");
149  strcpy(args.argv[1],"/BIN/HELLO.X");
150  strcpy(args.argv[2],"-p4");
151  strcpy(args.argv[3],"-i");
152  strcpy(args.argv[4],"/TMP/LENA.SGI");
153  strcpy(args.argv[5],"-o");
154  strcpy(args.argv[6],"/DEV/FB0");
155 
156  ksh_exec_cmd("exec", &args);
157
158  ksh_print("[%s]>",ms_n_cwd->n_name);
159  args.argc = 7;
160  strcpy(args.argv[0],"exec");
161  strcpy(args.argv[1],"/BIN/SHOWIMG.X");
162  strcpy(args.argv[2],"-p16");
163  strcpy(args.argv[3],"-i");
164  strcpy(args.argv[4],"/TMP/IMG.RGB");
165  strcpy(args.argv[5],"-o");
166  strcpy(args.argv[6],"/DEV/FB0");
167 
168  ksh_exec_cmd("exec", &args);
169
170#endif
171
172#if 0
173  task->vfs_cwd = ms_n_cwd;
174  ksh_print("[%s]>",ms_n_cwd->n_name);
175  args.argc = 2;
176  strcpy(args.argv[0],"cd");
177  strcpy(args.argv[1],"/tmp");
178  ksh_exec_cmd("cd", &args);
179
180  task->vfs_cwd = ms_n_cwd;
181  ksh_print("[%s]>",ms_n_cwd->n_name);
182  args.argc = 3;
183  strcpy(args.argv[0],"cp");
184  strcpy(args.argv[1],"r.txt");
185  strcpy(args.argv[2],"f.txt");
186  ksh_exec_cmd("cp", &args);
187#endif
188
189
190  while(1)
191  {
192    task->vfs_cwd = *ms_n_cwd;
193    //ksh_print("[%s]>",ms_n_cwd->n_name);FIXME
194    ksh_print("[%s]>", __FUNCTION__);
195    cmdLineAnalyser(&args);
196    cmd = args.argv[0];
197
198#if 0
199    print_args(&args);
200#endif
201
202    if((err=ksh_exec_cmd(cmd, &args)))
203    {
204      if(!strcmp(cmd, "exit"))
205        break;
206      else
207        ksh_print("Unknown command %s\n", cmd);
208    }
209  }
210
211  //bc_dump(&bc);
212  //bc_sync(&bc);
213  ksh_print("Finished\n");
214  return NULL;
215}
Note: See TracBrowser for help on using the repository browser.