This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathoutput.cpp
More file actions
153 lines (122 loc) · 3.28 KB
/
Copy pathoutput.cpp
File metadata and controls
153 lines (122 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* Copyright (C) 2016 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
//#include "report.h"
//#include "literal.h"
#include <output.h>
#include <report.h>
#include <foundation.h>
#include <foundation-auto.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#endif
//////////
static FILE *s_output = NULL;
void OutputFileBegin(FILE *p_file)
{
s_output = p_file;
}
void OutputWrite(const char *p_string)
{
if (s_output == NULL)
return;
fprintf(s_output, "%s", p_string);
}
void OutputWriteS(const char *p_left, const char *p_string, const char *p_right)
{
if (s_output == NULL)
return;
fprintf(s_output, "%s%s%s", p_left, p_string, p_right);
}
void OutputWriteI(const char *p_left, NameRef p_name, const char *p_right)
{
if (s_output == NULL)
return;
const char *t_name_string;
GetStringOfNameLiteral(p_name, &t_name_string);
OutputWriteS(p_left, t_name_string, p_right);
}
void OutputWriteD(const char *p_left, double* p_number, const char *p_right)
{
if (s_output == NULL)
return;
fprintf(s_output, "%s%f%s", p_left, *p_number, p_right);
}
void OutputWriteN(const char *p_left, intptr_t p_number, const char *p_right)
{
if (s_output == NULL)
return;
fprintf(s_output, "%s%ld%s", p_left, p_number, p_right);
}
void OutputEnd(void)
{
if (s_output == NULL)
return;
fclose(s_output);
}
/* This is the same as OutputWriteS, but escapes special XML
* characters (&, ", ', <, >) found in p_string */
void OutputWriteXmlS(const char *p_left, const char *p_string, const char *p_right)
{
struct xml_replacement_t {
const char *from, *to;
};
static const struct xml_replacement_t k_replacements[] = {
{"&", "&"},
{"<", "<"},
{">", ">"},
{"\"", """},
{"\'", "'"},
{NULL, NULL},
};
if (s_output == NULL)
{
return;
}
bool t_success = true;
MCAutoStringRef t_string;
if (t_success)
{
t_success =
MCStringCreateWithBytes(reinterpret_cast<const byte_t *>(p_string),
(uindex_t)strlen(p_string), kMCStringEncodingUTF8,
false, &t_string);
}
MCAutoStringRef t_xml_string;
if (t_success)
{
t_success = MCStringMutableCopy(*t_string, &t_xml_string);
}
for (int i = 0; t_success && k_replacements[i].from != nil; ++i)
{
t_success = MCStringFindAndReplace(*t_xml_string,
MCSTR(k_replacements[i].from),
MCSTR(k_replacements[i].to),
kMCStringOptionCompareExact);
}
MCAutoStringRefAsUTF8String t_xml_utf8string;
if (t_success)
{
t_success = t_xml_utf8string.Lock(*t_xml_string);
}
if (t_success)
{
OutputWriteS(p_left, *t_xml_utf8string, p_right);
}
else
{
/* UNCHECKED */ abort();
}
}
//////////