vi: speedup and code shrink (Walter Harms)
networking/interface.c: silence warning (Vladimir) wget: more robust EINTR detection
This commit is contained in:
parent
4b5709496b
commit
00d8417631
38
editors/vi.c
38
editors/vi.c
@ -662,7 +662,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present
|
|||||||
c = c - 'a';
|
c = c - 'a';
|
||||||
q = mark[(unsigned char) c];
|
q = mark[(unsigned char) c];
|
||||||
if (q != NULL) { // is mark valid
|
if (q != NULL) { // is mark valid
|
||||||
*addr = count_lines(text, q); // count lines
|
*addr = count_lines(text, q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1673,12 +1673,16 @@ static char *char_insert(char *p, char c) // insert the char c at 'p'
|
|||||||
}
|
}
|
||||||
if (autoindent && c == '\n') { // auto indent the new line
|
if (autoindent && c == '\n') { // auto indent the new line
|
||||||
char *q;
|
char *q;
|
||||||
|
size_t len;
|
||||||
q = prev_line(p); // use prev line as template
|
q = prev_line(p); // use prev line as template
|
||||||
for (; isblank(*q); q++) {
|
len = strspn(q, " \t"); // space or tab
|
||||||
uintptr_t bias = stupid_insert(p, *q); // insert the char
|
if (len) {
|
||||||
p += bias + 1;
|
uintptr_t bias;
|
||||||
|
bias = text_hole_make(p, len);
|
||||||
|
p += bias;
|
||||||
q += bias;
|
q += bias;
|
||||||
|
memcpy(p, q, len);
|
||||||
|
p += len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2042,7 +2046,7 @@ static uintptr_t string_insert(char *p, const char *s) // insert the string at '
|
|||||||
i = strlen(s);
|
i = strlen(s);
|
||||||
bias = text_hole_make(p, i);
|
bias = text_hole_make(p, i);
|
||||||
p += bias;
|
p += bias;
|
||||||
strncpy(p, s, i);
|
memcpy(p, s, i);
|
||||||
#if ENABLE_FEATURE_VI_YANKMARK
|
#if ENABLE_FEATURE_VI_YANKMARK
|
||||||
{
|
{
|
||||||
int cnt;
|
int cnt;
|
||||||
@ -2060,21 +2064,13 @@ static uintptr_t string_insert(char *p, const char *s) // insert the string at '
|
|||||||
#if ENABLE_FEATURE_VI_YANKMARK
|
#if ENABLE_FEATURE_VI_YANKMARK
|
||||||
static char *text_yank(char *p, char *q, int dest) // copy text into a register
|
static char *text_yank(char *p, char *q, int dest) // copy text into a register
|
||||||
{
|
{
|
||||||
char *t;
|
int cnt = q - p;
|
||||||
int cnt;
|
if (cnt < 0) { // they are backwards- reverse them
|
||||||
|
p = q;
|
||||||
if (q < p) { // they are backwards- reverse them
|
cnt = -cnt;
|
||||||
t = q;
|
|
||||||
q = p;
|
|
||||||
p = t;
|
|
||||||
}
|
}
|
||||||
cnt = q - p + 1;
|
free(reg[dest]); // if already a yank register, free it
|
||||||
t = reg[dest];
|
reg[dest] = xstrndup(p, cnt + 1);
|
||||||
free(t); // if already a yank register, free it
|
|
||||||
t = xmalloc(cnt + 1); // get a new register
|
|
||||||
memset(t, '\0', cnt + 1); // clear new text[]
|
|
||||||
strncpy(t, p, cnt); // copy text[] into bufer
|
|
||||||
reg[dest] = t;
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3115,7 +3111,7 @@ static void do_cmd(int c)
|
|||||||
case 'P': // P- Put register before
|
case 'P': // P- Put register before
|
||||||
case 'p': // p- put register after
|
case 'p': // p- put register after
|
||||||
p = reg[YDreg];
|
p = reg[YDreg];
|
||||||
if (p == 0) {
|
if (p == NULL) {
|
||||||
status_line_bold("Nothing in register %c", what_reg());
|
status_line_bold("Nothing in register %c", what_reg());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -990,7 +990,7 @@ static void ife_print6(struct interface *ptr)
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void ife_print6(struct interface *ptr) {}
|
#define ife_print6(a) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,14 +54,14 @@ enum {
|
|||||||
STALLTIME = 5 /* Seconds when xfer considered "stalled" */
|
STALLTIME = 5 /* Seconds when xfer considered "stalled" */
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int getttywidth(void)
|
static unsigned int get_tty2_width(void)
|
||||||
{
|
{
|
||||||
unsigned width;
|
unsigned width;
|
||||||
get_terminal_width_height(0, &width, NULL);
|
get_terminal_width_height(2, &width, NULL);
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void progressmeter(int flag)
|
static void progress_meter(int flag)
|
||||||
{
|
{
|
||||||
/* We can be called from signal handler */
|
/* We can be called from signal handler */
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
@ -70,7 +70,7 @@ static void progressmeter(int flag)
|
|||||||
unsigned ratio;
|
unsigned ratio;
|
||||||
int barlength, i;
|
int barlength, i;
|
||||||
|
|
||||||
if (flag == -1) { /* first call to progressmeter */
|
if (flag == -1) { /* first call to progress_meter */
|
||||||
start_sec = monotonic_sec();
|
start_sec = monotonic_sec();
|
||||||
lastupdate_sec = start_sec;
|
lastupdate_sec = start_sec;
|
||||||
lastsize = 0;
|
lastsize = 0;
|
||||||
@ -86,7 +86,7 @@ static void progressmeter(int flag)
|
|||||||
|
|
||||||
fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
|
fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
|
||||||
|
|
||||||
barlength = getttywidth() - 49;
|
barlength = get_tty2_width() - 49;
|
||||||
if (barlength > 0) {
|
if (barlength > 0) {
|
||||||
/* god bless gcc for variable arrays :) */
|
/* god bless gcc for variable arrays :) */
|
||||||
i = barlength * ratio / 100;
|
i = barlength * ratio / 100;
|
||||||
@ -138,13 +138,13 @@ static void progressmeter(int flag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flag == 0) {
|
if (flag == 0) {
|
||||||
/* last call to progressmeter */
|
/* last call to progress_meter */
|
||||||
alarm(0);
|
alarm(0);
|
||||||
transferred = 0;
|
transferred = 0;
|
||||||
fputc('\n', stderr);
|
fputc('\n', stderr);
|
||||||
} else {
|
} else {
|
||||||
if (flag == -1) { /* first call to progressmeter */
|
if (flag == -1) { /* first call to progress_meter */
|
||||||
signal_SA_RESTART_empty_mask(SIGALRM, progressmeter);
|
signal_SA_RESTART_empty_mask(SIGALRM, progress_meter);
|
||||||
}
|
}
|
||||||
alarm(1);
|
alarm(1);
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ static void progressmeter(int flag)
|
|||||||
*/
|
*/
|
||||||
#else /* FEATURE_WGET_STATUSBAR */
|
#else /* FEATURE_WGET_STATUSBAR */
|
||||||
|
|
||||||
static ALWAYS_INLINE void progressmeter(int flag UNUSED_PARAM) { }
|
static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) { }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -202,6 +202,7 @@ static size_t safe_fread(void *ptr, size_t nmemb, FILE *stream)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
clearerr(stream);
|
clearerr(stream);
|
||||||
|
errno = 0;
|
||||||
ret = fread(p, 1, nmemb, stream);
|
ret = fread(p, 1, nmemb, stream);
|
||||||
p += ret;
|
p += ret;
|
||||||
nmemb -= ret;
|
nmemb -= ret;
|
||||||
@ -218,6 +219,7 @@ static char *safe_fgets(char *s, int size, FILE *stream)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
clearerr(stream);
|
clearerr(stream);
|
||||||
|
errno = 0;
|
||||||
ret = fgets(s, size, stream);
|
ret = fgets(s, size, stream);
|
||||||
} while (ret == NULL && ferror(stream) && errno == EINTR);
|
} while (ret == NULL && ferror(stream) && errno == EINTR);
|
||||||
|
|
||||||
@ -765,7 +767,7 @@ However, in real world it was observed that some web servers
|
|||||||
* Retrieve file
|
* Retrieve file
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Do it before progressmeter (want to have nice error message) */
|
/* Do it before progress_meter (want to have nice error message) */
|
||||||
if (output_fd < 0) {
|
if (output_fd < 0) {
|
||||||
int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
|
int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
|
||||||
/* compat with wget: -O FILE can overwrite */
|
/* compat with wget: -O FILE can overwrite */
|
||||||
@ -775,7 +777,7 @@ However, in real world it was observed that some web servers
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(opt & WGET_OPT_QUIET))
|
if (!(opt & WGET_OPT_QUIET))
|
||||||
progressmeter(-1);
|
progress_meter(-1);
|
||||||
|
|
||||||
if (chunked)
|
if (chunked)
|
||||||
goto get_clen;
|
goto get_clen;
|
||||||
@ -817,7 +819,7 @@ However, in real world it was observed that some web servers
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(opt & WGET_OPT_QUIET))
|
if (!(opt & WGET_OPT_QUIET))
|
||||||
progressmeter(0);
|
progress_meter(0);
|
||||||
|
|
||||||
if ((use_proxy == 0) && target.is_ftp) {
|
if ((use_proxy == 0) && target.is_ftp) {
|
||||||
fclose(dfp);
|
fclose(dfp);
|
||||||
|
Loading…
Reference in New Issue
Block a user