Another bunch of non-functional cleanup changes to the OSD

git-svn-id: https://svn.eduke32.com/eduke32@7155 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2018-11-18 18:06:21 +00:00
parent f7fac7d9e0
commit 59fde95785
2 changed files with 280 additions and 271 deletions

View file

@ -176,6 +176,7 @@ typedef struct
osdcvar_t *cvars; osdcvar_t *cvars;
uint32_t numcvars; uint32_t numcvars;
osdsymbol_t *symbols;
osdsymbol_t *symbptrs[OSDMAXSYMBOLS]; osdsymbol_t *symbptrs[OSDMAXSYMBOLS];
int32_t numsymbols; int32_t numsymbols;

View file

@ -15,7 +15,6 @@
#include "common.h" #include "common.h"
#include "editor.h" #include "editor.h"
static osdsymbol_t *osd_symbols = NULL;
static osdsymbol_t *osd_addsymbol(const char *name); static osdsymbol_t *osd_addsymbol(const char *name);
static osdsymbol_t *osd_findsymbol(const char *pszName, osdsymbol_t *pSymbol); static osdsymbol_t *osd_findsymbol(const char *pszName, osdsymbol_t *pSymbol);
static osdsymbol_t *osd_findexactsymbol(const char *pszName); static osdsymbol_t *osd_findexactsymbol(const char *pszName);
@ -30,15 +29,17 @@ static void _internal_clearbackground(int32_t,int32_t);
static int32_t _internal_gettime(void); static int32_t _internal_gettime(void);
static void _internal_onshowosd(int32_t); static void _internal_onshowosd(int32_t);
osdmain_t *osd = NULL; osdmain_t *osd;
static int osdrowscur = -1; static int osdrowscur = -1;
static int osdmaxrows = 20; static int osdmaxrows = 20;
BFILE *osdlog;
const char* osdlogfn;
static int32_t osdkeytime = 0;
static int osdscrtime = 0;
BFILE *osdlog;
const char *osdlogfn;
static uint32_t osdkeytime = 0;
static uint32_t osdscrtime = 0;
#define OSD_EDIT_LINE_WIDTH (osd->draw.cols - 1 - 3) #define OSD_EDIT_LINE_WIDTH (osd->draw.cols - 1 - 3)
@ -414,38 +415,48 @@ static void _internal_onshowosd(int32_t a)
static int osdfunc_alias(osdcmdptr_t parm) static int osdfunc_alias(osdcmdptr_t parm)
{ {
osdsymbol_t *i;
if (parm->numparms < 1) if (parm->numparms < 1)
{ {
int32_t j = 0; int cnt = 0;
OSD_Printf("Alias listing:\n"); OSD_Printf("Alias listing:\n");
for (i=osd_symbols; i!=NULL; i=i->next)
if (i->func == OSD_ALIAS) for (auto &symbptr : osd->symbptrs)
{ {
j++; if (!symbptr->func || !symbptr->name)
OSD_Printf(" %s \"%s\"\n", i->name, i->help); break;
else if (symbptr->func == OSD_ALIAS)
{
cnt++;
OSD_Printf(" %s \"%s\"\n", symbptr->name, symbptr->help);
} }
if (j == 0) }
if (cnt == 0)
OSD_Printf("No aliases found.\n"); OSD_Printf("No aliases found.\n");
return OSDCMD_OK; return OSDCMD_OK;
} }
for (i=osd_symbols; i!=NULL; i=i->next) for (auto &symbptr : osd->symbptrs)
{ {
if (!Bstrcasecmp(parm->parms[0],i->name)) if (!symbptr->func || !symbptr->name)
break;
else if (!Bstrcasecmp(parm->parms[0], symbptr->name))
{ {
if (parm->numparms < 2) if (parm->numparms < 2)
{ {
if (i->func == OSD_ALIAS) if (symbptr->func == OSD_ALIAS)
OSD_Printf("alias %s \"%s\"\n", i->name, i->help); OSD_Printf("alias %s \"%s\"\n", symbptr->name, symbptr->help);
else OSD_Printf("%s is a function, not an alias\n",i->name); else
OSD_Printf("%s is not an alias\n", symbptr->name);
return OSDCMD_OK; return OSDCMD_OK;
} }
else if (symbptr->func != OSD_ALIAS && symbptr->func != OSD_UNALIASED)
if (i->func != OSD_ALIAS && i->func != OSD_UNALIASED)
{ {
OSD_Printf("Cannot override function \"%s\" with alias\n",i->name); OSD_Printf("Cannot override a function or cvar with an alias\n");
return OSDCMD_OK; return OSDCMD_OK;
} }
} }
@ -454,7 +465,7 @@ static int osdfunc_alias(osdcmdptr_t parm)
OSD_RegisterFunction(Xstrdup(parm->parms[0]), Xstrdup(parm->parms[1]), OSD_ALIAS); OSD_RegisterFunction(Xstrdup(parm->parms[0]), Xstrdup(parm->parms[1]), OSD_ALIAS);
if (!osd->execdepth) if (!osd->execdepth)
OSD_Printf("%s\n",parm->raw); OSD_Printf("%s\n", parm->raw);
return OSDCMD_OK; return OSDCMD_OK;
} }
@ -464,7 +475,7 @@ static int osdfunc_unalias(osdcmdptr_t parm)
if (parm->numparms < 1) if (parm->numparms < 1)
return OSDCMD_SHOWHELP; return OSDCMD_SHOWHELP;
for (auto symb=osd_symbols; symb!=NULL; symb=symb->next) for (auto symb=osd->symbols; symb!=NULL; symb=symb->next)
{ {
if (!Bstrcasecmp(parm->parms[0], symb->name)) if (!Bstrcasecmp(parm->parms[0], symb->name))
{ {
@ -494,7 +505,7 @@ static int osdfunc_listsymbols(osdcmdptr_t parm)
int maxwidth = 0; int maxwidth = 0;
for (auto symb=osd_symbols; symb!=NULL; symb=symb->next) for (auto symb=osd->symbols; symb!=NULL; symb=symb->next)
if (symb->func != OSD_UNALIASED) if (symb->func != OSD_UNALIASED)
maxwidth = max<int>(maxwidth, Bstrlen(symb->name)); maxwidth = max<int>(maxwidth, Bstrlen(symb->name));
@ -512,7 +523,7 @@ static int osdfunc_listsymbols(osdcmdptr_t parm)
int const parmlen = parm->numparms ? Bstrlen(parm->parms[0]) : 0; int const parmlen = parm->numparms ? Bstrlen(parm->parms[0]) : 0;
for (auto symb=osd_symbols; symb!=NULL; symb=symb->next) for (auto symb=osd->symbols; symb!=NULL; symb=symb->next)
{ {
if (symb->func == OSD_UNALIASED || (parm->numparms == 1 && Bstrncmp(parm->parms[0], symb->name, parmlen))) if (symb->func == OSD_UNALIASED || (parm->numparms == 1 && Bstrncmp(parm->parms[0], symb->name, parmlen)))
continue; continue;
@ -547,12 +558,10 @@ static int osdfunc_listsymbols(osdcmdptr_t parm)
static int osdfunc_help(osdcmdptr_t parm) static int osdfunc_help(osdcmdptr_t parm)
{ {
osdsymbol_t *symb;
if (parm->numparms != 1) if (parm->numparms != 1)
return OSDCMD_SHOWHELP; return OSDCMD_SHOWHELP;
symb = osd_findexactsymbol(parm->parms[0]); auto symb = osd_findexactsymbol(parm->parms[0]);
if (!symb) if (!symb)
OSD_Printf("Error: no help for undefined symbol \"%s\"\n", parm->parms[0]); OSD_Printf("Error: no help for undefined symbol \"%s\"\n", parm->parms[0]);
@ -577,15 +586,17 @@ static int osdfunc_clear(osdcmdptr_t UNUSED(parm))
static int osdfunc_history(osdcmdptr_t UNUSED(parm)) static int osdfunc_history(osdcmdptr_t UNUSED(parm))
{ {
int32_t j = 0;
osdhist_t *h = &osd->history;
UNREFERENCED_CONST_PARAMETER(parm); UNREFERENCED_CONST_PARAMETER(parm);
OSD_Printf("%sCommand history:\n", osd->draw.highlight); OSD_Printf("%sCommand history:\n", osd->draw.highlight);
for (bssize_t i=osd->history.maxlines-1; i>=0; i--) auto &h = osd->history;
if (h->buf[i])
OSD_Printf("%4d \"%s\"\n", h->total - h->lines + (++j), h->buf[i]); for (int i=osd->history.maxlines-1, j=0; i>=0; i--)
{
if (h.buf[i])
OSD_Printf("%4d \"%s\"\n", h.total - h.lines + (++j), h.buf[i]);
}
return OSDCMD_OK; return OSDCMD_OK;
} }
@ -601,21 +612,25 @@ void OSD_Cleanup(void)
hash_free(&h_osd); hash_free(&h_osd);
hash_free(&h_cvars); hash_free(&h_cvars);
for (osdsymbol_t *s; osd_symbols; osd_symbols=s) for (auto &symbptr : osd->symbptrs)
{ DO_FREE_AND_NULL(symbptr);
s=osd_symbols->next;
Bfree(osd_symbols); osd->symbols = NULL;
}
MAYBE_FCLOSE_AND_NULL(osdlog);
DO_FREE_AND_NULL(osd->cvars);
DO_FREE_AND_NULL(osd->editor.buf);
DO_FREE_AND_NULL(osd->editor.tmp);
for (auto & i : osd->history.buf) for (auto & i : osd->history.buf)
DO_FREE_AND_NULL(i); DO_FREE_AND_NULL(i);
DO_FREE_AND_NULL(osd->cvars);
DO_FREE_AND_NULL(osd->editor.buf);
DO_FREE_AND_NULL(osd->editor.tmp);
DO_FREE_AND_NULL(osd->text.buf); DO_FREE_AND_NULL(osd->text.buf);
DO_FREE_AND_NULL(osd->text.fmt); DO_FREE_AND_NULL(osd->text.fmt);
DO_FREE_AND_NULL(osd->version.buf); DO_FREE_AND_NULL(osd->version.buf);
MAYBE_FCLOSE_AND_NULL(osdlog);
DO_FREE_AND_NULL(osd); DO_FREE_AND_NULL(osd);
} }
@ -651,11 +666,16 @@ static int osdfunc_toggle(osdcmdptr_t parm)
if (parm->numparms != 1) if (parm->numparms != 1)
return OSDCMD_SHOWHELP; return OSDCMD_SHOWHELP;
intptr_t i = hash_find(&h_cvars, parm->parms[0]); int i = hash_find(&h_cvars, parm->parms[0]);
if (i == -1) if (i == -1)
for (i = osd->numcvars-1; i >= 0; i--) {
if (!Bstrcasecmp(parm->parms[0], osd->cvars[i].pData->name)) break; for (i = osd->numcvars-1; i>=0; i--)
{
if (!Bstrcasecmp(parm->parms[0], osd->cvars[i].pData->name))
break;
}
}
if (i == -1 || (osd->cvars[i].pData->flags & CVAR_TYPEMASK) != CVAR_BOOL) if (i == -1 || (osd->cvars[i].pData->flags & CVAR_TYPEMASK) != CVAR_BOOL)
{ {
@ -827,78 +847,65 @@ static int OSD_FindDiffPoint(const char *str1, const char *str2)
return i; return i;
} }
static void OSD_AdjustEditorPosition(osdedit_t &e)
{
e.pos = 0;
while (e.buf[e.pos])
e.pos++;
e.len = e.pos;
if (e.pos < e.start)
{
e.end = e.pos;
e.start = e.end - OSD_EDIT_LINE_WIDTH;
if (e.start < 0)
{
e.end -= e.start;
e.start = 0;
}
}
else if (e.pos >= e.end)
{
e.start += (e.pos - e.end);
e.end += (e.pos - e.end);
}
}
static void OSD_HistoryPrev(void) static void OSD_HistoryPrev(void)
{ {
osdhist_t &history = osd->history; osdhist_t &h = osd->history;
if (history.pos >= history.lines-1) return; if (h.pos >= h.lines-1) return;
osdedit_t &editor = osd->editor; osdedit_t &e = osd->editor;
Bmemcpy(editor.buf, history.buf[++history.pos], OSDEDITLENGTH); Bmemcpy(e.buf, h.buf[++h.pos], OSDEDITLENGTH);
editor.pos = 0; OSD_AdjustEditorPosition(e);
while (editor.buf[editor.pos]) editor.pos++;
editor.len = editor.pos;
if (editor.pos < editor.start)
{
editor.end = editor.pos;
editor.start = editor.end - OSD_EDIT_LINE_WIDTH;
if (editor.start < 0)
{
editor.end -= editor.start;
editor.start = 0;
}
}
else if (editor.pos >= editor.end)
{
editor.start += (editor.pos - editor.end);
editor.end += (editor.pos - editor.end);
}
} }
static void OSD_HistoryNext(void) static void OSD_HistoryNext(void)
{ {
osdhist_t &history = osd->history; osdhist_t &h = osd->history;
if (history.pos < 0) return; if (h.pos < 0) return;
osdedit_t &editor = osd->editor; osdedit_t &e = osd->editor;
if (history.pos == 0) if (h.pos == 0)
{ {
editor.len = 0; e.len = 0;
editor.pos = 0; e.pos = 0;
editor.start = 0; e.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; e.end = OSD_EDIT_LINE_WIDTH;
history.pos = -1; h.pos = -1;
return; return;
} }
Bmemcpy(editor.buf, history.buf[--history.pos], OSDEDITLENGTH); Bmemcpy(e.buf, h.buf[--h.pos], OSDEDITLENGTH);
editor.pos = 0; OSD_AdjustEditorPosition(e);
while (editor.buf[editor.pos]) editor.pos++;
editor.len = editor.pos;
if (editor.pos < editor.start)
{
editor.end = editor.pos;
editor.start = editor.end - OSD_EDIT_LINE_WIDTH;
if (editor.start < 0)
{
editor.end -= editor.start;
editor.start = 0;
}
}
else if (editor.pos >= editor.end)
{
editor.start += (editor.pos - editor.end);
editor.end += (editor.pos - editor.end);
}
} }
// //
@ -912,8 +919,8 @@ int OSD_HandleChar(char ch)
if (!osd || (osd->flags & OSD_CAPTURE) != OSD_CAPTURE) if (!osd || (osd->flags & OSD_CAPTURE) != OSD_CAPTURE)
return ch; return ch;
osdhist_t &history = osd->history; osdhist_t &h = osd->history;
osdedit_t &editor = osd->editor; osdedit_t &ed = osd->editor;
osdsymbol_t * tabc = NULL; osdsymbol_t * tabc = NULL;
static osdsymbol_t *lastmatch = NULL; static osdsymbol_t *lastmatch = NULL;
@ -924,60 +931,60 @@ int OSD_HandleChar(char ch)
switch (ch) switch (ch)
{ {
case asc_Ctrl_A: // jump to beginning of line case asc_Ctrl_A: // jump to beginning of line
editor.pos = 0; ed.pos = 0;
editor.start = 0; ed.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; ed.end = OSD_EDIT_LINE_WIDTH;
return 0; return 0;
case asc_Ctrl_B: // move one character left case asc_Ctrl_B: // move one character left
if (editor.pos > 0) if (ed.pos > 0)
editor.pos--; ed.pos--;
return 0; return 0;
case asc_Ctrl_C: // discard line case asc_Ctrl_C: // discard line
editor.buf[editor.len] = 0; ed.buf[ed.len] = 0;
OSD_Printf("%s\n", editor.buf); OSD_Printf("%s\n", ed.buf);
editor.len = 0; ed.len = 0;
editor.pos = 0; ed.pos = 0;
editor.start = 0; ed.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; ed.end = OSD_EDIT_LINE_WIDTH;
editor.buf[0] = 0; ed.buf[0] = 0;
return 0; return 0;
case asc_Ctrl_E: // jump to end of line case asc_Ctrl_E: // jump to end of line
editor.pos = editor.len; ed.pos = ed.len;
editor.end = editor.pos; ed.end = ed.pos;
editor.start = editor.end - OSD_EDIT_LINE_WIDTH; ed.start = ed.end - OSD_EDIT_LINE_WIDTH;
if (editor.start < 0) if (ed.start < 0)
{ {
editor.start = 0; ed.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; ed.end = OSD_EDIT_LINE_WIDTH;
} }
return 0; return 0;
case asc_Ctrl_F: // move one character right case asc_Ctrl_F: // move one character right
if (editor.pos < editor.len) if (ed.pos < ed.len)
editor.pos++; ed.pos++;
return 0; return 0;
case asc_BackSpace: case asc_BackSpace:
#ifdef __APPLE__ #ifdef __APPLE__
case 127: // control h, backspace case 127: // control h, backspace
#endif #endif
if (!editor.pos || !editor.len) if (!ed.pos || !ed.len)
return 0; return 0;
if ((osd->flags & OSD_OVERTYPE) == 0) if ((osd->flags & OSD_OVERTYPE) == 0)
{ {
if (editor.pos < editor.len) if (ed.pos < ed.len)
Bmemmove(editor.buf + editor.pos - 1, editor.buf + editor.pos, editor.len - editor.pos); Bmemmove(ed.buf + ed.pos - 1, ed.buf + ed.pos, ed.len - ed.pos);
editor.len--; ed.len--;
} }
if (--editor.pos < editor.start) if (--ed.pos < ed.start)
editor.start--, editor.end--; ed.start--, ed.end--;
#ifndef __APPLE__ #ifndef __APPLE__
fallthrough__; fallthrough__;
case 127: // handled in OSD_HandleScanCode (delete) case 127: // handled in OSD_HandleScanCode (delete)
@ -992,20 +999,20 @@ int OSD_HandleChar(char ch)
{ {
int editPos, iter; int editPos, iter;
for (editPos = editor.pos; editPos > 0; editPos--) for (editPos = ed.pos; editPos > 0; editPos--)
if (editor.buf[editPos - 1] == ' ') if (ed.buf[editPos - 1] == ' ')
break; break;
for (iter = 0; editPos < editor.len && editor.buf[editPos] != ' '; iter++, editPos++) for (iter = 0; editPos < ed.len && ed.buf[editPos] != ' '; iter++, editPos++)
editor.tmp[iter] = editor.buf[editPos]; ed.tmp[iter] = ed.buf[editPos];
editor.tmp[iter] = 0; ed.tmp[iter] = 0;
if (iter > 0) if (iter > 0)
{ {
tabc = osd_findsymbol(editor.tmp, NULL); tabc = osd_findsymbol(ed.tmp, NULL);
if (tabc && tabc->next && osd_findsymbol(editor.tmp, tabc->next)) if (tabc && tabc->next && osd_findsymbol(ed.tmp, tabc->next))
{ {
osdsymbol_t *symb = tabc; osdsymbol_t *symb = tabc;
int32_t maxwidth = 0, x = 0, num = 0, diffpt; int32_t maxwidth = 0, x = 0, num = 0, diffpt;
@ -1028,10 +1035,10 @@ int OSD_HandleChar(char ch)
if (!lastmatch->next) if (!lastmatch->next)
break; break;
symb = osd_findsymbol(editor.tmp, lastmatch->next); symb = osd_findsymbol(ed.tmp, lastmatch->next);
} }
OSD_Printf("%sFound %d possible completions for \"%s\":\n", osd->draw.highlight, num, editor.tmp); OSD_Printf("%sFound %d possible completions for \"%s\":\n", osd->draw.highlight, num, ed.tmp);
maxwidth += 3; maxwidth += 3;
symb = tabc; symb = tabc;
OSD_Printf(" "); OSD_Printf(" ");
@ -1044,7 +1051,7 @@ int OSD_HandleChar(char ch)
if (!lastmatch->next) if (!lastmatch->next)
break; break;
symb = osd_findsymbol(editor.tmp, lastmatch->next); symb = osd_findsymbol(ed.tmp, lastmatch->next);
x += maxwidth; x += maxwidth;
if (x > (osd->draw.cols - maxwidth)) if (x > (osd->draw.cols - maxwidth))
@ -1066,33 +1073,33 @@ int OSD_HandleChar(char ch)
} }
else else
{ {
tabc = osd_findsymbol(editor.tmp, lastmatch->next); tabc = osd_findsymbol(ed.tmp, lastmatch->next);
if (!tabc) if (!tabc)
tabc = osd_findsymbol(editor.tmp, NULL); // wrap */ tabc = osd_findsymbol(ed.tmp, NULL); // wrap */
} }
if (tabc) if (tabc)
{ {
int editPos; int editPos;
for (editPos = editor.pos; editPos > 0; editPos--) for (editPos = ed.pos; editPos > 0; editPos--)
if (editor.buf[editPos - 1] == ' ') if (ed.buf[editPos - 1] == ' ')
break; break;
editor.len = editPos; ed.len = editPos;
for (int iter = 0; tabc->name[iter] && editor.len <= OSDEDITLENGTH - 1 && (editor.len < commonsize); editPos++, iter++, editor.len++) for (int iter = 0; tabc->name[iter] && ed.len <= OSDEDITLENGTH - 1 && (ed.len < commonsize); editPos++, iter++, ed.len++)
editor.buf[editPos] = tabc->name[iter]; ed.buf[editPos] = tabc->name[iter];
editor.pos = editor.len; ed.pos = ed.len;
editor.end = editor.pos; ed.end = ed.pos;
editor.start = editor.end - OSD_EDIT_LINE_WIDTH; ed.start = ed.end - OSD_EDIT_LINE_WIDTH;
if (editor.start < 0) if (ed.start < 0)
{ {
editor.start = 0; ed.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; ed.end = OSD_EDIT_LINE_WIDTH;
} }
lastmatch = tabc; lastmatch = tabc;
@ -1101,8 +1108,8 @@ int OSD_HandleChar(char ch)
} }
case asc_Ctrl_K: // delete all to end of line case asc_Ctrl_K: // delete all to end of line
Bmemset(editor.buf + editor.pos, 0, OSDEDITLENGTH - editor.pos); Bmemset(ed.buf + ed.pos, 0, OSDEDITLENGTH - ed.pos);
editor.len = editor.pos; ed.len = ed.pos;
return 0; return 0;
case asc_Ctrl_L: // clear screen case asc_Ctrl_L: // clear screen
@ -1112,31 +1119,31 @@ int OSD_HandleChar(char ch)
return 0; return 0;
case asc_Enter: // control m, enter case asc_Enter: // control m, enter
if (editor.len > 0) if (ed.len > 0)
{ {
editor.buf[editor.len] = 0; ed.buf[ed.len] = 0;
if (!history.buf[0] || Bstrcmp(history.buf[0], editor.buf)) if (!h.buf[0] || Bstrcmp(h.buf[0], ed.buf))
{ {
DO_FREE_AND_NULL(history.buf[history.maxlines - 1]); DO_FREE_AND_NULL(h.buf[h.maxlines - 1]);
Bmemmove(&history.buf[1], &history.buf[0], sizeof(intptr_t) * history.maxlines - 1); Bmemmove(&h.buf[1], &h.buf[0], sizeof(intptr_t) * h.maxlines - 1);
OSD_SetHistory(0, editor.buf); OSD_SetHistory(0, ed.buf);
if (history.lines < history.maxlines) if (h.lines < h.maxlines)
history.lines++; h.lines++;
history.total++; h.total++;
} }
if (history.exec++ == history.maxlines) if (h.exec++ == h.maxlines)
OSD_Printf("Buffer full! Consider increasing \"osdhistorydepth\" beyond %d.\n", --history.exec); OSD_Printf("Buffer full! Consider increasing \"osdhistorydepth\" beyond %d.\n", --h.exec);
history.pos = -1; h.pos = -1;
} }
editor.len = 0; ed.len = 0;
editor.pos = 0; ed.pos = 0;
editor.start = 0; ed.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; ed.end = OSD_EDIT_LINE_WIDTH;
return 0; return 0;
case asc_Ctrl_N: // next (ie. down arrow) case asc_Ctrl_N: // next (ie. down arrow)
@ -1148,36 +1155,36 @@ int OSD_HandleChar(char ch)
return 0; return 0;
case asc_Ctrl_U: // delete all to beginning case asc_Ctrl_U: // delete all to beginning
if (editor.pos > 0 && editor.len) if (ed.pos > 0 && ed.len)
{ {
if (editor.pos < editor.len) if (ed.pos < ed.len)
Bmemmove(editor.buf, editor.buf + editor.pos, editor.len - editor.pos); Bmemmove(ed.buf, ed.buf + ed.pos, ed.len - ed.pos);
editor.len -= editor.pos; ed.len -= ed.pos;
editor.pos = 0; ed.pos = 0;
editor.start = 0; ed.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; ed.end = OSD_EDIT_LINE_WIDTH;
} }
return 0; return 0;
case asc_Ctrl_W: // delete one word back case asc_Ctrl_W: // delete one word back
if (editor.pos > 0 && editor.len > 0) if (ed.pos > 0 && ed.len > 0)
{ {
int editPos = editor.pos; int editPos = ed.pos;
while (editPos > 0 && editor.buf[editPos - 1] == asc_Space) editPos--; while (editPos > 0 && ed.buf[editPos - 1] == asc_Space) editPos--;
while (editPos > 0 && editor.buf[editPos - 1] != asc_Space) editPos--; while (editPos > 0 && ed.buf[editPos - 1] != asc_Space) editPos--;
if (editor.pos < editor.len) if (ed.pos < ed.len)
Bmemmove(editor.buf + editPos, editor.buf + editor.pos, editor.len - editor.pos); Bmemmove(ed.buf + editPos, ed.buf + ed.pos, ed.len - ed.pos);
editor.len -= (editor.pos - editPos); ed.len -= (ed.pos - editPos);
editor.pos = editPos; ed.pos = editPos;
if (editor.pos < editor.start) if (ed.pos < ed.start)
{ {
editor.start = editor.pos; ed.start = ed.pos;
editor.end = editor.start + OSD_EDIT_LINE_WIDTH; ed.end = ed.start + OSD_EDIT_LINE_WIDTH;
} }
} }
return 0; return 0;
@ -1187,21 +1194,21 @@ int OSD_HandleChar(char ch)
{ {
if ((osd->flags & OSD_OVERTYPE) == 0) if ((osd->flags & OSD_OVERTYPE) == 0)
{ {
if (editor.len == OSDEDITLENGTH) // buffer full, can't insert another char if (ed.len == OSDEDITLENGTH) // buffer full, can't insert another char
return 0; return 0;
if (editor.pos < editor.len) if (ed.pos < ed.len)
Bmemmove(editor.buf + editor.pos + 1, editor.buf + editor.pos, editor.len - editor.pos); Bmemmove(ed.buf + ed.pos + 1, ed.buf + ed.pos, ed.len - ed.pos);
editor.len++; ed.len++;
} }
else if (editor.pos == editor.len) else if (ed.pos == ed.len)
editor.len++; ed.len++;
editor.buf[editor.pos++] = ch; ed.buf[ed.pos++] = ch;
if (editor.pos > editor.end) if (ed.pos > ed.end)
editor.start++, editor.end++; ed.start++, ed.end++;
} }
return 0; return 0;
} }
@ -1219,9 +1226,7 @@ int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
{ {
if (keyDown) if (keyDown)
{ {
draw.scrolling = (osdrowscur == -1) ? 1 : draw.scrolling = (osdrowscur == -1) ? 1 : (osdrowscur == draw.rows) ? -1 : -draw.scrolling;
(osdrowscur == draw.rows) ? -1 :
-draw.scrolling;
osdrowscur += draw.scrolling; osdrowscur += draw.scrolling;
OSD_CaptureInput(draw.scrolling == 1); OSD_CaptureInput(draw.scrolling == 1);
osdscrtime = timerGetTicks(); osdscrtime = timerGetTicks();
@ -1242,7 +1247,7 @@ int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
return 0; return 0;
} }
osdedit_t &editor = osd->editor; osdedit_t &ed = osd->editor;
osdkeytime = gettime(); osdkeytime = gettime();
switch (scanCode) switch (scanCode)
@ -1270,9 +1275,9 @@ int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
draw.head = osd->text.lines-1; draw.head = osd->text.lines-1;
else else
{ {
editor.pos = 0; ed.pos = 0;
editor.start = editor.pos; ed.start = ed.pos;
editor.end = editor.start + OSD_EDIT_LINE_WIDTH; ed.end = ed.start + OSD_EDIT_LINE_WIDTH;
} }
break; break;
@ -1281,14 +1286,14 @@ int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
draw.head = 0; draw.head = 0;
else else
{ {
editor.pos = editor.len; ed.pos = ed.len;
editor.end = editor.pos; ed.end = ed.pos;
editor.start = editor.end - OSD_EDIT_LINE_WIDTH; ed.start = ed.end - OSD_EDIT_LINE_WIDTH;
if (editor.start < 0) if (ed.start < 0)
{ {
editor.start = 0; ed.start = 0;
editor.end = OSD_EDIT_LINE_WIDTH; ed.end = OSD_EDIT_LINE_WIDTH;
} }
} }
break; break;
@ -1298,64 +1303,64 @@ int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
break; break;
case sc_LeftArrow: case sc_LeftArrow:
if (editor.pos > 0) if (ed.pos > 0)
{ {
if (osd->flags & OSD_CTRL) if (osd->flags & OSD_CTRL)
{ {
while (editor.pos > 0) while (ed.pos > 0)
{ {
if (editor.buf[editor.pos-1] != asc_Space) if (ed.buf[ed.pos-1] != asc_Space)
break; break;
editor.pos--; ed.pos--;
} }
while (editor.pos > 0) while (ed.pos > 0)
{ {
if (editor.buf[editor.pos-1] == asc_Space) if (ed.buf[ed.pos-1] == asc_Space)
break; break;
editor.pos--; ed.pos--;
} }
} }
else editor.pos--; else ed.pos--;
} }
if (editor.pos < editor.start) if (ed.pos < ed.start)
{ {
editor.end -= (editor.start - editor.pos); ed.end -= (ed.start - ed.pos);
editor.start -= (editor.start - editor.pos); ed.start -= (ed.start - ed.pos);
} }
break; break;
case sc_RightArrow: case sc_RightArrow:
if (editor.pos < editor.len) if (ed.pos < ed.len)
{ {
if (osd->flags & OSD_CTRL) if (osd->flags & OSD_CTRL)
{ {
while (editor.pos < editor.len) while (ed.pos < ed.len)
{ {
if (editor.buf[editor.pos] == asc_Space) if (ed.buf[ed.pos] == asc_Space)
break; break;
editor.pos++; ed.pos++;
} }
while (editor.pos < editor.len) while (ed.pos < ed.len)
{ {
if (editor.buf[editor.pos] != asc_Space) if (ed.buf[ed.pos] != asc_Space)
break; break;
editor.pos++; ed.pos++;
} }
} }
else editor.pos++; else ed.pos++;
} }
if (editor.pos >= editor.end) if (ed.pos >= ed.end)
{ {
editor.start += (editor.pos - editor.end); ed.start += (ed.pos - ed.end);
editor.end += (editor.pos - editor.end); ed.end += (ed.pos - ed.end);
} }
break; break;
@ -1382,13 +1387,13 @@ int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
break; break;
case sc_Delete: case sc_Delete:
if (editor.pos == editor.len || !editor.len) if (ed.pos == ed.len || !ed.len)
return 0; return 0;
if (editor.pos <= editor.len-1) if (ed.pos <= ed.len-1)
Bmemmove(editor.buf+editor.pos, editor.buf+editor.pos+1, editor.len-editor.pos-1); Bmemmove(ed.buf+ed.pos, ed.buf+ed.pos+1, ed.len-ed.pos-1);
editor.len--; ed.len--;
break; break;
} }
@ -1474,14 +1479,11 @@ void OSD_ShowDisplay(int32_t onf)
void OSD_Draw(void) void OSD_Draw(void)
{ {
uint32_t topoffs;
int32_t row, lines, x, len;
if (!osd) if (!osd)
return; return;
if (osdrowscur == 0) if (osdrowscur == 0)
OSD_ShowDisplay((osd->flags & OSD_DRAW) ? 0 : 1); OSD_ShowDisplay((osd->flags & OSD_DRAW) != OSD_DRAW);
if (osdrowscur == osd->draw.rows) if (osdrowscur == osd->draw.rows)
osd->draw.scrolling = 0; osd->draw.scrolling = 0;
@ -1515,9 +1517,9 @@ void OSD_Draw(void)
if ((osd->flags & OSD_DRAW) == 0 || !osdrowscur) return; if ((osd->flags & OSD_DRAW) == 0 || !osdrowscur) return;
topoffs = osd->draw.head * osd->draw.cols; int topoffs = osd->draw.head * osd->draw.cols;
row = osdrowscur-1; int row = osdrowscur - 1;
lines = min(osd->text.lines-osd->draw.head, osdrowscur); int lines = min(osd->text.lines - osd->draw.head, osdrowscur);
videoBeginDrawing(); videoBeginDrawing();
@ -1531,33 +1533,39 @@ void OSD_Draw(void)
// and scrolling to the top. // and scrolling to the top.
if (topoffs + osd->draw.cols-1 >= OSDBUFFERSIZE) if (topoffs + osd->draw.cols-1 >= OSDBUFFERSIZE)
break; break;
drawosdstr(0,row,osd->text.buf+topoffs,osd->draw.cols,osd->draw.textshade,osd->draw.textpal);
topoffs+=osd->draw.cols; drawosdstr(0, row, osd->text.buf + topoffs, osd->draw.cols, osd->draw.textshade, osd->draw.textpal);
topoffs += osd->draw.cols;
} }
{ int offset = ((osd->flags & (OSD_CAPS | OSD_SHIFT)) == (OSD_CAPS | OSD_SHIFT) && osd->draw.head > 0);
int32_t offset = ((osd->flags & (OSD_CAPS|OSD_SHIFT)) == (OSD_CAPS|OSD_SHIFT) && osd->draw.head > 0); int const shade = osd->draw.promptshade ? osd->draw.promptshade : (sintable[(totalclock<<4)&2047]>>11);
int32_t shade = osd->draw.promptshade?osd->draw.promptshade:(sintable[(totalclock<<4)&2047]>>11);
if (osd->draw.head == osd->text.lines-1) drawosdchar(0,osdrowscur,'~',shade,osd->draw.promptpal); if (osd->draw.head == osd->text.lines-1)
else if (osd->draw.head > 0) drawosdchar(0,osdrowscur,'^',shade,osd->draw.promptpal); drawosdchar(0, osdrowscur, '~', shade, osd->draw.promptpal);
if (osd->flags & OSD_CAPS) drawosdchar(0+(osd->draw.head > 0),osdrowscur,'C',shade,osd->draw.promptpal); else if (osd->draw.head > 0)
if (osd->flags & OSD_SHIFT) drawosdchar(1+(osd->flags & OSD_CAPS && osd->draw.head > 0),osdrowscur,'H',shade,osd->draw.promptpal); drawosdchar(0, osdrowscur, '^', shade, osd->draw.promptpal);
drawosdchar(2+offset,osdrowscur,'>',shade,osd->draw.promptpal); if (osd->flags & OSD_CAPS)
drawosdchar((osd->draw.head > 0), osdrowscur, 'C', shade, osd->draw.promptpal);
len = min(osd->draw.cols-1-3-offset, osd->editor.len-osd->editor.start); if (osd->flags & OSD_SHIFT)
for (x=len-1; x>=0; x--) drawosdchar(1 + (osd->flags & OSD_CAPS && osd->draw.head > 0), osdrowscur, 'H', shade, osd->draw.promptpal);
drawosdchar(3+x+offset,osdrowscur, osd->editor.buf[osd->editor.start+x],osd->draw.editshade<<1,osd->draw.editpal);
offset += 3+osd->editor.pos-osd->editor.start; drawosdchar(2 + offset, osdrowscur, '>', shade, osd->draw.promptpal);
int const len = min(osd->draw.cols-1-3 - offset, osd->editor.len - osd->editor.start);
for (int x=len-1; x>=0; x--)
drawosdchar(3 + x + offset, osdrowscur, osd->editor.buf[osd->editor.start+x], osd->draw.editshade<<1, osd->draw.editpal);
offset += 3 + osd->editor.pos - osd->editor.start;
drawosdcursor(offset,osdrowscur,osd->flags & OSD_OVERTYPE,osdkeytime); drawosdcursor(offset,osdrowscur,osd->flags & OSD_OVERTYPE,osdkeytime);
if (osd->version.buf) if (osd->version.buf)
drawosdstr(osd->draw.cols - osd->version.len, osdrowscur - (offset >= osd->draw.cols - osd->version.len), drawosdstr(osd->draw.cols - osd->version.len, osdrowscur - (offset >= osd->draw.cols - osd->version.len),
osd->version.buf, osd->version.len, (sintable[(totalclock<<4)&2047]>>11), osd->version.pal); osd->version.buf, osd->version.len, (sintable[(totalclock<<4)&2047]>>11), osd->version.pal);
}
videoEndDrawing(); videoEndDrawing();
} }
@ -1945,19 +1953,19 @@ static osdsymbol_t *osd_addsymbol(const char *pszName)
auto const newsymb = (osdsymbol_t *)Xcalloc(1, sizeof(osdsymbol_t)); auto const newsymb = (osdsymbol_t *)Xcalloc(1, sizeof(osdsymbol_t));
if (!osd_symbols) if (!osd->symbols)
osd_symbols = newsymb; osd->symbols = newsymb;
else else
{ {
if (!Bstrcasecmp(pszName, osd_symbols->name)) if (!Bstrcasecmp(pszName, osd->symbols->name))
{ {
auto t = osd_symbols; auto t = osd->symbols;
osd_symbols = newsymb; osd->symbols = newsymb;
osd_symbols->next = t; osd->symbols->next = t;
} }
else else
{ {
auto s = osd_symbols; auto s = osd->symbols;
while (s->next) while (s->next)
{ {
@ -1991,9 +1999,9 @@ static osdsymbol_t *osd_addsymbol(const char *pszName)
// //
static osdsymbol_t * osd_findsymbol(const char * const pszName, osdsymbol_t *pSymbol) static osdsymbol_t * osd_findsymbol(const char * const pszName, osdsymbol_t *pSymbol)
{ {
Bassert(osd_symbols != NULL); Bassert(osd->symbols != NULL);
if (!pSymbol) pSymbol = osd_symbols; if (!pSymbol) pSymbol = osd->symbols;
int const nameLen = Bstrlen(pszName); int const nameLen = Bstrlen(pszName);
@ -2011,7 +2019,7 @@ static osdsymbol_t * osd_findsymbol(const char * const pszName, osdsymbol_t *pSy
// //
static osdsymbol_t * osd_findexactsymbol(const char *pszName) static osdsymbol_t * osd_findexactsymbol(const char *pszName)
{ {
Bassert(osd_symbols != NULL); Bassert(osd->symbols != NULL);
int symbolNum = hash_find(&h_osd, pszName); int symbolNum = hash_find(&h_osd, pszName);
@ -2168,7 +2176,7 @@ void OSD_WriteAliases(FILE *fp)
{ {
Bassert(fp); Bassert(fp);
for (auto symb=osd_symbols; symb!=NULL; symb=symb->next) for (auto symb=osd->symbols; symb!=NULL; symb=symb->next)
{ {
if (symb->func == (void *)OSD_ALIAS) if (symb->func == (void *)OSD_ALIAS)
Bfprintf(fp, "alias \"%s\" \"%s\"\n", symb->name, symb->help); Bfprintf(fp, "alias \"%s\" \"%s\"\n", symb->name, symb->help);