format code by clang-format

This commit is contained in:
Alexander Popov 2023-07-31 23:12:24 +03:00
parent 13ca75a3bf
commit 7812b19878
Signed by: iiiypuk
GPG Key ID: E47FE0AB36CD5ED6
4 changed files with 134 additions and 118 deletions

View File

@ -2,7 +2,7 @@ root = true
[*]
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
@ -10,8 +10,10 @@ insert_final_newline = true
[{*.c,*.h}]
indent_style = space
indent_size = 4
[Makefile]
indent_style = tab
indent_size = 4
[.gitmodules]
indent_style = tab

View File

@ -8,6 +8,9 @@
> This project use Semantic Versioning 2.0.0 https://semver.org/
## 31/07/2023 - (1.0.3)
- ♻️ - Format code via `clang-format --style=LLVM`
## 31/07/2023 - (1.0.2)
- ♻️ - Update software executable name
- ♻️ - Update Makefile

10
format-code Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
files=(
"src/main.c"
)
for file in "${files[@]}"
do
clang-format -i --style=LLVM --sort-includes=false $file
done

View File

@ -10,132 +10,133 @@
#define VERSION "1.0.2" // software version
void usage();
void info(cJSON * json);
void generate_library_list(cJSON * input_json, cJSON * output_json, char output_system);
void usage();
void info(cJSON *json);
void generate_library_list(cJSON *input_json, cJSON *output_json,
char output_system);
int
main(int argc, char const * argv[])
{
if (argc != 3) {
usage();
} else {
FILE *fp;
char str[900000];
char buffer[100];
int main(int argc, char const *argv[]) {
if (argc != 3) {
usage();
} else {
FILE *fp;
char str[900000];
char buffer[100];
fp = fopen(argv[1], "r");
while (fgets(buffer, sizeof(buffer), fp)) {
strcat(str, buffer);
}
fclose(fp);
cJSON *json = cJSON_Parse(str);
cJSON *launcher_libraries = cJSON_CreateObject();
cJSON *libraries = cJSON_CreateArray();
cJSON_AddItemToObject(launcher_libraries, "libraries", libraries);
generate_library_list(json, launcher_libraries, argv[2][0]);
int libraries_array_size = cJSON_GetArraySize(libraries);
switch (argv[2][0]) {
default:
usage();
break;
case 'i':
info(json);
break;
case 'w':
for (int i = 0; i < libraries_array_size; ++i) {
cJSON *library = cJSON_GetArrayItem(libraries, i);
printf("%%MC_DIR%%/libraries/%s;", cJSON_GetStringValue(library));
}
printf("%s\n", "%MC_DIR%/versions/%GAME_VERSION%/%GAME_VERSION%.jar");
break;
case 'l':
case 'x':
for (int i = 0; i < libraries_array_size; ++i) {
cJSON *library = cJSON_GetArrayItem(libraries, i);
printf("$MC_DIR/libraries/%s:", cJSON_GetStringValue(library));
}
printf("%s\n", "$MC_DIR/versions/$GAME_VERSION/$GAME_VERSION.jar");
break;
}
fp = fopen(argv[1], "r");
while (fgets(buffer, sizeof(buffer), fp)) {
strcat(str, buffer);
}
fclose(fp);
return 0;
}
cJSON *json = cJSON_Parse(str);
void
usage()
{
printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator",
"Version", VERSION);
printf("%s\n", "Usage:");
printf(" %s\n\n", "mc-libs-string <version.json> <system>");
printf(" %s\n\n", "<system> - w|l|x (windows or linux or osx)");
printf("%s\n", "Other:");
printf(" %s\n", "mc-libs-string <version.json> i - to get version info");
}
cJSON *launcher_libraries = cJSON_CreateObject();
cJSON *libraries = cJSON_CreateArray();
cJSON_AddItemToObject(launcher_libraries, "libraries", libraries);
void
info(cJSON * json)
{
char *minecraft_version = cJSON_GetStringValue(cJSON_GetObjectItem(json, "id"));
printf("Minecraft Version: %s\n", minecraft_version);
generate_library_list(json, launcher_libraries, argv[2][0]);
int libraries_array_size = cJSON_GetArraySize(libraries);
char *assets_version = cJSON_GetStringValue(cJSON_GetObjectItem(json, "assets"));
printf("Minecraft Assets Version: %s\n", assets_version);
cJSON *libraries = cJSON_GetObjectItem(json, "libraries");
int libraries_array_size = cJSON_GetArraySize(libraries);
printf("Minecraft libraries count: %d\n", libraries_array_size);
}
void
generate_library_list(cJSON * input_json, cJSON * output_json, char output_system)
{
cJSON *input_libraries = cJSON_GetObjectItem(input_json, "libraries");
cJSON *output_libraries = cJSON_GetObjectItem(output_json, "libraries");
int libraries_array_size = cJSON_GetArraySize(input_libraries);
char *output_system_name;
switch (output_system) {
switch (argv[2][0]) {
default:
usage();
break;
case 'i':
info(json);
break;
case 'w':
output_system_name = "windows";
break;
for (int i = 0; i < libraries_array_size; ++i) {
cJSON *library = cJSON_GetArrayItem(libraries, i);
printf("%%MC_DIR%%/libraries/%s;", cJSON_GetStringValue(library));
}
printf("%s\n", "%MC_DIR%/versions/%GAME_VERSION%/%GAME_VERSION%.jar");
break;
case 'l':
output_system_name = "linux";
break;
case 'x':
output_system_name = "osx";
break;
for (int i = 0; i < libraries_array_size; ++i) {
cJSON *library = cJSON_GetArrayItem(libraries, i);
printf("$MC_DIR/libraries/%s:", cJSON_GetStringValue(library));
}
printf("%s\n", "$MC_DIR/versions/$GAME_VERSION/$GAME_VERSION.jar");
break;
}
}
for (int i = 0; i < libraries_array_size; i++) {
cJSON *library = cJSON_GetArrayItem(input_libraries, i);
if (library != NULL) {
cJSON *downloads = cJSON_GetObjectItem(library, "downloads");
cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
cJSON *rules = cJSON_GetObjectItem(library, "rules");
cJSON *rules_item = cJSON_GetArrayItem(rules, 0);
cJSON *os_type = cJSON_GetObjectItem(rules_item, "os");
char *os_name = cJSON_GetStringValue(cJSON_GetObjectItem(os_type, "name"));
if (os_name != 0) {
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
if (strcmp(output_system_name, os_name) == 0) {
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
}
} else {
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
}
}
}
return 0;
}
void usage() {
printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator", "Version",
VERSION);
printf("%s\n", "Usage:");
printf(" %s\n\n", "mc-libs-string <version.json> <system>");
printf(" %s\n\n", "<system> - w|l|x (windows or linux or osx)");
printf("%s\n", "Other:");
printf(" %s\n", "mc-libs-string <version.json> i - to get version info");
}
void info(cJSON *json) {
char *minecraft_version =
cJSON_GetStringValue(cJSON_GetObjectItem(json, "id"));
printf("Minecraft Version: %s\n", minecraft_version);
char *assets_version =
cJSON_GetStringValue(cJSON_GetObjectItem(json, "assets"));
printf("Minecraft Assets Version: %s\n", assets_version);
cJSON *libraries = cJSON_GetObjectItem(json, "libraries");
int libraries_array_size = cJSON_GetArraySize(libraries);
printf("Minecraft libraries count: %d\n", libraries_array_size);
}
void generate_library_list(cJSON *input_json, cJSON *output_json,
char output_system) {
cJSON *input_libraries = cJSON_GetObjectItem(input_json, "libraries");
cJSON *output_libraries = cJSON_GetObjectItem(output_json, "libraries");
int libraries_array_size = cJSON_GetArraySize(input_libraries);
char *output_system_name;
switch (output_system) {
case 'w':
output_system_name = "windows";
break;
case 'l':
output_system_name = "linux";
break;
case 'x':
output_system_name = "osx";
break;
}
for (int i = 0; i < libraries_array_size; i++) {
cJSON *library = cJSON_GetArrayItem(input_libraries, i);
if (library != NULL) {
cJSON *downloads = cJSON_GetObjectItem(library, "downloads");
cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
cJSON *rules = cJSON_GetObjectItem(library, "rules");
cJSON *rules_item = cJSON_GetArrayItem(rules, 0);
cJSON *os_type = cJSON_GetObjectItem(rules_item, "os");
char *os_name =
cJSON_GetStringValue(cJSON_GetObjectItem(os_type, "name"));
if (os_name != 0) {
char *library_path =
cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
if (strcmp(output_system_name, os_name) == 0) {
cJSON_AddItemToArray(output_libraries,
cJSON_CreateString(library_path));
}
} else {
char *library_path =
cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
cJSON_AddItemToArray(output_libraries,
cJSON_CreateString(library_path));
}
}
}
}