home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / wp / bmacs.zip / SYMCHG.M < prev    next >
Text File  |  1986-05-01  |  3KB  |  101 lines

  1. ;****************************************************************************
  2. ;**        symchg.m:
  3. ;**            change to new symbols
  4. ;**            4/30/86, T. Revay
  5. ;**
  6. ;**        This macro reads symbols to be changed from a file, "symchg.txt".
  7. ;**        The file format is a list of symbols; symbols on odd numbered lines
  8. ;**        (with the first line in the file as line no. 1) are translated into
  9. ;**        the symbols on the even numbered line below them, with a period on
  10. ;**        the last line of the file.  For example, if symchg.txt contains:
  11. ;**
  12. ;**        FIRSTSYM
  13. ;**        NEWFIRSTSYM
  14. ;**        SECONDSYM
  15. ;**        NEWSECONDSYM
  16. ;**        .
  17. ;**
  18. ;**        the translation would be:
  19. ;**        
  20. ;**        (translate FIRSTSYM NEWFIRSTSYM)
  21. ;**        (translate SECONDSYM NEWSECONDSYM)
  22. ;**
  23. ;**        The last line of symchg.txt MUST contain a period as the ONLY
  24. ;**        character on the line.  This is the terminating condition for the
  25. ;**        macro, so it's real important.
  26. ;**
  27. ;**        To use this macro, change the "symchg.txt" file to record the search
  28. ;**        and translate strings you want.  Then edit the file(s) you want the
  29. ;**        symbols changed in.  Press F10, type "symchg", and off you go.  Note
  30. ;**        that the "translate" command will prompt you for every change you
  31. ;**        make; this can be changed to produce a global change if you're
  32. ;**        very brave (remember to press Alt-F10 to recompile the macro if
  33. ;**        you've made any changes.
  34. ;**
  35. ;***************************************************************************
  36.  
  37. (macro symchg
  38.     (
  39.         (string searchpat
  40.                 reppat
  41.                 filename
  42.                 sjunk
  43.                 bufname
  44.         )
  45.         (int    line
  46.         )
  47.  
  48.         (pause_on_error)
  49.         (inq_names filename sjunk bufname)
  50.         (if (exist "symchg.txt")
  51.             (
  52.             (edit_file "symchg.txt")
  53.             (= line 1)
  54.             (goto_line line)
  55.             (beginning_of_line)
  56.             (sprintf searchpat "%s" (read))
  57.             )
  58.         ;else
  59.             (
  60.             (beep)
  61.             (message "The file 'symchg.txt' must exist!  Press a key...")
  62.             (keyboard_flush)
  63.             (while (== (read_char) -1) )
  64.             (sprintf searchpat ".\n")
  65.             )
  66.         )
  67.         (while (!= searchpat ".\n")
  68.             (
  69.             (sprintf searchpat "%s" (substr searchpat 1 (- (strlen searchpat) 1) ) )
  70.             (++ line)
  71.             (goto_line line)
  72.             (beginning_of_line)
  73.             (sprintf reppat "%s" (read))
  74.             (sprintf reppat "%s" (substr reppat 1 (- (strlen reppat) 1) ) )
  75.             (message "Searching for [%s] ..." searchpat)
  76.             (edit_file filename)
  77.             (top_of_buffer)
  78.  
  79. ;**    These two lines following are for debugging; you should redirect output
  80. ;** to your printer if you uncomment them.
  81. ;**            (printf "Line %d: changing [%s] " line searchpat )
  82. ;**            (printf " to [%s]\n" reppat)
  83.  
  84. ;** Here is the call to translate.  The commented one performs a global
  85. ;** traslation without prompting -- BE CAREFUL ABOUT USING IT!
  86.  
  87.             (translate searchpat reppat)            
  88. ;**            (translate searchpat reppat 1)
  89.  
  90.             (edit_file "symchg.txt")
  91.             (++ line)
  92.             (goto_line line)
  93.             (sprintf searchpat "%s" (read))
  94.             )
  95.         )
  96.         (message "Finished" )
  97.         (edit_file filename)
  98.     )
  99. )
  100.  
  101.