From 36f4cb93ed8f1837658d7dc9b805681b9cb45ec6 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 23 May 2014 16:46:22 -0500 Subject: Use shared main() and file processor --- schedsim/shell/schedsim_priority/Makefile.am | 6 +- schedsim/shell/schedsim_priority/schedsim.cc | 167 ------------------- schedsim/shell/schedsim_smppriority/Makefile.am | 1 - .../schedsim_smppriority_affinity/Makefile.am | 1 - schedsim/shell/schedsim_smpsimple/Makefile.am | 1 - schedsim/shell/schedsim_smpsimple/schedsim.cc | 181 --------------------- schedsim/shell/shared/Makefile.am | 1 + schedsim/shell/shared/add_commands_stub.c | 26 +++ schedsim/shell/shared/schedsim.c | 172 ++++++++++++++++++++ schedsim/shell/shared/schedsim_shell.h | 2 + 10 files changed, 205 insertions(+), 353 deletions(-) delete mode 100644 schedsim/shell/schedsim_priority/schedsim.cc delete mode 100644 schedsim/shell/schedsim_smpsimple/schedsim.cc create mode 100644 schedsim/shell/shared/add_commands_stub.c create mode 100644 schedsim/shell/shared/schedsim.c diff --git a/schedsim/shell/schedsim_priority/Makefile.am b/schedsim/shell/schedsim_priority/Makefile.am index 378aea2..2480c5e 100644 --- a/schedsim/shell/schedsim_priority/Makefile.am +++ b/schedsim/shell/schedsim_priority/Makefile.am @@ -1,6 +1,8 @@ bin_PROGRAMS = schedsim_priority -schedsim_priority_SOURCES = config.c \ - schedsim.cc wrap_thread_dispatch.c printheir_executing.c +schedsim_priority_SOURCES = config.c +schedsim_priority_SOURCES += wrap_thread_dispatch.c +schedsim_priority_SOURCES += printheir_executing.c +schedsim_priority_SOURCES += $(srcdir)/../shared/add_commands_stub.c if HAS_SMP schedsim_priority_SOURCES += smp_stub.c diff --git a/schedsim/shell/schedsim_priority/schedsim.cc b/schedsim/shell/schedsim_priority/schedsim.cc deleted file mode 100644 index 5a204be..0000000 --- a/schedsim/shell/schedsim_priority/schedsim.cc +++ /dev/null @@ -1,167 +0,0 @@ -/* - * COPYRIGHT (c) 1989-2013. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - */ - -#include -#include -#include -#include -#include - -#include "shell.h" -#include "rtems_sched.h" - -/* - * Variables to control global behavior - */ -int verbose = 0; -const char *progname; -const char *scriptname; - -FILE *Script; -int ScriptFileLine = 0; - -/* - * Print program usage message - */ -void usage() -{ - fprintf( - stderr, - "Usage: %s [-v] script\n" - "\n" - " -v - enable verbose output\n", - progname - ); - exit( -1 ); -} - -#define RTEMS_SHELL_MAXIMUM_ARGUMENTS (128) - -void ProcessScript( - FILE *script -) -{ - char buffer[512]; - char *cStatus; - char *c; - size_t length; - int argc; - char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS]; - rtems_shell_cmd_t *shell_cmd; - - - while ( 1 ) { - cStatus = fgets( buffer, sizeof(buffer), script ); - if ( cStatus == NULL ) - break; - - // If the last line does not have a CR, then we don't want to - // arbitrarily clobber an = instead of a \n. - length = strlen(buffer); - if ( buffer[ length - 1] == '\n' ) - buffer[ length - 1] = '\0'; - - if ( verbose ) - fprintf( stderr, "%d: %s\n", ++ScriptFileLine, buffer ); - - if ( buffer[0] == '#' ) - continue; - - for ( c = buffer ; *c ; c++ ) { - if (!isblank((int)*c)) - break; - } - - - if (!strcmp(c,"bye") || !strcmp(c,"exit")) { - return; - } - - if (rtems_shell_make_args(c, &argc, argv, RTEMS_SHELL_MAXIMUM_ARGUMENTS)) { - fprintf(stderr, "Error parsing arguments\n" ); - continue; - } - - shell_cmd = rtems_shell_lookup_cmd(argv[0]); - if ( !shell_cmd ) { - fprintf(stderr, "%s is unknown command\n", c ); - continue; - } - - shell_cmd->command(argc, argv); - } -} - -int main( - int argc, - char **argv -) -{ - int opt; - progname = argv[0]; - - while ((opt = getopt(argc, argv, "v")) != -1) { - switch (opt) { - case 'v': verbose = 1; break; - default: /* '?' */ - usage(); - } - } - - if ( optind >= argc ) { - fprintf( stderr, "no script to process\n" ); - usage(); - } - - scriptname = argv[ optind ]; - - if ( verbose ) { - fprintf( - stderr, - "Script File : %s\n" - "verbose : %d\n", - scriptname, - verbose - ); - } - - // - // Initialize the command interpreter - // - rtems_shell_initialize_command_set(); - - // - // Open the script file - // - Script = fopen( scriptname, "r" ); - if ( !Script ) { - fprintf( stderr, "Unable to open script file (%s)\n", scriptname ); - exit( -1 ); - } - - // - // Process the Script - // - ProcessScript( Script ); - - // - // Open the script file - // - (void) fclose( Script ); - - // - // Just in case something throws - // - try { - } catch (...) { - exit(-1); - } - - return 0; -} diff --git a/schedsim/shell/schedsim_smppriority/Makefile.am b/schedsim/shell/schedsim_smppriority/Makefile.am index 4596b85..a775004 100644 --- a/schedsim/shell/schedsim_smppriority/Makefile.am +++ b/schedsim/shell/schedsim_smppriority/Makefile.am @@ -8,7 +8,6 @@ SOURCES += $(srcdir)/../schedsim_smpsimple/main_dump_ready_tasks.c SOURCES += $(srcdir)/../schedsim_smpsimple/printheir_executing.c SOURCES += $(srcdir)/../schedsim_smpsimple/smp_stub.c SOURCES += $(srcdir)/../schedsim_smpsimple/wrap_thread_dispatch.c -SOURCES += $(srcdir)/../schedsim_smpsimple/schedsim.cc schedsim_smppriority_SOURCES = $(SOURCES) cpukitdir=@rtems_srcdir@/cpukit diff --git a/schedsim/shell/schedsim_smppriority_affinity/Makefile.am b/schedsim/shell/schedsim_smppriority_affinity/Makefile.am index 7f25c34..8b87ed5 100644 --- a/schedsim/shell/schedsim_smppriority_affinity/Makefile.am +++ b/schedsim/shell/schedsim_smppriority_affinity/Makefile.am @@ -8,7 +8,6 @@ SOURCES += $(srcdir)/../schedsim_smpsimple/main_dump_ready_tasks.c SOURCES += $(srcdir)/../schedsim_smpsimple/printheir_executing.c SOURCES += $(srcdir)/../schedsim_smpsimple/smp_stub.c SOURCES += $(srcdir)/../schedsim_smpsimple/wrap_thread_dispatch.c -SOURCES += $(srcdir)/../schedsim_smpsimple/schedsim.cc schedsim_smppriority_affinity_SOURCES = $(SOURCES) cpukitdir=@rtems_srcdir@/cpukit diff --git a/schedsim/shell/schedsim_smpsimple/Makefile.am b/schedsim/shell/schedsim_smpsimple/Makefile.am index a931b05..bc058fe 100644 --- a/schedsim/shell/schedsim_smpsimple/Makefile.am +++ b/schedsim/shell/schedsim_smpsimple/Makefile.am @@ -8,7 +8,6 @@ schedsim_smpsimple_SOURCES += main_dump_ready_tasks.c schedsim_smpsimple_SOURCES += printheir_executing.c schedsim_smpsimple_SOURCES += smp_stub.c schedsim_smpsimple_SOURCES += wrap_thread_dispatch.c -schedsim_smpsimple_SOURCES += schedsim.cc cpukitdir=@rtems_srcdir@/cpukit schedsim_smpsimple_CPPFLAGS = -I$(top_builddir)/score/include diff --git a/schedsim/shell/schedsim_smpsimple/schedsim.cc b/schedsim/shell/schedsim_smpsimple/schedsim.cc deleted file mode 100644 index 5136ac9..0000000 --- a/schedsim/shell/schedsim_smpsimple/schedsim.cc +++ /dev/null @@ -1,181 +0,0 @@ -/* - * COPYRIGHT (c) 1989-2013. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - */ - -#include -#include -#include -#include -#include - -#include "shell.h" -#include "rtems_sched.h" - -/* - * Variables to control global behavior - */ -int verbose = 1; -const char *progname; -const char *scriptname; - -FILE *Script; -int ScriptFileLine = 0; - -/* - * Print program usage message - */ -void usage() -{ - fprintf( - stderr, - "Usage: %s [-v] script\n" - "\n" - " -v - enable verbose output\n", - progname - ); - exit( -1 ); -} - -#define RTEMS_SHELL_MAXIMUM_ARGUMENTS (128) - -void ProcessScript( - FILE *script -) -{ - char buffer[512]; - int sc; - char *cStatus; - char *c; - size_t length; - int argc; - char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS]; - rtems_shell_cmd_t *shell_cmd; - - - while ( 1 ) { - cStatus = fgets( buffer, sizeof(buffer), script ); - if ( cStatus == NULL ) - break; - // If the last line does not have a CR, then we don't want to - // arbitrarily clobber an = instead of a \n. - length = strlen(buffer); - if ( buffer[ length - 1] == '\n' ) - buffer[ length - 1] = '\0'; - - if ( verbose ) - printf( "==> %d: %s\n", ++ScriptFileLine, buffer ); - - if ( buffer[0] == '#' ) - continue; - - for ( c = buffer ; *c ; c++ ) { - if (!isblank((int)*c)) - break; - } - - - if (!strcmp(c,"bye") || !strcmp(c,"exit")) { - exit( 0 ); - } - - if (rtems_shell_make_args(c, &argc, argv, RTEMS_SHELL_MAXIMUM_ARGUMENTS)) { - fprintf(stderr, "Error parsing arguments\n" ); - continue; - } - - if ( argc == 0 ) - continue; - - shell_cmd = rtems_shell_lookup_cmd(argv[0]); - if ( !shell_cmd ) { - fprintf(stderr, "%s is unknown command\n", c ); - exit( 1 ); - } - - sc = shell_cmd->command(argc, argv); - if ( sc != 0 ) { - fprintf( stderr, "ERROR: Command %s returned %d\n", argv[0], sc ); - exit( sc ); - } - } -} - -extern "C" { - void add_commands(void); -}; - -int main( - int argc, - char **argv -) -{ - int opt; - progname = argv[0]; - - while ((opt = getopt(argc, argv, "v")) != -1) { - switch (opt) { - case 'v': verbose = 0; break; - default: /* '?' */ - usage(); - } - } - - if ( optind >= argc ) { - scriptname = "-"; - } else { - scriptname = argv[ optind ]; - } - - if ( !strcmp( scriptname, "-" ) ) { - scriptname = "/dev/stdin"; - } - - if ( verbose ) { - printf( - "Script File : %s\n" - "verbose : %d\n", - scriptname, - verbose - ); - } - - // - // Initialize the command interpreter - // - rtems_shell_initialize_command_set(); - add_commands(); - - // - // Open the script file - // - Script = fopen( scriptname, "r" ); - if ( !Script ) { - fprintf( stderr, "Unable to open script file (%s)\n", scriptname ); - exit( -1 ); - } - - // - // Process the Script - // - ProcessScript( Script ); - - // - // Open the script file - // - (void) fclose( Script ); - - // - // Just in case something throws - // - try { - } catch (...) { - exit(-1); - } - - return 0; -} diff --git a/schedsim/shell/shared/Makefile.am b/schedsim/shell/shared/Makefile.am index eb41f4f..5bbb770 100644 --- a/schedsim/shell/shared/Makefile.am +++ b/schedsim/shell/shared/Makefile.am @@ -24,6 +24,7 @@ libschedsim_a_CPPFLAGS += -I$(cpukitdir)/posix/inline endif libschedsim_a_SOURCES = +libschedsim_a_SOURCES += schedsim.c libschedsim_a_SOURCES += commands.c libschedsim_a_SOURCES += getopt.c libschedsim_a_SOURCES += lookup_semaphore.c diff --git a/schedsim/shell/shared/add_commands_stub.c b/schedsim/shell/shared/add_commands_stub.c new file mode 100644 index 0000000..d2b1961 --- /dev/null +++ b/schedsim/shell/shared/add_commands_stub.c @@ -0,0 +1,26 @@ +/* + * COPYRIGHT (c) 1989-2013. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include +#include +#include +#include +#include +#include + +#include "shell.h" +#include "rtems_sched.h" + +extern int main_dump_ready_tasks(int argc, char **argv); +extern int main_set_current_cpu(int argc, char **argv); +extern int main_dispatch(int argc, char **argv); + +void add_commands(void) +{ +} diff --git a/schedsim/shell/shared/schedsim.c b/schedsim/shell/shared/schedsim.c new file mode 100644 index 0000000..532fb71 --- /dev/null +++ b/schedsim/shell/shared/schedsim.c @@ -0,0 +1,172 @@ +/* + * COPYRIGHT (c) 1989-2013. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +#include +#include +#include +#include +#include + +#include "shell.h" +#include "rtems_sched.h" +#include "schedsim_shell.h" + +/* + * Variables to control global behavior + */ +int verbose = 1; +const char *progname; +const char *scriptname; + +FILE *Script; +int ScriptFileLine = 0; + +/* + * Print program usage message + */ +void usage() +{ + fprintf( + stderr, + "Usage: %s [-v] script\n" + "\n" + " -v - enable verbose output\n", + progname + ); + exit( -1 ); +} + +#define RTEMS_SHELL_MAXIMUM_ARGUMENTS (128) + +int ProcessScript( + FILE *script +) +{ + char buffer[512]; + int sc; + char *cStatus; + char *c; + size_t length; + int argc; + char *argv[RTEMS_SHELL_MAXIMUM_ARGUMENTS]; + rtems_shell_cmd_t *shell_cmd; + + + while ( 1 ) { + cStatus = fgets( buffer, sizeof(buffer), script ); + if ( cStatus == NULL ) + break; + // If the last line does not have a CR, then we don't want to + // arbitrarily clobber an = instead of a \n. + length = strlen(buffer); + if ( buffer[ length - 1] == '\n' ) + buffer[ length - 1] = '\0'; + + if ( verbose ) + printf( "==> %d: %s\n", ++ScriptFileLine, buffer ); + + if ( buffer[0] == '#' ) + continue; + + for ( c = buffer ; *c ; c++ ) { + if (!isblank((int)*c)) + break; + } + + + if (!strcmp(c,"bye") || !strcmp(c,"exit")) { + exit( 0 ); + } + + if (rtems_shell_make_args(c, &argc, argv, RTEMS_SHELL_MAXIMUM_ARGUMENTS)) { + fprintf(stderr, "Error parsing arguments\n" ); + continue; + } + + if ( argc == 0 ) + continue; + + shell_cmd = rtems_shell_lookup_cmd(argv[0]); + if ( !shell_cmd ) { + fprintf(stderr, "%s is unknown command\n", c ); + exit( 1 ); + } + + sc = shell_cmd->command(argc, argv); + if ( sc != 0 ) { + fprintf( stderr, "ERROR: Command %s returned %d\n", argv[0], sc ); + exit( sc ); + } + } +} + +int main( + int argc, + char **argv +) +{ + int sc; + int opt; + + progname = argv[0]; + + while ((opt = getopt(argc, argv, "v")) != -1) { + switch (opt) { + case 'v': verbose = 0; break; + default: /* '?' */ + usage(); + } + } + + if ( optind >= argc ) { + scriptname = "-"; + } else { + scriptname = argv[ optind ]; + } + + if ( !strcmp( scriptname, "-" ) ) { + scriptname = "/dev/stdin"; + } + + if ( verbose ) { + printf( + "Script File : %s\n" + "verbose : %d\n", + scriptname, + verbose + ); + } + + // + // Initialize the command interpreter + // + rtems_shell_initialize_command_set(); + add_commands(); + + // + // Open the script file + // + Script = fopen( scriptname, "r" ); + if ( !Script ) { + fprintf( stderr, "Unable to open script file (%s)\n", scriptname ); + exit( -1 ); + } + + // + // Process the Script + // + sc = ProcessScript( Script ); + + // + // Open the script file + // + (void) fclose( Script ); + + return sc; +} diff --git a/schedsim/shell/shared/schedsim_shell.h b/schedsim/shell/shared/schedsim_shell.h index 15685bc..f094a52 100644 --- a/schedsim/shell/shared/schedsim_shell.h +++ b/schedsim/shell/shared/schedsim_shell.h @@ -24,6 +24,8 @@ extern "C" { #endif +void add_commands(void); + #define CHECK_RTEMS_IS_UP() \ do { \ if ( _System_state_Current != SYSTEM_STATE_UP ) { \ -- cgit v1.2.3