1
0
mirror of https://github.com/fumiama/go-hide-param.git synced 2026-06-09 01:10:27 +08:00

adapt windows

This commit is contained in:
源文雨
2023-11-21 22:19:50 +08:00
parent 59ec042c4b
commit 083e2f3b87

38
win.go
View File

@@ -12,22 +12,23 @@ import (
// next splits command line string cmd into next // next splits command line string cmd into next
// argument and command line remainder. // argument and command line remainder.
func (cmd *commandSlice) next(is2erase bool) { func (cmd commandSlice) next(is2erase bool) commandSlice {
var inquote bool var inquote bool
var nslash int var nslash int
for ; len(*cmd) > 0; (*cmd) = (*cmd)[1:] { var erasenum int
switch (*cmd)[0] { for ; len(cmd) > 0; cmd = cmd[1:] {
switch cmd[0] {
case uint16(' '), uint16('\t'): case uint16(' '), uint16('\t'):
if !inquote { if !inquote {
return return cmd
} }
case uint16('"'): case uint16('"'):
if nslash%2 == 0 { if nslash%2 == 0 {
// use "Prior to 2008" rule from // use "Prior to 2008" rule from
// http://daviddeley.com/autohotkey/parameters/parameters.htm // http://daviddeley.com/autohotkey/parameters/parameters.htm
// section 5.2 to deal with double double quotes // section 5.2 to deal with double double quotes
if inquote && len(*cmd) > 1 && (*cmd)[1] == uint16('"') { if inquote && len(cmd) > 1 && (cmd)[1] == uint16('"') {
*cmd = (*cmd)[1:] cmd = cmd[1:]
} }
inquote = !inquote inquote = !inquote
} }
@@ -35,27 +36,30 @@ func (cmd *commandSlice) next(is2erase bool) {
continue continue
case uint16('\\'): case uint16('\\'):
nslash++ nslash++
if is2erase { fallthrough
(*cmd)[0] = uint16('*')
}
continue
default: default:
if is2erase { if is2erase {
(*cmd)[0] = uint16('*') erasenum++
if erasenum > 3 {
cmd[0] = uint16(' ')
} else {
cmd[0] = uint16('*')
}
} }
} }
nslash = 0 nslash = 0
} }
return cmd
} }
func (cmd *commandSlice) erase(pos uint) { func (cmd commandSlice) erase(pos uint) {
var p uint var p uint
for len(*cmd) > 0 && p <= pos { for len(cmd) > 0 && p <= pos {
if (*cmd)[0] == uint16(' ') || (*cmd)[0] == uint16('\t') { if cmd[0] == uint16(' ') || cmd[0] == uint16('\t') {
(*cmd) = (*cmd)[1:] cmd = cmd[1:]
continue continue
} }
cmd.next(p == pos) cmd = cmd.next(p == pos)
p++ p++
} }
} }
@@ -69,7 +73,7 @@ func utf16PtrToCommandSlice(p *uint16) commandSlice {
// Find NUL terminator. // Find NUL terminator.
end := unsafe.Pointer(p) end := unsafe.Pointer(p)
start := end start := end
n := 0 n := uintptr(0)
for *(*uint16)(end) != 0 { for *(*uint16)(end) != 0 {
end = unsafe.Pointer(uintptr(end) + unsafe.Sizeof(*p)) end = unsafe.Pointer(uintptr(end) + unsafe.Sizeof(*p))
n++ n++