bmk_bb2bmx.bmx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. Strict
  2. ' bmk_bb2bmx.bmx v0.4
  3. ' by [email protected]
  4. ' converts BlitzBasic source files to BlitzMax
  5. ' history
  6. ' AND OR operators -> bitwise if not followed by conditional operators =<>
  7. ' Min and Max -> _Min and _Max
  8. ' HandleFromObject and HandleToObject added to bbtype.bmx
  9. ' link and list fields in bbtype -> _link and _list
  10. ' IncrementArrays$(code$) adds 1 to all array dimensions of array declarations
  11. ' ReadString(TStream) function added and FreeSound(sound)->Release(sound)
  12. ' hidepointer -> hidemouse showpointer -> showmouse
  13. ' delete obj -> obj.remove
  14. ' readpixel->dev.blitz3d.readpixel writepixel->dev.blitz3d.writepixel
  15. ' seekfile -> seekstream filepos -> streampos
  16. ' channelvolume->SetChannelVolume soundvolume->
  17. ' readbytes -> ReadBank writebytes-> WriteBankq
  18. ' xor->~ getkey->waitkey mousewait->waitmouse
  19. ' handle -> HandleFromObject object -> HandleToObject
  20. ' stop -> DebugStop
  21. ' .label -> #label
  22. ' param[n]->param[] in function declarations
  23. ' added TypePrefix$ to help avoid type name / variable name clashes
  24. ' processes include files
  25. ' output bbtype.bmx and bbvkey.bmx files (thanks to Terabit)
  26. ' moved to bmk_bb2bmx
  27. ' inline comments replace ; with '
  28. ' command separators replace : with ;
  29. ' type specifiers replace . with :
  30. ' field separators replace \ with .
  31. ' boolean operators replace and or with & |
  32. ' array declarations replace Dim x(100) with Global x[100+1]
  33. ' graphics commands Line,Rect,Oval,Text -> DrawLine,DrawRect,DrawOval,DrawText
  34. ' implement old style Type handling for Each First Last Before After Insert
  35. ' Str becomes String
  36. ' Delete Each list -> list.Clear()
  37. ' Delete -> Release
  38. ' Data->DefData Read->ReadData
  39. ' KeyDown->VKeyDown KeyHit->VKeyHit
  40. ' native Color and ClsColor commands added to header
  41. ' not supported / stubbed out
  42. ' no float->boolean so error is "bitwise operators can only be used with integers"
  43. ' MouseZSpeed(), FreeBank(bank), Locate( x,y )
  44. ' LoopSound(sound), ChannelPitch(channel,hz),PlayCDTrack( track,mode=0 )
  45. Import brl.retro
  46. Const TAB$=Chr(9)
  47. Global TypePrefix$="bb"
  48. Function main()
  49. Local AppArgs$[]=["bb2bmx","bob.bb"]
  50. Local srcfile$,destfile$
  51. Local n=Len AppArgs
  52. If n<2
  53. Print "bb2bmx srcfile.bb [destfile.bmx]"
  54. End
  55. EndIf
  56. srcfile$=AppArgs[1]
  57. destfile$=Replace$(srcfile,".bb",".bmx")
  58. If n>2 destfile$=AppArgs[2]
  59. bb2bmx(srcfile,destfile)
  60. End Function
  61. Function ConvertBB(args$[])
  62. Local srcfile$,destfile$
  63. If Len args<1 Throw "convertbb option requires a filename"
  64. srcfile$=args[0]
  65. If Len args>1 destfile=args[1]
  66. bb2bmx srcfile,destfile
  67. End Function
  68. Global Includes:TList
  69. Global Complete:TList
  70. Global TypeLists:TList
  71. Function bb2bmx(srcfile$,destfile$)
  72. Local s$,currdir$,inc$,done$
  73. Local destinclude$
  74. Local src:TList,isrc:TList
  75. Local dest:TList,idest:TList
  76. Local incs:TList
  77. Includes=New TList
  78. TypeLists=New TList
  79. Complete=New TList
  80. currdir=CurrentDir()
  81. src=ReadTextFile(srcfile)
  82. If Not src Throw "bb2bmx failed to open "+srcfile
  83. If Not destfile destfile$=Replace$(srcfile,".bb",".bmx")
  84. ChangeDir ExtractDir(srcfile)
  85. WriteVKeyFile
  86. WriteBBTypeFile
  87. dest=New TList
  88. Print "converting "+srcfile
  89. ConvertSourceList(src,dest)
  90. ' process includes
  91. While Not Includes.IsEmpty()
  92. incs=Includes
  93. Includes=New TList
  94. For srcfile=EachIn incs
  95. ' check if include already converted
  96. For done=EachIn complete
  97. If done=srcfile Exit
  98. Next
  99. If done=srcfile Continue
  100. complete.AddLast srcfile
  101. isrc=ReadTextFile(srcfile)
  102. If Not isrc Throw "bb2bmx failed to open included file "+srcfile
  103. ChangeDir ExtractDir(srcfile)
  104. idest=New TList
  105. Print "converting "+srcfile
  106. ConvertSourceList(isrc,idest)
  107. destinclude$=Replace$(srcfile,".bb",".bmx")
  108. WriteTextFile(destinclude,idest)
  109. Next
  110. Wend
  111. ChangeDir(currdir)
  112. For s$=EachIn TypeLists
  113. dest.addfirst s$
  114. Next
  115. dest.addfirst ""
  116. dest.addfirst "Import "+Chr(34)+"bbvkey.bmx"+Chr(34)
  117. dest.addfirst "Import "+Chr(34)+"bbtype.bmx"+Chr(34)
  118. WriteTextFile(destfile,dest)
  119. End Function
  120. Function ProcessInclude$(s$)
  121. Local path$,inc$
  122. Local q,r
  123. q=Instr(s,Chr(34))
  124. If q=0 Return s$
  125. r=Instr(s,Chr(34),q+1)
  126. If r=0 Return s$
  127. path$=s[q..r-1]
  128. path=RealPath(path$)
  129. For inc=EachIn Includes
  130. If inc=path Exit
  131. Next
  132. If inc<>path
  133. Includes.AddLast(path)
  134. EndIf
  135. Return Replace$(s$,".bb",".bmx")
  136. End Function
  137. Function FindToken(s$,t$,p)
  138. Local l$,c
  139. t=Lower(t)
  140. l=Lower(s)
  141. Repeat
  142. p=Instr(l,t,p+1)
  143. If Not p Exit
  144. If p>1
  145. c=l[p-2]
  146. If c>47 And c<58 Continue '0-9
  147. If c>95 And c<122 Continue 'a-z
  148. If c=Asc("_") Continue
  149. EndIf
  150. If p+Len(t)-1<Len(l)
  151. c=l[p+Len(t)-1]
  152. If c>47 And c<58 Continue '0-9
  153. If c>95 And c<122 Continue 'a-z
  154. If c=Asc("_") Continue
  155. EndIf
  156. Return p
  157. Forever
  158. End Function
  159. Function ReplaceToken$(s$,t$,r$)
  160. Local l$,p,c
  161. Repeat
  162. p=FindToken(s,t,p)
  163. If Not p Exit
  164. s=s[..p-1]+r$+s[p+Len(t)-1..]
  165. p:+Len r$
  166. Forever
  167. Return s
  168. End Function
  169. Function FindEOC(s$,p) 'return position of next space or command separator
  170. Local q,r
  171. q=Instr(s," ",p)
  172. If q=0 q=Len s+1
  173. r=Instr(s,";",p)
  174. If r And r<q q=r
  175. r=Instr(s,"<",p)
  176. If r And r<q q=r
  177. r=Instr(s,">",p)
  178. If r And r<q q=r
  179. r=Instr(s,"=",p)
  180. If r And r<q q=r
  181. r=Instr(s,"-",p)
  182. If r And r<q q=r
  183. r=Instr(s,"+",p)
  184. If r And r<q q=r
  185. r=Instr(s,"*",p)
  186. If r And r<q q=r
  187. Return q
  188. End Function
  189. Function StripDims$(s$) 'remove dimensions in blitz arrays for blitzmax function parameters
  190. Local p,q
  191. p=1
  192. Repeat
  193. p=Instr(s$,"[",p)
  194. If p=0 Exit
  195. q=Instr(s$,"]",p)
  196. If q=0 Exit
  197. s$=s$[..p]+s$[q-1..]
  198. p=p+1
  199. Forever
  200. Return s
  201. End Function
  202. Function IncrementArrays$(s$) 'replace all arguments inside [] with
  203. Local p,q,a$
  204. p=Instr(s$,"[")
  205. If p=0 Return
  206. p=Instr(s$,"=")
  207. If p
  208. ' print "IncrementArray rejecting s$="+s$
  209. Return s$
  210. EndIf
  211. p=0
  212. While True
  213. p=Instr(s$,"[",p)
  214. If p=0 Exit
  215. q=Instr(s$,"]",p)
  216. If q=0 Exit
  217. a$=s$[p..q-1]
  218. a$=Replace(a$,",","+1,")
  219. a$=a$+"+1"
  220. s$=s$[..p]+a$+s$[q-1..]
  221. p=p+Len(a$)+1
  222. Wend
  223. Return s$
  224. End Function
  225. Function ConvertBoolOps$(s$) ' if AND OR not followed by < > = convert to bool operator & |
  226. Local p,q,r,t
  227. While True
  228. t=FindToken(s$,"And",p)
  229. If t=0 Exit
  230. q=Len(s$)
  231. r=FindToken(s$,"Then",t)
  232. If r And r<q q=r
  233. r=Instr(s$,";",t)
  234. If r And r<q q=r
  235. ' q is end of check
  236. r=Instr(s$,"=",t);If r And r<=q p=q;Continue
  237. r=Instr(s$,"<",t);If r And r<=q p=q;Continue
  238. r=Instr(s$,">",t);If r And r<=q p=q;Continue
  239. s$=s[..t-1]+"&"+s[t+2..]
  240. Wend
  241. p=0
  242. While True
  243. t=FindToken(s$,"Or",p)
  244. If t=0 Exit
  245. q=Len(s$)
  246. r=FindToken(s$,"Then",t)
  247. If r And r<q q=r
  248. r=Instr(s$,";",t)
  249. If r And r<q q=r
  250. ' q is end of check
  251. r=Instr(s$,"=",t);If r And r<=q p=q;Continue
  252. r=Instr(s$,"<",t);If r And r<=q p=q;Continue
  253. r=Instr(s$,">",t);If r And r<=q p=q;Continue
  254. s$=s[..t-1]+"|"+s[t+1..]
  255. Wend
  256. Return s$
  257. End Function
  258. Function Convert$(s$) 'substring of source line before rem and between any string literals
  259. Local p,q,r,c,n$
  260. ' replace : command separator
  261. s$=Replace(s$,":",";")
  262. '.label->#label
  263. p=Instr(Trim(s),".")
  264. If p=1
  265. p=Instr(s,".")
  266. s="#"+s[p..]
  267. EndIf
  268. ' replace . type specifier
  269. p=1
  270. Repeat
  271. p=Instr(s,".",p+1)
  272. If Not p Exit
  273. c=s[p]
  274. If c>47 And c<58 Continue 'ignore if decimal point
  275. s=s[..p-1]+":"+TypePrefix$+s[p..]
  276. Forever
  277. ' replace \ field separator
  278. s$=Replace(s$,"\",".")
  279. ' update BASIC API name changes
  280. s$=ReplaceToken(s,"freesound","Release")
  281. s$=ReplaceToken(s,"channelpan","SetChannelPan")
  282. s$=ReplaceToken(s,"filepos","StreamPos")
  283. s$=ReplaceToken(s,"seekfile","SeekStream")
  284. s$=ReplaceToken(s,"channelvolume","SetChannelVolume")
  285. s$=ReplaceToken(s,"readbytes","ReadBank")
  286. s$=ReplaceToken(s,"writebytes","WriteBank")
  287. s$=ReplaceToken(s,"mousewait","WaitMouse")
  288. ' hidepointer -> hidemouse showpointer -> showmouse
  289. s$=ReplaceToken(s,"hidepointer","HideMouse")
  290. s$=ReplaceToken(s,"showpointer","ShowMouse")
  291. ' replace boolean operators
  292. s$=ReplaceToken(s,"xor","~~")
  293. s$=ReplaceToken(s,"stop","DebugStop")
  294. Rem
  295. s$=ReplaceToken(s,"and","&")
  296. s$=ReplaceToken(s,"or","|")
  297. s$=ReplaceToken(s,"chr$","chr")
  298. s$=ReplaceToken(s,"line","DrawLine")
  299. s$=ReplaceToken(s,"rect","DrawRect")
  300. s$=ReplaceToken(s,"oval","DrawOval")
  301. s$=ReplaceToken(s,"text","DrawText")
  302. s$=ReplaceToken(s,"color","SetColor")
  303. s$=ReplaceToken(s,"clscolor","SetCLSColor")
  304. EndRem
  305. s$=ReplaceToken(s,"str","String")
  306. s$=ReplaceToken(s,"read","ReadData")
  307. s$=ReplaceToken(s,"data","DefData")
  308. s$=ReplaceToken(s,"restore","RestoreData")
  309. s$=ReplaceToken(s,"keydown","VKeyDown")
  310. s$=ReplaceToken(s,"keyhit","VKeyHit")
  311. s$=ReplaceToken(s,"getkey","WaitKey")
  312. s$=ReplaceToken(s,"readpixel","dev.blitz3d.ReadPixel") 'ReadPixelBuffer")
  313. s$=ReplaceToken(s,"writepixel","dev.blitz3d.WritePixel")
  314. s$=ReplaceToken(s,"graphicswidth","dev.blitz3d.GraphicsWidth")
  315. s$=ReplaceToken(s,"graphicsheight","dev.blitz3d.GraphicsHeight")
  316. s$=ReplaceToken(s,"min","fmin")
  317. s$=ReplaceToken(s,"max","fmax")
  318. ' delete obj -> obj.remove
  319. p=0
  320. Repeat
  321. p=FindToken(s,"delete",p)
  322. If Not p Exit
  323. If Lower(s[p+5..p+10])=" each" s=s[..p+5]+"Each "+TypePrefix$+Trim(s[p+10]);Continue
  324. If Lower(s[p+5..p+11])=" first" s=s[..p+5]+"First "+TypePrefix$+Trim(s[p+11]);Continue
  325. If Lower(s[p+5..p+10])=" last" s=s[..p+5]+"Last "+TypePrefix$+Trim(s[p+10]);Continue
  326. q=Instr(s," ",p+7)
  327. If q=0 q=Len s+1
  328. r=Instr(s,";",p+7)
  329. If r And r<q q=r
  330. s=s[..p-1]+s[p+6..q-1]+".Remove()"+s[q-1..] 'p+6
  331. p=q
  332. Forever
  333. s$=ConvertBoolOps(s)
  334. s$=ReplaceToken(s,"delete","Release")
  335. ' handle(obj) -> HandleFromObject(obj) object.blah(handle) -> HandleToObject(handle)
  336. s$=ReplaceToken(s,"handle","HandleFromObject")
  337. p=0
  338. Repeat
  339. p=FindToken(s,"object",p)
  340. If p=0 Exit
  341. q=Instr(s,":",p)
  342. If q=0 Exit
  343. r=Instr(s,"(",q)
  344. If r=0 Exit
  345. n$=s[q..r-1]
  346. c=1
  347. q=r
  348. While c
  349. If r>Len(s) Exit
  350. If s[r]="(" c:+1
  351. If s[r]=")" c:-1
  352. r:+1
  353. Wend
  354. s=s[..p-1]+n$+"(HandleToObject"+s[q-1..r-1]+")"+s[r..]
  355. p=p+Len(n)+16
  356. Forever
  357. ' replace New Type with New prefix_type
  358. p=0
  359. Repeat
  360. p=FindToken(s,"New",p)
  361. If Not p Exit
  362. s=s[..p+3]+TypePrefix$+s[p+3..]
  363. p=p+1
  364. Forever
  365. ' replace Dim var(size) with Global var[size]
  366. p=0
  367. Repeat
  368. p=FindToken(s,"Dim",p)
  369. If Not p Exit
  370. s=s[..p-1]+"Global"+s[p+2..]
  371. Repeat
  372. p=Instr(s,"(",p)
  373. If Not p Exit
  374. s=s[..p-1]+"["+s[p..]
  375. p=Instr(s,")",p)
  376. If Not p Exit
  377. s=s[..p-1]+"]"+s[p..] 'was +1
  378. Forever
  379. s=IncrementArrays(s$)
  380. Exit 'no multiple dim calls pre
  381. ' if not p exit
  382. Forever
  383. ' replace function(param[4]) with function(param[])
  384. p=0
  385. Repeat
  386. p=FindToken(s,"Function",p)
  387. If Not p Exit
  388. p=Instr(s,"(",p)
  389. If Not p Exit
  390. q=Instr(s,")",p)
  391. If Not q Exit
  392. n$=StripDims(s[p..q-1])
  393. s=s[..p]+n+s[q-1..]
  394. Exit
  395. Forever
  396. ' for b=each bob -> for b=eachin bob.list
  397. p=0
  398. Repeat
  399. p=FindToken(s,"Each",p)
  400. If Not p Exit
  401. q=FindEOC(s,p+6)
  402. s=s[..p-1]+"EachIn "+Trim(s[p+4..q-1])+"_list"+s[q-1..]
  403. p=q
  404. Forever
  405. ' First class
  406. p=0
  407. Repeat
  408. p=FindToken(s,"First",p)
  409. If Not p Exit
  410. q=FindEOC(s,p+7)
  411. n$=Trim(s[p+5..q-1])
  412. s=s[..p-1]+TypePrefix+n+"("+n+"_list.First())"+s[q-1..]
  413. p=q+Len(n)*2+14
  414. Forever
  415. ' Last class
  416. p=0
  417. Repeat
  418. p=FindToken(s,"Last",p)
  419. If Not p Exit
  420. q=FindEOC(s,p+6)
  421. n$=Trim(s[p+4..q-1])
  422. s=s[..p-1]+TypePrefix+n+"("+n+"_list.Last())"+s[q-1..]
  423. p=q+Len(n)*2+13
  424. Forever
  425. ' Insert b Before|After bob -> b.InsertAfter(bob)
  426. p=0
  427. Repeat
  428. p=FindToken(s,"Insert",p)
  429. If Not p Exit
  430. q=Instr(s," ",p+7)
  431. If Not q Exit
  432. n$=Lower(s[q..])
  433. If n$[..6]="before"
  434. n$="Before"
  435. r=q+7
  436. ElseIf n$[..5]="after"
  437. n$="After"
  438. r=q+6
  439. Else
  440. Exit
  441. EndIf
  442. c=FindEOC(s,r+1)
  443. s=s[..p-1]+s[p+6..q-1]+".Insert"+n$+"("+s[r..c-1]+")"+s[c..] 'n$+ simon was here
  444. p=c
  445. Forever
  446. ' After b -> b.After()
  447. p=0
  448. Repeat
  449. p=FindToken(s,"After",p)
  450. If Not p Exit
  451. q=Instr(s," ",p+7)
  452. If q=0 q=Len s+1
  453. r=Instr(s,";",p+7)
  454. If r And r<q q=r
  455. s=s[..p-1]+s[p+5..q-1]+".After()"+s[q-1..]
  456. p=q
  457. Forever
  458. ' Before b -> b.Before()
  459. p=0
  460. Repeat
  461. p=FindToken(s,"Before",p)
  462. If Not p Exit
  463. q=Instr(s," ",p+8)
  464. If q=0 q=Len s+1
  465. r=Instr(s,";",p+8)
  466. If r And r<q q=r
  467. s=s[..p-1]+s[p+6..q-1]+".Before()"+s[q-1..]
  468. p=q
  469. Forever
  470. Return s
  471. End Function
  472. Function FixQuotes$(q$)
  473. Local p,n
  474. Repeat
  475. p=Instr(q,Chr(34),p)
  476. If p=0 Exit
  477. p=p+1
  478. n=n+1
  479. Forever
  480. If n&1 Return q$+Chr(34) 'add one for odd quoted lines
  481. Return q
  482. End Function
  483. Function ConvertSourceList(src:TList,dest:TList)
  484. Local in$,out$,l$,p,q,r,inrem,name$
  485. Local strings[]
  486. For in=EachIn src
  487. l$=Lower$(in)
  488. If l$="rem" l$="rem "
  489. If inrem
  490. ' terminate remarks
  491. out$=in$
  492. p=Instr(l$,"endrem")
  493. If p<>1 p=Instr(l$,"end rem")
  494. If p=1
  495. inrem=0
  496. EndIf
  497. Else
  498. ' parse strings and remarks
  499. out$=""
  500. in$=fixquotes(in$)
  501. While in$
  502. q=Instr(in$,Chr(34))
  503. r=Instr(in$,";")
  504. inrem=Instr(l$,"rem ")
  505. If inrem And inrem<q q=0
  506. If r And r<q q=0
  507. If q
  508. r=Instr(in$,Chr(34),q+1)
  509. If r=0 r=Len(in$)
  510. out$=out$+Convert(in$[..q-1])+in$[q-1..r]
  511. in$=in$[r..]
  512. Continue
  513. EndIf
  514. If inrem And inrem<r r=0
  515. If r
  516. out$=out$+Convert(in$[..r-1])+"'"+in$[r..]
  517. Exit
  518. EndIf
  519. If inrem
  520. out$=out$+Convert(in$[..inrem-1])+in$[inrem-1..]
  521. Exit
  522. EndIf
  523. out$=out$+Convert(in$)
  524. Exit
  525. Wend
  526. EndIf
  527. l$=Lower(out)
  528. ' type handling extras
  529. If l$[..5]="type "
  530. name$=out$[5..]
  531. p=Instr(name," ")
  532. q=Instr(name,";")
  533. If (Not p) p=Len name
  534. If q And q<p p=q
  535. If p name=name[..p]
  536. name=Trim(name)
  537. p=p+5
  538. TypeLists.AddLast "Global "+name+"_list:TList=new TList"
  539. dest.AddLast "Type "+TypePrefix$+name+" Extends TBBType"+out$[p..]
  540. dest.AddLast ""
  541. dest.AddLast TAB$+"Method New()"
  542. dest.AddLast TAB$+TAB$+"Add("+name+"_list)"
  543. dest.AddLast TAB$+"End Method"
  544. dest.AddLast ""
  545. dest.AddLast TAB$+"Method After:"+TypePrefix$+name+"()"
  546. dest.AddLast TAB$+TAB$+"Local t:TLink"
  547. dest.AddLast TAB$+TAB$+"t=_link.NextLink()"
  548. dest.AddLast TAB$+TAB$+"If t Return "+TypePrefix$+name+"(t.Value())"
  549. dest.AddLast TAB$+"End Method"
  550. dest.AddLast ""
  551. dest.AddLast TAB$+"Method Before:"+TypePrefix$+name+"()"
  552. dest.AddLast TAB$+TAB$+"Local t:TLink"
  553. dest.AddLast TAB$+TAB$+"t=_link.PrevLink()"
  554. dest.AddLast TAB$+TAB$+"If t Return "+TypePrefix$+name+"(t.Value())"
  555. dest.AddLast TAB$+"End Method"
  556. dest.AddLast ""
  557. Continue
  558. EndIf
  559. ' Include "blah.bb" -> Include "blah.bmx"
  560. If l$[..8]="include " Or l$[..8]="include"+Chr$(34)
  561. out=ProcessInclude(out)
  562. EndIf
  563. dest.AddLast out
  564. Next
  565. End Function
  566. Function ReadTextFile:TList(file$)
  567. Local f:TStream,n
  568. Local txt:TList
  569. txt=New TList
  570. f=ReadStream(file)
  571. If Not f Return Null
  572. While Not Eof(f)
  573. txt.AddLast ReadLine(f)
  574. n:+1
  575. Wend
  576. Return txt
  577. End Function
  578. Function WriteTextFile(file$,txt:TList)
  579. Local f:TStream,l$
  580. f=WriteStream(file)
  581. If Not f Return
  582. For l$=EachIn txt
  583. WriteLine f,l
  584. Next
  585. CloseStream f
  586. End Function
  587. Function WriteVKeyFile()
  588. Local dest:TStream=WriteFile("bbvkey.bmx")
  589. If Not dest Return
  590. WriteLine dest,"' virtual key support for legacy Blitz apps"
  591. WriteLine dest,""
  592. WriteLine dest,"Global VKEY[]=[.."
  593. WriteLine dest,"0,KEY_ESCAPE,KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8,KEY_9,KEY_0,.."
  594. WriteLine dest,"KEY_MINUS,KEY_EQUALS,KEY_BACKSPACE,KEY_TAB,KEY_Q,KEY_W,KEY_E,KEY_R,KEY_T,.."
  595. WriteLine dest,"KEY_Y,KEY_U,KEY_I,KEY_O,KEY_P,KEY_OPENBRACKET,KEY_CLOSEBRACKET,KEY_RETURN,.."
  596. WriteLine dest,"KEY_LCONTROL,KEY_A,KEY_S,KEY_D,KEY_F,KEY_G,KEY_H,KEY_J,KEY_K,KEY_L,.."
  597. WriteLine dest,"KEY_SEMICOLON,KEY_QUOTES,KEY_TILDE,KEY_LSHIFT,KEY_BACKSLASH,.."
  598. WriteLine dest,"KEY_Z,KEY_X,KEY_C,KEY_V,KEY_B,KEY_N,KEY_M,KEY_COMMA,KEY_PERIOD,KEY_SLASH,.."
  599. WriteLine dest,"KEY_RSHIFT,KEY_NUMMULTIPLY,KEY_ALT,KEY_SPACE,KEY_CAPSLOCK,.."
  600. WriteLine dest,"KEY_F1,KEY_F2,KEY_F3,KEY_F4,KEY_F5,KEY_F6,KEY_F7,KEY_F8,KEY_F9,KEY_F10,.."
  601. WriteLine dest,"KEY_NUMLOCK,KEY_SCROLL,KEY_NUM7,KEY_NUM8,KEY_NUM9,KEY_NUMSUBTRACT,KEY_NUM4,.."
  602. WriteLine dest,"KEY_NUM5,KEY_NUM6,KEY_NUMADD,KEY_NUM1,KEY_NUM2,KEY_NUM3,KEY_NUM0,.."
  603. WriteLine dest,"KEY_NUMDECIMAL,KEY_NUMSLASH,KEY_F11,KEY_F12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.."
  604. WriteLine dest,"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,.."
  605. WriteLine dest,"KEY_EQUALS,0,0,KEY_MEDIA_PREV_TRACK,0,0,0,0,0,0,0,0,KEY_MEDIA_NEXT_TRACK,0,0,.."
  606. WriteLine dest,"KEY_ENTER,KEY_RCONTROL,0,0,KEY_VOLUME_MUTE,0,KEY_MEDIA_PLAY_PAUSE,0,.."
  607. WriteLine dest,"KEY_MEDIA_STOP,0,0,0,0,0,0,0,0,0,KEY_VOLUME_DOWN,0,KEY_VOLUME_UP,0,.."
  608. WriteLine dest,"KEY_BROWSER_HOME,KEY_DECIMAL,0,KEY_NUMDIVIDE,0,KEY_SCREEN,.."
  609. WriteLine dest,"0,0,0,0,0,0,0,0,0,0,0,0,0,KEY_PAUSE,0,KEY_HOME,KEY_UP,KEY_PAGEUP,0,.."
  610. WriteLine dest,"KEY_LEFT,0,KEY_RIGHT,0,KEY_END,KEY_DOWN,KEY_PAGEDOWN,KEY_INSERT,KEY_DELETE,.."
  611. WriteLine dest,"0,0,0,0,0,0,0,KEY_LWIN,KEY_RWIN,0,0,0,0,0,0,0,0,KEY_BROWSER_SEARCH,.."
  612. WriteLine dest,"KEY_BROWSER_FAVORITES,KEY_BROWSER_REFRESH,KEY_BROWSER_STOP,KEY_BROWSER_FORWARD,.."
  613. WriteLine dest,"KEY_BROWSER_BACK,0,KEY_LAUNCH_MAIL,KEY_LAUNCH_MEDIA_SELECT]"
  614. WriteLine dest,""
  615. WriteLine dest,"Function VKeyDown(key);return KeyDown(VKEY[key]);End Function"
  616. WriteLine dest,"Function VKeyHit(key);return KeyHit(VKEY[key]);End Function"
  617. WriteLine dest,""
  618. WriteLine dest,"'currently unsupported in BlitzMax"
  619. WriteLine dest,""
  620. WriteLine dest,"Function Locate( x,y );return 0;End Function"
  621. WriteLine dest,"Function MouseZSpeed();return 0;End Function"
  622. WriteLine dest,"Function FreeBank(bank);return 0;End Function"
  623. WriteLine dest,"Function LoopSound(sound);return 0;End Function"
  624. WriteLine dest,"Function ChannelPitch(channel,hz);return 0;End Function"
  625. WriteLine dest,"Function PlayCDTrack( track,mode=0 );return 0;End Function"
  626. WriteLine dest,"Function SoundVolume( sound,volume# );return 0;End Function"
  627. WriteLine dest,""
  628. CloseFile dest
  629. End Function
  630. Function WriteBBTypeFile()
  631. Local dest:TStream=WriteFile("bbtype.bmx")
  632. If Not dest Return
  633. WriteLine dest,"' BBType adds legacy Type functionality to BlitzMax Type"
  634. WriteLine dest,""
  635. WriteLine dest,"Type TBBType"
  636. WriteLine dest,""
  637. WriteLine dest," Field _list:TList"
  638. WriteLine dest," Field _link:TLink"
  639. WriteLine dest,""
  640. WriteLine dest," Method Add(t:TList)"
  641. WriteLine dest," _list=t"
  642. WriteLine dest," _link=_list.AddLast(self)"
  643. WriteLine dest," End Method"
  644. WriteLine dest,""
  645. WriteLine dest," Method InsertBefore(t:TBBType)"
  646. WriteLine dest," _link.Remove"
  647. WriteLine dest," _link=_list.InsertBeforeLink(self,t._link)"
  648. WriteLine dest," End Method"
  649. WriteLine dest,""
  650. WriteLine dest," Method InsertAfter(t:TBBType)"
  651. WriteLine dest," _link.Remove"
  652. WriteLine dest," _link=_list.InsertAfterLink(self,t._link)"
  653. WriteLine dest," End Method"
  654. WriteLine dest,""
  655. WriteLine dest," Method Remove()"
  656. WriteLine dest," _list.remove self"
  657. WriteLine dest," End Method"
  658. WriteLine dest,""
  659. WriteLine dest,"End Type"
  660. WriteLine dest,""
  661. WriteLine dest,"Function DeleteLast(t:TBBType)"
  662. WriteLine dest," if t TBBType(t._list.Last()).Remove()"
  663. WriteLine dest,"End Function"
  664. WriteLine dest,""
  665. WriteLine dest,"Function DeleteFirst(t:TBBType)"
  666. WriteLine dest," if t TBBType(t._list.First()).Remove()"
  667. WriteLine dest,"End Function"
  668. WriteLine dest,""
  669. WriteLine dest,"Function DeleteEach(t:TBBType)"
  670. WriteLine dest," if t t._list.Clear()"
  671. WriteLine dest,"End Function"
  672. WriteLine dest,""
  673. WriteLine dest,"Function ReadString$(in:TStream)"
  674. WriteLine dest," local length"
  675. WriteLine dest," length=readint(in)"
  676. WriteLine dest," if length>0 and length<1024*1024 return brl.stream.readstring(in,length)"
  677. WriteLine dest,"End Function"
  678. WriteLine dest,""
  679. WriteLine dest,"Function HandleToObject:Object(obj:Object)"
  680. WriteLine dest," Return obj"
  681. WriteLine dest,"End Function"
  682. WriteLine dest,""
  683. WriteLine dest,"Function HandleFromObject(obj:Object)"
  684. WriteLine dest," Local h=HandleToObject(obj)"
  685. WriteLine dest," Return h"
  686. WriteLine dest,"End Function"
  687. WriteLine dest,""
  688. WriteLine dest,""
  689. CloseFile dest
  690. End Function