[Toybox] Moving to toys/posix and toys/lsb.

Roy Tam roytam at gmail.com
Sun Aug 26 18:54:10 PDT 2012


2012/8/26 Rob Landley <rob at landley.net>:
> I banged up a quick make/make.sh modification to handle commands in
> subdirectories, so menuconfig can show menus for "Posix", "LSB", and
> "Other". (Maybe Android at some point.)
>
> One technical limitation is that it's still more or less a flat
> namespace: having a toys/posix/command.c and toys/lsb/command.c with the
> same name would fight both at the .config level and in the final command
> list. Then again this never seemed to bother anyone elsewhere, so...
>
> It was getting a bit crowded.
>
> Rob

FYI: posix/sh.c CFG_TOYSH_* defines is not changed to CFG_SH_* after the move.
the following patch fixes it.

--- sh.c        2012-08-26 07:08:51.000000000 +0800
+++ sh.c       2012-08-27 09:51:53.000000000 +0800
@@ -219,11 +219,11 @@
 static char *parse_word(char *start, struct command **cmd)
 {
        char *end;

        // Detect end of line (and truncate line at comment)
-       if (CFG_TOYSH_PIPES && strchr("><&|(;", *start)) return 0;
+       if (CFG_SH_PIPES && strchr("><&|(;", *start)) return 0;

        // Grab next word.  (Add dequote and envvar logic here)
        end = start;
        while (*end && !isspace(*end)) end++;
        (*cmd)->argv[(*cmd)->argc++] = xstrndup(start, end-start);
@@ -245,20 +245,20 @@
        struct command **cmd = &(line->cmd);
        char *start = line->cmdline = cmdline;

        if (!cmdline) return 0;

-       if (CFG_TOYSH_JOBCTL) line->cmdline = cmdline;
+       if (CFG_SH_JOBCTL) line->cmdline = cmdline;

        // Parse command into argv[]
        for (;;) {
                char *end;

                // Skip leading whitespace and detect end of line.
                while (isspace(*start)) start++;
                if (!*start || *start=='#') {
-                       if (CFG_TOYSH_JOBCTL) line->cmdlinelen = start-cmdline;
+                       if (CFG_SH_JOBCTL) line->cmdlinelen = start-cmdline;
                        return 0;
                }

                // Allocate next command structure if necessary
                if (!*cmd) *cmd = xzalloc(sizeof(struct
command)+8*sizeof(char *));
@@ -266,11 +266,11 @@
                // Parse next argument and add the results to argv[]
                end = parse_word(start, cmd);

                // If we hit the end of this command, how did it end?
                if (!end) {
-                       if (CFG_TOYSH_PIPES && *start) {
+                       if (CFG_SH_PIPES && *start) {
                                if (*start==';') {
                                        start++;
                                        break;
                                }
                                // handle | & < > >> << || &&
@@ -278,11 +278,11 @@
                        break;
                }
                start = end;
        }

-       if (CFG_TOYSH_JOBCTL) line->cmdlinelen = start-cmdline;
+       if (CFG_SH_JOBCTL) line->cmdlinelen = start-cmdline;

        return start;
 }

 // Execute the commands in a pipeline
@@ -311,11 +311,11 @@

                cmd->pid = vfork();
                if (!cmd->pid) xexec(cmd->argv);
                else waitpid(cmd->pid, &status, 0);

-               if (CFG_TOYSH_FLOWCTL || CFG_TOYSH_PIPES) {
+               if (CFG_SH_FLOWCTL || CFG_SH_PIPES) {
                        if (WIFEXITED(status)) cmd->pid = WEXITSTATUS(status);
                        if (WIFSIGNALED(status)) cmd->pid = WTERMSIG(status);
                }
        }

@@ -368,11 +368,11 @@
 void sh_main(void)
 {
        FILE *f;

        // Set up signal handlers and grab control of this tty.
-       if (CFG_TOYSH_TTY) {
+       if (CFG_SH_TTY) {
                if (isatty(0)) toys.optflags |= 1;
        }
        f = *toys.optargs ? xfopen(*toys.optargs, "r") : NULL;
        if (TT.command) handle(TT.command);
        else {

 1346032450.0


More information about the Toybox mailing list