aboutsummaryrefslogtreecommitdiff
path: root/msh.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-07-07 00:05:55 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-07-07 00:05:55 +0000
commit9a44341db29815ac86af4c53a5c7401b912d13e3 (patch)
tree1089bdbb9d8a20b986300ba598f3e639e6a848ec /msh.c
parent42cb7c8d4e193d803a15549757c0b905dbe1ce1a (diff)
downloadbusybox-w32-9a44341db29815ac86af4c53a5c7401b912d13e3.tar.gz
busybox-w32-9a44341db29815ac86af4c53a5c7401b912d13e3.tar.bz2
busybox-w32-9a44341db29815ac86af4c53a5c7401b912d13e3.zip
Add in a shell tagline (per lash/hush behavior) to make it easier
to know which shell is in use. Add in 'help' to list available builtins, and fixup msh so it can do STANDALONE_SHELL. -Erik git-svn-id: svn://busybox.net/trunk/busybox@3025 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'msh.c')
-rw-r--r--msh.c128
1 files changed, 98 insertions, 30 deletions
diff --git a/msh.c b/msh.c
index 66c3d54d3..e85d6ff8f 100644
--- a/msh.c
+++ b/msh.c
@@ -497,6 +497,7 @@ static struct op **find1case (struct op *t, char *w );
497static struct op *findcase (struct op *t, char *w ); 497static struct op *findcase (struct op *t, char *w );
498static void brkset(struct brkcon *bc ); 498static void brkset(struct brkcon *bc );
499static int dolabel(void); 499static int dolabel(void);
500static int dohelp(void);
500static int dochdir(struct op *t ); 501static int dochdir(struct op *t );
501static int doshift(struct op *t ); 502static int doshift(struct op *t );
502static int dologin(struct op *t ); 503static int dologin(struct op *t );
@@ -592,30 +593,31 @@ static struct res restab[] = {
592}; 593};
593 594
594 595
595struct builtin { 596struct builtincmd {
596 char *command; 597 const char *name;
597 int (*fn)(); 598 int (*builtinfunc)();
598}; 599};
599static struct builtin builtin[] = { 600static const struct builtincmd builtincmds[] = {
601 {".", dodot},
600 {":", dolabel}, 602 {":", dolabel},
601 {"cd", dochdir},
602 {"shift", doshift},
603 {"exec", doexec},
604 {"wait", dowait},
605 {"read", doread},
606 {"eval", doeval},
607 {"trap", dotrap},
608 {"break", dobreak}, 603 {"break", dobreak},
604 {"cd", dochdir},
609 {"continue",docontinue}, 605 {"continue",docontinue},
606 {"eval", doeval},
607 {"exec", doexec},
610 {"exit", doexit}, 608 {"exit", doexit},
611 {"export", doexport}, 609 {"export", doexport},
612 {"readonly",doreadonly}, 610 {"help", dohelp},
613 {"set", doset},
614 {".", dodot},
615 {"umask", doumask},
616 {"login", dologin}, 611 {"login", dologin},
617 {"newgrp", dologin}, 612 {"newgrp", dologin},
613 {"read", doread},
614 {"readonly",doreadonly},
615 {"set", doset},
616 {"shift", doshift},
618 {"times", dotimes}, 617 {"times", dotimes},
618 {"trap", dotrap},
619 {"umask", doumask},
620 {"wait", dowait},
619 {0,0} 621 {0,0}
620}; 622};
621 623
@@ -731,14 +733,18 @@ extern int shell_main(int argc, char **argv)
731 setval(ifs, " \t\n"); 733 setval(ifs, " \t\n");
732 734
733 prompt = lookup("PS1"); 735 prompt = lookup("PS1");
736#ifdef BB_FEATURE_SH_FANCY_PROMPT
734 if (prompt->value == null) 737 if (prompt->value == null)
738#endif
735 setval(prompt, "$ "); 739 setval(prompt, "$ ");
736 if (geteuid() == 0) { 740 if (geteuid() == 0) {
737 setval(prompt, "# "); 741 setval(prompt, "# ");
738 prompt->status &= ~EXPORT; 742 prompt->status &= ~EXPORT;
739 } 743 }
740 cprompt = lookup("PS2"); 744 cprompt = lookup("PS2");
745#ifdef BB_FEATURE_SH_FANCY_PROMPT
741 if (cprompt->value == null) 746 if (cprompt->value == null)
747#endif
742 setval(cprompt, "> "); 748 setval(cprompt, "> ");
743 749
744 iof = filechar; 750 iof = filechar;
@@ -794,8 +800,11 @@ extern int shell_main(int argc, char **argv)
794 setdash(); 800 setdash();
795 if (e.iop < iostack) { 801 if (e.iop < iostack) {
796 PUSHIO(afile, 0, iof); 802 PUSHIO(afile, 0, iof);
797 if (isatty(0) && isatty(1) && !cflag) 803 if (isatty(0) && isatty(1) && !cflag) {
798 interactive++; 804 interactive++;
805 printf( "\n\n" BB_BANNER " Built-in shell (msh)\n");
806 printf( "Enter 'help' for a list of built-in commands.\n\n");
807 }
799 } 808 }
800 signal(SIGQUIT, qflag); 809 signal(SIGQUIT, qflag);
801 if (name && name[0] == '-') { 810 if (name && name[0] == '-') {
@@ -2314,14 +2323,14 @@ int act;
2314 switch(t->type) { 2323 switch(t->type) {
2315 case TPAREN: 2324 case TPAREN:
2316 case TCOM: 2325 case TCOM:
2317 { 2326 {
2318 int child; 2327 int child;
2319 rv = forkexec(t, pin, pout, act, wp, &child); 2328 rv = forkexec(t, pin, pout, act, wp, &child);
2320 if (child) { 2329 if (child) {
2321 exstat = rv; 2330 exstat = rv;
2322 leave(); 2331 leave();
2332 }
2323 } 2333 }
2324 }
2325 break; 2334 break;
2326 2335
2327 case TPIPE: 2336 case TPIPE:
@@ -2828,6 +2837,21 @@ char *c, **v, **envp;
2828 register char *sp, *tp; 2837 register char *sp, *tp;
2829 int eacces = 0, asis = 0; 2838 int eacces = 0, asis = 0;
2830 2839
2840#ifdef BB_FEATURE_SH_STANDALONE_SHELL
2841 char *name = c;
2842#ifdef BB_FEATURE_SH_APPLETS_ALWAYS_WIN
2843 name = get_last_path_component(name);
2844#endif
2845 optind = 1;
2846 if (find_applet_by_name(name)) {
2847 /* We have to exec here since we vforked. Running
2848 * run_applet_by_name() won't work and bad things
2849 * will happen. */
2850 execve("/proc/self/exe", v, envp);
2851 execve("busybox", v, envp);
2852 }
2853#endif
2854
2831 sp = any('/', c)? "": path->value; 2855 sp = any('/', c)? "": path->value;
2832 asis = *sp == '\0'; 2856 asis = *sp == '\0';
2833 while (asis || *sp != '\0') { 2857 while (asis || *sp != '\0') {
@@ -2842,6 +2866,8 @@ char *c, **v, **envp;
2842 *tp++ = '/'; 2866 *tp++ = '/';
2843 for (i = 0; (*tp++ = c[i++]) != '\0';) 2867 for (i = 0; (*tp++ = c[i++]) != '\0';)
2844 ; 2868 ;
2869
2870 fprintf(stderr, "calling exec\n");
2845 execve(e.linep, v, envp); 2871 execve(e.linep, v, envp);
2846 switch (errno) { 2872 switch (errno) {
2847 case ENOEXEC: 2873 case ENOEXEC:
@@ -2917,6 +2943,49 @@ int (*f)();
2917 * built-in commands: doX 2943 * built-in commands: doX
2918 */ 2944 */
2919 2945
2946static int dohelp()
2947{
2948 int col;
2949 const struct builtincmd *x;
2950
2951 printf("\nBuilt-in commands:\n");
2952 printf("-------------------\n");
2953
2954 for (col=0, x = builtincmds; x->builtinfunc != NULL; x++) {
2955 if (!x->name)
2956 continue;
2957 col += printf("%s%s", ((col == 0) ? "\t" : " "), x->name);
2958 if (col > 60) {
2959 printf("\n");
2960 col = 0;
2961 }
2962 }
2963#ifdef BB_FEATURE_SH_STANDALONE_SHELL
2964 {
2965 int i;
2966 const struct BB_applet *applet;
2967 extern const struct BB_applet applets[];
2968 extern const size_t NUM_APPLETS;
2969
2970 for (i=0, applet = applets; i < NUM_APPLETS; applet++, i++) {
2971 if (!applet->name)
2972 continue;
2973
2974 col += printf("%s%s", ((col == 0) ? "\t" : " "),
2975 applet->name);
2976 if (col > 60) {
2977 printf("\n");
2978 col = 0;
2979 }
2980 }
2981 }
2982#endif
2983 printf("\n\n");
2984 return EXIT_SUCCESS;
2985}
2986
2987
2988
2920static int 2989static int
2921dolabel() 2990dolabel()
2922{ 2991{
@@ -3341,7 +3410,6 @@ int out;
3341/* 3410/*
3342 * Copyright (c) 1999 Herbert Xu <herbert@debian.org> 3411 * Copyright (c) 1999 Herbert Xu <herbert@debian.org>
3343 * This file contains code for the times builtin. 3412 * This file contains code for the times builtin.
3344 * $Id: msh.c,v 1.1 2001/06/29 04:57:14 andersen Exp $
3345 */ 3413 */
3346static int dotimes () 3414static int dotimes ()
3347{ 3415{
@@ -3362,14 +3430,14 @@ static int dotimes ()
3362} 3430}
3363 3431
3364 3432
3365static int (*inbuilt(s))() 3433static int (*inbuilt(char *s))()
3366register char *s;
3367{ 3434{
3368 register struct builtin *bp; 3435 const struct builtincmd *bp;
3436
3437 for (bp = builtincmds; bp->name != NULL; bp++)
3438 if (strcmp(bp->name, s) == 0)
3439 return(bp->builtinfunc);
3369 3440
3370 for (bp = builtin; bp->command != NULL; bp++)
3371 if (strcmp(bp->command, s) == 0)
3372 return(bp->fn);
3373 return((int(*)())NULL); 3441 return((int(*)())NULL);
3374} 3442}
3375 3443