From c93ed5ba015605d18384446d7b714c2d57e88e44 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Thu, 25 Jul 2024 09:26:07 +0200 Subject: [PATCH] cleanup --- src/brchess.c | 3 --- src/uci.c | 72 +++++++++++++++++++++++++-------------------------- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/brchess.c b/src/brchess.c index 7273931..5b158a6 100644 --- a/src/brchess.c +++ b/src/brchess.c @@ -13,9 +13,6 @@ #include -#include -#include -#include #include #include diff --git a/src/uci.c b/src/uci.c index 780ea7f..c72fe63 100644 --- a/src/uci.c +++ b/src/uci.c @@ -1,6 +1,6 @@ /* uci.c - uci protocol * - * Copyright (C) 2024 Bruno Raoult ("br") + * Copyright (C) 2021-2024 Bruno Raoult ("br") * Licensed under the GNU General Public License v3.0 or later. * Some rights reserved. See COPYING. * @@ -11,7 +11,6 @@ * */ - #include #include #include @@ -30,7 +29,7 @@ #include "search.h" struct command { - char *name; /* User printable name */ + char *name; /* command name */ int (*func)(pos_t *, char *); /* function doing the job */ char *doc; /* function doc */ }; @@ -46,6 +45,7 @@ int string_trim (char *str); int do_ucinewgame(pos_t *, char *); int do_uci(pos_t *, char *); int do_isready(pos_t *, char *); +int do_quit(pos_t *, char *); int do_position(pos_t *, char *); @@ -56,7 +56,6 @@ int do_perft(pos_t *, char *); int do_hist(pos_t *, char *); int do_help(pos_t *, char *); -int do_quit(pos_t *, char *); struct command commands[] = { { "help", do_help, "(not UCI) This help" }, @@ -77,33 +76,6 @@ struct command commands[] = { { NULL, (int(*)()) NULL, NULL } }; -static int done = 0; - -int uci(pos_t *pos) -{ - char *str = NULL, *saveptr, *token, *args; - int len; - size_t lenstr = 0; - struct command *command; - - while (!done && getline(&str, &lenstr, stdin) >= 0) { - if (!(len = string_trim(str))) - continue; - token = strtok_r(str, " ", &saveptr); - if (! (command= find_command(token))) { - fprintf(stderr, "Unknown [%s] command. Try 'help'.\n", token); - continue; - } - args = strtok_r(NULL, "", &saveptr); - execute_line(pos, command, args); - } - - if (str) - free(str); - - return 0; -} - /* Execute a command line. */ int execute_line(pos_t *pos, struct command *command, char *args) { @@ -370,7 +342,6 @@ int do_perft(__unused pos_t *pos, __unused char *arg) return 1; } - int do_hist(__unused pos_t *pos, __unused char *arg) { hist_static_print(); @@ -387,11 +358,6 @@ int do_help(__unused pos_t *pos, __unused char *arg) return 0; } -int do_quit(__unused pos_t *pos, __unused char *arg) -{ - return done = 1; -} - /* * int do_depth(__unused pos_t *pos, char *arg) * { @@ -490,3 +456,35 @@ int string_trim(char *str) *to = 0; return to - str; } + +static int done = 0; + +int do_quit(__unused pos_t *pos, __unused char *arg) +{ + return done = 1; +} + +int uci(pos_t *pos) +{ + char *str = NULL, *saveptr, *token, *args; + int len; + size_t lenstr = 0; + struct command *command; + + while (!done && getline(&str, &lenstr, stdin) >= 0) { + if (!(len = string_trim(str))) + continue; + token = strtok_r(str, " ", &saveptr); + if (! (command= find_command(token))) { + fprintf(stderr, "Unknown [%s] command. Try 'help'.\n", token); + continue; + } + args = strtok_r(NULL, "", &saveptr); + execute_line(pos, command, args); + } + + if (str) + free(str); + + return 0; +}