Index | FAQ | Search | Memberlist | Usergroups | Profile | Log in to check your private messages | Log in | Register

Session to Session Command History (Human Readable)

| Inside3d Forums Forum Index -> Programming Tutorials

View previous topic :: View next topic
Author | Message
--- | ---
Baker Joined: 14 Mar 2006 Posts: 1538 |

Posted: Fri Jun 25, 2010 6:18 am Post subject: Session to Session Command History (Human Readable) |

Every engine should have a command history. DarkPlaces recently got one and it makes life so much easier. PSP engines lack of a command history is a major nuisance when it comes to debugging and testing ... even with the on-screen keyboard it takes WAY too long to get things done.
Anyway, this modification is borrowed almost verbatim from ezQuake 1.9.
I feel it is superior to the incarnation in JoeQuake because the command line history is human readable and editable, whereas the JoeQuake (SonsQuake, actually ... for those who remember that engine) method ends up with a lot of 0x00 characters in it.
Anyways ...
1. Host.c
Find and add the yellow ...

Quote:
scr_disabled_for_loading = true; Host_WriteConfiguration (); if (con_initialized) History_Shutdown (); CDAudio_Shutdown ();

2a. Keys.c
Add this above the Key_Init function ...

Code:
// Added by VVD { 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);
}
}
// } Added by VVD

2b. Still keys.c ...
Find ...

Code:
#define MAXCMDLINE 256 char key_lines[32][MAXCMDLINE];

And replace with ...

Code:
#define HISTORY_FILE_NAME "id1/quake_history.txt" #define MAXCMDLINE 256 #define CMDLINES 32 char key_lines[CMDLINES][MAXCMDLINE];

We are defining the save history name (which I don't believe should be gamedir specific, but that's just my opinion). Plus we are changing the 32 to a #define.
2c. Still in keys.c ... finally ....

Quote:
void Key_Init (void) { int i; History_Init (); #if 0 // This section of code is now done in History_Init
for (i=0 ; i<32 ; i++)
{
key_lines[i][0] = ']';
key_lines[i][1] = 0;
}
key_linepos = 1;
#endif

_________________
Tomorrow Never Dies. I feel this Tomorrow knocking on the door ...

Back to top |

Display posts from previous:

| Inside3d Forums Forum Index -> Programming Tutorials | All times are GMT
Page 1 of 1

Jump to:

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2004 phpBB Group