replace malloc to g_malloc.
fix some leak (thx andrew_b) define TAGS_NAME, MAX_WIDTH_DEF_DIALOG vars
Этот коммит содержится в:
родитель
6c39432c98
Коммит
f3dcf1b3aa
@ -3088,7 +3088,7 @@ edit_select_definition_dialog (WEdit * edit, char *match_expr, int max_len, int
|
||||
|
||||
/* apply the choosen completion */
|
||||
if ( def_dlg->ret_value == B_ENTER ) {
|
||||
listbox_get_current (def_list, &curr, &curr_def);
|
||||
listbox_get_current (def_list, &curr, (etags_hash_t *) &curr_def);
|
||||
int do_moveto = 0;
|
||||
if ( edit->modified ) {
|
||||
if ( !edit_query_dialog2
|
||||
@ -3160,27 +3160,27 @@ edit_get_match_keyword_cmd (WEdit *edit)
|
||||
[word_start & M_EDIT_BUF_SIZE];
|
||||
match_expr = g_strdup_printf ("%.*s", word_len, bufpos);
|
||||
|
||||
path = g_strdup_printf ("%s/", g_get_current_dir());
|
||||
ptr = g_get_current_dir ();
|
||||
path = g_strconcat (ptr, G_DIR_SEPARATOR_S, (char *) NULL);
|
||||
g_free (ptr);
|
||||
|
||||
ptr = path;
|
||||
|
||||
/* Reursive search file 'TAGS' in parent dirs */
|
||||
/* Recursive search file 'TAGS' in parent dirs */
|
||||
do {
|
||||
ptr = g_path_get_dirname (path);
|
||||
g_free(path); path = ptr;
|
||||
|
||||
tagfile = g_build_filename (path, "TAGS", NULL);
|
||||
g_free (tagfile);
|
||||
tagfile = g_build_filename (path, TAGS_NAME, (char *) NULL);
|
||||
if ( exist_file (tagfile) )
|
||||
break;
|
||||
} while (strcmp( path, G_DIR_SEPARATOR_S) != 0);
|
||||
|
||||
if (tagfile){
|
||||
etags_set_definition_hash(tagfile, path, match_expr, (etags_hash_t *) &def_hash, &num_def);
|
||||
num_def = etags_set_definition_hash(tagfile, path, match_expr, (etags_hash_t *) &def_hash);
|
||||
g_free (tagfile);
|
||||
}
|
||||
g_free (path);
|
||||
|
||||
max_len = 60;
|
||||
max_len = MAX_WIDTH_DEF_DIALOG;
|
||||
word_len = 0;
|
||||
if ( num_def > 0 ) {
|
||||
edit_select_definition_dialog (edit, match_expr, max_len, word_len,
|
||||
|
45
edit/etags.c
45
edit/etags.c
@ -3,7 +3,7 @@
|
||||
$ find . -type f -name "*.[ch]" | etags -l c --declarations -
|
||||
|
||||
or, if etags utility not installed:
|
||||
$ find . -type f -name "*.[ch]" | ctags -R --c-kinds=+p --fields=+iaS --extra=+q -e -L-
|
||||
$ find . -type f -name "*.[ch]" | ctags --c-kinds=+p --fields=+iaS --extra=+q -e -L-
|
||||
|
||||
Copyright (C) 2009 Free Software Foundation, Inc.
|
||||
|
||||
@ -36,15 +36,15 @@
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "../src/global.h"
|
||||
#include "../src/util.h" /* canonicalize_pathname() */
|
||||
#include "../edit/etags.h"
|
||||
|
||||
/*** file scope functions **********************************************/
|
||||
|
||||
int parse_define(char *buf, char **long_name, char **short_name, long *line)
|
||||
gboolean parse_define(char *buf, char **long_name, char **short_name, long *line)
|
||||
{
|
||||
enum {in_longname, in_shortname, in_line, finish} def_state = in_longname;
|
||||
|
||||
@ -98,7 +98,7 @@ int parse_define(char *buf, char **long_name, char **short_name, long *line)
|
||||
*long_name = g_strdup (longdef);
|
||||
*short_name = g_strdup (shortdef);
|
||||
*line = atol (linedef);
|
||||
return 1;
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
buf++;
|
||||
@ -107,18 +107,17 @@ int parse_define(char *buf, char **long_name, char **short_name, long *line)
|
||||
*long_name = NULL;
|
||||
*short_name = NULL;
|
||||
*line = 0;
|
||||
return 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*** public functions **************************************************/
|
||||
|
||||
int etags_set_definition_hash(const char *tagfile, const char *start_path,
|
||||
const char *match_func,
|
||||
etags_hash_t *def_hash,
|
||||
int *num)
|
||||
etags_hash_t *def_hash)
|
||||
{
|
||||
FILE *f;
|
||||
static char buf[1024];
|
||||
static char buf[BUF_LARGE];
|
||||
|
||||
char *longname = NULL;
|
||||
char *shortname = NULL;
|
||||
@ -126,13 +125,14 @@ int etags_set_definition_hash(const char *tagfile, const char *start_path,
|
||||
|
||||
char *chekedstr = NULL;
|
||||
|
||||
int num = 0; /* returned value */
|
||||
|
||||
/* open file with positions */
|
||||
f = fopen (tagfile, "r");
|
||||
if (!f)
|
||||
return 1;
|
||||
return 0;
|
||||
|
||||
int pos;
|
||||
char *fullpath = NULL;
|
||||
char *filename = NULL;
|
||||
enum {start, in_filename, in_define} state = start;
|
||||
|
||||
@ -147,7 +147,7 @@ int etags_set_definition_hash(const char *tagfile, const char *start_path,
|
||||
case in_filename:
|
||||
pos = strcspn(buf, ",");
|
||||
g_free(filename);
|
||||
filename = malloc (pos + 2);
|
||||
filename = g_malloc (pos + 2);
|
||||
g_strlcpy(filename, (char *)buf, pos + 1);
|
||||
state = in_define;
|
||||
break;
|
||||
@ -160,27 +160,26 @@ int etags_set_definition_hash(const char *tagfile, const char *start_path,
|
||||
chekedstr = strstr (buf, match_func);
|
||||
if ( chekedstr ) {
|
||||
parse_define (chekedstr, &longname, &shortname, &line);
|
||||
if ( *num < MAX_DEFINITIONS - 1 ) {
|
||||
def_hash[*num].filename_len = strlen (filename);
|
||||
fullpath = g_build_filename (start_path, filename, NULL);
|
||||
canonicalize_pathname (fullpath);
|
||||
def_hash[*num].fullpath = g_strdup(fullpath);
|
||||
g_free (fullpath);
|
||||
def_hash[*num].filename = g_strdup (filename);
|
||||
if ( num < MAX_DEFINITIONS - 1 ) {
|
||||
def_hash[num].filename_len = strlen (filename);
|
||||
def_hash[num].fullpath = g_build_filename (start_path, filename, (char *) NULL);
|
||||
canonicalize_pathname (def_hash[num].fullpath);
|
||||
def_hash[num].filename = g_strdup (filename);
|
||||
if ( shortname ) {
|
||||
def_hash[*num].short_define = g_strdup (shortname);
|
||||
def_hash[num].short_define = g_strdup (shortname);
|
||||
} else {
|
||||
def_hash[*num].short_define = g_strdup (longname);
|
||||
def_hash[num].short_define = g_strdup (longname);
|
||||
}
|
||||
def_hash[*num].line = line;
|
||||
def_hash[num].line = line;
|
||||
g_free(shortname);
|
||||
g_free(longname);
|
||||
(*num)++;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_free(filename);
|
||||
return 0;
|
||||
return num;
|
||||
}
|
||||
|
14
edit/etags.h
14
edit/etags.h
@ -1,19 +1,25 @@
|
||||
#ifndef MC_EDIT_ETAGS_H
|
||||
#define MC_EDIT_ETAGS_H 1
|
||||
|
||||
#define MAX_DEFINITIONS 60
|
||||
#include <sys/types.h> /* size_t */
|
||||
#include "../src/global.h" /* include <glib.h> */
|
||||
|
||||
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
|
||||
#define MAX_DEFINITIONS 60 /* count found entries show */
|
||||
#define SHORT_DEF_LEN 30
|
||||
#define LONG_DEF_LEN 40
|
||||
#define LINE_DEF_LEN 16
|
||||
#define TAGS_NAME "TAGS"
|
||||
|
||||
typedef struct etags_hash_struct {
|
||||
int filename_len;
|
||||
size_t filename_len;
|
||||
unsigned char *fullpath;
|
||||
unsigned char *filename;
|
||||
unsigned char *short_define;
|
||||
long line;
|
||||
} etags_hash_t;
|
||||
|
||||
int etags_set_def_hash(char *tagfile, char *start_path, char *match_func, etags_hash_t *def_hash, int *num);
|
||||
int etags_set_definition_hash (const char *tagfile, const char *start_path,
|
||||
const char *match_func, etags_hash_t *def_hash);
|
||||
|
||||
#endif
|
||||
#endif /* MC_EDIT_ETAGS_H */
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user