-
Notifications
You must be signed in to change notification settings - Fork 1
/
configk.h
137 lines (120 loc) · 2.81 KB
/
configk.h
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
/*
* configk: an easy way to edit kernel configuration files and templates
* Copyright (C) 2023-2024 Red Hat Inc.
*
* This program 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.
*
* This program 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 COPYING file or <http://www.gnu.org/licenses/> for more details.
*/
#include <err.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define __USE_GNU
#include <search.h>
typedef struct
{
char *fname;
uint16_t s_count;
uint16_t o_count;
uint16_t u_count;
} sEntry; /* source entry */
typedef enum
{
CINT=0x1,
CHEX=0x2,
CBOOL=0x3,
CSTRING=0x4,
CTRISTATE=0x5,
CVALNOSET=0x6
} cType; /* config value type */
typedef struct
{
char *opt_name;
char *opt_value;
char *opt_prompt;
char *opt_depends;
char *opt_select;
char *opt_imply;
char *opt_range;
char *opt_help;
cType opt_type;
int32_t opt_status;
} cEntry; /* config entry */
typedef enum
{
SENTRY=0x1,
CENTRY=0x2,
CHENTRY=0x3
} nType; /* Node types */
/* configuration tree node */
typedef struct cNode cNode;
struct cNode
{
cNode *up;
cNode *down;
cNode *next;
void *data;
nType type;
};
enum OPTS
{
OUT_VERBOSE = 0x1,
OUT_CONFIG = 0x2,
OUTMASK = 0x3,
DISABLE_CONFIG = 0x4,
ENABLE_CONFIG = 0x8,
TOGGLE_CONFIG = 0x10,
EDITMASK = 0x1F,
SHOW_CONFIG = 0x20,
CHECK_CONFIG = 0x40,
EDIT_CONFIG = 0x80,
EDIT_INPLACE = 0x100
};
enum INDX
{
IPROG = 0x0,
ISOPT = 0x1,
IDOPT = 0x2,
IEOPT = 0x3,
IFOPT = 0x4,
ITOPT = 0x5,
IARCH = 0x6,
IEDTR = 0x7,
ITMPD = 0x8,
IGREP = 0x9,
GSTRSZ = 0xA
};
enum EXPRTYPE
{
EXPR_DEPENDS = 0x1,
EXPR_DEFAULT = 0x2,
EXPR_RANGE = 0x3
};
extern uint16_t opts;
#define HASHSZ 20000
extern struct hsearch_data chash;
extern cNode *tree_root(void);
extern cNode *tree_curr_root_up(void);
extern cNode *tree_cnode(void *, nType);
extern cNode *tree_add(cNode *);
extern cNode *tree_init(char *);
extern void tree_display(cNode *);
extern uint32_t tree_reset(cNode *);
extern void tree_display_config(cNode *);
extern cNode *filenode(cNode *);
extern char *append(char *, char *);
extern cEntry *add_new_config(char *, nType);
extern int8_t check_depends(const char *);
extern int8_t set_option(const char *, char *);
extern int8_t validate_option(const char *);
extern cNode *hsearch_kconfigs(const char *);
extern int8_t toggle_configs(const char *, uint8_t, char *, bool);