Repository navigation
Expand file tree
/
Copy pathconsole_shared.go
More file actions
123 lines (104 loc) · 4.13 KB
/
Copy pathconsole_shared.go
File metadata and controls
123 lines (104 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"golang.org/x/crypto/ssh/terminal"
)
func P_execute(arguments []FunctionArgument, errMessage *error, globalVariableArray *[]Variable, globalFunctionArray *[]Function, scopeName string, globalNativeVarList *[]string, globalSettings *GlobalSettingsObject, line_number int, column_number int, file_name string) FunctionReturn {
ret := FunctionReturn{Type: RET_TYPE_STRING, StringValue: ""}
if arguments[0].Type == ARG_TYPE_FLOAT {
fmt.Printf("%f", arguments[0].FloatValue)
ret.StringValue = strconv.FormatFloat(arguments[0].FloatValue, 'f', -1, 64)
} else if arguments[0].Type == ARG_TYPE_STRING {
fmt.Printf("%s", escapeString(arguments[0].StringValue))
ret.StringValue = arguments[0].StringValue
} else if arguments[0].Type == ARG_TYPE_INTEGER {
//integer
fmt.Printf("%d", arguments[0].IntegerValue)
ret.StringValue = strconv.Itoa(arguments[0].IntegerValue)
} else if arguments[0].Type == ARG_TYPE_BOOLEAN {
//boolean
fmt.Printf("%v", arguments[0].BooleanValue)
if arguments[0].BooleanValue {
ret.StringValue = "true"
} else {
ret.StringValue = "false"
}
} else if arguments[0].Type == ARG_TYPE_ASSOCIATIVE_ARRAY {
strVal := ""
x := 0
for k, v := range arguments[0].AssociativeArrayValue {
if v.Type == ARG_TYPE_FLOAT {
strVal = strVal + k + ":" + strconv.FormatFloat(v.FloatValue, 'f', -1, 64)
} else if v.Type == ARG_TYPE_STRING {
strVal = strVal + k + ":" + v.StringValue
} else if v.Type == ARG_TYPE_INTEGER {
strVal = strVal + k + ":" + strconv.Itoa(v.IntegerValue)
} else if v.Type == ARG_TYPE_BOOLEAN {
if v.BooleanValue {
strVal = strVal + k + ":" + "true"
} else {
strVal = strVal + k + ":" + "false"
}
} else {
strVal = strVal + k + ":" + "Nil"
}
if (x + 1) != len(arguments[0].AssociativeArrayValue) {
strVal = strVal + ", "
}
x += 1
}
fmt.Printf("{%s}", strVal)
} else if arguments[0].Type == ARG_TYPE_ARRAY {
strVal := ""
for x := 0; x < len(arguments[0].ArrayValue); x++ {
if arguments[0].ArrayValue[x].Type == ARG_TYPE_FLOAT {
strVal = strVal + strconv.FormatFloat(arguments[0].ArrayValue[x].FloatValue, 'f', -1, 64)
} else if arguments[0].ArrayValue[x].Type == ARG_TYPE_STRING {
strVal = strVal + arguments[0].ArrayValue[x].StringValue
} else if arguments[0].ArrayValue[x].Type == ARG_TYPE_INTEGER {
strVal = strVal + strconv.Itoa(arguments[0].ArrayValue[x].IntegerValue)
} else if arguments[0].ArrayValue[x].Type == ARG_TYPE_BOOLEAN {
if arguments[0].ArrayValue[x].BooleanValue {
strVal = strVal + "true"
} else {
strVal = strVal + "false"
}
} else {
strVal = strVal + "Nil"
}
if (x + 1) != len(arguments[0].ArrayValue) {
strVal = strVal + ", "
}
}
fmt.Printf("[%s]", strVal)
} else {
//Nil
fmt.Println("Nil")
}
return ret
}
func R_execute(arguments []FunctionArgument, errMessage *error, globalVariableArray *[]Variable, globalFunctionArray *[]Function, scopeName string, globalNativeVarList *[]string, globalSettings *GlobalSettingsObject, line_number int, column_number int, file_name string) FunctionReturn {
ret := FunctionReturn{Type: RET_TYPE_STRING, StringValue: ""}
if validateParameters(arguments, errMessage, line_number, column_number, file_name, 0, ARG_TYPE_STRING) {
reader := bufio.NewReader(os.Stdin)
fmt.Printf("%s", escapeString(arguments[0].StringValue))
text, _ := reader.ReadString('\n')
ret.StringValue = strings.Trim(text, "\n")
}
return ret
}
func Rp_execute(arguments []FunctionArgument, errMessage *error, globalVariableArray *[]Variable, globalFunctionArray *[]Function, scopeName string, globalNativeVarList *[]string, globalSettings *GlobalSettingsObject, line_number int, column_number int, file_name string) FunctionReturn {
ret := FunctionReturn{Type: RET_TYPE_STRING, StringValue: ""}
if validateParameters(arguments, errMessage, line_number, column_number, file_name, 0, ARG_TYPE_STRING) {
fmt.Printf("%s", escapeString(arguments[0].StringValue))
text, err := terminal.ReadPassword(0)
if err == nil {
ret.StringValue = strings.Trim(string(text), "\n")
}
}
return ret
}