// CSS parser along very much the same lines as the sam/html.c html parser

#ifndef CSS_HEADER
#define CSS_HEADER

#include <stddef.h>
#include "lib.h"

#define NAMELEN 72

//typedef struct tag {
//	char name[NAMELEN];
//	int isendtag;
//	Pair *attributes;
//	Wordlist *flags;
//} Tag;

typedef struct CSS {
	char *text;
	int text_len;

	char *raw;
	int raw_len;

//	Tag tag;
	int want_selector;
	int ignore;						// Allow whole CSS rules to be removed
	int start_done, done_some;		// Allow whole blank css blocks to be removed
	int start_media, in_media;

	char *work;
	int size;
	int bytes;
	int upto;

	size_t(*read)(char *,size_t,size_t,void *);
	size_t(*write)(const char *,size_t,size_t,void *);
	int(*error)(void *);
	int(*eof)(void *);

	char *logmsg;

	int warned;
} Css;

Css *css_new(int _bytes);
void css_reset(Css *h);
void css_free(Css **h);

void css_logmsg(Css *h, char *logmsg);

int css_scan(Css *h, FILE *f);

void css_setup(Css *h, size_t(*read)(char *,size_t,size_t,void *), size_t(*write)(const char *,size_t,size_t,void *), int(*error)(void *), int(*eof)(void *));
int css_scan_ex(Css *h, void *d);

/* return values (must match strings in css.c) */ 
enum {
	CSS_PARAM,		//param error
	CSS_FILE,		//file error
	CSS_BUF,		//buffer too small
	CSS_END,		//finished
	CSS_SELECTOR,   //css selector
	CSS_SELECTOR_COMMA, //comma before next selector
	CSS_DECL_START, //declaration opening {
	CSS_DECL,		//css declaration
	CSS_DECL_END,	//declaration closing }
	CSS_COMMENT,	//comment found
	CSS_SPACE,		//whitespace
	CSS_EOL,		//end of line
	CSS_IGNORE,		//html comments get ignored
	CSS_MORE,		//more data required
	CSS_MEDIA_START,// @media blocks
	CSS_MEDIA_END
};

//void css_write_tag(Tag *tag, FILE *f, void(*fn)(FILE *,Tag *,char *,char *,int));
//void css_write_tag_simple(Css *h, Tag *tag, void *d);

//void css_tag_copy(Tag *dst, Tag *t);
//void css_tag_free(Tag *tag);
void css_log(Css *h,char*txt, char*tag, int k, int cur_buffer_size, int fn(const char * arg_list, ...));

#endif

