1 /* 2 * parse.h 3 * 4 * Copyright 2012 Dimitar Toshkov Zhekov <dimitar.zhekov@gmail.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef PARSE_H 21 22 typedef enum _ParseNodeType 23 { 24 PT_VALUE, /* string */ 25 PT_ARRAY 26 } ParseNodeType; 27 28 typedef struct _ParseNode 29 { 30 const char *name; 31 ParseNodeType type; 32 void *value; 33 } ParseNode; 34 35 void parse_foreach(GArray *nodes, GFunc func, gpointer gdata); 36 char *parse_string(char *text, char newline); 37 void parse_message(char *message, const char *token); 38 gchar *parse_get_display_from_7bit(const char *text, gint hb_mode, gint mr_mode); 39 40 const ParseNode *parse_find_node(GArray *nodes, const char *name); 41 const void *parse_find_node_type(GArray *nodes, const char *name, ParseNodeType type); 42 #define parse_find_value(nodes, name) \ 43 ((char *) parse_find_node_type((nodes), (name), PT_VALUE)) 44 #define parse_find_locale(nodes, name) utils_7bit_to_locale(parse_find_value((nodes), (name))) 45 #define parse_find_array(nodes, name) \ 46 ((GArray *) parse_find_node_type((nodes), (name), PT_ARRAY)) 47 const char *parse_grab_token(GArray *nodes); /* removes token from nodes */ 48 #define parse_lead_array(nodes) ((GArray *) ((ParseNode *) nodes->data)->value) 49 #define parse_lead_value(nodes) ((char *) ((ParseNode *) nodes->data)->value) 50 51 gchar *parse_get_error(GArray *nodes); 52 void on_error(GArray *nodes); 53 54 typedef struct _ParseLocation 55 { 56 gchar *base_name; 57 const char *func; 58 const char *addr; 59 const char *file; 60 gint line; 61 } ParseLocation; 62 63 void parse_location(GArray *nodes, ParseLocation *loc); 64 #define parse_location_free(loc) g_free((loc)->base_name) 65 66 enum 67 { 68 HB_DEFAULT, 69 HB_7BIT, 70 HB_LOCALE, 71 HB_UTF8, 72 HB_COUNT 73 }; 74 75 enum 76 { 77 MR_COMPACT, 78 MR_NEUTRAL, 79 MR_DEFAULT, 80 MR_MODIFY, 81 MR_MODSTR, 82 MR_EDITVC 83 }; 84 85 enum 86 { 87 MODE_HBIT, 88 MODE_MEMBER, 89 MODE_ENTRY 90 }; 91 92 typedef struct _ParseMode 93 { 94 char *name; 95 gint hb_mode; 96 gint mr_mode; 97 gboolean entry; 98 } ParseMode; 99 100 typedef struct _ParseVariable 101 { 102 const char *name; 103 const char *value; 104 gint hb_mode; 105 gint mr_mode; 106 gchar *display; 107 /* if children */ 108 const char *expr; 109 const char *children; 110 gint numchild; 111 } ParseVariable; 112 113 char *parse_mode_reentry(const char *name); 114 gint parse_mode_get(const char *name, gint mode); 115 void parse_mode_update(const char *name, gint mode, gint value); 116 gboolean parse_variable(GArray *nodes, ParseVariable *var, const char *children); 117 #define parse_variable_free(var) g_free((var)->display) 118 119 void parse_load(GKeyFile *config); 120 void parse_save(GKeyFile *config); 121 122 void parse_init(void); 123 void parse_finalize(void); 124 125 #define PARSE_H 1 126 #endif 127