File: parser_util.h

package info (click to toggle)
i3-wm 4.25-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,676 kB
  • sloc: ansic: 30,144; perl: 19,136; sh: 70; makefile: 9
file content (59 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download
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
/*
 * vim:ts=4:sw=4:expandtab
 *
 * i3 - an improved tiling window manager
 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
 *
 * parser_util.h: utility functions for the config and commands parser
 *
 */
#pragma once

struct stack_entry {
    /* Just a pointer, not dynamically allocated. */
    const char *identifier;
    enum {
        STACK_STR = 0,
        STACK_LONG = 1,
    } type;
    union {
        char *str;
        long num;
    } val;
};

struct stack {
    struct stack_entry stack[10];
};

/**
 * Pushes a string (identified by 'identifier') on the stack.
 * If a string with the same identifier is already on the stack, the new
 * string will be appended, separated by a comma.
 *
 */
void parser_push_string(struct stack *stack, const char *identifier, const char *str);

/**
 * Pushes a long (identified by 'identifier') on the stack.
 *
 */
void parser_push_long(struct stack *stack, const char *identifier, long num);

/**
 * Returns the string with the given identifier.
 *
 */
const char *parser_get_string(const struct stack *stack, const char *identifier);

/**
 * Returns the long with the given identifier.
 *
 */
long parser_get_long(const struct stack *stack, const char *identifier);

/**
 * Clears the stack.
 *
 */
void parser_clear_stack(struct stack *stack);