* syntax.c (syntax_g_free): New macro to release and NULLify
glib allocated memory area(s). (strdup_convert): Rename to ... (convert): ... this. Don't strdup passed string. (get_args): Use convert instead of strdup_convert. (free_args): Make it do notning macro. (open_include_file): Eliminate p array. Use glib function to construct error_file_name. Use PATH_SEP instead of '/'; (edit_read_syntax_file): Use PATH_SEP_STR. (edit_load_syntax): Use syntax_g_free to release error_file_name. (edit_read_syntax_rules): Likewise.
Этот коммит содержится в:
родитель
d8bec56efe
Коммит
3eea969c3b
@ -1,3 +1,17 @@
|
|||||||
|
2002-01-15 Andrew V. Samoilov <kai@cmail.ru>
|
||||||
|
|
||||||
|
* syntax.c (syntax_g_free): New macro to release and NULLify
|
||||||
|
glib allocated memory area(s).
|
||||||
|
(strdup_convert): Rename to ...
|
||||||
|
(convert): ... this. Don't strdup passed string.
|
||||||
|
(get_args): Use convert instead of strdup_convert.
|
||||||
|
(free_args): Make it do notning macro.
|
||||||
|
(open_include_file): Eliminate p array. Use glib function to
|
||||||
|
construct error_file_name. Use PATH_SEP instead of '/';
|
||||||
|
(edit_read_syntax_file): Use PATH_SEP_STR.
|
||||||
|
(edit_load_syntax): Use syntax_g_free to release error_file_name.
|
||||||
|
(edit_read_syntax_rules): Likewise.
|
||||||
|
|
||||||
2001-12-22 Andrew V. Samoilov <kai@cmail.ru>
|
2001-12-22 Andrew V. Samoilov <kai@cmail.ru>
|
||||||
|
|
||||||
* editcmd.c (edit_goto_cmd): Use g_free to release f.
|
* editcmd.c (edit_goto_cmd): Use g_free to release f.
|
||||||
|
@ -68,6 +68,7 @@ static void *syntax_malloc (size_t x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define syntax_free(x) {if(x){free(x);(x)=0;}}
|
#define syntax_free(x) {if(x){free(x);(x)=0;}}
|
||||||
|
#define syntax_g_free(x) {if(x){g_free(x);(x)=0;}}
|
||||||
|
|
||||||
static long compare_word_to_right (WEdit * edit, long i, char *text, char *whole_left, char *whole_right, int line_start)
|
static long compare_word_to_right (WEdit * edit, long i, char *text, char *whole_left, char *whole_right, int line_start)
|
||||||
{
|
{
|
||||||
@ -431,10 +432,10 @@ static int read_one_line (char **line, FILE * f)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *strdup_convert (char *s)
|
static char *convert (char *s)
|
||||||
{
|
{
|
||||||
char *r, *p;
|
char *r, *p;
|
||||||
p = r = (char *) strdup (s);
|
p = r = s;
|
||||||
while (*s) {
|
while (*s) {
|
||||||
switch (*s) {
|
switch (*s) {
|
||||||
case '\\':
|
case '\\':
|
||||||
@ -506,21 +507,14 @@ static void get_args (char *l, char **args, int *argc)
|
|||||||
for (l = p + 1; *l && !whiteness (*l); l++);
|
for (l = p + 1; *l && !whiteness (*l); l++);
|
||||||
if (*l)
|
if (*l)
|
||||||
*l++ = '\0';
|
*l++ = '\0';
|
||||||
*args = strdup_convert (p);
|
*args = convert (p);
|
||||||
(*argc)++;
|
(*argc)++;
|
||||||
args++;
|
args++;
|
||||||
}
|
}
|
||||||
*args = 0;
|
*args = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void free_args (char **args)
|
#define free_args(x)
|
||||||
{
|
|
||||||
while (*args) {
|
|
||||||
syntax_free (*args);
|
|
||||||
args++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define break_a {result=line;break;}
|
#define break_a {result=line;break;}
|
||||||
#define check_a {if(!*a){result=line;break;}}
|
#define check_a {if(!*a){result=line;break;}}
|
||||||
#define check_not_a {if(*a){result=line;break;}}
|
#define check_not_a {if(*a){result=line;break;}}
|
||||||
@ -560,25 +554,23 @@ extern char *mc_home;
|
|||||||
static FILE *open_include_file (char *filename)
|
static FILE *open_include_file (char *filename)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char p[MAX_PATH_LEN];
|
|
||||||
syntax_free (error_file_name);
|
syntax_g_free (error_file_name);
|
||||||
error_file_name = (char *) strdup (filename);
|
error_file_name = g_strdup (filename);
|
||||||
if (*filename == '/')
|
if (*filename == PATH_SEP)
|
||||||
return fopen (filename, "r");
|
return fopen (filename, "r");
|
||||||
strcpy (p, home_dir);
|
|
||||||
strcat (p, EDIT_DIR "/");
|
g_free (error_file_name);
|
||||||
strcat (p, filename);
|
error_file_name = g_strconcat (home_dir, EDIT_DIR PATH_SEP_STR,
|
||||||
syntax_free (error_file_name);
|
filename, NULL);
|
||||||
error_file_name = (char *) strdup (p);
|
f = fopen (error_file_name, "r");
|
||||||
f = fopen (p, "r");
|
|
||||||
if (f)
|
if (f)
|
||||||
return f;
|
return f;
|
||||||
strcpy (p, mc_home);
|
|
||||||
strcat (p, "/syntax/");
|
g_free (error_file_name);
|
||||||
strcat (p, filename);
|
error_file_name = g_strconcat (mc_home, PATH_SEP_STR "syntax" PATH_SEP_STR,
|
||||||
syntax_free (error_file_name);
|
filename, NULL);
|
||||||
error_file_name = (char *) strdup (p);
|
return fopen (error_file_name, "r");
|
||||||
return fopen (p, "r");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns line number on error */
|
/* returns line number on error */
|
||||||
@ -613,7 +605,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
|
|||||||
f = g;
|
f = g;
|
||||||
g = 0;
|
g = 0;
|
||||||
line = save_line + 1;
|
line = save_line + 1;
|
||||||
syntax_free (error_file_name);
|
syntax_g_free (error_file_name);
|
||||||
if (l)
|
if (l)
|
||||||
syntax_free (l);
|
syntax_free (l);
|
||||||
if (!read_one_line (&l, f))
|
if (!read_one_line (&l, f))
|
||||||
@ -634,7 +626,7 @@ static int edit_read_syntax_rules (WEdit * edit, FILE * f)
|
|||||||
g = f;
|
g = f;
|
||||||
f = open_include_file (args[1]);
|
f = open_include_file (args[1]);
|
||||||
if (!f) {
|
if (!f) {
|
||||||
syntax_free (error_file_name);
|
syntax_g_free (error_file_name);
|
||||||
result = line;
|
result = line;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -869,7 +861,7 @@ static int edit_read_syntax_file (WEdit * edit, char **names, char *syntax_file,
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
char *lib_file;
|
char *lib_file;
|
||||||
|
|
||||||
lib_file = concat_dir_and_file (mc_home, "syntax/Syntax");
|
lib_file = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax");
|
||||||
check_for_default (lib_file, syntax_file);
|
check_for_default (lib_file, syntax_file);
|
||||||
g_free (lib_file);
|
g_free (lib_file);
|
||||||
|
|
||||||
@ -1004,7 +996,7 @@ void edit_load_syntax (WEdit * edit, char **names, char *type)
|
|||||||
message (0, _(" Load syntax file "),
|
message (0, _(" Load syntax file "),
|
||||||
_(" Error in file %s on line %d "),
|
_(" Error in file %s on line %d "),
|
||||||
error_file_name ? error_file_name : f, r);
|
error_file_name ? error_file_name : f, r);
|
||||||
syntax_free (error_file_name);
|
syntax_g_free (error_file_name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user