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 */
}
}
+/*
+ * 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
bool get_yesno(UAContext *ua, const char *prompt)
{
int len;
-
+ int ret;
ua->pint32_val = 0;
for (;;) {
if (!get_cmd(ua, 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);
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"),
}
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;
{
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));
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));