Added `-c' option to execute a command line. Should work, but doesn't
always do. More often than not one gets page faults. As it happens sometimes even before anything meaty has been done at all (e.g. in main()->init_statements()->shell_var_set_text()-> shell_value_init_text()->malloc()), I believe that's a problem not caused by me. And I wasn't able to track it down. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8924 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2c731698a2
commit
9516afb70a
@ -3,6 +3,7 @@
|
||||
#include <ctype.h>
|
||||
#include <syscalls.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "args.h"
|
||||
#include "shell_defs.h"
|
||||
@ -10,18 +11,16 @@
|
||||
|
||||
bool af_exit_after_script;
|
||||
char *af_script_file_name;
|
||||
char *gCommandToExecute = NULL;
|
||||
|
||||
static const char *kUsage =
|
||||
"Usage: shell [ -s ] [ -c <command> ] [ <script> ... ]\n";
|
||||
|
||||
static void handle_option(char *option){
|
||||
|
||||
switch(option[1]){
|
||||
case 's':// setup script
|
||||
if(option[2] == 0){
|
||||
af_exit_after_script = false;
|
||||
}
|
||||
}
|
||||
|
||||
printf("wrong option : %s \n",option);
|
||||
static
|
||||
void
|
||||
print_usage(bool error)
|
||||
{
|
||||
fprintf((error ? stderr : stdout), kUsage);
|
||||
}
|
||||
|
||||
void init_arguments(int argc,char **argv){
|
||||
@ -30,11 +29,29 @@ void init_arguments(int argc,char **argv){
|
||||
int shell_argc = 0;
|
||||
char name[255];
|
||||
|
||||
af_exit_after_script = true;
|
||||
af_exit_after_script = true;
|
||||
af_script_file_name = NULL;
|
||||
|
||||
while((cnt < argc) && (argv[cnt][0] == '-')){
|
||||
handle_option(argv[cnt]);
|
||||
const char *option = argv[cnt];
|
||||
switch(option[1]){
|
||||
case 's': // setup script
|
||||
if (option[2] == 0)
|
||||
af_exit_after_script = false;
|
||||
break;
|
||||
case 'c': // execute command
|
||||
cnt++;
|
||||
if (cnt >= argc) {
|
||||
print_usage(true);
|
||||
exit(1);
|
||||
}
|
||||
gCommandToExecute = argv[cnt];
|
||||
// ignore further args
|
||||
return;
|
||||
default:
|
||||
print_usage(true);
|
||||
exit(1);
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
|
||||
@ -54,6 +71,4 @@ void init_arguments(int argc,char **argv){
|
||||
shell_var_set_number(NAME_VAR_ARGC,shell_argc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
extern bool af_exit_after_script;
|
||||
extern char *af_script_file_name;
|
||||
extern char *gCommandToExecute;
|
||||
|
||||
void init_arguments(int argc,char **argv);
|
||||
|
||||
|
@ -80,6 +80,12 @@ main(int argc, char *argv[])
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (gCommandToExecute) {
|
||||
if (strlen(gCommandToExecute) > 0)
|
||||
parse_string(gCommandToExecute);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
printf("Welcome to the Haiku shell\n");
|
||||
|
||||
for (;;) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user