diff --git a/src/UI/Motif/xsend_file/Makefile.am b/src/UI/Motif/xsend_file/Makefile.am index dc541512..4e6d06fb 100644 --- a/src/UI/Motif/xsend_file/Makefile.am +++ b/src/UI/Motif/xsend_file/Makefile.am @@ -25,6 +25,7 @@ AM_CPPFLAGS = @AFD_MOTIF_INCLUDES@ -I../../.. -I../../common\ bin_PROGRAMS = xsend_file xsend_file_SOURCES = callbacks.c\ create_url_file.c\ + rr_file_name_file.c\ send_file.c\ xsend_file.c xsend_file_LDADD = ../common/libmotifafd.a\ diff --git a/src/UI/Motif/xsend_file/callbacks.c b/src/UI/Motif/xsend_file/callbacks.c index fee5a1bc..a093861f 100644 --- a/src/UI/Motif/xsend_file/callbacks.c +++ b/src/UI/Motif/xsend_file/callbacks.c @@ -37,6 +37,7 @@ DESCR__S_M3 ** HISTORY ** 24.01.2005 H.Kiehl Created ** 11.02.2014 A.Maul Properly set and unset active, passive mode. + ** 02.01.2019 A.Maul Added select rename-rule with rename option. ** */ DESCR__E_M3 @@ -96,13 +97,83 @@ extern Widget active_passive_w, statusbox_w, timeout_label_w, timeout_w, + rename_label_w[4], + rename_menu_w, + rename_toggle_w, + rename_onoff_w, + rename_filt_w, + rename_patt_w, user_name_label_w, user_name_w; extern XtInputId cmd_input_id; extern XmTextPosition wpr_position; extern XmFontList fontlist; extern struct send_data *db; +extern int no_of_rule_headers; +extern struct rule *rule; +/*############################ rename_toggle() ##########################*/ +void +rename_onoff(Widget w, XtPointer client_data, XtPointer call_data) +{ + XmString xstr; + + if (db->rename_do & SET_RENAME_ON) + { + db->rename_do &= ~SET_RENAME_ON; + _set_rename_boxies(OFF); + xstr = XmStringCreateLtoR("Off", XmFONTLIST_DEFAULT_TAG); + XtVaSetValues(w, XmNlabelString, xstr, NULL); + XmStringFree(xstr); + } + else + { + db->rename_do |= SET_RENAME_ON; + _set_rename_boxies(ON); + xstr = XmStringCreateLtoR("On ", XmFONTLIST_DEFAULT_TAG); + XtVaSetValues(w, XmNlabelString, xstr, NULL); + XmStringFree(xstr); + } + return; +} + +/*############################ rename_toggle() ##########################*/ +void +rename_toggle(Widget w, XtPointer client_data, XtPointer call_data) +{ + XmString xstr; + + if (db->rename_do & SET_RENAME_MANUAL) + { + db->rename_do &= ~SET_RENAME_MANUAL; + db->rename_do |= SET_RENAME_RULE; + _set_rename_boxies(ON); + xstr = XmStringCreateLtoR("Rule ", XmFONTLIST_DEFAULT_TAG); + XtVaSetValues(w, XmNlabelString, xstr, NULL); + XmStringFree(xstr); + } + else + { + db->rename_do &= ~SET_RENAME_RULE; + db->rename_do |= SET_RENAME_MANUAL; + _set_rename_boxies(ON); + xstr = XmStringCreateLtoR("Manual", XmFONTLIST_DEFAULT_TAG); + XtVaSetValues(w, XmNlabelString, xstr, NULL); + XmStringFree(xstr); + } + return; +} + +/*############################ rename_eval() ############################*/ +void +rename_eval(Widget w, XtPointer client_data, XtPointer call_data) +{ + XT_PTR_TYPE rule_num = (XT_PTR_TYPE)client_data; + if (rule_num < no_of_rule_headers) + { + db->rename_num = rule_num; + } +} /*############################ close_button() ###########################*/ void @@ -286,6 +357,36 @@ send_button(Widget w, XtPointer client_data, XtPointer call_data) show_message(statusbox_w, "No protocol selected, or unknown."); break; } + /* + * check filter/pattern + rule, call rewrite file_name_file + */ + if (db->rename_do & SET_RENAME_ON) + { + if (db->rename_do & SET_RENAME_MANUAL) + { + if (db->rename_filt[0] == '\0') + { + show_message(statusbox_w, "No rename filter given!"); + XmProcessTraversal(rename_filt_w, XmTRAVERSE_CURRENT); + return; + } + if (db->rename_patt[0] == '\0') + { + show_message(statusbox_w, "No rename pattern given!"); + XmProcessTraversal(rename_patt_w, XmTRAVERSE_CURRENT); + return; + } + } + else + { + if (db->rename_num == INCORRECT) + { + show_message(statusbox_w, "Invalid rename-rule name!"); + XmProcessTraversal(rename_menu_w, XmTRAVERSE_CURRENT); + return; + } + } + } if (wpr_position != 0) { @@ -295,6 +396,37 @@ send_button(Widget w, XtPointer client_data, XtPointer call_data) wpr_position = 0; } create_url_file(); + + if ((db->rename_do & SET_RENAME_ON) && ( + (db->protocol == FTP) || (db->protocol == SFTP) || (db->protocol == LOC)) + ) + { + if (db->rename_do & SET_RENAME_RULE) + { + if (rr_file_name_file(rule, db->rename_num, NULL, NULL) == INCORRECT) + { + show_message(statusbox_w, "Evaluating rename-rule(s) failed!"); + return; + } + } + if (db->rename_do & SET_RENAME_MANUAL) + { + if (rr_file_name_file(rule, -1, db->rename_filt, db->rename_patt) == INCORRECT) + { + show_message(statusbox_w, "Evaluating rename-rule( failed!"); + return; + } + } + } + else + { + if (rr_file_name_file(rule, -1, NULL, NULL) == INCORRECT) + { + show_message(statusbox_w, "Resetting rename-rule evaluation failed!"); + return; + } + } + send_file(); /* Set Stop button. */ @@ -360,6 +492,7 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) { return; } + db->protocol = (XT_PTR_TYPE)client_data; switch ((XT_PTR_TYPE)client_data) { case FTP : @@ -475,6 +608,8 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) XtSetSensitive(lock_box_w, True); XtSetSensitive(prefix_w, True); + _set_rename_boxies(ON); + XmTextSetString(proxy_w, db->proxy_name); XtSetSensitive(proxy_label_w, True); XtSetSensitive(proxy_w, True); @@ -594,6 +729,8 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) XtSetSensitive(lock_box_w, True); XtSetSensitive(prefix_w, True); + _set_rename_boxies(ON); + XtSetSensitive(proxy_label_w, False); XtSetSensitive(proxy_w, False); @@ -722,6 +859,8 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) XtSetSensitive(lock_box_w, False); XtSetSensitive(prefix_w, False); + _set_rename_boxies(OFF); + XtSetSensitive(proxy_label_w, False); XtSetSensitive(proxy_w, False); break; @@ -747,6 +886,7 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) XtSetSensitive(mode_box_w, False); XtSetSensitive(lock_box_w, True); XtSetSensitive(prefix_w, True); + _set_rename_boxies(ON); break; #ifdef _WITH_SCP_SUPPORT @@ -771,6 +911,7 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) XtSetSensitive(mode_box_w, False); XtSetSensitive(lock_box_w, True); XtSetSensitive(prefix_w, True); + _set_rename_boxies(ON); if (db->port == 0) { char str_line[MAX_PORT_DIGITS + 1]; @@ -849,6 +990,8 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) XtSetSensitive(lock_box_w, False); XtSetSensitive(prefix_w, False); + _set_rename_boxies(OFF); + XtSetSensitive(proxy_label_w, False); XtSetSensitive(proxy_w, False); break; @@ -858,7 +1001,6 @@ protocol_toggled(Widget w, XtPointer client_data, XtPointer call_data) (void)fprintf(stderr, "Junk programmer!\n"); exit(INCORRECT); } - db->protocol = (XT_PTR_TYPE)client_data; return; } @@ -1008,6 +1150,43 @@ send_save_input(Widget w, XtPointer client_data, XtPointer call_data) XmProcessTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP); break; + /* + * save rename values + */ + case RENAME_FILT_NO_ENTER : + (void)strcpy(db->rename_filt, value); + break; + case RENAME_FILT_ENTER : + (void)strcpy(db->rename_filt, value); + reset_message(statusbox_w); + XmProcessTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP); + break; + + case RENAME_PATT_NO_ENTER : + (void)strcpy(db->rename_patt, value); + break; + case RENAME_PATT_ENTER : + (void)strcpy(db->rename_patt, value); + reset_message(statusbox_w); + XmProcessTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP); + break; + + case RENAME_RULE_NO_ENTER : + case RENAME_RULE_ENTER : + db->rename_num = get_rule(value, no_of_rule_headers); + if (db->rename_num == INCORRECT) + { + show_message(statusbox_w, "Invalid rename-rule name!"); + XtFree(value); + return; + } + if (type == RENAME_RULE_ENTER) + { + XmProcessTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP); + } + reset_message(statusbox_w); + break; + default : (void)fprintf(stderr, "ERROR : Impossible! (%s %d)\n", __FILE__, __LINE__); diff --git a/src/UI/Motif/xsend_file/rr_file_name_file.c b/src/UI/Motif/xsend_file/rr_file_name_file.c new file mode 100644 index 00000000..361068d5 --- /dev/null +++ b/src/UI/Motif/xsend_file/rr_file_name_file.c @@ -0,0 +1,229 @@ +/* + * eval_files.c - Part of AFD, an automatic file distribution program. + * Copyright (c) 2000 - 2012 Deutscher Wetterdienst (DWD), + * Holger Kiehl + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "afddefs.h" + +DESCR__S_M3 +/* + ** NAME + ** rr_file_name_file - modifies file with filenames + ** + ** SYNOPSIS + ** void rr_file_name_file(char *file_name, struct data *p_db) + ** + ** DESCRIPTION + ** This function applies the given rename-rule to all the filenames + ** in file_name_file, appending the target/remote name to the local name. + ** If there already is a rename-name, it is overwritten. + ** Afterwards the file_name_file is re-written with the changes. + ** + ** RETURN VALUES + ** SUCCESS or INCORRECT. + ** + ** AUTHOR + ** A.Maul + ** + ** HISTORY + ** 02.01.2019 A.Maul Created. + */ +DESCR__E_M3 + +#include /* stderr, fprintf() */ +#include /* atoi() */ +#include /* strcpy(), strerror(), strcmp() */ +#include /* getpid(), write(), close() */ +#include +#include + +extern char file_name_file[], file_name_file_copy[]; + +/*####################### _rr_file_name_file() #############################*/ +int rr_file_name_file(struct rule *rule, int rule_no, char *filter, char *rename_to) +{ + int ret; + char *buffer, *modbuf; + off_t buffer_sz, modbuf_sz; + struct stat foo; + int fd; + + if (file_name_file_copy[0] == '\0') + { + (void) strcpy(file_name_file_copy, file_name_file); + (void) strcat(file_name_file_copy, ".rr"); + } + if (stat(file_name_file_copy, &foo) != 0) + { + if ((buffer_sz = read_file_no_cr(file_name_file, &buffer, NO, __FILE__, __LINE__)) == INCORRECT) + { + ret = INCORRECT; + } + if ((fd = open(file_name_file_copy, (O_WRONLY | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR))) == -1) + { + (void) fprintf(stderr, "Failed to open() `%s' : %s (%s %d)\n", file_name_file_copy, strerror(errno), __FILE__, + __LINE__); + return (INCORRECT); + } + else + { + if (write(fd, buffer, buffer_sz) != buffer_sz) + { + (void) fprintf(stderr, "Failed to write() to `%s' : %s (%s %d)\n", file_name_file_copy, strerror(errno), + __FILE__, __LINE__); + return (INCORRECT); + } + if (close(fd) == -1) + { + (void) fprintf(stderr, "Failed to close() `%s' : %s (%s %d)\n", file_name_file_copy, strerror(errno), + __FILE__, __LINE__); + } + ret = SUCCESS; + } + } + else + { + if ((buffer_sz = read_file_no_cr(file_name_file_copy, &buffer, NO, __FILE__, __LINE__)) == INCORRECT) + { + ret = INCORRECT; + } + ret = SUCCESS; + } + if (ret != INCORRECT) + { + char *ptr = buffer; + char *p_fn, filename[MAX_PATH_LENGTH], realname[MAX_PATH_LENGTH]; + size_t length; + register int i, k; + + modbuf_sz = 0; + modbuf = NULL; + length = 0; + + do + { + i = 0; + while ((*ptr != '\n') && (*ptr != '|') && (*ptr != '\0')) + { + filename[i] = *ptr; + ptr++; + i++; + } + if (*ptr == '\n') + { + ptr++; + } + filename[i] = '\0'; + if (*ptr == '|') + { + i = 0; + ptr++; + while ((*ptr != '\n') && (*ptr != '\0')) + { + realname[i] = *ptr; + ptr++; + i++; + } + if (*ptr == '\n') + { + ptr++; + } + realname[i] = '\0'; + if (!(p_fn = strrchr(realname, '/'))) + { + p_fn = realname; + } + } + else + { + realname[0] = '\0'; + if (!(p_fn = strrchr(filename, '/'))) + { + p_fn = filename; + } + } + if (*p_fn == '/') + { + p_fn++; + } + int counter_fd = -1, *unique_counter; + if (rule_no >= 0) + { + /* find and use rule from file rename.rule */ + for (k = 0; k < rule[rule_no].no_of_rules; k++) + { + if (pmatch(rule[rule_no].filter[k], p_fn, NULL ) == 0) + { + change_name(p_fn, rule[rule_no].filter[k], rule[rule_no].rename_to[k], realname, MAX_PATH_LENGTH, + &counter_fd, &unique_counter, 0); + break; + } + } + } + else + if ((filter != NULL )&& (rename_to != NULL) && (filter[0] != '\0') && (rename_to[0] != '\0')){ + /* use single rename */ + change_name(p_fn, filter, rename_to, realname, MAX_PATH_LENGTH, + &counter_fd, &unique_counter, 0); + } + if ((length + strlen(filename) + strlen(realname) + 2) >= modbuf_sz) + { + modbuf_sz += 2 * MAX_PATH_LENGTH; + if (!(modbuf = (char*) realloc(modbuf, modbuf_sz * sizeof(char)))) + { + (void) fprintf(stderr, "Could not realloc() memory : %s [%s %d]\n", strerror(errno), __FILE__, __LINE__); + return (INCORRECT); + } + } + if (realname[0]) + { + length += sprintf(&modbuf[length], "%s|%s\n", filename, realname); + } + else + { + length += sprintf(&modbuf[length], "%s\n", filename); + } + } while ((*ptr != '\0') && (ptr < buffer + buffer_sz)); + + if ((fd = open(file_name_file, (O_WRONLY | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR))) == -1) + { + (void) fprintf(stderr, "Failed to open() `%s' : %s (%s %d)\n", file_name_file, strerror(errno), __FILE__, + __LINE__); + return (INCORRECT); + } + else + { + if (write(fd, modbuf, length) != length) + { + (void) fprintf(stderr, "Failed to write() to `%s' : %s (%s %d)\n", file_name_file, strerror(errno), + __FILE__, __LINE__); + return (INCORRECT); + } + if (close(fd) == -1) + { + (void) fprintf(stderr, "Failed to close() `%s' : %s (%s %d)\n", file_name_file, strerror(errno), __FILE__, + __LINE__); + } + } + ret = SUCCESS; + free(buffer); + free(modbuf); + } + + return (ret); +} diff --git a/src/UI/Motif/xsend_file/send_file.c b/src/UI/Motif/xsend_file/send_file.c index 5e7f3c61..1ed35fcc 100644 --- a/src/UI/Motif/xsend_file/send_file.c +++ b/src/UI/Motif/xsend_file/send_file.c @@ -42,6 +42,7 @@ DESCR__S_M3 ** HISTORY ** 05.12.1999 H.Kiehl Created ** 31.01.2005 H.Kiehl Adapted from xexec_cmd(). + ** 02.01.2019 A.Maul Add parameter for LOCK_OFF to 'cmd'. ** */ DESCR__E_M3 @@ -148,6 +149,10 @@ send_file(void) { length += sprintf(&cmd[length], " -l DOT"); } + else if (db->lock == SET_LOCK_OFF) + { + length += sprintf(&cmd[length], " -l OFF"); + } else if (db->lock == SET_LOCK_DOT_VMS) { length += sprintf(&cmd[length], " -l DOT_VMS"); diff --git a/src/UI/Motif/xsend_file/xsend_file.c b/src/UI/Motif/xsend_file/xsend_file.c index 187eccdc..0e2dfe0e 100644 --- a/src/UI/Motif/xsend_file/xsend_file.c +++ b/src/UI/Motif/xsend_file/xsend_file.c @@ -39,7 +39,7 @@ DESCR__S_M1 ** HISTORY ** 24.01.2005 H.Kiehl Created ** 12.08.2006 H.Kiehl Added extended active/passive mode option. - ** + ** 02.01.2019 A.Maul Added select rename-rule with rename option. */ DESCR__E_M1 @@ -112,6 +112,12 @@ Widget active_passive_w, statusbox_w, timeout_label_w, timeout_w, + rename_label_w[4], + rename_menu_w, + rename_toggle_w, + rename_onoff_w, + rename_filt_w, + rename_patt_w, user_name_label_w = NULL, user_name_w = NULL; XmFontList fontlist; @@ -120,12 +126,15 @@ int button_flag, sys_log_fd = STDERR_FILENO; pid_t cmd_pid; char file_name_file[MAX_PATH_LENGTH], + file_name_file_copy[MAX_PATH_LENGTH], url_file_name[MAX_PATH_LENGTH], work_dir[MAX_PATH_LENGTH], font_name[20], *p_work_dir; struct send_data *db; const char *sys_log_name = SYSTEM_LOG_FIFO; +int no_of_rule_headers = 0; +struct rule *rule = NULL; /* Local function prototypes. */ static void init_xsend_file(int *, char **, char *, char *), @@ -140,6 +149,10 @@ static void init_xsend_file(int *, char **, char *, char *), int main(int argc, char *argv[]) { + long i; + unsigned int glyph_height, + screen_height; + XFontStruct *font_struct; char window_title[40]; static String fallback_res[] = { @@ -157,6 +170,7 @@ main(int argc, char *argv[]) criteriabox_w, main_form_w, optionbox_w, + optionbox2_w, pane_w, radio_w, separator_w, @@ -241,6 +255,15 @@ main(int argc, char *argv[]) fontlist = XmFontListAppendEntry(NULL, entry); XmFontListEntryFree(&entry); + /* get screen and font height, then calculate size of pulldown-select. */ + if ((font_struct = XLoadQueryFont(display, font_name)) == NULL) + { + (void)fprintf(stderr, "Could not query %s font.\n", font_name); + exit(INCORRECT); + } + screen_height = DisplayHeight(display, DefaultScreen(display)); + glyph_height = font_struct->ascent + font_struct->descent; + /*---------------------------------------------------------------*/ /* Button Box */ /*---------------------------------------------------------------*/ @@ -518,6 +541,7 @@ main(int argc, char *argv[]) XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, + XmNleftOffset, 3, XmNalignment, XmALIGNMENT_END, NULL); dir_subject_w = XtVaCreateManagedWidget("", @@ -611,6 +635,248 @@ main(int argc, char *argv[]) XtManageChild(optionbox_w); + /*---------------------------------------------------------------*/ + /* Horizontal Separator */ + /*---------------------------------------------------------------*/ + argcount = 0; + XtSetArg(args[argcount], XmNorientation, XmHORIZONTAL); + argcount++; + XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_WIDGET); + argcount++; + XtSetArg(args[argcount], XmNtopWidget, optionbox_w); + argcount++; + XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_FORM); + argcount++; + XtSetArg(args[argcount], XmNrightAttachment, XmATTACH_FORM); + argcount++; + separator_w = XmCreateSeparator(criteriabox_w, "separator", args, argcount); + XtManageChild(separator_w); + + optionbox_w = XtVaCreateManagedWidget("optionbox4", + xmFormWidgetClass, criteriabox_w, + XmNtopAttachment, XmATTACH_WIDGET, + XmNtopWidget, separator_w, + XmNleftAttachment, XmATTACH_FORM, + XmNrightAttachment, XmATTACH_FORM, + NULL); + + /* Label Rename. */ + rename_label_w[0] = XtVaCreateManagedWidget("Rename :", + xmLabelGadgetClass, optionbox_w, + XmNfontList, fontlist, + XmNtopAttachment, XmATTACH_FORM, + XmNbottomAttachment, XmATTACH_FORM, + XmNleftAttachment, XmATTACH_FORM, + XmNleftOffset, 3, + XmNalignment, XmALIGNMENT_END, + NULL); + XtManageChild(rename_label_w[0]); + + /* Toggle box for enabling rename. */ + rename_onoff_w = XtVaCreateWidget("rename_onoff_box", + xmRowColumnWidgetClass, optionbox_w, + XmNorientation, XmHORIZONTAL, + XmNpacking, XmPACK_TIGHT, + XmNnumColumns, 1, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, rename_label_w[0], + XmNresizable, False, + NULL); + button_w = XtVaCreateManagedWidget("Off", + xmToggleButtonGadgetClass, rename_onoff_w, + XmNfontList, fontlist, + XmNset, False, + NULL); + XtAddCallback(button_w, XmNvalueChangedCallback, + (XtCallbackProc)rename_onoff, NULL); + XtManageChild(rename_onoff_w); + + /* Decide if there are too many rules to display */ + if (no_of_rule_headers < ((screen_height / (glyph_height + 8)))) + { + /* + * display of pulldown menu is possible ... + */ + rename_label_w[3] = NULL; + /* Dropdown-box selecting rename-rule. */ + argcount = 0; + XtSetArg(args[argcount], XmNfontList, fontlist); + argcount++; + pane_w = XmCreatePulldownMenu(optionbox_w, "pane", args, argcount); + + argcount = 0; + XtSetArg(args[argcount], XmNsubMenuId, pane_w); + argcount++; + XtSetArg(args[argcount], XmNleftAttachment, XmATTACH_WIDGET); + argcount++; + XtSetArg(args[argcount], XmNleftWidget, rename_onoff_w); + argcount++; + XtSetArg(args[argcount], XmNtopAttachment, XmATTACH_FORM); + argcount++; + XtSetArg(args[argcount], XmNtopOffset, -2); + argcount++; + rename_menu_w = XmCreateOptionMenu(optionbox_w, "rename_selection", + args, argcount); + XtManageChild(rename_menu_w); + + argcount = 0; + XtSetArg(args[argcount], XmNfontList, fontlist); + argcount++; + XtSetValues(XmOptionLabelGadget(rename_menu_w), args, argcount); + + /* Add all possible buttons. */ + argcount = 0; + XtSetArg(args[argcount], XmNfontList, fontlist); + argcount++; + for (i=0;irename_num = 0; + } + else + { + /* + * too many rules for acceptable pulldown menu, so create a text-box ... + */ + rename_label_w[3] = XtVaCreateManagedWidget("Rule-name:", + xmLabelGadgetClass, optionbox_w, + XmNfontList, fontlist, + XmNtopAttachment, XmATTACH_FORM, + XmNbottomAttachment, XmATTACH_FORM, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, rename_onoff_w, + XmNalignment, XmALIGNMENT_END, + NULL); + XtManageChild(rename_label_w[3]); + rename_menu_w = XtVaCreateManagedWidget("rename_name", + xmTextWidgetClass, optionbox_w, + XmNfontList, fontlist, + XmNmarginHeight, 1, + XmNmarginWidth, 1, + XmNshadowThickness, 1, + XmNtopAttachment, XmATTACH_FORM, + XmNtopOffset, 6, + XmNbottomAttachment, XmATTACH_FORM, + XmNbottomOffset, 6, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, rename_label_w[3], + XmNrows, 1, + XmNcolumns, 20, + XmNmaxLength, MAX_RULE_HEADER_LENGTH -1, + NULL); + XtAddCallback(rename_menu_w, XmNlosingFocusCallback, send_save_input, + (XtPointer)RENAME_RULE_NO_ENTER); + XtAddCallback(rename_menu_w, XmNactivateCallback, send_save_input, + (XtPointer)RENAME_RULE_ENTER); + XtManageChild(rename_menu_w); + } + + /* Toggle box for rename by rule or manual entry. */ + rename_toggle_w = XtVaCreateWidget("rename_togglebox", + xmRowColumnWidgetClass, optionbox_w, + XmNorientation, XmHORIZONTAL, + XmNpacking, XmPACK_TIGHT, + XmNnumColumns, 1, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, rename_menu_w, + XmNresizable, False, + NULL); + button_w = XtVaCreateManagedWidget("Rule ", + xmToggleButtonGadgetClass, rename_toggle_w, + XmNfontList, fontlist, + XmNset, False, + NULL); + XtAddCallback(button_w, XmNvalueChangedCallback, + (XtCallbackProc)rename_toggle, NULL); + XtManageChild(rename_toggle_w); + + optionbox2_w = optionbox_w; + /* text fields for rename filter and pattern. */ + optionbox_w = XtVaCreateManagedWidget("optionbox5", + xmFormWidgetClass, criteriabox_w, + XmNtopAttachment, XmATTACH_WIDGET, + XmNtopWidget, optionbox2_w, + XmNleftAttachment, XmATTACH_FORM, + XmNrightAttachment, XmATTACH_FORM, + NULL); + + rename_label_w[1] = XtVaCreateManagedWidget("Filter:", + xmLabelGadgetClass, optionbox_w, + XmNfontList, fontlist, + XmNtopAttachment, XmATTACH_FORM, + XmNbottomAttachment, XmATTACH_FORM, + XmNbottomOffset, 6, + XmNleftAttachment, XmATTACH_FORM, + XmNleftOffset, 3, + XmNalignment, XmALIGNMENT_END, + NULL); + XtManageChild(rename_label_w[1]); + rename_filt_w = XtVaCreateManagedWidget("rename_filter", + xmTextWidgetClass, optionbox_w, + XmNfontList, fontlist, + XmNmarginHeight, 1, + XmNmarginWidth, 1, + XmNshadowThickness, 1, + XmNtopAttachment, XmATTACH_FORM, + XmNbottomAttachment, XmATTACH_FORM, + XmNbottomOffset, 6, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, rename_label_w[1], + XmNcolumns, 40, + XmNmaxLength, MAX_FILENAME_LENGTH - 1, + NULL); + XtAddCallback(rename_filt_w, XmNlosingFocusCallback, send_save_input, + (XtPointer)RENAME_FILT_NO_ENTER); + XtAddCallback(rename_filt_w, XmNactivateCallback, send_save_input, + (XtPointer)RENAME_FILT_ENTER); + XtManageChild(rename_filt_w); + + rename_label_w[2] = XtVaCreateManagedWidget("Pattern:", + xmLabelGadgetClass, optionbox_w, + XmNfontList, fontlist, + XmNtopAttachment, XmATTACH_FORM, + XmNbottomAttachment, XmATTACH_FORM, + XmNbottomOffset, 6, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftOffset, 6, + XmNleftWidget, rename_filt_w, + XmNalignment, XmALIGNMENT_END, + NULL); + XtManageChild(rename_label_w[2]); + rename_patt_w = XtVaCreateManagedWidget("rename_pattern", + xmTextWidgetClass, optionbox_w, + XmNfontList, fontlist, + XmNmarginHeight, 1, + XmNmarginWidth, 1, + XmNshadowThickness, 1, + XmNtopAttachment, XmATTACH_FORM, + XmNbottomAttachment, XmATTACH_FORM, + XmNbottomOffset, 6, + XmNleftAttachment, XmATTACH_WIDGET, + XmNleftWidget, rename_label_w[2], + XmNcolumns, 40, + XmNmaxLength, MAX_FILENAME_LENGTH - 1, + NULL); + XtAddCallback(rename_patt_w, XmNlosingFocusCallback, send_save_input, + (XtPointer)RENAME_PATT_NO_ENTER); + XtAddCallback(rename_patt_w, XmNactivateCallback, send_save_input, + (XtPointer)RENAME_PATT_ENTER); + XtManageChild(rename_patt_w); + + if (db->protocol != FTP) + { + db->rename_do = OFF; + _set_rename_boxies(OFF); + } + else + { + db->rename_do = SET_RENAME_RULE; + _set_rename_boxies(ON); + } + + /*---------------------------------------------------------------*/ /* Horizontal Separator */ /*---------------------------------------------------------------*/ @@ -1108,6 +1374,7 @@ init_xsend_file(int *argc, char *title_name, char *file_name_file) { + int i; if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS)) @@ -1133,6 +1400,7 @@ init_xsend_file(int *argc, } (void)my_strncpy(file_name_file, argv[1], MAX_PATH_LENGTH); url_file_name[0] = '\0'; + file_name_file_copy[0] = '\0'; /* Prepare title for window. */ (void)strcpy(title_name, "xsend_file "); @@ -1149,6 +1417,12 @@ init_xsend_file(int *argc, } memset(db, 0, sizeof(struct send_data)); + /* load rename.rule */ + if (rule == NULL) + { + get_rename_rules(NO); + } + /* Now set some default values. */ button_flag = SEND_BUTTON; db->protocol = FTP; @@ -1182,6 +1456,9 @@ init_xsend_file(int *argc, db->port = -1; } #endif + db->rename_num = INCORRECT; + db->rename_filt[0] = '\0'; + db->rename_patt[0] = '\0'; return; } @@ -1216,6 +1493,10 @@ xsend_file_exit(void) } } (void)unlink(file_name_file); + if (file_name_file_copy[0] != '\0') + { + (void)unlink(file_name_file_copy); + } if (url_file_name[0] != '\0') { (void)unlink(url_file_name); @@ -1229,7 +1510,7 @@ static void sig_segv(int signo) { (void)fprintf(stderr, "Aaarrrggh! Received SIGSEGV. (%s %d)\n", - __FILE__, __LINE__); + __FILE__, __LINE__); abort(); } @@ -1237,7 +1518,7 @@ sig_segv(int signo) /*++++++++++++++++++++++++++++++ sig_bus() ++++++++++++++++++++++++++++++*/ static void sig_bus(int signo) -{ +{ (void)fprintf(stderr, "Uuurrrggh! Received SIGBUS. (%s %d)\n", __FILE__, __LINE__); abort(); diff --git a/src/UI/Motif/xsend_file/xsend_file.h b/src/UI/Motif/xsend_file/xsend_file.h index b3649c21..caaf5a64 100644 --- a/src/UI/Motif/xsend_file/xsend_file.h +++ b/src/UI/Motif/xsend_file/xsend_file.h @@ -48,6 +48,12 @@ #define PREFIX_ENTER 33 #define PROXY_NO_ENTER 34 #define PROXY_ENTER 35 +#define RENAME_RULE_NO_ENTER 36 +#define RENAME_RULE_ENTER 37 +#define RENAME_FILT_NO_ENTER 38 +#define RENAME_FILT_ENTER 39 +#define RENAME_PATT_NO_ENTER 40 +#define RENAME_PATT_ENTER 41 #define CREATE_DIR_TOGGLE 0 #define ATTACH_FILE_TOGGLE 1 @@ -121,6 +127,10 @@ (XtPointer)PASSWORD_ENTER); \ } +#define SET_RENAME_ON 1 +#define SET_RENAME_RULE 2 +#define SET_RENAME_MANUAL 4 + /* Structure holding all data of for sending files. */ struct send_data { @@ -137,6 +147,10 @@ struct send_data XT_PTR_TYPE lock; /* DOT, DOT_VMS, OFF, etc. */ XT_PTR_TYPE transfer_mode; XT_PTR_TYPE protocol; + XT_PTR_TYPE rename_do; + int rename_num; + char rename_filt[MAX_FILENAME_LENGTH]; + char rename_patt[MAX_FILENAME_LENGTH]; int port; int debug; time_t timeout; @@ -156,6 +170,77 @@ extern void close_button(Widget, XtPointer, XtPointer), protocol_toggled(Widget, XtPointer, XtPointer), send_button(Widget, XtPointer, XtPointer), send_file(void), - send_save_input(Widget, XtPointer, XtPointer); + send_save_input(Widget, XtPointer, XtPointer), + rename_onoff(Widget, XtPointer, XtPointer), + rename_toggle(Widget, XtPointer, XtPointer), + rename_eval(Widget, XtPointer, XtPointer); +extern int rr_file_name_file(struct rule*, int, char*, char*); + +#define _set_rename_boxies(what) if ((what) == OFF)\ + {\ + if ((db->protocol != FTP)\ + && (db->protocol != LOC))\ + {\ + XtSetSensitive(rename_label_w[0], False);\ + XtSetSensitive(rename_onoff_w, False);\ + }\ + XtSetSensitive(rename_toggle_w, False);\ + if (rename_label_w[3])\ + {\ + XtSetSensitive(rename_label_w[3], False);\ + }\ + XtSetSensitive(rename_menu_w, False);\ + XtSetSensitive(rename_label_w[1], False);\ + XtSetSensitive(rename_label_w[2], False);\ + XtSetSensitive(rename_filt_w, False);\ + XtSetSensitive(rename_patt_w, False);\ + }\ + else\ + {\ + XtSetSensitive(rename_label_w[0], True);\ + XtSetSensitive(rename_onoff_w, True);\ + if (db->rename_do & SET_RENAME_ON)\ + {\ + XtSetSensitive(rename_toggle_w, True);\ + if (db->rename_do & SET_RENAME_MANUAL)\ + {\ + if (rename_label_w[3])\ + {\ + XtSetSensitive(rename_label_w[3], False);\ + }\ + XtSetSensitive(rename_menu_w, False);\ + XtSetSensitive(rename_label_w[1], True);\ + XtSetSensitive(rename_label_w[2], True);\ + XtSetSensitive(rename_filt_w, True);\ + XtSetSensitive(rename_patt_w, True);\ + }\ + else\ + {\ + if (rename_label_w[3])\ + {\ + XtSetSensitive(rename_label_w[3], True);\ + }\ + XtSetSensitive(rename_menu_w, True);\ + XtSetSensitive(rename_label_w[1], False);\ + XtSetSensitive(rename_label_w[2], False);\ + XtSetSensitive(rename_filt_w, False);\ + XtSetSensitive(rename_patt_w, False);\ + }\ + }\ + else\ + {\ + XtSetSensitive(rename_toggle_w, False);\ + if (rename_label_w[3])\ + {\ + XtSetSensitive(rename_label_w[3], False);\ + }\ + XtSetSensitive(rename_menu_w, False);\ + XtSetSensitive(rename_label_w[1], False);\ + XtSetSensitive(rename_label_w[2], False);\ + XtSetSensitive(rename_filt_w, False);\ + XtSetSensitive(rename_patt_w, False);\ + }\ + }\ +/* END define _set_rename_boxies */ #endif /* __xsend_file_h */