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

📄 file.c

📁 一个开源著名的TDE编辑器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
      }   }   RESTORE_LINE( prompt_line );   return( rc );}/* * Name:    search_and_seize * Purpose: search files for a pattern * Date:    October 31, 1992 * Passed:  window:  pointer to current window * Notes:   New window replaces old window.  Old window becomes invisible. * * jmh 021024: moved the display code into attempt_edit_display(). * jmh 050809: restore the original path when continuing the search. */int  search_and_seize( TDE_WIN *window ){char  *name = NULL;char  cwd[PATH_MAX];            /* buffer for current directory */int   i;int   update_type;char  *tokens;register int rc;register TDE_WIN *win;          /* put window pointer in a register */TDE_WIN *first_win = NULL;int   bottom_line;DISPLAY_BUFF;   win = window;   update_type = win == NULL ? GLOBAL : LOCAL;   if (update_type == LOCAL) {      bottom_line = win->bottom_line;      if (!g_status.sas_defined ||          (g_status.command == DefineGrep && g_status.sas_defined != TRUE+1)) {         g_status.command = DefineGrep;         rc = do_dialog( grep_dialog, grep_proc );         if (rc == ERROR)            return( ERROR );         g_status.sas_search_type = (CB_G_RegX) ? REG_EXPRESSION : BOYER_MOORE;         tokens = get_dlg_text( EF_G_Pattern );         if (*tokens == '\0')            return( ERROR );         strcpy( (char *)((g_status.sas_search_type == BOYER_MOORE)                          ? sas_bm.pattern : sas_regx.pattern), tokens );         tokens = get_dlg_text( EF_G_Files );         if (*tokens == '\0')            return( ERROR );         strcpy( g_status.sas_tokens, tokens );         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_defined = TRUE;         if (g_status.sas_search_type == BOYER_MOORE) {            bm.search_defined = sas_bm.search_defined = OK;            build_boyer_array( );         } else            regx.search_defined = sas_regx.search_defined = OK;         /*          * free all the previous names          */         while (g_status.sas_dta != NULL)            g_status.sas_dta = next_file( g_status.sas_dta );         get_current_directory( cwd );         if (g_status.sas_path != NULL  &&  g_status.sas_path != init_wd)            free( g_status.sas_path );         g_status.sas_path = strdup( cwd );      }   } else      bottom_line = g_display.end_line;   if (g_status.sas_defined > TRUE) {      g_status.sas_defined = TRUE + 2;      update_type |= CMDLINE;      g_option.file_chunk = g_option_all.file_chunk;   } else {      g_option.file_mode  = TEXT;      g_option.file_chunk = (CB_G_Binary) ? -abs( g_option_all.file_chunk )                                          : MAX_LINE_LENGTH;   }   rc = ERROR;   if (g_status.sas_defined && g_status.sas_arg < g_status.sas_argc) {      if (win != NULL)         un_copy_line( win->ll, win, TRUE, TRUE );      /*       * make sure the right search type is used       */      g_status.search = (g_status.sas_search_type == BOYER_MOORE)                        ? 0 : SEARCH_REGX;      if (CB_G_Results) {         g_status.search |= SEARCH_RESULTS;         results_window = NULL;      }      /*       * make sure the right directory is used       */      get_current_directory( cwd );      if (g_status.sas_path != NULL)         set_current_directory( g_status.sas_path );      /*       * while we haven't found a valid file, search thru the command       * line path.       * we may have an invalid file name when we finish matching all       * files according to a pattern.  then, we need to go to the next       * command line argument if it exists.       */      SAVE_LINE( bottom_line );      while (rc == ERROR && g_status.sas_arg < g_status.sas_argc) {         /*          * if we haven't starting searching for a file, check to see if          * the file is a valid file name.  if no file is found, then let's          * see if we can find according to a search pattern.          */         if (g_status.sas_dta == NULL) {            name = g_status.sas_argv[g_status.sas_arg];            if (is_glob( name )) {               g_status.sas_dta = find_files( name );               if (g_status.sas_dta != NULL) {                  rc = OK;                  name = g_status.sas_dta->name;               } else {                  ++g_status.sas_arg;                  if (win != NULL)                     /*                      * invalid path or file name                      */                     error( WARNING, bottom_line, win8 );               }            } else {               rc = file_exists( name );               if (rc == READ_ONLY)                  rc = OK;               ++g_status.sas_arg;            }         } else {            /*             * we already found one file with wild card characters,             * find the next matching file.             */            g_status.sas_dta = next_file( g_status.sas_dta );            rc = (g_status.sas_dta == NULL) ? ERROR : OK;            if (rc == OK)               name = g_status.sas_dta->name;            else               ++g_status.sas_arg;         }         /*          * if everything is everything so far, set up the file          * and window structures and bring the file into the editor.          */         if (rc == OK) {            join_strings( line_out, win19, name );            set_prompt( line_out, bottom_line );            rc = attempt_edit_display( name, update_type );            if (rc == OK  &&  CB_G_LoadAll) {               rc = ERROR;               if (first_win == NULL)                  first_win = g_status.current_window;            }         }         /*          * either there are no more matching files or we had an          * invalid file name, set rc to ERROR and let's look at the          * next file name or pattern on the command line.          */         else            rc = ERROR;      }      if (!mode.track_path) {         set_current_directory( cwd );         if (rc != ERROR  &&  !make_window)            show_window_fname( g_status.current_window );      }      if (rc == ERROR) {         if (CB_G_Results && results_window != NULL) {            rc = OK;            if (win == NULL && first_win == NULL) {               g_status.current_window = results_window;               g_status.current_file   = results_file;               redraw_screen( results_window );            } else               change_window( g_status.current_window, results_window );         } else if (first_win != NULL) {            rc = OK;            change_window( g_status.current_window, first_win );            found_rline = 0;            show_curl_line( g_status.current_window );         } else            RESTORE_LINE( bottom_line );      }      g_status.search = 0;   }   if (rc == ERROR &&  g_status.sas_arg >= g_status.sas_argc  && win != NULL)      /*       * no more files to load       * pattern not found       */      error( WARNING, bottom_line,             (g_status.command == RepeatGrep) ? win9 : win9b );   return( rc );}/* * Name:    grep_proc * Purpose: dialog callback for DefineGrep * Author:  Jason Hood * Date:    November 30, 2003 * Notes:   verify the pattern if it's regx. */int  grep_proc( int id, char *text ){int  rc = OK;   if (id == IDE_G_PATTERN || id == 0) {      if (CB_G_RegX) {         if (id == 0)            text = get_dlg_text( EF_G_Pattern );         if (*text != '\0') {            strcpy( (char *)regx.pattern, text );            if (build_nfa( ) == ERROR) {               regx.search_defined = g_status.sas_defined = FALSE;               rc = IDE_G_PATTERN;            }         }      }   }   return( rc );}/* * Name:     edit_next_file * Purpose:  edit next file on command line. * Date:     January 6, 1992 * Modified: December 29, 1996 by Jason Hood * Passed:   window:  pointer to current window * Notes:    New window replaces old window.  Old window becomes invisible. * * jmh 981107: pipe now recognizes binary option. * jmh 990425: binary option applies to all following files, until "-b-"; *              "-b" will always use DEFAULT_BIN_LENGTH, not the previous *              value of "-b". *             add line number to history. * jmh 990429: added -r option to load subsequent files read-only; use "-r-" *              to open files read-write. * jmh 990921: modified line number to also recognize column (line:col) or *              binary offset (+offset). Now uses strtol (allowing hex/octal *              values), not atoi (which was technically a bug, anyway). * jmh 010528: added -t option to specify physical tab size (-t or -t0 means *              use deflate mode, -tn sets inflate mode if using deflate, -t- *              restores normal behavior). * jmh 021021: with the new path tracking behaviour, use the initial TDE *              directory to load files. * jmh 021023: added -e option to execute a "startup" macro. * jmh 021024: handle all the command line options here and display warnings *              for unknown options; swapped -L and -L- to remain consistent *              (ie: -L will now disable syntax highlighting, -L- will restore *               filename matching.) * jmh 021028: have -t default to tab size of 8; allow tabs greater than *              half the screen (same as config). * jmh 021102: if window is NULL, return 1 if no options, 2 if options but *              no files. * jmh 030303: added -n option to create a scratch window; *             use a switch to process the options. * jmh 030331: added -c option to title (caption) the window. * jmh 030730: added -s option to load a file as scratch; *             modified option processing to have "one-shot" options (using *              '+') and options after the file (using upper-case or '-' in *              the case of position). Note that "one-shot" options with *              wildcards will only apply to the first file found; options *              after the wildcard will not be processed at all. * jmh 030820: ignore empty ("") arguments. * jmh 031026: fixed -e option (changed to _CONTROLKEY for global and added *              _SHIFTKEY for local). * jmh 040715: added -a option to load all files at once. */int  edit_next_file( TDE_WIN *window ){char *name = NULL;char namebuf[PATH_MAX];int  i;int  update_type;register int rc = ERROR;register TDE_WIN *win;          /* put window pointer in a register */fattr_t fattr;char cwd[PATH_MAX];char *arg;int  minus;int  filename;int  seen_file = FALSE;TDE_WIN *first_win = NULL;   win = window;   update_type = CMDLINE | (win == NULL ? GLOBAL : LOCAL);   if (g_option_all.read_only)      update_type |= g_option_all.read_only;   else if (g_status.viewer_mode)      update_type |= O_READ_ONLY;   if (g_status.arg < g_status.argc) {      if (win != NULL) {         if (un_copy_line( win->ll, win, TRUE, TRUE ) == ERROR)            return( ERROR );      }      /*       * Restore the initial path, to ensure we can still find       *  files specified on the command line.       */      get_current_directory( cwd );      set_current_directory( init_wd );      /*       * Reset the "local" options to the "global" options.       */      g_option = g_option_all;      /*       * while we haven't found a valid file, search thru the command       * line path.       * we may have an invalid file name when we finish matching all       * files according to a pattern.  then, we need to go to the next       * command line argument if it exists.       */      while (rc == ERROR  &&  g_status.arg < g_status.argc) {         /*          * if we haven't started searching for a file, check to see if          * the file is a valid file name.  if no file is found, then let's          * see if we can find according to a search pattern.          */         if (g_status.dta == NULL) {            /*             * Read the pipe before any other files.             */            if (g_status.input_redir) {               name = "";               rc = OK;               filename = TRUE;            } else               filename = FALSE;            for (; g_status.arg < g_status.argc; ++g_status.arg) {               arg = g_status.argv[g_status.arg];               i = *arg;               if (i == '-'  ||  i == '+') {                  minus = (i == '-');                  if (filename) {                     if (bj_islower( arg[1] ) || arg[1] == 'F' || arg[1] == 'G')                        break;                     if (!minus) {                        char j = arg[1];                        if (j == '-' || j == '+' || j == ':')                           j = arg[2];                        if (j >= '0' && j <= '9')                           break;                     }                  }                  i = bj_tolower( arg[1] );                  if (i == 'n') {                     if (filename)                        break;                     filename = TRUE;                     name = "";                     rc = OK;                     g_status.command = ScratchWindow;                     continue;                  }                  switch (i) {                     case 'f':                     case 'g':                        /*                         * search and seize requires at least 4 arg's, eg:                         *    tde -f findme *.c                         */                        if (g_status.argc - g_status.arg >= 3) {                           mode.search_case = (i == arg[1]) ? IGNORE : MATCH;                           CB_G_Results = (arg[2] 

⌨️ 快捷键说明

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