Commit 103c94b10481cf8479c9d0356e5202bc9200a04f

Authored by Wolfgang Denk
Committed by Tom Rini
1 parent be29df6a1a

setexpr: simplify code, improve help message

Simplify the argument checking for the "setexpr" command.  This is
done mainly to make future extensions easier.

Also improve the help message for the one argument version of the
command - this does not "load an address", but a value, which in
this context may be a plain number or a pointer dereference.

Signed-off-by: Wolfgang Denk <wd@denx.de>

Showing 1 changed file with 11 additions and 7 deletions Side-by-side Diff

common/cmd_setexpr.c
... ... @@ -56,22 +56,26 @@
56 56 ulong value;
57 57 int w;
58 58  
59   - /* Validate arguments */
60   - if (argc != 5 && argc != 3)
  59 + if (argc < 3)
61 60 return CMD_RET_USAGE;
62   - if (argc == 5 && strlen(argv[3]) != 1)
63   - return CMD_RET_USAGE;
64 61  
65 62 w = cmd_get_data_size(argv[0], 4);
66 63  
67 64 a = get_arg(argv[2], w);
68 65  
  66 + /* plain assignment: "setexpr name value" */
69 67 if (argc == 3) {
70 68 setenv_hex(argv[1], a);
71   -
72 69 return 0;
73 70 }
74 71  
  72 + /* standard operators: "setexpr name val1 op val2" */
  73 + if (argc != 5)
  74 + return CMD_RET_USAGE;
  75 +
  76 + if (strlen(argv[3]) != 1)
  77 + return CMD_RET_USAGE;
  78 +
75 79 b = get_arg(argv[4], w);
76 80  
77 81 switch (argv[3][0]) {
... ... @@ -117,7 +121,7 @@
117 121 " express specified by <op>. <op> can be &, |, ^, +, -, *, /, %\n"
118 122 " size argument is only meaningful if value1 and/or value2 are\n"
119 123 " memory addresses (*)\n"
120   - "setexpr[.b, .w, .l] name *value\n"
121   - " - load a memory address into a variable"
  124 + "setexpr[.b, .w, .l] name [*]value\n"
  125 + " - load a value into a variable"
122 126 );