summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-17 17:10:58 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-17 17:10:58 -0400
commit801e922ddd37ec15ccb8dd16cca9c587b7c1d6fb (patch)
tree9f30308b9df0a872ff95f68e4ebe3d070fd1fef6
parent858dfa5e53f2068b0b88eb5ebdaef5afc5f0301d (diff)
downloadlibvt100-801e922ddd37ec15ccb8dd16cca9c587b7c1d6fb.tar.gz
libvt100-801e922ddd37ec15ccb8dd16cca9c587b7c1d6fb.zip
hide the parser state
this shouldn't be public (none of the parser stuff should be), but the way i was doing before with redefining certain types from parser.h was causing warnings on clang.
-rw-r--r--src/parser.c132
-rw-r--r--src/parser.h2
-rw-r--r--src/parser.l2
-rw-r--r--src/screen.c18
-rw-r--r--src/screen.h10
-rw-r--r--src/vt100.h2
6 files changed, 85 insertions, 81 deletions
diff --git a/src/parser.c b/src/parser.c
index fa8d7b8..faf16d2 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -657,11 +657,13 @@ static yyconst flex_int16_t yy_chk[780] =
#include "vt100.h"
+#define UNUSED(x) ((void)x)
+
#define VT100_PARSER_CSI_MAX_PARAMS 256
#define YY_EXIT_FAILURE (UNUSED(yyscanner), 2)
#define YY_NO_INPUT 1
-#line 84 "src/parser.l"
+#line 86 "src/parser.l"
static void vt100_parser_handle_bel(VT100Screen *vt);
static void vt100_parser_handle_bs(VT100Screen *vt);
static void vt100_parser_handle_tab(VT100Screen *vt);
@@ -702,7 +704,7 @@ static void vt100_parser_handle_osc1(VT100Screen *vt, char *buf, size_t len);
static void vt100_parser_handle_osc2(VT100Screen *vt, char *buf, size_t len);
static void vt100_parser_handle_ascii(VT100Screen *vt, char *text, size_t len);
static void vt100_parser_handle_text(VT100Screen *vt, char *text, size_t len);
-#line 706 "src/parser.c"
+#line 708 "src/parser.c"
#define INITIAL 0
@@ -950,10 +952,10 @@ YY_DECL
}
{
-#line 126 "src/parser.l"
+#line 128 "src/parser.l"
-#line 957 "src/parser.c"
+#line 959 "src/parser.c"
while ( 1 ) /* loops until end-of-file is reached */
{
@@ -1008,232 +1010,232 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
-#line 128 "src/parser.l"
+#line 130 "src/parser.l"
vt100_parser_handle_bel(yyextra);
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 129 "src/parser.l"
+#line 131 "src/parser.l"
vt100_parser_handle_bs(yyextra);
YY_BREAK
case 3:
YY_RULE_SETUP
-#line 130 "src/parser.l"
+#line 132 "src/parser.l"
vt100_parser_handle_tab(yyextra);
YY_BREAK
case 4:
/* rule 4 can match eol */
-#line 132 "src/parser.l"
+#line 134 "src/parser.l"
case 5:
/* rule 5 can match eol */
-#line 133 "src/parser.l"
+#line 135 "src/parser.l"
case 6:
/* rule 6 can match eol */
YY_RULE_SETUP
-#line 133 "src/parser.l"
+#line 135 "src/parser.l"
vt100_parser_handle_lf(yyextra);
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 134 "src/parser.l"
+#line 136 "src/parser.l"
vt100_parser_handle_cr(yyextra);
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 135 "src/parser.l"
+#line 137 "src/parser.l"
YY_BREAK
case 9:
YY_RULE_SETUP
-#line 137 "src/parser.l"
+#line 139 "src/parser.l"
vt100_parser_handle_deckpam(yyextra);
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 138 "src/parser.l"
+#line 140 "src/parser.l"
vt100_parser_handle_deckpnm(yyextra);
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 139 "src/parser.l"
+#line 141 "src/parser.l"
vt100_parser_handle_ri(yyextra);
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 140 "src/parser.l"
+#line 142 "src/parser.l"
vt100_parser_handle_ris(yyextra);
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 141 "src/parser.l"
+#line 143 "src/parser.l"
vt100_parser_handle_vb(yyextra);
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 142 "src/parser.l"
+#line 144 "src/parser.l"
vt100_parser_handle_decsc(yyextra);
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 143 "src/parser.l"
+#line 145 "src/parser.l"
vt100_parser_handle_decrc(yyextra);
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 145 "src/parser.l"
+#line 147 "src/parser.l"
vt100_parser_handle_ich(yyextra, yytext, yyleng);
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 146 "src/parser.l"
+#line 148 "src/parser.l"
vt100_parser_handle_cuu(yyextra, yytext, yyleng);
YY_BREAK
case 18:
YY_RULE_SETUP
-#line 147 "src/parser.l"
+#line 149 "src/parser.l"
vt100_parser_handle_cud(yyextra, yytext, yyleng);
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 148 "src/parser.l"
+#line 150 "src/parser.l"
vt100_parser_handle_cuf(yyextra, yytext, yyleng);
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 149 "src/parser.l"
+#line 151 "src/parser.l"
vt100_parser_handle_cub(yyextra, yytext, yyleng);
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 150 "src/parser.l"
+#line 152 "src/parser.l"
vt100_parser_handle_cha(yyextra, yytext, yyleng);
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 151 "src/parser.l"
+#line 153 "src/parser.l"
vt100_parser_handle_cup(yyextra, yytext, yyleng);
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 152 "src/parser.l"
+#line 154 "src/parser.l"
vt100_parser_handle_ed(yyextra, yytext, yyleng);
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 153 "src/parser.l"
+#line 155 "src/parser.l"
vt100_parser_handle_el(yyextra, yytext, yyleng);
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 154 "src/parser.l"
+#line 156 "src/parser.l"
vt100_parser_handle_il(yyextra, yytext, yyleng);
YY_BREAK
case 26:
YY_RULE_SETUP
-#line 155 "src/parser.l"
+#line 157 "src/parser.l"
vt100_parser_handle_dl(yyextra, yytext, yyleng);
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 156 "src/parser.l"
+#line 158 "src/parser.l"
vt100_parser_handle_dch(yyextra, yytext, yyleng);
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 157 "src/parser.l"
+#line 159 "src/parser.l"
vt100_parser_handle_vpa(yyextra, yytext, yyleng);
YY_BREAK
case 29:
YY_RULE_SETUP
-#line 158 "src/parser.l"
+#line 160 "src/parser.l"
vt100_parser_handle_sm(yyextra, yytext, yyleng);
YY_BREAK
case 30:
YY_RULE_SETUP
-#line 159 "src/parser.l"
+#line 161 "src/parser.l"
vt100_parser_handle_rm(yyextra, yytext, yyleng);
YY_BREAK
case 31:
YY_RULE_SETUP
-#line 160 "src/parser.l"
+#line 162 "src/parser.l"
vt100_parser_handle_sgr(yyextra, yytext, yyleng);
YY_BREAK
case 32:
YY_RULE_SETUP
-#line 161 "src/parser.l"
+#line 163 "src/parser.l"
vt100_parser_handle_csr(yyextra, yytext, yyleng);
YY_BREAK
case 33:
YY_RULE_SETUP
-#line 163 "src/parser.l"
+#line 165 "src/parser.l"
vt100_parser_handle_decsed(yyextra, yytext, yyleng);
YY_BREAK
case 34:
YY_RULE_SETUP
-#line 164 "src/parser.l"
+#line 166 "src/parser.l"
vt100_parser_handle_decsel(yyextra, yytext, yyleng);
YY_BREAK
case 35:
YY_RULE_SETUP
-#line 166 "src/parser.l"
+#line 168 "src/parser.l"
vt100_parser_handle_osc0(yyextra, yytext, yyleng);
YY_BREAK
case 36:
YY_RULE_SETUP
-#line 167 "src/parser.l"
+#line 169 "src/parser.l"
vt100_parser_handle_osc1(yyextra, yytext, yyleng);
YY_BREAK
case 37:
YY_RULE_SETUP
-#line 168 "src/parser.l"
+#line 170 "src/parser.l"
vt100_parser_handle_osc2(yyextra, yytext, yyleng);
YY_BREAK
case 38:
-#line 171 "src/parser.l"
+#line 173 "src/parser.l"
case 39:
-#line 172 "src/parser.l"
+#line 174 "src/parser.l"
case 40:
-#line 173 "src/parser.l"
+#line 175 "src/parser.l"
case 41:
YY_RULE_SETUP
-#line 173 "src/parser.l"
+#line 175 "src/parser.l"
YY_BREAK
case 42:
YY_RULE_SETUP
-#line 175 "src/parser.l"
+#line 177 "src/parser.l"
vt100_parser_handle_ascii(yyextra, yytext, yyleng);
YY_BREAK
case 43:
YY_RULE_SETUP
-#line 176 "src/parser.l"
+#line 178 "src/parser.l"
vt100_parser_handle_text(yyextra, yytext, yyleng);
YY_BREAK
case 44:
-#line 179 "src/parser.l"
+#line 181 "src/parser.l"
case 45:
-#line 180 "src/parser.l"
+#line 182 "src/parser.l"
case 46:
-#line 181 "src/parser.l"
+#line 183 "src/parser.l"
case 47:
-#line 182 "src/parser.l"
+#line 184 "src/parser.l"
case 48:
-#line 183 "src/parser.l"
+#line 185 "src/parser.l"
case 49:
-#line 184 "src/parser.l"
+#line 186 "src/parser.l"
case 50:
YY_RULE_SETUP
-#line 184 "src/parser.l"
+#line 186 "src/parser.l"
return yyleng;
YY_BREAK
case YY_STATE_EOF(INITIAL):
-#line 186 "src/parser.l"
+#line 188 "src/parser.l"
return 0;
YY_BREAK
case 51:
/* rule 51 can match eol */
YY_RULE_SETUP
-#line 188 "src/parser.l"
+#line 190 "src/parser.l"
{
fprintf(stderr,
"unhandled CSI sequence: \\033%s\\%hho\n",
@@ -1242,14 +1244,14 @@ YY_RULE_SETUP
YY_BREAK
case 52:
YY_RULE_SETUP
-#line 194 "src/parser.l"
+#line 196 "src/parser.l"
{
fprintf(stderr, "unhandled CSI sequence: \\033%s\n", yytext + 1);
}
YY_BREAK
case 53:
YY_RULE_SETUP
-#line 198 "src/parser.l"
+#line 200 "src/parser.l"
{
yytext[yyleng - 1] = '\0';
fprintf(stderr,
@@ -1260,14 +1262,14 @@ YY_RULE_SETUP
case 54:
/* rule 54 can match eol */
YY_RULE_SETUP
-#line 205 "src/parser.l"
+#line 207 "src/parser.l"
{
fprintf(stderr, "unhandled escape sequence: \\%hho\n", yytext[1]);
}
YY_BREAK
case 55:
YY_RULE_SETUP
-#line 209 "src/parser.l"
+#line 211 "src/parser.l"
{
fprintf(stderr, "unhandled escape sequence: %s\n", yytext + 1);
}
@@ -1275,24 +1277,24 @@ YY_RULE_SETUP
case 56:
/* rule 56 can match eol */
YY_RULE_SETUP
-#line 213 "src/parser.l"
+#line 215 "src/parser.l"
{
fprintf(stderr, "unhandled control character: \\%hho\n", yytext[0]);
}
YY_BREAK
case 57:
YY_RULE_SETUP
-#line 217 "src/parser.l"
+#line 219 "src/parser.l"
{
fprintf(stderr, "invalid utf8 byte: \\%hho\n", yytext[0]);
}
YY_BREAK
case 58:
YY_RULE_SETUP
-#line 221 "src/parser.l"
+#line 223 "src/parser.l"
YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK
-#line 1296 "src/parser.c"
+#line 1298 "src/parser.c"
case YY_END_OF_BUFFER:
{
@@ -2384,7 +2386,7 @@ static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables"
-#line 221 "src/parser.l"
+#line 223 "src/parser.l"
diff --git a/src/parser.h b/src/parser.h
index ba9d7a2..f75c1ed 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -330,7 +330,7 @@ extern int vt100_parser_yylex (yyscan_t yyscanner);
#undef YY_DECL
#endif
-#line 221 "src/parser.l"
+#line 223 "src/parser.l"
#line 337 "src/parser.h"
diff --git a/src/parser.l b/src/parser.l
index 6594358..7471074 100644
--- a/src/parser.l
+++ b/src/parser.l
@@ -3,6 +3,8 @@
#include "vt100.h"
+#define UNUSED(x) ((void)x)
+
#define VT100_PARSER_CSI_MAX_PARAMS 256
#define YY_EXIT_FAILURE (UNUSED(yyscanner), 2)
diff --git a/src/screen.c b/src/screen.c
index 5ba16e7..8e8f783 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -6,6 +6,11 @@
#include "vt100.h"
#include "parser.h"
+struct vt100_parser_state {
+ yyscan_t scanner;
+ YY_BUFFER_STATE state;
+};
+
static void vt100_screen_get_string(
VT100Screen *vt, struct vt100_loc *start, struct vt100_loc *end,
char **strp, size_t *lenp, int formatted);
@@ -33,7 +38,8 @@ VT100Screen *vt100_screen_new(int rows, int cols)
void vt100_screen_init(VT100Screen *vt)
{
vt->grid = calloc(1, sizeof(struct vt100_grid));
- vt100_parser_yylex_init_extra(vt, &vt->scanner);
+ vt->parser_state = calloc(1, sizeof(struct vt100_parser_state));
+ vt100_parser_yylex_init_extra(vt, &vt->parser_state->scanner);
}
void vt100_screen_set_window_size(VT100Screen *vt, int rows, int cols)
@@ -105,11 +111,12 @@ void vt100_screen_set_scrollback_length(VT100Screen *vt, int rows)
int vt100_screen_process_string(VT100Screen *vt, char *buf, size_t len)
{
+ struct vt100_parser_state *state = vt->parser_state;
int remaining;
- vt->state = vt100_parser_yy_scan_bytes(buf, len, vt->scanner);
- remaining = vt100_parser_yylex(vt->scanner);
- vt100_parser_yy_delete_buffer(vt->state, vt->scanner);
+ state->state = vt100_parser_yy_scan_bytes(buf, len, state->scanner);
+ remaining = vt100_parser_yylex(state->scanner);
+ vt100_parser_yy_delete_buffer(state->state, state->scanner);
return len - remaining;
}
@@ -745,7 +752,8 @@ void vt100_screen_cleanup(VT100Screen *vt)
free(vt->title);
free(vt->icon_name);
- vt100_parser_yylex_destroy(vt->scanner);
+ vt100_parser_yylex_destroy(vt->parser_state->scanner);
+ free(vt->parser_state);
}
void vt100_screen_delete(VT100Screen *vt)
diff --git a/src/screen.h b/src/screen.h
index 01ad280..881a76f 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -75,12 +75,7 @@ struct vt100_grid {
struct vt100_row *rows;
};
-/* XXX including parser.h in a place which would be visible here breaks things,
- * so we copy these defintions over here */
-typedef void* yyscan_t;
-struct yy_buffer_state;
-typedef struct yy_buffer_state *YY_BUFFER_STATE;
-
+struct vt100_parser_state;
struct vt100_screen {
struct vt100_grid *grid;
struct vt100_grid *alternate;
@@ -94,8 +89,7 @@ struct vt100_screen {
int scrollback_length;
- yyscan_t scanner;
- YY_BUFFER_STATE state;
+ struct vt100_parser_state *parser_state;
unsigned char hide_cursor: 1;
unsigned char application_keypad: 1;
diff --git a/src/vt100.h b/src/vt100.h
index 12bbb7c..a3429ef 100644
--- a/src/vt100.h
+++ b/src/vt100.h
@@ -7,6 +7,4 @@ typedef struct vt100_screen VT100Screen;
#include "screen.h"
-#define UNUSED(x) ((void)x)
-
#endif