forked from Telodendria/Telodendria
Format headers as well.
indent(1) does a weird thing with prototype functions, but it's good enough for me, as long as it's consistent.
This commit is contained in:
parent
aabb2a0203
commit
3437c5db2c
9 changed files with 94 additions and 86 deletions
2
make.sh
2
make.sh
|
@ -74,7 +74,7 @@ recipe_clean() {
|
|||
}
|
||||
|
||||
recipe_format() {
|
||||
find src -name '*.c' | while IFS= read -r src; do
|
||||
find src -name '*.c' -or -name '*.h' | while IFS= read -r src; do
|
||||
echo "indent $src"
|
||||
indent -bad -bap -bbb -nbc -bl -c36 -cd36 -ncdb -nce \
|
||||
-ci8 -cli1 -d0 -di1 -ndj -ei -fc1 -i4 -ip -l72 \
|
||||
|
|
|
@ -45,7 +45,7 @@ TelodendriaPrintUsage(LogConfig * lc)
|
|||
Log(lc, LOG_MESSAGE, " -h Print this usage, then exit.");
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
LogConfig *lc;
|
||||
|
|
|
@ -6,27 +6,27 @@
|
|||
typedef struct Array Array;
|
||||
|
||||
extern Array *
|
||||
ArrayCreate(void);
|
||||
ArrayCreate(void);
|
||||
|
||||
extern size_t
|
||||
ArraySize(Array *array);
|
||||
ArraySize(Array * array);
|
||||
|
||||
extern void *
|
||||
ArrayGet(Array *array, size_t index);
|
||||
ArrayGet(Array * array, size_t index);
|
||||
|
||||
extern int
|
||||
ArrayInsert(Array *, void *value, size_t index);
|
||||
ArrayInsert(Array *, void *value, size_t index);
|
||||
|
||||
extern int
|
||||
ArrayAdd(Array *array, void *value);
|
||||
ArrayAdd(Array * array, void *value);
|
||||
|
||||
extern void *
|
||||
ArrayDelete(Array *array, size_t index);
|
||||
ArrayDelete(Array * array, size_t index);
|
||||
|
||||
extern void
|
||||
ArrayFree(Array *array);
|
||||
ArrayFree(Array * array);
|
||||
|
||||
extern int
|
||||
ArrayTrim(Array *array);
|
||||
ArrayTrim(Array * array);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,22 +4,21 @@
|
|||
#include <stddef.h>
|
||||
|
||||
extern size_t
|
||||
Base64EncodedSize(size_t inputSize);
|
||||
Base64EncodedSize(size_t inputSize);
|
||||
|
||||
extern size_t
|
||||
Base64DecodedSize(const char *base64, size_t len);
|
||||
Base64DecodedSize(const char *base64, size_t len);
|
||||
|
||||
extern char *
|
||||
Base64Encode(const char *input, size_t len);
|
||||
Base64Encode(const char *input, size_t len);
|
||||
|
||||
extern char *
|
||||
Base64Decode(const char *input, size_t len);
|
||||
Base64Decode(const char *input, size_t len);
|
||||
|
||||
extern void
|
||||
Base64Unpad(char *base64, size_t length);
|
||||
Base64Unpad(char *base64, size_t length);
|
||||
|
||||
extern int
|
||||
Base64Pad(char **base64Ptr, size_t length);
|
||||
Base64Pad(char **base64Ptr, size_t length);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -11,27 +11,27 @@ typedef struct ConfigDirective ConfigDirective;
|
|||
typedef struct ConfigParseResult ConfigParseResult;
|
||||
|
||||
extern ConfigParseResult *
|
||||
ConfigParse(FILE *stream);
|
||||
ConfigParse(FILE * stream);
|
||||
|
||||
extern unsigned int
|
||||
ConfigParseResultOk(ConfigParseResult *result);
|
||||
ConfigParseResultOk(ConfigParseResult * result);
|
||||
|
||||
extern size_t
|
||||
ConfigParseResultLineNumber(ConfigParseResult *result);
|
||||
ConfigParseResultLineNumber(ConfigParseResult * result);
|
||||
|
||||
extern HashMap *
|
||||
ConfigParseResultGet(ConfigParseResult *result);
|
||||
ConfigParseResultGet(ConfigParseResult * result);
|
||||
|
||||
extern void
|
||||
ConfigParseResultFree(ConfigParseResult *result);
|
||||
ConfigParseResultFree(ConfigParseResult * result);
|
||||
|
||||
extern Array *
|
||||
ConfigValuesGet(ConfigDirective *directive);
|
||||
ConfigValuesGet(ConfigDirective * directive);
|
||||
|
||||
extern HashMap *
|
||||
ConfigChildrenGet(ConfigDirective *directive);
|
||||
ConfigChildrenGet(ConfigDirective * directive);
|
||||
|
||||
extern void
|
||||
ConfigFree(HashMap *conf);
|
||||
ConfigFree(HashMap * conf);
|
||||
|
||||
#endif /* TELODENDRIA_CONFIG_H */
|
||||
#endif /* TELODENDRIA_CONFIG_H */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* documented, and generally readable and understandable, yet also
|
||||
* performant enough to be useful, because it is used extensively in
|
||||
* Telodendria.
|
||||
*
|
||||
*
|
||||
* Fundamentally, this is an entirely generic map implementation. It
|
||||
* can be used for many general purposes, but it is designed to only
|
||||
* implement the features that Telodendria needs to function well.
|
||||
|
@ -26,60 +26,60 @@ typedef struct HashMap HashMap;
|
|||
|
||||
/*
|
||||
* HashMapCreate: Create a new HashMap object.
|
||||
*
|
||||
*
|
||||
* Returns: A HashMap object that is ready to be used by the rest of
|
||||
* the HashMap functions, or NULL if memory could not be allocated on
|
||||
* the heap.
|
||||
*/
|
||||
extern HashMap *
|
||||
HashMapCreate(void);
|
||||
HashMapCreate(void);
|
||||
|
||||
extern void
|
||||
HashMapMaxLoadSet(HashMap *map, float load);
|
||||
HashMapMaxLoadSet(HashMap * map, float load);
|
||||
|
||||
/*
|
||||
* HashMapSet: Set the given key in the HashMap to the given value. Note
|
||||
* that the value is not copied into the HashMap's own memory space;
|
||||
* only the pointer is stored. It is the caller's job to ensure that the
|
||||
* value's memory remains valid for the life of the HashMap.
|
||||
*
|
||||
*
|
||||
* Returns: The previous value at the given key, or NULL if the key did
|
||||
* not previously exist or any of the parameters provided are NULL. All
|
||||
* keys must have values; you can't set a key to NULL. To delete a key,
|
||||
* use HashMapDelete.
|
||||
* use HashMapDelete.
|
||||
*/
|
||||
extern void *
|
||||
HashMapSet(HashMap * map, const char *key, void *value);
|
||||
HashMapSet(HashMap * map, const char *key, void *value);
|
||||
|
||||
/*
|
||||
* HashMapGet: Get the value for the given key.
|
||||
*
|
||||
*
|
||||
* Returns: The value at the given key, or NULL if the key does not
|
||||
* exist, no map was provided, or no key was provided.
|
||||
*/
|
||||
extern void *
|
||||
HashMapGet(HashMap * map, const char *key);
|
||||
HashMapGet(HashMap * map, const char *key);
|
||||
|
||||
/*
|
||||
* HashMapDelete: Delete the value for the given key.
|
||||
*
|
||||
*
|
||||
* Returns: The value at the given key, or NULL if the key does not
|
||||
* exist or the map or key was not provided.
|
||||
*/
|
||||
extern void *
|
||||
HashMapDelete(HashMap *map, const char *key);
|
||||
HashMapDelete(HashMap * map, const char *key);
|
||||
|
||||
extern void
|
||||
HashMapIterate(HashMap *map, void (*iteratorFunc)(void *));
|
||||
HashMapIterate(HashMap * map, void (*iteratorFunc) (void *));
|
||||
|
||||
/*
|
||||
* HashMapFree: Free the hash map, returning its memory to the operating
|
||||
* system. Note that this function does not free the values stored in
|
||||
* system. Note that this function does not free the values stored in
|
||||
* the map since this hash map implementation has no way of knowing
|
||||
* what actually is stored in it. You should use HashMapIterate to
|
||||
* free the values using your own algorithm.
|
||||
*/
|
||||
extern void
|
||||
HashMapFree(HashMap *map);
|
||||
HashMapFree(HashMap * map);
|
||||
|
||||
#endif /* TELODENDRIA_HASHMAP_H */
|
||||
#endif /* TELODENDRIA_HASHMAP_H */
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef TELODENDRIA_HTTP_H
|
||||
#define TELODENDRIA_HTTP_H
|
||||
|
||||
typedef enum HttpRequestMethod {
|
||||
typedef enum HttpRequestMethod
|
||||
{
|
||||
HTTP_GET,
|
||||
HTTP_HEAD,
|
||||
HTTP_POST,
|
||||
|
@ -13,12 +14,13 @@ typedef enum HttpRequestMethod {
|
|||
HTTP_PATCH
|
||||
} HttpRequestMethod;
|
||||
|
||||
typedef enum HttpStatus {
|
||||
typedef enum HttpStatus
|
||||
{
|
||||
/* Informational responses */
|
||||
HTTP_CONTINUE = 100,
|
||||
HTTP_SWITCHING_PROTOCOLS = 101,
|
||||
HTTP_EARLY_HINTS = 103,
|
||||
|
||||
|
||||
/* Successful responses */
|
||||
HTTP_OK = 200,
|
||||
HTTP_CREATED = 201,
|
||||
|
@ -27,7 +29,7 @@ typedef enum HttpStatus {
|
|||
HTTP_NO_CONTENT = 204,
|
||||
HTTP_RESET_CONTENT = 205,
|
||||
HTTP_PARTIAL_CONTENT = 206,
|
||||
|
||||
|
||||
/* Redirection messages */
|
||||
HTTP_MULTIPLE_CHOICES = 300,
|
||||
HTTP_MOVED_PERMANENTLY = 301,
|
||||
|
@ -36,7 +38,7 @@ typedef enum HttpStatus {
|
|||
HTTP_NOT_MODIFIED = 304,
|
||||
HTTP_TEMPORARY_REDIRECT = 307,
|
||||
HTTP_PERMANENT_REDIRECT = 308,
|
||||
|
||||
|
||||
/* Client error messages */
|
||||
HTTP_BAD_REQUEST = 400,
|
||||
HTTP_UNAUTHORIZED = 401,
|
||||
|
@ -61,7 +63,7 @@ typedef enum HttpStatus {
|
|||
HTTP_TOO_MANY_REQUESTS = 429,
|
||||
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
||||
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
||||
|
||||
|
||||
/* Server error responses */
|
||||
HTTP_INTERNAL_SERVER_ERROR = 500,
|
||||
HTTP_NOT_IMPLEMENTED = 501,
|
||||
|
@ -74,23 +76,25 @@ typedef enum HttpStatus {
|
|||
HTTP_NETWORK_AUTH_REQUIRED = 511
|
||||
} HttpStatus;
|
||||
|
||||
struct HttpRequest {
|
||||
struct HttpRequest
|
||||
{
|
||||
HttpRequestMethod method;
|
||||
};
|
||||
|
||||
struct HttpResponse {
|
||||
struct HttpResponse
|
||||
{
|
||||
HttpStatus status;
|
||||
};
|
||||
|
||||
extern char *
|
||||
HttpGetStatusString(const HttpStatus httpStatus);
|
||||
HttpGetStatusString(const HttpStatus httpStatus);
|
||||
|
||||
extern HttpRequestMethod
|
||||
HttpRequestMethodFromString(const char *requestMethod);
|
||||
HttpRequestMethodFromString(const char *requestMethod);
|
||||
|
||||
typedef struct HttpRequest HttpRequest;
|
||||
typedef struct HttpResponse HttpResponse;
|
||||
|
||||
typedef void (*HttpHandler)(HttpRequest *, HttpResponse *);
|
||||
typedef void (*HttpHandler) (HttpRequest *, HttpResponse *);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include <HashMap.h>
|
||||
#include <Array.h>
|
||||
|
||||
typedef enum JsonType {
|
||||
typedef enum JsonType
|
||||
{
|
||||
JSON_OBJECT,
|
||||
JSON_ARRAY,
|
||||
JSON_STRING,
|
||||
|
@ -14,56 +15,58 @@ typedef enum JsonType {
|
|||
JSON_NULL
|
||||
} JsonType;
|
||||
|
||||
typedef struct JsonValue {
|
||||
typedef struct JsonValue
|
||||
{
|
||||
JsonType type;
|
||||
union as {
|
||||
union as
|
||||
{
|
||||
HashMap *object;
|
||||
Array *array;
|
||||
char *string;
|
||||
int64_t integer;
|
||||
double floating;
|
||||
int boolean : 1;
|
||||
int boolean:1;
|
||||
};
|
||||
} JsonValue;
|
||||
|
||||
|
||||
extern JsonType
|
||||
JsonValueType(JsonValue *value);
|
||||
JsonValueType(JsonValue * value);
|
||||
|
||||
extern JsonValue *
|
||||
JsonValueObject(HashMap *object);
|
||||
JsonValueObject(HashMap * object);
|
||||
|
||||
extern HashMap *
|
||||
JsonValueAsObject(JsonValue *value);
|
||||
JsonValueAsObject(JsonValue * value);
|
||||
|
||||
extern JsonValue *
|
||||
JsonValueArray(Array *array);
|
||||
JsonValueArray(Array * array);
|
||||
|
||||
extern Array *
|
||||
JsonValueAsArray(JsonValue *value);
|
||||
JsonValueAsArray(JsonValue * value);
|
||||
|
||||
extern JsonValue *
|
||||
JsonValueString(char *string);
|
||||
JsonValueString(char *string);
|
||||
|
||||
extern JsonValue *
|
||||
JsonValueInteger(int64_t integer);
|
||||
JsonValueInteger(int64_t integer);
|
||||
|
||||
extern JsonValue *
|
||||
JsonValueFloat(double floating);
|
||||
JsonValueFloat(double floating);
|
||||
|
||||
extern JsonValue *
|
||||
JsonValueBoolean(int boolean);
|
||||
JsonValueBoolean(int boolean);
|
||||
|
||||
extern JsonValue *
|
||||
JsonValueNull(void);
|
||||
JsonValueNull(void);
|
||||
|
||||
extern void *
|
||||
JsonValueFree(JsonValue *value);
|
||||
JsonValueFree(JsonValue * value);
|
||||
|
||||
extern char *
|
||||
JsonEncode(HashMap *object);
|
||||
JsonEncode(HashMap * object);
|
||||
|
||||
extern HashMap *
|
||||
JsonDecode(char *string);
|
||||
JsonDecode(char *string);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum LogLevel {
|
||||
typedef enum LogLevel
|
||||
{
|
||||
LOG_ERROR,
|
||||
LOG_WARNING,
|
||||
LOG_TASK,
|
||||
|
@ -12,52 +13,53 @@ typedef enum LogLevel {
|
|||
LOG_DEBUG
|
||||
} LogLevel;
|
||||
|
||||
typedef enum LogFlag {
|
||||
LOG_FLAG_COLOR = (1 << 0)
|
||||
typedef enum LogFlag
|
||||
{
|
||||
LOG_FLAG_COLOR = (1 << 0)
|
||||
} LogFlag;
|
||||
|
||||
typedef struct LogConfig LogConfig;
|
||||
|
||||
extern LogConfig *
|
||||
LogConfigCreate(void);
|
||||
LogConfigCreate(void);
|
||||
|
||||
extern void
|
||||
LogConfigFree(LogConfig *config);
|
||||
LogConfigFree(LogConfig * config);
|
||||
|
||||
extern void
|
||||
LogConfigLevelSet(LogConfig *config, LogLevel level);
|
||||
LogConfigLevelSet(LogConfig * config, LogLevel level);
|
||||
|
||||
extern LogLevel
|
||||
LogConfigLevelGet(LogConfig *config);
|
||||
LogConfigLevelGet(LogConfig * config);
|
||||
|
||||
extern void
|
||||
LogConfigIndentSet(LogConfig *config, size_t indent);
|
||||
LogConfigIndentSet(LogConfig * config, size_t indent);
|
||||
|
||||
extern size_t
|
||||
LogConfigIndentGet(LogConfig *config);
|
||||
LogConfigIndentGet(LogConfig * config);
|
||||
|
||||
extern void
|
||||
LogConfigIndent(LogConfig *config);
|
||||
LogConfigIndent(LogConfig * config);
|
||||
|
||||
extern void
|
||||
LogConfigUnindent(LogConfig *config);
|
||||
LogConfigUnindent(LogConfig * config);
|
||||
|
||||
extern void
|
||||
LogConfigOutputSet(LogConfig *config, FILE *out);
|
||||
LogConfigOutputSet(LogConfig * config, FILE * out);
|
||||
|
||||
extern void
|
||||
LogConfigFlagSet(LogConfig *config, int flags);
|
||||
LogConfigFlagSet(LogConfig * config, int flags);
|
||||
|
||||
extern void
|
||||
LogConfigFlagClear(LogConfig *config, int flags);
|
||||
LogConfigFlagClear(LogConfig * config, int flags);
|
||||
|
||||
extern int
|
||||
LogConfigFlagGet(LogConfig *config, int flags);
|
||||
LogConfigFlagGet(LogConfig * config, int flags);
|
||||
|
||||
extern void
|
||||
LogConfigTimeStampFormatSet(LogConfig *config, char *tsFmt);
|
||||
LogConfigTimeStampFormatSet(LogConfig * config, char *tsFmt);
|
||||
|
||||
extern void
|
||||
Log(LogConfig *config, LogLevel level, const char *msg, ...);
|
||||
Log(LogConfig * config, LogLevel level, const char *msg,...);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue