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