+//#define lowercase(c) (c | 0x20)
+#define isrusletter(c) (memchr(koi,c,66)==NULL?0:1)
+
+const char koi[] = {
+193,194,215,199,196,197,163,214,218,201,202,203,204,205,206,207,208,210,
+211,212,213,198,200,195,222,219,221,216,223,217,220,192,209,
+225,226,247,231,228,229,179,246,250,233,234,235,236,237,238,239,240,242,
+243,244,245,230,232,227,254,251,253,248,255,249,252,224,241
+};
+int lowruscase(char c)
+{
+ char *ctmp_p;
+ int ch=0;
+ if (memchr(koi,c,66)==NULL) return koi[0];
+ ch=strlen(koi)-strlen(memchr(koi,c,66));
+ if (ch>33) return ch-33; else return ch;
+}
+/* cp1251 for encoding into koi8-r
+const char win[] = {
+224,225,226,227,228,229,184,230,231,232,233,234,235,236,237,238,239,240,
+241,242,243,244,245,246,247,248,249,252,250,251,253,254,255,
+192,193,194,195,196,197,168,198,199,200,201,202,203,204,205,206,207,208,
+209,210,211,212,213,214,215,216,217,220,218,219,221,222,223
+};*/
+
+
+
+int findruswords(char *message)
+{
+ int i,c,n=0;
+ //char *tmp_p;
+ struct rusletter *pos,*tmp;
+ for (;;)
+ {
+ while (!isrusletter(*message)) if (*message=='\0') return n; else message++;
+ pos=&ruswords;
+ while (isrusletter(*message))
+ {
+ c=lowruscase(*message);
+ /*tmp_p=memchr(koi,message[0],33);
+ if (tmp_p==NULL) return n;
+ c=strlen(koi)-strlen(tmp_p);*/
+ if (pos->next[(int)c]==NULL)
+ {
+ tmp=malloc(sizeof(struct rusletter));
+ if (tmp==NULL)
+ {
+ fprintf(stderr, "findruswords(): malloc failure\n");
+ exit(1);
+ }
+ tmp->nb=0;
+ for (i=0;i<33;i++) tmp->next[i]=NULL;
+ pos->next[(int)c]=tmp;
+ }
+ pos=pos->next[(int)c];
+ message++;
+ }
+ pos->nb++;
+ n++;
+ }
+ return n;
+}
+
+
+void freeruswords(struct rusletter *pos)
+{
+ int i;
+ for (i=0;i<33;i++) if (pos->next[i]!=NULL)
+ {
+ freeruswords(pos->next[i]);
+ free(pos->next[i]);
+ (*pos).next[i]=NULL;
+ }
+}
+