86 lines
No EOL
1.5 KiB
C
86 lines
No EOL
1.5 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,
|
|
linkMode,
|
|
h1Mode,
|
|
h2Mode,
|
|
h3Mode,
|
|
listMode,
|
|
} gemtextParserMode;
|
|
|
|
typedef enum {
|
|
lineStart,
|
|
lineEnd,
|
|
firstLinkChar,
|
|
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;
|
|
lineBuffer buffer;
|
|
char *linkUrl;
|
|
} 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 |