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

📄 file.c

📁 C语言高级实例解析的配套光盘资料
💻 C
📖 第 1 页 / 共 4 页
字号:
         file->prev = fp;
         if (fp->next)
            fp->next->prev = file;
         file->next = fp->next;
         fp->next = file;
      }

      

      assert( file_mode == CRLF  ||  file_mode == LF  ||  file_mode == BINARY );
      assert( strlen( name ) < MAX_COLS );

      strcpy( file->file_name, name );
      get_fattr( name, (int *)&file->file_attrib );
      file->block_type  = NOTMARKED;
      file->block_br    = file->block_er = 0l;
      file->block_bc    = file->block_ec = 0;
      file->ref_count   = 0;
      file->modified    = FALSE;
      file->backed_up   = FALSE;
      file->new_file    = !existing;
      file->next_letter = 'a';
      file->file_no     = ++g_status.file_count;
      file->crlf        = file_mode;
      g_status.current_file = file;
      make_backup_fname( file );
   } else if (file != NULL) {
     
      ll = file->undo_top;
      while (ll != NULL) {
         temp_ll = ll->next;
         if (ll->line != NULL)
            my_free( ll->line );
         my_free( ll );
         ll = temp_ll;
      }

      ll = file->line_list;
      while (ll != NULL) {
         temp_ll = ll->next;
         if (ll->line != NULL)
            my_free( ll->line );
         my_free( ll );
         ll = temp_ll;
      }

#if defined( __MSC__ )
      _fheapmin( );
#endif

      free( file );
   }
   return( rc );
}



int  edit_another_file( WINDOW *window )
{
char fname[MAX_COLS];           
char spdrive[_MAX_DRIVE];       
char spdir[_MAX_DIR];           
char spname[_MAX_FNAME];        
char spext[_MAX_EXT];           
register WINDOW *win;           
int  rc;
int  file_mode;
int  bin_length;

   win = window;
   entab_linebuff( );
   if (un_copy_line( win->ll, win, TRUE ) == ERROR)
      return( ERROR );
  
   fname[0] = '\0';
   
   if ((rc = get_name( ed15, win->bottom_line, fname,
                 g_display.message_color )) == OK  &&  *fname != '\0') {
      file_mode = TEXT;
      bin_length = 0;

      assert( strlen( fname ) <= MAX_COLS );

      _splitpath( fname, spdrive, spdir, spname, spext );
      if (stricmp( spext, ".exe" ) == 0  ||  stricmp( spext, ".com" ) == 0) {
         file_mode = BINARY;
         bin_length = g_status.file_chunk;
      }
      rc = attempt_edit_display( fname, LOCAL, file_mode, bin_length );
      if (rc == OK)
         show_avail_mem( );
   }
   return( rc );
}



int  edit_next_file( WINDOW *window )
{
char name[MAX_COLS];            
char spdrive[_MAX_DRIVE];       
char spdir[_MAX_DIR];           
char spname[_MAX_FNAME];        
char spext[_MAX_EXT];           
int  file_mode;
int  bin_length;
int  i;
int  update_type;
register int rc = ERROR;
register WINDOW *win;           

   win = window;
   update_type = win == NULL ? GLOBAL : LOCAL;
   if (g_status.arg < g_status.argc) {
      if (win != NULL) {
         entab_linebuff( );
         if (un_copy_line( win->ll, win, TRUE ) == ERROR)
            return( ERROR );
      }

      while (rc == ERROR && g_status.arg < g_status.argc) {

         
         if (g_status.found_first == FALSE) {

            assert( strlen( g_status.argv[g_status.arg] ) < MAX_COLS );

            strcpy( name, g_status.argv[g_status.arg] );
            rc = get_fattr( name, &i );

            if (rc == OK || rc == 2) {
               ++g_status.arg;
               rc = OK;

            } else if (rc != ERROR) {
               rc = my_findfirst( &g_status.dta, name, NORMAL | READ_ONLY |
                               HIDDEN | SYSTEM | ARCHIVE );

             
               if (rc == OK) {
                  g_status.found_first = TRUE;
                  i = strlen( name ) - 1;
                  while (i >= 0) {
                     if (name[i] == ':' || name[i] == '\\')
                        break;
                     --i;
                  }
                  name[++i] = '\0';

                  assert( strlen( name ) < MAX_COLS );

                  strcpy( g_status.path, name );
                  strcpy( name, g_status.path );
                  strcat( name, g_status.dta.name );
               } else {
                  ++g_status.arg;
                  if (win != NULL)
                    
                     error( WARNING, win->bottom_line, win8 );
               }
            } else if (rc == ERROR)
               ++g_status.arg;
         } else {

           
            rc = my_findnext( &g_status.dta );
            if (rc == OK) {

               assert( strlen( g_status.path ) + strlen( g_status.dta.name )
                           < MAX_COLS );

               strcpy( name, g_status.path );
               strcat( name, g_status.dta.name );
            } else {
               g_status.found_first = FALSE;
               ++g_status.arg;
            }
         }

        
         if (rc == OK) {
            file_mode = g_status.file_mode;
            bin_length = g_status.file_chunk;

            assert( strlen( name ) <= MAX_COLS );

            _splitpath( name, spdrive, spdir, spname, spext );
            if (stricmp( spext, ".exe" ) == 0 || stricmp( spext, ".com" ) == 0)
               file_mode = BINARY;
            rc = attempt_edit_display( name, update_type, file_mode, bin_length );
            if (rc == OK)
               show_avail_mem( );
         }

         
         else
            rc = ERROR;
      }
   }
   if (rc == ERROR  &&  g_status.arg >= g_status.argc  &&  win != NULL)
    
      error( WARNING, win->bottom_line, win9 );
   return( rc );
}



int  search_and_seize( WINDOW *window )
{
char name[MAX_COLS];            
char searching[MAX_COLS];       
char line_buff[(MAX_COLS+1)*2]; 
char spdrive[_MAX_DRIVE];       
char spdir[_MAX_DIR];           
char spname[_MAX_FNAME];        
char spext[_MAX_EXT];           
int  file_mode;
int  bin_length;
int  i;
int  update_type;
char *tokens;
register int rc = ERROR;
register WINDOW *win;           
int  bottom_line;

   win = window;
   update_type = win == NULL ? GLOBAL : LOCAL;
   if (update_type == LOCAL) {
      if (!g_status.sas_defined ||  g_status.command == DefineGrep ||
                              g_status.command == DefineRegXGrep) {

        
         if (g_status.command == DefineGrep)
            g_status.sas_search_type = BOYER_MOORE;
         else
            g_status.sas_search_type = REG_EXPRESSION;

         if (g_status.sas_search_type == BOYER_MOORE) {
            *sas_bm.pattern = '\0';
            if (get_name( win16a, win->bottom_line, (char *)sas_bm.pattern,
                             g_display.message_color ) == ERROR)
               return( ERROR );
            if (*sas_bm.pattern == '\0')
               return( ERROR );
         } else {
            *sas_regx.pattern = '\0';
            if (get_name( win16b, win->bottom_line, (char *)sas_regx.pattern,
                             g_display.message_color ) == ERROR)
               return( ERROR );
            if (*sas_regx.pattern == '\0')
               return( ERROR );
            else
               strcpy( (char *)regx.pattern, (char *)sas_regx.pattern );
         }
         *g_status.sas_tokens = '\0';
         if (get_name( win17, win->bottom_line, g_status.sas_tokens,
                          g_display.message_color ) == ERROR)
            return( ERROR );
         i = 0;
         tokens = strtok( g_status.sas_tokens, SAS_DELIMITERS );
         while (tokens != NULL) {
            g_status.sas_arg_pointers[i++] = tokens;
            tokens = strtok( NULL, SAS_DELIMITERS );
         }
         if (i == 0)
            return( ERROR );
         g_status.sas_arg_pointers[i] = NULL;
         g_status.sas_argc = i;
         g_status.sas_arg = 0;
         g_status.sas_argv = g_status.sas_arg_pointers;
         g_status.sas_found_first = FALSE;
         if (g_status.command == DefineGrep) {
            g_status.sas_defined = TRUE;
            bm.search_defined = sas_bm.search_defined = OK;
            build_boyer_array( );
         } else {
            i = build_nfa( );
            if (i == OK) {
               g_status.sas_defined = TRUE;
               regx.search_defined = sas_regx.search_defined = OK;
            } else
               g_status.sas_defined = FALSE;
         }
      }
      bottom_line = win->bottom_line;
   } else
      bottom_line = g_display.nlines;
   if (g_status.sas_defined && g_status.sas_arg < g_status.sas_argc) {
      if (win != NULL) {
         entab_linebuff( );
         un_copy_line( win->ll, win, TRUE );
      }

      
      while (rc == ERROR && g_status.sas_arg < g_status.sas_argc) {

         
         if (g_status.sas_found_first == FALSE) {

            assert( strlen( g_status.sas_argv[g_status.sas_arg] ) < MAX_COLS );

            strcpy( name, g_status.sas_argv[g_status.sas_arg] );
            rc = get_fattr( name, &i );

            
            if (rc == OK || rc == 2) {
               ++g_status.sas_arg;
               rc = OK;

            
            } else if (rc != ERROR) {
               rc = my_findfirst( &g_status.sas_dta, name, NORMAL | READ_ONLY |
                               HIDDEN | SYSTEM | ARCHIVE );

              
               if (rc == OK) {
                  g_status.sas_found_first = TRUE;
                  i = strlen( name ) - 1;
                  while (i >= 0) {
                     if (name[i] == ':' || name[i] == '\\')
                        break;
                     --i;
                  }
                  name[++i] = '\0';

                  assert( strlen( name ) + strlen( g_status.sas_dta.name )
                                   < MAX_COLS );

                  strcpy( g_status.sas_path, name );
                  strcpy( name, g_status.sas_path );
                  strcat( name, g_status.sas_dta.name );
               } else {
                  ++g_status.sas_arg;
                  if (win != NULL)
                  
                     error( WARNING, win->bottom_line, win8 );
               }
            } else if (rc == ERROR)
               ++g_status.sas_arg;
         } else {

           
            rc = my_findnext( &g_status.sas_dta );
            if (rc == OK) {

               assert( strlen( g_status.sas_path ) +
                       strlen( g_status.sas_dta.name ) < MAX_COLS );

               strcpy( name, g_status.sas_path );
               strcat( name, g_status.sas_dta.name );
            } else {
               g_status.sas_found_first = FALSE;
               ++g_status.sas_arg;
            }
         }

        
         if (rc == OK) {

            assert( strlen( win19 ) + strlen( name ) < MAX_COLS );

            strcpy( searching, win19 );
            strcat( searching, name );
            save_screen_line( 0, bottom_line, line_buff );
            set_prompt( searching, bottom_line );
            file_mode = TEXT;
            bin_length = 0;

            assert( strlen( name ) <= MAX_COLS );

            _splitpath( name, spdrive, spdir, spname, spext );
            if (stricmp( spext, ".exe" ) == 0 || stricmp( spext, ".com" ) == 0){
               file_mode = BINARY;
               bin_length = g_status.file_chunk;
            }
            rc = attempt_edit_display( name, update_type, file_mode, bin_length );
            if (rc == OK)
               show_avail_mem( );
            restore_screen_line( 0, bottom_line, line_buff );

            if (rc == OK) {
               win = g_status.current_window;
               bin_offset_adjust( win, g_status.sas_rline );
               find_adjust( win, g_status.sas_ll, g_status.sas_rline,
                            g_status.sas_rcol );
               make_ruler( win );
               show_ruler( win );
               show_ruler_pointer( win );
               show_window_header( win );
               if (win->vertical)
                  show_vertical_separator( win );
               win->file_info->dirty = LOCAL;
            }
         }

         else
            rc = ERROR;
      }
   }
   if (rc == ERROR &&  g_status.sas_arg >= g_status.sas_argc  && win != NULL)
      
      error( WARNING, win->bottom_line, win9 );
   return( rc );
}

⌨️ 快捷键说明

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