small weather widget for X11
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 146 lines 4.6 kB view raw
1/* 2 * Fetched from https://github.com/skeeto/pdjson 67108d883 3 * 4 * This is free and unencumbered software released into the public domain. 5 * 6 * Anyone is free to copy, modify, publish, use, compile, sell, or 7 * distribute this software, either in source code form or as a compiled 8 * binary, for any purpose, commercial or non-commercial, and by any 9 * means. 10 * 11 * In jurisdictions that recognize copyright laws, the author or authors 12 * of this software dedicate any and all copyright interest in the 13 * software to the public domain. We make this dedication for the benefit 14 * of the public at large and to the detriment of our heirs and 15 * successors. We intend this dedication to be an overt act of 16 * relinquishment in perpetuity of all present and future rights to this 17 * software under copyright law. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 * OTHER DEALINGS IN THE SOFTWARE. 26 * 27 * For more information, please refer to <http://unlicense.org/> 28 */ 29 30#ifndef PDJSON_H 31#define PDJSON_H 32 33#ifndef PDJSON_SYMEXPORT 34# define PDJSON_SYMEXPORT 35#endif 36 37#ifdef __cplusplus 38extern "C" { 39#else 40#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) 41 #include <stdbool.h> 42#else 43 #ifndef bool 44 #define bool int 45 #define true 1 46 #define false 0 47 #endif /* bool */ 48#endif /* __STDC_VERSION__ */ 49#endif /* __cplusplus */ 50 51#include <stdio.h> 52 53enum json_type { 54 JSON_ERROR = 1, JSON_DONE, 55 JSON_OBJECT, JSON_OBJECT_END, JSON_ARRAY, JSON_ARRAY_END, 56 JSON_STRING, JSON_NUMBER, JSON_TRUE, JSON_FALSE, JSON_NULL 57}; 58 59struct json_allocator { 60 void *(*malloc)(size_t); 61 void *(*realloc)(void *, size_t); 62 void (*free)(void *); 63}; 64 65typedef int (*json_user_io)(void *user); 66 67typedef struct json_stream json_stream; 68typedef struct json_allocator json_allocator; 69 70PDJSON_SYMEXPORT void json_open_buffer(json_stream *json, const void *buffer, size_t size); 71PDJSON_SYMEXPORT void json_open_string(json_stream *json, const char *string); 72PDJSON_SYMEXPORT void json_open_stream(json_stream *json, FILE *stream); 73PDJSON_SYMEXPORT void json_open_user(json_stream *json, json_user_io get, json_user_io peek, void *user); 74PDJSON_SYMEXPORT void json_close(json_stream *json); 75 76PDJSON_SYMEXPORT void json_set_allocator(json_stream *json, json_allocator *a); 77PDJSON_SYMEXPORT void json_set_streaming(json_stream *json, bool mode); 78 79PDJSON_SYMEXPORT enum json_type json_next(json_stream *json); 80PDJSON_SYMEXPORT enum json_type json_peek(json_stream *json); 81PDJSON_SYMEXPORT void json_reset(json_stream *json); 82PDJSON_SYMEXPORT const char *json_get_string(json_stream *json, size_t *length); 83PDJSON_SYMEXPORT double json_get_number(json_stream *json); 84 85PDJSON_SYMEXPORT enum json_type json_skip(json_stream *json); 86PDJSON_SYMEXPORT enum json_type json_skip_until(json_stream *json, enum json_type type); 87 88PDJSON_SYMEXPORT size_t json_get_lineno(json_stream *json); 89PDJSON_SYMEXPORT size_t json_get_position(json_stream *json); 90PDJSON_SYMEXPORT size_t json_get_depth(json_stream *json); 91PDJSON_SYMEXPORT enum json_type json_get_context(json_stream *json, size_t *count); 92PDJSON_SYMEXPORT const char *json_get_error(json_stream *json); 93 94PDJSON_SYMEXPORT int json_source_get(json_stream *json); 95PDJSON_SYMEXPORT int json_source_peek(json_stream *json); 96PDJSON_SYMEXPORT bool json_isspace(int c); 97 98/* internal */ 99 100struct json_source { 101 int (*get)(struct json_source *); 102 int (*peek)(struct json_source *); 103 size_t position; 104 union { 105 struct { 106 FILE *stream; 107 } stream; 108 struct { 109 const char *buffer; 110 size_t length; 111 } buffer; 112 struct { 113 void *ptr; 114 json_user_io get; 115 json_user_io peek; 116 } user; 117 } source; 118}; 119 120struct json_stream { 121 size_t lineno; 122 123 struct json_stack *stack; 124 size_t stack_top; 125 size_t stack_size; 126 enum json_type next; 127 unsigned flags; 128 129 struct { 130 char *string; 131 size_t string_fill; 132 size_t string_size; 133 } data; 134 135 size_t ntokens; 136 137 struct json_source source; 138 struct json_allocator alloc; 139 char errmsg[128]; 140}; 141 142#ifdef __cplusplus 143} /* extern "C" */ 144#endif /* __cplusplus */ 145 146#endif