nsgenbind
Loading...
Searching...
No Matches
src
output.c
Go to the documentation of this file.
1
/* generated output implementation
2
*
3
* This file is part of nsgenbind.
4
* Licensed under the MIT License,
5
* http://www.opensource.org/licenses/mit-license.php
6
* Copyright 2019 Vincent Sanders <vince@netsurf-browser.org>
7
*/
8
9
#include <stdio.h>
10
#include <stdarg.h>
11
#include <stdlib.h>
12
#include <string.h>
13
14
#include "
utils.h
"
15
#include "
output.h
"
16
17
struct
opctx
{
18
char
*
filename
;
19
FILE *
outf
;
20
unsigned
int
lineno
;
21
};
22
23
int
output_open
(
const
char
*
filename
,
struct
opctx
**opctx_out)
24
{
25
struct
opctx
*
opctx
;
26
27
opctx
=
malloc
(
sizeof
(
struct
opctx
));
28
if
(
opctx
== NULL) {
29
return
-1;
30
}
31
32
opctx
->
filename
= strdup(
filename
);
33
if
(
opctx
->
filename
== NULL) {
34
free
(
opctx
);
35
return
-1;
36
}
37
38
/* open output file */
39
opctx
->
outf
=
genb_fopen_tmp
(
opctx
->
filename
);
40
if
(
opctx
->
outf
== NULL) {
41
free
(
opctx
->
filename
);
42
free
(
opctx
);
43
return
-1;
44
}
45
46
opctx
->
lineno
= 2;
47
*opctx_out =
opctx
;
48
49
return
0;
50
}
51
52
int
output_close
(
struct
opctx
*
opctx
)
53
{
54
int
res;
55
res =
genb_fclose_tmp
(
opctx
->
outf
,
opctx
->
filename
);
56
free
(
opctx
->
filename
);
57
free
(
opctx
);
58
return
res;
59
}
60
64
static
char
output_buffer[128*1024];
65
66
int
outputf
(
struct
opctx
*
opctx
,
const
char
*fmt, ...)
67
{
68
va_list ap;
69
int
res;
70
int
idx;
71
72
va_start(ap, fmt);
73
res = vsnprintf(output_buffer,
sizeof
(output_buffer), fmt, ap);
74
va_end(ap);
75
76
/* account for newlines in output */
77
for
(idx = 0; idx < res; idx++) {
78
if
(output_buffer[idx] ==
'\n'
) {
79
opctx
->
lineno
++;
80
}
81
}
82
83
fwrite(output_buffer, 1, res,
opctx
->
outf
);
84
85
return
res;
86
}
87
88
int
outputc
(
struct
opctx
*
opctx
,
int
c)
89
{
90
if
(c ==
'\n'
) {
91
opctx
->
lineno
++;
92
}
93
fputc(c,
opctx
->
outf
);
94
95
return
0;
96
}
97
98
int
output_line
(
struct
opctx
*
opctx
)
99
{
100
int
res;
101
res = fprintf(
opctx
->
outf
,
102
"#line %d \"%s\"\n"
,
103
opctx
->
lineno
,
opctx
->
filename
);
104
opctx
->
lineno
++;
105
return
res;
106
}
filename
DOMString filename
Definition
html.idl:1561
malloc
void * malloc(YYSIZE_T)
free
void free(void *)
outputc
int outputc(struct opctx *opctx, int c)
Definition
output.c:88
output_line
int output_line(struct opctx *opctx)
Definition
output.c:98
outputf
int outputf(struct opctx *opctx, const char *fmt,...)
Definition
output.c:66
output_close
int output_close(struct opctx *opctx)
Definition
output.c:52
output_open
int output_open(const char *filename, struct opctx **opctx_out)
Definition
output.c:23
output.h
opctx
Definition
output.c:17
opctx::filename
char * filename
Definition
output.c:18
opctx::outf
FILE * outf
Definition
output.c:19
opctx::lineno
unsigned int lineno
Definition
output.c:20
genb_fopen_tmp
FILE * genb_fopen_tmp(const char *fname)
Definition
utils.c:70
genb_fclose_tmp
int genb_fclose_tmp(FILE *filef_tmp, const char *fname)
Definition
utils.c:93
utils.h
Generated on Fri Dec 12 2025 12:46:06 for nsgenbind by
1.9.8