/* * Build attr->ofname from attr->fname and * attr->olname from attr->olname */ void build_attr_output_fnames(JCR *jcr, ATTR *attr) { /* * Prepend the where directory so that the * files are put where the user wants. * * We do a little jig here to handle Win32 files with * a drive letter -- we simply change the drive * from, for example, c: to c/ for * every filename if a prefix is supplied. * */ if (jcr->where_bregexp) { char *ret; apply_bregexps(attr->fname, jcr->where_bregexp, &ret); pm_strcpy(attr->ofname, ret); if (attr->type == FT_LNKSAVED || attr->type == FT_LNK) { /* Always add prefix to hard links (FT_LNKSAVED) and * on user request to soft links */ if ((attr->type == FT_LNKSAVED || jcr->prefix_links)) { apply_bregexps(attr->lname, jcr->where_bregexp, &ret); pm_strcpy(attr->olname, ret); } else { pm_strcpy(attr->olname, attr->lname); } } } else if (jcr->where[0] == 0) { pm_strcpy(attr->ofname, attr->fname); pm_strcpy(attr->olname, attr->lname); } else { const char *fn; int wherelen = strlen(jcr->where); pm_strcpy(attr->ofname, jcr->where); /* copy prefix */ #if defined(HAVE_WIN32) if (attr->fname[1] == ':') { attr->fname[1] = '/'; /* convert : to / */ } #endif fn = attr->fname; /* take whole name */ /* Ensure where is terminated with a slash */ if (!IsPathSeparator(jcr->where[wherelen-1]) && !IsPathSeparator(fn[0])) { pm_strcat(attr->ofname, "/"); } pm_strcat(attr->ofname, fn); /* copy rest of name */ /* * Fixup link name -- if it is an absolute path */ if (attr->type == FT_LNKSAVED || attr->type == FT_LNK) { bool add_link; /* Always add prefix to hard links (FT_LNKSAVED) and * on user request to soft links */ if (IsPathSeparator(attr->lname[0]) && (attr->type == FT_LNKSAVED || jcr->prefix_links)) { pm_strcpy(attr->olname, jcr->where); add_link = true; } else { attr->olname[0] = 0; add_link = false; } #if defined(HAVE_WIN32) if (attr->lname[1] == ':') { attr->lname[1] = '/'; /* turn : into / */ } #endif fn = attr->lname; /* take whole name */ /* Ensure where is terminated with a slash */ if (add_link && !IsPathSeparator(jcr->where[wherelen-1]) && !IsPathSeparator(fn[0])) { pm_strcat(attr->olname, "/"); } pm_strcat(attr->olname, fn); /* copy rest of link */ } } #if defined(HAVE_WIN32) strip_double_slashes(attr->ofname); strip_double_slashes(attr->olname); #endif }
int main(int argc, char *const *argv) { char *fname = NULL; char *expr = NULL; int ch; bool sed=false; char data[1000]; FILE *fd; setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); while ((ch = getopt(argc, argv, "sd:f:e:")) != -1) { switch (ch) { case 'd': /* set debug level */ if (*optarg == 't') { dbg_timestamp = true; } else { debug_level = atoi(optarg); if (debug_level <= 0) { debug_level = 1; } } break; case 'f': /* data */ fname = optarg; break; case 'e': expr = optarg; break; case 's': sed=true; break; case '?': default: usage(); } } argc -= optind; argv += optind; if (!fname) { printf("A data file must be specified.\n"); usage(); } if (!expr) { printf("An expression must be specified.\n"); usage(); } OSDependentInit(); alist *list; char *p; list = get_bregexps(expr); if (!list) { printf("Can't use %s as 'sed' expression\n", expr); exit (1); } fd = fopen(fname, "r"); if (!fd) { printf(_("Could not open data file: %s\n"), fname); exit(1); } while (fgets(data, sizeof(data)-1, fd)) { strip_trailing_newline(data); apply_bregexps(data, list, &p); if (sed) { printf("%s\n", p); } else { printf("%s => %s\n", data, p); } } fclose(fd); free_bregexps(list); delete list; exit(0); }