1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#ifndef lint
static char Rcs_Id[] __attribute__ ((unused)) =
"$Id: exp_table.c,v 1.4 2005/06/11 22:43:53 geoff Exp $";
#endif
/*
* Note: this file was written by Edward Avis. Thus, it is not
* distributed under the same license as the rest of ispell.
*/
/*
* $Log: exp_table.c,v $
* Revision 1.4 2005/06/11 22:43:53 geoff
* Don't try to malloc zero elements during initialization.
*
* Revision 1.3 2005/04/14 15:19:37 geoff
* Get rid of a compiler warning.
*
* Revision 1.2 2005/04/14 14:38:23 geoff
* Add RCS keywords. Reformat to be more consistent with ispell style.
* This may also include some bug fixes; I unfortunately don't really
* remember.
*
* Revision 1.1 2002/07/02 00:06:50 geoff
* Initial revision
*/
#include "config.h"
#include "ispell.h"
#include "msgs.h"
#include "proto.h"
#include "exp_table.h"
void exp_table_init (e, orig_word)
struct exp_table *
e;
ichar_t * orig_word;
{
e->size = 0;
e->max_size = 1;
e->exps = malloc (e->max_size * sizeof (*e->exps));
e->flags = malloc (e->max_size * sizeof (*e->flags) * MASKSIZE);
e->orig_word = orig_word;
}
const ichar_t * get_orig_word (e)
const struct exp_table *
e;
{
return e->orig_word;
}
const char * get_expansion (e, i)
const struct exp_table *
e;
int i;
{
return e->exps[i];
}
MASKTYPE get_flags (e, i)
const struct exp_table *
e;
int i;
{
return e->flags[i * MASKSIZE];
}
int num_expansions (e)
const struct exp_table *
e;
{
return e->size;
}
int add_expansion_copy (e, s, flags)
struct exp_table * e;
const char * s;
MASKTYPE flags[];
{
char * copy;
int copy_size;
int i;
/*
* Check not already there.
*/
for (i = 0; i < e->size; i++)
{
if (strcmp (e->exps[i], s) == 0)
return 0;
}
/*
* Grow the pointer table if necessary.
*/
if (e->size == e->max_size)
{
e->max_size *= 2;
e->exps = realloc(e->exps, e->max_size * sizeof (*e->exps));
e->flags =
realloc(e->flags, e->max_size * sizeof (*e->flags) * MASKSIZE);
if (e->exps == NULL || e->flags == NULL)
{
(void) fprintf (stderr, TGOOD_C_NO_SPACE);
exit (1);
}
}
copy_size = strlen (s) + 1;
copy = malloc (copy_size * sizeof copy[0]);
if (copy == NULL)
{
(void) fprintf (stderr, TGOOD_C_NO_SPACE);
exit (1);
}
strncpy (copy, s, copy_size);
e->exps[e->size] = copy;
BCOPY ((char *) &flags[0], &e->flags[e->size * MASKSIZE],
MASKSIZE * sizeof flags[0]);
++e->size;
return 1;
}
struct exp_table * exp_table_empty (e)
struct exp_table * e;
{
int i;
for (i = 0; i < e->size; i++)
free (e->exps[i]);
e->size = 0;
return e;
}
void exp_table_dump (e)
const struct exp_table *
e;
{
int i;
/*
* BUGS: assumes 32-bit masks; assumes MASKSIZE = 1
*/
fprintf(stderr, "original word: %s\n", ichartosstr(e->orig_word, 0));
fprintf(stderr, "%d expansions\n", e->size);
for (i = 0; i < e->size; i++)
fprintf(stderr, "flags %lx generate expansion %s\n",
(long) e->flags[i * MASKSIZE], e->exps[i]);
}
|