home *** CD-ROM | disk | FTP | other *** search
-
-
- QBREDIRECT
-
- By Peter R. Barnes
-
- March, 1992
-
-
-
-
-
- WHAT IS QBREDIRECT?
-
- This utility module allows QuickBasic programmers to display the
- redirected output of an executed program simultaneously to the screen
- as it is sent to the redirection target (usually, a file). Why would
- you want to do this? The best reason I can think of would be the
- common situation where you want to record some information to a file
- for later action or review, but need to keep the user informed of the
- current status. The sample program REDTEST.BAS, included here, is a
- good example.
-
- Let's say your program wants to format a user disk, and keep track of
- the total bytes available on that disk. One simple way to accomplish
- this task is to do something like:
-
- SHELL "format a: >fmt.txt"
-
- At the end of the formatting process, DOS will tell you how much space
- is available on the disk by outputting:
-
- xxxxxxx bytes free
-
- Now, with redirection being used, that number would be written to your
- redirection target file, fmt.txt, where you could obtain it by opening
- and reading the file via Basic. But there are two obstacles to doing
- this. As soon as DOS receives a command to format, it puts out a
- message:
-
- Insert disk in Drive A:
- Press ENTER when ready
-
- If output is redirected, that message is sent to the target file, too,
- so the user never sees it. Meanwhile, DOS waits for the user to press
- ENTER -- and DOS is very patient, it will wait a !!!LONG!!! time. To
- make things worse, DOS does the same thing after it outputs the "bytes
- free" message, by asking:
-
- FORMAT ANOTHER (Y/N)?
-
- Again, DOS will expect an answer, but only our redirection file knows
- the question!
-
- Of course, you could use a library that provides routines to do this
- task, or some other fancy tricks such as using redirected input, but
- why bother, when DOS will do it for you? All you REALLY want to do is
- capture the output, and redirection does a fine job of accomplishing
- that task. The only problem is that DOS likes to do things its' way;
- it will not allow you to see what's going on when redirection is used,
- like the example we are considering here.
-
- The QBREDIR module solves the problem by tapping into the DOS Interrupt
- Services interrupt 21 routine. Whenever DOS does just about anything
- related to the outside world, it uses interrupt 21 to do the job. Our
- module intercepts calls to this interrupt to check for DOS output to a
- file. If that is the case, QBREDIR duplicates the information and
- sends it to the screen so that the user can see what is going on. Your
- program controls this action merely by setting or zeroing a flag
- variable that you pass to QBREDIR when you install the module in
- memory. By polling this flag, QBREDIR determines what action will
- occur when output is redirected.
-
-
-
- THE LEGAL STUFF
-
- This program is released to the public domain, meaning you may use it
- for any purpose you desire. Nor will I be responsible for anything
- that happens when you use it, period. The program is based on the
- public-domain routine REDVIEW.COM, written by Alexander Novy and Petr
- Horak of the University of Prague in Czechoslovakia, and I have revised
- it to work with QuickBasic Ver. 4.5. I did this only as an exercise
- for myself in assembly level programming, and I thought someone else
- may find it useful.
-
-
-
- RESTRICTIONS ON USING QBREDIR
-
- Because this routine installs a custom interrupt handler in your PC
- when it is run, it must be treated with care, in that you must always
- remember to remove it from memory after you have installed it.
- Furthermore, the routine reads a value from a memory location that was
- identified as your flag variable when the routine was installed in
- memory; however, we all know that QuickBasic occasionally likes to
- move variables around whenever it feels the urge, so you may observe a
- problem that indicates that QBREDIR has lost track of your flag
- variable. All I can suggest in those cases is that you use a liberal
- sprinkling of DEFSEG, VARSEG, and VARPTR statements to verify what is
- happening. I don't think it will happen, though, unless your program
- is REALLY long, or it uses lots of dynamic, redimensioned arrays, or a
- ton of concatenated string variables.
-
- You can avoid the problem by calling the QFRedSet subroutine just
- before the redirection is to occur, because that will pass the current
- address of your flag variable to QBREDIR. A call to QFRedSet, after
- the initial call to install the handler routine and prior to any call
- to QFRedOff, merely updates the location of your flag variable for the
- handler.
-
- Note that you cannot use QBREDIR in the QuickBasic Editor environment,
- because redirection has no effect when you are in the editor environment.
- Also remember that, when redirection is in effect, QBREDIR only displays
- redirected output information; in our "format" example above, this means
- that our routine will display the "FORMAT ANOTHER (Y/N)?" message, but
- it will NOT echo the "Y" or "N" keystroke that the user types to answer
- the prompt, because that is handled by a different interrupt (the
- keystroke will appear in the redirection file, however).
-
-
-
-
- HOW TO USE QBREDIR
-
- With those restrictions in mind, the routine is easy to use. When you
- want to enable screen display of redirected output, you call the
- installation routine, passing to it the address of the integer variable
- that will activate the display:
-
- CALL QFRedSet (YourFlagVariable%)
-
- Thereafter, whenever you want to turn display of redirected output on
- or off, just set your variable to zero (off) or 1 (on). The interrupt
- handler routine will look at this flag to determine its' action.
-
- When it is time to end your program, or if you just want to uninstall
- the handler routine from memory, you simply:
-
- CALL QFRedOff
-
- Thereafter, all redirected output will be processed in the usual DOS
- manner. Be sure to ALWAYS do this call before you end your program, OR
- YOU WILL SURELY LOCK UP YOUR COMPUTER AFTER YOUR PROGRAM ENDS.
-
- Examine the source code in REDTEST.BAS to get an idea how easy it is to
- set up and use this utility. Just be sure to link your program with
- the module QBREDIR.OBJ when you make your executable file:
-
- LINK /[your options] YOURPROG + QBREDIR;
-
-
-
- FILES INCLUDED WITH THIS PROGRAM
-
- You should have the following files in this package:
-
- QBREDIR.OBJ -- This is the Object module you link with
- your program to enable redirection
- display
-
- QBREDIR.ASM -- The Assembly listing used to make the
- Object module. It is in tutorial form
- because that was its original purpose.
-
- QBREDIR.DOC -- This documentation file
-
- QBREDIR.LST -- A listing file produced by TASM during
- compilation, included here for those
- interested
-
- REDTEST.BAS -- Source code for a simple demonstration
- of the handler routines
-
- REDTEST.EXE -- Executable form of the demo program
-
-
-
-
- "REGISTRATION"
-
- If you like this routine (or even if you don't), I would enjoy hearing
- your comments about it. Send them to:
-
- Peter R. Barnes
- 9116 Saddlebow Dr.
- Brentwood, Tn. 37027
-
- or you can leave a message in the I-LINK Quick Basic Conference on any
- BBS system, and I will pick it up. I am usually checking on to the
- following excellent boards every day or so:
-
- DATAWORLD 615/966 3574 'Tennessee's Finest!
-
- HACKER CENTRAL 201/334 2555
-
- COMPUDATA 609/232 1245
-
-
- Remember the Quick Basic Motto:
-
- ANYTHING C CAN DO, WE CAN DO BETTER!
-