parse_cmd now using file name strings rather than file struct
This commit is contained in:
@@ -81,26 +81,24 @@ char* smartstrcasestr(const char *haystack, const char *needle){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char* parse_cmd(const char *cmd, file *f){
|
char* parse_cmd(const char *cmd, char *file_name){
|
||||||
char *out;
|
char *out;
|
||||||
if (f == NULL) {
|
if (file_name == NULL) {
|
||||||
out = malloc(strlen(cmd)+1);
|
return NULL;
|
||||||
memcpy(out, cmd, strlen(cmd)+1);
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
const char *offset = strstr(cmd, SETTINGS_COMMAND_REPLACE_STR);
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
char *pos;
|
char *pos;
|
||||||
unsigned long i = 0;
|
unsigned long i = 0;
|
||||||
while(f->file_name[i]) {
|
while(file_name[i]) {
|
||||||
if (f->file_name[i] == '\'') {
|
if (file_name[i] == '\'') {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
out = malloc(strlen(cmd) + 1 + (strlen(f->file_name)+(count*3)) + 3);
|
out = malloc(strlen(cmd) + 1 + (strlen(file_name)+(count*3)) + 3);
|
||||||
|
|
||||||
pos = out;
|
pos = out;
|
||||||
if (offset) {
|
if (offset) {
|
||||||
@@ -115,13 +113,13 @@ char* parse_cmd(const char *cmd, file *f){
|
|||||||
pos++;
|
pos++;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while(f->file_name[i]) {
|
while(file_name[i]) {
|
||||||
if (f->file_name[i] == '\'') {
|
if (file_name[i] == '\'') {
|
||||||
*pos++ = '\'';
|
*pos++ = '\'';
|
||||||
*pos++ = '\\';
|
*pos++ = '\\';
|
||||||
*pos++ = '\'';
|
*pos++ = '\'';
|
||||||
}
|
}
|
||||||
*pos = f->file_name[i];
|
*pos = file_name[i];
|
||||||
pos++;
|
pos++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@
|
|||||||
|
|
||||||
/*char* concat(const char *s1, const char *s2);*/
|
/*char* concat(const char *s1, const char *s2);*/
|
||||||
char* smartstrcasestr(const char *haystack, const char *needle);
|
char* smartstrcasestr(const char *haystack, const char *needle);
|
||||||
char* parse_cmd(const char *cmd, file *f);
|
char* parse_cmd(const char *cmd, char *file_name);
|
||||||
|
|
||||||
|
|||||||
+30
-33
@@ -201,7 +201,7 @@ void move_right(){
|
|||||||
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
if (mid_dir.current_file->file_type & FILE_TYPE_DIR) {
|
||||||
change_dir(mid_dir.current_file->file_name);
|
change_dir(mid_dir.current_file->file_name);
|
||||||
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
} else if (mid_dir.current_file->file_type & FILE_TYPE_EXEC) {
|
||||||
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR,mid_dir.current_file);
|
char *cmd = parse_cmd("./"SETTINGS_COMMAND_REPLACE_STR, mid_dir.current_file->file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
} else {
|
} else {
|
||||||
char *mime = get_mimetype(mid_dir.current_file);
|
char *mime = get_mimetype(mid_dir.current_file);
|
||||||
@@ -219,7 +219,7 @@ void move_right(){
|
|||||||
for (i = 0; i < file_extension_default_count; i++) {
|
for (i = 0; i < file_extension_default_count; i++) {
|
||||||
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
|
if (strcmp(extension, file_extension_default_cmd[i].file_extension) == 0) {
|
||||||
if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
if (file_extension_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||||
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file);
|
cmd = parse_cmd(file_extension_default_cmd[i].command + 1, mid_dir.current_file->file_name);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0 && setsid()) {
|
if (pid == 0 && setsid()) {
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
@@ -227,7 +227,7 @@ void move_right(){
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file);
|
cmd = parse_cmd(file_extension_default_cmd[i].command, mid_dir.current_file->file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
}
|
}
|
||||||
status |= STATUS_MOVE_RIGHT_MATCH;
|
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||||
@@ -240,7 +240,7 @@ void move_right(){
|
|||||||
for (i = 0; i < mimetype_default_count; i++) {
|
for (i = 0; i < mimetype_default_count; i++) {
|
||||||
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
if (strstr(mime, mimetype_default_cmd[i].mimetype)) {
|
||||||
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
if (mimetype_default_cmd[i].command[0] == SETTINGS_COMMAND_FORK) {
|
||||||
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file);
|
cmd = parse_cmd(mimetype_default_cmd[i].command + 1, mid_dir.current_file->file_name);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0 && setsid()) {
|
if (pid == 0 && setsid()) {
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
@@ -248,7 +248,7 @@ void move_right(){
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file);
|
cmd = parse_cmd(mimetype_default_cmd[i].command, mid_dir.current_file->file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
}
|
}
|
||||||
status |= STATUS_MOVE_RIGHT_MATCH;
|
status |= STATUS_MOVE_RIGHT_MATCH;
|
||||||
@@ -288,12 +288,12 @@ void open_with(){
|
|||||||
wclear(win_b);
|
wclear(win_b);
|
||||||
char *cmd;
|
char *cmd;
|
||||||
char *str = malloc(INPUT_BUFFER_SIZE);
|
char *str = malloc(INPUT_BUFFER_SIZE);
|
||||||
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file);
|
char *parsed_ui_text = parse_cmd(ui_open_with_text, mid_dir.current_file->file_name);
|
||||||
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
|
|
||||||
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
|
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, str) == 0) {
|
||||||
if (str[0] == SETTINGS_COMMAND_FORK) {
|
if (str[0] == SETTINGS_COMMAND_FORK) {
|
||||||
cmd = parse_cmd(str+1, mid_dir.current_file);
|
cmd = parse_cmd(str+1, mid_dir.current_file->file_name);
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == 0 && setsid()) {
|
if (pid == 0 && setsid()) {
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
@@ -301,7 +301,7 @@ void open_with(){
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmd = parse_cmd(str, mid_dir.current_file);
|
cmd = parse_cmd(str, mid_dir.current_file->file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
}
|
}
|
||||||
free(cmd);
|
free(cmd);
|
||||||
@@ -313,20 +313,19 @@ void open_with(){
|
|||||||
}
|
}
|
||||||
void rename_hovered(){
|
void rename_hovered(){
|
||||||
wclear(win_b);
|
wclear(win_b);
|
||||||
file tmp;
|
char *new_file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file->file_name);
|
||||||
char *parsed_ui_text = parse_cmd(ui_rename_text, mid_dir.current_file);
|
|
||||||
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
mvwprintw(win_b, 0, 0, parsed_ui_text);
|
||||||
|
|
||||||
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, tmp.file_name) == 0) {
|
if (read_string(win_b, 0, strlen(parsed_ui_text)+1, new_file_name) == 0) {
|
||||||
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file);
|
char *cmd0 = parse_cmd(rename_cmd, mid_dir.current_file->file_name);
|
||||||
char *cmd1 = parse_cmd(cmd0, &tmp);
|
char *cmd1 = parse_cmd(cmd0, new_file_name);
|
||||||
ignore_return(system(cmd1));
|
ignore_return(system(cmd1));
|
||||||
free(cmd0);
|
free(cmd0);
|
||||||
free(cmd1);
|
free(cmd1);
|
||||||
}
|
}
|
||||||
free(parsed_ui_text);
|
free(parsed_ui_text);
|
||||||
free(tmp.file_name);
|
free(new_file_name);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
@@ -338,7 +337,7 @@ void delete(unsigned long passes){
|
|||||||
|
|
||||||
for (i = 0; i < mid_dir.file_count; i++) {
|
for (i = 0; i < mid_dir.file_count; i++) {
|
||||||
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
|
if (mid_dir.file_list[i].status & FILE_STATUS_SELECTED) {
|
||||||
cmd = parse_cmd(del_cmd, &mid_dir.file_list[i]);
|
cmd = parse_cmd(del_cmd, mid_dir.file_list[i].file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
del_count++;
|
del_count++;
|
||||||
@@ -350,7 +349,7 @@ void delete(unsigned long passes){
|
|||||||
if (&mid_dir.current_file[i] > mid_dir.file_list + mid_dir.file_count) {
|
if (&mid_dir.current_file[i] > mid_dir.file_list + mid_dir.file_count) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
cmd = parse_cmd(del_cmd, &mid_dir.current_file[i]);
|
cmd = parse_cmd(del_cmd, mid_dir.current_file[i].file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
@@ -362,29 +361,27 @@ void delete(unsigned long passes){
|
|||||||
}
|
}
|
||||||
void makedir(){
|
void makedir(){
|
||||||
wclear(win_b);
|
wclear(win_b);
|
||||||
file tmp;
|
char *file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
|
||||||
mvwprintw(win_b, 0, 0, ui_makedir_text);
|
mvwprintw(win_b, 0, 0, ui_makedir_text);
|
||||||
if (read_string(win_b, 0, strlen(ui_makedir_text)+1, tmp.file_name) == 0) {
|
if (read_string(win_b, 0, strlen(ui_makedir_text)+1, file_name) == 0) {
|
||||||
char *cmd = parse_cmd(makedir_cmd, &tmp);
|
char *cmd = parse_cmd(makedir_cmd, file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
free(tmp.file_name);
|
free(file_name);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
void makefile(){
|
void makefile(){
|
||||||
wclear(win_b);
|
wclear(win_b);
|
||||||
file tmp;
|
char *file_name = malloc(INPUT_BUFFER_SIZE);
|
||||||
tmp.file_name = malloc(INPUT_BUFFER_SIZE);
|
|
||||||
mvwprintw(win_b, 0, 0, ui_makefile_text);
|
mvwprintw(win_b, 0, 0, ui_makefile_text);
|
||||||
if (read_string(win_b, 0, strlen(ui_makefile_text)+1, tmp.file_name) == 0) {
|
if (read_string(win_b, 0, strlen(ui_makefile_text)+1, file_name) == 0) {
|
||||||
char *cmd = parse_cmd(makefile_cmd, &tmp);
|
char *cmd = parse_cmd(makefile_cmd, file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
free(tmp.file_name);
|
free(file_name);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY);
|
||||||
}
|
}
|
||||||
@@ -441,14 +438,14 @@ void order_by(unsigned long passes, int index){
|
|||||||
void cmd_on_selected(unsigned long passes, int index){
|
void cmd_on_selected(unsigned long passes, int index){
|
||||||
unused(passes);
|
unused(passes);
|
||||||
|
|
||||||
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file);
|
char *cmd = parse_cmd(key_binding[index].black_magic, mid_dir.current_file->file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
status |= (STATUS_RUN_BACKEND | STATUS_RELOAD_DIRECTORY | STATUS_UPDATE_SCREEN_CLEAR);
|
||||||
}
|
}
|
||||||
void yank_file_name(){
|
void yank_file_name(){
|
||||||
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file);
|
char *cmd = parse_cmd(clipboard_cmd, mid_dir.current_file->file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
|
|
||||||
@@ -460,7 +457,7 @@ void yank_file_path(){
|
|||||||
memcpy(tmp->file_name, global_path, strlen(global_path));
|
memcpy(tmp->file_name, global_path, strlen(global_path));
|
||||||
memcpy(tmp->file_name+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
memcpy(tmp->file_name+strlen(global_path)+1, mid_dir.current_file->file_name, strlen(mid_dir.current_file->file_name)+1);
|
||||||
tmp->file_name[strlen(global_path)] = '/'; /*no +1 is needed*/
|
tmp->file_name[strlen(global_path)] = '/'; /*no +1 is needed*/
|
||||||
char *cmd = parse_cmd(clipboard_cmd, tmp);
|
char *cmd = parse_cmd(clipboard_cmd, tmp->file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
free(tmp->file_name);
|
free(tmp->file_name);
|
||||||
@@ -546,15 +543,15 @@ void paste(unsigned long passes){
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (yank_files.status == COPY_FILE) {
|
if (yank_files.status == COPY_FILE) {
|
||||||
cmd = parse_cmd(copy_cmd, &tmp);
|
cmd = parse_cmd(copy_cmd, tmp.file_name);
|
||||||
} else if (yank_files.status == CUT_FILE) {
|
} else if (yank_files.status == CUT_FILE) {
|
||||||
cmd = parse_cmd(cut_cmd, &tmp);
|
cmd = parse_cmd(cut_cmd, tmp.file_name);
|
||||||
} else {
|
} else {
|
||||||
free(dest_file_name);
|
free(dest_file_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
tmp.file_name = dest_file_name;
|
tmp.file_name = dest_file_name;
|
||||||
cmd = parse_cmd(cmd, &tmp);
|
cmd = parse_cmd(cmd, tmp.file_name);
|
||||||
ignore_return(system(cmd));
|
ignore_return(system(cmd));
|
||||||
free(cmd);
|
free(cmd);
|
||||||
free(tmp.file_name);
|
free(tmp.file_name);
|
||||||
|
|||||||
Reference in New Issue
Block a user