47 lines
1.9 KiB
C
47 lines
1.9 KiB
C
/* Tahgibu 2.0.0: punto de entrada.
|
|
* Uso: tahgibu [--version] [--safe-mode] [archivo.tgb] */
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "tahgibu/tahgibu.h"
|
|
#include "ui/ui_run.h"
|
|
|
|
int main(int argc, char **argv) {
|
|
const char *open_path = NULL;
|
|
for (int i = 1; i < argc; i++) {
|
|
if (!strcmp(argv[i], "--version")) { printf("%s %s (API %d, formato .tgb %d)\n", TGB_APP_NAME, TGB_VERSION_STRING, TGB_API_VERSION, TGB_FORMAT_VERSION_CURRENT); return 0; }
|
|
if (!strcmp(argv[i], "--safe-mode")) {
|
|
#ifdef _WIN32
|
|
_putenv_s("TGB_SAFE_MODE", "1");
|
|
#else
|
|
setenv("TGB_SAFE_MODE", "1", 1);
|
|
#endif
|
|
continue;
|
|
}
|
|
if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
|
|
printf("Uso: %s [--version] [--safe-mode] [archivo.tgb]\n --safe-mode arranca sin cargar ninguna extension\n", argv[0]);
|
|
return 0;
|
|
}
|
|
if (argv[i][0] == '-') { fprintf(stderr, "Opcion desconocida: %s\n", argv[i]); return 2; }
|
|
open_path = argv[i];
|
|
}
|
|
tgb_context *ctx = NULL;
|
|
if (TGB_FAILED(tgb_context_create(NULL, &ctx))) { fprintf(stderr, "No se pudo iniciar Tahgibu: %s\n", tgb_last_error()); return 1; }
|
|
|
|
tgb_recovery *rec = NULL;
|
|
if (TGB_FAILED(tgb_recovery_open(ctx, &rec))) { /* sin recuperación se puede trabajar, pero se avisa */
|
|
fprintf(stderr, "Aviso: la recuperacion de sesiones esta desactivada: %s\n", tgb_last_error());
|
|
rec = NULL;
|
|
}
|
|
tgb_plugin_manager *plugins = NULL;
|
|
if (TGB_FAILED(tgb_plugin_manager_create(ctx, &plugins))) {
|
|
fprintf(stderr, "Aviso: las extensiones estan desactivadas: %s\n", tgb_last_error());
|
|
plugins = NULL;
|
|
}
|
|
int rc = tgb_ui_run(ctx, rec, plugins, open_path);
|
|
tgb_plugin_manager_destroy(plugins);
|
|
tgb_recovery_close(rec, true); /* cierre normal: se borran marcador y autoguardados de esta sesión */
|
|
tgb_context_destroy(ctx);
|
|
return rc;
|
|
}
|