format code by clang-format
This commit is contained in:
parent
13ca75a3bf
commit
7812b19878
@ -2,7 +2,7 @@ root = true
|
|||||||
|
|
||||||
[*]
|
[*]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
@ -10,8 +10,10 @@ insert_final_newline = true
|
|||||||
|
|
||||||
[{*.c,*.h}]
|
[{*.c,*.h}]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
|
||||||
|
|
||||||
[Makefile]
|
[Makefile]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
|
[.gitmodules]
|
||||||
|
indent_style = tab
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
|
|
||||||
> This project use Semantic Versioning 2.0.0 https://semver.org/
|
> 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)
|
## 31/07/2023 - (1.0.2)
|
||||||
- ♻️ - Update software executable name
|
- ♻️ - Update software executable name
|
||||||
- ♻️ - Update Makefile
|
- ♻️ - Update Makefile
|
||||||
|
10
format-code
Executable file
10
format-code
Executable 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
|
233
src/main.c
233
src/main.c
@ -10,132 +10,133 @@
|
|||||||
|
|
||||||
#define VERSION "1.0.2" // software version
|
#define VERSION "1.0.2" // software version
|
||||||
|
|
||||||
void usage();
|
void usage();
|
||||||
void info(cJSON * json);
|
void info(cJSON *json);
|
||||||
void generate_library_list(cJSON * input_json, cJSON * output_json, char output_system);
|
void generate_library_list(cJSON *input_json, cJSON *output_json,
|
||||||
|
char output_system);
|
||||||
|
|
||||||
int
|
int main(int argc, char const *argv[]) {
|
||||||
main(int argc, char const * argv[])
|
if (argc != 3) {
|
||||||
{
|
usage();
|
||||||
if (argc != 3) {
|
} else {
|
||||||
usage();
|
FILE *fp;
|
||||||
} else {
|
char str[900000];
|
||||||
FILE *fp;
|
char buffer[100];
|
||||||
char str[900000];
|
|
||||||
char buffer[100];
|
|
||||||
|
|
||||||
fp = fopen(argv[1], "r");
|
fp = fopen(argv[1], "r");
|
||||||
while (fgets(buffer, sizeof(buffer), fp)) {
|
while (fgets(buffer, sizeof(buffer), fp)) {
|
||||||
strcat(str, buffer);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
return 0;
|
cJSON *json = cJSON_Parse(str);
|
||||||
}
|
|
||||||
|
|
||||||
void
|
cJSON *launcher_libraries = cJSON_CreateObject();
|
||||||
usage()
|
cJSON *libraries = cJSON_CreateArray();
|
||||||
{
|
cJSON_AddItemToObject(launcher_libraries, "libraries", libraries);
|
||||||
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
|
generate_library_list(json, launcher_libraries, argv[2][0]);
|
||||||
info(cJSON * json)
|
int libraries_array_size = cJSON_GetArraySize(libraries);
|
||||||
{
|
|
||||||
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"));
|
switch (argv[2][0]) {
|
||||||
printf("Minecraft Assets Version: %s\n", assets_version);
|
default:
|
||||||
|
usage();
|
||||||
cJSON *libraries = cJSON_GetObjectItem(json, "libraries");
|
break;
|
||||||
int libraries_array_size = cJSON_GetArraySize(libraries);
|
case 'i':
|
||||||
printf("Minecraft libraries count: %d\n", libraries_array_size);
|
info(json);
|
||||||
}
|
break;
|
||||||
|
|
||||||
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':
|
case 'w':
|
||||||
output_system_name = "windows";
|
for (int i = 0; i < libraries_array_size; ++i) {
|
||||||
break;
|
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 'l':
|
||||||
output_system_name = "linux";
|
|
||||||
break;
|
|
||||||
case 'x':
|
case 'x':
|
||||||
output_system_name = "osx";
|
for (int i = 0; i < libraries_array_size; ++i) {
|
||||||
break;
|
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++) {
|
return 0;
|
||||||
cJSON *library = cJSON_GetArrayItem(input_libraries, i);
|
}
|
||||||
|
|
||||||
if (library != NULL) {
|
void usage() {
|
||||||
cJSON *downloads = cJSON_GetObjectItem(library, "downloads");
|
printf("%s\n%s: %s\n\n", "Minecraft Libraries List Generator", "Version",
|
||||||
cJSON *artifact = cJSON_GetObjectItem(downloads, "artifact");
|
VERSION);
|
||||||
|
printf("%s\n", "Usage:");
|
||||||
cJSON *rules = cJSON_GetObjectItem(library, "rules");
|
printf(" %s\n\n", "mc-libs-string <version.json> <system>");
|
||||||
cJSON *rules_item = cJSON_GetArrayItem(rules, 0);
|
printf(" %s\n\n", "<system> - w|l|x (windows or linux or osx)");
|
||||||
cJSON *os_type = cJSON_GetObjectItem(rules_item, "os");
|
printf("%s\n", "Other:");
|
||||||
char *os_name = cJSON_GetStringValue(cJSON_GetObjectItem(os_type, "name"));
|
printf(" %s\n", "mc-libs-string <version.json> i - to get version info");
|
||||||
|
}
|
||||||
if (os_name != 0) {
|
|
||||||
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
|
void info(cJSON *json) {
|
||||||
|
char *minecraft_version =
|
||||||
if (strcmp(output_system_name, os_name) == 0) {
|
cJSON_GetStringValue(cJSON_GetObjectItem(json, "id"));
|
||||||
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
|
printf("Minecraft Version: %s\n", minecraft_version);
|
||||||
}
|
|
||||||
} else {
|
char *assets_version =
|
||||||
char *library_path = cJSON_GetStringValue(cJSON_GetObjectItem(artifact, "path"));
|
cJSON_GetStringValue(cJSON_GetObjectItem(json, "assets"));
|
||||||
cJSON_AddItemToArray(output_libraries, cJSON_CreateString(library_path));
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user