mirror of
https://github.com/sheumann/hush.git
synced 2024-05-28 21:41:30 +00:00
Add support for displaying prefixes as well as setting them with prefix builtin
This commit is contained in:
parent
0d0ec552b5
commit
46abe82986
89
shell/hush.c
89
shell/hush.c
|
@ -112,6 +112,7 @@
|
||||||
|
|
||||||
#ifdef __GNO__
|
#ifdef __GNO__
|
||||||
# include <gsos.h>
|
# include <gsos.h>
|
||||||
|
# include <orca.h>
|
||||||
# define setpgid setpgid_is_broken_on_gno_206
|
# define setpgid setpgid_is_broken_on_gno_206
|
||||||
/* setpgid is broken in GNO 2.0.6: It doesn't actually change the pgrp for
|
/* setpgid is broken in GNO 2.0.6: It doesn't actually change the pgrp for
|
||||||
* the process (but it does update the pgrp reference counts, effectively
|
* the process (but it does update the pgrp reference counts, effectively
|
||||||
|
@ -997,6 +998,9 @@ static const struct built_in_command bltins1[] = {
|
||||||
#endif
|
#endif
|
||||||
#if HUSH_DEBUG
|
#if HUSH_DEBUG
|
||||||
BLTIN("memleak" , builtin_memleak , NULL),
|
BLTIN("memleak" , builtin_memleak , NULL),
|
||||||
|
#endif
|
||||||
|
#ifdef __GNO__
|
||||||
|
BLTIN("prefix" , builtin_prefix , "Display or set GS/OS prefixes"),
|
||||||
#endif
|
#endif
|
||||||
BLTIN("read" , builtin_read , "Input into variable"),
|
BLTIN("read" , builtin_read , "Input into variable"),
|
||||||
#if ENABLE_HUSH_FUNCTIONS
|
#if ENABLE_HUSH_FUNCTIONS
|
||||||
|
@ -1016,9 +1020,6 @@ static const struct built_in_command bltins1[] = {
|
||||||
BLTIN("umask" , builtin_umask , "Set file creation mask"),
|
BLTIN("umask" , builtin_umask , "Set file creation mask"),
|
||||||
BLTIN("unset" , builtin_unset , "Unset variables"),
|
BLTIN("unset" , builtin_unset , "Unset variables"),
|
||||||
BLTIN("wait" , builtin_wait , "Wait for process"),
|
BLTIN("wait" , builtin_wait , "Wait for process"),
|
||||||
#ifdef __GNO__
|
|
||||||
BLTIN("prefix" , builtin_prefix , "Set GS/OS prefixes"),
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
/* For now, echo and test are unconditionally enabled.
|
/* For now, echo and test are unconditionally enabled.
|
||||||
* Maybe make it configurable? */
|
* Maybe make it configurable? */
|
||||||
|
@ -10009,33 +10010,85 @@ static int FAST_FUNC builtin_return(char **argv)
|
||||||
#ifdef __GNO__
|
#ifdef __GNO__
|
||||||
static int FAST_FUNC builtin_prefix(char **argv)
|
static int FAST_FUNC builtin_prefix(char **argv)
|
||||||
{
|
{
|
||||||
unsigned prefix;
|
int prefix = -2, maxprefix = 31; /* -2 means * prefix */
|
||||||
PrefixRecGS prefixrec;
|
PrefixRecGS prefixrec = {2};
|
||||||
|
int argc = 0;
|
||||||
|
|
||||||
if (!argv[1] || !argv[2] || argv[3]) {
|
while (argv[argc])
|
||||||
|
argc++;
|
||||||
|
|
||||||
|
if (argc > 3) {
|
||||||
bb_error_msg("%s: invalid arguments", argv[0]);
|
bb_error_msg("%s: invalid arguments", argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (argc >= 2) {
|
||||||
|
errno = 0;
|
||||||
|
if (strcmp(argv[1], "@") == 0) {
|
||||||
|
prefix = maxprefix = -1;
|
||||||
|
} else if (argc == 2 && strcmp(argv[1], "*") == 0) {
|
||||||
|
prefix = maxprefix = -2;
|
||||||
|
} else {
|
||||||
|
prefix = maxprefix = bb_strtoi(argv[1], NULL, 10);
|
||||||
|
if (errno || prefix > 31 || prefix < 0) {
|
||||||
|
bb_error_msg("%s: invalid prefix number '%s'", argv[0], argv[1]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
errno = 0;
|
if (argc == 3) {
|
||||||
prefix = bb_strtou(argv[1], NULL, 10);
|
/* set a prefix */
|
||||||
if (errno || prefix > 31) {
|
prefixrec.prefixNum = prefix;
|
||||||
bb_error_msg("%s: invalid prefix number '%s'", argv[0], argv[1]);
|
prefixrec.buffer.setPrefix = __C2GSMALLOC(argv[2]);
|
||||||
return EXIT_FAILURE;
|
if (prefixrec.buffer.setPrefix == NULL) {
|
||||||
|
bb_error_msg("%s: memory allocation failure", argv[0]);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPrefix(&prefixrec);
|
||||||
|
|
||||||
|
GIfree(prefixrec.buffer.setPrefix);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefixrec.pCount = 2;
|
/* get one or more prefixes */
|
||||||
prefixrec.prefixNum = prefix;
|
prefixrec.buffer.getPrefix = GOinit(8192, NULL);
|
||||||
prefixrec.buffer.setPrefix = __C2GSMALLOC(argv[2]);
|
if (prefixrec.buffer.getPrefix == NULL) {
|
||||||
if (prefixrec.buffer.setPrefix == NULL) {
|
|
||||||
bb_error_msg("%s: memory allocation failure", argv[0]);
|
bb_error_msg("%s: memory allocation failure", argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetPrefix(&prefixrec);
|
for (; prefix <= maxprefix; prefix++) {
|
||||||
|
if (prefix != -2) {
|
||||||
GIfree(prefixrec.buffer.setPrefix);
|
prefixrec.prefixNum = prefix;
|
||||||
|
GetPrefix(&prefixrec);
|
||||||
|
} else {
|
||||||
|
/* Abuse prefixrec as a parameter rec for GetBootVol */
|
||||||
|
prefixrec.prefixNum = 1; /* pCount */
|
||||||
|
GetBootVol(&prefixrec.prefixNum);
|
||||||
|
}
|
||||||
|
if (toolerror()) continue;
|
||||||
|
prefixrec.buffer.getPrefix->
|
||||||
|
bufString.text[prefixrec.buffer.getPrefix->bufString.length] = 0;
|
||||||
|
if (prefixrec.buffer.getPrefix->bufString.length > 0 || argc == 2) {
|
||||||
|
if (argc == 1) {
|
||||||
|
switch(prefix) {
|
||||||
|
case -2:
|
||||||
|
printf(" *: ");
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
printf(" @: ");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("%2i: ", prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
puts(prefixrec.buffer.getPrefix->bufString.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GOfree(prefixrec.buffer.getPrefix);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user