+
+static char *
+clean_backslash(
+ char *line)
+{
+ char *s = line, *s1, *s2;
+ char *p = line;
+ int i;
+
+ while(*s != '\0') {
+ if (*s == '\\') {
+ s++;
+ s1 = s+1;
+ s2 = s+2;
+ if (*s != '\0' && isdigit((int)*s) &&
+ *s1 != '\0' && isdigit((int)*s1) &&
+ *s2 != '\0' && isdigit((int)*s2)) {
+ /* this is \000, an octal value */
+ i = ((*s)-'0')*64 + ((*s1)-'0')*8 + ((*s2)-'0');
+ *p++ = i;
+ s += 3;
+ } else if (*s == '\\') { /* we remove one / */
+ *p++ = *s++;
+ } else { /* we keep the / */
+ *p++ = '\\';
+ *p++ = *s++;
+ }
+ } else {
+ *p++ = *s++;
+ }
+ }
+ *p = '\0';
+
+ return line;
+}
+
+
+static int
+get_index_dir(
+ char *dump_hostname,
+ char *hostname,
+ char *diskname)
+{
+ struct stat dir_stat;
+ char *fn;
+ char *s;
+ char *lower_hostname;
+
+ lower_hostname = stralloc(dump_hostname);
+ for(s=lower_hostname; *s != '\0'; s++)
+ *s = tolower(*s);
+
+ fn = getindexfname(dump_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ if (hostname != NULL) {
+ fn = getindexfname(hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ }
+ amfree(fn);
+ fn = getindexfname(lower_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ if(diskname != NULL) {
+ fn = getoldindexfname(dump_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ if (hostname != NULL) {
+ fn = getoldindexfname(hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ }
+ amfree(fn);
+ fn = getoldindexfname(lower_hostname, diskname, NULL, 0);
+ if (stat(fn, &dir_stat) == 0 && S_ISDIR(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ amfree(fn);
+ return 1;
+ }
+ amfree(fn);
+ }
+ amfree(lower_hostname);
+ return -1;
+}
+
+static char *
+get_index_name(
+ char *dump_hostname,
+ char *hostname,
+ char *diskname,
+ char *timestamps,
+ int level)
+{
+ struct stat dir_stat;
+ char *fn;
+ char *s;
+ char *lower_hostname;
+
+ lower_hostname = stralloc(dump_hostname);
+ for(s=lower_hostname; *s != '\0'; s++)
+ *s = tolower(*s);
+
+ fn = getindexfname(dump_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ amfree(fn);
+ if(hostname != NULL) {
+ fn = getindexfname(hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ }
+ amfree(fn);
+ fn = getindexfname(lower_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ amfree(fn);
+ if(diskname != NULL) {
+ fn = getoldindexfname(dump_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ amfree(fn);
+ if(hostname != NULL) {
+ fn = getoldindexfname(hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ }
+ amfree(fn);
+ fn = getoldindexfname(lower_hostname, diskname, timestamps, level);
+ if (stat(fn, &dir_stat) == 0 && S_ISREG(dir_stat.st_mode)) {
+ amfree(lower_hostname);
+ return fn;
+ }
+ }
+ amfree(lower_hostname);
+ return NULL;
+}