+extern cvar_t con_textsize;
+
+
+static void Key_History_Init(void)
+{
+ qfile_t *historyfile;
+ ConBuffer_Init(&history, HIST_TEXTSIZE, HIST_MAXLINES, zonemempool);
+
+ historyfile = FS_OpenRealFile("darkplaces_history.txt", "rb", false); // rb to handle unix line endings on windows too
+ if(historyfile)
+ {
+ char buf[MAX_INPUTLINE];
+ int bufpos;
+ int c;
+
+ bufpos = 0;
+ for(;;)
+ {
+ c = FS_Getc(historyfile);
+ if(c < 0 || c == 0 || c == '\r' || c == '\n')
+ {
+ if(bufpos > 0)
+ {
+ buf[bufpos] = 0;
+ ConBuffer_AddLine(&history, buf, bufpos, 0);
+ bufpos = 0;
+ }
+ if(c < 0)
+ break;
+ }
+ else
+ {
+ if(bufpos < MAX_INPUTLINE - 1)
+ buf[bufpos++] = c;
+ }
+ }
+
+ FS_Close(historyfile);
+ }
+
+ history_line = -1;
+}
+
+static void Key_History_Shutdown(void)
+{
+ // TODO write history to a file
+
+ qfile_t *historyfile = FS_OpenRealFile("darkplaces_history.txt", "w", false);
+ if(historyfile)
+ {
+ int i;
+ for(i = 0; i < CONBUFFER_LINES_COUNT(&history); ++i)
+ FS_Printf(historyfile, "%s\n", ConBuffer_GetLine(&history, i));
+ FS_Close(historyfile);
+ }
+
+ ConBuffer_Shutdown(&history);
+}
+
+static void Key_History_Push(void)
+{
+ if(key_line[1]) // empty?
+ if(strcmp(key_line, "]quit")) // putting these into the history just sucks
+ if(strncmp(key_line, "]quit ", 6)) // putting these into the history just sucks
+ ConBuffer_AddLine(&history, key_line + 1, strlen(key_line) - 1, 0);
+ Con_Printf("%s\n", key_line); // don't mark empty lines as history
+ history_line = -1;
+}