Announcement

Collapse
No announcement yet.

Splitting up very large project

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lance Edmonds
    replied
    Bern, that would only be a problem is the merged file was to be loaded back into the IDE... the compiler itself has no arbitary line limit.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Bern Ertl
    replied
    Steve,

    You might need to add some error checking to ensure that your merged
    file(s) do not exceed 16K lines.



    ------------------
    Bernard Ertl

    Leave a comment:


  • Steve Hutchesson
    replied
    The problem posed with includes nested too deep is one that I am
    interested in so I wrote a small toy to solve the problem in the
    short term, it simple starts at the main file and includes all
    of the "#INCLUDE" files into one big file. It does not seem to
    have any problems and the big file that it makes builds correctly
    on the projects that I have tested it on.

    It loops through multiple levels of includes and appears to have
    no nesting level limits, it can get reasonable slow with multiple
    passes because it includes all of the system include files as well.

    Something that is important, it must be run from the directory that
    the main BAS file is in. It assumes that the main file has the paths
    of the included files in it and it will not work if they are not as
    it will not be able to find those files to include them.

    Code:
      ' #########################################################################
      '
      '                             PBmerge.bas
      '
      '   Merges all dependencies into one large file, will remove each nested
      '   level of include files and merges the file into the main file until
      '   no more are left. MUST be run from the directory of the main file.
      '
      ' #########################################################################
      
          #COMPILE EXE
      
          DECLARE SUB GetInclude(incld$)
          DECLARE FUNCTION Exist&(fname$)
      
      ' #########################################################################
      
      FUNCTION PBmain() as LONG
      
          LOCAL loopFlag as LONG
      
          loopFlag = 0
      
          If not exist&(command$) Then
            StdOut "Cannot find that file"
            Exit FUNCTION
          End If
      
        ' -------------------------------------
        ' Copy original file to temporary file
        ' -------------------------------------
          Open command$ for binary as #1
          get$ #1, lof(1), x$
          Close #1
      
          Open "passfile.txt" for Output as #1
          Print #1, x$;
          Close #1
        ' -------------------------------------
      
          Start_Loop:
      
          Open "passfile.txt" for Input as #1
          Open "tempfile.bas" for Output As #2
            Do
              line input #1, a$
      
              If instr(ucase$(a$),"INCLUDE ") <> 0 Then
                If left$(ltrim$(a$),1) <> "'" Then
                  GetInclude a$
                  loopFlag = 1
                ! jmp nxt1
                End If
              End If
      
              Print #2, a$
      
            nxt1:
            Loop while not eof(1)
          Close #2
          Close #1
      
          If loopFlag = 1 Then
            loopFlag = 0
            kill "passfile.txt"
            name "tempfile.bas" as "passfile.txt"
            ! jmp Start_Loop
          End If
      
          kill "passfile.txt"
      
          StdOut "Done"
      
          FUNCTION = 0
      
      END FUNCTION
      
      ' #########################################################################
      
      SUB GetInclude(incld$)
      
          LOCAL lpos as LONG
          LOCAL ln   as LONG
      
          ln = len(incld$)
          lpos = instr(1,incld$,chr$(34))
      
          ln = ln - lpos
      
          TheName$ = trim$(remove$(right$(incld$,ln),chr$(34)))
      
          cp& = instr(TheName$,"'")
          If cp& <> 0 Then
            TheName$ = left$(TheName$,instr(TheName$,"'")-1)
          End If
      
          If exist&(TheName$) Then
            StdOut "Merging "+TheName$
            Open TheName$ for Binary as #3
              Get$ #3, lof(3), b$
              Print #2, b$
            Close #3
          End If
      
      
      END SUB
      
      ' #########################################################################
      
      FUNCTION Exist&(fname$)
        FUNCTION = Len( Dir$(fname$, 17) ) > 0
      END FUNCTION
      
      ' #########################################################################
    Regards,

    [email protected]

    PS: I just added a check to see if the files to be added existed, this catches
    any misreads in the source file such as commented out sections.

    [This message has been edited by Steve Hutchesson (edited April 20, 2001).]

    Leave a comment:


  • Lance Edmonds
    replied
    Yes, the key word should probably be "levels" rather than files. I'll ask the Documentation Dept to make this more clear in the next update. Thanks for pointing this out!


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Hello Again,

    I just thought I would whip up an example of how far you can push #INCLUDE statements.

    BASE:
    Code:
    rem Base.bas
    #compile exe
    #include "Level1.inc"
    
    
    function pbmain as long
        msgbox"Status: OK"
    end function
    LEVEL1:
    Code:
    rem Level1.inc
    #include "Level2.inc"
    LEVEL2:
    Code:
    rem Level2.inc
    #include "Level3.inc
    LEVEL3:
    Code:
    rem Level3.inc
    rem **NO MORE LEVELS ALLOWED**
    To make this very simple, you cannot have more than three include statements nested. I'm not sure how this translates to four in the help file. Maybe PowerBasic was really refering to the number of files...

    ------------------
    Cheers!

    Leave a comment:


  • Tom Hanlin
    replied
    It's on the wish list...

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Peter P Stephensen
    replied
    I too would like the limit to be set up! This would make
    the translation of C-projects to PB easier.

    Regards
    Peter

    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Thanks Tom and Colin,

    Funny you should mention the four level limit, I just ran into it. In the example I gave I decided to go one step further. I took all the included Modules(.BAS) and put them inside a header called "Modules.inc" then, instead of including all those modules I only had to include "Modules.inc". Thats when the limit hit me!

    Tom or Lance,

    Is it likely that this limit will change in the next update?

    ------------------
    Cheers!

    Leave a comment:


  • Colin Schmidt
    replied
    Be careful though, as #INCLUDE can only go down four levels. This got me in my first large project and I had to restructure it completely!

    Colin Schmidt

    ------------------
    Colin Schmidt & James Duffy, Praxis Enterprises, Canada
    [email protected]

    Leave a comment:


  • Tom Hanlin
    replied
    That's an excellent programming practice, yes.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Leave a comment:


  • Guest's Avatar
    Guest replied
    I found out why compiling was going very slow. In one of my header files I forgot to put the "#IF NOT %DEF() #ENDIF" so it was being included a bunch of times.


    Code:
    [Main.bas]
    |
    |
    |__[Windows.inc]
    |  |
    |  |
    |  |__[win32api.inc]
    |  |__[commctrl.inc]
    |  |__[comdlg32.inc]
    |
    |
    |__[Main.inc]
    |  |
    |  |
    |  |__[Resource.inc]
    |  |__[Main.pbr]
    |
    |
    |__[Module.bas]
       |
       |
       |__[Windows.inc]
       |__[Main.inc]
       |__[Module.inc]
    For every INC file you should include the following
    Code:
    rem Module.inc
    #if not %def(%MODULE)
        %MODULE = 1
    
        rem place constants,declares, and globals here
    
    #endif

    Have I got this right?

    ------------------
    Cheers!

    Leave a comment:


  • Borje Hagsten
    replied
    No standard way, as far as I know. In large projects, I like to use
    many custom controls in the form of .inc files, and each sub-dialog
    is created in separate .bas files. Maybe not the best approach but
    it works fine for me. Something like:
    Code:
    MainProg.bas
      #INCLUDE DECLARES.BAS
      #INCLUDE SUBS1.BAS
      #INCLUDE CONTROL1.INC
      #INCLUDE CONTROL2.INC
      #INCLUDE CONTROL3.INC
      #INCLUDE DIALOG1.BAS
      #INCLUDE DIALOG2.BAS
      #INCLUDE DIALOG3.BAS
    ..etc, where SUBS1, SUBS2, etc may contain anything from one huge routine
    to many small, related ones and DECLARES.INC contains all declarations,
    for all dialogs, subs and functions - with pointers to where they are.

    The reason for sub-dialogs in separate .BAS files is because I usually
    start out designing dialogs as separate, small exe files and when the
    design is ready, I change PBMAIN to something like "AboutBoxProc" so
    it can be called up from main prog. Think it's easier and faster to
    design sub-dialogs this way, since compilation is faster, this making
    it easier to rearrange controls to my liking. When "visual design" is
    ready, I simply include the file into main prog..


    ------------------

    Leave a comment:


  • Guest's Avatar
    Guest replied
    Thanks Peter, thats pretty much what I did also. Did you notice the compiler takes a lot longer to compile when you split up your project?

    ------------------
    Cheers!

    Leave a comment:


  • Peter P Stephensen
    replied
    Mark,

    I am currently working on a large project. I have tried to do it
    the C-way, by splitting it in a lot of files (21 bas-files and
    29 inc-files).

    The main file is called make.bas looks like this:
    Code:
    '////////////////////////////////
    '     MAKE - File
    '////////////////////////////////
     
    '////////////////////////////////
    '     Compile options
    '////////////////////////////////
    #compile exe "release\Bef01.exe"
    #dim all
    #register none
     
    '////////////////////////////////
    '     Resources
    '////////////////////////////////
    #resource "res\bef.pbr"
    #include "res\resource.inc"
     
    '////////////////////////////////
    '     Windows include-files
    '////////////////////////////////
    #include "win32api.inc"
    #include "mdi32.inc"
    #include "commctrl.inc"
    #include "comdlg32.inc"
     
    '////////////////////////////////
    '     User defined entries
    '////////////////////////////////
    #include "tabctrl1.inc"
    #include "spread30.inc"
     
    #include "..\include\chart6a.inc"
    #include "..\include\const.inc"
    #include "..\include\fileconv.inc"
    #include "..\include\group.inc"
    #include "..\include\initstr.inc"
    #include "..\include\str.inc"
    #include "..\include\tab.inc"
     
    ' Functions
    %PSP_GetFile = 1
    %PSP_SetFont = 1
    %PSP_SetRegistry = 1
    %PSP_GetRegistry = 1
    %PSP_TXT = 1
    %PSP_BrowseForFolder = 1
    %PSP_FindWindowText = 1
    %PSP_malloc = 1
    %PSP_free = 1
    %PSP_Splash = 1
    #include "psp.inc"
     
    '////////////////////////////////
    '     Source code
    '////////////////////////////////
    #include "main.bas"
    #include "misc.bas"
    #include "data.bas"
    #include "menu.bas"
    #include "text.bas"
    #include "progress.bas"
    #include "dialogs.bas"
    #include "mdi.bas"
    #include "reg.bas"
    #include "sheet1.bas"
    #include "status.bas"
    #include "toolbar.bas"
    #include "wrkspace.bas"
    #include "frame.bas"
    #include "settings.bas"
    #include "InpSheet.bas"
    #include "mortfreq.bas"
    #include "general.bas"
    #include "expage.bas"
    #include "output.bas"
     
    '////////////////////////////////
    '     End of MAKE - File
    '////////////////////////////////
    For each of the source-code files I have an inc-file that
    declares functions and constants.
    As an example frame.inc looks like this:
    Code:
    #if not %def(%FRAME_INC)
    %FRAME_INC = 1
     
    $FrameClass = "MdiFrame"
     
    %IDC_TITLE = 100
     
    ' Declarations
    declare function RegisterFrame() as long
    declare function CreateFrame() as long
    declare function FrameWndProc (byval hwnd as long, byval message as long, _
                           byval wParam as long, byval lParam as long) as long
    declare function CloseEnumProc (byval hwnd as long, byval lParam as long) as long
    declare function InitDataProc(byval dummy as long) as long
     
    #endif
    Frame.bas looks like this:
    Code:
    #include "progress.inc"
    #include "dialogs.inc"
    #include "main.inc"
    #include "data.inc"
    #include "mdi.inc"
    #include "status.inc"
    #include "toolbar.inc"
    #include "wrkspace.inc"
    #include "settings.inc"
    #include "mortfreq.inc"
    #include "frame.inc"
    #include "output.inc"
     
    ' ....all the source code
    If I in a module (some other bas-file) needs a function
    defined in frame.bas, I just write #include "frame.inc"
    at the top of this file.

    When i write a new module I just add it in the make-file.

    Regards
    Peter


    ------------------


    [This message has been edited by Peter P Stephensen (edited April 18, 2001).]

    Leave a comment:


  • Guest's Avatar
    Guest started a topic Splitting up very large project

    Splitting up very large project

    Hello Everyone,

    I have been working on a very large project. Because of its size I thought it would be better to split it up into smaller pieces. My problem is, I'm not sure how to go about resolving all the INCLUDE problems. I noticed under C++ there is usually an implimentation file along with the header file (.C and .H). Is there a good set of rules to follow when doing this with PBDLL. Can someone maybe give me a list of rules to follow when splitting up files.

    Simply put, how would you do it?

    ------------------
    Cheers!
Working...
X