| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "jacl.h" |
| 7 |
#include "types.h" |
| 8 |
#include "prototypes.h" |
| 9 |
#include "encapsulate.h" |
| 10 |
#include <string.h> |
| 11 |
|
| 12 |
extern struct synonym_type *synonym_table; |
| 13 |
extern struct filter_type *filter_table; |
| 14 |
|
| 15 |
char text_buffer[1024]; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
const char *comma = "comma\0"; |
| 20 |
const char *then = "then\0"; |
| 21 |
const char *word[MAX_WORDS]; |
| 22 |
int quoted[MAX_WORDS]; |
| 23 |
int percented[MAX_WORDS]; |
| 24 |
int wp; |
| 25 |
|
| 26 |
void |
| 27 |
encapsulate() |
| 28 |
{ |
| 29 |
int index, |
| 30 |
length; |
| 31 |
int position = 0; |
| 32 |
int new_word = TRUE; |
| 33 |
|
| 34 |
length = strlen(text_buffer); |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
for (index = 0; index < MAX_WORDS; index++) { |
| 39 |
quoted[index] = 0; |
| 40 |
percented[index] = 0; |
| 41 |
} |
| 42 |
|
| 43 |
for (index = 0; index < length; index++) { |
| 44 |
|
| 45 |
switch (text_buffer[index]) { |
| 46 |
case ':': |
| 47 |
case '\t': |
| 48 |
case ' ': |
| 49 |
case ',': |
| 50 |
text_buffer[index] = 0; |
| 51 |
new_word = TRUE; |
| 52 |
break; |
| 53 |
case ';': |
| 54 |
case '#': |
| 55 |
case '\r': |
| 56 |
case '\n': |
| 57 |
|
| 58 |
|
| 59 |
text_buffer[index] = 0; |
| 60 |
index = length; |
| 61 |
break; |
| 62 |
case '"': |
| 63 |
index++; |
| 64 |
|
| 65 |
|
| 66 |
quoted[position] = 1; |
| 67 |
|
| 68 |
word[position] = &text_buffer[index]; |
| 69 |
|
| 70 |
if (position < MAX_WORDS) |
| 71 |
position++; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
for (; index < length; index++) { |
| 77 |
if (text_buffer[index] == '"') { |
| 78 |
text_buffer[index] = 0; |
| 79 |
new_word = TRUE; |
| 80 |
break; |
| 81 |
} else if (text_buffer[index] == '\r' || text_buffer[index] == '\n') { |
| 82 |
text_buffer[index] = 0; |
| 83 |
index = length; |
| 84 |
break; |
| 85 |
} |
| 86 |
} |
| 87 |
break; |
| 88 |
default: |
| 89 |
if (new_word) { |
| 90 |
if (text_buffer[index] == '%' && text_buffer[index+1] != ' ' && text_buffer[index+1] != '\t') { |
| 91 |
percented[position]++; |
| 92 |
break; |
| 93 |
} |
| 94 |
word[position] = &text_buffer[index]; |
| 95 |
new_word = FALSE; |
| 96 |
if (position < MAX_WORDS) |
| 97 |
position++; |
| 98 |
} |
| 99 |
break; |
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
for (index = position; index < MAX_WORDS; index++) |
| 106 |
word[index] = NULL; |
| 107 |
|
| 108 |
wp = 0; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
void |
| 113 |
command_encapsulate() |
| 114 |
{ |
| 115 |
int index, |
| 116 |
length; |
| 117 |
int position = 0; |
| 118 |
int new_word = TRUE; |
| 119 |
|
| 120 |
length = strlen(text_buffer); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
for (index = 0; index < MAX_WORDS; index++) { |
| 125 |
quoted[index] = 0; |
| 126 |
} |
| 127 |
|
| 128 |
for (index = 0; index < length; index++) { |
| 129 |
|
| 130 |
|
| 131 |
text_buffer[index] = tolower((int) text_buffer[index]); |
| 132 |
|
| 133 |
switch (text_buffer[index]) { |
| 134 |
case ':': |
| 135 |
case '\t': |
| 136 |
case ' ': |
| 137 |
text_buffer[index] = 0; |
| 138 |
new_word = TRUE; |
| 139 |
break; |
| 140 |
case ',': |
| 141 |
text_buffer[index] = 0; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
word[position] = comma; |
| 146 |
if (position < MAX_WORDS) |
| 147 |
position++; |
| 148 |
new_word = TRUE; |
| 149 |
break; |
| 150 |
case '.': |
| 151 |
text_buffer[index] = 0; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
word[position] = then; |
| 156 |
if (position < MAX_WORDS) |
| 157 |
position++; |
| 158 |
new_word = TRUE; |
| 159 |
break; |
| 160 |
case ';': |
| 161 |
case '\r': |
| 162 |
case '\n': |
| 163 |
|
| 164 |
|
| 165 |
text_buffer[index] = 0; |
| 166 |
index = length; |
| 167 |
break; |
| 168 |
case '"': |
| 169 |
index++; |
| 170 |
|
| 171 |
|
| 172 |
quoted[position] = 1; |
| 173 |
|
| 174 |
word[position] = &text_buffer[index]; |
| 175 |
|
| 176 |
if (position < MAX_WORDS) |
| 177 |
position++; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
for (; index < length; index++) { |
| 183 |
if (text_buffer[index] == '"') { |
| 184 |
text_buffer[index] = 0; |
| 185 |
new_word = TRUE; |
| 186 |
break; |
| 187 |
} else if (text_buffer[index] == '\r' || text_buffer[index] == '\n') { |
| 188 |
text_buffer[index] = 0; |
| 189 |
index = length; |
| 190 |
break; |
| 191 |
} |
| 192 |
} |
| 193 |
break; |
| 194 |
default: |
| 195 |
if (new_word) { |
| 196 |
word[position] = &text_buffer[index]; |
| 197 |
new_word = FALSE; |
| 198 |
if (position < MAX_WORDS) |
| 199 |
position++; |
| 200 |
} |
| 201 |
break; |
| 202 |
} |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
for (index = position; index < MAX_WORDS; index++) { |
| 208 |
word[index] = NULL; |
| 209 |
} |
| 210 |
|
| 211 |
wp = 0; |
| 212 |
} |
| 213 |
|
| 214 |
void |
| 215 |
jacl_truncate() |
| 216 |
{ |
| 217 |
int index, |
| 218 |
counter, |
| 219 |
match; |
| 220 |
int position = 0; |
| 221 |
|
| 222 |
struct synonym_type *synonym; |
| 223 |
struct filter_type *filter = filter_table; |
| 224 |
|
| 225 |
|
| 226 |
if (filter != NULL) { |
| 227 |
while (word[position] != NULL) { |
| 228 |
match = FALSE; |
| 229 |
do { |
| 230 |
if (!strcmp(word[position], filter->word)) { |
| 231 |
for (index = position; word[index + 1] != NULL; |
| 232 |
index++) |
| 233 |
word[index] = word[index + 1]; |
| 234 |
word[index] = NULL; |
| 235 |
match = TRUE; |
| 236 |
} |
| 237 |
filter = filter->next_filter; |
| 238 |
} |
| 239 |
while (filter != NULL && !match); |
| 240 |
filter = filter_table; |
| 241 |
if (!match) |
| 242 |
position++; |
| 243 |
}; |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
if (synonym_table != NULL) { |
| 248 |
for (counter = 0; word[counter] != NULL; counter++) { |
| 249 |
synonym = synonym_table; |
| 250 |
do { |
| 251 |
if (!strcmp(word[counter], synonym->original)) { |
| 252 |
word[counter] = synonym->standard; |
| 253 |
break; |
| 254 |
} |
| 255 |
if (synonym->next_synonym != NULL) |
| 256 |
synonym = synonym->next_synonym; |
| 257 |
else |
| 258 |
break; |
| 259 |
} |
| 260 |
while (TRUE); |
| 261 |
} |
| 262 |
} |
| 263 |
} |