1
0
Fork 0
forked from hanez/xtc
xtc/src/main.c

74 lines
2.8 KiB
C
Raw Normal View History

#include "xtc/xtc.h"
#include "xtc/xtc_version.h"
2026-10-26 23:03:17 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xtc/xtc_project.h"
#include "xtc/xtc_audio.h"
2026-10-26 23:03:17 +01:00
/**
* @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)
2026-10-26 23:03:17 +01:00
{
if (argc == 2 && !strcmp(argv[1], "--version")) {
2026-10-27 01:37:21 +01:00
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 | --recover-recording TEMP NEW.wav]\nNo arguments checks core startup/shutdown. "
2026-10-27 01:37:21 +01:00
"Validation checks metadata only.");
return EXIT_SUCCESS;
}
if (argc == 4 && !strcmp(argv[1], "--recover-recording")) {
xtc_result result = xtc_recorder_recover(argv[2], argv[3]);
if (result != XTC_OK) {
fprintf(stderr, "Recording recovery failed: %s. Source retained; choose a new writable destination.\n",
xtc_result_string(result));
return EXIT_FAILURE;
}
puts("Complete recorded frames recovered; source retained.");
return EXIT_SUCCESS;
}
if (argc == 3 && !strcmp(argv[1], "--validate")) {
xtc_project *project = NULL;
xtc_result result = xtc_project_create(&project);
2026-10-27 01:37:21 +01:00
if (result == XTC_OK)
result = xtc_project_load(project, argv[2]);
xtc_project_destroy(project);
2026-10-27 01:37:21 +01:00
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 | --recover-recording TEMP NEW.wav]\n", stderr);
2026-10-27 01:37:21 +01:00
return EXIT_FAILURE;
}
2026-10-26 23:20:00 +01:00
xtc_app *app = NULL;
xtc_result result = xtc_app_create(&app);
2026-10-26 23:03:17 +01:00
2026-10-26 23:20:00 +01:00
if (result != XTC_OK) {
2026-10-27 01:37:21 +01:00
(void)fprintf(stderr, "Application initialization failed: %s\n", xtc_result_string(result));
2026-10-26 23:03:17 +01:00
return EXIT_FAILURE;
}
2026-10-26 23:20:00 +01:00
xtc_app_destroy(app);
2026-10-27 01:37:21 +01:00
if (printf("%s %s: core startup/shutdown OK\n", XTC_PROJECT_NAME, XTC_VERSION_STRING) < 0) {
2026-10-26 23:03:17 +01:00
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}