2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* File ..................: bbs/fsedit.c
|
|
|
|
* Purpose ...............: FullScreen Message editor.
|
2001-10-21 05:13:30 +00:00
|
|
|
* Last modification date : 20-Oct-2001
|
2001-08-17 05:46:24 +00:00
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
* Copyright (C) 1997-2001
|
|
|
|
*
|
|
|
|
* Michiel Broek FIDO: 2:280/2802
|
|
|
|
* Beekmansbos 10
|
|
|
|
* 1971 BV IJmuiden
|
|
|
|
* the Netherlands
|
|
|
|
*
|
|
|
|
* This file is part of MBSE BBS.
|
|
|
|
*
|
|
|
|
* This BBS is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* MBSE BBS is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MBSE BBS; see the file COPYING. If not, write to the Free
|
|
|
|
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "fsedit.h"
|
|
|
|
|
|
|
|
|
|
|
|
void Show_Ins(void)
|
|
|
|
{
|
|
|
|
locate(1, 70);
|
|
|
|
colour(YELLOW, BLUE);
|
2001-10-21 18:08:47 +00:00
|
|
|
printf("%s", InsMode ? "INS": "OVR");
|
2001-08-17 05:46:24 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Top_Help()
|
|
|
|
{
|
|
|
|
locate(1,1);
|
|
|
|
colour(YELLOW, BLUE);
|
|
|
|
printf("%s", padleft((char *)"Press ESC for menu, other keys is edit text", 80, ' '));
|
|
|
|
Show_Ins();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Top_Menu(void)
|
|
|
|
{
|
|
|
|
locate(1,1);
|
|
|
|
colour(WHITE, RED);
|
|
|
|
printf("%s", padleft((char *)"(A)bort (H)elp (S)ave - Any other key is continue edit", 80, ' '));
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ls(int a, int y)
|
|
|
|
{
|
|
|
|
locate(y, 10);
|
|
|
|
printf("%c ", a ? 179 : '|');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Rs(int a)
|
|
|
|
{
|
|
|
|
colour(LIGHTGREEN, BLUE);
|
|
|
|
printf("%c", a ? 179 : '|');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Ws(int a, int y)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
Ls(a, y);
|
|
|
|
for (i = 0; i < 57; i++)
|
|
|
|
printf(" ");
|
|
|
|
Rs(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Hl(int a, int y, char *txt)
|
|
|
|
{
|
|
|
|
Ls(a, y);
|
|
|
|
colour(WHITE, BLUE);
|
|
|
|
printf("%s", padleft(txt, 57, ' '));
|
|
|
|
Rs(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Full_Help(void)
|
|
|
|
{
|
|
|
|
int a, i;
|
|
|
|
|
|
|
|
a = exitinfo.GraphMode;
|
|
|
|
|
|
|
|
colour(LIGHTGREEN, BLUE);
|
|
|
|
|
|
|
|
/* Top row */
|
|
|
|
locate(1, 10);
|
|
|
|
printf("%c", a ? 213 : '+');
|
|
|
|
for (i = 0; i < 58; i++)
|
|
|
|
printf("%c", a ? 205 : '=');
|
|
|
|
printf("%c", a ? 184 : '+');
|
|
|
|
|
|
|
|
Ws(a, 2);
|
|
|
|
|
|
|
|
Ls(a, 3);
|
|
|
|
colour(YELLOW, BLUE);
|
|
|
|
printf("%s", padleft((char *)" Editor Help", 57, ' '));
|
|
|
|
Rs(a);
|
|
|
|
|
|
|
|
Ws(a, 4);
|
|
|
|
Hl(a, 5, (char *)"Ctrl-S or LeftArrow - Cursor left");
|
|
|
|
Hl(a, 6, (char *)"Ctrl-D or RightArrow - Cursor right");
|
|
|
|
Hl(a, 7, (char *)"Ctrl-E or UpArrow - Cursor up");
|
|
|
|
Hl(a, 8, (char *)"Ctrl-X or DownArrow - Cursor down");
|
|
|
|
Hl(a, 9, (char *)"Ctrl-V or Insert - Insert or Overwrite");
|
|
|
|
Hl(a, 10, (char *)"Ctrl-N - Insert line");
|
|
|
|
Hl(a, 11, (char *)"Ctrl-Y - Delete line");
|
|
|
|
Ws(a, 12);
|
|
|
|
Hl(a, 13, (char *)"Ctrl-L - Refresh screen");
|
|
|
|
Hl(a, 14, (char *)"Ctrl-R - Read from file");
|
|
|
|
Ws(a, 15);
|
|
|
|
|
|
|
|
locate(16,10);
|
|
|
|
printf("%c", a ? 212 : '+');
|
|
|
|
for (i = 0; i < 58; i++)
|
|
|
|
printf("%c", a ? 205 : '=');
|
|
|
|
printf("%c", a ? 190 : '+');
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Setcursor(void)
|
|
|
|
{
|
|
|
|
CurRow = Row + TopVisible - 1;
|
|
|
|
locate(Row + 1, Col);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Beep(void)
|
|
|
|
{
|
|
|
|
printf("\007");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Refresh and rebuild screen in editing mode.
|
|
|
|
*/
|
|
|
|
void Refresh(void)
|
|
|
|
{
|
|
|
|
int i, j = 2;
|
|
|
|
|
|
|
|
clear();
|
|
|
|
Top_Help();
|
|
|
|
locate(j,1);
|
|
|
|
colour(CFG.TextColourF, CFG.TextColourB);
|
|
|
|
|
|
|
|
for (i = 1; i <= Line; i++) {
|
|
|
|
if ((i >= TopVisible) && (i < (TopVisible + exitinfo.iScreenLen -1))) {
|
|
|
|
locate(j, 1);
|
|
|
|
j++;
|
|
|
|
printf("%s", Message[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Setcursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Debug(void)
|
|
|
|
{
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Col=%d Row=%d TopVisible=%d Lines=%d CurRow=%d Len=%d",
|
2001-08-17 05:46:24 +00:00
|
|
|
Col, Row, TopVisible, Line, Row+TopVisible-1, strlen(Message[Row+TopVisible-1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GetstrLC(char *sStr, int iMaxlen)
|
|
|
|
{
|
|
|
|
unsigned char ch = 0;
|
|
|
|
int iPos = 0;
|
|
|
|
|
|
|
|
strcpy(sStr, "");
|
|
|
|
alarm_on();
|
|
|
|
|
|
|
|
while (ch != 13) {
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
ch = Readkey();
|
|
|
|
|
|
|
|
if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) {
|
|
|
|
if (iPos > 0) {
|
|
|
|
printf("\b \b");
|
|
|
|
sStr[--iPos] = '\0';
|
|
|
|
} else
|
|
|
|
putchar('\007');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch > 31 && ch < 127) {
|
|
|
|
if (iPos <= iMaxlen) {
|
|
|
|
iPos++;
|
|
|
|
sprintf(sStr, "%s%c", sStr, ch);
|
|
|
|
printf("%c", ch);
|
|
|
|
} else
|
|
|
|
putchar('\007');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-21 05:13:30 +00:00
|
|
|
void ScrollUp()
|
|
|
|
{
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Scroll up");
|
2001-10-21 05:13:30 +00:00
|
|
|
if (TopVisible > 12) {
|
|
|
|
TopVisible -= 12;
|
|
|
|
Row += 12;
|
|
|
|
} else {
|
2001-10-21 18:08:47 +00:00
|
|
|
Row += TopVisible - 1;
|
2001-10-21 05:13:30 +00:00
|
|
|
TopVisible = 1;
|
|
|
|
}
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-10-21 05:13:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ScrollDown()
|
|
|
|
{
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Scroll down");
|
2001-10-21 05:13:30 +00:00
|
|
|
if ((TopVisible + 12) <= Line) {
|
|
|
|
Row -= 12;
|
|
|
|
TopVisible += 12;
|
|
|
|
}
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-10-21 05:13:30 +00:00
|
|
|
}
|
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
int Fs_Edit()
|
|
|
|
{
|
|
|
|
unsigned char ch;
|
|
|
|
int i, Changed = FALSE;
|
|
|
|
char *filname, *tmpname;
|
|
|
|
FILE *fd;
|
|
|
|
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Entering FullScreen editor");
|
2001-08-17 05:46:24 +00:00
|
|
|
clear();
|
|
|
|
fflush(stdout);
|
|
|
|
if ((ttyfd = open("/dev/tty", O_RDWR|O_NONBLOCK)) < 0) {
|
|
|
|
WriteError("$Can't open tty");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
Setraw();
|
|
|
|
InsMode = TRUE;
|
|
|
|
TopVisible = 1;
|
|
|
|
Col = 1;
|
|
|
|
Row = 1;
|
|
|
|
Refresh();
|
|
|
|
Debug();
|
|
|
|
|
|
|
|
while (TRUE) {
|
|
|
|
Nopper();
|
|
|
|
alarm_on();
|
|
|
|
ch = Readkey();
|
|
|
|
CurRow = Row + TopVisible - 1;
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case KEY_ENTER:
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Enter pressed");
|
2001-08-17 05:46:24 +00:00
|
|
|
Debug();
|
|
|
|
if (Col == 1) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Enter at beginning of line */
|
2001-08-17 05:46:24 +00:00
|
|
|
for (i = Line; i >= CurRow; i--) {
|
|
|
|
sprintf(Message[i+1], "%s", Message[i]);
|
|
|
|
}
|
|
|
|
Message[i+1][0] = '\0';
|
|
|
|
} else {
|
|
|
|
for (i = Line; i > CurRow; i--) {
|
|
|
|
sprintf(Message[i+1], "%s", Message[i]);
|
|
|
|
}
|
|
|
|
Message[CurRow+1][0] = '\0';
|
|
|
|
if (Col <= strlen(Message[CurRow])) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Enter in middle of line */
|
2001-08-17 05:46:24 +00:00
|
|
|
for (i = Col-1; i <= strlen(Message[CurRow]); i++) {
|
|
|
|
sprintf(Message[CurRow+1], "%s%c", Message[CurRow+1], Message[CurRow][i]);
|
|
|
|
}
|
|
|
|
Message[CurRow][Col-1] = '\0';
|
|
|
|
}
|
2001-10-21 18:08:47 +00:00
|
|
|
/* else Enter at end of line */
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
Line++;
|
|
|
|
Row++;
|
|
|
|
Col = 1;
|
2001-10-21 18:08:47 +00:00
|
|
|
if (Row >= (exitinfo.iScreenLen -1)) ScrollDown();
|
2001-08-17 05:46:24 +00:00
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
Changed = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ('N' - 64): /* Insert line, scroll down */
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Insert line");
|
2001-08-17 05:46:24 +00:00
|
|
|
Debug();
|
|
|
|
for (i = Line; i >= CurRow; i--)
|
|
|
|
sprintf(Message[i+1], "%s", Message[i]);
|
|
|
|
Message[CurRow][0] = '\0';
|
|
|
|
Line++;
|
|
|
|
Col = 1;
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
Changed = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ('Y' - 64): /* Erase line, scroll up */
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Erase line");
|
2001-08-17 05:46:24 +00:00
|
|
|
Debug();
|
|
|
|
if (Line == CurRow) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Erasing last line */
|
|
|
|
if ((Line > 1) || (strlen(Message[CurRow]) > 0)) {
|
2001-08-17 05:46:24 +00:00
|
|
|
Message[CurRow][0] = '\0';
|
2001-10-21 18:08:47 +00:00
|
|
|
if (Line > 1) {
|
|
|
|
Line--;
|
|
|
|
if (Row == 1) ScrollUp();
|
2001-08-17 05:46:24 +00:00
|
|
|
Row--;
|
2001-10-21 18:08:47 +00:00
|
|
|
}
|
|
|
|
if (Col > strlen(Message[CurRow]))
|
|
|
|
Col = strlen(Message[CurRow]);
|
2001-08-17 05:46:24 +00:00
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
Changed = TRUE;
|
|
|
|
} else
|
|
|
|
Beep();
|
|
|
|
} else {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Erasing line in the middle */
|
2001-08-17 05:46:24 +00:00
|
|
|
for (i = CurRow; i < Line; i++) {
|
|
|
|
sprintf(Message[i], "%s", Message[i+1]);
|
|
|
|
}
|
|
|
|
Message[i+1][0] = '\0';
|
|
|
|
Line--;
|
|
|
|
if (Col > strlen(Message[CurRow]) + 1)
|
|
|
|
Col = strlen(Message[CurRow]) + 1;
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
Changed = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_UP:
|
|
|
|
case ('E' - 64):
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Cursor up");
|
|
|
|
Debug();
|
2001-08-17 05:46:24 +00:00
|
|
|
if (Row > 1) {
|
|
|
|
Row--;
|
2001-10-21 18:08:47 +00:00
|
|
|
if (Col > strlen(Message[CurRow-1]) + 1)
|
|
|
|
Col = strlen(Message[CurRow-1]) + 1;
|
2001-08-17 05:46:24 +00:00
|
|
|
Setcursor();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
} else {
|
2001-10-21 05:13:30 +00:00
|
|
|
ScrollUp();
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_DOWN:
|
|
|
|
case ('X' - 64):
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Cursor down");
|
2001-08-17 05:46:24 +00:00
|
|
|
Debug();
|
|
|
|
if (Row < (Line - TopVisible + 1)) {
|
|
|
|
if (Row < (exitinfo.iScreenLen -1)) {
|
|
|
|
Row++;
|
2001-10-21 18:08:47 +00:00
|
|
|
if (Col > strlen(Message[CurRow+1]) + 1)
|
|
|
|
Col = strlen(Message[CurRow+1]) + 1;
|
2001-08-17 05:46:24 +00:00
|
|
|
Setcursor();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
} else {
|
2001-10-21 05:13:30 +00:00
|
|
|
ScrollDown();
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
Beep();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_LEFT:
|
|
|
|
case ('S' - 64):
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Cursor left");
|
|
|
|
Debug();
|
2001-08-17 05:46:24 +00:00
|
|
|
if (Col > 1) {
|
|
|
|
Col--;
|
|
|
|
Setcursor();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-10-21 05:13:30 +00:00
|
|
|
} else if (CurRow > 1) {
|
|
|
|
Col = strlen(Message[CurRow-1]) +1;
|
|
|
|
if (Row == 1) ScrollUp();
|
|
|
|
Row--;
|
|
|
|
Setcursor();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-10-21 05:13:30 +00:00
|
|
|
} else if (TopVisible > 12) {
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
} else
|
|
|
|
Beep();
|
2001-10-21 05:13:30 +00:00
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_RIGHT:
|
|
|
|
case ('D' - 64):
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Cursor Right");
|
|
|
|
Debug();
|
2001-08-17 05:46:24 +00:00
|
|
|
if (Col <= strlen(Message[CurRow])) {
|
|
|
|
Col++;
|
|
|
|
Setcursor();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-10-21 05:13:30 +00:00
|
|
|
} else if (Row < (Line - TopVisible +1)) {
|
|
|
|
Row++;
|
|
|
|
Col = 1;
|
|
|
|
if (Row > (exitinfo.iScreenLen -1)) ScrollDown();
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
} else
|
|
|
|
Beep();
|
2001-10-21 05:13:30 +00:00
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_DEL:
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: DEL key");
|
|
|
|
Debug();
|
2001-08-17 05:46:24 +00:00
|
|
|
if (Col <= strlen(Message[CurRow])) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/*
|
|
|
|
* If before the end of the line...
|
|
|
|
*/
|
2001-08-17 05:46:24 +00:00
|
|
|
Setcursor();
|
|
|
|
for (i = Col; i <= strlen(Message[CurRow]); i++) {
|
|
|
|
Message[CurRow][i-1] = Message[CurRow][i];
|
|
|
|
printf("%c", Message[CurRow][i]);
|
|
|
|
}
|
|
|
|
printf(" \b");
|
2001-10-21 05:13:30 +00:00
|
|
|
Message[CurRow][i-1] = '\0';
|
2001-08-17 05:46:24 +00:00
|
|
|
Setcursor();
|
2001-10-23 05:45:07 +00:00
|
|
|
} else if (((strlen(Message[CurRow]) + strlen(Message[CurRow+1]) < 75)
|
|
|
|
|| (strlen(Message[CurRow]) == 0))
|
|
|
|
&& (CurRow < Line)) {
|
2001-10-21 05:13:30 +00:00
|
|
|
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();
|
2001-08-17 05:46:24 +00:00
|
|
|
} else
|
|
|
|
Beep();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trap the extra code so it isn't
|
|
|
|
* inserted in the text
|
|
|
|
*/
|
|
|
|
ch = Readkey();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_BACKSPACE:
|
|
|
|
case KEY_RUBOUT:
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: BS (Backspace)");
|
|
|
|
Debug();
|
2001-08-17 05:46:24 +00:00
|
|
|
if (Col == 1 && CurRow == 1) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* BS on first character in message */
|
2001-08-17 05:46:24 +00:00
|
|
|
Beep();
|
|
|
|
} else if (Col == 1) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* BS at beginning of line */
|
2001-10-21 05:13:30 +00:00
|
|
|
if ((strlen(Message[CurRow-1]) + strlen(Message[CurRow]) < 75)
|
|
|
|
|| strlen(Message[CurRow]) == 0) {
|
2001-08-17 05:46:24 +00:00
|
|
|
Col = strlen(Message[CurRow-1]) + 1;
|
|
|
|
strcat(Message[CurRow-1], Message[CurRow]);
|
|
|
|
for ( i = CurRow; i < Line; i++)
|
|
|
|
sprintf(Message[i], "%s", Message[i+1]);
|
|
|
|
Message[i+1][0] = '\0';
|
|
|
|
Line--;
|
2001-10-21 05:13:30 +00:00
|
|
|
if (Row == 1) ScrollUp();
|
2001-08-17 05:46:24 +00:00
|
|
|
Row--;
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
Changed = TRUE;
|
2001-10-21 05:13:30 +00:00
|
|
|
} else {
|
|
|
|
i = strlen(Message[CurRow-1]) + strlen(Message[CurRow]);
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: BS lines are too big! %d + %d = %d",
|
2001-10-21 05:13:30 +00:00
|
|
|
strlen(Message[CurRow]),
|
|
|
|
strlen(Message[CurRow-1]),
|
|
|
|
i);
|
|
|
|
Beep();
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
} else {
|
|
|
|
if (Col == strlen(Message[CurRow]) + 1) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* BS at end of line */
|
2001-08-17 05:46:24 +00:00
|
|
|
printf("\b \b");
|
|
|
|
fflush(stdout);
|
|
|
|
Col--;
|
|
|
|
Message[CurRow][Col-1] = '\0';
|
|
|
|
Changed = TRUE;
|
|
|
|
} else {
|
2001-10-21 18:08:47 +00:00
|
|
|
/* BS in middle of line */
|
2001-08-17 05:46:24 +00:00
|
|
|
Col--;
|
|
|
|
Setcursor();
|
2001-10-21 05:13:30 +00:00
|
|
|
for (i = Col; i <= strlen(Message[CurRow]); i++) {
|
2001-08-17 05:46:24 +00:00
|
|
|
Message[CurRow][i-1] = Message[CurRow][i];
|
|
|
|
printf("%c", Message[CurRow][i]);
|
|
|
|
}
|
|
|
|
printf(" \b");
|
|
|
|
Message[CurRow][strlen(Message[CurRow])] = '\0';
|
|
|
|
Setcursor();
|
|
|
|
Changed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-10-21 05:13:30 +00:00
|
|
|
case KEY_INS: /* Toggle Insert Mode */
|
2001-08-17 05:46:24 +00:00
|
|
|
case ('V' - 64):
|
2001-10-21 05:13:30 +00:00
|
|
|
InsMode = !InsMode;
|
2001-08-17 05:46:24 +00:00
|
|
|
Show_Ins();
|
|
|
|
colour(CFG.TextColourF, CFG.TextColourB);
|
|
|
|
Setcursor();
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: InsertMode now %s", InsMode ? "True" : "False");
|
2001-08-17 05:46:24 +00:00
|
|
|
/*
|
|
|
|
* Trap the extra code so it isn't
|
|
|
|
* inserted in the text
|
|
|
|
*/
|
|
|
|
ch = Readkey();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ('L' - 64): /* Refresh screen */
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Refresh()");
|
2001-08-17 05:46:24 +00:00
|
|
|
Refresh();
|
|
|
|
Debug();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ('R' - 64): /* Read from file */
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Read from file");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
tmpname = calloc(PATH_MAX, sizeof(char));
|
|
|
|
filname = calloc(PATH_MAX, sizeof(char));
|
|
|
|
|
|
|
|
colour(14, 0);
|
|
|
|
/* Please enter filename: */
|
|
|
|
printf("\n%s", (char *) Language(245));
|
|
|
|
colour(CFG.InputColourF, CFG.InputColourB);
|
|
|
|
GetstrLC(filname, 80);
|
|
|
|
|
|
|
|
if ((strcmp(filname, "") == 0)) {
|
|
|
|
colour(CFG.HiliteF, CFG.HiliteB);
|
|
|
|
/* No filename entered, aborting */
|
|
|
|
printf("\n\n%s\n", (char *) Language(246));
|
|
|
|
Pause();
|
|
|
|
free(filname);
|
|
|
|
free(tmpname);
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*(filname) == '/' || *(filname) == ' ') {
|
|
|
|
colour(CFG.HiliteF, CFG.HiliteB);
|
|
|
|
/* Illegal filename */
|
|
|
|
printf("\n\n%s\n", (char *) Language(247));
|
|
|
|
Pause();
|
|
|
|
free(tmpname);
|
|
|
|
free(filname);
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf(tmpname, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, filname);
|
|
|
|
if ((fd = fopen(tmpname, "r")) == NULL) {
|
|
|
|
WriteError("$Can't open %s", tmpname);
|
|
|
|
colour(CFG.HiliteF, CFG.HiliteB);
|
|
|
|
/* File does not exist, please try again */
|
|
|
|
printf("\n\n%s\n", (char *) Language(296));
|
|
|
|
Pause();
|
|
|
|
} else {
|
|
|
|
while ((fgets(filname, 80, fd)) != NULL) {
|
|
|
|
for (i = 0; i < strlen(filname); i++) {
|
|
|
|
if (*(filname + i) == '\0')
|
|
|
|
break;
|
|
|
|
if (*(filname + i) == '\n')
|
|
|
|
*(filname + i) = '\0';
|
|
|
|
if (*(filname + i) == '\r')
|
|
|
|
*(filname + i) = '\0';
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Make sure that any tear or origin lines are
|
|
|
|
* made invalid.
|
|
|
|
*/
|
|
|
|
if (strncmp(filname, (char *)"--- ", 4) == 0)
|
|
|
|
filname[1] = 'v';
|
|
|
|
if (strncmp(filname, (char *)" * Origin:", 10) == 0)
|
|
|
|
filname[1] = '+';
|
|
|
|
sprintf(Message[Line], "%s", filname);
|
|
|
|
Line++;
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
Changed = TRUE;
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('+', "FSEDIT: Inserted file %s", tmpname);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(tmpname);
|
|
|
|
free(filname);
|
|
|
|
Col = 1;
|
2001-10-21 18:08:47 +00:00
|
|
|
Refresh();
|
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KEY_ESCAPE: /* Editor menu */
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Escape pressed");
|
2001-08-17 05:46:24 +00:00
|
|
|
Top_Menu();
|
|
|
|
|
|
|
|
ch = toupper(Readkey());
|
|
|
|
if (ch == 'A' || ch == 'S') {
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: %s message (%c)", (ch == 'S' && Changed) ? "Saving" : "Aborting", ch);
|
2001-08-17 05:46:24 +00:00
|
|
|
Unsetraw();
|
|
|
|
close(ttyfd);
|
|
|
|
Debug();
|
|
|
|
clear();
|
|
|
|
fflush(stdout);
|
|
|
|
for (i = 1; i <= Line; i++)
|
2001-10-21 05:13:30 +00:00
|
|
|
Syslog('b', "%3d \"%s\"", i, Message[i]);
|
2001-08-17 05:46:24 +00:00
|
|
|
if (ch == 'S' && Changed) {
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('+', "FSEDIT: Message saved");
|
2001-08-17 05:46:24 +00:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('+', "FSEDIT: Message aborted");
|
2001-08-17 05:46:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == 'H') {
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: User wants help");
|
2001-08-17 05:46:24 +00:00
|
|
|
Full_Help();
|
|
|
|
ch = Readkey();
|
|
|
|
Refresh();
|
|
|
|
} else
|
|
|
|
Top_Help();
|
|
|
|
|
|
|
|
colour(CFG.TextColourF, CFG.TextColourB);
|
|
|
|
Setcursor();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (ch > 31 && ch < 127) {
|
|
|
|
/*
|
|
|
|
* Normal printable characters
|
|
|
|
*/
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
if (Col == strlen(Message[CurRow]) + 1) {
|
|
|
|
/*
|
|
|
|
* Append to line
|
|
|
|
*/
|
|
|
|
if (Col < 79) {
|
|
|
|
Col++;
|
|
|
|
sprintf(Message[CurRow], "%s%c", Message[CurRow], ch);
|
|
|
|
printf("%c", ch);
|
|
|
|
fflush(stdout);
|
|
|
|
Changed = TRUE;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Do simple word wrap
|
|
|
|
*/
|
|
|
|
for (i = Line; i > CurRow; i--) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/*
|
|
|
|
* Shift lines down by one
|
|
|
|
*/
|
2001-08-17 05:46:24 +00:00
|
|
|
sprintf(Message[i+1], "%s", Message[i]);
|
|
|
|
}
|
2001-10-21 18:08:47 +00:00
|
|
|
/*
|
|
|
|
* Clear row for wrapped words
|
|
|
|
*/
|
2001-08-17 05:46:24 +00:00
|
|
|
Message[CurRow+1][0] = '\0';
|
|
|
|
Col = 74;
|
|
|
|
while (Message[CurRow][Col] != ' ' && i != 0)
|
|
|
|
Col--;
|
|
|
|
Col++;
|
|
|
|
if (Col <= strlen(Message[CurRow])) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/*
|
|
|
|
* Move end of line to new row
|
|
|
|
*/
|
2001-08-17 05:46:24 +00:00
|
|
|
for (i = Col; i <= strlen(Message[CurRow]); i++) {
|
|
|
|
sprintf(Message[CurRow+1], "%s%c", Message[CurRow+1], Message[CurRow][i]);
|
|
|
|
}
|
|
|
|
Message[CurRow][Col-1] = '\0';
|
|
|
|
}
|
|
|
|
sprintf(Message[CurRow+1], "%s%c", Message[CurRow+1], ch);
|
|
|
|
Line++;
|
|
|
|
Row++;
|
|
|
|
Col = strlen(Message[CurRow+1])+1;
|
|
|
|
Refresh();
|
2001-10-21 18:08:47 +00:00
|
|
|
/* Debug(); */
|
2001-08-17 05:46:24 +00:00
|
|
|
Changed = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Insert or overwrite
|
|
|
|
*/
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: %s in line", InsMode ? "Insert" : "Overwrite");
|
2001-08-17 05:46:24 +00:00
|
|
|
if (InsMode) {
|
|
|
|
if (strlen(Message[CurRow]) < 80) {
|
2001-10-21 05:13:30 +00:00
|
|
|
for (i = strlen(Message[CurRow]); i >= (Col-1); i--) {
|
2001-10-21 18:08:47 +00:00
|
|
|
/*
|
|
|
|
* Shift characters right
|
|
|
|
*/
|
2001-08-17 05:46:24 +00:00
|
|
|
Message[CurRow][i+1] = Message[CurRow][i];
|
|
|
|
}
|
|
|
|
Message[CurRow][Col-1] = ch;
|
|
|
|
Col++;
|
|
|
|
locate(Row + 1, 1);
|
|
|
|
printf(Message[CurRow]);
|
|
|
|
Setcursor();
|
|
|
|
Changed = TRUE;
|
|
|
|
} else {
|
|
|
|
Beep();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Message[CurRow][Col-1] = ch;
|
|
|
|
printf("%c", ch);
|
|
|
|
fflush(stdout);
|
|
|
|
Col++;
|
|
|
|
Changed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
2001-10-21 18:08:47 +00:00
|
|
|
Syslog('b', "FSEDIT: Pressed %d (unsupported)", ch);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteError("FsEdit(): Impossible to be here");
|
|
|
|
Unsetraw();
|
|
|
|
close(ttyfd);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|