-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcparse.y
More file actions
147 lines (126 loc) · 3.54 KB
/
Copy pathcparse.y
File metadata and controls
147 lines (126 loc) · 3.54 KB
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
141
142
143
144
145
146
147
/*
* 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.
*/
%locations
%define api.pure full
%define api.prefix {cc}
%define parse.error verbose
%parse-param {char *ret}
%initial-action { reindex = 0; }
%union {
int num;
char *txt;
};
%token <txt> CC_CONFIG CC_CONFID CC_CONFVAL
%token <txt> CC_EOL
%start cline
%type <num> centry
%{
#include <stdio.h>
#include "configk.h"
/* cache recently edited entries */
#define REDITSZ 256
static uint16_t reindex;
static cEntry *redits[REDITSZ];
uint8_t cache_redits(cEntry *);
static uint8_t is_redits(cEntry *);
void yyerror(YYLTYPE *, char *, char const *);
extern char *gstr;
extern char *types[];
extern uint8_t cstatus, postedit;
extern int yylex(YYSTYPE *, YYLTYPE *);
%}
%%
cline:
%empty
| cline centry
;
centry:
CC_CONFIG CC_CONFID CC_CONFVAL CC_EOL {
cNode *c = hsearch_kconfigs($2);
cEntry *t = c ? (cEntry *)c->data : NULL;
uint8_t ceditflag = 0;
if (EDIT_CONFIG == postedit)
{
if (!t || is_redits(t))
break;
else if (cstatus == ENABLE_CONFIG)
{
if (t->opt_status == -CVALNOSET)
{
ceditflag = 1;
warnx("Enable option:");
}
else if (strcmp(t->opt_value, $3))
{
ceditflag = 1;
warnx("Edit option %s: %s => %s", $2, t->opt_value, $3);
}
}
else if (cstatus == DISABLE_CONFIG && t->opt_status != -CVALNOSET)
{
ceditflag = 1;
warnx("Disable option:");
}
}
if (!postedit || ceditflag)
toggle_configs($2, cstatus, $3, postedit);
if (SHOW_CONFIG == postedit)
{
if (t)
{
if (t->opt_status == -CVALNOSET)
printf("# CONFIG_%s is not set\n", t->opt_name);
else
printf("CONFIG_%s=%s\n", t->opt_name, t->opt_value);
}
else
{
warnx("option '%s' not found in the source tree", $2);
if (cstatus == ENABLE_CONFIG)
printf("CONFIG_%s=%s\n", $2, $3);
else if (cstatus == DISABLE_CONFIG)
printf("# CONFIG_%s is not set\n", $2);
}
}
free($2); free($3);
}
| CC_EOL { if (SHOW_CONFIG == postedit) printf("\n"); }
| error CC_EOL { yyerrok; }
;
%%
void
yyerror(YYLTYPE *loc, char *ret, char const *serr)
{
warnx("%s => %d: %d: %s", __func__, loc->last_line, *ret, serr);
}
uint8_t
is_redits(cEntry *t)
{
for (int i = 0; i < reindex; i++)
if (redits[i] == t)
return 1;
return 0;
}
uint8_t
cache_redits(cEntry *t)
{
if (is_redits(t))
return 0;
redits[reindex++] = t;
if (!(reindex %= REDITSZ))
warnx("recent edits cache full, reset");
return reindex;
}