Re: [hackers] [sbase[PATCH] numfmt: very minimal implementation

From: David Demelier <markand_AT_malikania.fr>
Date: Wed, 21 Nov 2018 09:25:06 +0100

Le 20/11/2018 à 22:53, ilmich a écrit :
> ---
> Makefile | 1 +
> numfmt.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 49 insertions(+)
> create mode 100644 numfmt.c
>
> diff --git a/Makefile b/Makefile
> index 0e421e7..ae3d640 100644
> --- a/Makefile
> +++ b/Makefile
> _AT_@ -130,6 +130,7 @@ BIN =\
> nice\
> nl\
> nohup\
> + numfmt\
> od\
> paste\
> pathchk\
> diff --git a/numfmt.c b/numfmt.c
> new file mode 100644
> index 0000000..b44e344
> --- /dev/null
> +++ b/numfmt.c
> _AT_@ -0,0 +1,48 @@
> +/* See LICENSE file for copyright and license details. */
> +#include <stdlib.h>
> +#include <string.h>
> +
> +#include "util.h"
> +
> +static void
> +usage(void)
> +{
> + eprintf("usage: %s [--to=iec] number \n", argv0);
> +}
> +
> +int
> +main(int argc, char *argv[])
> +{
> + int ret = 0;
> + char *mode;
> +
> + ARGBEGIN {
> + case '-': /* long options */
> + if ( strncmp(argv[0], "-to=", 4) == 0 )
> + {
> + mode = &argv[0][4];
> + brk_=1; /* shift to next arg*/
> + break;
> + }
> + default:
> + usage();
> + } ARGEND
> +
> + if (!argc) {
> + usage();
> + } else {
> + for (; argc ; argv++, argc--) {

You have mixed spaces / tabs.

You should show whitespaces in your editor.

> + if (mode) {
> + if (strcmp(mode,"iec") == 0) {
> + printf("%s\n", humansize(strtol(*argv,NULL,10)));
> + continue;
> + }
> + eprintf("for now only iec output format is supported\n");
> + } else {
> + /* print numbers as is */
> + printf("%s\n", *argv);
> + }
> + }
> + }
> + return ret;
> +}
>

Regards,

-- 
David
Received on Wed Nov 21 2018 - 09:25:06 CET

This archive was generated by hypermail 2.3.0 : Wed Nov 21 2018 - 09:36:23 CET