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

📄 file.c

📁 在MAC OS下的一个可以直接调试modem的工具minicom,类似于是在windows下的超级终端.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * file.c	Functions to handle file selector. * *	This file is part of the minicom communications package, *	Copyright 1991-1995 Miquel van Smoorenburg. * *	This file created from code mostly cadged from "dial.c" *	by Miquel van Smoorenburg.  Written by James S. Seymour. *	Copyright (c) 1998 by James S. Seymour (jseymour@jimsun.LinxNet.com) *      Some mods for i18n *      Copyright (c) 1998 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> * *	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. * *  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., *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "rcsid.h"RCSID("$Id: file.c,v 1.13 2007-10-10 20:18:20 al-guest Exp $")#include "port.h"#include "minicom.h"#include "intl.h"#include "getsdir.h"#ifdef HAVE_UNISTD_H#  include <unistd.h>#endif#define FILE_MWTR 1	/* main window top row */#define SUBM_OKAY 5	/* last entry in sub-menu */static int nrents = 1;static void file_tell(const char *s);/* * replaced by macro (on test basis)static GETSDIR_ENTRY *getno(int no, GETSDIR_ENTRY *dirdat); */static void dhili(int k);static void prdir(WIN *dirw, int top, int cur, GETSDIR_ENTRY *dirdat, int longest);static void prone(WIN *dirw, GETSDIR_ENTRY *dirdat, int longest, int inverse);static void *set_work_dir(void *existing, size_t min_len);static int  new_filedir(GETSDIR_ENTRY *o_dirdat, int flushit);static void goto_filedir(char *new_dir, int absolut);static int  tag_untag(char *pat, int tag);static char *concat_list(GETSDIR_ENTRY *d);static int  init_filedir(void);static WIN *dsub;static const char *const what[] =  {    /* TRANSLATORS: Translation of each of these menu items should not be     * longer than 7 characters. The upper-case letter is a shortcut,     * so keep them unique and ASCII; 'h', 'j', 'k', 'l' are reserved */    N_("[Goto]"), N_("[Prev]"), N_("[Show]"), N_("[Tag]"), N_("[Untag]"),    N_("[Okay]")  };#define WHAT_NR_OPTIONS (sizeof (what) / sizeof (*what))#define WHAT_WIDTH 8 /* Width of one entry *//* Number of bytes for <= 7 characters */static size_t what_lens[WHAT_NR_OPTIONS];/* Number of ' ' padding entries at left and right, left is >= 1 */static int what_padding[WHAT_NR_OPTIONS][2];static int dprev;/* Little menu. */static const char *d_yesno[] = { N_("   Yes  "), N_("   No   "), NULL };/* * Tell a little message */static void file_tell(const char *s){  WIN *w;  w = mc_tell("%s", s);  sleep(1);  mc_wclose(w, 1);}/* Draw an entry in the horizontal menu */static void horiz_draw(size_t k, char start_attr, char end_attr){  static const char spaces[] = "        ";  mc_wprintf(dsub, "%.*s", what_padding[k][0], spaces);  mc_wsetattr(dsub, start_attr);  mc_wprintf(dsub, "%.*s", what_lens[k], _(what[k]));  mc_wsetattr(dsub, end_attr);  mc_wprintf(dsub, "%.*s", what_padding[k][1], spaces);}/* * Highlight a choice in the horizontal menu. */static void dhili(int k){  int initial_y = (76 - (WHAT_NR_OPTIONS * WHAT_WIDTH >= 76	           ? 74 : WHAT_NR_OPTIONS * WHAT_WIDTH)) / 2;  if (k == dprev)    return;  if (dprev >= 0) {    mc_wlocate(dsub, initial_y + WHAT_WIDTH * dprev, 0);    if (!useattr)      mc_wputs(dsub, " ");    else      horiz_draw(dprev, stdattr, stdattr);  }  dprev = k;  mc_wlocate(dsub, initial_y + WHAT_WIDTH * k, 0);  if (!useattr)    mc_wputs(dsub, ">");  else    horiz_draw(k, XA_REVERSE | stdattr, stdattr);}/* */#define getno(n,d) ((n) >= nrents? (GETSDIR_ENTRY *) NULL : &((d)[n]))/* * Get entry "no" in list.static GETSDIR_ENTRY *getno(no, dirdat)int no;GETSDIR_ENTRY *dirdat;{  if (no >= nrents)    return (GETSDIR_ENTRY *) NULL;  return &dirdat[no];} *//* * Print the directory. Only draw from "cur" to bottom. */static void prdir(WIN *dirw, int top, int cur,                  GETSDIR_ENTRY *dirdat, int longest){  int f, start;  GETSDIR_ENTRY *d;  char f_str[BUFSIZ];  char t_str[BUFSIZ];  start = cur - top;  dirflush = 0;  sprintf(f_str, " %%-%ds", longest + 2);  mc_wlocate(dirw, 0, start + FILE_MWTR);  for (f = start; f < dirw->ys - (1 + FILE_MWTR); f++) {    if ((d = getno(f + top, dirdat)) == (GETSDIR_ENTRY *)NULL)      break;    if (d->cflags & FL_TAG)      mc_wsetattr(dirw, XA_REVERSE | stdattr);    if (S_ISDIR(d->mode)) {      snprintf(t_str, sizeof(t_str), "[%s]", d->fname);      mc_wprintf(dirw, f_str, t_str);    } else      mc_wprintf(dirw, f_str, d->fname);    mc_wsetattr(dirw, XA_NORMAL | stdattr);    mc_wputc(dirw, '\n');  }  dirflush = 1;  mc_wflush();}/* * Print one directory entry. */static void prone(WIN *dirw, GETSDIR_ENTRY *dirdat, int longest, int inverse){  char f_str[BUFSIZ];  char t_str[BUFSIZ];  dirflush = 0;  sprintf(f_str, " %%-%ds", longest + 2);  /*  if (dirdat->cflags & FL_TAG)    mc_wsetattr(dirw, XA_REVERSE | stdattr);     */  if (inverse)    mc_wsetattr(dirw, XA_REVERSE | stdattr);  if (S_ISDIR(dirdat->mode)) {    snprintf(t_str, sizeof(t_str),  "[%s]", dirdat->fname);    mc_wprintf(dirw, f_str, t_str);  } else    mc_wprintf(dirw, f_str, dirdat->fname);  mc_wsetattr(dirw, XA_NORMAL | stdattr);  dirflush = 1;  mc_wflush();}static WIN *main_w;static GETSDIR_ENTRY *dirdat, *d;static int cur = 0;static int ocur = 0;static int subm = SUBM_OKAY;static int quit = 0;static int top = 0;static int c = 0;static int pgud = 0;static int first = 1;static char *s;static int longest;static char file_title[BUFSIZ];static char cwd_str[BUFSIZ];static char *prev_dir = NULL;static char *work_dir = NULL;static char *d_work_dir = NULL;static char *u_work_dir = NULL;static int min_len = 1;static char wc_str[128] = "";static char wc_mem[128] = "";static int tag_cnt = 0;static int how_many = 0;static int down_loading = 0;static char *ret_buf = NULL;/* Init up/down work directories to make sure we start from * the configuration defaults on the next up/download. jl 6/2000 */void init_dir(char dir){  char *p = NULL;    switch (dir) {  case 'u':    p = u_work_dir;    u_work_dir = (char *)NULL;    break;  case 'd':    p = d_work_dir;    d_work_dir = (char *)NULL;    break;  }  free((void *) p);  return;}static void *set_work_dir(void *existing, size_t min_len){  void *vp;  vp = existing == NULL       ? malloc(min_len) : realloc(existing, min_len);  if (down_loading)    d_work_dir = vp;  else    u_work_dir = vp;  return vp;}/* * Initialize new file directory. * * Sets the current working directory.  Non-0 return = no change. */static int new_filedir(GETSDIR_ENTRY *o_dirdat, int flushit){  static size_t dp_len = 0;  static char cwd_str_fmt[BUFSIZ] = "";  size_t new_dp_len, fmt_len;  char disp_dir[80];  int initial_y = (76 - (WHAT_NR_OPTIONS * WHAT_WIDTH >= 76                   ? 74 : WHAT_NR_OPTIONS * WHAT_WIDTH)) / 2;  size_t i;  cur      =  0;  ocur     =  0;  subm     =  SUBM_OKAY;  quit     =  0;  top      =  0;  c        =  0;  pgud     =  0;  first    =  1;  min_len  =  1;  dprev    = -1;  tag_cnt  =  0;  /* got to do some error-checking here!!!  Maybe use mcd(), too! */  if (prev_dir != NULL)    free(prev_dir);  prev_dir = getcwd(NULL, BUFSIZ);  /*   * get last directory   */  work_dir = down_loading ? d_work_dir : u_work_dir;  /*   * init working directory to default?   */  if (work_dir == NULL) {    char *s = down_loading? P_DOWNDIR : P_UPDIR;    min_len = 1;    if (*s != '/')      min_len += strlen(homedir) + 1;    min_len += strlen(s);    if (min_len < BUFSIZ)      min_len = BUFSIZ;    work_dir = set_work_dir(NULL, min_len);    if (*s == '/')      strncpy(work_dir, s, min_len);    else      snprintf(work_dir, min_len, "%s/%s", homedir, s);  }  /* lop-off trailing "/" for consistency */  if (strlen(work_dir) > 1 && work_dir[strlen(work_dir) - 1] == '/')    work_dir[strlen(work_dir) - 1] = (char)0;  chdir(work_dir);  /* All right, draw the file directory! */  if (flushit) {    dirflush = 0;    mc_winclr(main_w);    mc_wredraw(main_w, 1);  }  mc_wcursor(main_w, CNORMAL);  {    char *s;    if (down_loading) {      if (how_many < 0)        s = _("Select one or more files for download");      else if (how_many)	s = _("Select a file for download");      else	s = _("Select a directory for download");    } else {      if (how_many < 0)        s = _("Select one or more files for upload");      else if (how_many)	s = _("Select a file for upload");      else	s = _("Select a directory for upload");    }    snprintf(file_title, sizeof(file_title), "%s", s);  }  mc_wtitle(main_w, TMID, file_title);  if ((new_dp_len = strlen(work_dir)) > dp_len) {    dp_len = new_dp_len;    snprintf(cwd_str_fmt, sizeof(cwd_str_fmt),             _("Directory: %%-%ds"), (int)dp_len);  }  new_dp_len = mbslen (work_dir);  if (new_dp_len + (fmt_len = mbslen(cwd_str_fmt)) > 75) {    size_t i;    char *tmp_dir = work_dir;    /* We want the last 73 characters */    for (i = 0; 73 + i < new_dp_len + fmt_len; i++) {      wchar_t wc;      tmp_dir += one_mbtowc(&wc, work_dir, MB_LEN_MAX);    }    snprintf(disp_dir, sizeof(disp_dir), "...%s", tmp_dir);    snprintf(cwd_str, sizeof(cwd_str), cwd_str_fmt, disp_dir);  } else    snprintf(cwd_str, sizeof(cwd_str), cwd_str_fmt, work_dir);  mc_wlocate(main_w, 0, 0);  mc_wputs(main_w, cwd_str);  for (i = 0; i < WHAT_NR_OPTIONS; i++) {    const char *str, *c;    size_t j;    str = _(what[i]);    c = str;    for (j = 0; j < WHAT_WIDTH - 1 && *c != 0; j++) {      wchar_t wc;      c += one_mbtowc (&wc, c, MB_LEN_MAX);    }    what_lens[i] = c - str;    j = WHAT_WIDTH - j; /* Characters left for padding */    what_padding[i][1] = j / 2; /* Rounding down */    what_padding[i][0] = j - what_padding[i][1]; /* >= 1 */  }  mc_wlocate(dsub, initial_y, 0);  for (i = 0; i < WHAT_NR_OPTIONS; i++)    horiz_draw(i, mc_wgetattr(dsub), mc_wgetattr(dsub));  mc_wsetregion(main_w, 1, main_w->ys - FILE_MWTR);  main_w->doscroll = 0;  /* old dir to discard? */  if (o_dirdat != (GETSDIR_ENTRY *) NULL)    free(o_dirdat);  /* get sorted directory */  if ((nrents = getsdir(".", wc_str,                        GETSDIR_PARNT|GETSDIR_NSORT|GETSDIR_DIRSF,                        0, &dirdat, &longest)) < 0) {    /* we really want to announce the error here!!! */    mc_wclose(main_w, 1);    mc_wclose(dsub, 1);    free(dirdat);    return -1;  }  prdir(main_w, top, top, dirdat, longest);    mc_wlocate(main_w, initial_y, main_w->ys - FILE_MWTR);  mc_wputs(main_w, _("( Escape to exit, Space to tag )"));  dhili(subm);  /* this really needs to go in dhili !!!*/  mc_wlocate(main_w, 0, cur + FILE_MWTR - top);  if (flushit) {    dirflush = 1;    mc_wredraw(dsub, 1);  }  return 0;}/* * Goto a new directory

⌨️ 快捷键说明

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