From e72a1467e9f29a61fb72a27d240fd0f0f4d53a00 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 30 Mar 2024 11:30:11 +0100 Subject: Reformatted com_boards() and replaced sprintf() calls --- FICS/gameproc.c | 62 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/FICS/gameproc.c b/FICS/gameproc.c index 258e0f4..cff355b 100644 --- a/FICS/gameproc.c +++ b/FICS/gameproc.c @@ -1330,43 +1330,45 @@ PUBLIC int com_time(int p, param_list param) return COM_OK; } -PUBLIC int com_boards(int p, param_list param) +PUBLIC int +com_boards(int p, param_list param) { - char *category = NULL; - char dname[MAX_FILENAME_SIZE]; - DIR *dirp; + DIR *dirp; + char *category = NULL; + char dname[MAX_FILENAME_SIZE] = { '\0' }; #ifdef USE_DIRENT - struct dirent *dp; + struct dirent *dp; #else - struct direct *dp; + struct direct *dp; #endif - if (param[0].type == TYPE_WORD) - category = param[0].val.word; - if (category) { - pprintf(p, "Boards Available For Category %s:\n", category); - sprintf(dname, "%s/%s", board_dir, category); - } else { - pprintf(p, "Categories Available:\n"); - sprintf(dname, "%s", board_dir); - } - dirp = opendir(dname); - if (!dirp) { - pprintf(p, "No such category %s, try \"boards\".\n", category); - return COM_OK; - } + if (param[0].type == TYPE_WORD) + category = param[0].val.word; -/* YUK! what a mess, how about printing an ordered directory? - DAV*/ + if (category) { + pprintf(p, "Boards Available For Category %s:\n", category); + snprintf(dname, sizeof dname, "%s/%s", board_dir, category); + } else { + pprintf(p, "Categories Available:\n"); + snprintf(dname, sizeof dname, "%s", board_dir); + } - for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { - if (!strcmp(dp->d_name, ".")) - continue; - if (!strcmp(dp->d_name, "..")) - continue; - pprintf(p, "%s\n", dp->d_name); - } - closedir(dirp); - return COM_OK; + if ((dirp = opendir(dname)) == NULL) { + pprintf(p, "No such category %s, try \"boards\".\n", category); + return COM_OK; + } + + // YUK! What a mess, how about printing an ordered directory? - DAV + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { + if (!strcmp(dp->d_name, ".")) + continue; + if (!strcmp(dp->d_name, "..")) + continue; + pprintf(p, "%s\n", dp->d_name); + } + + closedir(dirp); + return COM_OK; } PUBLIC int -- cgit v1.2.3