Ejemplo n.º 1
0
Archivo: prompt.c Proyecto: rofl0r/nano
/* Move to the beginning of the prompt text.  If the SMART_HOME flag is
 * set, move to the first non-whitespace character of the prompt text if
 * we're not already there, or to the beginning of the prompt text if we
 * are. */
void do_statusbar_home(void)
{
    size_t pww_save = statusbar_pww;

#ifndef NANO_TINY
    if (ISSET(SMART_HOME)) {
	size_t statusbar_x_save = statusbar_x;

	statusbar_x = indent_length(answer);

	if (statusbar_x == statusbar_x_save ||
		statusbar_x == strlen(answer))
	    statusbar_x = 0;

	statusbar_pww = statusbar_xplustabs();
    } else {
#endif
	statusbar_x = 0;
	statusbar_pww = statusbar_xplustabs();
#ifndef NANO_TINY
    }
#endif

    if (need_statusbar_horizontal_update(pww_save))
	update_statusbar_line(answer, statusbar_x);
}
Ejemplo n.º 2
0
/* Move to the beginning of the current line.  If the SMART_HOME flag is
 * set, move to the first non-whitespace character of the current line
 * if we aren't already there, or to the beginning of the current line
 * if we are. */
void do_home(void)
{
    size_t pww_save = openfile->placewewant;

#ifndef NANO_TINY
    if (ISSET(SMART_HOME)) {
	size_t current_x_save = openfile->current_x;

	openfile->current_x = indent_length(openfile->current->data);

	if (openfile->current_x == current_x_save ||
		openfile->current->data[openfile->current_x] == '\0')
	    openfile->current_x = 0;

	openfile->placewewant = xplustabs();
    } else {
#endif
	openfile->current_x = 0;
	openfile->placewewant = 0;
#ifndef NANO_TINY
    }
#endif

    if (need_horizontal_update(pww_save))
	update_line(openfile->current, openfile->current_x);
}
Ejemplo n.º 3
0
/* Move to the beginning of the current line.  If the SMART_HOME flag is
 * set, move to the first non-whitespace character of the current line
 * if we aren't already there, or to the beginning of the current line
 * if we are. */
void do_home(void)
{
    size_t was_column = xplustabs();

#ifndef NANO_TINY
    if (ISSET(SMART_HOME)) {
	size_t current_x_save = openfile->current_x;

	openfile->current_x = indent_length(openfile->current->data);

	if (openfile->current_x == current_x_save ||
		openfile->current->data[openfile->current_x] == '\0')
	    openfile->current_x = 0;
    } else
#endif
	openfile->current_x = 0;

    openfile->placewewant = xplustabs();

    if (need_horizontal_scroll(was_column, openfile->placewewant))
	update_line(openfile->current, openfile->current_x);
}
Ejemplo n.º 4
0
/* Process a stream. This is where the real work happens,
 * except that centering is handled separately.
 */
static void
process_stream(FILE *stream, const char *name) {
  size_t last_indent=SILLY;	/* how many spaces in last indent? */
  size_t para_line_number=0;	/* how many lines already read in this para? */
  size_t first_indent=SILLY;	/* indentation of line 0 of paragraph */
  HdrType prev_header_type=hdr_ParagraphStart;
	/* ^-- header_type of previous line; -1 at para start */
  wchar_t *line;
  size_t length;

  if (centerP) { center_stream(stream, name); return; }
  while ((line=get_line(stream,&length)) != NULL) {
    size_t np=indent_length(line, length);
    { HdrType header_type=hdr_NonHeader;
      if (grok_mail_headers && prev_header_type!=hdr_NonHeader) {
        if (np==0 && might_be_header(line))
          header_type = hdr_Header;
        else if (np>0 && prev_header_type>hdr_NonHeader)
          header_type = hdr_Continuation;
      }
      /* We need a new paragraph if and only if:
       *   this line is blank,
       *   OR it's a troff request (and we don't format troff),
       *   OR it's a mail header,
       *   OR it's not a mail header AND the last line was one,
       *   OR the indentation has changed
       *      AND the line isn't a mail header continuation line
       *      AND this isn't the second line of an indented paragraph.
       */
      if ( length==0
           || (line[0]=='.' && !format_troff)
           || header_type==hdr_Header
           || (header_type==hdr_NonHeader && prev_header_type>hdr_NonHeader)
           || (np!=last_indent
               && header_type != hdr_Continuation
               && (!allow_indented_paragraphs || para_line_number != 1)) ) {
        new_paragraph(output_in_paragraph ? last_indent : first_indent, np);
        para_line_number = 0;
        first_indent = np;
        last_indent = np;
        if (header_type==hdr_Header) last_indent=2;	/* for cont. lines */
        if (length==0 || (line[0]=='.' && !format_troff)) {
          if (length==0)
            putwchar('\n');
          else
            wprintf(L"%.*ls\n", (int)length, line);
          prev_header_type=hdr_ParagraphStart;
          continue;
        }
      }
      else {
        /* If this is an indented paragraph other than a mail header
         * continuation, set |last_indent|.
         */
        if (np != last_indent && header_type != hdr_Continuation)
          last_indent=np;
      }
      prev_header_type = header_type;
    }

    { size_t n=np;
      while (n<length) {
        /* Find word end and count spaces after it */
        size_t word_length=0, space_length=0;
        while (n+word_length < length && line[n+word_length] != ' ')
          ++word_length;
        space_length = word_length;
        while (n+space_length < length && line[n+space_length] == ' ')
          ++space_length;
        /* Send the word to the output machinery. */
        output_word(first_indent, last_indent,
                    line+n, word_length, space_length-word_length);
        n += space_length;
      }
    }
    ++para_line_number;
  }
  new_paragraph(output_in_paragraph ? last_indent : first_indent, 0);
  if (ferror(stream)) { warn("%s", name); ++n_errors; }
}