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

📄 textui.c

📁 一个linux下的ftp程序。它是使用文件传输协议的一系列程序的集合。
💻 C
字号:
/*****************************************************************************//*  textui.c - Text 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 "gftp-text.h"static const char cvsid[] = "$Id: textui.c,v 1.13 2004/07/28 02:47:24 masneyb Exp $";voidgftpui_lookup_file_colors (gftp_file * fle, char **start_color,                           char ** end_color){  if (S_ISDIR (fle->st_mode))    *start_color = GFTPUI_COMMON_COLOR_BLUE;  else if (S_ISLNK (fle->st_mode))    *start_color = GFTPUI_COMMON_COLOR_WHITE;  else if ((fle->st_mode & S_IXUSR) ||           (fle->st_mode & S_IXGRP) ||           (fle->st_mode & S_IXOTH))    *start_color = GFTPUI_COMMON_COLOR_GREEN;  else    *start_color = GFTPUI_COMMON_COLOR_DEFAULT;  *end_color = GFTPUI_COMMON_COLOR_DEFAULT;}voidgftpui_refresh (void *uidata, int clear_cache_entry){  gftp_request * request;  request = uidata; /* Note: uidata is set to the request in gftp_text.c */  if (clear_cache_entry)    gftp_delete_cache_entry (request, NULL, 0);}void *gftpui_generic_thread (void * (*func) (void *), void *data){  return (func (data));}intgftpui_check_reconnect (gftpui_callback_data * cdata){  return (1);}voidgftpui_prompt_username (void *uidata, gftp_request * request){  char tempstr[256];  gftp_set_username (request,                      gftp_text_ask_question (_("Username [anonymous]:"), 1,                                             tempstr, sizeof (tempstr)));}voidgftpui_prompt_password (void *uidata, gftp_request * request){  char tempstr[256];  gftp_set_password (request,                     gftp_text_ask_question (_("Password:"), 0,                                             tempstr, sizeof (tempstr)));}voidgftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle){}voidgftpui_ask_transfer (gftp_transfer * tdata){  char buf, question[1024], srcsize[50], destsize[50], *pos, defaction;  int action, newaction;  gftp_file * tempfle;  GList * templist;  action = newaction = -1;  for (templist = tdata->files; templist != NULL; templist = templist->next)    {      tempfle = templist->data;      if (tempfle->startsize == 0 || S_ISDIR (tempfle->st_mode))        continue;      while (action == -1)        {          insert_commas (tempfle->size, srcsize, sizeof (srcsize));          insert_commas (tempfle->startsize, destsize, sizeof (destsize));          if ((pos = strrchr (tempfle->file, '/')) != NULL)            pos++;          else            pos = tempfle->file;          gftp_get_transfer_action (tdata->fromreq, tempfle);          switch (tempfle->transfer_action)            {              case GFTP_TRANS_ACTION_OVERWRITE:                action = GFTP_TRANS_ACTION_OVERWRITE;                defaction = 'o';                break;              case GFTP_TRANS_ACTION_SKIP:                action = GFTP_TRANS_ACTION_SKIP;                defaction = 's';                break;              case GFTP_TRANS_ACTION_RESUME:                action = GFTP_TRANS_ACTION_RESUME;                defaction = 'r';                break;              default:                defaction = ' ';                break;            }              g_snprintf (question, sizeof (question), _("%s already exists. (%s source size, %s destination size):\n(o)verwrite, (r)esume, (s)kip, (O)verwrite All, (R)esume All, (S)kip All: (%c)"), pos, srcsize, destsize, defaction);          gftp_text_ask_question (question, 1, &buf, 1);          switch (buf)            {              case 'o':                action = GFTP_TRANS_ACTION_OVERWRITE;                break;              case 'O':                action = newaction = GFTP_TRANS_ACTION_OVERWRITE;                break;              case 'r':                action = GFTP_TRANS_ACTION_RESUME;                break;              case 'R':                action = newaction = GFTP_TRANS_ACTION_RESUME;                break;              case 's':                action = GFTP_TRANS_ACTION_SKIP;                break;              case 'S':                action = newaction = GFTP_TRANS_ACTION_SKIP;                break;              case '\0':              case '\n':                break;              default:                action = -1;                break;            }        }      tempfle->transfer_action = action;      action = newaction;    }}static void_gftpui_text_print_status (gftp_transfer * tdata){  static int progress_pos = 0;  char *progress = "|/-\\";  int sw, tot, i;  printf ("\r%c [", progress[progress_pos++]);  if (progress[progress_pos] == '\0')    progress_pos = 0;  sw = gftp_text_get_win_size () - 20;  tot = (float) tdata->curtrans / (float) tdata->tot_file_trans * (float) sw;                          if (tot > sw)    tot = sw;  for (i=0; i<tot; i++)    printf ("=");  for (i=0; i<sw-tot; i++)    printf (" ");  printf ("] @ %.2fKB/s", tdata->kbs);  fflush (stdout);}voidgftpui_start_current_file_in_transfer (gftp_transfer * tdata){  _gftpui_text_print_status (tdata);}voidgftpui_update_current_file_in_transfer (gftp_transfer * tdata){  _gftpui_text_print_status (tdata);}voidgftpui_finish_current_file_in_transfer (gftp_transfer * tdata){  _gftpui_text_print_status (tdata);  printf ("\n");}voidgftpui_start_transfer (gftp_transfer * tdata){  gftpui_common_transfer_files (tdata);}voidgftpui_disconnect (void *uidata){  gftp_request * request;  request = uidata; /* Note: uidata is set to the request in gftp_text.c */  gftp_disconnect (request);}intgftpui_protocol_ask_yes_no (gftp_request * request, char *title, char *question){  char buf[10];  int ret;  do    {      gftp_text_ask_question (question, 1, buf, sizeof (buf));      if (strcasecmp (buf, "yes") == 0)        ret = 1;      else if (strcasecmp (buf, "no") == 0)        ret = 0;      else        ret = -1;    }  while (ret == -1);  return (ret);}char *gftpui_protocol_ask_user_input (gftp_request * request, char *title,                                char *question, int shown){  char buf[255];  do    {      gftp_text_ask_question (question, shown, buf, sizeof (buf));    }  while (*buf == '\0');  return (g_strdup (buf));}

⌨️ 快捷键说明

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