util.h - sfeed - RSS and Atom parser
(HTM) git clone git://git.codemadness.org/sfeed
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
util.h (2361B)
---
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
19 char *strcasestr(const char *, const char *);
20 #undef strlcat
21 size_t strlcat(char *, const char *, size_t);
22 #undef strlcpy
23 size_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 */
34 struct 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 */
44 struct 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
54 enum {
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 does not return.
61 * some compilers use: __attribute__((noreturn)), _Noreturn, noreturn */
62 #ifndef __dead
63 #define __dead
64 #endif
65
66 __dead void err(int, const char *, ...);
67 __dead void errx(int, const char *, ...);
68
69 int uri_format(char *, size_t, struct uri *);
70 int uri_hasscheme(const char *);
71 int uri_makeabs(struct uri *, struct uri *, struct uri *);
72 int uri_parse(const char *, struct uri *);
73
74 void checkfileerror(FILE *, const char *, int);
75 size_t colw(const char *);
76 time_t getcomparetime(void);
77 void parseline(char *, char *[FieldLast]);
78 void printutf8pad(FILE *, const char *, size_t, int);
79 int strtotime(const char *, time_t *);
80 void xmlencode(const char *, FILE *);