Request: improved Import command

BlitzMax Forums/BlitzMax Programming/Request: improved Import command

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

then just CUT AND PASTE, saves loads of typeing
This produces unreadable code.

For the time this feature isn't implemented yet, I wrote a special module scope named "all", which contains lists of all modules and scopes. But this shouldn't be the final solution.
Strict

Import brl.filesystem

Incbin "update.bmx"

Function UpdateModuleScopeAll ( )
  Local Path$ = getenv_ ( "BMXPATH" ).Replace ( "/" , "" )
  If Not Path
    Return
  EndIf
  If Path [ Len Path - 1 ] <> Asc ""
    Path :+ ""
  EndIf
  Path :+ "mod"
  DeleteDir Path + "\all.mod" , True
  Local Scopes$ []
  Local Modules$ [] []
  For Local File$ = EachIn LoadDir ( Path )
    If File [ Len File - 4 ..].ToLower ( ) = ".mod"
      Scopes = Scopes [.. Len Scopes + 1 ]
      Scopes [ Len Scopes - 1 ] = File [.. Len File - 4 ]
      Modules = Modules [.. Len Modules + 1 ]
      For Local Sub$ = EachIn LoadDir ( Path + "" + File )
        If Sub [ Len Sub - 4 ..].ToLower ( ) = ".mod"
          For Local S$ = EachIn LoadDir ( Path + "" + File + "" + Sub )
            If Sub [.. Len Sub - 4 ].ToLower ( ) + ".bmx" = S.ToLower ( )
              If File.ToLower ( ) <> "pub.mod" Or Sub.ToLower ( ) <> "all.mod"
                Modules [ Len Modules - 1 ] = Modules [ Len Modules - 1 ] [.. Len Modules [ Len Modules - 1 ] + 1 ]
                Modules [ Len Modules - 1 ] [ Len Modules [ Len Modules - 1 ] - 1 ] = S [.. Len S - 4 ]
              EndIf
              Exit
            EndIf
          Next
        EndIf
      Next
    EndIf
  Next
  CreateDir Path + "\all.mod"
  CreateDir Path + "\all.mod\all.mod"
  Local Stream:TStream = WriteStream ( Path + "\all.mod\all.mod\all.bmx" )
  WriteString Stream , "Strict~nModule all.all~n"
  For Local Scope$ = EachIn Scopes
    WriteString Stream , "~nImport all." + Scope
  Next
  CloseStream Stream
  Stream = WriteStream ( Path + "\all.mod\all.mod\update.bmx" )
  WriteString Stream , String.FromBytes ( IncbinPtr "update.bmx" , IncbinLen "update.bmx" )
  CloseStream Stream
  For Local I = 0 Until Len Scopes
    CreateDir Path + "\all.mod" + Scopes [ I ] + ".mod"
    Stream = WriteStream ( Path + "\all.mod" + Scopes [ I ] + ".mod" + Scopes [ I ] + ".bmx" )
    WriteString Stream , "Strict~nModule all." + Scopes [ I ] + "~n"
    For Local ModName$ = EachIn Modules [ I ]
      WriteString Stream , "~nImport " + Scopes [ I ] + "." + ModName
    Next
    CloseStream Stream
  Next
EndFunction

Rem
Strict
Framework brl.blitz

Import "..\mod\all.mod\all.mod\update.bmx"

UpdateModuleScopeAll

To install it create a folder "all.mod" in the BMX mod folder, then create "all.mod/all.mod", finally create the file "all.mod/all.mod/update.bmx" and copy the code into it. then create a new untitled document in the MaxIDE and copy the code after the Rem-statement into it and run it.
Rebuild the module and you're finish.

So for now you can write "Import all.pub" instead of "Import pub.*" and "Import all.all" instead of "Import *.*"