forked from telnet23/bas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpty.bas
More file actions
83 lines (58 loc) · 2.37 KB
/
pty.bas
File metadata and controls
83 lines (58 loc) · 2.37 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
' PTY.BAS -- Ptycon helper
' %usage: pty.bas [line|command] [-e|-l|-f=<file>]
line$ = argv$( 1 )
50 ' argparse
for a = 1 to argc%
55 argv$( a ) = th_sed$( argv$( a ) , "^(-?-|\/)" )
if argv$( a ) = "?" or argv$( a ) = "h" or argv$( a ) = "help" then : goto 150
if argv$( a ) = "e" or argv$( a ) = "exit" then : exitpty = 1
if argv$( a ) = "q" or argv$( a ) = "quit" then : exitpty = 1
if argv$( a ) = "l" or argv$( a ) = "list" then : listpty = 1
if argv$( a ) = "le" or argv$( a ) = "el" then : exitpty = 1 : listpty = 1
if th_re( argv$( a ) , "^f(ile)?\=" ) then : pty_in$ = th_sed$( argv$( a ) , "f(ile)?\=" ) : pty_in = 1
if th_re( argv$( a ) , "\d" ) then : line$ = th_re$( argv$( a ) , "\d+" ) : isline = 1
next
for a = 1 to argc%
if argv$( a ) = "dx" or argv$( a ) = "rx" then : sx = 1
next
60 th_exec "call 666218"
sleep 0.1
if pty_in then : gosub 280
gosub 270
if not fnf and pty_in then : gosub 290
if sx then : goto 140
if isline then : th_exec "attach " + line$
gosub 170
end
140 th_exec argv$( a ) + " " + argv$( a + 1 ) + " " + argv$( a + 2 )
gosub 170
end
150 if not pty_in then : & "%usage: run " argv$( 0 ) " [line|command] [-e|-l|-f=<file>]"
&
& " -e, --exit" , "exit after running other commands"
& " -l, --list" , "list available lines"
& " -le, -el" , "both -e and -l"
& " -f=<file>" , "read commands from a file"
&
& " Argument order is nonstrict.
end
170 if exitpty then : th_exec "exit" ; out$
return
270 if listpty then : th_exec "list"
return
280 if pty_in$ = "" then : & ups$( "pty: please specify a file" ) : end
if not th_re( dir$ , "\s" + pty_in$ + "\s" ) then : & ups$( "pty: file '" + pty_in$ + "' not found" ) : return : fnf = 1
& ">>> READING FROM FILE '" pty_in$ "'..." : &
open pty_in$, as #1
281 if typ( 1 ) = 3 then : goto 285
input# 1, cmds$( cmd_count )
cmd_count = cmd_count + 1
goto 281
285 close #1
return
290 ' exec cmds from file
for i = 0 to cmd_count
th_exec cmds$( i )
sleep 0.1
next
return