void test_tok(void) {
TESTBEGIN("tok");
- assert_tok(" test tokens with, line / * + - , ; $1", {
- "test", "tokens", "with", ",", "line", "/", "*", "+", "-", ",",
- ";", "$1", NULL});
+ assert_tok(" test tokens with, line / * + - , ; $1",
+ {"test", "tokens", "with", ",", "line", "/", "*", "+", "-", ",",
+ ";", "$1", NULL});
- assert_tokuntil(" this is a, test for tok , until", ',', {
- "this is a", "test for tok ", "until", NULL});
+ assert_tokuntil(" this is a, test for tok , until", ',',
+ {"this is a", "test for tok ", "until", NULL});
TESTEND("tok");
}
"#define test 123\ntest\n#undefine test\ntest");
// macro
- assert_preproc
- (" line p1 1 label01,2 3\n line p2 2\n line p3 3 p1, p2, p3\n", 0,
- "#macro test\n line $1 1 label$$$$,$$ $$\n line $2 2\n line $3 3 "
- "$0\n#endmacro\ntest p1, p2, p3");
+ assert_preproc(
+ " line p1 1 label01,2 3\n line p2 2\n line p3 3 p1, p2, p3\n", 0,
+ "#macro test\n line $1 1 label$$$$,$$ $$\n line $2 2\n line $3 3 "
+ "$0\n#endmacro\ntest p1, p2, p3");
assert_preproc("test macro with no args\n", 0,
"#macro test\ntest macro with no args\n#endmacro\ntest");
assert_preproc("", -1, "#macro test\n not terminated\n");
- assert_preproc("nested macro t1\nafter\ncontent n1\n", 0,
- "#macro test\nnested macro $1\n#macro "
- "nested\ncontent $1\n#endmacro\nafter\nnested n1\n#endmacro\ntest t1");
+ assert_preproc(
+ "nested macro t1\nafter\ncontent n1\n", 0,
+ "#macro test\nnested macro $1\n#macro "
+ "nested\ncontent $1\n#endmacro\nafter\nnested n1\n#endmacro\ntest t1");
// ifdef
- assert_preproc("before\nifdeftest defined!\nafter", 0,
- "before\n#define test\n#ifdef test\nifdeftest defined!\n#endif\nafter");
+ assert_preproc(
+ "before\nifdeftest defined!\nafter", 0,
+ "before\n#define test\n#ifdef test\nifdeftest defined!\n#endif\nafter");
assert_preproc("before\nafter", 0,
"before\n#ifdef test\nifdeftest defined!\n#endif\nafter");
assert_preproc("ifdeftest defined!\n", -1,
// ifndef
assert_preproc("before\nifndeftest defined!\nafter", 0,
"before\n#ifndef test\nifndeftest defined!\n#endif\nafter");
- assert_preproc("before\nafter", 0,
- "before\n#define test\n#ifndef test\nifndeftest defined!\n#endif\nafter");
+ assert_preproc(
+ "before\nafter", 0,
+ "before\n#define test\n#ifndef test\nifndeftest defined!\n#endif\nafter");
assert_preproc("ifndeftest defined!\n", -1,
"#ifndef test\nifndeftest defined!\n");
ulas_tokbuffree(&ulas.toks);
}
-int ulas_icntr(void) {
- return ulas.icntr++;
-}
+int ulas_icntr(void) { return ulas.icntr++; }
struct ulas_config ulas_cfg_from_env(void) {
struct ulas_config cfg;
// 0b prefix is not supported in strtol... so we implement it by hand
if (*buf == 'b') {
buf++;
- tok.lit.val.intv = (int) strtol(buf, &buf, 2);
+ tok.lit.val.intv = (int)strtol(buf, &buf, 2);
} else {
- tok.lit.val.intv = (int) strtol(buf - 1, &buf, 0);
+ tok.lit.val.intv = (int)strtol(buf - 1, &buf, 0);
}
} else if (first == '\'') {
tok.type = ULAS_TOKLITERAL;
buf++;
tok.lit.val.intv = ulas_unescape(*buf, rc);
} else {
- tok.lit.val.intv = (int) *buf;
+ tok.lit.val.intv = (int)*buf;
}
buf++;
if (*buf != '\'') {
#undef WLED_TOKISTERM
struct ulas_str ulas_str(unsigned long n) {
- struct ulas_str str = { malloc(n), n };
+ struct ulas_str str = {malloc(n), n};
return str;
}
first_tok = 0;
struct ulas_ppdef *def =
- ulas_preprocgetdef(pp, pp->tok.buf, pp->tok.maxlen);
+ ulas_preprocgetdef(pp, pp->tok.buf, pp->tok.maxlen);
if (def) {
// if so... expand now and leave
switch (def->type) {
- case ULAS_PPDEF:{
+ case ULAS_PPDEF: {
unsigned long val_len = strlen(def->value);
int wsi = ulas_preproclws(pp, praw_line - read, *n);
if (val_len) {
}
break;
}
- case ULAS_PPMACRO:{
+ case ULAS_PPMACRO: {
// TODO: i am sure we can optimize the resize of line buffers here...
// get 9 comma separated values.
int paramc = 0;
while (paramc < ULAS_MACROPARAMMAX &&
ulas_tokuntil(&pp->macroparam[paramc], ',', &praw_line, *n) >
- 0) {
+ 0) {
// trim new lines from the end of macro params
ulas_trimend('\n', pp->macroparam[paramc].buf,
strlen(pp->macroparam[paramc].buf));
ulas_strensr(&pp->line, strlen(def->value) + 2);
const char *macro_argname[ULAS_MACROPARAMMAX] = {
- "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9"
- };
+ "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9"};
const char *val = def->value;
unsigned long vallen = strlen(def->value);
const char *name = macro_argname[mi];
if (pp->macroparam[mi].buf[0] &&
strncmp((name), pp->macrobuf.buf, pp->macrobuf.maxlen) == 0) {
- ulas_strensr(&pp->line,
- strnlen(pp->line.buf,
- pp->line.maxlen) +
- strnlen(pp->macroparam[mi].buf,
- pp->macroparam[mi].maxlen) + 1);
+ ulas_strensr(&pp->line, strnlen(pp->line.buf, pp->line.maxlen) +
+ strnlen(pp->macroparam[mi].buf,
+ pp->macroparam[mi].maxlen) +
+ 1);
tocat = pp->macroparam[mi].buf;
tocatlen = pp->macroparam[mi].maxlen;
// make sure to include leading white space
int wsi = ulas_preproclws(pp, val - valread, vallen);
ulas_strensr(&pp->line, strnlen(pp->line.buf, pp->line.maxlen) +
- tocatlen + wsi + 1);
+ tocatlen + wsi + 1);
strncat(pp->line.buf, tocat, tocatlen);
}
}
char *line = ulas_preprocexpand(pp, raw_line, &n);
const char *pline = line;
- const char *dirstrs[] = { ULAS_PPSTR_DEF, ULAS_PPSTR_MACRO,
- ULAS_PPSTR_IFDEF, ULAS_PPSTR_IFNDEF,
- ULAS_PPSTR_ENDIF, ULAS_PPSTR_ENDMACRO,
- ULAS_PPSTR_UNDEF, NULL
- };
- enum ulas_ppdirs dirs[] = { ULAS_PPDIR_DEF, ULAS_PPDIR_MACRO,
- ULAS_PPDIR_IFDEF, ULAS_PPDIR_IFNDEF,
- ULAS_PPDIR_ENDIF, ULAS_PPDIR_ENDMACRO,
- ULAS_PPDIR_UNDEF
- };
+ const char *dirstrs[] = {ULAS_PPSTR_DEF, ULAS_PPSTR_MACRO,
+ ULAS_PPSTR_IFDEF, ULAS_PPSTR_IFNDEF,
+ ULAS_PPSTR_ENDIF, ULAS_PPSTR_ENDMACRO,
+ ULAS_PPSTR_UNDEF, NULL};
+ enum ulas_ppdirs dirs[] = {ULAS_PPDIR_DEF, ULAS_PPDIR_MACRO,
+ ULAS_PPDIR_IFDEF, ULAS_PPDIR_IFNDEF,
+ ULAS_PPDIR_ENDIF, ULAS_PPDIR_ENDMACRO,
+ ULAS_PPDIR_UNDEF};
enum ulas_ppdirs found_dir = ULAS_PPDIR_NONE;
if (found_dir != ULAS_PPDIR_NONE) {
ulas_trimend('\n', line, strlen(line));
switch (found_dir) {
- case ULAS_PPDIR_DEF:{
+ case ULAS_PPDIR_DEF: {
// next token is a name
// and then the entire remainder of the line is a value
if (ulas_tok(&pp->tok, &pline, n) == 0) {
return -1;
}
- struct ulas_ppdef def = { ULAS_PPDEF, strdup(pp->tok.buf), strdup(pline),
- 0
- };
+ struct ulas_ppdef def = {ULAS_PPDEF, strdup(pp->tok.buf), strdup(pline),
+ 0};
ulas_preprocdef(pp, def);
// define short-circuits the rest of the logic
// because it just takes the entire rest of the line as a value!
goto dirdone;
}
- case ULAS_PPDIR_MACRO:{
+ case ULAS_PPDIR_MACRO: {
// get a name, ensure no more tokens come after
// and then consume lines until ENDMACRO is seen
if (ulas_tok(&pp->tok, &pline, n) == 0) {
}
// we leak the str's buffer into the def now
// this is ok because we call free for it later anyway
- struct ulas_ppdef def = { ULAS_PPMACRO, name, val.buf, 0 };
+ struct ulas_ppdef def = {ULAS_PPMACRO, name, val.buf, 0};
ulas_preprocdef(pp, def);
goto dirdone;
case ULAS_PPDIR_ENDMACRO:
break;
case ULAS_PPDIR_IFDEF:
- case ULAS_PPDIR_IFNDEF:{
+ case ULAS_PPDIR_IFNDEF: {
// get the name
// get a name, ensure no more tokens come after
// and then consume lines until ENDMACRO is seen
return -1;
}
struct ulas_ppdef *def =
- ulas_preprocgetdef(pp, pp->tok.buf, pp->tok.maxlen);
+ ulas_preprocgetdef(pp, pp->tok.buf, pp->tok.maxlen);
char buf[ULAS_LINEMAX];
memset(buf, 0, ULAS_LINEMAX);
}
goto dirdone;
}
- case ULAS_PPDIR_UNDEF:{
+ case ULAS_PPDIR_UNDEF: {
if (ulas_tok(&pp->tok, &pline, n) == 0) {
ULASERR("Expected name for #undef\n");
return -1;
}
struct ulas_preproc ulas_preprocinit(void) {
- struct ulas_preproc pp = { NULL, 0, ulas_str(1), ulas_str(1) };
+ struct ulas_preproc pp = {NULL, 0, ulas_str(1), ulas_str(1)};
for (unsigned long i = 0; i < ULAS_MACROPARAMMAX; i++) {
pp.macroparam[i] = ulas_str(8);
}
tb->len++;
}
-void ulas_tokbufclear(struct ulas_tokbuf *tb) {
- tb->len = 0;
-}
+void ulas_tokbufclear(struct ulas_tokbuf *tb) { tb->len = 0; }
-void ulas_tokbuffree(struct ulas_tokbuf *tb) {
- free(tb->buf);
-}
+void ulas_tokbuffree(struct ulas_tokbuf *tb) { free(tb->buf); }
/**
* Assembly step
if (ulas.tok.buf[0] == ULAS_TOK_ASMDIR_BEGIN) {
const char *dirstrs[] = {
- ULAS_ASMSTR_ORG, ULAS_ASMSTR_SET, ULAS_ASMSTR_BYTE, ULAS_ASMSTR_STR,
- ULAS_ASMSTR_FILL, ULAS_ASMSTR_PAD, ULAS_ASMSTR_INCBIN, NULL
- };
+ ULAS_ASMSTR_ORG, ULAS_ASMSTR_SET, ULAS_ASMSTR_BYTE, ULAS_ASMSTR_STR,
+ ULAS_ASMSTR_FILL, ULAS_ASMSTR_PAD, ULAS_ASMSTR_INCBIN, NULL};
enum ulas_asmdir dirs[] = {
- ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, ULAS_ASMDIR_BYTE, ULAS_ASMDIR_STR,
- ULAS_ASMDIR_FILL, ULAS_ASMDIR_PAD, ULAS_ASMDIR_INCBIN
- };
+ ULAS_ASMDIR_ORG, ULAS_ASMDIR_SET, ULAS_ASMDIR_BYTE, ULAS_ASMDIR_STR,
+ ULAS_ASMDIR_FILL, ULAS_ASMDIR_PAD, ULAS_ASMDIR_INCBIN};
enum ulas_asmdir dir = ULAS_ASMDIR_NONE;