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

📄 wildname.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 2 页
字号:


/* fenster mitten auf bildschirm */
   top   = (ROWS    - (HIST_SIZE     + 2)) / 2;
   left  = (COLUMNS - (window_length + 2)) / 2;
   bot   = top  + (HIST_SIZE     + 1);
   right = left + (window_length + 1);

/* begrenzen */
   top  = max (0, top);
   left = max (0, left);

/* reste alter fenster entfernen */
   if (window_length < old_window_length)
   {
      restore_window_background (old_top, old_left, old_bot, old_right);
   }
   old_window_length = window_length;
   old_top   = top;
   old_left  = left;
   old_bot   = bot;
   old_right = right;

/* plotten */
   plot_rectangle (top, left, bot, right);


   pop_cursor ();


   return;
}  /* plot_dir_window */

/* -FF-  */

static void prepare_indizes (int delta, int total_num,
                             int *file_ind, int *row_ind, int *top_ind)
{
/* modify indizes */
   *file_ind += delta;
   *row_ind  += delta;

/* limit indizes */
   *file_ind = min (*file_ind, (total_num-1));
   *file_ind = max (*file_ind, 0);

   *row_ind  = min (*row_ind , (total_num-1));
   *row_ind  = min (*row_ind , (HIST_SIZE-1));
   *row_ind  = max (*row_ind , 0);

/* calc top index */
   *top_ind  = *file_ind - *row_ind;

   return;
}  /* prepare_indizes */

/* -FF-  */

static void restore_window_background (int top, int left, int bot, int right)
{
   refresh_display_window (top, left, bot, right);
   refresh_whole_screen ();
   return;
}

/* -FF-  */

static int get_real_filename (char *pathname, int filename_index)
{
struct DIR_ENTRY *de;
int file_ind, top_ind, row_ind, key, dir_num, total_num;
int slen, ii, jj, layer, delta, empty_path, new_win, return_key;
DIR *act_dir;

#define TEXT_RESERVE 80         /* max. zulaessige strlen (text) */
static char l_text   [BUF_256 + TEXT_RESERVE];
static char filename [MAX_FILENAME];  /* without path */


/* video output ON ? */
   if (!get_video_active (0))
      return -1;   /* --> */

/* directory level (= no of separators) */
   slen = strlen (pathname);
   layer = 0;
   for (ii = 0 ; ii < slen ; ii++)
   {
      if (pathname[ii] == *FILE_SEPARATOR)
         layer++;
   }

/* separate pathname from filename */

/* file without path */
   strncpy (filename, &pathname[filename_index], sizeof(filename));

/* path without file */
   if (filename_index > 0)
   {
      empty_path = 0;
      pathname [filename_index-1] = '\0';
   }
   else
   {
      empty_path = 2;
      strcpy (pathname, ".");
   }

   old_window_length = 0;
once_more:

/* check, if directory exists */
   if (filename_index > 0)   /* index <= 0 : we are on current directory */
   {
   /* check directory */
      act_dir = opendir (pathname);

   /* test result */
      if (act_dir == NULL)
      {
         err_message (INVALID_PATH_NAME);
         restore_window_background (top, left, bot, right);
         return -1;   /* --> */
      }
   }

/* status display */
   line_2_flag = 1;
   show_status_line_2 ("Reading Directory ...", 0, -1, 0);

/* construct file with all directory entries */
   de = get_directory_buffer (pathname, filename, &dir_num, &total_num);

/* display current directory */
   sprintf (l_text, "Path: \"%s%c%s\" (%d+%d)",
                             pathname, *FILE_SEPARATOR, filename,
                             dir_num, (total_num-dir_num));
   show_status_line_2 (l_text, 0, -1, 0);

   file_ind = !strcmp (de[1].name, "..");   /* if ".." exists, point to it */
   row_ind  = file_ind;
   top_ind  = file_ind - row_ind;
   plot_dir_window (de, total_num);

#if (WITH_MOUSE)
   MouSetMoveArea (0,   0,
                   0, 255,
                   2);
#endif

#if (ACT_SERVER == SERVER_VT_100)
   text_area++;
#endif

/* command loop */
   new_win = 1;
   return_key = 0;
   while (return_key == 0)
   {
      plot_dir_content (de, top_ind, row_ind, total_num, new_win);
      new_win = 0;

      key = toupper (get_1_key (0));

      if ((key >= 'A') && (key <= 'Z'))  /* upper case character ? */
      {
      /* jump to next file with 1st char (like xtree) */
         for (ii = 1 ; ii < total_num ; ii++)
         {
            jj = (ii + file_ind) % total_num;
            
            if (toupper (de[jj].name[0]) == key)  /* match 1st char ? */
            {
               delta = jj - file_ind;

               prepare_indizes (delta, total_num,
                                &file_ind, &row_ind, &top_ind);   
               break;
            }
         }  /* for ii */
      }
      else
      {
         delta = 1;
         switch (key)
         {
            case KEY_PGUP:  /* to top and 16 more */
               delta = HIST_SIZE + file_ind - top_ind;
            /* fall through */
   
            case KEY_UP:
               prepare_indizes (-delta, total_num,
                                &file_ind, &row_ind, &top_ind);   
               break;
   
            case KEY_PGDN:  /* to bottom and 16 more */
               delta = 2 * HIST_SIZE - 1 + top_ind - file_ind;
            /* fall through */
   
            case KEY_DOWN:
               prepare_indizes (delta, total_num,
                                &file_ind, &row_ind, &top_ind);   
               break;
   
            case KEY_HOME:
               file_ind = 0;
               row_ind  = 0;
               top_ind  = 0;
               break;
   
            case KEY_END:
               file_ind = total_num-1;
               row_ind  = min (file_ind, HIST_SIZE-1);
               top_ind  = file_ind - row_ind;
               break;
   
            case 0x1b:    /* <esc> */
            case 0x03:    /* ^C */
               strncat (pathname, FILE_SEPARATOR, BUF_256);
               strncat (pathname, filename, BUF_256);

            /* remove ".\" at begin of path */
               if (empty_path)
                  strcpy (pathname, &pathname[2]);
   
               return_key = -1;   /* --> */
               break;
   
#if (VAR_EOLN)
            case 0x0d:    /* <cr>     */
            case 0x0a:    /* <lf>     */
            case 0x0d0a:  /* <cr><lf> */
#else
            case C_R:     /* <cr> */
#endif
               if (!de[file_ind].dir_flag)
               {  /* file, get it ! */
                  strncat (pathname, FILE_SEPARATOR, BUF_256);
                  strncat (pathname, sel_entry, BUF_256);
   
               /* remove ".\" at begin of path */
                  if (empty_path)
                     strcpy (pathname, &pathname[2]);
   
                  return_key = 1;   /* --> */
               }
               else
               {  /* directory, change to it ! */

                  if (strcmp (de[file_ind].name, ".") == 0)
                  {
#if 0
                     break;   /* "." : do nothing */
#else
                  /* return the directory name + separator only */
                     strncat (pathname, FILE_SEPARATOR, BUF_256);

                     return_key = 1;   /* --> */
                     break;
#endif
                  }

                  if (strcmp (de[file_ind].name, "..") == 0)
                  {           /* ".." : one directory back */
                              /* remove one entry in pathname */
                     layer--;
                     if (layer >= 0)
                     {
                        slen = strlen (pathname);
                        for (ii = slen-1 ; ii >= 0 ; ii--)
                        {
                           if (pathname[ii] == *FILE_SEPARATOR)
                           {
                              pathname[ii] = '\0';
                              filename_index = ii+1;
                              goto once_more;             /* 'tschuldigung */
                           }
                        }
                     }
                  }
   
               /* one directory fore */
               /* insert new entry in pathname */
                  layer++;
                  strncat (pathname, FILE_SEPARATOR, BUF_256);
                  strncat (pathname, sel_entry, BUF_256);
                  filename_index = strlen (pathname);
                  goto once_more;             /* 'tschuldigung */
               }
               break;
   
            case KEY_DO_NOTHING:
               break;

            default:
               beep ();
               break;
         }  /* switch (key) */
      }  /* if no upper case character */
   }  /* while */

/* end of function */
   restore_window_background (top, left, bot, right);

#if (WITH_MOUSE)
   MouSetMoveArea ( 0                , (byte) TOP_ROW,
                   (byte) (COLUMNS-1), (byte) MAX_ROW,
                    -1);
#endif

#if (ACT_SERVER == SERVER_VT_100)
   text_area--;
#endif

   return (return_key);
}  /* get_real_filename */

/* -FF-  */

int wildcard_filename (char *pathname)
{

/* input value : full pathname (e.g. "..\include\*.h")                 */ 
/*                                                                     */ 
/* return value:                                                       */ 
/*    0 : normal filename (without wildcard)         ==> take it       */
/*    1 : with wildcard, converted to valid filename ==> take it       */
/*   -1 : with wildcard, no valid filename selected  ==> keep old name */


char *tmp_name;
int wild_flag, namind, name_len, ii, result;
static char rest_string [MAX_FILENAME];


/* convert file separators + check for wildcards */
   wild_flag = 0;
   tmp_name = pathname;
   *rest_string = '\0';

   while (*tmp_name)
   {
   /* replace separators */
      if ((*tmp_name == '/') ||
          (*tmp_name == '\\'))
      {
         *tmp_name = *FILE_SEPARATOR;
      }

   /* check for wildcards */
      if ((*tmp_name == '*') ||
          (*tmp_name == '?'))
      {
         wild_flag = 1;
      }

   /* check for spaces */
      if ((wild_flag) &&
          (*tmp_name == ' '))
      {
#if (ACT_OP_SYSTEM == WIN_32)
		 if (strnicmp(&tmp_name[1], "vo", 2) == 0)
		 {
#endif
            strncpy (rest_string, tmp_name, sizeof(rest_string)-1);
            *tmp_name = '\0';   /* force end of string */
            break;
#if (ACT_OP_SYSTEM == WIN_32)
		 }
#endif
      }

      tmp_name++;
   }

#if (ACT_OP_SYSTEM == MS_DOS)

/* insert file separator between drive and path, eventually */
/* (e.g. "L:*.LST" --> "L:\*.LST") */

   if ((pathname [1] == ':') &&
       (pathname [2] != *FILE_SEPARATOR))
   {
      name_len = strlen (pathname);
      memcpy_rev (&pathname[3], &pathname[2], (long)(name_len-1));
      pathname [2] = *FILE_SEPARATOR;
   }

#endif

/* find limit between path and filename */
   namind   = 0;
   name_len = strlen (pathname);
 
   for (ii = (name_len-1) ; ii >= 0 ; ii--)   /* rueckwaerts */
   {
   /* abort search, if a separator is found before */
      if (pathname [ii] == *FILE_SEPARATOR)
      {
         namind = ii + 1;
         break; 
      }
   }  /* for ii */


/* found wildcard character ? */
   if (!wild_flag)
   {
      return 0;                              /* 0 */
   }
   else
   {
      result = get_real_filename (pathname, namind);   /* 1 or -1 */

   /* append space and rest again */
      if (*rest_string)
      {
         strcat (pathname, rest_string);
      }
      
      return result;
   }
}  /* wildcard_filename */

/* -FF-  */

#endif

/* Modification History */
/* 02.11.93 - file erzeugt */
/* 06.11.93 - wildcard_file() returns result */
/* 08.11.93 - umstellung auf opendir, readdir */
/* 29.11.93 - mb_ctype.h */
/* 12.12.93 - MouSetMoveArea () */
/* 19.12.93 - bugfix: directory "." is noe handled properly */
/* 20.12.93 - text_area */
/* 27.09.94 - type cast(s) wg. compiler warnings (microsoft c 6.0) */
/* 29.09.94 - check ((de = malloc(...)) == NULL) */
/* 22.02.95 - file_entry weggelassen */
/* 24.02.95 - QSORT_FUNC_ANSI */
/* 20.10.95 - window-size dynamic = f (filename-length) */
/* 22.10.95 - WILD_MAX_LEN, WILD_MIN_LEN */
/* 23.10.95 - bugfix */
/* 24.11.95 - wildcard_filename(): Quit Init "*.c vo" */
/* 15.11.96 - bugfix: dir_flag = ((buff.st_mode & S_IFDIR) != 0); */
/* 05.09.98 - VAR_EOLN */
/* 04.03.99 - directory sign 'd' replaced with '/' */
/* 01.05.03 - wildcard filename + "vo" in WIN_32 */
/* 14.02.04 - out_1_char (int key, int rectangle) */

⌨️ 快捷键说明

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