📄 disp_hnd.c
字号:
/* disp_hnd.c 24.03.04 */
/*!
/ --------------------------------------------------------------
/ Copyright (C) 2004: Michael Braun
/ Kaetinger Muehlenweg 103 A
/ D-28816 Stuhr
/ --------------------------------------------------------------
/
/ display output subroutines, operating system dependant
/
*/
/****************************************************************
* *
* BENUTZTE UNTERPROGRAMME (C LIBRARY) *
* *
****************************************************************/
#include "config.h"
#include "global.h"
#include "standard.h"
#include "history.h"
#include "disp_hnd.h"
#include "mon_outp.h"
#include "err_mess.h"
#include "kb_input.h"
#include "commands.h"
#include "memo_hnd.h"
#include "mb_ctype.h"
#include "macro.h"
#include "blocks.h"
#include "perform.h"
#include "calc_var.h"
#include "switches.h"
#include "mbed_sub.h"
#include "mbedit.h"
#include "calc.h"
#include "window.h"
#include "wildname.h"
#include "mousec.h"
#include "microsft.h"
#include "hi_light.h"
#include "ansi_out.h"
/****************************************************************
* *
* BENUTZTE UNTERPROGRAMME / GLOBALE VARIABLEN *
* *
****************************************************************/
/*
/ Die Ausgabe-Optimierung kann bei MS-DOS abgeschaltet werden,
/ um Speicherplatz zu sparen. Das VGA-Video ist so schnell, dass
/ eine Optimierung nicht notwendig ist.
/ Dagegen ist Speicherplatz unter MS-DOS immer knapp.
*/
#if (ACT_OP_SYSTEM == MS_DOS) || (ACT_OP_SYSTEM == WIN_32)
#define OUTPUT_OPTIMIZED 0 /* always OFF ! */
#else
#define OUTPUT_OPTIMIZED 0 /* <== select here ! */
#endif
#if (OUTPUT_OPTIMIZED)
static char text_buff [LIMIT_ROWS] [LIMIT_COLUMNS+1];
static byte attr_buff [LIMIT_ROWS] [LIMIT_COLUMNS+1];
#endif
static byte attr [LIMIT_COLUMNS+1];
#define BEG_INVERS 0x01
#define BEG_COMMENT 0x02
#define BEG_KEYWORD 0x04
#define BEG_STRING 0x08
#define END_INVERS 0x10
#define END_COMMENT 0x20
#define END_KEYWORD 0x40
#define END_STRING 0x80
#if (ACT_OP_SYSTEM == LINUX)
#define DISPLAY_PAUSE 0 /* msec */
#define CLEAR_TO_EOL_BEFORE 1 /* 1 = fids' behaviour */
#else
#define CLEAR_TO_EOL_BEFORE 0 /* 0 = less work for terminal */
#endif
/* keyword definitions for several languages */
#define ACTUAL_NUMBER_FILETYPES num_file_types
#define FILE_TYPE max(0, (fc->file_type < ACTUAL_NUMBER_FILETYPES ? fc->file_type : 0))
/* data for dynamic syntax highlighting (from config file "mbedit.syn") */
static HiLight *hi_light = hi_light_default;
#define STRICTLY_AEDIT_COMPATIBLE 0 /* 29.04.03 */
static int num_file_types = 1; /* we start with index 1 (0 = no highlighting) */
/****************************************************************
* *
* ENDE DER DEKLARATIONEN *
* *
****************************************************************/
/* -FF- */
int is_comment_ml1 (char *buf)
{
if (hi_light[FILE_TYPE].comment_ml1)
{
if (strnicmp(buf, hi_light[FILE_TYPE].comment_ml1,
strlen(hi_light[FILE_TYPE].comment_ml1)) == 0)
{
return (strlen(hi_light[FILE_TYPE].comment_ml1));
}
}
return 0;
} /* is_comment_ml1 */
int is_comment_ml2 (char *buf)
{
if (hi_light[FILE_TYPE].comment_ml2)
{
if (strnicmp(buf, hi_light[FILE_TYPE].comment_ml2,
strlen(hi_light[FILE_TYPE].comment_ml2)) == 0)
{
return (strlen(hi_light[FILE_TYPE].comment_ml2));
}
}
return 0;
} /* is_comment_ml2 */
int is_comment_sl (char *buf)
{
if (hi_light[FILE_TYPE].comment_sl)
{
if (strnicmp(buf, hi_light[FILE_TYPE].comment_sl,
strlen(hi_light[FILE_TYPE].comment_sl)) == 0)
{
return (strlen(hi_light[FILE_TYPE].comment_sl));
}
}
return 0;
} /* is_comment_sl */
/* -FF- */
int show_syntax_file (void)
{
int ii, jj, rows;
printf ("\015\012");
printf ("loaded syntax file : \"%s\" \015\012", str_synt);
printf (" filetype: extension(s) \015\012");
rows = 3;
for (jj = 0 ; jj < ACTUAL_NUMBER_FILETYPES ; jj++)
{
printf (" %2d: ", jj);
for (ii = 0; ii < hi_light[jj].num_file_ext; ii++)
{
printf ("\"%s\"\t", hi_light[jj].file_ext[ii]);
}
printf ("\015\012");
rows++;
} /* for jj */
return rows;
} /* show_syntax_file */
/* -FF- */
static reduce_delimiters (int file_index, char *string)
{
size_t ii, jj;
for (ii = 0; ii < strlen(hi_light[file_index].e_delimit); ii++)
{
for (jj = 0; jj < strlen(string); jj++)
{
if (hi_light[file_index].e_delimit[ii] == string[jj])
{
/* remove this character from the delimiter set */
memcpy( &hi_light[file_index].e_delimit[ii],
&hi_light[file_index].e_delimit[ii+1],
strlen(hi_light[file_index].e_delimit) - ii);
}
} /* for jj */
} /* for ii */
} /* reduce_delimiters */
char *get_hi_light_delimiters (int file_index)
{
return hi_light[file_index].e_delimit;
} /* get_hi_light_delimiters */
/* -FF- */
int read_syntax_file (char *filename)
{
FILE *fp;
STATIC char parse_line [BUF_256];
char *string, *buffer;
int line_no, err_line;
char err_text [20];
#if (ACT_OP_SYSTEM == OS_9)
#define BIG_BUFFER 32
#endif
#if BIG_BUFFER
static int read_level;
static char bigbuff [BIG_BUFFER*BUFSIZ];
#endif
int counter;
long filpos = 0;
#define FILE_MUST_EXIST 1 /* NEU, konst. ! */
#define FTI (num_file_types - 1) /* actual index to write */
err_line = 0; /* default: no error */
line_no = 0;
/* anzeige */
show_status_line_2 ("*** reading syntax file ***", 0, -2, 0);
/* open datafile */
fp = fopen (filename, "r");
if (fp == NULL) /* file doesn't exist */
{
#if FILE_MUST_EXIST
err_message (FILE_DOESN_T_EXIST);
return -2; /* error : abort --> */
#else
return 0; /* no bytes read */
#endif
}
/* for speed up */
#if BIG_BUFFER
if (read_level == 0) /* only the first time */
setvbuf (fp, bigbuff, _IOFBF, sizeof(bigbuff));
read_level++;
#endif
/* count the number of file types */
counter = 1; /* one additional entry '0' */
while (fgets (parse_line, sizeof(parse_line), fp) != NULL)
{
if (toupper(parse_line[0]) == 'E')
counter++;
} /* while fgets */
rewind (fp); /* back to start */
/* create buffer and clear it */
hi_light = malloc (counter * sizeof(HiLight));
if (hi_light != NULL)
{
memset (hi_light, 0, (counter * sizeof(HiLight)));
strcpy (hi_light[0].e_delimit, TOKEN_DELIMITERS); /* default for unknown file type */
}
else
{
return -1;
}
/* read datafile */
/* interprete syntax file */
while (fgets (parse_line, sizeof(parse_line), fp) != NULL)
{
line_no++;
switch (toupper(parse_line[0]))
{
case ';': /* comment */
default: /* empty lines, etc... */
break;
case 'E': /* file extensions */
strtok(parse_line, " \015\012\011"); /* skip entry */
num_file_types++;
strcpy (hi_light[FTI].e_delimit, TOKEN_DELIMITERS);
/* get all tokens for this line until EOL or comment */
counter = 0;
for (;;)
{
string = strtok(NULL, " \015\012\011");
if (string == NULL) break; /* end of line */
if (*string == ';') break; /* comment */
counter++;
} /* for ;; */
/* restore the old file position */
fseek(fp, filpos, SEEK_SET);
fgets (parse_line, sizeof(parse_line), fp);
strtok(parse_line, " \015\012\011"); /* skip entry */
/* this is the array for the file extension pointer */
buffer = malloc(sizeof(char *) * max(1, counter));
if (buffer != NULL)
{
hi_light[FTI].file_ext = (char ***)buffer;
for (hi_light[FTI].num_file_ext = 0 ; ;
hi_light[FTI].num_file_ext++)
{
string = strtok(NULL, " \015\012\011");
if (string == NULL) break; /* end of line */
if (*string == ';') break; /* comment */
buffer = malloc(strlen(string) + 1);
if (buffer != NULL) strcpy (buffer, string);
hi_light[FTI].file_ext[hi_light[FTI].num_file_ext] =
(char **)buffer;
} /* for num_file_ext */
} /* if buffer */
else
{
sprintf (err_text, " (line %d)", line_no);
err_message_1 (OUT_OF_MEMORY, err_text);
break;
}
#if 0
{
printf ("FTI = %d, num_file_types = %d, num_file_ext = %d: ",
FTI, num_file_types, hi_light[FTI].num_file_ext);
for (ii = 0; ii < hi_light[FTI].num_file_ext; ii++)
{
printf ("\"%s\" ", hi_light[FTI].file_ext[ii]);
}
printf ("\n");
}
#endif
break;
case 'C': /* case sensitivity */
strtok(parse_line, " \015\012\011"); /* skip entry */
hi_light[FTI].case_sensitive = atoi(strtok(NULL, " \015\012\011"));
break;
case 'M': /* comment type 1 (multiple lines) */
strtok(parse_line, " \015\012\011"); /* skip entry */
string = strtok(NULL, " \015\012\011");
if (string)
{
buffer = malloc(strlen(string) + 1);
if (buffer != NULL) strcpy (buffer, string);
hi_light[FTI].comment_ml1 = buffer;
}
string = strtok(NULL, " \015\012\011");
if (string)
{
buffer = malloc(strlen(string) + 1);
if (buffer != NULL) strcpy (buffer, string);
hi_light[FTI].comment_ml2 = buffer;
}
break;
case 'S': /* comment type 2 (single line) */
strtok(parse_line, " \015\012\011"); /* skip entry */
string = strtok(NULL, " \015\012\011");
if (string)
{
buffer = malloc(strlen(string) + 1);
if (buffer != NULL) strcpy (buffer, string);
hi_light[FTI].comment_sl = buffer;
}
break;
case 'F': /* comment type 3 (first column) */
strtok(parse_line, " \015\012\011"); /* skip entry */
string = strtok(NULL, " \015\012\011");
if (string)
{
buffer = malloc(strlen(string) + 1);
if (buffer != NULL) strcpy (buffer, string);
hi_light[FTI].comment_fc = buffer;
}
break;
case 'K': /* keywords */
strtok(parse_line, " \015\012\011"); /* skip entry */
if (hi_light[FTI].keywords == NULL) /* 1st time only */
{
/* count the total number of keywords for this file_type */
/* get all lines with 'K' until next file_type or EOF */
counter = 0;
for (;;)
{
if (toupper(parse_line[0]) == 'E')
{
break; /* next file_type: ==> abort */
} /* if 'E' */
if (toupper(parse_line[0]) == 'K')
{
for (;;)
{
string = strtok(NULL, " \015\012\011");
if (string == NULL) break; /* end of line */
if (*string == ';') break; /* comment */
counter++;
} /* for ;; */
} /* if 'K' */
if (fgets (parse_line, sizeof(parse_line), fp) == NULL)
break; /* EOF */
strtok(parse_line, " \015\012\011"); /* skip entry */
} /* for ;; */
/* restore the old file position */
fseek(fp, filpos, SEEK_SET);
fgets (parse_line, sizeof(parse_line), fp);
strtok(parse_line, " \015\012\011"); /* skip entry */
/* this is the array for the keyword pointer */
buffer = malloc(sizeof(char *) * max(1, counter));
if (buffer != NULL) hi_light[FTI].keywords = (char ***)buffer;
hi_light[FTI].num_keywords = 0;
} /* 1st time only */
if (hi_light[FTI].keywords)
{
for (; ; hi_light[FTI].num_keywords++)
{
string = strtok(NULL, " \015\012\011");
if (string == NULL) break; /* end of line */
if (*string == ';') break; /* comment */
buffer = malloc(strlen(string) + 1);
if (buffer != NULL) strcpy (buffer, string);
hi_light[FTI].keywords[hi_light[FTI].num_keywords] =
(char **)buffer;
reduce_delimiters (FTI, string);
} /* for num_keywords */
} /* if buffer */
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -