diff options
author | dreammaster | 2019-09-08 22:36:19 +0100 |
---|---|---|
committer | Paul Gilbert | 2019-09-25 20:13:27 -0700 |
commit | ac9b8fd43d75aca937a32e581e06019833776248 (patch) | |
tree | cf48cd66bf6e3c4e96a96e9ab0dd995bf78053bc /engines/glk/adrift/sxutils.cpp | |
parent | fc410a88a0e8840f7d3cf3522ac4a33460bed761 (diff) | |
download | scummvm-rg350-ac9b8fd43d75aca937a32e581e06019833776248.tar.gz scummvm-rg350-ac9b8fd43d75aca937a32e581e06019833776248.tar.bz2 scummvm-rg350-ac9b8fd43d75aca937a32e581e06019833776248.zip |
GLK: ADRIFT: Formatting
Diffstat (limited to 'engines/glk/adrift/sxutils.cpp')
-rw-r--r-- | engines/glk/adrift/sxutils.cpp | 182 |
1 files changed, 86 insertions, 96 deletions
diff --git a/engines/glk/adrift/sxutils.cpp b/engines/glk/adrift/sxutils.cpp index d52670db31..90c7385131 100644 --- a/engines/glk/adrift/sxutils.cpp +++ b/engines/glk/adrift/sxutils.cpp @@ -38,14 +38,14 @@ namespace Adrift { * that trace output is synchronized to test expectation failure messages. */ void sx_trace(const sc_char *format, ...) { - va_list ap; - assert (format); + va_list ap; + assert(format); - va_start(ap, format); - Common::String line = Common::String::vformat(format, ap); - va_end(ap); + va_start(ap, format); + Common::String line = Common::String::vformat(format, ap); + va_end(ap); - debug("%s", line.c_str()); + debug("%s", line.c_str()); } /* @@ -79,7 +79,7 @@ void sx_fatal(const sc_char *format, ...) { /* Unique non-heap address for zero size malloc() and realloc() requests. */ static void *sx_zero_allocation = &sx_zero_allocation; - + /* * sx_malloc() * sx_realloc() @@ -90,54 +90,51 @@ static void *sx_zero_allocation = &sx_zero_allocation; * defined, so we have to take special care to get predictable behavior. */ void * -sx_malloc (size_t size) -{ - void *allocated; +sx_malloc(size_t size) { + void *allocated; - if (size == 0) - return sx_zero_allocation; + if (size == 0) + return sx_zero_allocation; - allocated = malloc (size); - if (!allocated) - sx_fatal ("sx_malloc: requested %lu bytes\n", (sc_uint) size); - else if (allocated == sx_zero_allocation) - sx_fatal ("sx_malloc: zero-byte allocation address returned\n"); + allocated = malloc(size); + if (!allocated) + sx_fatal("sx_malloc: requested %lu bytes\n", (sc_uint) size); + else if (allocated == sx_zero_allocation) + sx_fatal("sx_malloc: zero-byte allocation address returned\n"); - memset (allocated, 0, size); - return allocated; + memset(allocated, 0, size); + return allocated; } void * -sx_realloc (void *pointer, size_t size) -{ - void *allocated; - - if (size == 0) - { - sx_free (pointer); - return sx_zero_allocation; - } - - if (pointer == sx_zero_allocation) - pointer = NULL; - - allocated = realloc (pointer, size); - if (!allocated) - sx_fatal ("sx_realloc: requested %lu bytes\n", (sc_uint) size); - else if (allocated == sx_zero_allocation) - sx_fatal ("sx_realloc: zero-byte allocation address returned\n"); - - if (!pointer) - memset (allocated, 0, size); - return allocated; +sx_realloc(void *pointer, size_t size) { + void *allocated; + + if (size == 0) { + sx_free(pointer); + return sx_zero_allocation; + } + + if (pointer == sx_zero_allocation) + pointer = NULL; + + allocated = realloc(pointer, size); + if (!allocated) + sx_fatal("sx_realloc: requested %lu bytes\n", (sc_uint) size); + else if (allocated == sx_zero_allocation) + sx_fatal("sx_realloc: zero-byte allocation address returned\n"); + + if (!pointer) + memset(allocated, 0, size); + return allocated; } -void sx_free (void *pointer) { - if (sx_zero_allocation != &sx_zero_allocation) - sx_fatal ("sx_free: write to zero-byte allocation address detected\n"); +void sx_free(void *pointer) { + if (sx_zero_allocation != &sx_zero_allocation) + sx_fatal("sx_free: write to zero-byte allocation address detected\n"); - if (pointer && pointer != sx_zero_allocation) - free (pointer); + if (pointer && pointer != sx_zero_allocation) + free(pointer); } @@ -148,16 +145,16 @@ void sx_free (void *pointer) { * Returns NULL if unsuccessful. */ Common::SeekableReadStream *sx_fopen(const sc_char *name, const sc_char *extension, const sc_char *mode) { - assert (name && extension && mode); + assert(name && extension && mode); - Common::String filename = Common::String::format("%s.%s", name, extension); - Common::File *f = new Common::File(); + Common::String filename = Common::String::format("%s.%s", name, extension); + Common::File *f = new Common::File(); - if (f->open(filename)) - return f; + if (f->open(filename)) + return f; - delete f; - return nullptr; + delete f; + return nullptr; } @@ -171,19 +168,17 @@ static const sc_char NUL = '\0'; * Built in replacements for locale-sensitive libc ctype.h functions. */ static sc_bool -sx_isspace (sc_char character) -{ - static const sc_char *const WHITESPACE = "\t\n\v\f\r "; +sx_isspace(sc_char character) { + static const sc_char *const WHITESPACE = "\t\n\v\f\r "; - return character != NUL && strchr (WHITESPACE, character) != NULL; + return character != NUL && strchr(WHITESPACE, character) != NULL; } static sc_bool -sx_isprint (sc_char character) -{ - static const sc_int MIN_PRINTABLE = ' ', MAX_PRINTABLE = '~'; +sx_isprint(sc_char character) { + static const sc_int MIN_PRINTABLE = ' ', MAX_PRINTABLE = '~'; - return character >= MIN_PRINTABLE && character <= MAX_PRINTABLE; + return character >= MIN_PRINTABLE && character <= MAX_PRINTABLE; } @@ -194,20 +189,19 @@ sx_isprint (sc_char character) * in place, and returns the string address for convenience. */ sc_char * -sx_trim_string (sc_char *string) -{ - sc_int index_; - assert (string); +sx_trim_string(sc_char *string) { + sc_int index_; + assert(string); - for (index_ = strlen (string) - 1; - index_ >= 0 && sx_isspace (string[index_]); index_--) - string[index_] = NUL; + for (index_ = strlen(string) - 1; + index_ >= 0 && sx_isspace(string[index_]); index_--) + string[index_] = NUL; - for (index_ = 0; sx_isspace (string[index_]);) - index_++; - memmove (string, string + index_, strlen (string) - index_ + 1); + for (index_ = 0; sx_isspace(string[index_]);) + index_++; + memmove(string, string + index_, strlen(string) - index_ + 1); - return string; + return string; } @@ -219,30 +213,26 @@ sx_trim_string (sc_char *string) * place, and returns the string address for convenience. */ sc_char * -sx_normalize_string (sc_char *string) -{ - sc_int index_; - assert (string); - - string = sx_trim_string (string); - - for (index_ = 0; string[index_] != NUL; index_++) - { - if (sx_isspace (string[index_])) - { - sc_int cursor; - - string[index_] = ' '; - for (cursor = index_ + 1; sx_isspace (string[cursor]);) - cursor++; - memmove (string + index_ + 1, - string + cursor, strlen (string + cursor) + 1); - } - else if (!sx_isprint (string[index_])) - string[index_] = '?'; - } - - return string; +sx_normalize_string(sc_char *string) { + sc_int index_; + assert(string); + + string = sx_trim_string(string); + + for (index_ = 0; string[index_] != NUL; index_++) { + if (sx_isspace(string[index_])) { + sc_int cursor; + + string[index_] = ' '; + for (cursor = index_ + 1; sx_isspace(string[cursor]);) + cursor++; + memmove(string + index_ + 1, + string + cursor, strlen(string + cursor) + 1); + } else if (!sx_isprint(string[index_])) + string[index_] = '?'; + } + + return string; } char *adrift_fgets(char *buf, int max, Common::SeekableReadStream *s) { |