Format code with clang-format

This commit is contained in:
Xpl0itU 2022-04-05 23:19:07 +02:00
parent c5f973a9c1
commit ede6469b5d
15 changed files with 741 additions and 737 deletions

65
.clang-format Normal file
View File

@ -0,0 +1,65 @@
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never

View File

@ -96,8 +96,7 @@ cJSON_GetErrorPtr(void) {
return (const char *) (global_error.json + global_error.position);
}
auto
cJSON_GetStringValue(const cJSON *const item) -> CJSON_PUBLIC(char *) {
auto cJSON_GetStringValue(const cJSON *const item) -> CJSON_PUBLIC(char *) {
if (cJSON_IsString(item) == 0) {
return nullptr;
}
@ -105,8 +104,7 @@ cJSON_GetStringValue(const cJSON *const item) -> CJSON_PUBLIC(char *) {
return item->valuestring;
}
auto
cJSON_GetNumberValue(const cJSON *const item) -> CJSON_PUBLIC(double) {
auto cJSON_GetNumberValue(const cJSON *const item) -> CJSON_PUBLIC(double) {
if (cJSON_IsNumber(item) == 0) {
return (double) NAN;
}
@ -149,7 +147,7 @@ static auto case_insensitive_strcmp(const unsigned char *string1, const unsigned
using internal_hooks = struct internal_hooks {
void *(CJSON_CDECL *allocate)(size_t size);
void (CJSON_CDECL *deallocate)(void *pointer);
void(CJSON_CDECL *deallocate)(void *pointer);
void *(CJSON_CDECL *reallocate)(void *pointer, size_t size);
};
@ -319,7 +317,7 @@ static auto parse_number(cJSON *const item, parse_buffer *const input_buffer) ->
goto loop_end;
}
}
loop_end:
loop_end:
number_c_string[i] = '\0';
number = strtod((const char *) number_c_string, (char **) &after_end);
@ -340,13 +338,12 @@ static auto parse_number(cJSON *const item, parse_buffer *const input_buffer) ->
item->type = cJSON_Number;
input_buffer->offset += (size_t)(after_end - number_c_string);
input_buffer->offset += (size_t) (after_end - number_c_string);
return true;
}
/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */
auto
cJSON_SetNumberHelper(cJSON *object, double number) -> CJSON_PUBLIC(double) {
auto cJSON_SetNumberHelper(cJSON *object, double number) -> CJSON_PUBLIC(double) {
if (number >= INT_MAX) {
object->valueint = INT_MAX;
} else if (number <= (double) INT_MIN) {
@ -358,8 +355,7 @@ cJSON_SetNumberHelper(cJSON *object, double number) -> CJSON_PUBLIC(double) {
return object->valuedouble = number;
}
auto
cJSON_SetValuestring(cJSON *object, const char *valuestring) -> CJSON_PUBLIC(char *) {
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) == 0) || ((object->type & cJSON_IsReference) != 0)) {
@ -659,7 +655,7 @@ utf16_literal_to_utf8(const unsigned char *const input_pointer, const unsigned c
return sequence_length;
fail:
fail:
return 0;
}
@ -679,10 +675,10 @@ static auto parse_string(cJSON *const item, parse_buffer *const input_buffer) ->
/* calculate approximate size of the output (overestimate) */
size_t allocation_length = 0;
size_t skipped_bytes = 0;
while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) {
while (((size_t) (input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) {
/* is escape sequence */
if (input_end[0] == '\\') {
if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) {
if ((size_t) (input_end + 1 - input_buffer->content) >= input_buffer->length) {
/* prevent buffer overflow when last input character is a backslash */
goto fail;
}
@ -691,12 +687,12 @@ static auto parse_string(cJSON *const item, parse_buffer *const input_buffer) ->
}
input_end++;
}
if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) {
if (((size_t) (input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) {
goto fail; /* string ended unexpectedly */
}
/* This is at most how much we need for the output */
allocation_length = (size_t)(input_end - buffer_at_offset(input_buffer)) - skipped_bytes;
allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes;
output = (unsigned char *) input_buffer->hooks.allocate(allocation_length + sizeof(""));
if (output == nullptr) {
goto fail; /* allocation failure */
@ -709,7 +705,7 @@ static auto parse_string(cJSON *const item, parse_buffer *const input_buffer) ->
if (*input_pointer != '\\') {
*output_pointer++ = *input_pointer++;
}
/* escape sequence */
/* escape sequence */
else {
unsigned char sequence_length = 2;
if ((input_end - input_pointer) < 1) {
@ -760,18 +756,18 @@ static auto parse_string(cJSON *const item, parse_buffer *const input_buffer) ->
item->type = cJSON_String;
item->valuestring = (char *) output;
input_buffer->offset = (size_t)(input_end - input_buffer->content);
input_buffer->offset = (size_t) (input_end - input_buffer->content);
input_buffer->offset++;
return true;
fail:
fail:
if (output != nullptr) {
input_buffer->hooks.deallocate(output);
}
if (input_pointer != nullptr) {
input_buffer->offset = (size_t)(input_pointer - input_buffer->content);
input_buffer->offset = (size_t) (input_pointer - input_buffer->content);
}
return false;
@ -822,7 +818,7 @@ static auto print_string_ptr(const unsigned char *const input, printbuffer *cons
break;
}
}
output_length = (size_t)(input_pointer - input) + escape_characters;
output_length = (size_t) (input_pointer - input) + escape_characters;
output = ensure(output_buffer, output_length + sizeof("\"\""));
if (output == nullptr) {
@ -937,8 +933,7 @@ static auto skip_utf8_bom(parse_buffer *const buffer) -> parse_buffer * {
return buffer;
}
auto
cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *) {
size_t buffer_length;
if (nullptr == value) {
@ -952,9 +947,8 @@ cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool
}
/* Parse an object - create a new root, and populate. */
auto
cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end,
cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end,
cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *) {
parse_buffer buffer = {nullptr, 0, 0, 0, {nullptr, nullptr, nullptr}};
cJSON *item = nullptr;
@ -995,7 +989,7 @@ cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **
return item;
fail:
fail:
if (item != nullptr) {
cJSON_Delete(item);
}
@ -1022,13 +1016,11 @@ cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **
}
/* Default options for cJSON_Parse */
auto
cJSON_Parse(const char *value) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_Parse(const char *value) -> CJSON_PUBLIC(cJSON *) {
return cJSON_ParseWithOpts(value, nullptr, 0);
}
auto
cJSON_ParseWithLength(const char *value, size_t buffer_length) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_ParseWithLength(const char *value, size_t buffer_length) -> CJSON_PUBLIC(cJSON *) {
return cJSON_ParseWithLengthOpts(value, buffer_length, nullptr, 0);
}
@ -1078,7 +1070,7 @@ static auto print(const cJSON *const item, cJSON_bool format, const internal_hoo
return printed;
fail:
fail:
if (buffer->buffer != nullptr) {
hooks->deallocate(buffer->buffer);
}
@ -1091,18 +1083,15 @@ static auto print(const cJSON *const item, cJSON_bool format, const internal_hoo
}
/* Render a cJSON item/entity/structure to text. */
auto
cJSON_Print(const cJSON *item) -> CJSON_PUBLIC(char *) {
auto cJSON_Print(const cJSON *item) -> CJSON_PUBLIC(char *) {
return (char *) print(item, true, &global_hooks);
}
auto
cJSON_PrintUnformatted(const cJSON *item) -> CJSON_PUBLIC(char *) {
auto cJSON_PrintUnformatted(const cJSON *item) -> CJSON_PUBLIC(char *) {
return (char *) print(item, false, &global_hooks);
}
auto
cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_PUBLIC(char *) {
auto cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_PUBLIC(char *) {
printbuffer p = {nullptr, 0, 0, 0, 0, 0, {nullptr, nullptr, nullptr}};
if (prebuffer < 0) {
@ -1128,8 +1117,7 @@ cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_P
return (char *) p.buffer;
}
auto
cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) -> CJSON_PUBLIC(cJSON_bool) {
printbuffer p = {nullptr, 0, 0, 0, 0, 0, {nullptr, nullptr, nullptr}};
if ((length < 0) || (buffer == nullptr)) {
@ -1321,7 +1309,7 @@ static auto parse_array(cJSON *const item, parse_buffer *const input_buffer) ->
goto fail; /* expected end of array */
}
success:
success:
input_buffer->depth--;
if (head != nullptr) {
@ -1335,7 +1323,7 @@ static auto parse_array(cJSON *const item, parse_buffer *const input_buffer) ->
return true;
fail:
fail:
if (head != nullptr) {
cJSON_Delete(head);
}
@ -1370,7 +1358,7 @@ static auto print_array(const cJSON *const item, printbuffer *const output_buffe
}
update_offset(output_buffer);
if (current_element->next != nullptr) {
length = (size_t)(output_buffer->format != 0 ? 2 : 1);
length = (size_t) (output_buffer->format != 0 ? 2 : 1);
output_pointer = ensure(output_buffer, length + 1);
if (output_pointer == nullptr) {
return false;
@ -1472,7 +1460,7 @@ static auto parse_object(cJSON *const item, parse_buffer *const input_buffer) ->
goto fail; /* expected end of object */
}
success:
success:
input_buffer->depth--;
if (head != nullptr) {
@ -1485,7 +1473,7 @@ static auto parse_object(cJSON *const item, parse_buffer *const input_buffer) ->
input_buffer->offset++;
return true;
fail:
fail:
if (head != nullptr) {
cJSON_Delete(head);
}
@ -1504,7 +1492,7 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
}
/* Compose the output: */
length = (size_t)(output_buffer->format != 0 ? 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;
@ -1536,7 +1524,7 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
}
update_offset(output_buffer);
length = (size_t)(output_buffer->format != 0 ? 2 : 1);
length = (size_t) (output_buffer->format != 0 ? 2 : 1);
output_pointer = ensure(output_buffer, length);
if (output_pointer == nullptr) {
return false;
@ -1554,7 +1542,7 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
update_offset(output_buffer);
/* print comma if not last */
length = ((size_t)(output_buffer->format != 0 ? 1 : 0) + (size_t)(current_item->next != nullptr ? 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;
@ -1590,8 +1578,7 @@ static auto print_object(const cJSON *const item, printbuffer *const output_buff
}
/* Get Array size/item / object item. */
auto
cJSON_GetArraySize(const cJSON *array) -> CJSON_PUBLIC(int) {
auto cJSON_GetArraySize(const cJSON *array) -> CJSON_PUBLIC(int) {
cJSON *child = nullptr;
size_t size = 0;
@ -1627,8 +1614,7 @@ static auto get_array_item(const cJSON *array, size_t index) -> cJSON * {
return current_child;
}
auto
cJSON_GetArrayItem(const cJSON *array, int index) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_GetArrayItem(const cJSON *array, int index) -> CJSON_PUBLIC(cJSON *) {
if (index < 0) {
return nullptr;
}
@ -1651,8 +1637,8 @@ static auto get_object_item(const cJSON *const object, const char *const name, c
}
} else {
while ((current_element != nullptr) && (case_insensitive_strcmp((const unsigned char *) name,
(const unsigned char *) (current_element->string)) !=
0)) {
(const unsigned char *) (current_element->string)) !=
0)) {
current_element = current_element->next;
}
}
@ -1664,18 +1650,15 @@ static auto get_object_item(const cJSON *const object, const char *const name, c
return current_element;
}
auto
cJSON_GetObjectItem(const cJSON *const object, const char *const string) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_GetObjectItem(const cJSON *const object, const char *const string) -> CJSON_PUBLIC(cJSON *) {
return get_object_item(object, string, false);
}
auto
cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_GetObjectItemCaseSensitive(const cJSON *const object, const char *const string) -> CJSON_PUBLIC(cJSON *) {
return get_object_item(object, string, true);
}
auto
cJSON_HasObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_HasObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON_bool) {
return cJSON_GetObjectItem(object, string) != nullptr ? 1 : 0;
}
@ -1732,8 +1715,7 @@ static auto add_item_to_array(cJSON *array, cJSON *item) -> cJSON_bool {
}
/* Add item to array/object. */
auto
cJSON_AddItemToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_AddItemToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
return add_item_to_array(array, item);
}
@ -1786,19 +1768,16 @@ add_item_to_object(cJSON *const object, const char *const string, cJSON *const i
return add_item_to_array(object, item);
}
auto
cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
return add_item_to_object(object, string, item, &global_hooks, false);
}
/* Add an item to an object with constant string as key */
auto
cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
return add_item_to_object(object, string, item, &global_hooks, true);
}
auto
cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
if (array == nullptr) {
return false;
}
@ -1806,8 +1785,7 @@ cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_b
return add_item_to_array(array, create_reference(item, &global_hooks));
}
auto
cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool) {
if ((object == nullptr) || (string == nullptr)) {
return false;
}
@ -1815,8 +1793,7 @@ cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -
return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false);
}
auto
cJSON_AddNullToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return null;
@ -1826,8 +1803,7 @@ cJSON_AddNullToObject(cJSON *const object, const char *const name) -> CJSON_PUBL
return nullptr;
}
auto
cJSON_AddTrueToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return true_item;
@ -1837,8 +1813,7 @@ cJSON_AddTrueToObject(cJSON *const object, const char *const name) -> CJSON_PUBL
return nullptr;
}
auto
cJSON_AddFalseToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return false_item;
@ -1848,8 +1823,7 @@ cJSON_AddFalseToObject(cJSON *const object, const char *const name) -> CJSON_PUB
return nullptr;
}
auto
cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return bool_item;
@ -1859,8 +1833,7 @@ cJSON_AddBoolToObject(cJSON *const object, const char *const name, const cJSON_b
return nullptr;
}
auto
cJSON_AddNumberToObject(cJSON *const object, const char *const name, const double number) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return number_item;
@ -1870,8 +1843,7 @@ cJSON_AddNumberToObject(cJSON *const object, const char *const name, const doubl
return nullptr;
}
auto
cJSON_AddStringToObject(cJSON *const object, const char *const name, const char *const string) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return string_item;
@ -1881,8 +1853,7 @@ cJSON_AddStringToObject(cJSON *const object, const char *const name, const char
return nullptr;
}
auto
cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *const raw) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return raw_item;
@ -1892,8 +1863,7 @@ cJSON_AddRawToObject(cJSON *const object, const char *const name, const char *co
return nullptr;
}
auto
cJSON_AddObjectToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return object_item;
@ -1903,8 +1873,7 @@ cJSON_AddObjectToObject(cJSON *const object, const char *const name) -> CJSON_PU
return nullptr;
}
auto
cJSON_AddArrayToObject(cJSON *const object, const char *const name) -> CJSON_PUBLIC(cJSON *) {
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) != 0) {
return array;
@ -1914,8 +1883,7 @@ cJSON_AddArrayToObject(cJSON *const object, const char *const name) -> CJSON_PUB
return nullptr;
}
auto
cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) -> CJSON_PUBLIC(cJSON *) {
if ((parent == nullptr) || (item == nullptr)) {
return nullptr;
}
@ -1944,8 +1912,7 @@ cJSON_DetachItemViaPointer(cJSON *parent, cJSON *const item) -> CJSON_PUBLIC(cJS
return item;
}
auto
cJSON_DetachItemFromArray(cJSON *array, int which) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_DetachItemFromArray(cJSON *array, int which) -> CJSON_PUBLIC(cJSON *) {
if (which < 0) {
return nullptr;
}
@ -1958,15 +1925,13 @@ cJSON_DeleteItemFromArray(cJSON *array, int which) {
cJSON_Delete(cJSON_DetachItemFromArray(array, which));
}
auto
cJSON_DetachItemFromObject(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_DetachItemFromObject(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *) {
cJSON *to_detach = cJSON_GetObjectItem(object, string);
return cJSON_DetachItemViaPointer(object, to_detach);
}
auto
cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *) {
cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string);
return cJSON_DetachItemViaPointer(object, to_detach);
@ -1983,8 +1948,7 @@ cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) {
}
/* Replace array/object items with new ones. */
auto
cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
cJSON *after_inserted = nullptr;
if (which < 0) {
@ -2007,8 +1971,7 @@ cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC
return true;
}
auto
cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *replacement) -> CJSON_PUBLIC(cJSON_bool) {
if ((parent == nullptr) || (replacement == nullptr) || (item == nullptr)) {
return false;
}
@ -2047,8 +2010,7 @@ cJSON_ReplaceItemViaPointer(cJSON *const parent, cJSON *const item, cJSON *repla
return true;
}
auto
cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
if (which < 0) {
return false;
}
@ -2072,19 +2034,16 @@ replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJ
return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement);
}
auto
cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
return replace_item_in_object(object, string, newitem, false);
}
auto
cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool) {
return replace_item_in_object(object, string, newitem, true);
}
/* Create basic types: */
auto
cJSON_CreateNull(void) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateNull(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_NULL;
@ -2093,8 +2052,7 @@ cJSON_CreateNull(void) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateTrue(void) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateTrue(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_True;
@ -2103,8 +2061,7 @@ cJSON_CreateTrue(void) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateFalse(void) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateFalse(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_False;
@ -2113,8 +2070,7 @@ cJSON_CreateFalse(void) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateBool(cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateBool(cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = boolean != 0 ? cJSON_True : cJSON_False;
@ -2123,8 +2079,7 @@ cJSON_CreateBool(cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateNumber(double num) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateNumber(double num) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_Number;
@ -2143,8 +2098,7 @@ cJSON_CreateNumber(double num) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateString(const char *string) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateString(const char *string) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_String;
@ -2158,8 +2112,7 @@ cJSON_CreateString(const char *string) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateStringReference(const char *string) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateStringReference(const char *string) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_String | cJSON_IsReference;
@ -2169,8 +2122,7 @@ cJSON_CreateStringReference(const char *string) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateObjectReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateObjectReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_Object | cJSON_IsReference;
@ -2180,8 +2132,7 @@ cJSON_CreateObjectReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateArrayReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateArrayReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_Array | cJSON_IsReference;
@ -2191,8 +2142,7 @@ cJSON_CreateArrayReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateRaw(const char *raw) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateRaw(const char *raw) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_Raw;
@ -2206,8 +2156,7 @@ cJSON_CreateRaw(const char *raw) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateArray(void) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateArray(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_Array;
@ -2216,8 +2165,7 @@ cJSON_CreateArray(void) -> CJSON_PUBLIC(cJSON *) {
return item;
}
auto
cJSON_CreateObject(void) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateObject(void) -> CJSON_PUBLIC(cJSON *) {
cJSON *item = cJSON_New_Item(&global_hooks);
if (item != nullptr) {
item->type = cJSON_Object;
@ -2227,8 +2175,7 @@ cJSON_CreateObject(void) -> CJSON_PUBLIC(cJSON *) {
}
/* Create Arrays: */
auto
cJSON_CreateIntArray(const int *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateIntArray(const int *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
size_t i = 0;
cJSON *n = nullptr;
cJSON *p = nullptr;
@ -2261,8 +2208,7 @@ cJSON_CreateIntArray(const int *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
return a;
}
auto
cJSON_CreateFloatArray(const float *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateFloatArray(const float *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
size_t i = 0;
cJSON *n = nullptr;
cJSON *p = nullptr;
@ -2295,8 +2241,7 @@ cJSON_CreateFloatArray(const float *numbers, int count) -> CJSON_PUBLIC(cJSON *)
return a;
}
auto
cJSON_CreateDoubleArray(const double *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateDoubleArray(const double *numbers, int count) -> CJSON_PUBLIC(cJSON *) {
size_t i = 0;
cJSON *n = nullptr;
cJSON *p = nullptr;
@ -2329,8 +2274,7 @@ cJSON_CreateDoubleArray(const double *numbers, int count) -> CJSON_PUBLIC(cJSON
return a;
}
auto
cJSON_CreateStringArray(const char *const *strings, int count) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_CreateStringArray(const char *const *strings, int count) -> CJSON_PUBLIC(cJSON *) {
size_t i = 0;
cJSON *n = nullptr;
cJSON *p = nullptr;
@ -2364,8 +2308,7 @@ cJSON_CreateStringArray(const char *const *strings, int count) -> CJSON_PUBLIC(c
}
/* Duplication */
auto
cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *) {
auto cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *) {
cJSON *newitem = nullptr;
cJSON *child = nullptr;
cJSON *next = nullptr;
@ -2391,8 +2334,7 @@ cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *)
}
}
if (item->string != nullptr) {
newitem->string = (item->type & cJSON_StringIsConst) != 0 ? item->string : (char *) cJSON_strdup(
(unsigned char *) item->string, &global_hooks);
newitem->string = (item->type & cJSON_StringIsConst) != 0 ? item->string : (char *) cJSON_strdup((unsigned char *) item->string, &global_hooks);
if (newitem->string == nullptr) {
goto fail;
}
@ -2426,7 +2368,7 @@ cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *)
return newitem;
fail:
fail:
if (newitem != nullptr) {
cJSON_Delete(newitem);
}
@ -2470,7 +2412,8 @@ static void minify_string(char **input, char **output) {
*input += static_strlen("\"");
*output += static_strlen("\"");
return;
} if (((*input)[0] == '\\') && ((*input)[1] == '\"')) {
}
if (((*input)[0] == '\\') && ((*input)[1] == '\"')) {
(*output)[1] = (*input)[1];
*input += static_strlen("\"");
*output += static_strlen("\"");
@ -2520,8 +2463,7 @@ cJSON_Minify(char *json) {
*into = '\0';
}
auto
cJSON_IsInvalid(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsInvalid(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2529,8 +2471,7 @@ cJSON_IsInvalid(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Invalid);
}
auto
cJSON_IsFalse(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsFalse(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2538,8 +2479,7 @@ cJSON_IsFalse(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_False);
}
auto
cJSON_IsTrue(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsTrue(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2548,8 +2488,7 @@ cJSON_IsTrue(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
}
auto
cJSON_IsBool(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsBool(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2557,8 +2496,7 @@ cJSON_IsBool(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & (cJSON_True | cJSON_False)) != 0);
}
auto
cJSON_IsNull(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsNull(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2566,8 +2504,7 @@ cJSON_IsNull(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_NULL);
}
auto
cJSON_IsNumber(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsNumber(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2575,8 +2512,7 @@ cJSON_IsNumber(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Number);
}
auto
cJSON_IsString(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsString(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2584,8 +2520,7 @@ cJSON_IsString(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_String);
}
auto
cJSON_IsArray(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsArray(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2593,8 +2528,7 @@ cJSON_IsArray(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Array);
}
auto
cJSON_IsObject(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsObject(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2602,8 +2536,7 @@ cJSON_IsObject(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Object);
}
auto
cJSON_IsRaw(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_IsRaw(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
if (item == nullptr) {
return false;
}
@ -2611,8 +2544,7 @@ cJSON_IsRaw(const cJSON *const item) -> CJSON_PUBLIC(cJSON_bool) {
return static_cast<cJSON_bool>((item->type & 0xFF) == cJSON_Raw);
}
auto
cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive) -> CJSON_PUBLIC(cJSON_bool) {
auto cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_sensitive) -> CJSON_PUBLIC(cJSON_bool) {
if ((a == nullptr) || (b == nullptr) || ((a->type & 0xFF) != (b->type & 0xFF))) {
return false;
}
@ -2719,8 +2651,7 @@ cJSON_Compare(const cJSON *const a, const cJSON *const b, const cJSON_bool case_
}
}
auto
cJSON_malloc(size_t size) -> CJSON_PUBLIC(void *) {
auto cJSON_malloc(size_t size) -> CJSON_PUBLIC(void *) {
return global_hooks.allocate(size);
}

View File

@ -124,7 +124,7 @@ using cJSON_Hooks = struct cJSON_Hooks {
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
void *(CJSON_CDECL *malloc_fn)(size_t sz);
void (CJSON_CDECL *free_fn)(void *ptr);
void(CJSON_CDECL *free_fn)(void *ptr);
};
using cJSON_bool = int;
@ -145,181 +145,131 @@ cJSON_InitHooks(cJSON_Hooks *hooks);
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
auto
cJSON_Parse(const char *value) -> CJSON_PUBLIC(cJSON *);
auto cJSON_Parse(const char *value) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_ParseWithLength(const char *value, size_t buffer_length) -> CJSON_PUBLIC(cJSON *);
auto cJSON_ParseWithLength(const char *value, size_t buffer_length) -> CJSON_PUBLIC(cJSON *);
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
auto
cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *);
auto cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end,
cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *);
auto cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end,
cJSON_bool require_null_terminated) -> CJSON_PUBLIC(cJSON *);
/* Render a cJSON entity to text for transfer/storage. */
auto
cJSON_Print(const cJSON *item) -> CJSON_PUBLIC(char *);
auto cJSON_Print(const cJSON *item) -> CJSON_PUBLIC(char *);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
auto
cJSON_PrintUnformatted(const cJSON *item) -> CJSON_PUBLIC(char *);
auto cJSON_PrintUnformatted(const cJSON *item) -> CJSON_PUBLIC(char *);
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
auto
cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_PUBLIC(char *);
auto cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -> CJSON_PUBLIC(char *);
/* 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, int length, cJSON_bool format) -> CJSON_PUBLIC(cJSON_bool);
auto 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);
/* Returns the number of items in an array (or object). */
auto
cJSON_GetArraySize(const cJSON *array) -> CJSON_PUBLIC(int);
auto cJSON_GetArraySize(const cJSON *array) -> CJSON_PUBLIC(int);
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
auto
cJSON_GetArrayItem(const cJSON *array, int index) -> CJSON_PUBLIC(cJSON *);
auto cJSON_GetArrayItem(const cJSON *array, int index) -> CJSON_PUBLIC(cJSON *);
/* Get item "string" from object. Case insensitive. */
auto
cJSON_GetObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto cJSON_GetObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_GetObjectItemCaseSensitive(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto cJSON_GetObjectItemCaseSensitive(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_HasObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_HasObjectItem(const cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON_bool);
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
CJSON_PUBLIC(const char *)
cJSON_GetErrorPtr(void);
/* Check item type and return its value */
auto
cJSON_GetStringValue(const cJSON *item) -> CJSON_PUBLIC(char *);
auto cJSON_GetStringValue(const cJSON *item) -> CJSON_PUBLIC(char *);
auto
cJSON_GetNumberValue(const cJSON *item) -> CJSON_PUBLIC(double);
auto cJSON_GetNumberValue(const cJSON *item) -> CJSON_PUBLIC(double);
/* These functions check the type of an item */
auto
cJSON_IsInvalid(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsInvalid(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsFalse(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsFalse(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsTrue(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsTrue(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsBool(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsBool(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsNull(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsNull(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsNumber(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsNumber(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsString(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsString(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsArray(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsArray(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsObject(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsObject(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_IsRaw(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_IsRaw(const cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
/* These calls create a cJSON item of the appropriate type. */
auto
cJSON_CreateNull(void) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateNull(void) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateTrue(void) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateTrue(void) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateFalse(void) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateFalse(void) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateBool(cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateBool(cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateNumber(double num) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateNumber(double num) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateString(const char *string) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateString(const char *string) -> CJSON_PUBLIC(cJSON *);
/* raw json */
auto
cJSON_CreateRaw(const char *raw) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateRaw(const char *raw) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateArray(void) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateArray(void) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateObject(void) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateObject(void) -> CJSON_PUBLIC(cJSON *);
/* Create a string where valuestring references a string so
* it will not be freed by cJSON_Delete */
auto
cJSON_CreateStringReference(const char *string) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateStringReference(const char *string) -> CJSON_PUBLIC(cJSON *);
/* Create an object/array that only references it's elements so
* they will not be freed by cJSON_Delete */
auto
cJSON_CreateObjectReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateObjectReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateArrayReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateArrayReference(const cJSON *child) -> CJSON_PUBLIC(cJSON *);
/* These utilities create an Array of count items.
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
auto
cJSON_CreateIntArray(const int *numbers, int count) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateIntArray(const int *numbers, int count) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateFloatArray(const float *numbers, int count) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateFloatArray(const float *numbers, int count) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateDoubleArray(const double *numbers, int count) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateDoubleArray(const double *numbers, int count) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_CreateStringArray(const char *const *strings, int count) -> CJSON_PUBLIC(cJSON *);
auto cJSON_CreateStringArray(const char *const *strings, int count) -> CJSON_PUBLIC(cJSON *);
/* Append item to the specified array/object. */
auto
cJSON_AddItemToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_AddItemToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
* writing to `item->string` */
auto
cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
auto
cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -> CJSON_PUBLIC(cJSON_bool);
/* Remove/Detach items from Arrays/Objects. */
auto
cJSON_DetachItemViaPointer(cJSON *parent, cJSON *item) -> CJSON_PUBLIC(cJSON *);
auto cJSON_DetachItemViaPointer(cJSON *parent, cJSON *item) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_DetachItemFromArray(cJSON *array, int which) -> CJSON_PUBLIC(cJSON *);
auto cJSON_DetachItemFromArray(cJSON *array, int which) -> CJSON_PUBLIC(cJSON *);
CJSON_PUBLIC(void)
cJSON_DeleteItemFromArray(cJSON *array, int which);
auto
cJSON_DetachItemFromObject(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto cJSON_DetachItemFromObject(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
auto cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) -> CJSON_PUBLIC(cJSON *);
CJSON_PUBLIC(void)
cJSON_DeleteItemFromObject(cJSON *object, const char *string);
@ -328,30 +278,23 @@ CJSON_PUBLIC(void)
cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
/* Update array items. */
auto
cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool); /* Shifts pre-existing items to the right. */
auto
cJSON_ReplaceItemViaPointer(cJSON *parent, cJSON *item, cJSON *replacement) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool); /* Shifts pre-existing items to the right. */
auto 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);
auto cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool);
auto
cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool);
auto cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) -> CJSON_PUBLIC(cJSON_bool);
/* Duplicate a cJSON item */
auto
cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *);
auto cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) -> CJSON_PUBLIC(cJSON *);
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
* The item->next and ->prev pointers are always zero on return from Duplicate. */
/* 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 *a, const cJSON *b, cJSON_bool case_sensitive) -> CJSON_PUBLIC(cJSON_bool);
auto 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,
@ -361,50 +304,38 @@ 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 *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddNullToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddTrueToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddTrueToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddFalseToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddFalseToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddBoolToObject(cJSON *object, const char *name, cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddBoolToObject(cJSON *object, const char *name, cJSON_bool boolean) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddNumberToObject(cJSON *object, const char *name, double number) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddNumberToObject(cJSON *object, const char *name, double number) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddStringToObject(cJSON *object, const char *name, const char *string) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddStringToObject(cJSON *object, const char *name, const char *string) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddRawToObject(cJSON *object, const char *name, const char *raw) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddRawToObject(cJSON *object, const char *name, const char *raw) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddObjectToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto cJSON_AddObjectToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto
cJSON_AddArrayToObject(cJSON *object, const char *name) -> CJSON_PUBLIC(cJSON *);
auto 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))
/* helper for the cJSON_SetNumberValue macro */
auto
cJSON_SetNumberHelper(cJSON *object, double number) -> CJSON_PUBLIC(double);
auto cJSON_SetNumberHelper(cJSON *object, double number) -> CJSON_PUBLIC(double);
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double) number) : (number))
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
auto
cJSON_SetValuestring(cJSON *object, const char *valuestring) -> CJSON_PUBLIC(char *);
auto cJSON_SetValuestring(cJSON *object, const char *valuestring) -> CJSON_PUBLIC(char *);
/* Macro for iterating over an array or object */
#define cJSON_ArrayForEach(element, array) for (element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
auto
cJSON_malloc(size_t size) -> CJSON_PUBLIC(void *);
auto cJSON_malloc(size_t size) -> CJSON_PUBLIC(void *);
CJSON_PUBLIC(void)
cJSON_free(void *object);

View File

@ -115,15 +115,17 @@ compare_pointers(const unsigned char *name, const unsigned char *pointer, const
}
for (; (*name != '\0') && (*pointer != '\0') &&
(*pointer != '/'); (void) name++, pointer++) /* compare until next '/' */
(*pointer != '/');
(void) name++, pointer++) /* compare until next '/' */
{
if (*pointer == '~') {
/* check for escaped '~' (~0) and '/' (~1) */
if (((pointer[1] != '0') || (*name != '~')) && ((pointer[1] != '1') || (*name != '/'))) {
/* invalid escape sequence or wrong character in *name */
return false;
} pointer++;
}
pointer++;
} else if (((case_sensitive == 0) && (tolower(*name) != tolower(*pointer))) ||
((case_sensitive != 0) && (*name != *pointer))) {
return false;
@ -131,7 +133,8 @@ compare_pointers(const unsigned char *name, const unsigned char *pointer, const
}
if (((*pointer != 0) && (*pointer != '/')) != (*name != 0)) {
/* one string has ended, the other not */
return false;;
return false;
;
}
return true;
@ -169,8 +172,7 @@ static void encode_string_as_pointer(unsigned char *destination, const unsigned
destination[0] = '\0';
}
auto
cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const target) -> CJSON_PUBLIC(char *) {
auto cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const target) -> CJSON_PUBLIC(char *) {
size_t child_index = 0;
cJSON *current_child = nullptr;
@ -210,9 +212,9 @@ cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const
if (cJSON_IsObject(object) != 0) {
auto *full_pointer = (unsigned char *) cJSON_malloc(strlen((char *) target_pointer) +
pointer_encoded_length(
(unsigned char *) current_child->string) +
2);
pointer_encoded_length(
(unsigned char *) current_child->string) +
2);
full_pointer[0] = '/';
encode_string_as_pointer(full_pointer + 1, (unsigned char *) current_child->string);
strcat((char *) full_pointer, (char *) target_pointer);
@ -252,7 +254,7 @@ static auto decode_array_index_from_pointer(const unsigned char *const pointer,
}
for (position = 0; (pointer[position] >= '0') && (pointer[0] <= '9'); position++) {
parsed_index = (10 * parsed_index) + (size_t)(pointer[position] - '0');
parsed_index = (10 * parsed_index) + (size_t) (pointer[position] - '0');
}
if ((pointer[position] != '\0') && (pointer[position] != '/')) {
@ -302,13 +304,11 @@ static auto get_item_from_pointer(cJSON *const object, const char *pointer, cons
return current_element;
}
auto
cJSONUtils_GetPointer(cJSON *const object, const char *pointer) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_GetPointer(cJSON *const object, const char *pointer) -> CJSON_PUBLIC(cJSON *) {
return get_item_from_pointer(object, pointer, false);
}
auto
cJSONUtils_GetPointerCaseSensitive(cJSON *const object, const char *pointer) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_GetPointerCaseSensitive(cJSON *const object, const char *pointer) -> CJSON_PUBLIC(cJSON *) {
return get_item_from_pointer(object, pointer, true);
}
@ -404,7 +404,7 @@ static auto detach_path(cJSON *object, const unsigned char *path, const cJSON_bo
goto cleanup;
}
cleanup:
cleanup:
if (parent_pointer != nullptr) {
cJSON_free(parent_pointer);
}
@ -545,8 +545,9 @@ 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;
} return true;
}
return true;
case cJSON_Object:
sort_object(a, case_sensitive);
@ -567,8 +568,9 @@ 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;
} return true;
}
return true;
default:
break;
@ -629,35 +631,34 @@ 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) == 0) {
return INVALID;
}
if (cJSON_IsString(operation) == 0){
return INVALID;}
if (strcmp(operation->valuestring, "add") == 0) {
return ADD;
}
if (strcmp(operation->valuestring, "add") == 0) {
return ADD;
}
if (strcmp(operation->valuestring, "remove") == 0) {
return REMOVE;
}
if (strcmp(operation->valuestring, "remove") == 0) {
return REMOVE;
}
if (strcmp(operation->valuestring, "replace") == 0) {
return REPLACE;
}
if (strcmp(operation->valuestring, "replace") == 0) {
return REPLACE;
}
if (strcmp(operation->valuestring, "move") == 0) {
return MOVE;
}
if (strcmp(operation->valuestring, "move") == 0) {
return MOVE;
}
if (strcmp(operation->valuestring, "copy") == 0) {
return COPY;
}
if (strcmp(operation->valuestring, "copy") == 0) {
return COPY;
}
if (strcmp(operation->valuestring, "test") == 0) {
return TEST;
}
if (strcmp(operation->valuestring, "test") == 0) {
return TEST;
}
return INVALID;
return INVALID;
}
/* overwrite and existing item with another one and free resources on the way */
@ -702,7 +703,7 @@ static auto apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case
} else if (opcode == TEST) {
/* compare value: {...} with the given path */
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;
get_object_item(patch, "value", case_sensitive), case_sensitive)) == 0;
goto cleanup;
}
@ -859,7 +860,7 @@ static auto apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case
goto cleanup;
}
cleanup:
cleanup:
if (value != nullptr) {
cJSON_Delete(value);
}
@ -870,8 +871,7 @@ static auto apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case
return status;
}
auto
cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) -> CJSON_PUBLIC(int) {
auto cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) -> CJSON_PUBLIC(int) {
const cJSON *current_patch = nullptr;
int status = 0;
@ -895,8 +895,7 @@ cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) -> CJSO
return 0;
}
auto
cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const patches) -> CJSON_PUBLIC(int) {
auto cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const patches) -> CJSON_PUBLIC(int) {
const cJSON *current_patch = nullptr;
int status = 0;
@ -993,7 +992,8 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
/* generate patches for all array elements that exist in both "from" and "to" */
for (index = 0; (from_child != nullptr) && (to_child !=
nullptr); (void) (from_child = from_child->next), (void) (to_child = to_child->next), index++) {
nullptr);
(void) (from_child = from_child->next), (void) (to_child = to_child->next), index++) {
/* check if conversion to unsigned long is valid
* This should be eliminated at compile time by dead code elimination
* if size_t is an alias of unsigned long, or if it is bigger */
@ -1084,8 +1084,7 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
}
}
auto
cJSONUtils_GeneratePatches(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_GeneratePatches(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
cJSON *patches = nullptr;
if ((from == nullptr) || (to == nullptr)) {
@ -1098,8 +1097,7 @@ cJSONUtils_GeneratePatches(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(c
return patches;
}
auto
cJSONUtils_GeneratePatchesCaseSensitive(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_GeneratePatchesCaseSensitive(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
cJSON *patches = nullptr;
if ((from == nullptr) || (to == nullptr)) {
@ -1168,13 +1166,11 @@ static auto merge_patch(cJSON *target, const cJSON *const patch, const cJSON_boo
return target;
}
auto
cJSONUtils_MergePatch(cJSON *target, const cJSON *const patch) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_MergePatch(cJSON *target, const cJSON *const patch) -> CJSON_PUBLIC(cJSON *) {
return merge_patch(target, patch, false);
}
auto
cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON *const patch) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON *const patch) -> CJSON_PUBLIC(cJSON *) {
return merge_patch(target, patch, true);
}
@ -1242,12 +1238,10 @@ static auto generate_merge_patch(cJSON *const from, cJSON *const to, const cJSON
return patch;
}
auto
cJSONUtils_GenerateMergePatch(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_GenerateMergePatch(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
return generate_merge_patch(from, to, false);
}
auto
cJSONUtils_GenerateMergePatchCaseSensitive(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
auto cJSONUtils_GenerateMergePatchCaseSensitive(cJSON *const from, cJSON *const to) -> CJSON_PUBLIC(cJSON *) {
return generate_merge_patch(from, to, true);
}

View File

@ -30,29 +30,23 @@ extern "C" {
#include "cJSON.h"
/* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */
auto
cJSONUtils_GetPointer(cJSON *object, const char *pointer) -> CJSON_PUBLIC(cJSON *);
auto cJSONUtils_GetPointer(cJSON *object, const char *pointer) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_GetPointerCaseSensitive(cJSON *object, const char *pointer) -> CJSON_PUBLIC(cJSON *);
auto 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 *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto cJSONUtils_GeneratePatches(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_GeneratePatchesCaseSensitive(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto cJSONUtils_GeneratePatchesCaseSensitive(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
/* Utility for generating patch array entries. */
CJSON_PUBLIC(void)
cJSONUtils_AddPatchToArray(cJSON *array, const char *operation, const char *path,
const cJSON *value);
/* Returns 0 for success. */
auto
cJSONUtils_ApplyPatches(cJSON *object, const cJSON *patches) -> CJSON_PUBLIC(int);
auto cJSONUtils_ApplyPatches(cJSON *object, const cJSON *patches) -> CJSON_PUBLIC(int);
auto
cJSONUtils_ApplyPatchesCaseSensitive(cJSON *object, const cJSON *patches) -> CJSON_PUBLIC(int);
auto cJSONUtils_ApplyPatchesCaseSensitive(cJSON *object, const cJSON *patches) -> CJSON_PUBLIC(int);
/*
// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:
@ -77,22 +71,17 @@ cJSONUtils_ApplyPatchesCaseSensitive(cJSON *object, const cJSON *patches) -> CJS
/* 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 *patch) -> CJSON_PUBLIC(cJSON *);
auto cJSONUtils_MergePatch(cJSON *target, const cJSON *patch) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON *patch) -> CJSON_PUBLIC(cJSON *);
auto 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 *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto
cJSONUtils_GenerateMergePatchCaseSensitive(cJSON *from, cJSON *to) -> CJSON_PUBLIC(cJSON *);
auto 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 *object, const cJSON *target) -> CJSON_PUBLIC(char *);
auto cJSONUtils_FindPointerFromObjectTo(const cJSON *object, const cJSON *target) -> CJSON_PUBLIC(char *);
/* Sorts the members of the object into alphabetical order. */
CJSON_PUBLIC(void)

View File

@ -48,20 +48,24 @@ void drawLine(int x1, int y1, int x2, int y2, uint8_t r, uint8_t g, uint8_t b, u
int y;
if (x1 == x2) {
if (y1 < y2) {
for (y = y1; y <= y2; y++) { drawPixel(x1, y, r, g, b, a);
}
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);
}
}
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);
}
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);
}
}
for (x = x2; x <= x1; x++) {
drawPixel(x, y1, r, g, b, a);
}
}
}
}
@ -127,8 +131,8 @@ void drawFillCircle(int xCen, int yCen, int radius, uint8_t r, uint8_t g, uint8_
for (x = -radius; x <= radius; x++) {
if (x * x + y * y <= radius * radius + radius * .8f) {
drawPixel(xCen + x, yCen + y, r, g, b, a);
}
}
}
}
}
}
@ -198,8 +202,9 @@ void drawRGB5A3(int x, int y, float scale, uint8_t *fileContent) {
uint32_t nw = w;
uint32_t nh = h;
if (scale <= 0) { scale = 1;
}
if (scale <= 0) {
scale = 1;
}
nw = w * scale;
nh = h * scale;
@ -220,19 +225,22 @@ void drawRGB5A3(int x, int y, float scale, uint8_t *fileContent) {
} 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);
}
}
}
@ -240,10 +248,11 @@ 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;
if (cur_buf1) {
screen2 = (uint32_t *) scrBuffer + tvBufferSize + otherBuff1;
} else {
screen2 = (uint32_t *) scrBuffer + tvBufferSize;
}
}
memcpy(screen2, out, w * h * 4);
}
@ -251,8 +260,9 @@ 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);
}
@ -270,7 +280,7 @@ void draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y) {
uint8_t col = bitmap->buffer[q * bitmap->pitch + p];
if (col == 0) continue;
float opacity = col / 255.0;
drawPixel(i, j, fcolor.r, fcolor.g, fcolor.b, (uint8_t)(fcolor.a * opacity));
drawPixel(i, j, fcolor.r, fcolor.g, fcolor.b, (uint8_t) (fcolor.a * opacity));
}
}
break;

View File

@ -7,11 +7,11 @@ auto doit(char *text) -> char * {
json = cJSON_Parse(text);
if (json == nullptr) {
return (char*)"";
} str = cJSON_GetObjectItemCaseSensitive(json, "Date");
out = strdup(str->valuestring);
return out;
return (char *) "";
}
str = cJSON_GetObjectItemCaseSensitive(json, "Date");
out = strdup(str->valuestring);
return out;
}
/* Read a file, parse, render back, etc. */
@ -53,7 +53,8 @@ auto getSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot) -> char * {
if (checkEntry(path) != 0) {
char *info = dofile(path);
return info;
} return (char*)"";
}
return (char *) "";
}
auto setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) -> bool {
@ -63,7 +64,7 @@ auto setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) -> b
cJSON *config = cJSON_CreateObject();
if (config == nullptr) {
return false;
}
}
cJSON *entry = cJSON_CreateString(date);
if (entry == nullptr) {
@ -76,12 +77,12 @@ auto setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) -> b
cJSON_Delete(config);
if (configString == nullptr) {
return false;
}
}
FILE *fp = fopen(path, "wb");
if (fp == nullptr) {
return false;
}
}
fwrite(configString, strlen(configString), 1, fp);

View File

@ -130,23 +130,27 @@ auto ttfPrintString(int x, int y, char *string, bool wWrap, bool ceroX) -> int {
if ((buf & 0xF0) == 0xC0) {
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
if ((b2 & 0xC0) == 0x80) {
b2 &= 0x3F;
}
buf = ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xD0) {
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
if ((b2 & 0xC0) == 0x80) {
b2 &= 0x3F;
}
buf = 0x400 | ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xE0) {
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;
}
if ((b2 & 0xC0) == 0x80) {
b2 &= 0x3F;
}
if ((b3 & 0xC0) == 0x80) {
b3 &= 0x3F;
}
buf = ((b1 & 0xF) << 12) | (b2 << 6) | b3;
}
} else if ((buf & 0x80) != 0u) {
@ -156,10 +160,11 @@ auto ttfPrintString(int x, int y, char *string, bool wWrap, bool ceroX) -> int {
if (buf == '\n') {
pen_y += (fontFace->size->metrics.height >> 6);
if (ceroX) { pen_x = 0;
if (ceroX) {
pen_x = 0;
} else {
pen_x = x;
}
}
continue;
}
@ -176,20 +181,21 @@ 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) {
continue;
}
}
error = FT_Render_Glyph(fontFace->glyph, FT_RENDER_MODE_NORMAL);
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;
if (ceroX) {
pen_x = 0;
} else {
pen_x = x;
}
}
} else {
return pen_x;
}
@ -217,23 +223,27 @@ auto ttfStringWidth(char *string, int8_t part) -> int {
if ((buf & 0xF0) == 0xC0) {
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
if ((b2 & 0xC0) == 0x80) {
b2 &= 0x3F;
}
buf = ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xD0) {
uint8_t b1 = buf & 0xFF;
uint8_t b2 = *string++;
if ((b2 & 0xC0) == 0x80) { b2 &= 0x3F;
}
if ((b2 & 0xC0) == 0x80) {
b2 &= 0x3F;
}
buf = 0x400 | ((b1 & 0xF) << 6) | b2;
} else if ((buf & 0xF0) == 0xE0) {
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;
}
if ((b2 & 0xC0) == 0x80) {
b2 &= 0x3F;
}
if ((b3 & 0xC0) == 0x80) {
b3 &= 0x3F;
}
buf = ((b1 & 0xF) << 12) | (b2 << 6) | b3;
}
} else if ((buf & 0x80) != 0u) {
@ -252,10 +262,12 @@ 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++;
}
@ -265,13 +277,14 @@ auto ttfStringWidth(char *string, int8_t part) -> int {
error = FT_Load_Glyph(fontFace, glyph_index, FT_LOAD_BITMAP_METRICS_ONLY);
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

@ -1,9 +1,9 @@
#include "string.hpp"
#include "main.h"
#include "icon.h"
#include "json.h"
#include "log_freetype.h"
#include "main.h"
#include "savemng.h"
#include "string.hpp"
using namespace std;
@ -32,22 +32,22 @@ int titleSort(const void *c1, const void *c2) {
case 2:
if (((Title *) c1)->isTitleOnUSB == ((Title *) c2)->isTitleOnUSB) {
return 0;
}
}
if (((Title *) c1)->isTitleOnUSB) {
return -1 * sorta;
}
}
if (((Title *) c2)->isTitleOnUSB) {
return 1 * sorta;
}
}
return 0;
case 3:
if (((Title *) c1)->isTitleOnUSB && !((Title *) c2)->isTitleOnUSB) {
return -1 * sorta;
}
}
if (!((Title *) c1)->isTitleOnUSB && ((Title *) c2)->isTitleOnUSB) {
return 1 * sorta;
}
}
return strcmp(((Title *) c1)->shortName, ((Title *) c2)->shortName) * sorta;
@ -89,12 +89,12 @@ Title *loadWiiUTitles(int run) {
}
for (uint32_t i = 0; i < receivedCount; i++) {
char *element = tList + (i * 0x61);
savesl[j].highID = *(uint32_t * )(element);
savesl[j].highID = *(uint32_t *) (element);
if (savesl[j].highID != (0x00050000 | 0x00050002)) {
usable--;
continue;
}
savesl[j].lowID = *(uint32_t * )(element + 4);
savesl[j].lowID = *(uint32_t *) (element + 4);
savesl[j].dev = static_cast<uint8_t>(!(memcmp(element + 0x56, "usb", 4) == 0));
savesl[j].found = false;
j++;
@ -114,7 +114,7 @@ Title *loadWiiUTitles(int run) {
while ((data = readdir(dir)) != nullptr) {
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) {
@ -155,7 +155,7 @@ Title *loadWiiUTitles(int run) {
while ((data = readdir(dir)) != nullptr) {
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);
@ -199,7 +199,7 @@ Title *loadWiiUTitles(int run) {
titles[titleswiiu].saveInit = !saves[i].found;
char *xmlBuf = nullptr;
if (loadFile(path, (uint8_t * *) & xmlBuf) > 0) {
if (loadFile(path, (uint8_t **) &xmlBuf) > 0) {
char *cptr = strchr(strstr(xmlBuf, "product_code"), '>') + 7;
memset(titles[titleswiiu].productCode, 0, sizeof(titles[titleswiiu].productCode));
strncpy(titles[titleswiiu].productCode, cptr, strcspn(cptr, "<"));
@ -208,14 +208,14 @@ Title *loadWiiUTitles(int run) {
memset(titles[titleswiiu].shortName, 0, sizeof(titles[titleswiiu].shortName));
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) {
cptr = strchr(strstr(xmlBuf, "longname_ja"), '>') + 1;
}
}
strncpy(titles[titleswiiu].longName, cptr, strcspn(cptr, "<"));
free(xmlBuf);
@ -235,8 +235,9 @@ 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);
@ -291,8 +292,9 @@ Title *loadWiiTitles() {
closedir(dir);
}
}
if (titlesvwii == 0) { return nullptr;
}
if (titlesvwii == 0) {
return nullptr;
}
Title *titles = (Title *) malloc(titlesvwii * sizeof(Title));
if (titles == nullptr) {
@ -378,15 +380,17 @@ 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);
@ -407,11 +411,13 @@ Title *loadWiiTitles() {
void unloadTitles(Title *titles, int count) {
for (int i = 0; i < count; i++) {
if (titles[i].iconBuf != nullptr) { free(titles[i].iconBuf);
}
if (titles[i].iconBuf != nullptr) {
free(titles[i].iconBuf);
}
}
if (titles != nullptr) {
free(titles);
}
if (titles != nullptr) { free(titles);
}
}
/* Entry point */
@ -491,8 +497,7 @@ int main(void) {
console_print_pos(M_OFF, 4, " Batch Backup");
console_print_pos(M_OFF, 2 + cursor, "\u2192");
console_print_pos_aligned(17, 4, 2, "\ue000: Select Mode");
}
break;
} break;
case 1: { // Select Title
if (mode == 2) {
entrycount = 3;
@ -509,33 +514,35 @@ 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 (!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].isTitleOnUSB ? "(USB)" : ((mode == 0) ? "(NAND)" : ""),
titles[i + scroll].isTitleDupe ? " [D]" : "",
titles[i + scroll].saveInit ? "" : " [Not Init]");
} 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 != 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 != nullptr) {
drawRGB5A3((M_OFF + 2) * 12 - 2, (i + 3) * 24 + 3, 0.25,
titles[i + scroll].iconBuf);
}
}
}
}
if (mode == 0) {
@ -545,8 +552,7 @@ int main(void) {
}
console_print_pos_aligned(17, 4, 2, "\ue000: Select Game \ue001: Back");
}
}
break;
} break;
case 2: { // Select Task
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,
@ -562,16 +568,17 @@ int main(void) {
console_print_pos(M_OFF, 10, " Copy Savedata to Title in %s",
titles[targ].isTitleOnUSB ? "NAND" : "USB");
}
if (titles[targ].iconBuf != nullptr) { 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 != nullptr) { 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");
}
break;
} break;
case 3: { // Select Options
entrycount = 3;
console_print_pos(M_OFF, 2, "[%08X-%08X] %s", titles[targ].highID, titles[targ].lowID,
@ -611,8 +618,10 @@ int main(void) {
} 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");
}
slot, 0)
? "Has Save"
: "Empty");
}
}
}
@ -624,8 +633,10 @@ int main(void) {
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");
}
slot, 0)
? "Has Save"
: "Empty");
}
}
if ((task == 0) || (task == 1) || (task == 5)) {
@ -643,17 +654,18 @@ int main(void) {
(!((task == 0) || (task == 1) || (task == 5))),
(!((task < 3) || (task == 5))),
wiiuacc[allusers].pID, slot,
versionList != nullptr ? versionList[slot] : 0) ? "Has Save"
: "Empty");
}
versionList != nullptr ? versionList[slot] : 0)
? "Has Save"
: "Empty");
}
}
}
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++;
@ -664,8 +676,10 @@ int main(void) {
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");
}
wiiuacc[allusers_d].pID, 0, 0)
? "Has Save"
: "Empty");
}
}
if ((task != 3) && (task != 4)) {
@ -700,16 +714,18 @@ int main(void) {
}
console_print_pos(M_OFF, 5 + cursor * 3, "\u2192");
if (titles[targ].iconBuf != nullptr) { 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 != nullptr) { drawRGB5A3(650, 100, 1, titles[targ].iconBuf);
}
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) {
@ -732,8 +748,7 @@ int main(void) {
console_print_pos_aligned(17, 4, 2, "\ue000: Copy \ue001: Back");
break;
}
}
break;
} break;
}
console_print_pos(0, 16, "----------------------------------------------------------------------------");
console_print_pos(0, 17, "Press \ue044 to exit.");
@ -758,32 +773,34 @@ int main(void) {
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;
if (entrycount <= 14) {
cursor = (cursor + 1) % entrycount;
} else if (cursor < 6) {
cursor++;
} else if (((cursor + scroll + 1) % entrycount) != 0) {
scroll++;
} else {
cursor = scroll = 0;
}
}
} 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--);
if (scroll > 0) {
cursor -= (cursor > 6) ? 1 : 0 * (scroll--);
} else if (cursor > 0) {
cursor--;
} else if (entrycount > 14) {
scroll = entrycount - (cursor = 6) - 1;
} else {
cursor = entrycount - 1;
}
}
}
if ((vpad_status.trigger & (VPAD_BUTTON_LEFT | VPAD_STICK_L_EMULATION_LEFT)) |
@ -953,8 +970,9 @@ 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;
}
}
}
@ -997,8 +1015,9 @@ 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?")) {
@ -1049,8 +1068,9 @@ 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) {
@ -1098,7 +1118,8 @@ int main(void) {
}
} else if (((vpad_status.trigger & VPAD_BUTTON_B) |
((kpad_status.trigger & WPAD_BUTTON_B) | (kpad_status.classic.trigger & WPAD_CLASSIC_BUTTON_B) |
(kpad_status.pro.trigger & WPAD_PRO_BUTTON_B))) && menu > 0) {
(kpad_status.pro.trigger & WPAD_PRO_BUTTON_B))) &&
menu > 0) {
clearBuffers();
WHBLogFreetypeDraw();
menu--;
@ -1107,8 +1128,9 @@ int main(void) {
cursor = cursorb;
scroll = scrollb;
}
if (menu == 2) { cursor = cursort;
}
if (menu == 2) {
cursor = cursort;
}
}
}

View File

@ -1,8 +1,8 @@
#include "fat.h"
#include <malloc.h>
#include <cstdarg>
#include <cstdlib>
#include <cstring>
#include <malloc.h>
#include <coreinit/screen.h>
#include <padscore/kpad.h>

View File

@ -49,8 +49,8 @@ void show_file_operation(const char *file_name, const char *file_src, const char
int FSAR(int result) {
if ((result & 0xFFFF0000) == 0xFFFC0000) {
return (result & 0xFFFF) | 0xFFFF0000;
}
return result;
}
return result;
}
int32_t loadFile(const char *fPath, uint8_t **buf) {
@ -66,8 +66,8 @@ int32_t loadFile(const char *fPath, uint8_t **buf) {
if (fread(*buf, size, 1, file) == 1) {
ret = size;
} else {
free(*buf);
}
free(*buf);
}
}
fclose(file);
}
@ -94,8 +94,8 @@ int32_t loadFilePart(const char *fPath, uint32_t start, uint32_t size, uint8_t *
if (fread(*buf, size, 1, file) == 1) {
ret = size;
} else {
free(*buf);
}
free(*buf);
}
}
fclose(file);
}
@ -103,9 +103,9 @@ int32_t loadFilePart(const char *fPath, uint32_t start, uint32_t size, uint8_t *
}
int32_t loadTitleIcon(Title *title) {
uint32_t highID = title->highID;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char path[256];
@ -118,8 +118,8 @@ int32_t loadTitleIcon(Title *title) {
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);
}
sprintf(path, "%s:/usr/title/%08x/%08x/meta/iconTex.tga", isUSB ? "usb" : "mlc", highID, lowID);
}
return loadFile(path, &title->iconBuf);
}
@ -129,26 +129,27 @@ int32_t loadTitleIcon(Title *title) {
int checkEntry(const char *fPath) {
struct stat st;
if (stat(fPath, &st) == -1) {
return 0;
}
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;
}
return -1;
}
int c = 0;
struct dirent *data;
while ((data = readdir(dir)) != nullptr) {
if (++c > 2) {
break;
}
break;
}
}
closedir(dir);
@ -168,8 +169,9 @@ int createFolder(const char *fPath) { //Adapted from mkdir_p made by JonathonRei
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 = '/';
}
@ -177,8 +179,9 @@ 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;
@ -208,8 +211,9 @@ 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 != nullptr) { free(tmp);
}
if (tmp != nullptr) {
free(tmp);
}
}
void console_print_pos(int x, int y, const char *format, ...) { // Source: ftpiiu
@ -218,11 +222,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 != nullptr)) {
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
}
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
}
va_end(va);
if (tmp != nullptr) { free(tmp);
}
if (tmp != nullptr) {
free(tmp);
}
}
void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ...) { // Source: ftpiiu
@ -233,21 +238,23 @@ void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ..
va_start(va, format);
if ((vasprintf(&tmp, format, va) >= 0) && (tmp != nullptr)) {
if ((uint32_t)(ttfStringWidth(tmp, -1) / 12) > len) {
if ((uint32_t) (ttfStringWidth(tmp, -1) / 12) > len) {
char *p = tmp;
if (strrchr(p, '\n') != nullptr) { p = strrchr(p, '\n') + 1;
}
while ((uint32_t)(ttfStringWidth(p, -1) / 12) > len) {
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);
for (int i = l1; i > 0; i--) {
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;
if ((uint32_t) (ttfStringWidth(p, -1) / 12) <= len) {
if (strrchr(p, cdiv) != nullptr) {
p = strrchr(p, cdiv) + 1;
} else {
p = q + l1;
}
p = q + l1;
}
q[l1] = o;
break;
}
@ -264,18 +271,20 @@ 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 != nullptr) { 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 != nullptr)) {
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
}
if (tmp != nullptr) { free(tmp);
}
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
}
if (tmp != nullptr) {
free(tmp);
}
}
bool promptConfirm(Style st, const char *question) {
@ -319,8 +328,8 @@ bool promptConfirm(Style st, const char *question) {
WPADExtensionType controllerType;
// check if the controller is connected
if (WPADProbe((WPADChan) i, &controllerType) != 0) {
continue;
}
continue;
}
KPADRead((WPADChan) i, &(kpad[i]), 1);
kpad_status = kpad[i];
@ -348,13 +357,14 @@ void promptError(const char *message, ...) {
OSScreenClearBufferEx(SCREEN_DRC, 0x7F000000);
char *tmp = nullptr;
if ((vasprintf(&tmp, message, va) >= 0) && (tmp != nullptr)) {
int x = 31 - (ttfStringWidth(tmp, -2) / 24);
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 != nullptr) { free(tmp);
}
if (tmp != nullptr) {
free(tmp);
}
flipBuffers();
WHBLogFreetypeDraw();
va_end(va);
@ -364,7 +374,7 @@ void promptError(const char *message, ...) {
void getAccountsWiiU() {
/* get persistent ID - thanks to Maschell */
nn::act::Initialize();
int i = 0;
int i = 0;
int accn = 0;
wiiuaccn = nn::act::GetNumOfAccounts();
wiiuacc = (Account *) malloc(wiiuaccn * sizeof(Account));
@ -400,11 +410,12 @@ void getAccountsWiiU() {
}
void getAccountsSD(Title *title, uint8_t slot) {
uint32_t highID = title->highID;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
sdaccn = 0;
if (sdacc != nullptr) { free(sdacc);
}
if (sdacc != nullptr) {
free(sdacc);
}
char path[255];
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
@ -412,8 +423,9 @@ 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);
@ -425,8 +437,9 @@ 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;
@ -439,8 +452,8 @@ 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;
}
return -1;
}
FILE *dest = fopen(oPath.c_str(), "wb");
if (dest == nullptr) {
@ -455,8 +468,8 @@ int DumpFile(string pPath, string oPath) {
fclose(source);
fclose(dest);
for (i--; i >= 0; i--) {
free(buffer[i]);
}
free(buffer[i]);
}
return -1;
}
@ -465,11 +478,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;
int sizew = 0;
int size = 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();
@ -481,28 +495,28 @@ int DumpFile(string pPath, string oPath) {
fclose(source);
fclose(dest);
for (int i = 0; i < 3; i++) {
free(buffer[i]);
}
free(buffer[i]);
}
return -1;
}
passedMs = (uint32_t) OSTicksToMilliseconds(OSGetTime() - startTime);
if (passedMs == 0) {
passedMs = 1; // avoid 0 div
}
passedMs = 1; // avoid 0 div
}
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
sizew += size;
show_file_operation(basename(pPath.c_str()), pPath.c_str(), oPath.c_str());
console_print_pos(-2, 15, "Bytes Copied: %d of %d (%i kB/s)", sizew, sizef,
(uint32_t)(((uint64_t) sizew * 1000) / ((uint64_t) 1024 * passedMs)));
(uint32_t) (((uint64_t) sizew * 1000) / ((uint64_t) 1024 * passedMs)));
flipBuffers();
WHBLogFreetypeDraw();
}
fclose(source);
fclose(dest);
for (int i = 0; i < 3; i++) {
free(buffer[i]);
}
free(buffer[i]);
}
IOSUHAX_FSA_ChangeMode(fsaFd, newlibToFSA((char *) oPath.c_str()), 0x666);
@ -512,8 +526,8 @@ 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;
}
return -1;
}
mkdir(tPath.c_str(), DEFFILEMODE);
struct dirent *data = (dirent *) malloc(sizeof(dirent));
@ -522,8 +536,9 @@ 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);
@ -552,8 +567,8 @@ int DumpDir(string pPath, string tPath) { // Source: ft2sd
int DeleteDir(char *pPath) {
DIR *dir = opendir(pPath);
if (dir == nullptr) {
return -1;
}
return -1;
}
struct dirent *data;
@ -561,8 +576,9 @@ 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);
@ -577,13 +593,15 @@ 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();
@ -609,8 +627,9 @@ 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) {
@ -665,8 +684,9 @@ 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;
}
@ -683,19 +703,21 @@ bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot) {
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;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if (highID == 0 || lowID == 0) { return false;
}
if (highID == 0 || lowID == 0) {
return false;
}
char srcPath[PATH_SIZE];
if (!isWii) {
@ -706,16 +728,18 @@ bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t s
} 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);
}
sprintf(srcPath, "%s/%08x/%08x/%s/%08X", path, highID, lowID, "user", user);
}
} else {
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 != 0) { sprintf(srcPath + strlen(srcPath), "/v%u", version);
}
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");
@ -735,19 +759,20 @@ bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t s
}
if (checkEntry(srcPath) == 2) {
if (folderEmpty(srcPath) == 0) {
return true;
}
}
return true;
}
}
return false;
}
bool hasCommonSave(Title *title, bool inSD, bool iine, uint8_t slot, int version) {
uint32_t highID = title->highID;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
if (isWii) { return false;
}
if (isWii) {
return false;
}
char srcPath[PATH_SIZE];
if (!inSD) {
@ -757,32 +782,36 @@ bool hasCommonSave(Title *title, bool inSD, bool iine, uint8_t slot, int version
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 != 0) { sprintf(srcPath + strlen(srcPath), "/v%u", version);
}
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 (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;
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
uint32_t highIDb = titleb->highID;
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);
@ -799,15 +828,16 @@ 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.");
}
promptError("Copy failed.");
}
}
void backupAllSave(Title *titles, int count, OSCalendarTime *date) {
@ -827,12 +857,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;
uint32_t highID = titles[i].highID;
uint32_t lowID = titles[i].lowID;
bool isUSB = titles[i].isTitleOnUSB;
bool isUSB = titles[i].isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char srcPath[PATH_SIZE];
char dstPath[PATH_SIZE];
@ -841,8 +872,9 @@ 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.");
}
}
}
@ -850,11 +882,11 @@ 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;
return;
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
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");
@ -870,8 +902,9 @@ 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));
@ -880,8 +913,9 @@ 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];
@ -895,15 +929,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;
backupSavedata(title, slotb, allusers, common);
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char srcPath[PATH_SIZE];
char dstPath[PATH_SIZE];
@ -922,28 +957,31 @@ 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;
backupSavedata(title, slotb, allusers, common);
}
uint32_t highID = title->highID;
uint32_t lowID = title->lowID;
bool isUSB = title->isTitleOnUSB;
bool isUSB = title->isTitleOnUSB;
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
char srcPath[PATH_SIZE];
char origPath[PATH_SIZE];
@ -954,40 +992,47 @@ 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;
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 != 0) { 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);
@ -998,31 +1043,36 @@ 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;
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 != 0) { 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);
@ -1033,14 +1083,16 @@ 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

@ -9,12 +9,12 @@
#include <coreinit/mcp.h>
#include <coreinit/memdefaultheap.h>
#include <coreinit/thread.h>
#include <cstdio>
#include <dirent.h>
#include <fcntl.h>
#include <iosuhax.h>
#include <iosuhax_devoptab.h>
#include <padscore/kpad.h>
#include <cstdio>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <vpad/input.h>

View File

@ -6,7 +6,7 @@ auto replace_str(char *str, char *orig, char *rep) -> char * {
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';

View File

@ -1,8 +1,8 @@
#include <memory>
#include <string>
#include <cstdarg>
#include <stdexcept>
#include "savemng.h"
#include <cstdarg>
#include <memory>
#include <stdexcept>
#include <string>
using namespace std;
@ -10,12 +10,12 @@ auto replace_str(char *str, char *orig, char *rep) -> char *;
auto StartsWith(const char *a, const char *b) -> bool;
template<typename ... Args>
auto string_format(const std::string &format, Args ... args) -> std::string {
int size_s = std::snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0'
template<typename... Args>
auto string_format(const std::string &format, Args... args) -> std::string {
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
if (size_s <= 0) { throw std::runtime_error("Error during formatting."); }
auto size = static_cast<size_t>( size_s );
auto size = static_cast<size_t>(size_s);
std::unique_ptr<char[]> buf(new char[size]);
std::snprintf(buf.get(), size, format.c_str(), args ...);
std::snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
}

View File

@ -87,8 +87,7 @@ auto tgaRead(const unsigned char *buffer, const TGA_ORDER *order) -> int * {
int imageDataOffset = 18 + (colormapDepth / 8) * colormapLength;
pixels = createPixelsFromColormap(width, height, colormapDepth, buffer, imageDataOffset, buffer,
colormapOrigin, descriptor, order);
}
break;
} break;
case RGB:
pixels = createPixelsFromRGB(width, height, depth, buffer, 18, descriptor, order);
break;
@ -101,20 +100,17 @@ auto tgaRead(const unsigned char *buffer, const TGA_ORDER *order) -> int * {
pixels = createPixelsFromColormap(width, height, colormapDepth, decodeBuffer, 0, buffer, colormapOrigin,
descriptor, order);
tgaFree(decodeBuffer);
}
break;
} break;
case RGB_RLE: {
unsigned char *decodeBuffer = decodeRLE(width, height, depth, buffer, 18);
pixels = createPixelsFromRGB(width, height, depth, decodeBuffer, 0, descriptor, order);
tgaFree(decodeBuffer);
}
break;
} break;
case GRAYSCALE_RLE: {
unsigned char *decodeBuffer = decodeRLE(width, height, depth, buffer, 18);
pixels = createPixelsFromGrayscale(width, height, depth, decodeBuffer, 0, descriptor, order);
tgaFree(decodeBuffer);
}
break;
} break;
default:
break;
}