/* vi: set sw=4 ts=4: */
/*
 * Mini less implementation for busybox
 *
 *
 * Copyright (C) 2005 by Rob Sullivan <cogito.ergo.cogito@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307 USA
 *
 *      This program needs a lot of development, so consider it in a beta stage
 *      at best.
 *
 *      TODO:
 *      - Add more regular expression support - search modifiers, certain matches, etc.
 *      - Add more complex bracket searching - currently, nested brackets are
 *      not considered.
 *      - Add support for "F" as an input. This causes less to act in
 *      a similar way to tail -f.
 *      - Check for binary files, and prompt the user if a binary file
 *      is detected.
 *      - Allow horizontal scrolling. Currently, lines simply continue onto
 *      the next line, per the terminal's discretion
 *
 *      Notes:
 *      - filename is an array and not a pointer because that avoids all sorts
 *      of complications involving the fact that something that is pointed to
 *      will be changed if the pointer is changed.
 *      - the inp file pointer is used so that keyboard input works after
 *      redirected input has been read from stdin
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <ctype.h>

#include "busybox.h"

#ifdef CONFIG_FEATURE_LESS_REGEXP
#include "xregex.h"
#endif


/* These are the escape sequences corresponding to special keys */
#define REAL_KEY_UP 'A'
#define REAL_KEY_DOWN 'B'
#define REAL_KEY_RIGHT 'C'
#define REAL_KEY_LEFT 'D'
#define REAL_PAGE_UP '5'
#define REAL_PAGE_DOWN '6'

/* These are the special codes assigned by this program to the special keys */
#define PAGE_UP 20
#define PAGE_DOWN 21
#define KEY_UP 22
#define KEY_DOWN 23
#define KEY_RIGHT 24
#define KEY_LEFT 25

/* The escape codes for highlighted and normal text */
#define HIGHLIGHT "\033[7m"
#define NORMAL "\033[0m"

/* The escape code to clear the screen */
#define CLEAR "\033[H\033[J"

/* Maximum number of lines in a file */
#define MAXLINES 10000

/* Get height and width of terminal */
#define tty_width_height()              get_terminal_width_height(0, &width, &height)

static int height;
static int width;
static char **files;
static char filename[256];
static char **buffer;
static char **flines;
static int current_file = 1;
static int line_pos;
static int num_flines;
static int num_files = 1;
static int past_eof;

/* Command line options */
static unsigned long flags;
#define FLAG_E 1
#define FLAG_M (1<<1)
#define FLAG_m (1<<2)
#define FLAG_N (1<<3)
#define FLAG_TILDE (1<<4)

/* This is needed so that program behaviour changes when input comes from
   stdin */
static int inp_stdin;

#ifdef CONFIG_FEATURE_LESS_MARKS
static int mark_lines[15][2];
static int num_marks;
#endif

#ifdef CONFIG_FEATURE_LESS_REGEXP
static int match_found;
static int match_lines[100];
static int match_pos;
static int num_matches;
static int match_backwards;
static int num_back_match = 1;
#endif

/* Needed termios structures */
static struct termios term_orig, term_vi;

/* File pointer to get input from */
static FILE *inp;

/* Reset terminal input to normal */
static void set_tty_cooked(void) {
	fflush(stdout);
	tcsetattr(fileno(inp), TCSANOW, &term_orig);
}

/* Set terminal input to raw mode  (taken from vi.c) */
static void set_tty_raw(void) {
	tcsetattr(fileno(inp), TCSANOW, &term_vi);
}

/* Exit the program gracefully */
static void tless_exit(int code) {

	/* TODO: We really should save the terminal state when we start,
		 and restore it when we exit. Less does this with the
		 "ti" and "te" termcap commands; can this be done with
		 only termios.h? */

	putchar('\n');
	exit(code);
}

/* Grab a character from input without requiring the return key. If the
   character is ASCII \033, get more characters and assign certain sequences
   special return codes. Note that this function works best with raw input. */
static int tless_getch(void) {

	int input;

	set_tty_raw();

	input = getc(inp);
	/* Detect escape sequences (i.e. arrow keys) and handle
	   them accordingly */

	if (input == '\033' && getc(inp) == '[') {
		input = getc(inp);
		set_tty_cooked();
		if (input == REAL_KEY_UP)
			return KEY_UP;
		else if (input == REAL_KEY_DOWN)
			return KEY_DOWN;
		else if (input == REAL_KEY_RIGHT)
			return KEY_RIGHT;
		else if (input == REAL_KEY_LEFT)
			return KEY_LEFT;
		else if (input == REAL_PAGE_UP)
			return PAGE_UP;
		else if (input == REAL_PAGE_DOWN)
			return PAGE_DOWN;
	}
	/* The input is a normal ASCII value */
	else {
		set_tty_cooked();
		return input;
	}
	return 0;
}

/* Move the cursor to a position (x,y), where (0,0) is the
   top-left corner of the console */
static void move_cursor(int x, int y) {
	printf("\033[%i;%iH", x, y);
}

static void clear_line(void) {
	move_cursor(height, 0);
	printf("\033[K");
}

/* This adds line numbers to every line, as the -N flag necessitates */
static void add_linenumbers(void) {

	char current_line[256];
	int i;

	for (i = 0; i <= num_flines; i++) {
		safe_strncpy(current_line, flines[i], 256);
		flines[i] = bb_xasprintf("%5d %s", i + 1, current_line);
	}
}

static void data_readlines(void) {

	int i;
	char current_line[256];
	FILE *fp;

	fp = (inp_stdin) ? stdin : bb_xfopen(filename, "rt");
	flines = NULL;
	for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) {
		strcpy(current_line, "");
		fgets(current_line, 256, fp);
		if(fp != stdin)
			bb_xferror(fp, filename);
		flines = xrealloc(flines, (i+1) * sizeof(char *));
		flines[i] = bb_xstrdup(current_line);
	}
	num_flines = i - 2;

	/* Reset variables for a new file */

	line_pos = 0;
	past_eof = 0;

	fclose(fp);

	if(inp == NULL)
		inp = (inp_stdin) ? bb_xfopen(CURRENT_TTY, "r") : stdin;

	if (flags & FLAG_N)
		add_linenumbers();
}

/* Turn a percentage into a line number */
static int reverse_percent(int percentage) {
	double linenum = percentage;
	linenum = ((linenum / 100) * num_flines) - 1;
	return(linenum);
}

#ifdef CONFIG_FEATURE_LESS_FLAGS

/* Interestingly, writing calc_percent as a function and not a prototype saves around 32 bytes
 * on my build. */
static int calc_percent(void) {
	return ((100 * (line_pos + height - 2) / num_flines) + 1);
}

/* Print a status line if -M was specified */
static void m_status_print(void) {

	int percentage;

	if (!past_eof) {
		if (!line_pos) {
			if (num_files > 1)
				printf("%s%s %s%i%s%i%s%i-%i/%i ", HIGHLIGHT, filename, "(file ", current_file, " of ", num_files, ") lines ", line_pos + 1, line_pos + height - 1, num_flines + 1);
			else {
				printf("%s%s lines %i-%i/%i ", HIGHLIGHT, filename, line_pos + 1, line_pos + height - 1, num_flines + 1);
			}
		}
		else {
			printf("%s %s lines %i-%i/%i ", HIGHLIGHT, filename, line_pos + 1, line_pos + height - 1, num_flines + 1);
		}

		if (line_pos == num_flines - height + 2) {
			printf("(END) %s", NORMAL);
			if ((num_files > 1) && (current_file != num_files))
				printf("%s- Next: %s%s", HIGHLIGHT, files[current_file], NORMAL);
		}
		else {
			percentage = calc_percent();
			printf("%i%% %s", percentage, NORMAL);
		}
	}
	else {
		printf("%s%s lines %i-%i/%i (END) ", HIGHLIGHT, filename, line_pos + 1, num_flines + 1, num_flines + 1);
		if ((num_files > 1) && (current_file != num_files))
			printf("- Next: %s", files[current_file]);
		printf("%s", NORMAL);
	}
}

/* Print a status line if -m was specified */
static void medium_status_print(void) {

	int percentage;
	percentage = calc_percent();

	if (!line_pos)
		printf("%s%s %i%%%s", HIGHLIGHT, filename, percentage, NORMAL);
	else if (line_pos == num_flines - height + 2)
		printf("%s(END)%s", HIGHLIGHT, NORMAL);
	else
		printf("%s%i%%%s", HIGHLIGHT, percentage, NORMAL);
}
#endif

/* Print the status line */
static void status_print(void) {

	/* Change the status if flags have been set */
#ifdef CONFIG_FEATURE_LESS_FLAGS
	if (flags & FLAG_M)
		m_status_print();
	else if (flags & FLAG_m)
		medium_status_print();
	/* No flags set */
	else {
#endif
		if (!line_pos) {
			printf("%s%s %s", HIGHLIGHT, filename, NORMAL);
			if (num_files > 1)
				printf("%s%s%i%s%i%s%s", HIGHLIGHT, "(file ", current_file, " of ", num_files, ")", NORMAL);
		}
		else if (line_pos == num_flines - height + 2) {
			printf("%s%s %s", HIGHLIGHT, "(END)", NORMAL);
			if ((num_files > 1) && (current_file != num_files))
				printf("%s%s%s%s", HIGHLIGHT, "- Next: ", files[current_file], NORMAL);
		}
		else {
			putchar(':');
		}
#ifdef CONFIG_FEATURE_LESS_FLAGS
	}
#endif
}

/* Print the buffer */
static void buffer_print(void) {

	int i;

	printf("%s", CLEAR);
	if (num_flines >= height - 2) {
		for (i = 0; i < height - 1; i++)
			printf("%s", buffer[i]);
	}
	else {
		for (i = 1; i < (height - 1 - num_flines); i++)
			putchar('\n');
		for (i = 0; i < height - 1; i++)
			printf("%s", buffer[i]);
	}

	status_print();
}

/* Initialise the buffer */
static void buffer_init(void) {

	int i;

	if(buffer == NULL) {
		/* malloc the number of lines needed for the buffer */
		buffer = xrealloc(buffer, height * sizeof(char *));
	} else {
		for (i = 0; i < (height - 1); i++)
			free(buffer[i]);
	}

	/* Fill the buffer until the end of the file or the
	   end of the buffer is reached */
	for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) {
		buffer[i] = bb_xstrdup(flines[i]);
	}

	/* If the buffer still isn't full, fill it with blank lines */
	for (; i < (height - 1); i++) {
		buffer[i] = bb_xstrdup("");
	}
}

/* Move the buffer up and down in the file in order to scroll */
static void buffer_down(int nlines) {

	int i;

	if (!past_eof) {
		if (line_pos + (height - 3) + nlines < num_flines) {
			line_pos += nlines;
			for (i = 0; i < (height - 1); i++) {
				free(buffer[i]);
				buffer[i] = bb_xstrdup(flines[line_pos + i]);
			}
		}
		else {
			/* As the number of lines requested was too large, we just move
			to the end of the file */
			while (line_pos + (height - 3) + 1 < num_flines) {
				line_pos += 1;
				for (i = 0; i < (height - 1); i++) {
					free(buffer[i]);
					buffer[i] = bb_xstrdup(flines[line_pos + i]);
				}
			}
		}

		/* We exit if the -E flag has been set */
		if ((flags & FLAG_E) && (line_pos + (height - 2) == num_flines))
			tless_exit(0);
	}
}

static void buffer_up(int nlines) {

	int i;
	int tilde_line;

	if (!past_eof) {
		if (line_pos - nlines >= 0) {
			line_pos -= nlines;
			for (i = 0; i < (height - 1); i++) {
				free(buffer[i]);
				buffer[i] = bb_xstrdup(flines[line_pos + i]);
			}
		}
		else {
		/* As the requested number of lines to move was too large, we
		   move one line up at a time until we can't. */
			while (line_pos != 0) {
				line_pos -= 1;
				for (i = 0; i < (height - 1); i++) {
					free(buffer[i]);
					buffer[i] = bb_xstrdup(flines[line_pos + i]);
				}
			}
		}
	}
	else {
		/* Work out where the tildes start */
		tilde_line = num_flines - line_pos + 3;

		line_pos -= nlines;
		/* Going backwards nlines lines has taken us to a point where
		   nothing is past the EOF, so we revert to normal. */
		if (line_pos < num_flines - height + 3) {
			past_eof = 0;
			buffer_up(nlines);
		}
		else {
			/* We only move part of the buffer, as the rest
			is past the EOF */
			for (i = 0; i < (height - 1); i++) {
				free(buffer[i]);
				if (i < tilde_line - nlines + 1)
					buffer[i] = bb_xstrdup(flines[line_pos + i]);
				else {
					if (line_pos >= num_flines - height + 2)
						buffer[i] = bb_xstrdup("~\n");
				}
			}
		}
	}
}

static void buffer_line(int linenum) {

	int i;

	past_eof = 0;

	if (linenum < 1 || linenum > num_flines) {
		clear_line();
		printf("%s%s%i%s", HIGHLIGHT, "Cannot seek to line number ", linenum, NORMAL);
	}
	else if (linenum < (num_flines - height - 2)) {
		for (i = 0; i < (height - 1); i++) {
			free(buffer[i]);
			buffer[i] = bb_xstrdup(flines[linenum + i]);
		}
		line_pos = linenum;
	}
	else {
		for (i = 0; i < (height - 1); i++) {
			free(buffer[i]);
			if (linenum + i < num_flines + 2)
				buffer[i] = bb_xstrdup(flines[linenum + i]);
			else
				buffer[i] = bb_xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
		}
		line_pos = linenum;
		/* Set past_eof so buffer_down and buffer_up act differently */
		past_eof = 1;
	}
}

/* Reinitialise everything for a new file - free the memory and start over */
static void reinitialise(void) {

	int i;

	for (i = 0; i <= num_flines; i++)
		free(flines[i]);
	free(flines);

	data_readlines();
	buffer_init();
	buffer_print();
}

static void examine_file(void) {

	int newline_offset;

	clear_line();
	printf("Examine: ");
	fgets(filename, 256, inp);

	/* As fgets adds a newline to the end of an input string, we
	   need to remove it */
	newline_offset = strlen(filename) - 1;
	filename[newline_offset] = '\0';

	files[num_files] = bb_xstrdup(filename);
	current_file = num_files + 1;
	num_files++;

	inp_stdin = 0;
	reinitialise();
}

/* This function changes the file currently being paged. direction can be one of the following:
 * -1: go back one file
 *  0: go to the first file
 *  1: go forward one file
*/
static void change_file (int direction) {
	if (current_file != ((direction > 0) ? num_files : 1)) {
		current_file = direction ? current_file + direction : 1;
		strcpy(filename, files[current_file - 1]);
		reinitialise();
	}
	else {
		clear_line();
		printf("%s%s%s", HIGHLIGHT, (direction > 0) ? "No next file" : "No previous file", NORMAL);
	}
}

static void remove_current_file(void) {

	int i;

	if (current_file != 1) {
		change_file(-1);
		for (i = 3; i <= num_files; i++)
			files[i - 2] = files[i - 1];
		num_files--;
		buffer_print();
	}
	else {
		change_file(1);
		for (i = 2; i <= num_files; i++)
			files[i - 2] = files[i - 1];
		num_files--;
		current_file--;
		buffer_print();
	}
}

static void colon_process(void) {

	int keypress;

	/* Clear the current line and print a prompt */
	clear_line();
	printf(" :");

	keypress = tless_getch();
	switch (keypress) {
		case 'd':
			remove_current_file();
			break;
		case 'e':
			examine_file();
			break;
#ifdef CONFIG_FEATURE_LESS_FLAGS
		case 'f':
			clear_line();
			m_status_print();
			break;
#endif
		case 'n':
			change_file(1);
			break;
		case 'p':
			change_file(-1);
			break;
		case 'q':
			tless_exit(0);
			break;
		case 'x':
			change_file(0);
			break;
		default:
			break;
	}
}

#ifdef CONFIG_FEATURE_LESS_REGEXP
/* The below two regular expression handler functions NEED development. */

/* Get a regular expression from the user, and then go through the current
   file line by line, running a processing regex function on each one. */

static char *insert_highlights (char *line, int start, int end) {

	return bb_xasprintf("%.*s%s%.*s%s%s", start, line, HIGHLIGHT,
			end - start, line + start, NORMAL, line + end);
}

static char *process_regex_on_line(char *line, regex_t *pattern) {
	/* This function takes the regex and applies it to the line.
	   Each part of the line that matches has the HIGHLIGHT
	   and NORMAL escape sequences placed around it by
	   insert_highlights, and then the line is returned. */

	int match_status;
	char *line2 = (char *) malloc((sizeof(char) * (strlen(line) + 1)) + 64);
	char sub_line[256];
	int prev_eo = 0;
	regmatch_t match_structs;

	memset(sub_line, 0, 256);
	strcpy(line2, line);

	match_found = 0;
	match_status = regexec(pattern, line2, 1, &match_structs, 0);

	while (match_status == 0) {

		memset(sub_line, 0, 256);

		if (match_found == 0)
			match_found = 1;

		line2 = insert_highlights(line2, match_structs.rm_so + prev_eo, match_structs.rm_eo + prev_eo);
		if (match_structs.rm_eo + 11 + prev_eo < strlen(line2))
			strcat(sub_line, line2 + match_structs.rm_eo + 11 + prev_eo);

		prev_eo += match_structs.rm_eo + 11;
		match_status = regexec(pattern, sub_line, 1, &match_structs, REG_NOTBOL);
	}

	return line2;
}

static void regex_process(void) {

	char uncomp_regex[100];
	char current_line[256];
	int i;
	int j = 0;
	regex_t *pattern;

	/* Reset variables */
	match_lines[0] = -1;
	match_pos = 0;
	num_matches = 0;
	match_found = 0;

	pattern = (regex_t *) malloc(sizeof(regex_t));
	memset(pattern, 0, sizeof(regex_t));

	/* Get the uncompiled regular expression from the user */
	clear_line();
	putchar((match_backwards) ? '?' : '/');
	uncomp_regex[0] = 0;
	fgets(uncomp_regex, sizeof(uncomp_regex), stdin);
	i = strlen(uncomp_regex);
	if(i > 0) {
		if(uncomp_regex[i-1] == '\n')
			uncomp_regex[i-1] = '\0';
		else
			while((i = getchar()) != '\n' && i != EOF);
	}

	/* Compile the regex and check for errors */
	xregcomp(pattern, uncomp_regex, 0);

	/* Run the regex on each line of the current file here */
	for (i = 0; i <= num_flines; i++) {
		strcpy(current_line, process_regex_on_line(flines[i], pattern));
		flines[i] = bb_xstrdup(current_line);
		if (match_found) {
			match_lines[j] = i;
			j++;
		}
	}

	num_matches = j;
	if ((match_lines[0] != -1) && (num_flines > height - 2))
		buffer_line(match_lines[0]);
	else
		buffer_init();
}

static void goto_match(int match) {

	/* This goes to a specific match - all line positions of matches are
	   stored within the match_lines[] array. */
	if ((match < num_matches) && (match >= 0)) {
		buffer_line(match_lines[match]);
		match_pos = match;
	}
}

static void search_backwards(void) {

	int current_linepos = line_pos;
	int i;

	match_backwards = 1;
	regex_process();

	for (i = 0; i < num_matches; i++) {
		if (match_lines[i] > current_linepos) {
			buffer_line(match_lines[i - num_back_match]);
			break;
		}
	}

	/* Reset variables */
	match_backwards = 0;
	num_back_match = 1;

}
#endif

static void number_process(int first_digit) {

	int i = 1;
	int num;
	char num_input[80];
	char keypress;
	char *endptr;

	num_input[0] = first_digit;

	/* Clear the current line, print a prompt, and then print the digit */
	clear_line();
	printf(":%c", first_digit);

	/* Receive input until a letter is given (max 80 chars)*/
	while((i < 80) && (num_input[i] = tless_getch()) && isdigit(num_input[i])) {
		putchar(num_input[i]);
		i++;
	}

	/* Take the final letter out of the digits string */
	keypress = num_input[i];
	num_input[i] = '\0';
	num = strtol(num_input, &endptr, 10);
	if (endptr==num_input || *endptr!='\0' || num < 1 || num > MAXLINES)
		goto END;

	/* We now know the number and the letter entered, so we process them */
	switch (keypress) {
		case KEY_DOWN: case 'z': case 'd': case 'e': case ' ': case '\015':
			buffer_down(num);
			break;
		case KEY_UP: case 'b': case 'w': case 'y': case 'u':
			buffer_up(num);
			break;
		case 'g': case '<': case 'G': case '>':
			if (num_flines >= height - 2)
				buffer_line(num - 1);
			break;
		case 'p': case '%':
			buffer_line(reverse_percent(num));
			break;
#ifdef CONFIG_FEATURE_LESS_REGEXP
		case 'n':
			goto_match(match_pos + num - 1);
			break;
		case '/':
			regex_process();
			goto_match(num - 1);
			break;
		case '?':
			num_back_match = num;
			search_backwards();
			break;
#endif
		default:
			break;
	}
END:
	buffer_print();
}

#ifdef CONFIG_FEATURE_LESS_FLAGCS
static void flag_change(void) {

	int keypress;

	clear_line();
	putchar('-');
	keypress = tless_getch();

	switch (keypress) {
		case 'M':
			flags ^= FLAG_M;
			break;
		case 'm':
			flags ^= FLAG_m;
			break;
		case 'E':
			flags ^= FLAG_E;
			break;
		case '~':
			flags ^= FLAG_TILDE;
			break;
		default:
			break;
	}
}

static void show_flag_status(void) {

	int keypress;
	int flag_val;

	clear_line();
	putchar('_');
	keypress = tless_getch();

	switch (keypress) {
		case 'M':
			flag_val = flags & FLAG_M;
			break;
		case 'm':
			flag_val = flags & FLAG_m;
			break;
		case '~':
			flag_val = flags & FLAG_TILDE;
			break;
		case 'N':
			flag_val = flags & FLAG_N;
			break;
		case 'E':
			flag_val = flags & FLAG_E;
			break;
		default:
			flag_val = 0;
			break;
	}

	clear_line();
	printf("%s%s%i%s", HIGHLIGHT, "The status of the flag is: ", flag_val != 0, NORMAL);
}
#endif

static void full_repaint(void) {

	int temp_line_pos = line_pos;
	data_readlines();
	buffer_init();
	buffer_line(temp_line_pos);
	buffer_print();
}


static void save_input_to_file(void) {

	char current_line[256];
	int i;
	FILE *fp;

	clear_line();
	printf("Log file: ");
	fgets(current_line, 256, inp);
	current_line[strlen(current_line) - 1] = '\0';
	if (strlen(current_line)) {
		fp = bb_xfopen(current_line, "w");
		for (i = 0; i < num_flines; i++)
			fprintf(fp, "%s", flines[i]);
		fclose(fp);
		buffer_print();
	}
	else
		printf("%sNo log file%s", HIGHLIGHT, NORMAL);
}

#ifdef CONFIG_FEATURE_LESS_MARKS
static void add_mark(void) {

	int letter;
	int mark_line;

	clear_line();
	printf("Mark: ");
	letter = tless_getch();

	if (isalpha(letter)) {
		mark_line = line_pos;

		/* If we exceed 15 marks, start overwriting previous ones */
		if (num_marks == 14)
			num_marks = 0;

		mark_lines[num_marks][0] = letter;
		mark_lines[num_marks][1] = line_pos;
		num_marks++;
	}
	else {
		clear_line();
		printf("%s%s%s", HIGHLIGHT, "Invalid mark letter", NORMAL);
	}
}

static void goto_mark(void) {

	int letter;
	int i;

	clear_line();
	printf("Go to mark: ");
	letter = tless_getch();
	clear_line();

	if (isalpha(letter)) {
		for (i = 0; i <= num_marks; i++)
			if (letter == mark_lines[i][0]) {
				buffer_line(mark_lines[i][1]);
				break;
			}
		if ((num_marks == 14) && (letter != mark_lines[14][0]))
			printf("%s%s%s", HIGHLIGHT, "Mark not set", NORMAL);
	}
	else
		printf("%s%s%s", HIGHLIGHT, "Invalid mark letter", NORMAL);
}
#endif


#ifdef CONFIG_FEATURE_LESS_BRACKETS

static char opp_bracket (char bracket) {

	switch (bracket) {
		case '{': case '[':
			return bracket + 2;
			break;
		case '(':
			return ')';
			break;
		case '}': case ']':
			return bracket - 2;
			break;
		case ')':
			return '(';
			break;
		default:
			return 0;
			break;
	}
}

static void match_right_bracket(char bracket) {

	int bracket_line = -1;
	int i;

	clear_line();

	if (strchr(flines[line_pos], bracket) == NULL)
		printf("%s%s%s", HIGHLIGHT, "No bracket in top line", NORMAL);
	else {
		for (i = line_pos + 1; i < num_flines; i++) {
			if (strchr(flines[i], opp_bracket(bracket)) != NULL) {
				bracket_line = i;
				break;
			}
		}

		if (bracket_line == -1)
			printf("%s%s%s", HIGHLIGHT, "No matching bracket found", NORMAL);

		buffer_line(bracket_line - height + 2);
		buffer_print();
	}
}

static void match_left_bracket (char bracket) {

	int bracket_line = -1;
	int i;

	clear_line();

	if (strchr(flines[line_pos + height - 2], bracket) == NULL) {
		printf("%s%s%s", HIGHLIGHT, "No bracket in bottom line", NORMAL);
		printf("%s", flines[line_pos + height]);
		sleep(4);
	}
	else {
		for (i = line_pos + height - 2; i >= 0; i--) {
			if (strchr(flines[i], opp_bracket(bracket)) != NULL) {
				bracket_line = i;
				break;
			}
		}

		if (bracket_line == -1)
			printf("%s%s%s", HIGHLIGHT, "No matching bracket found", NORMAL);

		buffer_line(bracket_line);
		buffer_print();
	}
}

#endif  /* CONFIG_FEATURE_LESS_BRACKETS */

static void keypress_process(int keypress) {
	switch (keypress) {
		case KEY_DOWN: case 'e': case 'j': case '\015':
			buffer_down(1);
			buffer_print();
			break;
		case KEY_UP: case 'y': case 'k':
			buffer_up(1);
			buffer_print();
			break;
		case PAGE_DOWN: case ' ': case 'z':
			buffer_down(height - 1);
			buffer_print();
			break;
		case PAGE_UP: case 'w': case 'b':
			buffer_up(height - 1);
			buffer_print();
			break;
		case 'd':
			buffer_down((height - 1) / 2);
			buffer_print();
			break;
		case 'u':
			buffer_up((height - 1) / 2);
			buffer_print();
			break;
		case 'g': case 'p': case '<': case '%':
			buffer_up(num_flines + 1);
			buffer_print();
			break;
		case 'G': case '>':
			buffer_down(num_flines + 1);
			buffer_print();
			break;
		case 'q': case 'Q':
			tless_exit(0);
			break;
#ifdef CONFIG_FEATURE_LESS_MARKS
		case 'm':
			add_mark();
			buffer_print();
			break;
		case '\'':
			goto_mark();
			buffer_print();
			break;
#endif
		case 'r':
			buffer_print();
			break;
		case 'R':
			full_repaint();
			break;
		case 's':
			if (inp_stdin)
				save_input_to_file();
			break;
		case 'E':
			examine_file();
			break;
#ifdef CONFIG_FEATURE_LESS_FLAGS
		case '=':
			clear_line();
			m_status_print();
			break;
#endif
#ifdef CONFIG_FEATURE_LESS_REGEXP
		case '/':
			regex_process();
			buffer_print();
			break;
		case 'n':
			goto_match(match_pos + 1);
			buffer_print();
			break;
		case 'N':
			goto_match(match_pos - 1);
			buffer_print();
			break;
		case '?':
			search_backwards();
			buffer_print();
			break;
#endif
#ifdef CONFIG_FEATURE_LESS_FLAGCS
		case '-':
			flag_change();
			buffer_print();
			break;
		case '_':
			show_flag_status();
			break;
#endif
#ifdef CONFIG_FEATURE_LESS_BRACKETS
		case '{': case '(': case '[':
			match_right_bracket(keypress);
			break;
		case '}': case ')': case ']':
			match_left_bracket(keypress);
			break;
#endif
		case ':':
			colon_process();
			break;
		default:
			break;
	}

	if (isdigit(keypress))
		number_process(keypress);
}

int less_main(int argc, char **argv) {

	int keypress;

	flags = bb_getopt_ulflags(argc, argv, "EMmN~");

	argc -= optind;
	argv += optind;
	files = argv;
	num_files = argc;

	if (!num_files) {
		if (ttyname(STDIN_FILENO) == NULL)
			inp_stdin = 1;
		else {
			bb_error_msg("Missing filename");
			bb_show_usage();
		}
	}

	strcpy(filename, (inp_stdin) ? bb_msg_standard_input : files[0]);
	tty_width_height();
	data_readlines();
	tcgetattr(fileno(inp), &term_orig);
	term_vi = term_orig;
	term_vi.c_lflag &= (~ICANON & ~ECHO);
	term_vi.c_iflag &= (~IXON & ~ICRNL);
	term_vi.c_oflag &= (~ONLCR);
	term_vi.c_cc[VMIN] = 1;
	term_vi.c_cc[VTIME] = 0;
	buffer_init();
	buffer_print();

	while (1) {
		keypress = tless_getch();
		keypress_process(keypress);
	}
}
