Ok, so there you have a few of my favourite routines, all you need now is a librarian to sort them out for you. Ok, I give up, here is one for you - this is very basic and not super at all (sorry for that pun) it is up to you to expand on this if you want.
Some suggestions would be :
Make PE aware ?
Add better/some error trapping.
Save the dependencies so that the user need not enter them manually.
Check what has just been entered with what has already been entered to avoid duplications.
Reduce the number of file open/closes etc (On the Library file)
Convert to assembler - Ha, now you're quaking in your boots !
(I have omitted line numbers from the following listing.
CLS Output = 3 INPUT 'Library name : ' LibraryName$ INPUT 'Output file name : '; Output$ OPEN_NEW #Output, Output$ : REPeat main_loop INPUT 'Routine name (ENTER to quit) : '; Name$ IF (Name$ = '') EXIT MainLoop END IF ExtractName Name$ END REPeat MainLoop : CLOSE #Output PRINT "Done." STOP : : DEF PROCedure ExtractName(ReqdName$) LOCal A$, Library, FoundName$ Library = Output + 1 OPEN_IN #Library, LibraryName$ REPeat LibLoop IF (EOF #Library) EXIT LibLoop END IF INPUT #Library, A$ IF (A$(1 TO 6) == "* NAME") FoundName$ = A$(17 TO) IF (FoundName$ == ReqdName$) PRINT "Found subroutine : " & ReqdName$ GetDependencies(Library) ExtractCode(Library) CLOSE #Library RETurn ENDIF END IF END REPeat LibLoop PRINT "Cannot find : " & ReqdName$ END DEFine ExtractName : : DEF PROCedure GetDependencies(Channel) LOCal A$ REPeat DependLoop IF (EOF #Channel) RETurn END IF INPUT #Channel, A$ IF (A$(1 TO 12) == "* DEPENDENCY") IF (A$(17 TO 20) == "None") PRINT "No dependencies" Return END IF PRINT "Dependency required : " & A$(17 TO) END IF IF (A$(1 TO 9) == "* PURPOSE" RETurn END IF END REPeat DependLoop END DEFine GetDependencies : : DEF PROC ExtractCode(Channel) LOCal A$ REPeat FindCodeLoop IF (EOF #Channel) RETurn END IF INPUT #Channel, A$ IF (A$(1 TO 5) == "*----" EXIT FindCodeLoop END IF END REPeat FindCodeLoop REPeat WriteCodeLoop IF (EOF #Channel) RETurn END IF INPUT #Channel, A$ IF (A$(1 TO 5) == "*----" EXIT WriteCodeLoop END IF PRINT #Output, A$ END REPeat WriteCodeLoop PRINT "Extracted."\\ END DEFine ExtractCode
After asking for your details etc, it simply enters a loop asking you for the next routine to be extracted. This name is passed to ExtractName which opens the library file and scans it looking for all those lines which start '* NAME'. Once it finds one, it tests to see if this line includes the name you are looking for.
Note that this version of the program assumes you are using EXACTLY the same format in your comments as I am above and as per the following description :
Column 1 = An asterisk, the comment marker for most assemblers I have used.
Column 2 = A space.
Columns 3 to 16 = Parameter name, eg NAME, DEPENDENCY etc
Columns 17 onwards = Parameter details etc.
If the name found is the same as the one you requested, the dependencies are extracted and listed. You are advised to note these dependencies and enter them as the next routine to extract. Try not to duplicate names etc as the program doesn't test for duplicates.
Once all dependencies have been listed, The code is extracted and written to the output file.
A sample session follows :
Library name : Win1_GWASL_Library_lib Output file name : Win1_source_MyNextProject_asm Routine name (ENTER to quit) : Colours Found subroutine : COLOURS No dependencies Extracted. Routine name (ENTER to quit) : Scr_paper_sb Found subroutine : SCR_PAPER_SB Dependency required : SCR_PAPER Dependency required : SCR_STRIP Extracted. Routine name (ENTER to quit) : Scr_paper Found subroutine : SCR_PAPER No dependencies Extracted. Routine name (ENTER to quit) : SCR_STRIP Found subroutine : SCR_STRIP No dependencies Extracted. Routine name (ENTER to quit) : Done.
So there you have it and now you can enhance it as required to suit your own purposes. Remember, my version expects the comments to be in the format given above. Additionally, no comments are written to the output file but you can easily amend the code in ExtractCode to do the needful. Enjoy.