4 Commits

Author SHA1 Message Date
22b7e9a765 add comments to makefile 2025-01-28 22:27:20 +00:00
9388844acb add IS_64_BIT macro to interface.h 2024-07-25 22:14:06 +01:00
955edb781c get new len from strcspn
remove reset input buffer
2024-07-25 21:35:56 +01:00
a719af8265 use ++i 2024-07-25 17:34:38 +01:00
6 changed files with 27 additions and 11 deletions

View File

@@ -10,6 +10,8 @@
#include "VoicemeeterRemote.h" #include "VoicemeeterRemote.h"
#define IS_64_BIT sizeof(void *) == 8
PT_VMR create_interface(); PT_VMR create_interface();
#endif /* __IVMR_H__ */ #endif /* __IVMR_H__ */

View File

@@ -1,38 +1,53 @@
# Program name
program = vmrcli program = vmrcli
# Compiler
CC = gcc CC = gcc
# Directories
SRC_DIR := src SRC_DIR := src
OBJ_DIR := obj OBJ_DIR := obj
BIN_DIR := bin BIN_DIR := bin
# Executable and source/object files
EXE := $(BIN_DIR)/$(program).exe EXE := $(BIN_DIR)/$(program).exe
SRC := $(wildcard $(SRC_DIR)/*.c) SRC := $(wildcard $(SRC_DIR)/*.c)
OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) OBJ := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
# Conditional compilation flags for logging
LOG_USE_COLOR ?= yes LOG_USE_COLOR ?= yes
ifeq ($(LOG_USE_COLOR), yes) ifeq ($(LOG_USE_COLOR), yes)
CPPFLAGS := -Iinclude -MMD -MP -DLOG_USE_COLOR CPPFLAGS := -Iinclude -MMD -MP -DLOG_USE_COLOR
else else
CPPFLAGS := -Iinclude -MMD -MP CPPFLAGS := -Iinclude -MMD -MP
endif endif
# Compiler and linker flags
CFLAGS = -O -Wall -W -pedantic -ansi -std=c2x CFLAGS = -O -Wall -W -pedantic -ansi -std=c2x
LDFLAGS := -Llib LDFLAGS := -Llib
LDLIBS := -lm LDLIBS := -lm
# Phony targets
.PHONY: all clean .PHONY: all clean
# Default target
all: $(EXE) all: $(EXE)
# Link the executable
$(EXE): $(OBJ) | $(BIN_DIR) $(EXE): $(OBJ) | $(BIN_DIR)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
# Compile source files to object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
# Create necessary directories
$(BIN_DIR) $(OBJ_DIR): $(BIN_DIR) $(OBJ_DIR):
pwsh -Command New-Item -Path $@ -ItemType Directory pwsh -Command New-Item -Path $@ -ItemType Directory
# Clean up generated files
clean: clean:
pwsh -Command Remove-Item -Recurse $(EXE), $(OBJ_DIR) -force pwsh -Command Remove-Item -Recurse $(EXE), $(OBJ_DIR) -force
# Include dependency files
-include $(OBJ:.o=.d) -include $(OBJ:.o=.d)

View File

@@ -81,7 +81,7 @@ static long initialize_dll_interfaces(PT_VMR vmr)
return -100; return -100;
} }
// use right dll according to O/S type // use right dll according to O/S type
if (sizeof(void *) == 8) if (IS_64_BIT)
strncat(dll_fullpath, DLL64_NAME, DLL_FULLPATH_SZ - strlen(DLL64_NAME) - 1); strncat(dll_fullpath, DLL64_NAME, DLL_FULLPATH_SZ - strlen(DLL64_NAME) - 1);
else else
strncat(dll_fullpath, DLL32_NAME, DLL_FULLPATH_SZ - strlen(DLL32_NAME) - 1); strncat(dll_fullpath, DLL32_NAME, DLL_FULLPATH_SZ - strlen(DLL32_NAME) - 1);

View File

@@ -118,7 +118,7 @@ void log_set_quiet(bool enable)
int log_add_callback(log_LogFn fn, void *udata, int level) int log_add_callback(log_LogFn fn, void *udata, int level)
{ {
for (int i = 0; i < MAX_CALLBACKS; i++) for (int i = 0; i < MAX_CALLBACKS; ++i)
{ {
if (!L.callbacks[i].fn) if (!L.callbacks[i].fn)
{ {
@@ -163,7 +163,7 @@ void log_log(int level, const char *file, int line, const char *fmt, ...)
va_end(ev.ap); va_end(ev.ap);
} }
for (int i = 0; i < MAX_CALLBACKS && L.callbacks[i].fn; i++) for (int i = 0; i < MAX_CALLBACKS && L.callbacks[i].fn; ++i)
{ {
Callback *cb = &L.callbacks[i]; Callback *cb = &L.callbacks[i];
if (level >= cb->level) if (level >= cb->level)

View File

@@ -92,7 +92,7 @@ bool is_comment(char *s)
*/ */
struct quickcommand *command_in_quickcommands(const char *command_key, const struct quickcommand *quickcommands, int n) struct quickcommand *command_in_quickcommands(const char *command_key, const struct quickcommand *quickcommands, int n)
{ {
for (int i = 0; i < n; i++) for (int i = 0; i < n; ++i)
{ {
if (strcmp(command_key, quickcommands[i].name) == 0) if (strcmp(command_key, quickcommands[i].name) == 0)
{ {

View File

@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
for (int i = optind; i < argc; i++) for (int i = optind; i < argc; ++i)
{ {
parse_input(vmr, argv[i]); parse_input(vmr, argv[i]);
} }
@@ -240,11 +240,11 @@ static void usage()
static enum kind set_kind(char *kval) static enum kind set_kind(char *kval)
{ {
if (strcmp(kval, "basic") == 0) if (strcmp(kval, "basic") == 0)
return sizeof(void *) == 8 ? BASICX64 : BASIC; return IS_64_BIT ? BASICX64 : BASIC;
else if (strcmp(kval, "banana") == 0) else if (strcmp(kval, "banana") == 0)
return sizeof(void *) == 8 ? BANANAX64 : BANANA; return IS_64_BIT ? BANANAX64 : BANANA;
else if (strcmp(kval, "potato") == 0) else if (strcmp(kval, "potato") == 0)
return sizeof(void *) == 8 ? POTATOX64 : POTATO; return IS_64_BIT ? POTATOX64 : POTATO;
else else
return UNKNOWN; return UNKNOWN;
} }
@@ -266,12 +266,11 @@ static void interactive(PT_VMR vmr, bool with_prompt)
printf(">> "); printf(">> ");
while (fgets(input, MAX_LINE, stdin) != NULL) while (fgets(input, MAX_LINE, stdin) != NULL)
{ {
input[strcspn(input, "\n")] = 0; input[(len = strcspn(input, "\n"))] = 0;
if ((len = strlen(input)) == 1 && toupper(input[0]) == 'Q') if (len == 1 && toupper(input[0]) == 'Q')
break; break;
parse_input(vmr, input); parse_input(vmr, input);
memset(input, 0, len); /* reset input buffer */
if (with_prompt) if (with_prompt)
printf(">> "); printf(">> ");