/*-------------------------------------------------------------------------*/ static int CopyTree(const char *src_pathname, const char *src_filename, const char *dest_pathname, const char *dest_filename) { char filepattern[MAXPATH], new_src_pathname[MAXPATH], new_dest_pathname[MAXPATH], src_path_filename[MAXPATH], dest_path_filename[MAXPATH], tmp_filename[MAXFILE + MAXEXT], tmp_pathname[MAXPATH]; struct ffblk fileblock; int fileattrib, done; /* copy files in subdirectories */ strmcpy(filepattern, src_pathname, sizeof(filepattern)); strmcat(filepattern, src_filename, sizeof(filepattern)); done = findfirst(filepattern, &fileblock, FA_DIREC); while (!done) { if (fileblock.ff_attrib == FA_DIREC && strcmp(fileblock.ff_name, ".") != 0 && strcmp(fileblock.ff_name, "..") != 0) { /* build source pathname */ strmcpy(new_src_pathname, src_pathname, sizeof(new_src_pathname)); strmcat(new_src_pathname, fileblock.ff_name, sizeof(new_src_pathname)); strmcat(new_src_pathname, DIR_SEPARATOR, sizeof(new_src_pathname)); /* build destination pathname */ strmcpy(new_dest_pathname, dest_pathname, sizeof(new_dest_pathname)); strmcat(new_dest_pathname, fileblock.ff_name, sizeof(new_dest_pathname)); strmcat(new_dest_pathname, DIR_SEPARATOR, sizeof(new_dest_pathname)); if (!CopyTree(new_src_pathname, "*.*", new_dest_pathname, "*.*")) return 0; } done = findnext(&fileblock); } fileattrib = FA_RDONLY+FA_ARCH+FA_HIDDEN+FA_SYSTEM; /* find first source file */ strmcpy(filepattern, src_pathname, sizeof(filepattern)); strmcat(filepattern, src_filename, sizeof(filepattern)); done = findfirst(filepattern, &fileblock, fileattrib); /* check if destination directory must be created */ if (!dir_exists(dest_pathname)) { strmcpy(tmp_pathname, dest_pathname, sizeof(tmp_pathname)); if (makedir(tmp_pathname) != 0) { #ifdef USE_KITTEN error(1,28,"Unable to create directory"); #else error("Unable to create directory"); #endif return 0; } } /* copy files */ while (!done) { /* build source filename including path */ strmcpy(src_path_filename, src_pathname, sizeof(src_path_filename)); strmcat(src_path_filename, fileblock.ff_name, sizeof(src_path_filename)); /* build destination filename including path */ strmcpy(dest_path_filename, dest_pathname, sizeof(dest_path_filename)); build_filename(tmp_filename, fileblock.ff_name, dest_filename); strmcat(dest_path_filename, tmp_filename, sizeof(dest_path_filename)); if (!xcopy_file(src_path_filename, dest_path_filename)) return 0; done = findnext(&fileblock); } return 1; }
/*-------------------------------------------------------------------------*/ void xcopy_files(const char *src_pathname, const char *src_filename, const char *dest_pathname, const char *dest_filename) { char filepattern[MAXPATH], new_src_pathname[MAXPATH], new_dest_pathname[MAXPATH], src_path_filename[MAXPATH], dest_path_filename[MAXPATH], tmp_filename[MAXFILE + MAXEXT], tmp_pathname[MAXPATH]; struct ffblk fileblock; int fileattrib, done; if (switch_emptydir || switch_subdir || switch_tree) { /* copy files in subdirectories too */ strmcpy(filepattern, src_pathname, sizeof(filepattern)); strmcat(filepattern, "*.*", sizeof(filepattern)); done = findfirst(filepattern, &fileblock, FA_DIREC); while (!done) { if ((fileblock.ff_attrib & FA_DIREC) != 0 && strcmp(fileblock.ff_name, ".") != 0 && strcmp(fileblock.ff_name, "..") != 0) { /* build source pathname */ strmcpy(new_src_pathname, src_pathname, sizeof(new_src_pathname)); strmcat(new_src_pathname, fileblock.ff_name, sizeof(new_src_pathname)); strmcat(new_src_pathname, DIR_SEPARATOR, sizeof(new_src_pathname)); /* build destination pathname */ strmcpy(new_dest_pathname, dest_pathname, sizeof(new_dest_pathname)); strmcat(new_dest_pathname, fileblock.ff_name, sizeof(new_dest_pathname)); strmcat(new_dest_pathname, DIR_SEPARATOR, sizeof(new_dest_pathname)); xcopy_files(new_src_pathname, src_filename, new_dest_pathname, dest_filename); } done = findnext(&fileblock); } } fileattrib = FA_RDONLY + FA_ARCH; if (switch_hidden) { /* replace hidden and system files too */ fileattrib = fileattrib + FA_HIDDEN + FA_SYSTEM; } /* find first source file */ strmcpy(filepattern, src_pathname, sizeof(filepattern)); strmcat(filepattern, src_filename, sizeof(filepattern)); done = findfirst(filepattern, &fileblock, fileattrib); if (!done) { file_found = -1; } /* check if destination directory must be created */ if ((!done || switch_emptydir) && !dir_exists(dest_pathname)) { strmcpy(tmp_pathname, dest_pathname, sizeof(tmp_pathname)); if (make_dir(tmp_pathname) != 0) { printf("%s %s\n", catgets(cat, 1, 20, "Unable to create directory"), tmp_pathname); if (switch_continue) { return; } else { catclose(cat); exit(4); } } } /* check, if only directory tree should be created */ if (switch_tree) { return; } /* copy files */ while (!done) { /* check, if copied files should have archive attribute set */ if ((switch_archive == 0 && switch_archive_reset == 0) || fileblock.ff_attrib & FA_ARCH) { /* build source filename including path */ strmcpy(src_path_filename, src_pathname, sizeof(src_path_filename)); strmcat(src_path_filename, fileblock.ff_name, sizeof(src_path_filename)); /* build destination filename including path */ strmcpy(dest_path_filename, dest_pathname, sizeof(dest_path_filename)); build_filename(tmp_filename, fileblock.ff_name, dest_filename); strmcat(dest_path_filename, tmp_filename, sizeof(dest_path_filename)); xcopy_file(src_path_filename, dest_path_filename); } done = findnext(&fileblock); } }