mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 4/5] filetype: add command support
Date: Sun, 15 Jan 2012 11:00:20 +0100	[thread overview]
Message-ID: <1326621621-11484-4-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <20120115095156.GH5002@game.jcrosoft.org>

this will allow to detect the filetype of a file and export it as filetype

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/Kconfig    |    5 +++++
 commands/Makefile   |    1 +
 commands/filetype.c |   39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 0 deletions(-)
 create mode 100644 commands/filetype.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 766428c..c613e22 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -181,6 +181,11 @@ config CMD_NANDTEST
 	select PARTITION_NEED_MTD
 	prompt "nandtest"
 
+config CMD_FILETYPE
+	tristate
+	depends on FILETYPE
+	prompt "filetype"
+
 endmenu
 
 menu "console                       "
diff --git a/commands/Makefile b/commands/Makefile
index 31442b5..a91eed2 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -64,3 +64,4 @@ obj-$(CONFIG_CMD_OFTREE)	+= oftree.o
 obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
 obj-$(CONFIG_CMD_IOMEM)		+= iomem.o
 obj-$(CONFIG_CMD_LINUX_EXEC)	+= linux_exec.o
+obj-$(CONFIG_CMD_FILETYPE)	+= filetype.o
diff --git a/commands/filetype.c b/commands/filetype.c
new file mode 100644
index 0000000..7c5e907
--- /dev/null
+++ b/commands/filetype.c
@@ -0,0 +1,39 @@
+/*
+ * (C) Copyright 2012 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
+ *
+ * Under GPLv2 Only
+ */
+
+#include <common.h>
+#include <command.h>
+#include <fs.h>
+#include <filetype.h>
+#include <environment.h>
+
+static int do_filetype(struct command *cmdtp, int argc, char *argv[])
+{
+	enum filetype type;
+
+	if (argc < 2)
+		return COMMAND_ERROR_USAGE;
+
+	type = file_name_detect_type(argv[1]);
+
+	printf("%s: %s detected\n", argv[1], file_type_to_string(type));
+
+	export_env_ull("filetype" , type);
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(filetype)
+BAREBOX_CMD_HELP_USAGE("filetype file\n")
+BAREBOX_CMD_HELP_USAGE("export filetype\n")
+BAREBOX_CMD_HELP_SHORT("detect file type\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(filetype)
+	.cmd		= do_filetype,
+	.usage		= "detect file type",
+	BAREBOX_CMD_HELP(cmd_filetype_help)
+BAREBOX_CMD_END
-- 
1.7.7


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

  parent reply	other threads:[~2012-01-15 10:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-15  9:51 [PATCH 0/5] Calao dfu upload kernel or uImage and boot it Jean-Christophe PLAGNIOL-VILLARD
2012-01-15 10:00 ` [PATCH 1/5] dfu: add description how to specify the "description" to the long help Jean-Christophe PLAGNIOL-VILLARD
2012-01-15 10:00 ` [PATCH 2/5] defaultenv/boot: add getopt option support to select boot mode Jean-Christophe PLAGNIOL-VILLARD
2012-02-09 14:46   ` Jean-Christophe PLAGNIOL-VILLARD
2012-01-15 10:00 ` [PATCH 3/5] defaultenv/boot: add boot the kernel from the mem Jean-Christophe PLAGNIOL-VILLARD
2012-01-15 10:00 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-01-17 10:35   ` [PATCH 4/5] filetype: add command support Sascha Hauer
2012-01-15 10:00 ` [PATCH 5/5] usb-926x: add dfu mem options support Jean-Christophe PLAGNIOL-VILLARD
2012-01-17 10:29   ` 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=1326621621-11484-4-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /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