summaryrefslogtreecommitdiff
path: root/buf.c
diff options
context:
space:
mode:
authorJohn Millaway <john43@users.sourceforge.net>2003-03-27 18:02:58 +0000
committerJohn Millaway <john43@users.sourceforge.net>2003-03-27 18:02:58 +0000
commit17551916f3f63d31562c1c6c15ea8749b4a9279b (patch)
treee815f489a1aa347b4f19acfaafbde5f3bb75a61b /buf.c
parent6fe6068dee3020caf4bd93c2c7d71c675df3201d (diff)
Added %top block syntax.
Added test for %top block. Documented %top block.
Diffstat (limited to 'buf.c')
-rw-r--r--buf.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/buf.c b/buf.c
index 833837e..647be69 100644
--- a/buf.c
+++ b/buf.c
@@ -33,11 +33,24 @@
#include "flexdef.h"
+/* Take note: The buffer object is sometimes used as a String buffer (one
+ * continuous string), and sometimes used as a list of strings, usually line by
+ * line.
+ *
+ * The type is specified in buf_init by the elt_size. If the elt_size is
+ * sizeof(char), then the buffer should be treated as string buffer. If the
+ * elt_size is sizeof(char*), then the buffer should be treated as a list of
+ * strings.
+ *
+ * Certain functions are only appropriate for one type or the other.
+ */
+
/* global buffers. */
-struct Buf userdef_buf; /* for user #definitions triggered by cmd-line. */
-struct Buf defs_buf; /* for #define's autogenerated. List of strings. */
-struct Buf yydmap_buf; /* string buffer to hold yydmap elements */
-struct Buf m4defs_buf; /**< Holds m4 definitions. List of strings. */
+struct Buf userdef_buf; /**< for user #definitions triggered by cmd-line. */
+struct Buf defs_buf; /**< for #define's autogenerated. List of strings. */
+struct Buf yydmap_buf; /**< string buffer to hold yydmap elements */
+struct Buf m4defs_buf; /**< m4 definitions. List of strings. */
+struct Buf top_buf; /**< contains %top code. String buffer. */
struct Buf *buf_print_strings(struct Buf * buf, FILE* out)
{
@@ -66,6 +79,24 @@ struct Buf *buf_prints (struct Buf *buf, const char *fmt, const char *s)
return buf;
}
+/** Append a line directive to the string buffer.
+ * @param buf A string buffer.
+ * @param filename file name
+ * @param lineno line number
+ * @return buf
+ */
+struct Buf *buf_linedir (struct Buf *buf, const char* filename, int lineno)
+{
+ char *t, *fmt = "#line %d \"%s\"\n";
+
+ t = flex_alloc (strlen (fmt) + strlen (filename) + (int)(1 + log(lineno>=0?lineno:-lineno)/log(10)) + 1);
+ sprintf (t, fmt, lineno, filename);
+ buf = buf_strappend (buf, t);
+ flex_free (t);
+ return buf;
+}
+
+
/** Append the contents of @a src to @a dest.
* @param @a dest the destination buffer
* @param @a dest the source buffer