1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/*
* pythonLoggingConfig.c
*
* Copyright (c) 2016, Masatake YAMATO <yamato@redhat.com>
* Copyright (c) 2016, Red Hat, K.K.
*
* 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.
*
* This module contains functions for generating tags for config files of
* python's logging.config module.
*
* https://docs.python.org/2/library/logging.config.html
*
*/
/*
* INCLUDE FILES
*/
#include "general.h" /* must always come first */
#include "entry.h"
#include "iniconf.h"
#include "kind.h"
#include "parse.h"
#include "read.h"
#include "routines.h"
#include <string.h>
/*
* DATA DEFINITIONS
*/
typedef enum {
K_LOGGER_SECTION,
K_LOGGER_QUALNAME,
} pythonLoggingConfigKind;
static kindDefinition PythonLoggingConfigKinds [] = {
{ true, 'L', "loggerSection", "logger sections" },
{ true, 'q', "qualname", "logger qualnames" },
};
#define LOGGER_PREFIX "logger_"
#define LOGGER_LEN (sizeof("logger_") - 1)
struct sPythonLoggingConfigSubparser {
iniconfSubparser iniconf;
int index;
};
static void newDataCallback (iniconfSubparser *iniconf,
const char *section, const char *key, const char *value)
{
tagEntryInfo e;
if (section && (strncmp (LOGGER_PREFIX, section, LOGGER_LEN) == 0))
{
if (key == NULL && value == NULL)
{
const char *logger = section + LOGGER_LEN;
if (logger [0] == '\0')
goto out;
initTagEntry (&e, logger, K_LOGGER_SECTION);
((struct sPythonLoggingConfigSubparser *)iniconf)->index = makeTagEntry (&e);
}
else if (key && (strcmp (key, "qualname") == 0)
&& value && value[0] != '\0')
{
initTagEntry (&e, value, K_LOGGER_QUALNAME);
e.extensionFields.scopeIndex = ((struct sPythonLoggingConfigSubparser*)iniconf)->index;
makeTagEntry (&e);
}
}
out:
return;
}
static bool probeLanguage (const char *section, const char *key CTAGS_ATTR_UNUSED, const char *value CTAGS_ATTR_UNUSED)
{
if (section && (strncmp (LOGGER_PREFIX, section, LOGGER_LEN) == 0))
return true;
else
return false;
}
static void exclusiveSubparserChosenCallback (subparser *s, void *data CTAGS_ATTR_UNUSED)
{
((struct sPythonLoggingConfigSubparser *)s)->index = CORK_NIL;
}
static void findPythonLoggingConfigTags (void)
{
scheduleRunningBaseparser (0);
}
extern parserDefinition* PythonLoggingConfigParser (void)
{
static struct sPythonLoggingConfigSubparser pythonLoggingConfigSubparser = {
.iniconf = {
.subparser = {
.direction = SUBPARSER_BI_DIRECTION,
.exclusiveSubparserChosenNotify = exclusiveSubparserChosenCallback,
},
.probeLanguage = probeLanguage,
.newDataNotify = newDataCallback,
},
};
static parserDependency dependencies [] = {
[0] = { DEPTYPE_SUBPARSER, "Iniconf", &pythonLoggingConfigSubparser },
};
parserDefinition* const def = parserNew ("PythonLoggingConfig");
def->dependencies = dependencies;
def->dependencyCount = ARRAY_SIZE (dependencies);
def->kindTable = PythonLoggingConfigKinds;
def->kindCount = ARRAY_SIZE (PythonLoggingConfigKinds);
def->parser = findPythonLoggingConfigTags;
def->useCork = CORK_QUEUE;
return def;
}
|