Example #1
0
File: cmds.c Project: hankem/jed
/* does not leave current line */
unsigned char *jed_skip_whitespace (void)
{
   unsigned char *p, *pmax;

   p = CLine->data + Point;
   pmax = jed_eol_position (CLine);

   while ((p < pmax) && IS_WHITESPACE(p))
     p = jed_multibyte_chars_forward (p, pmax, 1, NULL, 0);

   jed_position_point (p);
   return p;
}
Example #2
0
void write_syntax_highlight (int row, Line *l, unsigned int len)
{
   Syntax_Table_Type *st = CBuf->syntax_table;
   unsigned char ch;
   unsigned int flags;
   unsigned char *p1;
   unsigned short syntax;
   register unsigned char *p;
   register unsigned char *pmax;
   int context;

   p = l->data;
   pmax = p + len;

#if JED_HAS_COLOR_COLUMNS
   if (CBuf->coloring_style)
     {
	color_columns (row, p, pmax);
	return;
     }
#endif

   if (st == NULL) return;

#if JED_HAS_DFA_SYNTAX
   if (st->use_dfa_syntax
       && (st->hilite != NULL)
       && (st->hilite->dfa != NULL))
     {
	dfa_syntax_highlight (p, pmax, st);
	return;
     }
#endif

   flags = st->flags;

#if JED_HAS_LINE_ATTRIBUTES
   context = l->flags & JED_LINE_SYNTAX_BITS;
#else
   context = 0;
#endif

   if (context & JED_LINE_IN_COMMENT)
     {
	/* I do not like the whitespace that preceeds the
	 * '*' on the current line to be highlighted.  So...
	 */
	if (flags & C_COMMENT_TYPE)
	  {
	     p1 = p;
	     while ((p1 < pmax) && ((*p1 == ' ') || (*p1 == '\t')))
	       p1++;

	     if ((p1 < pmax) && (*p1 == '*'))
	       p = write_using_color (p, p1, 0);
	  }

	p = highlight_comment (p, p, pmax, st);
     }
   else if (context & JED_LINE_IN_STRING0)
     {
	p = highlight_string (p, pmax, st->quote_char, st->string_chars[0], 0);
     }
   else if (context & JED_LINE_IN_STRING1)
     {
	p = highlight_string (p, pmax, st->quote_char, st->string_chars[1], 0);
     }
   else if (context & JED_LINE_IN_HTML)
     {
	p1 = p;
	ch = st->sgml_stop_char;
	while ((p1 < pmax) && (*p1++ != ch))
	  ;
	p = write_using_color (p, p1, JHTML_KEY_COLOR);
     }
   else if ((flags & FORTRAN_TYPE)
	    && st->fortran_comment_chars[*p])
     {
	(void) write_using_color (p, pmax, JCOM_COLOR);
	return;
     }
   else
     {
	/* Handle the preprocessor */
	if (flags & PREPROCESS_IGNORE_WHITESPACE)
	  {
	     p = write_whitespace (p, pmax, JTWS_COLOR);
	     if (p == pmax)
	       return;
	  }
	if (*p == st->preprocess)
	  {
	     if (flags & PREPROCESS_COLOR_WHOLE_LINE)
	       {
		  (void) write_using_color (p, pmax, JPREPROC_COLOR);
		  return;
	       }
	     p1 = p + 1;
	     /* FIXME!!! I need to add a whitespace syntax */
	     while ((p1 < pmax) && ((*p1 == ' ') || (*p1 == '\t')))
	       p1++;
	     while ((p1 < pmax) && (Char_Syntax[*p1] != 0))
	       p1++;

	     p = write_using_color (p, p1, JPREPROC_COLOR);
	  }
     }

   /* Now the preliminary stuff is done so do the hard part */
   while (p < pmax)
     {
	syntax = Char_Syntax[*p];

	/* Do comment syntax before word syntax since the comment start
	 * may be a word.
	 */
	if (syntax & COMMENT_SYNTAX)
	  {
	     p1 = p + 1;
	     ch = *p;

	     if ((st->comment_start != NULL)
		 && (ch == st->comment_start[0])
		 && (p + st->comment_start_len <= pmax)
		 && (0 == strncmp ((char *)p, st->comment_start, st->comment_start_len)))
	       {
		  p = highlight_comment (p, p + st->comment_start_len, pmax, st);
		  continue;
	       }

	     if (_jed_is_eol_comment_start (st, l, p, pmax, NULL))
	       {
		  (void) write_using_color (p, pmax, JCOM_COLOR);
		  return;
	       }
	  }

	if (syntax & WORD_SYNTAX)
	  {
	     if ((*p > '9') || (0 == (syntax & NUMBER_SYNTAX)))
	       {
		  p = highlight_word (p, pmax);
		  continue;
	       }
	  }

	if (syntax == 0)
	  {
	     p1 = p;
	     while ((p1 < pmax) && (Char_Syntax[*p1] == 0))
	       p1++;
	     if ((p1 != pmax)
		 || ((Jed_Highlight_WS & HIGHLIGHT_WS_TRAILING) == 0))
	       {
		  p = write_using_color (p, p1, 0);
		  continue;
	       }
	     while (p1 > p)
	       {
		  p1--;
		  if ((*p1 != ' ') && (*p1 != '\t'))
		    {
		       p1++;
		       break;
		    }
	       }
	     p = write_using_color (p, p1, 0);
	     if (p1 != pmax)
	       (void) write_using_color (p1, pmax, JTWS_COLOR);
	     return;
	  }

	if (syntax & DELIM_SYNTAX)
	  {
	     p = write_using_color (p, p + 1, JDELIM_COLOR);
	     continue;
	  }

	if (syntax & STRING_SYNTAX)
	  {
	     p = highlight_string (p, pmax, st->quote_char, *p, 1);
	     continue;
	  }

	if (syntax & OP_SYNTAX)
	  {
	     p = write_using_color (p, p + 1, JOP_COLOR);
	     continue;
	  }

	if (syntax & NUMBER_SYNTAX)
	  {
	     p = highlight_number (p, pmax);
	     continue;
	  }

	if (syntax & HTML_START_SYNTAX)
	  {
	     p1 = p;
	     while (p1 < pmax)
	       {
		  if (Char_Syntax[*p1] & HTML_END_SYNTAX)
		    {
		       p1++;
		       break;
		    }
		  p1++;
	       }
	     p = write_using_color (p, p1, JHTML_KEY_COLOR);
	     continue;
	  }

	if (syntax & HTML_END_SYNTAX)  /* missed start from previous line */
	  {
	     /* FIXME!!! Start from beginning */
	     p = write_using_color (p, p + 1, JHTML_KEY_COLOR);
	     continue;
	  }

	if ((syntax & OPEN_DELIM_SYNTAX) || (syntax & CLOSE_DELIM_SYNTAX))
	  {
	     p = write_using_color (p, p + 1, JDELIM_COLOR);
	     continue;
	  }

	if ((syntax & QUOTE_SYNTAX) && (flags & TEX_LIKE_KEYWORDS))
	  {
	     p1 = p + 1;
	     if (p1 < pmax)
	       {
		  if (Char_Syntax[*p1] & WORD_SYNTAX)
		    {
		       do
			 {
			    p1++;
			 }
		       while ((p1 < pmax) && (Char_Syntax[*p1] & WORD_SYNTAX));
		    }
		  else p1++;
	       }
	     p = write_using_color (p, p1, JKEY_COLOR);
	     continue;
	  }

	if (syntax & QUOTE_SYNTAX)
	  {
	     p1 = jed_multibyte_chars_forward (p, pmax, 2, NULL, 1);
	     /* p1 = p + 2; */
	     if (p1 < pmax)
	       {
		  p = write_using_color (p, p1, 0);
		  continue;
	       }
	  }

	/* Undefined. */
	p = write_using_color (p, p + 1, 0);
     }
}