X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=interactive.c;h=61b4f293562bfe8077f9bcc25f528887605bb7ce;hp=4c0392784604d4af06701dcdee355197d7ba868a;hb=3b3e9706dbfaf454f92e45e43fadffab06f87320;hpb=3bb9b0ca535be1eb28b64972bdf0e205e6afc93e diff --git a/interactive.c b/interactive.c index 4c03927..61b4f29 100644 --- a/interactive.c +++ b/interactive.c @@ -1,15 +1,18 @@ /* - * Copyright (C) 2008 Andre Noll + * Copyright (C) 2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ +/** \file interactive.c \brief Commands for interactive mode. */ + #include /* isspace() */ #include "adu.h" #include "format.h" #include "user.h" #include "string.h" +#include "cmdline.h" #include "select.cmdline.h" #include "select.h" #include "error.h" @@ -32,6 +35,7 @@ struct interactive_command { static struct uid_range *admissible_uids; static struct format_info *fi; +/** The set of supported interactive commands. */ #define INTERACTIVE_COMMANDS \ INTERACTIVE_COMMAND(set, "change the current configuration") \ INTERACTIVE_COMMAND(reset, "reset configuration to defaults") \ @@ -40,6 +44,7 @@ static struct format_info *fi; INTERACTIVE_COMMAND(source, "read and execute interactive commands from a file") +/** \cond doxygen is not smart enough for this */ #define INTERACTIVE_COMMAND(name, desc) \ static int icom_ ## name (char *line); @@ -58,7 +63,9 @@ struct interactive_command icmds[] = { INTERACTIVE_COMMANDS {.name = NULL} }; +/** \endcond */ +/** Iterate over the list of all interactive commands. */ #define FOR_EACH_COMMAND(c) for (c = icmds; c->name; c++) static int read_input_line(char *line, size_t size) @@ -80,6 +87,9 @@ static int icom_help(__a_unused char *line) return 1; } +/** + * Print the list of commands with short descriptions. + */ void print_interactive_help(void) { struct interactive_command *c; @@ -100,7 +110,6 @@ static int icom_reset(__a_unused char *line) static int icom_set(char *line) { - int ret; struct select_cmdline_parser_params params = { .override = 1, .initialize = 0, @@ -117,12 +126,24 @@ static int icom_set(char *line) fi = NULL; free(admissible_uids); admissible_uids = NULL; - ret = parse_select_options(line, ¶ms, &admissible_uids, &fi); - if (ret >= 0) - return ret; - return icom_reset(NULL); + return parse_select_options(line, ¶ms, &admissible_uids, &fi); } +/** + * Wrapper for isspace. + * NetBSD needs this. + */ +/* + * The values should be cast to an unsigned char first, then to int. + * Why? Because the isdigit (as do all other is/to functions/macros) + * expect a number from 0 upto and including 255 as their (int) argument. + * Because char is signed on most systems, casting it to int immediately + * gives the functions an argument between -128 and 127 (inclusive), + * which they will use as an array index, and which will thus fail + * horribly for characters which have their most significant bit set. + */ +#define adu_isspace(c) isspace((int)(unsigned char)(c)) + static int exec_interactive_command(char *line) { const char const *delim = "\t\n\f\r\v "; @@ -135,7 +156,7 @@ static int exec_interactive_command(char *line) return 1; len = strlen(line); - while (len && isspace(line[len - 1])) { + while (len && adu_isspace(line[len - 1])) { line[len - 1] = '\0'; len--; } @@ -190,10 +211,15 @@ out: return ret; } +/** + * The main function for interactive mode. + * + * \return Standard. + */ int com_interactive(void) { char line[255]; - int ret = 1; + int ret; select_cmdline_parser_init(&select_conf); ret = parse_select_options(NULL, NULL, &admissible_uids, &fi); @@ -206,6 +232,7 @@ int com_interactive(void) ret = exec_interactive_command(line); if (ret < 0) printf("%s\n", adu_strerror(-ret)); + fflush(NULL); } return ret; }