[Turn off line numbering]1: arg line, @defs; 2: var out, a, l, x, m, args, opts, o, i, v; 3: 4: // submit: ["template", "template"..] 5: // => if value is 1, it will take the next part of the string 6: // receive: [["template", "flag", bool, value]], [...]]; 7: opts = (args = []); 8: line = line.explode_quoted(); 9: l = listlen(line); 10: x = 1; 11: while (x <= l) { 12: a = line[x]; 13: if ((m = regexp(a, "^[+-]"))) { 14: o = m[1] == "+"; 15: v = ""; 16: a = substr(a, 2).trim(); 17: if (!a) 18: throw(~stop, "Missing option flag following '" + (o ? "+" : "-") + "'"); 19: if ((i = "=" in a)) { 20: if (i == strlen(a) && listlen(line) > x) { 21: v = line[++x]; 22: a = substr(a, 1, strlen(a) - 1).trim(); 23: } else { 24: [a, v] = explode(a, "=", 1); 25: } 26: } 27: if ((i = find m in (defs) where (match_template(a, m)))) 28: opts += [[defs[i], a, o, v]]; 29: else 30: opts += [[0, a, o, v]]; 31: } else { 32: args += [a]; 33: } 34: x++; 35: } 36: return [args, opts];
// Created 27-Mar-1995 as a part of ColdCore, see: @help Credit