[Turn on line numbering]arg line, @defs; var out, a, l, x, m, args, opts, o, i, v; // submit: ["template", "template"..] // => if value is 1, it will take the next part of the string // receive: [["template", "flag", bool, value]], [...]]; opts = (args = []); line = line.explode_quoted(); l = listlen(line); x = 1; while (x <= l) { a = line[x]; if ((m = regexp(a, "^[+-]"))) { o = m[1] == "+"; v = ""; a = substr(a, 2).trim(); if (!a) throw(~stop, "Missing option flag following '" + (o ? "+" : "-") + "'"); if ((i = "=" in a)) { if (i == strlen(a) && listlen(line) > x) { v = line[++x]; a = substr(a, 1, strlen(a) - 1).trim(); } else { [a, v] = explode(a, "=", 1); } } if ((i = find m in (defs) where (match_template(a, m)))) opts += [[defs[i], a, o, v]]; else opts += [[0, a, o, v]]; } else { args += [a]; } x++; } return [args, opts];
// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit