print.c revision 1.2.2.1 1 1.2.2.1 bouyer /* $NetBSD: print.c,v 1.2.2.1 2000/11/20 20:39:27 bouyer Exp $ */
2 1.2.2.1 bouyer
3 1.2.2.1 bouyer /*-
4 1.2.2.1 bouyer * Copyright (c) 1999 Shin Takemura.
5 1.2.2.1 bouyer * All rights reserved.
6 1.2.2.1 bouyer *
7 1.2.2.1 bouyer * This software is part of the PocketBSD.
8 1.2.2.1 bouyer *
9 1.2.2.1 bouyer * Redistribution and use in source and binary forms, with or without
10 1.2.2.1 bouyer * modification, are permitted provided that the following conditions
11 1.2.2.1 bouyer * are met:
12 1.2.2.1 bouyer * 1. Redistributions of source code must retain the above copyright
13 1.2.2.1 bouyer * notice, this list of conditions and the following disclaimer.
14 1.2.2.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.2.1 bouyer * notice, this list of conditions and the following disclaimer in the
16 1.2.2.1 bouyer * documentation and/or other materials provided with the distribution.
17 1.2.2.1 bouyer * 3. All advertising materials mentioning features or use of this software
18 1.2.2.1 bouyer * must display the following acknowledgement:
19 1.2.2.1 bouyer * This product includes software developed by the PocketBSD project
20 1.2.2.1 bouyer * and its contributors.
21 1.2.2.1 bouyer * 4. Neither the name of the project nor the names of its contributors
22 1.2.2.1 bouyer * may be used to endorse or promote products derived from this software
23 1.2.2.1 bouyer * without specific prior written permission.
24 1.2.2.1 bouyer *
25 1.2.2.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.2.2.1 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.2.2.1 bouyer * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.2.2.1 bouyer * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.2.2.1 bouyer * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.2.2.1 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.2.2.1 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.2.2.1 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.2.2.1 bouyer * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.2.2.1 bouyer * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.2.2.1 bouyer * SUCH DAMAGE.
36 1.2.2.1 bouyer *
37 1.2.2.1 bouyer */
38 1.2.2.1 bouyer #include <pbsdboot.h>
39 1.2.2.1 bouyer #include <res/resource.h> /* for IDC_STATUS, status area ID */
40 1.2.2.1 bouyer
41 1.2.2.1 bouyer static HANDLE debug_log = INVALID_HANDLE_VALUE;
42 1.2.2.1 bouyer
43 1.2.2.1 bouyer int
44 1.2.2.1 bouyer debug_printf(LPWSTR lpszFmt, ...)
45 1.2.2.1 bouyer {
46 1.2.2.1 bouyer int count;
47 1.2.2.1 bouyer va_list ap;
48 1.2.2.1 bouyer wchar_t buffer[1024];
49 1.2.2.1 bouyer char ascbuf[2048];
50 1.2.2.1 bouyer
51 1.2.2.1 bouyer va_start(ap, lpszFmt);
52 1.2.2.1 bouyer count = wvsprintf(buffer, lpszFmt, ap);
53 1.2.2.1 bouyer va_end(ap);
54 1.2.2.1 bouyer if (count > 0) {
55 1.2.2.1 bouyer DWORD n;
56 1.2.2.1 bouyer OutputDebugStringW(buffer);
57 1.2.2.1 bouyer
58 1.2.2.1 bouyer if (debug_log != INVALID_HANDLE_VALUE) {
59 1.2.2.1 bouyer /* convert wide char string into multibyte
60 1.2.2.1 bouyer string (ascii) */
61 1.2.2.1 bouyer n = wcstombs(ascbuf, buffer, sizeof(ascbuf));
62 1.2.2.1 bouyer /* convert into DOS style new line code */
63 1.2.2.1 bouyer if (ascbuf[n - 1] == 0x0a) {
64 1.2.2.1 bouyer ascbuf[n - 1] = 0x0d;
65 1.2.2.1 bouyer ascbuf[n + 0] = 0x0a;
66 1.2.2.1 bouyer ascbuf[n + 1] = 0x00;
67 1.2.2.1 bouyer n += 1;
68 1.2.2.1 bouyer }
69 1.2.2.1 bouyer WriteFile(debug_log, ascbuf, n, &n, NULL);
70 1.2.2.1 bouyer }
71 1.2.2.1 bouyer }
72 1.2.2.1 bouyer return count;
73 1.2.2.1 bouyer }
74 1.2.2.1 bouyer
75 1.2.2.1 bouyer int
76 1.2.2.1 bouyer msg_printf(UINT type, LPWSTR caption, LPWSTR lpszFmt, ...)
77 1.2.2.1 bouyer {
78 1.2.2.1 bouyer int count;
79 1.2.2.1 bouyer va_list ap;
80 1.2.2.1 bouyer TCHAR buffer[1024];
81 1.2.2.1 bouyer
82 1.2.2.1 bouyer va_start(ap, lpszFmt);
83 1.2.2.1 bouyer count = wvsprintf(buffer, lpszFmt, ap);
84 1.2.2.1 bouyer va_end(ap);
85 1.2.2.1 bouyer return MessageBox(hDlgMain, buffer, caption, type);
86 1.2.2.1 bouyer }
87 1.2.2.1 bouyer
88 1.2.2.1 bouyer int
89 1.2.2.1 bouyer stat_printf(LPWSTR lpszFmt, ...)
90 1.2.2.1 bouyer {
91 1.2.2.1 bouyer int count;
92 1.2.2.1 bouyer va_list ap;
93 1.2.2.1 bouyer wchar_t buffer[1024];
94 1.2.2.1 bouyer
95 1.2.2.1 bouyer va_start(ap, lpszFmt);
96 1.2.2.1 bouyer count = wvsprintf(buffer, lpszFmt, ap);
97 1.2.2.1 bouyer va_end(ap);
98 1.2.2.1 bouyer if (count > 0) {
99 1.2.2.1 bouyer SetDlgItemText(hDlgMain, IDC_STATUS, buffer);
100 1.2.2.1 bouyer }
101 1.2.2.1 bouyer return count;
102 1.2.2.1 bouyer }
103 1.2.2.1 bouyer
104 1.2.2.1 bouyer int
105 1.2.2.1 bouyer set_debug_log(TCHAR* filename)
106 1.2.2.1 bouyer {
107 1.2.2.1 bouyer
108 1.2.2.1 bouyer /*
109 1.2.2.1 bouyer * Logging into file is dangerous. It may cause file system clash,
110 1.2.2.1 bouyer * because it try to write file until the last moment to boot and
111 1.2.2.1 bouyer * Windows can't flush file cache properly.
112 1.2.2.1 bouyer * And therefore the logging will be disanable unless you put a
113 1.2.2.1 bouyer * dummy log file on a directory.
114 1.2.2.1 bouyer */
115 1.2.2.1 bouyer debug_log = CreateFile(
116 1.2.2.1 bouyer filename, /* file name */
117 1.2.2.1 bouyer GENERIC_READ, /* access (read-write) mode */
118 1.2.2.1 bouyer FILE_SHARE_READ,/* share mode */
119 1.2.2.1 bouyer NULL, /* pointer to security attributes */
120 1.2.2.1 bouyer OPEN_EXISTING, /* how to create */
121 1.2.2.1 bouyer FILE_ATTRIBUTE_NORMAL, /* file attributes*/
122 1.2.2.1 bouyer NULL /* handle to file with attributes to */
123 1.2.2.1 bouyer );
124 1.2.2.1 bouyer if (debug_log == INVALID_HANDLE_VALUE) {
125 1.2.2.1 bouyer return (-1);
126 1.2.2.1 bouyer }
127 1.2.2.1 bouyer CloseHandle(debug_log);
128 1.2.2.1 bouyer
129 1.2.2.1 bouyer debug_log = CreateFile(
130 1.2.2.1 bouyer filename, /* file name */
131 1.2.2.1 bouyer GENERIC_WRITE, /* access (read-write) mode */
132 1.2.2.1 bouyer FILE_SHARE_WRITE,/* share mode */
133 1.2.2.1 bouyer NULL, /* pointer to security attributes */
134 1.2.2.1 bouyer CREATE_ALWAYS, /* how to create */
135 1.2.2.1 bouyer FILE_ATTRIBUTE_NORMAL, /* file attributes*/
136 1.2.2.1 bouyer NULL /* handle to file with attributes to */
137 1.2.2.1 bouyer );
138 1.2.2.1 bouyer
139 1.2.2.1 bouyer if (debug_log == INVALID_HANDLE_VALUE) {
140 1.2.2.1 bouyer return (-1);
141 1.2.2.1 bouyer }
142 1.2.2.1 bouyer
143 1.2.2.1 bouyer return (0);
144 1.2.2.1 bouyer }
145 1.2.2.1 bouyer
146 1.2.2.1 bouyer void
147 1.2.2.1 bouyer close_debug_log()
148 1.2.2.1 bouyer {
149 1.2.2.1 bouyer if (debug_log != INVALID_HANDLE_VALUE) {
150 1.2.2.1 bouyer CloseHandle(debug_log);
151 1.2.2.1 bouyer debug_log = INVALID_HANDLE_VALUE;
152 1.2.2.1 bouyer /*
153 1.2.2.1 bouyer * I hope Windows flush file buffer properly...
154 1.2.2.1 bouyer */
155 1.2.2.1 bouyer Sleep(2000);
156 1.2.2.1 bouyer }
157 1.2.2.1 bouyer }
158