📄 history.c
字号:
#endif
return (return_text);
} /* get_history_buffer */
/* -FF- */
int read_history_file (void)
{
enum HIST_ID id, old_id;
int entry, key = 0, ii;
FILE *fp;
#define RESERVE 100 /* fuer eintrag vor text */
STATIC char line_buf [BUF_256 + RESERVE];
char *line_ptr;
int delete_prot, err_flag;
char *str_ptr;
err_flag = 0; /* default: no error */
show_status_line_2 ("*** searching history file ***", 0, -2, 0);
/* build filename */
strcpy (pathname, HOME_DIR);
strcat (pathname, FILE_SEPARATOR);
strcat (pathname, HISTO_FILENAME);
/* open file */
fp = fopen (pathname, "rb");
if (fp == NULL) /* file doesn't exist */
{
return -1; /* error */
}
else
{
show_status_line_2 ("*** reading history file ***", 0, -2, 0);
entry = 0;
old_id = (enum HIST_ID) (-1); /* unknown id */
/* loop for all entries */
for (;;)
{
/* read line_buf binary */
line_ptr = line_buf;
for (ii = 0 ; ii < sizeof(line_buf) ; ii++)
{
key = fgetc (fp);
*line_ptr = (char) key;
line_ptr++;
if ((key == '\0') || /* end of string */
(key == EOF)) /* end of file */
break;
}
fgetc (fp); /* <cr> <lf> ueberlesen */
fgetc (fp);
line_buf [sizeof(line_buf) - 1] = '\0'; /* forced end of string */
if ((key != '\0') && (key != EOF))
{
err_flag = 1; /* line to long */
continue;
}
/* line_buf auswerten */
if (key == EOF)
{
break;
}
else
{
sscanf (line_buf, "%d %d", &id, &delete_prot);
if ((id >= 0) && (id < HIST_NUM))
{
/* search for begin of string (1.st char after ':') */
str_ptr = line_buf;
for (ii = 0 ; ii < max_text ; ii++)
{
if (*str_ptr == ':') break;
str_ptr++;
}
if (*str_ptr != ':')
{
err_flag = 3; /* no ':' in this line */
continue;
}
str_ptr++;
if (id != old_id) /* new id ? */
{
old_id = id;
entry = 0;
}
/* line to long */
if (strlen (str_ptr) >= max_text)
{
err_flag = 4;
continue;
}
/* no errors occured */
hist [id][entry].delete_protected = (char) delete_prot;
memcpy (hist [id][entry].text, str_ptr, max_text);
/* forced end of string */
hist [id][entry].text [max_text - 1] = '\0';
/* count up */
entry = (entry + 1) % HIST_SIZE;
}
else
{
err_flag = 2; /* bad hist_id */
continue;
}
}
} /* for (;;) */
fclose (fp);
if (err_flag)
{
err_message (INVALID_HISTORY_ENTRY);
return -2; /* error */
}
else
{
show_status_line_2 ("*** got history file ***", 0, -2, 0);
return 1; /* o.k. */
}
}
} /* read_history_file */
/* -FF- */
int write_history_file (int status)
{
/* status = 0: set flag file_modified */
/* status = 1: write file, if modified */
static int file_modified;
enum HIST_ID id;
int entry;
FILE *fp;
char *text_ptr;
#if (SMALL_BUFFERS_WG_CODEVIEW)
return 0; /* writing of file is switched off */
#else
/* fallunterscheidung */
if (status == 0)
{ /* internal call from history */
file_modified = 1; /* set flag */
}
else
{ /* call from mbedit at end of edit */
if (file_modified)
{
show_status_line_2 ("*** writing history file ***", 0, -2, 0);
/* build filename */
strcpy (pathname, HOME_DIR);
strcat (pathname, FILE_SEPARATOR);
strcat (pathname, HISTO_FILENAME);
/* open file */
fp = fopen (pathname, "wb");
if (fp == NULL) /* file doesn't exist */
{
return -1; /* error */
}
else
{
/* write history entries */
for (id = 0 ; id < HIST_NUM ; id++)
{
for (entry = 0 ; entry < HIST_SIZE ; entry++)
{
text_ptr = hist [id][entry].text;
if (*text_ptr)
{
/* hist_id + protect-flag */
fprintf (fp, "%2d %d:",
id,
hist [id][entry].delete_protected);
/* string (mit allen sonderzeichen !) */
fwrite (text_ptr, 1, strlen (text_ptr), fp);
/* ende kennung */
fputc ('\0', fp); /* end of string */
fputc (0x0d, fp); /* <cr> */
fputc (0x0a, fp); /* <lf> */
}
}
}
fclose (fp);
show_status_line_2 ("*** history file written ***", 0, -2, 0);
}
file_modified = 0; /* reset flag */
}
}
return 1; /* o.k. */
#endif
} /* write_history_file */
/* -FF- */
#if (WITH_LAST_AGAIN)
int read_status_file (void)
{
FILE *fp;
int file, err_flag, values;
STATIC char line_buf [BUF_256];
err_flag = 0; /* default: no error */
show_status_line_2 ("*** searching status file ***", 0, -2, 0);
/* build filename */
#if (WITH_LAST_AGAIN == 1)
strcpy (pathname, HOME_DIR);
#else
strcpy (pathname, ".");
#endif
strcat (pathname, FILE_SEPARATOR);
strcat (pathname, STATS_FILENAME);
/* open file */
fp = fopen (pathname, "r");
if (fp == NULL) /* file doesn't exist */
{
return -1; /* error */
}
else
{
show_status_line_2 ("*** reading status file ***", 0, -2, 0);
/* loop for all entries */
for (file = 0 ; file < MAX_FC_NUM ; file++)
{
if (fgets (line_buf, sizeof(line_buf), fp) == NULL)
break; /* EOF */
mini_file_num = max (mini_file_num, (file+1));
#if (ACT_OP_SYSTEM == MS_DOS) || (ACT_OP_SYSTEM == WIN_32)
values = sscanf (line_buf, "%d \"%[^\"]\" %ld",
&mini_control[file].view_only,
mini_control[file].filename,
&mini_control[file].byte_index);
#else
values = sscanf (line_buf, "%d %s %ld",
&mini_control[file].view_only,
mini_control[file].filename,
&mini_control[file].byte_index);
#endif
if (values != 3)
err_flag = 2; /* bad number of arguments */
} /* for file */
fclose (fp);
if (err_flag)
{
err_message (INVALID_STATUS_ENTRY);
return -2; /* error */
}
else
{
show_status_line_2 ("*** got status file ***", 0, -2, 0);
return 1; /* o.k. */
}
}
} /* read_status_file */
/* -FF- */
int write_status_file (void)
{
int file;
FILE *fp;
show_status_line_2 ("*** writing status file ***", 0, -2, 0);
/* build filename */
#if (WITH_LAST_AGAIN == 1)
strcpy (pathname, HOME_DIR);
#else
strcpy (pathname, ".");
#endif
strcat (pathname, FILE_SEPARATOR);
strcat (pathname, STATS_FILENAME);
/* open file */
fp = fopen (pathname, "w");
if (fp == NULL) /* file doesn't exist */
{
return -1; /* error */
}
else
{
/* write file infos */
for (file = 0 ; file < set.file_num ; file++)
{
if ((file_control[file].malloc_flag) &&
(*file_control[file].filename))
{
/* file_id, view_only-flag, filename + position */
#if (ACT_OP_SYSTEM == MS_DOS) || (ACT_OP_SYSTEM == WIN_32)
fprintf (fp, "%d \"%s\" %6ld\n",
file_control[file].view_only,
file_control[file].filename,
file_control[file].byte_index);
#else
fprintf (fp, "%d %-14s %6ld\n",
file_control[file].view_only,
file_control[file].filename,
file_control[file].byte_index);
#endif
}
}
fclose (fp);
show_status_line_2 ("*** history file written ***", 0, -2, 0);
}
return 1; /* o.k. */
} /* write_status_file */
#endif
/* -FF- */
void save_history_string (enum HIST_ID id, char *string)
{
int entry, start_ind, modified;
char del_prot;
/* video output ON ? */
if (!get_video_active (0)) return;
/* if empty string, return */
if (*string == '\0') return;
/* set flags to default */
modified = 0;
del_prot = 0;
/* search, if new string is already in history buffer */
start_ind = -1; /* default: not found */
for (entry = (HIST_SIZE-1) ; entry >= 0 ; entry--)
{
if (strncmp (hist [id][entry].text, string, max_text) == 0)
{
start_ind = entry;
del_prot = hist [id][entry].delete_protected; /* keep status of entry */
if (entry > 0) modified = 1;
break;
}
}
/* not found ? */
if (start_ind < 0)
{
/* then search for last entry without protection */
for (entry = (HIST_SIZE-1) ; entry >= 0 ; entry--)
{
if (!hist [id][entry].delete_protected)
{
start_ind = entry;
modified = 1;
break;
}
}
}
/* found deletable entry ? */
/* (hint: in xtree are always at least 2 entrys without protection) */
if (modified)
{
/* shift all entries from found entry to newest */
for (entry = start_ind ; entry > 0 ; entry--)
{
memcpy (&hist [id][entry], &hist [id][entry-1], max_total);
}
/* store new entry in buffer */
memcpy (hist [id][0].text, string, max_text);
hist [id][0].text [max_text - 1] = '\0'; /* forced end of string */
hist [id][0].delete_protected = del_prot;
write_history_file (0);
}
return;
} /* save_history_string */
/* -FF- */
static void limit_at_1st_blank (char *string)
{
/* example: converts "abcd efg" */
/* to "abcd" */
while (*string)
{
if (*string == ' ')
{
*string = '\0'; /* forced end of string */
break;
}
string++;
}
return;
} /* limit_at_1st_blank */
/* -FF- */
char *get_home_dir (void)
{
static char *path;
#define DEFAULT_PATH "."
path = getenv(":HOME:");
if (path)
{
limit_at_1st_blank (path);
if (*path)
return path;
}
path = getenv("HOME");
if (path)
{
limit_at_1st_blank (path);
if (*path)
return path;
}
return DEFAULT_PATH;
} /* get_home_dir */
/* -FF- */
/* Modification History */
/* 08.01.93 - file erzeugt */
/* 11.06.93 - Xterm gestrichen */
/* 28.08.93 - STATIC */
/* 10.09.93 - get_home_dir() */
/* 12.09.93 - get_video_active (ignore_batch) */
/* 12.09.93 - show_status_line_2 (..., ignore_batch) */
/* 04.11.93 - plot_rectangle: static --> extern */
/* 06.11.93 - plot_content: ohne modified */
/* 29.11.93 - semigrafik abschaltbar */
/* 01.12.93 - GRAFIK_OFF */
/* 06.12.93 - GRAFIK_OFF --> mon_outp.c */
/* 11.12.93 - hist_window_active */
/* 15.12.93 - build_modified_string (..., int *error) */
/* 20.12.93 - text_area */
/* 09.02.94 - limit_at_1st_blank () */
/* 17.05.94 - VERSION_SCO, KEY_RUBOUT, HDS */
/* 20.05.94 - save + restore last filenames + positions */
/* 21.05.94 - write_status_file(), read_status_file() */
/* 23.06.94 - only one array pathname [] */
/* 23.06.94 - WITH_LAST_AGAIN = 0, 1, 2 */
/* 06.10.94 - semigrafik for ANSI */
/* 24.02.95 - tabelle semi_grafik: dez. zahlen */
/* 05.09.98 - VAR_EOLN */
/* 14.02.04 - out_1_char (int key, int rectangle) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -