Browse Source

[bim] more C keywords

K. Lange 2 years ago
parent
commit
6d34e9ae4a
1 changed files with 21 additions and 12 deletions
  1. 21 12
      apps/bim.c

+ 21 - 12
apps/bim.c

@@ -589,7 +589,14 @@ static char * syn_c_types[] = {
 	"static","int","char","short","float","double","void","unsigned","volatile","const",
 	"register","long","inline","restrict","enum","auto","extern","bool","complex",
 	"uint8_t","uint16_t","uint32_t","uint64_t",
-	"int8_t","int16_t","int32_t","int64_t",
+	"int8_t","int16_t","int32_t","int64_t","FILE",
+	NULL
+};
+
+static char * syn_c_special[] = {
+	"NULL",
+	"stdin","stdout","stderr",
+	"STDIN_FILENO","STDOUT_FILENO","STDERR_FILENO",
 	NULL
 };
 
@@ -601,15 +608,17 @@ static int syn_c_extended(line_t * line, int i, int c, int last, int * out_left)
 		}
 		return FLAG_PRAGMA;
 	}
-
-	if ((!last || !syn_c_iskeywordchar(last)) && (i < line->actual - 3) &&
-		line->text[i].codepoint == 'N' &&
-		line->text[i+1].codepoint == 'U' &&
-		line->text[i+2].codepoint == 'L' &&
-		line->text[i+3].codepoint == 'L' &&
-		(i == line->actual - 4 || !syn_c_iskeywordchar(line->text[i+4].codepoint))) {
-		*out_left = 3;
-		return FLAG_NUMERAL;
+	
+	if ((!last || !syn_c_iskeywordchar(last)) && syn_c_iskeywordchar(c)) {
+		int j = i;
+		for (int s = 0; syn_c_special[s]; ++s) {
+			int d = 0;
+			while (j + d < line->actual && line->text[j+d].codepoint == syn_c_special[s][d]) d++;
+			if (syn_c_special[s][d] == '\0' && (j+d > line->actual || !syn_c_iskeywordchar(line->text[j+d].codepoint))) {
+				*out_left = d-1;
+				return FLAG_NUMERAL;
+			}
+		}
 	}
 
 	if ((!last || !syn_c_iskeywordchar(last)) && isdigit(c)) {
@@ -1709,7 +1718,7 @@ void add_indent(int new_line, int old_line) {
 				char_t c;
 				c.codepoint = '\t';
 				c.display_width = env->tabstop;
-				env->lines[new_line] = line_insert(env->lines[new_line], c, env->lines[new_line]->actual-1, new_line);
+				env->lines[new_line] = line_insert(env->lines[new_line], c, env->lines[new_line]->actual, new_line);
 				env->col_no++;
 				changed = 1;
 			} else {
@@ -1718,7 +1727,7 @@ void add_indent(int new_line, int old_line) {
 					c.codepoint = ' ';
 					c.display_width = 1;
 					c.flags = FLAG_SELECT;
-					env->lines[new_line] = line_insert(env->lines[new_line], c, env->lines[new_line]->actual-1, new_line);
+					env->lines[new_line] = line_insert(env->lines[new_line], c, env->lines[new_line]->actual, new_line);
 					env->col_no++;
 				}
 				changed = 1;