maxutil.bmx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Strict
  2. Module BRL.MaxUtil
  3. ModuleInfo "Version: 1.01"
  4. ModuleInfo "Author: Mark Sibly"
  5. ModuleInfo "License: zlib/libpng"
  6. ModuleInfo "Copyright: Blitz Research Ltd"
  7. ModuleInfo "Modserver: BRL"
  8. ModuleInfo "History: 1.01 Release"
  9. ModuleInfo "History: 1.00 Release"
  10. Import BRL.LinkedList
  11. Import BRL.FileSystem
  12. Import Pub.StdC
  13. Function BlitzMaxPath$()
  14. Global bmxpath$
  15. If bmxpath Return bmxpath
  16. Local p$=getenv_("BMXPATH")
  17. If p
  18. bmxpath=p
  19. Return p
  20. EndIf
  21. p=AppDir
  22. Repeat
  23. Local t$=p+"/bin/bmk"
  24. ?Win32
  25. t:+".exe"
  26. ?
  27. If FileType(t)=FILETYPE_FILE
  28. putenv_ "BMXPATH="+p
  29. bmxpath=p
  30. Return p
  31. EndIf
  32. Local q$=ExtractDir( p )
  33. If q=p Throw "Unable to locate BlitzMax path"
  34. p=q
  35. Forever
  36. End Function
  37. Function ModulePath$( modid$ )
  38. Local p$=BlitzMaxPath()+"/mod"
  39. If modid p:+"/"+modid.Replace(".",".mod/")+".mod"
  40. Return p
  41. End Function
  42. Function ModuleIdent$( modid$ )
  43. Return modid[modid.FindLast(".")+1..]
  44. End Function
  45. Function ModuleSource$( modid$ )
  46. Return ModulePath(modid)+"/"+ModuleIdent(modid)+".bmx"
  47. End Function
  48. Function ModuleArchive$( modid$,mung$="" )
  49. If mung And mung[0]<>Asc(".") mung="."+mung
  50. Return ModulePath(modid)+"/"+ModuleIdent(modid)+mung+".a"
  51. End Function
  52. Function ModuleInterface$( modid$,mung$="" )
  53. If mung And mung[0]<>Asc(".") mung="."+mung
  54. Return ModulePath(modid)+"/"+ModuleIdent(modid)+mung+".i"
  55. End Function
  56. Function EnumModules:TList( modid$="",mods:TList=Null )
  57. If Not mods mods=New TList
  58. Local dir$=ModulePath( modid )
  59. Local files$[]=LoadDir( dir )
  60. For Local file$=EachIn files
  61. Local path$=dir+"/"+file
  62. If file[file.length-4..]<>".mod" Or FileType(path)<>FILETYPE_DIR Continue
  63. Local t$=file[..file.length-4]
  64. If modid t=modid+"."+t
  65. Local i=t.Find( "." )
  66. If i<>-1 And t.Find( ".",i+1)=-1 mods.AddLast t
  67. mods=EnumModules( t,mods )
  68. Next
  69. Return mods
  70. End Function