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
1 merge request!1698Fix issues with chat messages
......@@ -150,27 +150,58 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr)
#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 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)
#define WRITEMEM(p,s,n) do { memcpy(p, s, n); p += n; } while (0)
#define WRITESTRINGN(p, s, n) ({ \
size_t tmp_i; \
\
for (tmp_i = 0; tmp_i < n && s[tmp_i] != '\0'; tmp_i++) \
WRITECHAR(p, s[tmp_i]); \
\
if (tmp_i < n) \
WRITECHAR(p, '\0'); \
})
#define WRITESTRING(p, s) ({ \
size_t tmp_i; \
\
for (tmp_i = 0; s[tmp_i] != '\0'; tmp_i++) \
WRITECHAR(p, s[tmp_i]); \
\
WRITECHAR(p, '\0'); \
})
#define WRITEMEM(p, s, n) ({ \
memcpy(p, s, n); \
p += n; \
})
#define SKIPSTRING(p) while (READCHAR(p) != '\0')
#define SKIPSTRINGN(p,n) ({ size_t tmp_i = 0; for (; tmp_i < n && READCHAR(p) != '\0'; tmp_i++); })
#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';})
#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; })
#if 0 // old names
#define WRITEBYTE(p,b) WRITEUINT8(p,b)
#define WRITESHORT(p,b) WRITEINT16(p,b)
#define WRITEUSHORT(p,b) WRITEUINT16(p,b)
#define WRITELONG(p,b) WRITEINT32(p,b)
#define WRITEULONG(p,b) WRITEUINT32(p,b)
#define READBYTE(p) READUINT8(p)
#define READSHORT(p) READINT16(p)
#define READUSHORT(p) READUINT16(p)
#define READLONG(p) READINT32(p)
#define READULONG(p) READUINT32(p)
#endif
#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.
Please register or to comment