home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / sprint / balance.zip / BALANCE.SPM
Text File  |  1989-07-02  |  2KB  |  60 lines

  1. ; Macro for checking delimiter balance in 100K+ Ventura 2.0 ASCII
  2. ; files. It would be great if it worked better.
  3. ; It remembers the value of "modf" in "w" and error codes in "i"
  4. ; so change these if used elsewhere. 
  5. ; Delimiters are () <>, checks all for a match
  6. #define w
  7. #define i
  8. swapmark : if (inbuff themark) swap themark
  9. ; balini1: inserts ^A (the default) before every occurrence 
  10. ; of the given character.
  11. balini1: ->y
  12.   r to markE
  13.   while (y csearch) (1 insert $ c)
  14. ; balinit: stores "modf" and calls balini1 on all delimiters
  15. ; balinit: set themark
  16. balinit: set markE
  17.     modf ->w
  18.     mark    ('(' balini1 ')'    balini1
  19.     '<' balini1    '>' balini1
  20.             )
  21. ; balterm: removes all the ^A's and restores "modf".
  22. balterm: exitmenus mark (r toend while (1 csearch) (1 del)) w ->modf 
  23. ; isopendelim: returns true if the current character is an open delimiter.
  24. isopendelim: current case ('(' 1, '<' 1, $ 0)
  25. ; closer: returns the closing delimiter matching the given open one.
  26. closer: case ('(' ')', '<' '>')
  27. ; nextdelim: moves to the next delimiter
  28. nextdelim: 1 csearch $ c
  29. ; balerr: prints appropriate error message, calls balterm, and aborts.
  30. balerr: (balterm $)
  31.   case ( 1 message "\nNo closing delimiter" abort,
  32.   2 message "\nMismatched closing delimiter" abort,
  33.   3 message "\nExtra closing delimiter" abort)
  34. ; bal1: checks from point through the end until
  35. ; 1. it finds an error (unclosed or mismatch closing delimiter),
  36. ; 2. it reaches the end of the file or an extra closing delimiter
  37. ; and then it stops.
  38. bal1: while (nextdelim isopendelim)
  39.   {set themark (current closer           ; get the current delimiter's match
  40.         ($ c bal1 $)                     ; store it
  41.         = current ? ($ c set themark )   ; if it matches, go to next
  42.             : (if isend {                ; otherwise
  43.                 1->i                     ; if it's the end, 
  44.                    }                     ; tell ballerr ok 
  45.                 else {                   ; else
  46.                 2->i                     ; tell ballerr mismatch 
  47.                      } 
  48.                (swap themark $)          ; go back to error
  49.                balerr)                   ; and bail out
  50.         )
  51.   }
  52. ; balance: the macro to be executed by the user.
  53. balance:  message "checking..>>"
  54.   balinit 
  55.   mark ( bal1
  56.      if !isend (3->i balerr)
  57.    )
  58.    balterm
  59.    message "\nno errors to end."
  60.