WONKY



LOG | FILES | OVERVIEW


#ifndef WONKY_STREAM_H
#define WONKY_STREAM_H WONKY_STREAM_H
#include <wonky_stream.hh>
#include <common.h>
#include <gcc_string.h>


struct wonky_stream
{
	ssize_t (*read)(void *state,void *dst,size_t num_bytes);
	ssize_t (*write)(void *state,void *src,size_t num_bytes);
	_Bool (*fseek)(void *state,size_t where,int whence);
	_Bool (*eof)(void *state);
	enum wonky_stream_type type;

	void *state;
};

struct wonky__scanformat
{
	size_t forward_crawl;
	enum wonky__scanformat_modifier modifier;
	enum wonky__scanformat_conversion conversion;
	_Bool alternate_form;
	_Bool wonky_form;
};


ssize_t wonky_read(struct wonky_stream *s,void *dst,size_t num_bytes);
ssize_t wonky_write(struct wonky_stream *s,void *src,size_t num_bytes);
ssize_t wonky_fseek(struct wonky_stream *s,size_t where,int whence);
ssize_t wonky_eof(struct wonky_stream *s);
int wonky_printf(const char *format,...);
int wonky_vprintf(const char *format,va_list args);
int wonky_fprintf(struct wonky_stream *s,const char *format,...);
int wonky_vfprintf(struct wonky_stream *s,const char *format,va_list args);


ssize_t wonky_stream_int_to_decimal(struct wonky_stream *s,intmax_t a);
ssize_t wonky_stream_uint_to_decimal(struct wonky_stream *s,uintmax_t a);
ssize_t wonky_stream_uint_to_hexadecimal(struct wonky_stream *s,uintmax_t a);
ssize_t wonky_stream_uint_to_octal(struct wonky_stream *s,uintmax_t a);
ssize_t wonky_stream_double_to_decimal(struct wonky_stream *s,double d);
ssize_t wonky_stream_from_fraction(struct wonky_stream *s,uint64_t a,uint64_t b,int precision);
struct wonky_stream wonky_stream_from_file(FILE *f);
void wonky_stream_delete(struct wonky_stream *s);

ssize_t wonky__FILE_read(void *state,void *dst,size_t num_bytes);
ssize_t wonky__FILE_write(void *state,void *src,size_t num_bytes);
_Bool wonky__FILE_fseek(void *state,size_t where,int whence);
_Bool wonky__FILE_eof(void *state);

ssize_t wonky__fail_read(void *state,void *dst,size_t num_bytes);
ssize_t wonky__fail_write(void *state,void *src,size_t num_bytes);
_Bool wonky__fail_fseek(void *state,size_t where,int whence);
_Bool wonky__fail_eof(void *state);
void wonky__parse_scan_format(const char *begining, struct wonky__scanformat *destination);
void wonky__from_scanformat(struct wonky__scanformat *fmt,va_list args,struct wonky_stream *destination,short *indentation);

/*float = 1 bit sign | 8 bit exponent | 23 bit mantissa*/
_Bool wonky__float_is_negative(float f);
int16_t wonky__float_get_exponent(float f);
uint32_t wonky__float_get_mantissa(float f);
float wonky__float_set_sign(float f,_Bool is_negative);
float wonky__float_set_exponent(float f,int16_t exponent);
float wonky__float_set_base(float f,uint32_t mantissa);

/*double = 1 bit sign | 11 bit exponent | 52 bit mantissa*/
_Bool wonky__double_is_negative(double d);
int16_t wonky__double_get_exponent(double d);
uint64_t wonky__double_get_mantissa(double d);
double wonky__double_set_sign(double d,_Bool is_negative);
double wonky__double_set_exponent(double d,int16_t exponent);
double wonky__double_set_mantissa(double d,uint64_t mantissa);

#endif