util.h 2.2 KB

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