From ea061d5b7aa3c41c32c4b3f6d79f389e176c1216 Mon Sep 17 00:00:00 2001 From: dianshi Date: Sat, 24 Jun 2023 08:40:22 +0100 Subject: Add all missing sources --- cmd/cmd.swift | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 cmd/cmd.swift (limited to 'cmd/cmd.swift') diff --git a/cmd/cmd.swift b/cmd/cmd.swift new file mode 100644 index 0000000..ec1ca44 --- /dev/null +++ b/cmd/cmd.swift @@ -0,0 +1,78 @@ +// +// cmd.swift +// cmd +// +// Created by Jacky Jack on 12/06/2023. +// + +import Foundation + +public class CmdToken { + public var type:Int = 0 + public var val="" + init(type: Int, val: String = "") { + self.type = type + self.val = val + } +} + + +public class CmdParser { + + public init() {} + + public func parse() { + var tok:cmd_tok_t = cmd_tok_t() + //var pointer = UnsafeMutablePointer(&tok) + var c="hello 123 0x0" + parse_cmd(&tok, c, c.count) + + + var iter = tok + while (iter.next != nil) { + iter = iter.next.pointee + //print("\(iter.type) \(iter.s) \(iter.e) \(iter.next) \(iter.sz)") + } + } + + public func parse(_ cmd: String) -> Array { + var token_list = Array() + var tok:cmd_tok_t = cmd_tok_t() + parse_cmd(&tok, cmd, cmd.count ) + + var iter = tok + var start_str = UnsafeRawPointer(cmd) + //print("cmd \(start_str)") + while (iter.next != nil) { + iter = iter.next.pointee + //print("\(iter.type) \(iter.s) \(iter.e) \(iter.next) \(iter.sz)") + if let start = iter.s { + //print("yes") + } else { + //print("Cant unwrap") + } + let addr_s = UnsafeRawPointer(&iter.s.pointee) + let addr_e = UnsafeRawPointer(&iter.e.pointee) + //let addr_len = addr_e - addr_s + //print("s \(addr_s) e \(addr_e)") + + //let length = iter.e - iter.s + + let sub_st = cmd.index(cmd.startIndex, offsetBy: addr_s - start_str ) + let sub_en = cmd.index(cmd.startIndex, offsetBy: addr_e - start_str ) + let subs = cmd[sub_st..