sfeed

simple feed reader - forked from https://git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeedsfeed.zip
Log | Files | Refs | Atom | README | LICENSE

util.h (raw) (2224B)


   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 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 
  68 int uri_format(char *, size_t, struct uri *);
  69 int uri_hasscheme(const char *);
  70 int uri_makeabs(struct uri *, struct uri *, struct uri *);
  71 int uri_parse(const char *, struct uri *);
  72 
  73 void checkfileerror(FILE *, const char *, int);
  74 void parseline(char *, char *[FieldLast]);
  75 void printutf8pad(FILE *, const char *, size_t, int);
  76 int  strtotime(const char *, time_t *);
  77 void xmlencode(const char *, FILE *);