ECC-917: eccodes_memfs (part 1)

This commit is contained in:
Shahram Najm 2020-04-02 16:46:49 +01:00
parent f0f1fec2a8
commit 4731805b7e
1 changed files with 15 additions and 4 deletions

View File

@ -28,6 +28,7 @@ print('Directories: ', dirs)
print('Excluding: ', EXCLUDED)
FILES = {}
SIZES = {}
NAMES = []
# Binary to ASCII function. Different in Python 2 and 3
@ -61,28 +62,32 @@ for directory in dirs:
if ext not in ['.def', '.table', '.tmpl']:
continue
fsize = os.path.getsize(full)
full = full.replace("\\","/")
fname = full[full.find("/%s/" % (dname,)):]
#print("MEMFS add", fname)
name = re.sub(r'\W', '_', fname)
assert name not in FILES
assert name not in SIZES
FILES[name] = fname
SIZES[name] = fsize
print('static const unsigned char %s[] = {' % (name,), file=g)
#print('const unsigned char %s[] = {' % (name,), file=g) #NEW
with open(full, 'rb') as f:
i = 0
#Python 2
#fcont = f.read().encode("hex")
#contents_hex = f.read().encode("hex")
#Python 2 and 3
fcont = binascii.hexlify(f.read())
contents_hex = binascii.hexlify(f.read())
# Read two characters at a time and convert to C hex
# e.g. 23 -> 0x23
for n in range(0, len(fcont), 2):
twoChars = ascii(fcont[n:n+2])
for n in range(0, len(contents_hex), 2):
twoChars = ascii(contents_hex[n:n+2])
print("0x%s," % (twoChars,), end="", file=g)
i += 1
if (i % 20) == 0:
@ -101,7 +106,13 @@ print("""
#include <errno.h>
#include <string.h>
#include "eccodes_windef.h"
""", file=g)
# NEW
#for k, v in SIZES.items():
# print ('extern const unsigned char %s[%d];' % (k, v), file=g)
print("""
struct entry {
const char* path;
const unsigned char* content;