summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell_script.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-07-23 20:28:13 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-07-23 20:28:13 +0000
commite6ee1712521799e6c571d992abe107bbccef5a3e (patch)
treeb1020f54d2fa9baf3203043a1f0b537cb2189d62 /cpukit/libmisc/shell/shell_script.c
parent2008-07-23 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-e6ee1712521799e6c571d992abe107bbccef5a3e.tar.bz2
2008-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/shell/shell_script.c: Clean up code for command not found including the error message.
Diffstat (limited to 'cpukit/libmisc/shell/shell_script.c')
-rw-r--r--cpukit/libmisc/shell/shell_script.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/cpukit/libmisc/shell/shell_script.c b/cpukit/libmisc/shell/shell_script.c
index 819506e121..0940a75046 100644
--- a/cpukit/libmisc/shell/shell_script.c
+++ b/cpukit/libmisc/shell/shell_script.c
@@ -47,25 +47,36 @@ static int findOnPATH(
char *scriptFile
)
{
+ int sc;
+
/*
* If the user script name starts with a / assume it is a fully
* qualified path name and just use it.
*/
if ( userScriptName[0] == '/' ) {
strcpy( scriptFile, userScriptName );
- return 0;
+ } else {
+ /*
+ * For now, the provided name is just turned into a fully
+ * qualified path name and used. There is no attempt to
+ * search along a path for it.
+ */
+
+ /* XXX should use strncat but what is the limit? */
+ getcwd( scriptFile, PATH_MAX );
+ strcat( scriptFile, "/" );
+ strcat(
+ scriptFile,
+ ( (userScriptName[0] == '.' && userScriptName[1] == '/') ?
+ &userScriptName[2] : userScriptName)
+ );
}
- /*
- * For now, the provided name is just turned into a fully
- * qualified path name and used. There is no attempt to
- * search along a path for it.
- */
+ sc = access( scriptFile, R_OK );
+ if ( sc ) {
+ return -1;
+ }
- getcwd( scriptFile, PATH_MAX );
- /* XXX should use strncat but what is the limit? */
- strcat( scriptFile, "/" );
- strcat( scriptFile, userScriptName );
return 0;
#if 0
@@ -156,7 +167,7 @@ int rtems_shell_main_joel(
*/
sc = findOnPATH( argv[getopt_reent.optind], scriptFile );
if ( sc ) {
- fprintf( stderr, "%s not found on PATH\n", argv[0] );
+ fprintf( stderr, "%s: command not found\n", argv[0] );
return -1;
}
@@ -227,7 +238,7 @@ int rtems_shell_script_file(
*/
sc = findOnPATH( argv[0], scriptFile );
if ( sc ) {
- fprintf( stderr, "%s not found on PATH\n", argv[0] );
+ fprintf( stderr, "%s: command not found\n", argv[0] );
return -1;
}