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

📄 mbedit.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
/*      mbedit.c                                  24.03.04       */
/*
/  --------------------------------------------------------------
/  Copyright (C) 2004: Michael Braun
/                      Kaetinger Muehlenweg 103 A
/                      D-28816 Stuhr
/  --------------------------------------------------------------
/
/    editor main program
/
*/


/************************/
/*  include files       */
/************************/

#define _GLOBAL_
#include "config.h"
#include "global.h"
#include "standard.h"
#include "mbedit.h"
#include "calc_var.h"
#include "switches.h"
#include "perform.h"
#include "mbed_sub.h"
#include "commands.h"
#include "blocks.h"
#include "kb_input.h"
#include "mon_outp.h"
#include "memo_hnd.h"
#include "file_hnd.h"
#include "history.h"
#include "disp_hnd.h"
#include "macro.h"
#include "help_opt.h"
#include "err_mess.h"
#include "mb_ctype.h"
#include "mousec.h"
#include "vbios.h"
#include "ansi_out.h"


/************************/
/* some defines         */
/************************/

#if (DEMO_VERSION)
#include "demo/demo.h"
#endif

#define TEST_PRINT  0


/************************/
/* local structures     */
/************************/



/************************/
/*  module definitions  */
/************************/

static int mouse_moved;
static int mouse_status = 1;

#if WITH_MOUSE

static int mouse_driver_ok;

void set_mouse_moved (void)
{
   mouse_moved = 1;
   return;
}  /* set_mouse_moved */


void set_mouse_status (int stat)
{
   mouse_status = stat;
   return;
}  /* set_mouse_status */

#endif

/* -FF-  */

/* abspeichern des exe-filenames (bei MS_DOS, full path, sonst kommande.    */
/* falls der unbrauchbar ist (z.B. zu lang), wird der default-pfad benutzt. */

#define DEFAULT_PATH "."
static char save_path [BUF_256];


char *get_exe_path (void)
{
   return save_path;

}  /* get_exe_path */


void store_exe_path (char *pathname)
{
int ii, last_slash;
int name_len;

/* search last slash */
   last_slash = -1;  /* default: not found */

   name_len = strlen (pathname);
   if (name_len < sizeof (save_path))         /* not to long ? */
   {
      for (ii = name_len ; ii >= 0 ; ii--)    /* rueckwaerts */
      {
         if ((pathname[ii] == '/') ||     /* unix, os/9 */
             (pathname[ii] == '\\'))      /* ms/dos     */
         {
            last_slash = ii;
            break;
         }
      }
   }

   if (last_slash >= 0)                         /* found any slash ? */
   {
      strncpy (save_path, pathname, last_slash);
   }
   else
   {
      strcpy (save_path, DEFAULT_PATH);
   }

/* forced end of string */
   save_path [sizeof(save_path) - 1] = '\0';

   return;
}  /* store_exe_path */

/* -FF-  */

/*---------------------------------*/
/* exchange normal/other buffers   */
/*---------------------------------*/

void exchange_file_control (int file_num, int direction)
{
/* inkr. modulo */
   act_buff_no [act_window] = (act_buff_no [act_window] + file_num + direction)
                                                        % file_num;

   fc = &file_control [act_buff_no [act_window]];

   return;
}  /* exchange_file_control */

/* -FF-  */

/*---------------------------------*/
/* init structure for file control */
/*---------------------------------*/

void init_file_control (struct FILE_CONTROL *fcl, int clear_flag)
{
/* clear_flag = 0 : set to begin of file */
/*            = 1 : clear file buffer    */

   fcl->buffer        = fcl->buff_0;
   fcl->byte_index    = 0L;
   fcl->top_left      = 0L;
   fcl->lin_left      = 0L;

   fcl->line_index    = 0L;

   fcl->arow          = 0;  /* nicht MIN_ROW !! */
   fcl->column        = 0;


   if (clear_flag)
   {
      *fcl->buffer       = EOF;
   
      fcl->tag_index [0] = -1;
      fcl->tag_index [1] = -1;
      fcl->tag_index [2] = -1;
      fcl->tag_index [3] = -1;
   
      fcl->find [0]      = -1;
      fcl->find [1]      = -1;
   
      fcl->buff_no       = act_buff_no [act_window];
   
      fcl->byte_anz      = 0L;
      fcl->line_anz      = 0L;
   
      fcl->view_only     = 0;
      fcl->change_flag   = 0;

      fcl->e_delimit     = get_hi_light_delimiters(get_file_type(fc->filename));;
   }

   return;
}  /* init_file_control */

/* -FF- */

int get_next_file_buffer (int direction)
{
int init_flag;
struct FILE_CONTROL *next_fc;


/* get other work buffer */
   init_flag = 0;
   next_fc = &file_control
             [(act_buff_no [act_window] + set.file_num + direction)
                                        % set.file_num];
   
   if (next_fc->malloc_flag == 0)
   {
      next_fc->buff_0 = loc_malloc (INIT_FILESIZE);
      if (next_fc->buff_0 != NULL)
      {
         next_fc->malloc_flag = 1;
         next_fc->buffer_size = INIT_FILESIZE;
#if (VAR_EOLN)
         next_fc->eoln = EOLN_INIT;
#endif
         init_flag = 1;
      }
      else
      {
         err_message (OUT_OF_MEMORY);
      }
   }

/* exchange buffers */
   if (next_fc->malloc_flag == 1)
   {
      exchange_file_control (set.file_num, direction);
      if (init_flag)
         init_file_control (fc, 1);
      /* perform_view (); */
      return 1;    /* o.k. */
   }
   else
   {
      return -1;   /* error */
   }
}  /* get_next_file_buffer */

/* -FF- */

void set_highbit(void)
{
   if (get_file_type(fc->filename) > 0)
	  fc->highbit = (set.highbit_global != 0);
   else
      fc->highbit = (set.highbit_global == 1);
}  /* set_highbit */

/* -FF- */

int get_1_datafile (void)
{
int ok_flag, file_type;
long file_length;

   ok_flag = 1;  /* default: o.k. */

/* check for read permission */
   if ((access (fc->filename, F_OK) == 0) &&
       (access (fc->filename, R_OK) != 0))
   {
      err_message (FILE_NOT_READABLE);
      fc->byte_anz = -1;
   }
   else
   {
#if (ACT_OP_SYSTEM != OS_9)
   /* Achtung ! Bei os-9 aendert "access(..,W_OK)" die Uhrzeit des Files */
   /* check for write permission */
      if ((access (fc->filename, F_OK) == 0) &&
          (access (fc->filename, W_OK) != 0))
      {
         fc->view_only = 1;
      }
#endif

   /* check buffer_size */   
      file_length = get_file_length (fc->filename, fc->view_only);
   
      if (file_length >= 0)
      {
         if (fc->view_only)
            ok_flag = (check_and_increase_buffer (fc, file_length,
                                                  0L, 1) >= 0);
         else
            ok_flag = (check_and_increase_buffer (fc, file_length,
                                                  FILE_RESERVE, 1) >= 0);
      
      /* buffer large enough ? */
         if (ok_flag)
         {                /* read file */
            fc->byte_anz = read_datafile (fc->filename, fc->buff_0,
                                          file_length , fc->view_only);
         }
         else
         {
            err_message (FILE_TO_LARGE);
            fc->byte_anz = -1;
         }
      }
      else
      {
         fc->byte_anz = -1;
      } 
   }
   
/* read file o.k. ? */
   if (fc->byte_anz < 0)
   {                        /* error, set buffer + filename to 'empty' */
      fc->byte_anz = 0;
      init_file_control (fc, 1);
      *fc->filename = '\0';
      ok_flag = 0;
   }
   fc->change_flag = 0;

#if (VAR_EOLN)
   fc->eoln     = get_var_eoln    (fc->buff_0, 0L, fc->byte_anz);
#endif
   fc->line_anz = get_total_lines (fc->buff_0, 0L, fc->byte_anz);


/* default */
   fc->syntax_flag = 0x00;


#if (WITH_SYNTAX_HIGHLIGHTING)
/* set syntax_flag = f (filename extension) */
/* files with name "*.c" or "*.h" are handled with c syntax ON */

   file_type = get_file_type(fc->filename);
   if (file_type > 0)
      fc->syntax_flag = 0x07 & set.syntax_global;
   else
      fc->syntax_flag = 0x00;


   fc->e_delimit = get_hi_light_delimiters(get_file_type(fc->filename));
#endif

   set_highbit();

   return ok_flag;

}  /* get_1_datafile */

/* -FF- */

/* ----------------------------------------------------------- */
/*  main program                                               */
/* ----------------------------------------------------------- */

int main (argc, argv)       /* hier bei main (und nur hier !): */
int argc;                   /* keine ANSI-Schreibweise, wegen  */
char *argv [];              /* des c-compiler unter ultrix     */
{
int ii, search_macro, read_macro, view_only_flag, ok_flag;
int no_of_options, no_of_files;
size_t  mk_len;
char *name_stt = NULL, *name_end;

#if (WITH_LAST_AGAIN)
int last_again;
#endif

#define MACRO_KENNUNG "macro("
struct MACRO *macro_ex;          /* for "Macro Execute" */

#if (DEMO_VERSION)
static int edit_version = 1;
#endif

/* init keyboard input */
   check_input_redirection ();

/* echo abschalten */
   kb_echo_off ();

/* video context saven */
   SaveVideoContext ();

/* Modify CTRL+C behavior. */
   if (signal (SIGINT, ctrlchandler) == SIG_ERR)
   {
      printf ("\015\012 Couldn't set SIGINT\015\012");
      kb_echo_on ();
      RestoreVideoContext ();
      exit (-1);
   }

/* init. display */
   if (init_mon_outp () < 0)
   {
      printf ("\015\012 error init video\015\012");  /* fatal error */
      kb_echo_on ();
      RestoreVideoContext ();
      signal (SIGINT, SIG_DFL);
      exit (-1);
   }

/* help command line options */
   if (argc >= 2)
   {
      if ((stricmp (argv[1], "-?")    == 0) ||
          (stricmp (argv[1], "-h")    == 0) ||
          (stricmp (argv[1], "-help") == 0))
      {
         printf ("\015\012 usage: mbedit [filenames] [options]\015\012");
         printf ("\015\012 - [filenames]: [<filename 1>] [<filename 2>] ... [<filename 10>]\015\012");

#if (WITH_LAST_AGAIN)
         printf ("\015\012 - [options]  : [- | last_again] [vo | viewonly] [batch]\015\012");
#else
         printf ("\015\012 - [options]  : [vo | viewonly] [batch]\015\012");
#endif
         printf ("\015\012                [nomacro] [macro(<macrofile>)]\015\012");

         kb_echo_on ();
         RestoreVideoContext ();
         signal (SIGINT, SIG_DFL);
         exit (-1);
      }
   }

#if (DEMO_VERSION == 2)
   edit_version = get_edit_status ();
#endif

/* get first work buffer */
   fc = &file_control [act_buff_no [act_window]];

   fc->buff_0 = loc_malloc (INIT_FILESIZE);
   if (fc->buff_0 != NULL)
   {
      fc->malloc_flag = 1;
      fc->buffer_size = INIT_FILESIZE;
#if (VAR_EOLN)
      fc->eoln = EOLN_INIT;
#endif
   }
   else
   {
      printf ("\015\012 malloc error buffer 0\015\012");  /* fatal error */
      kb_echo_on ();
      RestoreVideoContext ();
      signal (SIGINT, SIG_DFL);
      exit (-1);
   }


/* initialize */
   init_file_control (fc, 1);          /* file 'A' */

#if (MACRO_TUNING)
   init_sorted_tables ();
#endif


/* test_screen ();  Darstellung des VGA-Zeichensatzes (nur bei MS_DOS) */

/* vorsichtshalber vt-100-semi-grafik abschalten */
   set_grafik_off (0);


/* default settings */
   *fc->filename  = '\0';
   fc->byte_anz   = 0;

   view_only_flag = 0;    /* option "viewonly" | "vo"   --> 1 */
   search_macro  = 1;     /* option "nomacro"           --> 0 */
   read_macro    = 0;     /* option "macro(<filename>)" --> 1 */
#if (WITH_LAST_AGAIN)
   last_again    = 0;     /* option "-"                 --> 1 */
#endif


/* parse input line */
   no_of_options = 0;

   for (ii = 1 ; ii < argc ; ii++)
   {
   /* view only */
      if ((stricmp (argv[ii], "vo")       == 0) ||
          (stricmp (argv[ii], "viewonly") == 0))
      {
         no_of_options++;
         view_only_flag = 1;
      }

   /* batch mode */
      if (stricmp (argv[ii], "batch") == 0)
      {
         no_of_options++;
         set_batch_mode (1);
      }

#if (WITH_LAST_AGAIN)
   /* last files again */  
      if ((stricmp (argv[ii], "-")          == 0) ||
          (stricmp (argv[ii], "last_again") == 0))
      {
         no_of_options++;
         last_again = 1;
      }
#endif

   /* nomacro */
      if (stricmp (argv[ii], "nomacro") == 0)
      {
         no_of_options++;

⌨️ 快捷键说明

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