My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
output.h
1 #ifndef output_h
2 #define output_h
3 
4 #include <stdarg.h>
5 
6 /* Declare the tag for a generic output stream. */
7 
8 typedef struct OutputStream OutputStream;
9 
10 /* List iterator-specific method function declarations */
11 
12 /*
13  * Write a given number of characters to an output stream.
14  *
15  * Input:
16  * stream OutputStream * The output stream to write to.
17  * text const char * A string to be written to the stream.
18  * Output:
19  * return int 0 - OK.
20  * 1 - Error.
21  */
22 #define OUTPUT_WRITE_FN(fn) int (fn)(OutputStream *stream, const char *text)
23 
24 /*
25  * Delete a stream context (as recorded in OutputStream::data).
26  *
27  * Input:
28  * data void * The context data to be deleted.
29  * Output:
30  * return void * The deleted context data (always NULL).
31  */
32 #define OUTPUT_DEL_FN(fn) void *(fn)(void *data)
33 
34 /* Set the maximum length of any output token */
35 
36 enum {OUTPUT_WORKLEN=1024};
37 
38 /* Declare a generic output stream container */
39 
40 struct OutputStream {
41  OUTPUT_WRITE_FN(*write_fn); /* Function to write a string to the stream */
42  OUTPUT_DEL_FN(*del_fn); /* Iterator destructor */
43  char work[OUTPUT_WORKLEN]; /* Work buffer for encoding lexical components */
44  void *data; /* Type-specific data */
45  bool interactive;
46 };
47 
48 /*
49  * Construct an initially closed output stream, ready to be connected to
50  * an output sink with open_OutputStream().
51  */
52 OutputStream *new_OutputStream(void);
53 
54 /*
55  * Connect an output stream to a specific output sink. This function
56  * should only be called from type-specific stream open_*()
57  * functions (see below).
58  */
59 int open_OutputStream(OutputStream *stream, void *data,
60  OUTPUT_WRITE_FN(*write_fn), OUTPUT_DEL_FN(*del_fn));
61 
62 /*
63  * Close an output stream. Future writes will return with an error
64  * until the stream is successfully re-opened to another output sink.
65  */
66 void close_OutputStream(OutputStream *stream);
67 
68 /*
69  * Declare constructors for provided output stream iterators.
70  */
71 int open_FileOutputStream(OutputStream *stream, char *dir, char *name);
72 int open_StringOutputStream(OutputStream *stream, int truncate,
73  char *buffer, size_t size);
74 int open_StdioOutputStream(OutputStream *stream, int do_close, FILE *fp);
75 int open_LprintfOutputStream(OutputStream *stream, FILE *fp);
76 int open_StdoutStream(OutputStream *stream);
77 int open_StderrStream(OutputStream *stream);
78 
79 /*
80  * Declare a generic stream destructor.
81  */
82 OutputStream *del_OutputStream(OutputStream *stream);
83 
84 /*
85  * Write a '\0' terminated string to an output stream.
86  */
87 int write_OutputStream(OutputStream *stream, const char *s);
88 
89 /*
90  * Write an array of n characters to an output stream.
91  */
92 int nwrite_OutputStream(OutputStream *stream, const char *s, size_t n);
93 
94 /*
95  * Reopen a string output stream to a new line to be composed.
96  */
97 int clr_StringOutputStream(OutputStream *stream);
98 
99 /*
100  * Write a quoted string to the specified stream. This includes
101  * prepending and postpending " characters and the conversion of
102  * unprintable characters and embedded " characters to their equivalent
103  * C escape sequences (eg. tab -> \t).
104  */
105 int output_quoted_string(OutputStream *stream, char *string);
106 
107 typedef enum {
108  ET_BELL=1, /* \a - Bell */
109  ET_BS=2, /* \b - Backspace */
110  ET_FF=4, /* \f - Form feed */
111  ET_NL=8, /* \n - New line */
112  ET_CR=16, /* \r - Carriage return */
113  ET_HT=32, /* \t - Horizontal Tab */
114  ET_VT=64, /* \v - Vertical Tab */
115  ET_ESC=128, /* \\ - Backslash */
116  ET_QUOTE=256, /* \' - Single quotes */
117  ET_SPEECH=512, /* \" - Double quotes */
118  ET_OTHER=1024, /* \0nn - Other unprintable characters */
119 /*
120  * All of the above.
121  */
122  ET_ALL = (ET_BELL | ET_BS | ET_FF | ET_NL | ET_CR | ET_HT | ET_VT | ET_ESC |
123  ET_QUOTE | ET_SPEECH | ET_OTHER),
124 /*
125  * None of the above.
126  */
127  ET_NONE=0
128 } EscapeType;
129 
130 /*
131  * Output an unquoted string, optionally with selected unprintable
132  * and white-space characters displayed as escape sequences. The
133  * filter argument should be a bitwise union of EscapeType enumerators,
134  * with each bit specifying a character code that should be displayed
135  * as a C-style escape sequence. The flags[] argument should be an array
136  * of printf-style flags, of which only the '-' flag is used.
137  * If the output string doesn't take min_width characters then it will
138  * be padded with spaces. If the '-' flag has been specified trailing
139  * spaces will be added, otherwise leading spaces will be used. If the
140  * string takes more than max_width characters before padding then it
141  * will be truncated unless max_width is zero.
142  */
143 int output_string(OutputStream *stream, unsigned filter, char *flags,
144  unsigned min_width, int max_width, int max_char,
145  char *string);
146 
147 /*
148  * The following functions are OutputStream equivalents to fprintf()
149  * and vfprintf().
150  */
151 int output_printf(OutputStream *stream, const char *fmt, ...);
152 int output_vprintf(OutputStream *stream, const char *fmt, va_list ap);
153 
154 /*
155  * Write a long int in a given base.
156  */
157 typedef enum {
158  OUT_BINARY = 2,
159  OUT_OCTAL = 8,
160  OUT_DECIMAL = 10,
161  OUT_HEX = 16
162 } OutputBase;
163 
164 int output_int(OutputStream *stream, OutputBase base, char *flags, int width,
165  int precision, int lval);
166 int output_uint(OutputStream *stream, OutputBase base, char *flags, int width,
167  int precision, unsigned int ulval);
168 int output_double(OutputStream *stream, char *flags, int width, int precision,
169  char type, double dval);
170 
171 int output_sexagesimal(OutputStream *stream, char *flags, int width,
172  int ninteger, int precision, double number);
173 int output_date(OutputStream *stream, char *flags, int width,
174  int day, int month, int year);
175 int output_spaces(OutputStream *stream, int n);
176 int output_zeros(OutputStream *stream, int n);
177 int output_interval(OutputStream *stream, char *flags, int width,
178  int precision, double interval);
179 
180 #endif
Definition: eval_defs.h:33
Definition: tVideoCapabilitiesEml.cc:67
Definition: output.h:40