mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
msh: smallish code shrinkage; cosmetics
This commit is contained in:
parent
32b633aa3f
commit
95cb3263ae
126
shell/msh.c
126
shell/msh.c
@ -13,8 +13,8 @@
|
|||||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# include <sys/times.h>
|
#include <sys/times.h>
|
||||||
# include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
#ifdef STANDALONE
|
#ifdef STANDALONE
|
||||||
# ifndef _GNU_SOURCE
|
# ifndef _GNU_SOURCE
|
||||||
@ -291,15 +291,10 @@ static char flags['z' - 'a' + 1];
|
|||||||
/* this looks weird, but is OK ... we index flag with 'a'...'z' */
|
/* this looks weird, but is OK ... we index flag with 'a'...'z' */
|
||||||
static char *flag = flags - 'a';
|
static char *flag = flags - 'a';
|
||||||
|
|
||||||
static char *null; /* null value for variable */
|
|
||||||
static int intr; /* interrupt pending */
|
|
||||||
|
|
||||||
/* moved to G: static char *trap[_NSIG + 1]; */
|
/* moved to G: static char *trap[_NSIG + 1]; */
|
||||||
/* moved to G: static char ourtrap[_NSIG + 1]; */
|
/* moved to G: static char ourtrap[_NSIG + 1]; */
|
||||||
static int trapset; /* trap pending */
|
static int trapset; /* trap pending */
|
||||||
|
|
||||||
static int heedint; /* heed interrupt signals */
|
|
||||||
|
|
||||||
static int yynerrs; /* yacc */
|
static int yynerrs; /* yacc */
|
||||||
|
|
||||||
/* moved to G: static char line[LINELIM]; */
|
/* moved to G: static char line[LINELIM]; */
|
||||||
@ -615,55 +610,54 @@ struct res {
|
|||||||
int r_val;
|
int r_val;
|
||||||
};
|
};
|
||||||
static const struct res restab[] = {
|
static const struct res restab[] = {
|
||||||
{"for", FOR},
|
{ "for" , FOR },
|
||||||
{"case", CASE},
|
{ "case" , CASE },
|
||||||
{"esac", ESAC},
|
{ "esac" , ESAC },
|
||||||
{"while", WHILE},
|
{ "while", WHILE },
|
||||||
{"do", DO},
|
{ "do" , DO },
|
||||||
{"done", DONE},
|
{ "done" , DONE },
|
||||||
{"if", IF},
|
{ "if" , IF },
|
||||||
{"in", IN},
|
{ "in" , IN },
|
||||||
{"then", THEN},
|
{ "then" , THEN },
|
||||||
{"else", ELSE},
|
{ "else" , ELSE },
|
||||||
{"elif", ELIF},
|
{ "elif" , ELIF },
|
||||||
{"until", UNTIL},
|
{ "until", UNTIL },
|
||||||
{"fi", FI},
|
{ "fi" , FI },
|
||||||
{";;", BREAK},
|
{ ";;" , BREAK },
|
||||||
{"||", LOGOR},
|
{ "||" , LOGOR },
|
||||||
{"&&", LOGAND},
|
{ "&&" , LOGAND },
|
||||||
{"{", '{'},
|
{ "{" , '{' },
|
||||||
{"}", '}'},
|
{ "}" , '}' },
|
||||||
{".", DOT},
|
{ "." , DOT },
|
||||||
{0, 0},
|
{ NULL , 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct builtincmd {
|
struct builtincmd {
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*builtinfunc) (struct op * t);
|
int (*builtinfunc)(struct op *t);
|
||||||
};
|
};
|
||||||
static const struct builtincmd builtincmds[] = {
|
static const struct builtincmd builtincmds[] = {
|
||||||
{".", dodot},
|
{ "." , dodot },
|
||||||
{":", dolabel},
|
{ ":" , dolabel },
|
||||||
{"break", dobreak},
|
{ "break" , dobreak },
|
||||||
{"cd", dochdir},
|
{ "cd" , dochdir },
|
||||||
{"continue", docontinue},
|
{ "continue", docontinue },
|
||||||
{"eval", doeval},
|
{ "eval" , doeval },
|
||||||
{"exec", doexec},
|
{ "exec" , doexec },
|
||||||
{"exit", doexit},
|
{ "exit" , doexit },
|
||||||
{"export", doexport},
|
{ "export" , doexport },
|
||||||
{"help", dohelp},
|
{ "help" , dohelp },
|
||||||
{"login", dologin},
|
{ "login" , dologin },
|
||||||
{"newgrp", dologin},
|
{ "newgrp" , dologin },
|
||||||
{"read", doread},
|
{ "read" , doread },
|
||||||
{"readonly", doreadonly},
|
{ "readonly", doreadonly },
|
||||||
{"set", doset},
|
{ "set" , doset },
|
||||||
{"shift", doshift},
|
{ "shift" , doshift },
|
||||||
{"times", dotimes},
|
{ "times" , dotimes },
|
||||||
{"trap", dotrap},
|
{ "trap" , dotrap },
|
||||||
{"umask", doumask},
|
{ "umask" , doumask },
|
||||||
{"wait", dowait},
|
{ "wait" , dowait },
|
||||||
{0, 0}
|
{ NULL , NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct op *scantree(struct op *);
|
static struct op *scantree(struct op *);
|
||||||
@ -697,11 +691,11 @@ static struct var *path; /* search path for commands */
|
|||||||
static struct var *shell; /* shell to interpret command files */
|
static struct var *shell; /* shell to interpret command files */
|
||||||
static struct var *ifs; /* field separators */
|
static struct var *ifs; /* field separators */
|
||||||
|
|
||||||
static int areanum; /* current allocation area */
|
static int areanum; /* current allocation area */
|
||||||
static int intr;
|
static int intr; /* interrupt pending */
|
||||||
static int inparse;
|
static int inparse;
|
||||||
static char *null = (char*)"";
|
static char *null = (char*)""; /* null value for variable */
|
||||||
static int heedint = 1;
|
static int heedint = 1; /* heed interrupt signals */
|
||||||
static void (*qflag) (int) = SIG_IGN;
|
static void (*qflag) (int) = SIG_IGN;
|
||||||
static int startl;
|
static int startl;
|
||||||
static int peeksym;
|
static int peeksym;
|
||||||
@ -2693,7 +2687,7 @@ typedef int (*builtin_func_ptr)(struct op *);
|
|||||||
static builtin_func_ptr inbuilt(const char *s) {
|
static builtin_func_ptr inbuilt(const char *s) {
|
||||||
const struct builtincmd *bp;
|
const struct builtincmd *bp;
|
||||||
|
|
||||||
for (bp = builtincmds; bp->name != NULL; bp++)
|
for (bp = builtincmds; bp->name; bp++)
|
||||||
if (strcmp(bp->name, s) == 0)
|
if (strcmp(bp->name, s) == 0)
|
||||||
return bp->builtinfunc;
|
return bp->builtinfunc;
|
||||||
|
|
||||||
@ -3191,29 +3185,27 @@ static int dohelp(struct op *t)
|
|||||||
puts("\nBuilt-in commands:\n"
|
puts("\nBuilt-in commands:\n"
|
||||||
"-------------------");
|
"-------------------");
|
||||||
|
|
||||||
for (col = 0, x = builtincmds; x->builtinfunc != NULL; x++) {
|
col = 0;
|
||||||
if (!x->name)
|
x = builtincmds;
|
||||||
continue;
|
while (x->name) {
|
||||||
col += printf("%s%s", ((col == 0) ? "\t" : " "), x->name);
|
col += printf("%c%s", ((col == 0) ? '\t' : ' '), x->name);
|
||||||
if (col > 60) {
|
if (col > 60) {
|
||||||
puts("");
|
puts("");
|
||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
|
x++;
|
||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_SH_STANDALONE_SHELL
|
#if ENABLE_FEATURE_SH_STANDALONE_SHELL
|
||||||
{
|
{
|
||||||
int i;
|
const struct BB_applet *applet = applets;
|
||||||
const struct BB_applet *applet;
|
|
||||||
|
|
||||||
for (i = 0, applet = applets; i < NUM_APPLETS; applet++, i++) {
|
while (applet->name) {
|
||||||
if (!applet->name)
|
col += printf("%c%s", ((col == 0) ? '\t' : ' '), applet->name);
|
||||||
continue;
|
|
||||||
|
|
||||||
col += printf("%s%s", ((col == 0) ? "\t" : " "), applet->name);
|
|
||||||
if (col > 60) {
|
if (col > 60) {
|
||||||
puts("");
|
puts("");
|
||||||
col = 0;
|
col = 0;
|
||||||
}
|
}
|
||||||
|
applet++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -3221,8 +3213,6 @@ static int dohelp(struct op *t)
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int dolabel(struct op *t)
|
static int dolabel(struct op *t)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user