@@ -30,8 +30,11 @@ * 1 = 7-bit (compressed) * 0 = 8-bit (uncompressed) */ # define _IAIA_EXP_ASCFORM (0) #endif +#ifndef NULL +# define NULL ((void*)0) +#endif enum /* constants */ { base7bit = 128, @@ -55,12 +58,13 @@ #endif /* -- string to integer converters -- */ -iaia_error_type _IAIA_FN_ASCTOI(const char* s, iaia_word_type* ret) { +iaia_error_type +_IAIA_FN_ASCTOI(const char* s, iaia_word_type* ret) { iaia_word_type val = 0; - for (;*s!=null;++s) { + for (;*s!=0;++s) { uint8_t v = *s; if (v > base7bit) return iaia_e_domain; if (_IAIA_EXP_ASCFORM) @@ -70,13 +74,14 @@ val += v; } *ret = val; - return ok; + return iaia_e_ok; } -iaia_error_type _IAIA_FN_ATOI(iaia_word_type base, const char* s, iaia_word_type* ret) { - /* s must be a null-terminated ASCII numeral string */ +iaia_error_type +_IAIA_FN_ATOI(iaia_word_type base, const char* s, iaia_word_type* ret) { + /* s must be a NUL-terminated ASCII numeral string */ if (base > maxbase) return iaia_e_base; /* override the default base if it's a basèd literal */ if (s[0] == '@' || base == 0) return _IAIA_FN_ASCTOI(s + (s[0]=='@'),ret); @@ -88,9 +93,9 @@ bool insens = (base <= imaxbase); iaia_word_type val = 0; - for (;*s!=null;++s) { + for (;*s!=0;++s) { uint8_t v = *s; if(v >= 0x30 && v <= 0x39) v -= 0x30; else { if(v >= 0x61 && v <= 0x7a) { if (insens) v -= 0x20; else { @@ -115,17 +120,18 @@ /* -- integer to string converters -- */ /* needed for efficiency's sake, but really sucky - * this table needs to be kept in sync with the - * itoa algorithm by hand. unfortunately, given C's + * itoa algorithm manually. unfortunately, given C's * abject lack of metaprogramming, we have to do this * by hand. */ const char iaia_ref_table[] = /* numerals[10] */ "0123456789" /* bigalpha[26] */ "ABCDEFGHIJKLMNOPQRSTUVWXYZ" /* smallalpha[26] */ "abcdefghijklmnopqrstuvwxyz"; _Static_assert (sizeof iaia_ref_table - 1 == maxbase, "tables out of sync"); -iaia_error_type _IAIA_FN_ITOASC(iaia_word_type val, const char* buf_start, char* buf_end, char** newbuf) { +iaia_error_type +_IAIA_FN_ITOASC(iaia_word_type val, const char* buf_start, char* buf_end, char** newbuf) { char* ptr = buf_end; *ptr-- = 0; while(val > 0) { @@ -136,13 +142,14 @@ else val >>= 8; *ptr-- = (char)rem; } - if (newbuf != null) *newbuf = ptr + 1; - return ok; + if (newbuf != NULL) *newbuf = ptr + 1; + return iaia_e_ok; } -iaia_error_type _IAIA_FN_ITOA(iaia_word_type base, iaia_word_type val, const char* buf_start, +iaia_error_type +_IAIA_FN_ITOA(iaia_word_type base, iaia_word_type val, const char* buf_start, char* buf_end, char** newbuf, bool lowercase) { char* ptr = buf_end; @@ -161,8 +168,8 @@ out += ('a' - 'A'); *ptr-- = out; } - if (newbuf != null) *newbuf = ptr + 1; + if (newbuf != NULL) *newbuf = ptr + 1; return iaia_e_ok; }