From 8abf76df7c3140e85d2a83391c4ee54bd52a0924 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Mon, 2 Mar 2009 16:43:22 +0200 Subject: [PATCH] edit/editcmd.c * changed searching algorithm of 'TAGS' file * changed #include "etags.h" to "../edit/etags.h" for building outside of sources tree edit/etags.c: * apply template from maint/template.c file * rename all functions with prefix etags_* * make function "etags_get_pos_from" in file-scope visibility edit/etags.h: * added logic block "#ifndef ... #define ... #endif" for correctly processing of header file * remove declaration of file-scope function etags_get_pos_from (ex. get_pos_from) --- edit/editcmd.c | 36 +++++++++++++++---------------- edit/etags.c | 58 +++++++++++++++++++++++++++++++++++++++++++++----- edit/etags.h | 9 ++++++-- 3 files changed, 77 insertions(+), 26 deletions(-) diff --git a/edit/editcmd.c b/edit/editcmd.c index ef968df24..4ea2cf7e7 100644 --- a/edit/editcmd.c +++ b/edit/editcmd.c @@ -45,7 +45,7 @@ #include "editlock.h" #include "editcmddef.h" #include "edit-widget.h" -#include "etags.h" +#include "../edit/etags.h" #include "../src/panel.h" #include "../src/color.h" /* dialog_colors */ @@ -3133,13 +3133,11 @@ edit_get_match_keyword_cmd (WEdit *edit) { int word_len = 0, num_def = 0, max_len; long word_start = 0; - int len = 0; unsigned char *bufpos; char *match_expr; char *path = NULL; char *ptr = NULL; char *tagfile = NULL; - FILE *f; struct def_hash_type def_hash[MAX_DEFINITIONS]; @@ -3157,25 +3155,25 @@ edit_get_match_keyword_cmd (WEdit *edit) match_expr = g_strdup_printf ("%.*s", word_len, bufpos); path = g_strdup_printf ("%s/", g_get_current_dir()); - len = strlen (path); - ptr = path + len; - while ( ptr != path ) { - if ( *ptr == '/' ) { - path[len] = '\0'; - g_free (tagfile); - tagfile = g_strdup_printf ("%s/TAGS", path); - f = fopen (tagfile, "r"); - if ( f ) - break; - } - ptr--; - len--; + ptr = path; + + /* Reursive 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); + if ( exist_file (tagfile) ) + break; + } while (strcmp( path, G_DIR_SEPARATOR_S) != 0); + + if (tagfile){ + etags_set_def_hash(tagfile, path, match_expr, (struct def_hash_type *) &def_hash, &num_def); + g_free (tagfile); } - - set_def_hash(tagfile, path, match_expr, (struct def_hash_type *) &def_hash, &num_def); g_free (path); - g_free (tagfile); + max_len = 50; word_len = 0; if ( num_def > 0 ) { diff --git a/edit/etags.c b/edit/etags.c index 9ac4feeca..caca547a0 100644 --- a/edit/etags.c +++ b/edit/etags.c @@ -1,13 +1,58 @@ -/*find . -type f -name "*.[ch]" | etags -l c --declarations - */ +/* editor C-code navigation via tags. + make TAGS file via command: + $ find . -type f -name "*.[ch]" | etags -l c --declarations - + + or, if etags utility not installed: + $ ctags --languages=c -e -R -h '[ch]' + + Copyright (C) 2009 Free Software Foundation, Inc. + + Authors: + Ilia Maslakov , 2009 + Slava Zanko , 2009 + + + This file is part of the Midnight Commander. + + The Midnight Commander is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Midnight Commander is distributed in the hope that it will be + useful, but WITHOUT ANY WARRANTY; without even the implied warranty + of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. +*/ + +#include + #include #include #include #include #include #include -#include "etags.h" -long get_pos_from(char *str) +#include "../src/global.h" +#include "../edit/etags.h" + +/*** global variables **************************************************/ + +/*** file scope macro definitions **************************************/ + +/*** file scope type declarations **************************************/ + +/*** file scope variables **********************************************/ + +/*** file scope functions **********************************************/ + +static long etags_get_pos_from(char *str) { static char buf[16]; int i, j; @@ -25,7 +70,10 @@ long get_pos_from(char *str) return 0; } -int set_def_hash(char *tagfile, char *start_path, char *match_func, struct def_hash_type *def_hash, int *num) +/*** public functions **************************************************/ + + +int etags_set_def_hash(char *tagfile, char *start_path, char *match_func, struct def_hash_type *def_hash, int *num) { FILE *f; static char buf[4048]; @@ -68,7 +116,7 @@ int set_def_hash(char *tagfile, char *start_path, char *match_func, struct def_h int l = (int)strlen( buf ); for ( i = 0; i < l; i++) { if ( ( buf[i] == 0x7F || buf[i] == 0x01 ) && isdigit(buf[i+1]) ) { - line = get_pos_from(&buf[i+1]); + line = etags_get_pos_from(&buf[i+1]); state = start; if ( *num < MAX_DEFINITIONS ) { def_hash[*num].filename_len = strlen(filename); diff --git a/edit/etags.h b/edit/etags.h index 8d25e784a..b06ada96c 100644 --- a/edit/etags.h +++ b/edit/etags.h @@ -1,3 +1,6 @@ +#ifndef MC_EDIT_ETAGS_H +#define MC_EDIT_ETAGS_H 1 + #define MAX_DEFINITIONS 50 struct def_hash_type { @@ -5,5 +8,7 @@ struct def_hash_type { unsigned char *filename; long line; }; -long get_pos_from(char *str); -int set_def_hash(char *tagfile, char *start_path, char *match_func, struct def_hash_type *def_hash, int *num); + +int etags_set_def_hash(char *tagfile, char *start_path, char *match_func, struct def_hash_type *def_hash, int *num); + +#endif