home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MISC / TNH_PC.ZIP / BECKLEY.NL < prev    next >
Encoding:
Text File  |  1987-01-14  |  3.8 KB  |  129 lines

  1. Processing Tab Characters
  2.  
  3.            Robert H. Beckley
  4.     Manassas Personal Computer Club
  5.  
  6. Some editors, like the Personal
  7. Editor, compress blanks out of text
  8. files before storing those files onto
  9. the diskette. This helps shorten the
  10. files and thus provide more free
  11. diskette space. However, it adds an
  12. additional burden to any program that
  13. wants to process the files. In
  14. working on my own word processor,
  15. BEEPER, I added an assembly language
  16. routine that would expand the tabs
  17. back to the original blanks. I will
  18. share that Assembly Language program
  19. and a sample Pascal test program with
  20. you here.
  21.  
  22. A tab character is a special ASCII
  23. code that is inserted in a file to
  24. replace up to eight blanks. The tabs
  25. are set for columns 8, 16, 24, and so
  26. forth. If there are more than eight
  27. blanks in a row, multiple tab
  28. characters may be inserted into the
  29. text.  The algorithm for determining
  30. the number of blanks to insert to
  31. expand the tab is:
  32.  
  33. Number of blanks to insert =
  34. 8 - (COL mod 8)
  35.  
  36. Examples:
  37. If tab char is in col 1,
  38.    then insert 7 blanks
  39. If tab char is in col 2,
  40.    then insert 6 blanks
  41. If tab char is in col 7,
  42.    then insert 1 blank
  43. If tab char is in col 10,
  44.     then insert 6 blanks
  45.  
  46. The Assembly Language procedure that
  47. expands the tabs is shown on the
  48. following page. It can be called from
  49. a Pascal program. Two parameters are
  50. passed; both are variable length
  51. strings. The first is the original
  52. line which may or may not include
  53. tabs, and the second is the resulting
  54. string with tabs expanded to blanks.
  55. The second string must have enough
  56. space for the maximum length line
  57. that can result. The program sets the
  58. output string length to zero (a null
  59. string) if the input line is null or
  60. is all blank. I did this because that
  61. is what I needed in BEEPER. The
  62. program is documented, and I will
  63. leave it to the reader to learn it
  64. from the listing.
  65.  
  66. The program can be assembled with the
  67. Macro Assembler, resulting in object
  68. file that can be linked with the
  69. Pascal program which calls the
  70. EXPAND_TABS routine. A test Pascal
  71. program illustrates that tab
  72. expansion is provided. TEST shows how
  73. the Assembly Language is referenced
  74. from Pascal. An attribute of EXTERN
  75. is attached to the EXPAND_TABS
  76. procedure to allow the compiler to
  77. resolve calls to the procedure. TEST
  78. can then be compiled to produce
  79. TEST.OBJ. TEST.OBJ can be linked with
  80. the object produced by the Assembler
  81. to produce an executable TEST.EXE
  82. file.
  83.  
  84.  
  85. Assemble ENABLE.ASM --> ENABLE.OBJ
  86.  
  87. Compile TEST.PAS --> TEST.OBJ
  88.  
  89.     Link LINK TEST+ENABLE; --> TEST.EXE
  90.  
  91. The TEST program assumes there is a
  92. file on the default drive called
  93. TEST.TXT.  This file should contain
  94. text containing tab characters (e.g.,
  95. a file stored under Personal Editor
  96. without invoking the NOTABS option).
  97. The file is read, one line at a time,
  98. and each line is passed to the
  99. EXPAND_TABS routine. The results are
  100. shown on the screen:
  101.  
  102. Length of the original string
  103. The expanded original string
  104. The original string with "@"
  105.   displayed for each tab char
  106. ======== Call EXPAND_TABS =======
  107. Length of the resulting string
  108. The resulting string
  109.  
  110. This shows the tabs in the original
  111. string by displaying them as "@"
  112. characters.  The resulting string,
  113. which shows that the tabs were
  114. expanded properly, should be equal to
  115. the expanded original string (which
  116. DOS has properly expanded to display
  117. it). The TEST can be used to ensure
  118. that the above assemble and link
  119. steps where done correctly. I hope
  120. this routine will be useful for the
  121. those who need to expand tabs in text
  122. lines within a program.
  123.  
  124. EDITOR'S NOTE: The program has been
  125. put in a separate file called
  126. EXPNDTAB.ASM and the expand tab test
  127. program is a separate file called
  128. TESTTAB.PAS.
  129.