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

📄 dirlist.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
                        if (bj_isdigit( *prefix )) {                           fn += 2;                           while (*fn == ' ')                              ++fn;                        } else                           fn += name_ofs;                     }                     if (my_memcmp( fn, prefix, prelen ) == 0)                        break;                  }                  if (i == start)                     func = ERROR;      /* do nothing */               }            }         }         if (func == 0) {            if (i >= offset && i < offset+dir->avail) {               /* do nothing */            } else {               offset = i - (i % dir->lines);               if (dir->max_cols == 3 || dir->max_cols == 4)                  offset -= dir->lines;               else if (dir->max_cols == 5)                  offset -= dir->lines * 2;               if (offset < 0)                  offset = 0;               else if (offset > lastoffset)                  offset = lastoffset;               recalculate_dir( dir, flist, offset );            }            i     -= offset;            c      = i / dir->lines + 1;            r      = i % dir->lines + 1;            change = TRUE;         }      }      switch (func) {         case Rturn        :         case NextLine     :         case BegNextLine  :         case AbortCommand :         case Tab          :            stop = TRUE;            if (func == Tab) {               if (g_status.command == GotoWindow ||                   g_status.command == SyntaxSelect)                  stop = FALSE;               else                  hlight_line( colrow(oldc, oldr), dir->len, flist[fno].color );            }            break;         case LineUp :            if (r > 1) {               --r;            } else {               r = dir->lines;               if (c > 1) {                  --c;               } else if (offset > 0) {                  /*                   * recalculate the dir display stuff.                   */                  offset -= dir->lines;                  recalculate_dir( dir, flist, offset );               }            }            change = TRUE;            break;         case LineDown :            if (r < dir->prow) {               ++r;            } else if (r < dir->lines && c != dir->cols) {               ++r;            } else {               r = 1;               if (c < dir->cols) {                  ++c;               } else if (offset < lastoffset) {                  offset += dir->lines;                  recalculate_dir( dir, flist, offset );               }            }            change = TRUE;            break;         case CharLeft :         case StreamCharLeft :            if (c > 1) {               --c;            } else if (offset > 0) {               offset -= dir->lines;               recalculate_dir( dir, flist, offset );            } else {               c = dir->cols;               if (r > dir->prow)                  --c;            }            change = TRUE;            break;         case CharRight :         case StreamCharRight :            if (c < dir->cols) {               ++c;               if (c == dir->cols) {                  if (r > dir->prow)                     r = dir->prow;               }            } else if (offset < lastoffset) {               offset += dir->lines;               recalculate_dir( dir, flist, offset );               if (r > dir->prow)                  r = dir->prow;            } else               c = 1;            change = TRUE;            break;         case BegOfLine :            if (c != 1 || r != 1) {               c = r = 1;               change = TRUE;            }            break;         case EndOfLine :            if (c != dir->cols || r != dir->prow) {               c = dir->cols;               r = dir->prow;               change = TRUE;            }            break;         case ScreenDown :            if (offset < lastoffset) {               offset += dir->avail;               if (offset > lastoffset)                  offset = lastoffset;               recalculate_dir( dir, flist, offset );               if (c == dir->cols && r > dir->prow)                  r = dir->prow;               change = TRUE;            }            break;         case ScreenUp :            if (offset > 0) {               offset -= dir->avail;               if (offset < 0)                  offset = 0;               recalculate_dir( dir, flist, offset );               change = TRUE;            }            break;         case TopOfFile:                /* added by jmh 980523 */            if (c != 1 || r != 1) {     /* added conditions jmh 980527 */               c = r = 1;               change = TRUE;            }            if (offset != 0) {               offset = 0;               recalculate_dir( dir, flist, offset );               change = TRUE;            }            break;         case EndOfFile:                /* added by jmh 980523 */            if (offset != lastoffset) { /* added conditions jmh 980527 */               offset = lastoffset;               recalculate_dir( dir, flist, offset );               change = TRUE;            }            if (c != dir->cols || r != dir->prow) {               c = dir->cols;               r = dir->prow;               change = TRUE;            }            break;         case BackSpace:            /*             * jmh 980523: use BackSpace to select the "../" entry, which             *             will be first, except in root directory.             */            if (strcmp( flist[0].name, "../" ) == 0) {               fno  = 0;               stop = TRUE;            }            break;         case SortBoxBlock:            if (g_status.command == GotoWindow ||                g_status.command == SyntaxSelect)               break;            mode.dir_sort = (SORT_NAME + SORT_EXT) - mode.dir_sort;            shell_sort( flist, dir->cnt );            write_directory_list( flist+offset, dir );            change = TRUE;            break;         default :            break;      }   }   dir->select = fno;   return( func == AbortCommand ? ERROR : (func == Tab ? TRUE : OK) );}/* * Name:    recalculate_dir * Purpose: To recalcute dir structure when cursor goes ahead or behind screen * Date:    November 13, 1993 * Passed:  dir:    pointer to file structure *          flist:  pointer to file structure *          offset: number of files from beginning of flist * Notes:   Find new number of files on the screen.  Then, find out *           how many files names are in the last column. */void recalculate_dir( DIRECTORY *dir, LIST *flist, int offset ){register int off;   off = offset;   dir->nfiles = (dir->cnt - off) > dir->avail ? dir->avail :                                                 (dir->cnt - off);   dir->prow   = dir->lines - (dir->avail - dir->nfiles);   write_directory_list( flist+off, dir );}/* * Name:     shell_sort * Purpose:  To sort file names * Date:     February 13, 1992 * Modified: November 13, 1993, Frank Davis per Byrial Jensen * Passed:   flist: pointer to list structure *           cnt:   number of items to sort * Notes:    this implementation of Shellsort is based on the one by Robert *            Sedgewick on page 109, _Algorithms in C_. * * Change:   Use of my_memcmp instead of memcmp *           (In somes cases not-english people wants to use their own letters *           even in filenames; I am such one, Byrial). * * jmh 980805: place the ../ entry first and exclude it from the sort. */void shell_sort( LIST *flist, int cnt ){int  i;register int j;register int inc;LIST temp;LIST *fl;int (*cmp)( char *, char * );   sort.order_array = (mode.search_case == IGNORE) ?                      sort_order.ignore : sort_order.match;   if (cnt > 1) {      if (g_status.command == GotoWindow) {         char* n;         cmp = win_cmp;         n = flist[0].name + 2;       /* [!+-] and space */         while (*n == ' ')            /* padding spaces for the number */            ++n;         while (bj_isdigit( *n ))     /* the number */            ++n;         n += 6;                      /* the letter, space, !#* and space */         name_ofs = (int)(n - flist[0].name);      } else if (g_status.command == SyntaxSelect) {         cmp = shl_cmp;      } else {         cmp = dir_cmp;         for (j = 0; j < cnt; ++j)            if (strcmp( flist[j].name, "../" ) == 0)               break;         if (j < cnt) {            if (j != 0) {               flist[j].name = flist[0].name;               flist[0].name = "../";            }            --cnt;            ++flist;         }      }      fl = flist;      /*       * figure the increments, per Donald Knuth, _Sorting and Searching_, and       *  Robert Sedgewick, _Algorithms in C_.       */      j = cnt / 9;      for (inc=1; inc <= j; inc = 3 * inc + 1);      /*       * now, Shellsort the directory file names.       */      for (; inc > 0; inc /= 3) {         for (i=inc; i < cnt; i++) {            j = i;            memcpy( &temp, fl+j, sizeof(LIST) );            while (j >= inc  &&  cmp( fl[j-inc].name, temp.name ) > 0) {               memcpy( fl+j, fl+j-inc, sizeof(LIST) );               j -= inc;            }            memcpy( fl+j, &temp, sizeof(LIST) );         }      }   }}/* * Name:    dir_cmp * Purpose: compare two filenames for the directory sort * Author:  Jason Hood * Date:    August 5, 1998 * Passed:  name1: pointer to first filename *          name2: pointer to second filename * Returns: < 0 if name1 comes before name2 *            0 if name1 and name2 are equal (should never occur) *          > 0 if name1 comes after name2 * Notes:   directories are placed before files. *          the strings are assumed to be NUL-terminated. *          names that begin with a dot are not treated as extensions. */int  dir_cmp( char *name1, char *name2 ){int len;int d;int e1;int e2;   len = strlen( name1 ) + 1;           /* include the NUL */   e2  = strlen( name2 ) - 1;           /* last character */   d   = (name2[e2] == '/') - (name1[len-2] == '/');   if (d == 0) {      /*       * Both files are either directories or names       */      if (mode.dir_sort == SORT_NAME)         d = my_memcmp( (text_ptr)name1, (text_ptr)name2, len );      else {         /*          * Search for the extension          */         for (e1 = len-2; e1 > 0 && name1[e1] != '.'; --e1) ;         for (;           e2 > 0 && name2[e2] != '.'; --e2) ;         if (!e1 &&  e2) return -1;     /* no extension before extension */         if ( e1 && !e2) return +1;     /* extension after no extension */         if (!e1 && !e2)                /* neither have an extension */            d = my_memcmp( (text_ptr)name1, (text_ptr)name2, len );         else {            /*             * Sort the extension first. If the extension is the same,             * sort by name.             */            d = my_memcmp( (text_ptr)(name1+e1), (text_ptr)(name2+e2), len-e1 );            if (d == 0) {               name1[e1] = name2[e2] = '\0';               d = my_memcmp( (text_ptr)name1, (text_ptr)name2, len );               name1[e1] = name2[e2] = '.';            }         }      }   }   return( d );}/* * Count the directory components of name.  Helper function for win_cmp. */static int dircnt( const char *name ){int  cnt;   for (cnt = 0; *name; ++name)      if (*name == '/')         ++cnt;   return( cnt );}/* * Name:    win_cmp * Purpose: compare two names for the window list sort * Author:  Jason Hood * Date:    August 29, 2006 * Notes:   compares filenames first (current before sub before drive) then *           window number (if the title is the same). */static int  win_cmp( char *name1, char *name2 ){int  dir1, dir2;char *n1, *n2;   n1 = name1 + name_ofs;   n2 = name2 + name_ofs;   /*    * place relative paths before absolute paths    */#if defined( __UNIX__ )   if (*n1 == '/') {      if (*n2 != '/')         return( 1 );   }   else if (*n2 == '/')      return( -1 );#else   if (n1[1] == ':') {      if (n2[1] != ':')         return( 1 );      if (*n1 != *n2)         return( *n1 - *n2 );   }   else if (n2[1] == ':')      return( -1 );#endif   /*    * sort by path depth    */   dir1 = dircnt( n1 );   dir2 = dircnt( n2 );   if (dir1 != dir2)      return( dir1 - dir2 );   /*    * sort by name    */   dir1 = my_strcmp( (text_ptr)n1, (text_ptr)n2 );   if (dir1 != 0)      return( dir1 );   /*    * sort by window number    */   return( strcmp( name1 + 2, name2 + 2 ) );}/* * Name:    shl_cmp * Purpose: compare two languages for the language list * Author:  Jason Hood * Date:    September 13, 2006 */static int  shl_cmp( char *name1, char *name2 ){   return my_strcmp( (text_ptr)name1, (text_ptr)name2 );}

⌨️ 快捷键说明

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