/
bash.bas
222 lines (210 loc) · 5.02 KB
/
bash.bas
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
color 15,5
#define SIGINT 2
#define SIG_IGN cptr(sighandler_t, 1)
Type sighandler_t As Sub cdecl (ByVal As Integer)
Declare Function signal cdecl alias "signal" ( ByVal signum As Integer, ByVal handler As sighandler_t ) As sighandler_t
#include "vbcompat.bi"
#include once "crt/unistd.bi"
dim shared nnames(0 to 2048) as string
dim shared vvalues(0 to 2048) as string
dim shared vars as integer
dim shared counter(0 to 2048) as integer
dim shared progr(0 to 2048) as string
dim shared c as integer
dim shared exitss as integer
dim shared pp as integer
Declare Function kills lib "sigs" alias "kills" (p as integer,sig as integer) As Integer
Sub intercept cdecl (ByVal sig As Integer)
Print "^c"
End Sub
sub listvar()
dim eee as integer=-1
dim i as integer
for i=0 to vars
print nnames(i)+"="+vvalues(i)
next
end sub
sub setvar(names as string,values as string)
dim eee as integer=-1
dim i as integer
for i=0 to vars
if names=nnames(i) then
eee=i
vvalues(i)=values
i=vars
end if
next
if eee=-1 then
nnames(vars)=names
vvalues(vars)=values
vars=vars+1
end if
end sub
function getvars(names as string)as string
dim retss as string=""
dim eee as integer=-1
dim i as integer
for i=0 to vars
if names=nnames(i) then
eee=i
return vvalues(i)
i=vars
end if
next
return ""
end function
Sub producer(s as string,p as integer)
dim fff as integer= freefile
counter(c)=p
progr(c)=s
c=c+1
pp=p
print pp ;
print " "+s
Open Pipe s For Input As #fff
Dim As String ln
Do Until EOF(fff)
Line Input #fff, ln
Print ln
Loop
Close #fff
system()
End Sub
Dim As Integer i = 2
dim ss as string
dim sss as string
dim ssss as string
dim process as integer
dim d1 as integer
dim d2 as integer
dim cc as integer
dim ccc as integer
dim s1 as string
dim ppos as integer
dim script as integer
dim cond as integer
dim files1 as integer
dim s as string
dim files2 as integer
If signal(SIGINT, @intercept) = SIG_IGN Then signal(SIGINT, SIG_IGN)
i=0
Do
Dim As String arg = Command(i)
If Len(arg) = 0 Then
Exit Do
End If
setvar trim(str(i)),arg
i += 1
Loop
files1=freefile
Open Scrn For Input shared As #files1
while instr(lcase(trim(ss)),"exit")=0
if script=0 then
print curdir()+" >>>>";
line input #files1,ss
else
line input #files2,ss
end if
if lcase(trim(ss))="ps" then
print c ; " programs runing"
for i=0 to c-1
print trim(str(counter(i)))+" "+progr(i)
next
else
cc=instr(lcase(trim(ss)),"=")
if cc<1 then cc=len(ss)
i=instr(lcase(trim(ss))," ")
if i<1 then i=len(ss)
if cc<i then
SetEnviron(ss)
ss=trim(ss)
sss=mid(ss,1,instr(ss,"=")-1)
ssss=mid(ss,instr(ss,"=")+1)
setvar sss,ssss
else
if instr(lcase(trim(ss)),"cd ")=1 then
d1=instr(lcase(trim(ss))," ")
if d1>0 and d1<len(ss)then
ChDir(mid(ss,d1+1))
end if
else
d1=instr(ss,"&")
if d1> 0 then
ss=mid(ss,1,d1-1)
process=fork()
if process<>0 then producer(ss,process)
else
if instr(lcase(trim(ss)),"read ")=1 then
SetEnviron(ss)
sss=mid(ss,instr(ss," ")+1)
line input ssss
setvar sss,ssss
else
if lcase(trim(ss))="set" then
listvar()
else
cc=instr(lcase(trim(ss)),".lst")
if cc<1 then cc=len(ss)
i=instr(lcase(trim(ss))," ")
if i<1 then i=len(ss)
if cc<i then
script=1
i=0
files2=freefile
ss=trim(ss)
sss=mid(ss,1,instr(ss," ")-1)
Open sss For Input shared As #files2
ssss=ss+" END"
do
ccc=len(ssss)
cc=instr(ssss," ")
if cc>0 then ccc=instr(cc,ssss," ")
if cc<1 then cc=len(ssss)
s1=trim(mid(ssss,1,cc))
setvar trim(str(i)),s1
i=i+1
s1=""
if cc=len(ssss) then
ssss=mid(ssss,cc)
else
ssss=mid(ssss,cc+1)
end if
if instr(ssss," ")<1 then exit do
loop
else
ss=trim(ss)
sss=mid(ss,1,instr(ss," ")-1)
ssss=mid(ss,instr(ss," "))
while instr(ssss,"$")<>0
ccc=len(ssss)
cc=instr(ssss,"$")
if cc>0 then ccc=instr(cc,ssss," ")
if ccc<1 then ccc=len(ssss)
s1=trim(mid(ssss,cc+1,ccc-(cc)))
s1=trim(getvars(s1))
s1=s1+" "
if instr(s1,"$")>0 then s1=""
if cc=1 then
ssss=s1+mid(ssss,ccc+1)
else
if ccc=len(ssss) or ccc=len(ssss)-1 or ccc-1=len(ssss) then
ssss=mid(ssss,1,cc-1)+s1
else
ssss=mid(ssss,1,cc-1)+s1+mid(ssss,ccc+1)
end if
end if
wend
exec(sss,ssss)
end if
end if
end if
end if
end if
end if
end if
if script=1 and eof(files2) then
close files2
script=0
end if
wend
close