mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2024-11-10 07:21:58 +00:00
Add Bakers/Ezquakes persistent history feature
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@228 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
42c47095a1
commit
5a273f0a99
2 changed files with 72 additions and 3 deletions
|
@ -890,6 +890,9 @@ void Host_Shutdown(void)
|
|||
|
||||
Host_WriteConfiguration ();
|
||||
|
||||
if (con_initialized)
|
||||
History_Shutdown ();
|
||||
|
||||
CDAudio_Shutdown ();
|
||||
NET_Shutdown ();
|
||||
S_Shutdown();
|
||||
|
|
72
Quake/keys.c
72
Quake/keys.c
|
@ -27,8 +27,12 @@ key up events are sent even if in console mode
|
|||
|
||||
*/
|
||||
|
||||
#define MAXCMDLINE 256
|
||||
char key_lines[32][MAXCMDLINE];
|
||||
#define HISTORY_FILE_NAME "id1/history.txt"
|
||||
#define MAXCMDLINE 256
|
||||
#define CMDLINES 32
|
||||
|
||||
char key_lines[CMDLINES][MAXCMDLINE];
|
||||
|
||||
int key_linepos;
|
||||
int shift_down=false;
|
||||
int key_lastpress;
|
||||
|
@ -678,6 +682,63 @@ void Key_WriteBindings (FILE *f)
|
|||
fprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
|
||||
}
|
||||
|
||||
void History_Init (void)
|
||||
{
|
||||
int i, c;
|
||||
FILE *hf;
|
||||
|
||||
for (i = 0; i < CMDLINES; i++) {
|
||||
key_lines[i][0] = ']';
|
||||
key_lines[i][1] = 0;
|
||||
}
|
||||
key_linepos = 1;
|
||||
|
||||
// if (cl_savehistory.value)
|
||||
if ((hf = fopen(HISTORY_FILE_NAME, "rt")))
|
||||
{
|
||||
do
|
||||
{
|
||||
i = 1;
|
||||
do
|
||||
{
|
||||
c = fgetc(hf);
|
||||
key_lines[edit_line][i++] = c;
|
||||
} while (c != '\n' && c != EOF && i < MAXCMDLINE);
|
||||
key_lines[edit_line][i - 1] = 0;
|
||||
edit_line = (edit_line + 1) & (CMDLINES - 1);
|
||||
} while (c != EOF && edit_line < CMDLINES);
|
||||
fclose(hf);
|
||||
|
||||
history_line = edit_line = (edit_line - 1) & (CMDLINES - 1);
|
||||
key_lines[edit_line][0] = ']';
|
||||
key_lines[edit_line][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void History_Shutdown (void)
|
||||
{
|
||||
int i;
|
||||
FILE *hf;
|
||||
|
||||
// if (cl_savehistory.value)
|
||||
if ((hf = fopen(HISTORY_FILE_NAME, "wt")))
|
||||
{
|
||||
i = edit_line;
|
||||
do
|
||||
{
|
||||
i = (i + 1) & (CMDLINES - 1);
|
||||
} while (i != edit_line && !key_lines[i][1]);
|
||||
|
||||
do
|
||||
{
|
||||
// fprintf(hf, "%s\n", wcs2str(key_lines[i] + 1)); // Baker: I commented this line out because byte colored text isn't a feature in most ordinary engines
|
||||
fprintf(hf, "%s\n", key_lines[i] + 1);
|
||||
i = (i + 1) & (CMDLINES - 1);
|
||||
} while (i != edit_line && key_lines[i][1]);
|
||||
fclose(hf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
===================
|
||||
|
@ -688,7 +749,11 @@ void Key_Init (void)
|
|||
{
|
||||
int i;
|
||||
|
||||
BuildKeyMaps();
|
||||
BuildKeyMaps();
|
||||
|
||||
History_Init ();
|
||||
|
||||
#if 0 // This section of code is now done in History_Init
|
||||
|
||||
for (i=0 ; i<32 ; i++)
|
||||
{
|
||||
|
@ -696,6 +761,7 @@ void Key_Init (void)
|
|||
key_lines[i][1] = 0;
|
||||
}
|
||||
key_linepos = 1;
|
||||
#endif
|
||||
|
||||
key_blinktime = realtime; //johnfitz
|
||||
|
||||
|
|
Loading…
Reference in a new issue