Skip to content

Commit

Permalink
chore: better style for clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-chavez committed Feb 16, 2025
1 parent b12ba4b commit b76a6af
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 41 deletions.
9 changes: 5 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'false'
BinPackArguments: 'true'
BinPackParameters: 'true'
ColumnLimit: '1000'
ColumnLimit: 1000
IndentCaseLabels: 'true'
IndentPPDirectives: AfterHash
IndentWidth: '2'
MaxEmptyLinesToKeep: '1'
IndentWidth: 2
MaxEmptyLinesToKeep: 1
PointerAlignment: Right
SortIncludes: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: 'false'
SpacesBeforeTrailingComments: 1
TabWidth: '4'
TabWidth: 2
BracedInitializerIndentWidth: 2
UseTab: Never
9 changes: 8 additions & 1 deletion src/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ static int plmustache_get_variable(void *userdata, const char *name, struct must
return MUSTACH_OK;
}

struct mustach_itf plmustache_mustach_itf = {.enter = plmustache_section_enter, .next = plmustache_section_next, .leave = plmustache_section_leave, .get = plmustache_get_variable};
struct mustach_itf plmustache_mustach_itf = {

.enter = plmustache_section_enter,
.next = plmustache_section_next,
.leave = plmustache_section_leave,
.get = plmustache_get_variable

};

static char *datum_to_cstring(Datum datum, Oid typeoid, plmustache_obs_handler observer) {
HeapTuple typetuple = SearchSysCache(TYPEOID, ObjectIdGetDatum(typeoid), 0, 0, 0);
Expand Down
47 changes: 19 additions & 28 deletions src/observation.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,27 @@

#include <mustach/mustach.h>

static const char *mustach_strerror(int mustach_code) {
switch (mustach_code) {
case MUSTACH_ERROR_SYSTEM:
return "system error";
case MUSTACH_ERROR_UNEXPECTED_END:
return "unexpected end";
case MUSTACH_ERROR_EMPTY_TAG:
return "empty tag";
case MUSTACH_ERROR_TAG_TOO_LONG:
return "tag is too long";
case MUSTACH_ERROR_BAD_SEPARATORS:
return "bad separators";
case MUSTACH_ERROR_TOO_DEEP:
return "too deep";
case MUSTACH_ERROR_CLOSING:
return "closing";
case MUSTACH_ERROR_BAD_UNESCAPE_TAG:
return "bad unescape tag";
case MUSTACH_ERROR_INVALID_ITF:
return "invalid itf";
case MUSTACH_ERROR_ITEM_NOT_FOUND:
return "item not found";
case MUSTACH_ERROR_PARTIAL_NOT_FOUND:
return "partial not found";
case MUSTACH_ERROR_UNDEFINED_TAG:
return "undefined tag";
default:
return "unknown";
// clang-format off
static const char *mustach_strerror(int mustach_code){
switch(mustach_code){

case MUSTACH_ERROR_SYSTEM : return "system error";
case MUSTACH_ERROR_UNEXPECTED_END : return "unexpected end";
case MUSTACH_ERROR_EMPTY_TAG : return "empty tag";
case MUSTACH_ERROR_TAG_TOO_LONG : return "tag is too long";
case MUSTACH_ERROR_BAD_SEPARATORS : return "bad separators";
case MUSTACH_ERROR_TOO_DEEP : return "too deep";
case MUSTACH_ERROR_CLOSING : return "closing";
case MUSTACH_ERROR_BAD_UNESCAPE_TAG : return "bad unescape tag";
case MUSTACH_ERROR_INVALID_ITF : return "invalid itf";
case MUSTACH_ERROR_ITEM_NOT_FOUND : return "item not found";
case MUSTACH_ERROR_PARTIAL_NOT_FOUND: return "partial not found";
case MUSTACH_ERROR_UNDEFINED_TAG : return "undefined tag";
default : return "unknown";

}
}
// clang-format on

void ereporter(plmustache_observation o) {
switch (o.obs_type) {
Expand Down
6 changes: 3 additions & 3 deletions src/observation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
#define OBSERVATION_H

typedef enum {

ERROR_NO_OID = 1,
ERROR_NO_RETTYPE,
ERROR_NO_SRC,
ERROR_NOT_ONLY_IN_PARAMS,
ERROR_NO_TEXT_RET,
ERROR_UNNAMED_PARAMS,
ERROR_PARAM_IMPLICIT_ITERATOR

,
ERROR_PARAM_IMPLICIT_ITERATOR,
ERROR_NO_DO_BLOCKS,
ERROR_NO_TYPE_OID,
ERROR_MUSTACH

} plmustache_observation_type;

typedef struct {
Expand Down
8 changes: 3 additions & 5 deletions src/plmustache.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ PG_FUNCTION_INFO_V1(plmustache_handler);
Datum plmustache_handler(PG_FUNCTION_ARGS) {
Oid function_oid = fcinfo->flinfo->fn_oid;

char *mustache_result;
int mustach_code;
size_t mustache_result_size;

plmustache_call_info call_info = build_call_info(function_oid, fcinfo, ereporter);

plmustache_ctx ctx = build_mustache_ctx(call_info, fcinfo->args);

mustach_code = mustach_mem(ctx.template, 0, &plmustache_mustach_itf, &ctx, 0, &mustache_result, &mustache_result_size);
char *mustache_result;
size_t mustache_result_size;
int mustach_code = mustach_mem(ctx.template, 0, &plmustache_mustach_itf, &ctx, 0, &mustache_result, &mustache_result_size);

if (mustach_code < 0) {
ereporter((plmustache_observation){ERROR_MUSTACH, .error_mustach_code = mustach_code});
Expand Down

0 comments on commit b76a6af

Please sign in to comment.