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