implementation of copy_file and paste
This commit is contained in:
+101
-4
@@ -444,11 +444,108 @@ void yank_file_path(){
|
||||
|
||||
|
||||
}
|
||||
void yank_file(unsigned long passes, int index){
|
||||
TODO;
|
||||
void copy_file(unsigned long passes, int index){
|
||||
(void)passes;
|
||||
|
||||
yank_files.status = key_binding[index].black_magic;
|
||||
|
||||
unsigned long i;
|
||||
unsigned long j = 0;
|
||||
|
||||
char *path = malloc(strlen(global_path)+1); /* im at a loss for words, freeing this always segfaults if yank_files.count != 0
|
||||
if i use global_path directly or getcwd(NULL, 0), it will segfault at the next free on global_path.
|
||||
what makes this wierder is, regardless of if the yank_files.count != 0 is true or false, both do the same things
|
||||
so were going to just leak the size of the path */
|
||||
|
||||
memcpy(path, global_path, strlen(global_path)+1);
|
||||
|
||||
if (yank_files.count != 0) {
|
||||
for (i = 0; i < yank_files.count; i++) {
|
||||
free(yank_files.list[i]);
|
||||
}
|
||||
free(yank_files.list);
|
||||
yank_files.count = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < mid_dir.file_count; i++) {
|
||||
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
|
||||
yank_files.count++;
|
||||
}
|
||||
}
|
||||
if (yank_files.count != 0) {
|
||||
yank_files.list = malloc(yank_files.count * sizeof(char*));
|
||||
|
||||
for (i = 0; j < yank_files.count; i++) {
|
||||
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
|
||||
|
||||
char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1);
|
||||
memcpy(str, path, strlen(path));
|
||||
memcpy(str+strlen(path)+1, mid_dir.file_list[i].file_name, strlen(mid_dir.file_list[i].file_name)+1);
|
||||
str[strlen(path)] = '/';
|
||||
|
||||
yank_files.list[j] = str;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*this path is achieved if no file is explicitly selected by the user, thus we assume the user wants the currently hovered file*/
|
||||
yank_files.list = malloc(1 * sizeof(char*));
|
||||
|
||||
char *str = malloc(strlen(path) + 1 + strlen(mid_dir.current_file->file_name)+1);
|
||||
memcpy(str, path, strlen(path));
|
||||
memcpy(str+strlen(path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||
str[strlen(path)] = '/';
|
||||
|
||||
*yank_files.list = str;
|
||||
yank_files.count = 1;
|
||||
}
|
||||
|
||||
/*free(path);*/
|
||||
|
||||
|
||||
status |= (STATUS_RUN_BACKEND);
|
||||
}
|
||||
void paste(){
|
||||
TODO;
|
||||
void paste(unsigned long passes){
|
||||
|
||||
unsigned long i;
|
||||
unsigned long j;
|
||||
file tmp;
|
||||
char *cmd;
|
||||
|
||||
for (j = 0; j < passes; j++) {
|
||||
for (i = 0; i < yank_files.count; i++) {
|
||||
|
||||
char *file_name = strrchr(yank_files.list[i], '/')+1;
|
||||
char *dest_file_name = malloc(strlen(file_name)+1);
|
||||
memcpy(dest_file_name, file_name, strlen(file_name)+1);
|
||||
|
||||
|
||||
tmp.file_name = yank_files.list[i];
|
||||
while(access(dest_file_name, F_OK) == 0) {
|
||||
unsigned long len = strlen(dest_file_name);
|
||||
dest_file_name = realloc(dest_file_name, len+2);
|
||||
|
||||
dest_file_name[len] = '_';
|
||||
dest_file_name[len+1] = 0;
|
||||
|
||||
}
|
||||
if (yank_files.status == COPY_FILE) {
|
||||
cmd = parse_cmd(copy_cmd, &tmp);
|
||||
} else if (yank_files.status == CUT_FILE) {
|
||||
cmd = parse_cmd(cut_cmd, &tmp);
|
||||
} else {
|
||||
free(dest_file_name);
|
||||
continue;
|
||||
}
|
||||
tmp.file_name = dest_file_name;
|
||||
cmd = parse_cmd(cmd, &tmp);
|
||||
system(cmd);
|
||||
free(cmd);
|
||||
free(tmp.file_name);
|
||||
}
|
||||
}
|
||||
|
||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||
}
|
||||
void search(){
|
||||
echo();
|
||||
|
||||
Reference in New Issue
Block a user