hlog: pass an invocation indication to fill_template

This way, the function can behave differently based on which binary called
it.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
5 files changed, 17 insertions(+), 10 deletions(-)

M hlog/common/config.c
M hlog/common/config.h
M hlog/contest.c
M hlog/hlog.c
M init-data.sh
M hlog/common/config.c +6 -4
@@ 42,7 42,7 @@ static void complain_about_type(lua_Stat
 		lua_typename(L, lua_type(L, -1)));
 }
 
-static int process_config(lua_State *L, struct qso *template)
+static int process_config(lua_State *L, struct qso *template, const char *mode)
 {
 	char error[128];
 	int ret;

          
@@ 61,7 61,9 @@ static int process_config(lua_State *L, 
 				return ret;
 			}
 
-			ret = xlua_call(L, NULL, 1, 0, error, sizeof(error));
+			lua_pushstring(L, mode);
+
+			ret = xlua_call(L, NULL, 2, 0, error, sizeof(error));
 			if (ret) {
 				fprintf(stderr, "Error: 'fill_template' failed "
 					"to execute: %s\n", error);

          
@@ 116,7 118,7 @@ static int process_config(lua_State *L, 
 	return 0;
 }
 
-int load_config(int data_dir_fd, struct qso *template)
+int load_config(int data_dir_fd, struct qso *template, const char *mode)
 {
 	char error[128];
 	lua_State *L;

          
@@ 136,7 138,7 @@ int load_config(int data_dir_fd, struct 
 	switch (lua_type(L, -1)) {
 		case LUA_TTABLE:
 			/* got a table - process it */
-			ret = process_config(L, template);
+			ret = process_config(L, template, mode);
 			if (ret)
 				goto err_lua;
 			break;

          
M hlog/common/config.h +2 -2
@@ 1,5 1,5 @@ 
 /*
- * Copyright (c) 2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2021-2022 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal

          
@@ 23,6 23,6 @@ 
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-extern int load_config(int data_dir_fd, struct qso *template);
+extern int load_config(int data_dir_fd, struct qso *template, const char *mode);
 
 #endif

          
M hlog/contest.c +1 -1
@@ 710,7 710,7 @@ int main(int argc, char **argv)
 		goto err_free;
 	}
 
-	ret = load_config(AT_FDCWD, template);
+	ret = load_config(AT_FDCWD, template, "contest");
 	if (ret)
 		goto err_free;
 

          
M hlog/hlog.c +1 -1
@@ 2021,7 2021,7 @@ static int load_and_apply_config(void)
 		goto err;
 
 	/* read the config */
-	ret = load_config(AT_FDCWD, template);
+	ret = load_config(AT_FDCWD, template, "normal");
 	if (ret)
 		goto err_states;
 

          
M init-data.sh +7 -2
@@ 1,6 1,6 @@ 
 #!/bin/sh
 #
-# Copyright (c) 2020-2021 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+# Copyright (c) 2020-2022 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal

          
@@ 40,7 40,11 @@ mkdir "$DIR/qso"
 mkdir "$DIR/tmp"
 
 cat > "$DIR/config.lua" <<DONE
-local function fill_template(qso)
+local function fill_template(qso, mode)
+	-- The 'mode' argument conveys what executable invoked this
+	-- function.  "normal" indicates that we were called by 'hlog',
+	-- while values beginning with "contest" indicate 'hlog-contest'.
+
 	qso.tx.station_call = "WX1YZ" -- de station call sign
 	qso.tx.grid = "FN42" -- tx grid locator
 	qso.tx.power = 1500 -- tx power in W

          
@@ 48,6 52,7 @@ local function fill_template(qso)
 end
 
 return {
+	-- called once on startup to initialize a 'template' qso
 	fill_template = fill_template,
 }
 DONE