aboutsummaryrefslogtreecommitdiff
path: root/lib.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@home.transmeta.com>2003-03-13 15:03:49 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 20:59:14 -0700
commit90247bd7671b301cd30f43b40cc47e71392a1c04 (patch)
tree2ba802b6f4d7a2d033a1e4bb09f77db359144aa5 /lib.c
parentIgnore object files and the test app (diff)
downloadsparse-90247bd7671b301cd30f43b40cc47e71392a1c04.tar.gz
sparse-90247bd7671b301cd30f43b40cc47e71392a1c04.tar.bz2
sparse-90247bd7671b301cd30f43b40cc47e71392a1c04.zip
Add simple recursive-descent C expression parsing (but we only do the
simple binops so far, type parsing is still way off). Clean up and update tokenization.
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 0000000..d0b9d66
--- /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);
+}
+
+