1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
#define import_spp
#include <iraf.h>
/*
* ZZPSTR.C -- Support for debugging SPP programs.
*
* zzpstr (s1, s2) # Write a debug message to the process stderr
* zzlstr (s1, s2) # Write a debug message to /tmp/k.log
* spp_printstr (s) # GDB support function
* spp_printmemc (memc_p) # GDB support function
*
* The procedures zzpstr and zzlstr are meant to be called from within
* compiled SPP code to write debug messages to either the process stderr
* or to a log file. This is different than writing to SPP STDERR since
* the latter is a pseudofile (it gets sent to the CL before being written
* out). In other words zzpstr/zzlstr are low level debug functions,
* comparable to a host fprintf.
*
* spp_printstr and spp_printmemc are called from a debugger (GDB) to
* print char strings. spp_printstr prints a char variable as an EOS
* terminated string. spp_printmemc does the same thing, but takes a Memc
* pointer variable as input.
*
* The following commands can be added to your .gdbinit file to make it
* easier to use these functions:
*
* define ps
* call spp_printstr ($arg0)
* end
*
* define pc
* call spp_printmemc ($arg0)
* end
*
* Then you can type e.g., "ps fname" to print char variable fname,
* or "pc ip" to print the string pointed to by SPP Memc pointer "ip".
* Both of these functions will print tabs and newlines as \t and \n,
* and other control codes as \ooo where ooo is the octal value of the
* character.
*/
#define LOGFILE "/tmp/k.log"
void spp_printmemc (long memc_ptr);
void spp_printstr (XCHAR *s);
/* SPP_DEBUG -- Dummy function called to link the SPP debug functions into
* a program.
*/
int spp_debug (void) { return (0); }
/* ZZPSTR -- Write SPP text data directly to the host stderr. Up to two
* strings may be ouptut. Either may be the null pointer to disable.
* A newline is added at the end if not present in the last string.
*/
int
zzpstr_ (XCHAR *s1, XCHAR *s2)
{
register XCHAR *s, *ip;
register char *op;
char buf[4096];
int lastch = 0;
if ( (s = s1) ) {
for (ip=s, op=buf; (*op = *ip++); op++)
;
lastch = *(op-1);
write (2, buf, op-buf);
}
if ( (s = s2) ) {
for (ip=s, op=buf; (*op = *ip++); op++)
;
lastch = *(op-1);
write (2, buf, op-buf);
}
if (lastch != '\n')
write (2, "\n", 1);
return (XOK);
}
/* ZZLSTR -- Write SPP text data to a log file.
*/
int
zzlstr_ (XCHAR *s1, XCHAR *s2)
{
register XCHAR *s, *ip;
register char *op;
char buf[4096];
int lastch = 0;
int status = 0, fd;
if ((fd = open (LOGFILE, O_CREAT|O_WRONLY|O_APPEND, 0644)) < 0)
return (fd);
if ( (s = s1) ) {
for (ip=s, op=buf; (*op = *ip++); op++)
;
lastch = *(op-1);
status = write (fd, buf, op-buf);
}
if ( (s = s2) ) {
for (ip=s, op=buf; (*op = *ip++); op++)
;
lastch = *(op-1);
status = write (fd, buf, op-buf);
}
if (lastch != '\n')
status = write (fd, "\n", 1);
status = close (fd);
return (status);
}
/* SPP_PRINTSTR -- GDB callable debug function to print an EOS terminated SPP
* string passed as a char array.
*/
void
spp_printstr (XCHAR *s)
{
register XCHAR *ip;
register char *op, *otop;
static char obuf[1024];
int ch;
for (ip=s+1, op=obuf, otop=obuf+1020; (ch = *ip); ip++) {
if (!isprint (ch)) {
if (ch == '\t') {
*op++ = '\\';
*op++ = 't';
} else if (ch == '\n') {
*op++ = '\\';
*op++ = 'n';
} else {
*op++ = '\\';
*op++ = ((ch >> 6) & 07) + '0';
*op++ = ((ch >> 3) & 07) + '0';
*op++ = ( ch & 07) + '0';
}
} else
*op++ = ch;
if (op >= otop)
break;
}
*op++ = '\0';
printf ("%s\n", obuf);
fflush (stdout);
}
/* SPP_PRINTMEMC -- GDB callable debug function to print an EOS terminated SPP
* string passed as a pointer to char.
*/
void
spp_printmemc (long memc_ptr)
{
XCHAR *str = (XCHAR *) ((memc_ptr - 1) * 2 - 2);
spp_printstr (str);
}
|