* debugify.c, debugify.h: Fix for general gnu use. Remove C++
[deliverable/binutils-gdb.git] / gdb / debugify.c
1
2 /* Debug macros for developemnt.
3 Copyright 1997
4 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22 #include <stdio.h>
23 #ifdef HAVE_STDLIB_H
24 #include <stdlib.h>
25 #endif
26 #ifdef HAVE_STRING_H
27 #include <string.h>
28 #else
29 #include <strings.h>
30 #endif
31 #ifdef ANSI_PROTOTYPES
32 #include <stdarg.h>
33 #else
34 #include <varargs.h>
35 #endif
36
37
38 #define DEBUGIFY
39 #include "debugify.h"
40
41 #define REDIRECT
42
43 static FILE *fout = NULL;
44 static char fname[128];
45 static int file_cnt = 0; /* count number of open files */
46
47 void
48 puts_dbg (const char *data)
49 {
50 FILE *fdbg;
51
52 fdbg = fopen ("dbg.log", "a+");
53 if (fdbg == NULL)
54 return;
55 fprintf (fdbg, data);
56 fclose (fdbg);
57 }
58
59 /* Can't easily get the message back to gdb... write to a log instead. */
60 void
61 fputs_dbg (const char *data, FILE * fakestream)
62 {
63 #ifdef REDIRECT
64 puts_dbg (data);
65 #else /* REDIRECT */
66
67 if (fakestream == stdout || fakestream == stderr || fakestream == NULL)
68 {
69 if (fout == NULL)
70 {
71 for (file_cnt = 0; file_cnt < 20; file_cnt++)
72 {
73 sprintf (fname, "dbg%d.log", file_cnt);
74 if ((fout = fopen (fname), "r") != NULL)
75 fclose (fout);
76 else
77 break;
78 }
79 fout = fopen (fname, "w");
80 if (fout == NULL)
81 return;
82 }
83 fakestream = fout;
84 }
85 fprintf (fakestream, data);
86 fflush (fakestream);
87 #endif /* REDIRECT */
88 }
89
90 void
91 printf_dbg (const char *format,...)
92 {
93 va_list args;
94 char buf[256];
95 va_start (args, format);
96 vsprintf (buf, format, args);
97 puts_dbg (buf);
98 va_end (args);
99 }
This page took 0.032398 seconds and 5 git commands to generate.