4coder/4ed_metagen.cpp

84 lines
1.3 KiB
C++
Raw Normal View History

2016-02-25 23:52:11 +00:00
/*
* Mr. 4th Dimention - Allen Webster
*
* 25.02.2016
*
* File editing view for 4coder
*
*/
// TOP
#define ArrayCount(a) (sizeof(a)/sizeof(*a))
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char *keys_that_need_codes[] = {
"back",
"up",
"down",
"left",
"right",
"del",
"insert",
"home",
"end",
"page_up",
"page_down",
"esc",
"f1",
"f2",
"f3",
"f4",
"f5",
"f6",
"f7",
"f8",
"f9",
"f10",
"f11",
"f12",
"f13",
"f14",
"f15",
"f16",
};
void generate_keycode_enum(){
FILE *file;
char filename[] = "4coder_keycodes.h";
int i, count;
unsigned char code = 1;
file = fopen(filename, "wb");
fprintf(file, "enum Key_Code{\n");
count = ArrayCount(keys_that_need_codes);
for (i = 0; i < count;){
if (strcmp(keys_that_need_codes[i], "f1") == 0 && code < 0x7F){
code = 0x7F;
}
switch (code){
case '\n': code++; break;
case '\t': code++; break;
case 0x20: code = 0x7F; break;
default:
fprintf(file, "key_%s = %d,\n", keys_that_need_codes[i++], code++);
break;
}
}
fprintf(file, "};\n");
fclose(file);
printf("gen success: %s\n", filename);
}
int main(){
generate_keycode_enum();
}
// BOTTOM