return input;
}
-static char* tless_gets(void)
+static char* tless_gets(int sz)
{
int c;
int i = 0;
}
if (c < ' ')
continue;
+ if (i >= width - sz - 1)
+ continue; /* len limit */
putchar(c);
result[i++] = c;
result = xrealloc(result, i+1);
result[i] = '\0';
- if (i >= width-1) return result;
}
}
printf(HIGHLIGHT"%s"NORMAL, str);
}
+static void print_statusline(const char *str)
+{
+ clear_line();
+ printf(HIGHLIGHT"%.*s"NORMAL, width-1, str);
+}
+
static void data_readlines(void)
{
unsigned i, pos;
{
int percentage;
+ clear_line();
printf(HIGHLIGHT"%s", filename);
if (num_files > 1)
printf(" (file %i of %i)", current_file, num_files);
printf("%i%% "NORMAL, percentage);
}
-#if 0
-/* Print a status line if -m was specified */
-static void medium_status_print(void)
-{
- int percentage;
-
- percentage = calc_percent();
- if (!line_pos)
- printf(HIGHLIGHT"%s %i%% "NORMAL, filename, percentage);
- else if (line_pos >= num_flines - height + 2)
- print_hilite("(END)");
- else
- printf(HIGHLIGHT"%i%% "NORMAL, percentage);
-}
-#endif
-
#endif
/* Print the status line */
m_status_print();
return;
}
- //if (option_mask32 & FLAG_m) {
- // medium_status_print();
- // return;
- //}
/* No flags set */
#endif
+
+ clear_line();
if (line_pos && line_pos < num_flines - height + 2) {
putchar(':');
return;
print_found(buffer[i]);
else
print_ascii(buffer[i]);
- fputs(CLEAR_2_EOL, stdout); /* clears status line */
status_print();
}
static void examine_file(void)
{
- clear_line();
- printf("Examine: ");
+ print_statusline("Examine: ");
free(filename);
- filename = tless_gets();
+ filename = tless_gets(sizeof("Examine: ")-1);
/* files start by = argv. why we assume that argv is infinitely long??
files[num_files] = filename;
current_file = num_files + 1;
filename = xstrdup(files[current_file - 1]);
reinitialise();
} else {
- clear_line();
- print_hilite(direction > 0 ? "No next file" : "No previous file");
+ print_statusline(direction > 0 ? "No next file" : "No previous file");
}
}
int keypress;
/* Clear the current line and print a prompt */
- clear_line();
- printf(" :");
+ print_statusline(" :");
keypress = tless_getch();
switch (keypress) {
break;
#if ENABLE_FEATURE_LESS_FLAGS
case 'f':
- clear_line();
m_status_print();
break;
#endif
/* Get the uncompiled regular expression from the user */
clear_line();
putchar((option_mask32 & LESS_STATE_MATCH_BACKWARDS) ? '?' : '/');
- uncomp_regex = tless_gets();
+ uncomp_regex = tless_gets(1);
if (/*!uncomp_regex ||*/ !uncomp_regex[0]) {
free(uncomp_regex);
buffer_print();
err = regcomp_or_errmsg(&pattern, uncomp_regex, 0);
free(uncomp_regex);
if (err) {
- clear_line();
- fputs(err, stdout);
+ print_statusline(err);
free(err);
return;
}
int i;
FILE *fp;
- clear_line();
- printf("Log file: ");
- current_line = tless_gets();
+ print_statusline("Log file: ");
+ current_line = tless_gets(sizeof("Log file: ")-1);
if (strlen(current_line) > 0) {
fp = fopen(current_line, "w");
free(current_line);
if (!fp) {
- print_hilite("Error opening log file");
+ print_statusline("Error opening log file");
return;
}
for (i = 0; i < num_flines; i++)
return;
}
free(current_line);
- print_hilite("No log file");
+ print_statusline("No log file");
}
#if ENABLE_FEATURE_LESS_MARKS
{
int letter;
- clear_line();
- printf("Mark: ");
+ print_statusline("Mark: ");
letter = tless_getch();
if (isalpha(letter)) {
mark_lines[num_marks][1] = line_pos;
num_marks++;
} else {
- clear_line();
- print_hilite("Invalid mark letter");
+ print_statusline("Invalid mark letter");
}
}
int letter;
int i;
- clear_line();
- printf("Go to mark: ");
+ print_statusline("Go to mark: ");
letter = tless_getch();
clear_line();
break;
}
if (num_marks == 14 && letter != mark_lines[14][0])
- print_hilite("Mark not set");
+ print_statusline("Mark not set");
} else
- print_hilite("Invalid mark letter");
+ print_statusline("Invalid mark letter");
}
#endif
int bracket_line = -1;
int i;
- clear_line();
-
if (strchr(flines[line_pos], bracket) == NULL) {
- print_hilite("No bracket in top line");
+ print_statusline("No bracket in top line");
return;
}
for (i = line_pos + 1; i < num_flines; i++) {
}
}
if (bracket_line == -1)
- print_hilite("No matching bracket found");
+ print_statusline("No matching bracket found");
buffer_line(bracket_line - height + 2);
}
int bracket_line = -1;
int i;
- clear_line();
-
if (strchr(flines[line_pos + height - 2], bracket) == NULL) {
- print_hilite("No bracket in bottom line");
- /* ?? */
- /*printf("%s", flines[line_pos + height]);*/
- /*sleep(4);*/
+ print_statusline("No bracket in bottom line");
return;
}
}
}
if (bracket_line == -1)
- print_hilite("No matching bracket found");
+ print_statusline("No matching bracket found");
buffer_line(bracket_line);
}
break;
#if ENABLE_FEATURE_LESS_FLAGS
case '=':
- clear_line();
m_status_print();
break;
#endif