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

📄 utils.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            ++count;      }   }   return( count );}/* * Name:    find_end * Purpose: To find the last character in a line * Date:    October 31, 1992 * Passed:  s:    the string to search *          len:  length of string *          tabs: do tabs count as blanks? *          tab_size: size of tabs * Returns: the column of the last character */int  find_end( text_ptr s, int len, int tabs, int tab_size ){register int count = 0;   if (len > 0) {      if (tabs) {         do {            if (*s++ == '\t')               count += tab_size - (count % tab_size);            else               ++count;         } while (--len != 0);      } else         count = len;   }   return( count );}/* * Name:    is_line_blank * Purpose: is line empty or does it only contain spaces? * Date:    November 28, 1991 * Passed:  s:    the string to search *          len:  length of string *          tabs: do tabs count as spaces? * Returns: TRUE if line is blank or FALSE if something is in line */int is_line_blank( text_ptr s, int len, int tabs ){   if (len > 0) {      if (tabs)         while ((*s == ' ' || *s == '\t')  &&  --len != 0)            ++s;      else         while (*s == ' '  &&  --len != 0)            ++s;   } else      len = 0;   return( len == 0 );}/* * Name:    show_window_header * Purpose: show file stuff in window header * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   Clear line and display header in a lite bar */void show_window_header( TDE_WIN *window ){register TDE_WIN *win;          /* put window pointer in a register */int  line;   win = window;   line = win->cline;   win->cline = win->top;   window_eol_clear( win, Color( Head ) );   win->cline = line;   show_window_number_letter( win );   show_window_fname( win );   show_crlf_mode( win );   show_size( win );   show_line_col( win );}/* * Name:    show_window_number_letter * Purpose: show file number and letter of window in lite bar * Date:    June 5, 1991 * Passed:  window:  pointer to current window */void show_window_number_letter( TDE_WIN *window ){int  num;char temp[4];register TDE_WIN *win;   /* put window pointer in a register */   win = window;   num = win->file_info->file_no;   if (num < 10) {      temp[0] = ' ';      temp[1] = '0' + num;   } else {      temp[0] = '0' + num / 10;      temp[1] = '0' + num % 10;   }   temp[2] = win->letter;   temp[3] = '\0';   s_output( temp, win->top, win->left, Color( Head ) );}/* * Name:     show_window_fname * Purpose:  show file name in window header. * Date:     June 5, 1991 * Modified: November 13, 1993, Frank Davis per Byrial Jensen * Passed:   window:  pointer to current window * Notes:    Clear name field and display name in a lite bar * * jmh 980503: assume if the name is "" then it's a pipe and display "(pipe)" *     021105: made the length relative to the window size; *             display the attribute relative to the right edge. */void show_window_fname( TDE_WIN *window ){char *p;register TDE_WIN *win;          /* put window pointer in a register */int  col;int  wid;char temp[PATH_MAX+2];   win = window;   col = win->left + 5;   wid = win->end_col - col - 12;       /* line:col */   if (!win->vertical)      wid -= 17;                        /* attr crlf length */   else if (wid < 1)      return;   assert( wid <= g_display.ncols );   c_repeat( ' ', wid, col, win->top, Color( Head ) );   if (win->title)      strcpy( temp, win->title );   else if (*(p = win->file_info->file_name) == '\0')      strcpy( temp, p + 1 );   else      relative_path( temp, win, TRUE );#if defined( __WIN32__ )   {   char title[8+PATH_MAX+2];      join_strings( title, "TDE - ", temp );      SetConsoleTitle( title );   }#endif   p = temp;   if (strlen( p ) > (size_t)wid) {      if (win->vertical  &&  !win->title) {         p = win->file_info->fname;         if (strlen( p ) > (size_t)wid) {            if (wid < 9)               p = "";            else               p = reduce_string( temp, p, wid, MIDDLE );         }      } else         reduce_string( p, p, wid, MIDDLE );   }   s_output( p, win->top, col, Color( Head ) );   if (!win->vertical) {      s_output( str_fattr( temp, win->file_info->file_attrib ),                win->top, win->end_col-28, Color( Head ) );   }}/* * Name:     show_crlf_mode * Purpose:  display state of crlf flag * Date:     June 5, 1991 * Modified: November 13, 1993, Frank Davis per Byrial Jensen * jmh 991111: used an array. * jmh 021105: position relative to right edge. */void show_crlf_mode( TDE_WIN *window ){   if (!window->vertical)      s_output( crlf_mode[window->file_info->crlf],                window->top, window->end_col-23, Color( Head ) );}/* * Name:    show_size * Purpose: show number of lines in file * Date:    June 5, 1991 * Passed:  window:  pointer to current window * * jmh 021105: position relative to right edge. */void show_size( TDE_WIN *window ){   if (!window->vertical  &&  window->file_info->crlf != BINARY)      n_output( window->file_info->length, 7,                window->end_col-18, window->top, Color( Head ) );}/* * Name:    quit * Purpose: To close the current window without saving the current file. * Date:    June 5, 1991 * Passed:  window:  pointer to current window * Notes:   If the file has been modified but not saved, then the user is *           given a second chance before the changes are discarded. *          Note that this is only necessary if this is the last window *           that refers to the file.  If another window still refers to *           the file, then the check can be left until later. *          jmh - if output has been redirected then quitting will send *                 nothing - file (function file_file) should be used instead. *                 This is so windows can be closed without redirection taking *                 place multiple times. * * jmh 991121: Frank only counted visible windows, which means if a window is *              split and then zoomed, closing one would close both. I don't *              like this, so just use the reference count. */int  quit( TDE_WIN *window ){int  rc = OK;   if (window->file_info->modified && window->file_info->ref_count == 1  &&       !window->file_info->scratch) {      /*       * abandon changes?       */      if (get_yn( utils12, window->bottom_line, R_PROMPT | R_ABORT ) != A_YES)         rc = ERROR;   }   /*    * remove window, allocate screen lines to other windows etc    */   if (rc == OK)      finish( window );   return( OK );}/* * Name:     quit_all * Purpose:  To abandon all windows and leave the editor * Author:   Jason Hood * Date:     29 December, 1996 * Modified: 27 August, 1997 * Passed:   window:  pointer to current window * Notes:    if any window has been modified, prompt before leaving * * Change:   added disabled message during output redirection * 020911:   possibly save the workspace. * 040715:   no longer save the workspace. */int  quit_all( TDE_WIN *window ){int  prompt_line;register TDE_WIN *wp;int  mod = FALSE;int  rc  = A_YES;   prompt_line = g_display.end_line;   if (g_status.output_redir) {      error( WARNING, prompt_line, main22 );      return( ERROR );   }   for (wp=g_status.window_list; wp != NULL; wp=wp->next) {      if (wp->file_info->modified && !wp->file_info->scratch) {         mod = TRUE;         break;      }   }   if (mod) {      /*       * abandon all files?       */      rc = get_yn( utils12a, prompt_line, R_PROMPT | R_ABORT );   }   if (rc == A_YES)      g_status.stop = TRUE;   return( OK );}/* * Name:     date_time_stamp * Purpose:  put system date and time into file at cursor position * Date:     June 5, 1992 * Modified: November 13, 1993, Frank Davis per Byrial Jensen * Passed:   window:  pointer to current window * * jmh 980702: test for EOF * jmh 991126: if EOF or read-only, display anyway, but return ERROR. */int  date_time_stamp( TDE_WIN *window ){char answer[MAX_COLS+2];   format_time( mode.stamp, answer, NULL );   if (window->ll->len == EOF  ||  window->file_info->read_only) {      error( INFO, window->bottom_line, answer );      return( ERROR );   }   return( add_chars( (text_ptr)answer, window ) );}/* * Name:     stamp_format * Purpose:  to set a format for the date and time stamp * Date:     May 21, 1998 * Author:   Jason Hood * Passed:   window:  pointer to current window */int  stamp_format( TDE_WIN *window ){register TDE_WIN *win;   /* put window pointer in a register */char answer[MAX_COLS+2];   win = window;   if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)      return( ERROR );   strcpy( answer, mode.stamp );   /*    * stamp format (F1 = help):    */   if (get_name( utils17, g_display.end_line, answer, &h_stamp ) <= 0)      return( ERROR );   strcpy( mode.stamp, answer );   return( OK );}/* * Name:    add_chars * Purpose: insert string into file * Date:    June 5, 1992 * Passed:  string:  string to add to file *          window:  pointer to current window * * jmh 980524: treat the tab character as though the key was pressed. * jmh 980526: treat the newline character as the Rturn function. * jmh 980728: test rc in the while. * jmh 020913: if called from PasteFromClipboard use tab chars, not the func. * jmh 050816: PasteFromClipboard will wrap at max (well, usually). */int  add_chars( text_ptr string, TDE_WIN *window ){int  rc = OK;   while (*string && rc == OK) {      if (*string == '\t' && g_status.command != PasteFromClipboard)         rc = tab_key( window );      else if (*string == '\n')         rc = insert_newline( window );      else {         g_status.key_pressed = *string;         if (g_status.command == PasteFromClipboard  &&             window->rcol >= MAX_LINE_LENGTH - 2) {            rc = mode.right_justify;            mode.right_justify = FALSE;            g_status.command = FormatText;            word_wrap( window );            mode.right_justify = rc;            g_status.command = PasteFromClipboard;         }         rc = insert_overwrite( window );      }      ++string;   }   return( rc );}/* * Name:    shell * Purpose: shell to DOS (or whatever) * Author:  Jason Hood * Date:    November 27, 1996 * Modified: August 28, 1997 - tested for redirection * Passed:  window:  pointer to current window * Notes:   the video mode should not be changed on return to TDE * * jmh 990410: UNIX: use SHELL environment (or "/bin/sh") instead of "". * jmh 021023: restore overscan color. * jmh 030320: test if files have been modified. * jmh 031026: Execute function will prompt for command. * jmh 031029: test for different timestamps, not just newer. */int  shell( TDE_WIN *window ){char *cmd, *pos, *name;char answer[PATH_MAX+2];char fname[PATH_MAX];int  quote;int  capture, pause, quiet, save;int  fh, fh1, fh2;int  output_reloaded, old_reload;int  rc;TDE_WIN *win;TDE_WIN *out_win;file_infos *fp;ftime_t ftime;   if (g_status.command == Execute) {      if (do_dialog( exec_dialog, exec_proc ) == ERROR)         return( ERROR );      cmd = get_dlg_text( EF_Command );      pos = answer;      while (*cmd) {         if (*cmd != '%')            *pos++ = *cmd;         else {            if (cmd[1] == '=') {               ++cmd;               quote = FALSE;            } else               quote = TRUE;            switch (*++cmd) {               case '%' :                  *pos++ = '%';                  break;               case 'f' :               case 'F' :                  name = window->file_info->file_name;                  if (*name == '\0') {                     /*                      * command requires a file                      */                     error( WARNING, g_display.end_line, utils19 );                     return( ERROR );                  }                  if (*cmd == 'f')                     name = relative_path( fname, window, FALSE );

⌨️ 快捷键说明

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