Adding "copy" command to Quake
Type "copy" in the console and all that text is now on your clipboard and you can paste it somewhere, instead of the various hassle methods of using condump (if you use an engine with that) or using -condebug + qconsole.log.
In console.c (adapted from FitzQuake's condump command)
Code: Select all
/*
================
Con_Copy_f -- Baker -- adapted from Con_Dump
================
*/
void Con_Copy_f (void)
{
char outstring[CON_TEXTSIZE]="";
int l, x;
char *line;
char buffer[1024];
// skip initial empty lines
for (l = con_current - con_totallines + 1 ; l <= con_current ; l++)
{
line = con_text + (l%con_totallines)*con_linewidth;
for (x=0 ; x<con_linewidth ; x++)
if (line[x] != ' ')
break;
if (x != con_linewidth)
break;
}
// write the remaining lines
buffer[con_linewidth] = 0;
for ( ; l <= con_current ; l++)
{
line = con_text + (l%con_totallines)*con_linewidth;
strncpy (buffer, line, con_linewidth);
for (x=con_linewidth-1 ; x>=0 ; x--)
{
if (buffer[x] == ' ')
buffer[x] = 0;
else
break;
}
for (x=0; buffer[x]; x++)
buffer[x] &= 0x7f;
strcat(outstring, va("%s\r\n", buffer));
}
Sys_CopyToClipboard(outstring);
Con_Printf ("Copied console to clipboard\n");
}
Code: Select all
Cmd_AddCommand ("copy", Con_Copy_f); // Baker - copy console to clipboard
Code: Select all
// copies given text to clipboard
void Sys_CopyToClipboard(char *text) {
char *clipText;
HGLOBAL hglbCopy;
if (!OpenClipboard(NULL))
return;
if (!EmptyClipboard()) {
CloseClipboard();
return;
}
if (!(hglbCopy = GlobalAlloc(GMEM_DDESHARE, strlen(text) + 1))) {
CloseClipboard();
return;
}
if (!(clipText = GlobalLock(hglbCopy))) {
CloseClipboard();
return;
}
strcpy((char *) clipText, text);
GlobalUnlock(hglbCopy);
SetClipboardData(CF_TEXT, hglbCopy);
CloseClipboard();
}
Code: Select all
void Sys_CopyToClipboard(char *);