Debian Codegraph @

harness/output.c

raw
1 #include "harness.h"
2 #include <stdio.h>
3 #include <stdarg.h>
4 #include <ctype.h>
5
6 static int available_width = 0;
7 static unsigned long output_time = 0;
8
9 static void new_line(void)
10 {
11 if (available_width)
12 {
13 available_width = 0;
14 fputs("\"\n", stdout);
15 }
16 }
17
18 static void check_time(void)
19 {
20 unsigned long current_time = get_time();
21
22 if (current_time != output_time)
23 {
24 new_line();
25 printf("Time: %ld\n", current_time);
26 output_time = current_time;
27 }
28 }
29
30 void outputc(char c)
31 {
32 check_time();
33 if (!available_width)
34 {
35 fputs("Output: \"", stdout);
36 available_width = 65;
37 }
38 switch(c)
39 {
40 case '"':
41 fputs("\"", stdout);
42 available_width -= 1;
43 break;
44
45 case '\\':
46 fputs("\\\\", stdout);
47 available_width -= 2;
48 break;
49
50 case '\n':
51 fputs("\\n", stdout);
52 available_width -= 2;
53 break;
54
55 case '\r':
56 fputs("\\r", stdout);
57 available_width -= 2;
58 break;
59
60 default:
61 if (isprint(c))
62 {
63 available_width -= 1;
64 putchar(c);
65 }
66 else
67 {
68 available_width -= 4;
69 printf("\\%03o", c);
70 }
71 break;
72 }
73 if (available_width <= 0)
74 {
75 available_width = 0;
76 fputs("\"\n", stdout);
77 }
78 }
79
80 void outputf(const char *format, ...)
81 {
82 va_list args;
83
84 check_time();
85 new_line();
86
87 va_start(args, format);
88 vprintf(format, args);
89 va_end(args);
90 }
91
92 /* */
93 /* Local Variables: */
94 /* mode:c */
95 /* c-indentation-style: "whitesmith" */
96 /* c-basic-offset: 2 */
97 /* End: */