fix typo in UnistallDev
[openwrt.git] / package / busybox / patches / 400-revert_awk_getopt.patch
index f7b1c18..9aa747b 100644 (file)
@@ -1,37 +1,45 @@
 diff -ur busybox.old/editors/awk.c busybox.dev/editors/awk.c
 diff -ur busybox.old/editors/awk.c busybox.dev/editors/awk.c
---- busybox.old/editors/awk.c  2006-12-27 05:56:50.000000000 +0100
-+++ busybox.dev/editors/awk.c  2007-01-01 23:12:04.000000000 +0100
-@@ -2634,8 +2634,6 @@
+--- busybox.old/editors/awk.c  2007-01-19 22:23:12.000000000 +0100
++++ busybox.dev/editors/awk.c  2007-01-26 20:09:45.000000000 +0100
+@@ -2639,14 +2639,13 @@
  
  int awk_main(int argc, char **argv)
  {
 -      unsigned opt;
 -      char *opt_F, *opt_v, *opt_W;
  
  int awk_main(int argc, char **argv)
  {
 -      unsigned opt;
 -      char *opt_F, *opt_v, *opt_W;
-       char *s, *s1;
-       int i, j, c, flen;
+       int i, j, flen;
        var *v;
        var *v;
-@@ -2691,32 +2689,44 @@
+       var tv;
+       char **envp;
+       char *vnames = (char *)vNames; /* cheat */
+       char *vvalues = (char *)vValues;
++      int c;
+       /* Undo busybox.c, or else strtod may eat ','! This breaks parsing:
+        * $1,$2 == '$1,' '$2', NOT '$1' ',' '$2' */
+@@ -2694,40 +2693,54 @@
                free(s);
        }
  
 -      opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
                free(s);
        }
  
 -      opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
+-      argv += optind;
+-      argc -= optind;
 -      if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
 -      if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v
 -      if (opt & 0x4) { // -f
 -      if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
 -      if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v
 -      if (opt & 0x4) { // -f
--              from_file = TRUE;
--              F = afopen(programname, "r");
--              s = NULL;
+-              char *s = s; /* die, gcc, die */
+-              FILE *from_file = afopen(programname, "r");
 -              /* one byte is reserved for some trick in next_token */
 -              /* one byte is reserved for some trick in next_token */
--              if (fseek(F, 0, SEEK_END) == 0) {
--                      flen = ftell(F);
--                      s = (char *)xmalloc(flen+4);
--                      fseek(F, 0, SEEK_SET);
--                      i = 1 + fread(s+1, 1, flen, F);
+-              if (fseek(from_file, 0, SEEK_END) == 0) {
+-                      flen = ftell(from_file);
+-                      s = xmalloc(flen + 4);
+-                      fseek(from_file, 0, SEEK_SET);
+-                      i = 1 + fread(s + 1, 1, flen, from_file);
 -              } else {
 -              } else {
--                      for (i=j=1; j>0; i+=j) {
--                              s = (char *)xrealloc(s, i+4096);
--                              j = fread(s+i, 1, 4094, F);
--                      }
+-                      for (i = j = 1; j > 0; i += j) {
+-                              s = xrealloc(s, i + 4096);
+-                              j = fread(s + i, 1, 4094, from_file);
++      programname = NULL;
 +      while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) {
 +              switch (c) {
 +                      case 'F':
 +      while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) {
 +              switch (c) {
 +                      case 'F':
@@ -41,10 +49,9 @@ diff -ur busybox.old/editors/awk.c busybox.dev/editors/awk.c
 +                              if (! is_assignment(optarg))
 +                                      bb_show_usage();
 +                              break;
 +                              if (! is_assignment(optarg))
 +                                      bb_show_usage();
 +                              break;
-+                      case 'f':
-+                              from_file = TRUE;
-+                              F = afopen(programname = optarg, "r");
-+                              s = NULL;
++                      case 'f': {
++                              FILE *F = afopen(programname = optarg, "r");
++                              char *s = NULL;
 +                              /* one byte is reserved for some trick in next_token */
 +                              if (fseek(F, 0, SEEK_END) == 0) {
 +                                      flen = ftell(F);
 +                              /* one byte is reserved for some trick in next_token */
 +                              if (fseek(F, 0, SEEK_END) == 0) {
 +                                      flen = ftell(F);
@@ -62,6 +69,7 @@ diff -ur busybox.old/editors/awk.c busybox.dev/editors/awk.c
 +                              parse_program(s+1);
 +                              free(s);
 +                              break;
 +                              parse_program(s+1);
 +                              free(s);
 +                              break;
+                       }
 +                      case 'W':
 +                              bb_error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
 +                              break;
 +                      case 'W':
 +                              bb_error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
 +                              break;
@@ -70,12 +78,25 @@ diff -ur busybox.old/editors/awk.c busybox.dev/editors/awk.c
 +                              bb_show_usage();
                }
 -              s[i] = '\0';
 +                              bb_show_usage();
                }
 -              s[i] = '\0';
--              fclose(F);
--              parse_program(s+1);
+-              fclose(from_file);
+-              parse_program(s + 1);
 -              free(s);
 -              free(s);
+-      } else { // no -f: take program from 1st parameter
+-              if (!argc)
+-                      bb_show_usage();
++      }
++      argc -= optind;
++      argv += optind;
++
++      if (!programname) {
+               programname = "cmd. line";
+               parse_program(*argv++);
+               argc--;
        }
 -      if (opt & 0x8) // -W
 -              bb_error_msg("warning: unrecognized option '-W %s' ignored", opt_W);
        }
 -      if (opt & 0x8) // -W
 -              bb_error_msg("warning: unrecognized option '-W %s' ignored", opt_W);
-       if (!from_file) {
-               if (argc == optind)
+-
++      
+       /* fill in ARGV array */
+       setvar_i(V[ARGC], argc + 1);
+       setari_u(V[ARGV], 0, "awk");
This page took 0.024635 seconds and 4 git commands to generate.