Пример #1
0
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);
	}
}
Пример #2
0
static void full_repaint(void)
{
	int temp_line_pos = line_pos;
	data_readlines();
	buffer_init();
	buffer_line(temp_line_pos);
}
Пример #3
0
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;
	}
}
Пример #4
0
static void match_right_bracket(char bracket)
{
	unsigned i;

	if (strchr(flines[cur_fline], bracket) == NULL) {
		print_statusline("No bracket in top line");
		return;
	}
	bracket = opp_bracket(bracket);
	for (i = cur_fline + 1; i < max_fline; i++) {
		if (strchr(flines[i], bracket) != NULL) {
			buffer_line(i);
			return;
		}
	}
	print_statusline("No matching bracket found");
}
Пример #5
0
static void goto_match(int match)
{
	if (!pattern_valid)
		return;
	if (match < 0)
		match = 0;
	/* Try to find next match if eof isn't reached yet */
	if (match >= num_matches && eof_error > 0) {
		wanted_match = match; /* "I want to read until I see N'th match" */
		read_lines();
	}
	if (num_matches) {
		normalize_match_pos(match);
		buffer_line(match_lines[match_pos]);
	} else {
		print_statusline("No matches found");
	}
}
Пример #6
0
static void match_left_bracket(char bracket)
{
	int i;

	if (strchr(flines[cur_fline + max_displayed_line], bracket) == NULL) {
		print_statusline("No bracket in bottom line");
		return;
	}

	bracket = opp_bracket(bracket);
	for (i = cur_fline + max_displayed_line; i >= 0; i--) {
		if (strchr(flines[i], bracket) != NULL) {
			buffer_line(i);
			return;
		}
	}
	print_statusline("No matching bracket found");
}
Пример #7
0
static void goto_mark(void)
{
	int letter;
	int i;

	print_statusline("Go to mark: ");
	letter = less_getch(sizeof("Go to mark: ") - 1);
	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])
			print_statusline("Mark not set");
	} else
		print_statusline("Invalid mark letter");
}
Пример #8
0
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);
}
Пример #9
0
//-----------------------------------------------------------------------------
bool datareader_c::read( solution_ptr& solution, std::string scenario_id, xml_element_ptr top ) {
  if( !buffer_line() ) return false;
  //print_cells();

  solution = solution_ptr( new solution_c( solution_c::MODEL ) );
  solution->scenario_id = scenario_id;
  component_ptr component = boost::dynamic_pointer_cast<solution_c>( solution );

  xml_element_ptr element;
  std::string key, tag;

  for( unsigned i = 0; i < top->elements(); i++ ) {
    element = top->element( i );
    tag = element->get_name();
    if( tag == "Field" ) {
      read_field( component, element );
    } else if( tag == "Model" ) {
      read_model( component, element );
    }
  }

  return true;
}
Пример #10
0
//-----------------------------------------------------------------------------
bool datareader_c::read( trial_ptr& trial, std::string scenario_id, xml_element_ptr top ) {
  if( !buffer_line() ) return false;
  //print_cells();

  trial = trial_ptr( new trial_c() );
  trial->scenario_id = scenario_id;
  component_ptr component = boost::dynamic_pointer_cast<trial_c>( trial );

  xml_element_ptr element;
  std::string key, name;

  for( unsigned i = 0; i < top->elements(); i++ ) {
    element = top->element( i );
    name = element->get_name();
    if( name == "Field" ) {
      read_field( component, element );
    } else if( name == "Model" ) {
      read_model( component, element );
    }
  }

  return true;
}
Пример #11
0
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);
	}
}
Пример #12
0
static void number_process(int first_digit)
{
	unsigned i;
	int num;
	int keypress;
	char num_input[sizeof(int)*4]; /* more than enough */

	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 */
	i = 1;
	while (i < sizeof(num_input)-1) {
		keypress = less_getch(i + 1);
		if ((unsigned)keypress > 255 || !isdigit(num_input[i]))
			break;
		num_input[i] = keypress;
		bb_putchar(keypress);
		i++;
	}

	num_input[i] = '\0';
	num = bb_strtou(num_input, NULL, 10);
	/* on format error, num == -1 */
	if (num < 1 || num > MAXLINES) {
		buffer_print();
		return;
	}

	/* We now know the number and the letter entered, so we process them */
	switch (keypress) {
	case KEYCODE_DOWN: case 'z': case 'd': case 'e': case ' ': case '\015':
		buffer_down(num);
		break;
	case KEYCODE_UP: case 'b': case 'w': case 'y': case 'u':
		buffer_up(num);
		break;
	case 'g': case '<': case 'G': case '>':
		cur_fline = num + max_displayed_line;
		read_lines();
		buffer_line(num - 1);
		break;
	case 'p': case '%':
		num = num * (max_fline / 100); /* + max_fline / 2; */
		cur_fline = num + max_displayed_line;
		read_lines();
		buffer_line(num);
		break;
#if ENABLE_FEATURE_LESS_REGEXP
	case 'n':
		goto_match(match_pos + num);
		break;
	case '/':
		option_mask32 &= ~LESS_STATE_MATCH_BACKWARDS;
		regex_process();
		break;
	case '?':
		option_mask32 |= LESS_STATE_MATCH_BACKWARDS;
		regex_process();
		break;
#endif
	}
}
Пример #13
0
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) {
		buffer_print();
		return;
	}

	/* 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(((num / 100) * num_flines) - 1);
			break;
#ifdef CONFIG_FEATURE_LESS_REGEXP
		case 'n':
			goto_match(match_pos + num);
			break;
		case '/':
			match_backwards = 0;
			regex_process();
			break;
		case '?':
			match_backwards = 1;
			regex_process();
			break;
#endif
		default:
			break;
	}
}
Пример #14
0
static void regex_process(void)
{
	char uncomp_regex[100];
	char *current_line;
	int i;
	int j = 0;
	regex_t pattern;
	/* Get the uncompiled regular expression from the user */
	clear_line();
	putchar((match_backwards) ? '?' : '/');
	uncomp_regex[0] = 0;
	fgets(uncomp_regex, sizeof(uncomp_regex), inp);
	
	if (strlen(uncomp_regex) == 1) {
		if (num_matches)
			goto_match(match_backwards ? match_pos - 1 : match_pos + 1);
		else
			buffer_print();
		return;
	}
	uncomp_regex[strlen(uncomp_regex) - 1] = '\0';
	
	/* Compile the regex and check for errors */
	xregcomp(&pattern, uncomp_regex, 0);

	if (num_matches) {
		/* Get rid of all the highlights we added previously */
		for (i = 0; i <= num_flines; i++) {
			current_line = process_regex_on_line(flines[i], &old_pattern, 0);
			flines[i] = bb_xstrdup(current_line);
		}
	}
	old_pattern = pattern;
	
	/* Reset variables */
	match_lines = xrealloc(match_lines, sizeof(int));
	match_lines[0] = -1;
	match_pos = 0;
	num_matches = 0;
	match_found = 0;
	/* Run the regex on each line of the current file here */
	for (i = 0; i <= num_flines; i++) {
		current_line = process_regex_on_line(flines[i], &pattern, 1);
		flines[i] = bb_xstrdup(current_line);
		if (match_found) {
			match_lines = xrealloc(match_lines, (j + 1) * sizeof(int));
			match_lines[j] = i;
			j++;
		}
	}
	
	num_matches = j;
	if ((match_lines[0] != -1) && (num_flines > height - 2)) {
		if (match_backwards) {
			for (i = 0; i < num_matches; i++) {
				if (match_lines[i] > line_pos) {
					match_pos = i - 1;
					buffer_line(match_lines[match_pos]);
					break;
				}
			}
		}
		else
			buffer_line(match_lines[0]);
	}
	else
		buffer_init();
}
Пример #15
0
static void
print_source (file_info_type *  current_file,
	      list_info_type *  list,
	      unsigned int      width)
{
#define NUM_CACHE_LINES  3
  static cached_line cached_lines[NUM_CACHE_LINES];
  static int next_free_line = 0;
  cached_line * cache = NULL;

  if (current_file->linenum > list->hll_line
      && list->hll_line > 0)
    {
      /* This can happen with modern optimizing compilers.  The source
	 lines from the high level language input program are split up
	 and interleaved, meaning the line number we want to display
	 (list->hll_line) can have already been displayed.  We have
	 three choices:

	   a. Do nothing, since we have already displayed the source
	      line.  This was the old behaviour.

	   b. Display the particular line requested again, but only
	      that line.  This is the new behaviour.

	   c. Display the particular line requested again and reset
	      the current_file->line_num value so that we redisplay
	      all the following lines as well the next time we
	      encounter a larger line number.  */
      int i;

      /* Check the cache, maybe we already have the line saved.  */
      for (i = 0; i < NUM_CACHE_LINES; i++)
	if (cached_lines[i].file == current_file
	    && cached_lines[i].line == list->hll_line)
	  {
	    cache = cached_lines + i;
	    break;
	  }

      if (i == NUM_CACHE_LINES)
	{
	  cache = cached_lines + next_free_line;
	  next_free_line ++;
	  if (next_free_line == NUM_CACHE_LINES)
	    next_free_line = 0;

	  cache->file = current_file;
	  cache->line = list->hll_line;
	  cache->buffer[0] = 0;
	  rebuffer_line (current_file, cache->line, cache->buffer, width);
	}

      emit_line (list, "%4u:%-13s **** %s\n",
		 cache->line, cache->file->filename, cache->buffer);
      return;
    }

  if (!current_file->at_end)
    {
      int num_lines_shown = 0;

      while (current_file->linenum < list->hll_line
	     && !current_file->at_end)
	{
	  char *p;

	  cache = cached_lines + next_free_line;
	  cache->file = current_file;
	  cache->line = current_file->linenum + 1;
	  cache->buffer[0] = 0;
	  p = buffer_line (current_file, cache->buffer, width);

	  /* Cache optimization:  If printing a group of lines
	     cache the first and last lines in the group.  */
	  if (num_lines_shown == 0)
	    {
	      next_free_line ++;
	      if (next_free_line == NUM_CACHE_LINES)
		next_free_line = 0;
	    }

	  emit_line (list, "%4u:%-13s **** %s\n",
		     cache->line, cache->file->filename, p);
	  num_lines_shown ++;
	}
    }
}
Пример #16
0
static void keypress_process(int keypress)
{
	switch (keypress) {
	case KEYCODE_DOWN: case 'e': case 'j': case 0x0d:
		buffer_down(1);
		break;
	case KEYCODE_UP: case 'y': case 'k':
		buffer_up(1);
		break;
	case KEYCODE_PAGEDOWN: case ' ': case 'z': case 'f':
		buffer_down(max_displayed_line + 1);
		break;
	case KEYCODE_PAGEUP: case 'w': case 'b':
		buffer_up(max_displayed_line + 1);
		break;
	case 'd':
		buffer_down((max_displayed_line + 1) / 2);
		break;
	case 'u':
		buffer_up((max_displayed_line + 1) / 2);
		break;
	case KEYCODE_HOME: case 'g': case 'p': case '<': case '%':
		buffer_line(0);
		break;
	case KEYCODE_END: case 'G': case '>':
		cur_fline = MAXLINES;
		read_lines();
		buffer_line(cur_fline);
		break;
	case 'q': case 'Q':
		less_exit(EXIT_SUCCESS);
		break;
#if ENABLE_FEATURE_LESS_MARKS
	case 'm':
		add_mark();
		buffer_print();
		break;
	case '\'':
		goto_mark();
		buffer_print();
		break;
#endif
	case 'r': case 'R':
		buffer_print();
		break;
	/*case 'R':
		full_repaint();
		break;*/
	case 's':
		save_input_to_file();
		break;
	case 'E':
		examine_file();
		break;
#if ENABLE_FEATURE_LESS_FLAGS
	case '=':
		m_status_print();
		break;
#endif
#if ENABLE_FEATURE_LESS_REGEXP
	case '/':
		option_mask32 &= ~LESS_STATE_MATCH_BACKWARDS;
		regex_process();
		break;
	case 'n':
		goto_match(match_pos + 1);
		break;
	case 'N':
		goto_match(match_pos - 1);
		break;
	case '?':
		option_mask32 |= LESS_STATE_MATCH_BACKWARDS;
		regex_process();
		break;
#endif
#if ENABLE_FEATURE_LESS_DASHCMD
	case '-':
		flag_change();
		buffer_print();
		break;
#ifdef BLOAT
	case '_':
		show_flag_status();
		break;
#endif
#endif
#if ENABLE_FEATURE_LESS_BRACKETS
	case '{': case '(': case '[':
		match_right_bracket(keypress);
		break;
	case '}': case ')': case ']':
		match_left_bracket(keypress);
		break;
#endif
	case ':':
		colon_process();
		break;
	}

	if (isdigit(keypress))
		number_process(keypress);
}
Пример #17
0
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_line(0);
			break;
		case 'G': case '>':
			buffer_line(num_flines - height + 2);
			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 '/':
			match_backwards = 0;
			regex_process();
			break;
		case 'n':
			goto_match(match_pos + 1);
			break;
		case 'N':
			goto_match(match_pos - 1);
			break;
		case '?':
			match_backwards = 1;
			regex_process();
			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);
}