aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-11-24 07:34:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-11-24 07:34:42 +0000
commit00d8417631b1ae378d708e885dce74bafb02be96 (patch)
treee0537629e52b86a992f5e3abc45362bc07e620bb
parent4b5709496bb00301f4df6a8e3c0ced23b4d36603 (diff)
downloadbusybox-w32-00d8417631b1ae378d708e885dce74bafb02be96.tar.gz
busybox-w32-00d8417631b1ae378d708e885dce74bafb02be96.tar.bz2
busybox-w32-00d8417631b1ae378d708e885dce74bafb02be96.zip
vi: speedup and code shrink (Walter Harms)
networking/interface.c: silence warning (Vladimir) wget: more robust EINTR detection
-rw-r--r--editors/vi.c38
-rw-r--r--networking/interface.c2
-rw-r--r--networking/wget.c26
3 files changed, 32 insertions, 34 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 7f1d27fdf..7f5f2dcbc 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -662,7 +662,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present
662 c = c - 'a'; 662 c = c - 'a';
663 q = mark[(unsigned char) c]; 663 q = mark[(unsigned char) c];
664 if (q != NULL) { // is mark valid 664 if (q != NULL) { // is mark valid
665 *addr = count_lines(text, q); // count lines 665 *addr = count_lines(text, q);
666 } 666 }
667 } 667 }
668 } 668 }
@@ -1673,12 +1673,16 @@ static char *char_insert(char *p, char c) // insert the char c at 'p'
1673 } 1673 }
1674 if (autoindent && c == '\n') { // auto indent the new line 1674 if (autoindent && c == '\n') { // auto indent the new line
1675 char *q; 1675 char *q;
1676 1676 size_t len;
1677 q = prev_line(p); // use prev line as template 1677 q = prev_line(p); // use prev line as template
1678 for (; isblank(*q); q++) { 1678 len = strspn(q, " \t"); // space or tab
1679 uintptr_t bias = stupid_insert(p, *q); // insert the char 1679 if (len) {
1680 p += bias + 1; 1680 uintptr_t bias;
1681 bias = text_hole_make(p, len);
1682 p += bias;
1681 q += bias; 1683 q += bias;
1684 memcpy(p, q, len);
1685 p += len;
1682 } 1686 }
1683 } 1687 }
1684#endif 1688#endif
@@ -2042,7 +2046,7 @@ static uintptr_t string_insert(char *p, const char *s) // insert the string at '
2042 i = strlen(s); 2046 i = strlen(s);
2043 bias = text_hole_make(p, i); 2047 bias = text_hole_make(p, i);
2044 p += bias; 2048 p += bias;
2045 strncpy(p, s, i); 2049 memcpy(p, s, i);
2046#if ENABLE_FEATURE_VI_YANKMARK 2050#if ENABLE_FEATURE_VI_YANKMARK
2047 { 2051 {
2048 int cnt; 2052 int cnt;
@@ -2060,21 +2064,13 @@ static uintptr_t string_insert(char *p, const char *s) // insert the string at '
2060#if ENABLE_FEATURE_VI_YANKMARK 2064#if ENABLE_FEATURE_VI_YANKMARK
2061static char *text_yank(char *p, char *q, int dest) // copy text into a register 2065static char *text_yank(char *p, char *q, int dest) // copy text into a register
2062{ 2066{
2063 char *t; 2067 int cnt = q - p;
2064 int cnt; 2068 if (cnt < 0) { // they are backwards- reverse them
2065 2069 p = q;
2066 if (q < p) { // they are backwards- reverse them 2070 cnt = -cnt;
2067 t = q;
2068 q = p;
2069 p = t;
2070 } 2071 }
2071 cnt = q - p + 1; 2072 free(reg[dest]); // if already a yank register, free it
2072 t = reg[dest]; 2073 reg[dest] = xstrndup(p, cnt + 1);
2073 free(t); // if already a yank register, free it
2074 t = xmalloc(cnt + 1); // get a new register
2075 memset(t, '\0', cnt + 1); // clear new text[]
2076 strncpy(t, p, cnt); // copy text[] into bufer
2077 reg[dest] = t;
2078 return p; 2074 return p;
2079} 2075}
2080 2076
@@ -3115,7 +3111,7 @@ static void do_cmd(int c)
3115 case 'P': // P- Put register before 3111 case 'P': // P- Put register before
3116 case 'p': // p- put register after 3112 case 'p': // p- put register after
3117 p = reg[YDreg]; 3113 p = reg[YDreg];
3118 if (p == 0) { 3114 if (p == NULL) {
3119 status_line_bold("Nothing in register %c", what_reg()); 3115 status_line_bold("Nothing in register %c", what_reg());
3120 break; 3116 break;
3121 } 3117 }
diff --git a/networking/interface.c b/networking/interface.c
index b09148b27..00174d496 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -990,7 +990,7 @@ static void ife_print6(struct interface *ptr)
990 fclose(f); 990 fclose(f);
991} 991}
992#else 992#else
993static void ife_print6(struct interface *ptr) {} 993#define ife_print6(a) ((void)0)
994#endif 994#endif
995 995
996 996
diff --git a/networking/wget.c b/networking/wget.c
index d782cc4fe..3f80d615e 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -54,14 +54,14 @@ enum {
54 STALLTIME = 5 /* Seconds when xfer considered "stalled" */ 54 STALLTIME = 5 /* Seconds when xfer considered "stalled" */
55}; 55};
56 56
57static unsigned int getttywidth(void) 57static unsigned int get_tty2_width(void)
58{ 58{
59 unsigned width; 59 unsigned width;
60 get_terminal_width_height(0, &width, NULL); 60 get_terminal_width_height(2, &width, NULL);
61 return width; 61 return width;
62} 62}
63 63
64static void progressmeter(int flag) 64static void progress_meter(int flag)
65{ 65{
66 /* We can be called from signal handler */ 66 /* We can be called from signal handler */
67 int save_errno = errno; 67 int save_errno = errno;
@@ -70,7 +70,7 @@ static void progressmeter(int flag)
70 unsigned ratio; 70 unsigned ratio;
71 int barlength, i; 71 int barlength, i;
72 72
73 if (flag == -1) { /* first call to progressmeter */ 73 if (flag == -1) { /* first call to progress_meter */
74 start_sec = monotonic_sec(); 74 start_sec = monotonic_sec();
75 lastupdate_sec = start_sec; 75 lastupdate_sec = start_sec;
76 lastsize = 0; 76 lastsize = 0;
@@ -86,7 +86,7 @@ static void progressmeter(int flag)
86 86
87 fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio); 87 fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
88 88
89 barlength = getttywidth() - 49; 89 barlength = get_tty2_width() - 49;
90 if (barlength > 0) { 90 if (barlength > 0) {
91 /* god bless gcc for variable arrays :) */ 91 /* god bless gcc for variable arrays :) */
92 i = barlength * ratio / 100; 92 i = barlength * ratio / 100;
@@ -138,13 +138,13 @@ static void progressmeter(int flag)
138 } 138 }
139 139
140 if (flag == 0) { 140 if (flag == 0) {
141 /* last call to progressmeter */ 141 /* last call to progress_meter */
142 alarm(0); 142 alarm(0);
143 transferred = 0; 143 transferred = 0;
144 fputc('\n', stderr); 144 fputc('\n', stderr);
145 } else { 145 } else {
146 if (flag == -1) { /* first call to progressmeter */ 146 if (flag == -1) { /* first call to progress_meter */
147 signal_SA_RESTART_empty_mask(SIGALRM, progressmeter); 147 signal_SA_RESTART_empty_mask(SIGALRM, progress_meter);
148 } 148 }
149 alarm(1); 149 alarm(1);
150 } 150 }
@@ -188,7 +188,7 @@ static void progressmeter(int flag)
188 */ 188 */
189#else /* FEATURE_WGET_STATUSBAR */ 189#else /* FEATURE_WGET_STATUSBAR */
190 190
191static ALWAYS_INLINE void progressmeter(int flag UNUSED_PARAM) { } 191static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) { }
192 192
193#endif 193#endif
194 194
@@ -202,6 +202,7 @@ static size_t safe_fread(void *ptr, size_t nmemb, FILE *stream)
202 202
203 do { 203 do {
204 clearerr(stream); 204 clearerr(stream);
205 errno = 0;
205 ret = fread(p, 1, nmemb, stream); 206 ret = fread(p, 1, nmemb, stream);
206 p += ret; 207 p += ret;
207 nmemb -= ret; 208 nmemb -= ret;
@@ -218,6 +219,7 @@ static char *safe_fgets(char *s, int size, FILE *stream)
218 219
219 do { 220 do {
220 clearerr(stream); 221 clearerr(stream);
222 errno = 0;
221 ret = fgets(s, size, stream); 223 ret = fgets(s, size, stream);
222 } while (ret == NULL && ferror(stream) && errno == EINTR); 224 } while (ret == NULL && ferror(stream) && errno == EINTR);
223 225
@@ -765,7 +767,7 @@ However, in real world it was observed that some web servers
765 * Retrieve file 767 * Retrieve file
766 */ 768 */
767 769
768 /* Do it before progressmeter (want to have nice error message) */ 770 /* Do it before progress_meter (want to have nice error message) */
769 if (output_fd < 0) { 771 if (output_fd < 0) {
770 int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL; 772 int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
771 /* compat with wget: -O FILE can overwrite */ 773 /* compat with wget: -O FILE can overwrite */
@@ -775,7 +777,7 @@ However, in real world it was observed that some web servers
775 } 777 }
776 778
777 if (!(opt & WGET_OPT_QUIET)) 779 if (!(opt & WGET_OPT_QUIET))
778 progressmeter(-1); 780 progress_meter(-1);
779 781
780 if (chunked) 782 if (chunked)
781 goto get_clen; 783 goto get_clen;
@@ -817,7 +819,7 @@ However, in real world it was observed that some web servers
817 } 819 }
818 820
819 if (!(opt & WGET_OPT_QUIET)) 821 if (!(opt & WGET_OPT_QUIET))
820 progressmeter(0); 822 progress_meter(0);
821 823
822 if ((use_proxy == 0) && target.is_ftp) { 824 if ((use_proxy == 0) && target.is_ftp) {
823 fclose(dfp); 825 fclose(dfp);