]> git.draconx.ca Git - gob-dx.git/blob - src/out.c
Release 0.0.3
[gob-dx.git] / src / out.c
1 #include <stdio.h>
2 #include <stdarg.h>
3 #include <glib.h>
4
5 #include "out.h"
6
7 extern FILE *out;
8 extern FILE *outh;
9
10 extern char *filename;
11 extern char *filebase;
12
13 int outline = 1;
14 int outhline = 1;
15
16 static int
17 strchrcnt(char *s, char c)
18 {
19         int cnt = 0;
20         for(;*s;s++)
21                 if(*s == c)
22                         cnt++;
23         return cnt;
24 }
25
26 void
27 out_printf(FILE *fp,char *format,...)
28 {
29         va_list ap;
30         char *s;
31         va_start(ap,format);
32         
33         s = g_strdup_vprintf(format,ap);
34
35         if(fp == out)
36                 outline += strchrcnt(s,'\n');
37         else if(fp == outh)
38                 outhline += strchrcnt(s,'\n');
39         else
40                 g_assert_not_reached();
41
42         fprintf(fp,"%s",s);
43         g_free(s);
44
45         va_end(ap);
46 }
47
48 void
49 out_addline_infile(FILE *fp, int line)
50 {
51         if(fp == out)
52                 outline++;
53         else if(fp == outh)
54                 outhline++;
55         else
56                 g_assert_not_reached();
57
58         fprintf(fp,"#line %d \"%s\"\n",line,filename);
59 }
60
61 void
62 out_addline_outfile(FILE *fp)
63 {
64         if(fp == out) {
65                 outline++;
66                 fprintf(fp,"#line %d \"%s.c\"\n",outline,filebase);
67         } else if(fp == outh) {
68                 outhline++;
69                 fprintf(fp,"#line %d \"%s.h\"\n",outhline,filebase);
70         } else
71                 g_assert_not_reached();
72
73 }