sfeed

Simple RSS and Atom feed parser
git clone https://git.sinitax.com/codemadness/sfeed
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

util.h (2253B)


      1#include <stdio.h>
      2#include <time.h>
      3
      4#ifdef __OpenBSD__
      5#include <unistd.h>
      6#else
      7#define pledge(p1,p2) 0
      8#define unveil(p1,p2) 0
      9#endif
     10
     11/* ctype-like macros, but always compatible with ASCII / UTF-8 */
     12#define ISALPHA(c) ((((unsigned)c) | 32) - 'a' < 26)
     13#define ISCNTRL(c) ((c) < ' ' || (c) == 0x7f)
     14#define ISDIGIT(c) (((unsigned)c) - '0' < 10)
     15#define ISSPACE(c) ((c) == ' ' || ((((unsigned)c) - '\t') < 5))
     16#define TOLOWER(c) ((((unsigned)c) - 'A' < 26) ? ((c) | 32) : (c))
     17
     18#undef strcasestr
     19char *strcasestr(const char *, const char *);
     20#undef strlcat
     21size_t strlcat(char *, const char *, size_t);
     22#undef strlcpy
     23size_t strlcpy(char *, const char *, size_t);
     24
     25#ifndef SFEED_DUMBTERM
     26#define PAD_TRUNCATE_SYMBOL    "\xe2\x80\xa6" /* symbol: "ellipsis" */
     27#define UTF_INVALID_SYMBOL     "\xef\xbf\xbd" /* symbol: "replacement" */
     28#else
     29#define PAD_TRUNCATE_SYMBOL    "."
     30#define UTF_INVALID_SYMBOL     "?"
     31#endif
     32
     33/* feed info */
     34struct feed {
     35	char         *name;     /* feed name */
     36	unsigned long totalnew; /* amount of new items per feed */
     37	unsigned long total;    /* total items */
     38	/* sfeed_curses */
     39	char         *path;     /* path to feed or NULL for stdin */
     40	FILE         *fp;       /* file pointer */
     41};
     42
     43/* URI */
     44struct uri {
     45	char proto[48];     /* scheme including ":" or "://" */
     46	char userinfo[256]; /* username [:password] */
     47	char host[256];
     48	char port[6];       /* numeric port */
     49	char path[1024];
     50	char query[1024];
     51	char fragment[1024];
     52};
     53
     54enum {
     55	FieldUnixTimestamp = 0, FieldTitle, FieldLink, FieldContent,
     56	FieldContentType, FieldId, FieldAuthor, FieldEnclosure, FieldCategory,
     57	FieldLast
     58};
     59
     60/* hint for compilers and static analyzers that a function exits */
     61#ifndef __dead
     62#define __dead
     63#endif
     64
     65__dead void err(int, const char *, ...);
     66__dead void errx(int, const char *, ...);
     67
     68int uri_format(char *, size_t, struct uri *);
     69int uri_hasscheme(const char *);
     70int uri_makeabs(struct uri *, struct uri *, struct uri *);
     71int uri_parse(const char *, struct uri *);
     72
     73void checkfileerror(FILE *, const char *, int);
     74time_t getcomparetime(void);
     75void parseline(char *, char *[FieldLast]);
     76void printutf8pad(FILE *, const char *, size_t, int);
     77int  strtotime(const char *, time_t *);
     78void xmlencode(const char *, FILE *);