home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / ispell.lha / spell-region.mg < prev    next >
Text File  |  1991-01-20  |  2KB  |  95 lines

  1. /*
  2.  * Use the ispell ARexx port to check the spelling of every word in the region.
  3.  * Same interface as spell-word.
  4.  */
  5.  
  6. options results
  7. options failat 1
  8.  
  9. bufname = "*speller*"
  10. tmpfile = 'ram:'address()'-speller'
  11.  
  12. if ~show(ports, 'IRexxSpell') then address command 'run ispell -r >nil:'
  13.  
  14. /* Clean out the test buffer, and copy the region to it, and save it */
  15. 'switch-to-buffer "'bufname'"'
  16. 'beginning-of-buffer'
  17. 'end-of-buffer'
  18. 'kill-region'
  19. 'switch-to-buffer ""'    /* Null string -> goes to previous buffer */
  20. 'copy-region-as-kill'    /* Paranoid - we'll not delete it till we're done */
  21. 'switch-to-buffer "'bufname'"'
  22. 'yank'
  23. 'write-file' tmpfile
  24.  
  25. /* Go check the tmp file, then delete it */
  26. address command 'waitforport IRexxSpell'
  27. address 'IRexxSpell' 'filecheck' tmpfile
  28. errorfile = result
  29. address command 'delete quiet' tmpfile
  30. if ~open(errors, errorfile, 'Read') then do
  31.     'rexx-display "Can''t open error file"'
  32.     exit
  33.     end
  34.  
  35. /* Get the buffer name after the write */
  36. 'rexx-buffer' buffer
  37. if buffer.0 < 1 then do
  38.     'rexx-display "Can''t get buffer information"'
  39.     exit
  40.     end
  41. bufname = buffer.1
  42.  
  43. badword = readln(errors)
  44. if wordlist = "" then do
  45.     'rexx-display "No errors found"'
  46.     exit
  47.     end
  48.  
  49. /* Loop over bad words, fixing them if needed */
  50. do while ~eof(errors)
  51.     address 'IRexxSpell' 'check' badword
  52.     parse var result '&' wordlist
  53.     replace = getreplace("`"badword"' not recognized; replacement: ")
  54.     if replace = "" then iterate
  55.     if replace = "?" then do
  56.         if wordlist = "" then iterate
  57.         replace = getreplace(wordlist': ')
  58.         if replace = "" then iterate
  59.         if datatype(replace, 'Numeric') then
  60.             replace = word(wordlist, result)
  61.         end
  62.  
  63.     /* Got a replacement, put it in everywhere (probably a bad idea) */
  64.     'beginning-of-buffer'
  65.     'search-forward "'badword'"'
  66.     do while rc = 0
  67.         'backward-kill-word'
  68.         'rexx-insert "'replace'"'
  69.         'search-forward "'badword'"'
  70.         end
  71.     badword = readln(errors)
  72.     end
  73.  
  74. call close errors
  75. address command 'delete quiet' errorfile
  76.  
  77. /* Ok, put the new text back in place... */
  78. 'switch-to-buffer ""'
  79. 'kill-region'
  80. 'insert-buffer "'bufname'"'
  81. 'kill-buffer "'bufname'"'
  82. exit
  83.  
  84. getreplace: procedure expose errorfile
  85.     parse arg line
  86.  
  87.     options failat 3
  88.     'rexx-request "'line'"'
  89.     if rc > 1 then do
  90.         address command 'delete quiet' errorfile
  91.         exit
  92.         end
  93.     if rc > 0 then return ""
  94.     return result
  95.