mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
* syntax.c (edit_read_syntax_rules): Check for list of defines
is already initialized. (edit_read_syntax_file): Process `include ...` before first `file ...`, so color definitions can be stored separately.
This commit is contained in:
parent
0503338aaf
commit
902cd4834b
@ -1,5 +1,10 @@
|
|||||||
2003-03-03 Andrew V. Samoilov <sav@bcs.zp.ua>
|
2003-03-03 Andrew V. Samoilov <sav@bcs.zp.ua>
|
||||||
|
|
||||||
|
* syntax.c (edit_read_syntax_rules): Check for list of defines
|
||||||
|
is already initialized.
|
||||||
|
(edit_read_syntax_file): Process `include ...` before first
|
||||||
|
`file ...`, so color definitions can be stored separately.
|
||||||
|
|
||||||
* syntax.c (subst_defines): New function to substitute defines.
|
* syntax.c (subst_defines): New function to substitute defines.
|
||||||
(this_try_alloc_color_pair): Move color substitution ...
|
(this_try_alloc_color_pair): Move color substitution ...
|
||||||
(edit_read_syntax_rules): ... here. Use subst_defines() to
|
(edit_read_syntax_rules): ... here. Use subst_defines() to
|
||||||
|
@ -656,6 +656,7 @@ edit_read_syntax_rules (WEdit *edit, FILE *f, char **args)
|
|||||||
|
|
||||||
r = edit->rules = g_malloc0 (MAX_CONTEXTS * sizeof (struct context_rule *));
|
r = edit->rules = g_malloc0 (MAX_CONTEXTS * sizeof (struct context_rule *));
|
||||||
|
|
||||||
|
if (!defines)
|
||||||
defines = g_tree_new ((GCompareFunc) strcmp);
|
defines = g_tree_new ((GCompareFunc) strcmp);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -927,7 +928,7 @@ edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
|
|||||||
const char *editor_file, const char *first_line,
|
const char *editor_file, const char *first_line,
|
||||||
const char *type)
|
const char *type)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f, *g = NULL;
|
||||||
regex_t r;
|
regex_t r;
|
||||||
regmatch_t pmatch[1];
|
regmatch_t pmatch[1];
|
||||||
char *args[1024], *l = 0;
|
char *args[1024], *l = 0;
|
||||||
@ -936,6 +937,7 @@ edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char *lib_file;
|
char *lib_file;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
f = fopen (syntax_file, "r");
|
f = fopen (syntax_file, "r");
|
||||||
if (!f){
|
if (!f){
|
||||||
@ -954,11 +956,21 @@ edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
|
|||||||
get_args (l, args, &argc);
|
get_args (l, args, &argc);
|
||||||
if (!args[0])
|
if (!args[0])
|
||||||
continue;
|
continue;
|
||||||
|
/* Looking for `include ...` lines before first `file ...` ones */
|
||||||
|
if (!found && !strcmp (args[0], "include")) {
|
||||||
|
if (g)
|
||||||
|
continue;
|
||||||
|
if (!args[1] || !(g = open_include_file (args[1]))) {
|
||||||
|
result = line;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
goto found_type;
|
||||||
|
}
|
||||||
/* looking for `file ...' lines only */
|
/* looking for `file ...' lines only */
|
||||||
if (strcmp (args[0], "file")) {
|
if (strcmp (args[0], "file")) {
|
||||||
free_args (args);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
found = 1;
|
||||||
/* must have two args or report error */
|
/* must have two args or report error */
|
||||||
if (!args[1] || !args[2]) {
|
if (!args[1] || !args[2]) {
|
||||||
result = line;
|
result = line;
|
||||||
@ -994,7 +1006,7 @@ edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
|
|||||||
if (q) {
|
if (q) {
|
||||||
int line_error;
|
int line_error;
|
||||||
found_type:
|
found_type:
|
||||||
line_error = edit_read_syntax_rules (edit, f, args);
|
line_error = edit_read_syntax_rules (edit, g ? g : f, args);
|
||||||
if (line_error) {
|
if (line_error) {
|
||||||
if (!error_file_name) /* an included file */
|
if (!error_file_name) /* an included file */
|
||||||
result = line + line_error;
|
result = line + line_error;
|
||||||
@ -1004,18 +1016,21 @@ edit_read_syntax_file (WEdit * edit, char **names, const char *syntax_file,
|
|||||||
syntax_g_free (edit->syntax_type);
|
syntax_g_free (edit->syntax_type);
|
||||||
edit->syntax_type = g_strdup (args[2]);
|
edit->syntax_type = g_strdup (args[2]);
|
||||||
/* if there are no rules then turn off syntax highlighting for speed */
|
/* if there are no rules then turn off syntax highlighting for speed */
|
||||||
if (!edit->rules[1])
|
if (!g && !edit->rules[1])
|
||||||
if (!edit->rules[0]->keyword[1] && !edit->rules[0]->spelling) {
|
if (!edit->rules[0]->keyword[1] && !edit->rules[0]->spelling) {
|
||||||
edit_free_syntax_rules (edit);
|
edit_free_syntax_rules (edit);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (g) {
|
||||||
|
fclose (g);
|
||||||
|
g = NULL;
|
||||||
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free_args (args);
|
|
||||||
}
|
}
|
||||||
free_args (args);
|
}
|
||||||
syntax_g_free (l);
|
syntax_g_free (l);
|
||||||
fclose (f);
|
fclose (f);
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user