diff --git a/Makefile b/Makefile index 18201813d5613e8ac5b1ec6ace02682487bd36f3..0c509fa409e91cb77992e6fb5c1501accfa54c83 100644 --- a/Makefile +++ b/Makefile @@ -42,12 +42,12 @@ test: all clean: find build -type f -delete - rm *~ + rm -f *~ build/libmoberg.so: build/lib/moberg_config.o build/libmoberg.so: build/lib/moberg_device.o -build/libmoberg.so: build/lib/moberg_config_parser.o +build/libmoberg.so: build/lib/moberg_parser.o build/lib/moberg_device.o: moberg_device.h -build/parse_config.o: moberg_config_parser.h +build/parse_config.o: moberg_parser.h parse_config: build/moberg_driver.o parse_config: build/parse_config.o diff --git a/moberg.c b/moberg.c index f89e8b2f927fde0c5acf48f7973a4cf23c4f7738..fc44eee38b7f6d14fb404421566e90f095150fea 100644 --- a/moberg.c +++ b/moberg.c @@ -12,7 +12,7 @@ #include <string.h> #include <moberg.h> #include <moberg_config.h> -#include <moberg_config_parser.h> +#include <moberg_parser.h> struct moberg_digital_in_t { int index; diff --git a/moberg_config_parser.h b/moberg_config_parser.h deleted file mode 100644 index cc50adcf09589a1b526a56c13fde16b9da1520c6..0000000000000000000000000000000000000000 --- a/moberg_config_parser.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __MOBERG_CONFIG_PARSER_H__ -#define __MOBERG_CONFIG_PARSER_H__ - -#include <moberg_config.h> - -struct moberg_config_parser_context; - -struct moberg_config *moberg_config_parse(const char *buf); - -#endif diff --git a/moberg_config_parser_module.h b/moberg_config_parser_module.h deleted file mode 100644 index e51fb6e21d5275c0c07c609a4359b91a186a08e9..0000000000000000000000000000000000000000 --- a/moberg_config_parser_module.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef __MOBERG_CONFIG_PARSER_MODULE_H__ -#define __MOBERG_CONFIG_PARSER_MODULE_H__ - -#include <stdio.h> -#include <moberg_config_parser.h> - -struct moberg_config_parser_token; - -enum moberg_config_parser_token_kind { - tok_none, - tok_EOF, - tok_LPAREN, - tok_RPAREN, - tok_LBRACE, - tok_RBRACE, - tok_LBRACKET, - tok_RBRACKET, - tok_EQUAL, - tok_COMMA, - tok_COLON, - tok_SEMICOLON, - tok_INTEGER, - tok_IDENT, - tok_STRING, -}; - -struct moberg_config_parser_ident { - int length; - const char *value; -}; - -struct moberg_config_parser_token { - enum moberg_config_parser_token_kind kind; - union { - struct moberg_config_parser_ident ident; - struct moberg_config_parser_ident string; - struct moberg_config_parser_integer { - int value; - } integer; - } u; -}; - -int moberg_config_parser_acceptsym( - struct moberg_config_parser_context *c, - enum moberg_config_parser_token_kind kind, - struct moberg_config_parser_token *token); - -int moberg_config_parser_acceptkeyword( - struct moberg_config_parser_context *c, - const char *keyword); - -void moberg_config_parser_failed( - struct moberg_config_parser_context *c, - FILE *f); - -#endif diff --git a/moberg_device.c b/moberg_device.c index a7e2fae3ab965914179311d53166d72412b343af..aff00c58e9d40c039df0bade9bb3e1e716a5b26b 100644 --- a/moberg_device.c +++ b/moberg_device.c @@ -56,7 +56,7 @@ void moberg_device_free(struct moberg_device *device) } int moberg_device_parse_config(struct moberg_device *device, - struct moberg_config_parser_context *context) + struct moberg_parser_context *context) { return device->driver.parse_config(device, context); } @@ -73,7 +73,7 @@ int moberg_device_set_config(struct moberg_device *device, } int moberg_device_parse_map(struct moberg_device* device, - struct moberg_config_parser_context *context, + struct moberg_parser_context *context, struct moberg_device_map_range range) { int result; diff --git a/moberg_device.h b/moberg_device.h index c379b3d877471b0b687ef2ae0920bdc8c3bef2e5..1aeb7fa646372f0bf2e90b23aa5d0a1508cee224 100644 --- a/moberg_device.h +++ b/moberg_device.h @@ -2,7 +2,7 @@ #define __MOBERG_DEVICE_H__ #include <moberg_config.h> -#include <moberg_config_parser.h> +#include <moberg_parser.h> struct moberg_device_map_range { enum moberg_device_map_kind { @@ -51,17 +51,17 @@ struct moberg_device_encoder_in { int (*read)(struct moberg_device_encoder_in_context *, long *value); }; -struct moberg_config_parser_context; +struct moberg_parser_context; struct moberg_device; struct moberg_device_config; struct moberg_device_driver { int (*parse_config)( struct moberg_device* device, - struct moberg_config_parser_context *context); + struct moberg_parser_context *context); int (*parse_map)( struct moberg_device* device, - struct moberg_config_parser_context *context, + struct moberg_parser_context *context, enum moberg_device_map_kind kind); int (*config_free)( struct moberg_device_config *config); @@ -74,13 +74,13 @@ struct moberg_device *moberg_device_new(const char *driver); void moberg_device_free(struct moberg_device *device); int moberg_device_parse_config(struct moberg_device* device, - struct moberg_config_parser_context *context); + struct moberg_parser_context *context); int moberg_device_set_config(struct moberg_device* device, struct moberg_device_config *config); int moberg_device_parse_map(struct moberg_device* device, - struct moberg_config_parser_context *context, + struct moberg_parser_context *context, struct moberg_device_map_range range); int moberg_device_add_analog_in(struct moberg_device* device, diff --git a/moberg_module.h b/moberg_module.h new file mode 100644 index 0000000000000000000000000000000000000000..29ce50166c323fd44e6f763a6b1e09cfa9a643b6 --- /dev/null +++ b/moberg_module.h @@ -0,0 +1,58 @@ +#ifndef __MOBERG_MODULE_H__ +#define __MOBERG_MODULE_H__ + +#include <stdio.h> +#include <moberg_parser.h> + +struct moberg_parser_token; + +enum moberg_parser_token_kind { + tok_none, + tok_EOF, + tok_LPAREN, + tok_RPAREN, + tok_LBRACE, + tok_RBRACE, + tok_LBRACKET, + tok_RBRACKET, + tok_EQUAL, + tok_COMMA, + tok_COLON, + tok_SEMICOLON, + tok_INTEGER, + tok_IDENT, + tok_STRING, +}; + +struct moberg_parser_ident { + int length; + const char *value; +}; + +struct moberg_parser_integer { + int value; +}; + +struct moberg_parser_token { + enum moberg_parser_token_kind kind; + union { + struct moberg_parser_ident ident; + struct moberg_parser_ident string; + struct moberg_parser_integer integer; + } u; +}; + +int moberg_parser_acceptsym( + struct moberg_parser_context *c, + enum moberg_parser_token_kind kind, + struct moberg_parser_token *token); + +int moberg_parser_acceptkeyword( + struct moberg_parser_context *c, + const char *keyword); + +void moberg_parser_failed( + struct moberg_parser_context *c, + FILE *f); + +#endif diff --git a/moberg_config_parser.c b/moberg_parser.c similarity index 92% rename from moberg_config_parser.c rename to moberg_parser.c index 3ede13b07b6c73539ea98d9aeebb78192d9e087f..7a46d9dbd2628d8992151702cd8f39dab042bcca 100644 --- a/moberg_config_parser.c +++ b/moberg_parser.c @@ -5,17 +5,17 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <moberg_config_parser.h> -#include <moberg_config_parser_module.h> +#include <moberg_parser.h> +#include <moberg_module.h> #include <moberg_device.h> -typedef enum moberg_config_parser_token_kind kind_t; -typedef struct moberg_config_parser_token token_t; -typedef struct moberg_config_parser_ident ident_t; +typedef enum moberg_parser_token_kind kind_t; +typedef struct moberg_parser_token token_t; +typedef struct moberg_parser_ident ident_t; #define MAX_EXPECTED 10 -typedef struct moberg_config_parser_context { +typedef struct moberg_parser_context { struct moberg_config *config; const char *buf; /* Pointer to data to be parsed */ const char *p; /* current parse location */ @@ -31,13 +31,13 @@ static inline int acceptsym(context_t *c, kind_t kind, token_t *token) { - return moberg_config_parser_acceptsym(c, kind, token); + return moberg_parser_acceptsym(c, kind, token); } static inline int acceptkeyword(context_t *c, const char *keyword) { - return moberg_config_parser_acceptkeyword(c, keyword); + return moberg_parser_acceptkeyword(c, keyword); } static const void nextsym_ident(context_t *c) @@ -190,7 +190,7 @@ static int peeksym(context_t *c, return 0; } -int moberg_config_parser_acceptsym(context_t *c, +int moberg_parser_acceptsym(context_t *c, kind_t kind, token_t *token) { @@ -229,7 +229,7 @@ int moberg_config_parser_acceptsym(context_t *c, return 0; } -int moberg_config_parser_acceptkeyword(context_t *c, +int moberg_parser_acceptkeyword(context_t *c, const char *keyword) { token_t t; @@ -246,8 +246,8 @@ int moberg_config_parser_acceptkeyword(context_t *c, return 0; } -void moberg_config_parser_failed( - struct moberg_config_parser_context *c, +void moberg_parser_failed( + struct moberg_parser_context *c, FILE *f) { fprintf(f, "EXPECTED "); @@ -307,7 +307,7 @@ static int parse_map_range(context_t *c, range->max = max.u.integer.value; return 1; syntax_err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); err: return 0; } @@ -329,7 +329,7 @@ static int parse_map(context_t *c, if (! acceptsym(c, tok_SEMICOLON, NULL)) { goto syntax_err; } return 1; syntax_err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); err: return 0; } @@ -356,7 +356,7 @@ static int parse_device(context_t *c, } return 1; syntax_err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); err: return 0; } @@ -397,7 +397,7 @@ static int parse(context_t *c) } return 1; syntax_err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); goto err; err: return 0; diff --git a/moberg_parser.h b/moberg_parser.h new file mode 100644 index 0000000000000000000000000000000000000000..1d8148c8dce42ca3c3ca76a9f1de910b07a51cf4 --- /dev/null +++ b/moberg_parser.h @@ -0,0 +1,10 @@ +#ifndef __MOBERG_PARSER_H__ +#define __MOBERG_PARSER_H__ + +#include <moberg_config.h> + +struct moberg_parser_context; + +struct moberg_config *moberg_config_parse(const char *buf); + +#endif diff --git a/modules/comedi/Makefile b/modules/comedi/Makefile index 4923fc69f0e63868378cb240e2b6e1f99fd1fea3..ca1e0e2c66f5d303dc7efa46745329dbbe6f9edf 100644 --- a/modules/comedi/Makefile +++ b/modules/comedi/Makefile @@ -8,4 +8,4 @@ all: $(LIBRARIES:%=../../build/%) ../../build/libmoberg_comedi.so: comedi.c Makefile $(CC) -o $@ $(CCFLAGS) -shared -fPIC $< -../../build/libmoberg_comedi.so: ../../moberg_config_parser_module.h +../../build/libmoberg_comedi.so: ../../moberg_module.h diff --git a/modules/comedi/comedi.c b/modules/comedi/comedi.c index 457c2a78c99ae43eb9bd13019ba9ac0c624b697d..ccf738c89415c16c56df50401a358acab45d88aa 100644 --- a/modules/comedi/comedi.c +++ b/modules/comedi/comedi.c @@ -1,15 +1,15 @@ #include <moberg_config.h> -#include <moberg_config_parser.h> -#include <moberg_config_parser_module.h> +#include <moberg_parser.h> +#include <moberg_module.h> #include <moberg_device.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -typedef enum moberg_config_parser_token_kind kind_t; -typedef struct moberg_config_parser_token token_t; -typedef struct moberg_config_parser_ident ident_t; -typedef struct moberg_config_parser_context context_t; +typedef enum moberg_parser_token_kind kind_t; +typedef struct moberg_parser_token token_t; +typedef struct moberg_parser_ident ident_t; +typedef struct moberg_parser_context context_t; struct moberg_device_map {}; struct moberg_device_config { @@ -20,18 +20,18 @@ static inline int acceptsym(context_t *c, kind_t kind, token_t *token) { - return moberg_config_parser_acceptsym(c, kind, token); + return moberg_parser_acceptsym(c, kind, token); } static inline int acceptkeyword(context_t *c, const char *keyword) { - return moberg_config_parser_acceptkeyword(c, keyword); + return moberg_parser_acceptkeyword(c, keyword); } static int parse_config( struct moberg_device *device, - struct moberg_config_parser_context *c) + struct moberg_parser_context *c) { struct moberg_device_config *config = malloc(sizeof *config); if (! config) { @@ -81,7 +81,7 @@ static int parse_config( moberg_device_set_config(device, config); return 1; syntax_err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); free(config); err: return 0; @@ -89,7 +89,7 @@ err: static int parse_map( struct moberg_device *device, - struct moberg_config_parser_context *c, + struct moberg_parser_context *c, enum moberg_device_map_kind kind) { token_t min, max; @@ -138,7 +138,7 @@ static int parse_map( if (! acceptsym(c, tok_RBRACE, NULL)) { goto err; } return 1; err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); return 0; } diff --git a/modules/serial2002/Makefile b/modules/serial2002/Makefile index 9f66f2d087173ae0b696046dd2076d7bcb5d2de6..e6b34fb65ed69f754252b043941e922ebc2891da 100644 --- a/modules/serial2002/Makefile +++ b/modules/serial2002/Makefile @@ -8,4 +8,4 @@ all: $(LIBRARIES:%=../../build/%) ../../build/libmoberg_serial2002.so: serial2002.c Makefile $(CC) -o $@ $(CCFLAGS) -shared -fPIC $< -../../build/libmoberg_serial2002.so: ../../moberg_config_parser_module.h +../../build/libmoberg_serial2002.so: ../../moberg_module.h diff --git a/modules/serial2002/serial2002.c b/modules/serial2002/serial2002.c index b1e2a8cb4d50b3ac035801b5692ae4d1d9073112..f89a5b8120117ace2c5ced879c2cefa7fe64e450 100644 --- a/modules/serial2002/serial2002.c +++ b/modules/serial2002/serial2002.c @@ -1,26 +1,26 @@ #include <moberg_config.h> -#include <moberg_config_parser.h> -#include <moberg_config_parser_module.h> +#include <moberg_parser.h> +#include <moberg_module.h> #include <moberg_device.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -typedef enum moberg_config_parser_token_kind kind_t; -typedef struct moberg_config_parser_token token_t; -typedef struct moberg_config_parser_context context_t; +typedef enum moberg_parser_token_kind kind_t; +typedef struct moberg_parser_token token_t; +typedef struct moberg_parser_context context_t; static inline int acceptsym(context_t *c, kind_t kind, token_t *token) { - return moberg_config_parser_acceptsym(c, kind, token); + return moberg_parser_acceptsym(c, kind, token); } static inline int acceptkeyword(context_t *c, const char *keyword) { - return moberg_config_parser_acceptkeyword(c, keyword); + return moberg_parser_acceptkeyword(c, keyword); } struct moberg_device_config { @@ -30,7 +30,7 @@ struct moberg_device_config { static int parse_config( struct moberg_device *device, - struct moberg_config_parser_context *c) + struct moberg_parser_context *c) { struct moberg_device_config *config = malloc(sizeof *config); if (! config) { @@ -60,7 +60,7 @@ static int parse_config( moberg_device_set_config(device, config); return 1; syntax_err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); free(config); err: return 0; @@ -68,7 +68,7 @@ err: static int parse_map( struct moberg_device *device, - struct moberg_config_parser_context *c, + struct moberg_parser_context *c, enum moberg_device_map_kind ignore) { enum moberg_device_map_kind kind; @@ -109,7 +109,7 @@ static int parse_map( } return 1; syntax_err: - moberg_config_parser_failed(c, stderr); + moberg_parser_failed(c, stderr); return 0; }