Mercurial > projects > pwm
comparison tok.h @ 27:722a45b4028b
Add define command for defining macros
Macros are parsed when they are defined with the D command and can
subsequently be used as arguments for other commands.
Handle out of memory errors directly in tok.c.
author | Guido Berhoerster <guido+pwm@berhoerster.name> |
---|---|
date | Mon, 25 Sep 2017 21:21:25 +0200 |
parents | a7e41e1a79c8 |
children |
comparison
equal
deleted
inserted
replaced
26:5bdea77d0c1d | 27:722a45b4028b |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2016 Guido Berhoerster <guido+pwm@berhoerster.name> | 2 * Copyright (C) 2017 Guido Berhoerster <guido+pwm@berhoerster.name> |
3 * | 3 * |
4 * Permission is hereby granted, free of charge, to any person obtaining | 4 * Permission is hereby granted, free of charge, to any person obtaining |
5 * a copy of this software and associated documentation files (the | 5 * a copy of this software and associated documentation files (the |
6 * "Software"), to deal in the Software without restriction, including | 6 * "Software"), to deal in the Software without restriction, including |
7 * without limitation the rights to use, copy, modify, merge, publish, | 7 * without limitation the rights to use, copy, modify, merge, publish, |
23 | 23 |
24 #ifndef TOK_H | 24 #ifndef TOK_H |
25 #define TOK_H | 25 #define TOK_H |
26 | 26 |
27 enum tok_err { | 27 enum tok_err { |
28 TOK_ERR_SYSTEM_ERROR = -1, | 28 TOK_ERR_OK, |
29 TOK_ERR_UNTERMINATED_QUOTE = -2, | 29 TOK_ERR_UNTERMINATED_QUOTE = -1, |
30 TOK_ERR_TRAILING_BACKSLASH = -3 | 30 TOK_ERR_TRAILING_BACKSLASH = -2, |
31 TOK_ERR_INVALID_MACRO_NAME = -3 | |
31 }; | 32 }; |
32 | 33 |
33 enum tok_err tok_tokenize(const char *, int *, char ***); | 34 enum tok_type { |
35 TOK_ARG, | |
36 TOK_MACRO | |
37 }; | |
38 | |
39 struct tok_any { | |
40 enum tok_type type; | |
41 }; | |
42 | |
43 struct tok_arg { | |
44 enum tok_type type; | |
45 char *value; | |
46 }; | |
47 | |
48 struct tok_macro { | |
49 enum tok_type type; | |
50 char *name; | |
51 }; | |
52 | |
53 union tok { | |
54 struct tok_any any; | |
55 struct tok_arg arg; | |
56 struct tok_macro macro; | |
57 }; | |
58 | |
59 void tok_free(union tok **); | |
60 enum tok_err tok_tokenize(const char *, size_t *, union tok ***); | |
34 | 61 |
35 #endif /* !TOK_H */ | 62 #endif /* !TOK_H */ |