xtc/src/main.c

63 lines
2.2 KiB
C

#include "xtc/xtc.h"
#include "xtc/xtc_version.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xtc/xtc_project.h"
/**
* @brief Runs the xtc-check command-line entry point.
*
* Supports --version, --help, and --validate PROJECT. With no arguments it
* creates and destroys the application shell to check core startup/shutdown.
* Any other argument count prints usage to stderr.
*
* @param argc Number of command-line arguments, including the program name.
* @param argv Command-line argument vector; argv[0] is the program name.
* @return EXIT_SUCCESS on success, or EXIT_FAILURE for invalid usage,
* validation failure, or core initialization failure.
*/
int main(int argc, char **argv)
{
if (argc == 2 && !strcmp(argv[1], "--version")) {
printf("%s %s\n", XTC_PROJECT_NAME, XTC_VERSION_STRING);
return EXIT_SUCCESS;
}
if (argc == 2 && !strcmp(argv[1], "--help")) {
puts("Usage: xtc-check [--version | --help | --validate PROJECT]\nNo arguments checks core startup/shutdown. "
"Validation checks metadata only.");
return EXIT_SUCCESS;
}
if (argc == 3 && !strcmp(argv[1], "--validate")) {
xtc_project *project = NULL;
xtc_result result = xtc_project_create(&project);
if (result == XTC_OK)
result = xtc_project_load(project, argv[2]);
xtc_project_destroy(project);
if (result != XTC_OK) {
fprintf(stderr, "Project validation failed: %s\n", xtc_result_string(result));
return EXIT_FAILURE;
}
puts("Project metadata valid (external assets not loaded).");
return EXIT_SUCCESS;
}
if (argc != 1) {
fputs("Usage: xtc-check [--version | --help | --validate PROJECT]\n", stderr);
return EXIT_FAILURE;
}
xtc_app *app = NULL;
xtc_result result = xtc_app_create(&app);
if (result != XTC_OK) {
(void)fprintf(stderr, "Application initialization failed: %s\n", xtc_result_string(result));
return EXIT_FAILURE;
}
xtc_app_destroy(app);
if (printf("%s %s: core startup/shutdown OK\n", XTC_PROJECT_NAME, XTC_VERSION_STRING) < 0) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}