]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/quickbook/src/stream.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / tools / quickbook / src / stream.cpp
1 /*=============================================================================
2 Copyright (c) 2009 Daniel James
3
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8
9 #include "stream.hpp"
10 #include "path.hpp"
11 #include "files.hpp"
12
13 #if QUICKBOOK_WIDE_PATHS || QUICKBOOK_WIDE_STREAMS
14 #include <io.h>
15 #include <fcntl.h>
16 #endif
17
18 namespace quickbook {
19 namespace detail {
20 namespace {
21 bool ms_errors = false;
22 }
23
24 void set_ms_errors(bool x) {
25 ms_errors = x;
26 }
27
28 #if QUICKBOOK_WIDE_STREAMS
29
30 void initialise_output()
31 {
32 if (_isatty(_fileno(stdout))) _setmode(_fileno(stdout), _O_U16TEXT);
33 if (_isatty(_fileno(stderr))) _setmode(_fileno(stderr), _O_U16TEXT);
34 }
35
36 void write_utf8(ostream::base_ostream& out, quickbook::string_view x)
37 {
38 out << from_utf8(x);
39 }
40
41 ostream& out()
42 {
43 static ostream x(std::wcout);
44 return x;
45 }
46
47 namespace
48 {
49 inline ostream& error_stream()
50 {
51 static ostream x(std::wcerr);
52 return x;
53 }
54 }
55
56 #else
57
58 void initialise_output()
59 {
60 }
61
62 void write_utf8(ostream::base_ostream& out, quickbook::string_view x)
63 {
64 out << x;
65 }
66
67 ostream& out()
68 {
69 static ostream x(std::cout);
70 return x;
71 }
72
73 namespace
74 {
75 inline ostream& error_stream()
76 {
77 static ostream x(std::clog);
78 return x;
79 }
80 }
81
82 #endif
83
84 ostream& outerr()
85 {
86 return error_stream() << "Error: ";
87 }
88
89 ostream& outerr(fs::path const& file, std::ptrdiff_t line)
90 {
91 if (line >= 0)
92 {
93 if (ms_errors)
94 return error_stream() << path_to_stream(file) << "(" << line << "): error: ";
95 else
96 return error_stream() << path_to_stream(file) << ":" << line << ": error: ";
97 }
98 else
99 {
100 return error_stream() << path_to_stream(file) << ": error: ";
101 }
102 }
103
104 ostream& outerr(file_ptr const& f, string_iterator pos)
105 {
106 return outerr(f->path, f->position_of(pos).line);
107 }
108
109 ostream& outwarn(fs::path const& file, std::ptrdiff_t line)
110 {
111 if (line >= 0)
112 {
113 if (ms_errors)
114 return error_stream() << path_to_stream(file) << "(" << line << "): warning: ";
115 else
116 return error_stream() << path_to_stream(file) << ":" << line << ": warning: ";
117 }
118 else
119 {
120 return error_stream() << path_to_stream(file) << ": warning: ";
121 }
122 }
123
124 ostream& outwarn(file_ptr const& f, string_iterator pos)
125 {
126 return outwarn(f->path, f->position_of(pos).line);
127 }
128
129 ostream& ostream::operator<<(char c) {
130 assert(c && !(c & 0x80));
131 base << c;
132 return *this;
133 }
134
135 inline bool check_ascii(char const* x) {
136 for(;*x;++x) if(*x & 0x80) return false;
137 return true;
138 }
139
140 ostream& ostream::operator<<(char const* x) {
141 assert(check_ascii(x));
142 base << x;
143 return *this;
144 }
145
146 ostream& ostream::operator<<(std::string const& x) {
147 write_utf8(base, x);
148 return *this;
149 }
150
151 ostream& ostream::operator<<(quickbook::string_view x) {
152 write_utf8(base, x);
153 return *this;
154 }
155
156 ostream& ostream::operator<<(int x) {
157 base << x;
158 return *this;
159 }
160
161 ostream& ostream::operator<<(unsigned int x) {
162 base << x;
163 return *this;
164 }
165
166 ostream& ostream::operator<<(long x) {
167 base << x;
168 return *this;
169 }
170
171 ostream& ostream::operator<<(unsigned long x) {
172 base << x;
173 return *this;
174 }
175
176 #if !defined(BOOST_NO_LONG_LONG)
177 ostream& ostream::operator<<(boost::long_long_type x) {
178 base << x;
179 return *this;
180 }
181
182 ostream& ostream::operator<<(boost::ulong_long_type x) {
183 base << x;
184 return *this;
185 }
186 #endif
187
188 ostream& ostream::operator<<(fs::path const& x) {
189 base << path_to_stream(x);
190 return *this;
191 }
192
193 ostream& ostream::operator<<(base_ostream& (*x)(base_ostream&)) {
194 base << x;
195 return *this;
196 }
197
198 ostream& ostream::operator<<(base_ios& (*x)(base_ios&)) {
199 base << x;
200 return *this;
201 }
202 }}