# HG changeset patch # User masneyb # Date 1074728140 0 # Node ID d207b8241e968eed4cd9d4ecb8297a242245b51d # Parent 642bc7a87f05327beb7d34411d927f8a917d4e93 2003-1-21 Brian Masney * lib/config_file.c lib/gftp.h - set the character string arguments to const for the following functions: gftp_lookup_global_option(), gftp_lookup_request_option(), gftp_lookup_bookmark_option(), gftp_set_global_option(), gftp_set_request_option(), gftp_set_bookmark_option() * lib/misc.c lib/gftp.h - set the character string arguments to const for the function gftp_match_filespec() * src/gtk/gftp-gtk.c src/gtk/menu-items.c src/uicommon/gftpui.c - moved more UI independant parts to the uicommon directory. Moved some GUI specific functionality into gftp-gtk.c * src/text/gftp-text.c src/gtk/gftp-gtk.c src/uicommon/gftpui.c - pass the local/remote uidata/request structures to process_command(). Removed old function gftpui_common_init(). Added new gftpui_common_init() that sets up common functionality for a port. * src/gtk/gtkui.c src/gtk/gtkui_transfer.c - moved gftpui_add_file_to_transfer() to gtkui_transfer.c * src/gtk/gtkui_transfer.c - cleaned up these functions some and made them more modular * src/uicommon/gftpui.c src/uicommon/gftpui.h - for all of the command line functions, make the command argument a constant diff -r 642bc7a87f05 -r d207b8241e96 ChangeLog --- a/ChangeLog Wed Jan 21 16:46:01 2004 +0000 +++ b/ChangeLog Wed Jan 21 23:35:40 2004 +0000 @@ -1,3 +1,31 @@ +2003-1-21 Brian Masney + * lib/config_file.c lib/gftp.h - set the character string arguments to + const for the following functions: gftp_lookup_global_option(), + gftp_lookup_request_option(), gftp_lookup_bookmark_option(), + gftp_set_global_option(), gftp_set_request_option(), + gftp_set_bookmark_option() + + * lib/misc.c lib/gftp.h - set the character string arguments to const + for the function gftp_match_filespec() + + * src/gtk/gftp-gtk.c src/gtk/menu-items.c src/uicommon/gftpui.c - moved + more UI independant parts to the uicommon directory. Moved some GUI + specific functionality into gftp-gtk.c + + * src/text/gftp-text.c src/gtk/gftp-gtk.c src/uicommon/gftpui.c - pass + the local/remote uidata/request structures to process_command(). Removed + old function gftpui_common_init(). Added new gftpui_common_init() that + sets up common functionality for a port. + + * src/gtk/gtkui.c src/gtk/gtkui_transfer.c - moved + gftpui_add_file_to_transfer() to gtkui_transfer.c + + * src/gtk/gtkui_transfer.c - cleaned up these functions some and made + them more modular + + * src/uicommon/gftpui.c src/uicommon/gftpui.h - for all of the command + line functions, make the command argument a constant + 2003-1-18 Brian Masney * lib/misc.c lib/protocols.c lib/rfc2068.c lib/rfc959.c - if _LARGEFILE_SOURCE is defined, explicitly cast the file sizes to @@ -2029,7 +2057,7 @@ * cvsclean - added this script - * *.[ch] - added $Id: ChangeLog,v 1.206 2004/01/19 22:22:51 masneyb Exp $ tags + * *.[ch] - added $Id: ChangeLog,v 1.207 2004/01/21 23:35:30 masneyb Exp $ tags * debian/* - updated files from Debian maintainer diff -r 642bc7a87f05 -r d207b8241e96 lib/config_file.c --- a/lib/config_file.c Wed Jan 21 16:46:01 2004 +0000 +++ b/lib/config_file.c Wed Jan 21 23:35:40 2004 +0000 @@ -1249,7 +1249,7 @@ void -gftp_lookup_global_option (char * key, void *value) +gftp_lookup_global_option (const char * key, void *value) { gftp_config_list_vars * tmplistvar; gftp_config_vars * tmpconfigvar; @@ -1270,7 +1270,8 @@ void -gftp_lookup_request_option (gftp_request * request, char * key, void *value) +gftp_lookup_request_option (gftp_request * request, const char * key, + void *value) { gftp_config_vars * tmpconfigvar; @@ -1284,7 +1285,8 @@ void -gftp_lookup_bookmark_option (gftp_bookmarks_var * bm, char * key, void *value) +gftp_lookup_bookmark_option (gftp_bookmarks_var * bm, const char * key, + void *value) { gftp_config_vars * tmpconfigvar; @@ -1298,7 +1300,7 @@ void -gftp_set_global_option (char * key, const void *value) +gftp_set_global_option (const char * key, const void *value) { gftp_config_vars * tmpconfigvar, newconfigvar; void *nc_ptr; @@ -1348,7 +1350,8 @@ void -gftp_set_request_option (gftp_request * request, char * key, const void *value) +gftp_set_request_option (gftp_request * request, const char * key, + const void *value) { gftp_config_vars * tmpconfigvar; @@ -1382,7 +1385,8 @@ void -gftp_set_bookmark_option (gftp_bookmarks_var * bm, char * key, const void *value) +gftp_set_bookmark_option (gftp_bookmarks_var * bm, const char * key, + const void *value) { gftp_config_vars * tmpconfigvar, newconfigvar; int ret; diff -r 642bc7a87f05 -r d207b8241e96 lib/gftp.h --- a/lib/gftp.h Wed Jan 21 16:46:01 2004 +0000 +++ b/lib/gftp.h Wed Jan 21 23:35:40 2004 +0000 @@ -629,26 +629,26 @@ void print_bookmarks ( gftp_bookmarks_var * bookmarks ); -void gftp_lookup_global_option ( char * key, +void gftp_lookup_global_option ( const char * key, void *value ); void gftp_lookup_request_option ( gftp_request * request, - char * key, + const char * key, void *value ); void gftp_lookup_bookmark_option ( gftp_bookmarks_var * bm, - char * key, + const char * key, void *value ); -void gftp_set_global_option ( char * key, +void gftp_set_global_option ( const char * key, const void *value ); void gftp_set_request_option ( gftp_request * request, - char * key, + const char * key, const void *value ); void gftp_set_bookmark_option ( gftp_bookmarks_var * bm, - char * key, + const char * key, const void *value ); void gftp_register_config_vars ( gftp_config_vars *config_vars ); @@ -679,8 +679,8 @@ void make_nonnull ( char **str ); -int gftp_match_filespec ( char *filename, - char *filespec ); +int gftp_match_filespec ( const char *filename, + const char *filespec ); int gftp_parse_command_line ( int *argc, char ***argv ); diff -r 642bc7a87f05 -r d207b8241e96 lib/misc.c --- a/lib/misc.c Wed Jan 21 16:46:01 2004 +0000 +++ b/lib/misc.c Wed Jan 21 23:35:40 2004 +0000 @@ -262,9 +262,10 @@ /* FIXME - is there a replacement for this */ int -gftp_match_filespec (char *filename, char *filespec) +gftp_match_filespec (const char *filename, const char *filespec) { - char *filepos, *wcpos, *pos, *newpos, search_str[20]; + const char *filepos, *wcpos, *pos; + char search_str[20], *newpos; size_t len, curlen; if (filename == NULL || *filename == '\0' || diff -r 642bc7a87f05 -r d207b8241e96 src/gtk/gftp-gtk.c --- a/src/gtk/gftp-gtk.c Wed Jan 21 16:46:01 2004 +0000 +++ b/src/gtk/gftp-gtk.c Wed Jan 21 23:35:40 2004 +0000 @@ -124,13 +124,6 @@ } -static RETSIGTYPE -sig_child (int signo) -{ - viewedit_process_done = 1; -} - - static void menu_exit (GtkWidget * widget, gpointer data) { @@ -139,6 +132,81 @@ } +static void +change_setting (gftp_window_data * wdata, int menuitem, GtkWidget * checkmenu) +{ + switch (menuitem) + { + case 1: + gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1)); + break; + case 2: + gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0)); + break; + case 3: + current_wdata = &window1; + other_wdata = &window2; + if (wdata->request) + update_window_info (); + break; + case 4: + current_wdata = &window2; + other_wdata = &window1; + if (wdata->request) + update_window_info (); + break; + } +} + + +static void +_gftpui_gtk_do_openurl (gftp_window_data * wdata, gftp_dialog_data * ddata) +{ + const char *str; + + str = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); + if (str != NULL && *str != '\0') + gftpui_common_cmd_open (wdata, wdata->request, str); +} + + +static void +openurl_dialog (gpointer data) +{ + gftp_window_data * wdata; + + wdata = data; + MakeEditDialog (_("Connect via URL"), _("Enter a URL to connect to"), + NULL, 1, NULL, gftp_dialog_button_connect, + _gftpui_gtk_do_openurl, wdata, + NULL, NULL); +} + + +static void +tb_openurl_dialog (gpointer data) +{ + const char *edttxt; + + if (current_wdata->request->stopable) + { + ftp_log (gftp_logging_misc, NULL, + _("%s: Please hit the stop button first to do anything else\n"), + _("OpenURL")); + return; + } + + edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); + + if (GFTP_IS_CONNECTED (current_wdata->request)) + disconnect (current_wdata); + else if (edttxt != NULL && *edttxt != '\0') + toolbar_hostedit (NULL, NULL); + else + openurl_dialog (current_wdata); +} + + static GtkWidget * CreateMenus (GtkWidget * parent) { @@ -1137,18 +1205,15 @@ char *startup_directory; GtkWidget *window, *ui; - gftp_locale_init (); + gftpui_common_init (&argc, &argv, ftp_log); + g_thread_init (NULL); main_thread_id = pthread_self (); gtk_set_locale (); gtk_init (&argc, &argv); - signal (SIGCHLD, sig_child); - signal (SIGPIPE, SIG_IGN); - signal (SIGALRM, gftpui_common_signal_handler); - signal (SIGINT, gftpui_common_signal_handler); - - graphic_hash_table = g_hash_table_new (string_hash_function, string_hash_compare); + graphic_hash_table = g_hash_table_new (string_hash_function, + string_hash_compare); /* We override the read color functions because we are using a GdkColor structures to store the color. If I put this in lib/config_file.c, then @@ -1156,10 +1221,6 @@ gftp_option_types[gftp_option_type_color].read_function = gftp_gtk_config_file_read_color; gftp_option_types[gftp_option_type_color].write_function = gftp_gtk_config_file_write_color; - gftp_read_config_file (SHARE_DIR); - if (gftp_parse_command_line (&argc, &argv) != 0) - exit (0); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL); @@ -1204,16 +1265,15 @@ sortrows (GTK_CLIST (window2.listbox), -1, &window2); init_gftp (argc, argv, window); - gftpui_common_init (&window1, window1.request, - &window2, window2.request); - GDK_THREADS_ENTER (); gtk_main (); GDK_THREADS_LEAVE (); + return (0); } + void gftpui_show_or_hide_command (void) { diff -r 642bc7a87f05 -r d207b8241e96 src/gtk/gftp-gtk.h --- a/src/gtk/gftp-gtk.h Wed Jan 21 16:46:01 2004 +0000 +++ b/src/gtk/gftp-gtk.h Wed Jan 21 23:35:40 2004 +0000 @@ -265,14 +265,6 @@ void gftpui_chdir_dialog ( gpointer data ); /* menu_items.c */ -void change_setting ( gftp_window_data *wdata, - int menuitem, - GtkWidget * checkmenu ); - -void tb_openurl_dialog ( gpointer data ); - -void openurl_dialog ( gpointer data ); - void disconnect ( gpointer data ); void change_filespec ( gpointer data ); diff -r 642bc7a87f05 -r d207b8241e96 src/gtk/gtkui.c --- a/src/gtk/gtkui.c Wed Jan 21 16:46:01 2004 +0000 +++ b/src/gtk/gtkui.c Wed Jan 21 23:35:40 2004 +0000 @@ -36,7 +36,8 @@ const char *txt; txt = gtk_entry_get_text (GTK_ENTRY (gftpui_command_widget)); - gftpui_common_process_command (txt); + gftpui_common_process_command (&window1, window1.request, + &window2, window2.request, txt); gtk_entry_set_text (GTK_ENTRY (gftpui_command_widget), ""); } @@ -248,33 +249,6 @@ } -void -gftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle, - char *filepos) -{ - gftpui_common_curtrans_data * transdata; - gftp_file * fle; - char *text[2]; - - fle = curfle->data; - text[0] = filepos; - if (fle->transfer_action == GFTP_TRANS_ACTION_SKIP) - text[1] = _("Skipped"); - else - text[1] = _("Waiting..."); - - fle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), - tdata->user_data, NULL, text, 5, - NULL, NULL, NULL, NULL, - FALSE, FALSE); - transdata = g_malloc (sizeof (*transdata)); - transdata->transfer = tdata; - transdata->curfle = curfle; - - gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), fle->user_data, transdata); -} - - int gftpui_check_reconnect (gftpui_callback_data * cdata) { diff -r 642bc7a87f05 -r d207b8241e96 src/gtk/gtkui_transfer.c --- a/src/gtk/gtkui_transfer.c Wed Jan 21 16:46:01 2004 +0000 +++ b/src/gtk/gtkui_transfer.c Wed Jan 21 23:35:40 2004 +0000 @@ -20,8 +20,36 @@ #include "gftp-gtk.h" static const char cvsid[] = "$Id$"; + +void +gftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle, + char *filepos) +{ + gftpui_common_curtrans_data * transdata; + gftp_file * fle; + char *text[2]; + + fle = curfle->data; + text[0] = filepos; + if (fle->transfer_action == GFTP_TRANS_ACTION_SKIP) + text[1] = _("Skipped"); + else + text[1] = _("Waiting..."); + + fle->user_data = gtk_ctree_insert_node (GTK_CTREE (dlwdw), + tdata->user_data, NULL, text, 5, + NULL, NULL, NULL, NULL, + FALSE, FALSE); + transdata = g_malloc (sizeof (*transdata)); + transdata->transfer = tdata; + transdata->curfle = curfle; + + gtk_ctree_node_set_row_data (GTK_CTREE (dlwdw), fle->user_data, transdata); +} + + static void -trans_selectall (GtkWidget * widget, gpointer data) +gftpui_gtk_trans_selectall (GtkWidget * widget, gpointer data) { gftp_transfer * tdata; tdata = data; @@ -31,7 +59,7 @@ static void -trans_unselectall (GtkWidget * widget, gpointer data) +gftpui_gtk_trans_unselectall (GtkWidget * widget, gpointer data) { gftp_transfer * tdata; tdata = data; @@ -41,14 +69,15 @@ static void -overwrite (GtkWidget * widget, gpointer data) +gftpui_gtk_set_action (gftp_transfer * tdata, char * transfer_str, + int transfer_action) { GList * templist, * filelist; - gftp_transfer * tdata; gftp_file * tempfle; int curpos; - tdata = data; + g_static_mutex_lock (&tdata->structmutex); + curpos = 0; filelist = tdata->files; templist = GTK_CLIST (tdata->clist)->selection; @@ -56,58 +85,37 @@ { templist = get_next_selection (templist, &filelist, &curpos); tempfle = filelist->data; - tempfle->transfer_action = GFTP_TRANS_ACTION_OVERWRITE; - gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Overwrite")); + tempfle->transfer_action = transfer_action; + gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, transfer_str); } + + g_static_mutex_unlock (&tdata->structmutex); +} + + +static void +gftpui_gtk_overwrite (GtkWidget * widget, gpointer data) +{ + gftpui_gtk_set_action (data, _("Overwrite"), GFTP_TRANS_ACTION_OVERWRITE); } static void -resume (GtkWidget * widget, gpointer data) +gftpui_gtk_resume (GtkWidget * widget, gpointer data) { - GList * templist, * filelist; - gftp_transfer * tdata; - gftp_file * tempfle; - int curpos; - - tdata = data; - curpos = 0; - filelist = tdata->files; - templist = GTK_CLIST (tdata->clist)->selection; - while (templist != NULL) - { - templist = get_next_selection (templist, &filelist, &curpos); - tempfle = filelist->data; - tempfle->transfer_action = GFTP_TRANS_ACTION_RESUME; - gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Resume")); - } + gftpui_gtk_set_action (data, _("Resume"), GFTP_TRANS_ACTION_RESUME); } static void -skip (GtkWidget * widget, gpointer data) +gftpui_gtk_skip (GtkWidget * widget, gpointer data) { - GList * templist, * filelist; - gftp_transfer * tdata; - gftp_file * tempfle; - int curpos; - - tdata = data; - curpos = 0; - filelist = tdata->files; - templist = GTK_CLIST (tdata->clist)->selection; - while (templist != NULL) - { - templist = get_next_selection (templist, &filelist, &curpos); - tempfle = filelist->data; - tempfle->transfer_action = GFTP_TRANS_ACTION_SKIP; - gtk_clist_set_text (GTK_CLIST (tdata->clist), curpos, 3, _("Skip")); - } + gftpui_gtk_set_action (data, _("Skip"), GFTP_TRANS_ACTION_SKIP); } static void -ok (GtkWidget * widget, gpointer data) +gftpui_gtk_ok (GtkWidget * widget, gpointer data) { gftp_transfer * tdata; gftp_file * tempfle; @@ -122,19 +130,21 @@ break; } + tdata->ready = 1; if (templist == NULL) { tdata->show = 0; - tdata->ready = tdata->done = 1; + tdata->done = 1; } else - tdata->show = tdata->ready = 1; + tdata->show = 1; + g_static_mutex_unlock (&tdata->structmutex); } static void -cancel (GtkWidget * widget, gpointer data) +gftpui_gtk_cancel (GtkWidget * widget, gpointer data) { gftp_transfer * tdata; @@ -148,16 +158,17 @@ #if GTK_MAJOR_VERSION > 1 static void -transfer_action (GtkWidget * widget, gint response, gpointer user_data) +gftpui_gtk_transfer_action (GtkWidget * widget, gint response, + gpointer user_data) { switch (response) { case GTK_RESPONSE_OK: - ok (widget, user_data); + gftpui_gtk_ok (widget, user_data); gtk_widget_destroy (widget); break; case GTK_RESPONSE_CANCEL: - cancel (widget, user_data); + gftpui_gtk_cancel (widget, user_data); /* no break */ default: gtk_widget_destroy (widget); @@ -298,19 +309,19 @@ tempwid = gtk_button_new_with_label (_("Overwrite")); gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", - GTK_SIGNAL_FUNC (overwrite), (gpointer) tdata); + GTK_SIGNAL_FUNC (gftpui_gtk_overwrite), (gpointer) tdata); gtk_widget_show (tempwid); tempwid = gtk_button_new_with_label (_("Resume")); gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", - GTK_SIGNAL_FUNC (resume), (gpointer) tdata); + GTK_SIGNAL_FUNC (gftpui_gtk_resume), (gpointer) tdata); gtk_widget_show (tempwid); tempwid = gtk_button_new_with_label (_("Skip File")); gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); - gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (skip), - (gpointer) tdata); + gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", + GTK_SIGNAL_FUNC (gftpui_gtk_skip), (gpointer) tdata); gtk_widget_show (tempwid); hbox = gtk_hbox_new (TRUE, 20); @@ -320,13 +331,13 @@ tempwid = gtk_button_new_with_label (_("Select All")); gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", - GTK_SIGNAL_FUNC (trans_selectall), (gpointer) tdata); + GTK_SIGNAL_FUNC (gftpui_gtk_trans_selectall), (gpointer) tdata); gtk_widget_show (tempwid); tempwid = gtk_button_new_with_label (_("Deselect All")); gtk_box_pack_start (GTK_BOX (hbox), tempwid, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", - GTK_SIGNAL_FUNC (trans_unselectall), (gpointer) tdata); + GTK_SIGNAL_FUNC (gftpui_gtk_trans_unselectall), (gpointer) tdata); gtk_widget_show (tempwid); #if GTK_MAJOR_VERSION == 1 @@ -334,8 +345,8 @@ GTK_WIDGET_SET_FLAGS (tempwid, GTK_CAN_DEFAULT); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, TRUE, TRUE, 0); - gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (ok), - (gpointer) tdata); + gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", + GTK_SIGNAL_FUNC (gftpui_gtk_ok), (gpointer) tdata); gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (dialog)); @@ -347,14 +358,14 @@ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), tempwid, TRUE, TRUE, 0); gtk_signal_connect (GTK_OBJECT (tempwid), "clicked", - GTK_SIGNAL_FUNC (cancel), (gpointer) tdata); + GTK_SIGNAL_FUNC (gftpui_gtk_cancel), (gpointer) tdata); gtk_signal_connect_object (GTK_OBJECT (tempwid), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (dialog)); gtk_widget_show (tempwid); #else g_signal_connect (GTK_OBJECT (dialog), "response", - G_CALLBACK (transfer_action), (gpointer) tdata); + G_CALLBACK (gftpui_gtk_transfer_action),(gpointer) tdata); #endif gtk_widget_show (dialog); diff -r 642bc7a87f05 -r d207b8241e96 src/gtk/menu-items.c --- a/src/gtk/menu-items.c Wed Jan 21 16:46:01 2004 +0000 +++ b/src/gtk/menu-items.c Wed Jan 21 23:35:40 2004 +0000 @@ -20,108 +20,6 @@ #include static const char cvsid[] = "$Id$"; -void -change_setting (gftp_window_data * wdata, int menuitem, GtkWidget * checkmenu) -{ - switch (menuitem) - { - case 1: - gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1)); - break; - case 2: - gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0)); - break; - case 3: - current_wdata = &window1; - other_wdata = &window2; - if (wdata->request) - update_window_info (); - break; - case 4: - current_wdata = &window2; - other_wdata = &window1; - if (wdata->request) - update_window_info (); - break; - } -} - - -void -tb_openurl_dialog (gpointer data) -{ - const char *edttxt; - - if (current_wdata->request->stopable) - { - ftp_log (gftp_logging_misc, NULL, - _("%s: Please hit the stop button first to do anything else\n"), - _("OpenURL")); - return; - } - - edttxt = gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (hostedit)->entry)); - if (*edttxt == '\0') - { - ftp_log (gftp_logging_misc, NULL, - _("OpenURL: Operation canceled...you must enter a string\n")); - return; - } - - if (GFTP_IS_CONNECTED (current_wdata->request)) - disconnect (current_wdata); - else if (edttxt != NULL && *edttxt != '\0') - toolbar_hostedit (NULL, NULL); - else - openurl_dialog (current_wdata); -} - - -static void -do_openurl (gftp_window_data * wdata, gftp_dialog_data * ddata) -{ - const char *tempstr; - - if (current_wdata->request->stopable) - { - ftp_log (gftp_logging_misc, NULL, - _("%s: Please hit the stop button first to do anything else\n"), - _("OpenURL")); - return; - } - - tempstr = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); - if (*tempstr == '\0') - { - ftp_log (gftp_logging_misc, NULL, - _("OpenURL: Operation canceled...you must enter a string\n")); - return; - } - - if (GFTP_IS_CONNECTED (wdata->request)) - disconnect (wdata); - - if (gftp_parse_url (wdata->request, tempstr) == 0) - { - gtk_widget_destroy (ddata->dialog); - ftp_connect (wdata, wdata->request, 1); - } - else - gtk_widget_destroy (ddata->dialog); - - ddata->dialog = NULL; -} - - -void -openurl_dialog (gpointer data) -{ - MakeEditDialog (_("Connect via URL"), _("Enter ftp url to connect to"), - NULL, 1, NULL, gftp_dialog_button_connect, do_openurl, data, - NULL, NULL); -} - - void disconnect (gpointer data) { diff -r 642bc7a87f05 -r d207b8241e96 src/text/gftp-text.c --- a/src/text/gftp-text.c Wed Jan 21 16:46:01 2004 +0000 +++ b/src/text/gftp-text.c Wed Jan 21 23:35:40 2004 +0000 @@ -39,12 +39,6 @@ void -sig_child (int signo) -{ -} - - -void gftp_text_log (gftp_logging_level level, gftp_request * request, const char *string, ...) { @@ -191,15 +185,7 @@ char tempstr[512]; #endif - gftp_locale_init (); - - signal (SIGCHLD, sig_child); - signal (SIGPIPE, SIG_IGN); - - gftp_read_config_file (SHARE_DIR); - - if (gftp_parse_command_line (&argc, &argv) != 0) - exit (0); + gftpui_common_init (&argc, &argv, gftp_text_log); /* SSH doesn't support reading the password with askpass via the command line */ @@ -248,14 +234,12 @@ gftp_text_open (gftp_text_remreq, argv[1], NULL); */ - gftpui_common_init (NULL, gftp_text_locreq, - NULL, gftp_text_remreq); - #if HAVE_LIBREADLINE g_snprintf (prompt, sizeof (prompt), "%sftp%s> ", GFTPUI_COMMON_COLOR_BLUE, GFTPUI_COMMON_COLOR_DEFAULT); while ((tempstr = readline (prompt))) { - if (gftpui_common_process_command (tempstr) == 0) + if (gftpui_common_process_command (NULL, gftp_text_locreq, + NULL, gftp_text_remreq, tempstr) == 0) break; add_history (tempstr); diff -r 642bc7a87f05 -r d207b8241e96 src/uicommon/gftpui.c --- a/src/uicommon/gftpui.c Wed Jan 21 16:46:01 2004 +0000 +++ b/src/uicommon/gftpui.c Wed Jan 21 23:35:40 2004 +0000 @@ -23,20 +23,9 @@ sigjmp_buf gftpui_common_jmp_environment; volatile int gftpui_common_use_jmp_environment = 0; -static void *gftpui_common_local_uidata, *gftpui_common_remote_uidata; -static gftp_request * gftpui_common_local_request, - * gftpui_common_remote_request; GStaticMutex gftpui_common_transfer_mutex = G_STATIC_MUTEX_INIT; - - -static gftp_logging_func -_gftpui_common_log (gftp_request * request) -{ - if (request == NULL) - return (gftpui_common_local_request->logging_function); - else - return (request->logging_function); -} +volatile sig_atomic_t gftpui_common_child_process_done = 0; +gftp_logging_func gftpui_common_logfunc; static void * @@ -110,7 +99,7 @@ } -RETSIGTYPE +static RETSIGTYPE gftpui_common_signal_handler (int signo) { signal (signo, gftpui_common_signal_handler); @@ -122,6 +111,31 @@ } +static RETSIGTYPE +gftpui_common_sig_child (int signo) +{ + gftpui_common_child_process_done = 1; +} + + +void +gftpui_common_init (int *argc, char ***argv, gftp_logging_func logfunc) +{ + gftp_locale_init (); + + signal (SIGCHLD, gftpui_common_sig_child); + signal (SIGPIPE, SIG_IGN); + signal (SIGALRM, gftpui_common_signal_handler); + signal (SIGINT, gftpui_common_signal_handler); + + gftp_read_config_file (SHARE_DIR); + if (gftp_parse_command_line (argc, argv) != 0) + exit (0); + + gftpui_common_logfunc = logfunc; +} + + void gftpui_common_about (gftp_logging_func logging_function, gpointer logdata) { @@ -139,16 +153,17 @@ static int -gftpui_common_cmd_about (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_about (void *uidata, gftp_request * request, + const char *command) { - gftpui_common_about (_gftpui_common_log (request), - gftpui_common_local_request); + gftpui_common_about (gftpui_common_logfunc, NULL); return (1); } static int -gftpui_common_cmd_ascii (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_ascii (void *uidata, gftp_request * request, + const char *command) { gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1)); return (1); @@ -156,7 +171,8 @@ static int -gftpui_common_cmd_binary (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_binary (void *uidata, gftp_request * request, + const char *command) { gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0)); return (1); @@ -164,7 +180,8 @@ static int -gftpui_common_cmd_chmod (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_chmod (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; char *pos; @@ -190,7 +207,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->input_string = command; + cdata->input_string = (char *) command; cdata->source_string = pos; cdata->run_function = gftpui_common_run_chmod; @@ -204,7 +221,8 @@ static int -gftpui_common_cmd_rename (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_rename (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; char *pos; @@ -229,7 +247,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->source_string = command; + cdata->source_string = (char *) command; cdata->input_string = pos; cdata->run_function = gftpui_common_run_rename; @@ -243,7 +261,8 @@ static int -gftpui_common_cmd_delete (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_delete (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; @@ -263,7 +282,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->input_string = command; + cdata->input_string = (char *) command; cdata->run_function = gftpui_common_run_delete; gftpui_common_run_callback_function (cdata); @@ -276,7 +295,8 @@ static int -gftpui_common_cmd_rmdir (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_rmdir (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; @@ -296,7 +316,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->input_string = command; + cdata->input_string = (char *) command; cdata->run_function = gftpui_common_run_rmdir; gftpui_common_run_callback_function (cdata); @@ -309,7 +329,8 @@ static int -gftpui_common_cmd_site (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_site (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; @@ -329,7 +350,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->input_string = command; + cdata->input_string = (char *) command; cdata->run_function = gftpui_common_run_site; gftpui_common_run_callback_function (cdata); @@ -342,7 +363,8 @@ static int -gftpui_common_cmd_mkdir (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_mkdir (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; @@ -362,7 +384,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->input_string = command; + cdata->input_string = (char *) command; cdata->run_function = gftpui_common_run_mkdir; gftpui_common_run_callback_function (cdata); @@ -375,7 +397,8 @@ static int -gftpui_common_cmd_chdir (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_chdir (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; char *tempstr, *newdir = NULL; @@ -414,7 +437,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->input_string = newdir != NULL ? newdir : command; + cdata->input_string = newdir != NULL ? newdir : (char *) command; cdata->run_function = gftpui_common_run_chdir; gftpui_common_run_callback_function (cdata); @@ -429,7 +452,8 @@ static int -gftpui_common_cmd_close (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_close (void *uidata, gftp_request * request, + const char *command) { gftp_disconnect (request); return (1); @@ -437,7 +461,8 @@ static int -gftpui_common_cmd_pwd (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_pwd (void *uidata, gftp_request * request, + const char *command) { if (!GFTP_IS_CONNECTED (request)) { @@ -454,7 +479,8 @@ static int -gftpui_common_cmd_quit (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_quit (void *uidata, gftp_request * request, + const char *command) { gftp_shutdown(); @@ -463,16 +489,15 @@ static int -gftpui_common_cmd_clear (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_clear (void *uidata, gftp_request * request, + const char *command) { - gftp_logging_func logfunc; - if (strcasecmp (command, "cache") == 0) gftp_clear_cache_files (); else { - logfunc = _gftpui_common_log (request); - logfunc (gftp_logging_error, request, _("Invalid argument\n")); + gftpui_common_logfunc (gftp_logging_error, request, + _("Invalid argument\n")); } return (1); @@ -480,14 +505,12 @@ static int -gftpui_common_clear_show_subhelp (char *topic) +gftpui_common_clear_show_subhelp (const char *topic) { - gftp_logging_func logfunc; - - logfunc = gftpui_common_local_request->logging_function; if (strcmp (topic, "cache") == 0) { - logfunc (gftp_logging_misc, NULL, _("Clear the directory cache\n")); + gftpui_common_logfunc (gftp_logging_misc, NULL, + _("Clear the directory cache\n")); return (1); } @@ -496,15 +519,13 @@ static int -gftpui_common_set_show_subhelp (char *topic) +gftpui_common_set_show_subhelp (const char *topic) { - gftp_logging_func logfunc; gftp_config_vars * cv; - logfunc = gftpui_common_local_request->logging_function; if ((cv = g_hash_table_lookup (gftp_global_options_htable, topic)) != NULL) { - logfunc (gftp_logging_misc, NULL, "%s\n", cv->comment); + gftpui_common_logfunc (gftp_logging_misc, NULL, "%s\n", cv->comment); return (1); } @@ -513,7 +534,8 @@ static int -gftpui_common_cmd_ls (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_ls (void *uidata, gftp_request * request, + const char *command) { char *startcolor, *endcolor, *tempstr; gftpui_callback_data * cdata; @@ -530,7 +552,7 @@ cdata = g_malloc0 (sizeof (*cdata)); cdata->request = request; cdata->uidata = uidata; - cdata->source_string = *command != '\0' ? command : NULL; + cdata->source_string = *command != '\0' ? (char *) command : NULL; cdata->run_function = gftpui_common_run_ls; gftpui_common_run_callback_function (cdata); @@ -561,7 +583,8 @@ int -gftpui_common_cmd_open (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_open (void *uidata, gftp_request * request, + const char *command) { gftpui_callback_data * cdata; intptr_t retries; @@ -626,16 +649,14 @@ static int -gftpui_common_cmd_set (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_set (void *uidata, gftp_request * request, + const char *command) { gftp_config_vars * cv, newcv; - gftp_logging_func logfunc; char *pos, *backpos; GList * templist; int i; - logfunc = _gftpui_common_log (request); - if (command == NULL || *command == '\0') { for (templist = gftp_options_list; @@ -663,8 +684,8 @@ { if ((pos = strchr (command, '=')) == NULL) { - logfunc (gftp_logging_error, request, - _("usage: set [variable = value]\n")); + gftpui_common_logfunc (gftp_logging_error, request, + _("usage: set [variable = value]\n")); return (1); } *pos = '\0'; @@ -677,15 +698,15 @@ if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL) { - logfunc (gftp_logging_error, request, - _("Error: Variable %s is not a valid configuration variable.\n"), command); + gftpui_common_logfunc (gftp_logging_error, request, + _("Error: Variable %s is not a valid configuration variable.\n"), command); return (1); } if (!(cv->ports_shown & GFTP_PORT_TEXT)) { - logfunc (gftp_logging_error, request, - _("Error: Variable %s is not available in the text port of gFTP\n"), command); + gftpui_common_logfunc (gftp_logging_error, request, + _("Error: Variable %s is not available in the text port of gFTP\n"), command); return (1); } @@ -708,10 +729,12 @@ static int -gftpui_common_cmd_help (void *uidata, gftp_request * request, char *command) +gftpui_common_cmd_help (void *uidata, gftp_request * request, + const char *command) { - int i, j, ele, numrows, numcols = 6, handled, number_commands; - char *pos; + int i, j, ele, numrows, numcols = 6, handled, number_commands, cmdlen, + found; + const char *pos; for (number_commands=0; gftpui_common_commands[number_commands].command != NULL; @@ -720,25 +743,21 @@ if (command != NULL && *command != '\0') { for (pos = command; *pos != ' ' && *pos != '\0'; pos++); - if (*pos == ' ') - { - *pos++ = '\0'; - if (*pos == '\0') - pos = NULL; - } - else - pos = NULL; + cmdlen = pos - command; for (i=0; gftpui_common_commands[i].command != NULL; i++) { - if (strcmp (gftpui_common_commands[i].command, command) == 0) + if (strncmp (gftpui_common_commands[i].command, command, cmdlen) == 0) break; } if (gftpui_common_commands[i].cmd_description != NULL) { - if (pos != NULL && gftpui_common_commands[i].subhelp_func != NULL) - handled = gftpui_common_commands[i].subhelp_func (pos); + found = 1; + + if (*pos != '\0' && *(pos + 1) != '\0' && + gftpui_common_commands[i].subhelp_func != NULL) + handled = gftpui_common_commands[i].subhelp_func (pos + 1); else handled = 0; @@ -746,10 +765,12 @@ printf ("%s\n", _(gftpui_common_commands[i].cmd_description)); } else - *command = '\0'; + found = 0; } + else + found = 0; - if (command == NULL || *command == '\0') + if (!found) { numrows = number_commands / numcols; if (number_commands % numcols != 0) @@ -853,25 +874,13 @@ int -gftpui_common_init (void *locui, gftp_request * locreq, - void *remui, gftp_request * remreq) +gftpui_common_process_command (void *locui, gftp_request * locreq, + void *remui, gftp_request * remreq, + const char *command) { - gftpui_common_local_uidata = locui; - gftpui_common_local_request = locreq; - - gftpui_common_remote_uidata = remui; - gftpui_common_remote_request = remreq; - - return (0); -} - - -int -gftpui_common_process_command (const char *command) -{ + gftp_request * request; const char *stpos; char *pos, *newstr; - gftp_request * request; size_t cmdlen; void *uidata; int ret, i; @@ -916,31 +925,30 @@ else pos = ""; + if (gftpui_common_commands[i].reqtype == gftpui_common_request_local) + { + request = locreq; + uidata = locui; + } + else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote) + { + request = remreq; + uidata = remui; + } + else + { + request = NULL; + uidata = NULL; + } + if (gftpui_common_commands[i].command != NULL) { - if (gftpui_common_commands[i].reqtype == gftpui_common_request_local) - { - request = gftpui_common_local_request; - uidata = gftpui_common_local_uidata; - } - else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote) - { - request = gftpui_common_remote_request; - uidata = gftpui_common_remote_uidata; - } - else - { - request = NULL; - uidata = NULL; - } - ret = gftpui_common_commands[i].func (uidata, request, pos); } else { - gftpui_common_local_request->logging_function (gftp_logging_error, - gftpui_common_local_request, - _("Error: Command not recognized\n")); + gftpui_common_logfunc (gftp_logging_error, request, + _("Error: Command not recognized\n")); ret = 1; } diff -r 642bc7a87f05 -r d207b8241e96 src/uicommon/gftpui.h --- a/src/uicommon/gftpui.h Wed Jan 21 16:46:01 2004 +0000 +++ b/src/uicommon/gftpui.h Wed Jan 21 23:35:40 2004 +0000 @@ -50,10 +50,10 @@ { char *command; int minlen; - int (*func)(void *uidata, gftp_request * request, char *command); + int (*func)(void *uidata, gftp_request * request, const char *command); gftpui_common_request_type reqtype; char *cmd_description; - int (*subhelp_func) (char *topic); + int (*subhelp_func) (const char *topic); } gftpui_common_methods; typedef struct _gftpui_common_curtrans_data @@ -80,27 +80,29 @@ extern volatile int gftpui_common_use_jmp_environment; extern gftpui_common_methods gftpui_common_commands[]; extern GStaticMutex gftpui_common_transfer_mutex; +extern volatile sig_atomic_t gftpui_common_child_process_done; /* gftpui.c */ int gftpui_run_callback_function ( gftpui_callback_data * cdata ); int gftpui_common_run_callback_function ( gftpui_callback_data * cdata ); -RETSIGTYPE gftpui_common_signal_handler ( int signo ); +void gftpui_common_init ( int *argc, + char ***argv, + gftp_logging_func logfunc ); void gftpui_common_about ( gftp_logging_func logging_function, gpointer logdata ); -int gftpui_common_init ( void *locui, +int gftpui_common_process_command ( void *locui, gftp_request * locreq, void *remui, - gftp_request * remreq ); - -int gftpui_common_process_command ( const char *command ); + gftp_request * remreq, + const char *command ); int gftpui_common_cmd_open ( void *uidata, gftp_request * request, - char *command ); + const char *command ); gftp_transfer * gftpui_common_add_file_transfer ( gftp_request * fromreq, gftp_request * toreq,