#include "crt.bi"
#include "hunspell.bi"

   dim as FILE ptr wtclst

    /' first parse the command line options '/

    if (__FB_ARGC__ < 4) then
        fprintf(stderr,!"example (now it works with more dictionary files):\n") 
        fprintf(stderr,!"example affix_file dictionary_file file_of_words_to_check\n")
        end(1)
    end if
  
    /' open the words to check list '/
    wtclst = fopen(__FB_ARGV__[__FB_ARGC__ - 1],"r")
    if (wtclst = 0) then
        fprintf(stderr,!"Error - could not open file of words to check\n")
        end(1)
    end if
   
    dim as integer k
    dim as integer dp
    dim as zstring * 101 buf

    dim as Hunhandle ptr pMS= Hunspell_create(__FB_ARGV__[1], __FB_ARGV__[2])
    
    while(fgets(@buf, 100, wtclst)) 
      k = strlen(buf)
      *(@buf + k - 1) = 0
       dp = Hunspell_spell(pMS,@buf)
       if (dp) then
          fprintf(stdout,!"\"%s\" is okay\n",@buf)
          fprintf(stdout,!"\n")
       else
          fprintf(stdout,!"\"%s\" is incorrect!\n",@buf)
          fprintf(stdout,!"   suggestions:\n")
          dim as zstring ptr ptr wlst
          dim as integer ns = Hunspell_suggest(pMS, @wlst,@buf)
          for i as integer =0 to ns-1
            fprintf(stdout,!"    ...'%s'\n",wlst[i])
          next
          Hunspell_free_list(pMS, @wlst, ns)
          fprintf(stdout,!"\n")
       end if
    wend


    fclose(wtclst)
