/* * Shell Script Invocation * * Pseudo-code from Chris Johns, implemented and debugged * by Joel Sherrill. * * COPYRIGHT (c) 1989-2008. * 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. * * $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include #include #include #include #include #include "internal.h" static void rtems_shell_joel_usage() { printf( "joel [args] where args may be:\n" " -o FILE output file (default=stdout)\n" " -p PRIORITY task priority\n" " -s SIZE task stack size\n" " -t NAME task name\n" ); } int rtems_shell_main_decho( int argc, char **argv ) { int i; for (i=0 ; i= argc ) { fprintf( stderr, "Shell: No script to execute\n" ); return -1; } /* * Find script on the path. * * NOTE: It is terrible that this is done twice but it * seems to be the most expedient thing. */ sc = findOnPATH( argv[getopt_reent.optind], scriptFile ); if ( sc ) { fprintf( stderr, "%s not found on PATH\n", argv[0] ); return -1; } /* fprintf( stderr, "SCRIPT: -%s-\n", scriptFile ); */ /* * I assume that argv[optind...] will have the arguments to * the shell script. But that remains to be implemented. */ /* * Run the script */ result = rtems_shell_script( taskName, /* the name of the task */ stackSize, /* stack size */ taskPriority, /* task priority */ scriptFile, /* the script file */ outputFile, /* where to redirect the script */ 0, /* run once and exit */ 1, /* we will wait */ verbose /* do we echo */ ); if (result) return -1; return 0; } rtems_shell_cmd_t rtems_shell_JOEL_Command = { "joel", /* name */ "joel [args] SCRIPT", /* usage */ "misc", /* topic */ rtems_shell_main_joel, /* command */ NULL, /* alias */ NULL /* next */ }; /* * This is a helper function which takes a command as arguments * which has not been located as a built-in command and attempts * to find something in the filesystem with the same name that * appears to be a shell script. */ int rtems_shell_script_file( int argc, char *argv[] ) { #define FIRST_LINE_LENGTH 128 #define SCRIPT_ARGV_LIMIT 32 char scriptFile[PATH_MAX]; char *scriptHead; char scriptHeadBuffer[FIRST_LINE_LENGTH]; int sc; FILE *script; size_t length; int scriptArgc; char *scriptArgv[SCRIPT_ARGV_LIMIT]; /* * Clear argv pointer array */ for ( scriptArgc=0 ; scriptArgc