]> git.sur5r.net Git - bacula/bacula/commitdiff
o add new is_yesno() function. This function test argument against NT_("yes") and...
authorEric Bollengier <eric@eb.homelinux.org>
Sat, 22 Jul 2006 22:49:51 +0000 (22:49 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Sat, 22 Jul 2006 22:49:51 +0000 (22:49 +0000)
 o modify code that test against yes/no

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3169 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/dird/protos.h
bacula/src/dird/ua_input.c
bacula/src/dird/ua_select.c
bacula/src/dird/ua_update.c

index f24adf4a5c4510fecc62f948e4312a846c422c52..16a361df71e7f81e78a439d983958fa03fa79406 100644 (file)
@@ -169,6 +169,7 @@ void set_pooldbr_from_poolres(POOL_DBR *pr, POOL *pool, e_pool_op op);
 int get_cmd(UAContext *ua, const char *prompt);
 bool get_pint(UAContext *ua, const char *prompt);
 bool get_yesno(UAContext *ua, const char *prompt);
+bool is_yesno(char *val, int *ret);
 void parse_ua_args(UAContext *ua);
 
 /* ua_label.c */
index 98030367b3bd81d606b0ba1e09f9dda5ee706cf3..9472af92713d14bb89de706b94d1b2626e1ec4bf 100644 (file)
@@ -98,6 +98,30 @@ bool get_pint(UAContext *ua, const char *prompt)
    }
 }
 
+/*
+ * Test a yes or no response
+ *  Returns:  false if failure
+ *            true  if success => ret == 1 for yes
+ *                                ret == 0 for no
+ */
+bool is_yesno(char *val, int *ret)
+{
+   *ret = 0;
+   if ((strcasecmp(val,   _("yes")) == 0) ||
+       (strcasecmp(val, NT_("yes")) == 0))
+   {
+      *ret = 1;
+   } else if ((strcasecmp(val,   _("no")) == 0) ||
+              (strcasecmp(val, NT_("no")) == 0))
+   {
+      *ret = 0;
+   } else {
+      return false;
+   }
+
+   return true;
+}
+
 /*
  * Gets a yes or no response
  *  Returns:  false if failure
@@ -107,7 +131,7 @@ bool get_pint(UAContext *ua, const char *prompt)
 bool get_yesno(UAContext *ua, const char *prompt)
 {
    int len;
-
+   int ret;
    ua->pint32_val = 0;
    for (;;) {
       if (!get_cmd(ua, prompt)) {
@@ -117,22 +141,14 @@ bool get_yesno(UAContext *ua, const char *prompt)
       if (len < 1 || len > 3) {
          continue;
       }
-      if ((strncasecmp(ua->cmd,   _("yes"), len) == 0)  ||
-         (strncasecmp(ua->cmd, NT_("yes"), len) == 0)) 
-      {
-         ua->pint32_val = 1;
-         return true;
-      }
-      if ((strncasecmp(ua->cmd,   _("no"), len) == 0)  ||
-         (strncasecmp(ua->cmd, NT_("no"), len) == 0))
-      {
+      if (is_yesno(ua->cmd, &ret)) {
+         ua->pint32_val = ret;
          return true;
       }
       bsendmsg(ua, _("Invalid response. You must answer yes or no.\n"));
    }
 }
 
-
 void parse_ua_args(UAContext *ua)
 {
    parse_args(ua->cmd, &ua->args, &ua->argc, ua->argk, ua->argv, MAX_CMD_ARGS);
index 169fbc45e6e56fdcff8faaef68c1da21bce3f706..6fbfb84d033025fcb8e4c3d90ea2ea36ed4cad09 100644 (file)
@@ -34,6 +34,7 @@ extern struct s_jl joblevels[];
 int confirm_retention(UAContext *ua, utime_t *ret, const char *msg)
 {
    char ed1[100];
+   int val;
 
    for ( ;; ) {
        bsendmsg(ua, _("The current %s retention period is: %s\n"),
@@ -51,11 +52,8 @@ int confirm_retention(UAContext *ua, utime_t *ret, const char *msg)
           }
           continue;
        }
-       if (strcasecmp(ua->cmd, _("yes")) == 0) {
-          return 1;
-       }
-       if (strcasecmp(ua->cmd, _("no")) == 0) {
-          return 0;
+       if (is_yesno(ua->cmd, &val)) {
+          return val;           /* is 1 for yes, 0 for no */
        }
     }
     return 1;
index 87e5927d987da7ac08a1174e99276cf65ba8daf6..2422f46a00f8bb6403d1c0db5ab09c6a236da719 100644 (file)
@@ -219,14 +219,11 @@ static void update_volrecycle(UAContext *ua, char *val, MEDIA_DBR *mr)
 {
    int recycle;
    char ed1[50];
+
    POOL_MEM query(PM_MESSAGE);
-   if (strcasecmp(val, _("yes")) == 0) {
-      recycle = 1;
-   } else if (strcasecmp(val, _("no")) == 0) {
-      recycle = 0;
-   } else {
+   if (!is_yesno(val, &recycle)) {
       bsendmsg(ua, _("Invalid value. It must be yes or no.\n"));
-      return;
+      return;      
    }
    Mmsg(query, "UPDATE Media SET Recycle=%d WHERE MediaId=%s",
       recycle, edit_int64(mr->MediaId, ed1));
@@ -244,13 +241,9 @@ static void update_volinchanger(UAContext *ua, char *val, MEDIA_DBR *mr)
    char ed1[50];
 
    POOL_MEM query(PM_MESSAGE);
-   if (strcasecmp(val, _("yes")) == 0) {
-      InChanger = 1;
-   } else if (strcasecmp(val, _("no")) == 0) {
-      InChanger = 0;
-   } else {
+   if (!is_yesno(val, &InChanger)) {
       bsendmsg(ua, _("Invalid value. It must be yes or no.\n"));
-      return;
+      return;      
    }
    Mmsg(query, "UPDATE Media SET InChanger=%d WHERE MediaId=%s",
       InChanger, edit_int64(mr->MediaId, ed1));