home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / e_macros / eos2lex.e < prev    next >
Encoding:
Text File  |  1993-03-11  |  27.2 KB  |  744 lines

  1. ; Customization information:  Any of the following customization constants can
  2. ; be overridden by including the appropriate definition after a CONST statement
  3. ; in your MYCNF.E.  The addenda filename and dictionary filename were formerly
  4. ; overridden by a file EOS2LCUS.E.  We no longer support that.
  5. ;
  6. ; Example of customization:  include the following lines in your MYCNF.E
  7. ; (with the ';' deleted from the beginning of each line).
  8. ;
  9. ;    const                               -- Customizations for EOS2LEX:
  10. ;       ALTERNATIVE_approach = 1         -- Don't automatically display list.
  11. ;       my_ADDENDA_FILENAME= 'c:\doc\margoli.adf'     -- I keep these in my
  12. ;       my_DICTIONARY_FILENAME= 'c:\doc\us.dct'       -- c:\doc directory.
  13. ;
  14. ; Can load more than one dictionary:
  15. ;       my_DICTIONARY_FILENAME= 'c:\doc\us.dct c:\doc\legal.dct c:\doc\medical.dct'
  16.  
  17.  
  18. compile if not defined(SMALL)  -- If SMALL not defined, then being separately
  19.    include    'COLORS.E'       -- compiled, so we must include COLORS.E, and
  20.  define INCLUDING_FILE = 'EOS2LEX.E'
  21.    tryinclude 'MYCNF.E'        -- the user's configuration customizations.
  22.  compile if not defined(SITE_CONFIG)
  23.     const SITE_CONFIG = 'SITECNF.E'
  24.  compile endif
  25.  compile if SITE_CONFIG
  26.     tryinclude SITE_CONFIG
  27.  compile endif
  28.  compile if not defined(NLS_LANGUAGE)
  29.    const NLS_LANGUAGE = 'ENGLISH'
  30.  compile endif
  31. include NLS_LANGUAGE'.e'
  32. compile endif
  33.  
  34. const
  35. compile if not defined(DISPLAY_box)
  36. DISPLAY_box                  = 1        /* If the synonym entries should be */
  37. compile endif                           /* displayed in a box this variable */
  38.                                         /* should be 1 Otherwise, we will   */
  39.                                         /* use sayat to display the         */
  40.                                         /* synonyms.                        */
  41.  
  42. compile if not defined(RESPECT_case_for_addenda)
  43. RESPECT_case_for_addenda     = 0        /* If addenda entries are to be     */
  44. compile endif                           /* placed in the addenda without    */
  45.                                         /* modifying their case, then       */
  46.                                         /* this variable should be 1        */
  47.                                         /* Otherwise, it should be 0        */
  48.  
  49. compile if not defined(SCREEN_MOVEMENT_minimization)
  50. SCREEN_MOVEMENT_minimization = 1        /* To avoid a lot of screen         */
  51. compile endif                           /* movement during spell checking   */
  52.                                         /* set this constant to 1.          */
  53.                                         /* If screen movement during spell  */
  54.                                         /* checking is desired then clear   */
  55.                                         /* this constant to 0.              */
  56.  
  57. compile if not defined(ALTERNATIVE_approach)
  58. ALTERNATIVE_approach = 0                /* Setting this constant to 1       */
  59. compile endif                           /* allows one to bypass the         */
  60.                                         /* list of alternatives.            */
  61.                                         /* The errant word is highlighted   */
  62.                                         /* and we would press               */
  63.                                         /* Esc   - to bypass the list       */
  64.                                         /* Space - to display the list      */
  65.                                         /* When this is 0 the list is       */
  66.                                         /* automatically displayed.         */
  67.  
  68.  
  69. ;  EOS2LEX.E                                    by Ralph Yozzo.
  70. ;       Return Code information for documentation purposes
  71. ;                 /* Function Successful */
  72. ;       LXRFGOOD = 0000 , /* Good Return Code                               */
  73. ;       LXRFCORR = 0001 , /* Input Word to Spell Aid Correctly Spelled      */
  74. ;       LXRFAIDS = 0002 , /* Aid was for Base Form of Word                  */
  75. ;       LXRFHDCS = 0003 , /* Hyphenation/Dehyphenation Changed Spelling     */
  76. ;       LXRFPBFL = 0004 , /* Passback Full                                  */
  77. ;       LXRFUPDC = 0005 , /* Updateable Dictionary Created                  */
  78. ;       LXRFBASE = 0006 , /* Word has Multiple Bases                        */
  79. ;
  80. ;                 /* Function Unsuccessful */
  81. ;
  82. ;       LXRFNFND = 0100 , /* Word Not Found                                 */
  83. ;       LXRFNDAT = 0101 , /* No Data Available                              */
  84. ;       LXRFNAID = 0102 , /* No Aid Available                               */
  85. ;       LXRFIWCN = 0103 , /* Invalid Word Construction                      */
  86. ;       LXRFTMDC = 0104 , /* Too Many Dictionaries Open                     */
  87. ;       LXRFNUDC = 0105 , /* Dictionary is Not Updateable                   */
  88. ;       LXRFUDCF = 0106 , /* Updateable Dictionary Full                     */
  89. ;       LXRFDDUP = 0107 , /* Duplicate Dictionary                           */
  90. ;       LXRFDNAM = 0108 , /* Invalid Dictionary Name                        */
  91. ;       LXRFIDCT = 0109 , /* Bad Dictionary                                 */
  92. ;
  93. ;               /* Control Block or Parameter Error */
  94. ;
  95. ;       LXRFINIT = 0200 , /* PC LEXAM Not Initialized                       */
  96. ;       LXRFIFCN = 0201 , /* Invalid Function                               */
  97. ;       LXRFITOK = 0202 , /* Invalid Token in Dictionary List               */
  98. ;       LXRFIWRD = 0203 , /* Invalid Word                                   */
  99. ;       LXRFIFLG = 0204 , /* Illegal Input Flag Combination                 */
  100. ;       LXRFPARM = 0205 , /* Missing or Illegal Value in Parameter Area     */
  101. ;       LXRFPTSM = 0206 , /* Passback Too Small                             */
  102. ;       LXRFNFNM = 0207 , /* Filename Not Allowed for Updateable Dictionary */
  103. ;       LXRFNDCT = 0208 , /* Illegal Number of Dictionaries                 */
  104. ;       LXRFBUSY = 0209 , /* PC LEXAM Busy                                  */
  105. ;
  106. ;                 /* System Error */
  107. ;
  108. ;       LXRFMERR = 0400 , /* Memory Allocation Error                        */
  109. ;       LXRFNFIL = 0401 , /* File Not Found                                 */
  110. ;       LXRFNPTH = 0402 , /* Path Not Found                                 */
  111. ;       LXRFFOPN = 0403 , /* File Open Failed                               */
  112. ;       LXRFFACC = 0404 , /* File Access Denied                             */
  113. ;       LXRFFSHR = 0405 , /* File Sharing Violation                         */
  114. ;       LXRFFGEN = 0406   /* General File I/O Error                         */
  115.  
  116. const
  117.                   /* Function Successful */
  118.         LXRFGOOD = 0000   /* Good Return Code                               */
  119.  
  120.                   /* Function Unsuccessful */
  121.         LXRFNFND = 0100   /* Word Not Found                                 */
  122.  
  123.                 /* Control Block or Parameter Error */
  124.         LXRFINIT = 0200   /* PC LEXAM Not Initialized                       */
  125.         LXRFIFCN = 0201   /* Invalid Function                               */
  126.  
  127. CONST
  128.    NOTFOUND='## Not found'
  129.  
  130.  
  131. definit
  132.    universal  addenda_has_been_modified
  133.    universal  flexam_initialized
  134.    universal  flexam_is_in_a_bad_state
  135.    universal  list_bak_color,list_bar_color
  136.    universal  ADDENDA_FILENAME
  137.    universal  DICTIONARY_FILENAME
  138.  
  139.    if flexam_initialized /== '' then return; endif
  140. compile if defined(my_ADDENDA_FILENAME)
  141.    ADDENDA_FILENAME= my_ADDENDA_FILENAME
  142. compile else
  143.    ADDENDA_FILENAME= 'c:\lexam\lexam.adl'
  144. compile endif
  145. compile if defined(my_DICTIONARY_FILENAME)
  146.    DICTIONARY_FILENAME= my_DICTIONARY_FILENAME
  147. compile else
  148.    DICTIONARY_FILENAME= 'c:\lexam\us.dct'
  149. compile endif
  150.    addenda_has_been_modified=0
  151.    flexam_initialized=0
  152.    flexam_is_in_a_bad_state=0
  153.    list_bar_color = BLACK+CYANB
  154.    list_bak_color = CYAN +BLACKB
  155.  
  156. /* spell word at cursor position */
  157. def a_f9=
  158.    call load_lexam()
  159.    call rypbegin_word()
  160.    call spellword(1) -- jbl:  one word only
  161.    call may_be_save_addenda()
  162.  
  163. /* start spell checking at beginning of current line */
  164. defc proof
  165.    oldstate = command_state()
  166.    call load_lexam()
  167.    call proof2()
  168.    call may_be_save_addenda()
  169.    if oldstate then cursor_command endif
  170.  
  171.  
  172.  
  173.  
  174. /*  Check the word at the cursor position removing punction characters. */
  175. /*  It is assumed that the cursor is positioned at the beginning of the */
  176. /*  word */
  177. defproc spellword(one_word_only)
  178.    universal list_bar_color
  179.    getline line
  180.    if line<>'' then
  181.       i=.col
  182.       l=pos(' ',line,.col)
  183.       if l=0 then
  184.          l=length(line)+1
  185.          if l<i then l=i endif
  186.       endif
  187.       wrd=strip(substr(line,i,l-i))
  188.       result = lexam('Verification',wrd)
  189. ;     call messageNwait('LEXAM: Verification result<'result'>') /* rey */
  190.       if result and wrd<>'' then
  191.          call strippunct(wrd,l,i)      /* strip punctuation and try again */
  192. ;        call messageNwait('spellword: i='i)
  193.          .col=.col+i-1
  194.          result = lexam('Verification',wrd)
  195. ;        call messageNwait('LEXAM: Verification result<'result'>') /* rey */
  196.       endif
  197.       if result and wrd<>'' then
  198.          oldwordlen=length(wrd)
  199. ;        call messageNwait('y' .cursory 'x' .cursorx        'length(wrd) 'length(wrd) )
  200.          parse value lexam('SPelling Aid',wrd) with . result /* rey */
  201.          if rc>=LXRFINIT then
  202. ;            messageNwait('LEXAM: SPelling Aid error rc:'rc) /* rey */
  203.          else
  204. COMPILE IF ALTERNATIVE_approach = 1
  205.             -- jbl tg:  if checking one word only, give the list straight away.
  206.             if not one_word_only then
  207.                refresh /* ALTERNATIVE approach */
  208.                sayat '', .cursory, .cursorx, list_bar_color,length(wrd) /* ALTERNATIVE approach */
  209.                -- jbl tg:  Change the prompt when you're ready for the user to
  210.                -- do something so he'll know when the chg is done.
  211.                sayerror EOS2LEX_PROMPT1__MSG
  212.                k=getkey()
  213.                if k=esc then
  214.                   return 0
  215.                elseif k=F10 or k=F3 then
  216.                   return ''
  217.                endif
  218.             endif
  219. COMPILE ENDIF
  220.             newword=liststring(result,wrd)
  221.             if newword=10 then
  222.                return('')
  223.             endif
  224.             if substr(newword,1,length(NO_MATCH__MSG))=NO_MATCH__MSG then
  225.                return('')
  226.             endif
  227.             if newword<>'' then
  228. ;              messageNwait('newword='newword' line=<'line'> l='l)
  229.                replaceline substr(line,1,.col-1)||newword||substr(line,l)
  230.                return(length(newword)-oldwordlen)
  231.             endif
  232.          endif
  233.       else
  234.          -- jbl tg:  "correctly" message is useful only if checking one word.
  235.          if one_word_only then
  236.             sayerror SPELLED_OK__MSG
  237.          endif
  238.       endif
  239.    endif
  240.    return(0)
  241.  
  242. defproc liststring(string,spellword)
  243.    universal  addenda_has_been_modified
  244.    universal  list_bak_color,list_bar_color
  245.  
  246.    cursordata
  247.    getfileid fileid
  248.    newwindow 'e /w /n';deleteline
  249.    sayerror 1  /* get rid of new file message */
  250.    longestwidth=0
  251.    if string<>NOTFOUND and string<>'' then
  252.       while string<>'' do
  253.          parse value string with wrd string
  254.          if length(wrd)>longestwidth then longestwidth=length(wrd) endif
  255.          insertline LEXICAL_ESCAPE_embedded_control(wrd),.last+1
  256.       endwhile
  257.    else
  258.       line=NO_MATCH__MSG spellword
  259.       longestwidth=length(line)
  260.       insertline line,1
  261.    endif
  262.    svcol=fileid.col; svcx=fileid.cursorx
  263.    fileid.col=svcol+max(9,longestwidth+1); fileid.col=svcol  -- ensure word is on screen
  264.    boxx=fileid.cursorx; boxy=fileid.cursory+1
  265.  
  266.    -- Minor bug fix:  This was:
  267.    --     y=boxy + .last +2 - (fileid.windowy+fileid.windowheight)
  268.    --   That caused the box to be too short when the starting cursor position
  269.    --   was near the bottom of the screen in odd windowstyles.   jbl
  270.    y=boxy + .last +2 - fileid.windowheight
  271.  
  272.    if y>0 then
  273.       oldline=fileid.line;fileid.cursory=max(fileid.cursory-y,1);fileid.line=oldline
  274.       boxy=fileid.cursory+1
  275.    endif
  276.    x=boxx+longestwidth+2-(fileid.windowx+fileid.windowwidth)
  277.    if x>0 then
  278.       boxx=boxx-x
  279.    endif
  280.    display 0   -- turn off refresh so that don't see === Top === in list.
  281.    call sizelist(boxx,boxy,longestwidth+2,.last+2)
  282.    -- jbl:  "Quit" is confusing.  "Go on" is better.  E3Spell uses "Skip".
  283.    sayerror EOS2LEX_PROMPT2__MSG
  284.  
  285.    .cursory=1; 1
  286.  
  287.    -- Turn off cursor so it looks better.
  288.    call lex_cursoroff()
  289.    -- Use sayat's instead of mark/unmark.  Preserves user's mark.
  290.    boxx = .boxx+1
  291.  
  292.    -- A better way to adjust for messy mode or odd windowstyles.
  293.    -- The same adjustment used in sizelist().
  294.    boxy = boxy+fileid.windowy-1
  295.  
  296.    lng = max(longestwidth,8)  -- min box is 10; means min inside length is 8.
  297.    display 1   -- restore refresh to display list
  298.    refresh
  299.    sayat '', boxy+.line, boxx, list_bar_color,lng
  300.    display 0   -- turn off refresh in getkey()
  301.    if .last > .windowheight then
  302.       sayat '('MORE__MSG')', boxy+.boxheight-1, boxx+(lng-length(MORE__MSG)-2)%2, .boxcolor, length(MORE__MSG)+2
  303.    endif
  304.    loop
  305.       k=getkey()
  306.       ku=upcase(k)
  307.       ocy = .cursory
  308.       if k==up then
  309.          if .line<>1 then
  310.             sayat '', boxy+.cursory, boxx, list_bak_color,lng
  311.             up
  312.             if .cursory=ocy then display 1; refresh; display 0; endif
  313.             sayat '', boxy+.cursory, boxx, list_bar_color,lng
  314.          endif
  315.          iterate
  316.       endif
  317.       if k==down then
  318.          if .line<>.last then
  319.             sayat '', boxy+.cursory, boxx, list_bak_color,lng
  320.             down
  321.             if .cursory=ocy then display 1; refresh; display 0; endif
  322.             sayat '', boxy+.cursory, boxx, list_bar_color,lng
  323.          endif
  324.          iterate
  325.       endif
  326.       if k==enter or ku=='R' then
  327.          getline line
  328.          deletewindow
  329.          sayerror 0
  330.          -- Don't replace with the 'No match' string.
  331.          if line=NO_MATCH__MSG spellword then line='' endif
  332.       elseif k==f8  then
  333.          getline line
  334.          deletewindow
  335.          -- Don't replace with the 'No match' string.
  336.          if line <> NO_MATCH__MSG spellword then
  337.             call GLOBAL_change_errant_word(spellword,line)
  338.          endif
  339.          sayerror 0
  340.          line = ''
  341.       elseif k==f9 or k==f4 or ku=='A' then
  342.          call AMU_addenda_addition_processing(spellword)
  343.          deletewindow
  344.          sayerror 0
  345.          line = ''
  346.       elseif k==f5 or ku=='T' then
  347.          call AMU_temp_addenda_addition_processing(spellword)
  348.          deletewindow
  349.          sayerror 0
  350.          line = ''
  351.       elseif k==f3 or k==f10 or ku=='C' then
  352.          deletewindow
  353.          sayerror 0
  354.          line = '10'
  355.       elseif k==esc or ku=='N' then
  356.          deletewindow
  357.          sayerror 0
  358.          line = ''
  359.       else -- other key
  360.          iterate
  361.       endif
  362.       leave
  363.    endloop
  364.    call prestore_pos(.line svcol svcx .cursory)
  365.    display 1
  366.    insert_toggle; insert_toggle          -- Restore cursor
  367.    return line
  368.  
  369. defproc sizelist(x,y,w,h)     /* create a pop-up window */
  370.    universal list_bak_color
  371.  
  372.    /* note: x and y are assumed to be window-relative positions */
  373.    /* the following changes them to screen-relative    */
  374.    call sizepopup(x+.windowx-2, y+.windowy-1,w,h,1)
  375.    .windowcolor = list_bak_color
  376.  
  377. defproc proof2
  378.    universal  list_bak_color,list_bar_color
  379.    script_file_type = AMU_script_verification()
  380.    tex_file_type = (filetype() = 'TEX')
  381.  
  382.    /* position at beginning of first word */
  383.    getline line
  384.    cursordata ;.col=1;if substr(line,1,1)==' 'then tabword endif
  385.  
  386.    -- If there's a line-marked area in the current file, proof only in there.
  387.    firstline=.line ; lastline=.last
  388.    if marktype()='LINE' then  /* if no mark, default to entire file */
  389.       getfileid curfileid
  390.       getmark fl,ll,fc,lc,markfileid
  391.       if markfileid = curfileid then
  392.          firstline=fl; lastline=ll
  393.       endif
  394.    endif
  395.  
  396.    for zz= firstline to lastline
  397.       if testkey()/=='' then
  398.          sayerror EXIT_SPELL__MSG
  399.          loop
  400.             k=getkey()
  401.             if upcase(k)=YES_CHAR or k==f10 then
  402.                sayerror 0
  403.                return(0)
  404.             elseif k=esc or upcase(k)=NO_CHAR then
  405.                leave
  406.             endif
  407.          endloop
  408.          sayerror 0
  409.       endif
  410. COMPILE IF SCREEN_MOVEMENT_minimization = 1
  411.       sayerror 'lexam:' THINKING__MSG
  412.       display 0  /* SCREEN_MOVEMENT_minimization */
  413. COMPILE ENDIF
  414.       zz
  415.       getline line
  416. --    sayerror 'checking 'line -- Put this back in if you like progress report.
  417.       loop
  418.          l=pos(' ',line,.col)
  419.          if not l then
  420.             l=length(line)+1
  421.             if l<=.col then
  422.                .col=1
  423.                leave
  424.             endif
  425.          endif
  426.          wrd=substr(line,.col,l-.col)
  427. ;        messageNwait('proof: h1 wrd=<'wrd'>  .col='.col)
  428.          result = lexam('Verification',wrd)
  429. ;        call messageNwait('LEXAM: Verification result<'result'>') /* rey */
  430. ;        call messageNwait('wrd='substr(line,.col,l-.col))
  431.          if result and wrd<>'' then
  432.             if script_file_type and
  433.             (pos(substr(wrd,1,1),':&.') or substr(line,max(.col-1,1),1)=':') then
  434.                /* ignore script tags */
  435.                result=0           /* correction found by Emmett Hayes */
  436.                if substr(wrd,1,1)=':' then
  437.                   newl=pos('.',line,.col)
  438.                   if newl then
  439.                      l=newl
  440.                   endif
  441.                endif
  442.             elseif tex_file_type & substr(wrd,1,1)='\' then
  443.                result=0
  444.             else
  445.                call strippunct(wrd,l,i)   /* strip punctuation and try again */
  446. ;              messageNwait('proof: wrd=<'wrd'>  l='l'  i='i)
  447.                .col=.col+i-1
  448.                result = lexam('Verification',wrd)
  449. ;              call messageNwait('LEXAM: Verification result<'result'>') /* rey */
  450.             endif
  451.          endif
  452.          if result and wrd<>'' then
  453.             result = lexam('Verification',wrd)
  454. ;           call messageNwait('LEXAM: Verification result<'result'>') /* rey */
  455.             if result and wrd <> '' then
  456.                -- jbl:  This message is only distracting now.
  457.                -- sayerror 'creating list of possible spellings for 'wrd
  458.                display 1  /* SCREEN_MOVEMENT_minimization */
  459.                t=spellword(0) -- jbl:  not one word only
  460.                if t=='' then
  461.                   return(0)
  462.                endif
  463.                l=l+ t
  464.                getline line
  465.             endif
  466.          endif
  467. ;        messageNwait('loop: l='l)
  468.          .col=l+1
  469.       endloop
  470.    endfor
  471.    display 1  /* SCREEN_MOVEMENT_minimization */
  472.    sayerror DONE__MSG
  473.  
  474.  
  475. defproc strippunct(var wrd,var l,var i)
  476.    -- Make this a variable, not a constant. to save space.
  477.    punctuation ='~!@#$%^&*()_+|`1234567890-=\{}[]:";''<>?,./¬'
  478.    /* strip leading and trailing punctuation and try again*/
  479.    i=verify(wrd,punctuation)
  480. ;  messageNwait('strippunct: wrd=<'wrd'> i='i' l='l)
  481.    if i>0 then
  482.       l=l-length(wrd)
  483.       wrd=substr(wrd,i)
  484.       j=verify(wrd,punctuation,'m')
  485.       if j then
  486.          wrd=substr(wrd,1,j-1)
  487.       else
  488.          j=length(wrd)+1
  489.       endif
  490.       l=l+j+i-2
  491. ;     messageNwait('strippunct: wrd=<'wrd'>  l='l'  j='j' i='i)
  492.    else
  493.       i=length(wrd)+1
  494.    endif
  495.  
  496. defproc may_be_save_addenda
  497.    universal  addenda_has_been_modified
  498.    universal  AMU_addenda_file_identification
  499.    universal  ADDENDA_FILENAME
  500.  
  501.    if addenda_has_been_modified then
  502.       sayerror 'saving addenda 'ADDENDA_FILENAME
  503.       if AMU_addenda_file_identification<>''  then
  504.        getfileid AMU_current_file_identification
  505.        activatefile AMU_addenda_file_identification
  506.        's'
  507.        activatefile AMU_current_file_identification
  508.       endif
  509.       addenda_has_been_modified=0
  510.       sayerror 0
  511.    endif
  512.  
  513. /*
  514.    Return Values documented above
  515.  
  516. lexam('Initialize')
  517. lexam('Terminate')
  518. lexam('PIckup Dictionary',dictionary_name)
  519. lexam('DRop Dictionary',dictionary_name)
  520. lexam('SEt Addenda Language Type',addenda_type)
  521. lexam('Add to Transient Addenda',addenda_name)
  522. lexam('Read from Transient Addenda',addenda_name)
  523. lexam('Verification',word)
  524. lexam('SPelling Aid',word)
  525. lexam('Hyphenation',word)
  526. lexam('DEhyphenation',word)
  527. lexam('SYnonym',word)
  528. lexam('GRAMmar Aid',word)
  529. lexam('GRADe level',word)
  530. lexam('PArt-of-speech',word)
  531. */
  532.  
  533. defproc lexam_is_available()
  534.    result = lexam('Initialize')
  535. ;call messageNwait('Initialize:' result)
  536.    if result=LXRFGOOD or result=LXRFIFCN  then
  537.       return(1)
  538.    else
  539.       return(0)
  540.    endif
  541.  
  542. defc proofword,verify =
  543.    call load_lexam()
  544.    call rypbegin_word()
  545.    call spellword(1) -- jbl tg: one word only
  546.    call may_be_save_addenda()
  547.  
  548. defc syn =
  549.    call load_lexam()
  550.    call pbegin_word()
  551.    call synonym()
  552.  
  553. defproc synonym()
  554.    getline line
  555.    if line<>'' then
  556.       i=.col
  557.       l=pos(' ',line,.col)
  558.       if l=0 then
  559.          l=length(line)+1
  560.          if l<i then l=i endif
  561.       endif
  562.       wrd=strip(substr(line,i,l-i))
  563.       oldwordlen=length(wrd)
  564. ;     call messageNwait('LEXAM: SYnonym wrd<'wrd'>') /* rey */
  565.       result=lexam('Verification',wrd)
  566. ;     call messageNwait('LEXAM: Verification result<'result'>') /* rey */
  567.       if(result <> LXRFGOOD) then
  568.          sayerror NO_SYN__MSG '<'wrd'>'
  569.          return('')
  570.       endif
  571.       parse value lexam('SYnonym',wrd) with . result /* rey */
  572.       x=result
  573.       if result='' then
  574.          sayerror NO_SYN__MSG '<'wrd'>'
  575.          return('')
  576.       endif
  577. ;     call messageNwait('LEXAM: SYnonym result<'result'>') /* rey */
  578. ;     call messageNwait('LEXAM: rc<'rc'>') /* rey */
  579. COMPILE IF DISPLAY_box = 1
  580.       newword=liststring(result,wrd)
  581. COMPILE ELSE
  582.       newword=DISPLAY_list(result)
  583. COMPILE ENDIF
  584.       if newword=10 then
  585.          return('')
  586.       endif
  587.       if newword<>'' then
  588. ;        messageNwait('newword='newword' line=<'line'> l='l)
  589.          replaceline substr(line,1,.col-1)||newword||substr(line,l)
  590.          return(length(newword)-oldwordlen)
  591.       endif
  592.    endif
  593.  
  594. /* list synonyms for a word at the cursor position */
  595. def s_f9 =
  596.    call load_lexam()
  597.    call pbegin_word()
  598.    call synonym()
  599.  
  600. defproc load_lexam
  601.    universal flexam_initialized
  602.    universal flexam_is_in_a_bad_state
  603.    universal  ADDENDA_FILENAME
  604.    universal  DICTIONARY_FILENAME
  605.    if flexam_is_in_a_bad_state then
  606.       call messageNwait('LEXAM: ' BAD_DICT__MSG)
  607.       stop
  608.    endif
  609.    if not flexam_initialized then
  610.       flexam_initialized=1                /* perform initialization once */
  611.       if not lexam_is_available() then
  612.          messageNwait('LEXAM: ' INIT_ERROR__MSG)
  613.       endif
  614.       dictlist=DICTIONARY_FILENAME
  615.       do while dictlist <> ''
  616.          parse value dictlist with dictionary dictlist
  617.          result=lexam('PIckup Dictionary', dictionary)
  618.          if result & (result<>107) then  --107=dup. dict. - OK if it's already loaded.
  619.             call messageNwait('LEXAM: ' BAD_DICT__MSG'  RC =' result)
  620.             flexam_is_in_a_bad_state=1
  621.             stop
  622.          endif
  623.       enddo
  624.       call lexam('ADDEnda pickup Dictionary',ADDENDA_FILENAME)
  625.       call AMU_addenda_processing()
  626.    endif
  627.  
  628.  
  629. defproc rypbegin_word
  630.    getline line
  631.    punctuation =' ~!@#$%^&*()_+|`1234567890-=\{}[]:";''<>?,./¬'
  632.    location=.col
  633.    while not verify(substr(line,.col,1),punctuation,'m') and location do
  634.       location=location-1
  635.       .col=location
  636.    endwhile
  637.    .col=location+1
  638.  
  639. ; Addenda support commands
  640. ;defc AMU_addenda_pickup
  641. ;   universal  ADDENDA_FILENAME
  642. ;   call lexam('ADDEnda pickup Dictionary',ADDENDA_FILENAME)
  643.  
  644. ;defc AMU_addenda_addition
  645. ;   call lexam('ADDItion to Transient Addenda',arg(1))
  646.  
  647. defproc AMU_addenda_processing
  648.    universal AMU_addenda_file_identification
  649.    universal  ADDENDA_FILENAME
  650.    getfileid AMU_current_file_identification
  651.    'e /h /q 'ADDENDA_FILENAME
  652.    if not rc or rc = -282 then  -- sayerror('New file')
  653.       getfileid AMU_addenda_file_identification
  654.    else
  655.       AMU_addenda_file_identification =''
  656.       sayerror BAD_ADDENDA__MSG ADDENDA_FILENAME 'rc=' rc
  657.       stop
  658.    endif
  659.    activatefile AMU_current_file_identification
  660.    if AMU_addenda_file_identification <>'' then
  661.       for i = 1 to AMU_addenda_file_identification.last
  662.          getline line,i,AMU_addenda_file_identification
  663.          do while line <> ''
  664.             parse value line with wrd line
  665. COMPILE IF RESPECT_case_for_addenda
  666.             call lexam('ADDItion to Transient Addenda',wrd)
  667. COMPILE ELSE
  668.             call lexam('ADDItion to Transient Addenda',lowcase(wrd))
  669. COMPILE ENDIF
  670.          enddo
  671.       endfor
  672.    endif
  673.  
  674. defproc AMU_addenda_addition_processing(AMU_addenda_entry)
  675.    universal  addenda_has_been_modified
  676.    universal AMU_addenda_file_identification
  677.    addenda_has_been_modified=1
  678. COMPILE IF RESPECT_case_for_addenda = 0
  679.    AMU_addenda_entry=lowcase(AMU_addenda_entry)
  680. COMPILE ENDIF
  681.    call lexam('ADDItion to Transient Addenda',AMU_addenda_entry)
  682.    insertline AMU_addenda_entry,AMU_addenda_file_identification.last+1,AMU_addenda_file_identification
  683.  
  684. defproc AMU_temp_addenda_addition_processing(AMU_addenda_entry)
  685. COMPILE IF RESPECT_case_for_addenda = 0
  686.    AMU_addenda_entry=lowcase(AMU_addenda_entry)
  687. COMPILE ENDIF
  688.    call lexam('ADDItion to Transient Addenda',AMU_addenda_entry)
  689.  
  690. ; The following is a script file type verification algorithm
  691. ; suggested by Larry Margolis. (Thanks, Larry)
  692. defproc AMU_script_verification()
  693.    ext=filetype()
  694. compile if defined(my_SCRIPT_FILE_TYPE)
  695.    return ext='SCR' or ext='SCT' or ext='SCRIPT' or ext='IPF' or ext=my_SCRIPT_FILE_TYPE
  696. compile else
  697.    return ext='SCR' or ext='SCT' or ext='SCRIPT' or ext='IPF'
  698. compile endif
  699.  
  700. -- Turn cursor off.  Taken from LAM's MAILMENU.E, simplified for OS/2 only.
  701. defproc lex_cursoroff
  702.    string=atoi(0) || atoi(1) || atoi(1) || atoi(-1)
  703.    call dynalink('VIOCALLS',        /* dynamic link library name          */
  704.                  'VIOSETCURTYPE',   /* Video Input Output SET CURsor TYPE */
  705.                  selector(string)|| /* string selector                    */
  706.                  offset(string)||   /* string offset                      */
  707.                  atoi(0))           /* Vio Handle                         */
  708.  
  709. defproc GLOBAL_change_errant_word(spellword,line)
  710. ;call messageNwait('message: c /'spellword'/'line'/*') */
  711.    GLOBAL_saveline   = .line
  712.    GLOBAL_savecolumn = .col
  713.    'c /'spellword'/'line'/*'
  714.    GLOBAL_saveline
  715.    .col              = GLOBAL_savecolumn
  716.  
  717. defproc LEXICAL_ESCAPE_embedded_control(wrd)
  718.    LEXICAL_ESCAPE_position =pos(\255,wrd)
  719.    if LEXICAL_ESCAPE_position then
  720. ;     call messageNwait('LEXICAL_ESCAPE_position' LEXICAL_ESCAPE_position)
  721.       return overlay(' ',wrd,LEXICAL_ESCAPE_position)
  722.    endif
  723.    return wrd
  724.  
  725. ;defc lex_bad
  726. ;   universal  flexam_is_in_a_bad_state
  727. ;   flexam_is_in_a_bad_state=arg(1)
  728.  
  729. defproc DISPLAY_list(result)
  730.    universal list_bar_color
  731.    i=1
  732.    while result<>'' do
  733.       parse value result with word0 word1 word2 word3 word4 result
  734.       result0 = word0 word1 word2 word3 word4
  735.       sayat result0,i,1,list_bar_color,length(result0)
  736.       display 0
  737.       i=i+1
  738.    endwhile
  739.    k=getkey()
  740.    executekey k
  741.    display 1
  742.    return 10
  743.  
  744.