diff --git a/chapter/chapter_4.c b/chapter/chapter_4.c index 87822a4..6e5f0a7 100644 --- a/chapter/chapter_4.c +++ b/chapter/chapter_4.c @@ -72,8 +72,8 @@ static void syntax_delete (void) { // } while (--syntax_count != -1); for (offset = 0; offset < syntax_count; ++offset) { - syntax_begin [syntax_count] = deallocate (syntax_begin [syntax_count]); - syntax_end [syntax_count] = deallocate (syntax_end [syntax_count]); + syntax_begin [offset] = deallocate (syntax_begin [offset]); + syntax_end [offset] = deallocate (syntax_end [offset]); } syntax_enrange = deallocate (syntax_enrange); @@ -132,13 +132,17 @@ static int syntax_select (char * string, int * length) { for (select = offset = 0; select != syntax_count; ++select) { if (syntax_enrange [select] == FALSE) { - if (string_compare_limit (string, syntax_begin [select], string_length (syntax_begin [select])) != 0) { - goto selected; + if (string_compare_limit (string, syntax_begin [select], string_length (syntax_begin [select])) == TRUE) { + break; // We need to limit our string comparisson function. + } else { + continue; } } else { for (subset = 0; subset != string_length (syntax_begin [select]); ++subset) { if (string [offset] == syntax_begin [select] [subset]) { - goto selected; + goto selected; // We can't use 'break' here, because it will exit only one loop, not both of them. + } else { + continue; } } } @@ -152,7 +156,71 @@ static int syntax_select (char * string, int * length) { return (syntax_count); } - offset = 0; // TODO: Left of to fix this. Since I changed Xyntax, I need to adapt it. + for (offset = 1; string [offset - 1] != '\0'; ++offset) { + if (string [offset] == syntax_escape [select]) { + ++offset; + continue; + } + + if (syntax_derange [select] == FALSE) { + if (string_compare_limit (& string [offset], syntax_end [select], string_length (syntax_end [select])) == TRUE) { + * length = offset + string_length (syntax_end [select]); + return (select); + } + } else { + subset = 0; + if (string_compare (syntax_end [select], "") == TRUE) { + break; + } do { + if (string [offset] == syntax_end [select] [subset]) { + * length = offset; + goto finished; + } + } while (++subset != string_length (syntax_end [select])); + } + } + + finished: + + return (select); +} +/* +static int syntax_select (char * string, int * length) { + int offset = 0; + int select = 0; + + fatal_failure (syntax_active == FALSE, "syntax_select: Syntax is not active."); + fatal_failure (string == NULL, "syntax_select: String is null."); + fatal_failure (length == NULL, "syntax_select: Length is null."); + + do { + if (syntax_enrange [select] == 0) { + if (string_compare (string, syntax_begin [select]) == TRUE) { + if (syntax_derange [select] == 0) { + break; + } else { + if (character_compare_array (string [string_length (syntax_begin [select])], syntax_end [select]) != 0) { + break; + } + } + } + } else { + int subset = 0; + do { + if (string [offset] == syntax_begin [select] [subset]) { + goto selected; + } + } while (++subset != (int) string_length (syntax_begin [select])); + } + } while (++select != syntax_count); + + selected: + + if (select == syntax_count) { + * length = 1; + + return (syntax_count); + } do { ++offset; @@ -163,28 +231,28 @@ static int syntax_select (char * string, int * length) { } if (syntax_derange [select] == 0) { - if (string_compare_limit (& string [offset], syntax_end [select], string_length (syntax_end [select]))) { + if (string_compare (& string [offset], syntax_end [select]) == TRUE) { * length = offset + string_length (syntax_end [select]); return (select); } } else { - subset = 0; - if (string_compare (syntax_end [select], "") == 0) { + int subset = 0; + if (string_compare (syntax_end [select], "") != 0) { break; } do { if (string [offset] == syntax_end [select] [subset]) { * length = offset; return (select); } - } while (++subset != string_length (syntax_end [select])); + } while (++subset != (int) string_length (syntax_end [select])); } } while (string [offset - 1] != '\0'); return (select); } - +*/ static void syntax_highlight_c (void) { - char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n"; + char * separators = ".,:;<=>+*-/%!&~^?|()[]{}'\" \t\r\n"; char * keywords [] = { "register", "volatile", "auto", "const", "static", "extern", "if", "else",