mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 6/6] commands: implement 'diff' command
Date: Wed, 8 Oct 2014 19:32:26 +0400	[thread overview]
Message-ID: <20141008193226.0863b6e28861fd5e0adf1dc0@gmail.com> (raw)
In-Reply-To: <1412778255-4153-6-git-send-email-s.hauer@pengutronix.de>

On Wed,  8 Oct 2014 16:24:15 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:

> This command compares two files. It does not show the differences,
> it only returns successfully if both files are identical and with
> an error if they differ.

Here are my two comments:

1. there is the 'cmp' command for simple comparing two files from Unix cmdline.
Can we use 'cmp' name instead of 'diff'?

2. we already can use 
     memcmp -s FILE1 -d FILE2 0 0
   for comparing files :)

> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  commands/Kconfig  | 10 ++++++++++
>  commands/Makefile |  1 +
>  commands/diff.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 53 insertions(+)
>  create mode 100644 commands/diff.c
> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index d73a393..05d5426 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -811,6 +811,16 @@ config CMD_CP
>  	  Options:
>  		  -v	verbose
>  
> +config CMD_DIFF
> +	tristate
> +	prompt "diff"
> +	help
> +	  compare two files
> +
> +	  Usage: diff FILE1 FILE2
> +
> +	  Returns successfully if the two files are the same, return with an error if not
> +
>  config CMD_DIRNAME
>  	tristate
>  	prompt "dirname"
> diff --git a/commands/Makefile b/commands/Makefile
> index b1cdf33..e53bdde 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -106,3 +106,4 @@ obj-$(CONFIG_CMD_IMD)		+= imd.o
>  obj-$(CONFIG_CMD_HWCLOCK)	+= hwclock.o
>  obj-$(CONFIG_CMD_USBGADGET)	+= usbgadget.o
>  obj-$(CONFIG_CMD_FIRMWARELOAD)	+= firmwareload.o
> +obj-$(CONFIG_CMD_DIFF)		+= diff.o
> diff --git a/commands/diff.c b/commands/diff.c
> new file mode 100644
> index 0000000..26eaf88
> --- /dev/null
> +++ b/commands/diff.c
> @@ -0,0 +1,42 @@
> +/*
> + * diff - determine if two files differ
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +#include <complete.h>
> +#include <libfile.h>
> +
> +static int do_diff(int argc, char *argv[])
> +{
> +	if (argc != 3)
> +		return COMMAND_ERROR_USAGE;
> +
> +	return diff_file(argv[1], argv[2]);
> +}
> +
> +BAREBOX_CMD_HELP_START(diff)
> +BAREBOX_CMD_HELP_TEXT("Returns successfully if the two files are the same, return with an error if not")
> +BAREBOX_CMD_HELP_END
> +
> +BAREBOX_CMD_START(diff)
> +	.cmd		= do_diff,
> +	BAREBOX_CMD_DESC("compare two files")
> +	BAREBOX_CMD_OPTS("FILE1 FILE2")
> +	BAREBOX_CMD_GROUP(CMD_GRP_FILE)
> +	BAREBOX_CMD_HELP(cmd_diff_help)
> +BAREBOX_CMD_END
> -- 
> 2.1.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2014-10-08 15:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-08 14:24 [PATCH 1/6] fs: store pointer to fsdev instead of dev in struct filep Sascha Hauer
2014-10-08 14:24 ` [PATCH 2/6] fs: do not lookup global FILE * when the file is already available Sascha Hauer
2014-10-08 14:24 ` [PATCH 3/6] fs: Store the path in struct filep Sascha Hauer
2014-10-08 14:24 ` [PATCH 4/6] fs: implement fstat Sascha Hauer
2014-10-08 14:24 ` [PATCH 5/6] libfile: add diff_file function Sascha Hauer
2014-10-08 14:24 ` [PATCH 6/6] commands: implement 'diff' command Sascha Hauer
2014-10-08 15:32   ` Antony Pavlov [this message]
2014-10-09  6:50     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141008193226.0863b6e28861fd5e0adf1dc0@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox