unsigned long long int getSize(parse_file_t *in)
{
- char *token;
+ char *token, *token2;
+ unsigned long long int ret;
token = getToken(in);
- if(in->type == NUMBER) {
- return strtoull(token, NULL, 0);
+
+
+ if(in->type == QUOTEDSTRING) {
+ in->type = NUMBER;
+ token2 = token;
+ do {
+ if (!isdigit(*token2)) {
+ in->type = QUOTEDSTRING;
+ break;
+ }
+ } while (*(++token2) != '\0');
}
+
+ if(in->type == NUMBER) {
+ ret = strtoull(token, NULL, 0);
+ } else {
+ goto error;
+ }
+
+ return ret;
+error:
in->error(in,"incorrect size specification");
return -1;
}
sequence_t * unnamed_types, table_t * named_types)
{
char * token;
+ int car;
t->fmt = NULL;
t->size = 0;
+ t->custom_write = 0;
+ t->network = 0;
while(1) {
token = getToken(in);
} else if(!strcmp("size",token)) {
getEqual(in);
t->size = getSize(in);
- }
- }
+ } else if(!strcmp("custom_write", token)) {
+ t->custom_write = 1;
+ } else if(!strcmp("byte_order",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"byte order was expected (network?)");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp("network", token)) {
+ t->network = 1;
+ }
+ } else if(!strcmp("write",token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"write type was expected (custom?)");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp("custom", token)) {
+ t->custom_write = 1;
+ }
+ }
+ }
}
/**************************************************************************
void getEventAttributes(parse_file_t *in, event_t *ev)
{
char * token;
- char car;
+ int car;
ev->name = NULL;
ev->per_trace = 0;
ev->per_tracefile = 0;
+ ev->param_buffer = 0;
+ ev->no_instrument_function = 0;
while(1) {
token = getToken(in);
if(car == EOF) in->error(in,"name was expected");
else if(car == '\"') ev->name = allocAndCopy(getQuotedString(in));
else ev->name = allocAndCopy(getName(in));
- } else if(!strcmp("per_trace", token)) {
- ev->per_trace = 1;
- } else if(!strcmp("per_tracefile", token)) {
- ev->per_tracefile = 1;
+ } else if(!strcmp("scope", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"scope was expected");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp(token, "trace")) ev->per_trace = 1;
+ else if(!strcmp(token, "tracefile")) ev->per_tracefile = 1;
+ } else if(!strcmp("param", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"parameter type was expected");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp(token, "buffer")) ev->param_buffer = 1;
+ } else if(!strcmp("attribute", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == EOF) in->error(in,"attribute was expected");
+ else if(car == '\"') token = getQuotedString(in);
+ else token = getName(in);
+ if(!strcmp(token, "no_instrument_function"))
+ ev->no_instrument_function = 1;
}
-
}
}
void getFacilityAttributes(parse_file_t *in, facility_t *fac)
{
char * token;
- char car;
+ int car;
fac->name = NULL;
+ fac->arch = NULL;
+ fac->user = 0;
while(1) {
token = getToken(in);
if(car == EOF) in->error(in,"name was expected");
else if(car == '\"') fac->name = allocAndCopy(getQuotedString(in));
else fac->name = allocAndCopy(getName(in));
- }
+ if(!strncmp(fac->name, "user_", sizeof("user_")-1))
+ fac->user = 1;
+ } else if(!strcmp("arch", token)) {
+ getEqual(in);
+ car = seekNextChar(in);
+ if(car == '\"') fac->arch = allocAndCopy(getQuotedString(in));
+ else fac->arch = allocAndCopy(getName(in));
+ }
}
}
void getFieldAttributes(parse_file_t *in, field_t *f)
{
char * token;
- char car;
+ int car;
f->name = NULL;
else if(car == '\"') f->name = allocAndCopy(getQuotedString(in));
else f->name = allocAndCopy(getName(in));
}
- }
+ }
}
char *getNameAttribute(parse_file_t *in)
{
char * token;
char *name = NULL;
- char car;
+ int car;
while(1) {
token = getToken(in);
- if(strcmp("/",token) == 0 || strcmp(">",token) == 0){
- ungetToken(in);
- break;
- }
-
if(!strcmp("name",token)) {
getEqual(in);
car = seekNextChar(in);
if(car == EOF) in->error(in,"name was expected");
else if(car == '\"') name = allocAndCopy(getQuotedString(in));
else name = allocAndCopy(getName(in));
+ } else {
+ ungetToken(in);
+ break;
}
+
}
if(name == NULL) in->error(in, "Name was expected");
return name;
-
}
-//for <label name=label_name value=n format="..."/>, value is an option
-char * getValueStrAttribute(parse_file_t *in)
+//for <label name=label_name value=n format="...">, value is an option
+//Return value : 0 : no value, 1 : has a value
+int getValueAttribute(parse_file_t *in, long long *value)
{
- char * token;
+ char * token, *token2;
- token = getToken(in);
- if(strcmp("/",token) == 0){
+ token = getToken(in);
+
+ if(strcmp("/",token) == 0 || strcmp(">", token) == 0){
ungetToken(in);
- return NULL;
+ return 0;
}
-
if(strcmp("value",token))in->error(in,"value was expected");
+
getEqual(in);
token = getToken(in);
- if(in->type != NUMBER) in->error(in,"number was expected");
- return token;
+
+ if(in->type == QUOTEDSTRING) {
+ in->type = NUMBER;
+ token2 = token;
+ do {
+ if (!isdigit(*token2)) {
+ in->type = QUOTEDSTRING;
+ break;
+ }
+ } while (*(++token2) != '\0');
+ }
+
+ if(in->type == NUMBER)
+ *value = strtoll(token, NULL, 0);
+ else
+ goto error;
+ return 1;
+error:
+ in->error(in,"incorrect size specification");
+ return 0;
}
char * getDescription(parse_file_t *in)
{
long int pos;
- char * token, car, *str;
+ char * token, *str;
+ int car;
pos = ftell(in->fp);
getFacilityAttributes(in, fac);
if(fac->name == NULL) in->error(in, "Attribute not named");
-
+
fac->capname = allocAndCopy(fac->name);
strupper(fac->capname);
getRAnglebracket(in);
getRAnglebracket(in);
f->description = getDescription(in);
+ } else {
+ f->description = NULL;
}
//<int size=...>
//getLAnglebracket(in); //<subtype>
/* subfield */
- f = (field_t *)memAlloc(sizeof(field_t));
- sequence_push(&(t->fields),f);
+ f = (field_t *)memAlloc(sizeof(field_t));
+
+ f->name = NULL;
+ sequence_push(&(t->fields),f);
parseFields(in, f, unnamed_types, named_types, 0);
//getLAnglebracket(in); //<type struct>
else if(strcmp(token,"sequence") == 0) {
t->type = SEQUENCE;
sequence_init(&(t->fields));
- //getTypeAttributes(in, t, unnamed_types, named_types);
- //getForwardslash(in);
+ getTypeAttributes(in, t, unnamed_types, named_types);
+ getForwardslash(in);
getRAnglebracket(in); //<sequence>
//getLAnglebracket(in); //<sequence size type>
/* subfield */
- f = (field_t *)memAlloc(sizeof(field_t));
- sequence_push(&(t->fields),f);
+ f = (field_t *)memAlloc(sizeof(field_t));
+ f->name = NULL;
+ sequence_push(&(t->fields),f);
parseFields(in, f, unnamed_types, named_types, 0);
//getLAnglebracket(in); //<subtype>
/* subfield */
- f = (field_t *)memAlloc(sizeof(field_t));
- sequence_push(&(t->fields),f);
+ f = (field_t *)memAlloc(sizeof(field_t));
+ f->name = NULL;
+ sequence_push(&(t->fields),f);
parseFields(in, f, unnamed_types, named_types, 0);
//getLAnglebracket(in); //<type sequence>
}
else if(strcmp(token,"enum") == 0) {
char * str;
- int value = -1;
+ long long value = -1;
t->type = ENUM;
sequence_init(&(t->labels));
token = getToken(in); //"label" or "/"
while(strcmp("label",token) == 0){
int *label_value = malloc(sizeof(int));
+ int has_value = 0;
+ long long loc_value;
- str = allocAndCopy(getNameAttribute(in));
- token = getValueStrAttribute(in);
+ str = allocAndCopy(getNameAttribute(in));
+ has_value = getValueAttribute(in, &loc_value);
- sequence_push(&(t->labels),str);
+ sequence_push(&(t->labels),str);
- if(token) value = strtol(token, NULL, 0);
+ if(has_value) value = loc_value;
else value++;
*label_value = value;
}
else if(strcmp(token,"char") == 0) {
t->type = CHAR;
- t->size = 1;
getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 1;
getForwardslash(in);
getRAnglebracket(in);
}
else if(strcmp(token,"uchar") == 0) {
t->type = UCHAR;
- t->size = 1;
getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 1;
getForwardslash(in);
getRAnglebracket(in);
}
else if(strcmp(token,"short") == 0) {
t->type = SHORT;
- t->size = 2;
getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 2;
getForwardslash(in);
getRAnglebracket(in);
}
else if(strcmp(token,"ushort") == 0) {
t->type = USHORT;
- t->size = 2;
getTypeAttributes(in, t, unnamed_types, named_types);
+ t->size = 2;
getForwardslash(in);
getRAnglebracket(in);
}
char *token;
token = getToken(in);
- if(in->type != NAME) in->error(in,"Name token was expected");
+ // Optional descriptions
+ // if(in->type != NAME) in->error(in,"Name token was expected");
return token;
}
return token;
}
-char seekNextChar(parse_file_t *in)
+int seekNextChar(parse_file_t *in)
{
- char car;
+ int car;
while((car = getc(in->fp)) != EOF) {
if(!isspace(car)){
ungetc(car,in->fp);
char *getToken(parse_file_t * in)
{
FILE *fp = in->fp;
- char car, car1;
+ int car, car1;
int pos = 0, escaped;
if(in->unget == 1) {
escaped = 0;
while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
if(car == '\\' && escaped == 0) {
- in->buffer[pos] = car;
- pos++;
+ in->buffer[pos] = car;
+ pos++;
escaped = 1;
continue;
}
in->buffer[pos] = car;
pos++;
}
- if(car == EOF) ungetc(car,fp);
+ if(car == EOF) ungetc(car,fp);
if(pos == BUFFER_SIZE) in->error(in, "number token too large");
in->type = NUMBER;
- }
- else if(isalpha(car)) {
+ }
+ else if(isalnum(car) || car == '_' || car == '-') {
in->buffer[0] = car;
pos = 1;
while((car = getc(fp)) != EOF && pos < BUFFER_SIZE) {
- if(!(isalnum(car) || car == '_')) {
+ if(!(isalnum(car) || car == '_' || car == '-')) {
ungetc(car,fp);
break;
}
in->buffer[pos] = car;
pos++;
}
- if(car == EOF) ungetc(car,fp);
+ if(car == EOF) ungetc(car,fp);
if(pos == BUFFER_SIZE) in->error(in, "name token too large");
in->type = NAME;
- }
+ } else if(car == '?') {
+ in->buffer[0] = car;
+ pos++;
+ }
else in->error(in, "invalid character, unrecognized token");
}
in->buffer[pos] = 0;
void skipComment(parse_file_t * in)
{
- char car;
+ int car;
while((car = getc(in->fp)) != EOF) {
if(car == '\n') in->lineno++;
else if(car == '*') {
void skipEOL(parse_file_t * in)
{
- char car;
+ int car;
while((car = getc(in->fp)) != EOF) {
if(car == '\n') {
ungetc(car,in->fp);
unsigned long crc ;
int pos;
event_t * ev;
+ unsigned int i;
crc = crc32(facName);
for(pos = 0; pos < events->position; pos++){
ev = (event_t *)(events->array[pos]);
crc = partial_crc32(ev->name, crc);
- for(unsigned int i = 0; i < ev->fields.position; i++) {
+ for(i = 0; i < ev->fields.position; i++) {
field_t *f = (field_t*)ev->fields.array[i];
crc = partial_crc32(f->name, crc);
crc = getTypeChecksum(crc, f->type);
flag = 1;
break;
case SEQUENCE:
- sprintf(buf,"%zu", type->size);
- str = appendString("sequence ",buf);
+ str = allocAndCopy("sequence ");
flag = 1;
break;
case STRUCT:
void *sequence_pop(sequence_t *t)
{
- return t->array[t->position--];
+ if(t->position == 0) printf("Error : trying to pop an empty sequence");
+ return t->array[--t->position];
}
strcat(tmp,suffix);
return tmp;
}
-
-