tFix for reading negative numbers out of configuration files. - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 91774be5855ad25176ccae832819694066e0dca4
 (DIR) parent 1325360415e347e4fb171d85a9daa2b3a47d4c55
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Tue, 16 Jul 2002 17:18:32 +0000
       
       Fix for reading negative numbers out of configuration files.
       
       
       Diffstat:
         M src/dopewars.c                      |      15 +++++++++++++--
       
       1 file changed, 13 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/src/dopewars.c b/src/dopewars.c
       t@@ -375,10 +375,10 @@ struct GLOBALS Globals[] = {
           NULL, NULL, 0, "", NULL, NULL, FALSE, 0},
          {&DebtInterest, NULL, NULL, NULL, NULL, "DebtInterest",
           N_("Daily interest rate on the loan shark debt"),
       -   NULL, NULL, 0, "", NULL, NULL, FALSE, 0},
       +   NULL, NULL, 0, "", NULL, NULL, FALSE, -100},
          {&BankInterest, NULL, NULL, NULL, NULL, "BankInterest",
           N_("Daily interest rate on your bank balance"),
       -   NULL, NULL, 0, "", NULL, NULL, FALSE, 0},
       +   NULL, NULL, 0, "", NULL, NULL, FALSE, -100},
          {NULL, NULL, NULL, &Names.LoanSharkName, NULL, "LoanSharkName",
           N_("Name of the loan shark"), NULL, NULL, 0, "", NULL, NULL, FALSE, 0},
          {NULL, NULL, NULL, &Names.BankName, NULL, "BankName",
       t@@ -2072,9 +2072,20 @@ gboolean SetConfigValue(int GlobalIndex, int StructIndex,
            GlobalName = Globals[GlobalIndex].Name;
          }
          if (Globals[GlobalIndex].IntVal) {
       +    gboolean minus = FALSE;
       +
       +    /* GScanner doesn't understand negative numbers, so we need to
       +     * explicitly check for a prefixed minus sign */
            token = g_scanner_get_next_token(scanner);
       +    if (token == '-') {
       +      minus = TRUE;
       +      token = g_scanner_get_next_token(scanner);
       +    }
            if (token == G_TOKEN_INT) {
              IntVal = (int)scanner->value.v_int;
       +      if (minus) {
       +        IntVal = -IntVal;
       +      }
              if (IntVal < Globals[GlobalIndex].MinVal) {
                g_scanner_warn(scanner, _("%s can be no smaller than %d - ignoring!"),
                               GlobalName, Globals[GlobalIndex].MinVal);