Assembled 2
A column based text editor
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1
31#ifndef AS_CONFIG_H
32#define AS_CONFIG_H
33
34#include <includes.h>
35
37#define AS_CFG_TOKEN_EOF 0 // ''
39#define AS_CFG_TOKEN_COL 1 // ':'
41#define AS_CFG_TOKEN_STR 2 // "Sdfsdfaioietuaeadfbvx"
43#define AS_CFG_TOKEN_INT 3 // 123452
45#define AS_CFG_TOKEN_COM 4 // ','
47#define AS_CFG_TOKEN_KEY 5 // keyword like "keyseq" or "use" or "themes" (any string in As_LexStrLookup)
48#define AS_CFG_TOKEN_SQR 6 // '[' ']'
49
50#define AS_NEXT_TOKEN token = token->next;
51
52#define AS_EXPECT_TOKEN(__type__, __msg__) \
53 if (token->type != __type__) { \
54 printf("Error on line %d, %d: %s\n", token->line, token->column, __msg__); \
55 AS_DEBUG_MSG("Error on line %d, %d: %s\n", token->line, token->column, __msg__); \
56 exit(1); \
57 }
58#define AS_EXPECT_VALUE(__value__, __msg__) \
59 if (token->value != __value__) { \
60 printf("Error on line %d, %d: %s\n", token->line, token->column, __msg__); \
61 AS_DEBUG_MSG("Error on line %d, %d: %s\n", token->line, token->column, __msg__); \
62 exit(1); \
63 }
64
65// TODO: Optimize placement
75 AS_CFG_LOOKUP_UP,
76 AS_CFG_LOOKUP_DOWN,
77 AS_CFG_LOOKUP_LEFT,
78 AS_CFG_LOOKUP_RIGHT,
79 AS_CFG_LOOKUP_ENTER,
80 AS_CFG_LOOKUP_BUFFER_LEFT,
81 AS_CFG_LOOKUP_BUFFER_RIGHT,
82 AS_CFG_LOOKUP_WINDOW_LEFT,
83 AS_CFG_LOOKUP_WINDOW_RIGHT,
84 AS_CFG_LOOKUP_FILE_SAVE,
85 AS_CFG_LOOKUP_FILE_SAVE_ALL,
86 AS_CFG_LOOKUP_FILE_LOAD,
87 AS_CFG_LOOKUP_SELECTION,
88 AS_CFG_LOOKUP_MOVE_LN_UP,
89 AS_CFG_LOOKUP_MOVE_LN_DOWN,
90 AS_CFG_LOOKUP_COLDESC_LEFT,
91 AS_CFG_LOOKUP_COLDESC_RIGHT,
92
93 AS_CFG_LOOKUP_KEYBOARD,
94 AS_CFG_LOOKUP_START_SCR,
95 AS_CFG_LOOKUP_THEMES,
96 AS_CFG_LOOKUP_USE,
97 AS_CFG_LOOKUP_BG_DISABLE,
98 AS_CFG_LOOKUP_KEYSEQ,
99 AS_CFG_LOOKUP_LOGO_BMP,
100 AS_CFG_LOOKUP_COLUMNS,
101 AS_CFG_LOOKUP_DEFAULT,
102 AS_CFG_LOOKUP_DEFINE,
103 AS_CFG_LOOKUP_INCLUDE,
104 AS_CFG_LOOKUP_FOREGROUND,
105 AS_CFG_LOOKUP_BACKGROUND,
106};
107
111static const char *As_LexStrLookup[] = {
112 [AS_CFG_LOOKUP_UP] = "up",
113 [AS_CFG_LOOKUP_DOWN] = "down",
114 [AS_CFG_LOOKUP_LEFT] = "left",
115 [AS_CFG_LOOKUP_RIGHT] = "right",
116 [AS_CFG_LOOKUP_ENTER] = "enter",
117 [AS_CFG_LOOKUP_BUFFER_LEFT] = "buffer_left",
118 [AS_CFG_LOOKUP_BUFFER_RIGHT] = "buffer_right",
119 [AS_CFG_LOOKUP_WINDOW_LEFT] = "window_left",
120 [AS_CFG_LOOKUP_WINDOW_RIGHT] = "window_right",
121 [AS_CFG_LOOKUP_FILE_SAVE] = "file_save",
122 [AS_CFG_LOOKUP_FILE_SAVE_ALL] = "file_save_all",
123 [AS_CFG_LOOKUP_FILE_LOAD] = "file_load",
124 [AS_CFG_LOOKUP_SELECTION] = "selection",
125 [AS_CFG_LOOKUP_MOVE_LN_UP] = "move_line_up",
126 [AS_CFG_LOOKUP_MOVE_LN_DOWN] = "move_line_down",
127 [AS_CFG_LOOKUP_COLDESC_LEFT] = "column_left",
128 [AS_CFG_LOOKUP_COLDESC_RIGHT] = "column_right",
129
130 [AS_CFG_LOOKUP_KEYBOARD] = "keyboard",
131 [AS_CFG_LOOKUP_START_SCR] = "start_screen",
132 [AS_CFG_LOOKUP_THEMES] = "themes",
133 [AS_CFG_LOOKUP_USE] = "use",
134 [AS_CFG_LOOKUP_BG_DISABLE] = "background_disable",
135 [AS_CFG_LOOKUP_KEYSEQ] = "keyseq",
136 [AS_CFG_LOOKUP_LOGO_BMP] = "logo_bmp",
137 [AS_CFG_LOOKUP_COLUMNS] = "columns",
138 [AS_CFG_LOOKUP_DEFAULT] = "default",
139 [AS_CFG_LOOKUP_DEFINE] = "define",
140 [AS_CFG_LOOKUP_INCLUDE] = "include",
141 [AS_CFG_LOOKUP_FOREGROUND] = "foreground",
142 [AS_CFG_LOOKUP_BACKGROUND] = "background",
143};
144
148struct AS_CfgTok {
150 int type;
152 int value;
154 int line;
158 char *str;
161};
162
168struct AS_CfgTok *cfg_lex(FILE *file);
169
177int read_config();
178
179#endif
AS_LEXSTRLOOKUP_IDXS
Definition config.h:74
struct AS_CfgTok * cfg_lex(FILE *file)
Definition config.c:136
int read_config()
Definition config.c:305
Definition config.h:148
int type
The type of the token (AS_CFG_TOKEN_x).
Definition config.h:150
int line
The line number the token was found on.
Definition config.h:154
struct AS_CfgTok * next
Pointer to the next token.
Definition config.h:160
char * str
String for tokens of type AS_CFG_TOKEN_STR.
Definition config.h:158
int column
The column number the token was found on.
Definition config.h:156
int value
An integral value if the token has one.
Definition config.h:152