Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9f1c6f0f11
Fetching contributors…

Cannot retrieve contributors at this time

file 1524 lines (1342 sloc) 39.795 kb
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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
/* spell.c */

/* This file contains functions which maintain lists of words, with attributes.
* The list is organized as a tree, which allows it to be searched very quickly.
* Multiple lists can be maintained; the root node of the tree is passed as one
* of the arguments. This type of word list is used for storing the keywords
* in the "syntax" display mode, as well as a real spell-checker.
*/

#include "elvis.h"
#ifdef FEATURE_RCSID
char id_spell[] = "$Id: spell.c,v 1.38 2003/10/17 17:41:23 steve Exp $";
#endif

#define MAXWLEN 100 /* maximum word length */


#if defined(FEATURE_SPELL) || defined(DISPLAY_ANYDESCR)
/* Note that even if the spell-checking feature is disabled, we still need
* the following dictionary management functions, because the syntax display
* mode uses dictionaries for storing keywords.
*/

/* Perform spell-checking on a single letter within a word. Initially (at the
* start of a word), the node should be the top node of a dictionary. For
* each successive letter in the word, the node should be the value returned
* by the previous invocation of spellletter().
*
* Returns a new spell_t node if successful, or NULL if the word is definitely
* not in the list. At the end of the word, you should use the SPELL_IS_GOOD()
* macro to determine whether the word is in the dictionary.
*/
spell_t *spellletter(node, letter)
spell_t *node; /* top of dictionary, or value returned by previous call */
_CHAR_ letter; /* the first/next letter to check */
{

if (!node || letter < node->min || letter > node->max)
return NULL;
return node->link[letter - node->min];
}

/* Perform spell checking on a whole word. If len is 0 then the word is
* assumed to be NUL-terminated; else the word's length is the lesser of len
* or CHARlen(word).
*
* Returns NULL if unknown word, or the spell_t for a known or partial word.
* You should use the SPELL_IS_GOOD() macro to determine whether the return
* value indicates that the word is in the dictionary.
*/
spell_t *spellfindword(node, word, len)
spell_t *node; /* top of the dictionary */
CHAR *word; /* the word to check */
int len; /* maximum length to check, or 0 for any length */
{
/* the default length is determined by looking for a NUL terminator */
if (len == 0)
len = CHARlen(word);

/* check each letter of the word */
for (; len > 0 && *word; len--, word++)
{
/* check the next letter, ignoring case differences */
node = spellletter(node, *word);
if (!node)
break;
}

/* return the final result */
return node;
}

/* Add a word to a dictionary, and return the dictionary's root node.
* Initially (before the first word has been added) the dictionary's root
* node should be NULL. Thereafter, the root node should be whatever this
* function returns.
*
* The 28 least-significant bits of "flags" are unspecified; the calling
* function can use them to store extra information about the word. The 4
* most-significant bits are used for the SPELL_FLAG_COMPLETE, SPELL_FLAG_BAD,
* and SPELL_FLAG_PERSONAL flags. (The last bit is currently unused.)
* spelladdword() always turns on the SPELL_FLAG_COMPLETE bit, so often
* you'll simply leave those 4 bits off.
*
* Later, when you look up a word via spellletter() or spellfindword(), if
* SPELL_IS_GOOD() indicates that the word is in the dictionary, you can use
* (node->flags) to access the word's flags.
*/
spell_t *spelladdword(node, word, flags)
spell_t *node; /* root node of a dictionary */
CHAR *word; /* NULL-terminated word to add */
long flags; /* bitmap of flags */
{
int c, i;
spell_t *newnode;

#ifndef NDEBUG
for (i = 0; word[i]; i++)
assert(!elvspace(word[i]));
assert(i < MAXWLEN);
#endif
#if 0
if (~flags & SPELL_FLAG_COMPLETE)
printf("spelladdword(%s, \"%s\", 0x%lx)\n",
!node?"NULL":node==spellwords?"spellwords":"spelltags",
word, flags);
#endif

/* always set the SPELL_FLAG_COMPLETE flag */
flags |= SPELL_FLAG_COMPLETE;

/* if there is no such node, then create one */
if (!node)
{
node = (spell_t *)safekept(1, sizeof(spell_t));
}

/* if at end of word, then just store the flags and return */
if (!*word)
{
if (node)
node->flags = flags;
return node;
}

/* if this char won't fit in this node, then reallocate node */
c = *word;
if (node->max == 0) /* empty? will this be the first link? */
{
/* link[] already has 1 element, so this will fit */
node->min = node->max = c;
}
else if (c < node->min) /* before current min? */
{
newnode = (spell_t *)safekept(1, sizeof(spell_t) + (node->max - c + 1) * sizeof(spell_t *));
newnode->flags = node->flags;
newnode->min = c;
newnode->max = node->max;
for (i = 0; i <= node->max - node->min; i++)
newnode->link[node->min - c + i] = node->link[i];
safefree(node);
node = newnode;
}
else if (c > node->max) /* after current max? */
{
newnode = (spell_t *)safekept(1, sizeof(spell_t) + (c - node->min + 1) * sizeof(spell_t *));
newnode->flags = node->flags;
newnode->min = node->min;
newnode->max = c;
for (i = 0; i <= node->max - node->min; i++)
newnode->link[i] = node->link[i];
safefree(node);
node = newnode;
}

/* compute the index of this char's node->link[] pointer */
i = c - node->min;

/* recursively add the remainder of the word */
node->link[i] = spelladdword(node->link[i], word + 1, flags);

/* return this node */
return node;
}

/* Discard a spelling dictionary */
void spellfree(node)
spell_t *node; /* root node of a dictionary tree to free */
{
int i;

/* if NULL, then do nothing */
if (!node)
return;

/* recursively free any subtrees */
for (i = 0; i <= node->max - node->min; i++)
spellfree(node->link[i]);

/* free this node */
safefree(node);
}
#endif /* FEATURE_SPELL or DISPLAY_ANYDESCR */


#ifdef FEATURE_SPELL

static void wildspell P_((spell_t *node, CHAR *word, CHAR *partial));
static void savehelp P_((spell_t *node, CHAR *partial));
static void spelldraw P_((CHAR *p, long qty, _char_ font, long offset));

/* font to use to highlight spelling errors */
char spellfont;

/* dictionaries */
spell_t *spelltags; /* spelling words from "tags" files */
spell_t *spellwords; /* spelling words from "words" file, or :words cmd */

/* font-dependent spellcheck limits */
static spellcheck_t spelllimit[128];
static ELVBOOL spellset[128];

/* info about the last value displayed via the "spellshow" option, or returned
* by the last spellfix() function call.
*/
static MARKBUF showbegin, showend; /* extents of the word */
static CHAR showsuggest[100]; /* suggested alternatives */
static long showchange; /* used to detect changes */


/* prepare for doing some spell-checking. This updates the "tags" dictionary
* if there are any user buffers which have "spell" set.
*/
void spellbegin()
{
char *newstamp;
 static char oldstamp[20]; /* YYYY-MM-DDThh:mm:ss */
char *path;
char *fullname;
CHAR tagname[MAXWLEN];
BUFFER buf;
int c, i;
FILE *fp;

/* locate font (only required the first time) */
if (!spellfont)
{
spellfont = colorfind(toCHAR("spell"));
colorset(spellfont, toCHAR("underlined"), ElvFalse);
}

/* if no user buffers have "spell" set, then do nothing */
for (buf = buflist((BUFFER)NULL);
buf && (o_internal(buf) || !o_spell(buf));
buf = buflist(buf))
{
}
if (!buf)
return;

/* if timestamp of "tags" hasn't changed, then do nothing */
newstamp = dirtime("tags");
if (!newstamp || !strcmp(newstamp, oldstamp))
return;
strcpy(oldstamp, newstamp);

/* free the old spelltags dictionary, if any */
if (spelltags)
{
spellfree(spelltags);
spelltags = NULL;
}

/* for each file in the elvispath or tagpath... */
for (path = tochar8(o_elvispath ? o_elvispath : o_tags);
path;
path = (path == tochar8(o_tags)) ? NULL : tochar8(o_tags))
{
for (fullname = iopath(path, "tags", ElvTrue);
fullname;
fullname = iopath(NULL, "tags", ElvTrue))
{
/* for each tag in the file... */
fp = fopen(fullname, "r");
if (!fp)
continue;
for (i = 0; (c = getc(fp)) != EOF; )
{
if (c == '\n')
i = 0;
else if (i < 0)
continue;
else if (elvspace(c))
{
tagname[i] = '\0';
if (tagname[0] > '!' && i < MAXWLEN - 1)
spelltags = spelladdword(spelltags, tagname, 0);
i = -1;
}
else if (i < MAXWLEN - 2)
tagname[i++] = c;
}
fclose(fp);
}
}
}

/* This file pointer refers to a list of natural-language words */
static FILE *wordfp;
static long wordsize;

/* Search through the word file for a given word, using a binary search.
* If found, then add the word to the given dictionary. If not found, then
* still add it but with the SPELL_FLAG_BAD bit set. Return TRUE if good,
* FALSE if bad.
*/
ELVBOOL spellsearch(word)
CHAR *word; /* word to look for */
{
long pos, step;
int c;
CHAR *letterptr;

/* if the file hasn't been opened yet, then open it now */
if (!wordfp)
{
/* if no file is specified, then don't bother */
if (!o_spelldict)
return ElvFalse;

/* try to open the file. If error, then clobber the option */
wordfp = fopen(tochar8(o_spelldict), "rb");
if (!wordfp)
{
optputstr(toCHAR("spelldict"), toCHAR(""), ElvFalse);
return ElvFalse;
}

/* get the size of the file */
fseek(wordfp, 0L, SEEK_END);
wordsize = ftell(wordfp);
}

/* perform binary search until within a few bytes of word */
pos = 0;
step = wordsize / 2;
while (step > 100)
{
/* find start of line after seek position */
fseek(wordfp, pos + step, SEEK_SET);
while ((c = getc(wordfp)) != '\n' && c != EOF)
{
}

/* compare to word */
for (letterptr = word;
(c = elvtolower(getc(wordfp))) == *letterptr;
letterptr++)
{
}

/* exact match, by any chance? */
if (*letterptr == '\0' && elvspace(c))
{
spellwords = spelladdword(spellwords, word, 0);
return ElvTrue;
}

/* if EOF or greater then we want to step back; else forward */
if (c != EOF && c < *letterptr)
pos += step;
step /= 2;
}

/* we're close. skip to start of next line, and then read linearly */
fseek(wordfp, pos, SEEK_SET);
if (pos != 0)
{
while ((c = getc(wordfp)) != '\n' && c != EOF)
{
}
}

/* now read each word linearly, comparing to desired word */
letterptr = word;
while ((c = elvtolower(getc(wordfp))) != EOF && c <= *letterptr)
{
if (c == '\r')
continue;
else if (c == '\n')
{
if (*letterptr == '\0')
break;
else
letterptr = word;
}
else if (c == *letterptr)
letterptr++;
else
{
/* mismatch -- skip to next word */
while ((c = getc(wordfp)) != EOF && c != '\n')
{
}
letterptr = word;
}
}

/* if the above search was successful, then *letterptr should point
* to the NUL at the end of the word and c should be non-whitespace.
* Any other result means the word wasn't found.
*/
if (*letterptr || !elvspace(c))
{
spellwords = spelladdword(spellwords, word, SPELL_FLAG_BAD);
return ElvFalse;
}
else
{
spellwords = spelladdword(spellwords, word, 0);
return ElvTrue;
}
}

void spellend()
{
/* if the words file is open, close it */
if (wordfp)
{
fclose(wordfp);
wordfp = NULL;
}
}

/* Given a MARK for the start of a word, perform spell checking on the
* word, and return the result. Move the mark past the end of the word.
*/
spellresult_t spellcheck(mark, tagonly, cursoff)
MARK mark; /* start of word */
ELVBOOL tagonly; /* skip the natural-language dictionary? */
long cursoff; /* offset of cursor */
{
spell_t *tag = spelltags;
spell_t *word = tagonly ? NULL : spellwords;
spell_t *icword = word;
CHAR *cp, letter;
CHAR wordbuf[MAXWLEN], swordbuf[MAXWLEN];
int wlen, slen, i;
spellresult_t result;
long wordoff;

#if 0
disp_t *dm;

/* choose the display mode, via the bufdisplay option */
dm = ...
#endif

/* get the first letter. The character at the mark is assumed to
* be the first letter of the word, even if it isn't a letter.
*/
scanalloc(&cp, mark);
wordoff = markoffset(mark);
#if 0
if (dm->wordletter)
letter = (*dm->wordletter)(cp, ElvTrue);
else
#endif
{
letter = *cp;
scannext(&cp);
}

/* check each character of the word */
wlen = 0;
do
{
/* add this letter to the word buffer */
if (wlen < MAXWLEN)
wordbuf[wlen++] = elvtolower(letter);

/* look up this letter in the relevant dictionaries */
tag = spellletter(tag, letter);
word = spellletter(word, letter);
icword = spellletter(icword, elvtolower(letter));

/* get the next letter */
if (!cp)
letter = '\0';
else if (elvalnum(*cp) || *cp == '_')
{
letter = *cp;
scannext(&cp);
}
else if (*cp == '\'')
{
letter = *cp;
scannext(&cp);
if (!cp || !elvalpha(*cp))
{
if (cp)
scanprev(&cp);
letter = '\0';
}
}
#if 0
else if (dm->wordletter)
letter = (*dm->wordletter)(cp, ElvFalse);
#endif
else
letter = '\0';

} while (letter);

/* Move the mark past the end of the word. We do this regardless of
* whether the word is correct or not. This is slightly complicated
* by the fact that we may have hit the end of the buffer, in which
* case cp would be NULL.
*/
if (cp)
marksetoffset(mark, markoffset(scanmark(&cp)));
else
marksetoffset(mark, o_bufchars(markbuffer(mark)));
scanfree(&cp);

/* if too long to be a valid word, then it must be bad */
if (wlen >= MAXWLEN)
return SPELL_BAD;
wordbuf[wlen] = '\0';

/* Decide whether to use "tag" or "word"/"icword". We want to use
* "tag" if "word"/"icword" is NULL or incomplete; otherwise use
* "word"/"icword".
*/
if (!word || (~word->flags & SPELL_FLAG_COMPLETE))
word = icword;
if (!word || (tag && ((~word->flags & SPELL_FLAG_COMPLETE) || (word->flags & SPELL_FLAG_BAD))))
word = tag;

/* If the cursor is inside or at the end of an unknown or incomplete
* word, then pretend it is known to be "good".
*/
if (wordoff <= cursoff
&& cursoff <= markoffset(mark)
&& (!word || (~word->flags & SPELL_FLAG_COMPLETE)))
return SPELL_GOOD;

/* If unknown, and the natural-language dictionary is allowed, then
* search for the word. Exception: If the cursor is located at the
* end of an incomplete word, then don't try this until the user
* completes the word.
*/
if (!tagonly
&& o_spelldict
&& (!word || (~word->flags & SPELL_FLAG_COMPLETE)))
{
if (!spellsearch(wordbuf) && o_spellsuffix)
{

/* not found as given -- try suffix substitution */
for (cp = o_spellsuffix; *cp; cp++)
{
/* skip whitespace between suffixes */
if (elvspace(*cp))
continue;

/* count the length of this suffix */
for (slen = 0; cp[slen] && cp[slen] != '=' && !elvspace(cp[slen]); slen++)
{
}

/* does the word end with this suffix? */
if (slen < wlen && !CHARncmp(wordbuf + wlen - slen, cp, slen))
{
/* Yes! Use this suffix */
CHARcpy(swordbuf, wordbuf);
if (cp[slen] == '=')
{
for (i = 0; cp[slen + 1 + i] && !elvspace(cp[slen + 1 + i]); i++)
swordbuf[wlen - slen + i] = cp[slen + 1 + i];
swordbuf[wlen - slen + i] = '\0';
}
else
swordbuf[wlen - slen] = '\0';

/* Search for the alternate-suffix word.
* If that word is found and is good,
* then also add the word as it appears
* in the buffer.
*/
word = spellfindword(spellwords,swordbuf,0);
if (SPELL_IS_GOOD(word)
|| spellsearch(swordbuf))
{
spellwords = spelladdword(spellwords, wordbuf, 0);
}
else
{
spellwords = spelladdword(spellwords, wordbuf, SPELL_FLAG_BAD);
}

/* Stop after trying one suffix */
break;
}

/* skip to end of this suffix */
while (*cp && !elvspace(*cp))
cp++;
}
}
word = spellfindword(spellwords, wordbuf, wlen);
}

/* Classify the results */
if (!word)
result = SPELL_UNKNOWN;
else if (~word->flags & SPELL_FLAG_COMPLETE)
result = SPELL_INCOMPLETE;
else if (word->flags & SPELL_FLAG_BAD)
result = SPELL_BAD;
else
result = SPELL_GOOD;

return result;
}

/* Locate each word on the screen, and highlight any that appear to be spelled
* incorrectly. Note that the attributes affect the spelling rules, and also
* that in "markup" display modes, the markups themselves are normally hidden
* and hence won't be spell checked.
*/
void spellhighlight(win)
WINDOW win;
{
MARKBUF mark;
int i, bottom;
int offset;
char newfont, combofont;
long end;
CHAR *cp;
spellresult_t result;
ELVBOOL inputmode; /* are we in input mode? */

/* if spell-checking is disabled, then do nothing */
if (!o_spell(markbuffer(win->cursor)))
return;

/* spell checking makes no sense in "hex" mode. In fact, it is worse
* than useless since a punctuation character's hex value may look like
* a two-letter word on the screen, which confuses the spell checker.
*/
if (win->md == &dmhex)
return;

/* determine whether we're in input mode */
inputmode = (ELVBOOL)((win->state->mapflags & MAP_INPUT) != 0);

/* for each word on the screen... */
scanalloc(&cp, win->di->topmark);
offset = markoffset(win->di->topmark);
end = markoffset(win->di->bottommark);
i = 0;
bottom = (win->di->rows - 1) * win->di->columns;
mark.buffer = markbuffer(win->di->topmark);
for (; cp && offset < end; scannext(&cp), offset++)
{
/* skip if not on screen */
while (i < bottom && win->di->offsets[i] < offset)
i++;
if (i > bottom)
break;
if (win->di->offsets[i] > offset)
continue;

/* Skip if non-alphanumeric */
if (!elvalnum(*cp) && *cp != '_')
#if 0
&& dm->wordletter && !(*dm->wordletter)(cp, ElvTrue))
#endif
continue;

/* skip if font has "graphic" attribute or SPELL_CHECK_NONE */
newfont = (win->di->newfont[i] & 0x7f);
if (colorinfo[(int)newfont].da.bits & COLOR_GRAPHIC
|| spelllimit[(int)newfont] == SPELL_CHECK_NONE)
continue;

/* okay, we have found a word. "cp" points to it, "offset" is
* its offset, and "i" is its position in the screen. Now we
* need to check the status of that word. (This also locates
* the end of the word, by moving "mark".)
*/
mark.offset = offset;
result = spellcheck(&mark,
(ELVBOOL)(spelllimit[(int)newfont] == SPELL_CHECK_TAGONLY),
inputmode ? markoffset(win->cursor) : INFINITY);

/* if word began with a digit, then ignore errors */
if (elvdigit(*cp))
result = SPELL_GOOD;

/* if sidescrolling is enabled, and this word began at the
* left edge of the screen, and that edge isn't the start of
* a line, then what we've really done here is spell-check
* a partial word, not a whole word. To avoid possible false
* alarms, skip this word. (We still had to call spellcheck()
* to find the end of the word.)
*/
if (!o_wrap(win)
&& (i % win->di->columns) == 0
&& win->di->skipped > 0)
{
/* move to the end of the word. */
offset = mark.offset;
scanseek(&cp, &mark);
continue;
}

/* if the word is bad, then highlight it */
if (result == SPELL_BAD
|| result == SPELL_UNKNOWN
|| (result == SPELL_INCOMPLETE && markoffset(win->cursor) != mark.offset))
{
while (i < bottom
&& win->di->offsets[i] >= offset
&& win->di->offsets[i] < mark.offset)
{
newfont = win->di->newfont[i];
if (!(newfont & 0x7f))
newfont |= o_hasfocus(win)
? COLOR_FONT_NORMAL
: COLOR_FONT_IDLE;
combofont = win->di->newfont[i] =
colortmp(newfont, spellfont);
i++;
}
}

/* move to the end of the word. */
offset = mark.offset;
scanseek(&cp, &mark);
}
scanfree(&cp);
}


static BUFFER savebuf; /* buf to append lines to, or NULL to show */
static CHAR saveline[200]; /* buffer, holds a single line of words */
static CHAR savecmd[20]; /* beginning of line: either "" or "try words"*/
static CHAR saveword[MAXWLEN]; /* current word, or partial word */
static CHAR saveflag; /* flag within saveline: either '+' or '-' */
static long savecount; /* number of personal words found */

static void savehelp(node, partial)
spell_t *node; /* node to dump */
CHAR *partial;/* partial word */
{
CHAR flag[2];
MARKBUF end;
int i;

/* if no such node, then do nothing */
if (!node)
return;

/* if this is a personal word, then dump it */
if (node->flags & SPELL_FLAG_PERSONAL)
{
/* mark the end of this word */
*partial = '\0';

/* determine whether the flag is + or - */
if (node->flags & SPELL_FLAG_BAD)
flag[0] = '-';
else
flag[0] = '+';
flag[1] = '\0';

/* if it won't fit on this line, then start a new one */
if (CHARlen(saveline) + (partial - saveword) > 77)
{
CHARcat(saveline, toCHAR("\n"));
if (savebuf)
{
end.buffer = savebuf;
end.offset = o_bufchars(savebuf);
bufreplace(&end, &end, saveline, CHARlen(saveline));
}
else
drawextext(windefault, saveline, CHARlen(saveline));
CHARcpy(saveline, savecmd);
saveflag = '+';
}

/* add the word */
if (*saveline)
CHARcat(saveline, toCHAR(" "));
if (*flag != saveflag)
{
CHARcat(saveline, flag);
saveflag = *flag;
}
CHARcat(saveline, saveword);
savecount++;
}

/* check longer words too */
for (i = node->min; i <= node->max; i++)
{
*partial = i;
savehelp(node->link[*partial - node->min], partial+1);
}
}

/* This function walks through the spellwords tree, and outputs any any
* personal words that it finds there. This is used for both :mkexrc,
* and for listing the words via :word without arguments.
*/
void spellsave(custom)
BUFFER custom; /* buffer to append spell commands to, or NULL */
{
MARKBUF end;
int i, col, len;
spellcheck_t level;

/* use savehelp() to recursively search for personal words */
savebuf = custom;
if (custom)
CHARcpy(savecmd, toCHAR("try words"));
else
*savecmd = '\0';
CHARcpy(saveline, savecmd);
saveflag = '+';
savecount = 0L;
savehelp(spellwords, saveword);

/* finish the last command */
if (savecount > 0)
{
CHARcat(saveline, toCHAR("\n"));
if (custom)
{
end.buffer = custom;
end.offset = o_bufchars(custom);
bufreplace(&end, &end, saveline, CHARlen(saveline));
}
else
{
drawextext(windefault, saveline, CHARlen(saveline));
}
}

/* if just displaying, then we're done. */
if (!custom)
return;

/* also save the :check commands */
end.buffer = custom;
end.offset = o_bufchars(custom);
for (level = SPELL_CHECK_ALL; level <= SPELL_CHECK_NONE; level++)
{
for (i = 1, col = 0; i < colornpermanent; i++)
{
if (spelllimit[i] != level || !spellset[i])
continue;

/* start a new command? */
len = CHARlen(colorinfo[i].name);
if (col == 0 || col + len > 77)
{
if (col > 0)
{
bufreplace(&end, &end, toCHAR("\n"), 1);
end.offset++;
}
bufreplace(&end, &end,
toCHAR(level == SPELL_CHECK_NONE
? "try check -"
: level == SPELL_CHECK_TAGONLY
? "try check +"
: "try check *"),
11);
end.offset += 11;
col = 11;
}
else
{
/* space between words */
bufreplace(&end, &end, blanks, 1);
end.offset++;
col++;
}

/* add this font name */
bufreplace(&end, &end, colorinfo[i].name, len);
end.offset += len;
}

/* end the line */
if (col > 0)
{
bufreplace(&end, &end, toCHAR("\n"), 1);
end.offset++;
}
}
}


/* These indicate where any found matches should go */
static CHAR *wildbuf; /* buffer */
static int wildlen; /* size of wildbuf */
static int wildused; /* used portion of wildbuf */
static ELVBOOL wildcap; /* should matching words be capitalized? */

/* Look up a potential corrected spelling. This differs from spellfindword()
* in the way it handles case mismatches, and also it allows ' ' as a wildcard
* meaning "any single character". If the word is found, then it will be
* copied from the "partial" buffer onto the end of the "wildbuf".
*/
static void wildspell(node, word, partial)
spell_t *node; /* tree to search */
CHAR *word; /* partial candidate word to search for */
CHAR *partial; /* partial actual word found */
{
int len, i;

/* if no node, then do nothing */
if (!node)
return;

/* if reached end of word, and it is complete, then use it */
if (!*word)
{
len = (int)(partial - saveline);
if (SPELL_IS_GOOD(node)
&& (int)(partial - saveline) < wildlen - wildused - 2
&& (wildused < len || CHARncmp(saveline, wildbuf + wildused - len, len)))
{
if (wildused != 0)
wildbuf[wildused++] = ' ';
CHARncpy(&wildbuf[wildused], saveline, len);
if (wildcap)
wildbuf[wildused] = elvtoupper(*saveline);
wildused += len;
}
return;
}

/* if ' ' then try every character */
if (*word == ' ')
{
len = node->max;
for (i = node->min; i <= node->max; i++)
{
*partial = (CHAR)i;
if (node->link[*partial - node->min])
wildspell(node->link[*partial - node->min],
word + 1, partial + 1);
}
}
else
{
/* try an exact match for this character */
*partial = *word;
if (*partial >= node->min && *partial <= node->max
&& node->link[*partial - node->min])
wildspell(node->link[*partial - node->min],
word + 1, partial + 1);

/* if lowercase, then try an uppercase version of the same */
if (elvlower(*word))
{
*partial = elvtoupper(*word);
if (*partial >= node->min && *partial <= node->max
&& node->link[*partial - node->min])
wildspell(node->link[*partial - node->min], word + 1, partial + 1);
}
}
}

/* Perform spell-fixing on a whole word.
*
* The result is stored into the "result" CHAR buffer. This will be "" for
* valid words, "?" for invalid words with no suggestions, or a space-delimited
* list of suggestions for invalid words that can be derived from valid ones.
*/
void spellfix(word, result, resultlen, tagonly)
CHAR *word; /* the word to fix */
CHAR *result; /* where to store the result */
int resultlen; /* maximum length of result */
ELVBOOL tagonly; /* ignore natural-language dictionary */
{
int i;
CHAR tmp, tmp2;
int len; /* length of word */
spell_t *dict, *found;
CHAR *wordcopy;

static CHAR *loadeddict;

/* if given "" or number, then return "" */
if (!*word || elvdigit(*word))
{
*result = '\0';
return;
}

/* lookup the word unchanged. If exactly right then return "" */
found = spellfindword(spelltags, word, 0);
if (SPELL_IS_GOOD(found))
{
*result = '\0';
return;
}
if (!tagonly)
{
found = spellfindword(spellwords, word, 0);
if (SPELL_IS_GOOD(found))
{
*result = '\0';
return;
}
}

/* Detect whether the word is capitalized -- meaning the first
* character is uppercase but all other characters are lowercase
*/
wildcap = (ELVBOOL)elvupper(word[0]);
for (len = 1; wildcap && word[len]; len++)
if (elvupper(word[len]))
wildcap = ElvFalse;

/* copy the word into a private buffer, converting to lowercase */
for (len = 0; word[len]; len++)
saveword[len] = elvtolower(word[len]);
saveword[len] = '\0';
wildbuf = result;
wildlen = resultlen;
wildused = 0;

/* if doing natural-language search, then look for an exact (except
* for possible case differences) match one more time.
*/
if (!tagonly)
{
found = spellfindword(spellwords, saveword, 0);
if (SPELL_IS_GOOD(found))
{
*result = '\0';
return;
}
}

/* if the "spellautoload" option is set, and the "spelldict" hasn't
* been loaded since the last time it was changed, then load it now.
*/
if (o_spellautoload
&& o_spelldict
&& (!loadeddict || CHARcmp(o_spelldict, loadeddict)))
{

/* Save a copy of the word. This is important because the
* spellload() and spellshow() functions use the same buffer,
* so after loading a file, the "word" variable always ends up
* containing the last word from the file -- not the one we
* want to look up now.
*/
wordcopy = CHARdup(word);

/* load the file */
spellload(tochar8(o_spelldict), ElvFalse);

/* remember that we tried this dictionary */
if (loadeddict)
safefree(loadeddict);
loadeddict = CHARkdup(o_spelldict);

/* Recursively look up the word. We do it recursively so we
* can come back and free the local copy of the word.
*/
spellfix(wordcopy, result, resultlen, tagonly);
safefree(wordcopy);
return;
}

/* check both dictionaries -- natural language words first */
for (dict = (spellwords && !tagonly) ? spellwords : spelltags;
dict;
dict = (dict == spelltags) ? NULL : spelltags)
{
/* never force capitalization for words from "tags" */
if (dict == spelltags)
wildcap = ElvFalse;

/* check for case differences */
wildspell(dict, saveword, saveline);

/* check derivations with letters transposed */
for (i = 0; saveword[i + 1]; i++)
{
tmp = saveword[i];
saveword[i] = saveword[i + 1];
saveword[i + 1] = tmp;

wildspell(dict, saveword, saveline);

saveword[i + 1] = saveword[i];
saveword[i] = tmp;
}
if (wildlen < wildused + 2 * len)
break;

/* check for derivations with letters deleted */
tmp = '\0';
for (i = len - 1, tmp2 = '\0'; i >= 0; i--)
{
tmp = saveword[i];
saveword[i] = tmp2;

wildspell(dict, saveword, saveline);

tmp2 = tmp;
}
for (i = 0; i < len; i++)
{
tmp2 = saveword[i];
saveword[i] = tmp;
tmp = tmp2;
}
if (wildlen < wildused + 2 * len)
break;

/* check for derivations with one letter inserted */
saveword[len + 1] = '\0';
for (i = len, tmp2 = '\0'; i >= 0; i--)
{
saveword[i + 1] = saveword[i];
saveword[i] = ' ';

wildspell(dict, saveword, saveline);
}
for (i = 0; i <= len; i++)
saveword[i] = saveword[i + 1];
if (wildlen < wildused + 2 * len)
break;

/* check for derivations with one letter changed */
for (i = len - 1; i >= 0; i--)
{
tmp = saveword[i];
saveword[i] = ' ';

wildspell(dict, saveword, saveline);

saveword[i] = tmp;
}
if (wildlen < wildused + 2 * len)
break;

/* check for two words that have been run together */
for (i = 1;
i <= len - 1 && (found = spellfindword(dict, saveword, i));
i++)
{
if (!SPELL_IS_GOOD(found))
continue;
CHARncpy(saveline, saveword, i);
saveline[i] = '/';
wildspell(dict, saveword + i, saveline + i + 1);
}
if (wildlen < wildused + 2 * len)
break;
}

/* We never want to return "" for misspelled words. If nothing else
* was found, then return a "?" instead.
*/
if (wildused == 0)
result[wildused++] = '?';
result[wildused] = '\0';
}


/* This returns the value shown by the "show=spell" option. The return value
* is a static buffer; you don't need to free it.
*/
CHAR *spellshow(cursor, font)
MARK cursor; /* the window's cursor */
_char_ font; /* the font at the cursor (may be temp or selected) */
{
MARK left;
CHAR *word;
CHAR n, *s;

/* Strip off "selected" bit. If no font given, then assume "normal" */
font &= 0x7f;
if (!font)
font = 1;

/* If this font isn't supposed to be checked, then return "" */
*showsuggest = '\0';
if (spelllimit[font] == SPELL_CHECK_NONE)
return showsuggest;

/* Get the word at the cursor. If none, then return "" */
showend = *cursor;
left = wordatcursor(&showend, ElvTrue);
if (!left)
return showsuggest;
showbegin = *left;
word = bufmemory(&showbegin, &showend);

/* Generate the list of suggestions */
spellfix(word, showsuggest, QTY(showsuggest),
(ELVBOOL)(spelllimit[font] == SPELL_CHECK_TAGONLY));

/* Insert numbers before the first 9 words, if there's room */
if (*showsuggest != '?' && CHARlen(showsuggest) + 19 < QTY(showsuggest))
{
for (n = '1', s = showsuggest; n <= '9' && *s; n++)
{
/* insert a number here */
memmove(s + 2, s, QTY(showsuggest) - (s - showsuggest));
*s++ = n;
*s++ = '=';

/* move to start of next word, if any */
while (*s && !elvspace(*s))
s++;
while (elvspace(*s))
s++;
}
}

/* Remember the buffer version, so we can detect obsolete info */
showchange = markbuffer(cursor)->changes;

/* Clean up & return */
safefree(word);
return showsuggest;
}


/* replace a misspelled word with a suggested alternative */
ELVBOOL spellcount(cursor, count)
MARK cursor; /* which word the user wants to change */
long count; /* which alternative to use */
{
CHAR *word;
long len;

/* If alternatives are obsolete, or cursor has moved to a different
* word, or there are no alternatives, then fail
*/
if (markbuffer(cursor)->changes != showchange
|| markbuffer(cursor) != showbegin.buffer
|| markoffset(cursor) < showbegin.offset
|| markoffset(cursor) >= showend.offset
|| !*showsuggest
|| *showsuggest == '?')
return ElvFalse;

/* Find the start of the requested alternative. If there aren't
* that many alternatives, then fail.
*/
for (word = showsuggest; *word && count > 1; word++)
{
if (*word == ' ')
count--;
}
if (!*word)
return ElvFalse;

/* Skip past the number, if there is one */
while (elvdigit(*word))
word++;
if (*word == '=')
word++;

/* Find the length of this alternative. Also, convert an '/' characters
* into spaces.
*/
for (len = 1; word[len] && word[len] != ' '; len++)
{
if (word[len] == '/')
word[len] = ' ';
}

/* Replace the original word with the alternative */
bufreplace(&showbegin, &showend, word, len);
return ElvTrue;
}

/* adjust the spell-checking for a given font */
void spellcheckfont(fontname, check, bang)
CHAR *fontname; /* name of font to adjust */
spellcheck_t check; /* new setting */
ELVBOOL bang; /* hidden? */
{
int font;
CHAR *flag = toCHAR("*+-");
int col, len;
spellcheck_t level;

/* if given a fontname, then adjust it */
if (fontname)
{
/* find the font */
font = colorfind(fontname);
if (!font)
return;

/* store the setting */
spelllimit[font] = check;
spellset[font] = (ELVBOOL)!bang;

return;
}

/* else just list the settings */

for (level=SPELL_CHECK_ALL; level <= SPELL_CHECK_NONE; level++, flag++)
{
if (level < check)
continue;

for (font = 1, col = -1; font < colornpermanent; font++)
{
/* skip if not one that we care about */
if (spelllimit[font] != level
|| (!spellset[font] && !bang))
continue;

/* if won't fit on this line, then start a new line */
len = CHARlen(colorinfo[font].name);
if (col < 0 || col + 2 + len > o_columns(windefault))
{
if (col > 0)
drawextext(windefault, toCHAR("\n"), 1);
drawextext(windefault, flag, 1);
col = 1;
}
else /* space between names */
{
drawextext(windefault, blanks, 1);
col++;
}

/* write the name of this font */
drawextext(windefault, colorinfo[font].name, len);
col += len;
}

/* if last line didn't end, then end it now */
if (col > 0)
drawextext(windefault, toCHAR("\n"), 1);
}
}

/* This function is called by colortmp() to alert the spell-checker about any
* new, temporary fonts.
*/
void spelltmp(oldfont, newfont, combofont)
int oldfont,newfont;/* two fonts that were combined */
int combofont; /* the resulting temporary font */
{
/* make the combo font use the more restrictive checking style from
* either of its parent fonts.
*/
if (spelllimit[oldfont] > spelllimit[newfont])
spelllimit[combofont] = spelllimit[oldfont];
else
spelllimit[combofont] = spelllimit[newfont];
}

/* Scan a file for words. Add each word to the spellwords dictionary, marked
* as "good" words. Optionally mark them as being "personal" words too.
*/
void spellload(filename, personal)
char *filename; /* name of file to scan */
ELVBOOL personal; /* mark new words as "personal" ? */
{
FILE *fp;
int i, c;
spell_t *node;

/* Try to open the file. If failed, return silently */
fp = fopen(filename, "r");
if (!fp)
return;

/* find each word in the file */
for (i = 0; (c = getc(fp)) != EOF; )
{
/* apostrophes sometimes need special treatment */
if (c == '\'' && (i == 0 || !elvalpha(saveword[i - 1])))
{
c = getc(fp);
ungetc(c, fp);
c = elvalpha(c) ? '\'' : ' ';
}

if (i == 0 && elvalnum(c))
{
/* start of a new word */
saveword[i++] = elvtolower(c);
}
else if (i > 0 && (elvalnum(c) || c == '_' || c == '\'') && i < MAXWLEN - 1)
{
/* continuation of a word */
saveword[i++] = elvtolower(c);
}
else if (i > 0 && i < MAXWLEN)
{
/* end of a word */
saveword[i] = '\0';

/* add the word */
if (elvalnum(saveword[0]))
{
if (personal)
{
node = spellfindword(spellwords, saveword, i);
if (node && !SPELL_IS_GOOD(node))
node->flags = SPELL_FLAG_COMPLETE | SPELL_FLAG_PERSONAL;
else
spellwords = spelladdword(spellwords, saveword, SPELL_FLAG_PERSONAL);
}
else
{
spellwords = spelladdword(spellwords, saveword, 0);
}
}

/* prepare for next word */
i = 0;
}
}
fclose(fp);
}


static MARK cursor;
static long badword;
static ELVBOOL inword;

/* This function is used as the "draw" function by a display mode's image()
* function. The spellnext() needs this to spell-check words that aren't
* necessarily on the screen, so it can find the next bad one.
*/
static void spelldraw(p, qty, font, offset)
CHAR *p; /* first letter of text to draw */
long qty; /* quantity to draw (negative to repeat *p) */
_char_ font; /* font code of the text */
long offset; /* buffer offset of *p */
{
MARKBUF mark; /* a temporary mark */

/* if we've already found a bad word, then skip this. */
if (badword >= 0)
return;

/* repeated characters, or graphic chars can't contain words */
if (qty < 1L
|| colorinfo[(int)font].da.bits & COLOR_GRAPHIC)
{
inword = ElvFalse;
return;
}

/* check for words in the characters */
for (; --qty >= 0; p++, offset++)
{
/* if non-letter, then we aren't in a word anymore */
if (!inword && !elvalnum(*p) && *p != '_')
continue;
if (!elvalnum(*p) && *p != '_' && !(*p == '\'' && elvalpha(p[1])))
{
inword = ElvFalse;
continue;
}

/* If we're in a word that we already checked, then ignore it */
if (inword)
continue;

/* Else we're at the start of a word */
inword = ElvTrue;

/* Ignore words before the cursor, or in an unchecked font,
* or which start with a digit.
*/
if (offset <= markoffset(cursor)
|| spelllimit[font] == SPELL_CHECK_NONE
|| elvdigit(*p))
continue;

/* If this word is bad, then set badword to its offset */
if (spellcheck(marktmp(mark, markbuffer(cursor), offset),
(ELVBOOL)(spelllimit[font] == SPELL_CHECK_TAGONLY),
markoffset(cursor)) != SPELL_GOOD)
{
badword = offset;
break;
}
}
}

/* Locate the next misspelled word. This uses the window's current display
* mode, regardless of the buffer's o_bufdisplay(buf) setting. If there is
* no misspelled word between the cursor and the end of the file, then it
* returns NULL; else it returns the start of the word
*/
MARK spellnext(win, curs)
WINDOW win; /* the window whose display mode is to be used */
MARK curs; /* find the first word after this */
{
static MARKBUF mark; /* the return mark (also internal temp mark) */
MARK line; /* used during scanning/drawing text */
long bufchars;

/* Always fail if no window, or if in "hex" mode */
if (!win || win->md == &dmhex)
return NULL;

/* Note: Since spell checking is font-sensitive, we must format the
* text as though we were updating the display... but instead of
* drawing the formatted text, we look for words in it.
*/
cursor = curs;
inword = ElvFalse;
badword = -1;
bufchars = o_bufchars(markbuffer(cursor));
line = (*win->md->setup)(win, cursor, markoffset(cursor),
marktmp(mark, markbuffer(cursor), bufchars), win->mi);
while (line && markoffset(line) < bufchars && badword < 0L)
line = (*win->md->image)(win, line, win->mi, spelldraw);

/* if we found a bad word, then return its MARK; else return NULL */
if (badword >= 0)
return marktmp(mark, markbuffer(curs), badword);
return NULL;
}
#endif /* FEATURE_SPELL */
Something went wrong with that request. Please try again.