Should be more robust

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2071 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2006-03-10 03:50:23 +00:00
parent bfd3ebbafa
commit 903ad4800b

View file

@ -60,7 +60,7 @@ qboolean editoractive; //(export)
qboolean editormodal; //doesn't return. (export) qboolean editormodal; //doesn't return. (export)
qboolean editorblocking; qboolean editorblocking;
qboolean madechanges; qboolean madechanges;
qboolean insertkeyhit; qboolean insertkeyhit=true;
qboolean useeval; qboolean useeval;
char evalstring[256]; char evalstring[256];
@ -283,7 +283,7 @@ void EditorOpenFile(char *name)
len = 0; len = 0;
for(;;) for(;;)
{ {
if (pos+len >= flen) if (pos+len >= flen || len > sizeof(line) - 16)
break; break;
line[len] = VFS_GETC(F); line[len] = VFS_GETC(F);
@ -495,7 +495,8 @@ void Editor_Key(int key)
} }
break; break;
case K_F3: case K_F3:
useeval = true; if (editprogfuncs)
useeval = true;
break; break;
case K_F4: case K_F4:
EditorSaveFile(OpenEditorFile); EditorSaveFile(OpenEditorFile);
@ -511,7 +512,8 @@ void Editor_Key(int key)
break; break;
case K_F7: case K_F7:
EditorSaveFile(OpenEditorFile); EditorSaveFile(OpenEditorFile);
Cbuf_AddText("compile\n", RESTRICT_LOCAL); if (editprogfuncs)
Cbuf_AddText("compile\n", RESTRICT_LOCAL);
break; break;
case K_F8: case K_F8:
executionlinenum = cursorlinenum; executionlinenum = cursorlinenum;
@ -520,27 +522,27 @@ void Editor_Key(int key)
case K_F9: case K_F9:
{ {
int f = 0; int f = 0;
if (editprogfuncs) if (editprogfuncs)
{ {
if (editprogfuncs->ToggleBreak(editprogfuncs, OpenEditorFile+4, cursorlinenum, 2)) if (editprogfuncs->ToggleBreak(editprogfuncs, OpenEditorFile+4, cursorlinenum, 2))
f |= 1; f |= 1;
else else
f |= 2; f |= 2;
} }
#ifndef CLIENTONLY #ifndef CLIENTONLY
else if (svprogfuncs) else if (svprogfuncs)
{ {
if (svprogfuncs->ToggleBreak(svprogfuncs, OpenEditorFile+4, cursorlinenum, 2)) if (svprogfuncs->ToggleBreak(svprogfuncs, OpenEditorFile+4, cursorlinenum, 2))
f |= 1; f |= 1;
else else
f |= 2; f |= 2;
} }
#endif #endif
if (f & 1) if (f & 1)
cursorblock->flags |= FB_BREAK; cursorblock->flags |= FB_BREAK;
else else
cursorblock->flags &= ~FB_BREAK; cursorblock->flags &= ~FB_BREAK;
} }
break; break;
case K_F10: case K_F10:
@ -619,6 +621,7 @@ void Editor_Key(int key)
cursorx = cursorblock->datalength; cursorx = cursorblock->datalength;
memcpy(cursorblock->data + cursorblock->datalength, b->data, b->datalength); memcpy(cursorblock->data + cursorblock->datalength, b->data, b->datalength);
cursorblock->datalength += b->datalength;
cursorblock->next = b->next; cursorblock->next = b->next;
if (b->next) if (b->next)
@ -661,8 +664,8 @@ void Editor_Key(int key)
cursorblock->datalength--; cursorblock->datalength--;
} }
if (cursorx >= cursorblock->datalength) if (cursorx > cursorblock->datalength)
cursorx = cursorblock->datalength-1; cursorx = cursorblock->datalength;
} }
break; break;
@ -674,7 +677,7 @@ void Editor_Key(int key)
madechanges = true; madechanges = true;
GETBLOCK(strlen(b->data+cursorx), cursorblock); GETBLOCK(b->datalength - cursorx, cursorblock);
cursorblock->next = b->next; cursorblock->next = b->next;
cursorblock->prev = b; cursorblock->prev = b;
b->next = cursorblock; b->next = cursorblock;
@ -683,8 +686,9 @@ void Editor_Key(int key)
if (cursorblock->prev) if (cursorblock->prev)
cursorblock->prev->next = cursorblock; cursorblock->prev->next = cursorblock;
strcpy(cursorblock->data, b->data+cursorx); cursorblock->datalength = b->datalength - cursorx;
b->data[cursorx] = '\0'; memcpy(cursorblock->data, b->data+cursorx, cursorblock->datalength);
b->datalength = cursorx;
cursorx = 0; cursorx = 0;
} }
@ -721,6 +725,8 @@ void Editor_Key(int key)
cursorblock->data[cursorx] = key; cursorblock->data[cursorx] = key;
cursorx++; cursorx++;
if (cursorx > cursorblock->datalength)
cursorblock->datalength = cursorx;
} }
break; break;
} }
@ -779,7 +785,7 @@ void Draw_CursorLine(int ox, int y, fileblock_t *b)
a++; a++;
} }
if (a == cx) if (a == cx)
Draw_ColouredCharacter (x+ox, y, 11); Draw_ColouredCharacter (x+ox, y, 11|CON_WHITEMASK);
} }
void Draw_NonCursorLine(int x, int y, fileblock_t *b) void Draw_NonCursorLine(int x, int y, fileblock_t *b)
@ -1037,6 +1043,9 @@ void Editor_f(void)
return; return;
} }
editprogfuncs = NULL;
useeval = false;
if (editoractive) if (editoractive)
EditorSaveFile(OpenEditorFile); EditorSaveFile(OpenEditorFile);
EditorOpenFile(Cmd_Argv(1)); EditorOpenFile(Cmd_Argv(1));