1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// Copyright (c) 1996-2020 Live Networks, Inc. All rights reserved.
17// Basic Usage Environment: for a simple, non-scripted, console application
18// Implementation
19
20#include "BasicUsageEnvironment.hh"
21#include <stdio.h>
22
23////////// BasicUsageEnvironment //////////
24
25#if defined(__WIN32__) || defined(_WIN32)
26extern "C" int initializeWinsockIfNecessary();
27#endif
28
29BasicUsageEnvironment::BasicUsageEnvironment(TaskScheduler& taskScheduler)
30: BasicUsageEnvironment0(taskScheduler) {
31#if defined(__WIN32__) || defined(_WIN32)
32 if (!initializeWinsockIfNecessary()) {
33 setResultErrMsg("Failed to initialize 'winsock': ");
34 reportBackgroundError();
35 internalError();
36 }
37#endif
38}
39
40BasicUsageEnvironment::~BasicUsageEnvironment() {
41}
42
43BasicUsageEnvironment*
44BasicUsageEnvironment::createNew(TaskScheduler& taskScheduler) {
45 return new BasicUsageEnvironment(taskScheduler);
46}
47
48int BasicUsageEnvironment::getErrno() const {
49#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_WCE)
50 return WSAGetLastError();
51#else
52 return errno;
53#endif
54}
55
56UsageEnvironment& BasicUsageEnvironment::operator<<(char const* str) {
57 if (str == NULL) str = "(NULL)"; // sanity check
58 fprintf(stderr, "%s", str);
59 return *this;
60}
61
62UsageEnvironment& BasicUsageEnvironment::operator<<(int i) {
63 fprintf(stderr, "%d", i);
64 return *this;
65}
66
67UsageEnvironment& BasicUsageEnvironment::operator<<(unsigned u) {
68 fprintf(stderr, "%u", u);
69 return *this;
70}
71
72UsageEnvironment& BasicUsageEnvironment::operator<<(double d) {
73 fprintf(stderr, "%f", d);
74 return *this;
75}
76
77UsageEnvironment& BasicUsageEnvironment::operator<<(void* p) {
78 fprintf(stderr, "%p", p);
79 return *this;
80}
81