Debian Codegraph @

terps/tads/tads3/tchostsi.cpp

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header: d:/cvsroot/tads/tads3/TCHOSTSI.CPP,v 1.2 1999/05/17 02:52:27 MJRoberts Exp $";
4 #endif
5
6 /*
7 * Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved.
8 *
9 * Please see the accompanying license file, LICENSE.TXT, for information
10 * on using and copying this software.
11 */
12 /*
13 Name
14 tchostsi.cpp - stdio implementation of host interface
15 Function
16
17 Notes
18
19 Modified
20 04/22/99 MJRoberts - Creation
21 */
22
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27
28 #include "tchostsi.h"
29 #include "charmap.h"
30 #include "tcmain.h"
31 #include "tcglob.h"
32
33
34 /* ------------------------------------------------------------------------ */
35 /*
36 * stdio host interface
37 */
38
39 /*
40 * display a message
41 */
42 void CTcHostIfcStdio::v_print_msg(const char *msg, va_list args)
43 {
44 /* display the message on the standard output */
45 v_printf(msg, args);
46 }
47
48 /*
49 * display a process step message
50 */
51 void CTcHostIfcStdio::v_print_step(const char *msg, va_list args)
52 {
53 /* if we're showing progress messages, proceed */
54 if (show_progress_)
55 {
56 /* show the status message prefix (use a tab by default) */
57 printf("%s", status_prefix_ != 0 ? status_prefix_ : "\t");
58
59 /* display the message on the standard output */
60 v_printf(msg, args);
61 }
62 }
63
64 /*
65 * display an error message
66 */
67 void CTcHostIfcStdio::v_print_err(const char *msg, va_list args)
68 {
69 /* display the message on the standard error output */
70 v_printf(msg, args);
71 }
72
73 /*
74 * display a message - internal interface; this routine formats the
75 * message and converts it to the console character set for display
76 */
77 void CTcHostIfcStdio::v_printf(const char *msg, va_list args)
78 {
79 char buf[1024];
80
81 /* format the message to our internal buffer */
82 t3vsprintf(buf, sizeof(buf), msg, args);
83
84 /* translate to the local character set if we have a mapper */
85 if (G_tcmain->get_console_mapper() != 0)
86 {
87 char xlat_buf[1024];
88 utf8_ptr p;
89 size_t len;
90
91 /* translate it */
92 p.set(buf);
93 len = G_tcmain->get_console_mapper()
94 ->map_utf8z_esc(xlat_buf, sizeof(xlat_buf), p,
95 &CCharmapToLocal::source_esc_cb);
96
97 /* if there's room, null-terminate the buffer */
98 if (len < sizeof(xlat_buf))
99 xlat_buf[len] = '\0';
100
101 /* display it on the standard output */
102 printf("%s", xlat_buf);
103 }
104 else
105 {
106 /* there's no character mapper - display the untranslated buffer */
107 printf("%s", buf);
108 }
109
110 /*
111 * Flush the standard output immediately. If our output is being
112 * redirected to a pipe that another program is reading, this will
113 * ensure that the other program will see our output as soon as we
114 * produce it, which might be important in some cases. In any case,
115 * we don't generally produce so much console output that this should
116 * significantly affect performance.
117 */
118 fflush(stdout);
119 }
120