3
3
#include <stdlib.h>
4
4
#include <stdio.h>
5
5
#include <assert.h>
6
+ #include "../src/yaml_private.h"
6
7
7
8
int get_line (FILE * input , char * line );
8
9
char * get_anchor (char sigil , char * line , char * anchor );
9
10
char * get_tag (char * line , char * tag );
10
11
void get_value (char * line , char * value , int * style );
12
+ int usage (int ret );
11
13
12
14
int main (int argc , char * argv [])
13
15
{
14
16
FILE * input ;
15
17
yaml_emitter_t emitter ;
16
18
yaml_event_t event ;
19
+ yaml_version_directive_t * version_directive = NULL ;
17
20
18
21
int canonical = 0 ;
19
22
int unicode = 0 ;
20
23
char line [1024 ];
24
+ int foundfile = 0 ;
25
+ int i = 0 ;
26
+ int minor = 0 ;
27
+
28
+ for (i = 1 ; i < argc ; i ++ ) {
29
+ if (strncmp (argv [i ], "--help" , 6 ) == 0 )
30
+ return usage (0 );
31
+ if (strncmp (argv [i ], "-h" , 2 ) == 0 )
32
+ return usage (0 );
33
+ if (strncmp (argv [i ], "--directive" , 11 ) == 0 ) {
34
+ if (i + 1 == argc )
35
+ return usage (1 );
36
+ i ++ ;
37
+ if (strncmp (argv [i ], "1.1" , 3 ) == 0 )
38
+ minor = 1 ;
39
+ else if (strncmp (argv [i ], "1.2" , 3 ) == 0 )
40
+ minor = 2 ;
41
+ else
42
+ return usage (1 );
43
+ }
44
+ else if (!foundfile ) {
45
+ input = fopen (argv [i ], "rb" );
46
+ foundfile = 1 ;
47
+ }
21
48
22
- if (argc == 1 )
23
- input = stdin ;
24
- else if (argc == 2 )
25
- input = fopen (argv [1 ], "rb" );
26
- else {
27
- fprintf (stderr , "Usage: libyaml-emitter [<input-file>]\n" );
28
- return 1 ;
29
49
}
50
+ if (minor ) {
51
+ version_directive = YAML_MALLOC_STATIC (yaml_version_directive_t );
52
+ version_directive -> major = 1 ;
53
+ version_directive -> minor = minor ;
54
+ }
55
+ if (!foundfile )
56
+ input = stdin ;
57
+
30
58
assert (input );
31
59
32
60
if (!yaml_emitter_initialize (& emitter )) {
@@ -37,6 +65,7 @@ int main(int argc, char *argv[])
37
65
yaml_emitter_set_canonical (& emitter , canonical );
38
66
yaml_emitter_set_unicode (& emitter , unicode );
39
67
68
+
40
69
while (get_line (input , line )) {
41
70
int ok ;
42
71
char anchor [256 ];
@@ -51,7 +80,7 @@ int main(int argc, char *argv[])
51
80
}
52
81
else if (strncmp (line , "+DOC" , 4 ) == 0 ) {
53
82
implicit = strncmp (line , "+DOC ---" , 8 ) != 0 ;
54
- ok = yaml_document_start_event_initialize (& event , NULL , NULL , NULL , implicit );
83
+ ok = yaml_document_start_event_initialize (& event , version_directive , NULL , NULL , implicit );
55
84
}
56
85
else if (strncmp (line , "-DOC" , 4 ) == 0 ) {
57
86
implicit = strncmp (line , "-DOC ..." , 8 ) != 0 ;
@@ -229,3 +258,8 @@ void get_value(char *line, char *value, int *style)
229
258
}
230
259
value [i ] = '\0' ;
231
260
}
261
+
262
+ int usage (int ret ) {
263
+ fprintf (stderr , "Usage: run-emitter-test-suite [--directive (1.1|1.2)] [<input-file>]\n" );
264
+ return ret ;
265
+ }
0 commit comments