aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parse-events.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/parse-events.c b/parse-events.c
index 7b3b440..c5e8080 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -30,11 +30,11 @@
30 30
31#include "parse-events.h" 31#include "parse-events.h"
32 32
33static char *input_buf; 33static const char *input_buf;
34static unsigned long long input_buf_ptr; 34static unsigned long long input_buf_ptr;
35static unsigned long long input_buf_siz; 35static unsigned long long input_buf_siz;
36 36
37static void init_input_buf(char *buf, unsigned long long size) 37static void init_input_buf(const char *buf, unsigned long long size)
38{ 38{
39 input_buf = buf; 39 input_buf = buf;
40 input_buf_siz = size; 40 input_buf_siz = size;
@@ -657,26 +657,6 @@ static enum event_type get_type(int ch)
657 return EVENT_OP; 657 return EVENT_OP;
658} 658}
659 659
660static void __push_char(char c)
661{
662 if (input_buf_ptr <= 0)
663 die("too much pushback");
664 input_buf[--input_buf_ptr] = c;
665}
666
667static void __push_str(char *s)
668{
669 char *e = s;
670
671 while (*e++)
672 /* nothing */;
673 e--;
674 while (s != e) {
675 e--;
676 __push_char(*e);
677 }
678}
679
680static int __read_char(void) 660static int __read_char(void)
681{ 661{
682 if (input_buf_ptr >= input_buf_siz) 662 if (input_buf_ptr >= input_buf_siz)
@@ -693,6 +673,8 @@ static int __peek_char(void)
693 return input_buf[input_buf_ptr]; 673 return input_buf[input_buf_ptr];
694} 674}
695 675
676static enum event_type force_token(const char *str, char **tok);
677
696static enum event_type __read_token(char **tok) 678static enum event_type __read_token(char **tok)
697{ 679{
698 char buf[BUFSIZ]; 680 char buf[BUFSIZ];
@@ -848,24 +830,45 @@ static enum event_type __read_token(char **tok)
848 if (strcmp(*tok, "LOCAL_PR_FMT") == 0) { 830 if (strcmp(*tok, "LOCAL_PR_FMT") == 0) {
849 free(*tok); 831 free(*tok);
850 *tok = NULL; 832 *tok = NULL;
851 __push_str("\"\%s\" "); 833 return force_token("\"\%s\" ", tok);
852 return __read_token(tok);
853 } else if (strcmp(*tok, "STA_PR_FMT") == 0) { 834 } else if (strcmp(*tok, "STA_PR_FMT") == 0) {
854 free(*tok); 835 free(*tok);
855 *tok = NULL; 836 *tok = NULL;
856 __push_str("\" sta:%pM\" "); 837 return force_token("\" sta:%pM\" ", tok);
857 return __read_token(tok);
858 } else if (strcmp(*tok, "VIF_PR_FMT") == 0) { 838 } else if (strcmp(*tok, "VIF_PR_FMT") == 0) {
859 free(*tok); 839 free(*tok);
860 *tok = NULL; 840 *tok = NULL;
861 __push_str("\" vif:%p(%d)\" "); 841 return force_token("\" vif:%p(%d)\" ", tok);
862 return __read_token(tok);
863 } 842 }
864 } 843 }
865 844
866 return type; 845 return type;
867} 846}
868 847
848static enum event_type force_token(const char *str, char **tok)
849{
850 const char *save_input_buf;
851 unsigned long long save_input_buf_ptr;
852 unsigned long long save_input_buf_siz;
853 enum event_type type;
854
855 /* save off the current input pointers */
856 save_input_buf = input_buf;
857 save_input_buf_ptr = input_buf_ptr;
858 save_input_buf_siz = input_buf_siz;
859
860 init_input_buf(str, strlen(str));
861
862 type = __read_token(tok);
863
864 /* reset back to original token */
865 input_buf = save_input_buf;
866 input_buf_ptr = save_input_buf_ptr;
867 input_buf_siz = save_input_buf_siz;
868
869 return type;
870}
871
869static void free_token(char *tok) 872static void free_token(char *tok)
870{ 873{
871 if (tok) 874 if (tok)