Commit 3673bb52 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

More parsing work

parent a985014d
......@@ -3,7 +3,7 @@ CCFLAGS+=-Wall -Werror -I. -g
LDFLAGS+=-Lbuild/ -lmoberg
MODULES:=$(wildcard modules/*)
LDFLAGS_parse_config=-ldl moberg_driver.o
LDFLAGS_parse_config=-ldl -export-dynamic
all: $(LIBRARIES:%=build/%) $(MODULES) test/test_c parse_config
echo $(MODULES)
......@@ -14,11 +14,11 @@ build/libmoberg.so: moberg.c Makefile | build
build:
mkdir $@
%: %.o
$(CC) $(LDFLAGS) $(LDFLAGS_$(*)) -o $@ $<
%: build/%.o Makefile
$(CC) $(LDFLAGS) $(LDFLAGS_$(*)) -o $@ $(filter %.o,$^)
%.o: %.c
$(CC) $(CCFLAGS) -c $<
build/%.o: %.c Makefile
$(CC) $(CCFLAGS) -c -o $@ $<
.PHONY: $(MODULES)
......@@ -40,5 +40,6 @@ clean:
rm build/*
parse_config: moberg_config_parser.h
parse_config: moberg_driver.o
build/parse_config.o: moberg_config_parser.h
parse_config: build/moberg_driver.o
parse_config: build/parse_config.o
......@@ -7,13 +7,13 @@ struct moberg_config_parser_token;
enum moberg_config_parser_token_kind {
tok_none,
tok_LBRACE = '{',
tok_RBRACE,
tok_LBRACKET,
tok_RBRACKET,
tok_EQUAL,
tok_COLON,
tok_SEMICOLON,
tok_INTEGER,
tok_RBRACE = '}',
tok_LBRACKET = '[',
tok_RBRACKET = ']',
tok_EQUAL = '=',
tok_COLON = ':',
tok_SEMICOLON = ';',
tok_INTEGER = 256,
tok_CONFIG,
tok_MAP,
tok_ANALOGIN,
......@@ -22,15 +22,19 @@ enum moberg_config_parser_token_kind {
tok_DIGITALOUT,
tok_ENCODERIN,
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 {
int length;
const char *value;
} ident;
struct moberg_config_parser_ident ident;
struct moberg_config_parser_ident string;
struct moberg_config_parser_integer {
int value;
} integer;
......@@ -42,4 +46,8 @@ int moberg_config_parser_acceptsym(
enum moberg_config_parser_token_kind kind,
struct moberg_config_parser_token *token);
int moberg_config_parser_peeksym(
struct moberg_config_parser_context *c,
struct moberg_config_parser_token *token);
#endif
#include <moberg_config_parser.h>
#include <moberg_driver.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define acceptsym moberg_config_parser_acceptsym
#define peeksym moberg_config_parser_peeksym
typedef struct moberg_config_parser_token token_t;
typedef struct moberg_config_parser_ident ident_t;
static struct moberg_driver_config parse_config(
struct moberg_config_parser_context *context)
struct moberg_config_parser_context *c)
{
struct moberg_driver_config result;
token_t t;
printf("PARSE_CONFIG %s\n", __FILE__);
/*
const char *buf = context->buf;
while (*buf && *buf != '}') {
buf++;
printf("LBRACE %d", acceptsym(c, tok_LBRACE, &t));
for (;;) {
if (acceptsym(c, tok_IDENT, &t) ||
acceptsym(c, tok_CONFIG, &t)) {
const char *v = t.u.ident.value;
int l = t.u.ident.length;
if (strncmp("device", v, l) == 0) {
printf("DEVICE\n");
} else if (strncmp("modprobe", v, l) == 0) {
printf("MODPROBE\n");
} else if (strncmp("comedi", v, l) == 0) {
printf("CONFIG\n");
}
acceptsym(c, tok_EQUAL, NULL);
for (;;) {
peeksym(c, &t);
acceptsym(c, t.kind, NULL);
printf("%d\n", t.kind);
if (t.kind == tok_SEMICOLON) { break; }
}
} else if (acceptsym(c, tok_RBRACE, NULL)) {
break;
} else {
goto err;
}
}
context->buf = buf + 1;
*/
return result;
err:
exit(1);
return result;
}
......
......@@ -65,6 +65,7 @@ out: ;
static const void nextsym_integer(context_t *c)
{
c->token.kind = tok_INTEGER;
c->token.u.integer.value = 0;
while (*c->p && '0' <= *c->p && *c->p <= '9') {
c->token.u.integer.value *= 10;
......@@ -74,6 +75,27 @@ static const void nextsym_integer(context_t *c)
printf("INTEGER: %d\n", c->token.u.integer.value);
}
static const void nextsym_string(context_t *c)
{
printf("STTRING");
c->token.kind = tok_STRING;
c->p++;
c->token.u.string.value = c->p;
c->token.u.string.length = 0;
while (*c->p && *c->p != '"') {
if (*c->p == '\\') {
c->token.u.string.length++;
c->p++;
}
if (*c->p) {
c->token.u.string.length++;
c->p++;
}
}
c->p++;
printf("STRING: %.*s\n", c->token.u.string.length, c->token.u.string.value);
}
static int nextsym(context_t *c)
{
c->token.kind = tok_none;
......@@ -124,6 +146,9 @@ static int nextsym(context_t *c)
c->token.kind = tok_SEMICOLON;
c->p++;
break;
case '"':
nextsym_string(c);
break;
case 'a'...'z':
case 'A'...'Z':
case '_':
......@@ -138,7 +163,7 @@ static int nextsym(context_t *c)
break;
}
}
printf("TOKEN %d\n\n", c->token.kind);
printf("TOKEN %d %c\n\n", c->token.kind, c->token.kind<255?c->token.kind:' ');
if (c->token.kind != tok_none) {
return 1;
} else {
......@@ -160,6 +185,15 @@ int moberg_config_parser_acceptsym(context_t *c,
return 0;
}
int moberg_config_parser_peeksym(context_t *c,
token_t *token)
{
if (token) {
*token = c->token;
}
return *c->p != 0;
}
static int parse_map_range(context_t *c)
{
token_t low, high;
......@@ -260,6 +294,7 @@ static int parse_config(context_t *c)
return 1;
err:
printf("Failed!!");
exit (1);
return 0;
}
......
comedi {
config {
/* Parsed by parse_config in libmoberg_comedi.so */
device = /dev/comedi0 ;
device = "/dev/comedi0" ;
modprobe = [ comedi 8255 comedi_fc mite ni_tio ni_tiocmd ni_pcimio ] ;
config = [ ni_pcimio ] ;
}
......@@ -12,7 +12,7 @@ comedi {
serial2002 {
config {
/* Parsed by parse_config in libmoberg_serial2002.so */
device = /dev/ttyS0 ;
device = "/dev/ttyS0" ;
baud = 115200 ;
}
/* Moberg mapping[indices] = {driver specific}[indices]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment