#include <limits.h> // INT_MIN/INT_MAX
#include "common.h"
#include "../common/doregex.h"
+#include "../common/config.h"
#define USE_NCURSES_INTERFACE 0
#define DEBUG_TRACE_SERVER 0
void CompileRegex(regex_t *regex, const char *pattern, int flags);
// === GLOBALS ===
-char *gsDispenseServer = "merlo.ucc.gu.uwa.edu.au";
+const char *gsConfigFile = "/etc/opendispense/client.conf";
+
+const char *gsDispenseServer = "merlo.ucc.gu.uwa.edu.au";
int giDispensePort = 11020;
+ int giDispenseServerSet = 0; // True if set by command line
+ int giDispensePortSet = 0; // True if set by command line
tItem *gaItems;
int giNumItems;
" -m <min balance>\n"
" -M <max balance>\n"
" Set the Maximum/Minimum balances shown in `dispense acct`\n"
+ " -f <configfile>\n"
+ " Set the config file path (default: `/etc/opendispense/client.conf'\n"
"Definitions:\n"
" <itemid>\n"
" Item ID of the form <type>:<num> where <type> is a non-empty string of alpha-numeric characters, and <num> is a non-negative integer\n"
if( ret )
return ret;
+ // Load config file
+ Config_ParseFile(gsConfigFile);
+
+ // Parse config values
+ if (!giDispenseServerSet) {
+ gsDispenseServer = Config_GetValue("dispense_server",0);
+ }
+ if (!giDispensePortSet) {
+ giDispensePort = Config_GetValue_Int("dispense_port",0);
+ }
+
+
// Sub-commands
if( strcmp(gsTextArgs[0], "finger") == 0 ) {
return subcommand_finger();
giMaximumBalance = atoi(argv[++i]);
break;
+ case 'f': // Override Config File
+ if( i + 1 >= argc ) {
+ fprintf(stderr, "%s: -f takes an argument\n", argv[0]);
+ ShowUsage();
+ return RV_ARGUMENTS;
+ }
+ gsConfigFile = argv[++i];
+ break;
+
case 'u': // Override User
if( i + 1 >= argc ) {
fprintf(stderr, "%s: -u takes an argument\n", argv[0]);
return RV_ARGUMENTS;
}
gsDispenseServer = argv[++i];
+ giDispenseServerSet = 1;
break;
case 'P': // Override remote port
if( i + 1 >= argc ) {
return RV_ARGUMENTS;
}
giDispensePort = atoi(argv[++i]);
+ giDispensePortSet = 1;
break;
// Set slot name/price