labcomm_sig_parser.h 2.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* labcomm_sig_parser.h:
 * an example parser for labcomm signatures, illustrating how to skip samples
 * based on their signature. Intended as an embryo for introducing this 
 * functionality into the lib to allow a channel to survive types with no
 * registered handler.
 */

#ifndef LABCOMM_SIG_PARSER_H
#define LABCOMM_SIG_PARSER_H

#include "../labcomm_private.h"

#undef DEBUG 
#undef DEBUG_STACK

#undef QUIET 		//just print type and size when skipping data
#undef VERBOSE 		// print in great detail

#ifdef QUIET
#define INFO_PRINTF(format, args...)  
#undef VERBOSE
#else
#define INFO_PRINTF(format, args...)  \
      printf (format , ## args)
#endif

#ifdef VERBOSE
#define VERBOSE_PRINTF(format, args...)  \
      printf (format , ## args)
#else
#define VERBOSE_PRINTF(format, args...)  
#endif

#undef EXIT_WHEN_RECEIVING_DATA 

#undef RETURN_STRINGS  // highly experimental, and not used

#ifndef TRUE

#define FALSE 0
#define TRUE 1

#endif

typedef enum{
        TYPE_DECL = LABCOMM_TYPEDEF,
        SAMPLE_DECL = LABCOMM_SAMPLE,

        ARRAY_DECL = LABCOMM_ARRAY,
        STRUCT_DECL = LABCOMM_STRUCT,

        TYPE_BOOLEAN  = LABCOMM_BOOLEAN,
        TYPE_BYTE  = LABCOMM_BYTE,
        TYPE_SHORT  = LABCOMM_SHORT,
        TYPE_INTEGER  = LABCOMM_INT,
        TYPE_LONG  = LABCOMM_LONG,
        TYPE_FLOAT  = LABCOMM_FLOAT,
        TYPE_DOUBLE  = LABCOMM_DOUBLE,
        TYPE_STRING  = LABCOMM_STRING
} labcomm_type ;

/* internal type: stack for the parser */
typedef struct {
	unsigned char* c;
	size_t size;
	size_t capacity;
	unsigned int idx;
	void** stack;
	size_t stacksize;
	unsigned int top;
} buffer;

int init_buffer(buffer *b, size_t size, size_t stacksize) ;
int read_file(FILE *f, buffer *b);

//XXX experimental
#define MAX_SIGNATURES 10
#define MAX_NAME_LEN 32 
#define MAX_SIG_LEN 128

#define STACK_SIZE 16

unsigned int get_signature_len(unsigned int uid);
unsigned char* get_signature_name(unsigned int uid);
unsigned char* get_signature(unsigned int uid);
void dump_signature(unsigned int uid);

int do_parse(buffer *d);

/* parse signature and skip the corresponding bytes in the buffer 
 */
int skip_packed_sample_data(buffer *d, unsigned char *sig, unsigned int siglen);

#endif