File: melder_console.cpp

package info (click to toggle)
praat 5.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,728 kB
  • sloc: cpp: 333,759; ansic: 237,947; makefile: 731; python: 340
file content (73 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (2)
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
/* melder_console.cpp
 *
 * Copyright (C) 1992-2011 Paul Boersma
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* pb 2008/02/17
 * pb 2008/10/27 Melder_consoleIsAnsi
 * pb 2011/04/05 C++
 */

#include "melder.h"
#include "NUM.h"
#ifdef _WIN32
	#include <windows.h>
#endif

bool Melder_consoleIsAnsi = false;

void Melder_writeToConsole (const wchar_t *message, bool useStderr) {
	if (message == NULL) return;
	#if defined (_WIN32)
		(void) useStderr;
		static HANDLE console = NULL;
		if (console == NULL) {
			console = CreateFile (L"CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
		}
		if (Melder_consoleIsAnsi) {
			size_t n = wcslen (message);
			for (long i = 0; i < n; i ++) {
				unsigned int kar = (unsigned short) message [i];
				fputc (kar, stdout);
			}
		//} else if (Melder_consoleIsUtf8) {
			//char *messageA = Melder_peekWcsToUtf8 (message);
			//fprintf (stdout, "%s", messageA);
		} else {
			WriteConsole (console, message, wcslen (message), NULL, NULL);
		}
	#else
		Melder_fwriteWcsAsUtf8 (message, wcslen (message), useStderr ? stderr : stdout);
	#endif
}

#if defined (_WIN32) && defined (CONSOLE_APPLICATION)
int main (int argc, char *argvA []);
extern "C" int wmain (int argc, wchar_t *argvW []);
extern "C" int wmain (int argc, wchar_t *argvW []) {
	char **argvA = NULL;
	if (argc > 0) {
		argvA = NUMvector <char *> (0, argc - 1);
		for (int iarg = 0; iarg < argc; iarg ++) {
			argvA [iarg] = Melder_wcsToUtf8 (argvW [iarg]);
		}
	}
	return main (argc, argvA);
}
#endif

/* End of file melder_console.cpp */