]> git.draconx.ca Git - gob-dx.git/blob - src/out.c
Release 0.90.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
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
41                 g_assert_not_reached();
42
43         fprintf(fp,"%s",s);
44         g_free(s);
45 }
46
47 void
48 out_addline_infile(FILE *fp, int line)
49 {
50         if(fp == out)
51                 outline++;
52         else if(fp == outh)
53                 outhline++;
54         else
55                 g_assert_not_reached();
56
57         fprintf(fp,"#line %d \"%s\"\n",line,filename);
58 }
59
60 void
61 out_addline_outfile(FILE *fp)
62 {
63         if(fp == out) {
64                 outline++;
65                 fprintf(fp,"#line %d \"%s.c\"\n",outline,filebase);
66         } else if(fp == outh) {
67                 outhline++;
68                 fprintf(fp,"#line %d \"%s.h\"\n",outhline,filebase);
69         } else
70                 g_assert_not_reached();
71
72 }