aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib.c
diff options
Diffstat (limited to 'lib.c')
-rw-r--r--lib.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib.c b/lib.c
new file mode 100644
index 00000000..d0b9d661
--- /dev/null
+++ b/lib.c
@@ -0,0 +1,39 @@
+/*
+ * Helper routines
+ */
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "token.h"
+
+void warn(struct token *token, const char * fmt, ...)
+{
+ static char buffer[512];
+ struct stream *stream;
+
+ va_list args;
+ va_start(args, fmt);
+ vsprintf(buffer, fmt, args);
+ va_end(args);
+
+ stream = input_streams + token->stream;
+ fprintf(stderr, "warning: %s:%d: %s\n",
+ stream->name, token->line,
+ buffer);
+}
+
+
+void die(const char *fmt, ...)
+{
+ va_list args;
+ static char buffer[512];
+
+ va_start(args, fmt);
+ vsnprintf(buffer, sizeof(buffer), fmt, args);
+ va_end(args);
+
+ fprintf(stderr, "%s\n", buffer);
+ exit(1);
+}
+
+