NO

Author Topic: Using the Hunspell spelling checker in Pelles C  (Read 3397 times)

Offline CFred

  • Member
  • *
  • Posts: 36
Using the Hunspell spelling checker in Pelles C
« on: September 17, 2023, 04:13:06 PM »
Introduction
Hunspell is a library that can be incorporated into an application to check the spelling of words. It can list suggestions for spelling a word that is not spelled correctly. Several well-known applications use it, including the word processor in the free LibreOffice suite.

Hunspell module
Sadly, Hunspell is not well documented; there is little information on the internet about how to use it in the C language so I developed a module - the HunspellModule.c - that implements functions to make the Hunspell library easy to use in Pelles C. It has been designed to work with Windows 11 (x64). HunspellModule.c  includes functions that:

  • Initialises the Hunspell object
  • Frees the Hunspell object
  • Checks the spelling of a word
  • Adds a word to the 'run-time' dictionary
  • Removes a word from the 'run-time' dictionary
  • Suggests the spelling of a word
  • Frees the list of suggested words
  • Creates/loads a user dictionary
  • Adds a word to the user dictionary.

(The 'run-time' dictionary mentioned above is not a permanent dictionary; it is a temporary dictionary that is cleared when the Hunspell object is freed.)

Instructions on how to use the HunspellModule.c are given in the attached zip file. This also includes:

  • the 64 bit Hunspell DLL, Hunspellx64.dll
  • a dictionary folder containing language files for the UK and USA (Others are available from https://share.across.net/s/mgCY9BABkCJgDYt)
  • the HunspellModule.c file and its header file
  • a sample program to demonstrate how to use HunspellModule.c

Sample program
The sample program has a menu item named Hunspell. This has two submenu items. The first Hunspell submenu item is Get word to check. When selected it prompts the user to enter a word to check. If the word is correct then a message box confirms that word is in the dictionary. If the word is not in the dictionary (possibly because it has been mispelt) then a dialog box opens. This contains a list of suggested words that try to match the word that is not in the dictionary. The dialog box contains three buttons:
    [li]Add word to dictionary - this adds the word to a user dictionary. If the user dictionary does not exist then it is created and the word added to it[/li]
    [li]Ignore word - this adds the word to a run-time dictionary[/li]
    [li]Close - no action is taken with the word.[/li]
    [/list]

    The second Hunspell submenu item is Remove word. When selected, the user is prompted to enter a word. This word will no longer be available in the run-time dictionary.

    Functions not implemented
    The Hunspell library includes several other functions, but the HunspellModule.c does not implement them.

    Acknowledgements

    With thanks to Richard MacCutchan at Code Project for resolving an issue with adding a word to the run-time dictionary.


    Offline frankie

    • Global Moderator
    • Member
    • *****
    • Posts: 2113
    Re: Using the Hunspell spelling checker in Pelles C
    « Reply #1 on: September 17, 2023, 04:35:37 PM »
     Nice :D
    "It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

    Offline John Z

    • Member
    • *
    • Posts: 860
    Re: Using the Hunspell spelling checker in Pelles C
    « Reply #2 on: September 18, 2023, 10:42:19 AM »
    Thanks CFred, looks interesting.

    A LONG time ago I wrote a text editor (ZPAD of course) that included a spell checker OCX from Visual Components Inc.
    Even though ZPAD was written in VB it was fairly advanced for its time, but time moved on and Visual Components didn't it stayed 16 bits.... so ZPAD faded away.

    There are now many good editors so ZPAD wouldn't be groundbreaking, but maybe I'll reincarnate it, or not, .....but nice to have an option to include a spell checker in new projects.

    John Z

    Offline CFred

    • Member
    • *
    • Posts: 36
    Re: Using the Hunspell spelling checker in Pelles C
    « Reply #3 on: September 19, 2023, 01:45:15 PM »
    Visual components can be very useful and save time. I used a number of visual components for Delphi in the past, but in many ways I prefer to build my own component libraries because I can then update them if necessary. The only problem is the time that it takes to do this.

    Eventually I am hoping to build a replacement for the Guide, software that keeps notes in a tree-like interface. This is no longer updated but I still use it although its functionality limited (it doesn't check spellings, for example).