Branch data Line data Source code
1 : : /* m2spellcheck.cc provides an interface to GCC expression trees.
2 : :
3 : : Copyright (C) 2025 Free Software Foundation, Inc.
4 : : Contributed by Gaius Mulley <gaiusmod2@gmail.com>.
5 : :
6 : : This file is part of GNU Modula-2.
7 : :
8 : : GNU Modula-2 is free software; you can redistribute it and/or modify
9 : : it under the terms of the GNU General Public License as published by
10 : : the Free Software Foundation; either version 3, or (at your option)
11 : : any later version.
12 : :
13 : : GNU Modula-2 is distributed in the hope that it will be useful, but
14 : : WITHOUT ANY WARRANTY; without even the implied warranty of
15 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 : : General Public License for more details.
17 : :
18 : : You should have received a copy of the GNU General Public License
19 : : along with GNU Modula-2; see the file COPYING3. If not see
20 : : <http://www.gnu.org/licenses/>. */
21 : :
22 : : #include "gcc-consolidation.h"
23 : :
24 : : #include "../gm2-lang.h"
25 : : #include "../m2-tree.h"
26 : :
27 : : #define m2spellcheck_c
28 : : #include "m2assert.h"
29 : : #include "m2builtins.h"
30 : : #include "m2convert.h"
31 : : #include "m2decl.h"
32 : : #include "m2expr.h"
33 : : #include "m2spellcheck.h"
34 : :
35 : :
36 : : /* Define the hidden type Candidates declared in the definition module. */
37 : :
38 : : typedef struct Candidates_t {
39 : : auto_vec<const char *> candidates_array;
40 : : struct Candidates_t *next;
41 : : } Candidates;
42 : :
43 : :
44 : : static Candidates *freeList = NULL;
45 : :
46 : :
47 : : /* InitCandidates create an empty candidate array. */
48 : :
49 : : void *
50 : 156 : m2spellcheck_InitCandidates (void)
51 : : {
52 : 156 : Candidates *c = NULL;
53 : 156 : if (freeList == NULL)
54 : 132 : c = (Candidates *) xmalloc (sizeof (Candidates));
55 : : else
56 : : {
57 : 24 : c = freeList;
58 : 24 : freeList = freeList->next;
59 : : }
60 : 156 : memset (c, 0, sizeof (Candidates));
61 : 156 : return c;
62 : : }
63 : :
64 : : /* Push a string to the Candidates array.
65 : : The candidates array will contain str at the end. */
66 : :
67 : : static
68 : : void
69 : 2208 : Push (Candidates *cand, const char *name)
70 : : {
71 : 0 : cand->candidates_array.safe_push (name);
72 : 0 : }
73 : :
74 : : /* Push a string to the Candidates array.
75 : : The candidates array will contain str at the end. */
76 : :
77 : : void
78 : 2208 : m2spellcheck_Push (void *cand, const char *name)
79 : : {
80 : 2208 : Push (static_cast<Candidates *> (cand), name);
81 : 2208 : }
82 : :
83 : : static
84 : : void
85 : 156 : KillCandidates (Candidates **cand)
86 : : {
87 : : // --fixme-- deallocate and zero the candidates_array.
88 : 156 : (*cand)->next = freeList;
89 : 156 : freeList = *cand;
90 : 156 : (*cand) = NULL;
91 : 0 : }
92 : :
93 : : /* KillCandidates deallocates the candidates array and set (*cand) to NULL.
94 : : (*cand) is placed into the m2spellcheck module freeList. */
95 : :
96 : : void
97 : 156 : m2spellcheck_KillCandidates (void **cand)
98 : : {
99 : 156 : KillCandidates (reinterpret_cast<Candidates **> (cand));
100 : 156 : }
101 : :
102 : : /* FindClosestCharStar return the closest match to name found within
103 : : the candidates_array. NULL is returned if no close match is found. */
104 : :
105 : : const char*
106 : 156 : FindClosestCharStar (Candidates *cand, const char *name)
107 : : {
108 : 156 : return find_closest_string (name, &cand->candidates_array);
109 : : }
110 : :
111 : : const char*
112 : 156 : m2spellcheck_FindClosestCharStar (void *cand, const char *name)
113 : : {
114 : 156 : return FindClosestCharStar (static_cast<Candidates *> (cand),
115 : 156 : name);
116 : : }
|