- Timestamp:
- Jan 25, 2007, 11:34:28 PM (14 years ago)
- Location:
- zzuf/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/debug.c
r1689 r1718 35 35 #include "libzzuf.h" 36 36 37 extern int _zz_ hasdebug;37 extern int _zz_debugfd; 38 38 39 39 #define WRITE_INT(fd, i, base) \ … … 58 58 #endif 59 59 va_list args; 60 int saved_errno , fd = DEBUG_FILENO;60 int saved_errno; 61 61 62 if( !_zz_hasdebug)62 if(_zz_debugfd < 0) 63 63 return; 64 64 … … 66 66 va_start(args, format); 67 67 #ifdef SAFE_FUNCTION 68 write( fd, "** zzuf debug ** ", 17);68 write(_zz_debugfd, "** zzuf debug ** ", 17); 69 69 for(f = format; *f; f++) 70 70 { 71 71 if(*f != '%') 72 72 { 73 write( fd, f, 1);73 write(_zz_debugfd, f, 1); 74 74 continue; 75 75 } … … 83 83 char i = (char)(unsigned char)va_arg(args, int); 84 84 if(i >= 0x20 && i < 0x7f) 85 write( fd, &i, 1);85 write(_zz_debugfd, &i, 1); 86 86 else if(i == '\n') 87 write( fd, "\\n", 2);87 write(_zz_debugfd, "\\n", 2); 88 88 else if(i == '\t') 89 write( fd, "\\t", 2);89 write(_zz_debugfd, "\\t", 2); 90 90 else if(i == '\r') 91 write( fd, "\\r", 2);91 write(_zz_debugfd, "\\r", 2); 92 92 else 93 93 { 94 write( fd, "\\x", 2);95 write( fd, hex2char + ((i & 0xf0) >> 4), 1);96 write( fd, hex2char + (i & 0x0f), 1);94 write(_zz_debugfd, "\\x", 2); 95 write(_zz_debugfd, hex2char + ((i & 0xf0) >> 4), 1); 96 write(_zz_debugfd, hex2char + (i & 0x0f), 1); 97 97 } 98 98 } … … 100 100 { 101 101 int i = va_arg(args, int); 102 WRITE_INT( fd, i, 10);102 WRITE_INT(_zz_debugfd, i, 10); 103 103 } 104 104 else if(*f == 'x') 105 105 { 106 106 int i = va_arg(args, int); 107 WRITE_INT( fd, i, 16);107 WRITE_INT(_zz_debugfd, i, 16); 108 108 } 109 109 else if(f[0] == 'l' && f[1] == 'i') 110 110 { 111 111 long int i = va_arg(args, long int); 112 WRITE_INT( fd, i, 10);112 WRITE_INT(_zz_debugfd, i, 10); 113 113 f++; 114 114 } … … 116 116 { 117 117 long long int i = va_arg(args, long long int); 118 WRITE_INT( fd, i, 10);118 WRITE_INT(_zz_debugfd, i, 10); 119 119 f += 2; 120 120 } … … 123 123 uintptr_t i = va_arg(args, uintptr_t); 124 124 if(!i) 125 write( fd, "NULL", 5);125 write(_zz_debugfd, "NULL", 5); 126 126 else 127 127 { 128 write( fd, "0x", 2);129 WRITE_INT( fd, i, 16);128 write(_zz_debugfd, "0x", 2); 129 WRITE_INT(_zz_debugfd, i, 16); 130 130 } 131 131 } … … 134 134 char *s = va_arg(args, char *); 135 135 if(!s) 136 write( fd, "(nil)", 5);136 write(_zz_debugfd, "(nil)", 5); 137 137 else 138 138 { … … 140 140 while(s[l]) 141 141 l++; 142 write( fd, s, l);142 write(_zz_debugfd, s, l); 143 143 } 144 144 } … … 146 146 { 147 147 int i = va_arg(args, int); 148 write( fd, hex2char + ((i & 0xf0) >> 4), 1);149 write( fd, hex2char + (i & 0x0f), 1);148 write(_zz_debugfd, hex2char + ((i & 0xf0) >> 4), 1); 149 write(_zz_debugfd, hex2char + (i & 0x0f), 1); 150 150 f += 2; 151 151 } 152 152 else 153 153 { 154 write( fd, f - 1, 2);154 write(_zz_debugfd, f - 1, 2); 155 155 } 156 156 } 157 write( fd, "\n", 1);157 write(_zz_debugfd, "\n", 1); 158 158 #else 159 159 fprintf(stderr, "** zzuf debug ** "); -
zzuf/trunk/src/lib-fd.c
r1699 r1718 451 451 452 452 /* Hey, it’s our debug channel! Silently pretend we closed it. */ 453 if(fd == DEBUG_FILENO)453 if(fd == _zz_debugfd) 454 454 return 0; 455 455 -
zzuf/trunk/src/libzzuf.c
r1717 r1718 52 52 /* Global variables */ 53 53 int _zz_ready = 0; 54 int _zz_ hasdebug = 0;54 int _zz_debugfd = -1; 55 55 int _zz_signal = 0; 56 56 int _zz_memory = 0; … … 66 66 67 67 tmp = getenv("ZZUF_DEBUG"); 68 if(tmp && *tmp == '1')69 _zz_ hasdebug = 1;68 if(tmp) 69 _zz_debugfd = atoi(tmp); 70 70 71 71 tmp = getenv("ZZUF_SEED"); -
zzuf/trunk/src/libzzuf.h
r1714 r1718 16 16 * libzzuf.h: preloaded wrapper library 17 17 */ 18 19 /* We use file descriptor 17 as the debug channel */20 #define DEBUG_FILENO 1721 18 22 19 /* We arbitrarily split files into 1024-byte chunks. Each chunk has an … … 48 45 extern int _zz_ready; 49 46 extern int _zz_disabled; 50 extern int _zz_ hasdebug;47 extern int _zz_debugfd; 51 48 extern int _zz_signal; 52 49 extern int _zz_memory; -
zzuf/trunk/src/zzuf.c
r1710 r1718 65 65 # define SIGKILL 9 66 66 #endif 67 68 /* We use file descriptor 17 as the debug channel */ 69 #define DEBUG_FILENO 17 70 #define DEBUG_FILENO_STR "17" 67 71 68 72 static void loop_stdin(struct opts *); … … 200 204 break; 201 205 case 'd': /* --debug */ 202 setenv("ZZUF_DEBUG", "1", 1);206 setenv("ZZUF_DEBUG", DEBUG_FILENO_STR, 1); 203 207 break; 204 208 case 'D': /* --delay */
Note: See TracChangeset
for help on using the changeset viewer.