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