-
Notifications
You must be signed in to change notification settings - Fork 18
/
tools.h
195 lines (148 loc) · 4.63 KB
/
tools.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
* tools.h
* Typing
*
* Created by Michael Dickens on 8/7/09.
*
*/
#ifndef __TOOLS_H__
#define __TOOLS_H__
#include "values.h"
#define streq(str1, str2) (strcmp(str1, str2) == 0)
#define streqn(str1, str2, n) (strncmp(str1, str2, n) == 0)
#define ASCII_SHIFT 14
#define DI_LEN_MAX 5000
#define MON_LEN_MAX 200
#define ERROR_RATE_PERCENT 2
#define MONOGRAPHFILE "data/allChars.txt"
#define DIGRAPH_FILE "data/allDigraphs.txt"
/* Global variable declarations */
int64_t totalMon;
int64_t totalDi;
int monLen, diLen, triLen;
struct Monograph {
char key;
int64_t value;
};
struct Digraph {
char key[2];
int64_t value;
};
struct NGraph {
char *key;
int64_t value;
};
struct Monograph monographs[MON_LEN_MAX];
struct Digraph digraphs[DI_LEN_MAX];
/* Constant declarations */
#define LEFT 0
#define RIGHT 1
#define PINKY 0
#define RING 1
#define MIDDLE 2
#define INDEX 3
#define THUMB 4
/* Reduces monValues and diValues so as to prevent integer overflow. */
#define DIVISOR 100
/* These are guaranteed to hold a standard QWERTY layout. */
#define DEFAULT_KEYBOARD_30 "qwertyuiopasdfghjkl;zxcvbnm,./QWERTYUIOPASDFGHJKL:ZXCVBNM<>?"
#define DEFAULT_KEYBOARD_STANDARD "`1234567890-=qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?"
#define DEFAULT_KEYBOARD_KINESIS "1234567890-\tqwertyuiop=asdfghjkl;'zxcvbnm,./`\\[]\n !@#$%^&*()_\tQWERTYUIOP+ASDFGHJKL:\"ZXCVBNM<>?~|{}\n "
#define CHECK_FILE_FOR_NULL(file, filename) \
if ((file) == NULL) { \
fprintf(stderr, "Unable to open file: %s\n", (filename)); \
return 1; \
}
char keysToInclude[200];
typedef struct {
char layout[KSIZE_MAX + 1]; /* The one extra character is set to '\0' so
(layout) can be treated as a string. */
char shiftedLayout[KSIZE_MAX + 1];
int64_t fingerUsage[FINGER_COUNT];
int64_t fitness;
int64_t distance;
int64_t fingerWork;
int64_t inRoll;
int64_t outRoll;
int64_t sameHand;
int64_t sameFinger;
int64_t rowChange;
int64_t homeJump;
int64_t ringJump;
int64_t toCenter;
int64_t toOutside;
} Keyboard;
Keyboard nilKeyboard;
void copyArray(int dest[], int src[], int length);
void printTime(time_t start);
int initData();
void initKeyboardData();
int initTypingData();
int compileTypingData(char *outfileName, const char *filenames[],
int multipliers[], int length, int unit, int max);
int sortTypingData(char **keys, int *values, int left, int right);
int convertEscapeChar(int c);
/* Sort by values from highest to lowest.
*/
int cmpDigraphsByValue(const void *one, const void *two);
int cmpMonographsByValue(const void *one, const void *two);
int cmpNGraphsByValue(const void *one, const void *two);
int sortMonographs(char keys[], int64_t values[], int left, int right);
struct VarInfo {
const char *name; /* The name of the variable. */
int *addr; /* A pointer to the variable itself. */
const char *description;
};
#define VARIABLES_MAX_LEN 100
struct VarInfo variables[VARIABLES_MAX_LEN];
int variablesLength;
void initVariables();
int getValue(const char *name);
int setValue(char *str);
#define isBracket(c) (getMatchingBracket(c) != 0)
char getMatchingBracket(char c);
int keepShiftPair(char c);
char qwerty[30];
/* For each key, indicates which hand (LEFT or RIGHT) is responsible for typing
* that key.
*/
int hand[KSIZE_MAX];
/* For each key, indicates which finger (PINKY, RING, MIDDLE or INDEX) is
* responsible for typing that key.
*/
int finger[KSIZE_MAX];
/* Where 0 is pinky, -1 is left of pinky, ..., 3 is index, 4 is right of index.
* Anything greater than 4 is thumb.
*/
int column[KSIZE_MAX];
/* For each key, indicates which row that key lies on. The top row is 0,
* the row below it is 1, the row below that is 2, etc.
*/
int row[KSIZE_MAX];
/* Indicates which row is the home row.
*/
int homeRow;
/* Indicates the index of the first number in the layout, assuming
* keepNumbers is TRUE.
*/
int firstNumberIndex;
/* For each key, indicates whether that key requires a reach to the center.
*/
int isCenter[KSIZE_MAX];
/* For each key, indicates whether that key requires a reach to the outside.
*/
int isOutside[KSIZE_MAX];
/* For each key, indicates whether that key requires a reach to the center OR
* a reach to the outside. This one is produced automatically from isCenter[]
* and isOutside[].
*/
int isCenterOrOutside[KSIZE_MAX];
/* For each key, indicates whether that key should be printed. Any place-holder
* key that does not actually exist on the keyboard should not be printed.
*/
int printable[KSIZE_MAX];
/* Lookup tables for calcRowChange(). Each row and column represents a finger.
*/
int rowChangeTableUp[5][5];
int rowChangeTableDown[5][5];
#endif