File: cf-parser.c

package info (click to toggle)
obs-studio 30.2.3%2Bdfsg-3.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,928 kB
  • sloc: ansic: 202,137; cpp: 112,403; makefile: 868; python: 599; sh: 275; javascript: 19
file content (64 lines) | stat: -rw-r--r-- 1,931 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2023 Lain Bailey <lain@obsproject.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "cf-parser.h"

void cf_adderror(struct cf_parser *p, const char *error, int level,
		 const char *val1, const char *val2, const char *val3)
{
	uint32_t row, col;
	lexer_getstroffset(&p->cur_token->lex->base_lexer,
			   p->cur_token->unmerged_str.array, &row, &col);

	if (!val1 && !val2 && !val3) {
		error_data_add(&p->error_list, p->cur_token->lex->file, row,
			       col, error, level);
	} else {
		struct dstr formatted;
		dstr_init(&formatted);
		dstr_safe_printf(&formatted, error, val1, val2, val3, NULL);

		error_data_add(&p->error_list, p->cur_token->lex->file, row,
			       col, formatted.array, level);

		dstr_free(&formatted);
	}
}

bool cf_pass_pair(struct cf_parser *p, char in, char out)
{
	if (p->cur_token->type != CFTOKEN_OTHER ||
	    *p->cur_token->str.array != in)
		return p->cur_token->type != CFTOKEN_NONE;

	p->cur_token++;

	while (p->cur_token->type != CFTOKEN_NONE) {
		if (*p->cur_token->str.array == in) {
			if (!cf_pass_pair(p, in, out))
				break;
			continue;

		} else if (*p->cur_token->str.array == out) {
			p->cur_token++;
			return true;
		}

		p->cur_token++;
	}

	return false;
}