etags: get rid of limitation of definition length.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-02-20 11:43:29 +03:00
parent ce05476057
commit 451e1585a7
2 changed files with 61 additions and 29 deletions

View File

@ -80,12 +80,10 @@ parse_define (const char *buf, char **long_name, char **short_name, long *line)
} def_state = in_longname; } def_state = in_longname;
/* *INDENT-ON* */ /* *INDENT-ON* */
static char longdef[LONG_DEF_LEN]; GString *longdef = NULL;
static char shortdef[SHORT_DEF_LEN]; GString *shortdef = NULL;
static char linedef[LINE_DEF_LEN]; GString *linedef = NULL;
int nlong = 0;
int nshort = 0;
int nline = 0;
char c = *buf; char c = *buf;
while (!(c == '\0' || c == '\n')) while (!(c == '\0' || c == '\n'))
@ -97,22 +95,34 @@ parse_define (const char *buf, char **long_name, char **short_name, long *line)
def_state = in_line; def_state = in_line;
else if (c == 0x7F) else if (c == 0x7F)
def_state = in_shortname; def_state = in_shortname;
else if (nlong < LONG_DEF_LEN - 1) else
longdef[nlong++] = c; {
if (longdef == NULL)
longdef = g_string_sized_new (32);
g_string_append_c (longdef, c);
}
break; break;
case in_shortname_first_char: case in_shortname_first_char:
if (isdigit (c)) if (isdigit (c))
{ {
nshort = 0; if (shortdef == NULL)
shortdef = g_string_sized_new (32);
else
g_string_set_size (shortdef, 0);
buf--; buf--;
def_state = in_line; def_state = in_line;
} }
else if (c == 0x01) else if (c == 0x01)
def_state = in_line; def_state = in_line;
else if (nshort < SHORT_DEF_LEN - 1) else
{ {
shortdef[nshort++] = c; if (shortdef == NULL)
shortdef = g_string_sized_new (32);
g_string_append_c (shortdef, c);
def_state = in_shortname; def_state = in_shortname;
} }
break; break;
@ -122,24 +132,38 @@ parse_define (const char *buf, char **long_name, char **short_name, long *line)
def_state = in_line; def_state = in_line;
else if (c == '\n') else if (c == '\n')
def_state = finish; def_state = finish;
else if (nshort < SHORT_DEF_LEN - 1) else
shortdef[nshort++] = c; {
if (shortdef == NULL)
shortdef = g_string_sized_new (32);
g_string_append_c (shortdef, c);
}
break; break;
case in_line: case in_line:
if (c == ',' || c == '\n') if (c == ',' || c == '\n')
def_state = finish; def_state = finish;
else if (isdigit (c) && nline < LINE_DEF_LEN - 1) else if (isdigit (c))
linedef[nline++] = c; {
if (linedef == NULL)
linedef = g_string_sized_new (32);
g_string_append_c (linedef, c);
}
break; break;
case finish: case finish:
longdef[nlong] = '\0'; *long_name = longdef == NULL ? NULL : g_string_free (longdef, FALSE);
shortdef[nshort] = '\0'; *short_name = shortdef == NULL ? NULL : g_string_free (shortdef, FALSE);
linedef[nline] = '\0';
*long_name = longdef; if (linedef == NULL)
*short_name = shortdef; *line = 0;
*line = atol (linedef); else
{
*line = atol (linedef->str);
g_string_free (linedef, TRUE);
}
return TRUE; return TRUE;
default: default:
@ -218,17 +242,28 @@ etags_set_definition_hash (const char *tagfile, const char *start_path, const ch
{ {
char *longname = NULL; char *longname = NULL;
char *shortname = NULL; char *shortname = NULL;
long line = 0;
etags_hash_t *def_hash; etags_hash_t *def_hash;
parse_define (chekedstr, &longname, &shortname, &line);
def_hash = g_new (etags_hash_t, 1); def_hash = g_new (etags_hash_t, 1);
def_hash->fullpath = mc_build_filename (start_path, filename, (char *) NULL); def_hash->fullpath = mc_build_filename (start_path, filename, (char *) NULL);
canonicalize_pathname (def_hash->fullpath); canonicalize_pathname (def_hash->fullpath);
def_hash->filename = g_strdup (filename); def_hash->filename = g_strdup (filename);
def_hash->short_define = g_strdup (shortname != NULL ? shortname : longname);
def_hash->line = line; def_hash->line = 0;
parse_define (chekedstr, &longname, &shortname, &def_hash->line);
if (shortname != NULL && *shortname != '\0')
{
def_hash->short_define = shortname;
g_free (longname);
}
else
{
def_hash->short_define = longname;
g_free (shortname);
}
if (ret == NULL) if (ret == NULL)
ret = g_ptr_array_new_with_free_func (etags_hash_free); ret = g_ptr_array_new_with_free_func (etags_hash_free);

View File

@ -4,9 +4,6 @@
/*** typedefs(not structures) and defined constants **********************************************/ /*** typedefs(not structures) and defined constants **********************************************/
#define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */ #define MAX_WIDTH_DEF_DIALOG 60 /* max width def dialog */
#define SHORT_DEF_LEN 30
#define LONG_DEF_LEN 40
#define LINE_DEF_LEN 16
/*** enums ***************************************************************************************/ /*** enums ***************************************************************************************/