|
From: <le...@pr...> - 2005-05-02 04:48:23
|
Update of /cvsroot/meshdb/src/mailt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10859 Modified Files: Tag: leonard-dev swap.c Log Message: refactor checkmail0 Index: swap.c =================================================================== RCS file: /cvsroot/meshdb/src/mailt/Attic/swap.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- swap.c 2 May 2005 04:44:18 -0000 1.1.2.1 +++ swap.c 2 May 2005 04:48:14 -0000 1.1.2.2 @@ -1,5 +1,9 @@ /* $Id$ */ +/* + * Create a mail index that is a byte-swapped version of another + */ + #if defined(HAVE_CONFIG_H) # include "config.h" #endif @@ -19,8 +23,7 @@ } /* Functions to do byte swapping */ - -#define copydecl(name, halfname, type, halftype) \ +#define copyimpl(name, halfname, type, halftype) \ static void \ name(dst, src) \ type *dst; \ @@ -33,14 +36,14 @@ } #define uint8copy(dst, src) *(dst) = *(src) -copydecl(uint16copy, uint8copy, uint16_t, uint8_t) -copydecl(uint32copy, uint16copy, uint32_t, uint16_t) -copydecl(uint64copy, uint32copy, uint64_t, uint32_t) +copyimpl(uint16copy, uint8copy, uint16_t, uint8_t) +copyimpl(uint32copy, uint16copy, uint32_t, uint16_t) +copyimpl(uint64copy, uint32copy, uint64_t, uint32_t) #define int8copy(dst, src) *(dst) = *(src); -copydecl(int16copy, int8copy, int16_t, int8_t) -copydecl(int32copy, int16copy, int32_t, int16_t) -copydecl(int64copy, int32copy, int64_t, int32_t) +copyimpl(int16copy, int8copy, int16_t, int8_t) +copyimpl(int32copy, int16copy, int32_t, int16_t) +copyimpl(int64copy, int32copy, int64_t, int32_t) #define msgidcopy uint32copy @@ -102,6 +105,25 @@ } } +static void +checkmail0(m0in, m0out) + const struct mail0 *m0in; + const struct mail0 *m0out; +{ + if (m0in->version != MAIL0_VERSION && + m0out->version != MAIL0_VERSION) { + fprintf(stderr, "version mismatch: 0x%04x (expected %x)\n", + m0in->version, MAIL0_VERSION); + exit(1); + } + if (m0in->size != sizeof *m0in && + m0out->size != sizeof *m0in) { + fprintf(stderr, "size mismatch: 0x%04x (expected %x)\n", + m0in->size, sizeof *m0in); + exit(1); + } +} + int main(argc, argv) int argc; @@ -122,26 +144,16 @@ break; perror("fread"); } + convert(&m_out, &m_in); - if (first) { - struct mail0 *m0in = (struct mail0 *)&m_in; - struct mail0 *m0out = (struct mail0 *)&m_out; - if (m0in->version != MAIL0_VERSION && - m0out->version != MAIL0_VERSION) { - fprintf(stderr, "version mismatch: 0x%04x (expected %x)\n", - m0in->version, MAIL0_VERSION); - exit(1); - } - if (m0in->size != sizeof m_in && - m0out->size != sizeof m_in) { - fprintf(stderr, "size mismatch: 0x%04x (expected %x)\n", - m0in->size, sizeof m_in); - exit(1); - } - } + + /* Check the header after conversion because I am lazy */ + if (first) + checkmail0((struct mail0 *)&m_in, (struct mail0 *)&m_out); + first = 0; + if (fwrite(&m_out, sizeof m_out, 1, stdout) != 1) perror("fwrite"); - first = 0; } fflush(stdout); exit(0); |