⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gftpui.c

📁 一个linux下的ftp程序。它是使用文件传输协议的一系列程序的集合。
💻 C
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************//*  gftpui.c - UI related functions for gFTP                                 *//*  Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>                  *//*                                                                           *//*  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., 59 Temple Place - Suite 330, Boston, MA 02111 USA      *//*****************************************************************************/#include "gftpui.h"static const char cvsid[] = "$Id: gftpui.c,v 1.36 2005/01/25 02:34:19 masneyb Exp $";sigjmp_buf gftpui_common_jmp_environment;volatile int gftpui_common_use_jmp_environment = 0;GStaticMutex gftpui_common_transfer_mutex = G_STATIC_MUTEX_INIT;volatile sig_atomic_t gftpui_common_child_process_done = 0;static gftp_logging_func gftpui_common_logfunc;static int_gftpui_cb_connect (gftpui_callback_data * cdata){  if (cdata->connect_function != NULL)    return (cdata->connect_function (cdata));  else    return (gftp_connect (cdata->request));}static void_gftpui_cb_disconnect (gftpui_callback_data * cdata){  if (cdata->connect_function != NULL)    cdata->disconnect_function (cdata);  else    gftp_disconnect (cdata->request);}static void *_gftpui_common_thread_callback (void * data){   intptr_t network_timeout, sleep_time;  gftpui_callback_data * cdata;  int success, sj, num_timeouts;  cdata = data;  gftp_lookup_request_option (cdata->request, "network_timeout",                              &network_timeout);  gftp_lookup_request_option (cdata->request, "sleep_time",                              &sleep_time);  sj = sigsetjmp (gftpui_common_jmp_environment, 1);  gftpui_common_use_jmp_environment = 1;  num_timeouts = 0;  success = GFTP_ERETRYABLE;  if (sj != 1)    {      while (1)        {          if (network_timeout > 0)            alarm (network_timeout);          success = cdata->run_function (cdata);          alarm (0);          if (success == GFTP_ETIMEDOUT && num_timeouts == 0)            {              _gftpui_cb_disconnect (cdata);              num_timeouts++;              if (_gftpui_cb_connect (cdata) == 0)                continue;            }          if (success == GFTP_EFATAL || success == 0 || cdata->retries == 0)            break;          cdata->retries--;          cdata->request->logging_function (gftp_logging_error, cdata->request,                       _("Waiting %d seconds until trying to connect again\n"),                       sleep_time);          alarm (sleep_time);          pause ();        }    }  else    {      _gftpui_cb_disconnect (cdata);      cdata->request->logging_function (gftp_logging_error, cdata->request,                                        _("Operation canceled\n"));    }  gftpui_common_use_jmp_environment = 0;  cdata->request->stopable = 0;  return (GINT_TO_POINTER (success));}intgftpui_common_run_callback_function (gftpui_callback_data * cdata){  int ret;  if (!cdata->dont_check_connection && gftpui_check_reconnect (cdata) < 0)    return (0);  if (gftp_protocols[cdata->request->protonum].use_threads)    ret = GPOINTER_TO_INT (gftpui_generic_thread (_gftpui_common_thread_callback, cdata));  else    ret = GPOINTER_TO_INT (cdata->run_function (cdata));  if (ret == 0 && !cdata->dont_refresh)    gftpui_refresh (cdata->uidata, !cdata->dont_clear_cache);  return (ret == 0);}static RETSIGTYPEgftpui_common_signal_handler (int signo){  signal (signo, gftpui_common_signal_handler);  if (gftpui_common_use_jmp_environment)    siglongjmp (gftpui_common_jmp_environment, signo == SIGINT ? 1 : 2);  else if (signo == SIGINT)    exit (1);}static RETSIGTYPEgftpui_common_sig_child (int signo){  int ret;  if (gftpui_common_child_process_done == -1)    {      /* Running from text port */      while (waitpid (-1, &ret, WNOHANG) > 0)        {          /* Nothing */        }    }  else    gftpui_common_child_process_done = 1;}voidgftpui_common_init (int *argc, char ***argv, gftp_logging_func logfunc){  char *share_dir;  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);  share_dir = gftp_get_share_dir ();  gftp_read_config_file (share_dir);  if (gftp_parse_command_line (argc, argv) != 0)    exit (0);  gftpui_common_logfunc = logfunc;  gftpui_common_child_process_done = -1;}voidgftpui_common_about (gftp_logging_func logging_function, gpointer logdata){  char *str;  logging_function (gftp_logging_misc, logdata, "%s, Copyright (C) 1998-2003 Brian Masney <", gftp_version);  logging_function (gftp_logging_recv, logdata, "masneyb@gftp.org");  logging_function (gftp_logging_misc, logdata, _(">. If you have any questions, comments, or suggestions about this program, please feel free to email them to me. You can always find out the latest news about gFTP from my website at http://www.gftp.org/\n"));  logging_function (gftp_logging_misc, logdata, _("gFTP comes with ABSOLUTELY NO WARRANTY; for details, see the COPYING file. This is free software, and you are welcome to redistribute it under certain conditions; for details, see the COPYING file\n"));  str = _("Translated by");  if (strcmp (str, "Translated by") != 0)    logging_function (gftp_logging_misc, logdata, "%s\n", str);}static intgftpui_common_cmd_about (void *uidata, gftp_request * request,                         void *other_uidata, gftp_request * other_request,                         const char *command){  gftpui_common_about (gftpui_common_logfunc, NULL);  return (1);}static intgftpui_common_cmd_ascii (void *uidata, gftp_request * request,                         void *other_uidata, gftp_request * other_request,                         const char *command){  gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1));  return (1);}static intgftpui_common_cmd_binary (void *uidata, gftp_request * request,                         void *other_uidata, gftp_request * other_request,                         const char *command){  gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0));  return (1);}static intgftpui_common_cmd_chmod (void *uidata, gftp_request * request,                         void *other_uidata, gftp_request * other_request,                         const char *command){  gftpui_callback_data * cdata;  char *pos;  if (!GFTP_IS_CONNECTED (request))    {      request->logging_function (gftp_logging_error, request,                                 _("Error: Not connected to a remote site\n"));      return (1);    }  if ((pos = strchr (command, ' ')) != NULL)    *pos++ = '\0';  if (*command == '\0' || pos == NULL || *pos == '\0')    {      request->logging_function (gftp_logging_error, request,                                 _("usage: chmod <mode> <file>\n"));    }  else    {      cdata = g_malloc0 (sizeof (*cdata));      cdata->request = request;      cdata->uidata = uidata;      cdata->input_string = (char *) command;      cdata->source_string = pos;      cdata->run_function = gftpui_common_run_chmod;      gftpui_common_run_callback_function (cdata);      g_free (cdata);    }  return (1);}static intgftpui_common_cmd_rename (void *uidata, gftp_request * request,                          void *other_uidata, gftp_request * other_request,                          const char *command){  gftpui_callback_data * cdata;  char *pos;    if (!GFTP_IS_CONNECTED (request))    {      request->logging_function (gftp_logging_error, request,                                 _("Error: Not connected to a remote site\n"));      return (1);    }      if ((pos = strchr (command, ' ')) != NULL)    *pos++ = '\0';      if (*command == '\0' || pos == NULL || *pos == '\0')    {      request->logging_function (gftp_logging_error, request,                                 _("usage: rename <old name> <new name>\n"));    }  else    {      cdata = g_malloc0 (sizeof (*cdata));      cdata->request = request;      cdata->uidata = uidata;      cdata->source_string = (char *) command;      cdata->input_string = pos;      cdata->run_function = gftpui_common_run_rename;      gftpui_common_run_callback_function (cdata);      g_free (cdata);    }  return (1);}static intgftpui_common_cmd_delete (void *uidata, gftp_request * request,                          void *other_uidata, gftp_request * other_request,                          const char *command){  gftpui_callback_data * cdata;  if (!GFTP_IS_CONNECTED (request))    {      request->logging_function (gftp_logging_error, request,                                 _("Error: Not connected to a remote site\n"));      return (1);    }  else if (*command == '\0')    {      request->logging_function (gftp_logging_error, request,                                 _("usage: delete <file>\n"));    }  else    {      cdata = g_malloc0 (sizeof (*cdata));      cdata->request = request;      cdata->uidata = uidata;      cdata->input_string = (char *) command;      cdata->run_function = gftpui_common_run_delete;      gftpui_common_run_callback_function (cdata);      g_free (cdata);    }  return (1);}static intgftpui_common_cmd_rmdir (void *uidata, gftp_request * request,                         void *other_uidata, gftp_request * other_request,                         const char *command){  gftpui_callback_data * cdata;  if (!GFTP_IS_CONNECTED (request))    {      request->logging_function (gftp_logging_error, request,                                 _("Error: Not connected to a remote site\n"));      return (1);    }  else if (*command == '\0')    {      request->logging_function (gftp_logging_error, request,                                 _("usage: rmdir <directory>\n"));    }  else    {      cdata = g_malloc0 (sizeof (*cdata));      cdata->request = request;      cdata->uidata = uidata;      cdata->input_string = (char *) command;      cdata->run_function = gftpui_common_run_rmdir;      gftpui_common_run_callback_function (cdata);      g_free (cdata);    }  return (1);}static intgftpui_common_cmd_site (void *uidata, gftp_request * request,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -