]> www.infradead.org Git - users/rw/ppcboot.git/commitdiff
More fixes for hush variable handling
authorwdenk <wdenk>
Thu, 6 Dec 2001 18:45:53 +0000 (18:45 +0000)
committerwdenk <wdenk>
Thu, 6 Dec 2001 18:45:53 +0000 (18:45 +0000)
common/cmd_autoscript.c
common/cmd_bootm.c
common/hush.c
common/main.c

index ec73a0221854a2151f7ea3490737155fc9a86aa8..ef614c67e237849958a64d022e3dc39783b645ff 100644 (file)
@@ -46,7 +46,7 @@
         (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
 
 #ifdef CFG_HUSH_PARSER
-extern int parse_string_outer(char *s);
+extern int parse_string_outer(char *s, int end);
 #endif
 
 extern image_header_t header;          /* from cmd_bootm.c */
@@ -118,7 +118,7 @@ autoscript(bd_t *bd, ulong addr)
 #ifndef CFG_HUSH_PARSER        
        rcode = run_command(cmd, bd, 0);
 #else
-       rcode = parse_string_outer(cmd);
+       rcode = parse_string_outer(cmd, 1);
 #endif 
        free(cmd);
        return rcode;
index 40f21bef7408f7e4d4aa1729a71fcdef6bc57227..058e18a05fdafa3bb5d51c0a927c2d00afcc97cf 100644 (file)
@@ -36,7 +36,7 @@
 #endif
 
 #ifdef CFG_HUSH_PARSER
-extern int parse_string_outer(char *s);
+extern int parse_string_outer(char *s, int end);
 #endif
 int  gunzip (void *, int, unsigned char *, int *);
 
@@ -56,10 +56,11 @@ static void print_type (image_header_t *hdr);
  *  - loaded (first part of) image to header load address,
  *  - disabled interrupts.
  */
-typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[],
-                         ulong      addr,      /* of image to boot */
-                         ulong     *len_ptr,   /* multi-file image length table */
-                         int        verify);   /* getenv("verify")[0] != 'n' */
+typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, bd_t *bd, int flag,
+                         int   argc, char *argv[],
+                         ulong addr,           /* of image to boot */
+                         ulong *len_ptr,       /* multi-file image length table */
+                         int   verify);        /* getenv("verify")[0] != 'n' */
 
 static boot_os_Fcn do_bootm_linux;
 static boot_os_Fcn do_bootm_netbsd;
@@ -237,7 +238,7 @@ int do_bootm (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
        case IH_OS_VXWORKS:
            do_bootm_vxworks (cmdtp, bd, flag, argc, argv,
-                              addr, len_ptr, verify);
+                             addr, len_ptr, verify);
            break;
 #endif /* CFG_CMD_ELF */
        }
@@ -250,10 +251,11 @@ int do_bootm (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
 }
 
 static void
-do_bootm_linux (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[],
-               ulong           addr,
-               ulong          *len_ptr,
-               int             verify)
+do_bootm_linux (cmd_tbl_t *cmdtp, bd_t *bd, int flag,
+               int     argc, char *argv[],
+               ulong   addr,
+               ulong   *len_ptr,
+               int     verify)
 {
        ulong   sp;
        ulong   len, checksum;
@@ -515,10 +517,11 @@ do_bootm_linux (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[],
 }
 
 static void
-do_bootm_netbsd (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[],
-               ulong           addr,
-               ulong          *len_ptr,
-               int             verify)
+do_bootm_netbsd (cmd_tbl_t *cmdtp, bd_t *bd, int flag,
+               int     argc, char *argv[],
+               ulong   addr,
+               ulong   *len_ptr,
+               int     verify)
 {
        image_header_t *hdr = &header;
 
@@ -564,8 +567,7 @@ do_bootm_netbsd (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[],
                        len += strlen (argv[i]) + 1;
                cmdline = malloc (len);
 
-               for (i=2, len=0 ; i<argc ; i+=1)
-               {
+               for (i=2, len=0 ; i<argc ; i+=1) {
                        if (i > 2)
                                cmdline[len++] = ' ';
                        strcpy (&cmdline[len], argv[i]);
@@ -601,7 +603,7 @@ int do_bootd (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
 #ifndef CFG_HUSH_PARSER          
        if (run_command (getenv ("bootcmd"), bd, flag) == -1) rcode = 1;
 #else
-        if (parse_string_outer(getenv("bootcmd")) != 0 ) rcode = 1;    
+       if (parse_string_outer(getenv("bootcmd"), 1) != 0 ) rcode = 1;
 #endif 
        return rcode;
 }
@@ -836,13 +838,13 @@ int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
 static void
 do_bootm_vxworks (cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[],
-                  ulong addr, ulong *len_ptr, int verify)
+                 ulong addr, ulong *len_ptr, int verify)
 {
        image_header_t *hdr = &header;
-        char str[80];
+       char str[80];
 
-        sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
-        setenv("loadaddr", str);
-        do_bootvx(cmdtp, bd, 0, 0, NULL);
+       sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
+       setenv("loadaddr", str);
+       do_bootvx(cmdtp, bd, 0, 0, NULL);
 }
 #endif /* CFG_CMD_ELF */
index d76aa3ebee8998d887689deb24bbe30f0995fa07..f08911cd298db0ea7e45ae56aa1957498631f020 100644 (file)
@@ -470,15 +470,14 @@ static int parse_string(o_string *dest, struct p_context *ctx, const char *src);
 #endif
 static int parse_stream(o_string *dest, struct p_context *ctx, struct in_str *input0, int end_trigger);
 /*   setup: */
+static int parse_stream_outer(struct in_str *inp, int end);
 #ifndef __PPCBOOT__
-static int parse_stream_outer(struct in_str *inp);
-static int parse_string_outer(const char *s);
+static int parse_string_outer(const char *s, int end);
 static int parse_file_outer(FILE *f);
 #else
-static int parse_stream_outer(struct in_str *inp, int end);
 int ppcboot_hush_start(bd_t *bd);
-int parse_string_outer(char *s);
-static int parse_file_outer(void);
+int parse_string_outer(char *s, int end);
+int parse_file_outer(void);
 #endif
 #ifndef __PPCBOOT__
 /*   job management: */
@@ -1586,19 +1585,34 @@ static int run_pipe_real(struct pipe *pi)
                }
                if (child->sp) {
                        char *p1 = NULL, *p2;
+                       int size = 0;
                        int len = 0;
-                       /* make new string for parser */
+                       /* Fake quotation marks surrounding the echo argument */
+                       if (!(strcmp(child->argv[i], "echo"))) {
+                               size++;
+                               if (!child->argv[i + 2]) size++;
+                       }
                        for (n = i; child->argv[n]; n++) {
                                p2 = insert_var_value(child->argv[n]);
-                               p1 = xrealloc(p1, (len + 2 + strlen(p2)));
-                               strcpy(p1 + len, p2);
-                               strcat(p1, " ");
-                               len = strlen(p1);
+                               p1 = xrealloc(p1, (len + 1 + strlen(p2)));
+                               if (len) {
+                                       strcat(p1, " ");
+                               } else {
+                                       *p1 = '\0';
+                               }
+                               if (n == i + 1 && size) strcat(p1, "\"");
+                               strcat(p1, p2);
+                               len = strlen(p1) + 2 + size;
                                if (p2 != child->argv[n]) free(p2);
                        }
-               parse_string_outer(p1);
-               free(p1);
-               return last_return_code;
+                       if (size) strcat(p1, "\"");
+                       while ((p2 = strchr(p1, '\n'))) {
+                               *p2 = ' ';
+                       }
+                       strcat(p1, "\n");
+                       parse_string_outer(p1, 1);
+                       free(p1);
+                       return last_return_code;
                }
 #ifndef __PPCBOOT__                            
                for (x = bltins; x->cmd; x++) {
@@ -1755,7 +1769,7 @@ static int run_list_real(struct pipe *pi)
                if ((rpipe->r_mode == RES_IN ||
                    rpipe->r_mode == RES_FOR) &&
                    (rpipe->next == NULL)) {
-                               syntax();
+                               syntax();
 #ifdef __PPCBOOT__
                                flag_repeat = 0;
 #endif                         
@@ -1771,7 +1785,7 @@ static int run_list_real(struct pipe *pi)
                                flag_repeat = 0;
 #endif                         
                                return 1;
-           }
+               }
        }
        for (; pi; pi = (flag_restore != 0) ? rpipe : pi->next) {
                if (pi->r_mode == RES_WHILE || pi->r_mode == RES_UNTIL ||
@@ -3027,16 +3041,15 @@ void update_ifs_map(void)
 
 /* most recursion does not come through here, the exeception is
  * from builtin_source() */
-#ifndef __PPCBOOT__
-int parse_stream_outer(struct in_str *inp)
-#else
 int parse_stream_outer(struct in_str *inp, int end)
-#endif /* __PPCBOOT__ */
 {
 
        struct p_context ctx;
        o_string temp=NULL_O_STRING;
        int rcode;
+#ifdef __PPCBOOT__
+       int code;
+#endif
        do {
                initialize_context(&ctx);
                update_ifs_map();
@@ -3045,14 +3058,15 @@ int parse_stream_outer(struct in_str *inp, int end)
 #ifdef __PPCBOOT__             
                if (rcode == 1) flag_repeat = 0;
 #endif
-               if (rcode != 1) {
+               if (rcode != 1 && ctx.old_flag != 0) syntax();
+               if (rcode != 1 && ctx.old_flag == 0) {
                        done_word(&temp, &ctx);
                        done_pipe(&ctx,PIPE_SEQ);
 #ifndef __PPCBOOT__
                        run_list(ctx.list_head);
 #else
-                       rcode = run_list(ctx.list_head);
-                       if (rcode == -1) flag_repeat = 0;
+                       if (((code = run_list(ctx.list_head)) == -1)) 
+                           flag_repeat = 0;
 #endif
                } else {
                        if (ctx.old_flag != 0) {
@@ -3069,19 +3083,18 @@ int parse_stream_outer(struct in_str *inp, int end)
                        free_pipe_list(ctx.list_head,0);
                }
                b_free(&temp);
+       } while (rcode != -1 && end != 1);   /* loop on syntax errors, return on EOF */
 #ifndef __PPCBOOT__
-       } while (rcode != -1);   /* loop on syntax errors, return on EOF */
        return 0;
 #else
-       } while (end != 1);
-       return (rcode != 1) ? 0 : 1;
+       return (code != 0) ? 1 : 0;
 #endif /* __PPCBOOT__ */
 }
 
 #ifndef __PPCBOOT__
-static int parse_string_outer(const char *s)
+static int parse_string_outer(const char *s, int end)
 #else
-int parse_string_outer(char *s)
+int parse_string_outer(char *s, int end)
 #endif /* __PPCBOOT__ */
 {
        struct in_str input;
@@ -3089,28 +3102,24 @@ int parse_string_outer(char *s)
 #ifdef __PPCBOOT__
        if ( !s || !*s)
                return 1;
-       return parse_stream_outer(&input, 1);
-
-#else
-       return parse_stream_outer(&input);
-#endif /* __PPCBOOT__ */
+#endif
+       return parse_stream_outer(&input, end);
 }
 
 #ifndef __PPCBOOT__
 static int parse_file_outer(FILE *f)
 #else
-static int parse_file_outer(void)
+int parse_file_outer(void)
 #endif
 {
        int rcode;
        struct in_str input;
 #ifndef __PPCBOOT__    
        setup_file_in_str(&input, f);
-       rcode = parse_stream_outer(&input);
 #else
        setup_file_in_str(&input);
+#endif
        rcode = parse_stream_outer(&input, 0);
-#endif /* __PPCBOOT__ */
        return rcode;
 }
 
@@ -3126,8 +3135,7 @@ int ppcboot_hush_start(bd_t *bd)
        top_vars->next = 0;
        top_vars->flg_export = 0;
        top_vars->flg_read_only = 1;
-       parse_file_outer();
-       return 1;
+       return 0;
 }
 
 static void *xmalloc(size_t size) 
@@ -3240,7 +3248,7 @@ int hush_main(int argc, char **argv)
                                {
                                        global_argv = argv+optind;
                                        global_argc = argc-optind;
-                                       opt = parse_string_outer(optarg);
+                                       opt = parse_string_outer(optarg, 0);
                                        goto final_return;
                                }
                                break;
@@ -3341,7 +3349,7 @@ static char *insert_var_value(char *inp)
        }
        if (done) {
                res_str = xrealloc(res_str, (1 + res_str_len + strlen(inp)));
-               strcat(res_str, inp);
+               strcpy((res_str + res_str_len), inp);
        }
        return (res_str == NULL) ? inp : res_str;
 }
@@ -3351,10 +3359,11 @@ static char **make_list_in(char **inp, char *name)
        int len, i;
        int name_len = strlen(name);
        int n = 0;
-       char **list = NULL;
+       char **list;
        char *p1, *p2, *p3;
        
        /* create list of variable values */    
+       list = xmalloc(sizeof(*list));
        for (i = 0; inp[i]; i++) {
                p3 = insert_var_value(inp[i]);
                p1 = p3;
index d3c1861914751c5b71ec375a631d651a1dc83311..43867caa46a3bc9a7b5e2a9bcde519306a1f6149 100644 (file)
@@ -33,7 +33,8 @@
 
 #ifdef CFG_HUSH_PARSER  
 extern int ppcboot_hush_start(bd_t *bd);
-extern int parse_string_outer(char *s);
+extern int parse_file_outer(void);
+extern int parse_string_outer(char *s, int end);
 #endif
 
 static char * delete_char (char *buffer, char *p, int *colp, int *np, int plen);
@@ -210,13 +211,22 @@ void main_loop(bd_t *bd)
        char *p;
 #endif
 
+#ifdef CFG_HUSH_PARSER
+       ppcboot_hush_start(bd); 
+#endif
 
 #ifdef CONFIG_PREBOOT
        if ((p = getenv ("preboot")) != NULL) {
 # ifdef CONFIG_AUTOBOOT_KEYED
                int prev = disable_ctrlc(1);    /* disable Control C checking */
 # endif
+
+# ifndef CFG_HUSH_PARSER
                run_command (p, bd, 0);
+# else
+               parse_string_outer(p, 1);
+# endif
+
 # ifdef CONFIG_AUTOBOOT_KEYED
                disable_ctrlc(prev);    /* restore Control C checking */
 # endif
@@ -246,7 +256,13 @@ void main_loop(bd_t *bd)
 # ifdef CONFIG_AUTOBOOT_KEYED
                int prev = disable_ctrlc(1);    /* disable Control C checking */
 # endif
+
+# ifndef CFG_HUSH_PARSER
                run_command (s, bd, 0);
+# else
+               parse_string_outer(s, 1);
+# endif
+
 # ifdef CONFIG_AUTOBOOT_KEYED
                disable_ctrlc(prev);    /* restore Control C checking */
 # endif
@@ -257,7 +273,7 @@ void main_loop(bd_t *bd)
         * Main Loop for Monitor Command Processing
         */
 #ifdef CFG_HUSH_PARSER  
-       ppcboot_hush_start(bd); 
+       parse_file_outer();
        /* This point is never reached */
        for (;;);
 #else   
@@ -717,7 +733,7 @@ int do_run (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
 #ifndef CFG_HUSH_PARSER        
            if (run_command (getenv (argv[i]), bd, flag) != -1) ++rcode;
 #else      
-           if (parse_string_outer(getenv (argv[i])) == 0) ++rcode;
+           if (parse_string_outer(getenv (argv[i]), 1) == 0) ++rcode;
 #endif     
        }
        return ((rcode == i) ? 0 : 1);