+/* Allow the user to select a set of datestamps from those in
+ * holding disks. The result can be passed to
+ * holding_get_files_for_flush. If less than two dates are
+ * available, then no user interaction takes place.
+ *
+ * @returns: a new GSList listing the selected datestamps
+ */
+static GSList *
+pick_datestamp(void)
+{
+ GSList *datestamp_list;
+ GSList *r_datestamp_list = NULL;
+ GSList *ds;
+ char **datestamps = NULL;
+ int i;
+ char *answer = NULL;
+ char *a = NULL;
+ int ch = 0;
+ char max_char = '\0', chupper = '\0';
+
+ datestamp_list = holding_get_all_datestamps();
+
+ if(g_slist_length(datestamp_list) < 2) {
+ return datestamp_list;
+ } else {
+ datestamps = alloc(g_slist_length(datestamp_list) * SIZEOF(char *));
+ for(ds = datestamp_list, i=0; ds != NULL; ds = ds->next,i++) {
+ datestamps[i] = (char *)ds->data; /* borrowing reference */
+ }
+
+ while(1) {
+ puts(_("\nMultiple Amanda runs in holding disks; please pick one by letter:"));
+ for(ds = datestamp_list, max_char = 'A';
+ ds != NULL && max_char <= 'Z';
+ ds = ds->next, max_char++) {
+ g_printf(" %c. %s\n", max_char, (char *)ds->data);
+ }
+ max_char--;
+ g_printf(_("Select datestamps to flush [A..%c or <enter> for all]: "), max_char);
+ fflush(stdout); fflush(stderr);
+ amfree(answer);
+ if ((answer = agets(stdin)) == NULL) {
+ clearerr(stdin);
+ continue;
+ }
+
+ if (*answer == '\0' || strncasecmp(answer, "ALL", 3) == 0) {
+ break;
+ }
+
+ a = answer;
+ while ((ch = *a++) != '\0') {
+ if (!g_ascii_isspace(ch))
+ break;
+ }
+
+ /* rewrite the selected list into r_datestamp_list, then copy it over
+ * to datestamp_list */
+ do {
+ if (g_ascii_isspace(ch) || ch == ',') {
+ continue;
+ }
+ chupper = (char)toupper(ch);
+ if (chupper < 'A' || chupper > max_char) {
+ g_slist_free_full(r_datestamp_list);
+ r_datestamp_list = NULL;
+ break;
+ }
+ r_datestamp_list = g_slist_append(r_datestamp_list,
+ stralloc(datestamps[chupper - 'A']));
+ } while ((ch = *a++) != '\0');
+ if (r_datestamp_list && ch == '\0') {
+ g_slist_free_full(datestamp_list);
+ datestamp_list = r_datestamp_list;
+ break;
+ }
+ }
+ }
+ amfree(datestamps); /* references in this array are borrowed */
+ amfree(answer);
+
+ return datestamp_list;
+}
+