gemtext-parser/include/gemtext-parser.h
2023-10-07 13:24:32 -04:00

79 lines
No EOL
1.4 KiB
C

#ifndef GEMTEXT_PARSER_H
#define GEMTEXT_PARSER_H 1
#include <pthread.h> // pthread_mutex_t, pthread_cond_t
#include <stddef.h> // size_t
#include <stdio.h> // FILE
#define LBUF_SIZE 512
typedef enum {
normalMode,
preformattedMode,
quoteMode,
} gemtextParserMode;
typedef enum {
lineStart,
firstLinkChar,
secondLinkChar,
firstHashChar,
secondHashChar,
thirdHashChar,
firstBacktickChar,
secondBacktickChar,
thirdBacktickChar,
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 {
FILE *stream;
gemtextParserMode mode;
gemtextParserState state;
} gemtextParser;
struct _gemtextLine {
struct _gemtextLine *next;
struct _gemtextLine *prev;
gemtextLineType lineType;
union {
char *str;
gemtextLink *link;
};
};
typedef struct _gemtextLine gemtextLine;
typedef struct {
pthread_cond_t cond;
size_t count;
pthread_mutex_t mutex;
gemtextLine *head;
gemtextLine *tail;
} gemtextLineQueue;
#endif