summaryrefslogtreecommitdiff
path: root/package/sash
diff options
context:
space:
mode:
Diffstat (limited to 'package/sash')
-rw-r--r--package/sash/src/Makefile5
-rw-r--r--package/sash/src/README3
-rw-r--r--package/sash/src/cmd_uclinux.c41
-rw-r--r--package/sash/src/cmds.c24
-rw-r--r--package/sash/src/cp.c1
-rw-r--r--package/sash/src/date.c19
-rw-r--r--package/sash/src/df.c5
-rw-r--r--package/sash/src/free.c7
-rw-r--r--package/sash/src/hexdump.c39
-rw-r--r--package/sash/src/hostname.c2
-rw-r--r--package/sash/src/ls.c4
-rw-r--r--package/sash/src/ps.c93
-rw-r--r--package/sash/src/reboot.c17
-rw-r--r--package/sash/src/sash.c377
-rw-r--r--package/sash/src/sash.h16
-rw-r--r--package/sash/src/shutdown.c7
16 files changed, 154 insertions, 506 deletions
diff --git a/package/sash/src/Makefile b/package/sash/src/Makefile
index a7bd5894a..b857df38e 100644
--- a/package/sash/src/Makefile
+++ b/package/sash/src/Makefile
@@ -1,4 +1,3 @@
-
SH = sh
SHOBJS = sash.o cmds.o cmd_uclinux.o ls.o hexdump.o df.o free.o \
hostname.o date.o
@@ -10,12 +9,9 @@ REBOOT = reboot
REBOOTOBJS = reboot.o
SHOBJS += ps.o
-CFLAGS += -DCONFIG_USER_SASH_PS
LIBSASH = libsash/libsash.a
-CFLAGS += -DCOMMAND_HISTORY
-
all: $(SH) $(SHUTDOWN) $(REBOOT)
$(SH): $(SHOBJS) $(LIBSASH)
@@ -35,4 +31,3 @@ $(LIBSASH): dummy_target
clean:
-rm -f $(SH) $(SHUTDOWN) $(REBOOT) *.elf *.gdb *.o
$(MAKE) -C libsash clean
-
diff --git a/package/sash/src/README b/package/sash/src/README
index 191c7de63..db8b3d429 100644
--- a/package/sash/src/README
+++ b/package/sash/src/README
@@ -1,6 +1,3 @@
-
-
This shell is an adaption of David Bell's "sash", the stand-along shell,
with some adaptions (and truncations) for our environment. It also includes
a few utilities (like reboot and ps) that weren't part of the original sash.
-
diff --git a/package/sash/src/cmd_uclinux.c b/package/sash/src/cmd_uclinux.c
index 32886ebe4..bca2152b9 100644
--- a/package/sash/src/cmd_uclinux.c
+++ b/package/sash/src/cmd_uclinux.c
@@ -1,4 +1,3 @@
-
#include "sash.h"
#include <fcntl.h>
@@ -29,37 +28,37 @@ do_ps(argc, argv)
DIR * d;
struct dirent * de;
int l;
-
+
printf(" PID TTY STAT TIME COMMAND\n");
-
-
+
+
d = opendir("/proc");
if (!d)
return;
-
+
while (de = readdir(d)) {
for(i=0;i<strlen(de->d_name);i++)
if (!isdigit(de->d_name[i]))
goto next;
-
+
sprintf(psbuf, "/proc/%s/stat", de->d_name);
h = open(psbuf, O_RDONLY);
-
+
if (h==-1)
continue;
-
+
l = read(h, psbuf, 255);
if (l<=0) {
perror("Unable to read status");
close(h);
continue;
}
-
+
psbuf[l] = '\0';
psbuf[255] = '\0';
-
-
- if (sscanf(psbuf,
+
+
+ if (sscanf(psbuf,
"%d %s %c",
&pid, name, &statec)<3)
{
@@ -67,34 +66,34 @@ do_ps(argc, argv)
close(h);
continue;
}
-
+
state = statec;
-
+
close(h);
-
+
sprintf(psbuf, "/proc/%s/cmdline", de->d_name);
h = open(psbuf, O_RDONLY);
-
+
if (h == -1) {
perror("Unable to open cmdline");
continue;
}
-
+
l = read(h, psbuf, 255);
if (l < 0) {
perror("Unable to read cmdline");
close(h);
continue;
}
-
+
close(h);
-
+
psbuf[255] = psbuf[l] = '\0';
-
+
printf("%5d %3s %c --:-- %s\n", pid, "", state, psbuf);
next:
}
-
+
closedir(d);
}
#endif
diff --git a/package/sash/src/cmds.c b/package/sash/src/cmds.c
index b5c9168b3..149a1a755 100644
--- a/package/sash/src/cmds.c
+++ b/package/sash/src/cmds.c
@@ -24,9 +24,6 @@
#include <grp.h>
#include <utime.h>
#include <errno.h>
-#ifdef EMBED
-#include <config/autoconf.h>
-#endif
void
do_echo(argc, argv)
@@ -62,16 +59,6 @@ do_pwd(argc, argv)
}
void
-do_time(argc, argv)
- int argc;
- char ** argv;
-{
- struct timeval tv;
- gettimeofday(&tv, 0);
- printf("Time of day = %d.%6.6d seconds\n", tv.tv_sec, tv.tv_usec);
-}
-
-void
do_cd(argc, argv)
int argc;
char **argv;
@@ -117,7 +104,7 @@ do_mkdir(argc, argv)
}
void
-do_sleep(argc, argv)
+do_sleep(argc, argv)
int argc;
char **argv;
{
@@ -189,9 +176,6 @@ do_sync(argc, argv)
int argc;
char **argv;
{
-#ifdef CONFIG_USER_FLATFSD_FLATFSD
- system("exec flatfsd -s");
-#endif
sync();
}
@@ -559,7 +543,7 @@ do_cmp(argc, argv)
char *buf2;
struct stat statbuf1;
struct stat statbuf2;
-
+
if (stat(argv[1], &statbuf1) < 0) {
perror(argv[1]);
return;
@@ -581,7 +565,7 @@ do_cmp(argc, argv)
printf("Files are different sizes\n");
return;
}
-
+
fd1 = open(argv[1], 0);
if (fd1 < 0) {
perror(argv[1]);
@@ -594,7 +578,7 @@ do_cmp(argc, argv)
close(fd1);
return;
}
-
+
buf1 = malloc(8192-16);
buf2 = malloc(8192-16);
diff --git a/package/sash/src/cp.c b/package/sash/src/cp.c
index 11d03f74c..e66bfced8 100644
--- a/package/sash/src/cp.c
+++ b/package/sash/src/cp.c
@@ -1,4 +1,3 @@
-
void
do_cp(argc, argv)
char **argv;
diff --git a/package/sash/src/date.c b/package/sash/src/date.c
index a1a69a530..d761b3bbd 100644
--- a/package/sash/src/date.c
+++ b/package/sash/src/date.c
@@ -12,44 +12,41 @@ int do_date(int argc, char * argv[])
struct tm tm_time;
time(&tm);
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
-
+
if (argc > 1) {
int nr;
-
+
nr = sscanf(argv[1], "%2d%2d%2d%2d%d",
&(tm_time.tm_mon),
&(tm_time.tm_mday),
&(tm_time.tm_hour),
&(tm_time.tm_min), &(tm_time.tm_year));
-
+
if (nr < 4 || nr > 5) {
fprintf(stderr, invalid_date, argv[1]);
return(0);
}
-
+
/* correct for century - minor Y2K problem here? */
if (tm_time.tm_year >= 1900)
tm_time.tm_year -= 1900;
/* adjust date */
tm_time.tm_mon -= 1;
-
+
if((tm = mktime(&tm_time)) < 0) {
fprintf(stderr, invalid_date, argv[1]);
return(0);
}
-
+
if(stime(&tm) < 0) {
fprintf(stderr, "Unable to set date\n");
return(0);
}
-
+
return (0);
-
+
}
printf("%s\n",asctime(&tm_time));
return(0);
}
-
-
-
diff --git a/package/sash/src/df.c b/package/sash/src/df.c
index 99ac2217e..8f2c05533 100644
--- a/package/sash/src/df.c
+++ b/package/sash/src/df.c
@@ -41,15 +41,14 @@ do_df(int argc, char * argv[])
name = "/";
else
name = argv[1];
-
+
if (statfs(name, &stbuf) == -1) {
printf("Unable to get disk space of %s: %s\n", name, strerror(errno));
return;
}
-
+
printf("Total Kbytes: %ld\n", (stbuf.f_bsize / 256) * (stbuf.f_blocks / 4));
printf("Free Kbytes: %ld\n", (stbuf.f_bsize / 256) * (stbuf.f_bfree / 4));
printf("Total nodes: %ld\n", stbuf.f_files);
printf("Free nodes: %ld\n", stbuf.f_ffree);
}
-
diff --git a/package/sash/src/free.c b/package/sash/src/free.c
index d4d4dedd3..e2a580078 100644
--- a/package/sash/src/free.c
+++ b/package/sash/src/free.c
@@ -29,17 +29,16 @@ do_free(argc, argv)
char buf[256];
f = fopen("/proc/meminfo", "r");
-
+
if (!f) {
perror("Unable to open /proc/meminfo: ");
return;
}
-
+
for(i=0;i<3;i++) {
fgets(buf, 250, f);
fputs(buf, stdout);
}
-
+
fclose(f);
}
-
diff --git a/package/sash/src/hexdump.c b/package/sash/src/hexdump.c
index f12f62494..8b271981a 100644
--- a/package/sash/src/hexdump.c
+++ b/package/sash/src/hexdump.c
@@ -32,13 +32,13 @@ do_hexdump(argc, argv)
char *name = 0;
unsigned long pos = 0;
char *myname = argv[0];
-
+
if ( (argc > 2) && !strcmp(argv[1],"-s") ) {
pos = strtoul(argv[2], 0, 0);
argc -= 2;
argv += 2;
}
-
+
if (argc <= 1) {
fprintf(stderr, "No filename provided\n");
return;
@@ -54,15 +54,15 @@ do_hexdump(argc, argv)
if (pos)
fseek(fp, pos, SEEK_SET);
-
+
c = 0;
-
+
text[16] = 0;
-
+
while(!feof(fp)) {
-
+
strcmp(text, " ");
-
+
while (c < (pos & 0xf)) {
if (c == 0)
printf("%4X:", pos & 0xfffffff0);
@@ -70,35 +70,35 @@ do_hexdump(argc, argv)
text[c] = ' ';
c++;
}
-
+
{
int p = 0;
count = fread(buf, 1, 128 - (pos % 16), fp);
-
+
if (count <= 0)
break;
while (p < count) {
c = (pos & 0xf);
-
+
if (c == 0)
printf("%4X:", pos & 0xfffffff0);
-
+
if ((buf[p] < 32) || (buf[p]>126))
text[c] = '.';
else
text[c] = buf[p];
-
+
printf( (c==15) ? " %02.2X" : (c == 8) ? "-%02.2X" : " %02.2X", buf[p]);
-
+
if (c == 15)
printf(" %s\n", text);
-
+
pos++;
p++;
}
}
-
+
if (c = (pos & 0x0f)) {
while (c < 16) {
@@ -106,16 +106,16 @@ do_hexdump(argc, argv)
text[c] = ' ';
c++;
}
-
+
printf(" %s\n", text);
}
-
+
if (feof(fp))
break;
-
+
printf("--more--");
fflush(stdout);
-
+
fgets(buf, 80, stdin);
if (toupper(buf[0]) == 'Q')
break;
@@ -124,4 +124,3 @@ do_hexdump(argc, argv)
if (fp != stdin)
fclose(fp);
}
-
diff --git a/package/sash/src/hostname.c b/package/sash/src/hostname.c
index 8841e7fa3..5faeabce5 100644
--- a/package/sash/src/hostname.c
+++ b/package/sash/src/hostname.c
@@ -10,7 +10,7 @@
void do_hostname(int argc, char **argv)
{
char hn[PATHLEN + 1];
-
+
if(argc >= 2) {
if(strlen(argv[1]) > PATHLEN) {
printf("That name is too long.\n");
diff --git a/package/sash/src/ls.c b/package/sash/src/ls.c
index eae185240..5f59b6fb6 100644
--- a/package/sash/src/ls.c
+++ b/package/sash/src/ls.c
@@ -74,7 +74,7 @@ do_ls(argc, argv)
listsize = LISTSIZE;
}
listused = 0;
-
+
flags = 0;
if ((argc > 1) && (argv[1][0] == '-'))
{
@@ -135,7 +135,7 @@ do_ls(argc, argv)
printf("\n%s:\n", name);
while ((dp = readdir(dirp)) != NULL) {
-
+
if ((dp->d_name[0] == '.') && !(flags & LSF_ALL))
continue;
diff --git a/package/sash/src/ps.c b/package/sash/src/ps.c
index cc31d2398..610650ec6 100644
--- a/package/sash/src/ps.c
+++ b/package/sash/src/ps.c
@@ -75,20 +75,20 @@ do_ps(argc, argv)
#if 0
fclose(stdin);
-#endif
+#endif
printf(" PID PORT STAT SIZE SHARED %%CPU COMMAND\n"/*, _vfprintf_fp_ref, _vfscanf_fp_ref*/);
h = open("/proc/uptime", O_RDONLY);
-
+
if (h==-1) {
perror("Unable to open /proc/uptime\n");
return;
}
-
+
l = read(h, psbuf, 255);
- close(h);
+ close(h);
if (l<=0) {
@@ -99,56 +99,56 @@ do_ps(argc, argv)
psbuf[l] = '\0';
psbuf[255] = '\0';
-
+
ext = psbuf;
uptime_secs = atol(ext);
-
+
time_now = time(0);
-
+
d = opendir("/proc");
if (!d)
return;
-
+
while (de = readdir(d)) {
-
-
+
+
for(i=0;i<strlen(de->d_name);i++)
if (!isdigit(de->d_name[i]))
goto next;
sprintf(psbuf, "/proc/%s/stat", de->d_name);
-
+
h = open(psbuf, O_RDONLY);
-
+
if (h==-1)
continue;
-
+
l = read(h, psbuf, 255);
if (l<=0) {
perror("Unable to read status");
close(h);
continue;
}
-
+
psbuf[l] = '\0';
psbuf[255] = '\0';
-
+
ext = strrchr(psbuf, ')');
ext[0] = '\0';
statec = ext[2];
ext += 4;
-
+
ppid = atoi(ext);
ext = strchr(ext, ' ')+1;
pgrp = atoi(ext);
ext = strchr(ext, ' ')+1;
-
+
session = atoi(ext);
ext = strchr(ext, ' ')+1;
@@ -158,7 +158,7 @@ do_ps(argc, argv)
//printf("1|%s\n", ext);
//tpgid
ext = strchr(ext, ' ')+1;
-
+
//printf("2|%s\n", ext);
//flags
ext = strchr(ext, ' ')+1;
@@ -186,7 +186,7 @@ do_ps(argc, argv)
//printf("8|%s\n", ext);
stime = atoi(ext);
ext = strchr(ext, ' ')+1;
-
+
//printf("9|%s\n", ext);
//cutime
ext = strchr(ext, ' ')+1;
@@ -194,13 +194,13 @@ do_ps(argc, argv)
//printf("10|%s\n", ext);
//cstime
ext = strchr(ext, ' ')+1;
-
+
//priority
ext = strchr(ext, ' ')+1;
-
+
//nice
ext = strchr(ext, ' ')+1;
-
+
//timeout
ext = strchr(ext, ' ')+1;
@@ -208,26 +208,26 @@ do_ps(argc, argv)
ext = strchr(ext, ' ')+1;
start_time = atoi(ext);
-
+
ext = strchr(psbuf, '(');
ext++;
strcpy(name, ext);
-
+
pid = atoi(psbuf);
-
-
+
+
state = statec;
-
+
close(h);
-
+
dev_to_name(tty, tty_name);
-
+
bytes = 0;
sbytes = 0;
sprintf(psbuf, "/proc/%s/status", de->d_name);
f = fopen(psbuf, "r");
-
+
if (f) {
while (fgets(psbuf, 250, f)) {
if (strncmp(psbuf, "Mem:", 4) == 0) {
@@ -242,53 +242,53 @@ do_ps(argc, argv)
}
fclose(f);
}
-
+
seconds = ((uptime_secs * (long)HZ) - start_time) / HZ;
-
+
/*printf("seconds=%s\n", gcvt(seconds, 15, psbuf));*/
-
+
start = time_now - seconds;
-
+
/*
printf("1\n");
gcvt(start, 15, psbuf);
printf("2\n");
-
+
printf("start=%s\n", psbuf);
-
+
printf("utime=%d, stime=%d. start_time=%d\n", utime, stime, start_time);
*/
-
+
total_time = (utime + stime);
/*printf("total_time=%s\n", gcvt(total_time, 15, psbuf));*/
- pcpu = seconds ?
+ pcpu = seconds ?
(total_time * 10.0f * 100.0f / (float)HZ) / seconds :
- 0;
+ 0;
if (pcpu > 999) pcpu = 999;
sprintf(psbuf, "/proc/%s/cmdline", de->d_name);
h = open(psbuf, O_RDONLY);
-
+
if (h == -1) {
perror("Unable to open cmdline");
continue;
}
-
+
l = read(h, psbuf, 255);
if (l < 0) {
perror("Unable to read cmdline");
close(h);
continue;
}
-
+
close(h);
-
+
/*
* the args are NUL separated, substitute spaces instead
*/
@@ -301,14 +301,13 @@ do_ps(argc, argv)
psbuf[i] = ' ';
printf("%5d %4s %c %4ldK %3ldK %2u.%u %s\n", pid, tty_name, state,
- bytes, sbytes,
- pcpu / 10, pcpu % 10,
+ bytes, sbytes,
+ pcpu / 10, pcpu % 10,
/*(int)seconds / 60, (int)seconds % 60,*/
l ? psbuf : name);
next:
;
}
-
+
closedir(d);
}
-
diff --git a/package/sash/src/reboot.c b/package/sash/src/reboot.c
index ec464a041..479673a35 100644
--- a/package/sash/src/reboot.c
+++ b/package/sash/src/reboot.c
@@ -34,7 +34,7 @@ int main(int argc, char *argv[])
int delay = 0; /* delay in seconds before rebooting */
int rc;
int force = 0;
-
+
while ((rc = getopt(argc, argv, "h?d:f")) > 0) {
switch (rc) {
case 'd':
@@ -54,20 +54,6 @@ int main(int argc, char *argv[])
if(delay > 0)
sleep(delay);
-#ifdef CONFIG_DISKtel
- printf("unmounting /home\n");
- if(umount("/home") != 0){
- printf("unmounting failed!!!\n");
- }
-#endif
-
-#ifdef CONFIG_USER_FLATFSD_FLATFSD
- if (!force) {
- /* Ask flatfsd to reboot us safely */
- execlp("flatfsd", "flatfsd", "-b", NULL);
- /* if this returns, then force a reboot */
- }
-#endif
kill(1, SIGTSTP);
sync();
@@ -83,4 +69,3 @@ int main(int argc, char *argv[])
reboot(0x01234567);
exit(0); /* Shrug */
}
-
diff --git a/package/sash/src/sash.c b/package/sash/src/sash.c
index 7fb3a39fb..463d70740 100644
--- a/package/sash/src/sash.c
+++ b/package/sash/src/sash.c
@@ -12,12 +12,6 @@
#include "sash.h"
-#ifndef CMD_HELP
-#define CMD_HELP
-#endif
-#undef INTERNAL_PATH_EXPANSION
-#define FAVOUR_EXTERNAL_COMMANDS
-
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
@@ -26,7 +20,7 @@
#include <sys/time.h>
#include <sys/wait.h>
-static char version[] = "1.1.1";
+static char version[] = "OpenADK";
extern int intflag;
@@ -42,14 +36,10 @@ typedef struct {
CMDTAB cmdtab[] = {
-/*
- "alias", "[name [command]]", do_alias,
- 1, MAXARGS,
-*/
"cd", "[dirname]", do_cd,
1, 2,
-
- "sleep", "seconds", do_sleep,
+
+ "sleep", "seconds", do_sleep,
1, 2,
"chgrp", "gid filename ...", do_chgrp,
@@ -67,21 +57,12 @@ CMDTAB cmdtab[] = {
"cp", "srcname ... destname", do_cp,
3, MAXARGS,
-/*
- "dd", "if=name of=name [bs=n] [count=n] [skip=n] [seek=n]", do_dd,
- 3, MAXARGS,
-*/
"df", "[file-system]", do_df,
1, 2,
- "echo", "[args] ...", do_echo,
+ "echo", "[args] ...", do_echo,
1, MAXARGS,
-/*
- "ed", "[filename]", do_ed,
- 1, 2,
-*/
-
"exec", "filename [args]", do_exec,
2, MAXARGS,
@@ -91,15 +72,8 @@ CMDTAB cmdtab[] = {
"free", "", do_free,
1, 1,
-/*
- "-grep", "[-in] word filename ...", do_grep,
- 3, MAXARGS,
-*/
-
-#ifdef CMD_HELP
"help", "", do_help,
1, MAXARGS,
-#endif
"hexdump", "[-s pos] filename", do_hexdump,
1, 4,
@@ -122,7 +96,7 @@ CMDTAB cmdtab[] = {
"mknod", "filename type major minor", do_mknod,
5, 5,
- "more", "filename ...", do_more,
+ "more", "filename ...", do_more,
2, MAXARGS,
"mount", "[-t type] devname dirname", do_mount,
@@ -155,16 +129,9 @@ CMDTAB cmdtab[] = {
"source", "filename", do_source,
2, 2,
- "sync", "", do_sync,
+ "sync", "", do_sync,
1, 1,
-/* "time", "", do_time,
- 1, 1,
-*/
-/*
- "tar", "[xtv]f devname filename ...", do_tar,
- 2, MAXARGS,
-*/
"touch", "filename ...", do_touch,
2, MAXARGS,
@@ -174,18 +141,9 @@ CMDTAB cmdtab[] = {
"umount", "filename", do_umount,
2, 2,
-/*
- "unalias", "name", do_unalias,
- 2, 2,
-*/
-#ifdef CONFIG_USER_SASH_PS
"ps", "", do_ps,
1, MAXARGS,
-#endif
-/* "reboot", "", do_reboot,
- 1, MAXARGS,
-*/
"cat", "filename ...", do_cat,
2, MAXARGS,
@@ -217,11 +175,6 @@ static void catchquit();
static void catchchild();
static void readfile();
static void command();
-#ifdef COMMAND_HISTORY
-#define do_command(c,h) command(c,h)
-#else
-#define do_command(c,h) command(c)
-#endif
static void runcmd();
static void showprompt();
static BOOL trybuiltin();
@@ -230,12 +183,6 @@ static ALIAS *findalias();
extern char ** environ;
-/*
-char text1[] = "Text";
-char * text2 = text1;
-char ** text3 = &text2;
-*/
-
char buf[CMDLEN];
int exit_code = 0;
@@ -246,9 +193,8 @@ int main(argc, argv, env)
{
struct sigaction act;
char *cp;
-/* char buf[PATHLEN];*/
int dofile = 0;
-
+
if ((argc > 1) && !strcmp(argv[1], "-c")) {
/* We are that fancy a shell */
buf[0] = '\0';
@@ -257,11 +203,10 @@ int main(argc, argv, env)
if (dofile + 1 < argc)
strncat(buf, " ", sizeof(buf));
}
- do_command(buf, FALSE);
+ command(buf, FALSE);
exit(exit_code);
}
- //;'pa990523 +
if ((argc > 1) && strcmp(argv[1], "-t"))
{
dofile++;
@@ -280,29 +225,9 @@ int main(argc, argv, env)
sigaction(SIGCHLD, &act, NULL);
if (getenv("PATH") == NULL)
- putenv("PATH=/bin:/usr/bin:/etc:/sbin:/usr/sbin");
-
-/* cp = getenv("HOME");
- if (cp) {
- strcpy(buf, cp);
- strcat(buf, "/");
- strcat(buf, ".aliasrc");
+ putenv("PATH=/bin:/usr/bin:/sbin:/usr/sbin");
- if ((access(buf, 0) == 0) || (errno != ENOENT))
- readfile(buf);
- }
-*/
- //;'pa990523 -1/+
- //readfile(NULL);
- if (dofile)
- {
- //open the file for reading!
- readfile(argv[1]);
- }
- else
- {
- readfile(NULL); //no arguments!
- } //end if arguments supplied
+ readfile(dofile ? argv[1] : NULL);
exit(exit_code);
}
@@ -339,8 +264,6 @@ readfile(name)
while (TRUE) {
fflush(stdout);
- //;'pa990523 -1/+1
- //if (1)
if (fp == stdin) //using terminal, so show prompt
showprompt();
@@ -369,13 +292,12 @@ readfile(name)
ptr++;
}
if (*ptr != '#') {
- //;'pa990523 +
if (fp != stdin) {
//taking commands from file - echo
printf("Command: %s\n",buf);
} //end if (fp != stdin)
- do_command(buf, fp == stdin);
+ command(buf, fp == stdin);
}
}
@@ -388,11 +310,10 @@ readfile(name)
}
clearerr(fp);
- if (fp != stdin)
- {//;'pa990523 added braces and printf
+ if (fp != stdin) {
fclose(fp);
printf("Execution Finished, Exiting\n");
- } //end if (fp != stdin)
+ }
sourcecount--;
}
@@ -404,12 +325,8 @@ readfile(name)
* command is an alias, and expands wildcards.
*/
static void
-#ifdef COMMAND_HISTORY
command(cmd, do_history)
int do_history;
-#else
-command(cmd)
-#endif
char *cmd;
{
ALIAS *alias;
@@ -430,7 +347,6 @@ command(cmd)
while (isblank(*cmd))
cmd++;
-#ifdef COMMAND_HISTORY
if (do_history) {
int i;
static char *history[HISTORY_SIZE];
@@ -464,7 +380,6 @@ command(cmd)
history[0] = strdup(cmd);
}
}
-#endif
if (c = strchr(cmd, '&')) {
*c = '\0';
bg = 1;
@@ -473,7 +388,7 @@ command(cmd)
/* Set the last exit code */
setenv("?", last_exit_code, 1);
-
+
if ((cmd = expandenvvar(cmd)) == NULL)
return;
@@ -510,16 +425,14 @@ command(cmd)
return;
}
}
-
+
/*
* Now look for the command in the builtin table, and execute
* the command if found.
*/
-#ifdef FAVOUR_EXTERNAL_COMMANDS
if (!command_in_path(argv[0]))
-#endif
- if (trybuiltin(argc, argv))
- return;
+ if (trybuiltin(argc, argv))
+ return;
/*
* Not found, run the program along the PATH list.
@@ -528,7 +441,6 @@ command(cmd)
}
-#ifdef FAVOUR_EXTERNAL_COMMANDS
/*
* return true if we find this command in our
* path.
@@ -541,7 +453,7 @@ command_in_path(char *cmd)
if (strchr(cmd, '/') == 0) {
char * path;
static char path_copy[PATHLEN];
-
+
/* Search path for binary */
for (path = getenv("PATH"); path && *path; ) {
char * p2;
@@ -550,14 +462,14 @@ command_in_path(char *cmd)
if (p2 = strchr(path_copy, ':')) {
*p2 = '\0';
}
-
+
if (strlen(path_copy))
strcat(path_copy, "/");
strcat(path_copy, cmd);
-
+
if (!stat(path_copy, &stat_buf) && (stat_buf.st_mode & 0111))
return(TRUE);
-
+
p2 = strchr(path, ':');
if (p2)
path = p2 + 1;
@@ -568,7 +480,6 @@ command_in_path(char *cmd)
return(TRUE);
return(FALSE);
}
-#endif /* FAVOUR_EXTERNAL_COMMANDS */
/*
@@ -596,7 +507,7 @@ trybuiltin(argc, argv)
return FALSE;
} while (strcmp(argv[0], cmdptr->name));
-
+
/*
* Give a usage string if the number of arguments is too large
* or too small.
@@ -610,17 +521,6 @@ trybuiltin(argc, argv)
}
/*
- * Check here for several special commands which do not
- * have wildcarding done for them.
- */
-
-/* if (cmdptr->func == do_prompt) {
- (*cmdptr->func)(argc, argv);
- return TRUE;
- }
-*/
-
- /*
* Now for each command argument, see if it is a wildcard, and if
* so, replace the argument with the list of matching filenames.
*/
@@ -670,7 +570,6 @@ runcmd(cmd, bg, argc, argv)
char **argv;
{
register char * cp;
- BOOL magic;
int pid;
int status;
int oac;
@@ -680,40 +579,8 @@ runcmd(cmd, bg, argc, argv)
char *newargv[MAXARGS];
char *nametable[MAXARGS];
struct sigaction act;
-
+
newargv[0] = argv[0];
-
-#ifdef INTERNAL_PATH_EXPANSION
- if (strchr(argv[0], '/') == 0) {
- char * path;
- struct stat stat_buf;
- static char path_copy[PATHLEN];
-
- /* Search path for binary */
- for (path = getenv("PATH"); path && *path; ) {
- char * p2;
- strncpy(path_copy, path, sizeof(path_copy - 1));
- if (p2 = strchr(path_copy, ':')) {
- *p2 = '\0';
- }
-
- if (strlen(path_copy))
- strncat(path_copy, "/", sizeof(path_copy));
- strncat(path_copy, argv[0], sizeof(path_copy));
-
- if (!stat(path_copy, &stat_buf) && (stat_buf.st_mode & 0111)) {
- newargv[0] = path_copy;
- break;
- }
-
- p2 = strchr(path, ':');
- if (p2)
- path = p2 + 1;
- else
- path = 0;
- }
- }
-#endif
/*
* Now for each command argument, see if it is a wildcard, and if
@@ -744,43 +611,15 @@ runcmd(cmd, bg, argc, argv)
for (i = 0; i < matches; i++)
newargv[newargc++] = nametable[i];
}
-
- newargv[newargc] = 0;
-
- magic = FALSE;
-
- /*
- for (cp = cmd; *cp; cp++) {
- if ((*cp >= 'a') && (*cp <= 'z'))
- continue;
- if ((*cp >= 'A') && (*cp <= 'Z'))
- continue;
- if (isdecimal(*cp))
- continue;
- if (isblank(*cp))
- continue;
-
- if ((*cp == '.') || (*cp == '/') || (*cp == '-') ||
- (*cp == '+') || (*cp == '=') || (*cp == '_') ||
- (*cp == ':') || (*cp == ','))
- continue;
- magic = TRUE;
- }
- */
+ newargv[newargc] = 0;
- if (magic) {
- printf("%s: no such file or directory\n", cmd);
- system(cmd);
- return;
- }
-
if (!bg)
signal(SIGCHLD, SIG_DFL);
/*
- * No magic characters in the expanded command, so do the fork and
- * exec ourself. If this fails with ENOEXEC, then run the
+ * Do the fork and exec ourselves.
+ * If this fails with ENOEXEC, then run the
* shell anyway since it might be a shell script.
*/
if (!(pid = vfork())) {
@@ -791,16 +630,16 @@ runcmd(cmd, bg, argc, argv)
* We are the child, so run the program.
* First close any extra file descriptors we have opened.
* be sure not to modify any globals after the vfork !
- */
-
+ */
+
for (ci = 0; ci < sourcecount; ci++)
if (sourcefiles[ci] != stdin)
close(fileno(sourcefiles[ci]));
-
+
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
-
+
execvp(newargv[0], newargv);
ci = errno;
@@ -816,7 +655,7 @@ runcmd(cmd, bg, argc, argv)
_exit(ci == ENOENT ? 127 : 126);
}
-
+
if (pid < 0) {
memset(&act, 0, sizeof(act));
act.sa_handler = catchchild;
@@ -826,7 +665,7 @@ runcmd(cmd, bg, argc, argv)
perror("vfork failed");
return;
}
-
+
if (bg) {
printf("[%d]\n", pid);
return;
@@ -853,7 +692,7 @@ runcmd(cmd, bg, argc, argv)
memset(&act.sa_mask, 0, sizeof(act.sa_mask));
act.sa_flags = SA_RESTART;
sigaction(SIGCHLD, &act, NULL);
-
+
intcrlf = TRUE;
if (WIFEXITED(status)) {
@@ -865,12 +704,11 @@ runcmd(cmd, bg, argc, argv)
return;
}
-
+
perror(argv[0]);
exit(1);
}
-#ifdef CMD_HELP
void
do_help(argc, argv)
int argc;
@@ -881,94 +719,6 @@ do_help(argc, argv)
for (cmdptr = cmdtab; cmdptr->name && cmdptr->name[0]; cmdptr++)
printf("%-10s %s\n", cmdptr->name, cmdptr->usage);
}
-#endif /* CMD_HELP */
-
-#ifdef CMD_ALIAS
-void
-do_alias(argc, argv)
- int argc;
- char **argv;
-{
- char *name;
- char *value;
- ALIAS *alias;
- int count;
- char buf[CMDLEN];
-
- if (argc < 2) {
- count = aliascount;
- for (alias = aliastable; count-- > 0; alias++)
- printf("%s\t%s\n", alias->name, alias->value);
- return;
- }
-
- name = argv[1];
- if (argc == 2) {
- alias = findalias(name);
- if (alias)
- printf("%s\n", alias->value);
- else
- fprintf(stderr, "Alias \"%s\" is not defined\n", name);
- return;
- }
-
- if (strcmp(name, "alias") == 0) {
- fprintf(stderr, "Cannot alias \"alias\"\n");
- return;
- }
-
- if (!makestring(argc - 2, argv + 2, buf, CMDLEN))
- return;
-
- value = malloc(strlen(buf) + 1);
-
- if (value == NULL) {
- fprintf(stderr, "No memory for alias value\n");
- return;
- }
-
- strcpy(value, buf);
-
- alias = findalias(name);
- if (alias) {
- free(alias->value);
- alias->value = value;
- return;
- }
-
- if ((aliascount % ALIASALLOC) == 0) {
- count = aliascount + ALIASALLOC;
-
- if (aliastable)
- alias = (ALIAS *) realloc(aliastable,
- sizeof(ALIAS *) * count);
- else
- alias = (ALIAS *) malloc(sizeof(ALIAS *) * count);
-
- if (alias == NULL) {
- free(value);
- fprintf(stderr, "No memory for alias table\n");
- return;
- }
-
- aliastable = alias;
- }
-
- alias = &aliastable[aliascount];
-
- alias->name = malloc(strlen(name) + 1);
-
- if (alias->name == NULL) {
- free(value);
- fprintf(stderr, "No memory for alias name\n");
- return;
- }
-
- strcpy(alias->name, name);
- alias->value = value;
- aliascount++;
-}
-#endif /* CMD_ALIAS */
/*
* Look up an alias name, and return a pointer to it.
@@ -999,20 +749,6 @@ do_source(argc, argv)
readfile(argv[1]);
}
-/*void
-do_cd(argc, argv)
- int argc;
- char **argv;
-{
- char *name;
-
- name = argv[1];
-
- if (chdir(name))
- perror("Unable to chdir to %s");
-
-}*/
-
void
do_pid(argc, argv)
int argc;
@@ -1038,40 +774,6 @@ do_exec(argc, argv)
exit(1);
}
-/*void
-do_exit(argc, argv)
- int argc;
- char **argv;
-{
- if (argc>1)
- exit(atoi(argv[1]));
- else
- exit(0);
-}*/
-
-
-#ifdef CMD_ALIAS
-void
-do_unalias(argc, argv)
- int argc;
- char **argv;
-{
- ALIAS *alias;
-
- while (--argc > 0) {
- alias = findalias(*++argv);
- if (alias == NULL)
- continue;
-
- free(alias->name);
- free(alias->value);
- aliascount--;
- alias->name = aliastable[aliascount].name;
- alias->value = aliastable[aliascount].value;
- }
-}
-#endif /* CMD_ALIAS */
-
/*
* Display the prompt string.
*/
@@ -1079,9 +781,8 @@ static void
showprompt()
{
char *cp;
- //;'pa990523 changed from 6...
char buf[60];
-
+
if ((cp = getenv("PS1")) != NULL) {
printf("%s", cp);
}
@@ -1091,7 +792,7 @@ showprompt()
printf("%s> ", buf);
}
fflush(stdout);
-}
+}
static void
@@ -1123,18 +824,16 @@ catchchild()
char buf[40];
pid_t pid;
int status;
-
- /*signal(SIGCHLD, catchchild);*/ /* Unneeded */
pid = wait4(-1, &status, WUNTRACED, 0);
if (WIFSTOPPED(status))
sprintf(buf, "sh %d: Child %d stopped\n", getpid(), pid);
else
sprintf(buf, "sh %d: Child %d died\n", getpid(), pid);
-
+
if (intcrlf)
write(STDOUT, "\n", 1);
-
+
write(STDOUT, buf, strlen(buf));
}
diff --git a/package/sash/src/sash.h b/package/sash/src/sash.h
index eb2321fa0..2d272840a 100644
--- a/package/sash/src/sash.h
+++ b/package/sash/src/sash.h
@@ -12,16 +12,14 @@
#include <malloc.h>
#include <ctype.h>
-#define PATHLEN 256
+#define PATHLEN 256
#define CMDLEN 1024
-#define MAXARGS 50
+#define MAXARGS 50
#define ALIASALLOC 20
#define STDIN 0
#define STDOUT 1
#define MAXSOURCE 10
-#ifdef COMMAND_HISTORY
#define HISTORY_SIZE 20 /* Number of entries in command history */
-#endif
#ifndef isblank
#define isblank(ch) (((ch) == ' ') || ((ch) == '\t'))
@@ -38,14 +36,14 @@ typedef int BOOL;
#define TRUE ((BOOL) 1)
-extern void do_alias(), do_cd(), do_exec(), do_exit(), do_prompt();
-extern void do_source(), do_umask(), do_unalias(), do_help(), do_ln();
+extern void do_cd(), do_exec(), do_exit(), do_prompt();
+extern void do_source(), do_umask(), do_help(), do_ln();
extern void do_cp(), do_mv(), do_rm(), do_chmod(), do_mkdir(), do_rmdir();
extern void do_mknod(), do_chown(), do_chgrp(), do_sync(), do_printenv();
-extern void do_more(), do_cmp(), do_touch(), do_ls(), do_dd(), do_tar();
+extern void do_more(), do_cmp(), do_touch(), do_ls();
extern void do_mount(), do_umount(), do_setenv(), do_pwd(), do_echo();
-extern void do_kill(), do_grep(), do_ed(), do_hexdump(), do_pid();
-extern void do_df(), do_ps(), do_reboot(), do_cat(), do_time(), do_free();
+extern void do_kill(), do_hexdump(), do_pid();
+extern void do_df(), do_ps(), do_cat(), do_free();
extern void do_hostname(), do_sleep();
extern void do_date();
diff --git a/package/sash/src/shutdown.c b/package/sash/src/shutdown.c
index cc5ee8763..52d0530d8 100644
--- a/package/sash/src/shutdown.c
+++ b/package/sash/src/shutdown.c
@@ -41,7 +41,7 @@ main(argc, argv)
printf("Usage: %s [-d delay] -h|-r now\n", progname);
exit(0);
}
-
+
kill(1, SIGTSTP);
sync();
signal(SIGTERM,SIG_IGN);
@@ -53,13 +53,12 @@ main(argc, argv)
kill(-1, SIGKILL);
sync();
sleep(1);
-
+
if (strcmp(argv[1], "-h")==0) {
reboot(0xCDEF0123);
} else {
reboot(0x01234567);
}
-
+
exit(0); /* Shrug */
}
-