1 /*	$NetBSD: preference.c,v 1.4 2000/08/29 15:10:20 takemura Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999 Shin Takemura.
5  * All rights reserved.
6  *
7  * This software is part of the PocketBSD.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the PocketBSD project
20  *	and its contributors.
21  * 4. Neither the name of the project nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  */
38 #include <pbsdboot.h>
39 #include <commctrl.h>
40 #include <res/resource.h>
41 
42 
43 struct preference_s pref;
44 TCHAR* where_pref_load_from = NULL;
45 static TCHAR filenamebuf[1024];
46 
47 
48 #define SETTING_IDX 1
49 #define FB_TYPE 2
50 #define FB_WIDTH 3
51 #define FB_HEIGHT 4
52 #define FB_LINEBYTES 5
53 #define BOOT_TIME 6
54 #define FB_ADDR 7
55 #define PLATID_CPU 8
56 #define PLATID_MACHINE 9
57 #define SETTING_NAME 10
58 #define KERNEL_NAME 11
59 #define OPTIONS 12
60 #define CHECK_LAST_CHANCE 13
61 #define LOAD_DEBUG_INFO 14
62 #define SERIAL_PORT 15
63 #define REVERSE_VIDEO 16
64 #define AUTOBOOT 17
65 
66 #define NOFID 18
67 
68 
69 TCHAR *id_table[] = {
70 0,
71 TEXT("setting_idx"),
72 TEXT("fb_type"),
73 TEXT("fb_width"),
74 TEXT("fb_height"),
75 TEXT("fb_linebytes"),
76 TEXT("boot_time"),
77 TEXT("fb_addr"),
78 TEXT("platid_cpu"),
79 TEXT("platid_machine"),
80 TEXT("setting_name"),
81 TEXT("kernel_name"),
82 TEXT("options"),
83 TEXT("check_last_chance"),
84 TEXT("load_debug_info"),
85 TEXT("serial_port"),
86 TEXT("reverse_video"),
87 TEXT("autoboot"),
88 };
89 
90 
91 
92 void
93 pref_init(struct preference_s* pref)
94 {
95 	memset(pref, 0, sizeof(*pref));
96 }
97 
98 
99 /*
100  argument file is handle that was already opened .
101  if read is faile , this function will "not" close this handle .
102  return 0 if error . if end of file , return -1
103 */
104 int read1byte(HANDLE file,char *c){
105 	DWORD n;
106 	if(!ReadFile(file,c,sizeof(char),&n,NULL)){
107 		msg_printf(MSG_ERROR, TEXT("pref_load()"),
108 			   TEXT("ReadFile(): error=%d"), GetLastError());
109 		debug_printf(TEXT("ReadFile(): error=%d\r"), GetLastError());
110 
111 		return 0;
112 	}
113 	if (n != sizeof(char)) {
114 		if( n == 0){
115 			return (-1);
116 		}
117 		msg_printf(MSG_ERROR, TEXT("pref_load()"),
118 			   TEXT("ReadFile(): read %d bytes"), n);
119 		debug_printf(TEXT("ReadFile(): read %d bytes\r"), n);
120 
121 		return 0;
122 	}
123 	return 1;
124 }
125 
126 /*
127  argument file is handle that was already opened .
128  if write is faile, this function will "not" close this handle .
129  return 0 if error . write one line of string .
130 */
131 int write1string(HANDLE file,char *string){
132 	DWORD n;
133 	if(!WriteFile(file,string,sizeof(char)*strlen(string),&n,NULL)){
134 	    msg_printf(MSG_ERROR, TEXT("pref_write()"),
135 			   TEXT("WriteFile(): error=%d"), GetLastError());
136 		debug_printf(TEXT("WriteFile(): error=%d\n"), GetLastError());
137 
138 		return 0;
139 	}
140 	if (n != sizeof(char)*strlen(string)) {
141 		msg_printf(MSG_ERROR, TEXT("pref_write()"),
142 			   TEXT("WriteFile(): write %d bytes"), n);
143 		debug_printf(TEXT("WriteFile(): write %d bytes\n"), n);
144 
145 		return (0);
146 	}
147 
148 	return 1;
149 }
150 
151 void
152 pref_dump(struct preference_s* pref)
153 {
154 	debug_printf(TEXT("    kernel_name: %s\n"), pref->kernel_name);
155 	debug_printf(TEXT("        options: %s\n"), pref->options);
156 	debug_printf(TEXT("  user def name: %s\n"), pref->setting_name);
157 	debug_printf(TEXT("  setting index: %d\n"), pref->setting_idx);
158 	debug_printf(TEXT("           type: %d\n"), pref->fb_type);
159 	debug_printf(TEXT("          width: %d\n"), pref->fb_width);
160 	debug_printf(TEXT("         height: %d\n"), pref->fb_height);
161 	debug_printf(TEXT("     bytes/line: %d\n"), pref->fb_linebytes);
162 	debug_printf(TEXT("           addr: %d\n"), pref->fb_addr);
163 	debug_printf(TEXT("            cpu: %08lx\n"), pref->platid_cpu);
164 	debug_printf(TEXT("        machine: %08lx\n"), pref->platid_machine);
165 	debug_printf(TEXT("    last chance: %S\n"), pref->check_last_chance ?
166 		     "TRUE" : "FALSE");
167 	debug_printf(TEXT("load debug info: %S\n"), pref->load_debug_info ?
168 		     "TRUE" : "FALSE");
169 	debug_printf(TEXT("    serial port: %S\n"), pref->serial_port ?
170 		     "ON" : "OFF");
171 }
172 
173 
174 
175 /* To Do . modify this function*/
176 int
177 pref_read(TCHAR* filename, struct preference_s* pref)
178 {
179 	HANDLE file;
180 	DWORD length;
181 	static struct preference_s buf;
182 	char tempbuf[1024];
183 	TCHAR unidata[1024];
184 	TCHAR identif[1024];
185 	char c;
186 	int i,flag,d;
187 	int result;/* count of loading pref item */
188 
189 
190 	file = CreateFile(
191 		filename,      	/* file name */
192 		GENERIC_READ,	/* access (read-write) mode */
193 		FILE_SHARE_READ,/* share mode */
194 		NULL,		/* pointer to security attributes */
195 		OPEN_EXISTING,	/* how to create */
196 		FILE_ATTRIBUTE_NORMAL,	/* file attributes*/
197 		NULL		/* handle to file with attributes to */
198 		);
199 
200 	if (file == INVALID_HANDLE_VALUE) {
201 		return (-1);
202 	}
203 
204 
205 
206 
207 	flag = 1;
208 	result = 0;
209 	while(flag){
210 		i = 0;
211 		d = read1byte(file,&c);
212 		if( d <=0){
213 			if(d == -1){
214 				flag = 0;
215 				break;
216 			}
217 			else
218 			{
219 				CloseHandle(file);
220 				return (-1);
221 			}
222 		}
223 
224 
225 		while(c != ':' && c != '\r' && c!= '\n'){
226 			tempbuf[i] = c;
227 			d = read1byte(file,&c);
228 			if( d <=0){
229 				if(d == -1){
230 					flag = 0;
231 					break;
232 				}
233 				else
234 				{
235 					CloseHandle(file);
236 					return (-1);
237 				}
238 			}
239 			i++;
240 		}
241 		if(c == ':'){
242 
243 
244 			tempbuf[i] = '\0';
245 			length = MultiByteToWideChar(CP_ACP,0,tempbuf,-1,identif,0);
246 			MultiByteToWideChar(CP_ACP,0,tempbuf,-1,identif,length);
247 
248 			i = 0;
249 			d = read1byte(file,&c);
250 			flag = 1;
251 			while(c != '\r' && c != '\n' && flag){/* get unidata */
252 				if(d <= 0){
253 					if(d == -1){
254 						flag = 0;/* though needless ... */
255 						break;
256 					}
257 					else{
258 						CloseHandle(file);
259 						return -1;
260 					}
261 				}
262 				tempbuf[i] = c;
263 				d = read1byte(file,&c);
264 				i++;
265 
266 			}
267 			if(c == '\r'){/* skip \n */
268 				read1byte(file,&c);
269 			}
270 			tempbuf[i] = '\0';
271 			length = MultiByteToWideChar(CP_ACP,0,tempbuf,-1,unidata,0);
272 			MultiByteToWideChar(CP_ACP,0,tempbuf,-1,unidata,length);
273 
274 			for(i = 1; i < NOFID;i++){
275 				if(wcscmp(identif,id_table[i])==0){
276 					break;
277 				}
278 			}
279 			switch(i){
280 			case SETTING_IDX:
281 				d = _wtoi(unidata);
282 				buf.setting_idx = d;
283 				result++;
284 				break;
285 			case FB_TYPE:
286 				d = _wtoi(unidata);
287 				buf.fb_type = d;
288 				result++;
289 				break;
290 			case FB_WIDTH:
291 				d = _wtoi(unidata);
292 				buf.fb_width = d;
293 				result++;
294 				break;
295 			case FB_HEIGHT:
296 				d = _wtoi(unidata);
297 				buf.fb_height = d;
298 				result++;
299 				break;
300 			case FB_LINEBYTES:
301 				d = _wtoi(unidata);
302 				buf.fb_linebytes = d;
303 				result++;
304 				break;
305 			case BOOT_TIME:
306 				d = _wtoi(unidata);
307 				buf.boot_time = d;
308 				result++;
309 				break;
310 			case FB_ADDR:
311 				d = _wtoi(unidata);
312 				buf.fb_addr = d;
313 				result++;
314 				break;
315 			case PLATID_CPU:
316 				d = _wtoi(unidata);
317 				buf.platid_cpu = d;
318 				result++;
319 				break;
320 			case PLATID_MACHINE:
321 				d = _wtoi(unidata);
322 				buf.platid_machine = d;
323 				result++;
324 				break;
325 			case SETTING_NAME:
326 				wcscpy(buf.setting_name,unidata);
327 				result++;
328 				break;
329 			case KERNEL_NAME:
330 				wcscpy(buf.kernel_name,unidata);
331 				result++;
332 				break;
333 			case OPTIONS:
334 				wcscpy(buf.options,unidata);
335 				result++;
336 				break;
337 			case CHECK_LAST_CHANCE:
338 				if(wcscmp(unidata,TEXT("t")) == 0){
339 					buf.check_last_chance = TRUE;
340 				}
341 				else{
342 					buf.check_last_chance = FALSE;
343 				}
344 				result++;
345 				break;
346 			case LOAD_DEBUG_INFO:
347 				if(wcscmp(unidata,TEXT("t")) == 0){
348 					buf.load_debug_info = TRUE;
349 				}
350 				else{
351 					buf.load_debug_info = FALSE;
352 				}
353 				result++;
354 				break;
355 			case SERIAL_PORT:
356 				if(wcscmp(unidata,TEXT("t")) == 0){
357 					buf.serial_port = TRUE;
358 				}
359 				else{
360 					buf.serial_port = FALSE;
361 				}
362 				result++;
363 				break;
364 			case REVERSE_VIDEO:
365 				if(wcscmp(unidata,TEXT("t")) == 0){
366 					buf.reverse_video = TRUE;
367 				}
368 				else{
369 					buf.reverse_video = FALSE;
370 				}
371 				result++;
372 				break;
373 			case AUTOBOOT:
374 				if(wcscmp(unidata,TEXT("t")) == 0){
375 					buf.autoboot = TRUE;
376 				}
377 				else{
378 					buf.autoboot = FALSE;
379 				}
380 				result++;
381 				break;
382 			default:
383 				break;
384 			}
385 		}
386 	}
387 
388 
389 
390 
391 	CloseHandle(file);
392 
393 #if 0
394 	/* shortage of item is not error */
395 	if(result != NOFID -1){
396 		return -1;/* data is shortage */
397 	}
398 #endif
399 
400 	*pref = buf;
401 
402 	return (0);
403 }
404 
405 
406 
407 int
408 pref_load(struct path_s load_path[], int pathlen)
409 {
410 	int i;
411 
412 	where_pref_load_from = NULL;
413 	for (i = 0; i < pathlen; i++) {
414 		wsprintf(filenamebuf, TEXT("%s%s"),
415 			 load_path[i].name, PREFNAME);
416 		debug_printf(TEXT("pref_load: try to '%s'\n"), filenamebuf);
417 
418 		if (pref_read(filenamebuf, &pref) == 0) {
419 			debug_printf(TEXT("pref_load: succeded, '%s'.\n"),
420 				     filenamebuf);
421 			pref_dump(&pref);
422 			where_pref_load_from = filenamebuf;
423 			return (0);
424 		}
425 	}
426 
427 	return (-1);
428 }
429 
430 
431 int
432 pref_save(struct path_s load_path[], int pathlen)
433 {
434 	int i;
435 
436 	if (where_pref_load_from) {
437 		if (pref_write(where_pref_load_from, &pref) != 0) {
438 			msg_printf(MSG_ERROR, TEXT("Error()"),
439 			    TEXT("Can't write %s"), where_pref_load_from);
440 			return -1;
441 		}
442 		return 0;
443 	}
444 	for (i = 0; i < pathlen; i++) {
445 		if (!(load_path[i].flags & PATH_SAVE)) {
446 			continue;
447 		}
448 		wsprintf(filenamebuf, TEXT("%s%s"),
449 		    load_path[i].name, PREFNAME);
450 		debug_printf(TEXT("pref_save: try to '%s'\n"), filenamebuf);
451 		if (pref_write(filenamebuf, &pref) == 0) {
452 			debug_printf(TEXT("pref_write: succeded, '%s'.\n"),
453 			    filenamebuf);
454 			return (0);
455 		}
456 	}
457 
458 	msg_printf(MSG_ERROR, TEXT("Error()"),
459 	    TEXT("Can't write %s"), PREFNAME);
460 
461 	return (-1);
462 }
463 
464 
465 int
466 pref_write(TCHAR* filename, struct preference_s* buf)
467 {
468 	HANDLE file;
469 	char tempbuf[1024];
470 	TCHAR unibuf[1024];
471 	DWORD length;
472 
473 
474 	debug_printf(TEXT("pref_write('%s').\n"), filename);
475 	pref_dump(&pref);
476 
477        	file = CreateFile(
478 	       	filename,      	/* file name */
479 	       	GENERIC_WRITE,	/* access (read-write) mode */
480 	       	FILE_SHARE_WRITE,/* share mode */
481 	       	NULL,		/* pointer to security attributes */
482 	       	CREATE_ALWAYS,	/* how to create */
483 	       	FILE_ATTRIBUTE_NORMAL,	/* file attributes*/
484 	       	NULL		/* handle to file with attributes to */
485 	       	);
486 
487 	if (file == INVALID_HANDLE_VALUE) {
488 		debug_printf(TEXT("CreateFile(): error=%d\n"), GetLastError());
489 		return (-1);
490 	}
491 
492 
493 	wsprintf(unibuf,TEXT("setting_idx:%d\r\n"),buf->setting_idx);
494 	debug_printf(TEXT("setting_idx,tempbuf=%s"),unibuf);
495 		length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
496 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
497 	if(!write1string(file,tempbuf)){
498 		CloseHandle(file);
499 		return (-1);
500 	}
501 
502 
503 	wsprintf(unibuf,TEXT("fb_type:%d\r\n"),buf->fb_type);
504 	debug_printf(TEXT("fb_type,tempbuf=%s,"),unibuf);
505 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
506 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
507 	if(!write1string(file,tempbuf)){
508 		CloseHandle(file);
509 		return (-1);
510 	}
511 
512 
513 	wsprintf(unibuf,TEXT("fb_width:%d\r\n"),buf->fb_width);
514 	debug_printf(TEXT("fb_width,tempbuf=%s"),unibuf);
515 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
516 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
517 	if(!write1string(file,tempbuf)){
518 		CloseHandle(file);
519 		return (-1);
520 	}
521 
522 
523 
524 	wsprintf(unibuf,TEXT("fb_height:%d\r\n"),buf->fb_height);
525 	debug_printf(TEXT("fb_height,tempbuf=%s"),unibuf);
526 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
527 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
528 	if(!write1string(file,tempbuf)){
529 		CloseHandle(file);
530 		return (-1);
531 	}
532 
533 
534 
535 	wsprintf(unibuf,TEXT("fb_linebytes:%d\r\n"),buf->fb_linebytes);
536 	debug_printf(TEXT("fb_linebytes,tempbuf=%s"),unibuf);
537 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
538 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
539 	if(!write1string(file,tempbuf)){
540 		CloseHandle(file);
541 		return (-1);
542 	}
543 
544 
545 	wsprintf(unibuf,TEXT("boot_time:%d\r\n"),buf->boot_time);
546 	debug_printf(TEXT("boot_time,tempbuf=%s\n"),unibuf);
547 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
548 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
549 	if(!write1string(file,tempbuf)){
550 		CloseHandle(file);
551 		return (-1);
552 	}
553 
554 	wsprintf(unibuf,TEXT("fb_addr:%d\r\n"),buf->fb_addr);
555 	debug_printf(TEXT("fb_addr,tempbuf=%s"),unibuf);
556 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
557 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
558 	if(!write1string(file,tempbuf)){
559 		CloseHandle(file);
560 		return (-1);
561 	}
562 
563 
564 
565     wsprintf(unibuf,TEXT("platid_cpu:%d\r\n"),buf->platid_cpu);
566 	debug_printf(TEXT("platid_cpu,tempbuf=%s"),unibuf);
567 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
568 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
569 	if(!write1string(file,tempbuf)){
570 		CloseHandle(file);
571 		return (-1);
572 	}
573 
574 
575 	wsprintf(unibuf,TEXT("platid_machine:%d\r\n"),buf->platid_machine);
576 	debug_printf(TEXT("platid_machine,tempbuf=%s"),unibuf);
577 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
578 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
579 	if(!write1string(file,tempbuf)){
580 		CloseHandle(file);
581 		return (-1);
582 	}
583 
584 
585 
586 	wsprintf(unibuf,TEXT("setting_name:%s\r\n"),buf->setting_name);
587 	debug_printf(TEXT("setting_name,unibuf=%s,wcslen=%d"),unibuf,
588 		wcslen(unibuf));
589 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
590 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
591 
592 	if(!write1string(file,tempbuf)){
593 		CloseHandle(file);
594 		return (-1);
595 	}
596 
597 
598 
599 	wsprintf(unibuf,TEXT("kernel_name:%s\r\n"),buf->kernel_name);
600 	debug_printf(TEXT("kernel_name,unibuf=%s,wcslen=%d"),unibuf,
601 		wcslen(unibuf));
602 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
603 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
604 	if(!write1string(file,tempbuf)){
605 		CloseHandle(file);
606 		return (-1);
607 	}
608 
609 
610 
611 	wsprintf(unibuf,TEXT("options:%s\r\n"),buf->options);
612 	debug_printf(TEXT("options,unibuf=%s,wcslen=%d"),unibuf,
613 		wcslen(unibuf));
614 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
615 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
616 	if(!write1string(file,tempbuf)){
617 		CloseHandle(file);
618 		return (-1);
619 	}
620 
621 
622 	if(buf->check_last_chance){
623 		wsprintf(unibuf,TEXT("check_last_chance:t\r\n"));
624 	}
625 	else{
626 	wsprintf(unibuf,TEXT("check_last_chance:n\r\n"));
627 	}
628 
629 
630 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
631 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
632 	if(!write1string(file,tempbuf)){
633 		CloseHandle(file);
634 		return (-1);
635 	}
636 
637 
638 
639 
640 	if(buf->load_debug_info){
641 		wsprintf(unibuf,TEXT("load_debug_info:t\r\n"));
642 	}
643 	else{
644 	wsprintf(unibuf,TEXT("load_debug_info:n\r\n"));
645 	}
646 
647 
648 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
649 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
650 
651 
652 	if(!write1string(file,tempbuf)){
653 		CloseHandle(file);
654 		return (-1);
655 	}
656 
657 
658 
659 	if(buf->serial_port){
660 		wsprintf(unibuf,TEXT("serial_port:t\r\n"));
661 	}
662 	else{
663 	wsprintf(unibuf,TEXT("serial_port:n\r\n"));
664 	}
665 
666 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
667 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
668 
669 	if(!write1string(file,tempbuf)){
670 		CloseHandle(file);
671 		return (-1);
672 	}
673 
674 
675 
676 	if(buf->reverse_video){
677 		wsprintf(unibuf,TEXT("reverse_video:t\r\n"));
678 	}
679 	else{
680 	wsprintf(unibuf,TEXT("reverse_video:n\r\n"));
681 	}
682 
683 length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
684 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
685 	if(!write1string(file,tempbuf)){
686 		CloseHandle(file);
687 		return (-1);
688 	}
689 
690 	if(buf->autoboot){
691 		wsprintf(unibuf,TEXT("autoboot:t\r\n"));
692 	}
693 	else{
694 		wsprintf(unibuf,TEXT("autoboot:n\r\n"));
695 	}
696 
697 	length = WideCharToMultiByte(CP_ACP,0,unibuf,-1,NULL,0,NULL,NULL);
698 	WideCharToMultiByte(CP_ACP,0,unibuf,-1,tempbuf,length,NULL,NULL);
699 	if(!write1string(file,tempbuf)){
700 		CloseHandle(file);
701 		return (-1);
702 	}
703 
704 	CloseHandle(file);
705 	return (0);
706 }
707 
708