2 * reactos spinlock emulation of libcaptive
3 * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "reactos/internal/kd.h" /* self */
23 #include "captive/unicode.h" /* for captive_validate_AnsiString() */
24 #include <glib/gtypes.h>
25 #include <glib/gmessages.h>
26 #include <glib/galloca.h>
27 #include <glib/gstring.h>
28 #include <glib/gmem.h>
34 * #BOOLEAN variable defined to %FALSE by libcaptive.
35 * Currently just enables some debug output in
36 * reactos/ntoskrnl/ldr/loader.c
38 BOOLEAN /* __declspec(dllexport) */ KdDebuggerEnabled=FALSE;
43 * Defined to %KD_DEBUG_DISABLED by default in reactos.
44 * Currently just enables some debug output in
45 * reactos/ntoskrnl/ldr/loader.c
47 ULONG KdDebugState=KD_DEBUG_GDB;
50 /* storage for the trailing string part without newline */
51 static GString *KdpPrintString_buffer;
55 * @String: String text to print. Buffer is flushed only when newline seen.
57 * Prints the specified text string to the console. libcaptive
58 * accepts any newline characters as valid and autonewlines the text
61 ULONG KdpPrintString(PANSI_STRING String)
66 g_return_val_if_fail(captive_validate_AnsiString(String),0);
68 out_base=g_alloca(((size_t)String->Length)+1);
70 for (in=String->Buffer;*in;in++) {
71 if (*in=='\r' && in[1]=='\n')
73 if (*in=='\r' || *in=='\n')
80 /* Print all completed lines */
81 if ((out=strrchr(out_base,'\n'))) {
84 *out='\0'; /* cut off the rest of string */
86 if (!KdpPrintString_buffer)
89 previous=g_string_free(KdpPrintString_buffer,
90 FALSE); /* free_segment */
91 KdpPrintString_buffer=NULL;
93 g_message("KdpPrintString: %s%s", /* newline is appended by g_message() */
94 (!previous ? "" : previous),
99 out_base=out+1; /* leave the rest of string (if any) */
102 /* store/append the remaining rest of string w/o newline */
104 KdpPrintString_buffer=(!KdpPrintString_buffer ? g_string_new(out_base)
105 : g_string_append(KdpPrintString_buffer,out_base));
107 return (ULONG)String->Length;