--- /dev/null
+#include <stdio.h>
+#include <stdarg.h>
+#include <glib.h>
+
+#include "out.h"
+
+extern FILE *out;
+extern FILE *outh;
+
+extern char *filename;
+extern char *filebase;
+
+int outline = 1;
+int outhline = 1;
+
+static int
+strchrcnt(char *s, char c)
+{
+ int cnt = 0;
+ for(;*s;s++)
+ if(*s == c)
+ cnt++;
+ return cnt;
+}
+
+void
+out_printf(FILE *fp,char *format,...)
+{
+ va_list ap;
+ char *s;
+ va_start(ap,format);
+
+ s = g_strdup_vprintf(format,ap);
+
+ if(fp == out)
+ outline += strchrcnt(s,'\n');
+ else if(fp == outh)
+ outhline += strchrcnt(s,'\n');
+ else
+ g_assert_not_reached();
+
+ fprintf(fp,"%s",s);
+ g_free(s);
+
+ va_end(ap);
+}
+
+void
+out_addline_infile(FILE *fp, int line)
+{
+ if(fp == out)
+ outline++;
+ else if(fp == outh)
+ outhline++;
+ else
+ g_assert_not_reached();
+
+ fprintf(fp,"#line %d \"%s\"\n",line,filename);
+}
+
+void
+out_addline_outfile(FILE *fp)
+{
+ if(fp == out) {
+ outline++;
+ fprintf(fp,"#line %d \"%s.c\"\n",outline,filebase);
+ } else if(fp == outh) {
+ outhline++;
+ fprintf(fp,"#line %d \"%s.h\"\n",outhline,filebase);
+ } else
+ g_assert_not_reached();
+
+}