Commit 52bf241e authored by Zhukov, Alexander P's avatar Zhukov, Alexander P
Browse files

WIP

parent 24112e05
No preview for this file type
......@@ -3,6 +3,22 @@
#include <stdlib.h>
#include <byteswap.h>
unsigned long encodeDbl(double a){
unsigned long b;
unsigned char *src = (unsigned char *)&a,
*dst = (unsigned char *)&b;
dst[0] = src[7];
dst[1] = src[6];
dst[2] = src[5];
dst[3] = src[4];
dst[4] = src[3];
dst[5] = src[2];
dst[6] = src[1];
dst[7] = src[0];
return b;
}
typedef struct storage {
FILE* file;
unsigned long* contents;
......@@ -25,14 +41,20 @@ BinaryStorage bs_open(char* filename){
return storage;
}
int write_record(BinaryStorage *bs, char* name){
int write_record(BinaryStorage *bs, char* name, double value){
unsigned char name_len = strlen(name);
unsigned int total_length = bswap_32(1+1+name_len+1);
unsigned int total_length = bswap_32(1+1+name_len+1+8+1);
fwrite(&total_length,4,1,bs->file);
fputc(1,bs->file);
fwrite(&name_len,1,1,bs->file);
fwrite(name, 1,name_len,bs->file);
fputc(17,bs->file);
unsigned long rawdata = encodeDbl(value);
fwrite(&rawdata,8,1,bs->file);
fputc(254,bs->file);
bs->contents[bs->con_idx]=ftell(bs->file);
......@@ -63,6 +85,6 @@ void bs_close(BinaryStorage *bs){
int main(){
printf("Hello World!\n");
BinaryStorage storage = bs_open("test_c.bin");
write_record(&storage,"Hello World!");
write_record(&storage,"Hello World!", 314);
bs_close(&storage);
}
......@@ -29,7 +29,8 @@ print(args.file,'has',len(file), 'records')
def show(record):
if 'value' in record:
value = record['value']
record['value'] = value[0]
if isinstance(value,(str,list,tuple)):
record['value'] = value[0]
return record
if(not args.index):
......
Markdown is supported
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