diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-08-04 16:24:49 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-08-04 16:24:49 +0000 |
commit | a8952b3c7b1067f304e24237bd035263e6b62ed9 (patch) | |
tree | 5b9bbc59f59f38101e2bcd7a7d10cbd89a4e81ed /src/common | |
parent | 65ee11a599f904bdece45c55dd41eb2633da575f (diff) | |
download | hercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.tar.gz hercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.tar.bz2 hercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.tar.xz hercules-a8952b3c7b1067f304e24237bd035263e6b62ed9.zip |
Some all-around code reformatting/cleaning
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10947 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/utils.c | 39 | ||||
-rw-r--r-- | src/common/utils.h | 8 |
2 files changed, 22 insertions, 25 deletions
diff --git a/src/common/utils.c b/src/common/utils.c index 00b6dc290..15d1d2e68 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -20,41 +20,40 @@ #include <sys/stat.h> #endif -#ifdef UTIL_DUMP -void dump(const unsigned char* buffer, int num) +// generate a hex dump of the first 'length' bytes of 'buffer' +void dump(FILE* fp, const unsigned char* buffer, int length) { - int icnt, jcnt; + int i, j; - printf(" Hex ASCII\n"); - printf(" ----------------------------------------------- ----------------"); + fprintf(fp, " Hex ASCII\n"); + fprintf(fp, " ----------------------------------------------- ----------------"); - for (icnt = 0; icnt < num; icnt += 16) + for (i = 0; i < length; i += 16) { - printf("\n%p ", &buffer[icnt]); - for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) + fprintf(fp, "\n%p ", &buffer[i]); + for (j = i; j < i + 16; ++j) { - if (jcnt < num) - printf("%02hX ", buffer[jcnt]); + if (j < length) + fprintf(fp, "%02hX ", buffer[j]); else - printf(" "); + fprintf(fp, " "); } - printf(" | "); + fprintf(fp, " | "); - for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) + for (j = i; j < i + 16; ++j) { - if (jcnt < num) { - if (buffer[jcnt] > 31 && buffer[jcnt] < 127) - printf("%c", buffer[jcnt]); + if (j < length) { + if (buffer[j] > 31 && buffer[j] < 127) + fprintf(fp, "%c", buffer[j]); else - printf("."); + fprintf(fp, "."); } else - printf(" "); + fprintf(fp, " "); } } - printf("\n"); + fprintf(fp, "\n"); } -#endif // Allocate a StringBuf [MouseJstr] struct StringBuf * StringBuf_Malloc() diff --git a/src/common/utils.h b/src/common/utils.h index 66ce04c99..898a63ab4 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -4,13 +4,11 @@ #ifndef _UTILS_H_ #define _UTILS_H_ +#include <stdio.h> #include <stdarg.h> -// Function that dumps the hex of the first num bytes of the buffer to the screen -//#define UTIL_DUMP -#ifdef UTIL_DUMP -void dump(const unsigned char* buffer, int num); -#endif +// generate a hex dump of the first 'length' bytes of 'buffer' +void dump(FILE* fp, const unsigned char* buffer, int length); struct StringBuf { char *buf_; |