iPXE discussion forum
New operator islo (is lower)? - Printable Version

+- iPXE discussion forum (https://forum.ipxe.org)
+-- Forum: iPXE user forums (/forumdisplay.php?fid=1)
+--- Forum: General (/forumdisplay.php?fid=2)
+--- Thread: New operator islo (is lower)? (/showthread.php?tid=8317)



New operator islo (is lower)? - murmansk - 2017-02-06 15:12

Hi,

I'm trying to show different boot options, based on the memory of the computer: PCs with less than 1GB will not be allowed to install some operating systems.

I know that it can be made by sending {memsize} to a web server PHP script, and returning the PXE script with the correct boot options. But we have lots of remote sites that use PXE and don't have a local web server in them, nor a good network access to our central servers. So I'm trying to put all the logic inside the PXE boot script.

I looked at the 'iseq' (is equal) command source code, and cloned it into a new command: 'islo' (is lower). It seems to work ok with positive numbers.

I think that it could be interesting to add this operator: with `iseq' and 'islo' you can express any integer comparison.

I copy the 'git diff' here:

diff --git a/src/core/exec.c b/src/core/exec.c
index a13884b..ee19d1b 100644
--- a/src/core/exec.c
+++ b/src/core/exec.c
@@ -549,6 +549,48 @@ struct command iseq_command __command = {
.exec = iseq_exec,
};

+/** "islo" options */
+struct islo_options {};
+
+/** "islo" option list */
+static struct option_descriptor islo_opts[] = {};
+
+/** "islo" command descriptor */
+static struct command_descriptor islo_cmd =
+ COMMAND_DESC ( struct islo_options, islo_opts, 2, 2,
+ "<value1> <value2>" );
+
+/**
+ * "islo" command
+ *
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Return status code
+ */
+static int islo_exec ( int argc, char **argv ) {
+ struct islo_options opts;
+ unsigned int operand0, operand1;
+ int rc;
+
+ /* Parse options */
+ if ( ( rc = parse_options ( argc, argv, &islo_cmd, &opts ) ) != 0 )
+ return rc;
+
+ if ( ( rc = parse_integer ( argv[optind], &operand0 ) ) != 0 )
+ return rc;
+ if ( ( rc = parse_integer ( argv[optind+1], &operand1 ) ) != 0 )
+ return rc;
+
+ /* Return success if operand0 is lower than operand1 */
+ return ( ( operand0 < operand1 ) ? 0 : -ERANGE );
+}
+
+/** "islo" command */
+struct command islo_command __command = {
+ .name = "islo",
+ .exec = islo_exec,
+};
+
/** "sleep" options */
struct sleep_options {};