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:
Jordan Bancino 2022-07-25 15:25:06 -04:00
parent aabb2a0203
commit 3437c5db2c
9 changed files with 94 additions and 86 deletions

View File

@ -74,7 +74,7 @@ recipe_clean() {
} }
recipe_format() { 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" echo "indent $src"
indent -bad -bap -bbb -nbc -bl -c36 -cd36 -ncdb -nce \ indent -bad -bap -bbb -nbc -bl -c36 -cd36 -ncdb -nce \
-ci8 -cli1 -d0 -di1 -ndj -ei -fc1 -i4 -ip -l72 \ -ci8 -cli1 -d0 -di1 -ndj -ei -fc1 -i4 -ip -l72 \

View File

@ -45,7 +45,7 @@ TelodendriaPrintUsage(LogConfig * lc)
Log(lc, LOG_MESSAGE, " -h Print this usage, then exit."); Log(lc, LOG_MESSAGE, " -h Print this usage, then exit.");
} }
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
LogConfig *lc; LogConfig *lc;

View File

@ -6,27 +6,27 @@
typedef struct Array Array; typedef struct Array Array;
extern Array * extern Array *
ArrayCreate(void); ArrayCreate(void);
extern size_t extern size_t
ArraySize(Array *array); ArraySize(Array * array);
extern void * extern void *
ArrayGet(Array *array, size_t index); ArrayGet(Array * array, size_t index);
extern int extern int
ArrayInsert(Array *, void *value, size_t index); ArrayInsert(Array *, void *value, size_t index);
extern int extern int
ArrayAdd(Array *array, void *value); ArrayAdd(Array * array, void *value);
extern void * extern void *
ArrayDelete(Array *array, size_t index); ArrayDelete(Array * array, size_t index);
extern void extern void
ArrayFree(Array *array); ArrayFree(Array * array);
extern int extern int
ArrayTrim(Array *array); ArrayTrim(Array * array);
#endif #endif

View File

@ -4,22 +4,21 @@
#include <stddef.h> #include <stddef.h>
extern size_t extern size_t
Base64EncodedSize(size_t inputSize); Base64EncodedSize(size_t inputSize);
extern size_t extern size_t
Base64DecodedSize(const char *base64, size_t len); Base64DecodedSize(const char *base64, size_t len);
extern char * extern char *
Base64Encode(const char *input, size_t len); Base64Encode(const char *input, size_t len);
extern char * extern char *
Base64Decode(const char *input, size_t len); Base64Decode(const char *input, size_t len);
extern void extern void
Base64Unpad(char *base64, size_t length); Base64Unpad(char *base64, size_t length);
extern int extern int
Base64Pad(char **base64Ptr, size_t length); Base64Pad(char **base64Ptr, size_t length);
#endif #endif

View File

@ -11,27 +11,27 @@ typedef struct ConfigDirective ConfigDirective;
typedef struct ConfigParseResult ConfigParseResult; typedef struct ConfigParseResult ConfigParseResult;
extern ConfigParseResult * extern ConfigParseResult *
ConfigParse(FILE *stream); ConfigParse(FILE * stream);
extern unsigned int extern unsigned int
ConfigParseResultOk(ConfigParseResult *result); ConfigParseResultOk(ConfigParseResult * result);
extern size_t extern size_t
ConfigParseResultLineNumber(ConfigParseResult *result); ConfigParseResultLineNumber(ConfigParseResult * result);
extern HashMap * extern HashMap *
ConfigParseResultGet(ConfigParseResult *result); ConfigParseResultGet(ConfigParseResult * result);
extern void extern void
ConfigParseResultFree(ConfigParseResult *result); ConfigParseResultFree(ConfigParseResult * result);
extern Array * extern Array *
ConfigValuesGet(ConfigDirective *directive); ConfigValuesGet(ConfigDirective * directive);
extern HashMap * extern HashMap *
ConfigChildrenGet(ConfigDirective *directive); ConfigChildrenGet(ConfigDirective * directive);
extern void extern void
ConfigFree(HashMap *conf); ConfigFree(HashMap * conf);
#endif /* TELODENDRIA_CONFIG_H */ #endif /* TELODENDRIA_CONFIG_H */

View File

@ -4,7 +4,7 @@
* documented, and generally readable and understandable, yet also * documented, and generally readable and understandable, yet also
* performant enough to be useful, because it is used extensively in * performant enough to be useful, because it is used extensively in
* Telodendria. * Telodendria.
* *
* Fundamentally, this is an entirely generic map implementation. It * Fundamentally, this is an entirely generic map implementation. It
* can be used for many general purposes, but it is designed to only * can be used for many general purposes, but it is designed to only
* implement the features that Telodendria needs to function well. * implement the features that Telodendria needs to function well.
@ -26,60 +26,60 @@ typedef struct HashMap HashMap;
/* /*
* HashMapCreate: Create a new HashMap object. * HashMapCreate: Create a new HashMap object.
* *
* Returns: A HashMap object that is ready to be used by the rest of * 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 HashMap functions, or NULL if memory could not be allocated on
* the heap. * the heap.
*/ */
extern HashMap * extern HashMap *
HashMapCreate(void); HashMapCreate(void);
extern 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 * 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; * 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 * 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. * 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 * 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 * 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, * keys must have values; you can't set a key to NULL. To delete a key,
* use HashMapDelete. * use HashMapDelete.
*/ */
extern void * 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. * HashMapGet: Get the value for the given key.
* *
* Returns: The value at the given key, or NULL if the key does not * Returns: The value at the given key, or NULL if the key does not
* exist, no map was provided, or no key was provided. * exist, no map was provided, or no key was provided.
*/ */
extern void * extern void *
HashMapGet(HashMap * map, const char *key); HashMapGet(HashMap * map, const char *key);
/* /*
* HashMapDelete: Delete the value for the given key. * HashMapDelete: Delete the value for the given key.
* *
* Returns: The value at the given key, or NULL if the key does not * Returns: The value at the given key, or NULL if the key does not
* exist or the map or key was not provided. * exist or the map or key was not provided.
*/ */
extern void * extern void *
HashMapDelete(HashMap *map, const char *key); HashMapDelete(HashMap * map, const char *key);
extern void 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 * 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 * the map since this hash map implementation has no way of knowing
* what actually is stored in it. You should use HashMapIterate to * what actually is stored in it. You should use HashMapIterate to
* free the values using your own algorithm. * free the values using your own algorithm.
*/ */
extern void extern void
HashMapFree(HashMap *map); HashMapFree(HashMap * map);
#endif /* TELODENDRIA_HASHMAP_H */ #endif /* TELODENDRIA_HASHMAP_H */

View File

@ -1,7 +1,8 @@
#ifndef TELODENDRIA_HTTP_H #ifndef TELODENDRIA_HTTP_H
#define TELODENDRIA_HTTP_H #define TELODENDRIA_HTTP_H
typedef enum HttpRequestMethod { typedef enum HttpRequestMethod
{
HTTP_GET, HTTP_GET,
HTTP_HEAD, HTTP_HEAD,
HTTP_POST, HTTP_POST,
@ -13,12 +14,13 @@ typedef enum HttpRequestMethod {
HTTP_PATCH HTTP_PATCH
} HttpRequestMethod; } HttpRequestMethod;
typedef enum HttpStatus { typedef enum HttpStatus
{
/* Informational responses */ /* Informational responses */
HTTP_CONTINUE = 100, HTTP_CONTINUE = 100,
HTTP_SWITCHING_PROTOCOLS = 101, HTTP_SWITCHING_PROTOCOLS = 101,
HTTP_EARLY_HINTS = 103, HTTP_EARLY_HINTS = 103,
/* Successful responses */ /* Successful responses */
HTTP_OK = 200, HTTP_OK = 200,
HTTP_CREATED = 201, HTTP_CREATED = 201,
@ -27,7 +29,7 @@ typedef enum HttpStatus {
HTTP_NO_CONTENT = 204, HTTP_NO_CONTENT = 204,
HTTP_RESET_CONTENT = 205, HTTP_RESET_CONTENT = 205,
HTTP_PARTIAL_CONTENT = 206, HTTP_PARTIAL_CONTENT = 206,
/* Redirection messages */ /* Redirection messages */
HTTP_MULTIPLE_CHOICES = 300, HTTP_MULTIPLE_CHOICES = 300,
HTTP_MOVED_PERMANENTLY = 301, HTTP_MOVED_PERMANENTLY = 301,
@ -36,7 +38,7 @@ typedef enum HttpStatus {
HTTP_NOT_MODIFIED = 304, HTTP_NOT_MODIFIED = 304,
HTTP_TEMPORARY_REDIRECT = 307, HTTP_TEMPORARY_REDIRECT = 307,
HTTP_PERMANENT_REDIRECT = 308, HTTP_PERMANENT_REDIRECT = 308,
/* Client error messages */ /* Client error messages */
HTTP_BAD_REQUEST = 400, HTTP_BAD_REQUEST = 400,
HTTP_UNAUTHORIZED = 401, HTTP_UNAUTHORIZED = 401,
@ -61,7 +63,7 @@ typedef enum HttpStatus {
HTTP_TOO_MANY_REQUESTS = 429, HTTP_TOO_MANY_REQUESTS = 429,
HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431, HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451, HTTP_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
/* Server error responses */ /* Server error responses */
HTTP_INTERNAL_SERVER_ERROR = 500, HTTP_INTERNAL_SERVER_ERROR = 500,
HTTP_NOT_IMPLEMENTED = 501, HTTP_NOT_IMPLEMENTED = 501,
@ -74,23 +76,25 @@ typedef enum HttpStatus {
HTTP_NETWORK_AUTH_REQUIRED = 511 HTTP_NETWORK_AUTH_REQUIRED = 511
} HttpStatus; } HttpStatus;
struct HttpRequest { struct HttpRequest
{
HttpRequestMethod method; HttpRequestMethod method;
}; };
struct HttpResponse { struct HttpResponse
{
HttpStatus status; HttpStatus status;
}; };
extern char * extern char *
HttpGetStatusString(const HttpStatus httpStatus); HttpGetStatusString(const HttpStatus httpStatus);
extern HttpRequestMethod extern HttpRequestMethod
HttpRequestMethodFromString(const char *requestMethod); HttpRequestMethodFromString(const char *requestMethod);
typedef struct HttpRequest HttpRequest; typedef struct HttpRequest HttpRequest;
typedef struct HttpResponse HttpResponse; typedef struct HttpResponse HttpResponse;
typedef void (*HttpHandler)(HttpRequest *, HttpResponse *); typedef void (*HttpHandler) (HttpRequest *, HttpResponse *);
#endif #endif

View File

@ -4,7 +4,8 @@
#include <HashMap.h> #include <HashMap.h>
#include <Array.h> #include <Array.h>
typedef enum JsonType { typedef enum JsonType
{
JSON_OBJECT, JSON_OBJECT,
JSON_ARRAY, JSON_ARRAY,
JSON_STRING, JSON_STRING,
@ -14,56 +15,58 @@ typedef enum JsonType {
JSON_NULL JSON_NULL
} JsonType; } JsonType;
typedef struct JsonValue { typedef struct JsonValue
{
JsonType type; JsonType type;
union as { union as
{
HashMap *object; HashMap *object;
Array *array; Array *array;
char *string; char *string;
int64_t integer; int64_t integer;
double floating; double floating;
int boolean : 1; int boolean:1;
}; };
} JsonValue; } JsonValue;
extern JsonType extern JsonType
JsonValueType(JsonValue *value); JsonValueType(JsonValue * value);
extern JsonValue * extern JsonValue *
JsonValueObject(HashMap *object); JsonValueObject(HashMap * object);
extern HashMap * extern HashMap *
JsonValueAsObject(JsonValue *value); JsonValueAsObject(JsonValue * value);
extern JsonValue * extern JsonValue *
JsonValueArray(Array *array); JsonValueArray(Array * array);
extern Array * extern Array *
JsonValueAsArray(JsonValue *value); JsonValueAsArray(JsonValue * value);
extern JsonValue * extern JsonValue *
JsonValueString(char *string); JsonValueString(char *string);
extern JsonValue * extern JsonValue *
JsonValueInteger(int64_t integer); JsonValueInteger(int64_t integer);
extern JsonValue * extern JsonValue *
JsonValueFloat(double floating); JsonValueFloat(double floating);
extern JsonValue * extern JsonValue *
JsonValueBoolean(int boolean); JsonValueBoolean(int boolean);
extern JsonValue * extern JsonValue *
JsonValueNull(void); JsonValueNull(void);
extern void * extern void *
JsonValueFree(JsonValue *value); JsonValueFree(JsonValue * value);
extern char * extern char *
JsonEncode(HashMap *object); JsonEncode(HashMap * object);
extern HashMap * extern HashMap *
JsonDecode(char *string); JsonDecode(char *string);
#endif #endif

View File

@ -4,7 +4,8 @@
#include <stdio.h> #include <stdio.h>
#include <stddef.h> #include <stddef.h>
typedef enum LogLevel { typedef enum LogLevel
{
LOG_ERROR, LOG_ERROR,
LOG_WARNING, LOG_WARNING,
LOG_TASK, LOG_TASK,
@ -12,52 +13,53 @@ typedef enum LogLevel {
LOG_DEBUG LOG_DEBUG
} LogLevel; } LogLevel;
typedef enum LogFlag { typedef enum LogFlag
LOG_FLAG_COLOR = (1 << 0) {
LOG_FLAG_COLOR = (1 << 0)
} LogFlag; } LogFlag;
typedef struct LogConfig LogConfig; typedef struct LogConfig LogConfig;
extern LogConfig * extern LogConfig *
LogConfigCreate(void); LogConfigCreate(void);
extern void extern void
LogConfigFree(LogConfig *config); LogConfigFree(LogConfig * config);
extern void extern void
LogConfigLevelSet(LogConfig *config, LogLevel level); LogConfigLevelSet(LogConfig * config, LogLevel level);
extern LogLevel extern LogLevel
LogConfigLevelGet(LogConfig *config); LogConfigLevelGet(LogConfig * config);
extern void extern void
LogConfigIndentSet(LogConfig *config, size_t indent); LogConfigIndentSet(LogConfig * config, size_t indent);
extern size_t extern size_t
LogConfigIndentGet(LogConfig *config); LogConfigIndentGet(LogConfig * config);
extern void extern void
LogConfigIndent(LogConfig *config); LogConfigIndent(LogConfig * config);
extern void extern void
LogConfigUnindent(LogConfig *config); LogConfigUnindent(LogConfig * config);
extern void extern void
LogConfigOutputSet(LogConfig *config, FILE *out); LogConfigOutputSet(LogConfig * config, FILE * out);
extern void extern void
LogConfigFlagSet(LogConfig *config, int flags); LogConfigFlagSet(LogConfig * config, int flags);
extern void extern void
LogConfigFlagClear(LogConfig *config, int flags); LogConfigFlagClear(LogConfig * config, int flags);
extern int extern int
LogConfigFlagGet(LogConfig *config, int flags); LogConfigFlagGet(LogConfig * config, int flags);
extern void extern void
LogConfigTimeStampFormatSet(LogConfig *config, char *tsFmt); LogConfigTimeStampFormatSet(LogConfig * config, char *tsFmt);
extern void extern void
Log(LogConfig *config, LogLevel level, const char *msg, ...); Log(LogConfig * config, LogLevel level, const char *msg,...);
#endif #endif