home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / pine4.10.tar.gz / pine4.10.tar / pine4.10 / pico / osdep / spell.ms < prev    next >
Text File  |  1998-09-15  |  5KB  |  199 lines

  1. #line 2 "osdep/spell.ms"
  2. /*
  3.  * Program:    msspell.c
  4.  *
  5.  *
  6.  * Thomas Unger and Michael Seibel
  7.  * Networks and Distributed Computing
  8.  * Computing and Communications
  9.  * University of Washington
  10.  * Administration Builiding, AG-44
  11.  * Seattle, Washington, 98195, USA
  12.  * Internet: pine@cac.washington.edu
  13.  *
  14.  * Please address all bugs and comments to "pine-bugs@cac.washington.edu"
  15.  *
  16.  *
  17.  * Pine and Pico are registered trademarks of the University of Washington.
  18.  * No commercial use of these trademarks may be made without prior written
  19.  * permission of the University of Washington.
  20.  * 
  21.  * Pine, Pico, and Pilot software and its included text are Copyright
  22.  * 1989-1998 by the University of Washington.
  23.  * 
  24.  * The full text of our legal notices is contained in the file called
  25.  * CPYRIGHT, included with this distribution.
  26.  */
  27.  
  28. #include "headers.h"
  29.  
  30. #ifdef    SPELLER
  31. #include "../spell/spell.h"
  32.  
  33.  
  34. extern FILE        *gfDebugFile = NULL;
  35.  
  36.  
  37.  
  38. void chword PROTO((char *, char *));
  39.  
  40.  
  41. #define  NSHLINES  12
  42.  
  43. static char *spellhelp[] = {
  44.   "Spell Check Help",
  45.   " ",
  46.   "\tThe spell checker examines all words in the text.  It then",
  47.   "\toffers each misspelled word for correction while simultaneously",
  48.   "\thighlighting it in the text.  To leave a word unchanged simply",
  49.   "~\thit ~R~e~t~u~r~n at the edit prompt.  If a word has been corrected,",
  50.   "\teach occurrence of the incorrect word is offered for replacement.",
  51.   " ",
  52.   "~\tSpell checking can be cancelled at any time by typing ~^~C (~F~3)",
  53.   "\tafter exiting help.",
  54.   " ",
  55.   "End of Spell Check Help",
  56.   " ",
  57.   NULL
  58. };
  59.  
  60.  
  61. static char *pinespellhelp[] = {
  62.   "Spell Check Help",
  63.   " ",
  64.   "\tThe spell checker examines all words in the text.  It then",
  65.   "\toffers each misspelled word for correction while simultaneously",
  66.   "\thighlighting it in the text.  To leave a word unchanged simply",
  67.   "\thit Return at the edit prompt.  If a word has been corrected,",
  68.   "\teach occurrence of the incorrect word is offered for replacement.",
  69.   " ",
  70.   "\tSpell checking can be cancelled at any time by typing ^C (F3)",
  71.   "\tafter exiting help.",
  72.   " ",
  73.   "End of Spell Check Help",
  74.   " ",
  75.   NULL
  76. };
  77.  
  78.  
  79. extern HWND        ghTTYWnd;
  80.  
  81.  
  82.  
  83. /*
  84.  * spell() - check for potentially missspelled words and offer them for
  85.  *           correction
  86.  */
  87. spell(f, n)
  88.     int f, n;
  89. {
  90.     int    wlen, bsize, ret, begi, endi, offset, i, qlen;
  91.     char   wbuf[NLINE], *lbuf;
  92.     FILE   *p;
  93.     LINE  *lp;
  94.     struct StrStResult result;
  95.  
  96.     setimark(0, 1);
  97.     emlwrite("Checking spelling...",NULL);        /* greetings */
  98.  
  99.     ret = 1;
  100.  
  101.     StResetUserDict((char *) getenv("USER_DICTIONARY"), NULL);
  102.  
  103.     qlen = (Pmaster && Pmaster->quote_str) ? strlen(Pmaster->quote_str) : 0;
  104.     lbuf = (char *) malloc(sizeof(char));
  105.     bsize = 0;
  106.     for(lp = lforw(curbp->b_linep); lp != curbp->b_linep; lp = lforw(lp)){
  107.     if(qlen){                /* quoted line? */
  108.         i = 0;
  109.         if(qlen <= llength(lp))
  110.           while(i < qlen && Pmaster->quote_str[i] == lgetc(lp, i).c)
  111.         i++;
  112.  
  113.         if(i == qlen)
  114.           continue;
  115.     }
  116.  
  117.     if(bsize < llength(lp) + 2){        /* resize line buffer? */
  118.         bsize = llength(lp);
  119.         if(!(lbuf = (char *)realloc(lbuf, (bsize + 1) * sizeof(char)))){
  120.         emlwrite("Can't reallocate internal buffer!", NULL);
  121.         ret = 0;            /* FAILURE ! */
  122.         break;
  123.         }
  124.     }
  125.       
  126.     for(i = 0; i < llength(lp); i++)    /* copy line to buffer */
  127.       lbuf[i] = lgetc(lp, i).c;
  128.  
  129.     lbuf[i] = '\0';                /* initialize */
  130.     begi = endi = offset = 0;
  131.     while(wlen = StParseLine(lbuf, wbuf, &begi, &endi, i))
  132.       if(!SpellWord(wbuf, 0, ghTTYWnd, &result)){
  133.           curwp->w_doto = offset + begi;    /* place dot on word */
  134.           curwp->w_dotp = lp;
  135.           update();
  136.           (*term.t_rev)(1);
  137.           pputs(wbuf, 1);            /* and highlight it */
  138.           (*term.t_rev)(0);
  139.  
  140.           SpellWord(wbuf, ST_INTERACTIVE, ghTTYWnd, &result);
  141.  
  142.           curwp->w_flag |= WFMOVE;        /* put cursor back */
  143.           sgarbk = 0;            /* fake no-keymenu-change! */
  144.           update();
  145.           pputs(wbuf, 0);            /* un-highlight */
  146.  
  147.           if(result.code & (ST_EXIT | ST_ERROR)){
  148.           if(result.code & ST_EXIT)
  149.             emlwrite("Spell Checking Cancelled", NULL);
  150.  
  151.           lp = NULL;            /* stop looking */
  152.           ret  = 0;
  153.           break;
  154.           }
  155.           else if(result.replace[0]){
  156.           chword(wbuf, result.replace);    /* correct word */
  157.           offset += strlen(result.replace) - wlen;
  158.           update();            /* place cursor */
  159.           }
  160.       }
  161.  
  162.     if(!lp)                    /* more to come? */
  163.       break;
  164.     }
  165.  
  166.     StResetUserDict(NULL, NULL);
  167.     StClearHist();
  168.     swapimark(0, 1);
  169.     curwp->w_flag |= WFHARD|WFMODE;
  170.     sgarbk = TRUE;
  171.  
  172.     if(ret)
  173.       emlwrite("Done checking spelling", NULL);
  174.  
  175.     return(ret);
  176. }
  177.  
  178.  
  179.  
  180.  
  181. /* 
  182.  * chword() - change the given word, wp, pointed to by the curwp->w_dot 
  183.  *            pointers to the word in cb
  184.  */
  185. void
  186. chword(wb, cb)
  187.   char *wb;                    /* word buffer */
  188.   char *cb;                    /* changed buffer */
  189. {
  190.     ldelete((long) strlen(wb), NULL);        /* not saved in kill buffer */
  191.     while(*cb != '\0')
  192.       linsert(1, *cb++);
  193.  
  194.     curwp->w_flag |= WFEDIT;
  195. }
  196. #endif    /* SPELLER */
  197.  
  198.  
  199.