Fixed MANY bugs in the full screen editor

This commit is contained in:
Ken Bowley 2001-10-21 05:13:30 +00:00
parent d19b24f6e4
commit 2d70160edd
3 changed files with 123 additions and 81 deletions

View File

@ -4165,6 +4165,7 @@ v0.33.18 27-Jul-2001
The can be switched on using mbsetup. The can be switched on using mbsetup.
Fixed security problem in Unix username and password entry. Fixed security problem in Unix username and password entry.
Now stoped nicely if started without controling tty. Now stoped nicely if started without controling tty.
Many bugs fixed in the full screen editor.
mbuseradd: mbuseradd:
Ported to work on FreeBSD. Ported to work on FreeBSD.

View File

@ -2,7 +2,7 @@
* *
* File ..................: bbs/fsedit.c * File ..................: bbs/fsedit.c
* Purpose ...............: FullScreen Message editor. * Purpose ...............: FullScreen Message editor.
* Last modification date : 23-Jul-2001 * Last modification date : 20-Oct-2001
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2001 * Copyright (C) 1997-2001
@ -44,18 +44,6 @@
#include "fsedit.h" #include "fsedit.h"
extern int Line; /* Number of lines + 1 */
extern char *Message[]; /* TEXTBUFSIZE lines of 80 chars */
int Row; /* Current row on screen */
int Col; /* Current column in text and on screen */
int TopVisible; /* First visible line of text */
int InsMode; /* Insert mode */
int CurRow; /* Current row in buffer */
void Show_Ins(void);
void Show_Ins(void) void Show_Ins(void)
{ {
locate(1, 70); locate(1, 70);
@ -68,8 +56,6 @@ void Show_Ins(void)
} }
void Top_Help(void);
void Top_Help() void Top_Help()
{ {
locate(1,1); locate(1,1);
@ -79,8 +65,6 @@ void Top_Help()
} }
void Top_Menu(void);
void Top_Menu(void) void Top_Menu(void)
{ {
locate(1,1); locate(1,1);
@ -90,8 +74,6 @@ void Top_Menu(void)
} }
void Ls(int, int);
void Ls(int a, int y) void Ls(int a, int y)
{ {
locate(y, 10); locate(y, 10);
@ -99,8 +81,6 @@ void Ls(int a, int y)
} }
void Rs(int);
void Rs(int a) void Rs(int a)
{ {
colour(LIGHTGREEN, BLUE); colour(LIGHTGREEN, BLUE);
@ -108,8 +88,6 @@ void Rs(int a)
} }
void Ws(int, int);
void Ws(int a, int y) void Ws(int a, int y)
{ {
int i; int i;
@ -121,8 +99,6 @@ void Ws(int a, int y)
} }
void Hl(int, int, char *);
void Hl(int a, int y, char *txt) void Hl(int a, int y, char *txt)
{ {
Ls(a, y); Ls(a, y);
@ -132,8 +108,6 @@ void Hl(int a, int y, char *txt)
} }
void Full_Help(void);
void Full_Help(void) void Full_Help(void)
{ {
int a, i; int a, i;
@ -178,8 +152,6 @@ void Full_Help(void)
} }
void Setcursor(void);
void Setcursor(void) void Setcursor(void)
{ {
CurRow = Row + TopVisible - 1; CurRow = Row + TopVisible - 1;
@ -188,8 +160,6 @@ void Setcursor(void)
} }
void Beep(void);
void Beep(void) void Beep(void)
{ {
printf("\007"); printf("\007");
@ -197,11 +167,9 @@ void Beep(void)
} }
/* /*
* Refresh and rebuild screen in editing mode. * Refresh and rebuild screen in editing mode.
*/ */
void Refresh(void);
void Refresh(void) void Refresh(void)
{ {
int i, j = 2; int i, j = 2;
@ -222,8 +190,6 @@ void Refresh(void)
} }
void Debug(void);
void Debug(void) void Debug(void)
{ {
Syslog('B', "Col=%d Row=%d TopVisible=%d Lines=%d CurRow=%d Len=%d", Syslog('B', "Col=%d Row=%d TopVisible=%d Lines=%d CurRow=%d Len=%d",
@ -231,8 +197,6 @@ void Debug(void)
} }
void GetstrLC(char *, int);
void GetstrLC(char *sStr, int iMaxlen) void GetstrLC(char *sStr, int iMaxlen)
{ {
unsigned char ch = 0; unsigned char ch = 0;
@ -268,6 +232,34 @@ void GetstrLC(char *sStr, int iMaxlen)
} }
void ScrollUp()
{
Syslog('b', "Scroll up");
if (TopVisible > 12) {
TopVisible -= 12;
Row += 12;
} else {
Row += TopVisible;
TopVisible = 1;
}
Refresh();
Setcursor();
Debug();
}
void ScrollDown()
{
Syslog('b', "Scroll down");
if ((TopVisible + 12) <= Line) {
Row -= 12;
TopVisible += 12;
}
Refresh();
Setcursor();
Debug();
}
int Fs_Edit() int Fs_Edit()
{ {
@ -402,15 +394,7 @@ int Fs_Edit()
Setcursor(); Setcursor();
Debug(); Debug();
} else { } else {
if (TopVisible > 12) { ScrollUp();
Syslog('B', "Scroll up");
TopVisible -= 12;
Row += 12;
Refresh();
Setcursor();
Debug();
} else
Beep();
} }
break; break;
@ -427,12 +411,7 @@ int Fs_Edit()
Setcursor(); Setcursor();
Debug(); Debug();
} else { } else {
Syslog('B', "Scroll down"); ScrollDown();
Row -= 12;
TopVisible += 12;
Refresh();
Setcursor();
Debug();
} }
} else } else
Beep(); Beep();
@ -440,39 +419,69 @@ int Fs_Edit()
case KEY_LEFT: case KEY_LEFT:
case ('S' - 64): case ('S' - 64):
Syslog('B', "Cursor left"); Syslog('b', "Cursor left Col=%d Row=%d CurRow=%d TopVisible=%d", Col, Row, CurRow, TopVisible);
if (Col > 1) { if (Col > 1) {
Col--; Col--;
Setcursor(); Setcursor();
Debug(); Debug();
} else if (CurRow > 1) {
Col = strlen(Message[CurRow-1]) +1;
if (Row == 1) ScrollUp();
CurRow--;
Row--;
Setcursor();
Debug();
} else if (TopVisible > 12) {
Refresh();
Setcursor();
Debug();
} else } else
Beep(); Beep();
break; break;
case KEY_RIGHT: case KEY_RIGHT:
case ('D' - 64): case ('D' - 64):
Syslog('B', "Cursor Right");
if (Col <= strlen(Message[CurRow])) { if (Col <= strlen(Message[CurRow])) {
Col++; Col++;
Setcursor(); Setcursor();
Debug(); Debug();
} else if (Row < (Line - TopVisible +1)) {
Row++;
CurRow++;
Col = 1;
if (Row > (exitinfo.iScreenLen -1)) ScrollDown();
Refresh();
Setcursor();
Debug();
} else } else
Beep(); Beep();
break; break;
case KEY_DEL: case KEY_DEL:
Syslog('b', "DEL key"); Syslog('b', "DEL key Col=%d Row=%d CurRow=%d", Col, Row, CurRow);
if (Col <= strlen(Message[CurRow])) { if (Col <= strlen(Message[CurRow])) {
Syslog('B', "DEL in middle of line"); Syslog('b', "DEL Col(%d) <= Length(%d)", Col, strlen(Message[CurRow]));
Debug(); Debug();
Setcursor(); Setcursor();
for (i = Col; i <= strlen(Message[CurRow]); i++) { for (i = Col; i <= strlen(Message[CurRow]); i++) {
Syslog('B', "i=%d", i); /* Syslog('b', "i=%d", i); */
Message[CurRow][i-1] = Message[CurRow][i]; Message[CurRow][i-1] = Message[CurRow][i];
printf("%c", Message[CurRow][i]); printf("%c", Message[CurRow][i]);
} }
printf(" \b"); printf(" \b");
Message[i-1] = '\0'; Message[CurRow][i-1] = '\0';
Setcursor(); Setcursor();
} else if ((strlen(Message[CurRow]) + strlen(Message[CurRow+1]) < 75) && (CurRow < Line)) {
for (i = 0; i < strlen(Message[CurRow+1]); i++)
sprintf(Message[CurRow], "%s%c", Message[CurRow], Message[CurRow+1][i]);
for (i = CurRow+1; i < Line; i++)
sprintf(Message[i], "%s", Message[i+1]);
Message[Line][0] = '\0';
Line--;
Refresh();
} else } else
Beep(); Beep();
@ -485,28 +494,38 @@ int Fs_Edit()
case KEY_BACKSPACE: case KEY_BACKSPACE:
case KEY_RUBOUT: case KEY_RUBOUT:
Syslog('B', "BS at Col=%d Row=%d CurRow=%d", Col, Row, CurRow); Syslog('b', "BS at Col=%d Row=%d CurRow=%d", Col, Row, CurRow);
if (Col == 1 && CurRow == 1) { if (Col == 1 && CurRow == 1) {
Syslog('B', "BS on first character in message"); Syslog('b', "BS on first character in message");
Beep(); Beep();
} else if (Col == 1) { } else if (Col == 1) {
if (strlen(Message[CurRow-1]) + strlen(Message[CurRow]) < 75) { Syslog('b', "BS at beginning of line");
if ((strlen(Message[CurRow-1]) + strlen(Message[CurRow]) < 75)
|| strlen(Message[CurRow]) == 0) {
Col = strlen(Message[CurRow-1]) + 1; Col = strlen(Message[CurRow-1]) + 1;
strcat(Message[CurRow-1], Message[CurRow]); strcat(Message[CurRow-1], Message[CurRow]);
for ( i = CurRow; i < Line; i++) for ( i = CurRow; i < Line; i++)
sprintf(Message[i], "%s", Message[i+1]); sprintf(Message[i], "%s", Message[i+1]);
Message[i+1][0] = '\0'; Message[i+1][0] = '\0';
Line--; Line--;
if (Row == 1) ScrollUp();
Row--; Row--;
CurRow--; CurRow--;
Refresh(); Refresh();
Setcursor(); Setcursor();
Debug(); Debug();
Changed = TRUE; Changed = TRUE;
} else Beep(); } else {
i = strlen(Message[CurRow-1]) + strlen(Message[CurRow]);
Syslog('b', "BS lines are too big! %d + %d = %d",
strlen(Message[CurRow]),
strlen(Message[CurRow-1]),
i);
Beep();
}
} else { } else {
if (Col == strlen(Message[CurRow]) + 1) { if (Col == strlen(Message[CurRow]) + 1) {
Syslog('B', "BS at end of line"); Syslog('b', "BS at end of line");
Debug(); Debug();
printf("\b \b"); printf("\b \b");
fflush(stdout); fflush(stdout);
@ -514,12 +533,12 @@ int Fs_Edit()
Message[CurRow][Col-1] = '\0'; Message[CurRow][Col-1] = '\0';
Changed = TRUE; Changed = TRUE;
} else { } else {
Syslog('B', "BS in middle of line"); Syslog('b', "BS in middle of line");
Debug(); Debug();
Col--; Col--;
Setcursor(); Setcursor();
for (i = Col; i < strlen(Message[CurRow]); i++) { for (i = Col; i <= strlen(Message[CurRow]); i++) {
Syslog('B', "i=%d", i); /* Syslog('b', "i=%d", i); */
Message[CurRow][i-1] = Message[CurRow][i]; Message[CurRow][i-1] = Message[CurRow][i];
printf("%c", Message[CurRow][i]); printf("%c", Message[CurRow][i]);
} }
@ -531,16 +550,13 @@ int Fs_Edit()
} }
break; break;
case KEY_INS: case KEY_INS: /* Toggle Insert Mode */
case ('V' - 64): case ('V' - 64):
if (InsMode) InsMode = !InsMode;
InsMode = FALSE;
else
InsMode = TRUE;
Show_Ins(); Show_Ins();
colour(CFG.TextColourF, CFG.TextColourB); colour(CFG.TextColourF, CFG.TextColourB);
Setcursor(); Setcursor();
Syslog('B', "InsertMode now %s", InsMode ? "True" : "False"); Syslog('b', "InsertMode now %s", InsMode ? "True" : "False");
/* /*
* Trap the extra code so it isn't * Trap the extra code so it isn't
* inserted in the text * inserted in the text
@ -549,7 +565,7 @@ int Fs_Edit()
break; break;
case ('L' - 64): /* Refresh screen */ case ('L' - 64): /* Refresh screen */
Syslog('B', "Refresh()"); Syslog('b', "Refresh()");
Refresh(); Refresh();
Debug(); Debug();
break; break;
@ -632,19 +648,19 @@ int Fs_Edit()
break; break;
case KEY_ESCAPE: /* Editor menu */ case KEY_ESCAPE: /* Editor menu */
Syslog('B', "Escape pressed"); Syslog('b', "Escape pressed");
Top_Menu(); Top_Menu();
ch = toupper(Readkey()); ch = toupper(Readkey());
if (ch == 'A' || ch == 'S') { if (ch == 'A' || ch == 'S') {
Syslog('B', "%s message (%c)", (ch == 'S' && Changed) ? "Saving" : "Aborting", ch); Syslog('b', "%s message (%c)", (ch == 'S' && Changed) ? "Saving" : "Aborting", ch);
Unsetraw(); Unsetraw();
close(ttyfd); close(ttyfd);
Debug(); Debug();
clear(); clear();
fflush(stdout); fflush(stdout);
for (i = 1; i <= Line; i++) for (i = 1; i <= Line; i++)
Syslog('B', "%3d \"%s\"", i, Message[i]); Syslog('b', "%3d \"%s\"", i, Message[i]);
if (ch == 'S' && Changed) { if (ch == 'S' && Changed) {
Syslog('+', "Message saved"); Syslog('+', "Message saved");
return TRUE; return TRUE;
@ -655,7 +671,7 @@ int Fs_Edit()
} }
if (ch == 'H') { if (ch == 'H') {
Syslog('B', "User wants help"); Syslog('b', "User wants help");
Full_Help(); Full_Help();
ch = Readkey(); ch = Readkey();
Refresh(); Refresh();
@ -688,16 +704,16 @@ int Fs_Edit()
*/ */
for (i = Line; i > CurRow; i--) { for (i = Line; i > CurRow; i--) {
sprintf(Message[i+1], "%s", Message[i]); sprintf(Message[i+1], "%s", Message[i]);
Syslog('B', "[WW]-Moving row %d to %d", i, i+1); Syslog('b', "[WW]-Moving row %d to %d", i, i+1);
} }
Message[CurRow+1][0] = '\0'; Message[CurRow+1][0] = '\0';
Syslog('B', "[WW]-Clearing row %d", CurRow+1); Syslog('b', "[WW]-Clearing row %d", CurRow+1);
Col = 74; Col = 74;
while (Message[CurRow][Col] != ' ' && i != 0) while (Message[CurRow][Col] != ' ' && i != 0)
Col--; Col--;
Col++; Col++;
if (Col <= strlen(Message[CurRow])) { if (Col <= strlen(Message[CurRow])) {
Syslog('B', "[WW]-Move end of line %d to new row %d", CurRow, CurRow+1); Syslog('b', "[WW]-Move end of line %d to new row %d", CurRow, CurRow+1);
for (i = Col; i <= strlen(Message[CurRow]); i++) { for (i = Col; i <= strlen(Message[CurRow]); i++) {
sprintf(Message[CurRow+1], "%s%c", Message[CurRow+1], Message[CurRow][i]); sprintf(Message[CurRow+1], "%s%c", Message[CurRow+1], Message[CurRow][i]);
} }
@ -718,8 +734,8 @@ int Fs_Edit()
Syslog('b', "%s in line", InsMode ? "Insert" : "Overwrite"); Syslog('b', "%s in line", InsMode ? "Insert" : "Overwrite");
if (InsMode) { if (InsMode) {
if (strlen(Message[CurRow]) < 80) { if (strlen(Message[CurRow]) < 80) {
for (i = strlen(Message[CurRow]); i > (Col-1); i--) { for (i = strlen(Message[CurRow]); i >= (Col-1); i--) {
Syslog('B', "(i+1=%d)[%c] = (i=%d)[%c]", i+1, Message[CurRow][i+1], i, Message[CurRow][i]); /* Syslog('b', "(i+1=%d)[%c] = (i=%d)[%c]", i+1, Message[CurRow][i+1], i, Message[CurRow][i]); */
Message[CurRow][i+1] = Message[CurRow][i]; Message[CurRow][i+1] = Message[CurRow][i];
} }
Message[CurRow][Col-1] = ch; Message[CurRow][Col-1] = ch;

View File

@ -3,5 +3,30 @@
int Fs_Edit(void); /* The fullscreen message editor */ int Fs_Edit(void); /* The fullscreen message editor */
extern int Line; /* Number of lines + 1 */
extern char *Message[]; /* TEXTBUFSIZE lines of 80 chars */
int Row; /* Current row on screen */
int Col; /* Current column in text and on screen */
int TopVisible; /* First visible line of text */
int InsMode; /* Insert mode */
int CurRow; /* Current row in buffer */
void Show_Ins(void);
void Top_Help(void);
void Top_Menu(void);
void Ls(int, int);
void Rs(int);
void Ws(int, int);
void Hl(int, int, char *);
void Full_Help(void);
void Setcursor(void);
void Beep(void);
void Refresh(void);
void Debug(void);
void GetstrLC(char *, int);
void ScrollUp(void);
void ScrollDown(void);
#endif #endif