ARGS="--itemsfile items.cfg -p 11020"
ARGS=$ARGS" --cokeport /dev/ttyUSB0"
-#if [ "x$1" == "xdbg" ]; then
-# LD_LIBRARY_PATH=. gdb --args ./dispsrv $ARGS
-#else
+if [ "x$1" = "xdbg" ]; then
+ LD_LIBRARY_PATH=. gdb --args ./dispsrv $ARGS
+else
LD_LIBRARY_PATH=. ./dispsrv $ARGS
-#fi
+fi
#include <stdarg.h>
#include <regex.h>
#include <ncurses.h>
+#include <limits.h>
#include <unistd.h> // close
#include <netdb.h> // gethostbyname
regex_t gArrayRegex, gItemRegex, gSaltRegex, gUserInfoRegex;
int gbIsAuthenticated = 0;
-char *gsOverrideUser; //!< '-u' argument (dispense as another user)
+char *gsOverrideUser; //!< '-u' Dispense as another user
int gbUseNCurses = 0; //!< '-G' Use the NCurses GUI?
- int giSocket = -1;
+ int giMinimumBalance = INT_MIN; //!< '-m' Minumum balance for `dispense acct`
+ int giMaximumBalance = INT_MAX; //!< '-M' Maximum balance for `dispense acct`
// === CODE ===
int main(int argc, char *argv[])
ShowUsage();
return 0;
+ case 'm': // Minimum balance
+ giMinimumBalance = atoi(argv[++i]);
+ break;
+ case 'M': // Maximum balance
+ giMaximumBalance = atoi(argv[++i]);
+ break;
+
case 'u': // Override User
gsOverrideUser = argv[++i];
break;
// argv[i+1]: Username
// Alter account?
- if( i + 2 < argc ) {
-
+ if( i + 2 < argc )
+ {
if( i + 3 >= argc ) {
fprintf(stderr, "Error: `dispense acct' needs a reason\n");
exit(1);
"\t\tShow help text\n"
"\t-G\n"
"\t\tUse alternate GUI\n"
+ "\t-m <min balance>\n"
+ "\t-M <max balance>\n"
+ "\t\tSet the Maximum/Minimum balances shown in `dispense acct`\n"
);
}
int nUsers;
regmatch_t matches[4];
- sendf(Socket, "ENUM_USERS\n");
+ if( giMinimumBalance != INT_MIN ) {
+ if( giMaximumBalance != INT_MAX ) {
+ sendf(Socket, "ENUM_USERS %i %i\n", giMinimumBalance, giMaximumBalance);
+ }
+ else {
+ sendf(Socket, "ENUM_USERS %i\n", giMinimumBalance);
+ }
+ }
+ else {
+ if( giMaximumBalance != INT_MAX ) {
+ sendf(Socket, "ENUM_USERS - %i\n", giMaximumBalance);
+ }
+ else {
+ sendf(Socket, "ENUM_USERS\n");
+ }
+ }
buf = ReadLine(Socket);
responseCode = atoi(buf);
int numUsr = GetMaxID();
// Parse arguments
- //minBal = atoi(Args);
+ if( Args && strlen(Args) )
+ {
+ char *min = Args, *max;
+
+ max = strchr(Args, ' ');
+ if( max ) {
+ *max = '\0';
+ max ++;
+ }
+
+ // If <minBal> != "-"
+ if( strcmp(min, "-") != 0 )
+ minBal = atoi(min);
+ // If <maxBal> != "-"
+ if( max && strcmp(max, "-") != 0 )
+ maxBal = atoi(max);
+ }
// Get return number
for( i = 0; i < numUsr; i ++ )