tape_list = NULL;
if((tapef = fopen(tapefile,"r")) == NULL) {
- return 1;
+ if (errno == ENOENT) {
+ /* no tapelist is equivalent to an empty tapelist */
+ return 0;
+ } else {
+ g_debug("Error opening '%s': %s", tapefile, strerror(errno));
+ return 1;
+ }
}
while((line = agets(tapef)) != NULL) {
}
for(tp = tape_list; tp != NULL; tp = tp->next) {
- fprintf(tapef, "%s %s", tp->datestamp, tp->label);
- if(tp->reuse) fprintf(tapef, " reuse");
- else fprintf(tapef, " no-reuse");
- fprintf(tapef, "\n");
+ g_fprintf(tapef, "%s %s", tp->datestamp, tp->label);
+ if(tp->reuse) g_fprintf(tapef, " reuse");
+ else g_fprintf(tapef, " no-reuse");
+ if (tp->comment)
+ g_fprintf(tapef, " #%s", tp->comment);
+ g_fprintf(tapef, "\n");
}
if (fclose(tapef) == EOF) {
- fprintf(stderr,"error [closing %s: %s]", newtapefile, strerror(errno));
+ g_fprintf(stderr,_("error [closing %s: %s]"), newtapefile, strerror(errno));
amfree(newtapefile);
return 1;
}
tape_t *
add_tapelabel(
char *datestamp,
- char *label)
+ char *label,
+ char *comment)
{
tape_t *cur, *new;
new->position = 0;
new->reuse = 1;
new->label = stralloc(label);
+ new->comment = comment? stralloc(comment) : NULL;
new->prev = NULL;
if(tape_list != NULL) tape_list->prev = new;
skip_whitespace(s, ch);
tp->reuse = 1;
-#define sc "reuse"
- if(strncmp(s - 1, sc, SIZEOF(sc)-1) == 0)
+ if(strncmp_const(s - 1, "reuse") == 0) {
tp->reuse = 1;
-#undef sc
-#define sc "no-reuse"
- if(strncmp(s - 1, sc, SIZEOF(sc)-1) == 0)
+ s1 = s - 1;
+ skip_non_whitespace(s, ch);
+ s[-1] = '\0';
+ skip_whitespace(s, ch);
+ }
+ if(strncmp_const(s - 1, "no-reuse") == 0) {
tp->reuse = 0;
-#undef sc
+ s1 = s - 1;
+ skip_non_whitespace(s, ch);
+ s[-1] = '\0';
+ skip_whitespace(s, ch);
+ }
+
+ if (*(s - 1) == '#') {
+ tp->comment = stralloc(s); /* skip leading '#' */
+ } else {
+ tp->comment = NULL;
+ }
return tp;
}
return mktime(tm);
}
+
+void
+print_new_tapes(
+ FILE *output,
+ int nb)
+{
+ tape_t *lasttp, *iter;
+
+ /* Find latest reusable new tape */
+ lasttp = lookup_tapepos(lookup_nb_tape());
+ while (lasttp && lasttp->reuse == 0)
+ lasttp = lasttp->prev;
+
+ if(lasttp && nb > 0 && strcmp(lasttp->datestamp,"0") == 0) {
+ int c = 0;
+ iter = lasttp;
+ /* count the number of tapes we *actually* used */
+ while(iter && nb > 0 && strcmp(iter->datestamp,"0") == 0) {
+ if (iter->reuse) {
+ c++;
+ nb--;
+ }
+ iter = iter->prev;
+ }
+
+ if(c == 1) {
+ g_fprintf(output,
+ _("The next new tape already labelled is: %s.\n"),
+ lasttp->label);
+ } else {
+ g_fprintf(output,
+ _("The next %d new tapes already labelled are: %s"),
+ c, lasttp->label);
+ iter = lasttp->prev;
+ c--;
+ while(iter && c > 0 && strcmp(iter->datestamp,"0") == 0) {
+ if (iter->reuse) {
+ g_fprintf(output, ", %s", iter->label);
+ c--;
+ }
+ iter = iter->prev;
+ }
+ g_fprintf(output, ".\n");
+ }
+ }
+}