#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>

#pragma clang diagnostic ignored "-Wshift-op-parentheses"
#pragma clang diagnostic ignored "-Wbitwise-op-parentheses"

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef int32_t s32;
typedef uint64_t u64;

static inline u16 g16(void *p) { return ((u8 *)p)[0] | ((u8 *)p)[1]<<8; }
static inline u32 g32(void *p) { return g16(p) | g16((u8 *)p + 2)<<16; }
static inline u64 g64(void *p) { return g32(p) | (u64)g32((u8 *)p + 4)<<32; }
static inline void p16(void *p, u16 v) { ((u8 *)p)[0] = v; ((u8 *)p)[1] = v>>8; }

#define elemof(T) (sizeof T/sizeof*T)
#define endof(T) (T+elemof(T))

typedef struct {
	u8 *ptr;
	unsigned len;
} meml_t;

double ieee754(u64);

int ole_open(char *name);
meml_t get_workbook();

void output(char *format, ...);
u8 *output_unicode(u8 *ptr, int len, u8 flag);
void set_codepage(int n);
u8 *output_cp_string(u8 *ptr, int len);
