Improve readability

This commit is contained in:
Xpl0itU 2022-04-05 21:01:09 +02:00
parent 0a8e12385e
commit c5f973a9c1
11 changed files with 762 additions and 550 deletions

View File

@ -98,7 +98,7 @@ cJSON_GetErrorPtr(void) {
auto
cJSON_GetStringValue(const cJSON *const item) -> CJSON_PUBLIC(char *) {
if (!cJSON_IsString(item)) {
if (cJSON_IsString(item) == 0) {
return nullptr;
}
@ -107,7 +107,7 @@ cJSON_GetStringValue(const cJSON *const item) -> CJSON_PUBLIC(char *) {
auto
cJSON_GetNumberValue(const cJSON *const item) -> CJSON_PUBLIC(double) {
if (!cJSON_IsNumber(item)) {
if (cJSON_IsNumber(item) == 0) {
return (double) NAN;
}
@ -224,7 +224,7 @@ cJSON_InitHooks(cJSON_Hooks *hooks) {
/* Internal constructor. */
static auto cJSON_New_Item(const internal_hooks *const hooks) -> cJSON * {
auto *node = (cJSON *) hooks->allocate(sizeof(cJSON));
if (node) {
if (node != nullptr) {
memset(node, '\0', sizeof(cJSON));
}
@ -237,13 +237,13 @@ cJSON_Delete(cJSON *item) {
cJSON *next = nullptr;
while (item != nullptr) {
next = item->next;
if (!(item->type & cJSON_IsReference) && (item->child != nullptr)) {
if (((item->type & cJSON_IsReference) == 0) && (item->child != nullptr)) {
cJSON_Delete(item->child);
}
if (!(item->type & cJSON_IsReference) && (item->valuestring != nullptr)) {
if (((item->type & cJSON_IsReference) == 0) && (item->valuestring != nullptr)) {
global_hooks.deallocate(item->valuestring);
}
if (!(item->type & cJSON_StringIsConst) && (item->string != nullptr)) {
if (((item->type & cJSON_StringIsConst) == 0) && (item->string != nullptr)) {
global_hooks.deallocate(item->string);
}
global_hooks.deallocate(item);
@ -362,7 +362,7 @@ auto
cJSON_SetValuestring(cJSON *object, const char *valuestring) -> CJSON_PUBLIC(char *) {
char *copy = nullptr;
/* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */
if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) {
if (((object->type & cJSON_String) == 0) || ((object->type & cJSON_IsReference) != 0)) {
return nullptr;
}
if (strlen(valuestring) <= strlen(object->valuestring)) {
@ -415,7 +415,7 @@ static auto ensure(printbuffer *const p, size_t needed) -> unsigned char * {
return p->buffer + p->offset;
}
if (p->noalloc) {
if (p->noalloc != 0) {
return nullptr;
}
@ -444,7 +444,7 @@ static auto ensure(printbuffer *const p, size_t needed) -> unsigned char * {
} else {
/* otherwise reallocate manually */
newbuffer = (unsigned char *) p->hooks.allocate(newsize);
if (!newbuffer) {
if (newbuffer == nullptr) {
p->hooks.deallocate(p->buffer);
p->length = 0;
p->buffer = nullptr;
@ -475,7 +475,7 @@ static void update_offset(printbuffer *const buffer) {
/* securely comparison of floating-point variables */
static auto compare_double(double a, double b) -> cJSON_bool {
double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b);
return (fabs(a - b) <= maxVal * DBL_EPSILON);
return static_cast<cJSON_bool>(fabs(a - b) <= maxVal * DBL_EPSILON);
}
/* Render the number nicely from the given item into a string. */
@ -500,7 +500,7 @@ static auto print_number(const cJSON *const item, printbuffer *const output_buff
length = sprintf((char *) number_buffer, "%1.15g", d);
/* Check whether the original double can be recovered */
if ((sscanf((char *) number_buffer, "%lg", &test) != 1) || !compare_double((double) test, d)) {
if ((sscanf((char *) number_buffer, "%lg", &test) != 1) || (compare_double((double) test, d) == 0)) {
/* If not, print with 17 decimal places of precision */
length = sprintf((char *) number_buffer, "%1.17g", d);
}
@ -802,7 +802,7 @@ static auto print_string_ptr(const unsigned char *const input, printbuffer *cons
}
/* set "flag" to 1 if something needs to be escaped */
for (input_pointer = input; *input_pointer; input_pointer++) {
for (input_pointer = input; *input_pointer != 0u; input_pointer++) {
switch (*input_pointer) {
case '\"':
case '\\':
@ -891,17 +891,17 @@ static auto print_string(const cJSON *const item, printbuffer *const p) -> cJSON
}
/* Predeclare these prototypes. */
static auto parse_value(cJSON *const item, parse_buffer *const input_buffer) -> cJSON_bool;
static auto parse_value(cJSON *item, parse_buffer *input_buffer) -> cJSON_bool;
static auto print_value(const cJSON *const item, printbuffer *const output_buffer) -> cJSON_bool;
static auto print_value(const cJSON *item, printbuffer *output_buffer) -> cJSON_bool;
static auto parse_array(cJSON *const item, parse_buffer *const input_buffer) -> cJSON_bool;
static auto parse_array(cJSON *item, parse_buffer *input_buffer) -> cJSON_bool;
static auto print_array(const cJSON *const item, printbuffer *const output_buffer) -> cJSON_bool;
static auto print_array(const cJSON *item, printbuffer *output_buffer) -> cJSON_bool;
static auto parse_object(cJSON *const item, parse_buffer *const input_buffer) -> cJSON_bool;
static auto parse_object(cJSON *item, parse_buffer *input_buffer) -> cJSON_bool;
static auto print_object(const cJSON *const item, printbuffer *const output_buffer) -> cJSON_bool;
static auto print_object(const cJSON *item, printbuffer *output_buffer) -> cJSON_bool;
/* Utility to jump whitespace and cr/lf */
static auto buffer_skip_whitespace(parse_buffer *const buffer) -> parse_buffer * {
@ -977,19 +977,19 @@ cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **
goto fail;
}
if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) {
if (parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer))) == 0) {
/* parse failure. ep is set. */
goto fail;
}
/* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
if (require_null_terminated) {
if (require_null_terminated != 0) {
buffer_skip_whitespace(&buffer);
if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') {
goto fail;
}
}
if (return_parse_end) {
if (return_parse_end != nullptr) {
*return_parse_end = (const char *) buffer_at_offset(&buffer);
}
@ -1051,7 +1051,7 @@ static auto print(const cJSON *const item, cJSON_bool format, const internal_hoo
}
/* print the value */
if (!print_value(item, buffer)) {
if (print_value(item, buffer) == 0) {
goto fail;
}
update_offset(buffer);
@ -1110,7 +1110,7 @@ cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_P
}
p.buffer = (unsigned char *) global_hooks.allocate((size_t) prebuffer);
if (!p.buffer) {
if (p.buffer == nullptr) {
return nullptr;
}
@ -1120,7 +1120,7 @@ cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_P
p.format = fmt;
p.hooks = global_hooks;
if (!print_value(item, &p)) {
if (print_value(item, &p) == 0) {
global_hooks.deallocate(p.buffer);
return nullptr;
}
@ -1311,7 +1311,7 @@ static auto parse_array(cJSON *const item, parse_buffer *const input_buffer) ->
/* parse next value */
input_buffer->offset++;
buffer_skip_whitespace(input_buffer);
if (!parse_value(current_item, input_buffer)) {
if (parse_value(current_item, input_buffer) == 0) {
goto fail; /* failed to parse value */
}
buffer_skip_whitespace(input_buffer);
@ -1365,18 +1365,18 @@ static auto print_array(const cJSON *const item, printbuffer *const output_buffe
output_buffer->depth++;
while (current_element != nullptr) {
if (!print_value(current_element, output_buffer)) {
if (print_value(current_element, output_buffer) == 0) {
return false;
}
update_offset(output_buffer);
if (current_element->next) {
length = (size_t)(output_buffer->format ? 2 : 1);
if (current_element->next != nullptr) {
length = (size_t)(output_buffer->format != 0 ? 2 : 1);
output_pointer = ensure(output_buffer, length + 1);
if (output_pointer == nullptr) {
return false;
}
*output_pointer++ = ',';
if (output_buffer->format) {
if (output_buffer->format != 0) {
*output_pointer++ = ' ';
}
*output_pointer = '\0';
@ -1446,7 +1446,7 @@ static auto parse_object(cJSON *const item, parse_buffer *const input_buffer) ->
/* parse the name of the child */
input_buffer->offset++;
buffer_skip_whitespace(input_buffer);
if (!parse_string(current_item, input_buffer)) {
if (parse_string(current_item, input_buffer) == 0) {
goto fail; /* failed to parse name */
}
buffer_skip_whitespace(input_buffer);
@ -1462,7 +1462,7 @@ static auto parse_object(cJSON *const item, parse_buffer *const input_buffer) ->
/* parse the value */
input_buffer->offset++;
buffer_skip_whitespace(input_buffer);
if (!parse_value(current_item, input_buffer)) {
if (parse_value(current_item, input_buffer) == 0) {
goto fail; /* failed to parse value */
}
buffer_skip_whitespace(input_buffer);
@ -1504,7 +1504,7 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
}
/* Compose the output: */
length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */
length = (size_t)(output_buffer->format != 0 ? 2 : 1); /* fmt: {\n */
output_pointer = ensure(output_buffer, length + 1);
if (output_pointer == nullptr) {
return false;
@ -1512,13 +1512,13 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
*output_pointer++ = '{';
output_buffer->depth++;
if (output_buffer->format) {
if (output_buffer->format != 0) {
*output_pointer++ = '\n';
}
output_buffer->offset += length;
while (current_item) {
if (output_buffer->format) {
while (current_item != nullptr) {
if (output_buffer->format != 0) {
size_t i;
output_pointer = ensure(output_buffer, output_buffer->depth);
if (output_pointer == nullptr) {
@ -1531,39 +1531,39 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
}
/* print key */
if (!print_string_ptr((unsigned char *) current_item->string, output_buffer)) {
if (print_string_ptr((unsigned char *) current_item->string, output_buffer) == 0) {
return false;
}
update_offset(output_buffer);
length = (size_t)(output_buffer->format ? 2 : 1);
length = (size_t)(output_buffer->format != 0 ? 2 : 1);
output_pointer = ensure(output_buffer, length);
if (output_pointer == nullptr) {
return false;
}
*output_pointer++ = ':';
if (output_buffer->format) {
if (output_buffer->format != 0) {
*output_pointer++ = '\t';
}
output_buffer->offset += length;
/* print value */
if (!print_value(current_item, output_buffer)) {
if (print_value(current_item, output_buffer) == 0) {
return false;
}
update_offset(output_buffer);
/* print comma if not last */
length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0));
length = ((size_t)(output_buffer->format != 0 ? 1 : 0) + (size_t)(current_item->next != nullptr ? 1 : 0));
output_pointer = ensure(output_buffer, length + 1);
if (output_pointer == nullptr) {
return false;
}
if (current_item->next) {
if (current_item->next != nullptr) {
*output_pointer++ = ',';
}
if (output_buffer->format) {
if (output_buffer->format != 0) {
*output_pointer++ = '\n';
}
*output_pointer = '\0';
@ -1572,11 +1572,11 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
current_item = current_item->next;
}
output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2);
output_pointer = ensure(output_buffer, output_buffer->format != 0 ? (output_buffer->depth + 1) : 2);
if (output_pointer == nullptr) {
return false;
}
if (output_buffer->format) {
if (output_buffer->format != 0) {
size_t i;
for (i = 0; i < (output_buffer->depth - 1); i++) {
*output_pointer++ = '\t';
@ -1644,7 +1644,7 @@ static auto get_object_item(const cJSON *const object, const char *const name, c
}
current_element = object->child;
if (case_sensitive) {
if (case_sensitive != 0) {
while ((current_element != nullptr) && (current_element->string != nullptr) &&
(strcmp(name, current_element->string) != 0)) {
current_element = current_element->next;
@ -1676,7 +1676,7 @@ cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const st
auto
cJSON_HasObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON_bool) {
return cJSON_GetObjectItem(object, string) ? 1 : 0;
return cJSON_GetObjectItem(object, string) != nullptr ? 1 : 0;
}
/* Utility for array list handling. */
@ -1722,7 +1722,7 @@ static auto add_item_to_array(cJSON *array, cJSON *item) -> cJSON_bool {
item->next = nullptr;
} else {
/* append to the end */
if (child->prev) {
if (child->prev != nullptr) {
suffix_object(child->prev, item);
array->child->prev = item;
}
@ -1764,7 +1764,7 @@ add_item_to_object(cJSON *const object, const char *const string, cJSON *const i
return false;
}
if (constant_key) {
if (constant_key != 0) {
new_key = (char *) cast_away_const(string);
new_type = item->type | cJSON_StringIsConst;
} else {
@ -1776,7 +1776,7 @@ add_item_to_object(cJSON *const object, const char *const string, cJSON *const i
new_type = item->type & ~cJSON_StringIsConst;
}
if (!(item->type & cJSON_StringIsConst) && (item->string != nullptr)) {
if (((item->type & cJSON_StringIsConst) == 0) && (item->string != nullptr)) {
hooks->deallocate(item->string);
}
@ -1818,7 +1818,7 @@ cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -
auto
cJSON_AddNullToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
cJSON *null = cJSON_CreateNull();
if (add_item_to_object(object, name, null, &global_hooks, false)) {
if (add_item_to_object(object, name, null, &global_hooks, false) != 0) {
return null;
}
@ -1829,7 +1829,7 @@ cJSON_AddNullToObject(cJSON *const object, const char *const name) -> CJSON_PUBL
auto
cJSON_AddTrueToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
cJSON *true_item = cJSON_CreateTrue();
if (add_item_to_object(object, name, true_item, &global_hooks, false)) {
if (add_item_to_object(object, name, true_item, &global_hooks, false) != 0) {
return true_item;
}
@ -1840,7 +1840,7 @@ cJSON_AddTrueToObject(cJSON *const object, const char *const name) -> CJSON_PUBL
auto
cJSON_AddFalseToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
cJSON *false_item = cJSON_CreateFalse();
if (add_item_to_object(object, name, false_item, &global_hooks, false)) {
if (add_item_to_object(object, name, false_item, &global_hooks, false) != 0) {
return false_item;
}
@ -1851,7 +1851,7 @@ cJSON_AddFalseToObject(cJSON *const object, const char *const name) -> CJSON_PUB
auto
cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *) {
cJSON *bool_item = cJSON_CreateBool(boolean);
if (add_item_to_object(object, name, bool_item, &global_hooks, false)) {
if (add_item_to_object(object, name, bool_item, &global_hooks, false) != 0) {
return bool_item;
}
@ -1862,7 +1862,7 @@ cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_b
auto
cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number) -> CJSON_PUBLIC(cJSON *) {
cJSON *number_item = cJSON_CreateNumber(number);
if (add_item_to_object(object, name, number_item, &global_hooks, false)) {
if (add_item_to_object(object, name, number_item, &global_hooks, false) != 0) {
return number_item;
}
@ -1873,7 +1873,7 @@ cJSON_AddNumberToObject(cJSON *const object, const char *const name, const doubl
auto
cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string) -> CJSON_PUBLIC(cJSON *) {
cJSON *string_item = cJSON_CreateString(string);
if (add_item_to_object(object, name, string_item, &global_hooks, false)) {
if (add_item_to_object(object, name, string_item, &global_hooks, false) != 0) {
return string_item;
}
@ -1884,7 +1884,7 @@ cJSON_AddStringToObject(cJSON *const object, const char *const name, const char
auto
cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw) -> CJSON_PUBLIC(cJSON *) {
cJSON *raw_item = cJSON_CreateRaw(raw);
if (add_item_to_object(object, name, raw_item, &global_hooks, false)) {
if (add_item_to_object(object, name, raw_item, &global_hooks, false) != 0) {
return raw_item;
}
@ -1895,7 +1895,7 @@ cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *co
auto
cJSON_AddObjectToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
cJSON *object_item = cJSON_CreateObject();
if (add_item_to_object(object, name, object_item, &global_hooks, false)) {
if (add_item_to_object(object, name, object_item, &global_hooks, false) != 0) {
return object_item;
}
@ -1906,7 +1906,7 @@ cJSON_AddObjectToObject(cJSON *const object, const char *const name) -> CJSON_PU
auto
cJSON_AddArrayToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
cJSON *array = cJSON_CreateArray();
if (add_item_to_object(object, name, array, &global_hooks, false)) {
if (add_item_to_object(object, name, array, &global_hooks, false) != 0) {
return array;
}
@ -2063,7 +2063,7 @@ replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJ
}
/* replace the name in the replacement */
if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != nullptr)) {
if (((replacement->type & cJSON_StringIsConst) == 0) && (replacement->string != nullptr)) {
cJSON_free(replacement->string);
}
replacement->string = (char *) cJSON_strdup((const unsigned char *) string, &global_hooks);
@ -2086,7 +2086,7 @@ cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON
auto
cJSON_CreateNull(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_NULL;
}
@ -2096,7 +2096,7 @@ cJSON_CreateNull(void) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateTrue(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_True;
}
@ -2106,7 +2106,7 @@ cJSON_CreateTrue(void) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateFalse(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_False;
}
@ -2116,8 +2116,8 @@ cJSON_CreateFalse(void) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateBool(cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
item->type = boolean ? cJSON_True : cJSON_False;
if (item != nullptr) {
item->type = boolean != 0 ? cJSON_True : cJSON_False;
}
return item;
@ -2126,7 +2126,7 @@ cJSON_CreateBool(cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateNumber(double num) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_Number;
item->valuedouble = num;
@ -2146,10 +2146,10 @@ cJSON_CreateNumber(double num) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateString(const char *string) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_String;
item->valuestring = (char *) cJSON_strdup((const unsigned char *) string, &global_hooks);
if (!item->valuestring) {
if (item->valuestring == nullptr) {
cJSON_Delete(item);
return nullptr;
}
@ -2194,10 +2194,10 @@ cJSON_CreateArrayReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateRaw(const char *raw) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_Raw;
item->valuestring = (char *) cJSON_strdup((const unsigned char *) raw, &global_hooks);
if (!item->valuestring) {
if (item->valuestring == nullptr) {
cJSON_Delete(item);
return nullptr;
}
@ -2209,7 +2209,7 @@ cJSON_CreateRaw(const char *raw) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateArray(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_Array;
}
@ -2219,7 +2219,7 @@ cJSON_CreateArray(void) -> CJSON_PUBLIC(cJSON *) {
auto
cJSON_CreateObject(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item) {
if (item != nullptr) {
item->type = cJSON_Object;
}
@ -2240,13 +2240,13 @@ cJSON_CreateIntArray(const int *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
a = cJSON_CreateArray();
for (i = 0; a && (i < (size_t) count); i++) {
for (i = 0; (a != nullptr) && (i < (size_t) count); i++) {
n = cJSON_CreateNumber(numbers[i]);
if (!n) {
if (n == nullptr) {
cJSON_Delete(a);
return nullptr;
}
if (!i) {
if (i == 0u) {
a->child = n;
} else {
suffix_object(p, n);
@ -2254,7 +2254,7 @@ cJSON_CreateIntArray(const int *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
p = n;
}
if (a && a->child) {
if ((a != nullptr) && (a->child != nullptr)) {
a->child->prev = n;
}
@ -2274,13 +2274,13 @@ cJSON_CreateFloatArray(const float *numbers, int count) -> CJSON_PUBLIC(cJSON *)
a = cJSON_CreateArray();
for (i = 0; a && (i < (size_t) count); i++) {
for (i = 0; (a != nullptr) && (i < (size_t) count); i++) {
n = cJSON_CreateNumber((double) numbers[i]);
if (!n) {
if (n == nullptr) {
cJSON_Delete(a);
return nullptr;
}
if (!i) {
if (i == 0u) {
a->child = n;
} else {
suffix_object(p, n);
@ -2288,7 +2288,7 @@ cJSON_CreateFloatArray(const float *numbers, int count) -> CJSON_PUBLIC(cJSON *)
p = n;
}
if (a && a->child) {
if ((a != nullptr) && (a->child != nullptr)) {
a->child->prev = n;
}
@ -2308,13 +2308,13 @@ cJSON_CreateDoubleArray(const double *numbers, int count) -> CJSON_PUBLIC(cJSON
a = cJSON_CreateArray();
for (i = 0; a && (i < (size_t) count); i++) {
for (i = 0; (a != nullptr) && (i < (size_t) count); i++) {
n = cJSON_CreateNumber(numbers[i]);
if (!n) {
if (n == nullptr) {
cJSON_Delete(a);
return nullptr;
}
if (!i) {
if (i == 0u) {
a->child = n;
} else {
suffix_object(p, n);
@ -2322,7 +2322,7 @@ cJSON_CreateDoubleArray(const double *numbers, int count) -> CJSON_PUBLIC(cJSON
p = n;
}
if (a && a->child) {
if ((a != nullptr) && (a->child != nullptr)) {
a->child->prev = n;
}
@ -2342,13 +2342,13 @@ cJSON_CreateStringArray(const char *const *strings, int count) -> CJSON_PUBLIC(c
a = cJSON_CreateArray();
for (i = 0; a && (i < (size_t) count); i++) {
for (i = 0; (a != nullptr) && (i < (size_t) count); i++) {
n = cJSON_CreateString(strings[i]);
if (!n) {
if (n == nullptr) {
cJSON_Delete(a);
return nullptr;
}
if (!i) {
if (i == 0u) {
a->child = n;
} else {
suffix_object(p, n);
@ -2356,7 +2356,7 @@ cJSON_CreateStringArray(const char *const *strings, int count) -> CJSON_PUBLIC(c
p = n;
}
if (a && a->child) {
if ((a != nullptr) && (a->child != nullptr)) {
a->child->prev = n;
}
@ -2372,40 +2372,40 @@ cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *)
cJSON *newchild = nullptr;
/* Bail on bad ptr */
if (!item) {
if (item == nullptr) {
goto fail;
}
/* Create new item */
newitem = cJSON_New_Item(&global_hooks);
if (!newitem) {
if (newitem == nullptr) {
goto fail;
}
/* Copy over all vars */
newitem->type = item->type & (~cJSON_IsReference);
newitem->valueint = item->valueint;
newitem->valuedouble = item->valuedouble;
if (item->valuestring) {
if (item->valuestring != nullptr) {
newitem->valuestring = (char *) cJSON_strdup((unsigned char *) item->valuestring, &global_hooks);
if (!newitem->valuestring) {
if (newitem->valuestring == nullptr) {
goto fail;
}
}
if (item->string) {
newitem->string = (item->type & cJSON_StringIsConst) ? item->string : (char *) cJSON_strdup(
if (item->string != nullptr) {
newitem->string = (item->type & cJSON_StringIsConst) != 0 ? item->string : (char *) cJSON_strdup(
(unsigned char *) item->string, &global_hooks);
if (!newitem->string) {
if (newitem->string == nullptr) {
goto fail;
}
}
/* If non-recursive, then we're done! */
if (!recurse) {
if (recurse == 0) {
return newitem;
}
/* Walk the ->next chain for the child. */
child = item->child;
while (child != nullptr) {
newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */
if (!newchild) {
if (newchild == nullptr) {
goto fail;
}
if (next != nullptr) {
@ -2420,7 +2420,7 @@ cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *)
}
child = child->next;
}
if (newitem && newitem->child) {
if ((newitem != nullptr) && (newitem->child != nullptr)) {
newitem->child->prev = newchild;
}
@ -2470,7 +2470,7 @@ static void minify_string(char **input, char **output) {
*input += static_strlen("\"");
*output += static_strlen("\"");
return;
} else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) {
} if (((*input)[0] == '\\') && ((*input)[1] == '\"')) {
(*output)[1] = (*input)[1];
*input += static_strlen("\"");
*output += static_strlen("\"");
@ -2526,7 +2526,7 @@ cJSON_IsInvalid(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_Invalid;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Invalid);
}
auto
@ -2535,7 +2535,7 @@ cJSON_IsFalse(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_False;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_False);
}
auto
@ -2544,7 +2544,7 @@ cJSON_IsTrue(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xff) == cJSON_True;
return static_cast<cJSON_bool>((item->type & 0xff) == cJSON_True);
}
@ -2554,7 +2554,7 @@ cJSON_IsBool(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & (cJSON_True | cJSON_False)) != 0;
return static_cast<cJSON_bool>((item->type & (cJSON_True | cJSON_False)) != 0);
}
auto
@ -2563,7 +2563,7 @@ cJSON_IsNull(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_NULL;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_NULL);
}
auto
@ -2572,7 +2572,7 @@ cJSON_IsNumber(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_Number;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Number);
}
auto
@ -2581,7 +2581,7 @@ cJSON_IsString(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_String;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_String);
}
auto
@ -2590,7 +2590,7 @@ cJSON_IsArray(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_Array;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Array);
}
auto
@ -2599,7 +2599,7 @@ cJSON_IsObject(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_Object;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Object);
}
auto
@ -2608,7 +2608,7 @@ cJSON_IsRaw(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return false;
}
return (item->type & 0xFF) == cJSON_Raw;
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Raw);
}
auto
@ -2646,7 +2646,7 @@ cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_
return true;
case cJSON_Number:
if (compare_double(a->valuedouble, b->valuedouble)) {
if (compare_double(a->valuedouble, b->valuedouble) != 0) {
return true;
}
return false;
@ -2667,7 +2667,7 @@ cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_
cJSON *b_element = b->child;
for (; (a_element != nullptr) && (b_element != nullptr);) {
if (!cJSON_Compare(a_element, b_element, case_sensitive)) {
if (cJSON_Compare(a_element, b_element, case_sensitive) == 0) {
return false;
}
@ -2693,7 +2693,7 @@ cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_
return false;
}
if (!cJSON_Compare(a_element, b_element, case_sensitive)) {
if (cJSON_Compare(a_element, b_element, case_sensitive) == 0) {
return false;
}
}
@ -2706,7 +2706,7 @@ cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_
return false;
}
if (!cJSON_Compare(b_element, a_element, case_sensitive)) {
if (cJSON_Compare(b_element, a_element, case_sensitive) == 0) {
return false;
}
}

View File

@ -171,7 +171,7 @@ cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_P
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
auto
cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) -> CJSON_PUBLIC(cJSON_bool);
cJSON_PrintPreallocated(cJSON *item, char *buffer, int length, cJSON_bool format) -> CJSON_PUBLIC(cJSON_bool);
/* Delete a cJSON entity and all subentities. */
CJSON_PUBLIC(void)
cJSON_Delete(cJSON *item);
@ -184,10 +184,10 @@ auto
cJSON_GetArrayItem(const cJSON *array, int index) -> CJSON_PUBLIC(cJSON *);
/* Get item "string" from object. Case insensitive. */
auto
cJSON_GetObjectItem(const cJSON *const object, const char *const string) -> CJSON_PUBLIC(cJSON *);
cJSON_GetObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string) -> CJSON_PUBLIC(cJSON *);
cJSON_GetObjectItemCaseSensitive(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_HasObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON_bool);
@ -197,41 +197,41 @@ cJSON_GetErrorPtr(void);
/* Check item type and return its value */
auto
cJSON_GetStringValue(const cJSON *const item) -> CJSON_PUBLIC(char *);
cJSON_GetStringValue(const cJSON *item) -> CJSON_PUBLIC(char *);
auto
cJSON_GetNumberValue(const cJSON *const item) -> CJSON_PUBLIC(double);
cJSON_GetNumberValue(const cJSON *item) -> CJSON_PUBLIC(double);
/* These functions check the type of an item */
auto
cJSON_IsInvalid(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsInvalid(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsFalse(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsFalse(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsTrue(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsTrue(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsBool(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsBool(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsNull(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsNull(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsNumber(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsNumber(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsString(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsString(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsArray(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsArray(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsObject(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsObject(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsRaw(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool);
cJSON_IsRaw(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
/* These calls create a cJSON item of the appropriate type. */
auto
@ -307,7 +307,7 @@ cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -
/* Remove/Detach items from Arrays/Objects. */
auto
cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) -> CJSON_PUBLIC(cJSON *);
cJSON_DetachItemViaPointer(cJSON *parent, cJSON *item) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_DetachItemFromArray(cJSON *array, int which) -> CJSON_PUBLIC(cJSON *);
@ -331,7 +331,7 @@ cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
auto
cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool); /* Shifts pre-existing items to the right. */
auto
cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement) -> CJSON_PUBLIC(cJSON_bool);
cJSON_ReplaceItemViaPointer(cJSON *parent, cJSON *item, cJSON *replacement) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool);
@ -351,7 +351,7 @@ cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *);
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
auto
cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive) -> CJSON_PUBLIC(cJSON_bool);
cJSON_Compare(const cJSON *a, const cJSON *b, cJSON_bool case_sensitive) -> CJSON_PUBLIC(cJSON_bool);
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
* The input pointer json cannot point to a read-only address area, such as a string constant,
@ -362,31 +362,31 @@ cJSON_Minify(char *json);
/* Helper functions for creating and adding items to an object at the same time.
* They return the added item or NULL on failure. */
auto
cJSON_AddNullToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *);
cJSON_AddNullToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddTrueToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *);
cJSON_AddTrueToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddFalseToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *);
cJSON_AddFalseToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *);
cJSON_AddBoolToObject(cJSON *object, const char *name, cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number) -> CJSON_PUBLIC(cJSON *);
cJSON_AddNumberToObject(cJSON *object, const char *name, double number) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string) -> CJSON_PUBLIC(cJSON *);
cJSON_AddStringToObject(cJSON *object, const char *name, const char *string) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw) -> CJSON_PUBLIC(cJSON *);
cJSON_AddRawToObject(cJSON *object, const char *name, const char *raw) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddObjectToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *);
cJSON_AddObjectToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddArrayToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *);
cJSON_AddArrayToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))

View File

@ -87,7 +87,7 @@ compare_strings(const unsigned char *string1, const unsigned char *string2, cons
return 0;
}
if (case_sensitive) {
if (case_sensitive != 0) {
return strcmp((const char *) string1, (const char *) string2);
}
@ -103,7 +103,7 @@ compare_strings(const unsigned char *string1, const unsigned char *string2, cons
/* securely comparison of floating-point variables */
static auto compare_double(double a, double b) -> cJSON_bool {
double maxVal = fabs(a) > fabs(b) ? fabs(a) : fabs(b);
return (fabs(a - b) <= maxVal * DBL_EPSILON);
return static_cast<cJSON_bool>(fabs(a - b) <= maxVal * DBL_EPSILON);
}
@ -122,11 +122,10 @@ compare_pointers(const unsigned char *name, const unsigned char *pointer, const
if (((pointer[1] != '0') || (*name != '~')) && ((pointer[1] != '1') || (*name != '/'))) {
/* invalid escape sequence or wrong character in *name */
return false;
} else {
pointer++;
}
} else if ((!case_sensitive && (tolower(*name) != tolower(*pointer))) ||
(case_sensitive && (*name != *pointer))) {
} pointer++;
} else if (((case_sensitive == 0) && (tolower(*name) != tolower(*pointer))) ||
((case_sensitive != 0) && (*name != *pointer))) {
return false;
}
}
@ -190,7 +189,7 @@ cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const
auto *target_pointer = (unsigned char *) cJSONUtils_FindPointerFromObjectTo(current_child, target);
/* found the target? */
if (target_pointer != nullptr) {
if (cJSON_IsArray(object)) {
if (cJSON_IsArray(object) != 0) {
/* reserve enough memory for a 64 bit integer + '/' and '\0' */
auto *full_pointer = (unsigned char *) cJSON_malloc(
strlen((char *) target_pointer) + 20 + sizeof("/"));
@ -209,7 +208,7 @@ cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const
return (char *) full_pointer;
}
if (cJSON_IsObject(object)) {
if (cJSON_IsObject(object) != 0) {
auto *full_pointer = (unsigned char *) cJSON_malloc(strlen((char *) target_pointer) +
pointer_encoded_length(
(unsigned char *) current_child->string) +
@ -234,7 +233,7 @@ cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const
/* non broken version of cJSON_GetArrayItem */
static auto get_array_item(const cJSON *array, size_t item) -> cJSON * {
cJSON *child = array ? array->child : nullptr;
cJSON *child = array != nullptr ? array->child : nullptr;
while ((child != nullptr) && (item > 0)) {
item--;
child = child->next;
@ -275,19 +274,19 @@ static auto get_item_from_pointer(cJSON *const object, const char *pointer, cons
/* follow path of the pointer */
while ((pointer[0] == '/') && (current_element != nullptr)) {
pointer++;
if (cJSON_IsArray(current_element)) {
if (cJSON_IsArray(current_element) != 0) {
size_t index = 0;
if (!decode_array_index_from_pointer((const unsigned char *) pointer, &index)) {
if (decode_array_index_from_pointer((const unsigned char *) pointer, &index) == 0) {
return nullptr;
}
current_element = get_array_item(current_element, index);
} else if (cJSON_IsObject(current_element)) {
} else if (cJSON_IsObject(current_element) != 0) {
current_element = current_element->child;
/* GetObjectItem. */
while ((current_element != nullptr) &&
!compare_pointers((unsigned char *) current_element->string, (const unsigned char *) pointer,
case_sensitive)) {
(compare_pointers((unsigned char *) current_element->string, (const unsigned char *) pointer,
case_sensitive) == 0)) {
current_element = current_element->next;
}
} else {
@ -321,7 +320,7 @@ static void decode_pointer_inplace(unsigned char *string) {
return;
}
for (; *string; (void) decoded_string++, string++) {
for (; *string != 0u; (void) decoded_string++, string++) {
if (string[0] == '~') {
if (string[1] == '0') {
decoded_string[0] = '~';
@ -342,11 +341,11 @@ static void decode_pointer_inplace(unsigned char *string) {
/* non-broken cJSON_DetachItemFromArray */
static auto detach_item_from_array(cJSON *array, size_t which) -> cJSON * {
cJSON *c = array->child;
while (c && (which > 0)) {
while ((c != nullptr) && (which > 0)) {
c = c->next;
which--;
}
if (!c) {
if (c == nullptr) {
/* item doesn't exist */
return nullptr;
}
@ -354,7 +353,7 @@ static auto detach_item_from_array(cJSON *array, size_t which) -> cJSON * {
/* not the first element */
c->prev->next = c->next;
}
if (c->next) {
if (c->next != nullptr) {
c->next->prev = c->prev;
}
if (c == array->child) {
@ -392,13 +391,13 @@ static auto detach_path(cJSON *object, const unsigned char *path, const cJSON_bo
parent = get_item_from_pointer(object, (char *) parent_pointer, case_sensitive);
decode_pointer_inplace(child_pointer);
if (cJSON_IsArray(parent)) {
if (cJSON_IsArray(parent) != 0) {
size_t index = 0;
if (!decode_array_index_from_pointer(child_pointer, &index)) {
if (decode_array_index_from_pointer(child_pointer, &index) == 0) {
goto cleanup;
}
detached_item = detach_item_from_array(parent, index);
} else if (cJSON_IsObject(parent)) {
} else if (cJSON_IsObject(parent) != 0) {
detached_item = cJSON_DetachItemFromObject(parent, (char *) child_pointer);
} else {
/* Couldn't find object to remove child from. */
@ -521,7 +520,7 @@ static auto compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) ->
switch (a->type & 0xFF) {
case cJSON_Number:
/* numeric mismatch. */
if ((a->valueint != b->valueint) || (!compare_double(a->valuedouble, b->valuedouble))) {
if ((a->valueint != b->valueint) || (compare_double(a->valuedouble, b->valuedouble) == 0)) {
return false;
} else {
return true;
@ -538,7 +537,7 @@ static auto compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) ->
case cJSON_Array:
for ((void) (a = a->child), b = b->child; (a != nullptr) && (b != nullptr); (void) (a = a->next), b = b->next) {
cJSON_bool identical = compare_json(a, b, case_sensitive);
if (!identical) {
if (identical == 0) {
return false;
}
}
@ -546,9 +545,8 @@ static auto compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) ->
/* array size mismatch? (one of both children is not NULL) */
if ((a != nullptr) || (b != nullptr)) {
return false;
} else {
return true;
}
} return true;
case cJSON_Object:
sort_object(a, case_sensitive);
@ -556,12 +554,12 @@ static auto compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) ->
for ((void) (a = a->child), b = b->child; (a != nullptr) && (b != nullptr); (void) (a = a->next), b = b->next) {
cJSON_bool identical = false;
/* compare object keys */
if (compare_strings((unsigned char *) a->string, (unsigned char *) b->string, case_sensitive)) {
if (compare_strings((unsigned char *) a->string, (unsigned char *) b->string, case_sensitive) != 0) {
/* missing member */
return false;
}
identical = compare_json(a, b, case_sensitive);
if (!identical) {
if (identical == 0) {
return false;
}
}
@ -569,9 +567,8 @@ static auto compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) ->
/* object length mismatch (one of both children is not null) */
if ((a != nullptr) || (b != nullptr)) {
return false;
} else {
return true;
}
} return true;
default:
break;
@ -584,7 +581,7 @@ static auto compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) ->
/* non broken version of cJSON_InsertItemInArray */
static auto insert_item_in_array(cJSON *array, size_t which, cJSON *newitem) -> cJSON_bool {
cJSON *child = array->child;
while (child && (which > 0)) {
while ((child != nullptr) && (which > 0)) {
child = child->next;
which--;
}
@ -613,7 +610,7 @@ static auto insert_item_in_array(cJSON *array, size_t which, cJSON *newitem) ->
}
static auto get_object_item(const cJSON *const object, const char *name, const cJSON_bool case_sensitive) -> cJSON * {
if (case_sensitive) {
if (case_sensitive != 0) {
return cJSON_GetObjectItemCaseSensitive(object, name);
}
@ -632,7 +629,7 @@ enum patch_operation {
static auto decode_patch_operation(const cJSON *const patch, const cJSON_bool case_sensitive) -> enum patch_operation {
cJSON *operation = get_object_item(patch, "op", case_sensitive);
if (!cJSON_IsString(operation)) {
if (cJSON_IsString(operation) == 0) {
return INVALID;
}
@ -692,7 +689,7 @@ static auto apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case
int status = 0;
path = get_object_item(patch, "path", case_sensitive);
if (!cJSON_IsString(path)) {
if (cJSON_IsString(path) == 0) {
/* malformed patch. */
status = 2;
goto cleanup;
@ -704,8 +701,8 @@ static auto apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case
goto cleanup;
} else if (opcode == TEST) {
/* compare value: {...} with the given path */
status = !compare_json(get_item_from_pointer(object, path->valuestring, case_sensitive),
get_object_item(patch, "value", case_sensitive), case_sensitive);
status = static_cast<int>(compare_json(get_item_from_pointer(object, path->valuestring, case_sensitive),
get_object_item(patch, "value", case_sensitive), case_sensitive)) == 0;
goto cleanup;
}
@ -815,7 +812,7 @@ static auto apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case
/* split pointer in parent and child */
parent_pointer = cJSONUtils_strdup((unsigned char *) path->valuestring);
if (parent_pointer) {
if (parent_pointer != nullptr) {
child_pointer = (unsigned char *) strrchr((char *) parent_pointer, '/');
}
if (child_pointer != nullptr) {
@ -830,25 +827,25 @@ static auto apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case
/* Couldn't find object to add to. */
status = 9;
goto cleanup;
} else if (cJSON_IsArray(parent)) {
} else if (cJSON_IsArray(parent) != 0) {
if (strcmp((char *) child_pointer, "-") == 0) {
cJSON_AddItemToArray(parent, value);
value = nullptr;
} else {
size_t index = 0;
if (!decode_array_index_from_pointer(child_pointer, &index)) {
if (decode_array_index_from_pointer(child_pointer, &index) == 0) {
status = 11;
goto cleanup;
}
if (!insert_item_in_array(parent, index, value)) {
if (insert_item_in_array(parent, index, value) == 0) {
status = 10;
goto cleanup;
}
value = nullptr;
}
} else if (cJSON_IsObject(parent)) {
if (case_sensitive) {
} else if (cJSON_IsObject(parent) != 0) {
if (case_sensitive != 0) {
cJSON_DeleteItemFromObjectCaseSensitive(parent, (char *) child_pointer);
} else {
cJSON_DeleteItemFromObject(parent, (char *) child_pointer);
@ -878,7 +875,7 @@ cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) -> CJSO
const cJSON *current_patch = nullptr;
int status = 0;
if (!cJSON_IsArray(patches)) {
if (cJSON_IsArray(patches) == 0) {
/* malformed patches. */
return 1;
}
@ -903,7 +900,7 @@ cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const pat
const cJSON *current_patch = nullptr;
int status = 0;
if (!cJSON_IsArray(patches)) {
if (cJSON_IsArray(patches) == 0) {
/* malformed patches. */
return 1;
}
@ -976,7 +973,7 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
switch (from->type & 0xFF) {
case cJSON_Number:
if ((from->valueint != to->valueint) || !compare_double(from->valuedouble, to->valuedouble)) {
if ((from->valueint != to->valueint) || (compare_double(from->valuedouble, to->valuedouble) == 0)) {
compose_patch(patches, (const unsigned char *) "replace", path, nullptr, to);
}
return;
@ -1128,22 +1125,22 @@ cJSONUtils_SortObjectCaseSensitive(cJSON *const object) {
static auto merge_patch(cJSON *target, const cJSON *const patch, const cJSON_bool case_sensitive) -> cJSON * {
cJSON *patch_child = nullptr;
if (!cJSON_IsObject(patch)) {
if (cJSON_IsObject(patch) == 0) {
/* scalar value, array or NULL, just duplicate */
cJSON_Delete(target);
return cJSON_Duplicate(patch, 1);
}
if (!cJSON_IsObject(target)) {
if (cJSON_IsObject(target) == 0) {
cJSON_Delete(target);
target = cJSON_CreateObject();
}
patch_child = patch->child;
while (patch_child != nullptr) {
if (cJSON_IsNull(patch_child)) {
if (cJSON_IsNull(patch_child) != 0) {
/* NULL is the indicator to remove a value, see RFC7396 */
if (case_sensitive) {
if (case_sensitive != 0) {
cJSON_DeleteItemFromObjectCaseSensitive(target, patch_child->string);
} else {
cJSON_DeleteItemFromObject(target, patch_child->string);
@ -1152,7 +1149,7 @@ static auto merge_patch(cJSON *target, const cJSON *const patch, const cJSON_boo
cJSON *replace_me = nullptr;
cJSON *replacement = nullptr;
if (case_sensitive) {
if (case_sensitive != 0) {
replace_me = cJSON_DetachItemFromObjectCaseSensitive(target, patch_child->string);
} else {
replace_me = cJSON_DetachItemFromObject(target, patch_child->string);
@ -1189,7 +1186,7 @@ static auto generate_merge_patch(cJSON *const from, cJSON *const to, const cJSON
/* patch to delete everything */
return cJSON_CreateNull();
}
if (!cJSON_IsObject(to) || !cJSON_IsObject(from)) {
if ((cJSON_IsObject(to) == 0) || (cJSON_IsObject(from) == 0)) {
return cJSON_Duplicate(to, 1);
}
@ -1202,7 +1199,7 @@ static auto generate_merge_patch(cJSON *const from, cJSON *const to, const cJSON
if (patch == nullptr) {
return nullptr;
}
while (from_child || to_child) {
while ((from_child != nullptr) || (to_child != nullptr)) {
int diff;
if (from_child != nullptr) {
if (to_child != nullptr) {
@ -1226,7 +1223,7 @@ static auto generate_merge_patch(cJSON *const from, cJSON *const to, const cJSON
to_child = to_child->next;
} else {
/* object key exists in both objects */
if (!compare_json(from_child, to_child, case_sensitive)) {
if (compare_json(from_child, to_child, case_sensitive) == 0) {
/* not identical --> generate a patch */
cJSON_AddItemToObject(patch, to_child->string, cJSONUtils_GenerateMergePatch(from_child, to_child));
}

View File

@ -31,28 +31,28 @@ extern "C" {
/* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */
auto
cJSONUtils_GetPointer(cJSON *const object, const char *pointer) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_GetPointer(cJSON *object, const char *pointer) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_GetPointerCaseSensitive(cJSON *const object, const char *pointer) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_GetPointerCaseSensitive(cJSON *object, const char *pointer) -> CJSON_PUBLIC(cJSON *);
/* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */
/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
auto
cJSONUtils_GeneratePatches(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_GeneratePatches(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_GeneratePatchesCaseSensitive(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_GeneratePatchesCaseSensitive(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
/* Utility for generating patch array entries. */
CJSON_PUBLIC(void)
cJSONUtils_AddPatchToArray(cJSON *const array, const char *const operation, const char *const path,
const cJSON *const value);
cJSONUtils_AddPatchToArray(cJSON *array, const char *operation, const char *path,
const cJSON *value);
/* Returns 0 for success. */
auto
cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) -> CJSON_PUBLIC(int);
cJSONUtils_ApplyPatches(cJSON *object, const cJSON *patches) -> CJSON_PUBLIC(int);
auto
cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const patches) -> CJSON_PUBLIC(int);
cJSONUtils_ApplyPatchesCaseSensitive(cJSON *object, const cJSON *patches) -> CJSON_PUBLIC(int);
/*
// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:
@ -78,28 +78,28 @@ cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const pat
/* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */
/* target will be modified by patch. return value is new ptr for target. */
auto
cJSONUtils_MergePatch(cJSON *target, const cJSON *const patch) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_MergePatch(cJSON *target, const cJSON *patch) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON *const patch) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON *patch) -> CJSON_PUBLIC(cJSON *);
/* generates a patch to move from -> to */
/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
auto
cJSONUtils_GenerateMergePatch(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_GenerateMergePatchCaseSensitive(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *);
cJSONUtils_GenerateMergePatchCaseSensitive(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
/* Given a root object and a target object, construct a pointer from one to the other. */
auto
cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const target) -> CJSON_PUBLIC(char *);
cJSONUtils_FindPointerFromObjectTo(const cJSON *object, const cJSON *target) -> CJSON_PUBLIC(char *);
/* Sorts the members of the object into alphabetical order. */
CJSON_PUBLIC(void)
cJSONUtils_SortObject(cJSON *const object);
cJSONUtils_SortObject(cJSON *object);
CJSON_PUBLIC(void)
cJSONUtils_SortObjectCaseSensitive(cJSON *const object);
cJSONUtils_SortObjectCaseSensitive(cJSON *object);
#ifdef __cplusplus
}

View File

@ -44,17 +44,24 @@ void drawPixel32(int x, int y, RGBAColor color) {
void drawLine(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
int x, y;
int x;
int y;
if (x1 == x2) {
if (y1 < y2)
for (y = y1; y <= y2; y++) drawPixel(x1, y, r, g, b, a);
else
for (y = y2; y <= y1; y++) drawPixel(x1, y, r, g, b, a);
if (y1 < y2) {
for (y = y1; y <= y2; y++) { drawPixel(x1, y, r, g, b, a);
}
} else {
for (y = y2; y <= y1; y++) { drawPixel(x1, y, r, g, b, a);
}
}
} else {
if (x1 < x2)
for (x = x1; x <= x2; x++) drawPixel(x, y1, r, g, b, a);
else
for (x = x2; x <= x1; x++) drawPixel(x, y1, r, g, b, a);
if (x1 < x2) {
for (x = x1; x <= x2; x++) { drawPixel(x, y1, r, g, b, a);
}
} else {
for (x = x2; x <= x1; x++) { drawPixel(x, y1, r, g, b, a);
}
}
}
}
@ -66,7 +73,12 @@ void drawRect(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, uint8_t b, u
}
void drawFillRect(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
int X1, X2, Y1, Y2, i, j;
int X1;
int X2;
int Y1;
int Y2;
int i;
int j;
if (x1 < x2) {
X1 = x1;
@ -109,11 +121,14 @@ void drawCircle(int xCen, int yCen, int radius, uint8_t r, uint8_t g, uint8_t b,
void drawFillCircle(int xCen, int yCen, int radius, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
drawCircle(xCen, yCen, radius, r, g, b, a);
int x, y;
int x;
int y;
for (y = -radius; y <= radius; y++) {
for (x = -radius; x <= radius; x++)
if (x * x + y * y <= radius * radius + radius * .8f)
for (x = -radius; x <= radius; x++) {
if (x * x + y * y <= radius * radius + radius * .8f) {
drawPixel(xCen + x, yCen + y, r, g, b, a);
}
}
}
}
@ -178,14 +193,18 @@ void drawTGA(int x, int y, float scale, uint8_t *fileContent) {
}
void drawRGB5A3(int x, int y, float scale, uint8_t *fileContent) {
uint32_t w = 192, h = 64;
uint32_t nw = w, nh = h;
uint32_t w = 192;
uint32_t h = 64;
uint32_t nw = w;
uint32_t nh = h;
if (scale <= 0) scale = 1;
if (scale <= 0) { scale = 1;
}
nw = w * scale;
nh = h * scale;
uint32_t pos = 0, npos = 0;
uint32_t pos = 0;
uint32_t npos = 0;
RGBAColor color;
auto *pixels = (uint16_t *) fileContent;
@ -195,21 +214,25 @@ void drawRGB5A3(int x, int y, float scale, uint8_t *fileContent) {
for (uint32_t sj = j; sj < (j + sum); sj++, pos++) {
for (uint32_t si = i; si < (i + sum); si++) {
npos = ((si - i) / scale) + ((pos / scale) * 4);
if (pixels[npos] & 0x8000)
if ((pixels[npos] & 0x8000) != 0) {
color.c = ((pixels[npos] & 0x7C00) << 17) | ((pixels[npos] & 0x3E0) << 14) |
((pixels[npos] & 0x1F) << 11) | 0xFF;
else
} else {
color.c = (((pixels[npos] & 0xF00) * 0x11) << 16) | (((pixels[npos] & 0xF0) * 0x11) << 12) |
(((pixels[npos] & 0xF) * 0x11) << 8) | (((pixels[npos] & 0x7000) >> 12) * 0x24);
}
drawPixel32(si, sj, color);
}
}
}
}
if (scale > 0.5) {
if ((x > 0) && (y > 0)) drawRect(x - 1, y - 1, x + nw, y + nh, 255, 255, 255, 128);
if ((x > 1) && (y > 1)) drawRect(x - 2, y - 2, x + nw + 1, y + nh + 1, 255, 255, 255, 128);
if ((x > 2) && (y > 2)) drawRect(x - 3, y - 3, x + nw + 2, y + nh + 2, 255, 255, 255, 128);
if ((x > 0) && (y > 0)) { drawRect(x - 1, y - 1, x + nw, y + nh, 255, 255, 255, 128);
}
if ((x > 1) && (y > 1)) { drawRect(x - 2, y - 2, x + nw + 1, y + nh + 1, 255, 255, 255, 128);
}
if ((x > 2) && (y > 2)) { drawRect(x - 3, y - 3, x + nw + 2, y + nh + 2, 255, 255, 255, 128);
}
}
}
@ -217,9 +240,10 @@ void drawBackgroundDRC(uint32_t w, uint32_t h, uint8_t *out) {
uint32_t *screen2 = nullptr;
int otherBuff1 = drcBufferSize / 2;
if (cur_buf1) screen2 = (uint32_t *) scrBuffer + tvBufferSize + otherBuff1;
else
if (cur_buf1) { screen2 = (uint32_t *) scrBuffer + tvBufferSize + otherBuff1;
} else {
screen2 = (uint32_t *) scrBuffer + tvBufferSize;
}
memcpy(screen2, out, w * h * 4);
}
@ -227,7 +251,8 @@ void drawBackgroundTV(uint32_t w, uint32_t h, uint8_t *out) {
auto *screen1 = (uint32_t *) scrBuffer;
int otherBuff0 = tvBufferSize / 2;
if (cur_buf1) screen1 = (uint32_t *) scrBuffer + otherBuff0;
if (cur_buf1) { screen1 = (uint32_t *) scrBuffer + otherBuff0;
}
memcpy(screen1, out, w * h * 4);
}

View File

@ -6,13 +6,12 @@ auto doit(char *text) -> char * {
cJSON *str;
json = cJSON_Parse(text);
if (!json)
if (json == nullptr) {
return (char*)"";
else {
str = cJSON_GetObjectItemCaseSensitive(json, "Date");
} str = cJSON_GetObjectItemCaseSensitive(json, "Date");
out = strdup(str->valuestring);
return out;
}
}
/* Read a file, parse, render back, etc. */
@ -51,11 +50,10 @@ auto getFilesize(FILE *fp) -> long {
auto getSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot) -> char * {
char path[PATH_SIZE];
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u/savemiiMeta.json", highID, lowID, slot);
if (checkEntry(path)) {
if (checkEntry(path) != 0) {
char *info = dofile(path);
return info;
} else
return (char*)"";
} return (char*)"";
}
auto setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) -> bool {
@ -63,8 +61,9 @@ auto setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) -> b
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u/savemiiMeta.json", highID, lowID, slot);
cJSON *config = cJSON_CreateObject();
if (config == nullptr)
if (config == nullptr) {
return false;
}
cJSON *entry = cJSON_CreateString(date);
if (entry == nullptr) {
@ -75,12 +74,14 @@ auto setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) -> b
char *configString = cJSON_Print(config);
cJSON_Delete(config);
if (configString == nullptr)
if (configString == nullptr) {
return false;
}
FILE *fp = fopen(path, "wb");
if (fp == nullptr)
if (fp == nullptr) {
return false;
}
fwrite(configString, strlen(configString), 1, fp);

View File

@ -53,12 +53,12 @@ void drawPixel(int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
auto initScreen() -> uint32_t {
MEMHeapHandle heap = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM1);
if (frameBufferTVSize) {
if (frameBufferTVSize != 0u) {
frameBufferTVFrontPtr = (uint8_t *) MEMAllocFromFrmHeapEx(heap, frameBufferTVSize, 4);
frameBufferTVBackPtr = (uint8_t *) frameBufferTVFrontPtr + (1 * (1280 * 720 * 4));
}
if (frameBufferDRCSize) {
if (frameBufferDRCSize != 0u) {
frameBufferDRCFrontPtr = (uint8_t *) MEMAllocFromFrmHeapEx(heap, frameBufferDRCSize, 4);
frameBufferDRCBackPtr = (uint8_t *) frameBufferDRCFrontPtr + (1 * (896 * 480 * 4));
}
@ -119,37 +119,47 @@ void WHBLogFreetypeFree() {
auto ttfPrintString(int x, int y, char *string, bool wWrap, bool ceroX) -> int {
FT_GlyphSlot slot = fontFace->glyph;
FT_Error error;
int pen_x = x, pen_y = y;
int pen_x = x;
int pen_y = y;
FT_UInt previous_glyph;
while (*string) {
while (*string != 0) {
uint32_t buf = *string++;
if ((buf >> 6) == 3) {
if ((buf & 0xF0) == 0xC0) {
uint8_t b1 = buf & 0xFF, b2 = *string++;
if ((b2 & 0xC0) == 0x80) b2 &= 0x3F;
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
buf = ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xD0) {
uint8_t b1 = buf & 0xFF, b2 = *string++;
if ((b2 & 0xC0) == 0x80) b2 &= 0x3F;
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
buf = 0x400 | ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xE0) {
uint8_t b1 = buf & 0xFF, b2 = *string++, b3 = *string++;
if ((b2 & 0xC0) == 0x80) b2 &= 0x3F;
if ((b3 & 0xC0) == 0x80) b3 &= 0x3F;
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
uint8_t b3 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
if ((b3 & 0xC0) == 0x80) { b3 &= 0x3F;
}
buf = ((b1 & 0xF) << 12) | (b2 << 6) | b3;
}
} else if (buf & 0x80) {
} else if ((buf & 0x80) != 0u) {
string++;
continue;
}
if (buf == '\n') {
pen_y += (fontFace->size->metrics.height >> 6);
if (ceroX) pen_x = 0;
else
if (ceroX) { pen_x = 0;
} else {
pen_x = x;
}
continue;
}
@ -164,19 +174,22 @@ auto ttfPrintString(int x, int y, char *string, bool wWrap, bool ceroX) -> int {
}
error = FT_Load_Glyph(fontFace, glyph_index, FT_LOAD_DEFAULT);
if (error)
if (error) {
continue;
}
error = FT_Render_Glyph(fontFace->glyph, FT_RENDER_MODE_NORMAL);
if (error)
if (error) {
continue;
}
if ((pen_x + (slot->advance.x >> 6)) > 853) {
if (wWrap) {
pen_y += (fontFace->size->metrics.height >> 6);
if (ceroX) pen_x = 0;
else
if (ceroX) { pen_x = 0;
} else {
pen_x = x;
}
} else {
return pen_x;
}
@ -193,27 +206,37 @@ auto ttfPrintString(int x, int y, char *string, bool wWrap, bool ceroX) -> int {
auto ttfStringWidth(char *string, int8_t part) -> int {
FT_GlyphSlot slot = fontFace->glyph;
FT_Error error;
int pen_x = 0, max_x = 0, spart = 1;
int pen_x = 0;
int max_x = 0;
int spart = 1;
FT_UInt previous_glyph;
while (*string) {
while (*string != 0) {
uint32_t buf = *string++;
if ((buf >> 6) == 3) {
if ((buf & 0xF0) == 0xC0) {
uint8_t b1 = buf & 0xFF, b2 = *string++;
if ((b2 & 0xC0) == 0x80) b2 &= 0x3F;
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
buf = ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xD0) {
uint8_t b1 = buf & 0xFF, b2 = *string++;
if ((b2 & 0xC0) == 0x80) b2 &= 0x3F;
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
buf = 0x400 | ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xE0) {
uint8_t b1 = buf & 0xFF, b2 = *string++, b3 = *string++;
if ((b2 & 0xC0) == 0x80) b2 &= 0x3F;
if ((b3 & 0xC0) == 0x80) b3 &= 0x3F;
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
uint8_t b3 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
if ((b3 & 0xC0) == 0x80) { b3 &= 0x3F;
}
buf = ((b1 & 0xF) << 12) | (b2 << 6) | b3;
}
} else if (buf & 0x80) {
} else if ((buf & 0x80) != 0u) {
string++;
continue;
}
@ -229,8 +252,10 @@ auto ttfStringWidth(char *string, int8_t part) -> int {
if (buf == '\n') {
if (part != 0) {
if ((part > 0) && (spart == part)) return pen_x;
if (part == -2) max_x = max1(pen_x, max_x);
if ((part > 0) && (spart == part)) { return pen_x;
}
if (part == -2) { max_x = max1(pen_x, max_x);
}
pen_x = 0;
spart++;
}
@ -238,13 +263,15 @@ auto ttfStringWidth(char *string, int8_t part) -> int {
}
error = FT_Load_Glyph(fontFace, glyph_index, FT_LOAD_BITMAP_METRICS_ONLY);
if (error)
if (error) {
continue;
}
pen_x += (slot->advance.x >> 6);
previous_glyph = glyph_index;
}
if (spart < part) pen_x = 0;
if (spart < part) { pen_x = 0;
}
return max1(pen_x, max_x);
}

View File

@ -30,19 +30,24 @@ int titleSort(const void *c1, const void *c2) {
return strcmp(((Title *) c1)->shortName, ((Title *) c2)->shortName) * sorta;
case 2:
if (((Title *) c1)->isTitleOnUSB == ((Title *) c2)->isTitleOnUSB)
if (((Title *) c1)->isTitleOnUSB == ((Title *) c2)->isTitleOnUSB) {
return 0;
if (((Title *) c1)->isTitleOnUSB)
}
if (((Title *) c1)->isTitleOnUSB) {
return -1 * sorta;
if (((Title *) c2)->isTitleOnUSB)
}
if (((Title *) c2)->isTitleOnUSB) {
return 1 * sorta;
}
return 0;
case 3:
if (((Title *) c1)->isTitleOnUSB && !((Title *) c2)->isTitleOnUSB)
if (((Title *) c1)->isTitleOnUSB && !((Title *) c2)->isTitleOnUSB) {
return -1 * sorta;
if (!((Title *) c1)->isTitleOnUSB && ((Title *) c2)->isTitleOnUSB)
}
if (!((Title *) c1)->isTitleOnUSB && ((Title *) c2)->isTitleOnUSB) {
return 1 * sorta;
}
return strcmp(((Title *) c1)->shortName, ((Title *) c2)->shortName) * sorta;
@ -75,9 +80,10 @@ Title *loadWiiUTitles(int run) {
return nullptr;
}
int usable = receivedCount, j = 0;
int usable = receivedCount;
int j = 0;
Saves *savesl = (Saves *) malloc(receivedCount * sizeof(Saves));
if (!savesl) {
if (savesl == nullptr) {
promptError("Out of memory.");
return nullptr;
}
@ -89,13 +95,15 @@ Title *loadWiiUTitles(int run) {
continue;
}
savesl[j].lowID = *(uint32_t * )(element + 4);
savesl[j].dev = !(memcmp(element + 0x56, "usb", 4) == 0);
savesl[j].dev = static_cast<uint8_t>(!(memcmp(element + 0x56, "usb", 4) == 0));
savesl[j].found = false;
j++;
}
savesl = (Saves *) realloc(savesl, usable * sizeof(Saves));
int foundCount = 0, pos = 0, tNoSave = usable;
int foundCount = 0;
int pos = 0;
int tNoSave = usable;
for (int i = 0; i <= 1; i++) {
for (uint8_t a = 0; a < 2; a++) {
char path[255];
@ -104,8 +112,9 @@ Title *loadWiiUTitles(int run) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.')
if (data->d_name[0] == '.') {
continue;
}
sprintf(path, "%s:/usr/save/%s/%s/user", (i == 0) ? "usb" : "mlc", highIDs[a], data->d_name);
if (checkEntry(path) == 2) {
@ -131,7 +140,7 @@ Title *loadWiiUTitles(int run) {
foundCount += tNoSave;
Saves *saves = (Saves *) malloc((foundCount + tNoSave) * sizeof(Saves));
if (!saves) {
if (saves == nullptr) {
promptError("Out of memory.");
return nullptr;
}
@ -144,8 +153,9 @@ Title *loadWiiUTitles(int run) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.')
if (data->d_name[0] == '.') {
continue;
}
sprintf(path, "%s:/usr/save/%s/%s/meta/meta.xml", (i == 0) ? "usb" : "mlc", highIDs[a],
data->d_name);
@ -173,14 +183,15 @@ Title *loadWiiUTitles(int run) {
}
Title *titles = (Title *) malloc(foundCount * sizeof(Title));
if (!titles) {
if (titles == nullptr) {
promptError("Out of memory.");
return nullptr;
}
for (int i = 0; i < foundCount; i++) {
uint32_t highID = saves[i].highID, lowID = saves[i].lowID;
bool isTitleOnUSB = !saves[i].dev;
uint32_t highID = saves[i].highID;
uint32_t lowID = saves[i].lowID;
bool isTitleOnUSB = saves[i].dev == 0u;
char path[255];
sprintf(path, "%s:/usr/%s/%08x/%08x/meta/meta.xml", isTitleOnUSB ? "usb" : "mlc",
@ -195,14 +206,16 @@ Title *loadWiiUTitles(int run) {
cptr = strchr(strstr(xmlBuf, "shortname_en"), '>') + 1;
memset(titles[titleswiiu].shortName, 0, sizeof(titles[titleswiiu].shortName));
if (strcspn(cptr, "<") == 0)
if (strcspn(cptr, "<") == 0) {
cptr = strchr(strstr(xmlBuf, "shortname_ja"), '>') + 1;
}
strncpy(titles[titleswiiu].shortName, cptr, strcspn(cptr, "<"));
cptr = strchr(strstr(xmlBuf, "longname_en"), '>') + 1;
memset(titles[i].longName, 0, sizeof(titles[i].longName));
if (strcspn(cptr, "<") == 0)
if (strcspn(cptr, "<") == 0) {
cptr = strchr(strstr(xmlBuf, "longname_ja"), '>') + 1;
}
strncpy(titles[titleswiiu].longName, cptr, strcspn(cptr, "<"));
free(xmlBuf);
@ -222,7 +235,8 @@ Title *loadWiiUTitles(int run) {
titles[titleswiiu].lowID = lowID;
titles[titleswiiu].isTitleOnUSB = isTitleOnUSB;
titles[titleswiiu].listID = titleswiiu;
if (loadTitleIcon(&titles[titleswiiu]) < 0) titles[titleswiiu].iconBuf = nullptr;
if (loadTitleIcon(&titles[titleswiiu]) < 0) { titles[titleswiiu].iconBuf = nullptr;
}
titleswiiu++;
OSScreenClearBufferEx(SCREEN_TV, 0);
@ -277,10 +291,11 @@ Title *loadWiiTitles() {
closedir(dir);
}
}
if (titlesvwii == 0) return nullptr;
if (titlesvwii == 0) { return nullptr;
}
Title *titles = (Title *) malloc(titlesvwii * sizeof(Title));
if (!titles) {
if (titles == nullptr) {
promptError("Out of memory.");
return nullptr;
}
@ -311,13 +326,13 @@ Title *loadWiiTitles() {
if (file != nullptr) {
fseek(file, 0x20, SEEK_SET);
uint16_t *bnrBuf = (uint16_t *) malloc(0x80);
if (bnrBuf) {
if (bnrBuf != nullptr) {
fread(bnrBuf, 0x02, 0x20, file);
memset(titles[i].shortName, 0, sizeof(titles[i].shortName));
for (int j = 0, k = 0; j < 0x20; j++) {
if (bnrBuf[j] < 0x80)
if (bnrBuf[j] < 0x80) {
titles[i].shortName[k++] = (char) bnrBuf[j];
else if ((bnrBuf[j] & 0xF000) > 0) {
} else if ((bnrBuf[j] & 0xF000) > 0) {
titles[i].shortName[k++] = 0xE0 | ((bnrBuf[j] & 0xF000) >> 12);
titles[i].shortName[k++] = 0x80 | ((bnrBuf[j] & 0xFC0) >> 6);
titles[i].shortName[k++] = 0x80 | (bnrBuf[j] & 0x3F);
@ -332,9 +347,9 @@ Title *loadWiiTitles() {
memset(titles[i].longName, 0, sizeof(titles[i].longName));
for (int j = 0x20, k = 0; j < 0x40; j++) {
if (bnrBuf[j] < 0x80)
if (bnrBuf[j] < 0x80) {
titles[i].longName[k++] = (char) bnrBuf[j];
else if ((bnrBuf[j] & 0xF000) > 0) {
} else if ((bnrBuf[j] & 0xF000) > 0) {
titles[i].longName[k++] = 0xE0 | ((bnrBuf[j] & 0xF000) >> 12);
titles[i].longName[k++] = 0x80 | ((bnrBuf[j] & 0xFC0) >> 6);
titles[i].longName[k++] = 0x80 | (bnrBuf[j] & 0x3F);
@ -363,13 +378,15 @@ Title *loadWiiTitles() {
titles[i].listID = i;
memcpy(titles[i].productCode, &titles[i].lowID, 4);
for (int ii = 0; ii < 4; ii++) {
if (titles[i].productCode[ii] == 0) titles[i].productCode[ii] = '.';
if (titles[i].productCode[ii] == 0) { titles[i].productCode[ii] = '.';
}
}
titles[i].productCode[4] = 0;
titles[i].isTitleOnUSB = false;
titles[i].isTitleDupe = false;
titles[i].dupeID = 0;
if (!titles[i].saveInit || (loadTitleIcon(&titles[i]) < 0)) titles[i].iconBuf = nullptr;
if (!titles[i].saveInit || (loadTitleIcon(&titles[i]) < 0)) { titles[i].iconBuf = nullptr;
}
i++;
OSScreenClearBufferEx(SCREEN_TV, 0);
@ -390,9 +407,11 @@ Title *loadWiiTitles() {
void unloadTitles(Title *titles, int count) {
for (int i = 0; i < count; i++) {
if (titles[i].iconBuf) free(titles[i].iconBuf);
if (titles[i].iconBuf != nullptr) { free(titles[i].iconBuf);
}
}
if (titles) free(titles);
if (titles != nullptr) { free(titles);
}
}
/* Entry point */
@ -435,7 +454,10 @@ int main(void) {
uint8_t *tgaBufDRC = nullptr;
uint8_t *tgaBufTV = nullptr;
uint32_t wDRC = 0, hDRC = 0, wTV = 0, hTV = 0;
uint32_t wDRC = 0;
uint32_t hDRC = 0;
uint32_t wTV = 0;
uint32_t hTV = 0;
KPADStatus kpad_status;
VPADStatus vpad_status;
VPADReadError vpad_error;
@ -452,8 +474,8 @@ int main(void) {
else
OSScreenClearBufferEx(SCREEN_TV, 0x00006F00);
Title *titles = mode ? wiititles : wiiutitles;
int count = mode ? titlesvwii : titleswiiu;
Title *titles = mode != 0 ? wiititles : wiiutitles;
int count = mode != 0 ? titlesvwii : titleswiiu;
if (redraw) {
console_print_pos(0, 0, "SaveMii v%u.%u.%u", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);
@ -487,27 +509,33 @@ int main(void) {
(tsort > 0) ? ((sorta == 1) ? "\u2193 \ue083" : "\u2191 \ue083") : "");
entrycount = count;
for (int i = 0; i < 14; i++) {
if (i + scroll < 0 || i + scroll >= count) break;
if (i + scroll < 0 || i + scroll >= count) { break;
}
ttfFontColor32(0x00FF00FF);
if (!titles[i + scroll].saveInit) ttfFontColor32(0xFFFF00FF);
if (strcmp(titles[i + scroll].shortName, "DONT TOUCH ME") == 0) ttfFontColor32(0xFF0000FF);
if (strlen(titles[i + scroll].shortName))
if (!titles[i + scroll].saveInit) { ttfFontColor32(0xFFFF00FF);
}
if (strcmp(titles[i + scroll].shortName, "DONT TOUCH ME") == 0) { ttfFontColor32(0xFF0000FF);
}
if (strlen(titles[i + scroll].shortName) != 0u) {
console_print_pos(M_OFF, i + 2, " %s %s%s%s", titles[i + scroll].shortName,
titles[i + scroll].isTitleOnUSB ? "(USB)" : ((mode == 0) ? "(NAND)"
: ""),
titles[i + scroll].isTitleDupe ? " [D]" : "",
titles[i + scroll].saveInit ? "" : " [Not Init]");
else
} else {
console_print_pos(M_OFF, i + 2, " %08lx%08lx", titles[i + scroll].highID,
titles[i + scroll].lowID);
}
ttfFontColor32(0xFFFFFFFF);
if (mode == 0) {
if (titles[i + scroll].iconBuf)
if (titles[i + scroll].iconBuf != nullptr) {
drawTGA((M_OFF + 4) * 12 - 2, (i + 3) * 24, 0.18, titles[i + scroll].iconBuf);
}
} else if (mode == 1) {
if (titles[i + scroll].iconBuf)
if (titles[i + scroll].iconBuf != nullptr) {
drawRGB5A3((M_OFF + 2) * 12 - 2, (i + 3) * 24 + 3, 0.25,
titles[i + scroll].iconBuf);
}
}
}
if (mode == 0) {
@ -520,7 +548,7 @@ int main(void) {
}
break;
case 2: { // Select Task
entrycount = 3 + 2 * (mode == 0) + 1 * ((mode == 0) && (titles[targ].isTitleDupe));
entrycount = 3 + 2 * static_cast<int>(mode == 0) + 1 * static_cast<int>((mode == 0) && (titles[targ].isTitleDupe));
console_print_pos(M_OFF, 2, " [%08X-%08X] [%s]", titles[targ].highID, titles[targ].lowID,
titles[targ].productCode);
console_print_pos(M_OFF, 3, " %s", titles[targ].shortName);
@ -534,9 +562,11 @@ int main(void) {
console_print_pos(M_OFF, 10, " Copy Savedata to Title in %s",
titles[targ].isTitleOnUSB ? "NAND" : "USB");
}
if (titles[targ].iconBuf) drawTGA(660, 80, 1, titles[targ].iconBuf);
if (titles[targ].iconBuf != nullptr) { drawTGA(660, 80, 1, titles[targ].iconBuf);
}
} else if (mode == 1) {
if (titles[targ].iconBuf) drawRGB5A3(650, 80, 1, titles[targ].iconBuf);
if (titles[targ].iconBuf != nullptr) { drawRGB5A3(650, 80, 1, titles[targ].iconBuf);
}
}
console_print_pos(M_OFF, 2 + 3 + cursor, "\u2192");
console_print_pos_aligned(17, 4, 2, "\ue000: Select Task \ue001: Back");
@ -553,7 +583,7 @@ int main(void) {
} else if (task > 2) {
entrycount = 2;
console_print_pos(M_OFF, 4, "Select %s:", "version");
console_print_pos(M_OFF, 5, " < v%u >", versionList ? versionList[slot] : 0);
console_print_pos(M_OFF, 5, " < v%u >", versionList != nullptr ? versionList[slot] : 0);
} else if (task == 2) {
console_print_pos(M_OFF, 4, "Delete from:");
console_print_pos(M_OFF, 5, " (%s)", titles[targ].isTitleOnUSB ? "USB" : "NAND");
@ -576,24 +606,26 @@ int main(void) {
if (!isSlotEmpty(titles[targ].highID, titles[targ].lowID, slot)) {
entrycount++;
console_print_pos(M_OFF, 7, "Select SD user to copy from:");
if (sdusers == -1)
if (sdusers == -1) {
console_print_pos(M_OFF, 8, " < %s >", "all users");
else
} else {
console_print_pos(M_OFF, 8, " < %s > (%s)", sdacc[sdusers].persistentID,
hasAccountSave(&titles[targ], true, false, sdacc[sdusers].pID,
slot, 0) ? "Has Save" : "Empty");
}
}
}
if (task == 2) {
console_print_pos(M_OFF, 7, "Select Wii U user to delete from:");
if (allusers == -1)
if (allusers == -1) {
console_print_pos(M_OFF, 8, " < %s >", "all users");
else
} else {
console_print_pos(M_OFF, 8, " < %s (%s) > (%s)", wiiuacc[allusers].miiName,
wiiuacc[allusers].persistentID,
hasAccountSave(&titles[targ], false, false, wiiuacc[allusers].pID,
slot, 0) ? "Has Save" : "Empty");
}
}
if ((task == 0) || (task == 1) || (task == 5)) {
@ -602,43 +634,46 @@ int main(void) {
} else {
console_print_pos(M_OFF, (task == 1) ? 10 : 7, "Select Wii U user%s:",
(task == 5) ? " to copy from" : ((task == 1) ? " to copy to" : ""));
if (allusers == -1)
if (allusers == -1) {
console_print_pos(M_OFF, (task == 1) ? 11 : 8, " < %s >", "all users");
else
} else {
console_print_pos(M_OFF, (task == 1) ? 11 : 8, " < %s (%s) > (%s)",
wiiuacc[allusers].miiName, wiiuacc[allusers].persistentID,
hasAccountSave(&titles[targ],
((task == 0) || (task == 1) || (task == 5) ? false
: true),
((task < 3) || (task == 5) ? false : true),
(!((task == 0) || (task == 1) || (task == 5))),
(!((task < 3) || (task == 5))),
wiiuacc[allusers].pID, slot,
versionList ? versionList[slot] : 0) ? "Has Save"
versionList != nullptr ? versionList[slot] : 0) ? "Has Save"
: "Empty");
}
}
}
if ((task == 0) || (task == 1))
if (!isSlotEmpty(titles[targ].highID, titles[targ].lowID, slot))
if ((task == 0) || (task == 1)) {
if (!isSlotEmpty(titles[targ].highID, titles[targ].lowID, slot)) {
console_print_pos(M_OFF, 15, "Date: %s",
getSlotDate(titles[targ].highID, titles[targ].lowID, slot));
}
}
if (task == 5) {
entrycount++;
console_print_pos(M_OFF, 10, "Select Wii U user%s:", (task == 5) ? " to copy to" : "");
if (allusers_d == -1)
if (allusers_d == -1) {
console_print_pos(M_OFF, 11, " < %s >", "all users");
else
} else {
console_print_pos(M_OFF, 11, " < %s (%s) > (%s)", wiiuacc[allusers_d].miiName,
wiiuacc[allusers_d].persistentID,
hasAccountSave(&titles[titles[targ].dupeID], false, false,
wiiuacc[allusers_d].pID, 0, 0) ? "Has Save" : "Empty");
}
}
if ((task != 3) && (task != 4)) {
if (allusers > -1) {
if (hasCommonSave(&titles[targ],
((task == 0) || (task == 2) || (task == 5) ? false : true),
((task < 3) || (task == 5) ? false : true), slot,
versionList ? versionList[slot] : 0)) {
(!((task == 0) || (task == 2) || (task == 5))),
(!((task < 3) || (task == 5))), slot,
versionList != nullptr ? versionList[slot] : 0)) {
console_print_pos(M_OFF, (task == 1) || (task == 5) ? 13 : 10,
"Include 'common' save?");
console_print_pos(M_OFF, (task == 1) || (task == 5) ? 14 : 11, " < %s >",
@ -654,7 +689,7 @@ int main(void) {
entrycount--;
}
} else {
if (hasCommonSave(&titles[targ], true, true, slot, versionList ? versionList[slot] : 0)) {
if (hasCommonSave(&titles[targ], true, true, slot, versionList != nullptr ? versionList[slot] : 0)) {
console_print_pos(M_OFF, 7, "Include 'common' save?");
console_print_pos(M_OFF, 8, " < %s >", common ? "yes" : "no ");
} else {
@ -665,13 +700,16 @@ int main(void) {
}
console_print_pos(M_OFF, 5 + cursor * 3, "\u2192");
if (titles[targ].iconBuf) drawTGA(660, 100, 1, titles[targ].iconBuf);
if (titles[targ].iconBuf != nullptr) { drawTGA(660, 100, 1, titles[targ].iconBuf);
}
} else if (mode == 1) {
entrycount = 1;
if (titles[targ].iconBuf) drawRGB5A3(650, 100, 1, titles[targ].iconBuf);
if (!isSlotEmpty(titles[targ].highID, titles[targ].lowID, slot))
if (titles[targ].iconBuf != nullptr) { drawRGB5A3(650, 100, 1, titles[targ].iconBuf);
}
if (!isSlotEmpty(titles[targ].highID, titles[targ].lowID, slot)) {
console_print_pos(M_OFF, 15, "Date: %s",
getSlotDate(titles[targ].highID, titles[targ].lowID, slot));
}
}
switch (task) {
@ -718,33 +756,34 @@ int main(void) {
}
}
if (vpad_status.trigger | kpad_status.trigger | kpad_status.classic.trigger | kpad_status.pro.trigger)
if (vpad_status.trigger | kpad_status.trigger | kpad_status.classic.trigger | kpad_status.pro.trigger) {
redraw = true;
}
if ((vpad_status.trigger & (VPAD_BUTTON_DOWN | VPAD_STICK_L_EMULATION_DOWN)) |
(kpad_status.trigger & (WPAD_BUTTON_DOWN)) |
(kpad_status.classic.trigger & (WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_STICK_L_EMULATION_DOWN)) |
(kpad_status.pro.trigger & (WPAD_PRO_BUTTON_DOWN | WPAD_PRO_STICK_L_EMULATION_DOWN))) {
if (entrycount <= 14) cursor = (cursor + 1) % entrycount;
else if (cursor < 6)
if (entrycount <= 14) { cursor = (cursor + 1) % entrycount;
} else if (cursor < 6) {
cursor++;
else if ((cursor + scroll + 1) % entrycount)
} else if (((cursor + scroll + 1) % entrycount) != 0) {
scroll++;
else
} else {
cursor = scroll = 0;
sleep(0.1);
}
} else if ((vpad_status.trigger & (VPAD_BUTTON_UP | VPAD_STICK_L_EMULATION_UP)) |
(kpad_status.trigger & (WPAD_BUTTON_UP)) |
(kpad_status.classic.trigger & (WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_STICK_L_EMULATION_UP)) |
(kpad_status.pro.trigger & (WPAD_PRO_BUTTON_UP | WPAD_PRO_STICK_L_EMULATION_UP))) {
if (scroll > 0) cursor -= (cursor > 6) ? 1 : 0 * (scroll--);
else if (cursor > 0)
if (scroll > 0) { cursor -= (cursor > 6) ? 1 : 0 * (scroll--);
} else if (cursor > 0) {
cursor--;
else if (entrycount > 14)
} else if (entrycount > 14) {
scroll = entrycount - (cursor = 6) - 1;
else
} else {
cursor = entrycount - 1;
sleep(0.1);
}
}
if ((vpad_status.trigger & (VPAD_BUTTON_LEFT | VPAD_STICK_L_EMULATION_LEFT)) |
@ -820,7 +859,6 @@ int main(void) {
}
}
}
sleep(0.1);
} else if ((vpad_status.trigger & (VPAD_BUTTON_RIGHT | VPAD_STICK_L_EMULATION_RIGHT)) |
(kpad_status.trigger & (WPAD_BUTTON_RIGHT)) |
(kpad_status.classic.trigger & (WPAD_CLASSIC_BUTTON_RIGHT | WPAD_CLASSIC_STICK_L_EMULATION_RIGHT)) |
@ -894,7 +932,6 @@ int main(void) {
}
}
}
sleep(0.1);
}
if ((vpad_status.trigger & VPAD_BUTTON_R) | (kpad_status.trigger & (WPAD_BUTTON_PLUS)) |
@ -916,7 +953,8 @@ int main(void) {
qsort(titles, count, sizeof(Title), titleSort);
} else if (menu == 2) {
targ--;
if (targ < 0) targ = count - 1;
if (targ < 0) { targ = count - 1;
}
}
}
@ -928,18 +966,17 @@ int main(void) {
if (menu < 3) {
if (menu == 0) {
mode = cursor;
if (mode == 0 && (!wiiutitles || !titleswiiu)) {
if (mode == 0 && ((wiiutitles == nullptr) || (titleswiiu == 0))) {
promptError("No Wii U titles found.");
continue;
}
if (mode == 1 && (!wiititles || !titlesvwii)) {
if (mode == 1 && ((wiititles == nullptr) || (titlesvwii == 0))) {
promptError("No vWii saves found.");
continue;
}
}
if (menu == 1) {
sleep(0.1);
targ = cursor + scroll;
cursorb = cursor;
scrollb = scroll;
@ -960,28 +997,26 @@ int main(void) {
}
continue;
}
if (titles[targ].highID == 0 || titles[targ].lowID == 0) continue;
if (titles[targ].highID == 0 || titles[targ].lowID == 0) { continue;
}
if ((mode == 0) && (strcmp(titles[targ].shortName, "DONT TOUCH ME") == 0)) {
if (!promptConfirm(ST_ERROR, "CBHC save. Could be dangerous to modify. Continue?") ||
!promptConfirm(ST_WARNING, "Are you REALLY sure?")) {
sleep(0.1);
continue;
}
}
char path[255];
sprintf(path, "%s:/usr/title/000%x/%x/code/fw.img",
(titles[targ].isTitleOnUSB == true) ? "usb" : "mlc", titles[targ].highID,
(titles[targ].isTitleOnUSB) ? "usb" : "mlc", titles[targ].highID,
titles[targ].lowID);
if ((mode == 0) && checkEntry(path)) {
if ((mode == 0) && (checkEntry(path) != 0)) {
if (!promptConfirm(ST_ERROR, "vWii saves are in the vWii section. Continue?")) {
sleep(0.1);
continue;
}
}
if ((mode == 0) && (!titles[targ].saveInit)) {
if (!promptConfirm(ST_WARNING, "Recommended to run Game at least one time. Continue?") ||
!promptConfirm(ST_WARNING, "Are you REALLY sure?")) {
sleep(0.1);
continue;
}
}
@ -1014,7 +1049,8 @@ int main(void) {
if ((task == 3) || (task == 4)) {
char gamePath[PATH_SIZE];
memset(versionList, 0, 0x100 * sizeof(int));
if (getLoadiineGameSaveDir(gamePath, titles[targ].productCode) != 0) continue;
if (getLoadiineGameSaveDir(gamePath, titles[targ].productCode) != 0) { continue;
}
getLoadiineSaveVersionList(versionList, gamePath);
if (task == 4) {
if (!titles[targ].saveInit) {
@ -1045,10 +1081,10 @@ int main(void) {
wipeSavedata(&titles[targ], allusers, common);
break;
case 3:
importFromLoadiine(&titles[targ], common, versionList ? versionList[slot] : 0);
importFromLoadiine(&titles[targ], common, versionList != nullptr ? versionList[slot] : 0);
break;
case 4:
exportToLoadiine(&titles[targ], common, versionList ? versionList[slot] : 0);
exportToLoadiine(&titles[targ], common, versionList != nullptr ? versionList[slot] : 0);
break;
case 5:
for (int i = 0; i < count; i++) {
@ -1071,7 +1107,8 @@ int main(void) {
cursor = cursorb;
scroll = scrollb;
}
if (menu == 2) cursor = cursort;
if (menu == 2) { cursor = cursort;
}
}
}

View File

@ -47,9 +47,9 @@ void show_file_operation(const char *file_name, const char *file_src, const char
}
int FSAR(int result) {
if ((result & 0xFFFF0000) == 0xFFFC0000)
if ((result & 0xFFFF0000) == 0xFFFC0000) {
return (result & 0xFFFF) | 0xFFFF0000;
else
}
return result;
}
@ -62,11 +62,12 @@ int32_t loadFile(const char *fPath, uint8_t **buf) {
int size = st.st_size;
*buf = (uint8_t *) malloc(size);
if (*buf) {
if (fread(*buf, size, 1, file) == 1)
if (*buf != nullptr) {
if (fread(*buf, size, 1, file) == 1) {
ret = size;
else
free(*buf);
} else {
free(*buf);
}
}
fclose(file);
}
@ -89,11 +90,12 @@ int32_t loadFilePart(const char *fPath, uint32_t start, uint32_t size, uint8_t *
}
*buf = (uint8_t *) malloc(size);
if (*buf) {
if (fread(*buf, size, 1, file) == 1)
if (*buf != nullptr) {
if (fread(*buf, size, 1, file) == 1) {
ret = size;
else
free(*buf);
} else {
free(*buf);
}
}
fclose(file);
}
@ -101,8 +103,10 @@ int32_t loadFilePart(const char *fPath, uint32_t start, uint32_t size, uint8_t *
}
int32_t loadTitleIcon(Title *title) {
uint32_t highID = title->highID, lowID = title->lowID;
bool isUSB = title->isTitleOnUSB, isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char path[256];
if (isWii) {
@ -111,10 +115,11 @@ int32_t loadTitleIcon(Title *title) {
return loadFilePart(path, 0xA0, 24576, &title->iconBuf);
}
} else {
if (title->saveInit)
if (title->saveInit) {
sprintf(path, "%s:/usr/save/%08x/%08x/meta/iconTex.tga", isUSB ? "usb" : "mlc", highID, lowID);
else
sprintf(path, "%s:/usr/title/%08x/%08x/meta/iconTex.tga", isUSB ? "usb" : "mlc", highID, lowID);
} else {
sprintf(path, "%s:/usr/title/%08x/%08x/meta/iconTex.tga", isUSB ? "usb" : "mlc", highID, lowID);
}
return loadFile(path, &title->iconBuf);
}
@ -123,23 +128,27 @@ int32_t loadTitleIcon(Title *title) {
int checkEntry(const char *fPath) {
struct stat st;
if (stat(fPath, &st) == -1)
return 0;
if (stat(fPath, &st) == -1) {
return 0;
}
if (S_ISDIR(st.st_mode)) return 2;
if (S_ISDIR(st.st_mode)) { return 2;
}
return 1;
}
int folderEmpty(const char *fPath) {
DIR *dir = opendir(fPath);
if (dir == nullptr)
return -1;
if (dir == nullptr) {
return -1;
}
int c = 0;
struct dirent *data;
while ((data = readdir(dir)) != nullptr) {
if (++c > 2)
break;
if (++c > 2) {
break;
}
}
closedir(dir);
@ -153,13 +162,14 @@ int createFolder(const char *fPath) { //Adapted from mkdir_p made by JonathonRei
_path.assign(fPath);
for (p = (char *) _path.c_str() + 1; *p; p++) {
for (p = (char *) _path.c_str() + 1; *p != 0; p++) {
if (*p == '/') {
found++;
if (found > 2) {
*p = '\0';
if (checkEntry(_path.c_str()) == 0) {
if (mkdir(_path.c_str(), DEFFILEMODE) == -1) return -1;
if (mkdir(_path.c_str(), DEFFILEMODE) == -1) { return -1;
}
}
*p = '/';
}
@ -167,7 +177,8 @@ int createFolder(const char *fPath) { //Adapted from mkdir_p made by JonathonRei
}
if (checkEntry(_path.c_str()) == 0) {
if (mkdir(_path.c_str(), DEFFILEMODE) == -1) return -1;
if (mkdir(_path.c_str(), DEFFILEMODE) == -1) { return -1;
}
}
return 0;
@ -179,7 +190,7 @@ void console_print_pos_aligned(int y, uint16_t offset, uint8_t align, const char
va_list va;
va_start(va, format);
if ((vasprintf(&tmp, format, va) >= 0) && tmp) {
if ((vasprintf(&tmp, format, va) >= 0) && (tmp != nullptr)) {
switch (align) {
case 0:
x = (offset * 12);
@ -197,7 +208,8 @@ void console_print_pos_aligned(int y, uint16_t offset, uint8_t align, const char
ttfPrintString(x, (y + 1) * 24, tmp, false, false);
}
va_end(va);
if (tmp) free(tmp);
if (tmp != nullptr) { free(tmp);
}
}
void console_print_pos(int x, int y, const char *format, ...) { // Source: ftpiiu
@ -205,10 +217,12 @@ void console_print_pos(int x, int y, const char *format, ...) { // Source: ftpii
va_list va;
va_start(va, format);
if ((vasprintf(&tmp, format, va) >= 0) && tmp)
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
if ((vasprintf(&tmp, format, va) >= 0) && (tmp != nullptr)) {
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
}
va_end(va);
if (tmp) free(tmp);
if (tmp != nullptr) { free(tmp);
}
}
void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ...) { // Source: ftpiiu
@ -217,11 +231,12 @@ void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ..
va_list va;
va_start(va, format);
if ((vasprintf(&tmp, format, va) >= 0) && tmp) {
if ((vasprintf(&tmp, format, va) >= 0) && (tmp != nullptr)) {
if ((uint32_t)(ttfStringWidth(tmp, -1) / 12) > len) {
char *p = tmp;
if (strrchr(p, '\n') != nullptr) p = strrchr(p, '\n') + 1;
if (strrchr(p, '\n') != nullptr) { p = strrchr(p, '\n') + 1;
}
while ((uint32_t)(ttfStringWidth(p, -1) / 12) > len) {
char *q = p;
int l1 = strlen(q);
@ -229,9 +244,10 @@ void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ..
char o = q[l1];
q[l1] = '\0';
if ((uint32_t)(ttfStringWidth(p, -1) / 12) <= len) {
if (strrchr(p, cdiv) != nullptr) p = strrchr(p, cdiv) + 1;
else
p = q + l1;
if (strrchr(p, cdiv) != nullptr) { p = strrchr(p, cdiv) + 1;
} else {
p = q + l1;
}
q[l1] = o;
break;
}
@ -248,15 +264,18 @@ void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ..
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, true, true);
}
va_end(va);
if (tmp) free(tmp);
if (tmp != nullptr) { free(tmp);
}
}
void console_print_pos_va(int x, int y, const char *format, va_list va) { // Source: ftpiiu
char *tmp = nullptr;
if ((vasprintf(&tmp, format, va) >= 0) && tmp)
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
if (tmp) free(tmp);
if ((vasprintf(&tmp, format, va) >= 0) && (tmp != nullptr)) {
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
}
if (tmp != nullptr) { free(tmp);
}
}
bool promptConfirm(Style st, const char *question) {
@ -275,17 +294,17 @@ bool promptConfirm(Style st, const char *question) {
default:
msg = msg2;
}
if (st & ST_WARNING) {
if ((st & ST_WARNING) != 0) {
OSScreenClearBufferEx(SCREEN_TV, 0x7F7F0000);
OSScreenClearBufferEx(SCREEN_DRC, 0x7F7F0000);
} else if (st & ST_ERROR) {
} else if ((st & ST_ERROR) != 0) {
OSScreenClearBufferEx(SCREEN_TV, 0x7F000000);
OSScreenClearBufferEx(SCREEN_DRC, 0x7F000000);
} else {
OSScreenClearBufferEx(SCREEN_TV, 0x007F0000);
OSScreenClearBufferEx(SCREEN_DRC, 0x007F0000);
}
if (st & ST_MULTILINE) {
if ((st & ST_MULTILINE) != 0) {
} else {
console_print_pos(31 - (ttfStringWidth((char *) question, 0) / 24), 7, question);
@ -299,8 +318,9 @@ bool promptConfirm(Style st, const char *question) {
for (int i = 0; i < 4; i++) {
WPADExtensionType controllerType;
// check if the controller is connected
if (WPADProbe((WPADChan) i, &controllerType) != 0)
continue;
if (WPADProbe((WPADChan) i, &controllerType) != 0) {
continue;
}
KPADRead((WPADChan) i, &(kpad[i]), 1);
kpad_status = kpad[i];
@ -316,7 +336,7 @@ bool promptConfirm(Style st, const char *question) {
break;
}
}
return ret;
return ret != 0;
}
void promptError(const char *message, ...) {
@ -327,12 +347,14 @@ void promptError(const char *message, ...) {
OSScreenClearBufferEx(SCREEN_TV, 0x7F000000);
OSScreenClearBufferEx(SCREEN_DRC, 0x7F000000);
char *tmp = nullptr;
if ((vasprintf(&tmp, message, va) >= 0) && tmp) {
int x = 31 - (ttfStringWidth(tmp, -2) / 24), y = 8;
if ((vasprintf(&tmp, message, va) >= 0) && (tmp != nullptr)) {
int x = 31 - (ttfStringWidth(tmp, -2) / 24);
int y = 8;
x = (x < -4 ? -4 : x);
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, true, false);
}
if (tmp) free(tmp);
if (tmp != nullptr) { free(tmp);
}
flipBuffers();
WHBLogFreetypeDraw();
va_end(va);
@ -342,7 +364,8 @@ void promptError(const char *message, ...) {
void getAccountsWiiU() {
/* get persistent ID - thanks to Maschell */
nn::act::Initialize();
int i = 0, accn = 0;
int i = 0;
int accn = 0;
wiiuaccn = nn::act::GetNumOfAccounts();
wiiuacc = (Account *) malloc(wiiuaccn * sizeof(Account));
uint16_t out[11];
@ -354,9 +377,9 @@ void getAccountsWiiU() {
nn::act::GetMiiNameEx((int16_t *) out, i);
memset(wiiuacc[accn].miiName, 0, sizeof(wiiuacc[accn].miiName));
for (int j = 0, k = 0; j < 10; j++) {
if (out[j] < 0x80)
if (out[j] < 0x80) {
wiiuacc[accn].miiName[k++] = (char) out[j];
else if ((out[j] & 0xF000) > 0) {
} else if ((out[j] & 0xF000) > 0) {
wiiuacc[accn].miiName[k++] = 0xE0 | ((out[j] & 0xF000) >> 12);
wiiuacc[accn].miiName[k++] = 0x80 | ((out[j] & 0xFC0) >> 6);
wiiuacc[accn].miiName[k++] = 0x80 | (out[j] & 0x3F);
@ -377,9 +400,11 @@ void getAccountsWiiU() {
}
void getAccountsSD(Title *title, uint8_t slot) {
uint32_t highID = title->highID, lowID = title->lowID;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
sdaccn = 0;
if (sdacc) free(sdacc);
if (sdacc != nullptr) { free(sdacc);
}
char path[255];
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
@ -387,7 +412,8 @@ void getAccountsSD(Title *title, uint8_t slot) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.' || strncmp(data->d_name, "common", 6) == 0) continue;
if (data->d_name[0] == '.' || strncmp(data->d_name, "common", 6) == 0) { continue;
}
sdaccn++;
}
closedir(dir);
@ -399,7 +425,8 @@ void getAccountsSD(Title *title, uint8_t slot) {
struct dirent *data;
int i = 0;
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.' || strncmp(data->d_name, "common", 6) == 0) continue;
if (data->d_name[0] == '.' || strncmp(data->d_name, "common", 6) == 0) { continue;
}
sprintf(sdacc[i].persistentID, "%s", data->d_name);
sdacc[i].pID = strtoul(data->d_name, nullptr, 16);
sdacc[i].slot = i;
@ -411,8 +438,9 @@ void getAccountsSD(Title *title, uint8_t slot) {
int DumpFile(string pPath, string oPath) {
FILE *source = fopen(pPath.c_str(), "rb");
if (source == nullptr)
return -1;
if (source == nullptr) {
return -1;
}
FILE *dest = fopen(oPath.c_str(), "wb");
if (dest == nullptr) {
@ -426,8 +454,9 @@ int DumpFile(string pPath, string oPath) {
if (buffer[i] == nullptr) {
fclose(source);
fclose(dest);
for (i--; i >= 0; i--)
free(buffer[i]);
for (i--; i >= 0; i--) {
free(buffer[i]);
}
return -1;
}
@ -436,8 +465,12 @@ int DumpFile(string pPath, string oPath) {
setvbuf(source, buffer[0], _IOFBF, IO_MAX_FILE_BUFFER);
setvbuf(dest, buffer[1], _IOFBF, IO_MAX_FILE_BUFFER);
struct stat st;
if (stat(pPath.c_str(), &st) < 0) return -1;
int sizef = st.st_size, sizew = 0, size = 0, bytesWritten = 0;
if (stat(pPath.c_str(), &st) < 0) { return -1;
}
int sizef = st.st_size;
int sizew = 0;
int size = 0;
int bytesWritten = 0;
uint32_t passedMs = 1;
uint64_t startTime = OSGetTime();
@ -447,13 +480,15 @@ int DumpFile(string pPath, string oPath) {
promptError("Write %d,%s", bytesWritten, oPath.c_str());
fclose(source);
fclose(dest);
for (int i = 0; i < 3; i++)
free(buffer[i]);
for (int i = 0; i < 3; i++) {
free(buffer[i]);
}
return -1;
}
passedMs = (uint32_t) OSTicksToMilliseconds(OSGetTime() - startTime);
if (passedMs == 0)
passedMs = 1; // avoid 0 div
if (passedMs == 0) {
passedMs = 1; // avoid 0 div
}
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
sizew += size;
@ -465,8 +500,9 @@ int DumpFile(string pPath, string oPath) {
}
fclose(source);
fclose(dest);
for (int i = 0; i < 3; i++)
free(buffer[i]);
for (int i = 0; i < 3; i++) {
free(buffer[i]);
}
IOSUHAX_FSA_ChangeMode(fsaFd, newlibToFSA((char *) oPath.c_str()), 0x666);
@ -475,8 +511,9 @@ int DumpFile(string pPath, string oPath) {
int DumpDir(string pPath, string tPath) { // Source: ft2sd
DIR *dir = opendir(pPath.c_str());
if (dir == nullptr)
return -1;
if (dir == nullptr) {
return -1;
}
mkdir(tPath.c_str(), DEFFILEMODE);
struct dirent *data = (dirent *) malloc(sizeof(dirent));
@ -485,11 +522,12 @@ int DumpDir(string pPath, string tPath) { // Source: ft2sd
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
if (strcmp(data->d_name, "..") == 0 || strcmp(data->d_name, ".") == 0) continue;
if (strcmp(data->d_name, "..") == 0 || strcmp(data->d_name, ".") == 0) { continue;
}
string targetPath = string_format("%s/%s", tPath.c_str(), data->d_name);
if (data->d_type & DT_DIR) {
if ((data->d_type & DT_DIR) != 0) {
mkdir(targetPath.c_str(), DEFFILEMODE);
if (DumpDir(pPath + string_format("/%s", data->d_name), targetPath) != 0) {
closedir(dir);
@ -513,8 +551,9 @@ int DumpDir(string pPath, string tPath) { // Source: ft2sd
int DeleteDir(char *pPath) {
DIR *dir = opendir(pPath);
if (dir == nullptr)
return -1;
if (dir == nullptr) {
return -1;
}
struct dirent *data;
@ -522,12 +561,13 @@ int DeleteDir(char *pPath) {
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
if (strcmp(data->d_name, "..") == 0 || strcmp(data->d_name, ".") == 0) continue;
if (strcmp(data->d_name, "..") == 0 || strcmp(data->d_name, ".") == 0) { continue;
}
int len = strlen(pPath);
snprintf(pPath + len, PATH_MAX - len, "/%s", data->d_name);
if (data->d_type & DT_DIR) {
if ((data->d_type & DT_DIR) != 0) {
char origPath[PATH_SIZE];
sprintf(origPath, "%s", pPath);
DeleteDir(pPath);
@ -537,11 +577,13 @@ int DeleteDir(char *pPath) {
console_print_pos(-2, 0, "Deleting folder %s", data->d_name);
console_print_pos_multiline(-2, 2, '/', "From: \n%s", origPath);
if (unlink(origPath) == -1) promptError("Failed to delete folder %s\n%s", origPath, strerror(errno));
if (unlink(origPath) == -1) { promptError("Failed to delete folder %s\n%s", origPath, strerror(errno));
}
} else {
console_print_pos(-2, 0, "Deleting file %s", data->d_name);
console_print_pos_multiline(-2, 2, '/', "From: \n%s", pPath);
if (unlink(pPath) == -1) promptError("Failed to delete file %s\n%s", pPath, strerror(errno));
if (unlink(pPath) == -1) { promptError("Failed to delete file %s\n%s", pPath, strerror(errno));
}
}
flipBuffers();
@ -567,11 +609,12 @@ void getUserID(char *out) { // Source: loadiine_gx2
int getLoadiineGameSaveDir(char *out, const char *productCode) {
DIR *dir = opendir("sd:/wiiu/saves");
if (dir == nullptr) return -1;
if (dir == nullptr) { return -1;
}
struct dirent *data;
while ((data = readdir(dir)) != nullptr) {
if ((data->d_type & DT_DIR) && (strstr(data->d_name, productCode) != nullptr)) {
if (((data->d_type & DT_DIR) != 0) && (strstr(data->d_name, productCode) != nullptr)) {
sprintf(out, "sd:/wiiu/saves/%s", data->d_name);
closedir(dir);
return 0;
@ -594,7 +637,7 @@ int getLoadiineSaveVersionList(int *out, const char *gamePath) {
int i = 0;
struct dirent *data;
while (i < 255 && (data = readdir(dir)) != nullptr) {
if ((data->d_type & DT_DIR) && (strchr(data->d_name, 'v') != nullptr)) {
if (((data->d_type & DT_DIR) != 0) && (strchr(data->d_name, 'v') != nullptr)) {
out[++i] = strtol((data->d_name) + 1, nullptr, 10);
}
}
@ -613,7 +656,7 @@ int getLoadiineUserDir(char *out, const char *fullSavePath, const char *userID)
struct dirent *data;
while ((data = readdir(dir)) != nullptr) {
if ((data->d_type & DT_DIR) && (strstr(data->d_name, userID))) {
if (((data->d_type & DT_DIR) != 0) && ((strstr(data->d_name, userID)) != nullptr)) {
sprintf(out, "%s/%s", fullSavePath, data->d_name);
closedir(dir);
return 0;
@ -622,7 +665,8 @@ int getLoadiineUserDir(char *out, const char *fullSavePath, const char *userID)
sprintf(out, "%s/u", fullSavePath);
closedir(dir);
if (checkEntry(out) <= 0) return -1;
if (checkEntry(out) <= 0) { return -1;
}
return 0;
}
@ -634,39 +678,44 @@ bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot) {
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
}
int ret = checkEntry(path);
if (ret <= 0) return true;
else
return false;
return ret <= 0;
}
int getEmptySlot(uint32_t highID, uint32_t lowID) {
for (int i = 0; i < 256; i++) {
if (isSlotEmpty(highID, lowID, i)) return i;
if (isSlotEmpty(highID, lowID, i)) { return i;
}
}
return -1;
}
bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t slot, int version) {
uint32_t highID = title->highID, lowID = title->lowID;
bool isUSB = title->isTitleOnUSB, isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if (highID == 0 || lowID == 0) return false;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if (highID == 0 || lowID == 0) { return false;
}
char srcPath[PATH_SIZE];
if (!isWii) {
if (!inSD) {
const char *path = (isUSB ? "usb:/usr/save" : "mlc:/usr/save");
if (user == 0)
if (user == 0) {
sprintf(srcPath, "%s/%08x/%08x/%s/common", path, highID, lowID, "user");
else if (user == 0xFFFFFFFF)
} else if (user == 0xFFFFFFFF) {
sprintf(srcPath, "%s/%08x/%08x/%s", path, highID, lowID, "user");
else
sprintf(srcPath, "%s/%08x/%08x/%s/%08X", path, highID, lowID, "user", user);
} else {
sprintf(srcPath, "%s/%08x/%08x/%s/%08X", path, highID, lowID, "user", user);
}
} else {
if (!iine)
if (!iine) {
sprintf(srcPath, "sd:/wiiu/backups/%08x%08x/%u/%08X", highID, lowID, slot, user);
else {
if (getLoadiineGameSaveDir(srcPath, title->productCode) != 0) return false;
if (version) sprintf(srcPath + strlen(srcPath), "/v%u", version);
} else {
if (getLoadiineGameSaveDir(srcPath, title->productCode) != 0) { return false;
}
if (version != 0) { sprintf(srcPath + strlen(srcPath), "/v%u", version);
}
if (user == 0) {
uint32_t srcOffset = strlen(srcPath);
strcpy(srcPath + srcOffset, "/c\0");
@ -684,44 +733,56 @@ bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t s
sprintf(srcPath, "sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
}
}
if (checkEntry(srcPath) == 2)
if (folderEmpty(srcPath) == 0)
return true;
if (checkEntry(srcPath) == 2) {
if (folderEmpty(srcPath) == 0) {
return true;
}
}
return false;
}
bool hasCommonSave(Title *title, bool inSD, bool iine, uint8_t slot, int version) {
uint32_t highID = title->highID, lowID = title->lowID;
bool isUSB = title->isTitleOnUSB, isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if (isWii) return false;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if (isWii) { return false;
}
char srcPath[PATH_SIZE];
if (!inSD) {
const char *path = (isUSB ? "usb:/usr/save" : "mlc:/usr/save");
sprintf(srcPath, "%s/%08x/%08x/%s/common", path, highID, lowID, "user");
} else {
if (!iine)
if (!iine) {
sprintf(srcPath, "sd:/wiiu/backups/%08x%08x/%u/common", highID, lowID, slot);
else {
if (getLoadiineGameSaveDir(srcPath, title->productCode) != 0) return false;
if (version) sprintf(srcPath + strlen(srcPath), "/v%u", version);
} else {
if (getLoadiineGameSaveDir(srcPath, title->productCode) != 0) { return false;
}
if (version != 0) { sprintf(srcPath + strlen(srcPath), "/v%u", version);
}
uint32_t srcOffset = strlen(srcPath);
strcpy(srcPath + srcOffset, "/c\0");
}
}
if (checkEntry(srcPath) == 2)
if (folderEmpty(srcPath) == 0) return true;
if (checkEntry(srcPath) == 2) {
if (folderEmpty(srcPath) == 0) { return true;
}
}
return false;
}
void copySavedata(Title *title, Title *titleb, int8_t allusers, int8_t allusers_d, bool common) {
uint32_t highID = title->highID, lowID = title->lowID;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
uint32_t highIDb = titleb->highID, lowIDb = titleb->lowID;
uint32_t highIDb = titleb->highID;
uint32_t lowIDb = titleb->lowID;
bool isUSBb = titleb->isTitleOnUSB;
if (!promptConfirm(ST_WARNING, "Are you sure?")) return;
if (!promptConfirm(ST_WARNING, "Are you sure?")) { return;
}
int slotb = getEmptySlot(titleb->highID, titleb->lowID);
if ((slotb >= 0) && promptConfirm(ST_YES_NO, "Backup current savedata first to next empty slot?")) {
backupSavedata(titleb, slotb, allusers, common);
@ -738,13 +799,15 @@ void copySavedata(Title *title, Title *titleb, int8_t allusers, int8_t allusers_
if (allusers > -1) {
if (common) {
if (DumpDir(srcPath + "/common", dstPath + "/common") != 0) promptError("Common save not found.");
if (DumpDir(srcPath + "/common", dstPath + "/common") != 0) { promptError("Common save not found.");
}
}
}
if (DumpDir(srcPath + string_format("/%s", wiiuacc[allusers].persistentID),
dstPath + string_format("/%s", wiiuacc[allusers_d].persistentID)) != 0)
promptError("Copy failed.");
dstPath + string_format("/%s", wiiuacc[allusers_d].persistentID)) != 0) {
promptError("Copy failed.");
}
}
void backupAllSave(Title *titles, int count, OSCalendarTime *date) {
@ -764,10 +827,13 @@ void backupAllSave(Title *titles, int count, OSCalendarTime *date) {
sprintf(datetime, "%04d-%02d-%02dT%02d%02d%02d", dateTime.tm_year, dateTime.tm_mon, dateTime.tm_mday,
dateTime.tm_hour, dateTime.tm_min, dateTime.tm_sec);
for (int i = 0; i < count; i++) {
if (titles[i].highID == 0 || titles[i].lowID == 0 || !titles[i].saveInit) continue;
if (titles[i].highID == 0 || titles[i].lowID == 0 || !titles[i].saveInit) { continue;
}
uint32_t highID = titles[i].highID, lowID = titles[i].lowID;
bool isUSB = titles[i].isTitleOnUSB, isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
uint32_t highID = titles[i].highID;
uint32_t lowID = titles[i].lowID;
bool isUSB = titles[i].isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char srcPath[PATH_SIZE];
char dstPath[PATH_SIZE];
const char *path = (isWii ? "slc:/title" : (isUSB ? "usb:/usr/save" : "mlc:/usr/save"));
@ -775,17 +841,21 @@ void backupAllSave(Title *titles, int count, OSCalendarTime *date) {
sprintf(dstPath, "sd:/wiiu/backups/batch/%s/%08x%08x", datetime, highID, lowID);
createFolder(dstPath);
if (DumpDir(srcPath, dstPath) != 0) promptError("Backup failed.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Backup failed.");
}
}
}
void backupSavedata(Title *title, uint8_t slot, int8_t allusers, bool common) {
if (!isSlotEmpty(title->highID, title->lowID, slot) &&
!promptConfirm(ST_WARNING, "Backup found on this slot. Overwrite it?"))
return;
uint32_t highID = title->highID, lowID = title->lowID;
bool isUSB = title->isTitleOnUSB, isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
!promptConfirm(ST_WARNING, "Backup found on this slot. Overwrite it?")) {
return;
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
string path = (isWii ? "slc:/title" : (isUSB ? "usb:/usr/save" : "mlc:/usr/save"));
string srcPath = string_format("%s/%08x/%08x/%s", path.c_str(), highID, lowID, isWii ? "data" : "user");
string dstPath;
@ -800,7 +870,8 @@ void backupSavedata(Title *title, uint8_t slot, int8_t allusers, bool common) {
if (common) {
srcPath.append("/common");
dstPath.append("/common");
if (DumpDir(srcPath, dstPath) != 0) promptError("Common save not found.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Common save not found.");
}
}
srcPath.append(string_format("/%s", wiiuacc[allusers].persistentID));
dstPath.append(string_format("/%s", wiiuacc[allusers].persistentID));
@ -809,7 +880,8 @@ void backupSavedata(Title *title, uint8_t slot, int8_t allusers, bool common) {
return;
}
}
if (DumpDir(srcPath, dstPath) != 0) promptError("Backup failed. DO NOT restore from this slot.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Backup failed. DO NOT restore from this slot.");
}
OSCalendarTime now;
OSTicksToCalendarTime(OSGetTime(), &now);
char date[255];
@ -823,12 +895,16 @@ void restoreSavedata(Title *title, uint8_t slot, int8_t sdusers, int8_t allusers
promptError("No backup found on selected slot.");
return;
}
if (!promptConfirm(ST_WARNING, "Are you sure?")) return;
if (!promptConfirm(ST_WARNING, "Are you sure?")) { return;
}
int slotb = getEmptySlot(title->highID, title->lowID);
if ((slotb >= 0) && promptConfirm(ST_YES_NO, "Backup current savedata first to next empty slot?"))
backupSavedata(title, slotb, allusers, common);
uint32_t highID = title->highID, lowID = title->lowID;
bool isUSB = title->isTitleOnUSB, isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if ((slotb >= 0) && promptConfirm(ST_YES_NO, "Backup current savedata first to next empty slot?")) {
backupSavedata(title, slotb, allusers, common);
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char srcPath[PATH_SIZE];
char dstPath[PATH_SIZE];
const char *path = (isWii ? "slc:/title" : (isUSB ? "usb:/usr/save" : "mlc:/usr/save"));
@ -846,23 +922,29 @@ void restoreSavedata(Title *title, uint8_t slot, int8_t sdusers, int8_t allusers
if (common) {
strcpy(srcPath + srcOffset, "/common");
strcpy(dstPath + dstOffset, "/common");
if (DumpDir(srcPath, dstPath) != 0) promptError("Common save not found.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Common save not found.");
}
}
sprintf(srcPath + srcOffset, "/%s", sdacc[sdusers].persistentID);
sprintf(dstPath + dstOffset, "/%s", wiiuacc[allusers].persistentID);
}
if (DumpDir(srcPath, dstPath) != 0) promptError("Restore failed.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Restore failed.");
}
}
void wipeSavedata(Title *title, int8_t allusers, bool common) {
if (!promptConfirm(ST_WARNING, "Are you sure?") || !promptConfirm(ST_WARNING, "Hm, are you REALLY sure?")) return;
if (!promptConfirm(ST_WARNING, "Are you sure?") || !promptConfirm(ST_WARNING, "Hm, are you REALLY sure?")) { return;
}
int slotb = getEmptySlot(title->highID, title->lowID);
if ((slotb >= 0) && promptConfirm(ST_YES_NO, "Backup current savedata first?"))
backupSavedata(title, slotb, allusers, common);
uint32_t highID = title->highID, lowID = title->lowID;
bool isUSB = title->isTitleOnUSB, isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if ((slotb >= 0) && promptConfirm(ST_YES_NO, "Backup current savedata first?")) {
backupSavedata(title, slotb, allusers, common);
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char srcPath[PATH_SIZE];
char origPath[PATH_SIZE];
const char *path = (isWii ? "slc:/title" : (isUSB ? "usb:/usr/save" : "mlc:/usr/save"));
@ -872,31 +954,40 @@ void wipeSavedata(Title *title, int8_t allusers, bool common) {
if (common) {
strcpy(srcPath + offset, "/common");
sprintf(origPath, "%s", srcPath);
if (DeleteDir(srcPath) != 0) promptError("Common save not found.");
if (unlink(origPath) == -1) promptError("Failed to delete common folder.\n%s", strerror(errno));
if (DeleteDir(srcPath) != 0) { promptError("Common save not found.");
}
if (unlink(origPath) == -1) { promptError("Failed to delete common folder.\n%s", strerror(errno));
}
}
sprintf(srcPath + offset, "/%s", wiiuacc[allusers].persistentID);
sprintf(origPath, "%s", srcPath);
}
if (DeleteDir(srcPath) != 0) promptError("Failed to delete savefile.");
if (DeleteDir(srcPath) != 0) { promptError("Failed to delete savefile.");
}
if ((allusers > -1) && !isWii) {
if (unlink(origPath) == -1) promptError("Failed to delete user folder.\n%s", strerror(errno));
if (unlink(origPath) == -1) { promptError("Failed to delete user folder.\n%s", strerror(errno));
}
}
}
void importFromLoadiine(Title *title, bool common, int version) {
if (!promptConfirm(ST_WARNING, "Are you sure?")) return;
if (!promptConfirm(ST_WARNING, "Are you sure?")) { return;
}
int slotb = getEmptySlot(title->highID, title->lowID);
if (slotb >= 0 && promptConfirm(ST_YES_NO, "Backup current savedata first?"))
backupSavedata(title, slotb, 0, common);
uint32_t highID = title->highID, lowID = title->lowID;
if (slotb >= 0 && promptConfirm(ST_YES_NO, "Backup current savedata first?")) {
backupSavedata(title, slotb, 0, common);
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
char srcPath[PATH_SIZE];
char dstPath[PATH_SIZE];
if (getLoadiineGameSaveDir(srcPath, title->productCode) != 0) return;
if (version) sprintf(srcPath + strlen(srcPath), "/v%i", version);
if (getLoadiineGameSaveDir(srcPath, title->productCode) != 0) { return;
}
if (version != 0) { sprintf(srcPath + strlen(srcPath), "/v%i", version);
}
char usrPath[16];
getUserID(usrPath);
uint32_t srcOffset = strlen(srcPath);
@ -907,25 +998,31 @@ void importFromLoadiine(Title *title, bool common, int version) {
sprintf(dstPath + dstOffset, "/%s", usrPath);
promptError(srcPath);
promptError(dstPath);
if (DumpDir(srcPath, dstPath) != 0) promptError("Failed to import savedata from loadiine.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Failed to import savedata from loadiine.");
}
if (common) {
strcpy(srcPath + srcOffset, "/c\0");
strcpy(dstPath + dstOffset, "/common\0");
promptError(srcPath);
promptError(dstPath);
if (DumpDir(srcPath, dstPath) != 0) promptError("Common save not found.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Common save not found.");
}
}
}
void exportToLoadiine(Title *title, bool common, int version) {
if (!promptConfirm(ST_WARNING, "Are you sure?")) return;
uint32_t highID = title->highID, lowID = title->lowID;
if (!promptConfirm(ST_WARNING, "Are you sure?")) { return;
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
char srcPath[PATH_SIZE];
char dstPath[PATH_SIZE];
if (getLoadiineGameSaveDir(dstPath, title->productCode) != 0) return;
if (version) sprintf(dstPath + strlen(dstPath), "/v%u", version);
if (getLoadiineGameSaveDir(dstPath, title->productCode) != 0) { return;
}
if (version != 0) { sprintf(dstPath + strlen(dstPath), "/v%u", version);
}
char usrPath[16];
getUserID(usrPath);
uint32_t dstOffset = strlen(dstPath);
@ -936,12 +1033,14 @@ void exportToLoadiine(Title *title, bool common, int version) {
createFolder(dstPath);
promptError(srcPath);
promptError(dstPath);
if (DumpDir(srcPath, dstPath) != 0) promptError("Failed to export savedata to loadiine.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Failed to export savedata to loadiine.");
}
if (common) {
strcpy(dstPath + dstOffset, "/c\0");
strcpy(srcPath + srcOffset, "/common\0");
promptError(srcPath);
promptError(dstPath);
if (DumpDir(srcPath, dstPath) != 0) promptError("Common save not found.");
if (DumpDir(srcPath, dstPath) != 0) { promptError("Common save not found.");
}
}
}

View File

@ -4,8 +4,9 @@ auto replace_str(char *str, char *orig, char *rep) -> char * {
static char buffer[4096];
char *p;
if (!(p = strstr(str, orig))) // Is 'orig' even in 'str'?
if ((p = strstr(str, orig)) == nullptr) { // Is 'orig' even in 'str'?
return str;
}
strncpy(buffer, str, p - str); // Copy characters from 'str' start to 'orig' st$
buffer[p - str] = '\0';
@ -16,6 +17,5 @@ auto replace_str(char *str, char *orig, char *rep) -> char * {
}
auto StartsWith(const char *a, const char *b) -> bool {
if (strncmp(a, b, strlen(b)) == 0) return true;
return false;
return strncmp(a, b, strlen(b)) == 0;
}

View File

@ -131,7 +131,9 @@ static auto decodeRLE(int width, int height, int depth, const unsigned char *buf
while (decoded < decodeBufferLength) {
int packet = buffer[offset++] & 0xFF;
if ((packet & 0x80) != 0) { // RLE
int i, j, count;
int i;
int j;
int count;
for (i = 0; i < elementCount; i++) {
elements[i] = buffer[offset++];
}
@ -166,7 +168,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
if ((descriptor & RIGHT_ORIGIN) != 0) {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -184,7 +187,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
}
} else {
// LowerRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -204,7 +208,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
} else {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -222,7 +227,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
}
} else {
// LowerLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -246,7 +252,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
if ((descriptor & RIGHT_ORIGIN) != 0) {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -264,7 +271,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
}
} else {
// LowerRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -284,7 +292,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
} else {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -302,7 +311,8 @@ static auto createPixelsFromColormap(int width, int height, int depth, const uns
}
} else {
// LowerLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int colormapIndex = (bytes[offset + width * i + j] & 0xFF) - colormapOrigin;
@ -341,7 +351,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
if ((descriptor & RIGHT_ORIGIN) != 0) {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 3 * width * i + 3 * j;
@ -354,7 +365,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
}
} else {
// LowerRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 3 * width * i + 3 * j;
@ -370,7 +382,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
} else {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 3 * width * i + 3 * j;
@ -383,7 +396,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
}
} else {
// LowerLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 3 * width * i + 3 * j;
@ -402,7 +416,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
if ((descriptor & RIGHT_ORIGIN) != 0) {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 4 * width * i + 4 * j;
@ -415,7 +430,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
}
} else {
// LowerRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 4 * width * i + 4 * j;
@ -431,7 +447,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
} else {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 4 * width * i + 4 * j;
@ -444,7 +461,8 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
}
} else {
// LowerLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int index = offset + 4 * width * i + 4 * j;
@ -478,7 +496,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
if ((descriptor & RIGHT_ORIGIN) != 0) {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + width * i + j] & 0xFF;
@ -488,7 +507,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
}
} else {
// LowerRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + width * i + j] & 0xFF;
@ -501,7 +521,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
} else {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + width * i + j] & 0xFF;
@ -511,7 +532,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
}
} else {
// LowerLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + width * i + j] & 0xFF;
@ -527,7 +549,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
if ((descriptor & RIGHT_ORIGIN) != 0) {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + 2 * width * i + 2 * j + 0] & 0xFF;
@ -537,7 +560,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
}
} else {
// LowerRight
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + 2 * width * i + 2 * j + 0] & 0xFF;
@ -550,7 +574,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
} else {
if ((descriptor & UPPER_ORIGIN) != 0) {
// UpperLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + 2 * width * i + 2 * j + 0] & 0xFF;
@ -560,7 +585,8 @@ createPixelsFromGrayscale(int width, int height, int depth, const unsigned char
}
} else {
// LowerLeft
int i, j;
int i;
int j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
int e = bytes[offset + 2 * width * i + 2 * j + 0] & 0xFF;