Skip to content

Commit

Permalink
fix win build failing with some compilers due to inconsistent extensi… (
Browse files Browse the repository at this point in the history
#267)

* fix win build failing with some compilers due to inconsistent extension function types
  • Loading branch information
liquidaty committed Nov 9, 2024
1 parent b817442 commit a1c8a33
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 24 deletions.
18 changes: 11 additions & 7 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
THIS_MAKEFILE_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

CONFIGFILE ?= ../config.mk
ifneq ($(CONFIGFILE),)
ifeq ($(shell realpath `dirname ${CONFIGFILE}`),`realpath .`)
$(error howdydy)
$(info Using config file ${CONFIGFILE})

CONFIGFILEPATH:=$(shell ls ${CONFIGFILE} >/dev/null 2>/dev/null && realpath ${CONFIGFILE})
ifeq ($(CONFIGFILEPATH),)
ifeq ($(shell dirname ${CONFIGFILE}),.)
CONFIGFILEPATH:=$(shell ls ../${CONFIGFILE} >/dev/null 2>/dev/null && realpath ../${CONFIGFILE})
ifneq ($(CONFIGFILEPATH),)
$(info Config file ${CONFIGFILE} not found; using ../${CONFIGFILE})
endif
endif
endif

$(info Using config file ${CONFIGFILE})
include ${CONFIGFILE}

CONFIGFILEPATH=$(shell ls ${CONFIGFILE} >/dev/null 2>/dev/null && realpath ${CONFIGFILE})
ifeq ($(CONFIGFILEPATH),)
$(error Config file ${CONFIGFILE} not found)
else
include ${CONFIGFILEPATH}
endif

CC ?= cc
Expand Down
4 changes: 2 additions & 2 deletions app/sheet/key-bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ zsvsheet_handler_status zsvsheet_proc_key_binding_handler(struct zsvsheet_key_bi

int zsvsheet_register_key_binding(struct zsvsheet_key_binding *binding) {
if (zsvsheet_find_key_binding(binding->ch))
return -EEXIST; /* Key bound already */
return EEXIST; /* Key bound already */

if (binding->proc_id != ZSVSHEET_PROC_INVALID && binding->handler == NULL)
binding->handler = zsvsheet_proc_key_binding_handler;
Expand All @@ -43,7 +43,7 @@ int zsvsheet_register_key_binding(struct zsvsheet_key_binding *binding) {
return -ENOMEM;
}

int zsvsheet_register_proc_key_binding(char ch, int proc_id) {
int zsvsheet_register_proc_key_binding(char ch, zsvsheet_proc_id_t proc_id) {
struct zsvsheet_key_binding binding = {
.ch = ch,
.proc_id = proc_id,
Expand Down
2 changes: 1 addition & 1 deletion app/sheet/procedure.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ZSVSHEET_PROCEDURE_H
#define ZSVSHEET_PROCEDURE_H
#include <stdbool.h>
#include <zsv/ext.h>

/* ID's of bulitin procedures, extensions can register more.
*
Expand Down Expand Up @@ -32,7 +33,6 @@ enum {
};

#define ZSVSHEET_PROC_INVALID 0
typedef int zsvsheet_proc_id_t;

/* Procedures perform various actions in the editor. Procedures can be invoked
* by key-bindings, prompt invocation, another procedure or script. */
Expand Down
33 changes: 19 additions & 14 deletions include/zsv/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ typedef void *zsv_execution_context;
typedef enum zsv_ext_status (*zsv_ext_main)(zsv_execution_context ctx, int argc, const char *argv[],
struct zsv_opts *opts, const char *opts_used);

struct zsvsheet_proc_context;
typedef struct zsvsheet_proc_context *zsvsheet_proc_context_t;

/* custom sheet handler id */
typedef int zsvsheet_proc_id_t;

/**
* ZSV callbacks structure
Expand Down Expand Up @@ -153,30 +156,32 @@ struct zsv_ext_callbacks {
/****************************************
* Registering a custom `sheet` command *
****************************************/
/* TODO: Technically the ints in the return of this function and the argument
* of the next should be zsvsheet_proc_id_t but the includes in this
* projects are quite messy at this moment.
*/
int (*ext_sheet_register_proc)(const char *name,
zsvsheet_handler_status (*handler)(struct zsvsheet_proc_context *ctx));
zsvsheet_proc_id_t (*ext_sheet_register_proc)(const char *name,
zsvsheet_handler_status (*handler)(zsvsheet_proc_context_t ctx));

/* Use this one if you just need to call a procedure */
void (*ext_sheet_register_proc_key_binding)(char ch, int proc_id);
/**
* Bind a command to a key binding
* TO DO: allow binding of key that already exists; in which case
* allow handler to act as middleware that can cancel or allow other handlers to be executed
*
* @return 0 on success, else error
*/
int (*ext_sheet_register_proc_key_binding)(char ch, zsvsheet_proc_id_t proc_id);

/*** Custom command prompt ***/
/**
* Set the prompt for entering a subcommand
* @param s text to set the subcommand prompt to. must be < 256 bytes in length
* returns zsvsheet_status_ok on success
*/
zsvsheet_handler_status (*ext_sheet_prompt)(struct zsvsheet_proc_context *ctx, char *buffer, size_t bufsz,
const char *fmt, ...);
zsvsheet_handler_status (*ext_sheet_prompt)(zsvsheet_proc_context_t ctx, char *buffer, size_t bufsz, const char *fmt,
...);

/*** Custom command handling ***/
/**
* Set a status message
*/
zsvsheet_handler_status (*ext_sheet_handler_set_status)(struct zsvsheet_proc_context *ctx, const char *fmt, ...);
zsvsheet_handler_status (*ext_sheet_handler_set_status)(zsvsheet_proc_context_t ctx, const char *fmt, ...);

/**
* Get the key press that triggered this subcommand handler
Expand All @@ -187,7 +192,7 @@ struct zsv_ext_callbacks {
/**
* Get the current buffer
*/
zsvsheet_handler_buffer_t (*ext_sheet_handler_buffer_current)(struct zsvsheet_proc_context *ctx);
zsvsheet_handler_buffer_t (*ext_sheet_handler_buffer_current)(zsvsheet_proc_context_t ctx);

/**
* Get the prior buffer
Expand All @@ -202,7 +207,7 @@ struct zsv_ext_callbacks {
/**
* Open a tabular file as a new buffer
*/
zsvsheet_handler_status (*ext_sheet_handler_open_file)(zsvsheet_handler_context_t, const char *filepath,
zsvsheet_handler_status (*ext_sheet_handler_open_file)(zsvsheet_proc_context_t, const char *filepath,
struct zsv_opts *zopts);
};

Expand Down

0 comments on commit a1c8a33

Please sign in to comment.