Refactor keyboard file load. - sam - An updated version of the sam text editor.
(HTM) git clone git://vernunftzentrum.de/sam.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 4ee9c949e17d842112a6ebf9508efb13b0b29870
(DIR) parent cead875fb4c7df577eb3d215b2d21a290423c5a2
(HTM) Author: Rob King <jking@deadpixi.com>
Date: Thu, 11 Aug 2016 23:31:35 -0500
Refactor keyboard file load.
Diffstat:
libXg/latin1.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
---
(DIR) diff --git a/libXg/latin1.c b/libXg/latin1.c
@@ -236,6 +236,19 @@ freelatin(void)
}
void
+addlatin(char c0, char c1, int l)
+{
+ static int i = 0;
+
+ if (mappings && i < MAPPING_MAX){
+ mappings[i].c[0] = c0;
+ mappings[i].c[1] = c1;
+ mappings[i].l = l;
+ i++;
+ }
+}
+
+void
initlatin(void)
{
mappings = calloc(MAPPING_MAX + 1, sizeof(struct latin));
@@ -252,17 +265,10 @@ initlatin(void)
if (!keyboard)
return;
- int j = 0;
- while (j < MAPPING_MAX){
- int count = fscanf(keyboard, " %c%c %hx%*[^\n]\n", &(mappings[j].c[0]), &(mappings[j].c[1]), &(mappings[j].l));
- if (count == 3)
- j++;
- else if (count == EOF){
- memset(&(mappings[j]), 0, sizeof(struct latin));
- break;
- } else
- memset(&(mappings[j]), 0, sizeof(struct latin));
- }
+ unsigned char c0, c1;
+ unsigned short l;
+ while (fscanf(keyboard, " %c%c %hx%*[^\n]\n", &c0, &c1, &l) == 3)
+ addlatin(c0, c1, l);
fclose(keyboard);
}