home *** CD-ROM | disk | FTP | other *** search
- Processing Tab Characters
-
- Robert H. Beckley
- Manassas Personal Computer Club
-
- Some editors, like the Personal
- Editor, compress blanks out of text
- files before storing those files onto
- the diskette. This helps shorten the
- files and thus provide more free
- diskette space. However, it adds an
- additional burden to any program that
- wants to process the files. In
- working on my own word processor,
- BEEPER, I added an assembly language
- routine that would expand the tabs
- back to the original blanks. I will
- share that Assembly Language program
- and a sample Pascal test program with
- you here.
-
- A tab character is a special ASCII
- code that is inserted in a file to
- replace up to eight blanks. The tabs
- are set for columns 8, 16, 24, and so
- forth. If there are more than eight
- blanks in a row, multiple tab
- characters may be inserted into the
- text. The algorithm for determining
- the number of blanks to insert to
- expand the tab is:
-
- Number of blanks to insert =
- 8 - (COL mod 8)
-
- Examples:
- If tab char is in col 1,
- then insert 7 blanks
- If tab char is in col 2,
- then insert 6 blanks
- If tab char is in col 7,
- then insert 1 blank
- If tab char is in col 10,
- then insert 6 blanks
-
- The Assembly Language procedure that
- expands the tabs is shown on the
- following page. It can be called from
- a Pascal program. Two parameters are
- passed; both are variable length
- strings. The first is the original
- line which may or may not include
- tabs, and the second is the resulting
- string with tabs expanded to blanks.
- The second string must have enough
- space for the maximum length line
- that can result. The program sets the
- output string length to zero (a null
- string) if the input line is null or
- is all blank. I did this because that
- is what I needed in BEEPER. The
- program is documented, and I will
- leave it to the reader to learn it
- from the listing.
-
- The program can be assembled with the
- Macro Assembler, resulting in object
- file that can be linked with the
- Pascal program which calls the
- EXPAND_TABS routine. A test Pascal
- program illustrates that tab
- expansion is provided. TEST shows how
- the Assembly Language is referenced
- from Pascal. An attribute of EXTERN
- is attached to the EXPAND_TABS
- procedure to allow the compiler to
- resolve calls to the procedure. TEST
- can then be compiled to produce
- TEST.OBJ. TEST.OBJ can be linked with
- the object produced by the Assembler
- to produce an executable TEST.EXE
- file.
-
-
- Assemble ENABLE.ASM --> ENABLE.OBJ
-
- Compile TEST.PAS --> TEST.OBJ
-
- Link LINK TEST+ENABLE; --> TEST.EXE
-
- The TEST program assumes there is a
- file on the default drive called
- TEST.TXT. This file should contain
- text containing tab characters (e.g.,
- a file stored under Personal Editor
- without invoking the NOTABS option).
- The file is read, one line at a time,
- and each line is passed to the
- EXPAND_TABS routine. The results are
- shown on the screen:
-
- Length of the original string
- The expanded original string
- The original string with "@"
- displayed for each tab char
- ======== Call EXPAND_TABS =======
- Length of the resulting string
- The resulting string
-
- This shows the tabs in the original
- string by displaying them as "@"
- characters. The resulting string,
- which shows that the tabs were
- expanded properly, should be equal to
- the expanded original string (which
- DOS has properly expanded to display
- it). The TEST can be used to ensure
- that the above assemble and link
- steps where done correctly. I hope
- this routine will be useful for the
- those who need to expand tabs in text
- lines within a program.
-
- EDITOR'S NOTE: The program has been
- put in a separate file called
- EXPNDTAB.ASM and the expand tab test
- program is a separate file called
- TESTTAB.PAS.