Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/editors/sed.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1125 by niro, Wed Aug 18 21:56:57 2010 UTC revision 1126 by niro, Wed Aug 18 22:00:28 2010 UTC
# Line 61  Line 61 
61  #include "libbb.h"  #include "libbb.h"
62  #include "xregex.h"  #include "xregex.h"
63    
64    enum {
65     OPT_in_place = 1 << 0,
66    };
67    
68  /* Each sed command turns into one of these structures. */  /* Each sed command turns into one of these structures. */
69  typedef struct sed_cmd_s {  typedef struct sed_cmd_s {
70   /* Ordered by alignment requirements: currently 36 bytes on x86 */   /* Ordered by alignment requirements: currently 36 bytes on x86 */
# Line 938  static void process_files(void) Line 942  static void process_files(void)
942    
943   if (matched) {   if (matched) {
944   /* once matched, "n,xxx" range is dead, disabling it */   /* once matched, "n,xxx" range is dead, disabling it */
945   if (sed_cmd->beg_line > 0)   if (sed_cmd->beg_line > 0
946     && !(option_mask32 & OPT_in_place) /* but not for -i */
947     ) {
948   sed_cmd->beg_line = -2;   sed_cmd->beg_line = -2;
949     }
950   sed_cmd->in_match = !(   sed_cmd->in_match = !(
951   /* has the ending line come, or is this a single address command? */   /* has the ending line come, or is this a single address command? */
952   (sed_cmd->end_line ?   (sed_cmd->end_line ?
# Line 985  static void process_files(void) Line 992  static void process_files(void)
992   }   }
993    
994   /* actual sedding */   /* actual sedding */
995     //bb_error_msg("pattern_space:'%s' next_line:'%s' cmd:%c",
996     //pattern_space, next_line, sed_cmd->cmd);
997   switch (sed_cmd->cmd) {   switch (sed_cmd->cmd) {
998    
999   /* Print line number */   /* Print line number */
# Line 1111  static void process_files(void) Line 1120  static void process_files(void)
1120   {   {
1121   int len;   int len;
1122   /* If no next line, jump to end of script and exit. */   /* If no next line, jump to end of script and exit. */
1123     /* http://www.gnu.org/software/sed/manual/sed.html:
1124     * "Most versions of sed exit without printing anything
1125     * when the N command is issued on the last line of
1126     * a file. GNU sed prints pattern space before exiting
1127     * unless of course the -n command switch has been
1128     * specified. This choice is by design."
1129     */
1130   if (next_line == NULL) {   if (next_line == NULL) {
1131   free(next_line);   //goto discard_line;
1132   next_line = NULL;   goto discard_commands; /* GNU behavior */
  goto discard_line;  
1133   }   }
1134   /* Append next_line, read new next_line. */   /* Append next_line, read new next_line. */
1135   len = strlen(pattern_space);   len = strlen(pattern_space);
# Line 1270  static void add_cmd_block(char *cmdstr) Line 1285  static void add_cmd_block(char *cmdstr)
1285  int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;  int sed_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
1286  int sed_main(int argc UNUSED_PARAM, char **argv)  int sed_main(int argc UNUSED_PARAM, char **argv)
1287  {  {
  enum {  
  OPT_in_place = 1 << 0,  
  };  
1288   unsigned opt;   unsigned opt;
1289   llist_t *opt_e, *opt_f;   llist_t *opt_e, *opt_f;
1290   int status = EXIT_SUCCESS;   int status = EXIT_SUCCESS;
# Line 1292  int sed_main(int argc UNUSED_PARAM, char Line 1304  int sed_main(int argc UNUSED_PARAM, char
1304   opt_e = opt_f = NULL;   opt_e = opt_f = NULL;
1305   opt_complementary = "e::f::" /* can occur multiple times */   opt_complementary = "e::f::" /* can occur multiple times */
1306                      "nn"; /* count -n */                      "nn"; /* count -n */
1307     /* -i must be first, to match OPT_in_place definition */
1308   opt = getopt32(argv, "irne:f:", &opt_e, &opt_f,   opt = getopt32(argv, "irne:f:", &opt_e, &opt_f,
1309      &G.be_quiet); /* counter for -n */      &G.be_quiet); /* counter for -n */
1310   //argc -= optind;   //argc -= optind;

Legend:
Removed from v.1125  
changed lines
  Added in v.1126