Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Sat, 08 Oct 2016 15:38:31 UTC Commit: 1a43ee2afa2cbecd497554aa3c07163ea5dabd01 https://github.com/geany/geany/commit/1a43ee2afa2cbecd497554aa3c07163ea5dabd...
Log Message: ----------- Grab uctags kind.c/h
Modified Paths: -------------- ctags/main/kind.c ctags/main/kind.h
Modified: ctags/main/kind.c 158 lines changed, 158 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,158 @@ +/* + * + * Copyright (c) 2015, Red Hat, Inc. + * Copyright (c) 2015, Masatake YAMATO + * + * Author: Masatake YAMATO yamato@redhat.com + * + * This source code is released for free distribution under the terms of the + * GNU General Public License version 2 or (at your option) any later version. + * + */ + +#include "general.h" + +#include <stdio.h> +#include "debug.h" +#include "kind.h" +#include "parse.h" + +extern void printRole (const roleDesc* const role) +{ + if (role) + printf ("%s\t%s\t%s\n", role->name, role->description, role->enabled? "on": "off"); +} + +extern const char *renderRole (const roleDesc* const role, vString* b) +{ + vStringCatS (b, role->name); + return vStringValue (b); +} + +#define PR_KIND_WIDTH_LETTER 7 +#define PR_KIND_WIDTH_NAME 15 +#define PR_KIND_WIDTH_DESCRIPTION 30 +#define PR_KIND_WIDTH_ENABLED 8 +#define PR_KIND_WIDTH_REFONLY 7 +#define PR_KIND_WIDTH_NROLE 6 +#define PR_KIND_WIDTH_MASTER 10 +#define MAKE_KIND_FMT(PREFIX,LETTER_SPEC,NROLL_SPEC) \ + PREFIX \ + PR_KIND_FMT (LETTER,LETTER_SPEC) \ + " " \ + PR_KIND_FMT (NAME,s) \ + " " \ + PR_KIND_FMT (ENABLED,s) \ + " " \ + PR_KIND_FMT (REFONLY,s) \ + " " \ + PR_KIND_FMT (NROLE,NROLL_SPEC) \ + " " \ + PR_KIND_FMT (MASTER,s) \ + " " \ + PR_KIND_FMT (DESCRIPTION,s) \ + "\n" + +extern void printKindListHeader (bool indent, bool tabSeparated) +{ +#define KIND_HEADER_COMMON_FMT MAKE_KIND_FMT("%s", s, s) + + const char *fmt = tabSeparated + ? "%s%s%s\t%s\t%s\t%s\t%s\t%s\t%s\n" + : (indent + ? PR_KIND_FMT (LANG,s) KIND_HEADER_COMMON_FMT + : "%s" KIND_HEADER_COMMON_FMT) + ; + + printf (fmt, + (indent? "#PARSER": ""), + (indent? (tabSeparated? "\t": " "): ""), + (indent? "LETTER": "#LETTER"), + "NAME", + "ENABLED", + "REFONLY", + "NROLES", + "MASTER", + "DESCRIPTION"); + +#undef KIND_HEADER_COMMON_FMT +} + +extern void printKind (const kindOption* const kind, bool allKindFields, bool indent, + bool tabSeparated) +{ +#define KIND_FMT MAKE_KIND_FMT("", c, d) + + if (allKindFields) + { + printf ((tabSeparated + ?"%s%c\t%s\t%s\t%s\t%d\t%s\t%s\n" + :"%s" KIND_FMT), + (indent? (tabSeparated? "\t": " "): ""), + kind->letter, + kind->name != NULL ? kind->name : "", + kind->enabled ? "on" : "off", + kind->referenceOnly ? "TRUE" : "FALSE", + kind->nRoles, + (kind->master + || kind->slave ) ? getLanguageName (kind->syncWith): "", + kind->description != NULL ? kind->description : ""); + } + else if (!kind->referenceOnly) + { + printf ("%s%c %s%s\n", indent ? " " : "", kind->letter, + kind->description != NULL ? kind->description : + (kind->name != NULL ? kind->name : ""), + kind->enabled ? "" : " [off]"); + } + +#undef KIND_FMT +} + +const char *scopeSeparatorFor (const kindOption *kind, char parentLetter) +{ + scopeSeparator *table; + Assert (kind); + table = kind->separators; + + /* If no table is given, use the default generic separator ".". + The exception is if a root separator is looked up. In this case, + return NULL to notify there is no root separator to the caller. */ + + if (table == NULL) + { + if (parentLetter == KIND_NULL) + return NULL; + else + return "."; + } + + while (table - kind->separators < kind->separatorCount) + { + /* KIND_WILDCARD cannot be used as a key for finding + a root separator.*/ + if ( (table->parentLetter == KIND_WILDCARD + && parentLetter != KIND_NULL) + || table->parentLetter == parentLetter) + return table->separator; + table++; + } + if (parentLetter == KIND_NULL) + return NULL; + else + return "."; +} + +extern void enableKind (kindOption *kind, bool enable) +{ + kindOption *slave; + + if (kind->master) + enableKind (kind->master, enable); + else + { + kind->enabled = enable; + for (slave = kind->slave; slave; slave = slave->slave) + slave->enabled = enable; + } +}
Modified: ctags/main/kind.h 69 lines changed, 68 insertions(+), 1 deletions(-) =================================================================== @@ -9,19 +9,86 @@ #define CTAGS_MAIN_KIND_H
#include "general.h" +#include "types.h" +#include "routines.h" /* for STRINGIFY */ +#include "vstring.h" + +typedef struct sRoleDesc { + bool enabled; + const char* name; /* role name */ + const char* description; /* displayed in --help output */ +} roleDesc; + +extern void printRole (const roleDesc* const role); /* for --help */ +extern const char *renderRole (const roleDesc* const role, vString* b); + +/* + * Predefined kinds + */ +#define KIND_REGEX_DEFAULT 'r' +#define KIND_REGEX_DEFAULT_LONG "regex" +/* We treat ' ' as a ghost kind. + It will never be listed up in --list-kinds. */
#define KIND_NULL '\0'
-#define KIND_FILE_ALT '!' +#define KIND_GHOST ' ' +#define KIND_GHOST_LONG "ghost"
#define KIND_FILE_DEFAULT 'F' #define KIND_FILE_DEFAULT_LONG "file"
+#define KIND_FILE_ALT '!' + +#define KIND_GENERIC_REFERENCE '@' +#define KIND_GENERIC_REFERENCE_DEFAULT_LONG "reference" + +#define KIND_WILDCARD '*' + +typedef struct sScopeSeparator { + char parentLetter; + const char *separator; +} scopeSeparator; + struct sKindOption { bool enabled; /* are tags for kind enabled? */ char letter; /* kind letter */ const char* name; /* kind name */ const char* description; /* displayed in --help output */ + bool referenceOnly; + int nRoles; /* The number of role elements. */ + roleDesc *roles; + scopeSeparator *separators; + unsigned int separatorCount; + + /* Usage of `syncWith' field is a bit tricky. + + If `LANG_AUTO' is specified to `syncWith' field of a kind + (target kind), the main part of ctags updtes the field with + the id of a parser (master parser) when initializing + parsers. It also updates `slave' and `master' fields. + + If the value other than `LANG_AUTO' is specified, + the main part does nothing. */ + langType syncWith; + kindOption *slave; + kindOption *master; };
+#define ATTACH_ROLES(RS) .nRoles = ARRAY_SIZE(RS), .roles = RS +#define ATTACH_SEPARATORS(S) .separators = S, .separatorCount = ARRAY_SIZE(S) + +/* The value of `tabSeparated' is meaningfull only when `allKindFields' is true. */ +extern void printKind (const kindOption* const kind, bool allKindFields, bool indent, + bool tabSeparated); +extern void printKindListHeader (bool indent, bool tabSeparated); +extern const char *scopeSeparatorFor (const kindOption *kind, char parentLetter); + +extern void enableKind (kindOption *kind, bool enable); + +#define PR_KIND_STR(X) PR_KIND_WIDTH_##X +#define PR_KIND_FMT(X,T) "%-" STRINGIFY(PR_KIND_STR(X)) STRINGIFY(T) + +#define PR_KIND_WIDTH_LANG 15 + #endif /* CTAGS_MAIN_KIND_H */
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).