diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-05-08 22:17:23 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-05-08 22:17:23 +0000 |
commit | 3c1f902d48dacded4e60c0607c7abb0a275390fd (patch) | |
tree | 45b0e77e474c8a7c3e34e6e5756b947754238b09 | |
parent | 686bbd477fca7d3074ca34e999fd43873a0f7ecf (diff) | |
download | busybox-w32-3c1f902d48dacded4e60c0607c7abb0a275390fd.tar.gz busybox-w32-3c1f902d48dacded4e60c0607c7abb0a275390fd.tar.bz2 busybox-w32-3c1f902d48dacded4e60c0607c7abb0a275390fd.zip |
Move sed over to the generic llist_t for append. Saves about 90 bytes.
git-svn-id: svn://busybox.net/trunk/busybox@15040 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | editors/sed.c | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/editors/sed.c b/editors/sed.c index 44e86e245..a3b825028 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -116,11 +116,7 @@ static sed_cmd_t sed_cmd_head; | |||
116 | static sed_cmd_t *sed_cmd_tail = &sed_cmd_head; | 116 | static sed_cmd_t *sed_cmd_tail = &sed_cmd_head; |
117 | 117 | ||
118 | /* Linked list of append lines */ | 118 | /* Linked list of append lines */ |
119 | struct append_list { | 119 | static llist_t *append_head=NULL; |
120 | char *string; | ||
121 | struct append_list *next; | ||
122 | }; | ||
123 | static struct append_list *append_head=NULL, *append_tail=NULL; | ||
124 | 120 | ||
125 | void sed_free_and_close_stuff(void); | 121 | void sed_free_and_close_stuff(void); |
126 | #if ENABLE_FEATURE_CLEAN_UP | 122 | #if ENABLE_FEATURE_CLEAN_UP |
@@ -128,12 +124,7 @@ void sed_free_and_close_stuff(void) | |||
128 | { | 124 | { |
129 | sed_cmd_t *sed_cmd = sed_cmd_head.next; | 125 | sed_cmd_t *sed_cmd = sed_cmd_head.next; |
130 | 126 | ||
131 | while(append_head) { | 127 | llist_free_contents(append_head); |
132 | append_tail=append_head->next; | ||
133 | free(append_head->string); | ||
134 | free(append_head); | ||
135 | append_head=append_tail; | ||
136 | } | ||
137 | 128 | ||
138 | while (sed_cmd) { | 129 | while (sed_cmd) { |
139 | sed_cmd_t *sed_cmd_next = sed_cmd->next; | 130 | sed_cmd_t *sed_cmd_next = sed_cmd->next; |
@@ -691,28 +682,20 @@ static sed_cmd_t *branch_to(const char *label) | |||
691 | bb_error_msg_and_die("Can't find label for jump to `%s'", label); | 682 | bb_error_msg_and_die("Can't find label for jump to `%s'", label); |
692 | } | 683 | } |
693 | 684 | ||
694 | /* Append copy of string to append buffer */ | ||
695 | static void append(char *s) | 685 | static void append(char *s) |
696 | { | 686 | { |
697 | struct append_list *temp=calloc(1,sizeof(struct append_list)); | 687 | append_head=llist_add_to_end(append_head, bb_xstrdup(s)); |
698 | |||
699 | if(append_head) | ||
700 | append_tail=(append_tail->next=temp); | ||
701 | else append_head=append_tail=temp; | ||
702 | temp->string=strdup(s); | ||
703 | } | 688 | } |
704 | 689 | ||
705 | static void flush_append(void) | 690 | static void flush_append(void) |
706 | { | 691 | { |
692 | char *data; | ||
693 | |||
707 | /* Output appended lines. */ | 694 | /* Output appended lines. */ |
708 | while(append_head) { | 695 | while((data = (char *)llist_pop(&append_head))) { |
709 | fprintf(nonstdout,"%s\n",append_head->string); | 696 | fprintf(nonstdout,"%s\n",data); |
710 | append_tail=append_head->next; | 697 | free(data); |
711 | free(append_head->string); | ||
712 | free(append_head); | ||
713 | append_head=append_tail; | ||
714 | } | 698 | } |
715 | append_head=append_tail=NULL; | ||
716 | } | 699 | } |
717 | 700 | ||
718 | static void add_input_file(FILE *file) | 701 | static void add_input_file(FILE *file) |
@@ -1113,8 +1096,7 @@ int sed_main(int argc, char **argv) | |||
1113 | int status = EXIT_SUCCESS, opt, getpat = 1; | 1096 | int status = EXIT_SUCCESS, opt, getpat = 1; |
1114 | 1097 | ||
1115 | /* destroy command strings on exit */ | 1098 | /* destroy command strings on exit */ |
1116 | if (ENABLE_FEATURE_CLEAN_UP && atexit(sed_free_and_close_stuff) == -1) | 1099 | if (ENABLE_FEATURE_CLEAN_UP) atexit(sed_free_and_close_stuff); |
1117 | bb_perror_msg_and_die("atexit"); | ||
1118 | 1100 | ||
1119 | /* Lie to autoconf when it starts asking stupid questions. */ | 1101 | /* Lie to autoconf when it starts asking stupid questions. */ |
1120 | if(argc==2 && !strcmp(argv[1],"--version")) { | 1102 | if(argc==2 && !strcmp(argv[1],"--version")) { |