sgar.bas 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  1. ' Simple Garage (Garage manager program for Stunts)
  2. ' Copyright (C) 2022 Lucas Pedrosa
  3. ' This program is free software: you can redistribute it and/or modify
  4. ' it under the terms of the GNU General Public License as published by
  5. ' the Free Software Foundation, version 3 of the License.
  6. ' This program is distributed in the hope that it will be useful,
  7. ' but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. ' GNU General Public License for more details.
  10. ' You should have received a copy of the GNU General Public License
  11. ' along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. ' COMPILATION:
  13. ' Simple Garage has been compiled with FreeBasic 1.09.1 and tested
  14. ' in GNU/Linux Mint, FreeDOS and DOSBox
  15. ' It should compile well with any newer version and likely, with some
  16. ' older versions. You can get FreeBasic at:
  17. ' - http://www.freebasic.net
  18. ' For GNU/Linux and for DOS, compile with:
  19. ' - fbc sgar.bas
  20. ' For Windows, compile with:
  21. ' - fbc -s gui sgar.bas
  22. 'Simple Garage program
  23. 'Version 2 started 2022-08-27
  24. #define SGVERSION "2.0"
  25. #define MAXCARSPERGARAGE 100
  26. #include "file.bi"
  27. #ifdef __FB_LINUX__
  28. #define SLASH "/"
  29. #else
  30. #define SLASH "\"
  31. #endif
  32. Type Car
  33. id As String
  34. file(1 To 9) As String
  35. numfiles As Byte
  36. carname As String
  37. version As String
  38. author As String
  39. End Type
  40. Type Group
  41. gname As String
  42. cars As String
  43. End Type
  44. Type Garage
  45. dir As String
  46. name As String
  47. End Type
  48. Dim Shared car(0 To 15, 1 To MAXCARSPERGARAGE) As Car, cars(0 To 15) As UByte
  49. Dim Shared garage(0 To 15) As Garage, garages As UByte
  50. Dim Shared group(1 To 50) As Group, groups As UByte, locked As String
  51. Dim Shared progdir As String, cfgfile As String
  52. Dim Shared release_date As String, copyright_notice As String
  53. Dim Shared lastcommand(1 To 10) As String
  54. Sub LoadConfig
  55. garage(0).dir = "." : garage(1).dir = "garage"
  56. locked = "coun" : garages = 1
  57. progdir = ExePath
  58. If Right(progdir, 1) <> SLASH Then progdir &= SLASH
  59. cfgfile = progdir & "sgar.cfg"
  60. If Not FileExists(progdir & "sgar.cfg") Then Exit Sub
  61. Dim f As Integer, s As String
  62. Dim p As String, v As String, n As Short
  63. f = FreeFile
  64. Open progdir & "sgar.cfg" For Input As f
  65. Line Input #f, s
  66. If LCase(Left(s, 4)) = "cfg=" Then
  67. cfgfile = Mid(s, 5)
  68. Close f
  69. If FileExists(Mid(s, 5)) Then
  70. Open Mid(s, 5) For Input As f
  71. Else
  72. 'Redirection failed. No such configuration file.
  73. Exit Sub
  74. End If
  75. Else
  76. Seek #f, 1
  77. cfgfile = progdir & "sgar.cfg"
  78. End If
  79. garages = 0 : groups = 0
  80. While Not EoF(f)
  81. Line Input #f, s
  82. n = InStr(s, "=")
  83. If n Then
  84. p = LCase(Trim(Left(s, n - 1)))
  85. v = Trim(Mid(s, n + 1))
  86. Select Case p
  87. Case "stunts", "root"
  88. garage(0).dir = v
  89. garage(0).name = "Stunts"
  90. Case "garage"
  91. garages += 1
  92. n = InStr(v, ":")
  93. If n Then
  94. garage(garages).dir = Mid(v, n + 1)
  95. garage(garages).name = Left(v, n - 1)
  96. Else
  97. garage(garages).dir = v
  98. garage(garages).name = ""
  99. End If
  100. Case "junkyard"
  101. garages += 1
  102. garage(garages).dir = v
  103. garage(garages).name = "junkyard"
  104. Case "locked"
  105. locked = LCase(Trim(v))
  106. Case "group"
  107. n = InStr(v, ":")
  108. If n Then
  109. groups += 1
  110. group(groups).gname = LCase(Trim(Left(v, n - 1)))
  111. group(groups).cars = LCase(Trim(Mid(v, n + 1)))
  112. End If
  113. End Select
  114. End If
  115. WEnd
  116. Close f
  117. 'This will default to a garage named "garage" under the current path
  118. 'which may or may not work!
  119. If garages = 0 Then garages = 1
  120. End Sub
  121. Sub SaveConfig
  122. Dim f As Integer
  123. f = FreeFile
  124. Open cfgfile For Output As f
  125. If Err Then Exit Sub 'Wrong file name. Can't create
  126. Print #f, "stunts=" & garage(0).dir
  127. For i As Short = 1 To garages
  128. If Len(garage(i).name) Then
  129. Print #f, "garage=" & garage(i).name & ":" & garage(i).dir
  130. Else
  131. Print #f, "garage=" & garage(i).dir
  132. End If
  133. Next i
  134. Print #f, "locked=" & locked
  135. For i As Short = 1 To groups
  136. Print #f, "group=" & group(i).gname & ":" & group(i).cars
  137. Next i
  138. Close f
  139. End Sub
  140. Sub ReadDirs
  141. Dim As String s, t, id
  142. Dim code As Byte
  143. For collection As Byte = 0 To garages
  144. #ifdef __FB_LINUX__
  145. s = Dir(garage(collection).dir & SLASH & "*")
  146. #else
  147. s = Dir(garage(collection).dir & SLASH & "*.*")
  148. #endif
  149. While Len(s)
  150. t = LCase(s) : code = 0
  151. If Left(t, 3) = "car" AndAlso Right(t, 4) = ".res" AndAlso Len(t) = 11 Then
  152. 'Res file
  153. id = Mid(t, 4, 4)
  154. code = 1
  155. ElseIf Left(t, 4) = "stda" AndAlso Right(t, 4) = ".vsh" AndAlso Len(t) = 12 Then
  156. 'Uncompressed stda file
  157. id = Mid(t, 5, 4)
  158. code = 3
  159. ElseIf Left(t, 4) = "stda" AndAlso Right(t, 4) = ".pvs" AndAlso Len(t) = 12 Then
  160. 'Compressed stda file
  161. id = Mid(t, 5, 4)
  162. code = 4
  163. ElseIf Left(t, 4) = "stdb" AndAlso Right(t, 4) = ".vsh" AndAlso Len(t) = 12 Then
  164. 'Uncompressed stdb file
  165. id = Mid(t, 5, 4)
  166. code = 5
  167. ElseIf Left(t, 4) = "stdb" AndAlso Right(t, 4) = ".pvs" AndAlso Len(t) = 12 Then
  168. 'Compressed stdb file
  169. id = Mid(t, 5, 4)
  170. code = 6
  171. ElseIf Left(t, 2) = "st" AndAlso Right(t, 4) = ".3sh" AndAlso Len(t) = 10 Then
  172. 'Uncompressed shape file
  173. id = Mid(t, 3, 4)
  174. code = 7
  175. ElseIf Left(t, 2) = "st" AndAlso Right(t, 4) = ".p3s" AndAlso Len(t) = 10 Then
  176. 'Compressed shape file
  177. id = Mid(t, 3, 4)
  178. code = 8
  179. ElseIf Left(t, 3) = "car" AndAlso Right(t, 4) = ".cfg" AndAlso Len(t) = 11 Then
  180. 'Car configuration file
  181. id = Mid(t, 4, 4)
  182. code = 9
  183. End If
  184. If code Then
  185. Dim q As Byte = 0
  186. For i As Short = 1 To cars(collection)
  187. If car(collection, i).id = id Then
  188. q = -1
  189. car(collection, i).file(code) = s
  190. 'Don't include the configuration file in the count
  191. 'so it's easier to recognise redundant files
  192. If code <> 9 Then car(collection, i).numfiles += 1
  193. Exit For
  194. End If
  195. Next i
  196. If q = 0 Then
  197. cars(collection) += 1
  198. car(collection, cars(collection)).id = id
  199. car(collection, cars(collection)).numfiles = 1
  200. For i As Byte = 1 To 9
  201. car(collection, cars(collection)).file(i) = ""
  202. Next i
  203. car(collection, cars(collection)).file(code) = s
  204. End If
  205. End If
  206. s = Dir
  207. WEnd
  208. Next collection
  209. End Sub
  210. Sub ExtractCarInfo (c As Car, path As String)
  211. If Len(c.file(1)) = 0 Then
  212. c.carname = "Unknown"
  213. Else
  214. Dim f As Integer, s As String, n As Short, l As Long
  215. f = FreeFile
  216. Open path & SLASH & c.file(1) For Binary Access Read As f
  217. s = Space(100)
  218. Get #f, , s
  219. n = InStr(s, "gnam")
  220. Get #f, n + 16, l
  221. l += 39
  222. s = Space(255)
  223. Get #f, l, s
  224. n = InStr(s, Chr(0))
  225. If n Then s = Left(s, n - 1) Else s = Left(s, 40)
  226. Close f
  227. c.carname = s
  228. End If
  229. c.author = "" : c.version = ""
  230. If Len(c.file(9)) <> 0 Then
  231. Dim f As Integer, s As String, n As Short
  232. f = FreeFile
  233. Open path & SLASH & c.file(9) For Input As f
  234. While Not EoF(f)
  235. Line Input #f, s
  236. n = InStr(s, "=")
  237. If n Then
  238. Select Case LCase(Trim(Left(s, n - 1)))
  239. Case "version", "ver"
  240. c.version = Trim(Mid(s, n + 1))
  241. Case "author"
  242. c.author = Trim(Mid(s, n + 1))
  243. End Select
  244. End If
  245. WEnd
  246. Close f
  247. End If
  248. End Sub
  249. Function Resolve(s As String) As String
  250. 'Obtain a list of cars from a search string that can
  251. 'be a car, a list of cars, a group or a filter
  252. Dim n As Short, t As String, ss As String
  253. Dim result As String
  254. n = InStr(s, ",")
  255. If n Then 'It's a list
  256. Dim temp As String
  257. t = s
  258. Do
  259. n = InStr(t, ",")
  260. If n Then
  261. ss = Left(t, n - 1)
  262. t = Mid(t, n + 1)
  263. Else
  264. ss = t
  265. t = ""
  266. End If
  267. temp = Resolve(ss)
  268. If Len(temp) Then
  269. If Len(result) Then result &= ","
  270. result &= temp
  271. End If
  272. Loop Until Len(t) = 0
  273. ElseIf Left(s, 1) = "#" Then 'It's a group
  274. For i As Short = 1 To groups
  275. If LCase(group(i).gname) = LCase(Mid(s, 2)) Then Return group(i).cars
  276. Next i
  277. ElseIf Len(s) = 4 AndAlso InStr(s, "*") = 0 AndAlso InStr(s, ",") = 0 Then 'It's a car
  278. Return LCase(s)
  279. Else 'It's a filter
  280. Dim filtype As Byte, q As Byte
  281. If s = "*" Then
  282. filtype = 0
  283. ElseIf Left(s, 1) = "*" AndAlso Right(s, 1) = "*" Then
  284. filtype = 1
  285. ss = LCase(Mid(s, 2, Len(s) - 2))
  286. ElseIf Left(s, 1) = "*" Then
  287. filtype = 2
  288. ss = LCase(Mid(s, 2))
  289. ElseIf Right(s, 1) = "*" Then
  290. filtype = 3
  291. ss = LCase(Left(s, Len(s) - 1))
  292. Else
  293. filtype = 1
  294. ss = LCase(s)
  295. End If
  296. For g As Short = 0 To garages
  297. For i As Short = 1 To cars(g)
  298. q = 0
  299. Select Case filtype
  300. Case 0 : q = -1 'All
  301. Case 1
  302. If InStr(LCase(car(g, i).carname), ss) _
  303. OrElse InStr(LCase(car(g, i).id), ss) Then q = -1
  304. Case 2
  305. If Right(LCase(car(g, i).carname), Len(ss)) = ss _
  306. OrElse Right(LCase(car(g, i).id), Len(ss)) = ss Then q = -1
  307. Case Else
  308. If Left(LCase(car(g, i).carname), Len(ss)) = ss _
  309. OrElse Left(LCase(car(g, i).id), Len(ss)) = ss Then q = -1
  310. End Select
  311. If q <> 0 AndAlso InStr(result, LCase(car(g, i).id)) = 0 Then 'Add car to the list
  312. If Len(result) Then result &= ","
  313. result &= LCase(car(g, i).id)
  314. End If
  315. Next i
  316. Next g
  317. End If
  318. 'Get rid of repeated cars
  319. t = result
  320. result = ""
  321. Do
  322. n = InStr(t, ",")
  323. If n Then
  324. ss = Left(t, n - 1)
  325. t = Mid(t, n + 1)
  326. Else
  327. ss = t
  328. t = ""
  329. End If
  330. If InStr(result, ss) = 0 Then
  331. If Len(result) Then result &= ","
  332. result &= ss
  333. End If
  334. Loop Until Len(t) = 0
  335. Return result
  336. End Function
  337. Function MoveCar (id As String, orig As UByte, dest As UByte) As Byte
  338. Dim n As Short, many As Byte
  339. If Left(id, 1) = "#" Then 'It's a referenced group
  340. many = 1
  341. ElseIf InStr(id, ",") Then 'It's an ad-hoc group
  342. many = 2
  343. Else 'It's an individual car
  344. many = 0
  345. End If
  346. If many Then
  347. 'This is a group. Call repeatedly for each car
  348. Dim s As String, ercount As Short
  349. Dim thiscar As String, gn As Short = 0
  350. If many = 1 Then
  351. For i As Short = 1 To groups
  352. If group(i).gname = LCase(Mid(id, 2)) Then
  353. gn = i
  354. Exit For
  355. End If
  356. Next i
  357. If gn = 0 Then Return 1 'Group not found
  358. s = group(gn).cars
  359. Else
  360. s = id
  361. End If
  362. Do
  363. n = InStr(s, ",")
  364. If n Then
  365. thiscar = LCase(RTrim(Left(s, n - 1)))
  366. s = LTrim(Mid(s, n + 1))
  367. Else
  368. thiscar = LCase(Trim(s))
  369. s = ""
  370. End If
  371. ercount += MoveCar(thiscar, orig, dest)
  372. Loop Until Len(s) = 0
  373. If ercount Then Return 2 Else Return 0
  374. End If
  375. 'If car is locked, it cannot be moved
  376. If InStr(LCase(locked), LCase(id)) Then Return 3
  377. 'Find car
  378. n = 0
  379. For i As Short = 1 To cars(orig)
  380. If LCase(car(orig, i).id) = LCase(id) Then
  381. n = i
  382. Exit For
  383. End If
  384. Next i
  385. If n = 0 Then Return 1 'Car not found
  386. 'Move files
  387. For i As Short = 1 To 8
  388. If Len(car(orig, n).file(i)) Then
  389. FileCopy garage(orig).dir & SLASH & car(orig, n).file(i), garage(dest).dir & SLASH & car(orig, n).file(i)
  390. Kill garage(orig).dir & SLASH & car(orig, n).file(i)
  391. End If
  392. Next i
  393. 'Move car in lists
  394. cars(dest) += 1
  395. car(dest, cars(dest)) = car(orig, n)
  396. For i As Short = n To cars(orig)
  397. car(orig, i) = car(orig, i + 1)
  398. Next i
  399. cars(orig) -= 1
  400. Return 0 'Executed successfully
  401. End Function
  402. Sub Init
  403. LoadConfig
  404. If garage(0).dir = garage(1).dir Then
  405. Print
  406. Print "Error: Stunts and garage directory are the same or undefined!"
  407. Print " Edit sgar.cfg to set them correctly."
  408. Print
  409. End
  410. End If
  411. Dim f As Integer
  412. f = FreeFile
  413. Open garage(0).dir & SLASH & "test981" For Output As f : Close f
  414. If FileExists(garage(0).dir & SLASH & "test981") Then
  415. Kill garage(0).dir & SLASH & "test981"
  416. Else
  417. Print
  418. Print "Error: Stunts directory not properly configured"
  419. Print " Edit sgar.cfg to select the right directory for it"
  420. Print
  421. End
  422. End If
  423. Open garage(1).dir & SLASH & "test981" For Output As f : Close f
  424. If FileExists(garage(1).dir & SLASH & "test981") Then
  425. Kill garage(1).dir & SLASH & "test981"
  426. Else
  427. MkDir garage(1).dir
  428. Open garage(1).dir & SLASH & "test981" For Output As f : Close f
  429. If FileExists(garage(1).dir & SLASH & "test981") Then
  430. Kill garage(1).dir & SLASH & "test981"
  431. Print
  432. Print "Created garage directory at " & garage(1).dir
  433. Print
  434. Else
  435. Print
  436. Print "Error: The current garage directory is not accessible and could"
  437. Print " not be created. Please edit sgar.cfg to select a garage"
  438. Print " directory that can be used"
  439. Print
  440. End
  441. End If
  442. End If
  443. ReadDirs
  444. For g As Byte = 0 To garages
  445. For i As Short = 1 To cars(g)
  446. ExtractCarInfo car(g, i), garage(g).dir
  447. Next i
  448. Next g
  449. End Sub
  450. Function GarageNumber(gname As String) As Byte
  451. If ValInt(gname) >= 1 Then Return ValInt(gname)
  452. For i As Short = 1 To garages
  453. If LCase(garage(i).name) = LCase(gname) Then Return i
  454. Next i
  455. End Function
  456. Sub Echo (s As String = "", eol As Byte = -1)
  457. If eol Then
  458. Print s
  459. Else
  460. Print s;
  461. End If
  462. End Sub
  463. Sub RunCommand (s As String)
  464. Dim As String c, p(1 To 7), t
  465. Dim n As Short, ps As Byte
  466. n = InStr(s, " ")
  467. If n Then
  468. c = LCase(Trim(Left(s, n - 1)))
  469. t = Trim(Mid(s, n + 1))
  470. For i As Byte = 1 To 7
  471. ps += 1
  472. n = InStr(t, " ")
  473. If n Then
  474. p(ps) = RTrim(Left(t, n - 1))
  475. t = LTrim(Mid(t, n))
  476. Else
  477. p(ps) = t
  478. Exit For
  479. End If
  480. Next i
  481. Else
  482. c = LCase(Trim(s))
  483. ps = 0
  484. End If
  485. Select Case c
  486. Case ""
  487. Case "addto"
  488. Dim thisgroup As Short, st As String, ss As String
  489. If ps <> 2 Then
  490. Echo "Use: addto <group> <carid>"
  491. Echo
  492. Exit Sub
  493. End If
  494. For i As Short = 1 To groups
  495. If group(i).gname = LCase(p(1)) Then
  496. thisgroup = i
  497. Exit For
  498. End If
  499. Next i
  500. st = Resolve(p(2))
  501. Do
  502. n = InStr(st, ",")
  503. If n Then
  504. ss = Left(st, n - 1)
  505. st = Mid(st, n + 1)
  506. Else
  507. ss = st
  508. st = ""
  509. End If
  510. If Len(ss) <> 4 Then
  511. Echo "invalid car id: " & ss
  512. ElseIf thisgroup = 0 Then
  513. groups += 1
  514. group(groups).gname = LCase(p(1))
  515. group(groups).cars = LCase(ss)
  516. Echo "Created group " & p(1) & " with car " & ss
  517. thisgroup = groups
  518. ElseIf InStr(LCase(group(thisgroup).cars), LCase(ss)) Then
  519. Echo "Car " & ss & " is already present in group " & p(1)
  520. Else
  521. group(thisgroup).cars &= "," & LCase(ss)
  522. Echo "Added " & ss & " to " & p(1)
  523. End If
  524. Loop Until Len(st) = 0
  525. Echo ""
  526. SaveConfig
  527. Case "bring", "retrieve"
  528. Dim n As Short, t As String, tt As String, c As Short
  529. Dim g As Short
  530. If ps = 0 OrElse ps > 3 Then
  531. Echo "Use: retrieve|bring <carID> [[from] <garage>]"
  532. Echo ""
  533. Else
  534. If LCase(p(2)) = "from" Then p(2) = p(3)
  535. g = 0
  536. If ps > 1 Then 'Specified garage
  537. g = GarageNumber(p(2))
  538. If g > garages Then
  539. Echo "Only " & garages & " garages available!"
  540. Echo ""
  541. Exit Sub
  542. End If
  543. End If
  544. t = Resolve(p(1))
  545. Do
  546. c = InStr(t, ",")
  547. If c Then
  548. tt = Left(t, c - 1)
  549. t = Mid(t, c + 1)
  550. Else
  551. tt = t
  552. t = ""
  553. End If
  554. If g Then
  555. n = MoveCar(tt, g, 0)
  556. Else
  557. For i As Short = 1 To garages
  558. If LCase(garage(i).name) <> "junkyard" Then
  559. n = MoveCar(tt, i, 0)
  560. If n = 0 Then Exit For
  561. End If
  562. Next i
  563. End If
  564. Select Case n
  565. Case 0 : Echo "Successfully retrieved " & tt
  566. Case 1 : Echo "Car not found: " & tt
  567. Case 2 : Echo "Some cars retrieved"
  568. Case 3 : Echo "Car is locked and cannot be retrieved: " & tt
  569. Case Else : Echo "Unknown error"
  570. End Select
  571. Loop Until Len(t) = 0
  572. Echo ""
  573. End If
  574. Case "car"
  575. If ps <> 1 Then
  576. Echo "Use: car <car>"
  577. Echo ""
  578. Exit Sub
  579. End If
  580. p(1) = Resolve(p(1))
  581. If InStr(p(1), ",") Then
  582. Echo "Only a single car ID allowed for this command"
  583. Echo
  584. Exit Sub
  585. End If
  586. For g As Byte = 0 To garages
  587. For i As Short = 1 To cars(g)
  588. If LCase(car(g, i).id) = LCase(p(1)) Then
  589. Echo "Car name: " & car(g, i).carname
  590. If Len(car(g, i).version) Then Echo "Version: " & car(g, i).version
  591. If Len(car(g, i).author) Then Echo "Author: " & car(g, i).author
  592. Echo "Car ID: " & UCase(car(g, i).id)
  593. Echo "Found in: ", 0
  594. If Len(garage(g).name) Then Echo garage(g).name Else Echo "Garage #" & g
  595. Echo "Groups: ", 0
  596. Dim q As Short = 0
  597. For j As Short = 1 To groups
  598. If InStr(LCase(group(j).cars), LCase(car(g, i).id)) Then
  599. If q Then Echo ", ", 0
  600. q += 1
  601. Echo group(j).gname, 0
  602. End If
  603. Next j
  604. If q = 0 Then Echo "None" Else Echo
  605. Echo "Files: " & car(g, i).numfiles
  606. For j As Byte = 1 To 9
  607. If Len(car(g, i).file(j)) Then
  608. Echo " - " & car(g, i).file(j), 0
  609. Select Case Right(LCase(car(g, i).file(j)), 4)
  610. Case ".pvs", ".p3s", ".pre" : Echo " (packed)"
  611. Case Else : Echo " (unpacked)"
  612. End Select
  613. End If
  614. Next j
  615. Echo
  616. Exit Sub
  617. End If
  618. Next i
  619. Next g
  620. Echo "Car not found: " & p(1)
  621. Echo
  622. Case "cars"
  623. Dim total As Short
  624. Echo cars(0) & " cars ready for Stunts"
  625. For i As Short = 1 To garages
  626. Echo cars(i) & " cars in ", 0
  627. If Len(garage(i).name) Then Echo garage(i).name Else Echo "garage #" & i
  628. total += cars(i)
  629. Next i
  630. Echo total & " cars parked"
  631. Echo cars(0) + total & " total cars"
  632. If Len(locked) Then
  633. Dim t As String, tn As Short, num As Short
  634. t = locked
  635. Do
  636. tn = InStr(t, ",")
  637. If tn Then
  638. num += 1
  639. t = Mid(t, tn + 1)
  640. Else
  641. num += 1
  642. Exit Do
  643. End If
  644. Loop
  645. Echo num & " locked"
  646. End If
  647. Echo
  648. Case "dirs"
  649. For i As Short = 0 To garages
  650. If Len(garage(i).name) Then Echo garage(i).name, 0 Else Echo "Garage #" & i, 0
  651. Echo ": " & garage(i).dir
  652. Next i
  653. Echo
  654. Case "garagedir", "gdir"
  655. If Len(p(1)) = 0 Then
  656. Echo "Use: garagedir [<garage>] <directory>"
  657. Echo
  658. Exit Sub
  659. End If
  660. Dim gd As String, gn As Byte
  661. If ps = 1 Then
  662. gd = p(1)
  663. gn = 1
  664. Else
  665. gd = p(2)
  666. gn = 0
  667. End If
  668. If Open(gd & SLASH & "a123.tmp", For Output, As 1) Then
  669. Echo "Invalid path: " & gd
  670. Echo
  671. Else
  672. Close 1
  673. Kill gd & SLASH & "a123.tmp"
  674. If gn Then
  675. garage(1).dir = gd
  676. Else
  677. gn = 0
  678. If ValInt(p(1)) Then
  679. gn = ValInt(p(1))
  680. If gn > garages Then gn = 0
  681. Else
  682. For i As Short = 1 To garages
  683. If LCase(garage(i).name) = LCase(p(1)) Then
  684. gn = i
  685. Exit For
  686. End If
  687. Next i
  688. End If
  689. If gn Then
  690. garage(gn).dir = gd
  691. ElseIf garages < 15 Then
  692. garages += 1 : gn = garages
  693. garage(garages).dir = gd
  694. garage(garages).name = ""
  695. End If
  696. End If
  697. SaveConfig
  698. For i As Short = 0 To garages
  699. cars(i) = 0
  700. Next i
  701. garages = 1
  702. Init
  703. Echo "New garage #" & gn & " directory is " & gd
  704. Echo
  705. End If
  706. Case "garagename", "gname"
  707. If Len(p(1)) = 0 Then
  708. Echo "Use: garagename <garage> [new_name]"
  709. Echo
  710. Exit Sub
  711. End If
  712. If ps = 1 Then p(2) = ""
  713. If ValInt(p(1)) > garages Then
  714. Echo "There's no garage #" & ValInt(p(1)) & ". Only " & garages & " exist!"
  715. Echo
  716. Exit Sub
  717. End If
  718. If ValInt(p(1)) = 0 Then
  719. For i As Short = 1 To garages
  720. If LCase(garage(i).name) = LCase(p(1)) Then
  721. p(1) = Str(i)
  722. Exit For
  723. End If
  724. Next i
  725. End If
  726. If ValInt(p(1)) Then
  727. garage(ValInt(p(1))).name = p(2)
  728. SaveConfig
  729. If Len(p(2)) Then
  730. Echo "Garage #" & ValInt(p(1)) & " renamed as " & p(2)
  731. Else
  732. Echo "Garage #" & ValInt(p(1)) & " is now nameless"
  733. End If
  734. Echo
  735. Else
  736. Echo "Invalid garage"
  737. Echo
  738. End If
  739. Case "rmgarage", "rmg"
  740. If ps = 0 Then
  741. Echo "Use: rmgarage <garage>"
  742. Echo
  743. Exit Sub
  744. End If
  745. If ValInt(p(1)) = 0 Then
  746. For i As Short = 1 To garages
  747. If LCase(garage(i).name) = LCase(p(1)) Then
  748. p(1) = Str(i)
  749. Exit For
  750. End If
  751. Next i
  752. End If
  753. If ValInt(p(1)) > garages Then
  754. Echo "There are only " & garages & " garages!"
  755. ElseIf ValInt(p(1)) <= 0 Then
  756. Echo "Invalid garage"
  757. ElseIf ValInt(p(1)) = 1 AndAlso garages = 1 Then
  758. Echo "Cannot remove the only garage"
  759. Else
  760. For i As Short = ValInt(p(1)) To garages - 1
  761. garage(i) = garage(i + 1)
  762. Next i
  763. garages -= 1
  764. SaveConfig
  765. Echo "Removed garage from list"
  766. Echo "Please note that any cars in the removed garage will remain"
  767. Echo "in the garage directory!"
  768. End If
  769. Echo
  770. Case "list", "ls", "lp", "lg", "lj", "l"
  771. Dim As Byte fil(0 To 15) 'Filter flags
  772. Dim thislist As String, acar As String, comma As Short
  773. Dim carcount As Short, found As Byte
  774. Select Case Mid(c, 2)
  775. Case "", "ist"
  776. If ps = 2 Then
  777. Dim g As Short
  778. g = GarageNumber(p(2))
  779. If g >= 0 AndAlso g <= 15 Then fil(g) = -1
  780. Else
  781. For i As Short = 0 To garages
  782. fil(i) = -1
  783. Next i
  784. End If
  785. Case "s" : fil(0) = -1
  786. Case "g", "p"
  787. For i As Short = 1 To garages
  788. If LCase(garage(i).name) <> "junkyard" Then fil(i) = -1
  789. Next i
  790. Case "j"
  791. Dim g As Byte
  792. g = GarageNumber("junkyard")
  793. If g Then
  794. fil(g) = -1
  795. Else
  796. Echo "No junkyard found"
  797. Echo
  798. Exit Sub
  799. End If
  800. End Select
  801. If p(1) = "" Then p(1) = "*"
  802. thislist = Resolve(p(1)) : carcount = 0
  803. Do
  804. comma = InStr(thislist, ",")
  805. If comma Then
  806. acar = Left(thislist, comma - 1)
  807. thislist = Mid(thislist, comma + 1)
  808. Else
  809. acar = thislist
  810. thislist = ""
  811. End If
  812. found = 0
  813. For j As Short = 0 To garages
  814. If fil(j) Then
  815. For i As Short = 1 To cars(j)
  816. If LCase(car(j, i).id) = LCase(acar) Then
  817. Echo car(j, i).carname & Space(30 - Len(car(j, i).carname)), 0
  818. Echo UCase(car(j, i).id), 0
  819. If car(j, i).numfiles <> 4 Then Echo "! ", 0 Else Echo " ", 0
  820. If j Then
  821. If Len(garage(j).name) Then
  822. Echo garage(j).name
  823. Else
  824. Echo "Garage", 0
  825. If garages > 1 Then
  826. Echo " #" & j
  827. Else
  828. Echo
  829. End If
  830. End If
  831. Else
  832. Echo "Stunts"
  833. End If
  834. carcount += 1
  835. found = -1
  836. Exit For
  837. End If
  838. Next i
  839. End If
  840. Next j
  841. Loop Until Len(thislist) = 0
  842. If carcount > 1 Then
  843. Echo carcount & " cars found"
  844. ElseIf carcount = 1 Then
  845. Echo "1 car found"
  846. Else
  847. Echo "No cars found"
  848. End If
  849. Echo
  850. Case "park"
  851. Dim n As Short, t As String, tt As String, c As Short
  852. Dim g As Short
  853. If ps < 1 OrElse ps > 2 Then
  854. Echo "Use: park <carID> [<garage>]"
  855. Echo
  856. Else
  857. g = 1
  858. If ps = 2 Then
  859. g = GarageNumber(p(2))
  860. If g > garages Then
  861. Echo "Only " & garages & " garages available"
  862. Echo
  863. Exit Sub
  864. End If
  865. End If
  866. t = Resolve(p(1))
  867. Do
  868. c = InStr(t, ",")
  869. If c Then
  870. tt = Left(t, c - 1)
  871. t = Mid(t, c + 1)
  872. Else
  873. tt = t
  874. t = ""
  875. End If
  876. n = MoveCar(tt, 0, g)
  877. Select Case n
  878. Case 0 : Echo "Successfully parked " & tt
  879. Case 1 : Echo "Car not found: " & tt
  880. Case 2 : Echo "Some cars parked"
  881. Case 3 : Echo "Car is locked and cannot be parked: " & tt
  882. Case Else : Echo "Unknown error"
  883. End Select
  884. Loop Until Len(t) = 0
  885. Echo
  886. End If
  887. Case "stunts"
  888. If Len(1) = 0 Then
  889. Echo "Use: stunts <directory>"
  890. Echo
  891. ElseIf Open(p(1) & SLASH & "a123.tmp", For Output, As 1) Then
  892. Echo "Invalid path: " & p(1)
  893. Echo
  894. Else
  895. Close 1
  896. Kill p(1) & SLASH & "a123.tmp"
  897. garage(0).dir = p(1)
  898. SaveConfig
  899. For g As Byte = 0 To garages
  900. cars(g) = 0
  901. Next g
  902. garages = 1
  903. Init
  904. Echo "New Stunts directory is " & p(1)
  905. Echo
  906. End If
  907. Case "groups", "gs"
  908. Dim i As Short
  909. For i = 1 To groups
  910. Echo group(i).gname
  911. Next i
  912. Echo
  913. Echo i - 1 & " group", 0
  914. If i - 1 = 1 Then Echo Else Echo "s"
  915. Echo
  916. Case "group", "g"
  917. RunCommand "l #" & p(1)
  918. Case "removefrom", "rf"
  919. Dim thisgroup As Short, st As String, ss As String, nn As Short
  920. If ps <> 2 Then
  921. Echo "Use: removefrom/rf <group> <carid>"
  922. Echo
  923. Exit Sub
  924. End If
  925. For i As Short = 1 To groups
  926. If group(i).gname = LCase(p(1)) Then
  927. thisgroup = i
  928. Exit For
  929. End If
  930. Next i
  931. If thisgroup = 0 Then
  932. Echo "Group not found: " & p(1)
  933. Echo
  934. Exit Sub
  935. End If
  936. st = Resolve(p(2))
  937. Do
  938. nn = InStr(st, ",")
  939. If nn Then
  940. ss = Left(st, nn - 1)
  941. st = Mid(st, nn + 1)
  942. Else
  943. ss = st
  944. st = ""
  945. End If
  946. n = InStr(LCase(group(thisgroup).cars), LCase(ss))
  947. If Len(ss) <> 4 Then
  948. Echo "invalid car id: " & ss
  949. ElseIf n = 0 Then
  950. Echo "Car " & ss & " was not in that group"
  951. Else
  952. Dim As String b1, b2, temp
  953. b1 = LCase(Trim(group(thisgroup).cars))
  954. Do
  955. n = InStr(b1, ",")
  956. If n Then
  957. temp = RTrim(Left(b1, n - 1))
  958. b1 = LTrim(Mid(b1, n + 1))
  959. Else
  960. temp = RTrim(b1)
  961. b1 = ""
  962. End If
  963. If temp <> LCase(ss) Then
  964. If b2 = "" Then b2 = temp Else b2 &= "," & temp
  965. End If
  966. Loop Until Len(b1) = 0
  967. If Len(b2) Then
  968. group(thisgroup).cars = b2
  969. Echo "Removed " & ss & " from group " & p(1)
  970. Else
  971. For i As Short = thisgroup To groups - 1
  972. group(i) = group(i + 1)
  973. Next i
  974. groups -= 1
  975. Echo "Removed group " & p(1)
  976. Exit Do
  977. End If
  978. End If
  979. Loop Until Len(st) = 0
  980. Echo
  981. SaveConfig
  982. Case "delgroup", "rmgroup"
  983. If ps <> 1 Then
  984. Echo "Use: delgroup|rmgroup <group>"
  985. Echo
  986. Exit Sub
  987. End If
  988. If Left(p(1), 1) = "#" Then p(1) = Mid(p(1), 2)
  989. Dim q As Byte = 0
  990. For i As Short = 1 To groups
  991. If LCase(p(1)) = LCase(group(i).gname) Then
  992. q = -1
  993. For j As Short = i To groups - 1
  994. group(j) = group(j + 1)
  995. Next j
  996. groups -= 1
  997. SaveConfig
  998. Echo "Removed group " & p(1)
  999. Echo
  1000. Exit For
  1001. End If
  1002. Next i
  1003. If q = 0 Then
  1004. Echo "Group not found: " & p(1)
  1005. Echo
  1006. End If
  1007. Case "groupthese", "gt"
  1008. If ps <> 1 Then
  1009. Echo "Use: groupthese|gs <group>"
  1010. Echo
  1011. Exit Sub
  1012. End If
  1013. If cars(0) = 0 Then
  1014. Echo "No cars to add to group"
  1015. Echo
  1016. Exit Sub
  1017. End If
  1018. For i As Short = 1 To cars(0)
  1019. RunCommand "addto " & p(1) & " " & car(0, i).id
  1020. Next i
  1021. SaveConfig
  1022. Case "only"
  1023. If ps <> 1 Then
  1024. Echo "Use: only <group>"
  1025. Echo
  1026. Exit Sub
  1027. End If
  1028. If Left(p(1), 1) = "#" Then p(1) = Mid(p(1), 2)
  1029. Dim g As Short = 0
  1030. For i As Short = 1 To groups
  1031. If LCase(p(1)) = LCase(group(i).gname) Then
  1032. g = i
  1033. Exit For
  1034. End If
  1035. Next i
  1036. If g = 0 Then
  1037. Echo "Group not found: " & p(1)
  1038. Echo
  1039. Exit Sub
  1040. End If
  1041. 'Move to garage cars that are not in group
  1042. For i As Short = 1 To cars(0)
  1043. If InStr(LCase(group(g).cars), LCase(car(0, i).id)) = 0 Then
  1044. RunCommand "park " & car(0, i).id
  1045. i -= 1
  1046. End If
  1047. If i = cars(0) Then Exit For
  1048. Next i
  1049. 'Move to Stunts cars that are in group
  1050. For i As Short = 1 To cars(1)
  1051. If InStr(LCase(group(g).cars), LCase(car(1, i).id)) Then
  1052. RunCommand "bring " & car(1, i).id
  1053. i -= 1
  1054. End If
  1055. If i = cars(1) Then Exit For
  1056. Next i
  1057. Case "lock"
  1058. If ps <> 1 Then
  1059. Echo "Use: lock <carID>"
  1060. Echo
  1061. Exit Sub
  1062. End If
  1063. p(1) = LCase(Trim(p(1)))
  1064. If InStr(p(1), ",") Then
  1065. Echo "Only one car ID allowed for this command"
  1066. Echo
  1067. Exit Sub
  1068. End If
  1069. If Len(p(1)) <> 4 Then
  1070. Echo "Invalid car ID: " & UCase(p(1))
  1071. Echo
  1072. Exit Sub
  1073. End If
  1074. If InStr(locked, p(1)) Then
  1075. Echo "Car already locked: " & UCase(p(1))
  1076. Echo
  1077. Exit Sub
  1078. End If
  1079. If Len(locked) Then locked &= ","
  1080. locked &= p(1)
  1081. Echo "Locked " & UCase(p(1))
  1082. Echo
  1083. SaveConfig
  1084. Case "unlock"
  1085. If ps <> 1 Then
  1086. Echo "Use: lock <carID>"
  1087. Echo
  1088. Exit Sub
  1089. End If
  1090. p(1) = LCase(Trim(p(1)))
  1091. If InStr(p(1), ",") Then
  1092. Echo "Only one car ID allowed for this command"
  1093. Echo
  1094. Exit Sub
  1095. End If
  1096. If Len(p(1)) <> 4 Or InStr(p(1), ",") <> 0 Then
  1097. Echo "Invalid car ID: " & UCase(p(1))
  1098. Echo
  1099. Exit Sub
  1100. End If
  1101. Dim n As Short
  1102. n = InStr(locked, p(1))
  1103. If n = 0 Then
  1104. Echo "Car already unlocked: " & UCase(p(1))
  1105. Echo
  1106. Exit Sub
  1107. End If
  1108. locked = Left(locked, n - 1) & Mid(locked, n + 4)
  1109. n = InStr(locked, ",,")
  1110. If n Then locked = Left(locked, n) & Mid(locked, n + 2)
  1111. If Right(locked, 1) = "," Then locked = Left(locked, Len(locked) - 1)
  1112. If Left(locked, 1) = "," Then locked = Mid(locked, 2)
  1113. Echo "Unlocked car: " & UCase(p(1))
  1114. Echo
  1115. SaveConfig
  1116. Case "locked"
  1117. If Len(locked) Then
  1118. Echo "Locked cars: " & locked
  1119. Else
  1120. Echo "No cars locked"
  1121. End If
  1122. Echo
  1123. Case "version", "ver"
  1124. Echo "Simple Garage v" & SGVERSION & ", released " & release_date & " - by Cas"
  1125. Echo
  1126. Case "resolve"
  1127. Echo Resolve(p(1))
  1128. Echo
  1129. Case "help"
  1130. If LCase(p(1)) = "filters" Then
  1131. Echo "Most commands in which a car o more can be specified,"
  1132. Echo "where you see a parameter like <car(s)> can use any of"
  1133. Echo "the following:"
  1134. Echo
  1135. Echo "- A single car ID, e.g.: pmin"
  1136. Echo "- A group preceeded by a # sign, e.g.: #mycars"
  1137. Echo "- A filter such as: Porsche*"
  1138. Echo "- A comma-separated list of any of the above: jagu,*n,#orig,fgto"
  1139. Echo
  1140. Echo "Comma-separated lists are called ad-hoc groups in contrast"
  1141. Echo "to referenced groups, which are preceeded by a #."
  1142. Echo "Filters can be of either of the forms:"
  1143. Echo
  1144. Echo "*xyz - ending in xyz"
  1145. Echo "xyz* - beginning with xyz"
  1146. Echo "*xyz* - containing xyz"
  1147. Echo "xyz - also containing xyz (as long as length is not 4)"
  1148. Echo
  1149. Echo "Four characters in a row will be assumed to be a car ID"
  1150. Echo
  1151. Exit Sub
  1152. End If
  1153. Echo "addto <group> <car(s)> - Add car(s) to group"
  1154. Echo "car <carID> - Display information about a car"
  1155. Echo "cars - Display number of cars in Stunts & garage"
  1156. Echo "delgroup|rmgroup <group> - Delete a group"
  1157. Echo "dirs - Display current directories"
  1158. Echo "exit|quit - Leave Simple Garage"
  1159. Echo "group|g <group> - List cars in group"
  1160. Echo "groups|gs - List groups"
  1161. Echo "groupthese|gt <group> - Add all cars currently in Stunts to group"
  1162. Echo "lg|lp <car(s)> - List cars among the ones in the garage"
  1163. Echo "list|l <car(s)> - List cars among all available"
  1164. Echo "lock <carID> - Lock car"
  1165. Echo "locked - List locked car IDs"
  1166. Echo "ls <car(s)> - List cars among those ready in Stunts"
  1167. Echo "only <group> - Bring all cars in group and park all others"
  1168. Echo "park <car(s)> [garage] - Park car(s) in garage"
  1169. Echo "removefrom|rf <group> <car(s)> - Remove car(s) from group"
  1170. Echo "retrieve|bring <car(s)> [garage] - Bring car(s) back to Stunts"
  1171. Echo "unlock <carID> - Unlock car"
  1172. Echo "version|ver - Display program version"
  1173. Echo
  1174. Echo "Type 'help filters' for more information on car lists"
  1175. Echo
  1176. Case "exit", "quit" : End
  1177. Case Else
  1178. Echo "Uknown command: " & c
  1179. Echo
  1180. End Select
  1181. End Sub
  1182. Sub MyInput (s As String, maxlength As Short)
  1183. Dim akey As String, t As String, cpos As Short = 1
  1184. Dim As Short startx, starty
  1185. Dim update As Byte = -1, lastn As Byte
  1186. startx = Pos(0)
  1187. starty = CSRLin
  1188. Do
  1189. If update Then
  1190. Locate starty, startx
  1191. Print t & Space(80 - Len(t) - startx);
  1192. Line (8 * (startx - 2 + cpos), 16 * starty - 3)- Step (7, 0)
  1193. update = 0
  1194. End If
  1195. akey = InKey
  1196. Sleep 10
  1197. Select Case akey
  1198. Case " " To Chr(126)
  1199. If Len(t) < maxlength Then
  1200. t = Left(t, cpos - 1) & akey & Mid(t, cpos)
  1201. cpos += 1
  1202. update = -1
  1203. End If
  1204. Case Chr(8)
  1205. If cpos > 1 Then
  1206. t = Left(t, cpos - 2) & Mid(t, cpos)
  1207. cpos -= 1
  1208. update = -1
  1209. End If
  1210. Case Chr(255, 77)
  1211. If cpos < Len(t) + 1 Then
  1212. cpos += 1
  1213. update = -1
  1214. End If
  1215. Case Chr(255, 75)
  1216. If cpos > 1 Then
  1217. cpos -= 1
  1218. update = -1
  1219. End If
  1220. Case Chr(255, 83)
  1221. If cpos <= Len(t) Then
  1222. t = Left(t, cpos - 1) & Mid(t, cpos + 1)
  1223. update = -1
  1224. End If
  1225. Case Chr(255, 71)
  1226. cpos = 1
  1227. update = -1
  1228. Case Chr(255, 79)
  1229. cpos = Len(t) + 1
  1230. update = -1
  1231. Case Chr(255, 72)
  1232. If lastn < 10 Then
  1233. lastn += 1
  1234. t = lastcommand(lastn)
  1235. cpos = Len(t) + 1
  1236. update = -1
  1237. End If
  1238. Case Chr(255, 80)
  1239. If lastn > 0 Then
  1240. lastn -= 1
  1241. If lastn Then
  1242. t = lastcommand(lastn)
  1243. Else
  1244. t = ""
  1245. End If
  1246. cpos = Len(t) + 1
  1247. update = -1
  1248. End If
  1249. Case Chr(13)
  1250. s = t
  1251. Exit Do
  1252. Case Chr(27)
  1253. t = ""
  1254. cpos = 1
  1255. update = -1
  1256. Case Chr(255) & "k"
  1257. s = "exit"
  1258. Exit Do
  1259. End Select
  1260. Loop
  1261. Locate starty, startx : Print t & " "
  1262. End Sub
  1263. release_date = __DATE_ISO__
  1264. copyright_notice = "Copyright (C) 2022 - Lucas Pedrosa" & Chr(10) & _
  1265. "This program is free software distributed under the GPLv3" & Chr(10) & _
  1266. "See license.txt for details"
  1267. If Command = "/?" Or LCase(Command) = "--help" Then
  1268. Print "Simple Garage " & SGVERSION & ", released " & release_date
  1269. Print "Garage manager program for Stunts"
  1270. Print copyright_notice
  1271. Print
  1272. Print "Use: sgar <command>"
  1273. Print "to execute individual commands"
  1274. Print "Or: sgar"
  1275. Print "to access the GUI console"
  1276. Print
  1277. End
  1278. End If
  1279. If Len(Command) Then
  1280. Dim comline As String, n As Short
  1281. comline = Command
  1282. Do
  1283. n = InStr(comline, "%")
  1284. If n Then Mid(comline, n, 1) = "*"
  1285. Loop Until n = 0
  1286. Do
  1287. n = InStr(comline, "@")
  1288. If n Then Mid(comline, n, 1) = "#"
  1289. Loop Until n = 0
  1290. Init
  1291. RunCommand comline
  1292. End
  1293. End If
  1294. ScreenRes 640, 480
  1295. Width 80, 30
  1296. WindowTitle "Simple Garage " & SGVERSION
  1297. Dim s As String
  1298. Color 15
  1299. Print "Simple Garage " & SGVERSION & ", released " & release_date
  1300. Color 7
  1301. Print copyright_notice
  1302. Print
  1303. Color 15
  1304. Init
  1305. Do
  1306. Color 10 : Print "@>";
  1307. Color 15 : MyInput s, 70
  1308. Color 7 : RunCommand s
  1309. For i As Short = 10 To 2 Step -1
  1310. lastcommand(i) = lastcommand(i - 1)
  1311. Next i
  1312. lastcommand(1) = s
  1313. Loop