Imported Upstream version 2.6.1p1
[debian/amanda] / common-src / amfeatures.c
index 89a1c3829dbc542acb02404295665584dc93f554..5364ae4181204a94483662f893d6d224bc0e79a7 100644 (file)
@@ -72,6 +72,7 @@ am_init_feature_set(void)
 
        am_add_feature(f, fe_program_dump);
        am_add_feature(f, fe_program_gnutar);
+       am_add_feature(f, fe_program_application_api);
 
        am_add_feature(f, fe_options_compress_fast);
        am_add_feature(f, fe_options_compress_best);
@@ -145,6 +146,14 @@ am_init_feature_set(void)
 
        am_add_feature(f, fe_req_options_config);
 
+       am_add_feature(f, fe_rep_sendsize_quoted_error);
+       am_add_feature(f, fe_req_xml);
+       am_add_feature(f, fe_pp_script);
+       am_add_feature(f, fe_amindexd_DLE);
+       am_add_feature(f, fe_amrecover_dle_in_header);
+       am_add_feature(f, fe_xml_estimate);
+       am_add_feature(f, fe_xml_property_priority);
+       am_add_feature(f, fe_sendsize_rep_warning);
     }
     return f;
 }
@@ -361,11 +370,11 @@ am_feature_to_string(
     size_t                     i;
 
     if (f == NULL) {
-       result = stralloc("UNKNOWNFEATURE");
+       result = stralloc(_("UNKNOWNFEATURE"));
     } else {
        result = alloc((f->size * 2) + 1);
        for (i = 0; i < f->size; i++) {
-           snprintf(result + (i * 2), 2 + 1, "%02x", f->bytes[i]);
+           g_snprintf(result + (i * 2), 2 + 1, "%02x", f->bytes[i]);
        }
        result[i * 2] = '\0';
     }
@@ -399,6 +408,7 @@ am_string_to_feature(
     am_feature_t               *f = NULL;
     size_t                     i;
     int                                ch1, ch2;
+    char *                     orig = s;
 
     if (s != NULL && strcmp(s,"UNKNOWNFEATURE") != 0) {
        f = am_allocate_feature_set();
@@ -409,10 +419,10 @@ am_string_to_feature(
                ch1 -= 'a';
                ch1 += 10;
            } else if (ch1 >= 'A' && ch1 <= 'F') {
-               ch1 -= 'a';
+               ch1 -= 'A';
                ch1 += 10;
            } else {
-               break;
+               goto bad;
            }
            ch2 = *s++;
            if (isdigit(ch2)) {
@@ -421,23 +431,30 @@ am_string_to_feature(
                ch2 -= 'a';
                ch2 += 10;
            } else if (ch2 >= 'A' && ch2 <= 'F') {
-               ch2 -= 'a';
+               ch2 -= 'A';
                ch2 += 10;
-           } else {
-               amfree(f);                              /* bad conversion */
+           } else if (ch2 == '\0') {
+               g_warning("odd number of digits in amfeature string; truncating");
                break;
+           } else {
+               goto bad;
            }
            f->bytes[i] = (unsigned char)((ch1 << 4) | ch2);
        }
     }
     return f;
+
+bad:
+    g_warning("Bad feature string '%s'", orig);
+    am_release_feature_set(f);
+    return NULL;
 }
 
 #if defined(TEST)
 int
 main(
     int                argc,
-    char       **argv)
+    char **    argv)
 {
     am_feature_t               *f;
     am_feature_t               *f1;
@@ -446,20 +463,29 @@ main(
     int                                i;
     int                                n;
 
+    /*
+     * Configure program for internationalization:
+     *   1) Only set the message locale for now.
+     *   2) Set textdomain for all amanda related programs to "amanda"
+     *      We don't want to be forced to support dozens of message catalogs.
+     */  
+    setlocale(LC_MESSAGES, "C");
+    textdomain("amanda"); 
+
     f = am_init_feature_set();
     if (f == NULL) {
-       fprintf(stderr, "cannot initialize feature set\n");
+       g_fprintf(stderr, _("cannot initialize feature set\n"));
        return 1;
     }
 
     s = am_feature_to_string(f);
-    printf("base features=%s\n", s);
+    g_printf(_("base features=%s\n"), s);
 
     f1 = am_string_to_feature(s);
     s1 = am_feature_to_string(f1);
     if (strcmp(s, s1) != 0) {
-       fprintf(stderr, "base feature -> string -> feature set mismatch\n");
-       fprintf(stderr, "conv features=%s\n", s);
+       g_fprintf(stderr, _("base feature -> string -> feature set mismatch\n"));
+       g_fprintf(stderr, _("conv features=%s\n"), s);
     }
 
     amfree(s1);
@@ -469,29 +495,29 @@ main(
        if (argv[i][0] == '+') {
            n = atoi(&argv[i][1]);
            if (am_add_feature(f, (am_feature_e)n)) {
-               printf("added feature number %d\n", n);
+               g_printf(_("added feature number %d\n"), n);
            } else {
-               printf("could not add feature number %d\n", n);
+               g_printf(_("could not add feature number %d\n"), n);
            }
        } else if (argv[i][0] == '-') {
            n = atoi(&argv[i][1]);
            if (am_remove_feature(f, (am_feature_e)n)) {
-               printf("removed feature number %d\n", n);
+               g_printf(_("removed feature number %d\n"), n);
            } else {
-               printf("could not remove feature number %d\n", n);
+               g_printf(_("could not remove feature number %d\n"), n);
            }
        } else {
            n = atoi(argv[i]);
            if (am_has_feature(f, (am_feature_e)n)) {
-               printf("feature %d is set\n", n);
+               g_printf(_("feature %d is set\n"), n);
            } else {
-               printf("feature %d is not set\n", n);
+               g_printf(_("feature %d is not set\n"), n);
            }
        }
     }
 
     s = am_feature_to_string(f);
-    printf(" new features=%s\n", s);
+    g_printf(_(" new features=%s\n"), s);
     amfree(s);
 
     return 0;