c = c - 'a';
q = mark[(unsigned char) c];
if (q != NULL) { // is mark valid
- *addr = count_lines(text, q); // count lines
+ *addr = count_lines(text, q);
}
}
}
}
if (autoindent && c == '\n') { // auto indent the new line
char *q;
-
+ size_t len;
q = prev_line(p); // use prev line as template
- for (; isblank(*q); q++) {
- uintptr_t bias = stupid_insert(p, *q); // insert the char
- p += bias + 1;
+ len = strspn(q, " \t"); // space or tab
+ if (len) {
+ uintptr_t bias;
+ bias = text_hole_make(p, len);
+ p += bias;
q += bias;
+ memcpy(p, q, len);
+ p += len;
}
}
#endif
i = strlen(s);
bias = text_hole_make(p, i);
p += bias;
- strncpy(p, s, i);
+ memcpy(p, s, i);
#if ENABLE_FEATURE_VI_YANKMARK
{
int cnt;
#if ENABLE_FEATURE_VI_YANKMARK
static char *text_yank(char *p, char *q, int dest) // copy text into a register
{
- char *t;
- int cnt;
-
- if (q < p) { // they are backwards- reverse them
- t = q;
- q = p;
- p = t;
+ int cnt = q - p;
+ if (cnt < 0) { // they are backwards- reverse them
+ p = q;
+ cnt = -cnt;
}
- cnt = q - p + 1;
- t = reg[dest];
- 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;
+ free(reg[dest]); // if already a yank register, free it
+ reg[dest] = xstrndup(p, cnt + 1);
return p;
}
case 'P': // P- Put register before
case 'p': // p- put register after
p = reg[YDreg];
- if (p == 0) {
+ if (p == NULL) {
status_line_bold("Nothing in register %c", what_reg());
break;
}
STALLTIME = 5 /* Seconds when xfer considered "stalled" */
};
-static unsigned int getttywidth(void)
+static unsigned int get_tty2_width(void)
{
unsigned width;
- get_terminal_width_height(0, &width, NULL);
+ get_terminal_width_height(2, &width, NULL);
return width;
}
-static void progressmeter(int flag)
+static void progress_meter(int flag)
{
/* We can be called from signal handler */
int save_errno = errno;
unsigned ratio;
int barlength, i;
- if (flag == -1) { /* first call to progressmeter */
+ if (flag == -1) { /* first call to progress_meter */
start_sec = monotonic_sec();
lastupdate_sec = start_sec;
lastsize = 0;
fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
- barlength = getttywidth() - 49;
+ barlength = get_tty2_width() - 49;
if (barlength > 0) {
/* god bless gcc for variable arrays :) */
i = barlength * ratio / 100;
}
if (flag == 0) {
- /* last call to progressmeter */
+ /* last call to progress_meter */
alarm(0);
transferred = 0;
fputc('\n', stderr);
} else {
- if (flag == -1) { /* first call to progressmeter */
- signal_SA_RESTART_empty_mask(SIGALRM, progressmeter);
+ if (flag == -1) { /* first call to progress_meter */
+ signal_SA_RESTART_empty_mask(SIGALRM, progress_meter);
}
alarm(1);
}
*/
#else /* FEATURE_WGET_STATUSBAR */
-static ALWAYS_INLINE void progressmeter(int flag UNUSED_PARAM) { }
+static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) { }
#endif
do {
clearerr(stream);
+ errno = 0;
ret = fread(p, 1, nmemb, stream);
p += ret;
nmemb -= ret;
do {
clearerr(stream);
+ errno = 0;
ret = fgets(s, size, stream);
} while (ret == NULL && ferror(stream) && errno == EINTR);
* 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) {
int o_flags = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL;
/* compat with wget: -O FILE can overwrite */
}
if (!(opt & WGET_OPT_QUIET))
- progressmeter(-1);
+ progress_meter(-1);
if (chunked)
goto get_clen;
}
if (!(opt & WGET_OPT_QUIET))
- progressmeter(0);
+ progress_meter(0);
if ((use_proxy == 0) && target.is_ftp) {
fclose(dfp);