BBS: Inland Empire Archive Date: 04-05-92 (23:45) Number: 127 From: DANIEL CORBIER Refer#: 126 To: DARYL POSNETT Recvd: NO Subj: C vs BASIC (Was: Powerbas Conf: (2) Quik_Bas
'**************************************************************** ' Small (tiny) application that does the following: ' COMBINE : combines any number of source files into target files ' example of usage : combine test *.bas ' ( concatenates all .bas files in current dir into file test ) ' Challenge from Daryl Posnett. Written by Daniel Corbier ' See previous posting from Daryl Posnett for full description. '**************************************************************** On error goto ErrorHandler Print "COMBINE - Copyright 1992 by Daniel Corbier" Blank$ = chr$(9) + chr$(32) ParseLine$ = command$ + " " TargetFile$ = NextArgument$( ParseLine$, blank$ ) '*** If less then TWO parameters then exit with -1 If len( ParseLine$ ) = Tally( ParseLine$, any blank$ ) then Print "Error: Not enough parameters" End -1 End If Open TargetFile$ for append as #1 Do '** dir$() accepts all DOS wildcards for source filenames FileDescription$ = NextArgument$( ParseLine$, blank$ ) NextFile$ = dir$(FileDescription$) Do '** If file exists, then concatinate to TargetFile$ ** If NextFile$<> "" then call AppendFile(NextFile$) NextFile$ = dir$ '** dir$ is a PB variable Loop while NextFile$ <> "" Loop Until len( ParseLine$ ) = Tally( ParseLine$, any blank$ ) '*** Procedure to append FileName$ to TargetFile$ *** Sub AppendFile(FileName$) Print FileName$, Open FileName$ for binary as #2 LengthOfFile = lof(2) '** variable so file can copy to itself '*** Copy file in chunks of <= 32Kb *** While loc(2) < LengthOfFile Get$ #2, min(32700,LengthOfFile-loc(2)), chunk$ Print #1,chunk$; Wend Close #2 End Sub '*** Function to parse the command line *** Function NextArgument$( text$, blank$ ) Argument$ = extract$( ltrim$(text$,any blank$), any blank$ ) Text$ = mid$(text$,instr(text$,argument$)+len(argument$)) NextArgument$ = Argument$ End Function Print "done" End ErrorHandler: reg 1,&h5900 '** Load AH with DOS function 59h call interrupt &h21 '** Call function request interrupt print"DOS error";reg(1) '** Print DOS critical error End reg(1) '** Exit with errorlevel at AX register
----- A FEW NOTES The program was compiled with PB 2.10a as it is. No include files, no linked files, no ASM inline. Works like a charm. Incorporates every feature described by Daryl P. plus more. Smallest .EXE size: 18556 bytes Speed: Roughly same as DOS copy Lines: 64 Statements: 42 The following concepts from the program are probably foreign to QB4.5: ANY -- Usable in most string functions. For instance instr("abcdef", any "aef") finds the first character that is either an 'a', 'e', or 'f'. DIR$ -- DIR$() and DIR$ returns a matching file name. EXTRACT$ -- Portion of string leading up to first occurrence. REG -- Loads or retrieves info from a register. TALLY -- Counts the number of occurrences in a string$. END n -- Exits to DOS with errorlevel set to n. --- Maximus 2.01wb * Origin: The Programmer's Workshop (1:135/317)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET