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

📄 disp_hnd.c

📁 功能强大的文本编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
/*   text1         text2                text3      */
/* " file A=","L:\erwin.lst vo     ",",row: ...  " */
/* text1 hat feste    laenge                       */
/* text2 hat maximale laenge = f (laenge text3)    */
/* text3 hat minimale laenge                       */
/* die gesamt-laenge ist wieder fest !!            */

#if 0    /* comment */

/* the following statement doesn't work everywhere:                 */
/* (bug in ultrix compiler:                                         */
/* return value is 'address', but should be 'no of characters' !!)  */

   len1 = sprintf (text1, "......");

/* we use instead: */

   sprintf (text1, "......");
   len1 = strlen (text1);

#endif


#if LINE_1_DEBUG
   sprintf (text1, " topleft:%5ld,linleft:%5ld",
                    fc0->top_left, fc0->lin_left);
#else
   sprintf (text1, "%cfile %1c%1c", action_flag, file_id, mod_kenn);
#endif
   len1 = strlen (text1);

   sprintf (text3, ",row:%2d,col:%2d,line:%4ld(%4ld),char%s%5ld(%5ld) ",
                    (fc0->lrow + LINE_OFFSET), fc0->column, 
                    (fc0->line_index + LINE_OFFSET), fc0->line_anz+1,
                    chartext, fc0->byte_index, fc0->byte_anz);
   len3 = strlen (text3);

   len2 = min(max(COLUMNS, INIT_COLUMNS), LIMIT_COLUMNS) - len1 - len3; /* INIT_COLUMNS - len1 - len3; */
   sprintf (form2, "%%-%ds", len2);

/* limit filename (last n chars) */
   nam_ind = max (0, ((int) strlen (filename) - len2));
   nam_ptr = &filename [nam_ind];

/* form2 = z.B.: "%-20s" */
   sprintf (text2, form2, nam_ptr); 

/* zusammensetzen */
   assert ((strlen(text1) + strlen(text2)) < sizeof(text1));
   strcat (text1, text2);
   assert ((strlen(text1) + strlen(text3)) < sizeof(text1));
   strcat (text1, text3);

/* forced limitation of line */
   if (COLUMNS < INIT_COLUMNS)
   {
      text1[COLUMNS-1] = '!';
      text1[COLUMNS]   = '\0';
   }

/* show it */
   memset (attr, 0, sizeof (attr));
   optimize_output ((BOT_ROW - 1), 0, text1, attr, 2, 0);

   fflush (stdout);

   set_normal_mode ();

   pop_cursor ();

   return;
}  /* show_status_line_1 */

/* -FF-  */

void show_status_line_2 (char *loc_text, int left_justified, int cursor_pos,
                         int ignore_batch)
{
char form2[20], form3[60], form4[40];
int txt_ind, txt_len, len4, max_txt_len;
static int last_ind;

char help [LIMIT_COLUMNS];
char text [LIMIT_COLUMNS];


/* save for refresh_window */
   strncpy (save_text_2[act_window], loc_text, SAV_LEN);
   save_text_2[act_window][SAV_LEN - 1] = '\0';


/* anzeige bei macro execution nur, wenn gewuenscht */
   if (!get_video_active (ignore_batch))
      return;     /* don't display */

   push_cursor ();

/* constant string */
   sprintf (form4, " - %s%s%s - %s - M.Braun ", 
            VERSION_TEXT_1, VERSION_TEXT_2, VERSION_TEXT_3, VERSION_DATE);
   len4 = strlen(form4);
   max_txt_len = max(0,(COLUMNS - len4 - 1));

/* laenge des text strings */
   txt_len = strlen (loc_text);

/* string kurz genug ? */
   if (txt_len <= max_txt_len)
   {
      txt_ind = 0;
   }
   else
   {
   /* bei ueberlangen strings: anfang / ende unterdruecken */
      if (cursor_pos < 0)
      {
         if (left_justified)   /* hinten abschneiden */
            txt_ind = 0;
         else                  /* vorn abschneiden */
            txt_ind = max (0, ((int) txt_len - max_txt_len));
      }
      else
      {
         if (left_justified == 2)     /* index in get string = 0 */
         {
            txt_ind = 0;
         }
         else
         {
         /* try last index */
            txt_ind = last_ind;

         /* cursor right of window ? */
            if ((cursor_pos - txt_ind) > max_txt_len)
            {                                             /* shift left */
               txt_ind += cursor_pos - txt_ind - max_txt_len;
            }

         /* cursor left of window ? */
            if ((cursor_pos - txt_ind) < 0)
            {                                             /* shift rigth */
               txt_ind += cursor_pos - txt_ind;
            }

         /* empty space on rigth side ? */
            if ((txt_len - txt_ind) <= max_txt_len)
            {                                             /* shift rigth */
               txt_ind += txt_len - txt_ind - max_txt_len;
            }
         }
      }
   }

   strncpy (help, &loc_text[txt_ind], max_txt_len);
   help [max_txt_len] = '\0';    /* forced end of string */
   last_ind = txt_ind;  /* fuer naechsten aufruf merken */

/* generate format string */
   sprintf (form2, "%%-%ds", max_txt_len);
   sprintf (form3, " %s%s", form2, form4);


/* ausgabe-string aufbereiten */
   sprintf (text, form3, help);

/* forced limitation of line */
   if (COLUMNS < INIT_COLUMNS)
   {
      text[COLUMNS-1] = '!';
      text[COLUMNS]   = '\0';
   }

/* suppress last character to avoid scrolling of the entire screen */
#if (ACT_OP_SYSTEM == WIN_32)
   text[COLUMNS-1] = '\0';
#endif


/* show it */
/* ausgabe */
   set_cursor_to (BOT_ROW, 0);
   set_stat_2_mode ();

/* anzeige, ggf. mit cursor */
   memset (attr, 0, sizeof (attr));
   optimize_output (BOT_ROW, 0, text, attr, 2, (cursor_pos == -2));

   if (cursor_pos >= 0)
   {
      cursor_pos = max (0, min ((cursor_pos - txt_ind), max_txt_len));
      set_cursor_to (BOT_ROW, cursor_pos);   /* @@ +1 weggelassen */
   }
   else
   {
      if (cursor_pos == -1)
      {
         set_cursor_to (BOT_ROW, (txt_len + 1));  /* cursor hinter text */
      }
   }
   set_normal_mode ();

   fflush (stdout);

   pop_cursor ();

   return;
}  /* show_status_line_2 */

/* -FF-  */

#if (WITH_SYNTAX_HIGHLIGHTING)

#define SEARCH_HIGH_SPEED  1

#if (SEARCH_HIGH_SPEED)

#if (QSORT_FUNC_ANSI)
static int comp_strings_cs (const void *kt1, const void *kt2)
#else
static int comp_strings_cs (kt1, kt2)
const void *kt1;
const void *kt2;
#endif
{       /* case sensitive */
   return (strcmp ((char *)(*(char **)kt1),
                   (char *)(*(char **)kt2)));
}  /* comp_strings_cs */


#if (QSORT_FUNC_ANSI)
static int comp_strings_ic (const void *kt1, const void *kt2)
#else
static int comp_strings_ic (kt1, kt2)
const void *kt1;
const void *kt2;
#endif
{       /* ignore case */
   return (stricmp((char *)(*(char **)kt1),
                   (char *)(*(char **)kt2)));
}  /* comp_strings_ic */

#endif

/* -FF-  */

static size_t is_keyword (char FA_HU *buf, long index_1, long index_2)
{
/* tests, if the current buffer text is a keyword. */
/* if yes: return its length */
/* if no : return 0          */

static int first;

int ii, jj, delim1, help;
int len1, len2;
char *buffer;
char token[BUF_256];

#if (SEARCH_HIGH_SPEED)
int delta, start_index0;
#endif


/* initialize */
   if (first == 0)
   {
      first = 1;  /* never again */

#if (SEARCH_HIGH_SPEED)

   /* sort the keyword tables */
      for (jj = 0 ; jj < ACTUAL_NUMBER_FILETYPES ; jj++)
      {
         if (hi_light[jj].case_sensitive)
         {
             qsort (hi_light[jj].keywords,
                    hi_light[jj].num_keywords,
                    sizeof(char *),
                    comp_strings_cs);  /* case sensitive */
         }
         else
         {
             qsort (hi_light[jj].keywords,
                    hi_light[jj].num_keywords,
                    sizeof(char *),
                    comp_strings_ic);  /* ignore case */
         }
      }  /* for jj */

#endif


   /* calculate the lengths of the keywords and save them */
      for (jj = 0 ; jj < ACTUAL_NUMBER_FILETYPES ; jj++)
      {
      /* check, if array key_len already exists (from hi_light_default[]) */
         if (hi_light[jj].key_len == NULL)
         {
            buffer = malloc(sizeof(size_t *) * max(1, hi_light[jj].num_keywords));
            if (buffer != NULL)
            {
               hi_light[jj].key_len = (size_t *)buffer;
            }
            else
            {
               err_message (OUT_OF_MEMORY);
               break;
            }
         }

      /* now calculate the key_len */
         for (ii = 0 ; ii < hi_light[jj].num_keywords ; ii++)
         {
            hi_light[jj].key_len[ii] = strlen((char *)hi_light[jj].keywords[ii]);
         }  /* for ii */
      }  /* for jj */
   }  /* if first */


/* for safety reasons */
   if (hi_light[FILE_TYPE].key_len == NULL)
   {
      return 0;     /* no valid structure */
   }


/* delimiter before text ? */
   delim1 = 0;
   if (index_1 == 0L)
   {
      delim1 = 1;   /* begin of file */
   }
   else
   {
      if (is_delimiter (buf[-1]))
         delim1 = 1;
   }

/* check text */
   if (delim1)
   {
      /* isolate the token from the text buffer */
	  memset (token, 0, sizeof(token));
      strncpy(token, buf, min((sizeof(token) - 1),
		                      (index_2 - index_1)));
      strtok (token, fc->e_delimit);
      strtok (token, " \011\015\012");	/* <space>, <tab>, <cr>, <lf> */
	  len2 = strlen(token);

#if (SEARCH_HIGH_SPEED)
      start_index0 = start_index (hi_light[FILE_TYPE].num_keywords + 1);
      delta = start_index0;
   
      for (ii = delta-1 ; delta > 0 ;  /* */ )
      {
         if (ii >= hi_light[FILE_TYPE].num_keywords)
         {
            help = -1;          /* outside range */
         }
         else
         {
            len1 = hi_light[FILE_TYPE].key_len[ii];
			len1 = max(len1, len2);
			len1 = min(len1, (index_2 - index_1));
			
            if (hi_light[FILE_TYPE].case_sensitive)
               help = strncmp (token, (char *)hi_light[FILE_TYPE].keywords[ii], len1);
            else
               help = strnicmp(token, (char *)hi_light[FILE_TYPE].keywords[ii], len1);
         
            if (help == 0)
            {
               return (len1);
            }
         }

         delta >>= 1;           /* shift right 1 bit */
   
         if (help >= 0)         /* successive approximation */
            ii += delta;
         else
            ii -= delta;
      }  /* for loop */
#else
   /* search keyword in list */
      for (ii = 0 ; ii < hi_light[FILE_TYPE].num_keywords ; ii++)
      {
         len1 = hi_light[FILE_TYPE].key_len[ii];
		 len1 = max(len1, len2);
		 len1 = min(len1, (index_2 - index_1));
      
		 if (hi_light[FILE_TYPE].case_sensitive)
            help = strncmp (token, (char *)hi_light[FILE_TYPE].keywords[ii], len1);
         else
            help = strnicmp(token, (char *)hi_light[FILE_TYPE].keywords[ii], len1);

         if (help == 0)
         {
            return (len1);
         }
      }
#endif
   }  /* if delim1 */

   return 0;   /* nothing found */
}  /* is_keyword */

#endif

/* -FF-  */

int is_inside_string_or_comment (char FA_HU *buff, long start_index,
                                 long max_index, int first, int direction)
{
long ii, i1;
static int inside_s1, inside_s2, inside_sl, inside_fc, inside_ml;

   /* new line in backward direction ? */
   if ((direction == -1) &&
	   (start_index < max_index))	/* avoid segmentation violation */
   {
	   if ((buff[start_index + 1] == 0x0d) ||
		   (buff[start_index + 1] == 0x0a))
	      first = 1;
   }

   /* or first call of this ^K command */
   if (first)
   {
   /* search begin of line */
      i1 = start_index;
      for (ii = start_index; ii >= 0; ii--)
      {
         if ((buff[ii] == 0x0d) || (buff[ii] == 0x0a))
         {
            i1 = ii + 1;
            break;
         }
      }
      inside_s1 = 0;
      inside_s2 = 0;
	  inside_sl = 0;
	  inside_fc = 0;
	  inside_ml = 0;


   /* check for inside string */
      /* count string characters(" or ') from begin of line to start_index */
      for (ii = i1; ii < start_index; ii++)
      {
         if ((is_string_character(buff, ii, max_index) == 1) && (!inside_s2))
            inside_s1 = (inside_s1 + 1) & 0x01;    /* toggle each time */

         if ((is_string_character(buff, ii, max_index) == 2) && (!inside_s1))
            inside_s2 = (inside_s2 + 1) & 0x01;    /* toggle each time */

		 if ((inside_s1 == 0) && (inside_s2 == 0))
		 {
		    if (hi_light[FILE_TYPE].comment_sl != NULL)
		    {
               if (strnicmp(&buff[ii],
			  	          hi_light[FILE_TYPE].comment_sl,
                   strlen(hi_light[FILE_TYPE].comment_sl)) == 0)
               {
			      inside_sl = 1;
               }
			}

		    if (hi_light[FILE_TYPE].comment_fc != NULL)
		    {
               if (strnicmp(&buff[ii],

⌨️ 快捷键说明

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