Bläddra i källkod

[cmdline] Allow ";" as an unconditional command separator

It is currently possible to construct a sequence of commands to be
executed regardless of success or failure using "|| &&" as the command
separator.  (The "||" captures the failure case, the blank command
converts it to a success case.)

Allow ";" to be used as a more visually appealing (and
space-efficient) alternative.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 år sedan
förälder
incheckning
1f4c5f90c3
1 ändrade filer med 14 tillägg och 0 borttagningar
  1. 14
    0
      src/core/exec.c

+ 14
- 0
src/core/exec.c Visa fil

@@ -142,6 +142,16 @@ static int process_on_failure ( int rc ) {
142 142
 	return ( rc != 0 );
143 143
 }
144 144
 
145
+/**
146
+ * Process next command regardless of status from previous command
147
+ *
148
+ * @v rc		Status of previous command
149
+ * @ret process		Process next command
150
+ */
151
+static int process_always ( int rc __unused ) {
152
+	return 1;
153
+}
154
+
145 155
 /**
146 156
  * Find command terminator
147 157
  *
@@ -166,6 +176,10 @@ static int command_terminator ( char **tokens,
166 176
 			/* Short-circuit logical AND */
167 177
 			*process_next = process_on_success;
168 178
 			return i;
179
+		} else if ( strcmp ( tokens[i], ";" ) == 0 ) {
180
+			/* Process next command unconditionally */
181
+			*process_next = process_always;
182
+			return i;
169 183
 		}
170 184
 	}
171 185
 

Laddar…
Avbryt
Spara