parser lib for my games
Commit 677d9ec03861
tarball5 files changed+53-7
@@ -0,0 +1,14 @@
1
+.PHONY: all debug clean2
+3
+all:4
+ cmake -B build -DCMAKE_BUILD_TYPE=Release5
+ cmake --build build6
+7
+debug:8
+ cmake -B build -DCMAKE_BUILD_TYPE=Debug9
+ cmake --build build10
+11
+new: clean debug12
+13
+clean:14
+ rm -rf build@@ -14,7 +14,7 @@
1414
in {1515
packages.${system}.default = pkgs.stdenv.mkDerivation {1616
pname = "jag-parse";17
- version = "1.0.2";17
+ version = "1.1.0";1818
1919
src = ./.;2020
@@ -10,9 +10,12 @@
1010
#define ARROW_LEN 3 1111
1212
typedef enum {13
- NO_KEY, P_KEY, Q_KEY, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW, INCOMPLETE, UNKNOWN13
+ NO_KEY, ESCAPE_KEY, ENTER_KEY, LEFT_ARROW, RIGHT_ARROW, UP_ARROW, DOWN_ARROW, A_KEY, D_KEY, Q_KEY, P_KEY, S_KEY, W_KEY, INCOMPLETE, UNKNOWN1414
} keypress;1515
16
+17
+void free_buf();18
+1619
int add_to_buf(uint8_t *input, uint16_t input_length);1720
1821
keypress parse_input();@@ -1 +0,0 @@
1
-/nix/store/lqi15sh8mmswdlnd09l5xsaxf7a4gc1s-jag_parse-1.0.1@@ -8,6 +8,14 @@ uint16_t end = 0;
88
uint16_t length = 0;99
1010
11
+12
+void free_buf () {13
+ start = 0;14
+ end = 0;15
+ length = 0;16
+}17
+18
+1119
int add_to_buf(uint8_t *input, uint16_t input_length) {1220
1321
if (BUF_LEN - length < input_length)@@ -81,6 +89,8 @@ keypress parse_input() {
8189
length--;8290
8391
next_position = next_pos(next_position);92
+ } else {93
+ output = ESCAPE_KEY;8494
}8595
}8696
@@ -88,10 +98,30 @@ keypress parse_input() {
8898
8999
length--;90100
91
- if (next_char == 'p') {92
- output = P_KEY;93
- } else if(next_char == 'q') {94
- output = Q_KEY;101
+ switch (next_char) {102
+ case '\n':103
+ output = ENTER_KEY;104
+ break;105
+ case 'a':106
+ output = A_KEY;107
+ break;108
+ case 'd':109
+ output = D_KEY;110
+ break;111
+ case 'p':112
+ output = P_KEY;113
+ break;114
+ case 'q':115
+ output = Q_KEY;116
+ break;117
+ case 's':118
+ output = S_KEY;119
+ break;120
+ case 'w':121
+ output = W_KEY;122
+ break;123
+ default:124
+ break;95125
}96126
}