initial commit from fte-20010819-src.zip sources

This commit is contained in:
Gered 2019-03-31 15:57:52 -04:00
commit 727abd3235
205 changed files with 60009 additions and 0 deletions

25
Makefile Normal file
View file

@ -0,0 +1,25 @@
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
LIBDIR=$(PREFIX)/lib/fte
CONFIGDIR=$(LIBDIR)/config
.PHONY: all install
all: fte
(cd src ; make unix)
install: all
sh install
fte: fte.in Makefile
sed < fte.in >$@ \
-e "s|@@CONFIGDIR@@|$(CONFIGDIR)|g" \
-e "s|@@BINDIR@@|$(BINDIR)|g"
chmod a+x $@
dist: fte
clean:
rm -f fte
(cd src ; make -f fte-unix.mak clean)

17
fte.in Normal file
View file

@ -0,0 +1,17 @@
#!/bin/sh
if [ ! -f $HOME/.fterc ]
then
# Is there a .fte/mymain.fte ? If not, create it.
if [ ! -f $HOME/.fte/mymain.fte ]
then
if [ ! -d $HOME/.fte ]
then
mkdir $HOME/.fte
fi
cp @@CONFIGDIR@@/mymain.fte $HOME/.fte/mymain.fte
fi
(cd @@CONFIGDIR@@; @@BINDIR@@/cfte mymain.fte $HOME/.fterc) || exit 1
fi
exec @@BINDIR@@/xfte "$@"

31
src/Makefile Normal file
View file

@ -0,0 +1,31 @@
MAKE=make
all:
@echo 'What (emx, unix, cygwin, bcc2, win32ms, win32bcc5, win32mingw, djgpp2, vag)?'
emx:
$(MAKE) -f fte-emx.mak
unix:
$(MAKE) -f fte-unix.mak
cygwin:
$(MAKE) -f fte-cygwin-xf86.mak
bcc2:
$(MAKE) -f fte-bcc2.mak
win32ms:
nmake /f fte-msvc.mak
win32mingw:
$(MAKE) -f fte-mngw.mak
win32bcc5:
$(MAKE) -f fte-bcc5.mak
djgpp2:
$(MAKE) -f fte-dj2.mak
vag:
nmake /f fte-vag.mak

33
src/bin2c.cpp Normal file
View file

@ -0,0 +1,33 @@
#include "sysdep.h"
#define BUFLEN (64 * 1024)
unsigned char buf[BUFLEN];
int main(int argc, char **argv) {
int fd;
int i, n = 1, len;
if (argc != 2) {
fprintf(stderr, "Usage: %s filename\n", argv[0]); exit(1);
}
if ((fd = open(argv[1], O_RDONLY | O_BINARY)) == -1) {
fprintf(stderr, "Open: %s, error=%d\n", argv[1], errno);
exit(1);
}
printf("/* do not edit */\nunsigned char DefaultConfig[] = {\n");
while ((len = read(fd, buf, BUFLEN)) > 0) {
for (i = 0; i < len; i++) {
printf("0x%02.02X", buf[i]);
if (n++ % 10) {
printf(", ");
} else {
printf(",\n");
}
}
}
close(fd);
printf("\n};\n");
return 0;
}

BIN
src/bmps/close.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/copy.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/cut.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/errnext.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/errprev.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/exit.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/last.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/next.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/open.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/paste.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/pastecol.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/prev.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/redo.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/save.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/tagfind.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/tagnext.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/tagpop.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/tagprev.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
src/bmps/undo.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

712
src/c_bind.cpp Normal file
View file

@ -0,0 +1,712 @@
/* c_bind.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
//////////////////////////////////////////////////////////////////////////////
EMode *Modes = 0;
EEventMap *EventMaps = 0;
int CMacros = 0;
ExMacro *Macros = 0;
//////////////////////////////////////////////////////////////////////////////
#include "c_cmdtab.h"
//////////////////////////////////////////////////////////////////////////////
const char *GetCommandName(int Command) {
if (Command & CMD_EXT) {
Command &= ~CMD_EXT;
if ((Command < 0) ||
(Command >= CMacros))
return "?INVALID?";
if (Macros[Command].Name)
return Macros[Command].Name;
else
return "?NONE?";
}
for (int i = 0; i < int(sizeof(Command_Table) / sizeof(Command_Table[0])); i++)
if (Command_Table[i].CmdId == Command)
return Command_Table[i].Name;
return "?invalid?";
}
int CmdNum(char *Cmd) {
int i;
for (i = 0;
i < int(sizeof(Command_Table) / sizeof(Command_Table[0]));
i++)
if (strcmp(Cmd, Command_Table[i].Name) == 0)
return Command_Table[i].CmdId;
for (i = 0; i < CMacros; i++)
if (Macros[i].Name && (strcmp(Cmd, Macros[i].Name)) == 0)
return i | CMD_EXT;
return 0; // Nop
}
EMode *FindMode(const char *Name) {
EMode *m = Modes;
//fprintf(stderr, "Searching mode %s\n", Name);
while (m) {
if (strcmp(Name, m->fName) == 0)
return m;
m = m->fNext;
}
return 0;
}
EEventMap *FindEventMap(const char *Name) {
EEventMap *m = EventMaps;
//fprintf(stderr, "Searching map %s\n", Name);
while (m) {
if (strcmp(Name, m->Name) == 0)
return m;
m = m->Next;
}
return 0;
}
EEventMap *FindActiveMap(EMode *Mode) {
while (Mode) {
if (Mode->fEventMap)
return Mode->fEventMap;
Mode = Mode->fParent;
}
return 0;
}
EKey *SetKey(EEventMap *aMap, const char *aKey) {
EKeyMap **map = &aMap->KeyMap, *pm, *parent = 0;
EKey *k;
char Key[256];
char *p, *d;
EEventMap *xm = aMap;
// printf("Setting key %s\n", Key);
strcpy(Key, aKey);
// if mode has parent, get parent keymap
while (xm && xm->Parent && (parent == 0)) {
parent = xm->Parent->KeyMap;
// printf("%s : %s : %d\n", xm->fName, xm->fParent->fName, parent);
xm = xm->Parent;
}
d = p = Key;
while (d) {
// parse key combination
p = d;
d = strchr(p, '_');
if (d) {
if (d[1] == 0 || d[1] == '_')
d++;
if (*d == 0)
d = 0;
else {
*d = 0;
d++;
}
}
// if lastkey
if (d == 0) {
k = new EKey(p);
if (*map) {
(*map)->AddKey(k);
} else {
*map = new EKeyMap();
(*map)->fParent = parent;
(*map)->AddKey(k);
}
return k;
} else {
// if introductory key
if (*map == 0) { // first key in mode, create map
// printf("new map key = %s, parent %d\n", p, parent);
k = new EKey(p, 0);
*map = new EKeyMap();
(*map)->fParent = parent;
(*map)->AddKey(k);
} else {
KeySel ks;
ParseKey(p, ks);
if ((k = (*map)->FindKey(ks.Key)) == 0) { // check if key exists
// add it if not
k = new EKey(p, 0);
(*map)->AddKey(k);
}
}
map = &k->fKeyMap; // set current map to key's map
// get parent keymap
pm = parent;
parent = 0;
// printf("Searching %s\n", p);
while (pm) { // while exists
KeySel ks;
EKey *pk;
ParseKey(p, ks);
if ((pk = pm->FindKey(ks.Key)) != 0) { // if key exists, find parent of it
parent = pk->fKeyMap;
// printf("Key found %d\n", parent);
break;
}
pm = pm->fParent; // otherwise find parent of current keymap
}
}
}
return 0;
}
void InitWordChars() {
static int init = 0;
if (init == 0) {
for (int i = 0; i < 256; i++)
// isalnum???
if (isdigit(i) || (i >= 'A' && i <= 'Z')
|| (i >= 'a' && i <= 'z') || (i == '_')) {
WSETBIT(DefaultBufferFlags.WordChars, i, 1);
if ((i >= 'A' && i <= 'Z'))
WSETBIT(DefaultBufferFlags.CapitalChars, i, 1);
}
init = 1;
}
}
void SetWordChars(char *w, const char *s) {
const char *p;
memset((void *)w, 0, 32);
p = s;
while (p && *p) {
if (*p == '\\') {
p++;
if (*p == 0) return;
} else if (p[1] == '-') {
if (p[2] == 0) return ;
for (int i = p[0]; i < p[2]; i++)
WSETBIT(w, i, 1);
p += 2;
}
WSETBIT(w, *p, 1);
p++;
}
}
EMode::EMode(EMode *aMode, EEventMap *Map, const char *aName) {
fNext = 0;
fName = strdup(aName);
fEventMap = Map;
fParent = aMode;
InitWordChars();
if (aMode) {
#ifdef CONFIG_SYNTAX_HILIT
fColorize = aMode->fColorize;
#endif
Flags = aMode->Flags;
// duplicate strings in flags to allow them be freed
for (int i=0; i<BFS_COUNT; i++)
{
if (aMode->Flags.str[i] != 0)
Flags.str[i] = strdup(aMode->Flags.str[i]);
}
MatchName = 0;
MatchLine = 0;
MatchNameRx = 0;
MatchLineRx = 0;
if (aMode->MatchName) {
MatchName = strdup(aMode->MatchName);
MatchNameRx = RxCompile(MatchName);
}
if (aMode->MatchLine) {
MatchLine = strdup(aMode->MatchLine);
MatchLineRx = RxCompile(MatchLine);
}
} else {
MatchName = 0;
MatchLine = 0;
MatchNameRx = 0;
MatchLineRx = 0;
#ifdef CONFIG_SYNTAX_HILIT
fColorize = 0;
#endif
Flags = DefaultBufferFlags;
// there is no strings in default settings...
}
}
EMode::~EMode() {
// fEventMap is just pointer to EventMaps list, so do not destroy it
// fColorize is also just a pointer
free(fName);
free(MatchName);
RxFree(MatchNameRx);
free(MatchLine);
RxFree(MatchLineRx);
// free strings from flags
for (int i=0; i<BFS_COUNT; i++)
free(Flags.str[i]);
}
EKeyMap::EKeyMap() {
fKeys = NULL;
fParent = NULL;
}
EKeyMap::~EKeyMap() {
// free keys
{
EKey *e;
while((e = fKeys) != NULL)
{
fKeys = fKeys->fNext;
delete e;
}
}
}
void EKeyMap::AddKey(EKey *aKey) {
aKey->fNext = fKeys;
fKeys = aKey;
}
int MatchKey(TKeyCode aKey, KeySel aSel) {
long flags = aKey & ~ 0xFFFF;
long key = aKey & 0xFFFF;
flags &= ~kfAltXXX;
if (flags & kfShift) {
if (key < 256)
if (flags == kfShift)
flags &= ~kfShift;
else if (isascii(key))
key = toupper(key);
}
if ((flags & kfCtrl) && !(flags & kfSpecial))
if (key < 32)
key += 64;
flags &= ~aSel.Mask;
if (aSel.Mask & kfShift) {
if (key < 256)
if (isascii(key))
key = toupper(key);
}
aKey = key | flags;
if (aKey == aSel.Key)
return 1;
return 0;
}
EKey *EKeyMap::FindKey(TKeyCode aKey) {
EKey *p = fKeys;
while (p) {
if (MatchKey(aKey, p->fKey)) return p;
p = p->fNext;
}
return 0;
}
EEventMap::EEventMap(const char *AName, EEventMap *AParent) {
Name = strdup(AName);
Parent = AParent;
KeyMap = 0;
Next = EventMaps;
EventMaps = this;
memset(Menu, 0, sizeof(Menu));
memset(abbrev, 0, sizeof(abbrev));
}
EEventMap::~EEventMap() {
free(Name);
// free menu[]
{
for (int i = 0; i < EM_MENUS; i++)
{
free(Menu[i]);
}
}
// free Abbrev's
{
EAbbrev *ab;
for (int i = 0; i < ABBREV_HASH; i++)
{
while((ab = abbrev[i]) != NULL)
{
abbrev[i] = abbrev[i]->next;
delete ab;
}
}
}
// free keymap's
{
delete KeyMap;
}
}
void EEventMap::SetMenu(int which, const char *What) {
if (which < 0 || which >= EM_MENUS)
return;
if (Menu[which] != 0)
free(Menu[which]);
Menu[which] = strdup(What);
}
char *EEventMap::GetMenu(int which) {
if (which < 0 || which >= EM_MENUS)
return 0;
if (Menu[which] || Parent == 0)
return Menu[which];
else
return Parent->GetMenu(which);
}
#ifdef CONFIG_ABBREV
int EEventMap::AddAbbrev(EAbbrev *ab) {
int i = HashStr(ab->Match, ABBREV_HASH);
ab->next = abbrev[i];
abbrev[i] = ab;
return 1;
}
EAbbrev *EMode::FindAbbrev(const char *string) {
EEventMap *Map = fEventMap;
EAbbrev *ab;
int i;
if (string == 0)
return 0;
i = HashStr(string, ABBREV_HASH);
while (Map) {
ab = Map->abbrev[i];
while (ab != 0) {
if (ab->Match && (strcmp(string, ab->Match) == 0))
return ab;
ab = ab->next;
}
Map = Map->Parent;
}
return 0;
}
#endif
static const struct {
const char *Name;
TKeyCode Key;
} KeyList[] = {
{ "Esc", kbEsc },
{ "Tab", kbTab },
{ "Space", kbSpace },
{ "Enter", kbEnter },
{ "BackSp", kbBackSp },
{ "F1", kbF1 },
{ "F2", kbF2 },
{ "F3", kbF3 },
{ "F4", kbF4 },
{ "F5", kbF5 },
{ "F6", kbF6 },
{ "F7", kbF7 },
{ "F8", kbF8 },
{ "F9", kbF9 },
{ "F10", kbF10 },
{ "F11", kbF11 },
{ "F12", kbF12 },
{ "Left", kbLeft },
{ "Right", kbRight },
{ "Up", kbUp },
{ "Down", kbDown },
{ "Home", kbHome },
{ "End", kbEnd },
{ "PgUp", kbPgUp },
{ "PgDn", kbPgDn },
{ "Ins", kbIns },
{ "Del", kbDel },
{ "Center", kbCenter },
{ "Break", kbBreak },
{ "Pause", kbPause },
{ "PrtScr", kbPrtScr },
{ "SysReq", kbSysReq },
};
int ParseKey(const char *Key, KeySel &ks) {
unsigned char *p = (unsigned char *)Key;
TKeyCode KeyFlags = 0;
int i;
ks.Mask = 0;
ks.Key = 0;
while ((*p) && ((p[1] == '+') || (p[1] == '-'))) {
if (p[1] == '-') {
switch (p[0]) {
case 'A': ks.Mask |= kfAlt; break;
case 'C': ks.Mask |= kfCtrl; break;
case 'S': ks.Mask |= kfShift; break;
case 'G': ks.Mask |= kfGray; break;
case 'X': ks.Mask |= kfSpecial; break;
}
} else if (p[1] == '+') {
switch (p[0]) {
case 'A': KeyFlags |= kfAlt; break;
case 'C': KeyFlags |= kfCtrl; break;
case 'S': KeyFlags |= kfShift; break;
case 'G': KeyFlags |= kfGray; break;
case 'X': KeyFlags |= kfSpecial; break;
}
}
p += 2;
}
for (i = 0; i < int(sizeof(KeyList)/sizeof(KeyList[0])); i++)
if (strcmp((char *)p, KeyList[i].Name) == 0) {
ks.Key = KeyList[i].Key;
break;
}
if (ks.Key == 0)
ks.Key = *p;
if ((KeyFlags & kfCtrl) && !(KeyFlags & kfSpecial)) {
if (ks.Key < 256) {
if (ks.Key < 32)
ks.Key += 64;
else
ks.Key = toupper(ks.Key);
}
}
ks.Key |= KeyFlags;
return 0;
}
int GetKeyName(char *Key, KeySel &ks) {
*Key = 0;
if (ks.Key & kfAlt) strcat(Key, "A+");
if (ks.Mask & kfAlt) strcat(Key, "A-");
if (ks.Key & kfCtrl) strcat(Key, "C+");
if (ks.Mask & kfCtrl) strcat(Key, "C-");
if (ks.Key & kfGray) strcat(Key, "G+");
if (ks.Mask & kfGray) strcat(Key, "G-");
if (ks.Key & kfShift) strcat(Key, "S+");
if (ks.Mask & kfShift) strcat(Key, "S-");
if (keyCode(ks.Key) < 256) {
char c[2];
c[0] = (char)(ks.Key & 0xFF);
c[1] = 0;
//if (ks.Key & kfCtrl)
// if (c[0] < ' ')
// c[0] += '@';
if (c[0] == 32)
strcat(Key, "Space");
else
strcat(Key, c);
} else {
for (int i = 0; i < int(sizeof(KeyList)/sizeof(KeyList[0])); i++)
if (KeyList[i].Key == keyCode(ks.Key)) {
strcat(Key, KeyList[i].Name);
break;
}
}
return 0;
}
EKey::EKey(char *aKey) {
fNext = 0;
ParseKey(aKey, fKey);
fKeyMap = 0;
Cmd = -1;
}
EKey::EKey(char *aKey, EKeyMap *aKeyMap) {
fNext = 0;
Cmd = -1;
ParseKey(aKey, fKey);
fKeyMap = aKeyMap;
}
EKey::~EKey()
{
// if there is child keymaps delete them
delete fKeyMap;
}
#ifdef CONFIG_ABBREV
EAbbrev::EAbbrev(const char *aMatch, const char *aReplace) {
next = 0;
Match = strdup(aMatch);
Replace = strdup(aReplace);
Cmd = -1;
}
EAbbrev::EAbbrev(const char *aMatch, int aCmd) {
next = 0;
Replace = 0;
Match = strdup(aMatch);
Cmd = aCmd;
}
EAbbrev::~EAbbrev() {
if (Match)
free(Match);
if (Replace)
free(Replace);
}
#endif
int AddCommand(int no, int Command, int count, int ign) {
if (count == 0) return 0;
if (Command == 0) return 0;
Macros[no].cmds = (CommandType *)realloc(Macros[no].cmds, sizeof(CommandType) * (Macros[no].Count + 1));
Macros[no].cmds[Macros[no].Count].type = CT_COMMAND;
Macros[no].cmds[Macros[no].Count].u.num = Command;
Macros[no].cmds[Macros[no].Count].repeat = short(count);
Macros[no].cmds[Macros[no].Count].ign = short(ign);
Macros[no].Count++;
return 1;
}
int AddString(int no, const char *String) {
Macros[no].cmds = (CommandType *)realloc(Macros[no].cmds, sizeof(CommandType) * (Macros[no].Count + 1));
Macros[no].cmds[Macros[no].Count].type = CT_STRING;
Macros[no].cmds[Macros[no].Count].u.string = strdup(String);
Macros[no].cmds[Macros[no].Count].repeat = 0;
Macros[no].cmds[Macros[no].Count].ign = 0;
Macros[no].Count++;
return 1;
}
int AddNumber(int no, long number) {
Macros[no].cmds = (CommandType *)realloc(Macros[no].cmds, sizeof(CommandType) * (Macros[no].Count + 1));
Macros[no].cmds[Macros[no].Count].type = CT_NUMBER;
Macros[no].cmds[Macros[no].Count].u.num = number;
Macros[no].cmds[Macros[no].Count].repeat = 0;
Macros[no].cmds[Macros[no].Count].ign = 0;
Macros[no].Count++;
return 1;
}
int AddConcat(int no) {
Macros[no].cmds = (CommandType *)realloc(Macros[no].cmds, sizeof(CommandType) * (Macros[no].Count + 1));
Macros[no].cmds[Macros[no].Count].type = CT_CONCAT;
Macros[no].cmds[Macros[no].Count].u.num = 0;
Macros[no].cmds[Macros[no].Count].repeat = 0;
Macros[no].cmds[Macros[no].Count].ign = 0;
Macros[no].Count++;
return 1;
}
int AddVariable(int no, int number) {
Macros[no].cmds = (CommandType *)realloc(Macros[no].cmds, sizeof(CommandType) * (Macros[no].Count + 1));
Macros[no].cmds[Macros[no].Count].type = CT_VARIABLE;
Macros[no].cmds[Macros[no].Count].u.num = number;
Macros[no].cmds[Macros[no].Count].repeat = 0;
Macros[no].cmds[Macros[no].Count].ign = 0;
Macros[no].Count++;
return 1;
}
int NewCommand(const char *Name) {
Macros = (ExMacro *) realloc(Macros, sizeof(ExMacro) * (1 + CMacros));
Macros[CMacros].Count = 0;
Macros[CMacros].cmds = 0;
Macros[CMacros].Name = (Name != NULL) ? strdup(Name) : 0;
CMacros++;
return CMacros - 1;
}
int ExState::GetStrParam(EView *view, char *str, int maxlen) {
assert(maxlen >= 0);
if (Macro == -1
|| Pos == -1
|| Pos >= Macros[Macro].Count)
return 0;
if (Macros[Macro].cmds[Pos].type == CT_STRING) {
if (maxlen > 0) {
strncpy(str, Macros[Macro].cmds[Pos].u.string, maxlen);
str[maxlen - 1] = 0;
}
Pos++;
} else if (view && Macros[Macro].cmds[Pos].type == CT_VARIABLE) {
//puts("variable\x7");
if (view->GetStrVar(Macros[Macro].cmds[Pos].u.num, str, maxlen) == 0)
return 0;
Pos++;
} else
return 0;
if (Pos < Macros[Macro].Count) {
if (Macros[Macro].cmds[Pos].type == CT_CONCAT) {
Pos++;
int len = strlen(str);
int left = maxlen - len;
assert(left >= 0);
//puts("concat\x7");
if (GetStrParam(view, str + len, left) == 0)
return 0;
}
}
return 1;
}
int ExState::GetIntParam(EView *view, int *value) {
if (Macro == -1
|| Pos == -1
|| Pos >= Macros[Macro].Count)
return 0;
if (Macros[Macro].cmds[Pos].type == CT_NUMBER) {
*value = Macros[Macro].cmds[Pos].u.num;
Pos++;
} else if (view && Macros[Macro].cmds[Pos].type == CT_VARIABLE) {
if (view->GetIntVar(Macros[Macro].cmds[Pos].u.num, value) == 0)
return 0;
Pos++;
} else
return 0;
return 1;
}
int HashStr(const char *p, int maxim) {
unsigned int i = 1;
while (p && *p) {
i += i ^ (i << 3) ^ (unsigned int)(*p) ^ (i >> 3);
p++;
}
return i % maxim;
}

166
src/c_bind.h Normal file
View file

@ -0,0 +1,166 @@
/* c_bind.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __BIND_H
#define __BIND_H
#define ABBREV_HASH 16
class EMode;
class EEventMap;
class EKeyMap;
class EKey;
class EAbbrev;
class EView;
typedef struct {
TKeyCode Mask;
TKeyCode Key;
} KeySel;
class EMode {
public:
EMode *fNext;
char *fName;
char *MatchName;
char *MatchLine;
RxNode *MatchNameRx;
RxNode *MatchLineRx;
EBufferFlags Flags;
EEventMap *fEventMap;
EMode *fParent;
#ifdef CONFIG_SYNTAX_HILIT
EColorize *fColorize;
#endif
char filename[256];
EMode(EMode *aMode, EEventMap *Map, const char *aName);
~EMode();
EAbbrev *FindAbbrev(const char *string);
};
class EKeyMap {
public:
EKeyMap *fParent;
EKey *fKeys;
EKeyMap();
~EKeyMap();
void AddKey(EKey *aKey);
EKey *FindKey(TKeyCode aKey);
};
class EEventMap {
public:
EEventMap *Next;
EEventMap *Parent;
char *Name;
EKeyMap *KeyMap;
char *Menu[EM_MENUS]; // main + local
EAbbrev *abbrev[ABBREV_HASH];
EEventMap(const char *AName, EEventMap *AParent);
~EEventMap();
void SetMenu(int which, const char *What);
char *GetMenu(int which);
#ifdef CONFIG_ABBREV
int AddAbbrev(EAbbrev *ab);
#endif
};
#define CT_COMMAND 0
#define CT_NUMBER 1
#define CT_STRING 2
#define CT_VARIABLE 3
#define CT_CONCAT 4 /* concatenate strings */
typedef struct {
int type;
short repeat;
short ign;
union {
long num;
char *string;
} u;
} CommandType;
typedef struct {
char *Name;
int Count;
CommandType *cmds;
} ExMacro;
class EKey {
public:
KeySel fKey;
int Cmd;
EKeyMap *fKeyMap;
EKey *fNext;
EKey(char *aKey);
EKey(char *aKey, EKeyMap *aKeyMap);
~EKey();
};
#ifdef CONFIG_ABBREV
class EAbbrev {
public:
EAbbrev *next;
int Cmd;
char *Match;
char *Replace;
EAbbrev(const char *aMatch, const char *aReplace);
EAbbrev(const char *aMatch, int aCmd);
~EAbbrev();
};
#endif
class ExState { // state of macro execution
public:
int Macro;
int Pos;
int GetStrParam(EView *view, char *str, int buflen);
int GetIntParam(EView *view, int *value);
};
extern EMode *Modes;
extern EEventMap *EventMaps;
extern int CMacros;
extern ExMacro *Macros;
int GetCharFromEvent(TEvent &E, char *Ch);
const char *GetCommandName(int Command);
EMode *FindMode(const char *Name);
EEventMap *FindEventMap(const char *Name);
EEventMap *FindActiveMap(EMode *Mode);
EMode *GetModeForName(const char *FileName);
int CmdNum(const char *Cmd);
void ExecKey(EKey *Key);
EKey *SetKey(EEventMap *aMap, const char *Key);
int ParseKey(const char *Key, KeySel &ks);
int GetKeyName(char *Key, KeySel &ks);
int NewCommand(const char *Name);
int RunCommand(int Command);
int AddCommand(int no, int cmd, int count, int ign);
int AddString(int no, const char *Command);
int AddNumber(int no, long number);
int AddVariable(int no, int number);
int AddConcat(int no);
int HashStr(const char *str, int maxim);
void SetWordChars(char *w, const char *s);
#endif

335
src/c_cmdtab.h Normal file
View file

@ -0,0 +1,335 @@
/* c_cmdtab.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#define TAB(x) \
{ Ex##x, #x }
const struct {
unsigned short CmdId;
const char *Name;
} Command_Table[] = {
TAB(Nop),
TAB(Fail),
TAB(MoveLeft),
TAB(MoveRight),
TAB(MoveUp),
TAB(MoveDown),
TAB(MovePrev),
TAB(MoveNext),
TAB(MoveWordLeft),
TAB(MoveWordRight),
TAB(MoveWordPrev),
TAB(MoveWordNext),
TAB(MoveWordEndLeft),
TAB(MoveWordEndRight),
TAB(MoveWordEndPrev),
TAB(MoveWordEndNext),
TAB(MoveWordOrCapLeft),
TAB(MoveWordOrCapRight),
TAB(MoveWordOrCapPrev),
TAB(MoveWordOrCapNext),
TAB(MoveWordOrCapEndLeft),
TAB(MoveWordOrCapEndRight),
TAB(MoveWordOrCapEndPrev),
TAB(MoveWordOrCapEndNext),
TAB(MoveLineStart),
TAB(MoveLineEnd),
TAB(MovePageUp),
TAB(MovePageDown),
TAB(MovePageLeft),
TAB(MovePageRight),
TAB(MovePageStart),
TAB(MovePageEnd),
TAB(MoveFileStart),
TAB(MoveFileEnd),
TAB(MoveBlockStart),
TAB(MoveBlockEnd),
TAB(MoveFirstNonWhite),
TAB(MoveLastNonWhite),
TAB(MovePrevEqualIndent),
TAB(MoveNextEqualIndent),
TAB(MovePrevTab),
TAB(MoveNextTab),
TAB(MoveLineTop),
TAB(MoveLineCenter),
TAB(MoveLineBottom),
TAB(ScrollLeft),
TAB(ScrollRight),
TAB(ScrollDown),
TAB(ScrollUp),
TAB(MoveTabStart),
TAB(MoveTabEnd),
TAB(KillLine),
TAB(KillChar),
TAB(KillCharPrev),
TAB(KillWord),
TAB(KillWordPrev),
TAB(KillWordOrCap),
TAB(KillWordOrCapPrev),
TAB(KillToLineStart),
TAB(KillToLineEnd),
TAB(KillBlock),
TAB(KillBlockOrChar),
TAB(KillBlockOrCharPrev),
TAB(BackSpace),
TAB(Delete),
TAB(CharCaseUp),
TAB(CharCaseDown),
TAB(CharCaseToggle),
TAB(LineCaseUp),
TAB(LineCaseDown),
TAB(LineCaseToggle),
TAB(LineInsert),
TAB(LineAdd),
TAB(LineSplit),
TAB(LineJoin),
TAB(LineNew),
TAB(LineIndent),
TAB(LineTrim),
TAB(FileTrim),
TAB(BlockTrim),
TAB(InsertSpacesToTab),
TAB(InsertTab),
TAB(InsertSpace),
TAB(WrapPara),
TAB(InsPrevLineChar),
TAB(InsPrevLineToEol),
TAB(LineDuplicate),
TAB(BlockBegin),
TAB(BlockEnd),
TAB(BlockUnmark),
TAB(BlockCut),
TAB(BlockCopy),
TAB(BlockCutAppend),
TAB(BlockCopyAppend),
TAB(ClipClear),
TAB(BlockPaste),
TAB(BlockKill),
TAB(BlockSort),
TAB(BlockSortReverse),
TAB(BlockIndent),
TAB(BlockUnindent),
TAB(BlockClear),
TAB(BlockMarkStream),
TAB(BlockMarkLine),
TAB(BlockMarkColumn),
TAB(BlockCaseUp),
TAB(BlockCaseDown),
TAB(BlockCaseToggle),
TAB(BlockExtendBegin),
TAB(BlockExtendEnd),
TAB(BlockReIndent),
TAB(BlockSelectWord),
TAB(BlockSelectLine),
TAB(BlockSelectPara),
TAB(Undo),
TAB(Redo),
TAB(MatchBracket),
TAB(MovePrevPos),
TAB(MoveSavedPosCol),
TAB(MoveSavedPosRow),
TAB(MoveSavedPos),
TAB(SavePos),
TAB(CompleteWord),
TAB(MoveToLine),
TAB(MoveToColumn),
TAB(BlockPasteStream),
TAB(BlockPasteLine),
TAB(BlockPasteColumn),
TAB(ShowPosition),
TAB(FoldCreate),
TAB(FoldCreateByRegexp),
TAB(FoldDestroy),
TAB(FoldDestroyAll),
TAB(FoldPromote),
TAB(FoldDemote),
TAB(FoldOpen),
TAB(FoldOpenNested),
TAB(FoldClose),
TAB(FoldOpenAll),
TAB(FoldCloseAll),
TAB(FoldToggleOpenClose),
TAB(MoveFoldTop),
TAB(MoveFoldPrev),
TAB(MoveFoldNext),
TAB(PlaceBookmark),
TAB(RemoveBookmark),
TAB(GotoBookmark),
TAB(InsertString),
TAB(SelfInsert),
TAB(FilePrev),
TAB(FileNext),
TAB(FileLast),
TAB(SwitchTo),
TAB(FileReload),
TAB(FileSave),
TAB(FileSaveAll),
TAB(FileSaveAs),
TAB(FileWriteTo),
TAB(FileOpen),
TAB(FileOpenInMode),
TAB(FilePrint),
TAB(BlockPrint),
TAB(BlockRead),
TAB(BlockReadStream),
TAB(BlockReadLine),
TAB(BlockReadColumn),
TAB(BlockWrite),
TAB(IncrementalSearch),
TAB(Find),
TAB(FindReplace),
TAB(FindRepeat),
TAB(FindRepeatOnce),
TAB(FindRepeatReverse),
TAB(InsertChar),
TAB(FileClose),
TAB(FileCloseAll),
TAB(WinRefresh),
TAB(WinHSplit),
TAB(WinNext),
TAB(WinPrev),
TAB(WinClose),
TAB(WinZoom),
TAB(WinResize),
TAB(ExitEditor),
TAB(ViewBuffers),
TAB(ListRoutines),
TAB(DirOpen),
TAB(Compile),
TAB(CompilePrevError),
TAB(CompileNextError),
TAB(ViewMessages),
TAB(ShowKey),
TAB(ShowEntryScreen),
TAB(RunProgram),
TAB(HilitWord),
TAB(SearchWordPrev),
TAB(SearchWordNext),
TAB(HilitMatchBracket),
TAB(MainMenu),
TAB(LocalMenu),
TAB(ShowMenu),
TAB(ChangeMode),
TAB(ChangeKeys),
TAB(ChangeFlags),
TAB(ToggleAutoIndent),
TAB(ToggleInsert),
TAB(ToggleExpandTabs),
TAB(ToggleShowTabs),
TAB(ToggleUndo),
TAB(ToggleReadOnly),
TAB(ToggleKeepBackups),
TAB(ToggleMatchCase),
TAB(ToggleBackSpKillTab),
TAB(ToggleDeleteKillTab),
TAB(ToggleSpaceTabs),
TAB(ToggleIndentWithTabs),
TAB(ToggleBackSpUnindents),
TAB(ToggleWordWrap),
TAB(ToggleTrim),
TAB(ToggleShowMarkers),
TAB(SetLeftMargin),
TAB(SetRightMargin),
TAB(SetPrintDevice),
TAB(ChangeTabSize),
TAB(ChangeLeftMargin),
TAB(ChangeRightMargin),
TAB(ToggleSysClipboard),
TAB(Cancel),
TAB(Activate),
TAB(Rescan),
TAB(CloseActivate),
TAB(ActivateInOtherWindow),
TAB(DirGoUp),
TAB(DirGoDown),
TAB(DirGoRoot),
TAB(DirGoto),
TAB(DeleteFile),
TAB(ShowVersion),
TAB(ASCIITable),
TAB(TypeChar),
TAB(CharTrans),
TAB(LineTrans),
TAB(BlockTrans),
TAB(DesktopSave),
TAB(DesktopSaveAs),
TAB(ChildClose),
TAB(BufListFileSave),
TAB(BufListFileClose),
TAB(ViewModeMap),
TAB(ClearMessages),
TAB(BlockUnTab),
TAB(BlockEnTab),
TAB(TagFind),
TAB(TagFindWord),
TAB(TagNext),
TAB(TagPrev),
TAB(TagPop),
TAB(TagLoad),
TAB(TagClear),
TAB(TagGoto),
TAB(BlockMarkFunction),
TAB(IndentFunction),
TAB(MoveFunctionPrev),
TAB(MoveFunctionNext),
TAB(Search),
TAB(SearchB),
TAB(SearchRx),
TAB(SearchAgain),
TAB(SearchAgainB),
TAB(SearchReplace),
TAB(SearchReplaceB),
TAB(SearchReplaceRx),
TAB(InsertDate),
TAB(InsertUid),
TAB(FrameNew),
TAB(FrameClose),
TAB(FrameNext),
TAB(FramePrev),
TAB(ShowHelpWord),
TAB(ShowHelp),
TAB(ConfigRecompile),
TAB(PlaceGlobalBookmark),
TAB(RemoveGlobalBookmark),
TAB(GotoGlobalBookmark),
TAB(MoveBeginOrNonWhite),
TAB(MoveBeginLinePageFile),
TAB(MoveEndLinePageFile),
TAB(PushGlobalBookmark),
TAB(PopGlobalBookmark),
TAB(SetCIndentStyle),
TAB(SetIndentWithTabs),
TAB(RunCompiler),
TAB(FoldCreateAtRoutines),
TAB(LineCenter),
TAB(RunProgramAsync)
#if 0
//TAB(ShowMsg),
TAB(BlockReadPipe),
TAB(BlockWritePipe),
TAB(BlockPipe),
#endif
};

129
src/c_color.cpp Normal file
View file

@ -0,0 +1,129 @@
/* c_color.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
ChColor MsgColor[3] = { 0x07, 0x0B, 0x04 };
/* Status line */
ChColor hcStatus_Normal = 0x30;
ChColor hcStatus_Active = 0x70;
ChColor hcEntry_Field = 0x07;
ChColor hcEntry_Prompt = 0x0F;
ChColor hcEntry_Selection = 0x2F;
/* Plain */
ChColor hcPlain_Normal = 0x07;
ChColor hcPlain_Background = 0x07;
ChColor hcPlain_Selected = 0x80;
ChColor hcPlain_Markers = 0x03;
ChColor hcPlain_Found = 0x40;
ChColor hcPlain_Keyword = 0x0F;
ChColor hcPlain_Folds = 0x0A;
ChColor hcPlain_HilitWord = 0x0D;
/* LIST */
//ChColor hcList_Border = 0x03;
ChColor hcList_Status = 0x70;
ChColor hcList_Normal = 0x07;
ChColor hcList_Selected = 0x1F;
ChColor hcScrollBar_Arrows = 0x70;
ChColor hcScrollBar_Back = 0x07;
ChColor hcScrollBar_Fore = 0x07;
ChColor hcAsciiChars = 0x07;
ChColor hcMenu_Background = 0x70;
ChColor hcMenu_ActiveItem = 0x1F;
ChColor hcMenu_ActiveChar = 0x1C;
ChColor hcMenu_NormalItem = 0x70;
ChColor hcMenu_NormalChar = 0x74;
ChColor hcChoice_Title = 0x1F;
ChColor hcChoice_Param = 0x1B;
ChColor hcChoice_Background = 0x17;
ChColor hcChoice_ActiveItem = 0x20;
ChColor hcChoice_ActiveChar = 0x2F;
ChColor hcChoice_NormalItem = 0x1F;
ChColor hcChoice_NormalChar = 0x1E;
static const struct {
const char *Name;
ChColor *C;
} Colors[] =
{
{ "Status.Normal", &hcStatus_Normal },
{ "Status.Active", &hcStatus_Active },
{ "Message.Normal", &MsgColor[0] },
{ "Message.Bold", &MsgColor[1] },
{ "Message.Error", &MsgColor[2] },
{ "Entry.Field", &hcEntry_Field },
{ "Entry.Prompt", &hcEntry_Prompt },
{ "Entry.Selection", &hcEntry_Selection },
{ "LIST.Status", &hcList_Status },
{ "LIST.Normal", &hcList_Normal },
{ "LIST.Selected", &hcList_Selected },
{ "PLAIN.Normal", &hcPlain_Normal },
{ "PLAIN.Background", &hcPlain_Background },
{ "PLAIN.Selected", &hcPlain_Selected },
{ "PLAIN.Markers", &hcPlain_Markers },
{ "PLAIN.Found", &hcPlain_Found },
{ "PLAIN.Keyword", &hcPlain_Keyword },
{ "PLAIN.Folds", &hcPlain_Folds },
{ "PLAIN.HilitWord", &hcPlain_HilitWord },
{ "ScrollBar.Arrows", &hcScrollBar_Arrows },
{ "ScrollBar.Back", &hcScrollBar_Back },
{ "ScrollBar.Fore", &hcScrollBar_Fore },
{ "ASCII.Chars", &hcAsciiChars },
{ "Menu.Background", &hcMenu_Background },
{ "Menu.ActiveItem", &hcMenu_ActiveItem },
{ "Menu.ActiveChar", &hcMenu_ActiveChar },
{ "Menu.NormalItem", &hcMenu_NormalItem },
{ "Menu.NormalChar", &hcMenu_NormalChar },
{ "Choice.Title", &hcChoice_Title },
{ "Choice.Param", &hcChoice_Param },
{ "Choice.Background", &hcChoice_Background },
{ "Choice.ActiveItem", &hcChoice_ActiveItem },
{ "Choice.ActiveChar", &hcChoice_ActiveChar },
{ "Choice.NormalItem", &hcChoice_NormalItem },
{ "Choice.NormalChar", &hcChoice_NormalChar },
};
#define NCOLORS (sizeof(Colors)/sizeof(Colors[0]))
int SetColor(const char *ColorV, const char *Value) {
unsigned int Col;
unsigned int ColBg, ColFg;
ChColor C;
if (sscanf(Value, "%1X %1X", &ColFg, &ColBg) != 2)
return 0;
Col = ColFg | (ColBg << 4);
C = ChColor(Col);
for (unsigned int i = 0; i < NCOLORS; i++) {
if (strcmp(ColorV, Colors[i].Name) == 0) {
*Colors[i].C = C;
return 1;
}
}
return 0;
}

58
src/c_color.h Normal file
View file

@ -0,0 +1,58 @@
/* c_color.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __COLOR_H
#define __COLOR_H
extern ChColor hcStatus_Normal;
extern ChColor hcStatus_Active;
extern ChColor hcPlain_Normal;
extern ChColor hcPlain_Background;
extern ChColor hcPlain_Selected;
extern ChColor hcPlain_Markers;
extern ChColor hcPlain_Found;
extern ChColor hcPlain_Keyword;
extern ChColor hcPlain_Folds;
extern ChColor hcPlain_HilitWord;
extern ChColor hcEntry_Field;
extern ChColor hcEntry_Prompt;
extern ChColor hcEntry_Selection;
//extern ChColor hcList_Border;
extern ChColor hcList_Status;
extern ChColor hcList_Normal;
extern ChColor hcList_Selected;
extern ChColor hcScrollBar_Arrows;
extern ChColor hcScrollBar_Back;
extern ChColor hcScrollBar_Fore;
extern ChColor hcAsciiChars;
extern ChColor hcMenu_Background;
extern ChColor hcMenu_ActiveItem;
extern ChColor hcMenu_ActiveChar;
extern ChColor hcMenu_NormalItem;
extern ChColor hcMenu_NormalChar;
extern ChColor hcChoice_Title;
extern ChColor hcChoice_Param;
extern ChColor hcChoice_Background;
extern ChColor hcChoice_ActiveItem;
extern ChColor hcChoice_ActiveChar;
extern ChColor hcChoice_NormalItem;
extern ChColor hcChoice_NormalChar;
extern ChColor MsgColor[3];
int SetColor(const char *ChColor, const char *Value);
#endif

698
src/c_commands.h Normal file
View file

@ -0,0 +1,698 @@
/* c_commands.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __COMMANDS_H__
#define __COMMANDS_H__
typedef enum {
ErFAIL = 0,
ErOK = 1
} ExResult;
typedef enum {
ExNop,
ExFail,
//<cmd_cursor> Cursor Movement
//& <A HREF="modes.html#ms.CursorTroughTabs">CursorTroughTabs</A>
ExMoveDown,
/// Move cursor to next line.
ExMoveUp,
/// Move cursor to previous line
ExMoveLeft,
/// Move cursor to previous column.
ExMoveRight,
/// Move cursor to next column.
ExMovePrev,
/// Move cursor to previous character. Moves to end of the previous
/// line if cursor is at the beginning of line.
ExMoveNext,
/// Move cursor to next character. Moves to the beginning of next
/// line if cursor is at the end of line.
ExMoveWordLeft,
/// Move cursor to the beginning of the word on the left.
ExMoveWordRight,
/// Move cursor to the beginning of the word on the right.
ExMoveWordPrev,
/// Move cursor to the beginning of the previous word.
ExMoveWordNext,
/// Move cursor to the beginning of the next word.
ExMoveWordEndLeft,
/// Move cursor to the end of the previous word.
ExMoveWordEndRight,
/// Move cursor to the end of the word on the right.
ExMoveWordEndPrev,
/// Move cursor to the end of the previous word.
ExMoveWordEndNext,
/// Move cursor to the end of the next word.
ExMoveWordOrCapLeft,
/// Move cursor to the beginning of the word or capital letter on the right.
ExMoveWordOrCapRight,
/// Move cursor to the beginning of the word or capital letter on the left.
ExMoveWordOrCapPrev,
/// Move cursor to the beginning of the previous word or to previous
/// capital letter.
ExMoveWordOrCapNext,
/// Move cursor to the beginning of the next word or to next capital letter.
ExMoveWordOrCapEndLeft,
/// Move cursor to the end of the word or capitals on the left.
ExMoveWordOrCapEndRight,
/// Move cursor to the end of the word or capitals on the right.
ExMoveWordOrCapEndPrev,
/// Move cursor to the end of the previous word or capitals.
ExMoveWordOrCapEndNext,
/// Move cursor to the end of the next word or capitals.
ExMoveLineStart,
/// Move cursor to the beginning of line.
ExMoveLineEnd,
/// Move cursor to the end of line.
ExMovePageStart,
/// Move cursor to the first line on current page.
ExMovePageEnd,
/// Move cursor to the last line on currently page.
ExMovePageUp,
/// Display previous page.
ExMovePageDown,
/// Display next page.
ExMoveFileStart,
/// Move cursor to the beginning of file.
ExMoveFileEnd,
/// Move cursor to the end of file.
ExMovePageLeft,
/// Scroll horizontally to display page on the left.
ExMovePageRight,
/// Scroll horizontally to display page on the right.
ExMoveBlockStart,
/// Move cursor to the beginning of block.
ExMoveBlockEnd,
/// Move cursor to end beginning of block.
ExMoveFirstNonWhite,
/// Move cursor to the first non-blank character on line.
ExMoveLastNonWhite,
/// Move cursor to the last non-blank character on line.
ExMovePrevEqualIndent,
/// Move cursor to the previous line with equal indentation.
ExMoveNextEqualIndent,
/// Move cursor to the next line with equal indentation.
ExMovePrevTab,
/// Move cursor to the previous tab position.
ExMoveNextTab,
/// Move cursor to the next tab position.
ExMoveTabStart,
/// When cursor is on the tab characters, moves it to the beginning
/// of the tab.
ExMoveTabEnd,
/// When cursor is on the tab characters, moves it to the end
/// of the tab.
ExMoveLineTop,
/// Scroll the file to make the current line appear on the top of the window.
ExMoveLineCenter,
/// Scroll the file to make the current line appear on the center of the window.
ExMoveLineBottom,
/// Scroll the file to make the current line appear on the bottom of the window.
ExScrollLeft,
/// Scroll screen left.
ExScrollRight,
/// Scroll screen right.
ExScrollDown,
/// Scroll screen down.
ExScrollUp,
/// Scroll screen up.
ExMoveFoldTop,
/// Move to the beginning of current fold.
ExMoveFoldPrev,
/// Move to the beginning of previous fold.
ExMoveFoldNext,
/// Move to the beginning of next fold.
ExMoveBeginOrNonWhite,
/// Move to beginning of line, or to first non blank character
ExMoveBeginLinePageFile,
/// Move to the beginning of line. If there already, move to the beginning
/// page. If there already, move to the beginning of file.
ExMoveEndLinePageFile,
/// Move to the end of line. If there already, move to the end
/// page. If there already, move to the end of file.
ExMoveToLine,
/// Move to line number given as argument
ExMoveToColumn,
/// Move to column given as argument
ExMoveSavedPosCol,
/// Move to column from saved position
ExMoveSavedPosRow,
/// Move to line from saved position
ExMoveSavedPos,
/// Move to saved position
ExSavePos,
/// Save current cursor position
ExMovePrevPos,
/// Move to last cursor position
// ExCursorPush,
// ExCursorPop,
//<cmd_delete> Deleting Text
ExKillLine,
/// Delete current line. If the line is the last line in the file,
/// only the text is deleted.
ExKillChar,
/// Delete character under (after) cursor.
ExKillCharPrev,
/// Delete character before cursor.
ExKillWord,
/// Delete the word after cursor.
ExKillWordPrev,
/// Delete the word before cursor.
ExKillWordOrCap,
/// Delete word or capitals after cursor.
ExKillWordOrCapPrev,
/// Delete word or capitals before cursor.
ExKillToLineStart,
/// Delete characters to the beginning of line.
ExKillToLineEnd,
/// Delete characters to the end of line.
ExKillBlock,
/// Delete block.
ExKillBlockOrChar,
/// If block is marked, delete it, otherwise delete character under cursor.
ExKillBlockOrCharPrev,
/// If block is marked, delete it, otherwise delete character before cursor.
ExDelete,
/// Delete character under (after) cursor.
//& <A HREF="modes.html#ms.DeleteKillTab">DeleteKillTab</A>
//& <A HREF="modes.html#ms.DeleteKillBlock">DeleteKillBlock</A>
ExBackSpace,
/// Delete character before cursor.
//& <A HREF="modes.html#ms.BackSpKillTab">BackSpKillTab</A>
//& <A HREF="modes.html#ms.BackSpKillBlock">BackSpKillBlock</A>
//<cmd_line> Line Commands
ExLineInsert,
/// Insert a new line before the current one.
ExLineAdd,
/// Add a new line after the current one.
ExLineSplit,
/// Split current line after cursor position
ExLineJoin,
/// Join current line with next one. If cursor is positioned beyond
/// the end of line, the current line is first padded with whitespace.
ExLineNew,
/// Append a new line and move to the beginning of new line.
ExLineIndent,
/// Reindent current line.
ExLineTrim,
/// Trim whitespace at the end of current line.
ExLineDuplicate,
/// Duplicate the current line.
ExLineCenter,
/// Center the current line
//<cmd_block> Block Commands
ExBlockBegin,
/// Set block beginning to current position.
ExBlockEnd,
/// Set block end to current position.
ExBlockUnmark,
/// Unmark block.
ExBlockCut,
/// Cut selected block to clipboard.
ExBlockCopy,
/// Copy selected block to clipboard.
ExBlockCutAppend,
/// Cut selected block and append it to clipboard.
ExBlockCopyAppend,
/// Append selected block to clipboard.
ExBlockClear,
/// Clear selected block
ExBlockPaste,
/// Paste clipboard to current position.
ExBlockKill,
/// Delete selected text.
ExBlockIndent,
/// Indent block by 1 character.
ExBlockUnindent,
/// Unindent block by 1 character.
ExBlockMarkStream,
/// Start/stop marking stream block.
ExBlockMarkLine,
/// Start/stop marking line block.
ExBlockMarkColumn,
/// Start/stop marking column block.
ExBlockExtendBegin,
/// Start extending selected block.
ExBlockExtendEnd,
/// Stop extending selected block.
ExBlockReIndent,
/// Reindent entire block (C/REXX mode)
ExBlockSelectWord,
/// Select word under cursor as block.
ExBlockSelectLine,
/// Select current line as block.
ExBlockSelectPara,
/// Select current paragraph (delimited by blank lines) as block.
ExBlockPasteStream,
/// Paste clipboard to current position as stream block.
ExBlockPasteLine,
/// Paste clipboard to current position as line block.
ExBlockPasteColumn,
/// Paste clipboard to current position as column block.
ExBlockPrint,
/// Print a block to configured device.
ExBlockRead,
/// Read block from file.
ExBlockReadStream,
/// Read block from file as stream block
ExBlockReadLine,
/// Read block from file as line block
ExBlockReadColumn,
/// Read block from file as column block
ExBlockWrite,
/// Write marked block to file.
ExBlockSort,
/// Sorts the marked block in ascending order.
///
//\ If mode setting MatchCase is set, characters will be compared case
//\ sensitively.
///
//\ When block is marked in <A HREF="modes.html#ec.BlockMarkStream">
//\ Stream</A> or <A HREF="#ec.BlockMarkLine">Line</A> mode,
//\ the entire lines in marked block will be compared.
///
//\ When block is marked in <A HREF="#ec.BlockMarkColumn">Column</A>
//\ mode, only characters within marked columns will be compared.
ExBlockSortReverse,
/// Sorts the marked block in descending order.
//^ <A HREF="#ec.BlockSort">BlockSort</A>
ExBlockUnTab,
/// Remove tabs from marked lines.
ExBlockEnTab,
/// Generate and optimize tabs in marked lines.
ExBlockMarkFunction,
/// Mark current function as block.
ExBlockTrim,
/// Trim end-of-line whitespace
//<cmd_edit> Text Editing and Insertion
ExUndo,
/// Undo last operation
ExRedo,
/// Redo last undone operation.
//<cmd_fold> Folding Text
ExFoldCreate,
/// Create fold
ExFoldCreateByRegexp,
/// Create folds at lines matching a regular expression
ExFoldCreateAtRoutines,
/// Create folds at lines matching RoutineRx
ExFoldDestroy,
/// Destroy fold at current line
ExFoldDestroyAll,
/// Destroy all folds in the file
ExFoldPromote,
/// Promote fold to outer level
ExFoldDemote,
/// Demote fold to inner level
ExFoldOpen,
/// Open fold at current line
ExFoldOpenNested,
/// Open fold and nested folds
ExFoldClose,
/// Close current fold
ExFoldOpenAll,
/// Open all folds in the file
ExFoldCloseAll,
/// Close all folds in the file
ExFoldToggleOpenClose,
/// Toggle open/close current fold.
//<cmd_bookmark>Bookmarks
ExPlaceBookmark,
/// Place a file-local bookmark.
ExRemoveBookmark,
/// Place a file-local bookmark.
ExGotoBookmark,
/// Go to file-local bookmark location.
ExPlaceGlobalBookmark,
/// Place global (persistent) bookmark.
ExRemoveGlobalBookmark,
/// Remove global bookmark.
ExGotoGlobalBookmark,
/// Go to global bookmark location.
ExPushGlobalBookmark,
/// Push global bookmark (named as #<num>) to stack.
ExPopGlobalBookmark,
/// Pop global bookmark from stack.
//<cmd_trans> Character Translation
ExCharCaseUp,
/// Convert current character to uppercase
ExCharCaseDown,
/// Convert current character to lowercase
ExCharCaseToggle,
/// Toggle case of current character
ExCharTrans,
/// Translate current character (like perl/sed)
ExLineCaseUp,
/// Convert current line to uppercase
ExLineCaseDown,
/// Convert current line to lowercase
ExLineCaseToggle,
/// Toggle case of current line
ExLineTrans,
/// Translate characters on current line
ExBlockCaseUp,
/// Convert characters in selected block to uppercase
ExBlockCaseDown,
/// Convert characters in selected block to lowercase
ExBlockCaseToggle,
/// Toggle case of characters in selected block
ExBlockTrans,
/// Translate characters in selected block.
ExInsertString,
/// Insert argument string at cursor position
ExInsertSpace,
/// Insert space
ExInsertChar,
/// Insert character argument at cursor position
ExTypeChar,
/// Insert character at cursor position (expanding abbreviations)
ExInsertTab,
/// Insert tab character at cursor position
ExInsertSpacesToTab,
/// Insert appropriate number of spaces to simulate a tab.
ExSelfInsert,
/// Insert typed character
ExWrapPara,
/// Wrap current paragraph
ExInsPrevLineChar,
/// Insert character in previous line above cursor
ExInsPrevLineToEol,
/// Insert previous line from cursor to end of line
ExCompleteWord,
/// Complete current word to last word starting with the
/// same prefix.
ExFilePrev,
/// Switch to previous file in ring.
ExFileNext,
/// Switch to next file in ring.
ExFileLast,
/// Exchange last two files in ring.
ExSwitchTo,
/// Switch to numbered buffer given as argument
//<cmd_file> File Commands
ExFileOpen,
/// Open file
ExFileOpenInMode,
/// Open file in specified mode
ExFileReload,
/// Reload current file
ExFileSave,
/// Save current file
ExFileSaveAll,
/// Save all modified files
ExFileSaveAs,
/// Rename Save current file
ExFileWriteTo,
/// Write current file into another file
ExFilePrint,
/// Print current file
ExFileClose,
/// Close current file
ExFileCloseAll,
/// Close all open files
ExFileTrim,
/// Trim end-of-line whitespace
//<cmd_directory>
ExDirOpen,
/// Open directory browser
ExDirGoUp,
/// Change to parent directory
ExDirGoDown,
/// Change to currently selected directory
ExDirGoRoot,
/// Change to root directory
ExDirGoto,
/// Change to directory given as argument
//<cmd_search>
ExIncrementalSearch,
/// Incremental search
ExFind,
/// Find
ExFindReplace,
/// Find and replace
ExFindRepeat,
/// Repeat last find/replace operation
ExFindRepeatOnce,
/// Repeat last find/replace operation only once
ExFindRepeatReverse,
/// Repeat last find/replace operation in reverse
ExMatchBracket,
/// Find matching bracket ([{<>}])
ExHilitWord,
/// Highlight current word everywhere in the file
ExSearchWordPrev,
/// Search for previous occurence of word under cursor
ExSearchWordNext,
/// Search for next occurence of word under cursor
ExHilitMatchBracket,
/// Highlight matching bracket
ExSearch,
ExSearchB,
ExSearchRx,
ExSearchAgain,
ExSearchAgainB,
ExSearchReplace,
ExSearchReplaceB,
ExSearchReplaceRx,
//<cmd_window> Window Commands
ExWinHSplit,
/// Split window horizontally
ExWinNext,
/// Switch to next (bottom) window
ExWinPrev,
/// Switcn to previous (top) window.
ExWinClose,
/// Close current window
ExWinZoom,
/// Delete all windows except for current one
ExWinResize,
/// Resize current window (+n,-n given as argument)
ExViewBuffers,
/// View currently open buffers
ExListRoutines,
/// Display routines in current source file
ExExitEditor,
/// Exit FTE.
ExShowEntryScreen,
/// View external program output if available
//<cmd_compile> Compiler Support
ExCompile,
/// Ask for compile command and run compiler
ExRunCompiler,
/// Run configured compile command
ExViewMessages,
/// View compiler output
ExCompileNextError,
/// Switch to next compiler error
ExCompilePrevError,
/// Switch to previous compiler error
ExRunProgram,
/// Run external program
//<cmd_tags> TAGS Commands
/// fte supports TAGS files generated by programs like ctags.
ExTagFind,
/// Find word argumen in tag files.
ExTagFindWord,
/// Find word under cursor in tag files.
ExTagNext,
/// Switch to next occurance of tag
ExTagPrev,
/// Switch to previous occurance of tag
ExTagPop,
/// Pop saved position from tag stack
ExTagLoad,
/// Load tag file and merge with current tags
ExTagClear,
/// Clear loaded tags
ExTagGoto,
///
//<cmd_option> Option commands
ExToggleAutoIndent,
///
ExToggleInsert,
///
ExToggleExpandTabs,
///
ExToggleShowTabs,
///
ExToggleUndo,
///
ExToggleReadOnly,
///
ExToggleKeepBackups,
///
ExToggleMatchCase,
///
ExToggleBackSpKillTab,
///
ExToggleDeleteKillTab,
///
ExToggleSpaceTabs,
///
ExToggleIndentWithTabs,
///
ExToggleBackSpUnindents,
///
ExToggleWordWrap,
///
ExToggleTrim,
///
ExToggleShowMarkers,
///
ExSetLeftMargin,
///
ExSetRightMargin,
///
ExToggleSysClipboard,
///
ExSetPrintDevice,
///
ExChangeTabSize,
///
ExChangeLeftMargin,
///
ExChangeRightMargin,
///
//<cmd_other> Other commands
ExShowPosition,
/// Show internal position information on status line
ExShowVersion,
/// Show editor version information
ExShowKey,
/// Wait for keypress and display modifiers+key pressed
ExWinRefresh,
/// Refresh display
ExMainMenu,
/// Activate main menu
ExShowMenu,
/// Popup menu specified as argument
ExLocalMenu,
/// Popup context menu
ExChangeMode,
/// Change active mode for current buffer
ExChangeKeys,
/// Change keybindings for current buffer
ExChangeFlags,
/// Change option flags for current buffer
ExCancel,
///
ExActivate,
///
ExRescan,
///
ExCloseActivate,
///
ExActivateInOtherWindow,
///
ExDeleteFile,
///
ExASCIITable,
/// Display ASCII selector in status line.
ExDesktopSave,
/// Save desktop
ExClipClear,
/// Clear clipboard
ExDesktopSaveAs,
/// Save desktop under a new name
ExChildClose,
///
ExBufListFileSave,
/// Save currently selected file in buffer list
ExBufListFileClose,
/// Close currently selected file in buffer list
ExViewModeMap,
/// View current mode keybindings
ExClearMessages,
/// Clear compiler messages
ExIndentFunction,
/// Indent current function
ExMoveFunctionPrev,
/// Move cursor to previous function
ExMoveFunctionNext,
/// Move cursor to next function
ExInsertDate,
/// Insert date at cursor
ExInsertUid,
/// Insert user name at cursor
ExFrameNew,
///
ExFrameClose,
///
ExFrameNext,
///
ExFramePrev,
///
ExBufferViewNext,
///
ExBufferViewPrev,
///
ExShowHelpWord,
/// Show context help on keyword.
ExShowHelp,
/// Show help for FTE.
ExConfigRecompile,
/// Recompile editor configuration
ExSetCIndentStyle,
/// Set C indentation style parameters
/// Has the following parameters:
///
/// C_Indent = 4;
/// C_BraceOfs = 0;
/// C_ParenDelta = -1;
/// C_CaseOfs = 0;
/// C_CaseDelta = 4;
/// C_ClassOfs = 0;
/// C_ClassDelta = 4;
/// C_ColonOfs = -4;
/// C_CommentOfs = 0;
/// C_CommentDelta = 1;
/// C_FirstLevelWidth = -1;
/// C_FirstLevelIndent = 4;
/// C_Continuation = 4;
ExSetIndentWithTabs,
/// Set value of indent-with-tabs to argument
ExRunProgramAsync
} ExCommands;
#endif

1124
src/c_config.cpp Normal file

File diff suppressed because it is too large Load diff

49
src/c_config.h Normal file
View file

@ -0,0 +1,49 @@
/* c_config.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __CONFIG_H
#define __CONFIG_H
extern int ScreenSizeX;
extern int ScreenSizeY;
extern int CursorInsSize[2];
extern int CursorOverSize[2];
extern int SystemClipboard;
extern int OpenAfterClose;
extern int ShowMenuBar;
extern int ShowToolBar;
extern int SelectPathname;
extern char DefaultModeName[32];
extern int WSStyleSearch;
extern char PrintDevice[MAXPATH];
extern char CompileCommand[256];
extern int KeepHistory;
extern int LoadDesktopOnEntry;
extern int SaveDesktopOnExit;
extern int KeepMessages;
extern int ScrollBorderX;
extern int ScrollBorderY;
extern int ScrollJumpX;
extern int ScrollJumpY;
extern int GUIDialogs;
extern int SevenBit;
extern int WeirdScroll;
extern int LoadDesktopMode;
extern char HelpCommand[128];
extern char *ConfigSourcePath;
extern char ConfigFileName[MAXPATH];
int LoadConfig(int argc, char **argv, char *CfgFileName);
int GetIndentMode(const char *Str);
int GetHilitMode(const char *Str);
int UseDefaultConfig();
int AddCRegexp(int file, int line, int msg, const char *regexp);
int LoadFile(char *WhereName, char *CfgName);
#endif

162
src/c_desktop.cpp Normal file
View file

@ -0,0 +1,162 @@
/* c_desktop.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#ifdef CONFIG_DESKTOP
#define DESKTOP_VER "FTE Desktop 2\n"
#define DESKTOP_VER1 "FTE Desktop 1\n"
char DesktopFileName[256] = "";
int SaveDesktop(char *FileName) {
FILE *fp;
EModel *M;
fp = fopen(FileName, "w");
if (fp == 0)
return 0;
setvbuf(fp, FileBuffer, _IOFBF, sizeof(FileBuffer));
fprintf(fp, DESKTOP_VER);
M = ActiveModel;
while (M) {
switch(M->GetContext()) {
case CONTEXT_FILE:
{
EBuffer *B = (EBuffer *)M;
fprintf(fp, "F|%d|%s\n", B->ModelNo, B->FileName);
}
break;
#ifdef CONFIG_OBJ_DIRECTORY
case CONTEXT_DIRECTORY:
{
EDirectory *D = (EDirectory *)M;
fprintf(fp, "D|%d|%s\n", D->ModelNo, D->Path);
}
break;
#endif
}
M = M->Next;
if (M == ActiveModel)
break;
}
#ifdef CONFIG_TAGS
TagsSave(fp);
#endif
markIndex.saveToDesktop(fp);
fclose(fp);
return 1;
}
int LoadDesktop(char *FileName) {
FILE *fp;
char line[512];
char *p, *e;
int FLCount = 0;
#ifdef CONFIG_TAGS
TagClear();
#endif
fp = fopen(FileName, "r");
if (fp == 0)
return 0;
//setvbuf(fp, FileBuffer, _IOFBF, sizeof(FileBuffer));
if (fgets(line, sizeof(line), fp) == 0 ||
(strcmp(line, DESKTOP_VER) != 0 &&
(strcmp(line, DESKTOP_VER1) != 0)))
{
fclose(fp);
return 0;
}
while (fgets(line, sizeof(line), fp) != 0) {
e = strchr(line, '\n');
if (e == 0)
break;
*e = 0;
if ((line[0] == 'D' || line[0] == 'F') && line[1] == '|') {
int ModelNo = -1;
p = line + 2;
if (isdigit(*p)) {
ModelNo = atoi(p);
while (isdigit(*p)) p++;
if (*p == '|')
p++;
}
if (line[0] == 'F') { // file
if (FLCount > 0)
suspendLoads = 1;
if (FileLoad(0, p, 0, ActiveView))
FLCount++;
suspendLoads = 0;
#ifdef CONFIG_OBJ_DIRECTORY
} else if (line[0] == 'D') { // directory
EModel *m = new EDirectory(0, &ActiveModel, p);
assert(ActiveModel != 0 && m != 0);
#endif
}
if (ActiveModel) {
if (ModelNo != -1) {
if (FindModelID(ActiveModel, ModelNo) == 0)
ActiveModel->ModelNo = ModelNo;
}
if (ActiveModel != ActiveModel->Next) {
suspendLoads = 1;
ActiveView->SelectModel(ActiveModel->Next);
suspendLoads = 0;
}
}
} else {
#ifdef CONFIG_TAGS
if (line[0] == 'T' && line[1] == '|') { // tag file
TagsAdd(line + 2);
#endif
} else if (line[0] == 'M' && line[1] == '|') { // mark
char *name;
char *file;
EPoint P;
//long l;
char *e;
p = line + 2;
P.Row = strtol(p, &e, 10);
if (*e != '|')
break;
p = e + 1;
P.Col = strtol(p, &e, 10);
if (*e != '|')
break;
p = e + 1;
name = p;
while (*p && *p != '|')
p++;
if (*p == '|')
*p++ = 0;
else
break;
file = p;
markIndex.insert(name, file, P);
}
}
}
fclose(fp);
return 1;
}
#endif

28
src/c_desktop.h Normal file
View file

@ -0,0 +1,28 @@
/* c_desktop.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __DESKTOP_H__
#define __DESKTOP_H__
#ifdef CONFIG_DESKTOP
#ifdef UNIX
# define DESKTOP_NAME ".fte-desktop"
#else
# define DESKTOP_NAME "fte.dsk"
#endif
extern char DesktopFileName[256];
int SaveDesktop(char *FileName);
int LoadDesktop(char *FileName);
#endif
#endif

48
src/c_fconfig.h Normal file
View file

@ -0,0 +1,48 @@
/* c_fconfig.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __FCONFIG_H__
#define __FCONFIG_H__
#define CF_STRING 1
#define CF_INT 2
#define CF_REGEXP 3
#define CF_END 100
#define CF_SUB 101
#define CF_MENU 102
#define CF_OBJECT 103
#define CF_COMMAND 104
#define CF_ITEM 105
#define CF_SUBMENU 106
#define CF_MENUSUB 107
#define CF_MODE 108
#define CF_PARENT 109
#define CF_KEYSUB 110
#define CF_KEY 111
#define CF_COLOR 112
#define CF_KEYWORD 113
#define CF_SETVAR 114
#define CF_COMPRX 115
#define CF_EVENTMAP 116
#define CF_COLORIZE 117
#define CF_ABBREV 118
#define CF_HSTATE 119
#define CF_HTRANS 120
#define CF_HWORDS 121
#define CF_SUBMENUCOND 122
#define CF_HWTYPE 123
#define CF_VARIABLE 124
#define CF_CONCAT 125
#define CF_EOF 254
#define CONFIG_ID 0x1A1D70E1
#endif

329
src/c_hilit.cpp Normal file
View file

@ -0,0 +1,329 @@
/* c_hilit.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#ifdef CONFIG_SYNTAX_HILIT
static const struct {
const char *Name;
int Num;
SyntaxProc Proc;
} HilitModes[] = {
{ "PLAIN", HILIT_PLAIN, Hilit_Plain },
#ifdef CONFIG_HILIT_C
{ "C", HILIT_C, Hilit_C },
#endif
#ifdef CONFIG_HILIT_REXX
{ "REXX", HILIT_REXX, Hilit_REXX },
#endif
#ifdef CONFIG_HILIT_HTML
{ "HTML", HILIT_HTML, Hilit_HTML },
#endif
#ifdef CONFIG_HILIT_PERL
{ "PERL", HILIT_PERL, Hilit_PERL },
#endif
#ifdef CONFIG_HILIT_MAKE
{ "MAKE", HILIT_MAKE, Hilit_MAKE },
#endif
#ifdef CONFIG_HILIT_DIFF
{ "DIFF", HILIT_DIFF, Hilit_DIFF },
#endif
#ifdef CONFIG_HILIT_MERGE
{ "MERGE", HILIT_MERGE, Hilit_MERGE },
#endif
#ifdef CONFIG_HILIT_IPF
{ "IPF", HILIT_IPF, Hilit_IPF },
#endif
#ifdef CONFIG_HILIT_ADA
{ "Ada", HILIT_ADA, Hilit_ADA },
#endif
#ifdef CONFIG_HILIT_MSG
{ "MSG", HILIT_MSG, Hilit_MSG },
#endif
#ifdef CONFIG_HILIT_SH
{ "SH", HILIT_SH, Hilit_SH },
#endif
#ifdef CONFIG_HILIT_PASCAL
{ "PASCAL", HILIT_PASCAL, Hilit_PASCAL },
#endif
#ifdef CONFIG_HILIT_TEX
{ "TEX", HILIT_TEX, Hilit_TEX },
#endif
#ifdef CONFIG_HILIT_FTE
{ "FTE", HILIT_FTE, Hilit_FTE },
#endif
#ifdef CONFIG_HILIT_CATBS
{ "CATBS", HILIT_CATBS, Hilit_CATBS },
#endif
#ifdef CONFIG_HILIT_SIMPLE
{ "SIMPLE", HILIT_SIMPLE, Hilit_SIMPLE },
#endif
};
static const struct {
const char *Name;
int Num;
} IndentModes[] = {
#ifdef CONFIG_INDENT_C
{ "C", INDENT_C },
#endif
#ifdef CONFIG_INDENT_REXX
{ "REXX", INDENT_REXX },
#endif
#ifdef CONFIG_INDENT_SIMPLE
{ "SIMPLE", INDENT_REXX },
#endif
{ "PLAIN", INDENT_PLAIN },
};
EColorize *Colorizers = 0;
int GetIndentMode(const char *Str) {
for (unsigned int i = 0; i < sizeof(IndentModes) / sizeof(IndentModes[0]); i++)
if (strcmp(Str, IndentModes[i].Name) == 0)
return IndentModes[i].Num;
return 0;
}
int GetHilitMode(const char *Str) {
for (unsigned int i = 0; i < sizeof(HilitModes) / sizeof(HilitModes[0]); i++)
if (strcmp(Str, HilitModes[i].Name) == 0)
return HilitModes[i].Num;
return HILIT_PLAIN;
}
SyntaxProc GetHilitProc(int id) {
for (unsigned int i = 0; i < sizeof(HilitModes) / sizeof(HilitModes[0]); i++)
if (id == HilitModes[i].Num)
return HilitModes[i].Proc;
return 0;
}
#ifdef CONFIG_WORD_HILIT
int EBuffer::HilitAddWord(const char *Word) {
if (HilitFindWord(Word) == 1)
return 1;
WordList = (char **)realloc((void *)WordList, (1 + WordCount) * sizeof(char *));
if (WordList == 0) return 0;
WordList[WordCount++] = strdup(Word);
FullRedraw();
return 1;
}
int EBuffer::HilitFindWord(const char *Word) {
for (int i = 0; i < WordCount; i++) {
if (BFI(this, BFI_MatchCase) == 1) {
if (strcmp(Word, WordList[i]) == 0) return 1;
} else {
if (stricmp(Word, WordList[i]) == 0) return 1;
}
}
return 0;
}
int EBuffer::HilitRemoveWord(const char *Word) {
for (int i = 0; i < WordCount; i++) {
if (BFI(this, BFI_MatchCase) == 1) {
if (strcmp(Word, WordList[i]) != 0) continue;
} else {
if (stricmp(Word, WordList[i]) != 0) continue;
}
free(WordList[i]);
memmove(WordList + i, WordList + i + 1, sizeof(char *) * (WordCount - i - 1));
WordCount--;
WordList = (char **)realloc((void *)WordList, WordCount * sizeof(char *));
FullRedraw();
return 1;
}
return 0;
}
int EBuffer::HilitWord() {
PELine L = VLine(CP.Row);
char s[CK_MAXLEN + 2];
int P, len = 0;
P = CharOffset(L, CP.Col);
while ((P > 0) && ((ChClass(L->Chars[P - 1]) == 1) || (L->Chars[P - 1] == '_')))
P--;
while (len < CK_MAXLEN && P < L->Count && (ChClass(L->Chars[P]) == 1 || L->Chars[P] == '_'))
s[len++] = L->Chars[P++];
if (len == 0)
return 0;
s[len] = 0;
return (HilitFindWord(s)) ? HilitRemoveWord(s) : HilitAddWord(s);
}
#endif
/* ======================================================================= */
EColorize::EColorize(const char *AName, const char *AParent) {
Name = strdup(AName);
SyntaxParser = HILIT_PLAIN;
Next = Colorizers;
hm = 0;
Colorizers = this;
Parent = FindColorizer(AParent);
memset((void *)&Keywords, 0, sizeof(Keywords));
memset((void *)Colors, 0, sizeof(Colors));
if (Parent) {
SyntaxParser = Parent->SyntaxParser;
memcpy((void *)Colors, (void *)Parent->Colors, sizeof(Colors));
} else {
SyntaxParser = HILIT_PLAIN;
}
}
EColorize::~EColorize() {
free(Name);
for (int i=0; i<CK_MAXLEN; i++)
free(Keywords.key[i]);
delete hm;
}
EColorize *FindColorizer(const char *AName) {
EColorize *p = Colorizers;
while (p) {
if (strcmp(AName, p->Name) == 0)
return p;
p = p->Next;
}
return 0;
}
int EColorize::SetColor(int idx, const char *Value) {
unsigned int Col;
unsigned int ColBg, ColFg;
ChColor C;
if (sscanf(Value, "%1X %1X", &ColFg, &ColBg) != 2)
return 0;
Col = ColFg | (ColBg << 4);
C = ChColor(Col);
if (idx < 0 || idx >= COUNT_CLR)
return 0;
Colors[idx] = C;
return 1;
}
/* ======================================================================= */
void HTrans::InitTrans() {
match = 0;
matchLen = 0;
matchFlags = 0;
nextState = 0;
color = 0;
}
/* ======================================================================= */
void HState::InitState() {
memset((void *)&keywords, 0, sizeof(keywords));
firstTrans = 0;
transCount = 0;
color = 0;
wordChars = 0;
options = 0;
nextKwdMatchedState = -1;
nextKwdNotMatchedState = -1;
nextKwdNoCharState = -1;
}
int HState::GetHilitWord(int len, char *str, ChColor &clr) {
char *p;
if (len >= CK_MAXLEN || len < 1)
return 0;
p = keywords.key[len];
if (options & STATE_NOCASE) {
while (p && *p) {
if (strnicmp(p, str, len) == 0) {
clr = p[len];
return 1;
}
p += len + 1;
}
} else {
while (p && *p) {
if (memcmp(p, str, len) == 0) {
clr = p[len];
return 1;
}
p += len + 1;
}
}
return 0;
}
/* ======================================================================= */
HMachine::HMachine() {
stateCount = 0;
state = 0;
transCount = 0;
trans = 0;
}
HMachine::~HMachine() {
// free states
if (state)
{
int i;
while(stateCount--)
{
for (i=0; i<CK_MAXLEN; i++)
free(state[stateCount].keywords.key[i]);
free(state[stateCount].wordChars);
}
free(state);
}
// free transes
if (trans)
{
while(transCount--)
{
free(trans[transCount].match);
}
free(trans);
}
}
void HMachine::AddState(HState &aState) {
state = (HState *)realloc(state, (stateCount + 1) * sizeof(HState) );
assert( state );
state[stateCount] = aState;
state[stateCount].firstTrans = transCount;
stateCount++;
}
void HMachine::AddTrans(HTrans &aTrans) {
assert(stateCount > 0);
trans = (HTrans *)realloc(trans, (transCount + 1) * sizeof(HTrans) );
assert( trans );
state[stateCount - 1].transCount++;
trans[transCount] = aTrans;
transCount++;
}
#endif

223
src/c_hilit.h Normal file
View file

@ -0,0 +1,223 @@
/* c_hilit.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __HILIT_H__
#define __HILIT_H__
typedef unsigned short hlState;
typedef unsigned char hsState;
class EBuffer;
class ELine;
#define HILIT_P(proc) \
int proc(EBuffer *BF, int LN, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap, int *ECol)
//typedef int (*SyntaxProc)(EBuffer *BF, int LN, PCell B, int Pos, int Width, ELine *Line, hlState &State, hsState *StateMap);
typedef HILIT_P((*SyntaxProc));
int Indent_Plain(EBuffer *B, int Line, int PosCursor);
HILIT_P(Hilit_Plain);
#ifdef CONFIG_SYNTAX_HILIT
/* highlighting state */
#ifdef CONFIG_HILIT_C
HILIT_P(Hilit_C);
#endif
#ifdef CONFIG_HILIT_HTML
HILIT_P(Hilit_HTML);
#endif
#ifdef CONFIG_HILIT_PERL
HILIT_P(Hilit_PERL);
#endif
#ifdef CONFIG_HILIT_MAKE
HILIT_P(Hilit_MAKE);
#endif
#ifdef CONFIG_HILIT_REXX
HILIT_P(Hilit_REXX);
#endif
#ifdef CONFIG_HILIT_DIFF
HILIT_P(Hilit_DIFF);
#endif
#ifdef CONFIG_HILIT_MERGE
HILIT_P(Hilit_MERGE);
#endif
#ifdef CONFIG_HILIT_IPF
HILIT_P(Hilit_IPF);
#endif
#ifdef CONFIG_HILIT_ADA
HILIT_P(Hilit_ADA);
#endif
#ifdef CONFIG_HILIT_MSG
HILIT_P(Hilit_MSG);
#endif
#ifdef CONFIG_HILIT_SH
HILIT_P(Hilit_SH);
#endif
#ifdef CONFIG_HILIT_PASCAL
HILIT_P(Hilit_PASCAL);
#endif
#ifdef CONFIG_HILIT_TEX
HILIT_P(Hilit_TEX);
#endif
#ifdef CONFIG_HILIT_FTE
HILIT_P(Hilit_FTE);
#endif
#ifdef CONFIG_HILIT_CATBS
HILIT_P(Hilit_CATBS);
#endif
#ifdef CONFIG_HILIT_SIMPLE
HILIT_P(Hilit_SIMPLE);
#endif
#ifdef CONFIG_INDENT_C
int Indent_C(EBuffer *B, int Line, int PosCursor);
#endif
#ifdef CONFIG_INDENT_REXX
int Indent_REXX(EBuffer *B, int Line, int PosCursor);
#endif
#ifdef CONFIG_INDENT_SIMPLE
int Indent_SIMPLE(EBuffer *B, int Line, int PosCursor);
#endif
/*
* NT has 2-byte charcode and attribute... Following is not portable to non-
* intel; should be replaced by formal TCell definition' usage instead of
* assumed array.. (Jal)
*/
#ifdef NTCONSOLE
# define PCLI unsigned short
#else
# define PCLI unsigned char
#endif
#define ColorChar() \
do {\
BPos = C - Pos; \
if (B) \
if (BPos >= 0 && BPos < Width) { \
BPtr = (PCLI *) (B + BPos); \
BPtr[0] = *p; \
BPtr[1] = Color; \
} \
if (StateMap) StateMap[i] = (hsState)(State & 0xFF); \
} while (0)
// MoveChar(B, C - Pos, Width, *p, Color, 1);
// if (StateMap) StateMap[i] = State; }
#define NextChar() do { i++; p++; len--; C++; } while (0)
#define ColorNext() do { ColorChar(); NextChar(); } while (0)
#define HILIT_VARS(ColorNormal, Line) \
PCLI *BPtr; \
int BPos; \
ChColor Color = ColorNormal; \
int i; \
int len = Line->Count; \
char *p = Line->Chars; \
int NC = 0, C = 0; \
int TabSize = BFI(BF, BFI_TabSize); \
int ExpandTabs = BFI(BF, BFI_ExpandTabs);
//#define HILIT_VARS2()
// int len1 = len;
// char *last = p + len1 - 1;
#define IF_TAB() \
if (*p == '\t' && ExpandTabs) { \
NC = NextTab(C, TabSize); \
if (StateMap) StateMap[i] = hsState(State);\
if (B) MoveChar(B, C - Pos, Width, ' ', Color, NC - C);\
if (BFI(BF, BFI_ShowTabs)) ColorChar();\
i++,len--,p++;\
C = NC;\
continue;\
}
#define CK_MAXLEN 32
typedef struct {
int TotalCount;
int count[CK_MAXLEN];
char *key[CK_MAXLEN];
} ColorKeywords;
struct HTrans {
char *match;
int matchLen;
long matchFlags;
int nextState;
int color;
void InitTrans();
};
struct HState {
int transCount;
int firstTrans;
int color;
ColorKeywords keywords;
char *wordChars;
long options;
int nextKwdMatchedState;
int nextKwdNotMatchedState;
int nextKwdNoCharState;
void InitState();
int GetHilitWord(int len, char *str, ChColor &clr);
};
class HMachine {
public:
int stateCount;
int transCount;
HState *state;
HTrans *trans;
HMachine();
~HMachine();
void AddState(HState &aState);
void AddTrans(HTrans &aTrans);
HState *LastState() { return state + stateCount - 1; }
};
class EColorize {
public:
char *Name;
EColorize *Next;
EColorize *Parent;
int SyntaxParser;
ColorKeywords Keywords; // keywords to highlight
HMachine *hm;
ChColor Colors[COUNT_CLR];
EColorize(const char *AName, const char *AParent);
~EColorize();
int SetColor(int clr, const char *value);
};
extern EColorize *Colorizers;
EColorize *FindColorizer(const char *AName);
SyntaxProc GetHilitProc(int id);
int IsState(hsState *Buf, hsState State, int Len);
int LookAt(EBuffer *B, int Row, unsigned int Pos, const char *What, hsState State, int NoWord = 1, int CaseInsensitive = 0);
inline int LookAtNoCase(EBuffer *B, int Row, unsigned int Pos, const char *What, hsState State, int NoWord = 1)
{ return LookAt(B, Row, Pos, What, State, NoWord, 1); }
#endif
#endif

260
src/c_history.cpp Normal file
View file

@ -0,0 +1,260 @@
/* c_history.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#ifdef CONFIG_HISTORY
#define HISTORY_VER "FTE History 1\n"
char HistoryFileName[256] = "";
static FPosHistory **FPHistory = 0;
static int FPHistoryCount = 0;
static InputHistory inputHistory = { 0, 0, 0 };
void ClearHistory() { /*FOLD00*/
// free filenames from all entries
while(FPHistoryCount--)
{
free(FPHistory[FPHistoryCount]->FileName);
free(FPHistory[FPHistoryCount]);
}
// free history list
free(FPHistory);
// free input history
{
while(inputHistory.Count--)
{
free(inputHistory.Line[inputHistory.Count]);
}
free(inputHistory.Line);
free(inputHistory.Id);
}
}
int SaveHistory(char *FileName) { /*FOLD00*/
FILE *fp;
fp = fopen(FileName, "w");
if (fp == 0)
return 0;
setvbuf(fp, FileBuffer, _IOFBF, sizeof(FileBuffer));
fprintf(fp, HISTORY_VER);
if (FPHistory) { // file position history
int i;
for (i = 0; i < FPHistoryCount; i++)
fprintf(fp, "F|%d|%d|%s\n",
FPHistory[i]->Row,
FPHistory[i]->Col,
FPHistory[i]->FileName);
}
{ // input history
for (int i = 0; i < inputHistory.Count; i++) {
fprintf(fp, "I|%d|%s\n", inputHistory.Id[i], inputHistory.Line[i]);
}
}
fclose(fp);
return 1;
}
int LoadHistory(char *FileName) { /*fold00*/
FILE *fp;
char line[2048];
char *p, *e;
fp = fopen(FileName, "r");
if (fp == 0)
return 0;
setvbuf(fp, FileBuffer, _IOFBF, sizeof(FileBuffer));
if (fgets(line, sizeof(line), fp) == 0 ||
strcmp(line, HISTORY_VER) != 0)
{
fclose(fp);
return 0;
}
while (fgets(line, sizeof(line), fp) != 0) {
if (line[0] == 'F' && line[1] == '|') { // input history
int r, c;
p = line + 2;
r = strtol(p, &e, 10);
if (e == p)
break;
if (*e == '|')
e++;
else
break;
c = strtol(p = e, &e, 10);
if (e == p)
break;
if (*e == '|')
e++;
else
break;
e = strchr(p = e, '\n');
if (e == 0)
break;
*e = 0;
if (UpdateFPos(p, r, c) == 0)
break;
} else if (line[0] == 'I' && line[1] == '|') { // file position history
int i;
p = line + 2;
i = strtol(p, &e, 10);
if (e == p)
break;
if (*e == '|')
e++;
else
break;
e = strchr(p = e, '\n');
if (e == 0)
break;
*e = 0;
AddInputHistory(i, p);
}
}
fclose(fp);
return 1;
}
int UpdateFPos(char *FileName, int Row, int Col) { /*fold00*/
int L = 0, R = FPHistoryCount, M, N;
FPosHistory *fp, **NH;
int cmp;
if (FPHistory != 0) {
while (L < R) {
M = (L + R) / 2;
cmp = filecmp(FileName, FPHistory[M]->FileName);
if (cmp == 0) {
FPHistory[M]->Row = Row;
FPHistory[M]->Col = Col;
return 1;
} else if (cmp < 0) {
R = M;
} else {
L = M + 1;
}
}
} else {
FPHistoryCount = 0;
L = 0;
}
assert(L >= 0 && L <= FPHistoryCount);
fp = (FPosHistory *)malloc(sizeof(FPosHistory));
if (fp == 0)
return 0;
fp->Row = Row;
fp->Col = Col;
fp->FileName = strdup(FileName);
if (fp->FileName == 0) {
free(fp);
return 0;
}
N = 64;
while (N <= FPHistoryCount) N *= 2;
NH = (FPosHistory **)realloc((void *)FPHistory, N * sizeof(FPosHistory *));
if (NH == 0)
{
free(fp->FileName);
free(fp);
return 0;
}
FPHistory = NH;
if (L < FPHistoryCount)
memmove(FPHistory + L + 1,
FPHistory + L,
(FPHistoryCount - L) * sizeof(FPosHistory *));
FPHistory[L] = fp;
FPHistoryCount++;
return 1;
}
int RetrieveFPos(char *FileName, int &Row, int &Col) { /*FOLD00*/
int L = 0, R = FPHistoryCount, M;
int cmp;
if (FPHistory == 0)
return 0;
while (L < R) {
M = (L + R) / 2;
cmp = filecmp(FileName, FPHistory[M]->FileName);
if (cmp == 0) {
Row = FPHistory[M]->Row;
Col = FPHistory[M]->Col;
return 1;
} else if (cmp < 0) {
R = M;
} else {
L = M + 1;
}
}
return 0;
}
int AddInputHistory(int Id, char *String) { /*fold00*/
if (inputHistory.Count < MAX_INPUT_HIST) {
inputHistory.Count++;
inputHistory.Line = (char **) realloc((void *) inputHistory.Line,
inputHistory.Count * sizeof(char *));
inputHistory.Id = (int *) realloc((void *) inputHistory.Id,
inputHistory.Count * sizeof(int *));
} else {
free(inputHistory.Line[inputHistory.Count - 1]);
}
memmove(inputHistory.Line + 1,
inputHistory.Line,
(inputHistory.Count - 1) * sizeof(char *));
memmove(inputHistory.Id + 1,
inputHistory.Id,
(inputHistory.Count - 1) * sizeof(int *));
inputHistory.Id[0] = Id;
inputHistory.Line[0] = strdup(String);
return 1;
}
int CountInputHistory(int Id) { /*fold00*/
int i, c = 0;
for (i = 0; i < inputHistory.Count; i++)
if (inputHistory.Id[i] == Id) c++;
return c;
}
int GetInputHistory(int Id, char *String, int len, int Nth) { /*fold00*/
int i = 0;
assert(len > 0);
while (i < inputHistory.Count) {
if (inputHistory.Id[i] == Id) {
Nth--;
if (Nth == 0) {
strncpy(String, inputHistory.Line[i], len);
String[len - 1] = 0;
return 1;
}
}
i++;
}
return 0;
}
#endif

64
src/c_history.h Normal file
View file

@ -0,0 +1,64 @@
/* c_history.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __FPOSHIST_H__
#define __FPOSHIST_H__
#ifdef CONFIG_HISTORY
#ifdef UNIX
#define HISTORY_NAME ".fte-history"
#else
#define HISTORY_NAME "fte.his"
#endif
typedef struct {
char *FileName;
int Row, Col;
} FPosHistory;
#define MAX_INPUT_HIST 128
typedef struct {
int Count;
char **Line;
int *Id;
} InputHistory;
extern char HistoryFileName[256];
void ClearHistory();
int SaveHistory(char *FileName);
int LoadHistory(char *FileName);
int UpdateFPos(char *FileName, int Row, int Col);
int RetrieveFPos(char *FileName, int &Row, int &Col);
int AddInputHistory(int Id, char *String);
int CountInputHistory(int Id);
int GetInputHistory(int Id, char *String, int maxlen, int Nth);
/* history values */
#define HIST_DEFAULT 0
#define HIST_PATH 1
#define HIST_SEARCH 2
#define HIST_POSITION 3
#define HIST_SETUP 4
#define HIST_SHELL 5
#define HIST_COMPILE 6
#define HIST_SEARCHOPT 7
#define HIST_BOOKMARK 8
#define HIST_REGEXP 9
#define HIST_TRANS 10
#define HIST_TAGFILES 11
#endif
#endif

133
src/c_mode.cpp Normal file
View file

@ -0,0 +1,133 @@
/* c_mode.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
EBufferFlags DefaultBufferFlags = {
{
1, // AutoIndent
1, // InsertOn
0, // DrawOn
1, // HilitOn
1, // ExpandTabs
0, // Trim
8, // TabSize
HILIT_PLAIN, // HilitMode
INDENT_PLAIN, // IndentMode
0, // ShowTab
10, // LineChar
#if !defined(UNIX)
13, // StripChar
#else
-1,
#endif
1, // AddLine
#if !defined(UNIX)
1, // AddStrip
#else
0,
#endif
0, // ForceNewLine
0, // HardMode
1, // UndoRedo
0, // ReadOnly
0, // AutoSave
1, // KeepBackups
-1, // LoadMargin
256, // Max Undo/Redo Commands
1, // MatchCase
0, // BackKillTab
0, // DelKillTab
1, // BackSpUnindent
0, // SpaceTabs
1, // IndentWTabs
1, // Wrap.LeftMargin
72, // Wrap.RightMargin
1, // See Thru Sel
0, // WordWrap
0, // ShowMarkers
1, // CursorThroughTabs
0, // Save Folds
0, // MultiLineHilit
0, // AutoHilitParen
0, // Abbreviations
0, // BackSpKillBlock
0, // DeleteKillBlock
1, // PersistentBlocks
0, // InsertKillBlock
0, // UndoMoves
#ifdef UNIX
0, // DetectLineSep
#else
1,
#endif
0 // trim on save
},
{
0, // Routine Regexp
0, // DefFindOpt
0, // DefFindReplaceOpt
0, // comment start (folds)
0, // comment end (folds)
0, // filename rx
0, // firstline rx
0 // compile command
}
};
EMode *GetModeForName(const char *FileName) {
// char ext[10];
// char *p;
int l, i;
EMode *m;
RxMatchRes RM;
char buf[81];
int fd;
m = Modes;
while (m) {
if (m->MatchNameRx)
if (RxExec(m->MatchNameRx,
FileName, strlen(FileName), FileName,
&RM) == 1)
return m;
if (m->fNext == 0) break;
m = m->fNext;
}
fd = open(FileName, O_RDONLY);
if (fd != -1) {
l = read(fd, buf, 80);
close(fd);
if (l > 0) {
buf[l] = 0;
for (i = 0; i < l; i++) {
if (buf[i] == '\n') {
buf[i] = 0;
l = i;
break;
}
}
m = Modes;
while (m) {
if (m->MatchLineRx)
if (RxExec(m->MatchLineRx, buf, l, buf, &RM) == 1)
return m;
if (m->fNext == 0) break;
m = m->fNext;
}
}
}
if ((m = FindMode(DefaultModeName)) != 0) return m;
m = Modes;
while (m && m->fNext) m = m->fNext;
return m;
}

262
src/c_mode.h Normal file
View file

@ -0,0 +1,262 @@
/* c_mode.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __EMODE_H__
#define __EMODE_H__
#define CMD_EXT 0x1000 // max 4096 internal commands, check cfte.cpp
#define CONTEXT_NONE 0
#define CONTEXT_FILE 1
#define CONTEXT_DIRECTORY 2
#define CONTEXT_MESSAGES 3
#define CONTEXT_SHELL 4
#define CONTEXT_INPUT 5
#define CONTEXT_CHOICE 6
#define CONTEXT_LIST 7
#define CONTEXT_CHAR 8
#define CONTEXT_BUFFERS 9
#define CONTEXT_ROUTINES 10
#define CONTEXT_MAPVIEW 11
typedef unsigned char ChColor;
#define HILIT_PLAIN 0
#define HILIT_C 1
#define HILIT_HTML 2
#define HILIT_MAKE 3
#define HILIT_REXX 4
#define HILIT_DIFF 5
#define HILIT_IPF 6
#define HILIT_PERL 7
#define HILIT_MERGE 8
#define HILIT_ADA 9
#define HILIT_MSG 10
#define HILIT_SH 11
#define HILIT_PASCAL 12
#define HILIT_TEX 13
#define HILIT_FTE 14
#define HILIT_CATBS 15
#define HILIT_SIMPLE 16
#define INDENT_PLAIN 0
#define INDENT_C 1
#define INDENT_REXX 2
#define INDENT_SIMPLE 3
#define BFI_AutoIndent 0
#define BFI_Insert 1
#define BFI_DrawOn 2
#define BFI_HilitOn 3
#define BFI_ExpandTabs 4
#define BFI_Trim 5
#define BFI_TabSize 6
#define BFI_ShowTabs 9
#define BFI_HardMode 15
#define BFI_Undo 16
#define BFI_ReadOnly 17
#define BFI_AutoSave 18
#define BFI_KeepBackups 19
#define BFI_MatchCase 22
#define BFI_BackSpKillTab 23
#define BFI_DeleteKillTab 24
#define BFI_BackSpUnindents 25
#define BFI_SpaceTabs 26
#define BFI_IndentWithTabs 27
#define BFI_SeeThruSel 30
#define BFI_ShowMarkers 32
#define BFI_CursorThroughTabs 33
#define BFI_MultiLineHilit 35
#define BFI_WordWrap 31
#define BFI_LeftMargin 28
#define BFI_RightMargin 29
#define BFI_Colorizer 7
#define BFI_IndentMode 8
#define BFI_LineChar 10
#define BFI_StripChar 11
#define BFI_AddLF 12
#define BFI_AddCR 13
#define BFI_ForceNewLine 14
#define BFI_LoadMargin 20
#define BFI_SaveFolds 34
#define BFI_UndoLimit 21
#define BFI_AutoHilitParen 36
#define BFI_Abbreviations 37
#define BFI_BackSpKillBlock 38
#define BFI_DeleteKillBlock 39
#define BFI_PersistentBlocks 40
#define BFI_InsertKillBlock 41
#define BFI_EventMap 42
#define BFI_UndoMoves 43
#define BFI_DetectLineSep 44
#define BFI_TrimOnSave 45
#define BFI_COUNT 46
#define BFS_RoutineRegexp (0 | 256)
#define BFS_DefFindOpt (1 | 256)
#define BFS_DefFindReplaceOpt (2 | 256)
#define BFS_CommentStart (3 | 256)
#define BFS_CommentEnd (4 | 256)
#define BFS_FileNameRx (5 | 256)
#define BFS_FirstLineRx (6 | 256)
#define BFS_CompileCommand (7 | 256)
#define BFS_COUNT 8
#define BFS_WordChars (100 | 256) // ext
#define BFS_CapitalChars (101 | 256)
#define BFI(y,x) ((y)->Flags.num[(x) & 0xFF])
#define BFI_SET(y,x,v) ((y)->Flags.num[(x) & 0xFF]=(v))
#define BFS(y,x) ((y)->Flags.str[(x) & 0xFF])
#define WSETBIT(x,y,z) \
((x)[(unsigned char)(y) >> 3] = char((z) ? \
((x)[(unsigned char)(y) >> 3] | (1 << ((unsigned char)(y) & 0x7))) : \
((x)[(unsigned char)(y) >> 3] & ~(1 << ((unsigned char)(y) & 0x7)))))
#define WGETBIT(x,y) \
(((x)[(unsigned char)(y) / 8] & (1 << ((unsigned char)(y) % 8))) ? 1 : 0)
typedef struct {
int num[BFI_COUNT];
char *str[BFS_COUNT];
char WordChars[32];
char CapitalChars[32];
} EBufferFlags;
extern EBufferFlags DefaultBufferFlags;
/* globals */
#define FLAG_C_Indent 1
#define FLAG_C_BraceOfs 2
#define FLAG_REXX_Indent 3
#define FLAG_ScreenSizeX 6
#define FLAG_ScreenSizeY 7
#define FLAG_CursorInsertStart 8
#define FLAG_CursorInsertEnd 9
#define FLAG_CursorOverStart 10
#define FLAG_CursorOverEnd 11
#define FLAG_SysClipboard 12
#define FLAG_ShowHScroll 13
#define FLAG_ShowVScroll 14
#define FLAG_ScrollBarWidth 15
#define FLAG_SelectPathname 16
#define FLAG_C_CaseOfs 18
#define FLAG_DefaultModeName 19
#define FLAG_CompletionFilter 20
#define FLAG_ShowMenuBar 22
#define FLAG_C_CaseDelta 23
#define FLAG_C_ClassOfs 24
#define FLAG_C_ClassDelta 25
#define FLAG_C_ColonOfs 26
#define FLAG_C_CommentOfs 27
#define FLAG_C_CommentDelta 28
#define FLAG_OpenAfterClose 30
#define FLAG_PrintDevice 31
#define FLAG_CompileCommand 32
#define FLAG_REXX_Do_Offset 33
#define FLAG_KeepHistory 34
#define FLAG_LoadDesktopOnEntry 35
#define FLAG_SaveDesktopOnExit 36
#define FLAG_WindowFont 37
#define FLAG_KeepMessages 38
#define FLAG_ScrollBorderX 39
#define FLAG_ScrollBorderY 40
#define FLAG_ScrollJumpX 41
#define FLAG_ScrollJumpY 42
#define FLAG_ShowToolBar 43
#define FLAG_GUIDialogs 44
#define FLAG_PMDisableAccel 45
#define FLAG_SevenBit 46
#define FLAG_WeirdScroll 47
#define FLAG_LoadDesktopMode 48
#define FLAG_HelpCommand 49
#define FLAG_C_FirstLevelIndent 50
#define FLAG_C_FirstLevelWidth 51
#define FLAG_C_Continuation 52
#define FLAG_C_ParenDelta 32
#define EM_MENUS 2
#define EM_MainMenu 0
#define EM_LocalMenu 1
#define COL_SyntaxParser 1
#define CLR_Normal 0
#define CLR_Keyword 1
#define CLR_String 2
#define CLR_Comment 3
#define CLR_CPreprocessor 4
#define CLR_Regexp 5
#define CLR_Header 6
#define CLR_Quotes 7
#define CLR_Number 8
#define CLR_HexNumber 9
#define CLR_OctalNumber 10
#define CLR_FloatNumber 11
#define CLR_Function 12
#define CLR_Command 13
#define CLR_Tag 14
#define CLR_Punctuation 15
#define CLR_New 16
#define CLR_Old 17
#define CLR_Changed 18
#define CLR_Control 19
#define CLR_Separator 20
#define CLR_Variable 21
#define CLR_Symbol 22
#define CLR_Directive 23
#define CLR_Label 24
#define CLR_Special 25
#define CLR_QuoteDelim 26
#define CLR_RegexpDelim 27
#define COUNT_CLR 28
#define MATCH_MUST_BOL 0x0001
#define MATCH_MUST_BOLW 0x0002
#define MATCH_MUST_EOL 0x0004
#define MATCH_MUST_EOLW 0x0008
#define MATCH_NO_CASE 0x0010
#define MATCH_SET 0x0020
#define MATCH_NOTSET 0x0040
#define MATCH_QUOTECH 0x0100
#define MATCH_QUOTEEOL 0x0200
#define MATCH_NOGRAB 0x0400
#define MATCH_NEGATE 0x0800
#define MATCH_TAGASNEXT 0x1000
#define ACTION_NXSTATE 0x0001
#define STATE_NOCASE 0x0001
#define STATE_TAGASNEXT 0x0002
#define STATE_NOGRAB 0x0004
typedef enum {
mvFilePath = 1, /* directory + name + extension */
mvFileName, /* name + extension */
mvFileDirectory, /* directory + '/' */
mvFileBaseName, /* without the last extension */
mvFileExtension, /* the last one */
mvCurDirectory,
mvCurRow,
mvCurCol,
mvChar,
mvWord,
mvLine
} MacroVariable;
#endif

1789
src/cfte.cpp Normal file

File diff suppressed because it is too large Load diff

3
src/cfte.def Normal file
View file

@ -0,0 +1,3 @@
NAME cfte WINDOWCOMPAT
DESCRIPTION 'FTE Configuration Compiler'
STACKSIZE 49152

28
src/clip.h Normal file
View file

@ -0,0 +1,28 @@
/* clip.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __CLIPLIB_H
#define __CLIPLIB_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned long fLen;
char *fChar;
} ClipData;
int GetClipText(ClipData *cd);
int PutClipText(ClipData *cd);
#ifdef __cplusplus
}
#endif
#endif

18
src/clip_gpm.cpp Normal file
View file

@ -0,0 +1,18 @@
/* clip_gpm.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int GetPMClip() {
return 0;
}
int PutPMClip() {
return 0;
}

18
src/clip_no.cpp Normal file
View file

@ -0,0 +1,18 @@
/* clip_no.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int GetPMClip() {
return 0;
}
int PutPMClip() {
return 0;
}

71
src/clip_os2.cpp Normal file
View file

@ -0,0 +1,71 @@
/* clip_os2.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#include "clip.h"
int GetPMClip() {
ClipData cd;
unsigned int i,j, l, dx;
EPoint P;
if (GetClipText(&cd) == 0) {
SSBuffer->Clear();
j = 0;
l = 0;
for (i = 0; i < cd.fLen; i++) {
if (cd.fChar[i] == 0x0A) {
SSBuffer->AssertLine(l);
P.Col = 0; P.Row = l++;
dx = 0;
if ((i > 0) && (cd.fChar[i-1] == 0x0D)) dx++;
SSBuffer->InsertLine(P, i - j - dx, cd.fChar + j);
j = i + 1;
}
}
if (j < cd.fLen) { // remainder
i = cd.fLen;
SSBuffer->AssertLine(l);
P.Col = 0; P.Row = l++;
dx = 0;
if ((i > 0) && (cd.fChar[i-1] == 0x0D)) dx++;
SSBuffer->InsText(P.Row, P.Col, i - j - dx, cd.fChar + j);
j = i + 1;
}
}
return 0;
}
int PutPMClip() {
char *p = 0;
int l = 0;
PELine L;
int Len;
ClipData cd;
int rc;
for (int i = 0; i < SSBuffer->RCount; i++) {
L = SSBuffer->RLine(i);
p = (char *)realloc(p, l + (Len = L->Count) + 2);
memcpy(p + l, L->Chars, L->Count);
l += Len;
if (i < SSBuffer->RCount - 1) {
p[l++] = 13;
p[l++] = 10;
}
}
p = (char *)realloc(p, l + 1);
p[l++] = 0;
cd.fChar = p;
cd.fLen = l;
rc = (PutClipText(&cd) == 0);
free(p);
return rc?1:0;
}

57
src/clip_pm.cpp Normal file
View file

@ -0,0 +1,57 @@
/* clip_pm.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#include "clip.h"
#define INCL_WIN
#include <os2.h>
#include <string.h>
#include <stdlib.h>
extern HAB hab;
int GetClipText(ClipData *cd) {
int rc;
char *text;
cd->fLen = 0;
cd->fChar = 0;
if ((WinOpenClipbrd(hab) == TRUE) &&
((text = (char *) WinQueryClipbrdData(hab, CF_TEXT)) != 0))
{
cd->fLen = strlen(text);
cd->fChar = strdup(text);
}
WinCloseClipbrd(hab);
return 0;
}
int PutClipText(ClipData *cd) {
ULONG len;
void *text;
if (WinOpenClipbrd(hab) == TRUE) {
WinEmptyClipbrd(hab);
len = cd->fLen;
if (len) {
DosAllocSharedMem((void **)&text,
0,
len + 1,
PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
strncpy((char *)text, cd->fChar, len + 1);
if (!WinSetClipbrdData(hab, (ULONG) text, CF_TEXT, CFI_POINTER))
DosBeep(100, 1500);
}
WinCloseClipbrd(hab);
}
return 0;
}

439
src/clip_pmv.cpp Normal file
View file

@ -0,0 +1,439 @@
/* clip_pm.cpp
*
* Copyright (c) 1994-1998, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#include "clip.h"
#define INCL_WIN
#define INCL_DOS
#define INCL_ORDINALS
#include <os2.h>
#include <string.h>
#include <stdlib.h>
/*
* Pointers to PM functions
* Instead of calling PM directly, we are obtaining these pointers
* on first access to clipboard.
* All these prototypes are copied from OS2.H
* Note: all prototypes are 32-bit version only
*/
#define ORD_WIN32ADDATOM 700
#define ORD_WIN32ALARM 701
#define ORD_WIN32BEGINENUMWINDOWS 702
#define ORD_WIN32BEGINPAINT 703
#define ORD_WIN32CALCFRAMERECT 704
#define ORD_WIN32CANCELSHUTDOWN 705
#define ORD_WIN32CLOSECLIPBRD 707
#define ORD_WIN32COMPARESTRINGS 708
#define ORD_WIN32COPYACCELTABLE 709
#define ORD_WIN32COPYRECT 710
#define ORD_WIN32CPTRANSLATECHAR 711
#define ORD_WIN32CPTRANSLATESTRING 712
#define ORD_WIN32CREATEACCELTABLE 713
#define ORD_WIN32CREATEATOMTABLE 714
#define ORD_WIN32CREATECURSOR 715
#define ORD_WIN32CREATEMSGQUEUE 716
#define ORD_WIN32CREATEPOINTER 717
#define ORD_WIN32DDEINITIATE 718
#define ORD_WIN32DDEPOSTMSG 719
#define ORD_WIN32DDERESPOND 720
#define ORD_WIN32DELETEATOM 721
#define ORD_WIN32DELETELIBRARY 722
#define ORD_WIN32DESTROYACCELTABLE 723
#define ORD_WIN32DESTROYATOMTABLE 724
#define ORD_WIN32DESTROYCURSOR 725
#define ORD_WIN32DESTROYMSGQUEUE 726
#define ORD_WIN32DESTROYPOINTER 727
#define ORD_WIN32DESTROYWINDOW 728
#define ORD_WIN32DISMISSDLG 729
#define ORD_WIN32DRAWBITMAP 730
#define ORD_WIN32DRAWBORDER 731
#define ORD_WIN32DRAWPOINTER 732
#define ORD_WIN32EMPTYCLIPBRD 733
#define ORD_WIN32ENABLEPHYSINPUT 734
#define ORD_WIN32ENABLEWINDOW 735
#define ORD_WIN32ENABLEWINDOWUPDATE 736
#define ORD_WIN32ENDENUMWINDOWS 737
#define ORD_WIN32ENDPAINT 738
#define ORD_WIN32ENUMCLIPBRDFMTS 739
#define ORD_WIN32ENUMDLGITEM 740
#define ORD_WIN32EQUALRECT 741
#define ORD_WIN32EXCLUDEUPDATEREGION 742
#define ORD_WIN32FILLRECT 743
#define ORD_WIN32FINDATOM 744
#define ORD_WIN32FLASHWINDOW 745
#define ORD_WIN32FOCUSCHANGE 746
#define ORD_WIN32FREEERRORINFO 748
#define ORD_WIN32GETCLIPPS 749
#define ORD_WIN32GETCURRENTTIME 750
#define ORD_WIN32GETERRORINFO 751
#define ORD_WIN32GETKEYSTATE 752
#define ORD_WIN32GETLASTERROR 753
#define ORD_WIN32GETMAXPOSITION 754
#define ORD_WIN32GETMINPOSITION 755
#define ORD_WIN32GETNEXTWINDOW 756
#define ORD_WIN32GETPS 757
#define ORD_WIN32GETPHYSKEYSTATE 758
#define ORD_WIN32GETSCREENPS 759
#define ORD_WIN32GETSYSBITMAP 760
#define ORD_WIN32INSENDMSG 761
#define ORD_WIN32INFLATERECT 762
#define ORD_WIN32INITIALIZE 763
#define ORD_WIN32INTERSECTRECT 764
#define ORD_WIN32INVALIDATERECT 765
#define ORD_WIN32INVALIDATEREGION 766
#define ORD_WIN32INVERTRECT 767
#define ORD_WIN32ISCHILD 768
#define ORD_WIN32ISPHYSINPUTENABLED 769
#define ORD_WIN32ISRECTEMPTY 770
#define ORD_WIN32ISTHREADACTIVE 771
#define ORD_WIN32ISWINDOW 772
#define ORD_WIN32ISWINDOWENABLED 773
#define ORD_WIN32ISWINDOWSHOWING 774
#define ORD_WIN32ISWINDOWVISIBLE 775
#define ORD_WIN32LOADACCELTABLE 776
#define ORD_WIN32LOADLIBRARY 777
#define ORD_WIN32LOADMENU 778
#define ORD_WIN32LOADMESSAGE 779
#define ORD_WIN32LOADPOINTER 780
#define ORD_WIN32LOADSTRING 781
#define ORD_WIN32LOCKVISREGIONS 782
#define ORD_WIN32LOCKWINDOWUPDATE 784
#define ORD_WIN32MAKEPOINTS 785
#define ORD_WIN32MAKERECT 786
#define ORD_WIN32MAPDLGPOINTS 787
#define ORD_WIN32MAPWINDOWPOINTS 788
#define ORD_WIN32MESSAGEBOX 789
#define ORD_WIN32MSGSEMWAIT 790
#define ORD_WIN32NEXTCHAR 791
#define ORD_WIN32OFFSETRECT 792
#define ORD_WIN32OPENCLIPBRD 793
#define ORD_WIN32OPENWINDOWDC 794
#define ORD_WIN32PREVCHAR 795
#define ORD_WIN32PROCESSDLG 796
#define ORD_WIN32PTINRECT 797
#define ORD_WIN32QUERYACCELTABLE 798
#define ORD_WIN32QUERYACTIVEWINDOW 799
#define ORD_WIN32QUERYANCHORBLOCK 800
#define ORD_WIN32QUERYATOMLENGTH 801
#define ORD_WIN32QUERYATOMNAME 802
#define ORD_WIN32QUERYATOMUSAGE 803
#define ORD_WIN32QUERYCAPTURE 804
#define ORD_WIN32QUERYCLASSNAME 805
#define ORD_WIN32QUERYCLIPBRDDATA 806
#define ORD_WIN32QUERYCLIPBRDFMTINFO 807
#define ORD_WIN32QUERYCLIPBRDOWNER 808
#define ORD_WIN32QUERYCLIPBRDVIEWER 809
#define ORD_WIN32QUERYCP 810
#define ORD_WIN32QUERYCPLIST 811
#define ORD_WIN32QUERYCURSORINFO 812
#define ORD_WIN32QUERYDESKTOPWINDOW 813
#define ORD_WIN32QUERYDLGITEMSHORT 814
#define ORD_WIN32QUERYDLGITEMTEXT 815
#define ORD_WIN32QUERYDLGITEMTEXTLENGTH 816
#define ORD_WIN32QUERYFOCUS 817
#define ORD_WIN32QUERYMSGPOS 818
#define ORD_WIN32QUERYMSGTIME 819
#define ORD_WIN32QUERYOBJECTWINDOW 820
#define ORD_WIN32QUERYPOINTER 821
#define ORD_WIN32QUERYPOINTERINFO 822
#define ORD_WIN32QUERYPOINTERPOS 823
#define ORD_WIN32QUERYQUEUEINFO 824
#define ORD_WIN32QUERYQUEUESTATUS 825
#define ORD_WIN32QUERYSYSCOLOR 826
#define ORD_WIN32QUERYSYSMODALWINDOW 827
#define ORD_WIN32QUERYSYSPOINTER 828
#define ORD_WIN32QUERYSYSVALUE 829
#define ORD_WIN32QUERYSYSTEMATOMTABLE 830
#define ORD_WIN32QUERYUPDATERECT 831
#define ORD_WIN32QUERYUPDATEREGION 832
#define ORD_WIN32QUERYVERSION 833
#define ORD_WIN32QUERYWINDOW 834
#define ORD_WIN32QUERYWINDOWDC 835
#define ORD_WIN32QUERYWINDOWPOS 837
#define ORD_WIN32QUERYWINDOWPROCESS 838
#define ORD_WIN32QUERYWINDOWPTR 839
#define ORD_WIN32QUERYWINDOWRECT 840
#define ORD_WIN32QUERYWINDOWTEXT 841
#define ORD_WIN32QUERYWINDOWTEXTLENGTH 842
#define ORD_WIN32QUERYWINDOWULONG 843
#define ORD_WIN32QUERYWINDOWUSHORT 844
#define ORD_WIN32REGISTERUSERDATATYPE 845
#define ORD_WIN32REGISTERUSERMSG 846
#define ORD_WIN32RELEASEPS 848
#define ORD_WIN32SCROLLWINDOW 849
#define ORD_WIN32SETACCELTABLE 850
#define ORD_WIN32SETACTIVEWINDOW 851
#define ORD_WIN32SETCAPTURE 852
#define ORD_WIN32SETCLASSMSGINTEREST 853
#define ORD_WIN32SETCLIPBRDDATA 854
#define ORD_WIN32SETCLIPBRDOWNER 855
#define ORD_WIN32SETCLIPBRDVIEWER 856
#define ORD_WIN32SETCP 857
#define ORD_WIN32SETDLGITEMSHORT 858
#define ORD_WIN32SETDLGITEMTEXT 859
#define ORD_WIN32SETFOCUS 860
#define ORD_WIN32SETMSGINTEREST 861
#define ORD_WIN32SETMSGMODE 862
#define ORD_WIN32SETMULTWINDOWPOS 863
#define ORD_WIN32SETOWNER 864
#define ORD_WIN32SETPARENT 865
#define ORD_WIN32SETPOINTER 866
#define ORD_WIN32SETPOINTERPOS 867
#define ORD_WIN32SETRECT 868
#define ORD_WIN32SETRECTEMPTY 869
#define ORD_WIN32SETSYNCHROMODE 870
#define ORD_WIN32SETSYSCOLORS 871
#define ORD_WIN32SETSYSMODALWINDOW 872
#define ORD_WIN32SETSYSVALUE 873
#define ORD_WIN32SETWINDOWBITS 874
#define ORD_WIN32SETWINDOWPOS 875
#define ORD_WIN32SETWINDOWPTR 876
#define ORD_WIN32SETWINDOWTEXT 877
#define ORD_WIN32SETWINDOWULONG 878
#define ORD_WIN32SETWINDOWUSHORT 879
#define ORD_WIN32SHOWCURSOR 880
#define ORD_WIN32SHOWPOINTER 881
#define ORD_WIN32SHOWTRACKRECT 882
#define ORD_WIN32SHOWWINDOW 883
#define ORD_WIN32STARTTIMER 884
#define ORD_WIN32STOPTIMER 885
#define ORD_WIN32SUBSTITUTESTRINGS 886
#define ORD_WIN32SUBTRACTRECT 887
#define ORD_WIN32TERMINATE 888
#define ORD_WIN32TRACKRECT 890
#define ORD_WIN32UNIONRECT 891
#define ORD_WIN32UPDATEWINDOW 892
#define ORD_WIN32UPPER 893
#define ORD_WIN32UPPERCHAR 894
#define ORD_WIN32VALIDATERECT 895
#define ORD_WIN32VALIDATEREGION 896
#define ORD_WIN32WAITMSG 897
#define ORD_WIN32WINDOWFROMDC 898
#define ORD_WIN32WINDOWFROMID 899
#define ORD_WIN32WINDOWFROMPOINT 900
#define ORD_WIN32BROADCASTMSG 901
#define ORD_WIN32POSTQUEUEMSG 902
#define ORD_WIN32SENDDLGITEMMSG 903
#define ORD_WIN32TRANSLATEACCEL 904
#define ORD_WIN32CALLMSGFILTER 905
#define ORD_WIN32CREATEFRAMECONTROLS 906
#define ORD_WIN32CREATEMENU 907
#define ORD_WIN32CREATESTDWINDOW 908
#define ORD_WIN32CREATEWINDOW 909
#define ORD_WIN32DEFDLGPROC 910
#define ORD_WIN32DEFWINDOWPROC 911
#define ORD_WIN32DISPATCHMSG 912
#define ORD_WIN32DRAWTEXT 913
#define ORD_WIN32GETDLGMSG 914
#define ORD_WIN32GETMSG 915
#define ORD_WIN32MSGMUXSEMWAIT 916
#define ORD_WIN32MULTWINDOWFROMIDS 917
#define ORD_WIN32PEEKMSG 918
#define ORD_WIN32POSTMSG 919
#define ORD_WIN32SENDMSG 920
#define ORD_WIN32SETKEYBOARDSTATETABLE 921
#define ORD_WIN32CREATEDLG 922
#define ORD_WIN32DLGBOX 923
#define ORD_WIN32LOADDLG 924
#define ORD_WIN32QUERYCLASSINFO 925
#define ORD_WIN32REGISTERCLASS 926
#define ORD_WIN32RELEASEHOOK 927
#define ORD_WIN32SETHOOK 928
#define ORD_WIN32SUBCLASSWINDOW 929
#define ORD_WIN32SETCLASSTHUNKPROC 930
#define ORD_WIN32QUERYCLASSTHUNKPROC 931
#define ORD_WIN32SETWINDOWTHUNKPROC 932
#define ORD_WIN32QUERYWINDOWTHUNKPROC 933
#define ORD_WIN32QUERYWINDOWMODEL 934
#define ORD_WIN32SETDESKTOPBKGND 935
#define ORD_WIN32QUERYDESKTOPBKGND 936
#define ORD_WIN32POPUPMENU 937
#define ORD_WIN32SETPRESPARAM 938
#define ORD_WIN32QUERYPRESPARAM 939
#define ORD_WIN32REMOVEPRESPARAM 940
#define ORD_WIN32REALIZEPALETTE 941
#define ORD_WIN32CREATEPOINTERINDIRECT 942
#define ORD_WIN32SAVEWINDOWPOS 943
#define ORD_WIN32GETERASEPS 952
#define ORD_WIN32RELEASEERASEPS 953
#define ORD_WIN32SETPOINTEROWNER 971
#define ORD_WIN32STRETCHPOINTER 968
#define ORD_WIN32SETERRORINFO 977
#define ORD_WIN32WAITEVENTSEM 978
#define ORD_WIN32REQUESTMUTEXSEM 979
#define ORD_WIN32WAITMUXWAITSEM 980
#ifndef INCL_32
#error Prototypes are for 32-bit compiler only
#endif
HAB (APIENTRY *p_WinInitialize)(ULONG flOptions);
BOOL (APIENTRY *p_WinTerminate)(HAB hab);
HMQ (APIENTRY *p_WinCreateMsgQueue)(HAB hab, LONG cmsg);
BOOL (APIENTRY *p_WinDestroyMsgQueue)(HMQ hmq);
BOOL (APIENTRY *p_WinEmptyClipbrd)(HAB hab);
BOOL (APIENTRY *p_WinOpenClipbrd)(HAB hab);
BOOL (APIENTRY *p_WinCloseClipbrd)(HAB hab);
BOOL (APIENTRY *p_WinSetClipbrdData)(HAB hab, ULONG ulData, ULONG fmt, ULONG rgfFmtInfo);
ULONG (APIENTRY *p_WinQueryClipbrdData)(HAB hab, ULONG fmt);
static struct impentry {
ULONG ordinal;
PFN *pointer;
} imported_functions[] = {
{ ORD_WIN32INITIALIZE, (PFN *) &p_WinInitialize },
{ ORD_WIN32TERMINATE, (PFN *) &p_WinTerminate },
{ ORD_WIN32CREATEMSGQUEUE, (PFN *) &p_WinCreateMsgQueue },
{ ORD_WIN32DESTROYMSGQUEUE,(PFN *) &p_WinDestroyMsgQueue },
{ ORD_WIN32EMPTYCLIPBRD, (PFN *) &p_WinEmptyClipbrd },
{ ORD_WIN32OPENCLIPBRD, (PFN *) &p_WinOpenClipbrd },
{ ORD_WIN32CLOSECLIPBRD, (PFN *) &p_WinCloseClipbrd },
{ ORD_WIN32SETCLIPBRDDATA, (PFN *) &p_WinSetClipbrdData },
{ ORD_WIN32QUERYCLIPBRDDATA,(PFN *)&p_WinQueryClipbrdData },
{ 0, 0 }
};
/*
* Load PMWIN.DLL and get pointers to all reqd PM functions
*/
static BOOL loadDLL(void) {
static BOOL loaded = FALSE;
static BOOL loaded_ok = FALSE;
static HMODULE pmwin;
char error[200];
if (loaded == TRUE)
return loaded_ok;
loaded = TRUE;
if (DosLoadModule((PSZ)error, sizeof(error), (PSZ)"PMWIN.DLL", &pmwin) == 0) {
struct impentry *imp;
for (imp = imported_functions; imp->ordinal; imp++)
if (DosQueryProcAddr(pmwin, imp->ordinal, NULL, imp->pointer) != 0)
return FALSE;
loaded_ok = TRUE;
}
return loaded_ok;
}
/*
AccessPmClipboard:
Purpose: perform all necessary PM stuff and open clipboard for access;
Return : TRUE on success, FALSE on error;
Note : on error, clipboard is released automatically.
LeavePmClipboard:
Purpose: releases previously opened clipboard and clear all PM stuff
Return : none
*/
static struct {
PPIB ppib;
HAB hab;
HMQ hmq;
ULONG savedtype;
BOOL opened;
} PmInfo;
static void LeavePmClipboard(void) {
if (PmInfo.opened)
p_WinCloseClipbrd(PmInfo.hab);
if (PmInfo.hmq)
p_WinDestroyMsgQueue(PmInfo.hmq);
if (PmInfo.hab)
p_WinTerminate(PmInfo.hab);
PmInfo.ppib->pib_ultype = PmInfo.savedtype;
}
static BOOL AccessPmClipboard(void) {
PTIB ptib;
if (loadDLL() == FALSE) {
DosBeep(100, 1500);
return FALSE;
}
memset(&PmInfo, 0, sizeof(PmInfo));
// mutate into PM application for clipboard (Win**) functions access
DosGetInfoBlocks(&ptib, &PmInfo.ppib);
PmInfo.savedtype = PmInfo.ppib->pib_ultype;
PmInfo.ppib->pib_ultype = PROG_PM;
if ((PmInfo.hab = p_WinInitialize(0)) != NULLHANDLE) {
if ((PmInfo.hmq = p_WinCreateMsgQueue(PmInfo.hab, 0)) != NULLHANDLE) {
if (p_WinOpenClipbrd(PmInfo.hab) == TRUE) {
PmInfo.opened = TRUE;
}
}
}
if (PmInfo.opened != TRUE) {
LeavePmClipboard();
DosBeep(100, 1500);
}
return PmInfo.opened;
}
int GetClipText(ClipData *cd) {
int rc = -1;
char *text;
cd->fLen = 0;
cd->fChar = 0;
if (AccessPmClipboard() != TRUE)
return rc;
if ((text = (char *) p_WinQueryClipbrdData(PmInfo.hab, CF_TEXT)) != 0) {
cd->fLen = strlen(text);
cd->fChar = strdup(text);
rc = 0;
}
LeavePmClipboard();
return rc;
}
int PutClipText(ClipData *cd) {
ULONG len;
void *text;
int rc = -1;
if (AccessPmClipboard() != TRUE)
return rc;
p_WinEmptyClipbrd(PmInfo.hab);
len = cd->fLen;
if (len) {
DosAllocSharedMem((void **)&text,
0,
len + 1,
PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
strncpy((char *)text, cd->fChar, len + 1);
if (!p_WinSetClipbrdData(PmInfo.hab, (ULONG) text, CF_TEXT, CFI_POINTER))
DosBeep(100, 1500);
else
rc = 0;
}
LeavePmClipboard();
return rc;
}

103
src/clip_vio.cpp Normal file
View file

@ -0,0 +1,103 @@
/* clip_vio.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
// OS/2 does not allow VIO programs to use the clipboard :-(
#include "fte.h"
#include "clip.h"
#define INCL_DOS
#include <os2.h>
#include <string.h>
#include <stdlib.h>
#define SEM_PREFIX "\\SEM32\\PMCLIPS\\"
#define MEM_PREFIX "\\SHAREMEM\\PMCLIPS\\"
#define CMD_GET 1
#define CMD_PUT 2
static HMTX hmtxSyn;
static HEV hevGet;
static HEV hevPut;
static HEV hevEnd;
int GetClipText(ClipData *cd) {
int rc;
ULONG PostCount;
char *mem;
rc = DosOpenMutexSem(SEM_PREFIX "CLIPSYN", &hmtxSyn);
if (rc != 0) return -1;
rc = DosOpenEventSem(SEM_PREFIX "CLIPGET", &hevGet);
if (rc != 0) return -1;
/* rc = DosOpenEventSem(SEM_PREFIX "CLIPPUT", &hevPut);*/
/* if (rc != 0) return -1;*/
rc = DosOpenEventSem(SEM_PREFIX "CLIPEND", &hevEnd);
if (rc != 0) return -1;
DosRequestMutexSem(hmtxSyn, SEM_INDEFINITE_WAIT);
DosResetEventSem(hevEnd, &PostCount);
DosPostEventSem(hevGet);
DosWaitEventSem(hevEnd, SEM_INDEFINITE_WAIT);
if (0 == DosGetNamedSharedMem((void **)&mem, MEM_PREFIX "CLIPDATA", PAG_READ | PAG_WRITE)) {
cd->fLen = *(ULONG*)mem;
cd->fChar = strdup(mem + 4);
DosFreeMem(mem);
} else {
cd->fLen = 0;
cd->fChar = 0;
}
DosPostEventSem(hevGet);
DosReleaseMutexSem(hmtxSyn);
/* DosCloseEventSem(hevPut);*/
DosCloseEventSem(hevGet);
DosCloseEventSem(hevEnd);
DosCloseMutexSem(hmtxSyn);
return 0;
}
int PutClipText(ClipData *cd) {
int rc;
ULONG PostCount;
char *mem;
rc = DosOpenMutexSem(SEM_PREFIX "CLIPSYN", &hmtxSyn);
if (rc != 0) return -1;
/* rc = DosOpenEventSem(SEM_PREFIX "CLIPGET", &hevGet);*/
/* if (rc != 0) return -1;*/
rc = DosOpenEventSem(SEM_PREFIX "CLIPPUT", &hevPut);
if (rc != 0) return -1;
rc = DosOpenEventSem(SEM_PREFIX "CLIPEND", &hevEnd);
if (rc != 0) return -1;
DosRequestMutexSem(hmtxSyn, SEM_INDEFINITE_WAIT);
DosResetEventSem(hevEnd, &PostCount);
if (0 == DosAllocSharedMem((void **)&mem,
MEM_PREFIX "CLIPDATA",
cd->fLen + 5,
PAG_COMMIT | PAG_READ | PAG_WRITE))
{
ULONG L = cd->fLen;
memcpy((void *)mem, (void *)&L, 4);
strcpy(mem + 4, cd->fChar);
}
DosPostEventSem(hevPut);
DosWaitEventSem(hevEnd, SEM_INDEFINITE_WAIT);
DosPostEventSem(hevPut);
DosReleaseMutexSem(hmtxSyn);
DosCloseEventSem(hevPut);
/* DosCloseEventSem(hevGet); */
DosCloseEventSem(hevEnd);
DosCloseMutexSem(hmtxSyn);
if (mem)
DosFreeMem(mem);
return 0;
}

83
src/clip_x11.cpp Normal file
View file

@ -0,0 +1,83 @@
/* clip_x11.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int GetXSelection(int *len, char **data);
int SetXSelection(int len, char *data);
int GetPMClip() {
char *data;
int len;
int i,j, l, dx;
EPoint P;
if (GetXSelection(&len, &data) == 0) {
SSBuffer->Clear();
j = 0;
l = 0;
for (i = 0; i < len; i++) {
if (data[i] == '\n') {
SSBuffer->AssertLine(l);
P.Col = 0; P.Row = l++;
dx = 0;
if ((i > 0) && (data[i-1] == '\r')) dx++;
SSBuffer->InsertLine(P, i - j - dx, data + j);
j = i + 1;
}
}
if (j < len) { // remainder
i = len;
SSBuffer->AssertLine(l);
P.Col = 0; P.Row = l++;
dx = 0;
if ((i > 0) && (data[i-1] == '\r')) dx++;
SSBuffer->InsText(P.Row, P.Col, i - j - dx, data + j);
j = i + 1;
}
free(data);
return 1;
}
return 0;
}
int PutPMClip() {
PELine L;
char *p = NULL;
int rc = 0;
int l = 0;
for (int i = 0; i < SSBuffer->RCount; i++) {
L = SSBuffer->RLine(i);
char *n = (char *)realloc(p, l + L->Count + 1);
if (n != NULL) {
for(int j = 0; j < L->Count; j++) {
if ((j < (L->Count - 1)) && (L->Chars[j + 1] == '\b'))
j++;
else
n[l++] = L->Chars[j];
}
if (i < SSBuffer->RCount - 1)
n[l++] = '\n';
else
n[l] = 0;
} else
break;
p = n; // if p already contains some address it will be freed
}
if (p != NULL) {
// remove some 'UNWANTED' characters - sequence XX 0x08 YY -> YY
// this makes usable cut&paste from manpages
rc = (SetXSelection(l, p) == 0);
free(p);
}
return (rc)?1:0;
}

73
src/clipprog.cpp Normal file
View file

@ -0,0 +1,73 @@
/* clipprog.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#define INCL_DOS
#define INCL_PM
#include <os2.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#define SEM_PREFIX "\\SEM32\\PMCLIPS\\"
#define MEM_PREFIX "\\SHAREMEM\\PMCLIPS\\"
#define CMD_GET 1
#define CMD_PUT 2
HAB hab;
HMQ hmq;
QMSG qmsg;
HMTX hmtxSyn;
HEV hevGet;
HEV hevPut;
HEV hevEnd;
HMUX hmuxWait;
void clipsrv(void *foo) {
HAB hab;
HMQ hmq;
ULONG Cmd;
ULONG len;
char *text;
void *shmem = "the text";
hab = NULLHANDLE;
if ((WinOpenClipbrd(hab) == TRUE) &&
((text = (char *) WinQueryClipbrdData(hab, CF_TEXT)) != 0))
{
DosGetSharedMem(text, PAG_READ);
len = strlen(text);
puts(text);
}
WinCloseClipbrd(hab);
len = strlen(shmem);
if (len) {
DosAllocSharedMem((void **)&text,
0,
len + 1,
PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE | OBJ_GETTABLE);
strcpy(text, shmem);
}
if (WinOpenClipbrd(hab) == TRUE) {
if (!WinSetClipbrdData(hab, (ULONG) text, CF_TEXT, CFI_POINTER))
DosBeep(100, 1500);
WinCloseClipbrd(hab);
}
}
int main() {
clipsrv(NULL);
return 0;
}

185
src/clipserv.cpp Normal file
View file

@ -0,0 +1,185 @@
/* clipserv.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#define INCL_DOS
#define INCL_PM
#include <os2.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include "sysdep.h"
#define SEM_PREFIX "\\SEM32\\PMCLIPS\\"
#define MEM_PREFIX "\\SHAREMEM\\PMCLIPS\\"
#define CMD_GET 1
#define CMD_PUT 2
HAB hab;
HMQ hmq;
QMSG qmsg;
HMTX hmtxSyn;
HEV hevGet;
HEV hevPut;
HEV hevEnd;
HMUX hmuxWait;
void _LNK_CONV clipsrv(void *foo) {
HAB hab;
HMQ hmq;
hab = WinInitialize(0);
hmq = WinCreateMsgQueue(hab, 0);
while (1) {
ULONG ulPostCount;
ULONG Cmd;
ULONG len;
char *text;
void *shmem;
WinWaitMuxWaitSem(hmuxWait, SEM_INDEFINITE_WAIT, &Cmd);
switch (Cmd) {
case CMD_GET:
DosResetEventSem(hevGet, &ulPostCount);
shmem = 0;
if ((WinOpenClipbrd(hab) == TRUE) &&
((text = (char *) WinQueryClipbrdData(hab, CF_TEXT)) != 0))
{
len = strlen(text);
puts(text);
if (0 == DosAllocSharedMem(&shmem,
MEM_PREFIX "CLIPDATA",
len + 5,
PAG_COMMIT | PAG_WRITE | PAG_READ))
{
memcpy(shmem, (void *)&len, 4);
memcpy((void *)(((char *)shmem) + sizeof(ULONG)), text, len + 1);
} else {
DosBeep(200, 500);
}
} else {
/*DosBeep(100, 1500);*/
len = 0;
if (0 == DosAllocSharedMem(&shmem,
MEM_PREFIX "CLIPDATA",
4,
PAG_COMMIT | PAG_WRITE | PAG_READ))
{
memcpy(shmem, (void *)&len, 4);
}
}
WinCloseClipbrd(hab);
DosPostEventSem(hevEnd);
DosWaitEventSem(hevGet, SEM_INDEFINITE_WAIT);
DosResetEventSem(hevGet, &ulPostCount);
if (shmem) DosFreeMem(shmem);
break;
case CMD_PUT:
DosResetEventSem(hevPut, &ulPostCount);
if (0 == DosGetNamedSharedMem(&shmem,
MEM_PREFIX "CLIPDATA",
PAG_READ | PAG_WRITE))
{
if (WinOpenClipbrd(hab) == TRUE) {
WinEmptyClipbrd(hab);
len = strlen((char *)shmem + 4);
if (len) {
DosAllocSharedMem((void **)&text,
0,
len + 1,
PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE);
strcpy(text, ((char *)shmem) + 4);
if (!WinSetClipbrdData(hab, (ULONG) text, CF_TEXT, CFI_POINTER))
DosBeep(100, 1500);
}
WinCloseClipbrd(hab);
} else {
DosBeep(1500, 3500);
}
} else {
DosBeep(500, 7500);
}
DosPostEventSem(hevEnd);
DosWaitEventSem(hevPut, SEM_INDEFINITE_WAIT);
DosResetEventSem(hevPut, &ulPostCount);
if (shmem) DosFreeMem(shmem);
break;
}
}
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
}
int main() {
SEMRECORD sem[2];
int rc;
rc = DosCreateMutexSem(SEM_PREFIX "CLIPSYN",
&hmtxSyn,
0,
0);
if (rc != 0) return 1;
puts("CLIPSYN");
rc = DosCreateEventSem(SEM_PREFIX "CLIPEND",
&hevEnd,
0,
0);
if (rc != 0) return 1;
puts("CLIPEND");
rc = DosCreateEventSem(SEM_PREFIX "CLIPGET",
&hevGet,
0,
0);
if (rc != 0) return 1;
puts("CLIPGET");
rc = DosCreateEventSem(SEM_PREFIX "CLIPPUT",
&hevPut,
0,
0);
if (rc != 0) return 1;
puts("CLIPPUT");
sem[0].hsemCur = (PULONG) hevGet;
sem[0].ulUser = CMD_GET;
sem[1].hsemCur = (PULONG) hevPut;
sem[1].ulUser = CMD_PUT;
rc = DosCreateMuxWaitSem(0,
&hmuxWait,
2,
sem,
DCMW_WAIT_ANY);
if (rc != 0) return 1;
puts("CLIPMUX");
hab = WinInitialize(0);
hmq = WinCreateMsgQueue(hab, 0);
#if defined(__EMX__) || defined(__TOS_OS2__)
_beginthread(clipsrv, NULL, 8192, 0);
#else
_beginthread(clipsrv, 8192, 0);
#endif
while (WinGetMsg (hab, &qmsg, 0, 0, 0))
WinDispatchMsg (hab, &qmsg);
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
return 0;
}

3
src/clipserv.def Normal file
View file

@ -0,0 +1,3 @@
NAME clipserv WINDOWAPI
DESCRIPTION 'FTE Clipboard access server for VIO'
STACKSIZE 49152

50
src/cliputil.cpp Normal file
View file

@ -0,0 +1,50 @@
/* cliputil.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "clip.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXCLIPTEXT 256 * 1024 /* just for demo */
char buffer[MAXCLIPTEXT];
int main(int argc, char **argv) {
ClipData cd;
int i;
if ((argc == 2) && (strcmp(argv[1], "-s") == 0)) {
cd.fLen = fread(buffer, 1, MAXCLIPTEXT, stdin);
cd.fChar = buffer;
if (PutClipText(&cd) == -1) {
fprintf(stderr, "Coult not set clipboard text\n");
return 1;
}
} else if (argc == 1) {
if (GetClipText(&cd) == 0) {
if ((cd.fLen != 0) && cd.fChar) {
printf("%s", cd.fChar);
}
} else {
fprintf(stderr, "Could not get clipboard text\n");
return 1;
}
} else {
fprintf(stderr,
"Usage: %s {-s}\n"
"\n"
"Examples:\n"
" cliputil | more\n"
" dir | cliputil -s\n",
argv[0]);
return 1;
}
return 0;
}

3
src/cliputil.def Normal file
View file

@ -0,0 +1,3 @@
NAME ClipUtil WINDOWCOMPAT
DESCRIPTION 'Clipboard Utility - get/put clipboard text from command line'
STACKSIZE 49152

30
src/commands.cpp Normal file
View file

@ -0,0 +1,30 @@
/* commands.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int GetDefaultDirectory(EModel *M, char *Path, int MaxLen) {
if (M)
M->GetPath(Path, MaxLen);
if (!M || Path[0] == 0)
if (ExpandPath(".", Path) == -1)
return 0;
SlashDir(Path);
return 1;
}
int SetDefaultDirectory(EModel *M) {
char Path[MAXPATH];
if (GetDefaultDirectory(M, Path, sizeof(Path)) == 0)
return 0;
if (ChangeDir(Path) == -1)
return 0;
return 1;
}

457
src/compkeys.cpp Normal file
View file

@ -0,0 +1,457 @@
/*
* compkeys.cpp
*
* Copyright (c) 1998 by István Váradi
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "console.h"
#include "conkbd.h"
#define FTESL_KBDCTRL(x) ( x-'a'+ 1)
static unsigned get_linux_keycode(TKeyCode kcode)
{
static unsigned lnxkeycodes[] = {
/* 32 */
57, 2, 40, 4, 5, 6, 8, 40,
/* 40 */
10, 11, 9, 13, 51, 12, 52, 53,
/* 48 */
11, 2, 3, 4, 5, 6, 7, 8,
/* 56 */
9 , 10, 39, 39, 51, 13, 52, 53,
/* 64 */
3 , 30, 48, 46, 32, 18, 33, 34,
/* 72 */
35, 23, 36, 37, 38, 50, 49, 24,
/* 80 */
25, 16, 19, 31, 20, 22, 47, 17,
/* 88 */
45, 21, 44, 26, 86, 27, 7, 12,
/* 96 */
43, 30, 48, 46, 32, 18, 33, 34,
/* 104 */
35, 23, 36, 37, 38, 50, 49, 24,
/* 112 */
25, 16, 19, 31, 20, 22, 47, 17,
/* 120 */
45, 21, 44, 26, 86, 27, 43, 0,
};
TKeyCode key = keyCode(kcode)|(kcode&kfGray);
switch(key) {
case kbF1:
case kbF2:
case kbF3:
case kbF4:
case kbF5:
case kbF6:
case kbF7:
case kbF8:
case kbF9:
case kbF10:
return 59+key-kbF1;
break;
case kbF11:
return 87;
break;
case kbF12:
return 88;
break;
case kbHome:
return 102;
break;
case kbEnd:
return 107;
break;
case kbPgUp:
return 104;
break;
case kbPgDn:
return 109;
break;
case kbIns:
return 110;
break;
case kbDel:
return 111;
break;
case kbUp:
return 103;
break;
case kbDown:
return 108;
break;
case kbLeft:
return 105;
break;
case kbRight:
return 106;
break;
case kbEnter:
return 28;
break;
case kbEsc:
return 1;
break;
case kbBackSp:
return 14;
break;
case kbSpace:
return 57;
break;
case kbTab:
return 15;
break;
case kbCenter:
return 76;
break;
case kfGray|'/':
return 98;
break;
case kfGray|'*':
return 55;
break;
case kfGray|'+':
return 78;
break;
case kfGray|'-':
return 74;
break;
case kfGray|kbEnter:
return 96;
break;
case kfGray|'.':
return 83;
break;
case kfGray|'7':
case kfGray|kbHome:
return 71;
break;
case kfGray|'8':
case kfGray|kbUp:
return 72;
break;
case kfGray|'9':
case kfGray|kbPgUp:
return 73;
break;
case kfGray|'4':
case kfGray|kbLeft:
return 75;
break;
case kfGray|'5':
return 76;
break;
case kfGray|'6':
case kfGray|kbRight:
return 77;
break;
case kfGray|'1':
case kfGray|kbEnd:
return 79;
break;
case kfGray|'2':
case kfGray|kbDown:
return 80;
break;
case kfGray|'3':
case kfGray|kbPgDn:
return 81;
break;
default:
if (key<128 && key>32) return lnxkeycodes[key-32];
else return 0;
}
}
typedef struct keymapper
{
TKeyCode kcode;
const char* kname;
} keymapper;
static keymapper speckeymap[]={
{ kbHome, "Home" },
{ kbEnd, "End" },
{ kbPgUp, "PgUp" },
{ kbPgDn, "PgDn" },
{ kbIns, "Ins" },
{ kbDel, "Del" },
{ kbUp, "Up" },
{ kbDown, "Down" },
{ kbLeft, "Left" },
{ kbRight, "Right" },
{ kbEnter, "Enter" },
{ kbEsc, "Esc" },
{ kbBackSp, "BackSp" },
{ kbSpace, "Space" },
{ kbTab, "Tab" },
{ kbCenter, "Center" },
};
TKeyCode ftesl_getkeycode(const char* key)
{
TKeyCode kcode = 0;
if ( (*key)=='\0') return 0;
while (*(key+1)=='+') {
switch (*key) {
case 'A':
kcode|=kfAlt; break;
case 'C':
kcode|=kfCtrl; break;
case 'S':
kcode|=kfShift; break;
case 'G':
kcode|=kfGray; break;
default:
return 0;
break;
}
key+=2;
}
if ( (*key)=='\0') return 0;
if ( *(key+1)=='\0') {
kcode|=*(unsigned char *)key;
return kcode;
}
for(unsigned i=0; i<sizeof(speckeymap)/sizeof(keymapper); i++) {
if (!strcmp(key, speckeymap[i].kname)) {
kcode|=speckeymap[i].kcode;
return kcode;
}
}
if ( *key == 'F' ) {
key++;
if ( *key>='1' && *key<='9' ) {
if ( *key == '1' && *(key+1)!='\0' ) {
key++;
switch (*key) {
case '1':
kcode|=kbF11;
break;
case '2':
kcode|=kbF12;
break;
default:
return 0;
break;
}
return kcode;
}
kcode|=kbF1+(*key-'1');
return kcode;
}
}
return 0;
}
int ftesl_get_ctrlcode(TKeyCode key)
{
TKeyCode kcode = keyCode(key);
switch(kcode) {
case kbUp:
return FTESL_KBDCTRL('u');
case kbDown:
return FTESL_KBDCTRL('d');
case kbLeft:
return FTESL_KBDCTRL('l');
case kbRight:
return FTESL_KBDCTRL('r');
case kbCenter:
return FTESL_KBDCTRL('x');
case kbHome:
return FTESL_KBDCTRL('b');
case kbEnd:
return FTESL_KBDCTRL('e');
case kbPgUp:
return FTESL_KBDCTRL('p');
case kbPgDn:
return FTESL_KBDCTRL('n');
case kbIns:
return FTESL_KBDCTRL('q');
case kbDel:
return FTESL_KBDCTRL('z');
case kbBackSp:
return FTESL_KBDCTRL('h');
case kbTab:
return FTESL_KBDCTRL('i');
case kbEnter:
return FTESL_KBDCTRL('m');
}
if (kcode>=kbF1 && kcode<=kbF12) return FTESL_KBDCTRL('f');
else return (int)kcode;
}
int main(int argc, char* argv[])
{
FILE* fin;
FILE* fout;
char finname[255];
char foutname[255];
char linebuf[256];
char* lptr;
char keyspecbuf[32];
char* bufptr;
int err = 0;
unsigned linecnt = 0;
unsigned strcnt = 0;
//int opt;
finname[0] = '\0';
foutname[0] = '\0';
printf("Linux keymap compiler for SLang FTE, Copyright (c) 1998 by István Váradi\n\n");
if (argc<3) {
fprintf(stderr, "Usage: compkeys infile outfile\n\n");
fprintf(stderr, " where:\n");
fprintf(stderr, " infile: the file with the list of the keys\n");
fprintf(stderr, " outfile: the name of the output keymap file\n");
exit(-2);
}
strcpy(finname, argv[1]);
strcpy(foutname, argv[2]);
fin = fopen(finname, "rt");
if (fin==NULL) {
fprintf(stderr, "Can't open input file '%s' for reading.\n", finname);
return -1;
}
fout = fopen(foutname, "wb");
if (fout==NULL) {
fprintf(stderr, "Can't open output file '%s' for writing.\n", foutname);
fclose(fin);
return -1;
}
printf("Compiling from '%s' into '%s'.\n", finname, foutname);
fprintf(fout, "############################\n");
fprintf(fout, "# Keytable to use with FTE #\n");
fprintf(fout, "# generated by 'compkeys' #\n");
fprintf(fout, "############################\n\n");
err = 0;
while(!err && fgets(linebuf, sizeof(linebuf), fin)==linebuf) {
linecnt++;
lptr = linebuf;
while(!err) {
while(*lptr!='\0' && strchr(" \t", *lptr)!=NULL) lptr++;
if (*lptr=='#' || *lptr=='\0' || *lptr=='\n') break;
bufptr=keyspecbuf;
while(*lptr!='\0' && strchr(" \t\n", *lptr)==NULL)
*(bufptr++)=*(lptr++);
*(bufptr++)='\0';
TKeyCode kcode = ftesl_getkeycode(keyspecbuf), kcode1;
if (kcode==0) {
err = 2;
} else {
fprintf(fout, "\n# %s\n", keyspecbuf);
if (kcode&kfShift) fprintf(fout, "shift ");
if (kcode&kfCtrl) fprintf(fout, "control ");
if (kcode&kfAlt) fprintf(fout, "alt ");
fprintf(fout, "keycode %3u = F%u\n",
get_linux_keycode(kcode), 100+strcnt);
fprintf(fout, "string F%u = \"\\033", 100+strcnt);
if (kcode&kfShift) fprintf(fout, "\\023");
if (kcode&kfCtrl) fprintf(fout, "\\003");
if (kcode&kfAlt) fprintf(fout, "\\001");
int ccode = ftesl_get_ctrlcode(kcode);
fprintf(fout, "\\%03o", ccode);
if (ccode==FTESL_KBDCTRL('f')) {
kcode1 = keyCode(kcode);
switch(kcode1) {
case kbF1:
case kbF2:
case kbF3:
case kbF4:
case kbF5:
case kbF6:
case kbF7:
case kbF8:
case kbF9:
fprintf(fout, "%c", (int)'1'+int(kcode1-kbF1));
break;
case kbF10:
fprintf(fout, "0"); break;
case kbF11:
fprintf(fout, "a"); break;
case kbF12:
fprintf(fout, "b"); break;
}
}
fprintf(fout, "\"\n");
strcnt++;
}
}
}
fclose(fout);
fclose(fin);
if (err) {
fprintf(stderr, "line %u: ", linecnt);
switch (err) {
case 1:
fprintf(stderr, "syntax error");
break;
case 2:
fprintf(stderr, "invalid key specification: '%s'",
keyspecbuf);
}
fprintf(stderr, "\n");
remove(foutname);
} else {
printf("\nDone.\n");
}
if (err) return -1; else return 0;
}

1145
src/con_dosx.cpp Normal file

File diff suppressed because it is too large Load diff

397
src/con_i18n.cpp Normal file
View file

@ -0,0 +1,397 @@
/*
* con_i18n.cpp
*
* Copyright (c) 1998, Zdenek Kabelac
*
* I18N support by kabi@fi.muni.cz
*
* written as plain 'C' module and might be used
* in other programs to implement I18N support
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include "con_i18n.h"
#define KEYMASK 0xff
#define KEYBYTEMAX 0xf00
#ifdef USE_HARD_REMAP
/*
* This part is used when your Xserver doesn't work well with XKB extension
*/
/* Keyboard definition file - currently only Czech national keyboard
* write your own keyboard for your language
* And remember - this is supposed to be used only if your Xserver
* is not supporting keyboard extension
*/
#include "con_ikcz.h"
/*
* Quite a complex function to convert normal keys
* to dead-keys and remapped keys
*/
static int I18NKeyAnalyze(XKeyEvent * keyEvent, KeySym * key, /*fold00*/
char *keyName, int nbytes)
{
static long prev_state = 0, local_switch = 0,
keypos = 0, last_keypos = 0, remap = 0;
long i;
struct keyboardRec *kbdActual;
/* Find the state of keyboard
* Check for different ISO group or modifier 5
* So to activate remaping, you need to press at least
* ScrollLock which is usually mapped as modifier 5
*/
i = ((keyEvent->state | local_switch) & 0xFFA0);
if (i != prev_state) {
/* reset table position */
last_keypos = keypos = 0;
prev_state = i;
}
if (keyEvent->type == KeyPress) {
if (i && ((*key == XK_Pause) || (*key == XK_F21))) {
remap = !remap;
return 0;
} else if (*key == XK_F23) {
local_switch ^= (1UL<< 12);
return 0;
}
}
/*
* Check for already remapped ISO8859-X keys
* this should not normaly happen :-)
* as we need to use this hack
*/
if ((*key > KEYMASK) && (*key < KEYBYTEMAX) || (*key > 0xffffff00)) {
*key &= KEYMASK;
keyName[0] = (char) *key;
return 1;
}
/* Select keyboard map */
if (!i)
kbdActual = nationalKey[0];
else if (!remap)
kbdActual = nationalKey[1];
else
kbdActual = nationalKey[2];
if (keyEvent->type == KeyPress) {
long i = last_keypos;
/*
* Search for DeadKey -> do loop over all tables.
*
* Note: We can define ONE DeadKey and use
* it for several tables sequentially
*/
for (;;) {
i++;
if ((kbdActual[0].tab == NULL) || kbdActual[i].tab == NULL) {
i = 0;
if (kbdActual[i].tab == NULL) {
/* Looks like empty table -> IGNORE */
keypos = i;
return nbytes;
}
}
if (i == last_keypos)
break;
if (kbdActual[i].deadkey == *key) {
keypos = kbdActual[i].next;
/* Found DeadKey -> delete it
* and mark actual position for next search */
last_keypos = i;
keyName[0] = *key = 0;
return 0;
}
}
} else if (keypos)
return 0; /* ignore key release */
/* Now we know it is not a DeadKey and we
* are in selected remaping keyboard table */
/* printf("** key:%5d\tstatus:0x%x\n", *key, prev_state); */
if (*key < KEYBYTEMAX) {
/*
* this is selected constant and will change when
* this editor will be able to write in japan :-)
*/
int i = 0;
/* remaping only real keys */
while (kbdActual[keypos].tab[i].key_english != 0) {
if (*key == kbdActual[keypos].tab[i].key_english) {
*key = kbdActual[keypos].tab[i].key_remap;
break;
}
i++;
}
last_keypos = keypos = kbdActual[keypos].next;
/* printf("** remap: %3d %3d\n", keypos, *key); */
keyName[0] = *key && KEYMASK;
return 1;
}
return 0;
}
/*FOLD00*/
#else
/*********************************************
* *
* Standart methods for reading Keyboard *
* *
*********************************************/
/* ISO-8859-2 key-change
* All these functions are for keyboard reading.
* Correct displaing of this text is another thing,
* but as I only need ISO-8859 encoding support,
* I don't care about this (for now).
*/
static int I18NKeyAnalyze(XKeyEvent * keyEvent, KeySym * key, /*fold00*/
char *keyName, int nbytes)
{
KeySym t = (unsigned char) keyName[0];
/*
* ISO-8859-2 is using some characters from 8859-1 and
* rest of them is located between 0x100 - 0x200 in 'X' so
* with ISO-8859-2 font we'll remap them down bellow < 0x100
* This is mostly true for all Latin-X alphas, just
* special font to display them correctly is needed.
* This jobs does Xserver - and keysymbol is returned
* in the 1st. byte of keyName string.
*/
if ((nbytes == 1) && *key < KEYBYTEMAX)
*key = t;
#ifdef USE_HACK_FOR_BAD_XSERVER
/*
* this is really hack - but some Xservers are somewhat
* strange, so we remap character manually
*/
else if (!nbytes && (*key > KEYMASK) && (*key < KEYBYTEMAX)) {
*key &= KEYMASK;
keyName[0] = *key & KEYMASK;
nbytes = 1;
}
#endif
return nbytes;
}
/*FOLD00*/
#endif
/*
* Initialize I18N functions - took me hours to
* figure out how this works even though it was
* cut & pasted from 'xterm' sources, but as 'xterm'
* is using Xt Toolkit some things have to be made
* different
*/
XIC I18NInit(Display * display, Window win, unsigned long *mask) /*fold00*/
{
XIC xic = (XIC) NULL;
#if XlibSpecificationRelease >= 6
XIM xim = (XIM) NULL;
XIMStyles *xim_styles;
XIMStyle input_style = 0;
char *s, tmp[256];
int found = False;
*mask = 0;
/* Locale setting taken from XtSetLanguageProc */
if (!(s = setlocale(LC_ALL, "")))
fprintf(stderr, "I18N warning: Locale not supported by C library, "
"locale unchanged!\n");
if (!XSupportsLocale()) {
fprintf(stderr, "I18N warning: Locale not supported by Xlib, "
"locale set to C!\n");
s = setlocale(LC_ALL, "C");
}
if (!XSetLocaleModifiers(""))
fprintf(stderr, "I18N warning: X locale modifiers not supported, "
"using default\n");
xim = XOpenIM(display, NULL, NULL, NULL);
if (xim == NULL) {
// there are languages without Input Methods ????
fprintf(stderr, "I18N warning: Input method not specified\n");
return NULL;
}
if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL)
|| xim_styles == NULL) {
fprintf(stderr, "I18N error: Input method doesn't support any style\n");
XCloseIM(xim);
return NULL;
}
/*
* This is some kind of debugging message to inform user
* that something is wrong with his system
*/
if (s != NULL && (strstr(s, XLocaleOfIM(xim)) == NULL))
fprintf(stderr, "I18N warning: System locale: \"%s\" differs from "
"IM locale: \"%s\"...\n", s, XLocaleOfIM(xim));
/*
* This part is cut&paste from other sources
* There is no reason to do it this way, because
* the only input style currently supported is Root
* but for the future extension I'll leave it here
*/
strcpy(tmp, XIM_INPUT_STYLE);
for (s = tmp; s && !found;) {
char *ns, *end;
int i;
while ((*s != 0) && isspace(*s))
s++;
if (*s == 0)
break;
if ((ns = end = strchr(s, ',')) != 0)
ns++;
else
end = s + strlen(s);
while (isspace(*end))
end--;
*end = '\0';
if (!strcmp(s, "OverTheSpot"))
input_style = (XIMPreeditPosition | XIMStatusArea);
else if (!strcmp(s, "OffTheSpot"))
input_style = (XIMPreeditArea | XIMStatusArea);
else if (!strcmp(s, "Root"))
input_style = (XIMPreeditNothing | XIMStatusNothing);
for (i = 0; (unsigned short) i < xim_styles->count_styles; i++)
if (input_style == xim_styles->supported_styles[i]) {
found = True;
break;
}
s = ns;
}
XFree(xim_styles);
if (!found) {
fprintf(stderr, "I18N error: Input method doesn't support my "
"preedit type\n");
XCloseIM(xim);
return NULL;
}
/* This program only understand the Root preedit_style yet */
if (input_style != (XIMPreeditNothing | XIMStatusNothing)) {
fprintf(stderr, "I18N error: This program only supports the "
"'Root' preedit type\n");
XCloseIM(xim);
return NULL;
}
xic = XCreateIC(xim, XNInputStyle, input_style,
XNClientWindow, win,
XNFocusWindow, win,
NULL);
if (xic == NULL) {
fprintf(stderr, "I18N error: Failed to create input context\n");
XCloseIM(xim);
} else if (XGetICValues(xic, XNFilterEvents, mask, NULL))
fprintf(stderr, "I18N error: Can't get Event Mask\n");
#else
*mask = 0;
#endif
return xic;
}
/*FOLD00*/
void I18NFocusIn(XIC xic) /*fold00*/
{
#if XlibSpecificationRelease >= 6
if (xic != NULL)
XSetICFocus(xic);
#endif
}
/*FOLD00*/
void I18NFocusOut(XIC xic) /*fold00*/
{
#if XlibSpecificationRelease >= 6
if (xic != NULL)
XUnsetICFocus(xic);
#endif
}
/*FOLD00*/
/*
* Lookup correct keysymbol from keymap event
*/
int I18NLookupString(XKeyEvent * keyEvent, char *keyName, int keySize, /*FOLD00*/
KeySym * key, XIC xic)
{
static int showKeys = 0;
int nbytes = 0;
#if XlibSpecificationRelease >= 6
if (xic != NULL) {
if (keyEvent->type == KeyPress) {
Status status_return;
/* No KeyRelease events here ! */
#if 1
nbytes = XmbLookupString(xic, keyEvent, keyName, keySize,
key, &status_return);
#else
wchar_t wk;
nbytes = XwcLookupString(xic, keyEvent, &wk, 1, key, &status_return);
printf("code=%0X\n", wk);
keySize = 1;
keyName[0] = wk & 0xFF;
#endif
}
} else
#endif
do {
static XComposeStatus compose_status = { NULL, 0 };
nbytes = XLookupString(keyEvent, keyName, keySize,
key, &compose_status);
} while (0);
if (showKeys) {
fprintf(stderr, "Key: 0x%04lx '%s'\tKeyEventState:0x%x\t",
*key, XKeysymToString(*key), keyEvent->state);
if (nbytes && isprint(keyName[0])) {
keyName[nbytes] = 0;
fprintf(stderr, "String:'%s' Size:%2d ", keyName, nbytes);
}
fputs("\n", stderr);
}
if (((*key == XK_F1) || (*key == XK_F11))
&& ((keyEvent->state & (ShiftMask | ControlMask))
== (ShiftMask | ControlMask))
&& (keyEvent->type == KeyPress))
showKeys = !showKeys;
return I18NKeyAnalyze(keyEvent, key, keyName, nbytes);
}
/*FOLD00*/

32
src/con_i18n.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef __CONI18N_H__
#define __CONI18N_H__
#include <X11/Xlib.h>
#include <X11/Xlocale.h>
/*
* For now the only supported input style is root !!!
* in future this should be read from resources
*/
#define XIM_INPUT_STYLE "Root"
struct remapKey {
KeySym key_english;
KeySym key_remap;
};
struct keyboardRec {
struct remapKey *tab;
KeySym deadkey;
short next;
};
/*
* prototypes for I18N functions
*/
extern void I18NFocusOut(XIC);
extern void I18NFocusIn(XIC);
extern int I18NLookupString(XKeyEvent *, char *, int, KeySym *, XIC);
extern XIC I18NInit(Display *, Window, unsigned long *);
#endif

390
src/con_ikcz.h Normal file
View file

@ -0,0 +1,390 @@
#ifndef __CON_IKCS_H
#define __CON_IKCS_H
static struct remapKey keyboardStd[] =
{
{0,}
};
static struct remapKey keyboardHalfCz[] =
{
{XK_2, 0xff & 'ì'},
{XK_3, 0xff & '¹'},
{XK_4, 0xff & 'è'},
{XK_5, 0xff & 'ø'},
{XK_6, 0xff & '¾'},
{XK_7, 0xff & 'ý'},
{XK_8, 0xff & 'á'},
{XK_9, 0xff & 'í'},
{XK_0, 0xff & 'é'},
{0,}
};
static struct remapKey keyboardFullCz[] =
{
{XK_1, 0xff & '+'},
{XK_exclam, XK_1},
{XK_2, 0xff & 'ì'},
{XK_at, XK_2},
{XK_3, 0xff & '¹'},
{XK_numbersign, XK_3},
{XK_4, 0xff & 'è'},
{XK_dollar, XK_4},
{XK_5, 0xff & 'ø'},
{XK_percent, XK_5},
{XK_6, 0xff & '¾'},
{XK_asciicircum, XK_6},
{XK_7, 0xff & 'ý'},
{XK_ampersand, XK_7},
{XK_8, 0xff & 'á'},
{XK_asterisk, XK_8},
{XK_9, 0xff & 'í'},
{XK_parenleft, XK_9},
{XK_0, 0xff & 'é'},
{XK_parenright, XK_0},
{XK_minus, XK_equal},
{XK_underscore, XK_percent},
{XK_bracketleft, 0xff & 'ú'},
{XK_braceleft, 0xff & '/'},
{XK_bracketright, 0xff & ')'},
{XK_braceright, 0xff & '('},
{XK_semicolon, 0xff & 'ù'},
{XK_apostrophe, 0xff & '§'},
{XK_colon, 0xff & '"'},
{XK_quotedbl, 0xff & '!'},
{XK_comma, 0xff & ','},
{XK_less, 0xff & '?'},
{XK_period, 0xff & '.'},
{XK_greater, 0xff & ':'},
{XK_question, 0xff & '_'},
{XK_slash, 0xff & '-'},
{0,}
};
static struct remapKey keyboardAcute[] =
{
{XK_w, 0xff & 'ì'},
{XK_W, 0xff & 'Ì'},
{XK_e, 0xff & 'é'},
{XK_E, 0xff & 'É'},
{XK_r, 0xff & 'à'},
{XK_R, 0xff & 'À'},
{XK_t, 0xff & '»'},
{XK_T, 0xff & '«'},
{XK_y, 0xff & 'ý'},
{XK_Y, 0xff & 'Ý'},
{XK_u, 0xff & 'ú'},
{XK_U, 0xff & 'Ú'},
{XK_i, 0xff & 'í'},
{XK_I, 0xff & 'Í'},
{XK_o, 0xff & 'ó'},
{XK_O, 0xff & 'Ó'},
{XK_p, 0xff & '§'},
{XK_P, 0xff & '§'},
{XK_a, 0xff & 'á'},
{XK_A, 0xff & 'Á'},
{XK_s, 0xff & ''},
{XK_S, 0xff & '¦'},
{XK_d, 0xff & 'ï'},
{XK_D, 0xff & 'Ï'},
{XK_h, 0xff & 'þ'},
{XK_H, 0xff & 'Þ'},
{XK_l, 0xff & 'å'},
{XK_L, 0xff & 'Å'},
{XK_z, 0xff & '¼'},
{XK_Z, 0xff & '¬'},
{XK_x, 0xff & '×'},
{XK_X, 0xff & '×'},
{XK_c, 0xff & 'æ'},
{XK_C, 0xff & 'Æ'},
{XK_b, 0xff & 'ß'},
{XK_B, 0xff & 'ß'},
{XK_n, 0xff & 'ñ'},
{XK_N, 0xff & 'Ñ'},
{XK_equal, 0xff & '´'},
{0,}
};
static struct remapKey keyboardCaron[] =
{
{XK_e, 0xff & 'ì'},
{XK_E, 0xff & 'Ì'},
{XK_r, 0xff & 'ø'},
{XK_R, 0xff & 'Ø'},
{XK_t, 0xff & '»'},
{XK_T, 0xff & '«'},
{XK_u, 0xff & 'ù'},
{XK_U, 0xff & 'Ù'},
{XK_i, 0xff & 'î'},
{XK_I, 0xff & 'Î'},
{XK_o, 0xff & 'ö'},
{XK_O, 0xff & 'Ö'},
{XK_a, 0xff & 'ä'},
{XK_A, 0xff & 'Ä'},
{XK_s, 0xff & '¹'},
{XK_S, 0xff & '©'},
{XK_d, 0xff & 'ï'},
{XK_D, 0xff & 'Ï'},
{XK_l, 0xff & 'µ'},
{XK_L, 0xff & '¥'},
{XK_z, 0xff & '¾'},
{XK_Z, 0xff & '®'},
{XK_x, 0xff & '¤'},
{XK_X, 0xff & '¤'},
{XK_c, 0xff & 'è'},
{XK_C, 0xff & 'È'},
{XK_n, 0xff & 'ò'},
{XK_N, 0xff & 'Ò'},
{XK_plus, 0xff & '·'},
{0,}
};
static struct remapKey keyboardFirst[] =
{
{XK_w, 0xff & 'ì'},
{XK_W, 0xff & 'Ì'},
{XK_e, 0xff & 'é'},
{XK_E, 0xff & 'É'},
{XK_r, 0xff & 'ø'},
{XK_R, 0xff & 'Ø'},
{XK_t, 0xff & '»'},
{XK_T, 0xff & '«'},
{XK_y, 0xff & 'ý'},
{XK_Y, 0xff & 'Ý'},
{XK_u, 0xff & 'ú'},
{XK_U, 0xff & 'Ú'},
{XK_i, 0xff & 'í'},
{XK_I, 0xff & 'Í'},
{XK_o, 0xff & 'ó'},
{XK_O, 0xff & 'Ó'},
{XK_p, 0xff & '§'},
{XK_P, 0xff & '§'},
{XK_a, 0xff & 'á'},
{XK_A, 0xff & 'Á'},
{XK_s, 0xff & '¹'},
{XK_S, 0xff & '©'},
{XK_d, 0xff & 'ï'},
{XK_D, 0xff & 'Ï'},
{XK_h, 0xff & 'þ'},
{XK_H, 0xff & 'Þ'},
{XK_l, 0xff & 'å'},
{XK_L, 0xff & 'Å'},
{XK_z, 0xff & '¾'},
{XK_Z, 0xff & '®'},
{XK_x, 0xff & '×'},
{XK_X, 0xff & '×'},
{XK_c, 0xff & 'è'},
{XK_C, 0xff & 'È'},
{XK_b, 0xff & 'ß'},
{XK_B, 0xff & 'ß'},
{XK_n, 0xff & 'ò'},
{XK_N, 0xff & 'Ò'},
{0,}
};
static struct remapKey keyboardSecond[] =
{
{XK_equal, 0xff & '´'},
{XK_plus, 0xff & '·'},
{XK_e, 0xff & 'ì'},
{XK_E, 0xff & 'Ì'},
{XK_r, 0xff & 'à'},
{XK_R, 0xff & 'À'},
{XK_t, 0xff & 'þ'},
{XK_T, 0xff & 'Þ'},
{XK_u, 0xff & 'ù'},
{XK_U, 0xff & 'Ù'},
{XK_i, 0xff & 'î'},
{XK_I, 0xff & 'Î'},
{XK_o, 0xff & 'ö'},
{XK_O, 0xff & 'Ö'},
{XK_a, 0xff & 'ä'},
{XK_A, 0xff & 'Ä'},
{XK_s, 0xff & ''},
{XK_S, 0xff & '¦'},
{XK_d, 0xff & 'ð'},
{XK_D, 0xff & 'Ð'},
{XK_l, 0xff & 'µ'},
{XK_L, 0xff & '¥'},
{XK_z, 0xff & '¼'},
{XK_Z, 0xff & '¬'},
{XK_x, 0xff & '¤'},
{XK_X, 0xff & '¤'},
{XK_c, 0xff & 'æ'},
{XK_C, 0xff & 'Æ'},
{XK_n, 0xff & 'ñ'},
{XK_N, 0xff & 'Ñ'},
{0,}
};
static struct remapKey keyboardThird[] =
{
{XK_a, 0xff & 'â'},
{XK_A, 0xff & 'Â'},
{XK_e, 0xff & 'ë'},
{XK_E, 0xff & 'Ë'},
{XK_u, 0xff & 'ü'},
{XK_U, 0xff & 'Ü'},
{XK_o, 0xff & 'ô'},
{XK_O, 0xff & 'Ô'},
{XK_s, 0xff & 'ß'},
{XK_S, 0xff & 'ß'},
{XK_l, 0xff & '³'},
{XK_L, 0xff & '£'},
{XK_z, 0xff & '¿'},
{XK_Z, 0xff & '¯'},
{XK_c, 0xff & 'ç'},
{XK_C, 0xff & 'Ç'},
{0,}
};
static struct remapKey keyboardFourth[] =
{
{XK_a, 0xff & 'ã'},
{XK_A, 0xff & 'Ã'},
{XK_e, 0xff & 'ê'},
{XK_E, 0xff & 'Ê'},
{XK_u, 0xff & 'û'},
{XK_U, 0xff & 'Ü'},
{XK_o, 0xff & 'õ'},
{XK_O, 0xff & 'Õ'},
{XK_l, 0xff & '£'},
{XK_L, 0xff & '£'},
{0,}
};
static struct remapKey keyboardFifth[] =
{
{XK_a, 0xff & '±'},
{XK_A, 0xff & '¡'},
{XK_o, 0xff & '§'},
{XK_O, 0xff & '§'},
{XK_l, 0xff & '|'},
{XK_L, 0xff & '|'},
{0,}
};
#define KEYMAPS_MACRO \
{keyboardAcute, 0, 0}, /* 1 */ \
{keyboardCaron, 0, 0}, /* 2 */ \
{keyboardFirst, 0, 0}, /* 3 */ \
{keyboardSecond, 0, 0}, /* 4 */ \
{keyboardThird, 0, 0}, /* 5 */ \
{keyboardFourth, 0, 0}, /* 6 */ \
{keyboardFifth, 0, 0}, /* 7 */
#ifdef XK_dead_acute
#define XKB_DEAD_KEYS \
{keyboardStd, XK_dead_acute, 1}, \
{keyboardStd, XK_dead_caron, 2}, \
{keyboardStd, XK_dead_iota, 3}, \
{keyboardStd, XK_dead_iota, 4}, \
{keyboardStd, XK_dead_iota, 5}, \
{keyboardStd, XK_dead_iota, 6}, \
{keyboardStd, XK_dead_iota, 7}, \
{keyboardStd, XK_dead_iota, 0},
#else
#define XKB_DEAD_KEYS
#endif
#ifdef XK_F22
#define F22_DEAD_KEYS \
{keyboardStd, XK_F22, 3}, \
{keyboardStd, XK_F22, 4}, \
{keyboardStd, XK_F22, 5}, \
{keyboardStd, XK_F22, 6}, \
{keyboardStd, XK_F22, 7}, \
{keyboardStd, XK_F22, 0},
#else
#define F22_DEAD_KEYS
#endif
#define KBD_MACRO \
{keyboardStd, XK_Print, 3}, \
{keyboardStd, XK_Print, 4}, \
{keyboardStd, XK_Print, 5}, \
{keyboardStd, XK_Print, 6}, \
{keyboardStd, XK_Print, 7}, \
{keyboardStd, XK_Print, 0}, \
XKB_DEAD_KEYS \
F22_DEAD_KEYS
static struct keyboardRec kbdStdRec[] =
{
{keyboardStd, 0, 0}, /* 0 */
KEYMAPS_MACRO
KBD_MACRO
{NULL,}
};
static struct keyboardRec kbdHalfCzRec[] =
{
{keyboardHalfCz, 0, 0}, /* 0 */
KEYMAPS_MACRO
KBD_MACRO
{NULL,}
};
static struct keyboardRec kbdFullCzRec[] =
{
{keyboardFullCz, 0, 0}, /* 0 */
KEYMAPS_MACRO
{keyboardStd, XK_equal, 1},
{keyboardStd, XK_plus, 2},
KBD_MACRO
{NULL,}
};
/*
* one standart keyboard and two national keyboards
* (for programmers and for writers)
*/
static struct keyboardRec *nationalKey[] =
{
kbdStdRec,
kbdHalfCzRec,
kbdFullCzRec,
0
};
#endif

1205
src/con_linux.cpp Normal file

File diff suppressed because it is too large Load diff

1925
src/con_nt.cpp Normal file

File diff suppressed because it is too large Load diff

1226
src/con_os2.cpp Normal file

File diff suppressed because it is too large Load diff

1057
src/con_slang.cpp Normal file

File diff suppressed because it is too large Load diff

1660
src/con_x11.cpp Normal file

File diff suppressed because it is too large Load diff

77
src/conkbd.h Normal file
View file

@ -0,0 +1,77 @@
/* conkbd.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __CONKBD_H__
#define __CONKBD_H__
#define kfAltXXX 0x01000000L
#define kfModifier 0x02000000L
#define kfSpecial 0x00010000L
#define kfAlt 0x00100000L
#define kfCtrl 0x00200000L
#define kfShift 0x00400000L
#define kfGray 0x00800000L
#define kfKeyUp 0x10000000L
#define kfAll 0x00F00000L
#define isAltXXX(x) (((x) & (kfAltXXX)) != 0)
#define isAlt(x) (((x) & kfAlt) != 0)
#define isCtrl(x) (((x) & kfCtrl) != 0)
#define isShift(x) (((x) & kfShift) != 0)
#define isGray(x) (((x) & kfGray) != 0)
#define keyType(x) ((x) & kfAll)
#define keyCode(x) ((x) & 0x000FFFFF)
#define kbCode(x) (((x) & 0x0FFFFFFF) & ~(kfGray | kfAltXXX))
#define isAscii(x) ((((x) & (kfAlt | kfCtrl)) == 0) && (keyCode(x) < 256))
#define kbF1 (kfSpecial | 0x101)
#define kbF2 (kfSpecial | 0x102)
#define kbF3 (kfSpecial | 0x103)
#define kbF4 (kfSpecial | 0x104)
#define kbF5 (kfSpecial | 0x105)
#define kbF6 (kfSpecial | 0x106)
#define kbF7 (kfSpecial | 0x107)
#define kbF8 (kfSpecial | 0x108)
#define kbF9 (kfSpecial | 0x109)
#define kbF10 (kfSpecial | 0x110)
#define kbF11 (kfSpecial | 0x111)
#define kbF12 (kfSpecial | 0x112)
#define kbUp (kfSpecial | 0x201)
#define kbDown (kfSpecial | 0x202)
#define kbLeft (kfSpecial | 0x203)
#define kbCenter (kfSpecial | 0x204)
#define kbRight (kfSpecial | 0x205)
#define kbHome (kfSpecial | 0x206)
#define kbEnd (kfSpecial | 0x207)
#define kbPgUp (kfSpecial | 0x208)
#define kbPgDn (kfSpecial | 0x209)
#define kbIns (kfSpecial | 0x210)
#define kbDel (kfSpecial | 0x211)
#define kbSpace 32
#define kbBackSp (kfSpecial | 8)
#define kbTab (kfSpecial | 9)
#define kbEnter (kfSpecial | 13)
#define kbEsc (kfSpecial | 27)
#define kbAlt (kfModifier | 0x301)
#define kbCtrl (kfModifier | 0x302)
#define kbShift (kfModifier | 0x303)
#define kbCapsLock (kfModifier | 0x304)
#define kbNumLock (kfModifier | 0x305)
#define kbScrollLock (kfModifier | 0x306)
#define kbPause (kfSpecial | 0x401)
#define kbPrtScr (kfSpecial | 0x402)
#define kbSysReq (kfSpecial | 0x403)
#define kbBreak (kfSpecial | 0x404)
#endif

211
src/console.h Normal file
View file

@ -0,0 +1,211 @@
/* console.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __CONSOLE_H__
#define __CONSOLE_H__
/* don't change these, used as index */
#define DCH_C1 0
#define DCH_C2 1
#define DCH_C3 2
#define DCH_C4 3
#define DCH_H 4
#define DCH_V 5
#define DCH_M1 6
#define DCH_M2 7
#define DCH_M3 8
#define DCH_M4 9
#define DCH_X 10
#define DCH_RPTR 11
#define DCH_EOL 12
#define DCH_EOF 13
#define DCH_END 14
#define DCH_AUP 15
#define DCH_ADOWN 16
#define DCH_HFORE 17
#define DCH_HBACK 18
#define DCH_ALEFT 19
#define DCH_ARIGHT 20
#define ConMaxCols 256
#define ConMaxRows 128
#define csUp 0
#define csDown 1
#define csLeft 2
#define csRight 3
#define evNone 0
#define evKeyDown 0x0001
#define evKeyUp 0x0002
#define evMouseDown 0x0010
#define evMouseUp 0x0020
#define evMouseMove 0x0040
#define evMouseAuto 0x0080
#define evCommand 0x0100
#define evBroadcast 0x0200
#define evNotify 0x0400
#define evKeyboard (evKeyDown | evKeyUp)
#define evMouse (evMouseDown | evMouseUp | evMouseMove | evMouseAuto)
#define evMessage (evCommand | evBroadcast)
#include "conkbd.h"
#define cmRefresh 1
#define cmResize 2
#define cmClose 3
#define cmPipeRead 4
#define cmMainMenu 5
#define cmPopupMenu 6
/* vertical scroll */
#define cmVScrollUp 10
#define cmVScrollDown 11
#define cmVScrollPgUp 12
#define cmVScrollPgDn 13
#define cmVScrollMove 14
/* horizontal scroll */
#define cmHScrollLeft 15
#define cmHScrollRight 16
#define cmHScrollPgLt 17
#define cmHScrollPgRt 18
#define cmHScrollMove 19
#define cmDroppedFile 30
#define cmRenameFile 31 /* TODO: in-place editing of titlebar */
typedef unsigned char TAttr;
typedef TAttr *PAttr;
#ifdef NTCONSOLE
typedef unsigned long TCell;
#else
typedef unsigned short TCell;
#endif
typedef TCell *PCell;
typedef TCell TDrawBuffer[ConMaxCols];
typedef TDrawBuffer *PDrawBuffer;
typedef unsigned long TEventMask;
typedef unsigned long TKeyCode;
typedef unsigned long TCommand;
class EModel; // forward
class GView;
typedef struct {
TEventMask What;
GView *View;
TKeyCode Code;
} TKeyEvent;
typedef struct {
TEventMask What;
GView *View;
long X;
long Y;
unsigned short Buttons;
unsigned short Count;
TKeyCode KeyMask;
} TMouseEvent;
typedef struct {
TEventMask What;
GView *View;
EModel *Model;
TCommand Command;
long Param1;
void *Param2;
} TMsgEvent;
typedef union {
TEventMask What;
TKeyEvent Key;
TMouseEvent Mouse;
TMsgEvent Msg;
char fill[32];
} TEvent;
#define SUBMENU_NORMAL (-1)
#define SUBMENU_CONDITIONAL (-2)
typedef struct _mItem {
char *Name;
char *Arg;
int SubMenu;
int Cmd;
} mItem;
typedef struct _mMenu {
char *Name;
int Count;
mItem *Items;
} mMenu;
extern int MenuCount;
extern mMenu *Menus;
int ConInit(int XSize, int YSize);
int ConDone();
int ConSuspend();
int ConContinue();
int ConSetTitle(char *Title, char *STitle);
int ConGetTitle(char *Title, int MaxLen, char *STitle, int SMaxLen);
int ConClear();
int ConPutBox(int X, int Y, int W, int H, PCell Cell);
int ConGetBox(int X, int Y, int W, int H, PCell Cell);
int ConPutLine(int X, int Y, int W, int H, PCell Cell);
int ConSetBox(int X, int Y, int W, int H, TCell Cell);
int ConScroll(int Way, int X, int Y, int W, int H, TAttr Fill, int Count);
int ConSetSize(int X, int Y);
int ConQuerySize(int *X, int *Y);
int ConSetCursorPos(int X, int Y);
int ConQueryCursorPos(int *X, int *Y);
int ConShowCursor();
int ConHideCursor();
int ConCursorVisible();
int ConSetCursorSize(int Start, int End);
int ConSetMousePos(int X, int Y);
int ConQueryMousePos(int *X, int *Y);
int ConShowMouse();
int ConHideMouse();
int ConMouseVisible();
int ConQueryMouseButtons(int *ButtonCount);
int ConGetEvent(TEventMask EventMask, TEvent *Event, int WaitTime, int Delete);
int ConPutEvent(TEvent Event);
void MoveCh(PCell B, char Ch, TAttr Attr, int Count);
void MoveChar(PCell B, int Pos, int Width, const char Ch, TAttr Attr, int Count);
void MoveMem(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, int Count);
void MoveStr(PCell B, int Pos, int Width, const char* Ch, TAttr Attr, int MaxCount);
void MoveCStr(PCell B, int Pos, int Width, const char* Ch, TAttr A0, TAttr A1, int MaxCount);
void MoveAttr(PCell B, int Pos, int Width, TAttr Attr, int Count);
void MoveBgAttr(PCell B, int Pos, int Width, TAttr Attr, int Count);
int CStrLen(const char *s);
int NewMenu(const char *Name);
int NewItem(int menu, const char *Name);
int NewSubMenu(int menu, const char *Name, int submenu, int type);
int GetMenuId(const char *Name);
char ConGetDrawChar(int index);
extern char WindowFont[64];
#endif

517
src/defcfg.fte Normal file
View file

@ -0,0 +1,517 @@
menu File {
item "&Open...\tF3" { FileOpen }
item "&Reload\tShift+F3" { FileReload }
item "&Save\tF2" { FileSave }
item "Save &As...\tShift+F2" { FileSaveAs }
item "Save Al&l\tCtrl+F2" { FileSaveAll }
item "&Close\tAlt+Q" { FileClose }
item;
item "&Next\tAlt+Left" { FileNext }
item "&Previous\tAlt+Right" { FilePrev }
item;
item "E&xit\tAlt+X" { ExitEditor }
}
menu Edit {
item "&Undo\tAlt+BackSp" { Undo }
item "&Redo\tAlt+Shift+BackSp" { Redo }
item;
item "Cu&t\tShift+Del" { BlockCut }
item "&Copy\tCtrl+Ins" { BlockCopy }
item "&Paste\tShift+Ins" { BlockPasteStream }
item "P&aste Column\tAlt+Ins" { BlockPasteColumn }
item;
item "&Delete line\tCtrl+Y" { KillLine }
item "&Split line\tCtrl+L" { LineSplit }
item "&Join line\tCtrl+J" { LineJoin }
item;
item "&Quote Literal...\tCtrl+Q" { InsertChar }
}
menu Translate {
item "Upperc&ase" { BlockCaseUp }
item "Low&ercase" { BlockCaseDown }
item "Tog&glecase" { BlockCaseToggle }
}
menu Block {
item "&Unmark\tEsc" { BlockUnmark }
item "Mark &Line\tAlt+L" { BlockMarkLine }
item "Mark &Stream\tAlt+A" { BlockMarkStream }
item "Mark &Column\tAlt+K" { BlockMarkColumn }
item;
item "&Indent\tAlt+I" { BlockIndent }
item "U&nindent\tAlt+U" { BlockUnindent }
item;
item "&Write..." { BlockWrite }
item "&Read..." { BlockRead }
item "&Print" { BlockPrint }
item;
submenu "Translat&e", Translate;
}
menu Search {
item "&Find...\tCtrl+F" { Find }
item "Find and &replace...\tCtrl+R" { FindReplace }
item "Repeat &Last find\tCtrl+L" { FindRepeat }
item "Repeat last find re&verse\tCtrl+B" { FindRepeatReverse }
item "Repeat last find &once\tCtrl+N" { FindRepeatOnce }
item "Incremental &search\tCtrl+S" { IncrementalSearch }
item;
item "&Place Bookmark..." { PlaceBookmark }
item "Goto &Bookmark..." { GotoBookmark }
item;
item "&Match paren\tAlt+-" { MatchBracket }
item "&Goto line...\tAlt+J" { MoveToLine }
}
menu Tools {
item "&Compile\tF9" { Compile "make -k " }
item "&Grep" { Compile "grep -n " }
item;
item "Sh&ell" { RunProgram "" }
item;
item "Go to prev &error\tF11" { CompilePrevError }
item "Go to &next error\tF12" { CompileNextError }
item;
item "&Messages\tS+F9" { ViewMessages }
}
menu Window {
item "Split &Horizontal\tShift+F2" { WinHSplit }
item "&Close view\tCtrl+Alt+F4" { WinClose }
item "Close &other views\tF5" { WinZoom }
item;
item "&Routines\tCtrl+I" { ListRoutines }
item "&Buffers\tAlt+0" { ViewBuffers }
item "&Directory\tC+M" { DirOpen }
}
menu Options {
item "&Insert mode\tC+O C+I" { ToggleInsert }
item "&Auto indent\tC+O C+A" { ToggleAutoIndent }
item "&Case sensitive\tC+O C+C" { ToggleMatchCase }
item "Trim &EOL spaces\tC+O C+E" { ToggleTrim }
item "&Read only\tC+O C+R" { ToggleReadOnly }
item "&Undo/Redo\tC+O C+U" { ToggleUndo }
item "&Show markers\tC+O C+." { ToggleShowMarkers; WinRefresh }
item;
item "&Word wrap\tC+O C+W" { ToggleWordWrap }
item "&Left margin...\tC+O A+[" { ChangeLeftMargin }
item "Ri&ght margin...\tC+O A+]" { ChangeRightMargin }
item;
item "&Tab size...\tC+O C+T" { ChangeTabSize; WinRefresh }
item "S&how tabs\tC+O Tab" { ToggleShowTabs; WinRefresh }
item "E&xpand tabs\tC+O C+Tab" { ToggleExpandTabs; WinRefresh }
item "&Print to... " { SetPrintDevice }
}
menu Help {
item "&About..." { ShowVersion }
}
menu Main {
submenu "&File", File;
submenu "&Edit", Edit;
submenu "&Block", Block;
submenu "&Search", Search;
submenu "&Tools", Tools;
submenu "&Window", Window;
submenu "&Options", Options;
submenu "&Help", Help;
}
menu Local {
item "&Unmark\tEsc" { BlockUnmark }
item "Cu&t\tShift+Del" { BlockCut }
item "&Copy\tCtrl+Ins" { BlockCopy }
item "&Paste\tShift+Ins" { BlockPasteStream }
item "P&aste Column\tAlt+Ins" { BlockPasteColumn }
item;
item "Delete &line\tCtrl+Y" { KillLine }
item "Delete to &EOL\tAlt+End" { KillToLineEnd }
item;
item "&Save\tF2" { FileSave }
item "Cl&ose\tAlt+Q" { FileClose }
}
eventmap MODEL { # basic commands, for files, directories, message view, etc.
key [C+F2] { FileSaveAll }
key [F3] { FileOpen }
key [F4] { WinNext }
key [C+F4] { WinHSplit }
key [S+F4] { WinPrev }
key [A+S-F4] { WinClose }
key [F5] { WinZoom }
key [F6] { FileNext }
key [S+F6] { FilePrev }
key [A+S-F6] { FileLast }
key [F10] { MainMenu }
key [C+F9] { RunProgram }
key [S+F10] { LocalMenu }
key [A+G-Up] { WinPrev }
key [A+G-Down] { WinNext }
key [A+G-Left] { FilePrev }
key [A+G-Right] { FileNext }
key [A+G-PgUp] { WinPrev; MovePageUp; WinNext }
key [A+G-PgDn] { WinNext; MovePageDown; WinPrev }
key [A+C+G-PgUp] { WinNext; MovePageUp; WinPrev }
key [A+C+G-PgDn] { WinPrev; MovePageDown; WinNext }
key [A+Q] { FileClose }
key [A+X] { ExitEditor }
key [C+S+G-Up] { WinResize -1 }
key [C+S+G-Down] { WinResize +1 }
# this is also useful for 'grep -n' etc. if configured
key [F9] { Compile; ViewMessages }
key [F11] { CompilePrevError }
key [F12] { CompileNextError }
key [S+F9] { ViewMessages }
key [A+0] { ViewBuffers }
key [A+1] { SwitchTo 1 }
key [A+2] { SwitchTo 2 }
key [A+3] { SwitchTo 3 }
key [A+4] { SwitchTo 4 }
key [A+5] { SwitchTo 5 }
key [A+6] { SwitchTo 6 }
key [A+7] { SwitchTo 7 }
key [A+8] { SwitchTo 8 }
key [A+9] { SwitchTo 9 }
}
eventmap PLAIN: MODEL {
# keymap for plaintext mode
MainMenu = 'Main'; # menu for menubar
LocalMenu = 'Local'; # local menu
key [Esc] { BlockMarkStream; BlockUnmark }
key [F2] { FileSave }
key [S+F2] { FileSaveAs }
key [A+S-F2] { FileSave; FileClose }
key [S+F3] { FileReload; WinRefresh }
key [C+F3] { FileOpenInMode }
key [F7] { BlockBegin }
key [S+F7] { MoveBlockStart }
key [F8] { BlockEnd }
key [S+F8] { MoveBlockEnd }
key [G-Left] { MoveLeft }
key [C+G-Left] { MoveWordPrev }
key [G-Right] { MoveRight }
key [C+G-Right] { MoveWordNext }
key [G-Up] { MoveUp }
key [G-Down] { MoveDown }
key [G-Home] { MoveLineStart }
key [C+G-Home] { MovePageStart }
key [G-End] { MoveLineEnd }
key [C+G-End] { MovePageEnd }
key [G-PgUp] { MovePageUp }
key [C+G-PgUp] { MoveFileStart }
key [G-PgDn] { MovePageDown }
key [C+G-PgDn] { MoveFileEnd }
# key [A+G-Up] { ScrollUp }
# key [A+G-Down] { ScrollDown }
# key [A+G-Left] { ScrollLeft }
# key [A+G-Right] { ScrollRight }
key [S+G-Left] { BlockExtendBegin; MoveLeft; BlockExtendEnd }
key [S+G-Right] { BlockExtendBegin; MoveRight; BlockExtendEnd }
# key [G+0] { ToggleInsert }
# key [G+S+0] { InsertString 'foo' }
key [C+G-S+Left] { BlockExtendBegin; MoveWordPrev; BlockExtendEnd }
key [C+G-S+Right] { BlockExtendBegin; MoveWordNext; BlockExtendEnd }
key [G-S+Up] { BlockExtendBegin; MoveUp; BlockExtendEnd }
key [G-S+Down] { BlockExtendBegin; MoveDown; BlockExtendEnd }
key [G-S+Home] { BlockExtendBegin; MoveLineStart; BlockExtendEnd }
key [G-S+End] { BlockExtendBegin; MoveLineEnd; BlockExtendEnd }
key [C+G-S+Home] { BlockExtendBegin; MovePageStart; BlockExtendEnd }
key [C+G-S+End] { BlockExtendBegin; MovePageEnd; BlockExtendEnd }
key [G-S+PgUp] { BlockExtendBegin; MovePageUp; BlockExtendEnd }
key [G-S+PgDn] { BlockExtendBegin; MovePageDown; BlockExtendEnd }
key [C+G-S+PgUp] { BlockExtendBegin; MoveFileStart; BlockExtendEnd }
key [C+G-S+PgDn] { BlockExtendBegin; MoveFileEnd; BlockExtendEnd }
key [A+G-S+Up] { BlockExtendBegin; ScrollUp; BlockExtendEnd }
key [A+G-S+Down] { BlockExtendBegin; ScrollDown; BlockExtendEnd }
key [A+G-S+Left] { BlockExtendBegin; ScrollLeft; BlockExtendEnd }
key [A+G-S+Right] { BlockExtendBegin; ScrollRight; BlockExtendEnd }
key [A+G-C+Up] { MovePrevEqualIndent }
key [A+G-C+Down] { MoveNextEqualIndent }
key [A+G-C+Left] { MovePrevTab }
key [A+G-C+Right] { MoveNextTab }
key [C+G-Ins] { BlockCopy }
key [C+G-Del] { BlockKill }
key [S+G-Ins] { BlockPasteStream }
key [S+G-Del] { BlockCut }
key [A+G-Ins] { BlockPasteColumn }
key [A+G-S+Ins] { BlockPasteLine }
key [G-Enter] { LineNew }
key [BackSp] { BackSpace }
key [G-Ins] { ToggleInsert }
key [G-Del] { Delete }
key [Tab] { InsertTab }
key [S+Tab] { InsertSpacesToTab 10 }
key [C+Tab] { CompleteWord }
# key [C+Tab] { InsertTab }
key [C+BackSp] { KillWordPrev }
key [C+S+BackSp] { KillToLineStart }
key [C+G-Enter] { LineSplit }
key [G-S+Enter] { LineInsert }
key [A+G-Enter] { LineAdd }
key [A+G-Del] { KillWord }
key [A+G-End] { KillToLineEnd }
key [A+BackSp] { Undo }
key [A+S+BackSp] { Redo }
key [C+A_1] { GotoBookmark "1" }
key [C+A_2] { GotoBookmark "2" }
key [C+A_3] { GotoBookmark "3" }
key [C+A_4] { GotoBookmark "4" }
key [C+A_5] { GotoBookmark "5" }
key [C+A_6] { GotoBookmark "6" }
key [C+A_7] { GotoBookmark "7" }
key [C+A_8] { GotoBookmark "8" }
key [C+A_9] { GotoBookmark "9" }
key [C+A_0] { GotoBookmark "0" }
key [C+P_1] { PlaceBookmark "1" }
key [C+P_2] { PlaceBookmark "2" }
key [C+P_3] { PlaceBookmark "3" }
key [C+P_4] { PlaceBookmark "4" }
key [C+P_5] { PlaceBookmark "5" }
key [C+P_6] { PlaceBookmark "6" }
key [C+P_7] { PlaceBookmark "7" }
key [C+P_8] { PlaceBookmark "8" }
key [C+P_9] { PlaceBookmark "9" }
key [C+P_0] { PlaceBookmark "0" }
key [C+B] { FindRepeatReverse }
key [C+C] { MoveToColumn }
key [C+D] { LineDuplicate }
key [C+F] { Find }
key [C+I] { ListRoutines }
key [C+J] { LineJoin }
key [C+L] { FindRepeat }
key [C+M] { DirOpen }
key [C+N] { FindRepeatOnce }
key [C+Q] { InsertChar }
key [C+R] { FindReplace }
key [C+T] { KillWord }
key [C+Y] { KillLine }
key [C+E] { LineTrim }
key [A+A] { BlockMarkStream }
key [A+B] { MainMenu 'B' }
key [A+C] { BlockCopy }
key [A+D] { MainMenu 'D' }
key [A+E] { MainMenu 'E' }
key [A+F] { MainMenu 'F' }
key [A+G] { BlockCut }
key [A+H] { MainMenu 'H' }
key [A+I] { BlockIndent }
key [A+J] { MoveToLine }
key [A+K] { BlockMarkColumn }
key [A+L] { BlockMarkLine }
key [A+O] { MainMenu 'O' }
key [A+R] { WrapPara } # Reformat
key [A+S] { MainMenu 'S' }
key [A+T] { MainMenu 'T' }
key [A+U] { BlockUnindent }
key [A+W] { MainMenu 'W' }
key [C+S] { IncrementalSearch }
key [C+O_C+A] { ToggleAutoIndent }
key [C+O_C+C] { ToggleMatchCase }
key [C+O_C+E] { ToggleTrim }
key [C+O_C+I] { ToggleInsert }
# key [C+O_C+M] { ChangeMode }
# key [C+O_C+M] { ShowMenu 'MChangeMode' }
key [C+O_C+R] { ToggleReadOnly }
key [C+O_C+S] { ToggleSysClipboard }
key [C+O_C+T] { ChangeTabSize }
key [C+O_C+U] { ToggleUndo }
key [C+O_C+W] { ToggleWordWrap }
key [C+O_.] { ToggleShowMarkers }
key [C+O_[] { SetLeftMargin }
key [C+O_\]] { SetRightMargin }
key [C+O_A+[] { ChangeLeftMargin }
key [C+O_A+\]] { ChangeRightMargin }
key [C+O_Tab] { ToggleShowTabs }
key [C+O_C+Tab] { ToggleExpandTabs }
key [C+O_Del] { ToggleDeleteKillTab }
key [C+O_G-Ins] { ToggleInsert }
key [C+O_BackSp] { ToggleBackSpKillTab }
key [C+O_Space] { ToggleIndentWithTabs }
key [C+O_C+BackSp] { ToggleBackSpUnindents }
key [A+-] { MatchBracket }
key [A+=] { HilitMatchBracket }
key [C+Space] { InsPrevLineChar }
key [A+Space] { InsPrevLineToEol }
key [A+F5] { ShowEntryScreen }
key [C+_] { ShowPosition }
key [Center] { MoveLineCenter }
key [C+X] { MovePrevPos }
# key [C+S+A] { ASCIITable }
key [G+*] { LineInsert ; MoveUp; ScrollUp }
# key [G++] { DumpFold }
key [A+G++] { FoldCreate }
key [A+G+-] { FoldDestroy }
key [G+S++] { FoldPromote }
key [G+S+-] { FoldDemote }
key [C+G++] { FoldOpen }
key [C+G+-] { FoldClose }
key [C+G+*] { FoldOpenNested }
key [C+G+/] { FoldToggleOpenClose }
key [A+G+*] { FoldOpenAll }
key [A+G+/] { FoldCloseAll }
# key [C+G-Up] { MoveFoldPrev }
# key [C+G-Down] { MoveFoldNext }
# key [A+C+A] { FileOpen 'BUFFER.CPP' }
key [C+K] { ShowKey }
key [A+,] { SearchWordPrev }
key [A+.] { SearchWordNext }
key [A+/] { HilitWord }
}
colorize PLAIN {
SyntaxParser = 'PLAIN';
color {
{ 'Normal', '7 0' },
};
}
mode PLAIN {
Colorizer = 'PLAIN';
}
eventmap LIST {
key [G-Left] { MoveLeft }
key [G-Right] { MoveRight }
key [G-Up] { MoveUp }
key [G-Down] { MoveDown }
key [G-Home] { MoveLineStart }
key [C+G-Home] { MovePageStart }
key [G-End] { MoveLineEnd }
key [C+G-End] { MovePageEnd }
key [G-PgUp] { MovePageUp }
key [C+G-PgUp] { MoveFileStart }
key [G-PgDn] { MovePageDown }
key [C+G-PgDn] { MoveFileEnd }
key [A+G-Up] { ScrollUp }
key [A+G-Down] { ScrollDown }
key [A+G-Left] { ScrollLeft }
key [A+G-Right] { ScrollRight }
key [Esc] { Cancel }
key [G-Enter] { Activate }
}
eventmap BUFFERS: LIST {
key [C+F10] { FileClose }
key [F2] { FileSave }
}
eventmap ROUTINES: LIST {
}
eventmap MLIST: MODEL {
key [G-Left] { MoveLeft }
key [G-Right] { MoveRight }
key [G-Up] { MoveUp }
key [G-Down] { MoveDown }
key [G-Home] { MoveLineStart }
key [C+G-Home] { MovePageStart }
key [G-End] { MoveLineEnd }
key [C+G-End] { MovePageEnd }
key [G-PgUp] { MovePageUp }
key [C+G-PgUp] { MoveFileStart }
key [G-PgDn] { MovePageDown }
key [C+G-PgDn] { MoveFileEnd }
# key [A+G-Up] { ScrollUp }
# key [A+G-Down] { ScrollDown }
# key [A+G-Left] { ScrollLeft }
# key [A+G-Right] { ScrollRight }
key [G-Enter] { Activate }
}
menu Directory {
item "&Next\tF6" { FileNext }
item "&Previous\tShift+F6" { FilePrev }
item;
item "&Close\tAlt+Q" { FileClose }
item;
item "E&xit\tAlt+X" { ExitEditor }
}
menu Navigate {
item "Go &< level\tCtrl+PgUp" { DirGoUp }
item "Go &> level\tCtrl+PgDn" { DirGoDown }
item "Go to &\\\tCtrl+\\" { DirGoRoot }
# item "&/ Goto Dir\t/" { DirGoto }
item "&\\ Goto Dir\t\\" { DirGoto }
item;
item '&A:\\' { DirGoto 'A:\\' }
item '&B:\\' { DirGoto 'B:\\' }
item '&C:\\' { DirGoto 'C:\\' }
item '&D:\\' { DirGoto 'D:\\' }
item '&E:\\' { DirGoto 'E:\\' }
item '&F:\\' { DirGoto 'F:\\' }
item '&G:\\' { DirGoto 'G:\\' }
item '&H:\\' { DirGoto 'H:\\' }
item '&I:\\' { DirGoto 'I:\\' }
}
menu DirMain {
submenu "&Directory", Directory;
submenu "&Navigate", Navigate;
submenu "&Tools", Tools;
submenu "&Window", Window;
}
eventmap DIRECTORY: MLIST {
MainMenu = 'DirMain';
key [C+G-PgUp] { DirGoUp }
key [C+G-PgDn] { DirGoDown }
key [C+\\] { DirGoRoot }
key [/] { DirGoto }
key [\\] { DirGoto }
key [C+D] { DeleteFile }
key [A+D] { MainMenu 'D' }
key [A+N] { MainMenu 'N' }
key [A+W] { MainMenu 'W' }
}
menu Messages {
item "&Close\tAlt+Q" { FileClose }
item;
item "&Next\tF6" { FileNext }
item "&Previous\tShift+F6" { FilePrev }
item;
item "E&xit\tAlt+X" { ExitEditor }
}
menu MsgMain {
submenu "&Messages", Messages;
submenu "&Tools", Tools;
submenu "&Window", Window;
}
eventmap MESSAGES: MLIST {
MainMenu = "MsgMain";
key [A+M] { MainMenu 'M' }
key [A+T] { MainMenu 'T' }
key [A+W] { MainMenu 'W' }
}

264
src/defcfg2.fte Normal file
View file

@ -0,0 +1,264 @@
menu File {
item "&Open...\tCtrl+O" { FileOpen }
item "&Reload" { FileReload }
item "&Save\tCtrl+S" { FileSave }
item "Save &As..." { FileSaveAs }
item "Save Al&l" { FileSaveAll }
item "&Close\tCtrl+W" { FileClose }
item;
item "E&xit\tCtrl+Q" { ExitEditor }
}
menu Edit {
item "&Undo\tCtrl+Z" { Undo }
item "&Redo" { Redo }
item;
item "Cu&t\tCtrl+X" { BlockCut }
item "&Copy\tCtrl+C" { BlockCopy }
item "&Paste\tCtrl+V" { BlockPasteStream }
}
menu Search {
item "&Find...\tCtrl+F" { Find }
item "Find &Next\tCtrl+G" { FindRepeat }
item;
item "Find and &replace...\tCtrl+R" { FindReplace }
item;
item "&Goto line..." { MoveToLine }
}
menu Help {
item "&About..." { ShowVersion }
}
menu Main {
submenu "&File", File;
submenu "&Edit", Edit;
submenu "&Search", Search;
submenu "&Help", Help;
}
menu Local {
item "&Unmark\tEsc" { BlockUnmark }
item "Cu&t\tCtrl+X" { BlockCut }
item "&Copy\tCtrl+C" { BlockCopy }
item "&Paste\tCtrl+V" { BlockPasteStream }
item "Cl&ose\tAlt+Q" { FileClose }
}
eventmap MODEL { # basic commands, for files, directories, message view, etc.
key [C+O] { FileOpen }
key [C+W] { FileClose }
key [F10] { MainMenu }
key [S+F10] { LocalMenu }
key [C+Q] { ExitEditor }
key [A+G-Left] { FilePrev }
key [A+G-Right] { FileNext }
}
eventmap PLAIN: MODEL {
# keymap for plaintext mode
MainMenu = 'Main'; # menu for menubar
LocalMenu = 'Local'; # local menu
key [Esc] { BlockMarkStream; BlockUnmark }
key [C+S] { FileSave }
key [C+C] { BlockCopy }
key [C+V] { BlockPasteStream }
key [C+X] { BlockCut }
key [A+BackSp] { Undo }
key [A+S+BackSp] { Redo }
key [G-Enter] { LineNew }
key [BackSp] { BackSpace }
key [G-Ins] { ToggleInsert }
key [G-Del] { Delete }
key [Tab] { InsertTab }
key [C+BackSp] { KillWordPrev }
key [C+F] { Find }
key [C+G] { FindRepeat }
key [G-Left] { MoveLeft }
key [C+G-Left] { MoveWordPrev }
key [G-Right] { MoveRight }
key [C+G-Right] { MoveWordNext }
key [G-Up] { MoveUp }
key [G-Down] { MoveDown }
key [G-Home] { MoveLineStart }
key [C+G-Home] { MovePageStart }
key [G-End] { MoveLineEnd }
key [C+G-End] { MovePageEnd }
key [G-PgUp] { MovePageUp }
key [C+G-PgUp] { MoveFileStart }
key [G-PgDn] { MovePageDown }
key [C+G-PgDn] { MoveFileEnd }
key [S+G-Left] { BlockExtendBegin; MoveLeft; BlockExtendEnd }
key [S+G-Right] { BlockExtendBegin; MoveRight; BlockExtendEnd }
key [C+G-S+Left] { BlockExtendBegin; MoveWordPrev; BlockExtendEnd }
key [C+G-S+Right] { BlockExtendBegin; MoveWordNext; BlockExtendEnd }
key [G-S+Up] { BlockExtendBegin; MoveUp; BlockExtendEnd }
key [G-S+Down] { BlockExtendBegin; MoveDown; BlockExtendEnd }
key [G-S+Home] { BlockExtendBegin; MoveLineStart; BlockExtendEnd }
key [G-S+End] { BlockExtendBegin; MoveLineEnd; BlockExtendEnd }
key [C+G-S+Home] { BlockExtendBegin; MovePageStart; BlockExtendEnd }
key [C+G-S+End] { BlockExtendBegin; MovePageEnd; BlockExtendEnd }
key [G-S+PgUp] { BlockExtendBegin; MovePageUp; BlockExtendEnd }
key [G-S+PgDn] { BlockExtendBegin; MovePageDown; BlockExtendEnd }
key [C+G-S+PgUp] { BlockExtendBegin; MoveFileStart; BlockExtendEnd }
key [C+G-S+PgDn] { BlockExtendBegin; MoveFileEnd; BlockExtendEnd }
key [C+G-Ins] { BlockCopy }
key [S+G-Ins] { BlockPasteStream }
key [S+G-Del] { BlockCut }
key [F7] { BlockBegin }
key [S+F7] { MoveBlockStart }
key [F8] { BlockEnd }
key [S+F8] { MoveBlockEnd }
key [A+E] { MainMenu 'E' }
key [A+F] { MainMenu 'F' }
key [A+H] { MainMenu 'H' }
key [A+S] { MainMenu 'S' }
}
colorize PLAIN {
SyntaxParser = 'PLAIN';
# color {
# { 'Normal', '-7' },
# };
}
mode PLAIN {
Colorizer = 'PLAIN';
}
eventmap LIST {
key [G-Left] { MoveLeft }
key [G-Right] { MoveRight }
key [G-Up] { MoveUp }
key [G-Down] { MoveDown }
key [G-Home] { MoveLineStart }
key [C+G-Home] { MovePageStart }
key [G-End] { MoveLineEnd }
key [C+G-End] { MovePageEnd }
key [G-PgUp] { MovePageUp }
key [C+G-PgUp] { MoveFileStart }
key [G-PgDn] { MovePageDown }
key [C+G-PgDn] { MoveFileEnd }
key [A+G-Up] { ScrollUp }
key [A+G-Down] { ScrollDown }
key [A+G-Left] { ScrollLeft }
key [A+G-Right] { ScrollRight }
key [Esc] { Cancel }
key [G-Enter] { Activate }
}
eventmap BUFFERS: LIST {
key [C+F10] { FileClose }
key [F2] { FileSave }
}
eventmap ROUTINES: LIST {
}
eventmap MLIST: MODEL {
key [G-Left] { MoveLeft }
key [G-Right] { MoveRight }
key [G-Up] { MoveUp }
key [G-Down] { MoveDown }
key [G-Home] { MoveLineStart }
key [C+G-Home] { MovePageStart }
key [G-End] { MoveLineEnd }
key [C+G-End] { MovePageEnd }
key [G-PgUp] { MovePageUp }
key [C+G-PgUp] { MoveFileStart }
key [G-PgDn] { MovePageDown }
key [C+G-PgDn] { MoveFileEnd }
# key [A+G-Up] { ScrollUp }
# key [A+G-Down] { ScrollDown }
# key [A+G-Left] { ScrollLeft }
# key [A+G-Right] { ScrollRight }
key [G-Enter] { Activate }
}
menu Directory {
item "&Next\tF6" { FileNext }
item "&Previous\tShift+F6" { FilePrev }
item;
item "&Close\tAlt+Q" { FileClose }
item;
item "E&xit\tAlt+X" { ExitEditor }
}
menu Navigate {
item "Go &< level\tCtrl+PgUp" { DirGoUp }
item "Go &> level\tCtrl+PgDn" { DirGoDown }
item "Go to &\\\tCtrl+\\" { DirGoRoot }
# item "&/ Goto Dir\t/" { DirGoto }
item "&\\ Goto Dir\t\\" { DirGoto }
item;
item '&A:\\' { DirGoto 'A:\\' }
item '&B:\\' { DirGoto 'B:\\' }
item '&C:\\' { DirGoto 'C:\\' }
item '&D:\\' { DirGoto 'D:\\' }
item '&E:\\' { DirGoto 'E:\\' }
item '&F:\\' { DirGoto 'F:\\' }
item '&G:\\' { DirGoto 'G:\\' }
item '&H:\\' { DirGoto 'H:\\' }
item '&I:\\' { DirGoto 'I:\\' }
}
menu DirMain {
submenu "&Directory", Directory;
submenu "&Navigate", Navigate;
submenu "&Tools", Tools;
submenu "&Window", Window;
}
eventmap DIRECTORY: MLIST {
MainMenu = 'DirMain';
key [C+G-PgUp] { DirGoUp }
key [C+G-PgDn] { DirGoDown }
key [C+\\] { DirGoRoot }
key [/] { DirGoto }
key [\\] { DirGoto }
key [A+D] { MainMenu 'D' }
key [A+N] { MainMenu 'N' }
key [A+W] { MainMenu 'W' }
}
menu Messages {
item "&Close\tAlt+Q" { FileClose }
item;
item "&Next\tF6" { FileNext }
item "&Previous\tShift+F6" { FilePrev }
item;
item "E&xit\tAlt+X" { ExitEditor }
}
menu MsgMain {
submenu "&Messages", Messages;
submenu "&Tools", Tools;
submenu "&Window", Window;
}
eventmap MESSAGES: MLIST {
MainMenu = "MsgMain";
key [A+M] { MainMenu 'M' }
key [A+T] { MainMenu 'T' }
key [A+W] { MainMenu 'W' }
}

23
src/dialog.h Normal file
View file

@ -0,0 +1,23 @@
/* dialog.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __DIALOG_H__
#define __DIALOG_H__
#define askYes 0
#define askNo 1
#define askCancel 2
#define askOK 3
int AskString(char *Prompt, char *String, int MaxLen);
int AskYesNo(char *Prompt);
int AskYesNoCancel(char *Prompt);
int AskOKCancel(char *Prompt);
#endif

1069
src/e_block.cpp Normal file

File diff suppressed because it is too large Load diff

983
src/e_buffer.cpp Normal file
View file

@ -0,0 +1,983 @@
/* e_buffer.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
EBuffer *SSBuffer = 0; // scrap buffer (clipboard)
///////////////////////////////////////////////////////////////////////////////
EBuffer::EBuffer(int createFlags, EModel **ARoot, const char * /*AName*/)
:EModel(createFlags, ARoot), TP(0,0), CP(0,0), BB(-1,-1), BE(-1,-1),
PrevPos(-1, -1), SavedPos(-1, -1), Match(-1, -1)
{
Modified = 0;
Loaded = 0;
Loading = 0;
FileName = 0;
LL = 0;
VV = 0;
FF = 0;
RGap = RCount = RAllocated = 0;
VGap = VCount = VAllocated = 0;
FCount = 0;
Modified = 0;
BlockMode = bmStream;
ExtendGrab = 0;
AutoExtend = 0;
MatchLen = MatchCount = 0;
#ifdef CONFIG_UNDOREDO
US.Num = 0;
US.Data = 0;
US.Top = 0;
US.UndoPtr = 0;
US.NextCmd = 1;
US.Record = 1;
US.Undo = 0;
#endif
#ifdef CONFIG_BOOKMARKS
BMCount = 0;
BMarks = 0;
#endif
#ifdef CONFIG_OBJ_ROUTINE
rlst.Count = 0;
rlst.Lines = 0;
Routines = 0;
#endif
#ifdef CONFIG_WORD_HILIT
WordList = 0;
WordCount = 0;
#endif
//Name = strdup(AName);
Allocate(0);
AllocVis(0);
Mode = GetModeForName("");
Flags = (Mode->Flags);
BFI(this, BFI_Undo) = 0;
BFI(this, BFI_ReadOnly) = 0;
Modified = 0;
MinRedraw = -1;
MaxRedraw = -1;
RedrawToEos = 0;
#ifdef CONFIG_SYNTAX_HILIT
StartHilit = 0;
EndHilit = -1;
HilitProc = 0;
if (Mode && Mode->fColorize)
HilitProc = GetHilitProc(Mode->fColorize->SyntaxParser);
#endif
InsertLine(CP,0,0); /* there should always be at least one line in the edit buffer */
Flags = (Mode->Flags);
Modified = 0;
}
EBuffer::~EBuffer() {
#ifdef CONFIG_HISTORY
if (FileName != 0 && Loaded)
UpdateFPos(FileName, VToR(CP.Row), CP.Col);
#endif
if (FileName && Loaded)
markIndex.storeForBuffer(this);
Clear();
if (LL)
free(LL);
//free(Name);
if (FileName)
free(FileName);
#ifdef CONFIG_BOOKMARKS
if (BMCount != 0) {
for (int i = 0; i < BMCount; i++)
free(BMarks[i].Name);
free(BMarks);
BMarks = 0;
BMCount = 0;
}
#endif
#ifdef CONFIG_OBJ_ROUTINE
if (rlst.Lines) {
free(rlst.Lines);
rlst.Lines = 0;
}
#endif
}
void EBuffer::DeleteRelated() {
#ifdef CONFIG_OBJ_ROUTINE
if (Routines) {
::ActiveView->DeleteModel(Routines);
Routines = 0;
}
#endif
}
int EBuffer::Clear() {
Modified = 1;
#ifdef CONFIG_SYNTAX_HILIT
EndHilit = -1;
StartHilit = 0;
while (WordCount--)
{
free(WordList[WordCount]);
}
free(WordList);
WordCount = 0;
WordList = 0;
#endif
#ifdef CONFIG_OBJ_ROUTINE
rlst.Count = 0;
if (rlst.Lines) {
free(rlst.Lines);
rlst.Lines = 0;
}
#endif
if (LL)
{
for (int i = 0; i < RCount; i++)
delete LL[GapLine(i, RGap, RCount, RAllocated)];
free(LL);
LL = 0;
}
RCount = RAllocated = RGap = 0;
VCount = VAllocated = VGap = 0;
if (VV)
{
free(VV);
VV = 0;
}
#ifdef CONFIG_UNDOREDO
FreeUndo();
#endif
if (FCount != 0) {
free(FF);
FCount = 0;
FF = 0;
}
return 0;
}
#ifdef CONFIG_UNDOREDO
int EBuffer::FreeUndo() {
for (int j = 0; j < US.Num; j++)
free(US.Data[j]);
free(US.Top);
free(US.Data);
US.Num = 0;
US.Data = 0;
US.Top = 0;
US.Undo = 0;
US.Record = 1;
US.UndoPtr = 0;
return 1;
}
#endif
int EBuffer::Modify() {
if (BFI(this, BFI_ReadOnly)) {
Msg(S_ERROR, "File is read-only.");
return 0;
}
if (Modified == 0) {
struct stat StatBuf;
if ((FileName != 0) && FileOk && (stat(FileName, &StatBuf) == 0)) {
if (FileStatus.st_size != StatBuf.st_size ||
FileStatus.st_mtime != StatBuf.st_mtime)
{
View->MView->Win->Choice(GPC_ERROR, "Warning! Press Esc!",
0,
"File %-.55s changed on disk!",
FileName);
switch (View->MView->Win->Choice(0, "File Changed on Disk",
2,
"&Modify",
"&Cancel",
"%s", FileName))
{
case 0:
break;
case 1:
case -1:
default:
return 0;
}
}
}
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo))
if (PushUChar(ucModified) == 0) return 0;
#endif
}
Modified++;
if (Modified == 0) Modified++;
return 1;
}
int EBuffer::LoadRegion(EPoint * /*A*/, int /*FH*/, int /*StripChar*/, int /*LineChar*/) {
return 0;
}
int EBuffer::InsertLine(EPoint Pos, int ACount, char *AChars) {
if (InsLine(Pos.Row, 0) == 0) return 0;
if (InsText(Pos.Row, Pos.Col, ACount, AChars) == 0) return 0;
return 1;
}
int EBuffer::UpdateMark(EPoint &M, int Type, int Row, int Col, int Rows, int Cols) {
switch (Type) {
case umInsert: /* text inserted */
switch (BlockMode) {
case bmLine:
case bmColumn:
if (M.Row >= Row)
M.Row += Rows;
break;
case bmStream:
if (Cols) {
if (M.Row == Row)
if (M.Col >= Col)
M.Col += Cols;
}
if (Rows) {
if (M.Row >= Row)
M.Row += Rows;
}
break;
}
break;
case umDelete:
switch (BlockMode) {
case bmLine:
case bmColumn:
if (M.Row >= Row)
if (InRange(Row, M.Row, Row + Rows))
M.Row = Row;
else
M.Row -= Rows;
break;
case bmStream:
if (Cols) {
if (M.Row == Row)
if (M.Col >= Col)
if (M.Col < Col + Cols)
M.Col = Col;
else
M.Col -= Cols;
}
if (Rows) {
if (M.Row >= Row)
if (M.Row < Row + Rows) {
M.Row = Row;
M.Col = 0;
} else M.Row -= Rows;
}
}
break;
case umSplitLine:
switch (BlockMode) {
case bmLine:
case bmColumn:
if (M.Row == Row) {
if (Col <= M.Col) {
M.Row++;
M.Col -= Col;
}
} else if (M.Row > Row) M.Row++;
break;
case bmStream:
if (M.Row == Row) {
if (Col <= M.Col) {
M.Row++;
M.Col -= Col;
}
} else if (M.Row > Row) M.Row++;
break;
}
break;
case umJoinLine:
switch (BlockMode) {
case bmLine:
case bmColumn:
if (M.Row == Row + 1)
M.Row--;
else if (M.Row > Row) M.Row--;
break;
case bmStream:
if (M.Row == Row + 1) {
M.Row--;
M.Col += Col;
} else if (M.Row > Row) M.Row--;
break;
}
break;
}
return 1;
}
int EBuffer::UpdateMarker(int Type, int Row, int Col, int Rows, int Cols) {
EPoint OldBB = BB, OldBE = BE;
EView *V;
UpdateMark(SavedPos, Type, Row, Col, Rows, Cols);
UpdateMark(PrevPos, Type, Row, Col, Rows, Cols);
UpdateMark(BB, Type, Row, Col, Rows, Cols);
UpdateMark(BE, Type, Row, Col, Rows, Cols);
V = View;
while (V) {
if (V->Model != this)
assert(1 == 0);
if (V != View) {
EPoint M;
M = GetViewVPort(V)->TP;
UpdateMark(GetViewVPort(V)->TP, Type, Row, Col, Rows, Cols);
GetViewVPort(V)->TP.Col = M.Col;
UpdateMark(GetViewVPort(V)->CP, Type, Row, Col, Rows, Cols);
}
V = V->NextView;
}
#ifdef CONFIG_OBJ_ROUTINE
for (int i = 0; i < rlst.Count && rlst.Lines; i++) {
EPoint M;
M.Col = 0;
M.Row = rlst.Lines[i];
UpdateMark(M, Type, Row, Col, Rows, Cols);
rlst.Lines[i] = M.Row;
}
#endif
for (int f = 0; f < FCount; f++) {
EPoint M;
M.Col = 0;
M.Row = FF[f].line;
UpdateMark(M, Type, Row, Col, Rows, Cols);
FF[f].line = M.Row;
}
#ifdef CONFIG_BOOKMARKS
for (int b = 0; b < BMCount; b++)
UpdateMark(BMarks[b].BM, Type, Row, Col, Rows, Cols);
#endif
if (OldBB.Row != BB.Row) {
int MinL = Min(OldBB.Row, BB.Row);
int MaxL = Max(OldBB.Row, BB.Row);
if (MinL != -1 && MaxL != -1)
Draw(MinL, MaxL);
}
if (OldBE.Row != BE.Row) {
int MinL = Min(OldBE.Row, BE.Row);
int MaxL = Max(OldBE.Row, BE.Row);
if (MinL != -1 && MaxL != -1)
Draw(MinL, MaxL);
}
return 1;
}
int EBuffer::ValidPos(EPoint Pos) {
if ((Pos.Col >= 0) &&
(Pos.Row >= 0) &&
(Pos.Row < VCount))
return 1;
return 0;
}
int EBuffer::RValidPos(EPoint Pos) {
if ((Pos.Col >= 0) &&
(Pos.Row >= 0) &&
(Pos.Row < RCount))
return 1;
return 0;
}
int EBuffer::AssertLine(int Row) {
if (Row == RCount)
if (InsLine(RCount, 0) == 0) return 0;
return 1;
}
int EBuffer::SetFileName(const char *AFileName, const char *AMode) {
FileOk = 0;
free(FileName);
FileName = strdup(AFileName);
Mode = 0;
if (AMode)
Mode = FindMode(AMode);
if (Mode == 0)
Mode = GetModeForName(AFileName);
assert(Mode != 0);
Flags = (Mode->Flags);
#ifdef CONFIG_SYNTAX_HILIT
HilitProc = 0;
if (Mode && Mode->fColorize)
HilitProc = GetHilitProc(Mode->fColorize->SyntaxParser);
#endif
UpdateTitle();
return FileName?1:0;
}
int EBuffer::SetPos(int Col, int Row, int tabMode) {
assert (Col >= 0 && Row >= 0 && Row < VCount);
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo) == 1 && BFI(this, BFI_UndoMoves) == 1) {
if (PushULong(CP.Col) == 0) return 0;
if (PushULong(CP.Row) == 0) return 0;
if (PushUChar(ucPosition) == 0) return 0;
}
#endif
if (AutoExtend) {
BlockExtendBegin();
AutoExtend = 1;
}
PrevPos = CP;
PrevPos.Row = (CP.Row < VCount) ? VToR(CP.Row) : (CP.Row - VCount + RCount);
CP.Row = Row;
CP.Col = Col;
if (AutoExtend) {
BlockExtendEnd();
AutoExtend = 1;
}
// if (View && View->Model == this ) {
// View->GetVPort();
// }
if (BFI(this, BFI_CursorThroughTabs) == 0) {
if (tabMode == tmLeft) {
if (MoveTabStart() == 0) return 0;
} else if (tabMode == tmRight) {
if (MoveTabEnd() == 0) return 0;
}
}
if (ExtendGrab == 0 && AutoExtend == 0 && BFI(this, BFI_PersistentBlocks) == 0) {
if (CheckBlock() == 1)
if (BlockUnmark() == 0)
return 0;
}
return 1;
}
int EBuffer::SetPosR(int Col, int Row, int tabMode) {
assert (Row >= 0 && Row < RCount && Col >= 0);
int L = RToV(Row);
if (L == -1)
if (ExposeRow(Row) == 0) return 0;
L = RToV(Row);
return SetPos(Col, L, tabMode);
}
int EBuffer::SetNearPos(int Col, int Row, int tabMode) {
if (Row >= VCount) Row = VCount - 1;
if (Row < 0) Row = 0;
if (Col < 0) Col = 0;
return SetPos(Col, Row, tabMode);
}
int EBuffer::SetNearPosR(int Col, int Row, int tabMode) {
if (Row >= RCount) Row = RCount - 1;
if (Row < 0) Row = 0;
if (Col < 0) Col = 0;
return SetPosR(Col, Row, tabMode);
}
int EBuffer::CenterPos(int Col, int Row, int tabMode) {
assert(Row >= 0 && Row < VCount && Col >= 0);
if (SetPos(Col, Row, tabMode) == 0) return 0;
if (View && View->Model == this) {
Row -= GetVPort()->Rows / 2;
if (Row < 0) Row = 0;
Col -= GetVPort()->Cols - 8;
if (Col < 0) Col = 0;
if (GetVPort()->SetTop(Col, Row) == 0) return 0;
GetVPort()->ReCenter = 1;
}
return 1;
}
int EBuffer::CenterPosR(int Col, int Row, int tabMode) {
int L;
assert(Row >= 0 && Row < RCount && Col >= 0);
L = RToV(Row);
if (L == -1)
if (ExposeRow(Row) == 0) return 0;
L = RToV(Row);
return CenterPos(Col, L, tabMode);
}
int EBuffer::CenterNearPos(int Col, int Row, int tabMode) {
if (Row >= VCount) Row = VCount - 1;
if (Row < 0) Row = 0;
if (Col < 0) Col = 0;
return CenterPos(Col, Row, tabMode);
}
int EBuffer::CenterNearPosR(int Col, int Row, int tabMode) {
if (Row >= RCount) Row = RCount - 1;
if (Row < 0) Row = 0;
if (Col < 0) Col = 0;
return CenterPosR(Col, Row, tabMode);
}
int EBuffer::LineLen(int Row) {
assert(Row >= 0 && Row < RCount);
PELine L = RLine(Row);
return ScreenPos(L, L->Count);
}
int EBuffer::LineChars(int Row) {
assert(Row >= 0 && Row < RCount);
return RLine(Row)->Count;
}
int EBuffer::DelLine(int Row, int DoMark) {
int VLine;
int GapSize;
// printf("DelLine: %d\n", Row);
if (Row < 0) return 0;
if (Row >= RCount) return 0;
if (Modify() == 0) return 0;
VLine = RToV(Row);
if (VLine == -1)
if (ExposeRow(Row) == 0) return 0;
VLine = RToV(Row);
assert(VLine != -1);
if (FindFold(Row) != -1) {
if (FoldDestroy(Row) == 0) return 0;
}
VLine = RToV(Row);
assert(VLine != -1);
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo) == 1) {
if (PushUData(RLine(Row)->Chars, RLine(Row)->Count) == 0) return 0;
if (PushULong(RLine(Row)->Count) == 0) return 0;
if (PushULong(Row) == 0) return 0;
if (PushUChar(ucDelLine) == 0) return 0;
}
#endif
if (DoMark)
UpdateMarker(umDelete, Row, 0, 1, 0);
//puts("Here");
Draw(Row, -1);
Hilit(Row);
assert(RAllocated >= RCount);
if (RGap != Row)
if (MoveRGap(Row) == 0) return 0;
GapSize = RAllocated - RCount;
delete LL[RGap + GapSize];
LL[RGap + GapSize] = 0;
RCount--;
GapSize++;
if (RAllocated - RAllocated / 2 > RCount) {
memmove(LL + RGap + GapSize - RAllocated / 3,
LL + RGap + GapSize,
sizeof(PELine) * (RCount - RGap));
if (Allocate(RAllocated - RAllocated / 3) == 0) return 0;
}
assert(VAllocated >= VCount);
if (VGap != VLine)
if (MoveVGap(VLine) == 0) return 0;
GapSize = VAllocated - VCount;
VV[VGap + GapSize] = 0;
VCount--;
GapSize++;
if (VAllocated - VAllocated / 2 > VCount) {
memmove(VV + VGap + GapSize - VAllocated / 3,
VV + VGap + GapSize,
sizeof(VV[0]) * (VCount - VGap));
if (AllocVis(VAllocated - VAllocated / 3) == 0) return 0;
}
return 1;
}
int EBuffer::InsLine(int Row, int DoAppend, int DoMark) {
PELine L;
int VLine = -1;
// printf("InsLine: %d\n", Row);
if (Row < 0) return 0;
if (Row > RCount) return 0;
if (Modify() == 0) return 0;
if (DoAppend) {
Row++;
}
if (Row < RCount) {
VLine = RToV(Row);
if (VLine == -1)
if (ExposeRow(Row) == 0) return 0;
VLine = RToV(Row);
assert(VLine != -1);
} else {
VLine = VCount;
}
L = new ELine(0, (char *)0);
if (L == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo) == 1) {
if (PushULong(Row) == 0) return 0;
if (PushUChar(ucInsLine) == 0) return 0;
}
#endif
if (DoMark)
UpdateMarker(umInsert, Row, 0, 1, 0);
Draw(Row, -1);
Hilit(Row);
VLine = RToVN(Row);
assert(RCount <= RAllocated);
// printf("++ %d G:C:A :: %d - %d - %d\n", Row, RGap, RCount, RAllocated);
if (RCount == RAllocated) {
if (Allocate(RCount ? (RCount * 2) : 1) == 0) return 0;
memmove(LL + RAllocated - (RCount - RGap),
LL + RGap,
sizeof(PELine) * (RCount - RGap));
}
if (RGap != Row)
if (MoveRGap(Row) == 0) return 0;
LL[RGap] = L;
RGap++;
RCount++;
// printf("-- %d G:C:A :: %d - %d - %d\n", Row, RGap, RCount, RAllocated);
assert(VCount <= VAllocated);
if (VCount == VAllocated) {
if (AllocVis(VCount ? (VCount * 2) : 1) == 0) return 0;
memmove(VV + VAllocated - (VCount - VGap),
VV + VGap,
sizeof(VV[0]) * (VCount - VGap));
}
if (VGap != VLine)
if (MoveVGap(VLine) == 0) return 0;
VV[VGap] = Row - VGap;
VGap++;
VCount++;
/* if (AllocVis(VCount + 1) == 0) return 0;
memmove(VV + VLine + 1, VV + VLine, sizeof(VV[0]) * (VCount - VLine));
VCount++;
Vis(VLine, Row - VLine);*/
return 1;
}
int EBuffer::DelChars(int Row, int Ofs, int ACount) {
PELine L;
// printf("DelChars: %d:%d %d\n", Row, Ofs, ACount);
if (Row < 0) return 0;
if (Row >= RCount) return 0;
L = RLine(Row);
if (Ofs < 0) return 0;
if (Ofs >= L->Count) return 0;
if (Ofs + ACount >= L->Count)
ACount = L->Count - Ofs;
if (ACount == 0) return 1;
if (Modify() == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo) == 1) {
if (PushUData(L->Chars + Ofs, ACount) == 0) return 0;
if (PushULong(ACount) == 0) return 0;
if (PushULong(Ofs) == 0) return 0;
if (PushULong(Row) == 0) return 0;
if (PushUChar(ucDelChars) == 0) return 0;
}
#endif
if (L->Count > Ofs + ACount)
memmove(L->Chars + Ofs, L->Chars + Ofs + ACount, L->Count - Ofs - ACount);
L->Count -= ACount;
if (L->Allocate(L->Count) == 0) return 0;
Draw(Row, Row);
Hilit(Row);
// printf("OK\n");
return 1;
}
int EBuffer::InsChars(int Row, int Ofs, int ACount, char *Buffer) {
PELine L;
// printf("InsChars: %d:%d %d\n", Row, Ofs, ACount);
assert(Row >= 0 && Row < RCount && Ofs >= 0);
L = RLine(Row);
if (Ofs < 0) return 0;
if (Ofs > L->Count) return 0;
if (ACount == 0) return 1;
if (Modify() == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo) == 1) {
if (PushULong(Row) == 0) return 0;
if (PushULong(Ofs) == 0) return 0;
if (PushULong(ACount) == 0) return 0;
if (PushUChar(ucInsChars) == 0) return 0;
}
#endif
if (L->Allocate(L->Count + ACount) == 0) return 0;
if (L->Count > Ofs)
memmove(L->Chars + Ofs + ACount, L->Chars + Ofs, L->Count - Ofs);
if (Buffer == 0)
memset(L->Chars + Ofs, ' ', ACount);
else
memmove(L->Chars + Ofs, Buffer, ACount);
L->Count += ACount;
Draw(Row, Row);
Hilit(Row);
// printf("OK\n");
return 1;
}
int EBuffer::UnTabPoint(int Row, int Col) {
ELine *L;
int Ofs, Pos, TPos;
assert(Row >= 0 && Row < RCount && Col >= 0);
L = RLine(Row);
Ofs = CharOffset(L, Col);
if (Ofs >= L->Count)
return 1;
if (L->Chars[Ofs] != '\t')
return 1;
Pos = ScreenPos(L, Ofs);
if (Pos < Col) {
TPos = NextTab(Pos, BFI(this, BFI_TabSize));
if (DelChars(Row, Ofs, 1) != 1)
return 0;
if (InsChars(Row, Ofs, TPos - Pos, 0) != 1)
return 0;
}
return 1;
}
int EBuffer::ChgChars(int Row, int Ofs, int ACount, char * /*Buffer*/) {
PELine L;
assert(Row >= 0 && Row < RCount && Ofs >= 0);
L = RLine(Row);
if (Ofs < 0) return 0;
if (Ofs > L->Count) return 0;
if (ACount == 0) return 1;
if (Modify() == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo) == 1) {
if (PushUData(L->Chars + Ofs, ACount) == 0) return 0;
if (PushULong(ACount) == 0) return 0;
if (PushULong(Ofs) == 0) return 0;
if (PushULong(Row) == 0) return 0;
if (PushUChar(ucDelChars) == 0) return 0;
if (PushULong(Row) == 0) return 0;
if (PushULong(Ofs) == 0) return 0;
if (PushULong(ACount) == 0) return 0;
if (PushUChar(ucInsChars) == 0) return 0;
}
#endif
Hilit(Row);
Draw(Row, Row);
return 1;
}
int EBuffer::DelText(int Row, int Col, int ACount, int DoMark) {
int L, B, C;
// printf("DelTExt: %d:%d %d\n", Row, Col, ACount);
assert(Row >= 0 && Row < RCount && Col >= 0);
if (Modify() == 0) return 0;
if (ACount == 0) return 1;
L = LineLen(Row);
if (Col >= L)
return 1;
if (ACount == -1 || ACount + Col > L)
ACount = L - Col;
if (UnTabPoint(Row, Col) == 0)
return 0;
if (UnTabPoint(Row, Col + ACount) == 0)
return 0;
B = CharOffset(RLine(Row), Col);
C = CharOffset(RLine(Row), Col + ACount);
if ((ACount > 0) && (B != -1) && (C != -1)) {
if (DelChars(Row, B, C - B) == 0) return 0;
if (DoMark) UpdateMarker(umDelete, Row, Col, 0, ACount);
}
// printf("OK\n");
return 1;
}
int EBuffer::InsText(int Row, int Col, int ACount, char *ABuffer, int DoMark) {
int B, L;
// printf("InsText: %d:%d %d\n", Row, Col, ACount);
assert(Row >= 0 && Row < RCount && Col >= 0 && ACount >= 0);
if (ACount == 0) return 1;
if (Modify() == 0) return 0;
if (DoMark) UpdateMarker(umInsert, Row, Col, 0, ACount);
L = LineLen(Row);
if (L < Col) {
if (InsChars(Row, RLine(Row)->Count, Col - L, 0) == 0)
return 0;
} else
if (UnTabPoint(Row, Col) == 0) return 0;
B = CharOffset(RLine(Row), Col);
if (InsChars(Row, B, ACount, ABuffer) == 0) return 0;
// printf("OK\n");
return 1;
}
int EBuffer::PadLine(int Row, int Length) {
int L;
L = LineLen(Row);
if (L < Length)
if (InsChars(Row, RLine(Row)->Count, Length - L, 0) == 0)
return 0;
return 1;
}
int EBuffer::InsLineText(int Row, int Col, int ACount, int LCol, PELine Line) {
int Ofs, Pos, TPos, C, B, L;
//fprintf(stderr, "\n\nInsLineText: %d:%d %d %d", Row, Col, ACount, LCol);
assert(Row >= 0 && Row < RCount && Col >= 0 && LCol >= 0);
if (BFI(this, BFI_ReadOnly) == 1)
return 0;
L = ScreenPos(Line, Line->Count);
if (LCol >= L) return 1;
if (ACount == -1) ACount = L - LCol;
if (ACount + LCol > L) ACount = L - LCol;
if (ACount == 0) return 1;
assert(ACount > 0);
B = Ofs = CharOffset(Line, LCol);
if (Ofs < Line->Count && Line->Chars[Ofs] == '\t') {
Pos = ScreenPos(Line, Ofs);
if (Pos < LCol) {
TPos = NextTab(Pos, BFI(this, BFI_TabSize));
if (InsText(Row, Col, TPos - LCol, 0) == 0)
return 0;
Col += TPos - LCol;
ACount -= TPos - LCol;
LCol = TPos;
B++;
}
}
C = Ofs = CharOffset(Line, LCol + ACount);
if (Ofs < Line->Count && Line->Chars[Ofs] == '\t') {
Pos = ScreenPos(Line, Ofs);
if (Pos < LCol + ACount) {
if (InsText(Row, Col, LCol + ACount - Pos, 0) == 0)
return 0;
}
}
//fprintf(stderr, "B = %d, C = %d\n", B, C);
C -= B;
if (C <= 0) return 1;
if (InsText(Row, Col, C, Line->Chars + B) == 0) return 0;
// printf("OK\n");
return 1;
}
int EBuffer::SplitLine(int Row, int Col) {
int VL;
assert(Row >= 0 && Row < RCount && Col >= 0);
if (BFI(this, BFI_ReadOnly) == 1) return 0;
VL = RToV(Row);
if (VL == -1)
if (ExposeRow(Row) == 0) return 0;
if (Row > 0) {
VL = RToV(Row - 1);
if (VL == -1)
if (ExposeRow(Row - 1) == 0) return 0;
}
VL = RToV(Row);
assert(VL != -1);
if (Col == 0) {
if (InsLine(Row, 0, 1) == 0) return 0;
} else {
UpdateMarker(umSplitLine, Row, Col, 0, 0);
if (InsLine(Row, 1, 0) == 0) return 0;
RLine(Row)->StateE = short((Row > 0) ? RLine(Row - 1)->StateE : 0);
if (Col < LineLen(Row)) {
int P, L;
//if (RLine(Row)->ExpandTabs(Col, -2, &Flags) == 0) return 0;
if (UnTabPoint(Row, Col) != 1)
return 0;
P = CharOffset(RLine(Row), Col);
L = LineLen(Row);
if (InsText(Row + 1, 0, RLine(Row)->Count - P, RLine(Row)->Chars + P, 0) == 0) return 0;
if (DelText(Row, Col, L - Col, 0) == 0) return 0;
}
}
Draw(Row, -1);
Hilit(Row);
return 1;
}
int EBuffer::JoinLine(int Row, int Col) {
int Len, VLine;
if (BFI(this, BFI_ReadOnly) == 1) return 0;
if (Row < 0 || Row >= RCount - 1) return 0;
if (Col < 0) return 0;
Len = LineLen(Row);
if (Col < Len) Col = Len;
VLine = RToV(Row);
if (VLine == -1) {
if (ExposeRow(Row) == 0) return 0;
if (ExposeRow(Row + 1) == 0) return 0;
}
VLine = RToV(Row);
if (Col == 0 && RLine(Row)->Count == 0) {
if (DelLine(Row, 1) == 0) return 0;
} else {
if (InsText(Row, Col, RLine(Row + 1)->Count, RLine(Row + 1)->Chars, 0) == 0) return 0;
if (DelLine(Row + 1, 0) == 0) return 0;
UpdateMarker(umJoinLine, Row, Col, 0, 0);
}
Draw(Row, -1);
Hilit(Row);
return 1;
}

770
src/e_buffer.h Normal file
View file

@ -0,0 +1,770 @@
/* e_buffer.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef _BUFFER_H_
#define _BUFFER_H_
#define bmLine 0
#define bmStream 1
#define bmColumn 2
#define E_OK 0 // all ok
#define E_CANCEL 1 // operation cancelled
#define E_ERROR 2 // error
#define E_NOMEM 3 // out of memory
#define umDelete 0
#define umInsert 1
#define umSplitLine 2
#define umJoinLine 3
#define tmNone 0
#define tmLeft 1
#define tmRight 2
typedef unsigned char TransTable[256];
#ifdef DOS /* 16 bit, sometime ;-) */
#define RWBUFSIZE 8192
#else
#define RWBUFSIZE 32768
#endif
extern char FileBuffer[RWBUFSIZE];
#define ChClass(x) (WGETBIT(Flags.WordChars, (x)) ? 1 : 0)
#define ChClassK(x) (((x) == ' ' || (x) == 9) ? 2 : ChClass(x))
#define InRange(a,x,b) (((a) <= (x)) && ((x) < (b)))
#define Min(a,b) (((a) < (b))?(a):(b))
#define Max(a,b) (((a) > (b))?(a):(b))
#define NextTab(pos,ts) (((pos) / (ts) + 1) * (ts))
#define GapLine(x,g,c,a) (((x) < (g)) ? (x) : ((x) + (a) - (c)))
typedef class ELine* PELine;
typedef class EPoint* PEPoint;
#define CHAR_TRESHOLD 0x3U
class ELine {
public:
int Count;
char *Chars;
#ifdef CONFIG_SYNTAX_HILIT
hlState StateE;
#endif
ELine(int ACount, char *AChars);
ELine(char *AChars, int ACount);
~ELine();
int Allocate(unsigned int Bytes);
// int Length(EBufferFlags *CurFlags);
};
class EPoint {
public:
int Row;
int Col;
// EPoint(EPoint &M) { Row = M.Row; Col = M.Col; }
EPoint(int aRow = 0, int aCol = 0) { Row = aRow; Col = aCol; }
~EPoint() {}
};
typedef struct _UndoStack {
int NextCmd, Record, Undo;
int UndoPtr;
int Num;
void **Data;
int *Top;
} UndoStack;
#ifdef CONFIG_OBJ_ROUTINE
class RoutineView;
typedef struct _RoutineList {
int Count;
int *Lines;
} RoutineList;
#endif
#ifdef CONFIG_BOOKMARKS
typedef struct {
char *Name;
EPoint BM;
} EBookmark;
#endif
typedef struct {
int line;
unsigned char level;
unsigned char open;
unsigned short flags;
} EFold;
class EEditPort: public EViewPort {
public:
EBuffer *Buffer;
EPoint TP, OldTP;
EPoint CP;
int Rows, Cols;
EEditPort(EBuffer *B, EView *V);
virtual ~EEditPort();
virtual void HandleEvent(TEvent &Event);
virtual void HandleMouse(TEvent &Event);
virtual void UpdateView();
virtual void RepaintView();
virtual void UpdateStatus();
virtual void RepaintStatus();
virtual void Resize(int Width, int Height);
int SetTop(int Col, int Row);
virtual void GetPos();
virtual void StorePos();
void DrawLine(int L, TDrawBuffer B);
void ScrollY(int Delta);
void RedrawAll();
};
class EBuffer: public EModel {
public:
//char *Name;
char *FileName;
int Modified;
EPoint TP;
EPoint CP;
EPoint BB;
EPoint BE;
EPoint PrevPos;
EPoint SavedPos;
EBufferFlags Flags;
EMode *Mode;
int BlockMode;
int ExtendGrab;
int AutoExtend;
int Loaded;
#ifdef CONFIG_UNDOREDO
UndoStack US;
#endif
struct stat FileStatus;
int FileOk;
int Loading;
int RAllocated; // text line allocation
int RGap;
int RCount;
PELine *LL;
int VAllocated; // visible lines
int VGap;
int VCount;
int *VV;
#ifdef CONFIG_FOLDS
int FCount;
EFold *FF;
#endif
EPoint Match;
int MatchLen;
int MatchCount;
RxMatchRes MatchRes;
#ifdef CONFIG_BOOKMARKS
int BMCount;
EBookmark *BMarks;
#endif
#ifdef CONFIG_OBJ_ROUTINE
RoutineList rlst;
RoutineView *Routines;
#endif
int MinRedraw, MaxRedraw;
int RedrawToEos;
#ifdef CONFIG_WORD_HILIT
char **WordList;
int WordCount;
#endif
#ifdef CONFIG_SYNTAX_HILIT
SyntaxProc HilitProc;
int StartHilit, EndHilit;
#endif
// constructors
EBuffer(int createFlags, EModel **ARoot, const char *AName);
~EBuffer();
virtual void DeleteRelated();
virtual EViewPort *CreateViewPort(EView *V);
EEditPort *GetViewVPort(EView *V);
EEditPort *GetVPort();
virtual int CanQuit();
virtual int ConfQuit(GxView *V, int multiFile = 0);
virtual int GetContext();
virtual EEventMap *GetEventMap();
virtual int BeginMacro();
virtual int ExecCommand(int Command, ExState &State);
virtual void HandleEvent(TEvent &Event);
virtual void GetName(char *AName, int MaxLen);
virtual void GetPath(char *APath, int MaxLen);
virtual void GetInfo(char *AInfo, int MaxLen);
virtual void GetTitle(char *ATitle, int MaxLen, char *ASTitle, int SMaxLen);
PELine RLine(int No) {
#ifdef DEBUG_EDITOR
int N = GapLine(No, RGap, RCount, RAllocated);
if (!((No < RCount) && (No >= 0) && (LL[N]))) {
printf("Get No = %d/%d Gap=%d RAlloc = %d, VCount = %d\n", No, RCount, RGap, RAllocated, VCount);
assert((No < RCount) && (No >= 0) && (LL[N]));
}
#endif
return LL[GapLine(No, RGap, RCount, RAllocated)];
}
void RLine(int No, PELine L) {
#ifdef DEBUG_EDITOR
if (!((No >= 0))) printf("Set No = %d\n", No);
assert((No >= 0));
#endif
LL[GapLine(No, RGap, RCount, RAllocated)] = L;
}
int Vis(int No) {
#ifdef DEBUG_EDITOR
if (No < 0 || No >= VCount) {
printf("Vis get no %d of %d\n", No, VCount);
assert (No >= 0 && No < VCount);
}
#endif
return VV[GapLine(No, VGap, VCount, VAllocated)];
}
void Vis(int No, int V) {
#ifdef DEBUG_EDITOR
if (No < 0 || No >= VCount) {
printf("Vis set no %d of %d to %d\n", No, VCount, V);
assert (No >= 0 && No < VCount);
}
#endif
VV[GapLine(No, VGap, VCount, VAllocated)] = V;
}
PELine VLine(int No) {
#ifdef DEBUG_EDITOR
if (!((No < VCount) && (No >= 0))) {
printf("VGet No = %d\n", No);
assert((No < VCount) && (No >= 0));
}
if (Vis(No) < 0)
assert(1 == 0);
#endif
return RLine(No + Vis(No));
}
void VLine(int No, PELine L) {
#ifdef DEBUG_EDITOR
if (!((No >= 0))) {
printf("VSet No = %d\n", No);
assert((No >= 0));
}
if (VV[No] < 0)
assert(1 == 0);
#endif
RLine(No + Vis(No), L);
}
int VToR(int No) {
#ifdef DEBUG_EDITOR
if (!(No < VCount)) {
printf("Get No = %d\n", No);
assert((No < VCount));
}
#endif
return No + Vis(No);
}
int RToV(int No);
int RToVN(int No);
// allocation
int Allocate(int ACount);
int MoveRGap(int RPos);
int AllocVis(int ACount);
int MoveVGap(int VPos);
int Modify();
int Clear();
#ifdef CONFIG_UNDOREDO
int FreeUndo();
#endif
// internal primitives
int ValidPos(EPoint W);
int RValidPos(EPoint W);
int LoadRegion(EPoint *A, int FH, int StripChar, int LineChar);
int SaveRegion(EPoint *A, EPoint *Z, int FH, int AddCR, int AddLF, int Mode);
int AssertLine(int Line);
int InsertLine(EPoint Pos, int ACount, char *AChars);
int UpdateMarker(int Type, int Line, int Col, int Lines, int Cols);
int UpdateMark(EPoint &M, int Type, int Line, int Col, int Lines, int Cols);
void UpdateVis(EPoint &M, int Row, int Delta);
void UpdateVisible(int Row, int Delta);
int LoadFrom(char *AFileName);
int SaveTo(char *AFileName);
int IsBlockStart();
int IsBlockEnd();
int BlockType(int Mode);
int BeginExtend();
int EndExtend();
int CheckBlock();
int BlockRedraw();
int SetBB(EPoint M);
int SetBE(EPoint M);
int Load();
int Save();
int Reload();
int FilePrint();
int SetFileName(const char *AFileName, const char *AMode);
int SetPos(int Col, int Row, int tabMode = tmNone);
int SetPosR(int Col, int Row, int tabMode = tmNone);
int CenterPos(int Col, int Row, int tabMode = tmNone);
int CenterPosR(int Col, int Row, int tabMode = tmNone);
int SetNearPos(int Col, int Row, int tabMode = tmNone);
int SetNearPosR(int Col, int Row, int tabMode = tmNone);
int CenterNearPos(int Col, int Row, int tabMode = tmNone);
int CenterNearPosR(int Col, int Row, int tabMode = tmNone);
int LineLen(int Row);
int LineChars(int Row);
/////////////////////////////////////////////////////////////////////////////
// Undo/Redo Routines
/////////////////////////////////////////////////////////////////////////////
int NextCommand();
#ifdef CONFIG_UNDOREDO
int PushUData(void *data, int len);
int PushULong(unsigned long l);
int PushUChar(unsigned char ch);
int PopUData(void *data, int len);
int GetUData(int No, int pos, void **data, int len);
int Undo(int undo);
int Undo();
int Redo();
int BeginUndo();
int EndUndo();
int PushBlockData();
#endif
/////////////////////////////////////////////////////////////////////////////
// Primitive Editing
/////////////////////////////////////////////////////////////////////////////
//int ExpReg(int Row, int Ofs, int ACount, int &B, int &E);
int ScreenPos(ELine *L, int Offset);
int CharOffset(ELine *L, int ScreenPos);
int DelLine(int Row, int DoMark = 1);
int UnTabPoint(int Row, int Col);
int InsLine(int Row, int DoAppend, int DoMark = 1);
int DelChars(int Row, int Ofs, int ACount);
int InsChars(int Row, int Ofs, int ACount, char *Buffer);
int ChgChars(int Row, int Ofs, int ACount, char *Buffer);
int DelText(int Row, int Col, int ACount, int DoMark = 1);
int InsText(int Row, int Col, int ACount, char *Buffer, int DoMark = 1);
int InsLineText(int Row, int Col, int ACount, int Pos, PELine Line);
int SplitLine(int Row, int Col);
int JoinLine(int Row, int Col);
int CanUnfold(int Row);
int PadLine(int Row, int Length);
int ShowRow(int Row);
int HideRow(int Row);
int ExposeRow(int Row); // make row visible (open all folds containing)
/////////////////////////////////////////////////////////////////////////////
// Redraw/Windowing Routines
/////////////////////////////////////////////////////////////////////////////
void Draw(int Line0, int LineE);
void DrawLine(TDrawBuffer B, int L, int C, int W, int &HilitX);
void Hilit(int FromRow);
void Rehilit(int ToRow);
void Redraw();
void FullRedraw();
int GetHilitWord(int len, char *str, ChColor &clr, int IgnCase = 0);
/////////////////////////////////////////////////////////////////////////////
// Utility Routines
/////////////////////////////////////////////////////////////////////////////
int LineIndented(int Row);
int IndentLine(int Row, int Indent);
#ifdef CONFIG_SYNTAX_HILIT
int GetMap(int Row, int *StateLen, hsState **StateMap);
#endif
int FindStr(char *Data, int Len, int Options);
int FindRx(RxNode *Rx, int Options);
int Find(SearchReplaceOptions &opt);
int IsLineBlank(int Row);
int TrimLine(int Row);
#ifdef CONFIG_OBJ_ROUTINE
int ScanForRoutines();
#endif
/////////////////////////////////////////////////////////////////////////////
// Bookmark Routines
/////////////////////////////////////////////////////////////////////////////
#ifdef CONFIG_BOOKMARKS
int PlaceBookmark(char *Name, EPoint P);
int RemoveBookmark(char *Name);
int GetBookmark(char *Name, EPoint &P);
int GotoBookmark(char *Name);
#endif
/////////////////////////////////////////////////////////////////////////////
// Editing Routines
/////////////////////////////////////////////////////////////////////////////
int MoveLeft();
int MoveRight();
int MoveUp();
int MoveDown();
int MovePrev();
int MoveNext();
int MoveWordLeftX(int start);
int MoveWordRightX(int start);
int MoveWordLeft();
int MoveWordRight();
int MoveWordPrev();
int MoveWordNext();
int MoveWordEndLeft();
int MoveWordEndRight();
int MoveWordEndPrev();
int MoveWordEndNext();
int MoveWordOrCapLeft();
int MoveWordOrCapRight();
int MoveWordOrCapPrev();
int MoveWordOrCapNext();
int MoveWordOrCapEndLeft();
int MoveWordOrCapEndRight();
int MoveWordOrCapEndPrev();
int MoveWordOrCapEndNext();
// int MoveWordStart();
// int MoveWordEnd();
int MoveLineStart();
int MoveLineEnd();
int MovePageUp();
int MovePageDown();
int MovePageLeft();
int MovePageRight();
int MovePageStart();
int MovePageEnd();
int MoveFileStart();
int MoveFileEnd();
int MoveBlockStart();
int MoveBlockEnd();
int ScrollLeft(int Cols);
int ScrollRight(int Cols);
int ScrollDown(int Lines);
int ScrollUp(int Lines);
int MoveToLine();
int MoveToColumn();
int MoveFirstNonWhite();
int MoveLastNonWhite();
int MovePrevEqualIndent();
int MoveNextEqualIndent();
int MovePrevTab();
int MoveNextTab();
int MoveLineTop();
int MoveLineCenter();
int MoveLineBottom();
int MovePrevPos();
int MoveSavedPosCol();
int MoveSavedPosRow();
int MoveSavedPos();
int SavePos();
int MoveTabStart();
int MoveTabEnd();
int MoveFoldTop();
int MoveFoldPrev();
int MoveFoldNext();
int MoveBeginOrNonWhite();
int MoveBeginLinePageFile();
int MoveEndLinePageFile();
int KillLine();
int KillChar();
int KillCharPrev();
int KillWord();
int KillWordPrev();
int KillWordOrCap();
int KillWordOrCapPrev();
int KillToLineStart();
int KillToLineEnd();
int KillBlock();
int BackSpace();
int Delete();
int CompleteWord();
int KillBlockOrChar();
int KillBlockOrCharPrev();
#define ccUp 0
#define ccDown 1
#define ccToggle 2
int CharTrans(TransTable tab);
int CharCaseUp();
int CharCaseDown();
int CharCaseToggle();
int LineTrans(TransTable tab);
int LineCaseUp();
int LineCaseDown();
int LineCaseToggle();
int BlockTrans(TransTable tab);
int BlockCaseUp();
int BlockCaseDown();
int BlockCaseToggle();
int CharTrans(ExState &State);
int LineTrans(ExState &State);
int BlockTrans(ExState &State);
int GetTrans(ExState &State, TransTable tab);
int LineInsert();
int LineAdd();
int LineSplit();
int LineJoin();
int LineNew();
int LineIndent();
int LineTrim();
int LineCenter();
int FileTrim();
int BlockTrim();
#ifdef CONFIG_UNDOREDO
int CanUndo();
int CanRedo();
#endif
int LineLen();
int LineCount();
int CLine();
int CColumn();
int InsertChar(char aCh);
int TypeChar(char aCh);
int InsertString(char *aStr, int aCount);
int InsertSpacesToTab(int TSize);
int InsertTab();
int InsertSpace();
int SelfInsert();
#ifdef CONFIG_WORDWRAP
int DoWrap(int WrapAll);
int WrapPara();
#endif
int InsPrevLineChar();
int InsPrevLineToEol();
int LineDuplicate();
int GetMatchBrace(EPoint &M, int MinLine, int MaxLine, int show);
int MatchBracket();
int HilitMatchBracket();
int BlockBegin();
int BlockEnd();
int BlockUnmark();
int BlockCut(int Append);
int BlockCopy(int Append);
int BlockPaste();
int BlockKill();
int BlockIndent();
int BlockUnindent();
int BlockClear();
int BlockMarkStream();
int BlockMarkLine();
int BlockMarkColumn();
int BlockReadFrom(char *aFileName, int blockMode);
int BlockWriteTo(char *aFileName, int Append = 0);
int BlockExtendBegin();
int BlockExtendEnd();
int BlockReIndent();
int BlockIsMarked();
int BlockPasteStream();
int BlockPasteLine();
int BlockPasteColumn();
int BlockSelectWord();
int BlockSelectLine();
int BlockSelectPara();
int BlockPrint();
int BlockSort(int Reverse);
int ClipClear();
int BlockUnTab();
int BlockEnTab();
int ToggleAutoIndent();
int ToggleInsert();
int ToggleExpandTabs();
int ToggleShowTabs();
int ToggleUndo();
int ToggleReadOnly();
int ToggleKeepBackups();
int ToggleMatchCase();
int ToggleBackSpKillTab();
int ToggleDeleteKillTab();
int ToggleSpaceTabs();
int ToggleIndentWithTabs();
int ToggleBackSpUnindents();
int ToggleWordWrap();
int ToggleTrim();
int ToggleShowMarkers();
int SetLeftMargin();
int SetRightMargin();
int ShowPosition();
int Search(ExState &State, char *aString, int Options, int CanResume = 0);
int SearchAgain(ExState &State, unsigned int Options);
int SearchReplace(ExState &State, char *aString, char *aReplaceString, int Options);
int Search(ExState &State);
int SearchB(ExState &State);
int SearchRx(ExState &State);
int SearchAgain(ExState &State);
int SearchAgainB(ExState &State);
int SearchReplace(ExState &State);
int SearchReplaceB(ExState &State);
int SearchReplaceRx(ExState &State);
#ifdef CONFIG_WORD_HILIT
int HilitAddWord(const char *Word);
int HilitFindWord(const char *Word);
int HilitRemoveWord(const char *Word);
int HilitWord();
#endif
int SearchWord(int Flags);
#ifdef CONFIG_FOLDS
int FindFold(int Line);
int FindNearFold(int Line);
int FoldCreate(int Line);
int FoldCreateByRegexp(char *Regexp);
int FoldDestroy(int Line);
int FoldDestroyAll();
int FoldPromote(int Line);
int FoldDemote(int Line);
int FoldOpen(int Line);
int FoldOpenAll();
int FoldOpenNested();
int FoldClose(int Line);
int FoldCloseAll();
int FoldToggleOpenClose();
#endif
int ChangeMode(char *Mode);
int ChangeKeys(char *Mode);
int ChangeFlags(char *Mode);
int ScrollLeft(ExState &State);
int ScrollRight(ExState &State);
int ScrollDown(ExState &State);
int ScrollUp(ExState &State);
/* editor functions with user interface */
int MoveToColumn(ExState &State);
int MoveToLine(ExState &State);
int FoldCreateByRegexp(ExState &State);
#ifdef CONFIG_BOOKMARKS
int PlaceBookmark(ExState &State);
int RemoveBookmark(ExState &State);
int GotoBookmark(ExState &State);
#endif
int InsertString(ExState &State);
int SelfInsert(ExState &State);
int FileReload(ExState &State);
int FileSaveAs(char *FileName);
int FileSaveAs(ExState &State);
int FileWriteTo(char *FileName);
int FileWriteTo(ExState &State);
int BlockReadX(ExState &State, int BlockMode);
int BlockRead(ExState &State);
int BlockReadStream(ExState &State);
int BlockReadLine(ExState &State);
int BlockReadColumn(ExState &State);
int BlockWrite(ExState &State);
int Find(ExState &State);
int FindReplace(ExState &State);
int FindRepeat(ExState &State);
int FindRepeatOnce(ExState &State);
int FindRepeatReverse(ExState &State);
int InsertChar(ExState &State);
int TypeChar(ExState &State);
int ChangeMode(ExState &State);
int ChangeKeys(ExState &State);
int ChangeFlags(ExState &State);
int ChangeTabSize(ExState &State);
int ChangeRightMargin(ExState &State);
int ChangeLeftMargin(ExState &State);
#ifdef CONFIG_I_ASCII
int ASCIITable(ExState &State);
#endif
#ifdef CONFIG_TAGS
int FindTag(ExState &State);
int FindTagWord(ExState &State);
#endif
int SetCIndentStyle(ExState &State);
int FindFunction(int delta, int way);
int BlockMarkFunction();
int IndentFunction();
int MoveFunctionPrev();
int MoveFunctionNext();
int InsertDate(ExState& state);
int InsertUid();
int ShowHelpWord(ExState &State);
int PlaceGlobalBookmark(ExState &State);
int PushGlobalBookmark();
virtual int GetStrVar(int var, char *str, int buflen);
virtual int GetIntVar(int var, int *value);
int SetIndentWithTabs(ExState &State);
int FoldCreateAtRoutines();
};
extern EBuffer *SSBuffer;
extern SearchReplaceOptions LSearch;
extern int suspendLoads;
int DoneEditor();
EBuffer *FindFile(char *FileName);
#endif

1346
src/e_cmds.cpp Normal file

File diff suppressed because it is too large Load diff

18
src/e_djgpp2.cpp Normal file
View file

@ -0,0 +1,18 @@
/* e_djgpp2.cpp
*
* Copyright (c) 1997, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
* Contributed by Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>
*/
// djgpp2 specific routines
#include "fte.h"
int EView::SysShowHelp(ExState &State, const char *word) {
Msg(S_ERROR, "Not yet implemented");
return 0;
}

102
src/e_file.cpp Normal file
View file

@ -0,0 +1,102 @@
/* e_file.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
EBuffer *FindFile(char *FileName) {
EModel *M;
EBuffer *B;
M = ActiveModel;
while (M) {
if (M->GetContext() == CONTEXT_FILE) {
B = (EBuffer *)M;
if (filecmp(B->FileName, FileName) == 0) { return B; }
}
M = M->Next;
if (M == ActiveModel) break;
}
return 0;
}
#if 0
static void SwitchModel(EModel *AModel) {
if (AModel != AcgiveModel && MM && AModel) {
AModel->Prev->Next = AModel->Next;
AModel->Next->Prev = AModel->Prev;
AModel->Next = MM;
AModel->Prev = MM->Prev;
AModel->Prev->Next = AModel;
MM->Prev = AModel;
MM = AModel;
}
}
#endif
int FileLoad(int createFlags, const char *FileName, const char *Mode, EView *View) {
char Name[MAXPATH];
EBuffer *B;
assert(View != 0);
if (ExpandPath(FileName, Name) == -1) {
View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "Invalid path: %s.", FileName);
return 0;
}
B = FindFile(Name);
if (B) {
if (Mode != 0)
B->SetFileName(Name, Mode);
View->SwitchToModel(B);
return 1;
}
B = new EBuffer(createFlags, &ActiveModel, Name);
B->SetFileName(Name, Mode);
View->SwitchToModel(B);
return 1;
}
int MultiFileLoad(int createFlags, const char *FileName, const char *Mode, EView *View) {
char fX[MAXPATH];
int count = 0;
char FPath[MAXPATH];
char FName[MAXPATH];
FileFind *ff;
FileInfo *fi;
int rc;
assert(View != 0);
JustDirectory(FileName, fX);
if (fX[0] == 0) strcpy(fX, ".");
JustFileName(FileName, FName);
if (ExpandPath(fX, FPath) == -1) return 0;
Slash(FPath, 1);
ff = new FileFind(FPath, FName, ffHIDDEN | ffFULLPATH);
if (ff == 0)
return 0;
rc = ff->FindFirst(&fi);
while (rc == 0) {
count++;
if (FileLoad(createFlags, fi->Name(), Mode, View) == 0) {
delete fi;
delete ff;
return 0;
}
delete fi;
rc = ff->FindNext(&fi);
}
delete ff;
if (count == 0)
return FileLoad(createFlags, FileName, Mode, View);
return 1;
}

531
src/e_fold.cpp Normal file
View file

@ -0,0 +1,531 @@
/* e_fold.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int EBuffer::FindFold(int Line) { // optimize /*FOLD00*/
int f = FindNearFold(Line);
if (f != -1)
if (FF[f].line == Line)
return f;
return -1;
}
int EBuffer::FindNearFold(int Line) { /*FOLD00*/
int b = 0, B = FCount - 1, c;
while (b <= B) {
c = (b + B) / 2;
// printf("%d %d %d %d %d\n", b, B, c, Line, FF[c].line);
if (FF[c].line == Line)
return c;
if (c < FCount - 1) {
if (FF[c].line <= Line && FF[c + 1].line > Line)
return c;
} else {
if (FF[c].line <= Line)
return c;
}
if (FF[c].line < Line)
b = c + 1;
else
B = c - 1;
if (b > B)
break;
}
return -1;
}
int EBuffer::ShowRow(int Row) { /*FOLD00*/
int V = RToVN(Row), GapSize;
// printf("Showing row %d\n", Row);
assert(Row >= 0 && Row < RCount); // 0 cannot be hidden
if (V + Vis(V) == Row) return 1; // already visible
assert(VCount <= VAllocated);
if (VCount == VAllocated) {
if (AllocVis(VCount ? (VCount * 2) : 1) == 0) return 0;
memmove(VV + VAllocated - (VCount - VGap),
VV + VGap,
sizeof(int) * (VCount - VGap));
}
if (VGap != V + 1)
if (MoveVGap(V + 1) == 0) return 0;
VV[VGap] = Row - (VGap);
VGap++;
VCount++;
GapSize = VAllocated - VCount;
if (VGap != V + 2)
if (MoveVGap(V + 2) == 0) return 0;
for (int i = V + 2; i < VCount; i++)
VV[i + GapSize]--;
// Vis(i, Vis(i) - 1);
UpdateVisible(Row, 1);
// if (CP.Row > Row)
// if (SetPos(CP.Col, CP.Row + 1) == 0) return 0;
Draw(Row, -1);
return 1;
}
int EBuffer::HideRow(int Row) { /*FOLD00*/
int V = RToV(Row), GapSize;
assert(Row > 0 && Row < RCount); // 0 cannot be hidden
if (V == -1) return 1; // already hidden
UpdateVisible(Row, -1);
if (VGap != V)
if (MoveVGap(V) == 0) return 0;
GapSize = VAllocated - VCount;
VV[VGap + GapSize] = 0;
VCount--;
GapSize++;
if (VAllocated - VAllocated / 2 > VCount) {
memmove(VV + VGap + GapSize - VAllocated / 3,
VV + VGap + GapSize,
sizeof(int) * (VCount - VGap));
if (AllocVis(VAllocated - VAllocated / 3) == 0) return 0;
}
GapSize = VAllocated - VCount;
if (VGap != V)
if (MoveVGap(V) == 0) return 0;
for (int i = V; i < VCount; i++)
VV[i + GapSize]++;
// Vis(i, Vis(i) + 1);
// if (CP.Row > Row)
// if (SetPos(CP.Col, CP.Row - 1) == 0) return 0;
Draw(Row, -1);
return 1;
}
int EBuffer::ExposeRow(int Row) { /*FOLD00*/
int V;
int f, level, oldlevel = 100;
//DumpFold();
assert(Row >= 0 && Row < RCount); // range
V = RToV(Row);
if (V != -1) return 1; // already exposed
f = FindNearFold(Row);
assert(f != -1); // if not visible, must be folded
while (f >= 0) {
level = FF[f].level;
if (level < oldlevel) {
if (FF[f].open == 0) {
// printf("opening fold %d\n", f);
if (FoldOpen(FF[f].line) == 0) return 0;
}
oldlevel = level;
}
f--;
if (level == 0) break;
}
V = RToV(Row);
// if (V == -1) {
// printf("Expose Row = %d\n", Row);
// DumpFold();
// }
assert (V != -1);
return 1;
}
void EBuffer::UpdateVis(EPoint &M, int Row, int Delta) { /*FOLD00*/
if (Delta < 0) {
if (M.Row > Row)
if (M.Row < Row - Delta)
M.Row = Row;
else
M.Row += Delta;
} else {
if (M.Row >= Row)
M.Row += Delta;
}
}
void EBuffer::UpdateVisible(int Row, int Delta) { /*FOLD00*/
EView *w;
Row = RToV(Row);
UpdateVis(CP, Row, Delta);
w = View;
if (w) do {
UpdateVis(GetViewVPort(w)->TP, Row, Delta);
UpdateVis(GetViewVPort(w)->CP, Row, Delta);
w = w->Next;
} while (w != View);
}
int EBuffer::FoldCreate(int Line) { /*FOLD00*/
int n;
if (Modify() == 0) return 0;
if (FindFold(Line) != -1) return 1; // already exists
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo)) {
if (PushULong(Line) == 0) return 0;
if (PushUChar(ucFoldCreate) == 0) return 0;
}
#endif
n = FindNearFold(Line);
n++;
FF = (EFold *) realloc((void *)FF, sizeof(EFold) * ((1 + FCount) | 7));
assert(FF != 0);
memmove(FF + n + 1, FF + n, sizeof(EFold) * (FCount - n));
FCount++;
FF[n].line = Line;
FF[n].level = 0;
FF[n].open = 1;
FF[n].flags = 0;
Draw(Line, Line);
return 1;
}
int EBuffer::FoldCreateByRegexp(char *Regexp) { /*FOLD00*/
RxNode *R;
int err = 1;
if (Modify() == 0) return 0;
R = RxCompile(Regexp);
if (R != NULL) {
PELine X;
int first = -1;
int L;
for (L = 0; L < RCount; L++) {
RxMatchRes RM;
X = RLine(L);
if (RxExec(R, X->Chars, X->Count, X->Chars, &RM) == 1) {
if (first >= 0) {
int i;
for(i = L; i > 0; i--) {
PELine Y;
Y = RLine(i);
if ((Y->Count == 0) || strrchr(Y->Chars, '}')) {
if ((L - i) > 2) {
while ((i > 0) && (RLine(i - 1)->Count == 0))
i--;
if ((first >= 0) && i
&& (FoldCreate(i) == 0))
err = 0;
}
break;
}
}
} else
first = L;
if (FoldCreate(L) == 0) {
err = 0;
break;
}
}
}
RxFree(R);
}
return err;
}
int EBuffer::FoldCreateAtRoutines() { /*FOLD00*/
if (BFS(this, BFS_RoutineRegexp) == 0)
return 0;
return FoldCreateByRegexp(BFS(this, BFS_RoutineRegexp));
}
int EBuffer::FoldDestroy(int Line) { /*FOLD00*/
int f = FindFold(Line);
if (Modify() == 0) return 0;
if (f == -1) return 0;
if (FF[f].open == 0)
if (FoldOpen(Line) == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo)) {
if (PushULong(FF[f].level) == 0) return 0;
if (PushULong(Line) == 0) return 0;
if (PushUChar(ucFoldDestroy) == 0) return 0;
}
#endif
memmove(FF + f, FF + f + 1, sizeof(EFold) * (FCount - f - 1));
FCount--;
FF = (EFold *) realloc((void *)FF, sizeof(EFold) * (FCount | 7));
Draw(Line, Line);
return 1;
}
int EBuffer::FoldDestroyAll() { /*FOLD00*/
int l;
if (Modify() == 0) return 0;
for (l = 0; l < RCount; l++)
if (FindFold(l) != -1)
if (FoldDestroy(l) == 0) return 0;
return 1;
}
int EBuffer::FoldPromote(int Line) { /*FOLD00*/
int f = FindFold(Line);
if (Modify() == 0) return 0;
if (f == -1) return 0;
if (FF[f].open == 0) return 0;
if (FF[f].level == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo)) {
if (PushULong(Line) == 0) return 0;
if (PushUChar(ucFoldPromote) == 0) return 0;
}
#endif
if ((FF[f].line > 0) && (ExposeRow(FF[f].line - 1) == 0))
return 0;
FF[f].level--;
Draw(Line, Line);
return 1;
}
int EBuffer::FoldDemote(int Line) { /*FOLD00*/
int f = FindFold(Line);
if (Modify() == 0) return 0;
if (f == -1) return 0;
if (FF[f].open == 0) return 0;
if (FF[f].level == 99) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo)) {
if (PushULong(Line) == 0) return 0;
if (PushUChar(ucFoldDemote) == 0) return 0;
}
#endif
if ((FF[f].line > 0) && (ExposeRow(FF[f].line - 1) == 0))
return 0;
FF[f].level++;
Draw(Line, Line);
return 1;
}
int EBuffer::FoldOpen(int Line) { /*FOLD00*/
int f = FindFold(Line);
int l;
int level, toplevel;
int top;
if (f == -1) return 0;
if (FF[f].open == 1) return 1; // already open
if (Modify() == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo)) {
if (PushULong(Line) == 0) return 0;
if (PushUChar(ucFoldOpen) == 0) return 0;
}
#endif
FF[f].open = 1;
top = FF[f].line;
toplevel = FF[f].level;
// printf("Fold starts with %d\n", FF[f].line);
if (ShowRow(FF[f].line) == 0) return 0;
while (f < FCount) {
level = FF[f].level;
if (FF[f].open == 1) {
// fold is open
if (f == FCount - 1) {
for (l = FF[f].line; l < RCount; l++)
if (l != top)
if (ShowRow(l) == 0) return 0;
} else {
for (l = FF[f].line; l < FF[f + 1].line; l++)
if (l != top)
if (ShowRow(l) == 0) return 0;
}
f++;
} else { // fold is closed
// show head line
if (ShowRow(FF[f].line) == 0) return 0;
// skip closed folds
while ((f < FCount) && (level < FF[f + 1].level))
f++;
f++;
}
if (f < FCount && FF[f].level <= toplevel)
break;
}
return 1;
}
int EBuffer::FoldOpenAll() { /*FOLD00*/
int l;
for (l = 0; l < RCount; l++)
if (FindFold(l) != -1)
if (FoldOpen(l) == 0) return 0;
return 1;
}
int EBuffer::FoldOpenNested() { /*FOLD00*/
int Line = VToR(CP.Row);
int f = FindFold(Line);
int l;
int level;
if (f == -1) return 0;
level = FF[f].level;
while (f + 1 < FCount && FF[f + 1].level > level) f++;
if (f + 1 == FCount) {
if (FoldOpen(Line) == 0) return 0;
} else {
for (l = Line; l < RCount && l < FF[f + 1].line; l++) {
if (FindFold(l) != -1)
if (FoldOpen(l) == 0) return 0;
}
}
return 0;
}
int EBuffer::FoldClose(int Line) { /*FOLD00*/
int f = FindNearFold(Line);
int l, top;
int level;
if (f == -1) return 0;
if (FF[f].open == 0) return 1; // already closed
if (Modify() == 0) return 0;
if (SetPosR(CP.Col, FF[f].line, tmLeft) == 0) return 0;
#ifdef CONFIG_UNDOREDO
if (BFI(this, BFI_Undo)) {
if (PushULong(Line) == 0) return 0;
if (PushUChar(ucFoldClose) == 0) return 0;
}
#endif
FF[f].open = 0;
top = FF[f].line;
level = FF[f].level;
while ((f < FCount - 1) && (FF[f + 1].level > level)) f++;
/* performance tweak: do it in reverse (we'll see if it helps) */
if (f == FCount - 1) {
for (l = RCount - 1; l > top; l--)
if (HideRow(l) == 0) return 0;
} else {
for (l = FF[f + 1].line - 1; l > top; l--)
if (HideRow(l) == 0) return 0;
}
/* yup, it does. try below for a (MUCH!) slower version */
/*if (f == FCount - 1) {
for (l = top + 1; l < RCount; l++)
if (HideRow(l) == 0) return 0;
} else {
for (l = top + 1; l < FF[f + 1].line; l++)
if (HideRow(l) == 0) return 0;
}*/
return 1;
}
int EBuffer::FoldCloseAll() { /*FOLD00*/
int l;
for (l = RCount - 1; l >= 0; l--)
if (FindFold(l) != -1)
if (FoldClose(l) == 0) return 0;
return 1;
}
int EBuffer::FoldToggleOpenClose() { /*FOLD00*/
int Line = VToR(CP.Row);
int f;
f = FindNearFold(Line);
if (f == -1)
return 0;
if (FF[f].open) {
if (FoldClose(Line) == 0) return 0;
} else {
if (FoldOpen(Line) == 0) return 0;
}
return 1;
}
int EBuffer::MoveFoldTop() { /*FOLD00*/
int f = FindNearFold(VToR(CP.Row));
if (f == 0 || f == -1) return 0;
if (FF[f].line == VToR(CP.Row))
return 1;
if (SetPosR(CP.Col, FF[f].line, tmLeft) == 0) return 0;
return 1;
}
int EBuffer::MoveFoldPrev() { /*FOLD00*/
int f = FindNearFold(VToR(CP.Row));
if (f == 0 || f == -1) return 0;
if (FF[f].line == VToR(CP.Row)) {
do {
f--;
if (f < 0) return 0;
if (RToV(FF[f].line) != -1)
break;
} while (1);
}
if (SetPosR(CP.Col, FF[f].line, tmLeft) == 0) return 0;
return 1;
}
int EBuffer::MoveFoldNext() { /*FOLD00*/
int f = FindNearFold(VToR(CP.Row));
if (f == FCount - 1 || f == -1) return 0;
do {
f++;
if (f == FCount) return 0;
if (RToV(FF[f].line) != -1)
break;
} while (1);
if (SetPosR(CP.Col, FF[f].line, tmLeft) == 0) return 0;
return 1;
}

233
src/e_line.cpp Normal file
View file

@ -0,0 +1,233 @@
/* e_line.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
ELine::ELine(int ACount, char *AChars) {
Chars = NULL;
Count = ACount;
Allocate(Count);
#ifdef CONFIG_SYNTAX_HILIT
StateE = 0;
#endif
if (AChars)
memcpy(Chars, AChars, Count);
else
memset(Chars, ' ', Count);
}
ELine::ELine(char *AChars, int ACount) {
Chars = AChars;
Count = ACount;
#ifdef CONFIG_SYNTAX_HILIT
StateE = 0;
#endif
}
ELine::~ELine() {
if (Chars)
free(Chars);
}
int ELine::Allocate(unsigned int Bytes) {
unsigned int Allocated;
Allocated = (Bytes | CHAR_TRESHOLD);
if (Chars)
Chars = (char *) realloc(Chars, Allocated);
else
Chars = (char *) malloc(Allocated);
if (Chars == NULL)
return 0;
return 1;
}
int EBuffer::ScreenPos(ELine *L, int Offset) {
int ExpandTabs = BFI(this, BFI_ExpandTabs);
int TabSize = BFI(this, BFI_TabSize);
if (!ExpandTabs) {
return Offset;
} else {
char *p = L->Chars;
int Len = L->Count;
int Pos = 0;
int Ofs = Offset;
if (Ofs > Len) {
while (Len > 0) {
if (*p++ != '\t')
Pos++;
else
Pos = NextTab(Pos, TabSize);
Len--;
}
Pos += Ofs - L->Count;
} else {
while (Ofs > 0) {
if (*p++ != '\t')
Pos++;
else
Pos = NextTab(Pos, TabSize);
Ofs--;
}
}
return Pos;
}
}
int EBuffer::CharOffset(ELine *L, int ScreenPos) {
int ExpandTabs = BFI(this, BFI_ExpandTabs);
int TabSize = BFI(this, BFI_TabSize);
if (!ExpandTabs) {
return ScreenPos;
} else {
int Pos = 0;
int Ofs = 0;
char *p = L->Chars;
int Len = L->Count;
while (Len > 0) {
if (*p++ != '\t')
Pos++;
else
Pos = NextTab(Pos, TabSize);
if (Pos > ScreenPos)
return Ofs;
Ofs++;
Len--;
}
return Ofs + ScreenPos - Pos;
}
}
int EBuffer::Allocate(int ACount) {
PELine *L;
L = (PELine *) realloc(LL, sizeof(PELine) * (ACount + 1));
if (L == 0 && ACount != 0)
return 0;
RAllocated = ACount;
LL = L;
return 1;
}
int EBuffer::MoveRGap(int RPos) {
int GapSize = RAllocated - RCount;
if (RGap == RPos) return 1;
if (RPos < 0 || RPos > RCount) return 0;
if (RGap < RPos) {
if (RPos - RGap == 1) {
LL[RGap] = LL[RGap + GapSize];
} else {
memmove(LL + RGap,
LL + RGap + GapSize,
sizeof(PELine) * (RPos - RGap));
}
} else {
if (RGap - RPos == 1) {
LL[RPos + GapSize] = LL[RPos];
} else {
memmove(LL + RPos + GapSize,
LL + RPos,
sizeof(PELine) * (RGap - RPos));
}
}
RGap = RPos;
return 1;
}
int EBuffer::AllocVis(int ACount) {
int *V;
V = (int *) realloc(VV, sizeof(int) * (ACount + 1));
if (V == 0 && ACount != 0) return 0;
VAllocated = ACount;
VV = V;
return 1;
}
int EBuffer::MoveVGap(int VPos) {
int GapSize = VAllocated - VCount;
if (VGap == VPos) return 1;
if (VPos < 0 || VPos > VCount) return 0;
if (VGap < VPos) {
if (VPos - VGap == 1) {
VV[VGap] = VV[VGap + GapSize];
} else {
memmove(VV + VGap,
VV + VGap + GapSize,
sizeof(VV[0]) * (VPos - VGap));
}
} else {
if (VGap - VPos == 1) {
VV[VPos + GapSize] = VV[VPos];
} else {
memmove(VV + VPos + GapSize,
VV + VPos,
sizeof(VV[0]) * (VGap - VPos));
}
}
VGap = VPos;
return 1;
}
int EBuffer::RToV(int No) {
int L = 0, R = VCount, M, V;
if (No > Vis(VCount - 1) + VCount - 1) // beyond end
return -1;
if (No < VCount) // no folds before (direct match)
if (Vis(No) == 0) return No;
while (L < R) {
M = (L + R) >> 1;
V = Vis(M) + M;
if (V == No)
return M;
else if (V > No)
R = M;
else
L = M + 1;
}
return -1;
}
int EBuffer::RToVN(int No) {
int L = 0, R = VCount, M, V;
if (No == RCount)
return VCount;
if (No > Vis(VCount - 1) + VCount - 1)
return VCount - 1;
if (No < VCount)
if (Vis(No) == 0) return No;
while (L < R) {
M = (L + R) >> 1;
V = Vis(M) + M;
if (V == No)
return M;
else if (V > No)
R = M;
else {
if (M == VCount - 1)
return M;
else if (Vis(M + 1) + M + 1 > No)
return M;
L = M + 1;
}
}
return R;
}

450
src/e_loadsave.cpp Normal file
View file

@ -0,0 +1,450 @@
/* e_loadsave.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int EBuffer::Load() {
return LoadFrom(FileName);
}
int EBuffer::Reload() {
int R = VToR(CP.Row), C = CP.Col;
if (LoadFrom(FileName) == 0)
return 0;
SetNearPosR(C, R);
return 1;
}
int EBuffer::Save() {
if (BFI(this, BFI_ReadOnly)) {
Msg(S_ERROR, "File is read-only.");
return 0;
}
if (BFI(this, BFI_TrimOnSave))
FileTrim();
return SaveTo(FileName);
}
char FileBuffer[RWBUFSIZE];
int EBuffer::LoadFrom(char *AFileName) {
int fd;
int len = 0, partLen;
unsigned long numChars = 0, Lines = 0;
char *p, *e, *m = NULL;
int lm = 0;
int lf;
int SaveUndo, SaveReadOnly;
int first = 1;
int strip = BFI(this, BFI_StripChar);
int lchar = BFI(this, BFI_LineChar);
int margin = BFI(this, BFI_LoadMargin);
FileOk = 0;
fd = open(AFileName, O_RDONLY | O_BINARY, 0);
if (fd == -1) {
if (errno != ENOENT) {
Msg(S_INFO, "Could not open file %s (errno=%d, %s) .",
AFileName, errno, strerror(errno));
} else {
Msg(S_INFO, "New file %s.", AFileName);
}
Loaded = 1;
return 0;
}
Loading = 1;
Clear();
BlockUnmark();
SaveUndo = BFI(this, BFI_Undo);
SaveReadOnly = BFI(this, BFI_ReadOnly);
BFI(this, BFI_Undo) = 0;
BFI(this, BFI_ReadOnly) = 0;
while ((len = read(fd, FileBuffer, sizeof(FileBuffer))) > 0) {
if (first) {
first = 0;
if (BFI(this, BFI_DetectLineSep)) {
int was_lf = 0, was_cr = 0;
for (int c = 0; c < len; c++) {
if (FileBuffer[c] == 10) {
was_lf++;
break;
} else if (FileBuffer[c] == 13) {
was_cr++;
if (was_cr == 2)
break;
}
}
/* !!! fails if first line > 32k
* ??? set first to 1 in that case ? */
if (was_cr || was_lf) {
BFI(this, BFI_StripChar) = -1;
BFI(this, BFI_LoadMargin) = -1;
BFI(this, BFI_AddLF) = 0;
BFI(this, BFI_AddCR) = 0;
if (was_lf) {
BFI(this, BFI_LineChar) = 10;
BFI(this, BFI_AddLF) = 1;
if (was_cr) {
BFI(this, BFI_StripChar) = 13;
BFI(this, BFI_AddCR) = 1;
}
} else if (was_cr) {
BFI(this, BFI_LineChar) = 13;
BFI(this, BFI_AddCR) = 1;
} else {
BFI(this, BFI_LineChar) = -1;
BFI(this, BFI_LoadMargin) = 64;
}
strip = BFI(this, BFI_StripChar);
lchar = BFI(this, BFI_LineChar);
margin = BFI(this, BFI_LoadMargin);
}
}
}
p = FileBuffer;
do {
if (lchar != -1) { // do we have a LINE delimiter
e = (char *)memchr((void *)p, lchar, FileBuffer - p + len);
if (e == NULL) {
e = FileBuffer + len;
lf = 0;
} else
lf = 1;
} else if (margin != -1) { // do we have a right margin for wrap
if (FileBuffer + len >= p + margin) {
e = p + margin;
lf = 1;
} else {
e = FileBuffer + len;
lf = 0;
}
} else {
e = FileBuffer + len;
lf = 0;
}
partLen = e - p; // # of chars in buffer for current line
m = (char *)realloc((void *)m, (lm + partLen) + CHAR_TRESHOLD);
if (m == NULL)
goto fail;
memcpy((void *)(m + lm), p, partLen);
lm += partLen;
numChars += partLen;
if (lf) {
// there is a new line, add it to buffer
if (lm == 0 && m == NULL && (m = (char *)malloc(CHAR_TRESHOLD)) == 0)
goto fail;
#if 0
{ // support for VIM tabsize commands
char *t = strstr(m,"vi:ts=");
int ts = 0;
if (t && isdigit(t[6]))
ts = atoi(&t[6]);
if (ts > 0 && ts <= 16)
BFI(this, BFI_TabSize) = ts;
}
#endif
// Grow the line table if required,
if (RCount == RAllocated)
if (Allocate(RCount ? (RCount * 2) : 1) == 0)
goto fail;
if ((LL[RCount++] = new ELine((char *)m, lm)) == 0)
goto fail;
RGap = RCount;
lm = 0;
m = NULL;
Lines++;
}
p = e;
if (lchar != -1) // skip LINE terminator/separator
p++;
} while (lf);
Msg(S_INFO, "Loading: %d lines, %d bytes.", Lines, numChars);
}
if ((RCount == 0) || (lm > 0) || !BFI(this, BFI_ForceNewLine)) {
if (lm == 0 && m == NULL && (m = (char *)malloc(CHAR_TRESHOLD)) == 0)
goto fail;
// Grow the line table if required,
if (RCount == RAllocated)
if (Allocate(RCount ? (RCount * 2) : 1) == 0)
goto fail;
if ((LL[RCount++] = new ELine(m, lm)) == 0)
goto fail;
m = NULL;
RGap = RCount;
}
// Next time when you introduce something like this
// check all code paths - as the whole memory management
// is broken - you have forget to clear 'm' two line above comment!
// kabi@users.sf.net
// this bug has caused serious text corruption which is the worst
// thing for text editor
if (m)
free(m);
m = NULL;
// initialize folding array.
// TODO: allocate only when folds are actually used.
// needs fixing a lot of code in other places.
VCount = RCount;
VGap = VCount;
if (AllocVis(VCount ? VCount : 1) == 0)
goto fail;
memset(VV, 0, VCount * sizeof(int));
if (strip != -1) { // strip CR character from EOL if specified
// TODO: this should be done during load above to improve performance
for (int l = 0; l < RCount; l++) {
if (LL[l]->Count > 0)
if (LL[l]->Chars[LL[l]->Count - 1] == strip)
LL[l]->Count--;
}
}
if ((BFI(this, BFI_SaveFolds) != 0)) {
int len_start = 0, len_end = 0;
int level = 0, open = 0;
int l;
int pos = -1;
char foldnum[3] = "00";
if (BFS(this, BFS_CommentStart) == 0) len_start = 0;
else len_start = strlen(BFS(this, BFS_CommentStart));
if (BFS(this, BFS_CommentEnd) == 0) len_end = 0;
else len_end = strlen(BFS(this, BFS_CommentEnd));
for (l = RCount - 1; l >= 0; l--) {
if (LL[l]->Count >= len_start + len_end + 6) {
open = -1;
level = -1;
if (BFI(this, BFI_SaveFolds) == 1) {
pos = 0;
} else if (BFI(this, BFI_SaveFolds) == 2) {
pos = LL[l]->Count - len_start - 6 - len_end;
}
if (((len_start == 0) ||
(memcmp(LL[l]->Chars + pos,
BFS(this, BFS_CommentStart), len_start) == 0)
) &&
((len_end == 0) ||
(memcmp(LL[l]->Chars + pos + len_start + 6,
BFS(this, BFS_CommentEnd), len_end) == 0))
)
{
if (memcmp(LL[l]->Chars + pos + len_start,
"FOLD",4) == 0)
{
open = 1;
} else if (memcmp(LL[l]->Chars + pos + len_start,
"fold", 4) == 0) {
open = 0;
} else
open = -1;
foldnum[0] = LL[l]->Chars[pos + len_start + 4];
foldnum[1] = LL[l]->Chars[pos + len_start + 4 + 1];
if (1 != sscanf(foldnum, "%2d", &level))
level = -1;
if (!isdigit(LL[l]->Chars[pos + len_start + 4]) ||
!isdigit(LL[l]->Chars[pos + len_start + 5]))
level = -1;
if (open != -1 && level != -1 && open < 100) {
int f;
if (FoldCreate(l) == 0) goto fail;
f = FindFold(l);
assert(f != -1);
FF[f].level = (char)(level & 0xFF);
if (open == 0)
if (FoldClose(l) == 0) goto fail;
memmove(LL[l]->Chars + pos,
LL[l]->Chars + pos + len_start + len_end + 6,
LL[l]->Count - pos - len_start - len_end - 6);
LL[l]->Count -= len_start + len_end + 6;
}
}
}
}
}
if (SetPosR(0, 0) == 0) return 0;
BFI(this, BFI_Undo) = SaveUndo;
BFI(this, BFI_ReadOnly) = SaveReadOnly;
if (stat(FileName, &FileStatus) == -1) {
memset(&FileStatus, 0, sizeof(FileStatus));
FileOk = 0;
goto fail;
} else {
if (!(FileStatus.st_mode & (S_IWRITE | S_IWGRP | S_IWOTH)))
BFI(this, BFI_ReadOnly) = 1;
else
BFI(this, BFI_ReadOnly) = 0;
}
close(fd);
FileOk = 1;
Modified = 0;
Loading = 0;
Loaded = 1;
Draw(0, -1);
Msg(S_INFO, "Loaded %s.", AFileName);
return 1;
fail:
BFI(this, BFI_Undo) = SaveUndo;
BFI(this, BFI_ReadOnly) = SaveReadOnly;
close(fd);
Loading = 0;
Draw(0, -1);
View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "Error loading %s.", AFileName);
return 0;
}
int EBuffer::SaveTo(char *AFileName) {
char ABackupName[MAXPATH];
struct stat StatBuf;
FILE *fp;
int l;
PELine L;
unsigned long ByteCount = 0, OldCount = 0;
int f;
char fold[64];
unsigned int foldlen = 0;
if (FileOk && (stat(FileName, &StatBuf) == 0)) {
if (FileStatus.st_size != StatBuf.st_size ||
FileStatus.st_mtime != StatBuf.st_mtime)
{
switch (View->MView->Win->Choice(GPC_ERROR, "File Changed on Disk",
2,
"&Save",
"&Cancel",
"%s", FileName))
{
case 0:
break;
case 1:
case -1:
default:
return 0;
}
}
}
if (RCount <= 0) return 0;
Msg(S_INFO, "Backing up %s...", AFileName);
if (MakeBackup(AFileName, (char *)ABackupName) == 0) {
View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "Could not create backup file.");
return 0;
}
Msg(S_INFO, "Writing %s...", AFileName);
fp = 0;
#ifdef OS2 // to preserve EA's ?
fp = fopen(AFileName, "r+b");
if (fp != 0)
#if defined(__IBMCPP__) || defined(__WATCOMC__)
if ( chsize (fileno(fp), 0) != 0)
#else
if (ftruncate(fileno(fp), 0) != 0)
#endif // __IBMCPP__ || __WATCOMC__
goto erroropen;
#endif // OS2
if (fp == 0)
fp = fopen(AFileName, "wb");
if (fp == 0) goto erroropen;
setvbuf(fp, FileBuffer, _IOFBF, sizeof(FileBuffer));
for (l = 0; l < RCount; l++) {
L = RLine(l);
f = FindFold(l);
// format fold
if ((f != -1) && (BFI(this, BFI_SaveFolds) != 0)) {
foldlen = 0;
if (BFS(this, BFS_CommentStart) != 0) {
strcpy(fold + foldlen, BFS(this, BFS_CommentStart));
foldlen += strlen(BFS(this, BFS_CommentStart));
}
foldlen += sprintf(fold + foldlen,
FF[f].open ? "FOLD%02d" : "fold%02d",
FF[f].level);
if (BFS(this, BFS_CommentEnd) != 0) {
strcpy(fold + foldlen, BFS(this, BFS_CommentEnd));
foldlen += strlen(BFS(this, BFS_CommentEnd));
}
ByteCount += foldlen;
}
// write bol fold
if (f != -1 && BFI(this, BFI_SaveFolds) == 1)
if (fwrite(fold, 1, foldlen, fp) != foldlen) goto fail;
// write data
if ((int)(fwrite(L->Chars, 1, L->Count, fp)) != L->Count)
goto fail;
ByteCount += L->Count;
// write eof fold
if (f != -1 && BFI(this, BFI_SaveFolds) == 2)
if (fwrite(fold, 1, foldlen, fp) != foldlen) goto fail;
// write eol
if ((l < RCount - 1) || BFI(this, BFI_ForceNewLine)) {
if (BFI(this, BFI_AddCR) == 1) {
if (fputc(13, fp) < 0) goto fail;
ByteCount++;
}
if (BFI(this, BFI_AddLF) == 1) {
if (fputc(10, fp) < 0) goto fail;
ByteCount++;
}
}
if (ByteCount > OldCount + 65536) {
Msg(S_INFO, "Saving: %d lines, %d bytes.", l, ByteCount);
OldCount = ByteCount;
}
}
if (fclose(fp) != 0) goto fail;
Modified = 0;
FileOk = 1;
if (stat(FileName, &FileStatus) == -1) {
memset(&FileStatus, 0, sizeof(FileStatus));
FileOk = 0;
goto fail;
}
Msg(S_INFO, "Wrote %s.", AFileName);
if (BFI(this, BFI_KeepBackups) == 0) {
unlink(ABackupName);
}
return 1;
fail:
fclose(fp);
unlink(AFileName);
if (rename(ABackupName, AFileName) == -1) {
View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "Error renaming backup file to original!");
} else {
View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "Error writing file, backup restored.");
}
return 0;
erroropen:
View->MView->Win->Choice(GPC_ERROR, "Error", 1, "O&K", "Error writing %s (errno=%d).", AFileName, errno);
return 0;
}

258
src/e_mark.cpp Normal file
View file

@ -0,0 +1,258 @@
#include "fte.h"
EMarkIndex markIndex;
EMark::EMark(char *aName, char *aFileName, EPoint aPoint, EBuffer *aBuffer) {
Name = new char[strlen(aName) + 1];
FileName = new char[strlen(aFileName) + 1];
Buffer = 0;
Point = aPoint;
assert(Name != 0);
assert(FileName != 0);
strcpy(Name, aName);
strcpy(FileName, aFileName);
if (aBuffer == 0)
aBuffer = FindFile(aFileName);
if (aBuffer && aBuffer->Loaded)
setBuffer(aBuffer);
else
aBuffer = 0;
}
EMark::~EMark() {
if (Buffer)
removeBuffer(Buffer);
delete Name;
delete FileName;
}
int EMark::setBuffer(EBuffer *aBuffer) {
assert(aBuffer != 0);
assert(filecmp(aBuffer->FileName, FileName) == 0);
if (Point.Row >= aBuffer->RCount)
Point.Row = aBuffer->RCount - 1;
if (Point.Row < 0)
Point.Row = 0;
if (aBuffer->PlaceBookmark(Name, Point) == 1) {
Buffer = aBuffer;
return 1;
}
return 0;
}
int EMark::removeBuffer(EBuffer *aBuffer) {
assert(aBuffer != 0);
if (Buffer == 0 || Buffer != aBuffer)
return 0;
assert(filecmp(aBuffer->FileName, FileName) == 0);
if (Buffer->GetBookmark(Name, Point) == 0)
return 0;
if (Buffer->RemoveBookmark(Name) == 0)
return 0;
Buffer = 0;
return 1;
}
EPoint &EMark::getPoint() {
if (Buffer) {
assert(Buffer->GetBookmark(Name, Point) != 0);
}
return Point;
}
EMarkIndex::EMarkIndex() {
markCount = 0;
marks = 0;
}
EMarkIndex::~EMarkIndex() {
if (markCount > 0 && marks) {
for (int n = 0; n < markCount; n++)
delete marks[n];
delete marks;
marks = 0;
}
}
EMark *EMarkIndex::insert(char *aName, char *aFileName, EPoint aPoint, EBuffer *aBuffer) {
int L = 0, R = markCount, M, cmp;
assert(aName != 0 && aName[0] != 0);
assert(aFileName != 0 && aFileName[0] != 0);
while (L < R) {
M = (L + R) / 2;
cmp = strcmp(aName, marks[M]->getName());
if (cmp == 0)
return 0;
else if (cmp > 0)
L = M + 1;
else
R = M;
}
EMark **newMarks = (EMark **)realloc(marks,
sizeof(marks[0]) * (markCount + 1));
if (newMarks == 0)
return 0;
marks = newMarks;
EMark *m = new EMark(aName, aFileName, aPoint, aBuffer);
if (m == 0)
return 0;
memmove(marks + L + 1, marks + L, sizeof(marks[0]) * (markCount - L));
markCount++;
marks[L] = m;
return m;
}
EMark *EMarkIndex::insert(char *aName, EBuffer *aBuffer, EPoint aPoint) {
assert(aName != 0 && aName[0] != 0);
assert(aBuffer != 0);
assert(aBuffer->FileName != 0);
return insert(aName, aBuffer->FileName, aPoint, aBuffer);
}
EMark *EMarkIndex::locate(char *aName) {
int L = 0, R = markCount, M, cmp;
assert(aName != 0 && aName[0] != 0);
while (L < R) {
M = (L + R) / 2;
cmp = strcmp(aName, marks[M]->getName());
if (cmp == 0)
return marks[M];
else if (cmp > 0)
L = M + 1;
else
R = M;
}
return 0;
}
int EMarkIndex::remove(char *aName) {
int L = 0, R = markCount, M, cmp;
assert(aName != 0 && aName[0] != 0);
while (L < R) {
M = (L + R) / 2;
cmp = strcmp(aName, marks[M]->getName());
if (cmp == 0) {
EMark *m = marks[M];
memmove(marks + M,
marks + M + 1,
sizeof(marks[0]) * (markCount - M - 1));
markCount--;
EMark **newMarks = (EMark **)realloc(marks,
sizeof(marks[0]) * (markCount));
if (newMarks != 0 || markCount == 0)
marks = newMarks;
delete m;
return 1;
} else if (cmp > 0)
L = M + 1;
else
R = M;
}
return 0;
}
int EMarkIndex::view(EView *aView, char *aName) {
EMark *m = locate(aName);
if (m) {
EBuffer *b = m->getBuffer();
if (b == 0) {
if (FileLoad(0, m->getFileName(), 0, aView) == 0)
return 0;
if (retrieveForBuffer((EBuffer *)ActiveModel) == 0)
return 0;
b = (EBuffer *)ActiveModel;
}
aView->SwitchToModel(b);
return b->GotoBookmark(m->getName());
}
return 0;
}
int EMarkIndex::retrieveForBuffer(EBuffer *aBuffer) {
for (int n = 0; n < markCount; n++)
if (marks[n]->getBuffer() == 0 &&
filecmp(aBuffer->FileName, marks[n]->getFileName()) == 0)
{
if (marks[n]->setBuffer(aBuffer) == 0)
return 0;
}
return 1;
}
int EMarkIndex::storeForBuffer(EBuffer *aBuffer) {
for (int n = 0; n < markCount; n++)
if (marks[n]->getBuffer() == aBuffer)
if (marks[n]->removeBuffer(aBuffer) == 0)
return 0;
return 1;
}
int EMarkIndex::saveToDesktop(FILE *fp) {
for (int n = 0; n < markCount; n++) {
EPoint p = marks[n]->getPoint();
// ??? file of buffer or of mark? (different if file renamed) ???
// perhaps marks should be duplicated?
fprintf(fp, "M|%d|%d|%s|%s\n",
p.Row, p.Col,
marks[n]->getName(),
marks[n]->getFileName());
}
return 1;
}
// needs performance fixes (perhaps a redesign ?)
EMark *EMarkIndex::pushMark(EBuffer *aBuffer, EPoint P) {
int stackTop = -1;
for (int n = 0; n < markCount; n++) {
char *name = marks[n]->getName();
if (name && name[0] == '#' && isdigit(name[1])) {
int no = atoi(name + 1);
if (no > stackTop)
stackTop = no;
}
}
char name[20];
sprintf(name, "#%d", stackTop + 1);
return insert(name, aBuffer, P);
}
int EMarkIndex::popMark(EView *aView) {
int stackTop = -1;
for (int n = 0; n < markCount; n++) {
char *name = marks[n]->getName();
if (name && name[0] == '#' && isdigit(name[1])) {
int no = atoi(name + 1);
if (no > stackTop)
stackTop = no;
}
}
if (stackTop == -1)
return 0;
char name[20];
sprintf(name, "#%d", stackTop);
if (view(aView, name) == 0)
return 0;
assert(remove(name) == 1);
return 1;
}

57
src/e_mark.h Normal file
View file

@ -0,0 +1,57 @@
#ifndef __EMARK_H
#define __EMARK_H
class EMark {
public:
EMark(char *aName, char *aFileName, EPoint aPoint, EBuffer *aBuffer = 0);
~EMark();
int setBuffer(EBuffer *aBuffer);
int removeBuffer(EBuffer *aBuffer);
char *getName() { return Name; }
char *getFileName() { return FileName; }
EPoint &getPoint();
EBuffer *getBuffer() { return Buffer; }
private:
/* bookmark */
char *Name;
EPoint Point;
char *FileName;
/* bookmark in file */
EBuffer *Buffer;
};
class EMarkIndex {
public:
EMarkIndex();
~EMarkIndex();
EMark *insert(char *aName, char *aFileName, EPoint aPoint, EBuffer *aBuffer = 0);
EMark *insert(char *aName, EBuffer *aBuffer, EPoint aPoint);
EMark *locate(char *aName);
int remove(char *aName);
int view(EView *aView, char *aName);
// int MarkPush(EBuffer *B, EPoint P);
// int MarkPop(EView *V);
// int MarkSwap(EView *V, EBuffer *B, EPoint P);
// int MarkNext(EView *V);
// int MarkPrev(EView *V);
EMark *pushMark(EBuffer *aBuffer, EPoint P);
int popMark(EView *aView);
int retrieveForBuffer(EBuffer *aBuffer);
int storeForBuffer(EBuffer *aBuffer);
int saveToDesktop(FILE *fp);
private:
int markCount;
EMark **marks;
};
extern EMarkIndex markIndex;
#endif

39
src/e_os2.cpp Normal file
View file

@ -0,0 +1,39 @@
/* e_os2.cpp
*
* Copyright (c) 1997, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
// Win32 (NT) specific routines
#include "fte.h"
int EView::SysShowHelp(ExState &State, const char *word) {
char file[MAXPATH] = "";
char cmd[1024];
if (State.GetStrParam(this, file, sizeof(file) - 1) == 0)
if (MView->Win->GetStr("Help file",
sizeof(file) - 1, file, HIST_DEFAULT) == 0)
return 0;
char wordAsk[64] = "";
if (word == 0) {
if (State.GetStrParam(this, wordAsk, sizeof(wordAsk) - 1) == 0)
if (MView->Win->GetStr("Keyword",
sizeof(wordAsk) - 1, wordAsk, HIST_DEFAULT) == 0)
return 0;
word = wordAsk;
}
sprintf(cmd, "%s %s %s", HelpCommand, file, word);
if (system(cmd) != 0) {
Msg(S_ERROR, "Failed to start view.exe!");
return 0;
}
return 1;
}

194
src/e_print.cpp Normal file
View file

@ -0,0 +1,194 @@
/* e_print.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int EBuffer::BlockPrint() {
static char cr = 13;
static char lf = 10;
EPoint B, E;
int L;
int A, Z;
PELine LL;
FILE *fp;
int bc = 0, lc = 0;
int error = 0;
AutoExtend = 0;
if (CheckBlock() == 0) return 0;
if (RCount == 0) return 0;
B = BB;
E = BE;
Msg(S_INFO, "Printing to %s...", PrintDevice);
#if !defined(__IBMCPP__) && !defined(__WATCOMC__)
if (PrintDevice[0] == '|')
fp = popen(PrintDevice + 1, "w");
else
#endif
fp = fopen(PrintDevice, "w");
if (fp == NULL) {
Msg(S_INFO, "Failed to write to %s", PrintDevice);
return 0;
}
for (L = B.Row; L <= E.Row; L++) {
A = -1;
Z = -1;
LL = RLine(L);
switch (BlockMode) {
case bmLine:
if (L < E.Row) {
A = 0;
Z = LL->Count;
}
break;
case bmColumn:
if (L < E.Row) {
A = CharOffset(LL, B.Col);
Z = CharOffset(LL, E.Col);
}
break;
case bmStream:
if (B.Row == E.Row) {
A = CharOffset(LL, B.Col);
Z = CharOffset(LL, E.Col);
} else if (L == B.Row) {
A = CharOffset(LL, B.Col);
Z = LL->Count;
} else if (L < E.Row) {
A = 0;
Z = LL->Count;
} else if (L == E.Row) {
A = 0;
Z = CharOffset(LL, E.Col);
}
break;
}
if (A != -1 && Z != -1) {
if (A < LL->Count) {
if (Z > LL->Count)
Z = LL->Count;
if (Z > A) {
if ((int)(fwrite(LL->Chars + A, 1, Z - A, fp)) != Z - A) {
error++;
break;
} else
bc += Z - A;
}
}
if (BFI(this, BFI_AddCR) == 1)
if (fwrite(&cr, 1, 1, fp) != 1) {
error++;
break;
} else
bc++;
if (BFI(this, BFI_AddLF) == 1)
if (fwrite(&lf, 1, 1, fp) != 1) {
error++;
break;
} else {
bc++;
lc++;
}
if ((lc % 200) == 0)
Msg(S_INFO, "Printing, %d lines, %d bytes.", lc, bc);
}
}
if (!error) {
fwrite("\f\n", 2, 1, fp);
#if !defined(__IBMCPP__) && !defined(__WATCOMC__)
if (PrintDevice[0] == '|')
pclose(fp);
else
#endif
fclose(fp);
Msg(S_INFO, "Printing %d lines, %d bytes.", lc, bc);
return 1;
}
#if !defined(__IBMCPP__) && !defined(__WATCOMC__)
if (PrintDevice[0] == '|')
pclose(fp);
else
#endif
fclose(fp);
Msg(S_INFO, "Failed to write to %s", PrintDevice);
return 0;
}
int EBuffer::FilePrint() {
static char cr = 13;
static char lf = 10;
int l;
FILE *fp;
unsigned long ByteCount = 0;
int BChars;
Msg(S_INFO, "Printing %s to %s...", FileName, PrintDevice);
#if !defined(__IBMCPP__) && !defined(__WATCOMC__)
if (PrintDevice[0] == '|')
fp = popen(PrintDevice + 1, "w");
else
#endif
fp = fopen(PrintDevice, "w");
if (fp == NULL) {
Msg(S_ERROR, "Error printing %s to %s.", FileName, PrintDevice);
return 0;
}
BChars = 0;
for (l = 0; l < RCount; l++) {
if ((int) sizeof(FileBuffer) - (BChars + 2) < RLine(l)->Count) {
if (BChars) {
ByteCount += BChars;
Msg(S_INFO, "Printing: %d lines, %d bytes.", l, ByteCount);
if ((int)(fwrite(FileBuffer, 1, BChars, fp)) != BChars) goto fail;
BChars = 0;
}
}
if (RLine(l)->Count > int(sizeof(FileBuffer)) - 2) {
assert(BChars == 0);
ByteCount += RLine(l)->Count;
Msg(S_INFO, "Printing: %d lines, %d bytes.", l, ByteCount);
if (int(fwrite(RLine(l)->Chars, 1, RLine(l)->Count, fp)) != RLine(l)->Count) goto fail;
} else {
memcpy(FileBuffer + BChars, RLine(l)->Chars, RLine(l)->Count);
BChars += RLine(l)->Count;
}
if ((l < RCount - 1) || BFI(this, BFI_ForceNewLine)) {
assert(int(sizeof(FileBuffer)) >= BChars + 2);
if (BFI(this, BFI_AddCR) == 1) FileBuffer[BChars++] = cr;
if (BFI(this, BFI_AddLF) == 1) FileBuffer[BChars++] = lf;
}
}
if (BChars) {
ByteCount += BChars;
Msg(S_INFO, "Printing: %d lines, %d bytes.", l, ByteCount);
if ((int)(fwrite(FileBuffer, 1, BChars, fp)) != BChars) goto fail;
}
BChars = 0;
#if !defined(__IBMCPP__) && !defined(__WATCOMC__)
if (PrintDevice[0] == '|')
pclose(fp);
else
#endif
fclose(fp);
Msg(S_INFO, "Printed %s.", FileName);
return 1;
fail:
if (fp != NULL) {
#if !defined(__IBMCPP__) && !defined(__WATCOMC__)
if (PrintDevice[0] == '|')
pclose(fp);
else
#endif
fclose(fp);
}
Msg(S_ERROR, "Error printing %s to %s.", FileName, PrintDevice);
return 0;
}

596
src/e_redraw.cpp Normal file
View file

@ -0,0 +1,596 @@
/* e_redraw.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int EBuffer::GetMap(int Row, int *StateLen, hsState **StateMap) {
hlState State = 0;
Rehilit(Row);
*StateLen = LineChars(Row);
if (Row > 0) State = RLine(Row - 1)->StateE;
if (*StateLen > 0) {
PELine L = RLine(Row);
int ECol;
*StateMap = (hsState *) malloc(*StateLen);
if (*StateMap == 0) return 0;
#ifdef CONFIG_SYNTAX_HILIT
if (BFI(this, BFI_HilitOn) == 1 && HilitProc != 0)
HilitProc(this, Row, 0, 0, *StateLen, L, State, *StateMap, &ECol);
else
#endif
Hilit_Plain(this, Row, 0, 0, *StateLen, L, State, *StateMap, &ECol);
// if (L->StateE != State) {
// L->StateE = State;
// }
} else {
*StateLen = 1;
*StateMap = (hsState *) malloc(1);
if (*StateMap == 0) return 0;
(*StateMap)[0] = (hsState) (State & 0xFF);
}
return 1;
}
void EBuffer::FullRedraw() { // redraw all views
EView *V = View;
EEditPort *W;
while (V) {
W = GetViewVPort(V);
Draw(W->TP.Row, W->TP.Row + W->Rows);
V = V->Next;
if (V == View)
break;
}
}
void EBuffer::Hilit(int FromRow) {
if (FromRow != -1) {
if (StartHilit == -1)
StartHilit = FromRow;
else if (FromRow < StartHilit)
StartHilit = FromRow;
}
}
void EBuffer::Rehilit(int ToRow) {
hlState State;
int HilitX;
PELine L;
int ECol;
if (StartHilit == -1) // all ok
return ;
if (BFI(this, BFI_MultiLineHilit) == 0) // everything handled in redisplay
return;
if (ToRow <= StartHilit) // will be handled in redisplay
return;
if (ToRow >= RCount)
ToRow = RCount;
HilitX = 1;
while ((StartHilit < RCount) && ((StartHilit < ToRow) || HilitX)) {
L = RLine(StartHilit);
HilitX = 0;
if (StartHilit > 0)
State = RLine(StartHilit - 1)->StateE;
else
State = 0;
if (BFI(this, BFI_HilitOn) == 1 && HilitProc != 0) {
HilitProc(this, StartHilit, 0, 0, 0, L, State, 0, &ECol);
} else {
Hilit_Plain(this, StartHilit, 0, 0, 0, L, State, 0, &ECol);
}
if (L->StateE != State) {
HilitX = 1;
L->StateE = State;
}
Draw(StartHilit, StartHilit); // ?
if (StartHilit > EndHilit)
EndHilit = StartHilit;
if (HilitX == 0) // jump over (can we always do this ?)
if (StartHilit < EndHilit) {
StartHilit = EndHilit;
}
StartHilit++;
}
}
void EBuffer::Draw(int Row0, int RowE) {
// printf("r0 = %d, re = %d\n", Row0, RowE);
// printf("m = %d, max = %d, rts = %d\n", MinRedraw, MaxRedraw, RedrawToEos);
if (Row0 == -1) Row0 = 0;
if ((Row0 < MinRedraw) || (MinRedraw == -1)) {
MinRedraw = Row0;
if (MaxRedraw == -1) MaxRedraw = MinRedraw;
}
if (RowE == -1) {
RedrawToEos = 1;
MaxRedraw = MinRedraw;
} else if (((RowE > MaxRedraw) || (MaxRedraw == -1)) && (RowE != -1))
MaxRedraw = RowE;
// printf("m = %d, max = %d, rts = %d\n", MinRedraw, MaxRedraw, RedrawToEos);
}
void EBuffer::DrawLine(TDrawBuffer B, int VRow, int C, int W, int &HilitX) {
hlState State;
int StartPos, EndPos;
HilitX = 0;
MoveChar(B, 0, W, ' ', hcPlain_Background, W);
// if ((VRow == VCount - 1) && !BFI(this, BFI_ForceNewLine)) {
// if (BFI(this, BFI_ShowMarkers))
// MoveChar(B, 0, W, EOF_MARKER, hcPlain_Markers, W);
// }
if (VRow < VCount) {
int Row = VToR(VRow);
PELine L = RLine(Row);
int ECol = 0;
if (Row > 0) State = RLine(Row - 1)->StateE;
else State = 0;
#ifdef CONFIG_SYNTAX_HILIT
if (BFI(this, BFI_HilitOn) == 1 && HilitProc != 0)
HilitProc(this, Row, B, C, W, L, State, 0, &ECol);
else
#endif
Hilit_Plain(this, Row, B, C, W, L, State, 0, &ECol);
if (L->StateE != State) {
HilitX = 1;
L->StateE = State;
}
if (BFI(this, BFI_ShowMarkers)) {
MoveChar(B, ECol - C, W, ConGetDrawChar((Row == RCount - 1) ? DCH_EOF : DCH_EOL), hcPlain_Markers, 1);
ECol += 1;
}
if (Row < RCount) {
int f;
int Folded = 0;
static char fold[20];
int l;
f = FindFold(Row);
if (f != -1) {
if (FF[f].open == 1) {
l = sprintf(fold, "[%d]", FF[f].level);
MoveStr(B, ECol - C + 1, W, fold, hcPlain_Folds, 10);
ECol += l;
} else {
if (VRow < VCount - 1) {
Folded = Vis(VRow + 1) - Vis(VRow) + 1;
} else if (VRow < VCount) {
Folded = RCount - (VRow + Vis(VRow));
}
l = sprintf(fold, "(%d:%d)", FF[f].level, Folded);
MoveStr(B, ECol - C + 1, W, fold, hcPlain_Folds, 10);
ECol += l;
MoveAttr(B, 0, W, hcPlain_Folds, W);
}
}
}
if (BB.Row != -1 && BE.Row != -1 && Row >= BB.Row && Row <= BE.Row) {
switch(BlockMode) {
case bmLine:
StartPos = 0;
if (Row == BE.Row) EndPos = 0;
else EndPos = W;
break;
case bmColumn:
StartPos = BB.Col - C;
if (Row == BE.Row) EndPos = BB.Col - C;
else EndPos = BE.Col - C;
break;
case bmStream:
if (Row == BB.Row && Row == BE.Row) {
StartPos = BB.Col - C;
EndPos = BE.Col - C;
} else if (Row == BB.Row) {
StartPos = BB.Col - C;
EndPos = W;
} else if (Row == BE.Row) {
StartPos = 0;
EndPos = BE.Col - C;
} else {
StartPos = 0;
EndPos = W;
}
break;
default:
StartPos = EndPos = 0;
break;
}
if (BFI(this, BFI_SeeThruSel))
MoveBgAttr(B, StartPos, W, hcPlain_Selected, EndPos - StartPos);
else
MoveAttr(B, StartPos, W, hcPlain_Selected, EndPos - StartPos);
}
if (Match.Row != -1 && Match.Col != -1) {
if (Row == Match.Row) {
if (BFI(this, BFI_SeeThruSel))
MoveBgAttr(B, Match.Col - C, W, hcPlain_Found, MatchLen);
else
MoveAttr(B, Match.Col - C, W, hcPlain_Found, MatchLen);
}
}
} else if (VRow == VCount) {
if (BFI(this, BFI_ShowMarkers))
MoveChar(B, 0, W, ConGetDrawChar(DCH_END), hcPlain_Markers, W);
}
}
void EBuffer::Redraw() {
int HilitX;
EView *V;
EEditPort *W;
int Row;
TDrawBuffer B;
char s[256];
ChColor SColor;
int RowA, RowZ;
{
int W1, H1;
if (!(View && View->MView))
return;
View->MView->ConQuerySize(&W1, &H1);
if (H1 < 1 || W1 < 1) return;
}
// printf("Redraw\n");
if (CP.Row >= VCount) CP.Row = VCount - 1;
if (CP.Row < 0) CP.Row = 0;
CheckBlock();
V = View; /* check some window data */
if (!V) {
MinRedraw = MaxRedraw = -1;
RedrawToEos = 0;
return;
}
if (View == 0 || View->MView == 0 || View->MView->Win == 0)
return ;
for ( ; V; V = V->NextView) {
// printf("Checking\x7\n");
if (V->Model != this)
assert(1 == 0);
W = GetViewVPort(V);
if (W->Rows < 1 || W->Cols < 1)
continue;
if (V == View) {
int scrollJumpX = Min(ScrollJumpX, W->Cols / 2);
int scrollJumpY = Min(ScrollJumpY, W->Rows / 2);
int scrollBorderX = Min(ScrollBorderX, W->Cols / 2);
int scrollBorderY = Min(ScrollBorderY, W->Rows / 2);
W->CP = CP;
TP = W->TP;
if (W->ReCenter) {
W->TP.Row = CP.Row - W->Rows / 2;
W->TP.Col = CP.Col - W->Cols + 8;
W->ReCenter = 0;
}
if (W->TP.Row + scrollBorderY > CP.Row) W->TP.Row = CP.Row - scrollJumpY + 1 - scrollBorderY;
if (W->TP.Row + W->Rows - scrollBorderY <= CP.Row) W->TP.Row = CP.Row - W->Rows + 1 + scrollJumpY - 1 + scrollBorderY;
if (!WeirdScroll)
if (W->TP.Row + W->Rows >= VCount) W->TP.Row = VCount - W->Rows;
if (W->TP.Row < 0) W->TP.Row = 0;
if (W->TP.Col + scrollBorderX > CP.Col) W->TP.Col = CP.Col - scrollJumpX - scrollBorderX;
if (W->TP.Col + W->Cols - scrollBorderX <= CP.Col) W->TP.Col = CP.Col - W->Cols + scrollJumpX + scrollBorderX;
if (W->TP.Col < 0) W->TP.Col = 0;
if (W->OldTP.Row != -1 && W->OldTP.Col != -1 && RedrawToEos == 0) {
if ((W->OldTP.Row != W->TP.Row) || (W->OldTP.Col != W->TP.Col)) {
int A, B;
int DeltaX, DeltaY;
int Rows = W->Rows;
int Delta1 = 0, Delta2 = 0;
DeltaY = W->TP.Row - W->OldTP.Row ;
DeltaX = W->TP.Col - W->OldTP.Col;
if ((DeltaX == 0) && (-Rows < DeltaY) && (DeltaY < Rows)) {
if (DeltaY < 0) {
W->ScrollY(DeltaY);
A = W->TP.Row;
B = W->TP.Row - DeltaY;
} else {
W->ScrollY(DeltaY);
A = W->TP.Row + Rows - DeltaY;
B = W->TP.Row + Rows;
}
} else {
A = W->TP.Row;
B = W->TP.Row + W->Rows;
}
if (A >= VCount) {
Delta1 = A - VCount + 1;
A = VCount - 1;
}
if (B >= VCount) {
Delta2 = B - VCount + 1;
B = VCount - 1;
}
if (A < 0) A = 0;
if (B < 0) B = 0;
Draw(VToR(A) + Delta1, VToR(B) + Delta2);
}
} else {
int A = W->TP.Row;
int B = A + W->Rows;
int Delta = 0;
if (B > VCount) {
Delta += B - VCount;
B = VCount;
}
int LastV = VToR(VCount - 1);
int B1 = (B == VCount) ? RCount : VToR(B);
if (B1 >= LastV) {
Delta += B1 - LastV;
B1 = LastV;
}
if (B1 < 0) B1 = 0;
Draw(VToR(A), B1 + Delta);
}
W->OldTP = W->TP;
TP = W->TP;
}
if (W->CP.Row >= VCount) W->CP.Row = VCount - 1;
if (W->CP.Row < 0) W->CP.Row = 0;
if (W->TP.Row > W->CP.Row) W->TP.Row = W->CP.Row;
if (W->TP.Row < 0) W->TP.Row = 0;
if (V->MView->IsActive()) // hack
SColor = hcStatus_Active;
else
SColor = hcStatus_Normal;
MoveChar(B, 0, W->Cols, ' ', SColor, W->Cols);
if (V->MView->Win->GetViewContext() == V->MView) {
V->MView->Win->SetSbVPos(W->TP.Row, W->Rows, VCount + (WeirdScroll ? W->Rows - 1 : 0));
V->MView->Win->SetSbHPos(W->TP.Col, W->Cols, 1024 + (WeirdScroll ? W->Cols - 1 : 0));
}
if (V->CurMsg == 0) {
{
int CurLine = W->CP.Row;
int ActLine = VToR(W->CP.Row);
int CurColumn = W->CP.Col;
int CurPos = CharOffset(RLine(ActLine), CurColumn);
int NumLines = RCount;
int NumChars = RLine(ActLine)->Count;
// int NumColumns = ScreenPos(Line(CurLine), NumChars);
char *fName = FileName;
unsigned char CurCh = 0xFF;
int lf = strlen(fName);
char CCharStr[20] = "";
if (lf > 34) fName += lf - 34;
if (CurPos < NumChars) {
CurCh = VLine(CurLine)->Chars[CurPos];
sprintf(CCharStr, "%3u,%02X", CurCh, CurCh);
} else {
if (CurPos > NumChars) strcpy(CCharStr, " ");
else if (CurLine < NumLines - 1) strcpy(CCharStr, " EOL");
else strcpy(CCharStr, " EOF");
}
sprintf(s, "%04d:%02d %c%c%c%c%c %.6s %c"
#ifdef DOS
" %lu "
#endif
,
// CurLine + 1,
ActLine + 1,
CurColumn + 1,
// CurPos + 1,
(BFI(this, BFI_Insert)) ? 'I' : ' ',
(BFI(this, BFI_AutoIndent)) ? 'A' : ' ',
// (BFI(this, BFI_ExpandTabs))?'T':' ',
(BFI(this, BFI_MatchCase)) ? 'C' : ' ',
AutoExtend ?
(
(BlockMode == bmStream) ? 's' :
(BlockMode == bmLine) ? 'l' : 'c'
) :
((BlockMode == bmStream) ? 'S' :
(BlockMode == bmLine) ? 'L': 'C'
),
#ifdef CONFIG_WORDWRAP
(BFI(this, BFI_WordWrap) == 3) ? 't' :
(BFI(this, BFI_WordWrap) == 2) ? 'W' :
(BFI(this, BFI_WordWrap) == 1) ? 'w' :
' ',
#endif
// (BFI(this, BFI_Undo))?'U':' ',
// (BFI(this, BFI_Trim))?'E':' ',
// (Flags.KeepBackups)?'B':' ',
Mode->fName,
(Modified != 0)?'*':(BFI(this, BFI_ReadOnly))?'%':' '
#ifdef DOS
,coreleft()
#endif
);
int l = strlen(s);
int fw = W->Cols - l;
int fl = strlen(FileName);
char num[10];
MoveStr(B, 0, W->Cols, s, SColor, W->Cols);
sprintf(num, " %s %d", CCharStr, ModelNo);
MoveStr(B, W->Cols - strlen(num), W->Cols, num, SColor, W->Cols);
fw -= strlen(num);
if (fl > fw) {
MoveStr(B, l, W->Cols, FileName + fl - fw, SColor, W->Cols);
} else {
MoveStr(B, l, W->Cols, FileName, SColor, W->Cols);
}
}
} else {
MoveStr(B, 0, W->Cols, V->CurMsg, SColor, W->Cols);
}
if (V->MView->Win->GetStatusContext() == V->MView) {
V->MView->ConPutBox(0, W->Rows, W->Cols, 1, B);
if (V->MView->IsActive()) {
V->MView->ConShowCursor();
V->MView->ConSetCursorPos(W->CP.Col - W->TP.Col, W->CP.Row - W->TP.Row);
if (BFI(this, BFI_Insert)) {
V->MView->ConSetCursorSize(CursorInsSize[0], CursorInsSize[1]);
} else {
V->MView->ConSetCursorSize(CursorOverSize[0], CursorOverSize[1]);
}
}
}
}
Rehilit(VToR(CP.Row));
if (BFI(this, BFI_AutoHilitParen) == 1) {
if (Match.Row == -1 && Match.Col == -1)
HilitMatchBracket();
}
// if ((Window == WW) && (MinRedraw == -1))
// MaxRedraw = MinRedraw = VToR(CP.Row);
//printf("\n\nMinRedraw = %d, MaxRedraw = %d", MinRedraw, MaxRedraw);
if (MinRedraw == -1)
return;
// printf("Will redraw: %d to %d, to eos = %d\n", MinRedraw, MaxRedraw, RedrawToEos);
if (MinRedraw >= VCount) MinRedraw = VCount - 1;
if (MinRedraw < 0) MinRedraw = 0;
// puts("xxx\x7");
// printf("%d\n", MinRedraw);
Row = RowA = RToVN(MinRedraw);
// puts("xxx\x7");
RowZ = MaxRedraw;
if (MaxRedraw != -1) {
int Delta = 0;
if (MaxRedraw >= RCount) {
Delta = MaxRedraw - RCount + 1;
MaxRedraw = RCount - 1;
}
if (MaxRedraw < 0) MaxRedraw = 0;
// printf("%d\n", MaxRedraw);
RowZ = RToVN(MaxRedraw) + Delta;
}
// puts("xxx\x7");
//printf("\nRowA = %d, RowZ = %d", RowA, RowZ);
V = View;
while (V) {
if (V->Model != this)
assert(1 == 0);
W = GetViewVPort(V);
for (int R = W->TP.Row; R < W->TP.Row + W->Rows; R++) {
Row = R;
if ((Row >= RowA) &&
(RedrawToEos || Row <= RowZ))
{
DrawLine(B, Row, W->TP.Col, W->Cols, HilitX);
W->DrawLine(Row, B);
if (HilitX && Row == RowZ)
RowZ++;
}
}
V = V->NextView;
}
MinRedraw = MaxRedraw = -1;
RedrawToEos = 0;
}
int EBuffer::GetHilitWord(int len, char *str, ChColor &clr, int IgnCase) {
char *p;
if (Mode == 0 || Mode->fColorize == 0)
return 0;
if (len >= CK_MAXLEN)
return 0;
#ifdef CONFIG_WORD_HILIT
{
char s[CK_MAXLEN + 1];
s[CK_MAXLEN] = 0;
memcpy(s, str, len);
s[len] = 0;
if (HilitFindWord(s)) {
clr = hcPlain_HilitWord;
return 1;
}
}
#endif
if (len < 1) return 0;
p = Mode->fColorize->Keywords.key[len];
if (IgnCase) {
while (p && *p) {
if (strnicmp(p, str, len) == 0) {
clr = p[len];
return 1;
}
p += len + 1;
}
} else {
while (p && *p) {
if (memcmp(p, str, len) == 0) {
clr = p[len];
return 1;
}
p += len + 1;
}
}
if (0 && len < 128) { // disabled
char s[128];
memcpy(s, str, len);
s[len] = 0;
if (TagDefined(s)) {
//clr = 0x0A;
clr = Mode->fColorize->Colors[CLR_HexNumber];
return 1;
}
}
return 0;
}
EEditPort *EBuffer::GetViewVPort(EView *V) {
return (EEditPort *)V->Port;
}
EEditPort *EBuffer::GetVPort() {
return (EEditPort *)View->Port;
}

1116
src/e_regex.cpp Normal file

File diff suppressed because it is too large Load diff

110
src/e_regex.h Normal file
View file

@ -0,0 +1,110 @@
/* e_regex.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __REGEX_H
#define __REGEX_H
/*
* Operator:
*
* ^ Match the beginning of line
* $ Match the end of line
* . Match any character
* [ ] Match characters in set
* [^ ] Match characters not in set
* ? Match previous pattern 0 or 1 times (greedy)
* | Match previous or next pattern
* @ Match previous pattern 0 or more times (non-greedy)
* # Match previous pattern 1 or more times (non-greedy)
* * Match previous pattern 0 or more times (greedy)
* + Match previous pattern 1 or more times (greedy)
* { } Group characters to form one pattern
* ( ) Group and remember
* \ Quote next character (only of not a-z)
* < Match beginning of a word
* > Match end of a word
* \x## Match character with ASCII code ## (hex)
* \N### Match ascii code ### (dec)
* \o### Match ascii code
* \a Match \a \r Match 0x13 (cr)
* \b Match \b \t Match 0x09 (tab)
* \f Match \f \v Match \v
* \n Match 0x10 (lf) \e Match escape (^E)
* \s Match whitespace (cr/lf/tab/space)
* \S Match nonwhitespace (!\S)
* \w Match word character
* \W Match non-word character
* \d Match digit character
* \D Match non-digit character
* \U Match uppercase
* \L Match lowercase
* \C Match case sensitively from here on
* \c Match case ingnore from here on
*/
#define RE_NOTHING 0 // nothing
#define RE_JUMP 1 // jump to
#define RE_BREAK 2 // break |
#define RE_ATBOL 3 // match at beginning of line
#define RE_ATEOL 4 // match at end of line
#define RE_ATBOW 5 // match beginning of word
#define RE_ATEOW 6 // match end of word
#define RE_CASE 7 // match case sensitively from here
#define RE_NCASE 8 // ignore case from here.
#define RE_END 31 // end of regexp
#define RE_ANY (32 + 1) // match any character
#define RE_INSET (32 + 2) // match if in set
#define RE_NOTINSET (32 + 3) // match if not in set
#define RE_CHAR (32 + 4) // match character string
#define RE_WSPACE (32 + 5) // match whitespace
#define RE_NWSPACE (32 + 6) // match whitespace
#define RE_UPPER (32 + 7) // match uppercase
#define RE_LOWER (32 + 8) // match lowercase
#define RE_DIGIT (32 + 9) // match digit
#define RE_NDIGIT (32 + 10) // match non-digit
#define RE_WORD (32 + 11) // match word
#define RE_NWORD (32 + 12) // match non-word
#define RE_GROUP 256 // grouping
#define RE_OPEN 512 // open (
#define RE_CLOSE 1024 // close )
#define RE_MEM 2048 // store () match
#define RE_BRANCH 4096
#define RE_GREEDY 2048 // do a greedy match (as much as possible)
#define NSEXPS 64 // for replace only 0-9
#define RX_CASE 1 // matchcase
typedef struct _RxNode RxNode;
struct _RxNode {
short fWhat;
short fLen;
RxNode *fPrev;
RxNode *fNext;
union {
char *fChar;
RxNode *fPtr;
};
};
typedef struct {
int Open[NSEXPS]; // -1 = not matched
int Close[NSEXPS];
} RxMatchRes;
RxNode *RxCompile(const char *Regexp);
int RxExec(RxNode *Regexp, const char *Data, int Len, const char *Start, RxMatchRes *Match, unsigned int RxOpt = RX_CASE);
int RxReplace(const char *rep, const char *Src, int len, RxMatchRes match, char **Dest, int *Dlen);
void RxFree(RxNode *Node);
#endif

1153
src/e_search.cpp Normal file

File diff suppressed because it is too large Load diff

589
src/e_tags.cpp Normal file
View file

@ -0,0 +1,589 @@
/* e_tags.cpp *
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#ifdef CONFIG_TAGS
struct TagData {
int Tag; // tag name pos
int FileName;
int TagBase; // name of tag file
int Line;
int StrFind; // string to find
};
struct TagStack {
char *FileName;
int Line, Col;
TagStack *Next;
int TagPos;
char *CurrentTag;
};
static char *TagMem = 0;
static int TagLen = 0;
static int ATagMem = 0;
static int CTags = 0; // number of tags
static int ATags = 0;
static TagData *TagD = 0;
static int *TagI = 0;
static int TagFileCount = 0;
static int *TagFiles = 0;
static int TagFilesLoaded = 0; // tag files are loaded at first lookup
static char *CurrentTag = 0;
static int TagPosition = -1;
static TagStack *TStack;
static int AllocMem(char *Mem, int Len) { /*FOLD00*/
int N = 1024;
char *NM;
int TagPos = TagLen;
while (N < TagLen + Len) N <<= 1;
if (ATagMem < N || TagMem == 0) {
NM = (char *)realloc((void *)TagMem, N);
if (NM == 0)
return -1;
TagMem = NM;
ATagMem = N;
}
memcpy(TagMem + TagLen, Mem, Len);
TagLen += Len;
return TagPos;
}
static int AddTag(int Tag, int FileName, int TagBase, int Line, int StrFind) { /*FOLD00*/
int N;
N = 1024;
while (N < CTags + 1) N <<= 1;
if (ATags < N || TagD == 0) {
TagData *ND;
ND = (TagData *)realloc((void *)TagD, N * sizeof(TagData));
if (ND == 0)
return -1;
TagD = ND;
ATags = N;
}
TagD[CTags].Tag = Tag;
TagD[CTags].Line = Line;
TagD[CTags].FileName = FileName;
TagD[CTags].TagBase = TagBase;
TagD[CTags].StrFind = StrFind;
CTags++;
return 0;
}
#if defined(__IBMCPP__)
int _LNK_CONV cmptags(const void *p1, const void *p2) {
#else
int cmptags(const void *p1, const void *p2) {
#endif
return strcmp(TagMem + TagD[*(int *)p1].Tag,
TagMem + TagD[*(int *)p2].Tag);
}
int SortTags() { /*FOLD00*/
int *NI;
int i;
if (CTags == 0)
return 0;
NI = (int *)realloc((void *)TagI, CTags * sizeof(int));
if (NI == 0)
return -1;
TagI = NI;
for (i = 0; i < CTags; i++)
TagI[i] = i;
qsort(TagI, CTags, sizeof(TagI[0]), cmptags);
return 0;
}
int TagsLoad(int id) { /*FOLD00*/
//char line[2048];
char *tags;
int fd;
struct stat sb;
long size;
free(TagI);
TagI = 0;
if ((fd = open(TagMem + TagFiles[id], O_BINARY | O_RDONLY)) == -1)
return -1;
if (fstat(fd, &sb) == -1)
return -1;
if ((tags = (char *)malloc(sb.st_size)) == 0) {
close(fd);
return -1;
}
size = read(fd, tags, sb.st_size);
close(fd);
if (size != sb.st_size)
return -1;
if (TagMem == 0) { // preallocate (useful when big file)
char *NM;
NM = (char *)realloc((void *)TagMem, TagLen + sb.st_size);
if (NM != 0) {
TagMem = NM;
ATagMem = TagLen + sb.st_size;
}
}
char *p = tags;
char *e = tags + sb.st_size;
char *LTag, *LFile, *LLine;
int TagL, FileL/*, LineL*/;
int MTag, MFile;
while (p < e) {
LTag = p;
while (p < e && *p != '\t') p++;
if (p < e && *p == '\t') *p++ = 0;
else break;
TagL = p - LTag;
LFile = p;
while (p < e && *p != '\t') p++;
if (p < e && *p == '\t') *p++ = 0;
else break;
FileL = p - LFile;
LLine = p;
while (p < e && *p != '\r' && *p != '\n') p++;
if (p < e && *p == '\r') *p++ = 0; // optional
if (p < e && *p == '\n') *p++ = 0;
else break;
//LineL = p - LLine;
MTag = AllocMem(LTag, TagL + FileL);
if (MTag == -1)
break;
MFile = MTag + TagL;
if (LLine[0] == '/') {
char *AStr = LLine;
char *p = AStr + 1;
char *d = AStr;
int MStr;
while (*p) {
if (*p == '\\') {
p++;
if (*p)
*d++ = *p++;
} else if (*p == '^' || *p == '$') p++;
else if (*p == '/')
break;
else
*d++ = *p++;
}
*d = 0;
if (stricmp(d - 10, "/*FOLD00*/") == 0)
d[-11] = 0; /* remove our internal folds */
MStr = AllocMem(AStr, strlen(AStr) + 1);
if (MStr == -1)
break;
if (AddTag(MTag, MFile, TagFiles[id], -1, MStr) == -1)
break;
} else {
if (AddTag(MTag, MFile, TagFiles[id], atoi(LLine), -1) == -1)
break;
}
}
free(tags);
return 0;
}
int TagsAdd(char *FileName) { /*FOLD00*/
int *NewT;
int NewF;
NewF = AllocMem(FileName, strlen(FileName) + 1);
if (NewF == -1)
return 0;
NewT = (int *)realloc((void *)TagFiles, (TagFileCount + 1) * sizeof(int));
if (NewT == 0)
return 0;
TagFiles = NewT;
TagFiles[TagFileCount++] = NewF;
return 1;
}
int TagsSave(FILE *fp) { /*FOLD00*/
for (int i = 0; i < TagFileCount; i++)
fprintf(fp, "T|%s\n", TagMem + TagFiles[i]);
return 1;
}
static void ClearTagStack() { /*FOLD00*/
TagStack *T;
if (CurrentTag) {
free(CurrentTag);
CurrentTag = 0;
}
TagPosition = -1;
while (TStack) {
T = TStack;
TStack = TStack->Next;
free(T->CurrentTag);
free(T->FileName);
free(T);
}
}
int TagLoad(char *FileName) { /*FOLD00*/
if (TagsAdd(FileName) == 0)
return 0;
ClearTagStack();
if (TagFilesLoaded) {
if (TagsLoad(TagFileCount - 1) == -1) {
return 0;
}
if (SortTags() == -1) {
TagClear();
return 0;
}
}
return 1;
}
static int LoadTagFiles() { /*FOLD00*/
int i;
assert(TagFilesLoaded == 0);
for (i = 0; i < TagFileCount; i++)
if (TagsLoad(i) == -1) {
TagClear();
return 0;
}
if (SortTags() == -1) {
TagClear();
return 0;
}
TagFilesLoaded = 1;
return 1;
}
void TagClear() { /*FOLD00*/
free(TagD);
free(TagI);
TagD = 0;
TagI = 0;
CTags = 0;
ATags = 0;
free(TagFiles);
TagFiles = 0;
TagFileCount = 0;
TagFilesLoaded = 0;
free(TagMem);
TagMem = 0;
TagLen = 0;
ATagMem = 0;
ClearTagStack();
}
static int GotoFilePos(EView *View, char *FileName, int Line, int Col) { /*FOLD00*/
if (FileLoad(0, FileName, 0, View) == 0)
return 0;
if (((EBuffer *)ActiveModel)->Loaded == 0)
((EBuffer *)ActiveModel)->Load();
((EBuffer *)ActiveModel)->CenterNearPosR(Col, Line);
return 1;
}
static int GotoTag(int M, EView *View) { /*FOLD00*/
char path[MAXPATH];
char Dir[MAXPATH];
TagData *TT = &TagD[TagI[M]];
JustDirectory(TagMem + TT->TagBase, Dir);
if (IsFullPath(TagMem + TT->FileName)) {
strcpy(path, TagMem + TT->FileName);
} else {
strcpy(path, Dir);
Slash(path, 1);
strcat(path, TagMem + TT->FileName);
}
if (TT->Line != -1) {
if (GotoFilePos(View, path, TT->Line - 1, 0) == 0)
return 0;
} else {
if (GotoFilePos(View, path, 0, 0) == 0)
return 0;
if (((EBuffer *)ActiveModel)->FindStr(TagMem + TT->StrFind, strlen(TagMem + TT->StrFind), 0) == 0)
return 0;
}
((EBuffer *)ActiveModel)->FindStr(TagMem + TT->Tag, strlen(TagMem + TT->Tag), 0);
return 1;
}
static int PushPos(EBuffer *B) { /*FOLD00*/
TagStack *T;
T = (TagStack *)malloc(sizeof(TagStack));
if (T == 0)
return 0;
T->FileName = strdup(B->FileName);
if (T->FileName == 0) {
free(T);
return 0;
}
T->Line = B->VToR(B->CP.Row);
T->Col = B->CP.Col;
T->Next = TStack;
T->CurrentTag = CurrentTag;
CurrentTag = 0;
T->TagPos = TagPosition;
TagPosition = -1;
TStack = T;
return 1;
}
int TagGoto(EView *View, char *Tag) {
assert(Tag != 0);
if (TagFilesLoaded == 0)
if (LoadTagFiles() == 0)
return 0;
int L = 0, R = CTags, M, cmp;
if (CTags == 0)
return 0;
while (L < R) {
M = (L + R) / 2;
cmp = strcmp(Tag, TagMem + TagD[TagI[M]].Tag);
if (cmp == 0) {
while (M > 0 && strcmp(Tag, TagMem + TagD[TagI[M - 1]].Tag) == 0)
M--;
if (GotoTag(M, View) == 0)
return 0;
CurrentTag = strdup(Tag);
TagPosition = M;
return 1;
} else if (cmp < 0) {
R = M;
} else {
L = M + 1;
}
}
return 0; // tag not found
}
int TagFind(EBuffer *B, EView *View, char *Tag) { /*FOLD00*/
assert(View != 0 && Tag != 0 && B != 0);
if (TagFilesLoaded == 0)
if (LoadTagFiles() == 0)
return 0;
int L = 0, R = CTags, M, cmp;
if (CurrentTag) {
if (strcmp(CurrentTag, Tag) == 0) {
if (PushPos(B) == 0)
return 0;
CurrentTag = strdup(Tag);
if (CurrentTag == 0)
return 0;
TagPosition = TStack->TagPos;
return TagNext(View);
}
}
if (CTags == 0)
return -1;
while (L < R) {
M = (L + R) / 2;
cmp = strcmp(Tag, TagMem + TagD[TagI[M]].Tag);
if (cmp == 0) {
while (M > 0 && strcmp(Tag, TagMem + TagD[TagI[M - 1]].Tag) == 0)
M--;
if (PushPos(B) == 0)
return 0;
if (GotoTag(M, View) == 0)
return 0;
CurrentTag = strdup(Tag);
TagPosition = M;
return 1;
} else if (cmp < 0) {
R = M;
} else {
L = M + 1;
}
}
return 0; // tag not found
}
int TagDefined(char *Tag) {
int L = 0, R = CTags, M, cmp;
if (TagFilesLoaded == 0) // !!! always?
if (LoadTagFiles() == 0)
return 0;
if (CTags == 0)
return 0;
while (L < R) {
M = (L + R) / 2;
cmp = strcmp(Tag, TagMem + TagD[TagI[M]].Tag);
if (cmp == 0)
return 1;
else if (cmp < 0)
R = M;
else
L = M + 1;
}
return 0; // tag not found
}
int TagComplete(char **Words, int *WordsPos, int WordsMax, char *Tag) {
if ((Tag == NULL) || (Words == NULL) || (*WordsPos >= WordsMax))
return 0;
if (TagFilesLoaded == 0)
if (LoadTagFiles() == 0)
return 0;
if (CTags == 0)
return 0;
int L = 0, R = CTags, len = strlen(Tag);
while (L < R) {
int c, M;
M = (L + R) / 2;
c = strncmp(Tag, TagMem + TagD[TagI[M]].Tag, len);
if (c == 0) {
while (M > 0 &&
strncmp(Tag, TagMem + TagD[TagI[M - 1]].Tag, len) == 0)
M--; // find begining
int N = M, w = 0;
while(strncmp(Tag, TagMem + TagD[TagI[N]].Tag, len) == 0) {
// the first word is not tested for previous match
if (!w || strcmp(TagMem + TagD[TagI[N]].Tag,
TagMem + TagD[TagI[N-1]].Tag)) {
int l = strlen(TagMem + TagD[TagI[N]].Tag) - len;
if (l > 0) {
char *s = new char[l + 1];
if (s != NULL) {
strcpy(s, TagMem + TagD[TagI[N]].Tag + len);
Words[(*WordsPos)++] = s;
w++; // also mark the first usage
if (*WordsPos >= WordsMax)
break;
} else
break; // how about using exceptions
}
}
N++;
}
return w;
} else if (c < 0) {
R = M;
} else {
L = M + 1;
}
}
return 0; // tag not found
}
int TagNext(EView *View) { /*FOLD00*/
assert(View != 0);
if (CurrentTag == 0 || TagPosition == -1) {
return 0;
}
if (TagPosition < CTags - 1 && strcmp(CurrentTag, TagMem + TagD[TagI[TagPosition + 1]].Tag) == 0) {
TagPosition++;
if (GotoTag(TagPosition, View) == 0)
return 0;
return 1;
}
View->Msg(S_INFO, "No next match for tag.");
return 0;
}
int TagPrev(EView *View) { /*FOLD00*/
assert(View != 0);
if (CurrentTag == 0 || TagPosition == -1) {
View->Msg(S_INFO, "No current tag.");
return 0;
}
if (TagPosition > 0 && strcmp(CurrentTag, TagMem + TagD[TagI[TagPosition - 1]].Tag) == 0) {
TagPosition--;
if (GotoTag(TagPosition, View) == 0)
return 0;
return 1;
}
View->Msg(S_INFO, "No previous match for tag.");
return 0;
}
int TagPop(EView *View) { /*FOLD00*/
TagStack *T = TStack;
assert(View != 0);
if (T) {
TStack = T->Next;
if (CurrentTag)
free(CurrentTag);
CurrentTag = T->CurrentTag;
TagPosition = T->TagPos;
if (GotoFilePos(View, T->FileName, T->Line, T->Col) == 0) {
free(T);
return 0;
}
free(T);
return 1;
}
View->Msg(S_INFO, "Tag stack empty.");
return 0;
}
#endif

31
src/e_tags.h Normal file
View file

@ -0,0 +1,31 @@
/* e_tags.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __TAGS_H
#define __TAGS_H
#ifdef CONFIG_TAGS
int TagsAdd(char *FileName);
int TagsSave(FILE *fp);
int TagsLoad(int id);
int TagLoad(char *FileName);
void TagClear();
int TagGoto(EView *V, char *Tag);
int TagDefined(char *Tag);
int TagFind(EBuffer *B, EView *V, char *Tag);
int TagComplete(char **Words, int *WordsPos, int WordsMax, char *Tag);
int TagNext(EView *V);
int TagPrev(EView *V);
int TagPop(EView *V);
#endif
#endif

269
src/e_trans.cpp Normal file
View file

@ -0,0 +1,269 @@
/* e_trans.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
#include <ctype.h>
// FLAW: NULL characters can not be translated, need escaping
int ParseTrans(unsigned char *S, unsigned char *D, TransTable tab) {
unsigned char Dest[512];
unsigned char A, B;
unsigned int i;
if (S == 0 || D == 0)
return 0;
strncpy((char *)Dest, (char *)D, sizeof(Dest) - 1); Dest[sizeof(Dest) - 1] = 0;
D = Dest;
// no translation
for (i = 0; i < 256; i++)
tab[i] = (unsigned char)i;
while (*S && *D) {
if (S[0] && S[1] == '-' && S[2]) {
if (S[0] <= S[2]) {
A = (*S)++;
if (S[0] >= S[2])
S += 2;
} else {
A = (*S)--;
if (S[0] <= S[2])
S += 2;
}
} else {
A = *S++;
}
if (D[0] && D[1] == '-' && D[2]) {
if (D[0] <= D[2]) {
B = (*D)++;
if (D[0] >= D[2])
D += 2;
} else {
B = (*D)--;
if (D[0] <= D[2])
D += 2;
}
} else {
B = *D++;
}
tab[A] = B;
}
if (*S != *D) // one was too short
return 0;
return 1;
}
int MakeTrans(TransTable tab, int What) {
int i;
// no translation
for (i = 0; i <= 255; i++)
tab[i] = (unsigned char)i;
switch (What) {
case ccToggle:
case ccUp:
for (i = 33; i <= 255; i++)
if (isalpha(i) && (toupper(i) != i))
tab[i] = (unsigned char) toupper(i);
if (What != ccToggle)
break;
case ccDown:
for (i = 33; i <= 255; i++)
if (isalpha(i) && (i == tab[i]) && (tolower(i) != i))
tab[i] = (unsigned char) tolower(i);
break;
default:
return 0;
}
return 1;
}
int EBuffer::BlockTrans(TransTable tab) {
int L, I, B, E;
PELine LL;
if (CheckBlock() == 0) return 0;
if (RCount == 0) return 0;
for (L = BB.Row; L <= BE.Row; L++) {
LL = RLine(L);
B = 0;
E = 0;
switch (BlockMode) {
case bmLine:
if (L == BE.Row)
E = 0;
else
E = LL->Count;
break;
case bmColumn:
if (L == BE.Row)
E = 0;
else {
B = CharOffset(LL, BB.Col);
E = CharOffset(LL, BE.Col);
}
break;
case bmStream:
if (L == BB.Row && L == BE.Row) {
B = CharOffset(LL, BB.Col);
E = CharOffset(LL, BE.Col);
} else if (L == BB.Row) {
B = CharOffset(LL, BB.Col);
E = LL->Count;
} else if (L == BE.Row) {
B = 0;
E = CharOffset(LL, BE.Col);
} else {
B = 0;
E = LL->Count;
}
break;
}
if (B > LL->Count)
B = LL->Count;
if (E > LL->Count)
E = LL->Count;
if (E > B) {
if (ChgChars(L, B, E - B, 0) == 0) return 0;
for (I = B; I < E; I++)
LL->Chars[I] = tab[(unsigned char)LL->Chars[I]];
}
}
Draw(BB.Row, BE.Row);
return 1;
}
int EBuffer::CharTrans(TransTable tab) {
PELine L = VLine(CP.Row);
unsigned int P = CharOffset(L, CP.Col);
if (P >= (unsigned int)L->Count) return 0;
if (ChgChars(CP.Row, P, 1, 0) == 0) return 0;
L->Chars[P] = tab[(unsigned char)L->Chars[P]];
return 1;
}
int EBuffer::LineTrans(TransTable tab) {
PELine L = VLine(CP.Row);
int I;
if (L->Count > 0) {
if (ChgChars(CP.Row, 0, L->Count, 0) == 0) return 0;
for (I = 0; I < L->Count; I++)
L->Chars[I] = tab[(unsigned char)L->Chars[I]];
}
return 1;
}
int EBuffer::CharCaseUp() {
TransTable tab;
MakeTrans(tab, ccUp);
return CharTrans(tab);
}
int EBuffer::CharCaseDown() {
TransTable tab;
MakeTrans(tab, ccDown);
return CharTrans(tab);
}
int EBuffer::CharCaseToggle() {
TransTable tab;
MakeTrans(tab, ccToggle);
return CharTrans(tab);
}
int EBuffer::LineCaseUp() {
TransTable tab;
MakeTrans(tab, ccUp);
return LineTrans(tab);
}
int EBuffer::LineCaseDown() {
TransTable tab;
MakeTrans(tab, ccDown);
return LineTrans(tab);
}
int EBuffer::LineCaseToggle() {
TransTable tab;
MakeTrans(tab, ccToggle);
return LineTrans(tab);
}
int EBuffer::BlockCaseUp() {
TransTable tab;
MakeTrans(tab, ccUp);
return BlockTrans(tab);
}
int EBuffer::BlockCaseDown() {
TransTable tab;
MakeTrans(tab, ccDown);
return BlockTrans(tab);
}
int EBuffer::BlockCaseToggle() {
TransTable tab;
MakeTrans(tab, ccToggle);
return BlockTrans(tab);
}
int EBuffer::GetTrans(ExState &State, TransTable tab) {
unsigned char TrS[512] = "";
unsigned char TrD[512] = "";
if (State.GetStrParam(View, (char *)TrS, sizeof(TrS)) == 0)
if (View->MView->Win->GetStr("Trans From", sizeof(TrS), (char *)TrS, HIST_TRANS) == 0)
return 0;
if (State.GetStrParam(View, (char *)TrD, sizeof(TrD)) == 0)
if (View->MView->Win->GetStr("Trans To", sizeof(TrS), (char *)TrD, HIST_TRANS) == 0)
return 0;
if (ParseTrans(TrS, TrD, tab) == 0) {
Msg(S_ERROR, "Bad Trans Arguments %s %s.", TrS, TrD);
return 0;
}
return 1;
}
int EBuffer::CharTrans(ExState &State) {
TransTable tab;
if (GetTrans(State, tab) == 0)
return 0;
return CharTrans(tab);
}
int EBuffer::LineTrans(ExState &State) {
TransTable tab;
if (GetTrans(State, tab) == 0)
return 0;
return LineTrans(tab);
}
int EBuffer::BlockTrans(ExState &State) {
TransTable tab;
if (GetTrans(State, tab) == 0)
return 0;
return BlockTrans(tab);
}

370
src/e_undo.cpp Normal file
View file

@ -0,0 +1,370 @@
/* e_undo.cpp
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#include "fte.h"
int EBuffer::NextCommand() {
if (Match.Row != -1) {
Draw(Match.Row, Match.Row);
Match.Col = Match.Row = -1;
}
if (View)
View->SetMsg(0);
#ifdef CONFIG_UNDOREDO
return BeginUndo();
#else
return 1;
#endif
}
#ifdef CONFIG_UNDOREDO
int EBuffer::PushBlockData() {
if (BFI(this, BFI_Undo) == 0) return 1;
if (PushULong(BB.Col) == 0) return 0;
if (PushULong(BB.Row) == 0) return 0;
if (PushULong(BE.Col) == 0) return 0;
if (PushULong(BE.Row) == 0) return 0;
if (PushULong(BlockMode) == 0) return 0;
if (PushUChar(ucBlock) == 0) return 0;
return 1;
}
int EBuffer::BeginUndo() {
US.NextCmd = 1;
return 1;
}
int EBuffer::EndUndo() {
int N = US.Num - 1;
assert(N >= 0);
if (N >= 1) {
int Order = 1;
while (Order < N) Order <<= 1;
US.Data = (void **) realloc(US.Data, sizeof(void *) * Order);
US.Top = (int *) realloc(US.Top, sizeof(int) * Order);
US.Num--;
} else {
free(US.Data); US.Data = 0;
free(US.Top); US.Top = 0;
US.Num = 0;
}
return 1;
}
int EBuffer::PushULong(unsigned long l) {
// static unsigned long x = l;
return PushUData(&l, sizeof(unsigned long));
}
int EBuffer::PushUChar(unsigned char ch) {
return PushUData(&ch, sizeof(unsigned char));
}
int EBuffer::PushUData(void *data, int len) {
int N;
int Order = 1;
// printf("UPUSH: %d %c\n", len, *(char *)data); fflush(stdout);
if (BFI(this, BFI_Undo) == 0) return 0;
if (US.Record == 0) return 1;
if (US.NextCmd || US.Num == 0 || US.Data == 0 || US.Top == 0) {
N = US.Num;
if ((BFI(this, BFI_UndoLimit) == -1) || (US.Undo) || (US.Num < BFI(this, BFI_UndoLimit))) {
N++;
US.Data = (void **) realloc(US.Data, sizeof(void *) * (N | 255));
US.Top = (int *) realloc(US.Top, sizeof(int) * (N | 255));
if (US.Num == US.UndoPtr && !US.Undo)
US.UndoPtr++;
US.Num++;
} else {
N = US.Num;
free(US.Data[0]);
memmove(US.Data, US.Data + 1, (N - 1) * sizeof(US.Data[0]));
memmove(US.Top, US.Top + 1, (N - 1) * sizeof(US.Top[0]));
}
assert(US.Data);
assert(US.Top);
N = US.Num - 1;
US.Data[N] = 0;
US.Top[N] = 0;
if (US.NextCmd == 1) {
US.NextCmd = 0;
// puts("\x7");
if (PushULong(CP.Col) == 0) return 0;
if (PushULong(CP.Row) == 0) return 0;
if (PushUChar(ucPosition) == 0) return 0;
// puts("\x7");
}
US.NextCmd = 0;
}
N = US.Num - 1;
assert(N >= 0);
if (US.Undo == 0) US.UndoPtr = US.Num;
while (Order < (US.Top[N] + len)) Order <<= 1;
US.Data[N] = realloc(US.Data[N], Order);
memcpy((char *) US.Data[N] + US.Top[N], data, len);
US.Top[N] += len;
return 1;
}
int EBuffer::GetUData(int No, int pos, void **data, int len) {
int N;
if (No == -1)
N = US.Num - 1;
else
N = No;
if (BFI(this, BFI_Undo) == 0) return 0;
if (N < 0) return 0;
if (US.Data[N] == 0) return 0;
if (US.Top[N] == 0) return 0;
if (pos == -1)
pos = US.Top[N];
if (pos == 0)
return 0;
// printf("N,pos = %d,%d len = %d\n", N, pos, len);
assert(pos >= len);
*data = ((char *) US.Data[N]) + pos - len;
return 1;
}
#define UGETC(rc,no,pos,what) \
do { void *d; \
rc = GetUData(no, pos, &d, sizeof(unsigned char)); \
*(unsigned char *)&what = *(unsigned char *)d; \
pos -= sizeof(unsigned char); \
} while (0)
#define UGET(rc,no,pos,what) \
do { void *d; \
rc = GetUData(no, pos, &d, sizeof(what)); \
memcpy((void *)&what, d, sizeof(what)); \
pos -= sizeof(what); \
} while (0)
int EBuffer::Undo(int undo) {
unsigned char UndoCmd;
int rc;
unsigned long Line;
unsigned long Len;
unsigned long ACount;
unsigned long Col;
void *data;
int No;
int Pos;
if (BFI(this, BFI_Undo) == 0)
return 0;
if (undo)
No = US.UndoPtr - 1;
else
No = US.Num - 1;
Pos = US.Top[No];
if (No == 0 && Pos == 0) {
//puts("bottom");
return 0;
}
// for (int i = 0; i < Pos; i++) {
// printf("%d: %d\n", i, ((char *)US.Data[No])[i]);
// }
// printf("Undo %d %d,%d\n", undo, No, Pos); fflush(stdout);
// fprintf(stderr, "\nNo = %d, Num = %d\n", No, US.Num);
UGETC(rc, No, Pos, UndoCmd);
while (rc == 1) {
// printf("%d Undo %d %d,%d\n", UndoCmd, undo, No, Pos); fflush(stdout);
// for (int i = 0; i < Pos; i++) {
// printf("%d: %d\n", i, ((char *)US.Data[No])[i]);
// }
switch (UndoCmd) {
case ucInsLine:
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
// printf("\tDelLine %d\n", Line);
if (DelLine(Line) == 0) return 0;
break;
case ucDelLine:
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
UGET(rc, No, Pos, Len); if (rc == 0) return 0;
if (GetUData(No, Pos, &data, Len) == 0) return 0;
// printf("\tInsLine %d\n", Line);
if (InsLine(Line, 0) == 0) return 0;
// printf("\tInsText %d - %d\n", Line, Len);
if (InsText(Line, 0, Len, (char *) data) == 0) return 0;
Pos -= Len;
break;
case ucInsChars:
UGET(rc, No, Pos, ACount); if (rc == 0) return 0;
UGET(rc, No, Pos, Col); if (rc == 0) return 0;
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
// printf("\tDelChars %d %d %d\n", Line, Col, ACount);
if (DelChars(Line, Col, ACount) == 0) return 0;
break;
case ucDelChars:
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
UGET(rc, No, Pos, Col); if (rc == 0) return 0;
UGET(rc, No, Pos, ACount); if (rc == 0) return 0;
if (GetUData(No, Pos, &data, ACount) == 0) return 0;
// printf("\tInsChars %d %d %d\n", Line, Col, ACount);
if (InsChars(Line, Col, ACount, (char *) data) == 0) return 0;
Pos -= ACount;
break;
case ucPosition:
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
UGET(rc, No, Pos, Col); if (rc == 0) return 0;
// printf("\tSetPos %d %d\n", Line, Col);
if (SetPos(Col, Line) == 0) return 0;
break;
case ucBlock:
{
EPoint P;
unsigned long l;
// printf("\tBlock\n");
UGET(rc, No, Pos, l); if (rc == 0) return 0;
if (BlockMode != (int)l) BlockRedraw();
BlockMode = l;
UGET(rc, No, Pos, l); if (rc == 0) return 0; P.Row = l;
UGET(rc, No, Pos, l); if (rc == 0) return 0; P.Col = l;
if (SetBE(P) == 0) return 0;
UGET(rc, No, Pos, l); if (rc == 0) return 0; P.Row = l;
UGET(rc, No, Pos, l); if (rc == 0) return 0; P.Col = l;
if (SetBB(P) == 0) return 0;
}
break;
case ucFoldCreate:
// puts("ucFoldCreate");
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
if (FoldDestroy(Line) == 0) return 0;
break;
case ucFoldDestroy:
// puts("ucFoldDestroy");
{
unsigned long level;
int ff;
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
UGET(rc, No, Pos, level); if (rc == 0) return 0;
if (FoldCreate(Line) == 0) return 0;
ff = FindFold(Line);
assert(ff != -1);
FF[ff].level = (unsigned char) level;
}
break;
case ucFoldPromote:
// puts("ucFoldPromote");
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
if (FoldDemote(Line) == 0) return 0;
break;
case ucFoldDemote:
// puts("ucFoldDemote");
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
if (FoldPromote(Line) == 0) return 0;
break;
case ucFoldOpen:
// puts("ucFoldOpen");
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
if (FoldClose(Line) == 0) return 0;
break;
case ucFoldClose:
// puts("ucFoldClose");
UGET(rc, No, Pos, Line); if (rc == 0) return 0;
if (FoldOpen(Line) == 0) return 0;
break;
case ucModified:
// printf("\tModified\n");
Modified = 0;
break;
default:
assert(1 == "Oops: invalid undo command.\n"[0]);
}
// puts("\tok");
// fprintf(stderr, "\nNo = %d, Num = %d\n", No, US.Num);
UGETC(rc, No, Pos, UndoCmd);
}
if (undo)
US.UndoPtr--;
else {
US.UndoPtr++;
free(US.Data[No]);
if (EndUndo() == 0) return 0;
}
return 1;
}
int EBuffer::Redo() {
int rc;
if (BFI(this, BFI_Undo) == 0) return 0;
// US.NextCmd = 0; // disable auto push position
if (US.Num == 0 || US.UndoPtr == US.Num) {
Msg(S_INFO, "Nothing to redo.");
return 0;
}
US.Record = 0;
rc = Undo(0);
US.Record = 1;
return rc;
}
int EBuffer::Undo() {
int rc;
if (BFI(this, BFI_Undo) == 0) return 0;
assert(US.Num >= 0);
assert(US.UndoPtr >= 0);
if (US.Num == 0 || US.UndoPtr == 0) {
Msg(S_INFO, "Nothing to undo.");
return 0;
}
US.Undo = 1;
rc = Undo(1);
US.Undo = 0;
return rc;
}
#endif

43
src/e_undo.h Normal file
View file

@ -0,0 +1,43 @@
/* e_undo.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __UNDO_H__
#define __UNDO_H__
/*
* only core operations can be directly undone
* - Insert # of Lines
* - Delete # of Lines
* - Insert # Line
* - Delete Line Text
* - Insert Line Text
* - Positioning
* - Block marking
*/
#define ucInsLine 1
#define ucDelLine 2
#define ucInsChars 3
#define ucDelChars 4
#define ucJoinLine 5
#define ucSplitLine 6
#define ucPosition 7
#define ucBlock 8
#define ucModified 9
#define ucFoldCreate 11
#define ucFoldDestroy 12
#define ucFoldPromote 13
#define ucFoldDemote 14
#define ucFoldOpen 15
#define ucFoldClose 16
#endif

87
src/e_unix.cpp Normal file
View file

@ -0,0 +1,87 @@
/* e_unix.cpp
*
* Copyright (c) 1997, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifdef WINNT
#include "e_win32.cpp"
#else
// UNIX specific routines
#include "fte.h"
#include <sys/wait.h>
#include <signal.h>
int EView::SysShowHelp(ExState &State, const char *word) {
char options[128] = "";
char command[1024];
char file[MAXPATH];
if (State.GetStrParam(this, options, sizeof(options) - 1) == 0)
options[0] = 0;
char wordAsk[64] = "";
if (word == 0) {
if (State.GetStrParam(this, wordAsk, sizeof(wordAsk) - 1) == 0)
if (MView->Win->GetStr("Keyword",
sizeof(wordAsk) - 1, wordAsk, HIST_DEFAULT) == 0)
return 0;
word = wordAsk;
}
sprintf(file, "/tmp/fte%d-man-%s", getpid(), word);
sprintf(command, "%s %s %s >'%s' 2>&1", HelpCommand, options, word, file);
/// !!! why is this needed ???
#define SYSCALL(call) while(((call) == -1) && (errno == EINTR))
pid_t pid;
int err, status;
Msg(S_INFO, "Retrieving man page for %s, please wait", word);
if ((pid = fork()) == 0) {
close(1);
SYSCALL(err = open(file, O_CREAT | O_WRONLY | O_APPEND, S_IRWXU));
if (err != -1) {
close(2);
//dup(1); // ignore error output
close(0);
assert(open("/dev/null", O_RDONLY) == 0);
execlp("man", "man",
#ifndef AIX // current AIX's don't like the -a.
"-a",
#endif
word, NULL);
// execlp("/bin/sh", "sh", "-c", command, NULL);
}
perror("Can't Exec Command\n");
exit(-1);
} else if (pid < 0) {
perror("Can't fork");
return 0;
}
SYSCALL(err = waitpid(pid, &status, 0));
if (err == -1) {
perror("Waitpid failed\n");
return 0;
}
// int rc = system(command);
err = FileLoad(0, file, "CATBS", this);
unlink(file);
if (err == 0){
Msg(S_ERROR, "Error code %d retrieving manpage for %s", err, word);
return 0;
}
return 1;
}
#endif

39
src/e_win32.cpp Normal file
View file

@ -0,0 +1,39 @@
/* e_win32.cpp
*
* Copyright (c) 1997, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
// Win32 (NT) specific routines
#include "fte.h"
#include <windows.h>
int EView::SysShowHelp(ExState &State, const char *word) {
char file[MAXPATH] = "";
if (State.GetStrParam(this, file, sizeof(file) - 1) == 0)
if (MView->Win->GetStr("Help file",
sizeof(file) - 1, file, HIST_DEFAULT) == 0)
return 0;
char wordAsk[64] = "";
if (word == 0) {
if (State.GetStrParam(this, wordAsk, sizeof(wordAsk) - 1) == 0)
if (MView->Win->GetStr("Keyword",
sizeof(wordAsk) - 1, wordAsk, HIST_DEFAULT) == 0)
return 0;
word = wordAsk;
}
//** Start WinHelp,
if (!WinHelp(0, file, HELP_KEY, (DWORD)word)) {
Msg(S_ERROR, "Failed to start WinHelp!");
return 0;
}
return 1;
}

1068
src/egui.cpp Normal file

File diff suppressed because it is too large Load diff

91
src/egui.h Normal file
View file

@ -0,0 +1,91 @@
/* egui.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef __EGUI_H__
#define __EGUI_H__
class EFrame: public GFrame {
public:
EEventMap *CMap;
EModel *CModel;
EFrame(int XSize, int YSize);
virtual ~EFrame();
virtual void Update();
virtual void UpdateMenu();
};
class EGUI: public GUI {
public:
EKeyMap *ActiveMap;
EKeyMap *OverrideMap;
char CharMap[32];
EGUI(int &argc, char **argv, int XSize, int YSize);
virtual ~EGUI();
virtual int ExecCommand(GxView *view, int Command, ExState &State);
virtual int ExecMacro(GxView *view, int Macro);
virtual int BeginMacro(GxView *view);
void SetMsg(char *Msg);
void SetOverrideMap(EKeyMap *aMap, char *ModeName);
void SetMap(EKeyMap *aMap, KeySel *ks);
// void CharEvent(TEvent &Event, char Ch);
void DispatchKey(GxView *view, TEvent &Event);
void DispatchCommand(GxView *view, TEvent &Event);
virtual void DispatchEvent(GFrame *frame, GView *view, TEvent &Event);
int FileCloseX(EView *View, int CreateNew, int XClose = 0);
int FileClose(EView *View, ExState &State);
int FileCloseAll(EView *View, ExState &State);
int WinNext(GxView *view);
int WinPrev(GxView *view);
int WinHSplit(GxView *View);
int WinClose(GxView *View);
int WinZoom(GxView *View);
int WinResize(ExState &State, GxView *View);
int ExitEditor(EView *View);
int FrameNew();
int FrameClose(GxView *View);
int FrameNext(GxView *View);
int FramePrev(GxView *View);
int ShowEntryScreen();
int RunProgram(ExState &State, GxView *view);
int RunProgramAsync(ExState &State, GxView *view);
int MainMenu(ExState &State, GxView *View);
int ShowMenu(ExState &State, GxView *View);
int LocalMenu(GxView *View);
int DesktopSaveAs(ExState &State, GxView *View);
int findDesktop(char *argv[]);
void DoLoadDesktopOnEntry(int &argc, char **argv);
void EditorInit();
int CmdLoadFiles(int &argc, char **argv);
int InterfaceInit(int &argc, char **argv);
void DoLoadHistoryOnEntry(int &argc, char **argv);
void DoSaveHistoryOnExit();
void EditorCleanup();
void InterfaceCleanup();
virtual int Start(int &argc, char **argv);
virtual void Stop();
};
#endif

93
src/feature.h Normal file
View file

@ -0,0 +1,93 @@
/* feature.h
*
* Copyright (c) 1994-1996, Marko Macek
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
/* some stuff does not yet work */
#ifndef __FEATURE_H__
#define __FEATURE_H__
#undef CONFIG_EMULATE_VI // todo
#define CONFIG_CONFIGURABLE
#define CONFIG_MOUSE
#define CONFIG_CLIPBOARD
#define CONFIG_SHELL
#define CONFIG_MFRAMES
#define CONFIG_MWINDOWS
#define CONFIG_MBUFFERS
#define CONFIG_MENUS
#define CONFIG_SCROLLBARS
#define CONFIG_I_SEARCH
#define CONFIG_I_ASCII
#define CONFIG_HISTORY
#define CONFIG_DESKTOP
#define CONFIG_BLOCK_STREAM
#define CONFIG_BLOCK_COLUMN
#define CONFIG_BLOCK_LINE
#define CONFIG_IOBLOCKS
#define CONFIG_PRINTING
#define CONFIG_BOOKMARKS
#define CONFIG_WORDWRAP
#define CONFIG_ABBREV
#define CONFIG_TAGS
#define CONFIG_UNDOREDO
#define CONFIG_REGEXPS
#define CONFIG_FOLDS
#undef CONFIG_OBJ_HEXEDIT // todo
#undef CONFIG_OBJ_VIEWER // todo
#define CONFIG_OBJ_LIST
#define CONFIG_OBJ_FILE
#ifdef CONFIG_OBJ_LIST
#define CONFIG_OBJ_DIRECTORY
#define CONFIG_OBJ_ROUTINE
#define CONFIG_OBJ_BUFFERS
#define CONFIG_OBJ_MESSAGES
#endif
#define CONFIG_SYNTAX_HILIT
#define CONFIG_WORD_HILIT
#ifdef CONFIG_SYNTAX_HILIT
#define CONFIG_HILIT_C
#define CONFIG_HILIT_REXX
#define CONFIG_HILIT_HTML
#define CONFIG_HILIT_PERL
#define CONFIG_HILIT_ADA
#define CONFIG_HILIT_MAKE
#define CONFIG_HILIT_DIFF
#define CONFIG_HILIT_MERGE
#define CONFIG_HILIT_IPF
#define CONFIG_HILIT_MSG
#define CONFIG_HILIT_SH
#define CONFIG_HILIT_PASCAL
#define CONFIG_HILIT_TEX
#define CONFIG_HILIT_FTE
#define CONFIG_HILIT_CATBS
#define CONFIG_HILIT_SIMPLE
#endif
#if defined(CONFIG_HILIT_C)
#define CONFIG_INDENT_C
#endif
#if defined(CONFIG_HILIT_SIMPLE)
#define CONFIG_INDENT_SIMPLE
#endif
#if defined(CONFIG_HILIT_REXX)
#define CONFIG_INDENT_REXX
#endif
#define CONFIG_I_COMPLETE
#endif

84
src/fnmatch.h Normal file
View file

@ -0,0 +1,84 @@
/* Copyright (C) 1991, 92, 93, 96, 97, 98 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _FNMATCH_H
#define _FNMATCH_H 1
#ifdef __cplusplus
extern "C" {
#endif
#if defined __cplusplus || (defined __STDC__ && __STDC__) || defined WINDOWS32
# if !defined __GLIBC__ || !defined __P
# undef __P
# define __P(protos) protos
# endif
#else /* Not C++ or ANSI C. */
# undef __P
# define __P(protos) ()
/* We can get away without defining `const' here only because in this file
it is used only inside the prototype for `fnmatch', which is elided in
non-ANSI C where `const' is problematical. */
#endif /* C++ or ANSI C. */
#ifndef const
# if (defined __STDC__ && __STDC__) || defined __cplusplus
# define __const const
# else
# define __const
# endif
#endif
/* We #undef these before defining them because some losing systems
(HP-UX A.08.07 for example) define these in <unistd.h>. */
#undef FNM_PATHNAME
#undef FNM_NOESCAPE
#undef FNM_PERIOD
/* Bits set in the FLAGS argument to `fnmatch'. */
#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
#if !defined _POSIX_C_SOURCE || _POSIX_C_SOURCE < 2 || defined _GNU_SOURCE
# define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */
# define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */
# define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */
#endif
/* Value returned by `fnmatch' if STRING does not match PATTERN. */
#define FNM_NOMATCH 1
/* This value is returned if the implementation does not support
`fnmatch'. Since this is not the case here it will never be
returned but the conformance test suites still require the symbol
to be defined. */
#ifdef _XOPEN_SOURCE
# define FNM_NOSYS (-1)
#endif
/* Match STRING against the filename pattern PATTERN,
returning zero if it matches, FNM_NOMATCH if not. */
extern int fnmatch __P ((__const char *__pattern, __const char *__string,
int __flags));
#ifdef __cplusplus
}
#endif
#endif /* fnmatch.h */

72
src/fte-bcc2.mak Normal file
View file

@ -0,0 +1,72 @@
LIBDIR = \BCOS2\LIB
INCDIR = \BCOS2\INCLUDE
.AUTODEPEND
DEFINES=-DOS2 -DBCPP -DHEAPWALK
DEBUG =
#DEBUG=-v
INIT = $(LIBDIR)\c02.obj
CC = bcc
LD = tlink
CCFLAGS = $(DEFINES) -L$(LIBDIR) -I$(INCDIR) -H=fte.CSM \
-k- -sm -K -w -w-par -Ot -RT- -xd- -x- -vi- -d -a -y $(DEBUG)
LDFLAGS = -L$(LIBDIR) $(DEBUG) -s -Toe -Oc -B:0x10000
OEXT=obj
!include objs.inc
.cpp.$(OEXT):
$(CC) $(CCFLAGS) -c {$< }
.c.$(OEXT):
$(CC) $(CCFLAGS) -c {$< }
all: cfte.exe fte.exe ftepm.exe clipserv.exe cliputil.exe
defcfg.cnf: defcfg.fte cfte.exe
cfte defcfg.fte defcfg.cnf
defcfg.h: defcfg.cnf bin2c.exe
bin2c defcfg.cnf >defcfg.h
c_config.obj: defcfg.h
bin2c.exe: bin2c.cpp
$(CC) $(CCFLAGS) bin2c.cpp
cfte.exe: $(CFTE_OBJS)
$(LD) @&&|
$(LDFLAGS) $(INIT) $**,cfte.exe,cfte.map,os2 c2mt,cfte.def
|
fte.exe: $(OBJS) $(VIOOBJS)
$(LD) @&&|
$(LDFLAGS) $(INIT) $**,fte.exe,fte.map,os2 c2mt,fte.def
|
ftepm.exe:: $(OBJS) $(PMOBJS)
$(LD) @&&|
$(LDFLAGS) $(INIT) $**,ftepm.exe,ftepm.map,c2mt os2,ftepm.def
|
rc -i $(INCDIR) ftepm.rc ftepm.exe
clipserv.exe: clipserv.obj
$(LD) @&&|
$(LDFLAGS) $(INIT) $**,clipserv.exe,clipserv.map,c2mt os2,clipserv.def
|
cliputil.exe: cliputil.obj clip_vio.obj
$(LD) @&&|
$(LDFLAGS) $(INIT) $**,cliputil.exe,cliputil.map,c2mt os2,cliputil.def
|
ftepm.exe:: ftepm.res
rc ftepm.res ftepm.exe
ftepm.res: ftepm.rc pmdlg.rc
rc -i $(INCDIR) -r ftepm.rc

Some files were not shown because too many files have changed in this diff Show more