Simple utility to turn swipes into words -- "plugin" for wvkbd to enable swipe-typing under wayland SXMO.
Diffstat (limited to 'mapScore.c')
| -rw-r--r-- | mapScore.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1,10 +1,11 @@ #include <stdio.h> #include <stdlib.h> +#include <ctype.h> #define BUFSIZE 1024 char buffer[BUFSIZE]; // TODO: Support UTF-8. -int map[256][2]; +int map[256][3]; void makeMap(FILE *f) { int x = 0; int y = 0; @@ -14,8 +15,12 @@ void makeMap(FILE *f) { case '\t': x++; break; case '\n': y++; x=0; break; default: + explicit_label: map[c][0] = x; map[c][1] = y; + map[c][2] = 1; + c = toupper(c); + if (c < 256 && map[c][2] == 0) goto explicit_label; break; } } @@ -24,9 +29,13 @@ void makeMap(FILE *f) { int scoreWord(char *word, int (*fun)(int*,int*)) { char *c = word; int score = 0; + char *p = c; for (c++;*c;c++) { if (*c == '\n') break; - score += (*fun)(map[c[-1]],map[c[0]]); + // pass over ignore unset chars. + if(map[(unsigned char)*c][3] == 0) continue; + score += (*fun)(map[(unsigned char)*p],map[(unsigned char)*c]); + p=c; } return score; } @@ -53,7 +62,7 @@ int beeDist(int *p1, int *p2) { int main(int argc, char **argv) { if (argc < 2) { - fprintf(stderr, "Usage: mapScore map.tsv <words.txt >scoredWords.tsv"); + fprintf(stderr, "Usage: mapScore map.tsv <words.txt >scoredWords.tsv\n"); return 1; } |