Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-17 Thread Jerry Van Baren
On 07/16/2010 04:41 PM, Scott Wood wrote:
> On Thu, 15 Jul 2010 22:15:22 -0500
> Kim Phillips  wrote:
>
>> u-boot environments, esp. when boards are shared across multiple users,
>> can get pretty large and time consuming to visually parse.
>> The grepenv command this patch adds can be used in lieu of printenv
>> to facilitate searching.  grepenv works like printenv but limits its output
>> only to environment strings (variable name and value pairs) that match the
>> user specified substring.
>
> Since it doesn't actually handle regular expressions, I'd call it
> something like findenv.  Or fgrepenv. :-)
>
> -Scott

Me too on "findenv".  I don't like fgrepenv since it has the same 
problem as "grepenv".  It actually is a gssp (global substring print) :-P.

gvb

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Scott Wood
On Thu, 15 Jul 2010 22:15:22 -0500
Kim Phillips  wrote:

> u-boot environments, esp. when boards are shared across multiple users,
> can get pretty large and time consuming to visually parse.
> The grepenv command this patch adds can be used in lieu of printenv
> to facilitate searching.  grepenv works like printenv but limits its output
> only to environment strings (variable name and value pairs) that match the
> user specified substring.

Since it doesn't actually handle regular expressions, I'd call it
something like findenv.  Or fgrepenv. :-)

-Scott

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Wolfgang Denk
Dear Kim Phillips,

In message <20100716140256.dd540fe6.kim.phill...@freescale.com> you wrote:
>
> hmm - it adds ~450bytes text+data on powerpc.  Is that the concern?
> 
> I can make it optional, but, if so, I'd also like to add it to
> config_cmd_default.h instead of it being added to 100s of board config
> files.

I think it should be optional, and not be enabled by default.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
Ninety-Ninety Rule of Project Schedules:
The first ninety percent of the task takes ninety percent of
the time, and the last ten percent takes the other ninety percent.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Wolfgang Denk
Dear Kim,

In message <20100716134252.b053e2dc.kim.phill...@freescale.com> you wrote:
>
> > I'm in the process of resturcturing the whole environment handling.
> > The new implementation will use a hash table for internal storage, so
> > this code would no longer apply then.
> 
> it would still apply, in that the environment should still be greppable,
> but, yes, if the internal structures are changed, this patch would need
> updating, along the same lines as with printenv and friends.

I don;t see how you would grep the entries in a hash table - except by
walking through all entries, which works, but is slow. But then, the
new code will print the variable alphabetically sorted, so looking up
a setting will be much easier anyway :-)

> technically this should be allowed in, because it was submitted first
> and it's need is overdue IMHO (I have already gotten off-list thanks
> for this patch).  Subsequent patches need to honour valid patches
> posted to the list first.

Yes, you are right. Let's put this patch on hold for now; eventually
we can have both this and the new env code.

> Having said that, would you like to send me your hash table patches?

I'm still working on fixes and cleanup. I intend to post the patches
before the MW closes, though (and provide a branch to pull from).

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
No man knows what true happiness is until he gets married.  By  then,
of course, its too late.
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Kim Phillips
On Fri, 16 Jul 2010 12:55:42 +0200
Wolfgang Denk  wrote:

> Dear "Reinhard Meyer (-VC)",
> 
> In message <4c403472.3070...@emk-elektronik.de> you wrote:
> >
> > >> The grepenv command this patch adds can be used in lieu of printenv
> > >> to facilitate searching.  grepenv works like printenv but limits its 
> > >> output
> > >> only to environment strings (variable name and value pairs) that match 
> > >> the
> > >> user specified substring.
> > 
> > My five cents to this: this addition command should be optional (#ifdef) 
> > anyway...
> 
> Agreed...

hmm - it adds ~450bytes text+data on powerpc.  Is that the concern?

I can make it optional, but, if so, I'd also like to add it to
config_cmd_default.h instead of it being added to 100s of board config
files.

Kim

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Kim Phillips
On Fri, 16 Jul 2010 11:27:03 +0200
Wolfgang Denk  wrote:

> Dear Kim Phillips,
> 
> In message <20100715221522.1dd4eecb.kim.phill...@freescale.com> you wrote:
> > u-boot environments, esp. when boards are shared across multiple users,
> > can get pretty large and time consuming to visually parse.
> > The grepenv command this patch adds can be used in lieu of printenv
> > to facilitate searching.  grepenv works like printenv but limits its output
> > only to environment strings (variable name and value pairs) that match the
> > user specified substring.
> 
> Thanks, but I will not apply thjis.
> 
> I'm in the process of resturcturing the whole environment handling.
> The new implementation will use a hash table for internal storage, so
> this code would no longer apply then.

it would still apply, in that the environment should still be greppable,
but, yes, if the internal structures are changed, this patch would need
updating, along the same lines as with printenv and friends.

> Please wait a bit for me to publish the new code, and then try to
> reimplement it in the new environment.

technically this should be allowed in, because it was submitted first
and it's need is overdue IMHO (I have already gotten off-list thanks
for this patch).  Subsequent patches need to honour valid patches
posted to the list first.

Having said that, would you like to send me your hash table patches?

Kim

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Wolfgang Denk
Dear "Reinhard Meyer (-VC)",

In message <4c403472.3070...@emk-elektronik.de> you wrote:
>
> >> The grepenv command this patch adds can be used in lieu of printenv
> >> to facilitate searching.  grepenv works like printenv but limits its output
> >> only to environment strings (variable name and value pairs) that match the
> >> user specified substring.
> 
> My five cents to this: this addition command should be optional (#ifdef) 
> anyway...

Agreed...

> > I'm in the process of resturcturing the whole environment handling.
> > The new implementation will use a hash table for internal storage, so
> > this code would no longer apply then.
> > 
> > Please wait a bit for me to publish the new code, and then try to
> > reimplement it in the new environment.
> 
> Will be there a means to mark variables as non-saveable, example if one
> does a bootp/dhcp and a saveenv afterwards, ip-address, filesize etc.
> are saved as well, which makes absolutely no sense. Neither does
> saving the ethaddr when it is created from VPD data :)

No, this is not part of my current work yet. However, once the hash
table based code is in place and working, it should be pretty
straightforward to extend the "struct entry", which currently holds
only two fields for name and value, by one or more additional fields
that can be used to store flags holding for example information like
what you mentioned.

But this is step 2 - at best.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
"Whoever undertakes to set himself up as a judge of Truth  and  Know-
ledge is shipwrecked by the laughter of the gods."  - Albert Einstein
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Reinhard Meyer (-VC)
Wolfgang Denk schrieb:
> Dear Kim Phillips,
> 
> In message <20100715221522.1dd4eecb.kim.phill...@freescale.com> you wrote:
>> u-boot environments, esp. when boards are shared across multiple users,
>> can get pretty large and time consuming to visually parse.
>> The grepenv command this patch adds can be used in lieu of printenv
>> to facilitate searching.  grepenv works like printenv but limits its output
>> only to environment strings (variable name and value pairs) that match the
>> user specified substring.

My five cents to this: this addition command should be optional (#ifdef) 
anyway...

> 
> Thanks, but I will not apply thjis.
> 
> I'm in the process of resturcturing the whole environment handling.
> The new implementation will use a hash table for internal storage, so
> this code would no longer apply then.
> 
> Please wait a bit for me to publish the new code, and then try to
> reimplement it in the new environment.

Will be there a means to mark variables as non-saveable, example if one
does a bootp/dhcp and a saveenv afterwards, ip-address, filesize etc.
are saved as well, which makes absolutely no sense. Neither does
saving the ethaddr when it is created from VPD data :)

Reinhard

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH] common: add a grepenv command

2010-07-16 Thread Wolfgang Denk
Dear Kim Phillips,

In message <20100715221522.1dd4eecb.kim.phill...@freescale.com> you wrote:
> u-boot environments, esp. when boards are shared across multiple users,
> can get pretty large and time consuming to visually parse.
> The grepenv command this patch adds can be used in lieu of printenv
> to facilitate searching.  grepenv works like printenv but limits its output
> only to environment strings (variable name and value pairs) that match the
> user specified substring.

Thanks, but I will not apply thjis.

I'm in the process of resturcturing the whole environment handling.
The new implementation will use a hash table for internal storage, so
this code would no longer apply then.

Please wait a bit for me to publish the new code, and then try to
reimplement it in the new environment.

So thanks, but sorry...

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
The use of COBOL cripples the mind; its teaching  should,  therefore,
be regarded as a criminal offense.   - E. W. Dijkstra
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH] common: add a grepenv command

2010-07-15 Thread Kim Phillips
u-boot environments, esp. when boards are shared across multiple users,
can get pretty large and time consuming to visually parse.
The grepenv command this patch adds can be used in lieu of printenv
to facilitate searching.  grepenv works like printenv but limits its output
only to environment strings (variable name and value pairs) that match the
user specified substring.

Signed-off-by: Kim Phillips 
---
 common/cmd_nvedit.c |   55 ++-
 common/command.c|1 +
 2 files changed, 55 insertions(+), 1 deletions(-)

diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index 13325bc..c4bde27 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -4,7 +4,9 @@
  *
  * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH 
  * Andreas Heppel 
-
+ *
+ * Copyright 2010 Freescale Semiconductor, Inc.
+ *
  * See file CREDITS for list of people who contributed to this
  * project.
  *
@@ -139,6 +141,50 @@ static int printenv(char *name, int state)
return i;
 }
 
+int do_grepenv (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   char buf[CONFIG_SYS_CBSIZE], *searchstr;
+   int i = 0, j = 0, k = 0;
+   int rcode = 1;
+
+   if (argc != 2) {
+   cmd_usage(cmdtp);
+   return 1;
+   }
+
+   searchstr = argv[1];
+
+   /* find and print matching env vars */
+   do {
+   buf[j] = env_get_char(i);
+   if (buf[j] == searchstr[k]) {
+   k++;
+   if (searchstr[k] == '\0') {
+   /* match complete */
+   rcode = 0;
+   do {
+   i++; j++;
+   buf[j] = env_get_char(i);
+   } while (buf[j] != '\0');
+   puts(buf); puts("\n");
+   j = 0; k = 0;
+   } else
+   j++;
+   } else {
+   k = 0;
+   if (buf[j] == '\0') {
+   j = 0;
+   if (ctrlc())
+   return -1;
+   } else
+   j++;
+   }
+   i++;
+   } while (!(j == 0 && env_get_char(i) == '\0'));
+
+   return rcode;
+}
+
 int do_printenv (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
int i;
@@ -634,6 +680,13 @@ U_BOOT_CMD(
 );
 
 U_BOOT_CMD(
+   grepenv, 2, 0,  do_grepenv,
+   "search environment",
+   "fixed-string\n"
+   "- list environment name and value pairs matching 'fixed-string'"
+);
+
+U_BOOT_CMD(
setenv, CONFIG_SYS_MAXARGS, 0,  do_setenv,
"set environment variables",
"name value ...\n"
diff --git a/common/command.c b/common/command.c
index a1fc592..305bda0 100644
--- a/common/command.c
+++ b/common/command.c
@@ -191,6 +191,7 @@ void install_auto_complete(void)
 #if defined(CONFIG_CMD_EDITENV)
install_auto_complete_handler("editenv", var_complete);
 #endif
+   install_auto_complete_handler("grepenv", var_complete);
install_auto_complete_handler("printenv", var_complete);
install_auto_complete_handler("setenv", var_complete);
 #if defined(CONFIG_CMD_RUN)
-- 
1.7.1.1


___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot