Improved hash on zprocess, and added parsing for "jo".
#include <stdio.h>
#include "dictre.h"
static void give_accent_to_word(const char *word)
{
char def[MAXDEF];
char low[MAXWORD];
char recased[MAXWORD];
enum Case vcase[MAXWORD];
/* Get case */
get_case(vcase, word);
/* Get lowercase version */
get_lowcase_str(low, word);
/* Find the lowercase version */
find_def(low, def);
if (def[0] != 0) /* found */
{
/* Print the word UNTIL a space.
* the definition will have the form:
* ACCENTED_WORD NOMINATIVE1 NOMINATIVE2 ... \n */
char *first_space;
char spacepos;
first_space = strchr(def, ' ');
if (first_space != 0) /* Space found */
{
spacepos = first_space - def;
def[spacepos] = 0; /* Mark an end of string */
reapply_case(recased, def, vcase);
printf("%s", recased);
}
return;
}
/* if first_space == 0 or word not found */
printf("%s", word);
}
static void process_text(FILE *in, int pos, int length)
{
unsigned char tmp[MAXWORD];
int wordpos = 0;
do
{
int c;
/* Check pos only if length >= 0 */
if (length >= 0 && pos >= length)
break;
c = fgetc(in);
if (c == EOF)
break;
if (is_ASCII(c))
{
if (wordpos != 0)
{
tmp[wordpos] = 0;
give_accent_to_word(tmp);
wordpos = 0;
}
putchar(c);
}
else /* non-ASCII - we consider it russian */
{
tmp[wordpos++] = c;
}
pos += 1;
} while(1);
}
int main()
{
init_dictionary();
process_text(stdin, 0, -1);
end_dictionary();
}