diff 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
line wrap: on
line diff
--- a/tok.h	Thu Sep 21 09:45:59 2017 +0200
+++ b/tok.h	Mon Sep 25 21:21:25 2017 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Guido Berhoerster <guido+pwm@berhoerster.name>
+ * Copyright (C) 2017 Guido Berhoerster <guido+pwm@berhoerster.name>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -25,11 +25,38 @@
 #define	TOK_H
 
 enum tok_err {
-	TOK_ERR_SYSTEM_ERROR = -1,
-	TOK_ERR_UNTERMINATED_QUOTE = -2,
-	TOK_ERR_TRAILING_BACKSLASH = -3
+	TOK_ERR_OK,
+	TOK_ERR_UNTERMINATED_QUOTE = -1,
+	TOK_ERR_TRAILING_BACKSLASH = -2,
+	TOK_ERR_INVALID_MACRO_NAME = -3
+};
+
+enum tok_type {
+	TOK_ARG,
+	TOK_MACRO
+};
+
+struct tok_any {
+	enum tok_type	type;
 };
 
-enum tok_err	tok_tokenize(const char *, int *, char ***);
+struct tok_arg {
+	enum tok_type	type;
+	char		*value;
+};
+
+struct tok_macro {
+	enum tok_type	type;
+	char		*name;
+};
+
+union tok {
+	struct tok_any	any;
+	struct tok_arg	arg;
+	struct tok_macro macro;
+};
+
+void		tok_free(union tok **);
+enum tok_err	tok_tokenize(const char *, size_t *, union tok ***);
 
 #endif /* !TOK_H */