#ifndef GEMTEXT_PARSER_H #define GEMTEXT_PARSER_H 1 #include // pthread_mutex_t, pthread_cond_t #include // size_t #include // FILE #define LBUF_SIZE 512 typedef enum { normalMode, preformattedMode, quoteMode, linkMode, h1Mode, h2Mode, h3Mode, listMode, } gemtextParserMode; typedef enum { lineStart, lineEnd, firstLinkChar, linkDisplayStart, linkDisplay, firstHashChar, secondHashChar, thirdHashChar, firstBacktickChar, secondBacktickChar, thirdBacktickChar, preformattedAlt, trimStart, normalState, } gemtextParserState; typedef enum { normalLine, linkLine, listLine, h1Line, h2Line, h3Line, preformattedLine, quoteLine, endOfStream, } gemtextLineType; typedef struct { size_t capacity; size_t len; char *cursor; char *buf; } lineBuffer; typedef struct { char *url; char *display; } gemtextLink; typedef struct { char *altText; char *body; } preformattedNode; typedef struct { FILE *stream; gemtextParserMode mode; gemtextParserState state; lineBuffer buffer; union { char *linkUrl; char *altText; }; } gemtextParser; struct _gemtextLine { struct _gemtextLine *next; struct _gemtextLine *prev; gemtextLineType lineType; union { char *str; gemtextLink *link; preformattedNode *node; }; }; typedef struct _gemtextLine gemtextLine; typedef struct { pthread_cond_t cond; size_t count; pthread_mutex_t mutex; gemtextLine *head; gemtextLine *tail; } gemtextLineQueue; #endif