Debian Codegraph @

gcc/testsuite/libgdiagnostics.dg/test-write-text-to-file.c

raw
1 /* Example of writing diagnostics in text form, but to a file,
2 rather than stderr. */
3
4 #include "libgdiagnostics.h"
5
6 /*
7 _________111111111122
8 123456789012345678901
9 PRINT "hello world!";
10 */
11 const int line_num = __LINE__ - 2;
12
13 int
14 main ()
15 {
16 FILE *outfile = fopen ("test.txt", "w");
17 if (!outfile)
18 return -1;
19
20 diagnostic_manager *diag_mgr = diagnostic_manager_new ();
21
22 diagnostic_manager_add_text_sink (diag_mgr, outfile,
23 DIAGNOSTIC_COLORIZE_NO);
24
25 const diagnostic_file *file = diagnostic_manager_new_file (diag_mgr, __FILE__, "c");
26 const diagnostic_physical_location *loc_start
27 = diagnostic_manager_new_location_from_file_line_column (diag_mgr, file, line_num, 8);
28 const diagnostic_physical_location *loc_end
29 = diagnostic_manager_new_location_from_file_line_column (diag_mgr, file, line_num, 19);
30 const diagnostic_physical_location *loc_range
31 = diagnostic_manager_new_location_from_range (diag_mgr,
32 loc_start,
33 loc_start,
34 loc_end);
35
36 diagnostic *d = diagnostic_begin (diag_mgr,
37 DIAGNOSTIC_LEVEL_ERROR);
38 diagnostic_set_location (d, loc_range);
39
40 diagnostic_finish (d, "can't find %qs", "foo");
41
42 diagnostic_manager_release (diag_mgr);
43
44 fclose (outfile);
45
46 return 0;
47 };