Skip to content
Snippets Groups Projects
Commit a6685460 authored by LJ Sonic's avatar LJ Sonic
Browse files

Make byte stream manipulation code easier to read

parent 13778247
No related branches found
No related tags found
No related merge requests found
...@@ -150,27 +150,58 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) ...@@ -150,27 +150,58 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr)
#undef DEALIGNED #undef DEALIGNED
#define WRITESTRINGN(p,s,n) do { size_t tmp_i = 0; for (; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); if (tmp_i < n) WRITECHAR(p, '\0');} while (0) #define WRITESTRINGN(p, s, n) ({ \
#define WRITESTRING(p,s) do { size_t tmp_i = 0; for (; s[tmp_i] != '\0'; tmp_i++) WRITECHAR(p, s[tmp_i]); WRITECHAR(p, '\0');} while (0) size_t tmp_i; \
#define WRITEMEM(p,s,n) do { memcpy(p, s, n); p += n; } while (0) \
for (tmp_i = 0; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) \
#define SKIPSTRING(p) while (READCHAR(p) != '\0') WRITECHAR(p, s[tmp_i]); \
#define SKIPSTRINGN(p,n) ({ size_t tmp_i = 0; for (; tmp_i < n && READCHAR(p) != '\0'; tmp_i++); }) \
if (tmp_i < n) \
#define READSTRINGN(p,s,n) ({ size_t tmp_i = 0; for (; tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) WRITECHAR(p, '\0'); \
#define READSTRING(p,s) ({ size_t tmp_i = 0; for (; (s[tmp_i] = READCHAR(p)) != '\0'; tmp_i++); s[tmp_i] = '\0';}) })
#define READMEM(p,s,n) ({ memcpy(s, p, n); p += n; })
#define WRITESTRING(p, s) ({ \
#if 0 // old names size_t tmp_i; \
#define WRITEBYTE(p,b) WRITEUINT8(p,b) \
#define WRITESHORT(p,b) WRITEINT16(p,b) for (tmp_i = 0; s[tmp_i] != '\0'; tmp_i++) \
#define WRITEUSHORT(p,b) WRITEUINT16(p,b) WRITECHAR(p, s[tmp_i]); \
#define WRITELONG(p,b) WRITEINT32(p,b) \
#define WRITEULONG(p,b) WRITEUINT32(p,b) WRITECHAR(p, '\0'); \
})
#define READBYTE(p) READUINT8(p)
#define READSHORT(p) READINT16(p) #define WRITEMEM(p, s, n) ({ \
#define READUSHORT(p) READUINT16(p) memcpy(p, s, n); \
#define READLONG(p) READINT32(p) p += n; \
#define READULONG(p) READUINT32(p) })
#endif
#define SKIPSTRING(p) while (READCHAR(p) != '\0')
#define SKIPSTRINGN(p, n) ({ \
size_t tmp_i = 0; \
\
while (tmp_i < n && READCHAR(p) != '\0') \
tmp_i++; \
})
#define READSTRINGN(p, s, n) ({ \
size_t tmp_i = 0; \
\
while (tmp_i < n && (s[tmp_i] = READCHAR(p)) != '\0') \
tmp_i++; \
\
s[tmp_i] = '\0'; \
})
#define READSTRING(p, s) ({ \
size_t tmp_i = 0; \
\
while ((s[tmp_i] = READCHAR(p)) != '\0') \
tmp_i++; \
\
s[tmp_i] = '\0'; \
})
#define READMEM(p, s, n) ({ \
memcpy(s, p, n); \
p += n; \
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment