* config/tc-sparc.c (md_show_usage): Add missing backslash at end
[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
32 #define DEBUGIFY
33 #include "debugify.h"
34
35 #define REDIRECT
36
37 static FILE *fout = NULL;
38 static char fname[128];
39 static int file_cnt = 0; /* count number of open files */
40
41 void
42 puts_dbg (data)
43 const char *data;
44 {
45 FILE *fdbg;
46
47 fdbg = fopen ("dbg.log", "a+");
48 if (fdbg == NULL)
49 return;
50 fprintf (fdbg, data);
51 fclose (fdbg);
52 }
53
54 /* Can't easily get the message back to gdb... write to a log instead. */
55 void
56 fputs_dbg (data, fakestream)
57 const char *data;
58 FILE *fakestream;
59 {
60 #ifdef REDIRECT
61 puts_dbg (data);
62 #else /* REDIRECT */
63
64 if (fakestream == stdout || fakestream == stderr || fakestream == NULL)
65 {
66 if (fout == NULL)
67 {
68 for (file_cnt = 0; file_cnt < 20; file_cnt++)
69 {
70 sprintf (fname, "dbg%d.log", file_cnt);
71 if ((fout = fopen (fname), "r") != NULL)
72 fclose (fout);
73 else
74 break;
75 }
76 fout = fopen (fname, "w");
77 if (fout == NULL)
78 return;
79 }
80 fakestream = fout;
81 }
82 fprintf (fakestream, data);
83 fflush (fakestream);
84 #endif /* REDIRECT */
85 }
86
87 void
88 #ifdef ANSI_PROTOTYPES
89 printf_dbg (const char *format,...)
90 #else
91 printf_dbg (va_alist)
92 va_dcl
93 #endif
94 {
95 va_list args;
96 char buf[256];
97 #ifdef ANSI_PROTOTYPES
98 va_start (args, format);
99 #else
100 char *format;
101
102 va_start (args);
103 format = va_arg (args, char *);
104 #endif
105 vsprintf (buf, format, args);
106 puts_dbg (buf);
107 va_end (args);
108 }
This page took 0.031417 seconds and 4 git commands to generate.