home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / ispell-4.0-src.lha / src / amiga / ispell-4.0 / gen.c < prev    next >
C/C++ Source or Header  |  1993-06-01  |  4KB  |  218 lines

  1. /* Copyright (C) 1990, 1993 Free Software Foundation, Inc.
  2.  
  3.    This file is part of GNU ISPELL.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.    GNU General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include <stdio.h>
  20. #include <ctype.h>
  21. #include <setjmp.h>
  22. #include "ispell.h"
  23. #include "hash.h"
  24. #include "good.h"
  25.  
  26. extern int intr_typed;
  27.  
  28. char newword[MAX_WORD_LEN];
  29.  
  30. jmp_buf genjmp;
  31.  
  32. #ifdef __STDC__
  33.  
  34. void wrongletter (char *);
  35. void extraletter (char *);
  36. void missingletter (char *);
  37. void transposedletter (char *);
  38.  
  39. #else
  40.  
  41. void wrongletter ();
  42. void extraletter ();
  43. void missingletter ();
  44. void transposedletter ();
  45.  
  46. #endif
  47.  
  48. struct sp_corrections corrections;
  49.  
  50. int
  51. makepossibilities (word)
  52.   char *word;
  53. {
  54.   int i;
  55.   char uword[MAX_WORD_LEN];
  56.  
  57.   corrections.nwords = 0;
  58.  
  59.   if (strlen (word) > MAX_WORD_LEN - 5)
  60.     return (0);
  61.  
  62.   downcase (uword, word);
  63.  
  64.   if (setjmp (genjmp))
  65.     goto done;
  66.  
  67.   for (i = 0; i < MAXPOS; i++)
  68.     corrections.posbuf[i][0] = 0;
  69.  
  70.   wrongletter (uword);
  71.   extraletter (uword);
  72.   missingletter (uword);
  73.   transposedletter (uword);
  74.  
  75. done:;
  76.   fixcase (word, &corrections);
  77.   if (intr_typed)
  78.     return (1);
  79.  
  80.   return (0);
  81. }
  82.  
  83. void
  84. insert (word)
  85.      char *word;
  86. {
  87.   int i, n;
  88.  
  89.   n = corrections.nwords;
  90.   for (i = 0; i < n; i++)
  91.     if (strcmp (corrections.posbuf[i], word) == 0)
  92.       return;
  93.  
  94.   (void) strcpy (corrections.posbuf[n++], word);
  95.  
  96.   corrections.nwords = n;
  97.  
  98.   if (n >= 10)
  99.     longjmp (genjmp, 1);
  100. }
  101.  
  102. void
  103. wrongletter (word)
  104.   char *word;
  105. {
  106.   int i, len;
  107.   int j;
  108.  
  109.   if (intr_typed)
  110.     return;
  111.  
  112.   len = strlen (word);
  113.   (void) strcpy (newword, word);
  114.  
  115.   for (i = 0; i < len; i++)
  116.     {
  117.       if (intr_typed)
  118.     return;
  119.       for (j = 0; j < nnear_miss_letters; j++)
  120.     {
  121.       newword[i] = near_miss_letters[j];
  122.       if (good (newword, len, 1))
  123.         insert (newword);
  124.     }
  125.       newword[i] = word[i];
  126.     }
  127. }
  128.  
  129. void
  130. extraletter (word)
  131.   char *word;
  132. {
  133.   char *p, *s, *t;
  134.   int len;
  135.  
  136.   if (intr_typed)
  137.     return;
  138.  
  139.   len = strlen (word);
  140.  
  141.   if (len <= 2)
  142.     return;
  143.  
  144.   for (p = word; *p; p++)
  145.     {
  146.       if (intr_typed)
  147.     return;
  148.       for (s = word, t = newword; *s; s++)
  149.     if (s != p)
  150.       *t++ = *s;
  151.       *t = 0;
  152.       if (good (newword, len - 1, 1))
  153.     insert (newword);
  154.     }
  155. }
  156.  
  157. void
  158. missingletter (word)
  159.   char *word;
  160. {
  161.   char *p, *r, *s, *t;
  162.   int len;
  163.   int i;
  164.  
  165.   if (intr_typed)
  166.     return;
  167.  
  168.   len = strlen (word);
  169.  
  170.   for (p = word; p == word || p[-1]; p++)
  171.     {
  172.       if (intr_typed)
  173.     return;
  174.       for (s = newword, t = word; t != p; s++, t++)
  175.     *s = *t;
  176.       r = s++;
  177.       while (*t)
  178.     *s++ = *t++;
  179.       *s = 0;
  180.  
  181.       for (i = 0; i < nnear_miss_letters; i++)
  182.     {
  183.       *r = near_miss_letters[i];
  184.       if (good (newword, len + 1, 1))
  185.         insert (newword);
  186.     }
  187.     }
  188. }
  189.  
  190. void
  191. transposedletter (word)
  192.   char *word;
  193. {
  194.   char t;
  195.   char *p;
  196.   int len;
  197.  
  198.   if (intr_typed)
  199.     return;
  200.  
  201.   len = strlen (word);
  202.  
  203.   (void) strcpy (newword, word);
  204.   for (p = newword; p[1]; p++)
  205.     {
  206.       if (intr_typed)
  207.     return;
  208.       t = p[0];
  209.       p[0] = p[1];
  210.       p[1] = t;
  211.       if (good (newword, len, 1))
  212.     insert (newword);
  213.       t = p[0];
  214.       p[0] = p[1];
  215.       p[1] = t;
  216.     }
  217. }
  218.