mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
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)
This commit is contained in:
parent
ffca67e3cb
commit
8abf76df7c
@ -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 )
|
||||
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;
|
||||
}
|
||||
ptr--;
|
||||
len--;
|
||||
}
|
||||
} while (strcmp( path, G_DIR_SEPARATOR_S) != 0);
|
||||
|
||||
set_def_hash(tagfile, path, match_expr, (struct def_hash_type *) &def_hash, &num_def);
|
||||
g_free (path);
|
||||
if (tagfile){
|
||||
etags_set_def_hash(tagfile, path, match_expr, (struct def_hash_type *) &def_hash, &num_def);
|
||||
g_free (tagfile);
|
||||
}
|
||||
g_free (path);
|
||||
|
||||
max_len = 50;
|
||||
word_len = 0;
|
||||
if ( num_def > 0 ) {
|
||||
|
58
edit/etags.c
58
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 <il.smind@gmail.com>, 2009
|
||||
Slava Zanko <slavazanko@gmail.com>, 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 <config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <glib.h>
|
||||
#include <ctype.h>
|
||||
#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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user