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