home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / e / epmmac2.zip / EPMLEX.E < prev    next >
Text File  |  1992-12-18  |  31KB  |  754 lines

  1. /*
  2. ╔════════════════════════════════════════════════════════════════════════════╗
  3. ║ What's it called: EPMLEX.E                                                 ║
  4. ║                                                                            ║
  5. ║ What does it do : Spell checking and Synonym support for the EPM editor.   ║
  6. ║                                                                            ║
  7. ║                   There are two major components to spell and synonym      ║
  8. ║                   checking in EPM.  The first and most important is the    ║
  9. ║                   actual word verification and word/dictionary lookup.     ║
  10. ║                   This is done by the internal EPM opcode, "lexam".        ║
  11. ║                   This opcode can take on the variations indicated by      ║
  12. ║                   the LXF constants defined below.                         ║
  13. ║                                                                            ║
  14. ║                   The second most important part to word checking is the   ║
  15. ║                   presentation of the results.  This is neatly done in     ║
  16. ║                   EPM using a PM list box.  E has an internal list dialog  ║
  17. ║                   accessible through the 'listbox' function.  See          ║
  18. ║                   STDCTRL.E for details on the 'listbox' function.         ║
  19. ║                                                                            ║
  20. ║ Who and When    : Larry Margolis, 11/91                                    ║
  21. ║ Updated from the original                                                  ║
  22. ║ EPMLEX.E done by: C.Maurer,  R.Yozzo,  Gennaro Cuomo, and Larry Margolis   ║
  23. ║                   1/89 - 10/90                                             ║
  24. ╚════════════════════════════════════════════════════════════════════════════╝
  25. */
  26. ; Customizing information:  Any of the following customizing constants can
  27. ; be overridden by including the appropriate definition after a CONST statement
  28. ; in your MYCNF.E.
  29. ;
  30. ; Example of customizing:  include the following lines in your MYCNF.E
  31. ; (with the ';' deleted from the beginning of each line).
  32. ;
  33. ;    const                               -- Customizations for EPMLEX:
  34. ;       RESPECT_case_for_addenda = 0     -- Ignore case of addenda words.
  35. ;       my_ADDENDA_FILENAME= 'd:\doc\margoli.adf'     -- I keep these in my
  36. ;       my_DICTIONARY_FILENAME= 'd:\doc\us.dct'       -- d:\doc directory.
  37. ; Can also have multiple dictionaries, separated by spaces - all will be loaded:
  38. ;       my_DICTIONARY_FILENAME= 'd:\doc\us.dct d:\doc\medical.dct d:\doc\legal.dct'
  39.  
  40. compile if not defined(SMALL)  -- If SMALL not defined, then being separately compiled
  41. include 'stdconst.e'
  42.  define INCLUDING_FILE = 'EPMLEX.E'
  43.    tryinclude 'MYCNF.E'        -- Include the user's configuration customizations.
  44.  compile if not defined(SITE_CONFIG)
  45.     const SITE_CONFIG = 'SITECNF.E'
  46.  compile endif
  47.  compile if SITE_CONFIG
  48.     tryinclude SITE_CONFIG
  49.  compile endif
  50. const
  51.  compile if not defined(SPELL_SUPPORT)  -- Must set here, since set to 0 in ENGLISH.E
  52.   compile if EVERSION >= 5
  53.  SPELL_SUPPORT = 'DYNALINK'          -- New default
  54.   compile else
  55.  SPELL_SUPPORT = 0
  56.   compile endif
  57.  compile endif
  58.  compile if not defined(NLS_LANGUAGE)
  59.   const NLS_LANGUAGE = 'ENGLISH'
  60.  compile endif
  61. include NLS_LANGUAGE'.e'
  62. compile endif
  63.  
  64. const
  65. compile if not defined(PROOF_DIALOG_FIXED)
  66.    PROOF_DIALOG_FIXED = 0               -- 1 if dialog should stay in one spot
  67. compile endif
  68.  
  69. compile if not defined(ADDENDASUPPORT)
  70.    ADDENDASUPPORT =  1                  -- 1 if addenda support
  71. compile endif
  72.  
  73. compile if ADDENDASUPPORT
  74.  compile if not defined(RESPECT_case_for_addenda)
  75. RESPECT_case_for_addenda     = 1        /* If addenda entries are to be     */
  76.  compile endif                          /* placed in the addenda without    */
  77.                                         /* modifying their case, then       */
  78.                                         /* this variable should be 1        */
  79.                                         /* Otherwise, it should be 0        */
  80. compile endif -- ADDENDASUPPORT
  81.  
  82.  
  83. const
  84. ; Functions
  85. compile if EVERSION >= 5.50     -- Use the new function numbers
  86. LXFINIT   = 0     /* Initialize                   */
  87. LXFTERM   = 1     /* Terminate                    */
  88. LXFGDIC   = 2     /* Pickup Dictionary            */
  89. LXFFDIC   = 3     /* Drop Dictionary              */
  90. LXFSETADD = 4     /* Set Addenda Language Type    */
  91. LXFAD2TRS = 5     /* Add to Transient Addenda     */
  92. LXFREDTRS = 6     /* Read from Transient Addenda  */
  93. LXFSAVTRS = 7     /* Save Transient Addenda       */
  94. LXFVERFY  = 8     /* Verification                 */
  95. LXFSPAID  = 9     /* Spelling Aid                 */
  96. LXFHYPH   =10     /* Hyphenation                  */
  97. LXFDHYPH  =11     /* Dehyphenation                */
  98. LXFSYN    =12     /* Synonym                      */
  99. LXFAMUGDIC=255    /* Addenda Pickup Dictionary    */
  100.          /* (Pseudo-op; calls LXFGDIC internally) */
  101. compile else                    -- The old way; uses strings
  102. LXFINIT   = 'I'    -- Initialize
  103. LXFTERM   = 'T'    -- Terminate
  104. LXFGDIC   = 'PI'   -- Pickup Dictionary
  105. LXFFDIC   = 'DR'   -- Drop Dictionary
  106. LXFAD2TRS = 'ADDI' -- Add(ition) to Transient Addenda
  107. LXFVERFY  = 'V'    -- Verification
  108. LXFSPAID  = 'SP'   -- Spelling Aid
  109. LXFSYN    = 'SY'   -- Synonym
  110. LXFAMUGDIC= 'ADDE' -- Addenda Pickup Dictionary
  111. compile endif
  112.  
  113. ; Return codes
  114. LXRFGOOD = 0000   /* Function Successful:  Good Return Code                */
  115. LXRFNFND = 0100   /* Function Unsuccessful: Word Not Found                 */
  116. LXRFDUPD = 0107   /* Function Unsuccessful: Duplicate Dictionary           */
  117. LXRFINIT = 0200   /* PC LEXAM Not Initialized: Control Block/Parameter Err */
  118. LXRFIFCN = 0201   /* Invalid Function                                      */
  119.  
  120. definit
  121.    universal  addenda_has_been_modified
  122.    universal  ADDENDA_FILENAME
  123.    universal  DICTIONARY_FILENAME
  124.    universal  Dictionary_loaded
  125.  
  126. ; Note:  don't initialize the universals here for EPM if SPELL_SUPPORT =
  127. ; 'DYNALINK'; it will be done in STDCNF so that this won't override the
  128. ; config info read from the .INI file.
  129. compile if EVERSION < 5 or SPELL_SUPPORT <> 'DYNALINK'
  130.  compile if defined(my_ADDENDA_FILENAME)
  131.    ADDENDA_FILENAME= my_ADDENDA_FILENAME
  132.  compile else
  133.    ADDENDA_FILENAME= 'c:\lexam\lexam.adl'
  134.  compile endif
  135.  
  136.  compile if defined(my_DICTIONARY_FILENAME)
  137.    DICTIONARY_FILENAME= my_DICTIONARY_FILENAME
  138.  compile else
  139.    DICTIONARY_FILENAME= 'c:\lexam\us.dct'
  140.  compile endif
  141. compile endif
  142.  
  143.    addenda_has_been_modified=0
  144.    Dictionary_loaded = 0
  145.  
  146. /*
  147. ╔════════════════════════════════════════════════════════════════════════════╗
  148. ║ Synonym Support                                                            ║
  149. ╚════════════════════════════════════════════════════════════════════════════╝
  150. */
  151. /*
  152. ┌────────────────────────────────────────────────────────────────────────────┐
  153. │ What's it called: syn                                                      │
  154. │                                                                            │
  155. │ What does it do : The syn command uses E's lexam support to retrieve       │
  156. │                   possible synonyms for a specified word.                  │
  157. │                   If synonyms are found a                                  │
  158. │                   PM list box is shown containing the possible new words.  │
  159. │                                                                            │
  160. └────────────────────────────────────────────────────────────────────────────┘
  161. */
  162. defc syn =
  163.    if load_lexam() then
  164.      return
  165.    endif
  166.    call pbegin_word()
  167.    call synonym()
  168.    call drop_dictionary()
  169.  
  170.  
  171. /*
  172. ┌────────────────────────────────────────────────────────────────────────────┐
  173. │ What's it called: synonym()                                                │
  174. │                                                                            │
  175. │ What does it do : checks the next word on a line for its possible synonyms.│
  176. │                   possible synonyms for a specified word.                  │
  177. │                   If synonyms are found a                                  │
  178. │                   PM list box is shown containing the possible new words.  │
  179. │                                                                            │
  180. └────────────────────────────────────────────────────────────────────────────┘
  181. */
  182. defproc synonym()
  183.    getline line                           /* get the current line          */
  184.    if line<>'' then                       /* if it is NOT blank            */
  185.       i=.col                              /* get the current column number */
  186.       l=pos(' ',line,.col)                /* get possible word             */
  187.       if l=0 then                         /* could this be a word???       */
  188.          l=length(line)+1
  189.          if l<i then l=i endif
  190.       endif
  191.       wrd=strip(substr(line,i,l-i))       /* extract word candidate        */
  192.       oldwordlen=length(wrd)              /* save the length of the word   */
  193.       result=lexam(LXFVERFY,wrd)          /* authenticate word using lexam */
  194.       if result and wrd<>'' then          /* was it a success???             */
  195.          call strippunct(wrd,l,i)
  196.         .col=.col+i-1
  197.          result = lexam(LXFVERFY,wrd)
  198.       endif
  199.       if(result <> LXRFGOOD) then         /* was it a success ???          */
  200.          sayerror NO_MATCH__MSG '<'wrd'>' /* NO                      */
  201.          return ''                        /* exit function                 */
  202.       endif
  203.       /* It's a word!!!     */
  204.                                           /* get list of synonyms using lex*/
  205.       parse value lexam(LXFSYN,wrd) with 2 '/' result
  206.       if result='' then
  207.          sayerror NO_SYN__MSG '<'wrd'>'
  208.          return ''
  209.       endif
  210.  
  211.       do forever
  212.          newword = listbox(SYNONYMS__MSG,'/'result,'/'REPLACE__MSG'/'CANCEL__MSG'/'HELP__MSG'/')
  213.          if newword<>3 then leave; endif
  214.          -- help was pressed
  215.          'helpmenu 14002'
  216.          return ''
  217.       enddo
  218.       if newword<>'' then
  219.          replaceline leftstr(line,.col-1)||newword||substr(line,l)
  220.          return length(newword)-oldwordlen
  221.       endif
  222.    endif
  223.  
  224. /*
  225. ╔════════════════════════════════════════════════════════════════════════════╗
  226. ║ Spell Checking Support                                                     ║
  227. ╚════════════════════════════════════════════════════════════════════════════╝
  228. */
  229.  
  230. /*
  231. ┌────────────────────────────────────────────────────────────────────────────┐
  232. │ What's it called: proof()                                                  │
  233. │                                                                            │
  234. │ What does it do : The proof command uses E's lexam support to spell check  │
  235. │                   either the next word or a given word.     If a misspelled│
  236. │                   word is encountered, a                                   │
  237. │                   PM list box is shown containing the possible corrections.│
  238. │                   syntax:   proof  [word]                                  │
  239. │                          - if 'word' is not specified, proof searchs for   │
  240. │                            the next word (after the cursor) and checks it. │
  241. └────────────────────────────────────────────────────────────────────────────┘
  242. */
  243. defc proof
  244.    universal ADDENDA_FILENAME
  245.    if load_lexam() then
  246.      return
  247.    endif
  248.    if arg(1)<>'' then
  249.       call proof1(arg(1))
  250.    else
  251.       call proof2()
  252.    endif
  253. compile if ADDENDASUPPORT
  254.    if addenda_filename<>'' then
  255.       call maybe_save_addenda()
  256.    endif
  257. compile endif
  258.    call drop_dictionary()
  259.    if arg(1)='' then
  260.       sayerror DONE__MSG
  261.    endif
  262.  
  263. /*
  264. ┌────────────────────────────────────────────────────────────────────────────┐
  265. │ What's it called: proof2()                                                 │
  266. │                                                                            │
  267. │ What does it do : Start at the current cursor position,  locate the next   │
  268. │                   word, and check the spelling of that word.   The spelling│
  269. │                   of each word is done by calling the lexam function.      │
  270. │                   The 'lexam' fuction is a internal                        │
  271. │                   opcode that uses the dynalink feature to access the      │
  272. │                   LEXAM.DLL                                                │
  273. │                                                                            │
  274. └────────────────────────────────────────────────────────────────────────────┘
  275. */
  276. defproc proof2
  277.  script_file_type=AMU_script_verification()
  278.  
  279.  --@@ If there's a line-marked area in the current file, proof only in there.
  280.  firstline=max(.line,1); lastline=.last; what = 'file'
  281.  if marktype() then  /* if no mark, default to entire file */
  282.     getfileid curfileid
  283.     getmark fl,ll,fc,lc,markfileid
  284.     if markfileid = curfileid then
  285.        firstline=fl; lastline=ll
  286.        what = 'marked area'
  287.     endif
  288.  endif
  289.  partial_lines = marktype()='BLOCK' | marktype()='CHAR'
  290.  
  291.  /* start checking at next word...*/
  292. ;getline line
  293. ;.col=1
  294. ;if leftstr(line,1)==' 'then
  295. ;   tabword
  296. ;endif
  297.  if partial_lines then .col=fc; else .col=1; endif
  298.  firstline
  299.  if substr(textline(firstline), .col, 1)=' ' then tabword; endif
  300.  
  301.  for zz= firstline to lastline --@@
  302.    zz                                 /* advance to next (new) line         */
  303.    getline line
  304.    sayerror 'Spell Checking 'what'...'
  305.  
  306.    loop
  307.  
  308.      if partial_lines then
  309.         if .col>lc & (zz=lastline | marktype()='BLOCK') then
  310.            if marktype()='BLOCK' then .col=fc; endif
  311.            leave
  312.         endif
  313.      endif
  314.      l=pos(' ',line,.col)                /* find first word                 */
  315.      if not l then                       /* no more words on this line...   */
  316.         l=length(line)+1                 /* or there is only one word on    */
  317.         if l<=.col then                  /* the line...                     */
  318.            if marktype()='BLOCK' then .col=fc; else .col=1; endif
  319.            leave
  320.         endif
  321.      endif
  322.      wrd=substr(line,.col,l-.col)        /* extract word from line          */
  323.  
  324.      result = lexam(LXFVERFY,wrd)        /* verify word using lexam         */
  325.      if result and wrd<>'' then          /* was it a success???             */
  326.                                          /* YES, ignore script tags         */
  327.         if script_file_type and
  328.               (pos(leftstr(wrd,1),':&.') or pos(substr(line,max(.col-1,1),1),':&')) then
  329.            result=0
  330.            if leftstr(wrd,1)=':' then
  331.               newl=pos('.',line,.col)
  332.               if newl then
  333.                  l=newl
  334.               endif
  335.            endif
  336.         else                           /* strip punctuation and try again */
  337.            call strippunct(wrd,l,i)
  338.           .col=.col+i-1
  339.            result = lexam(LXFVERFY,wrd)
  340.         endif
  341.      endif
  342.      if result and wrd<>'' then
  343.         result = lexam(LXFVERFY,wrd)
  344.         if result and wrd<>'' then
  345.            -- t=-3 means help was requested, so call spellword again.
  346.            t=-3
  347.            do while t=-3
  348. compile if ADDENDASUPPORT
  349.               t=spellword('/~Next/~Temp. Add')    -- spell check the word
  350. compile else
  351.               t=spellword('/~Next')               -- spell check the word
  352. compile endif
  353.            enddo
  354.            if t=0 then                         -- error occured
  355.               return 0
  356.            endif
  357.            if t>0 then
  358.               l=l + t - 100
  359.            endif
  360.            if t=-4 then     -- Edit was selected.
  361.               l=-1          -- so .col won't change; recheck from current point
  362.            endif
  363.            getline line
  364.         endif
  365.      endif
  366.      .col=l+1
  367.    endloop
  368.  endfor
  369.  
  370. compile if PROOF_DIALOG_FIXED
  371.    define DIALOG_POSN = ', -2, .windowwidth'
  372. compile else
  373.    define DIALOG_POSN = ' '
  374. compile endif
  375. /*
  376. ┌────────────────────────────────────────────────────────────────────────────┐
  377. │ What's it called: spellword()                                              │
  378. │                                                                            │
  379. │ What does it do : Check the word at the cursor position, removing          │
  380. │                   punctuation characters.  It is assumed that the cursor   │
  381. │                   is positioned at the beginning of the word.  (Used by    │
  382. │                   proof2 and proofword.)  If it's a valid word then check  │
  383. │                   the spelling of the word using the lexam opcode.  If a   │
  384. │                   valid result is returned place it in a PM list box using │
  385. │                   the 'listbox' procedure.  Returns the length of the word │
  386. │                   found.  The optional argument is a string containing a   │
  387. │                   button name.  E.g., '/Next'                              │
  388. └────────────────────────────────────────────────────────────────────────────┘
  389. */
  390. defproc spellword
  391.    getline line                              /* ignore script tags           */
  392.    if line<>'' then                          /* if the line is not empty...  */
  393.       i=.col                                 /* save the cursor column       */
  394.       l=pos(' ',line,.col)                   /* get next word after cursor   */
  395.       if l=0 then                            /* is it a word???              */
  396.          l=length(line)+1
  397.          if l<i then l=i endif
  398.       endif
  399.       wrd=strip(substr(line,i,l-i))          /* extract word from line       */
  400.       result = lexam(LXFVERFY,wrd)           /* verify word                  */
  401.       if result and wrd<>'' then             /* was it a success             */
  402.          call strippunct(wrd,l,i)            /* strip punctuation/ try again */
  403.          .col=.col+i-1                       /* move to next column          */
  404.          result = lexam(LXFVERFY,wrd)        /* try word  verification again */
  405.       endif
  406.       if result and wrd<>'' then             /* was it a success             */
  407.          oldwordlen=length(wrd)              /* yes it's a word.....         */
  408.                                              /* use lexam to spell check word*/
  409.          refresh
  410.          parse value lexam(LXFSPAID,wrd) with 2 '/' result
  411.          if rc>=LXRFINIT then
  412.             sayerror LOOKUP_FAILED__MSG '<' wrd '>'
  413.             return -1  -- next word
  414.          else
  415.             if result='' then
  416.                result='*Nothing Found*'
  417.             endif
  418.             oldcol = .col; .col = .col + oldwordlen; .col = oldcol;
  419. compile if EVERSION < '5.50'
  420.             refresh
  421.             sayat wrd, .cursory, .cursorx,
  422.                   .textcolor%16+(.textcolor // 16)*16, oldwordlen
  423. compile else
  424.             circleit 2, .line, .col, .col+oldwordlen-1, 1 -- color irrelevant now
  425.             refresh  -- Refresh required to display circle
  426. compile endif
  427. compile if ADDENDASUPPORT
  428.             newword=listbox(PROOF__MSG '<'wrd'>', '/'result,
  429.                             '/'REPLACE__MSG'/'CANCEL__MSG||arg(1)'/'ADD__MSG'/'EDIT__MSG'.../'HELP__MSG $DIALOG_POSN)   -- put result in PM list box
  430.             if arg(1)='' then
  431.                butlist='7 7 3 4 5'  -- Next; Temp. Add; Add; Edit; Help
  432.             else
  433.                butlist='3 4 5 6 7'  -- Next; Temp. Add; Add; Edit; Help
  434.             endif
  435. compile else
  436.             newword=listbox(PROOF__MSG '<'wrd'>','/'result,'/'REPLACE__MSG'/'CANCEL__MSG ||arg(1)'/'EDIT__MSG'.../'HELP__MSG $DIALOG_POSN)  -- put result in PM list box
  437.             if arg(1)='' then
  438.                butlist='7 7 7 3 4'  -- Next; Temp. Add; Add; Edit; Help
  439.             else
  440.                butlist='3 7 7 4 5'  -- Next; Temp. Add; Add; Edit; Help
  441.             endif
  442. compile endif
  443.             parse value butlist with but_next but_temp_add but_add but_edit but_help
  444.             if newword=but_help then
  445.                'helpmenu 14000'
  446.                return -3     -- do line over again
  447.             endif
  448.             if newword=but_edit then
  449.                newword=entrybox(REPLACEMENT__MSG '<'wrd'>','/'REPLACE__MSG'/'CANCEL__MSG,wrd)
  450.                if newword='' then
  451.                   return -1  -- next word
  452.                endif
  453.                replaceline leftstr(line,.col-1)||newword||substr(line,l)
  454.                refresh
  455. ;;             return -100 - (length(newword)-oldwordlen)    -- Don't care about new len.
  456.                return -4    -- re-check line
  457.             endif
  458.             if newword='*Nothing Found*' then
  459.                return -1
  460.             endif
  461. compile if EVERSION < '5.50'
  462.             sayat wrd, .cursory, .cursorx, .textcolor, oldwordlen
  463. compile else
  464. ;           refresh  -- maybe can leave out...
  465. compile endif
  466.             if newword=but_next then   -- goto next word
  467.                return -1
  468.             endif
  469. compile if ADDENDASUPPORT
  470.             if newword=but_temp_add then   -- temporary addenda (just for this PROOF session)
  471.  compile if RESPECT_CASE_FOR_ADDENDA
  472.                call lexam(LXFAD2TRS, wrd)
  473.  compile else
  474.                call lexam(LXFAD2TRS,lowcase(wrd))
  475.  compile endif
  476.                return -1
  477.             endif
  478.             if newword=but_add then   -- addenda
  479.                call AMU_addenda_addition_processing(wrd)
  480.                return -1
  481.             endif
  482. compile endif
  483.             if newword<>'' then              /* was it a valid result ???    */
  484.                                              /* replace word in line         */
  485.                replaceline leftstr(line,.col-1)||newword||substr(line,l)
  486. compile if EVERSION < 5.50
  487.                refresh
  488. compile endif
  489.                return 100 + length(newword)-oldwordlen
  490. ;              return -1
  491.             endif
  492.           endif
  493.       else
  494.          --.messageline='word is spelled correctly'
  495.          return -2
  496.       endif
  497.    endif
  498.    return 0
  499.  
  500. /*
  501. ┌────────────────────────────────────────────────────────────────────────────┐
  502. │ What's it called: proof1()                                                 │
  503. │                                                                            │
  504. │ What does it do : Takes a word argument and looks it up in the lexam       │
  505. │                   dictionary using the 'lexam' opcode.                     │
  506. │                   If the word is found a list box is presented with the    │
  507. │                   possible correct word choices.                           │
  508. └────────────────────────────────────────────────────────────────────────────┘
  509. */
  510. defproc proof1( wrd )
  511.    result = lexam(LXFVERFY,wrd)            /* first off, is it a word?    */
  512.    if result then                          /* well is it???               */
  513.       result = lexam(LXFSPAID,wrd)         /* YES, now check it with lexam*/
  514.  
  515.       parse value result with .'/' result  /* remove first word           */
  516.       if rc>=LXRFINIT then
  517.          sayerror LOOKUP_FAILED__MSG '<' wrd '>'
  518.       else
  519.          if result='' then
  520.             result='*Nothing Found*'
  521.          endif
  522.          do forever
  523. compile if ADDENDASUPPORT
  524.             newword=listbox(PROOF_WORD__MSG,'/'result,'/'REPLACE__MSG'/'EXIT__MSG'/'ADD__MSG'/'HELP__MSG)     /* put result in PM list box   */
  525.             if newword='3' then   --  addenda
  526.                call AMU_addenda_addition_processing(wrd)
  527.                return -1
  528.             endif
  529.             if newword<>4 then leave; endif
  530. compile else
  531.             newword=listbox(PROOF_WORD__MSG,'/'strip(result),'/'REPLACE__MSG'/'EXIT__MSG'/'HELP__MSG)     /* put result in PM list box   */
  532.             if newword<>3 then leave; endif
  533. compile endif
  534.             'helpmenu 14001'
  535.          enddo
  536.          if newword='*Nothing Found*' then
  537.             return
  538.          endif
  539.          return newword
  540.       endif
  541.    endif
  542.  
  543. /*
  544. ╔════════════════════════════════════════════════════════════════════════════╗
  545. ║ Addenda Support                                                            ║
  546. ╚════════════════════════════════════════════════════════════════════════════╝
  547. */
  548. compile if ADDENDASUPPORT
  549. /*
  550. ┌────────────────────────────────────────────────────────────────────────────┐
  551. │ What's it called: maybe_save_addenda                                       │
  552. │                                                                            │
  553. │ What does it do :                                                          │
  554. │                                                                            │
  555. └────────────────────────────────────────────────────────────────────────────┘
  556. */
  557. ; Addenda support commands
  558.  
  559. defproc maybe_save_addenda
  560.    universal  addenda_has_been_modified
  561.    universal  AMU_addenda_file_identification
  562.    universal  ADDENDA_FILENAME
  563.  
  564. ;   if addenda_has_been_modified then
  565.      -- sayatbox 'saving addenda 'ADDENDA_FILENAME
  566.       if AMU_addenda_file_identification<>''  then
  567.        getfileid AMU_current_file_identification
  568.        rc = 0
  569.        activatefile AMU_addenda_file_identification
  570.        if not rc then
  571.           if .modify then 'xcom save'; endif
  572. ;;        'xcom quit'
  573.        endif
  574.        -- sayerror 'addenda file filed'
  575.        activatefile AMU_current_file_identification
  576.       endif
  577.       addenda_has_been_modified=0
  578.       -- sayerror 0
  579. ;  endif
  580.  
  581. ;defc AMU_addenda_pickup
  582. ;   universal  ADDENDA_FILENAME
  583. ;   call lexam(LXFAMUGDIC,ADDENDA_FILENAME)
  584.  
  585. ;defc AMU_addenda_addition
  586. ;   call lexam(LXFAD2TRS,arg(1))
  587.  
  588. defproc AMU_addenda_processing
  589.    universal AMU_addenda_file_identification
  590.    universal  ADDENDA_FILENAME
  591.    getfileid AMU_current_file_identification
  592.    'xcom e' ADDENDA_FILENAME
  593.    -- sayerror 'addenda file loaded'
  594.    if not rc or rc = sayerror('New file') then
  595.       getfileid AMU_addenda_file_identification
  596.    else
  597.       AMU_addenda_file_identification =''
  598.       sayerror BAD_ADDENDA__MSG ADDENDA_FILENAME 'rc=' rc
  599.       stop
  600.    endif
  601.    .visible=0 -- hidden file
  602.    activatefile AMU_current_file_identification
  603.    if AMU_addenda_file_identification <>'' then
  604.       for i = 1 to AMU_addenda_file_identification.last
  605.          getline line,i,AMU_addenda_file_identification
  606.          if upcase(leftstr(line, 8))='.DU ADD ' then
  607.             line=substr(line,9)
  608.          endif
  609.          do while line <> ''
  610.             parse value line with wrd line
  611.  compile if RESPECT_CASE_FOR_ADDENDA
  612.             call lexam(LXFAD2TRS,wrd)
  613.  compile else
  614.             call lexam(LXFAD2TRS,lowcase(wrd))
  615.  compile endif
  616.          enddo
  617.       endfor
  618.    endif
  619.  
  620. defproc AMU_addenda_addition_processing(AMU_addenda_entry)
  621.    universal  addenda_has_been_modified
  622.    universal AMU_addenda_file_identification, ADDENDA_FILENAME
  623.    addenda_has_been_modified=1
  624.  compile if not RESPECT_CASE_FOR_ADDENDA
  625.    AMU_addenda_entry=lowcase(AMU_addenda_entry)
  626.  compile endif
  627.    call lexam(LXFAD2TRS,AMU_addenda_entry)
  628.    if ADDENDA_FILENAME<>'' & AMU_addenda_file_identification<>'' then
  629.       insertline AMU_addenda_entry,AMU_addenda_file_identification.last+1,AMU_addenda_file_identification
  630.    endif
  631.  
  632.  
  633. compile endif -- ADDENDASUPPORT
  634.  
  635. ; The following is a script file type verification algorithm
  636. ; suggested by Larry Margolis. (Thanks, Larry)
  637. defproc AMU_script_verification()
  638.    ext=filetype()
  639. compile if defined(my_SCRIPT_FILE_TYPE)
  640.    return ext='SCR' or ext='SCT' or ext='SCRIPT' or ext='IPF' or ext=my_SCRIPT_FILE_TYPE
  641. compile else
  642.    return ext='SCR' or ext='SCT' or ext='SCRIPT' or ext='IPF'
  643. compile endif
  644.  
  645.  
  646. /*
  647. ╔════════════════════════════════════════════════════════════════════════════╗
  648. ║ General Lexam Support                                                      ║
  649. ╚════════════════════════════════════════════════════════════════════════════╝
  650. */
  651. defproc load_lexam
  652.    universal DICTIONARY_FILENAME
  653.    universal ADDENDA_FILENAME
  654.    universal Dictionary_loaded
  655.    result = lexam(LXFINIT)
  656.    if result<>LXRFGOOD and result<>LXRFIFCN  then
  657.       if result='febe' then  -- x'febe' = -322 = sayerror('Dynalink: unrecognized library name')
  658.          sayerror sayerrortext(-322) LEXAM_DLL'.DLL'
  659.          return 1
  660.       endif
  661.       sayerror INIT_ERROR__MSG
  662.    endif
  663.    dictlist=DICTIONARY_FILENAME
  664.    do while dictlist <> ''
  665.       parse value dictlist with dictionary dictlist
  666.       result=lexam(LXFGDIC, dictionary)
  667.       if result>=LXRFNFND & result<>LXRFDUPD then  -- Duplicate Dictionary; didn't unload?
  668.          if exist(dictionary) then
  669.             sayerror BAD_DICT__MSG '"'dictionary'";' ERROR__MSG result
  670.          else
  671.             sayerror NO_DICT__MSG '"'dictionary'"'
  672.          endif
  673.          return 1
  674.       endif
  675.    enddo
  676.    Dictionary_loaded = 1
  677. compile if ADDENDASUPPORT
  678.    if ADDENDA_FILENAME<>'' then
  679.       call lexam(LXFAMUGDIC,ADDENDA_FILENAME)
  680.       call AMU_addenda_processing()
  681.    endif
  682. compile endif
  683.    return 0
  684.  
  685. defproc drop_dictionary
  686.    universal DICTIONARY_FILENAME
  687.    universal  ADDENDA_FILENAME
  688.    universal  Dictionary_loaded
  689.    dictlist=DICTIONARY_FILENAME
  690.    do while dictlist <> ''
  691.       parse value dictlist with dictionary dictlist
  692.       call lexam(LXFFDIC, dictionary);
  693.    enddo
  694. compile if ADDENDASUPPORT
  695.    if ADDENDA_FILENAME<>'' then
  696.       call lexam(LXFFDIC,ADDENDA_FILENAME);
  697.    endif
  698. compile endif
  699.    call lexam(LXFTERM)
  700.    Dictionary_loaded = 0
  701.  
  702. defproc strippunct(var wrd,var l,var i)
  703.    -- Make this a variable, not a constant. to save space.
  704.    punctuation ='~!@#$¢£¥%^&*()_+|`1234567890-=\{}[]:";''<>?,./¬─═╔╗╚╝┌┐└┘║╦╠╣╩╬┬├┤┴┼│'
  705.    /* strip leading and trailing punctuation and try again*/
  706.    i=verify(wrd,punctuation)
  707.    if i then
  708.       l=l-length(wrd)
  709.       wrd=substr(wrd,i)
  710.       j=verify(wrd,punctuation,'m')
  711.       if j then
  712.          wrd=leftstr(wrd,j-1)
  713.       else
  714.          j=length(wrd)+1
  715.       endif
  716.       l=l+j+i-2
  717.    else
  718.       i=length(wrd)+1
  719.    endif
  720.  
  721. defc proofword,verify
  722.    universal ADDENDA_FILENAME
  723.    if load_lexam() then
  724.      return
  725.    endif
  726.    call pbegin_word()
  727.    spellrc = spellword('')
  728. compile if ADDENDASUPPORT
  729.    if addenda_filename<>'' then
  730.       call maybe_save_addenda()
  731.    endif
  732. compile endif
  733.    call drop_dictionary()
  734.    if -2 = spellrc then
  735.       sayerror SPELLED_OK__MSG
  736.    endif
  737.  
  738. defc dict
  739.    universal DICTIONARY_FILENAME
  740.    dictlist = arg(1)
  741.    if dictlist='' then
  742.       sayerror DICTLIST_IS__MSG DICTIONARY_FILENAME
  743.       return
  744.    endif
  745.    do while dictlist <> ''
  746.       parse value dictlist with dictionary dictlist
  747.       if not exist(dictionary) then
  748.          sayerror FILE_NOT_FOUND__MSG '"'dictionary'"; 'DICT_REMAINS__MSG DICTIONARY_FILENAME
  749.          return
  750.       endif
  751.    enddo
  752.    DICTIONARY_FILENAME = arg(1)
  753.  
  754.