Felipe97/llama-cpp-compiled
01.1k
1#include "arg.h"2#include "common.h"3#include "log.h"4 5#include "cli-context.h"6 7#include <signal.h>8 9#if defined(_WIN32)10#define WIN32_LEAN_AND_MEAN11#ifndef NOMINMAX12# define NOMINMAX13#endif14#include <windows.h>15#endif16 17#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)18static void signal_handler(int) {19 if (cli_context::interrupted().load()) {20 // second Ctrl+C - exit immediately21 // make sure to clear colors before exiting (not using LOG or console.cpp here to avoid deadlock)22 fprintf(stdout, "\033[0m\n");23 fflush(stdout);24 std::exit(130);25 }26 cli_context::interrupted().store(true);27}28#endif29 30// satisfies -Wmissing-declarations31int llama_cli(int argc, char ** argv);32 33int llama_cli(int argc, char ** argv) {34 common_params params;35 36 params.verbosity = LOG_LEVEL_ERROR; // by default, less verbose logs37 38 common_init();39 40 if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_CLI)) {41 return 1;42 }43 44#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))45 struct sigaction sigint_action;46 sigint_action.sa_handler = signal_handler;47 sigemptyset (&sigint_action.sa_mask);48 sigint_action.sa_flags = 0;49 sigaction(SIGINT, &sigint_action, NULL);50 sigaction(SIGTERM, &sigint_action, NULL);51#elif defined (_WIN32)52 auto console_ctrl_handler = +[](DWORD ctrl_type) -> BOOL {53 return (ctrl_type == CTRL_C_EVENT) ? (signal_handler(SIGINT), true) : false;54 };55 SetConsoleCtrlHandler(reinterpret_cast<PHANDLER_ROUTINE>(console_ctrl_handler), true);56#endif57 58 cli_context ctx_cli(params);59 60 if (!ctx_cli.init()) {61 return 1;62 }63 64 return ctx_cli.run();65}66 