From: Luigi Rizzo Date: Sat, 18 Nov 2006 20:08:17 +0000 (+0000) Subject: Move this macro from cli.c to cli.h so apps can use it X-Git-Tag: 1.6.0-beta1~3^2~3909 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f148916c23681d8f8bf9568ae877e985107ab83d;p=thirdparty%2Fasterisk.git Move this macro from cli.c to cli.h so apps can use it without duplicating the macro or the code: /*! * In many cases we need to print singular or plural * words depending on a count. This macro helps us e.g. * printf("we have %d object%s", n, ESS(n)); */ #define ESS(x) ((x) == 1 ? "" : "s") git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47827 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/include/asterisk/cli.h b/include/asterisk/cli.h index 4f5d882de9..6b8308e755 100644 --- a/include/asterisk/cli.h +++ b/include/asterisk/cli.h @@ -48,6 +48,13 @@ void ast_cli(int fd, char *fmt, ...) #define AST_CLI_COMPLETE_EOF "_EOF_" +/*! + * In many cases we need to print singular or plural + * words depending on a count. This macro helps us e.g. + * printf("we have %d object%s", n, ESS(n)); + */ +#define ESS(x) ((x) == 1 ? "" : "s") + /*! \page CLI_command_api CLI command API CLI commands are described by a struct ast_cli_entry that contains diff --git a/main/cli.c b/main/cli.c index fdde50fff2..09f848cdba 100644 --- a/main/cli.c +++ b/main/cli.c @@ -341,7 +341,6 @@ static void print_uptimestr(int fd, time_t timeval, const char *prefix, int prin #define DAY (HOUR*24) #define WEEK (DAY*7) #define YEAR (DAY*365) -#define ESS(x) ((x == 1) ? "" : "s") /* plural suffix */ #define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */ if (timeval < 0) /* invalid, nothing to show */ return; @@ -938,7 +937,7 @@ static int group_show_channels(int fd, int argc, char *argv[]) if (havepattern) regfree(®exbuf); - ast_cli(fd, "%d active channel%s\n", numchans, (numchans != 1) ? "s" : ""); + ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans)); return RESULT_SUCCESS; #undef FORMAT_STRING }