Mercurial > audlegacy
annotate src/libguess/russian_impl.c @ 3212:59b84ca1b09c trunk
Added my g15composer-based Python script for displaying Now Playing info on the LCD of the Logitech G15 Gaming Keyboard.
author | ssokolow@localhost.localdomain |
---|---|
date | Wed, 01 Aug 2007 22:04:59 -0400 |
parents | e9f66c3905ec |
children | e90e154a353e |
rev | line source |
---|---|
3202
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /* |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
2 * This code is derivitive of librcd. |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
3 * No copyright notice was found. |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
4 */ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
5 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
7 #include <string.h> |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
8 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
9 #include "libguess.h" |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
10 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
11 #define NF_VALUE -2 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
12 #define max(a,b) ((a>b)?a:b) |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
13 #define min(a,b) ((a<b)?a:b) |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
14 #define bit(i) (1<<i) |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
15 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
16 typedef struct lng_stat2 { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
17 unsigned char a; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
18 unsigned char b; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
19 double rate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
20 double srate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
21 double erate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
22 } lng_stat2; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
23 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24 #include "russian_tab.c" |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27 static int end_symbol(char ch) { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 if (ch=='\r'||ch=='\n'||ch==0||ch==' '||ch=='\t'||ch==','||ch=='.'||ch=='!'||ch=='?'||ch==';'||ch=='-'||ch==':'||ch=='"'||ch=='\''||ch==')') return 1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 return 0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32 static int start_symbol(char ch) { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33 if ((ch=='\t')||ch=='\r'||ch=='\n'||(ch==' ')||(ch=='(')||(ch=='"')||(ch=='\'')) return 1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34 return 0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 typedef const struct lng_stat2 *lng_stat2_ptr; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39 static void bfind(const unsigned char *a, lng_stat2_ptr *w, lng_stat2_ptr *k, lng_stat2_ptr *al) { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 const struct lng_stat2 *winptr, *koiptr,*altptr; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41 int ki,wi,ai,d,ws=0,ks=0,as=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 d=npow2>>1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
43 wi=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
44 ki=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
45 ai=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
46 winptr=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
47 koiptr=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
48 altptr=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
49 do{ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
50 d>>=1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
51 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
52 if(!ws){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
53 if (wi>indexes2) wi-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
54 else { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
55 winptr=enc_win+wi-1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
56 if(a[0]==winptr->a){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
57 if(a[1]==winptr->b){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
58 ws=1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
59 }else if(a[1]<winptr->b){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
60 wi-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
61 }else{ //b>win[wi].b |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
62 wi+=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
63 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
64 }else if(a[0]<winptr->a){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
65 wi-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
66 }else{ //a>win[wi].a |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
67 wi+=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
68 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
69 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
70 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
71 if(!ks){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
72 if (ki>indexes2) ki-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
73 else { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
74 koiptr=enc_koi+ki-1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
75 if(a[0]==koiptr->a){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
76 if(a[1]==koiptr->b){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
77 ks=1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
78 }else if(a[1]<koiptr->b){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
79 ki-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
80 }else{ //b>win[wi].b |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
81 ki+=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
82 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
83 }else if(a[0]<koiptr->a){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
84 ki-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
85 }else{ //a>win[wi].a |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
86 ki+=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
87 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
88 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
89 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
90 if(!as){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
91 if (ai>indexes2) ai-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
92 else { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
93 altptr=enc_alt+ai-1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
94 if(a[0]==altptr->a){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
95 if(a[1]==altptr->b){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
96 as=1; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
97 }else if(a[1]<altptr->b){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
98 ai-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
99 }else{ //b>win[wi].b |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
100 ai+=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
101 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
102 }else if(a[0]<altptr->a){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
103 ai-=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
104 }else{ //a>win[wi].a |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
105 ai+=d; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
106 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
107 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
108 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
109 }while(d); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
110 if (ws) *w=winptr; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
111 else *w=NULL; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
112 if (ks) *k=koiptr; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
113 else *k=NULL; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
114 if (as) *al=altptr; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
115 else *al=NULL; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
116 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
117 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
118 static double calculate(double s, double m, double e) { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
119 return s+m+e; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
120 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
121 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
122 static const char *is_win_charset2(const unsigned char *txt, int len){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
123 const struct lng_stat2 *winptr, *koiptr,*altptr; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
124 double winstep,koistep,altstep,winestep,koiestep,altestep,winsstep,koisstep,altsstep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
125 double winstat=0,koistat=0,altstat=0,winestat=0,koiestat=0,altestat=0,winsstat=0,koisstat=0,altsstat=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
126 long j; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
127 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
128 #ifdef _AUTO_DEBUG |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
129 fprintf(stderr,"Word: %s\n",txt); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
130 #endif |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
131 for(j=0;j<len-1;j++){ |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
132 //skip bottom half of table |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
133 if(txt[j]<128 || txt[j+1]<128) continue; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
134 #ifdef _AUTO_DEBUG |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
135 fprintf(stderr,"Pair: %c%c",txt[j],txt[j+1]); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
136 #endif |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
137 bfind(txt+j,&winptr,&koiptr,&altptr); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
138 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
139 if ((j==0)||(start_symbol(txt[j-1]))) { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
140 if (winptr) winsstep=winptr->srate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
141 else winsstep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
142 if (koiptr) koisstep=koiptr->srate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
143 else koisstep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
144 if (altptr) altsstep=altptr->srate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
145 else altsstep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
146 winestep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
147 koiestep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
148 altestep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
149 winstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
150 koistep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
151 altstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
152 #ifdef _AUTO_DEBUG |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
153 fprintf(stderr,", Win %lf, Koi %lf, Alt: %lf\n",winsstep,koisstep,altsstep); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
154 #endif |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
155 } else if ((j==len-2)||(end_symbol(txt[j+2]))) { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
156 if (winptr) winestep=winptr->erate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
157 else winestep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
158 if (koiptr) koiestep=koiptr->erate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
159 else koiestep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
160 if (altptr) altestep=altptr->erate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
161 else altestep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
162 winsstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
163 koisstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
164 altsstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
165 winstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
166 koistep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
167 altstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
168 #ifdef _AUTO_DEBUG |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
169 fprintf(stderr,", Win %lf, Koi %lf, Alt %lf\n",winestep,koiestep,altestep); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
170 #endif |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
171 } else { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
172 if (winptr) winstep=winptr->rate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
173 else winstep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
174 if (koiptr) koistep=koiptr->rate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
175 else koistep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
176 if (altptr) altstep=altptr->rate; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
177 else altstep=NF_VALUE; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
178 winsstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
179 winestep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
180 koisstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
181 koiestep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
182 altsstep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
183 altestep=0; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
184 #ifdef _AUTO_DEBUG |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
185 fprintf(stderr,", Win %lf, Koi %lf, Alt %lf\n",winstep,koistep,altstep); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
186 #endif |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
187 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
188 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
189 winstat+=winstep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
190 koistat+=koistep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
191 altstat+=altstep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
192 winsstat+=winsstep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
193 koisstat+=koisstep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
194 altsstat+=altsstep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
195 winestat+=winestep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
196 koiestat+=koiestep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
197 altestat+=altestep; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
198 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
199 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
200 #ifdef _AUTO_DEBUG |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
201 fprintf(stderr,"Start. Win: %lf, Koi: %lf, Alt: %lf\n",winsstat,koisstat,altsstat); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
202 fprintf(stderr,"Middle. Win: %lf, Koi: %lf, Alt: %lf\n",winstat,koistat,altstat); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
203 fprintf(stderr,"End. Win: %lf, Koi: %lf, Alt: %lf\n",winestat,koiestat,altestat); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
204 fprintf(stderr,"Final. Win: %lf, Koi: %lf, Alt: %lf\n",calculate(winsstat,winstat,winestat),calculate(koisstat,koistat,koiestat),calculate(altsstat,altstat,altestat)); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
205 #endif |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
206 if ((calculate(altsstat,altstat,altestat)>calculate(koisstat,koistat,koiestat))&&(calculate(altsstat,altstat,altestat)>calculate(winsstat,winstat,winestat))) "CP866"; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
207 if (calculate(koisstat,koistat,koiestat)>calculate(winsstat,winstat,winestat)) return "KOI8-R"; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
208 return "CP1251"; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
209 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
210 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
211 const char *guess_ru(const char *buf, int len) |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
212 { |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
213 if (dfa_validate_utf8(buf, len)) |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
214 return "UTF-8"; |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
215 |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
216 return is_win_charset2((const unsigned char *) buf, len); |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
217 } |
e9f66c3905ec
Migrate relevant libRCD code to libguess.
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
218 |