Browse Source

clearification of keysize descriptor stuff

master
bg 8 years ago
parent
commit
4702ee6467
1 changed files with 18 additions and 19 deletions
  1. +18
    -19
      bcal/keysize_descriptor.c

+ 18
- 19
bcal/keysize_descriptor.c View File

@@ -28,50 +28,49 @@
#include <stdlib.h>
#include "keysize_descriptor.h"

#define KS8 ((uint8_t*)ks_desc)
uint8_t is_valid_keysize_P(const void* ks_desc, uint16_t keysize){
uint8_t type;
type = *((uint8_t*)ks_desc);
ks_desc = (uint8_t*)ks_desc + 1;
type = KS8[0];
ks_desc = KS8 + 1;
if(type==KS_TYPE_TERMINATOR)
return 0;
if(type==KS_TYPE_LIST){
uint8_t items;
uint16_t item;
items = *((uint8_t*)ks_desc);
ks_desc = (uint8_t*)ks_desc + 1;
items = KS8[0];
ks_desc = KS8 + 1;
while(items--){
item = *((uint16_t*)ks_desc);
ks_desc = (uint8_t*)ks_desc + 2;
item = KS8[1] * 256 + KS8[0];
ks_desc = KS8 + 2;
if(item==keysize)
return 1;
}
ks_desc = (uint8_t*)ks_desc - 2;
ks_desc = KS8 - 2;
}
if(type==KS_TYPE_RANGE){
uint16_t max, min;
min = *((uint16_t*)ks_desc);
min = KS8[1] * 256 + KS8[0];
ks_desc = (uint8_t*)ks_desc + 2;
max = *((uint16_t*)ks_desc);
if(min<=keysize && keysize<=max)
max = KS8[1] * 256 + KS8[0];
if(min <= keysize && keysize <= max)
return 1;
}
if(type==KS_TYPE_ARG_RANGE){
uint16_t max, min, dist, offset;
min = *((uint16_t*)ks_desc);
ks_desc = (uint8_t*)ks_desc + 2;
max = *((uint16_t*)ks_desc);
ks_desc = (uint8_t*)ks_desc + 2;
dist = *((uint16_t*)ks_desc);
ks_desc = (uint8_t*)ks_desc + 2;
offset = *((uint16_t*)ks_desc);
if(min<=keysize && keysize<=max && (keysize%dist==offset))
min = KS8[1] * 256 + KS8[0];
max = KS8[3] * 256 + KS8[2];
dist = KS8[5] * 256 + KS8[4];
offset = KS8[7] * 256 + KS8[6];
ks_desc = KS8 + 6;
if(min <= keysize && keysize <= max && (keysize % dist == offset))
return 1;
}
if(type>KS_TYPE_ARG_RANGE){
/* bad error, you may insert a big warning message here */
return 0;
}
return is_valid_keysize_P((uint8_t*)ks_desc+1, keysize); /* search the next record */
return is_valid_keysize_P(KS8+1, keysize); /* search the next record */
}

uint16_t get_keysize(const void* ks_desc){


Loading…
Cancel
Save