Skip to content
Snippets Groups Projects
Commit ea4a68bf authored by Sven Gestegård Robertz's avatar Sven Gestegård Robertz
Browse files

updated sig_parser to intentions

parent 25ad39c4
No related branches found
No related tags found
No related merge requests found
...@@ -37,9 +37,9 @@ ifeq ($(LABCOMM_EXPERIMENTAL),true) ...@@ -37,9 +37,9 @@ ifeq ($(LABCOMM_EXPERIMENTAL),true)
experimental/labcomm_udp_reader_writer.o experimental/labcomm_udp_reader_writer.o
endif endif
# Enable experimental objects by `make LABCOMM_SIG_PARSER=true` # Enable experimental objects by `make labcomm2014_sig_PARSER=true`
ifeq ($(LABCOMM_SIG_PARSER),true) ifeq ($(LABCOMM_SIG_PARSER),true)
OBJS += experimental/labcomm_sig_parser.o OBJS += experimental/labcomm2014_sig_parser.o
endif endif
LABCOMM_JAR=../../../compiler/labcomm$(LIBVERSION)_compiler.jar LABCOMM_JAR=../../../compiler/labcomm$(LIBVERSION)_compiler.jar
...@@ -95,9 +95,9 @@ distclean: clean ...@@ -95,9 +95,9 @@ distclean: clean
../liblabcomm$(LIBVERSION).a: $(OBJS) ../liblabcomm$(LIBVERSION).a: $(OBJS)
ar -r $@ $^ ar -r $@ $^
# Enable sig parser objects by `make LABCOMM_SIG_PARSER=true` # Enable sig parser objects by `make labcomm2014_sig_PARSER=true`
ifeq ($(LABCOMM_SIG_PARSER),true) ifeq ($(LABCOMM_SIG_PARSER),true)
experimental/test_sig_parser : experimental/labcomm_sig_parser.o experimental/test_sig_parser.c experimental/test_sig_parser : experimental/labcomm2014_sig_parser.o experimental/test_sig_parser.c
endif endif
# compilation rules # compilation rules
......
/* labcomm_sig_parser.h: /* labcomm2014_sig_parser.h:
* an example parser for labcomm signatures, illustrating how to skip samples * an example parser for labcomm signatures, illustrating how to skip samples
* based on their signature. Intended as an embryo for introducing this * based on their signature. Intended as an embryo for introducing this
* functionality into the lib to allow a channel to survive types with no * functionality into the lib to allow a channel to survive types with no
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#ifndef LABCOMM_SIG_PARSER_H #ifndef LABCOMM_SIG_PARSER_H
#define LABCOMM_SIG_PARSER_H #define LABCOMM_SIG_PARSER_H
#include "../labcomm.h" #include "labcomm2014.h"
#include "../labcomm_private.h" #include "labcomm2014_private.h"
#define DEBUG #define DEBUG
#define QUIET_STACK // don't print anything for push/pop #define QUIET_STACK // don't print anything for push/pop
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#ifdef STATIC_ALLOCATION #ifdef STATIC_ALLOCATION
#define MAX_SIGNATURES 16 #define MAX_SIGNATURES 100
#define MAX_NAME_LEN 32 #define MAX_NAME_LEN 32
#define MAX_SIG_LEN 128 #define MAX_SIG_LEN 128
#define TYPEDEF_BASE MAX_SIGNATURES #define TYPEDEF_BASE MAX_SIGNATURES
...@@ -52,14 +52,14 @@ typedef struct { ...@@ -52,14 +52,14 @@ typedef struct {
// signatures start at index 0 // signatures start at index 0
// typedefs start at index MAX_SIGNATURES // typedefs start at index MAX_SIGNATURES
#ifdef STATIC_ALLOCATION #ifdef STATIC_ALLOCATION
struct labcomm_signature sig_ts[2*MAX_SIGNATURES]; struct labcomm2014_signature sig_ts[2*MAX_SIGNATURES];
unsigned int signatures_length[2*MAX_SIGNATURES]; unsigned int signatures_length[2*MAX_SIGNATURES];
unsigned int signatures_name_length[2*MAX_SIGNATURES]; unsigned int signatures_name_length[2*MAX_SIGNATURES];
unsigned char signatures_name[2*MAX_SIGNATURES][MAX_NAME_LEN]; unsigned char signatures_name[2*MAX_SIGNATURES][MAX_NAME_LEN];
unsigned char signatures[2*MAX_SIGNATURES][MAX_SIG_LEN]; unsigned char signatures[2*MAX_SIGNATURES][MAX_SIG_LEN];
#else #else
struct labcomm_signature *sig_ts; // [2*MAX_SIGNATURES] struct labcomm2014_signature *sig_ts; // [2*MAX_SIGNATURES]
unsigned int *signatures_length; // [2*MAX_SIGNATURES] unsigned int *signatures_length; // [2*MAX_SIGNATURES]
unsigned char **signatures; // [2*MAX_SIGNATURES][MAX_SIG_LEN]; unsigned char **signatures; // [2*MAX_SIGNATURES][MAX_SIG_LEN];
...@@ -68,30 +68,30 @@ typedef struct { ...@@ -68,30 +68,30 @@ typedef struct {
char **signatures_name; // [2*MAX_SIGNATURES][MAX_NAME_LEN]; char **signatures_name; // [2*MAX_SIGNATURES][MAX_NAME_LEN];
#endif #endif
} labcomm_sig_parser_t; } labcomm2014_sig_parser_t;
int labcomm_sig_parser_init(labcomm_sig_parser_t *p, size_t size, int labcomm2014_sig_parser_init(labcomm2014_sig_parser_t *p, size_t size,
size_t stacksize, size_t max_num_signatures, size_t stacksize, size_t max_num_signatures,
size_t max_name_len, size_t max_sig_len); size_t max_name_len, size_t max_sig_len);
int labcomm_sig_parser_read_file(labcomm_sig_parser_t *p, FILE *f); int labcomm2014_sig_parser_read_file(labcomm2014_sig_parser_t *p, FILE *f);
int accept_packet(labcomm_sig_parser_t *p); int accept_packet(labcomm2014_sig_parser_t *p);
struct labcomm_signature *get_sig_t(labcomm_sig_parser_t *p,unsigned int uid); struct labcomm2014_signature *get_sig_t(labcomm2014_sig_parser_t *p,unsigned int uid);
unsigned int get_signature_len(labcomm_sig_parser_t *p,unsigned int uid); unsigned int get_signature_len(labcomm2014_sig_parser_t *p,unsigned int uid);
char* get_signature_name(labcomm_sig_parser_t *p,unsigned int uid); char* get_signature_name(labcomm2014_sig_parser_t *p,unsigned int uid);
unsigned char* get_signature(labcomm_sig_parser_t *p,unsigned int uid); unsigned char* get_signature(labcomm2014_sig_parser_t *p,unsigned int uid);
void dump_signature(labcomm_sig_parser_t *p,unsigned int uid); void dump_signature(labcomm2014_sig_parser_t *p,unsigned int uid);
int more(labcomm_sig_parser_t *b); int more(labcomm2014_sig_parser_t *b);
/* parse signature and skip the corresponding bytes in the labcomm_sig_parser /* parse signature and skip the corresponding bytes in the labcomm2014_sig_parser
*/ */
int skip_packed_sample_data(labcomm_sig_parser_t *p, struct labcomm_signature *sig); int skip_packed_sample_data(labcomm2014_sig_parser_t *p, struct labcomm2014_signature *sig);
#ifdef QUIET #ifdef QUIET
#define INFO_PRINTF(format, args...) #define INFO_PRINTF(format, args...)
...@@ -131,5 +131,5 @@ typedef enum{ ...@@ -131,5 +131,5 @@ typedef enum{
TYPE_DOUBLE = LABCOMM_DOUBLE, TYPE_DOUBLE = LABCOMM_DOUBLE,
TYPE_STRING = LABCOMM_STRING, TYPE_STRING = LABCOMM_STRING,
TYPE_SAMPLE_REF = LABCOMM_REF TYPE_SAMPLE_REF = LABCOMM_REF
} labcomm_type ; } labcomm2014_type ;
#endif #endif
/* labcomm_sig_parser.c: /* labcomm2014_sig_parser.c:
* a main program for the example labcomm signatures parser * a main program for the example labcomm signatures parser
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "labcomm_sig_parser.h" #include "experimental/labcomm2014_sig_parser.h"
#define DEBUG_READ #define DEBUG_READ
#define BUF_SIZE 1024 #define BUF_SIZE 1024
#define STACK_SIZE 16 #define STACK_SIZE 16
#define MAX_NUM_SIGNATURES 10 #define MAX_NUM_SIGNATURES 10
#define MAX_SIGNATURES 16 #define MAX_SIGNATURES 100
#define MAX_NAME_LEN 32 #define MAX_NAME_LEN 64
#define MAX_SIG_LEN 128 #define MAX_SIG_LEN 512
void test_read(labcomm_sig_parser_t *p) { void test_read(labcomm2014_sig_parser_t *p) {
int r = labcomm_sig_parser_read_file(p, stdin); int r = labcomm2014_sig_parser_read_file(p, stdin);
#ifdef DEBUG_READ #ifdef DEBUG_READ
printf("read %d bytes:\n\n", r); printf("read %d bytes:\n\n", r);
int i; int i;
...@@ -29,9 +29,9 @@ void test_read(labcomm_sig_parser_t *p) { ...@@ -29,9 +29,9 @@ void test_read(labcomm_sig_parser_t *p) {
#endif #endif
} }
int main() { int main() {
labcomm_sig_parser_t p; labcomm2014_sig_parser_t p;
if(labcomm_sig_parser_init(&p, BUF_SIZE, STACK_SIZE, if(labcomm2014_sig_parser_init(&p, BUF_SIZE, STACK_SIZE,
MAX_NUM_SIGNATURES, MAX_NAME_LEN, MAX_SIG_LEN) ) { MAX_NUM_SIGNATURES, MAX_NAME_LEN, MAX_SIG_LEN) ) {
printf("failed to init buffer\n"); printf("failed to init buffer\n");
exit(1); exit(1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment