This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbsebbs/fsedit.c

785 lines
17 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2001-11-14 21:37:58 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: FullScreen Message editor.
*
*****************************************************************************
2004-02-21 17:22:00 +00:00
* Copyright (C) 1997-2004
2001-08-17 05:46:24 +00:00
*
* 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
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-08-17 05:46:24 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbselib.h"
2001-11-12 21:42:17 +00:00
#include "../lib/mbse.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
2001-11-12 21:42:17 +00:00
#include "mail.h"
2001-11-14 21:37:58 +00:00
#include "input.h"
2001-11-12 21:42:17 +00:00
#include "language.h"
#include "timeout.h"
#include "pinfo.h"
2001-08-17 05:46:24 +00:00
#include "fsedit.h"
#include "term.h"
2004-11-03 20:48:45 +00:00
#include "ttyio.h"
2001-08-17 05:46:24 +00:00
void Show_Ins(void)
{
2003-07-01 20:02:58 +00:00
locate(1, 70);
colour(YELLOW, BLUE);
2004-11-03 20:48:45 +00:00
if (InsMode)
PUTSTR((char *)"INS");
else
PUTSTR((char *)"OVR");
2001-08-17 05:46:24 +00:00
}
void Top_Help()
{
2004-11-03 20:48:45 +00:00
char temp[81];
2003-07-01 20:02:58 +00:00
locate(1,1);
colour(YELLOW, BLUE);
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s", padleft((char *)"Press ESC for menu, other keys is edit text", 79, ' '));
PUTSTR(temp);
2003-07-01 20:02:58 +00:00
Show_Ins();
2001-08-17 05:46:24 +00:00
}
void Top_Menu(void)
{
2004-11-03 20:48:45 +00:00
char temp[81];
2003-07-01 20:02:58 +00:00
locate(1,1);
colour(WHITE, RED);
2004-11-03 20:48:45 +00:00
sprintf(temp, "%s", padleft((char *)"(A)bort (H)elp (S)ave - Any other key is continue edit", 79, ' '));
PUTSTR(temp);
2001-08-17 05:46:24 +00:00
}
void Ls(int a, int y)
{
2003-07-01 20:02:58 +00:00
locate(y, 10);
2004-11-03 20:48:45 +00:00
PUTCHAR(a ? 179 : '|');
2001-08-17 05:46:24 +00:00
}
void Rs(int a)
{
2003-07-01 20:02:58 +00:00
colour(LIGHTGREEN, BLUE);
2004-11-03 20:48:45 +00:00
PUTCHAR(a ? 179 : '|');
2001-08-17 05:46:24 +00:00
}
void Ws(int a, int y)
{
2003-07-01 20:02:58 +00:00
int i;
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
Ls(a, y);
2004-11-03 20:48:45 +00:00
for (i = 0; i < 58; i++)
PUTCHAR(' ');
2003-07-01 20:02:58 +00:00
Rs(a);
2001-08-17 05:46:24 +00:00
}
void Hl(int a, int y, char *txt)
{
2003-07-01 20:02:58 +00:00
Ls(a, y);
colour(WHITE, BLUE);
2004-11-03 20:48:45 +00:00
PUTSTR(padleft(txt, 58, ' '));
2003-07-01 20:02:58 +00:00
Rs(a);
2001-08-17 05:46:24 +00:00
}
void Full_Help(void)
{
2003-07-01 20:02:58 +00:00
int a, i;
a = exitinfo.GraphMode;
colour(LIGHTGREEN, BLUE);
/* Top row */
locate(1, 10);
2004-11-03 20:48:45 +00:00
PUTCHAR(a ? 213 : '+');
2003-07-01 20:02:58 +00:00
for (i = 0; i < 58; i++)
2004-11-03 20:48:45 +00:00
PUTCHAR(a ? 205 : '=');
PUTCHAR(a ? 184 : '+');
2003-07-01 20:02:58 +00:00
Ws(a, 2);
Ls(a, 3);
colour(YELLOW, BLUE);
2004-11-03 20:48:45 +00:00
PUTSTR(padleft((char *)" Editor Help", 58, ' '));
2003-07-01 20:02:58 +00:00
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);
2004-11-03 20:48:45 +00:00
PUTCHAR(a ? 212 : '+');
2003-07-01 20:02:58 +00:00
for (i = 0; i < 58; i++)
2004-11-03 20:48:45 +00:00
PUTCHAR(a ? 205 : '=');
PUTCHAR(a ? 190 : '+');
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
2001-08-17 05:46:24 +00:00
void Setcursor(void)
{
2003-07-01 20:02:58 +00:00
CurRow = Row + TopVisible - 1;
locate(Row + 1, Col);
2001-08-17 05:46:24 +00:00
}
void Beep(void)
{
2004-11-03 20:48:45 +00:00
PUTCHAR('\007');
2001-08-17 05:46:24 +00:00
}
/*
* Refresh and rebuild screen in editing mode.
*/
void Refresh(void)
{
2003-07-01 20:02:58 +00:00
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++;
2004-11-03 20:48:45 +00:00
PUTSTR(Message[i]);
2001-08-17 05:46:24 +00:00
}
2003-07-01 20:02:58 +00:00
}
Setcursor();
2001-08-17 05:46:24 +00:00
}
void GetstrLC(char *sStr, int iMaxlen)
{
2003-07-01 20:02:58 +00:00
unsigned char ch = 0;
int iPos = 0;
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
strcpy(sStr, "");
alarm_on();
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
while (ch != 13) {
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
ch = Readkey();
if ((ch == 8) || (ch == KEY_DEL) || (ch == 127)) {
if (iPos > 0) {
2004-11-03 20:48:45 +00:00
BackErase();
2003-07-01 20:02:58 +00:00
sStr[--iPos] = '\0';
} else {
Beep();
}
}
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
if (ch > 31 && ch < 127) {
if (iPos <= iMaxlen) {
iPos++;
sprintf(sStr, "%s%c", sStr, ch);
2004-11-03 20:48:45 +00:00
PUTCHAR(ch);
2003-07-01 20:02:58 +00:00
} else {
Beep();
}
2001-08-17 05:46:24 +00:00
}
2003-07-01 20:02:58 +00:00
}
2001-08-17 05:46:24 +00:00
2004-11-03 20:48:45 +00:00
Enter(1);
2001-08-17 05:46:24 +00:00
}
void ScrollUp()
{
2003-07-01 20:02:58 +00:00
if (TopVisible > 12) {
TopVisible -= 12;
Row += 12;
} else {
Row += TopVisible - 1;
TopVisible = 1;
}
Refresh();
}
void ScrollDown()
{
2003-07-01 20:02:58 +00:00
if ((TopVisible + 12) <= Line) {
Row -= 12;
TopVisible += 12;
}
Refresh();
}
2003-07-01 20:02:58 +00:00
void FsMove(unsigned char Direction)
{
2003-07-01 20:02:58 +00:00
switch (Direction) {
case KEY_RIGHT:
/*
2003-07-01 20:02:58 +00:00
* FIXME: FsMove KEY_RIGHT
* Handle long lines better.
* For now, we will just refuse to go past col 80
*/
2003-07-01 20:02:58 +00:00
if ((Col <= strlen(Message[CurRow])) && (Col < 80)){
Col++;
Setcursor();
} else if (Row < (Line - TopVisible +1)) {
Row++;
Col = 1;
if (Row > (exitinfo.iScreenLen -1)) ScrollDown();
Refresh();
} else
Beep();
break;
case KEY_LEFT:
if (Col > 1) {
Col--;
Setcursor();
} else if (CurRow > 1) {
Col = strlen(Message[CurRow-1]) +1;
/*
* FIXME: FsMove KEY_LEFT
* Handle long lines better.
* For now, we will just refuse to go past col 80
*/
if (Col > 80)
Col = 80;
if (Row == 1)
ScrollUp();
Row--;
Setcursor();
} else
Beep();
break;
case KEY_UP:
2003-07-01 20:02:58 +00:00
if (CurRow > 1) {
Row--;
if (Col > strlen(Message[CurRow-1]) + 1)
Col = strlen(Message[CurRow-1]) +1;
2003-07-01 20:02:58 +00:00
if ((Row < 1) && (CurRow != Row))
ScrollUp();
2003-07-01 20:02:58 +00:00
else
Setcursor();
2003-07-01 20:02:58 +00:00
} else
Beep();
break;
case KEY_DOWN:
2003-07-01 20:02:58 +00:00
if (Row < (Line - TopVisible + 1)) {
Row++;
if (Col > strlen(Message[CurRow+1]) + 1)
Col = strlen(Message[CurRow+1]) + 1;
2003-07-01 20:02:58 +00:00
if (Row <= (exitinfo.iScreenLen -1))
Setcursor();
2003-07-01 20:02:58 +00:00
else
ScrollDown();
2003-07-01 20:02:58 +00:00
} else
Beep();
break;
}
}
2003-07-01 20:02:58 +00:00
int FsWordWrap()
{
2003-07-01 20:02:58 +00:00
int WCol, i = 0;
unsigned char tmpLine[80];
tmpLine[0] = '\0';
/*
* FIXME: FsWordWrap
* The word wrap still fails the BIG WORD test
* (BIG WORD = continuous string of characters that spans multiple
* lines without any spaces)
*/
Syslog('b', "FSEDIT: Word Wrap");
WCol = 79;
while (Message[CurRow][WCol] != ' ' && WCol > 0)
WCol--;
if ((WCol > 0) && (WCol < 80))
WCol++;
else
WCol=80;
if (WCol <= strlen(Message[CurRow])) {
/*
2003-07-01 20:02:58 +00:00
* If WCol = 80 (no spaces in line) be sure to grab
* character 79. Otherwise, drop it, because it's a space.
*/
2003-07-01 20:02:58 +00:00
if ((WCol == 80) || (WCol-1 == Col))
sprintf(tmpLine, "%s%c", tmpLine, Message[CurRow][79]);
/*
* Grab all characters from WCol to end of line.
*/
for (i = WCol; i < strlen(Message[CurRow]); i++) {
sprintf(tmpLine, "%s%c", tmpLine, Message[CurRow][i]);
}
/*
* Truncate current row.
*/
Message[CurRow][WCol-1] = '\0';
/*
* If this is the last line, then be sure to create a
* new line.x
*/
if (CurRow >= Line) {
Line = CurRow+1;
Message[CurRow+1][0] = '\0';
}
2003-07-01 20:02:58 +00:00
/*
* If the wrapped section and the next row will not fit on
* one line, shift all lines down one and use the wrapped
* section to create a new line.
*
* Otherwise, slap the wrapped section on the front of the
* next row with a space if needed.
*/
if ((strlen(tmpLine) + strlen(Message[CurRow+1])) > 79) {
for (i = Line; i > CurRow; i--)
sprintf(Message[i+1], "%s", Message[i]);
sprintf(Message[CurRow+1], "%s", tmpLine);
Line++;
WCol = strlen(tmpLine) + 1;
} else {
if ((WCol == 80) && (Col >= WCol))
WCol = strlen(tmpLine)+1;
else {
if (tmpLine[strlen(tmpLine)] != ' ')
sprintf(tmpLine, "%s ", tmpLine);
WCol = strlen(tmpLine);
}
sprintf(Message[CurRow+1], "%s", strcat(tmpLine, Message[CurRow+1]));
}
}
2003-07-01 20:02:58 +00:00
return WCol;
}
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
2001-08-17 05:46:24 +00:00
int Fs_Edit()
{
2003-07-01 20:02:58 +00:00
unsigned char ch;
int i, Changed = FALSE;
char *filname, *tmpname;
FILE *fd;
Syslog('b', "FSEDIT: Entering FullScreen editor");
clear();
InsMode = TRUE;
TopVisible = 1;
Col = 1;
Row = 1;
Refresh();
while (TRUE) {
Nopper();
alarm_on();
ch = Readkey();
CurRow = Row + TopVisible - 1;
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
switch (ch) {
case KEY_ENTER:
if (Col == 1) {
/* Enter at beginning of line */
2001-08-17 05:46:24 +00:00
for (i = Line; i >= CurRow; i--) {
2003-07-01 20:02:58 +00:00
sprintf(Message[i+1], "%s", Message[i]);
2001-08-17 05:46:24 +00:00
}
Message[i+1][0] = '\0';
2003-07-01 20:02:58 +00:00
} else {
2001-08-17 05:46:24 +00:00
for (i = Line; i > CurRow; i--) {
2003-07-01 20:02:58 +00:00
sprintf(Message[i+1], "%s", Message[i]);
2001-08-17 05:46:24 +00:00
}
Message[CurRow+1][0] = '\0';
if (Col <= strlen(Message[CurRow])) {
2003-07-01 20:02:58 +00:00
/* Enter in middle of line */
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-08-17 05:46:24 +00:00
}
/* else Enter at end of line */
2003-07-01 20:02:58 +00:00
}
Line++;
Row++;
Col = 1;
if (Row >= (exitinfo.iScreenLen -1))
ScrollDown();
Refresh();
Changed = TRUE;
break;
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
case ('N' - 64): /* Insert line, scroll down */
for (i = Line; i >= CurRow; i--)
2001-08-17 05:46:24 +00:00
sprintf(Message[i+1], "%s", Message[i]);
2003-07-01 20:02:58 +00:00
Message[CurRow][0] = '\0';
Line++;
Col = 1;
Refresh();
Changed = TRUE;
break;
case ('Y' - 64): /* Erase line, scroll up */
if (Line == CurRow) {
/* Erasing last line */
if ((Line > 1) || (strlen(Message[CurRow]) > 0)) {
2003-07-01 20:02:58 +00:00
Message[CurRow][0] = '\0';
if (Line > 1) {
Line--;
if (Row == 1)
ScrollUp();
Row--;
}
if (Col > strlen(Message[CurRow]))
Col = strlen(Message[CurRow]);
Refresh();
Changed = TRUE;
} else
2003-07-01 20:02:58 +00:00
Beep();
} else {
/* Erasing line in the middle */
for (i = CurRow; i < Line; i++) {
2003-07-01 20:02:58 +00:00
sprintf(Message[i], "%s", Message[i+1]);
2001-08-17 05:46:24 +00:00
}
Message[i+1][0] = '\0';
Line--;
if (Col > strlen(Message[CurRow]) + 1)
2003-07-01 20:02:58 +00:00
Col = strlen(Message[CurRow]) + 1;
Refresh();
Changed = TRUE;
2003-07-01 20:02:58 +00:00
}
break;
case KEY_UP:
case ('E' - 64):
FsMove(KEY_UP);
break;
case KEY_DOWN:
case ('X' - 64):
FsMove(KEY_DOWN);
break;
case KEY_LEFT:
case ('S' - 64):
FsMove(KEY_LEFT);
break;
case KEY_RIGHT:
case ('D' - 64):
FsMove(KEY_RIGHT);
break;
case KEY_DEL:
if (Col <= strlen(Message[CurRow])) {
/*
* If before the end of the line...
*/
2001-08-17 05:46:24 +00:00
Setcursor();
for (i = Col; i <= strlen(Message[CurRow]); i++) {
2003-07-01 20:02:58 +00:00
Message[CurRow][i-1] = Message[CurRow][i];
2004-11-03 20:48:45 +00:00
PUTCHAR(Message[CurRow][i]);
2001-08-17 05:46:24 +00:00
}
2004-11-03 20:48:45 +00:00
PUTCHAR(' ');
PUTCHAR('\b');
Message[CurRow][i-1] = '\0';
2001-08-17 05:46:24 +00:00
Setcursor();
2003-07-01 20:02:58 +00:00
} else if (((strlen(Message[CurRow]) + strlen(Message[CurRow+1]) < 75)
|| (strlen(Message[CurRow]) == 0)) && (CurRow < Line)) {
for (i = 0; i < strlen(Message[CurRow+1]); i++)
2003-07-01 20:02:58 +00:00
sprintf(Message[CurRow], "%s%c", Message[CurRow], Message[CurRow+1][i]);
for (i = CurRow+1; i < Line; i++)
2003-07-01 20:02:58 +00:00
sprintf(Message[i], "%s", Message[i+1]);
Message[Line][0] = '\0';
Line--;
Refresh();
2003-07-01 20:02:58 +00:00
} else
2001-08-17 05:46:24 +00:00
Beep();
2003-07-01 20:02:58 +00:00
/*
* Trap the extra code so it isn't
* inserted in the text
*/
if (ch == KEY_DEL)
Readkey();
break;
case KEY_BACKSPACE:
case KEY_RUBOUT:
if (Col == 1 && CurRow == 1) {
/* BS on first character in message */
2001-08-17 05:46:24 +00:00
Beep();
2003-07-01 20:02:58 +00:00
} else if (Col == 1) {
/* BS at beginning of line */
2003-07-01 20:02:58 +00:00
if ((strlen(Message[CurRow-1]) + strlen(Message[CurRow]) < 75) || strlen(Message[CurRow]) == 0) {
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--;
if (Row == 1)
ScrollUp();
Row--;
Refresh();
Changed = TRUE;
} else {
2003-07-01 20:02:58 +00:00
i = strlen(Message[CurRow-1]) + strlen(Message[CurRow]);
Beep();
}
2003-07-01 20:02:58 +00:00
} else {
2001-08-17 05:46:24 +00:00
if (Col == strlen(Message[CurRow]) + 1) {
2003-07-01 20:02:58 +00:00
/* BS at end of line */
2004-11-03 20:48:45 +00:00
BackErase();
2003-07-01 20:02:58 +00:00
Col--;
Message[CurRow][Col-1] = '\0';
Changed = TRUE;
2001-08-17 05:46:24 +00:00
} else {
2003-07-01 20:02:58 +00:00
/* BS in middle of line */
Col--;
Setcursor();
for (i = Col; i <= strlen(Message[CurRow]); i++) {
Message[CurRow][i-1] = Message[CurRow][i];
2004-11-03 20:48:45 +00:00
PUTCHAR(Message[CurRow][i]);
2003-07-01 20:02:58 +00:00
}
2004-11-03 20:48:45 +00:00
PUTCHAR(' ');
PUTCHAR('\b');
2003-07-01 20:02:58 +00:00
Message[CurRow][strlen(Message[CurRow])] = '\0';
Setcursor();
Changed = TRUE;
2001-08-17 05:46:24 +00:00
}
2003-07-01 20:02:58 +00:00
}
break;
case KEY_INS: /* Toggle Insert Mode */
case ('V' - 64):
InsMode = !InsMode;
Show_Ins();
colour(CFG.TextColourF, CFG.TextColourB);
Setcursor();
/*
* Trap the extra code so it isn't
* inserted in the text
*/
if (ch == KEY_INS)
Readkey();
break;
case ('L' - 64): /* Refresh screen */
Refresh();
break;
case ('R' - 64): /* Read from file */
Syslog('b', "FSEDIT: Read from file");
tmpname = calloc(PATH_MAX, sizeof(char));
filname = calloc(PATH_MAX, sizeof(char));
2004-11-03 20:48:45 +00:00
Enter(1);
2003-07-01 20:02:58 +00:00
/* Please enter filename: */
2004-11-03 20:48:45 +00:00
pout(YELLOW, BLACK, (char *) Language(245));
2003-07-01 20:02:58 +00:00
colour(CFG.InputColourF, CFG.InputColourB);
GetstrLC(filname, 80);
if ((strcmp(filname, "") == 0)) {
2004-11-03 20:48:45 +00:00
Enter(2);
2001-08-17 05:46:24 +00:00
/* No filename entered, aborting */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(246));
Enter(1);
2001-08-17 05:46:24 +00:00
Pause();
free(filname);
free(tmpname);
Refresh();
break;
2003-07-01 20:02:58 +00:00
}
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
if (*(filname) == '/' || *(filname) == ' ') {
2004-11-03 20:48:45 +00:00
Enter(2);
2001-08-17 05:46:24 +00:00
/* Illegal filename */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(247));
Enter(1);
2001-08-17 05:46:24 +00:00
Pause();
free(tmpname);
free(filname);
Refresh();
break;
2003-07-01 20:02:58 +00:00
}
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
sprintf(tmpname, "%s/%s/wrk/%s", CFG.bbs_usersdir, exitinfo.Name, filname);
if ((fd = fopen(tmpname, "r")) == NULL) {
2001-08-17 05:46:24 +00:00
WriteError("$Can't open %s", tmpname);
2004-11-03 20:48:45 +00:00
Enter(2);
2001-08-17 05:46:24 +00:00
/* File does not exist, please try again */
2004-11-03 20:48:45 +00:00
pout(CFG.HiliteF, CFG.HiliteB, (char *) Language(296));
Enter(1);
2001-08-17 05:46:24 +00:00
Pause();
2003-07-01 20:02:58 +00:00
} else {
2001-08-17 05:46:24 +00:00
while ((fgets(filname, 80, fd)) != NULL) {
2003-07-01 20:02:58 +00:00
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++;
if ((Line - 1) == TEXTBUFSIZE)
break;
2001-08-17 05:46:24 +00:00
}
fclose(fd);
Changed = TRUE;
Syslog('+', "FSEDIT: Inserted file %s", tmpname);
2003-07-01 20:02:58 +00:00
}
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
free(tmpname);
free(filname);
Col = 1;
Refresh();
break;
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
case KEY_ESCAPE: /* Editor menu */
Top_Menu();
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
ch = toupper(Readkey());
if (ch == 'A' || ch == 'S') {
Syslog('b', "FSEDIT: %s message (%c)", (ch == 'S' && Changed) ? "Saving" : "Aborting", ch);
2001-08-17 05:46:24 +00:00
clear();
if (ch == 'S' && Changed) {
2003-12-08 18:01:25 +00:00
Syslog('+', "FSEDIT: Message will be saved");
2003-07-01 20:02:58 +00:00
return TRUE;
2001-08-17 05:46:24 +00:00
} else {
2003-07-01 20:02:58 +00:00
Syslog('+', "FSEDIT: Message aborted");
return FALSE;
2001-08-17 05:46:24 +00:00
}
2003-07-01 20:02:58 +00:00
}
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
if (ch == 'H') {
2001-08-17 05:46:24 +00:00
Full_Help();
ch = Readkey();
Refresh();
2003-07-01 20:02:58 +00:00
} else
2001-08-17 05:46:24 +00:00
Top_Help();
2003-07-01 20:02:58 +00:00
colour(CFG.TextColourF, CFG.TextColourB);
Setcursor();
break;
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
default:
2005-04-03 21:26:31 +00:00
if ((ch > 31) || traduce(&ch) ) {
2001-08-17 05:46:24 +00:00
/*
2005-04-03 21:26:31 +00:00
* Normal printable characters or hi-ascii
2001-08-17 05:46:24 +00:00
*/
if (Col == strlen(Message[CurRow]) + 1) {
2003-07-01 20:02:58 +00:00
/*
* Append to line
*/
sprintf(Message[CurRow], "%s%c", Message[CurRow], ch);
if (strlen(Message[CurRow]) > 79){
Col = FsWordWrap();
Row++;
Refresh();
} else {
Col++;
2004-11-03 20:48:45 +00:00
PUTCHAR(ch);
2003-07-01 20:02:58 +00:00
}
Changed = TRUE;
} else {
/*
* Insert or overwrite
*/
if (InsMode) {
for (i = strlen(Message[CurRow]); i >= (Col-1); i--) {
/*
* Shift characters right
*/
Message[CurRow][i+1] = Message[CurRow][i];
}
Message[CurRow][Col-1] = ch;
Col++;
if (strlen(Message[CurRow]) > 80) {
i = FsWordWrap();
if (Col > strlen(Message[CurRow])+1) {
Col = Col - strlen(Message[CurRow]);
if (Col > 1)
Col--;
Row++;
2003-07-01 20:02:58 +00:00
}
if (Row > (exitinfo.iScreenLen -1))
ScrollDown();
else
Refresh();
} else {
2003-07-01 20:02:58 +00:00
locate(Row + 1, 1);
2004-11-03 20:48:45 +00:00
PUTSTR(Message[CurRow]);
2003-07-01 20:02:58 +00:00
Setcursor();
2001-08-17 05:46:24 +00:00
}
Changed = TRUE;
2003-07-01 20:02:58 +00:00
} else {
Message[CurRow][Col-1] = ch;
2004-11-03 20:48:45 +00:00
PUTCHAR(ch);
2003-07-01 20:02:58 +00:00
Col++;
Changed = TRUE;
}
2001-08-17 05:46:24 +00:00
}
2003-07-01 20:02:58 +00:00
}
2001-08-17 05:46:24 +00:00
}
2003-07-01 20:02:58 +00:00
}
2001-08-17 05:46:24 +00:00
2003-07-01 20:02:58 +00:00
WriteError("FsEdit(): Impossible to be here");
return FALSE;
2001-08-17 05:46:24 +00:00
}