diff options
Diffstat (limited to 'CmdLine/main.swift')
-rw-r--r-- | CmdLine/main.swift | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/CmdLine/main.swift b/CmdLine/main.swift new file mode 100644 index 0000000..3876d05 --- /dev/null +++ b/CmdLine/main.swift @@ -0,0 +1,76 @@ +// +// main.swift +// CmdLine +// +// Created by Jacky Jack on 24/02/2023. +// + +import Foundation +import Darwin +//import cmd +import cmd + +print("Test CMD") +var tok:cmd_tok_t = cmd_tok_t() +var c="asd 123" +//cmd.(&tok, c, c.count) +//cmdparse_cmd(<#T##tl: UnsafeMutablePointer<cmd_tok_t>!##UnsafeMutablePointer<cmd_tok_t>!#>, <#T##str: UnsafePointer<CChar>!##UnsafePointer<CChar>!#>, <#T##str_size: Int##Int#>) +//var p = cmd.Par() +var p = cmd.CmdParser() +//p.parse() +let r = p.parse("123 0x0 0b1 \"this is me\" asd123 a@1 1.20 admin@main.lv") +let r1 = p.parse("ls") +let r2 = p.parse("one") +let r3 = p.parse("ls 123") +let r4 = p.parse("args 0x0 0b1 \"this is me\" asd123 a@1 1.20 admin@main.lv") +for e in 0..<r.count { + print("tok \(r[e].type) - \(r[e].val)") +} + +let cmd_ls = CmdTableEntry() +cmd_ls.command = "ls" +func call_ls(_ args:Array<CmdToken>?) { + print("List nothing") +} +cmd_ls.callback = call_ls + +let cmd_one = CmdTableEntry() +var cmd_one_i = 0 +cmd_one.command = "one" +func call_cmd(_ args:Array<CmdToken>?) { + print("+1 == \(cmd_one_i)") + cmd_one_i += 1 +} +cmd_one.callback = call_cmd + +let cmd_show_args = CmdTableEntry() +func call_show_args(_ _args:Array<CmdToken>?) { + if let args = _args { + for arg in args { + print("\(arg.val) ") + } + } +} +cmd_show_args.command = "args" +cmd_show_args.callback = call_show_args + +let commands = CmdTable() +commands.addEntry(cmd_ls) +commands.addEntry(cmd_one) +commands.addEntry(cmd_show_args) + + +commands.listCommands() + + +commands.execute(r) +commands.execute(r1) +commands.execute(r2) +commands.execute(r2) +commands.execute(r2) +commands.execute(r2) +commands.execute(r3) +commands.execute(r4) +print("Test CMD") + + |