Commit 4143e65f authored by Sven Robertz's avatar Sven Robertz
Browse files

array skipping maybe works

parent a733b92f
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#undef DEBUG_STACK #undef DEBUG_STACK
#undef DEBUG_READ #undef DEBUG_READ
#define EXIT_WHEN_RECEIVING_DATA //arrays (at least varsize not working) #undef EXIT_WHEN_RECEIVING_DATA //arrays (at least varsize not working)
#define FALSE 0 #define FALSE 0
#define TRUE 1 #define TRUE 1
...@@ -437,7 +437,7 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po ...@@ -437,7 +437,7 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po
unsigned int skip = 0; unsigned int skip = 0;
unsigned int tot_nbr_elem_tmp = 1; unsigned int tot_nbr_elem_tmp = 1;
unsigned int nIdx = unpack32(sig, *pos); unsigned int nIdx = unpack32(sig, *pos);
printf("skip_array: nIdx = %d\n", nIdx); printf("skip_array: nIdx = %d (from sig)\n", nIdx);
*pos +=4; *pos +=4;
unsigned int idx[nIdx]; unsigned int idx[nIdx];
unsigned int nVar=0; unsigned int nVar=0;
...@@ -447,7 +447,7 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po ...@@ -447,7 +447,7 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po
for(i=0; i<nIdx; i++) { for(i=0; i<nIdx; i++) {
idx[i] = unpack32(sig, *pos); idx[i] = unpack32(sig, *pos);
*pos += 4; *pos += 4;
printf("skip_array: idx[%d]=%d\n", i, idx[i]); printf("skip_array: idx[%d]=%d (from sig)\n", i, idx[i]);
if(idx[i] == 0) { if(idx[i] == 0) {
nVar++; nVar++;
} else { } else {
...@@ -458,7 +458,8 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po ...@@ -458,7 +458,8 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po
for(i=0; i<nVar; i++) { for(i=0; i<nVar; i++) {
var[i] = get32(d); var[i] = get32(d);
printf("skip_array: var[%d]=%d\n", i, var[i]); printf("skip_array: var[%d]=%d (from sample)\n", i, var[i]);
tot_nbr_elem_tmp *= var[i];
} }
unsigned int type = unpack32(sig, *pos); unsigned int type = unpack32(sig, *pos);
...@@ -468,13 +469,11 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po ...@@ -468,13 +469,11 @@ int skip_array(buffer *d, unsigned char *sig, unsigned int len, unsigned int *po
skip = elemSize * tot_nbr_elem_tmp; skip = elemSize * tot_nbr_elem_tmp;
printf("skip_array: skip: %d * %d = %d\n", elemSize, tot_nbr_elem_tmp, skip); printf("skip_array: skip: %d * %d = %d\n", tot_nbr_elem_tmp, elemSize ,skip);
advancen(d, skip); advancen(d, skip);
skip += nVar; return skip + 4*nVar;
return skip;
} }
int skip_struct(buffer *d, unsigned char *sig, unsigned int len, unsigned int *pos) { int skip_struct(buffer *d, unsigned char *sig, unsigned int len, unsigned int *pos) {
...@@ -486,14 +485,19 @@ int skip_struct(buffer *d, unsigned char *sig, unsigned int len, unsigned int *p ...@@ -486,14 +485,19 @@ int skip_struct(buffer *d, unsigned char *sig, unsigned int len, unsigned int *p
for(i=0; i<nFields; i++) { for(i=0; i<nFields; i++) {
//skip name //skip name
unsigned int namelen = unpack32(sig, *pos); unsigned int namelen = unpack32(sig, *pos);
*pos += (4+namelen); // 32bit len + actual string
#ifdef DEBUG #ifdef DEBUG
printf("namelen==%d \n",namelen); printf("namelen==%d",namelen);
char name[namelen+1];
name[namelen]=0;
strncpy(name, sig+*pos+4, namelen);
printf(", name = %s",name);
#endif #endif
*pos += (4+namelen); // 32bit len + actual string
unsigned int type = unpack32(sig, *pos); unsigned int type = unpack32(sig, *pos);
*pos += 4; *pos += 4;
#ifdef DEBUG #ifdef DEBUG
printf("type == %x\n", type); printf(": type == %x\n", type);
#endif #endif
skipped += skip_type(type, d, sig, len, pos); skipped += skip_type(type, d, sig, len, pos);
} }
...@@ -548,6 +552,7 @@ int skip_type(unsigned int type, buffer *d, ...@@ -548,6 +552,7 @@ int skip_type(unsigned int type, buffer *d,
case ARRAY_DECL : case ARRAY_DECL :
printf("array\n"); printf("array\n");
skipped += skip_array(d, sig, len, pos); skipped += skip_array(d, sig, len, pos);
break;
case STRUCT_DECL : case STRUCT_DECL :
printf("struct\n"); printf("struct\n");
skipped += skip_struct(d, sig, len, pos); skipped += skip_struct(d, sig, len, pos);
...@@ -590,8 +595,8 @@ int skip_type(unsigned int type, buffer *d, ...@@ -590,8 +595,8 @@ int skip_type(unsigned int type, buffer *d,
skipped+=len+4; skipped+=len+4;
break;} break;}
case ARRAY_DECL : case ARRAY_DECL :
printf("array\n");
skipped += skip_array(d, sig, len, pos); skipped += skip_array(d, sig, len, pos);
break;
case STRUCT_DECL : case STRUCT_DECL :
skipped += skip_struct(d, sig, len, pos); skipped += skip_struct(d, sig, len, pos);
break; break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment