File: systemdunit.c

package info (click to toggle)
universal-ctags 0%2Bgit20200824-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,092 kB
  • sloc: ansic: 103,112; lisp: 7,241; sh: 6,962; vhdl: 5,924; perl: 2,014; cpp: 1,928; python: 1,828; javascript: 1,529; cs: 1,193; sql: 587; php: 544; f90: 534; makefile: 500; ruby: 498; yacc: 459; asm: 358; fortran: 341; xml: 308; objc: 289; ada: 273; tcl: 205; java: 157; cobol: 122; erlang: 61; ml: 49; awk: 43
file content (140 lines) | stat: -rw-r--r-- 3,104 bytes parent folder | download | duplicates (6)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
*
*   Copyright (c) 2015, Red Hat, Inc.
*   Copyright (c) 2015, Masatake YAMATO
*
*   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 FILES
*/
#include "general.h"  /* must always come first */

#include <ctype.h>
#include <string.h>

#include "entry.h"
#include "iniconf.h"
#include "parse.h"
#include "read.h"
#include "routines.h"
#include "vstring.h"
#include "xtag.h"



/*
*   DATA DEFINITIONS
*/
typedef enum {
	K_UNIT,
} systemdUnitKind;

typedef enum {
	R_UNIT_Requires,
	R_UNIT_Wants,
	R_UNIT_After,
	R_UNIT_Before,
	R_UNIT_RequiredBy,
	R_UNIT_WantedBy,

} systemdUnitRole;

static roleDefinition SystemdUnitUnitRoles [] = {
	{ true, "Requires", "referred in Requires key" },
	{ true, "Wants", "referred in Wants key" },
	{ true, "After", "referred in After key" },
	{ true, "Before", "referred in Before key" },
	{ true, "RequiredBy", "referred in RequiredBy key" },
	{ true, "WantedBy", "referred in WantedBy key" },
	/* ... */
};

static kindDefinition SystemdUnitKinds [] = {
	{ true, 'u', "unit", "units",
	  .referenceOnly = true, ATTACH_ROLES(SystemdUnitUnitRoles)},
};

static int roleOf (const char* key, int kind)
{
	int i;

	for (i = 0; i < SystemdUnitKinds [kind].nRoles; i++)
	{
		if (strcmp (SystemdUnitKinds [kind].roles[i].name, key) == 0)
			return i;
	}

	return -1;
}

static void makeSystemdReferencedUnit (const char *value, int kind, int role)
{
	vString *unit = vStringNew ();

	while (*value != '\0')
	{
		if (*value == ',')
		{
			makeSimpleRefTag (unit, kind, role);
			vStringClear (unit);
		}
		else if (! isspace ((int) *value))
			vStringPut (unit, *value);

		value++;
	}

	if (vStringLength (unit) > 0)
		makeSimpleRefTag (unit, kind, role);
	vStringDelete (unit);
}

static void newDataCallback (iniconfSubparser *s CTAGS_ATTR_UNUSED,
							 const char *section CTAGS_ATTR_UNUSED, const char *key, const char *value)
{
	int r;

	if (isXtagEnabled (XTAG_REFERENCE_TAGS) && value)
	{
		r = roleOf (key, K_UNIT);
		if (r >= 0)
			makeSystemdReferencedUnit (value, K_UNIT, r);
	}
}

static void findSystemdUnitTags (void)
{
	scheduleRunningBaseparser (0);
}

extern parserDefinition* SystemdUnitParser (void)
{
	static const char *const extensions [] = { "service", "socket", "device",
											   "mount", "automount", "swap", "target",
											   "path", "timer", "snapshot",
											   "slice", NULL };
	static iniconfSubparser systemdUnitSubparser = {
		.subparser = {
			.direction = SUBPARSER_SUB_RUNS_BASE,
		},
		.newDataNotify = newDataCallback,
	};
	static parserDependency dependencies [] = {
		[0] = { DEPTYPE_SUBPARSER, "Iniconf", &systemdUnitSubparser },
	};

	parserDefinition* const def = parserNew ("SystemdUnit");

	def->dependencies = dependencies;
	def->dependencyCount = ARRAY_SIZE(dependencies);
	def->kindTable      = SystemdUnitKinds;
	def->kindCount  = ARRAY_SIZE (SystemdUnitKinds);
	def->extensions = extensions;
	def->parser     = findSystemdUnitTags;
	def->useCork    = CORK_QUEUE;
	return def;
}