]> git.draconx.ca Git - gob-dx.git/blob - src/out.c
Release 0.92.2
[gob-dx.git] / src / out.c
1 #include <stdio.h>
2 #include <stdarg.h>
3 #include <glib.h>
4
5 #include "main.h"
6
7 #include "out.h"
8
9 int outline = 1;
10 static gboolean in_out = TRUE;
11 int outhline = 1;
12 static gboolean in_outh = TRUE;
13 int outphline = 1;
14 static gboolean in_outph = TRUE;
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
32         va_start(ap,format);
33         s = g_strdup_vprintf(format,ap);
34         va_end(ap);
35
36         if(fp == out)
37                 outline += strchrcnt(s,'\n');
38         else if(fp == outh)
39                 outhline += strchrcnt(s,'\n');
40         else if(fp == outph)
41                 outphline += 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                 in_out = FALSE;
55         } else if(fp == outh) {
56                 outhline++;
57                 in_outh = FALSE;
58         } else if(fp == outph) {
59                 outphline++;
60                 in_outph = FALSE;
61         } else
62                 g_assert_not_reached();
63
64         fprintf(fp,"#line %d \"%s\"\n",line,filename);
65 }
66
67 void
68 out_addline_outfile(FILE *fp)
69 {
70         if(fp == out) {
71                 if(in_out) return;
72                 outline++;
73                 if(!for_cpp)
74                         fprintf(fp,"#line %d \"%s.c\"\n",outline,filebase);
75                 else
76                         fprintf(fp,"#line %d \"%s.cc\"\n",outline,filebase);
77                 in_out = TRUE;
78         } else if(fp == outh) {
79                 if(in_outh) return;
80                 outhline++;
81                 fprintf(fp,"#line %d \"%s.h\"\n",outhline,filebase);
82                 in_outh = TRUE;
83         } else if(fp == outph) {
84                 if(in_outph) return;
85                 outphline++;
86                 fprintf(fp,"#line %d \"%s-private.h\"\n",outphline,filebase);
87                 in_outph = TRUE;
88         } else
89                 g_assert_not_reached();
90 }