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

@ -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

@ -32,10 +32,10 @@ typedef struct HashMap HashMap;
* 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
@ -49,7 +49,7 @@ HashMapMaxLoadSet(HashMap *map, float load);
* 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.
@ -58,7 +58,7 @@ HashMapSet(HashMap * map, const char *key, void *value);
* 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.
@ -67,10 +67,10 @@ HashMapGet(HashMap * map, const char *key);
* 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
@ -80,6 +80,6 @@ HashMapIterate(HashMap *map, void (*iteratorFunc)(void *));
* 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,7 +14,8 @@ 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,
@ -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