c655274d5af8383a27c2796966e4fa0c51353c04
[browser-switch] / configfile.h
1 /*
2  * configfile.h -- definitions for config file parsing
3  *
4  * Copyright (C) 2009 Steven Luo
5  * Derived from a Python implementation by Jason Simpson and Steven Luo
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20  * USA.
21  */
22
23 #ifndef _CONFIGFILE_H
24 #define _CONFIGFILE_H
25
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <regex.h>
29
30 #define DEFAULT_HOMEDIR "/home/user"
31 #define CONFIGFILE_LOC "/.config/browser-switchboard"
32 #define CONFIGFILE_LOC_OLD "/.config/browser-proxy"
33 #define MAXLINE 1024
34
35 /* regex matching blank lines or comments */
36 #define REGEX_IGNORE "^[[:space:]]*(#|$)"
37 #define REGEX_IGNORE_FLAGS REG_EXTENDED|REG_NOSUB
38
39 /* regex matching foo = "bar", with arbitrary whitespace at beginning and end
40    of line and surrounding the = */
41 #define REGEX_CONFIG1 "^[[:space:]]*([^=[:space:]]+)[[:space:]]*=[[:space:]]*\"(.*)\"[[:space:]]*$"
42 #define REGEX_CONFIG1_FLAGS REG_EXTENDED
43
44 /* regex matching foo = bar, with arbitrary whitespace at beginning of line and
45    surrounding the = */
46 #define REGEX_CONFIG2 "^[[:space:]]*([^=[:space:]]+)[[:space:]]*=[[:space:]]*(.*)$"
47 #define REGEX_CONFIG2_FLAGS REG_EXTENDED|REG_NEWLINE
48
49
50 struct swb_config_line {
51         /* Whether or not the line has been parsed */
52         int parsed;
53         /* If parsed, the config key; otherwise, the entire line */
54         char *key;
55         /* If parsed, the config value */
56         char *value;
57 };
58
59 FILE *open_config_file(void);
60
61 int parse_config_file_begin(void);
62 void parse_config_file_end(void);
63 int parse_config_file_line(FILE *fp, struct swb_config_line *line);
64
65 #endif /* _CONFIGFILE_H */