}
}
UnlockRes();
- do_prompt(ua, _("Storage"), _("Select Storage resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Storage"), _("Select Storage resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
store = (STORE *)GetResWithName(R_STORAGE, name);
return store;
}
}
}
UnlockRes();
- do_prompt(ua, _("FileSet"), _("Select FileSet resource"), name, sizeof(name));
+ if (do_prompt(ua, _("FileSet"), _("Select FileSet resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
fs = (FILESET *)GetResWithName(R_FILESET, name);
return fs;
}
}
}
UnlockRes();
- do_prompt(ua, _("Catalog"), _("Select Catalog resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Catalog"), _("Select Catalog resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
catalog = (CAT *)GetResWithName(R_CATALOG, name);
}
return catalog;
}
}
UnlockRes();
- do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Job"), _("Select Job resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
job = (JOB *)GetResWithName(R_JOB, name);
return job;
}
}
}
UnlockRes();
- do_prompt(ua, _("Job"), _("Select Restore Job"), name, sizeof(name));
+ if (do_prompt(ua, _("Job"), _("Select Restore Job"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
job = (JOB *)GetResWithName(R_JOB, name);
return job;
}
}
}
UnlockRes();
- do_prompt(ua, _("Client"), _("Select Client (File daemon) resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Client"), _("Select Client (File daemon) resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
client = (CLIENT *)GetResWithName(R_CLIENT, name);
return client;
}
}
}
UnlockRes();
- do_prompt(ua, _("Pool"), _("Select Pool resource"), name, sizeof(name));
+ if (do_prompt(ua, _("Pool"), _("Select Pool resource"), name, sizeof(name)) < 0) {
+ return NULL;
+ }
pool = (POOL *)GetResWithName(R_POOL, name);
return pool;
}
* Returns: -1 on error
* index base 0 on success, and choice
* is copied to prompt if not NULL
+ * prompt is set to the chosen prompt item string
*/
int do_prompt(UAContext *ua, const char *automsg, const char *msg, char *prompt, int max_prompt)
{
int i, item;
char pmsg[MAXSTRING];
+ if (prompt) {
+ *prompt = 0;
+ }
if (ua->num_prompts == 2) {
item = 1;
if (prompt) {
bsendmsg(ua, "%6d: %s\n", i, ua->prompt[i]);
}
- if (prompt) {
- *prompt = 0;
- }
-
for ( ;; ) {
/* First item is the prompt string, not the items */
if (ua->num_prompts == 1) {
bsendmsg(ua, _("Selection is empty!\n"));
- item = 0; /* list is empty ! */
+ item = -1; /* list is empty ! */
break;
}
if (ua->num_prompts == 2) {
free(ua->prompt[i]);
}
ua->num_prompts = 0;
- return item - 1;
+ return item>0 ? item-1 : item;
}
/* Ignore slots, scan and barcode(s) keywords */
if (strcasecmp("scan", ua->argk[i]) == 0 ||
strcasecmp("barcode", ua->argk[i]) == 0 ||
+ strcasecmp("barcodes", ua->argk[i]) == 0 ||
strcasecmp("slots", ua->argk[i]) == 0) {
continue;
}
store = NULL;
}
- if (!store && store_name) {
+ if (!store && store_name && store_name[0] != 0) {
store = (STORE *)GetResWithName(R_STORAGE, store_name);
if (!store) {
bsendmsg(ua, _("Storage resource \"%s\": not found\n"), store_name);
return store;
}
+/* Get drive that we are working with for this storage */
int get_storage_drive(UAContext *ua, STORE *store)
{
int i, drive = -1;
if (i >=0) {
drive = atoi(ua->argv[i]);
} else if (store && store->autochanger) {
- ua->cmd[0] = 0;
- if (!get_cmd(ua, _("Enter autochanger drive[0]: "))) {
- drive = -1; /* None */
- } else {
- drive = atoi(ua->cmd);
+ /* If our structure is not set ask SD for # drives */
+ if (store->drives == 0) {
+ store->drives = get_num_drives_from_SD(ua);
}
+ /* If only one drive, default = 0 */
+ if (store->drives == 1) {
+ drive = 0;
+ } else {
+ /* Ask user to enter drive number */
+ ua->cmd[0] = 0;
+ if (!get_cmd(ua, _("Enter autochanger drive[0]: "))) {
+ drive = -1; /* None */
+ } else {
+ drive = atoi(ua->cmd);
+ }
+ }
}
return drive;
}