Lines Matching refs:state

42 static int normal_assignment(pa_config_parser_state *state) {
45 pa_assert(state);
47 for (item = state->item_table; item->parse; item++) {
49 if (item->lvalue && !pa_streq(state->lvalue, item->lvalue))
52 if (item->section && !state->section)
55 if (item->section && !pa_streq(state->section, item->section))
58 state->data = item->data;
60 return item->parse(state);
63 pa_log("[%s:%u] Unknown lvalue '%s' in section '%s'.", state->filename, state->lineno, state->lvalue, pa_strna(state->section));
69 static int proplist_assignment(pa_config_parser_state *state) {
70 pa_assert(state);
71 pa_assert(state->proplist);
73 if (pa_proplist_sets(state->proplist, state->lvalue, state->rvalue) < 0) {
74 pa_log("[%s:%u] Failed to parse a proplist entry: %s = %s", state->filename, state->lineno, state->lvalue, state->rvalue);
82 static int parse_line(pa_config_parser_state *state) {
85 state->lvalue = state->buf + strspn(state->buf, WHITESPACE);
87 if ((c = strpbrk(state->lvalue, COMMENTS)))
90 if (!*state->lvalue)
93 if (pa_startswith(state->lvalue, ".include ")) {
97 fn = pa_strip(state->lvalue + 9);
100 if ((k = strrchr(state->filename, '/'))) {
101 char *dir = pa_xstrndup(state->filename, k - state->filename);
107 r = pa_config_parse(fn, NULL, state->item_table, state->proplist, false, state->userdata);
112 if (*state->lvalue == '[') {
115 k = strlen(state->lvalue);
118 if (state->lvalue[k-1] != ']') {
119 pa_log("[%s:%u] Invalid section header.", state->filename, state->lineno);
123 pa_xfree(state->section);
124 state->section = pa_xstrndup(state->lvalue + 1, k-2);
126 if (pa_streq(state->section, "Properties")) {
127 if (!state->proplist) {
128 pa_log("[%s:%u] \"Properties\" section is not allowed in this file.", state->filename, state->lineno);
132 state->in_proplist = true;
134 state->in_proplist = false;
139 if (!(state->rvalue = strchr(state->lvalue, '='))) {
140 pa_log("[%s:%u] Missing '='.", state->filename, state->lineno);
144 *state->rvalue = 0;
145 state->rvalue++;
147 state->lvalue = pa_strip(state->lvalue);
148 state->rvalue = pa_strip(state->rvalue);
150 if (state->in_proplist)
151 return proplist_assignment(state);
153 return normal_assignment(state);
167 pa_config_parser_state state;
172 pa_zero(state);
186 state.filename = filename;
187 state.item_table = t;
188 state.userdata = userdata;
191 state.proplist = pa_proplist_new();
194 if (!fgets(state.buf, sizeof(state.buf), f)) {
202 state.lineno++;
204 if (parse_line(&state) < 0)
209 pa_proplist_update(proplist, PA_UPDATE_REPLACE, state.proplist);
214 if (state.proplist)
215 pa_proplist_free(state.proplist);
217 pa_xfree(state.section);
297 int pa_config_parse_int(pa_config_parser_state *state) {
301 pa_assert(state);
303 i = state->data;
305 if (pa_atoi(state->rvalue, &k) < 0) {
306 pa_log("[%s:%u] Failed to parse numeric value: %s", state->filename, state->lineno, state->rvalue);
314 int pa_config_parse_unsigned(pa_config_parser_state *state) {
318 pa_assert(state);
320 u = state->data;
322 if (pa_atou(state->rvalue, &k) < 0) {
323 pa_log("[%s:%u] Failed to parse numeric value: %s", state->filename, state->lineno, state->rvalue);
331 int pa_config_parse_size(pa_config_parser_state *state) {
335 pa_assert(state);
337 i = state->data;
339 if (pa_atou(state->rvalue, &k) < 0) {
340 pa_log("[%s:%u] Failed to parse numeric value: %s", state->filename, state->lineno, state->rvalue);
348 int pa_config_parse_bool(pa_config_parser_state *state) {
352 pa_assert(state);
354 b = state->data;
356 if ((k = pa_parse_boolean(state->rvalue)) < 0) {
357 pa_log("[%s:%u] Failed to parse boolean value: %s", state->filename, state->lineno, state->rvalue);
366 int pa_config_parse_not_bool(pa_config_parser_state *state) {
370 pa_assert(state);
372 b = state->data;
374 if ((k = pa_parse_boolean(state->rvalue)) < 0) {
375 pa_log("[%s:%u] Failed to parse boolean value: %s", state->filename, state->lineno, state->rvalue);
384 int pa_config_parse_string(pa_config_parser_state *state) {
387 pa_assert(state);
389 s = state->data;
392 *s = *state->rvalue ? pa_xstrdup(state->rvalue) : NULL;