mirror of https://github.com/ksherlock/dict.git
commit old WIP.
This commit is contained in:
parent
6c08fa1373
commit
028fab0ce9
128
nda.c
128
nda.c
|
@ -19,6 +19,7 @@
|
||||||
#include <quickdraw.h>
|
#include <quickdraw.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
#include "nda.h"
|
#include "nda.h"
|
||||||
|
@ -61,7 +62,7 @@ static Connection connection;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
st_none,
|
st_none,
|
||||||
st_init,
|
st_idle,
|
||||||
st_connect,
|
st_connect,
|
||||||
st_login,
|
st_login,
|
||||||
st_client,
|
st_client,
|
||||||
|
@ -76,6 +77,12 @@ static unsigned st = 0;
|
||||||
static LongWord qtick = 0;
|
static LongWord qtick = 0;
|
||||||
const char *ReqName = "\pTCP/IP~kelvin~dict~";
|
const char *ReqName = "\pTCP/IP~kelvin~dict~";
|
||||||
|
|
||||||
|
int define(Word ipid, const char *dict);
|
||||||
|
pascal void MarinettiCallback(char *str);
|
||||||
|
|
||||||
|
void EnableControls(void);
|
||||||
|
void DisableControls(void);
|
||||||
|
|
||||||
void InsertString(word length, char *cp) {
|
void InsertString(word length, char *cp) {
|
||||||
Handle handle;
|
Handle handle;
|
||||||
// TERecord **temp;
|
// TERecord **temp;
|
||||||
|
@ -108,8 +115,19 @@ void TCPLoop(void) {
|
||||||
unsigned x;
|
unsigned x;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
Word ipid = connection.ipid;
|
||||||
|
|
||||||
switch (st) {
|
switch (st) {
|
||||||
|
|
||||||
|
case st_idle:
|
||||||
|
if (GetTick() >= qtick) {
|
||||||
|
TCPIPWriteTCP(ipid, "QUIT\r\n", 6, 1, 0);
|
||||||
|
qtick = GetTick() + 60 * 30;
|
||||||
|
st = st_quit;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case st_connect:
|
case st_connect:
|
||||||
x = ConnectionPoll(&connection);
|
x = ConnectionPoll(&connection);
|
||||||
switch (x) {
|
switch (x) {
|
||||||
|
@ -118,6 +136,7 @@ void TCPLoop(void) {
|
||||||
break;
|
break;
|
||||||
case kConnectionStateDisconnected:
|
case kConnectionStateDisconnected:
|
||||||
case kConnectionStateError:
|
case kConnectionStateError:
|
||||||
|
EnableControls();
|
||||||
st = st_none;
|
st = st_none;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -126,9 +145,8 @@ void TCPLoop(void) {
|
||||||
x = ConnectionPoll(&connection);
|
x = ConnectionPoll(&connection);
|
||||||
switch (x) {
|
switch (x) {
|
||||||
case kConnectionStateDisconnected:
|
case kConnectionStateDisconnected:
|
||||||
st = st_none;
|
|
||||||
break;
|
|
||||||
case kConnectionStateError:
|
case kConnectionStateError:
|
||||||
|
EnableControls();
|
||||||
st = st_none;
|
st = st_none;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -155,7 +173,7 @@ void TCPLoop(void) {
|
||||||
sizeof(buffer) - 2, &rlr);
|
sizeof(buffer) - 2, &rlr);
|
||||||
if (!rlr.rlrIsDataFlag)
|
if (!rlr.rlrIsDataFlag)
|
||||||
return;
|
return;
|
||||||
|
qtick += 60 * 15; /* bump timeout */
|
||||||
/* ensure a trailing \r and 0 */
|
/* ensure a trailing \r and 0 */
|
||||||
x = rlr.rlrBuffCount;
|
x = rlr.rlrBuffCount;
|
||||||
if (x) {
|
if (x) {
|
||||||
|
@ -205,6 +223,7 @@ void TCPLoop(void) {
|
||||||
if (status == 250) {
|
if (status == 250) {
|
||||||
++st;
|
++st;
|
||||||
/* send define string... */
|
/* send define string... */
|
||||||
|
define(ipid, NULL);
|
||||||
}
|
}
|
||||||
/* else error */
|
/* else error */
|
||||||
break;
|
break;
|
||||||
|
@ -216,20 +235,24 @@ void TCPLoop(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == 552) {
|
if (status == 552) {
|
||||||
InsertString(10, "No match\r");
|
MarinettiCallback("\pNo match");
|
||||||
st = st_none;
|
st = st_idle;
|
||||||
} else {
|
} else {
|
||||||
InsertString(rlr.rlrBuffCount, buffer);
|
InsertString(rlr.rlrBuffCount, buffer);
|
||||||
st = st_none;
|
st = st_idle;
|
||||||
}
|
}
|
||||||
|
EnableControls();
|
||||||
|
qtick = GetTick() + 60 * 60 * 2; /* 2-minute timeout */
|
||||||
break;
|
break;
|
||||||
case st_define2:
|
case st_define2:
|
||||||
/* expect 151 */
|
/* expect 151 */
|
||||||
if (status == 151)
|
if (status == 151)
|
||||||
++st;
|
++st;
|
||||||
else if (status == 250)
|
else if (status == 250) {
|
||||||
st = st_none;
|
st = st_idle;
|
||||||
else {
|
qtick = GetTick() + 60 * 60 * 2; /* 2-minute timeout */
|
||||||
|
EnableControls();
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case st_define3:
|
case st_define3:
|
||||||
|
@ -392,6 +415,86 @@ GrafPortPtr NDAOpen(void) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char word_to_define[256];
|
||||||
|
int define(Word ipid, const char *dict) {
|
||||||
|
word terr;
|
||||||
|
int ok;
|
||||||
|
unsigned x;
|
||||||
|
static char buffer[512];
|
||||||
|
|
||||||
|
if (!dict || !*dict)
|
||||||
|
dict = "!";
|
||||||
|
|
||||||
|
|
||||||
|
x = sprintf(buffer, "DEFINE %s \"%b\"\r\n", dict, word_to_define);
|
||||||
|
|
||||||
|
terr = TCPIPWriteTCP(ipid, buffer, x, 1, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DoDefine(void) {
|
||||||
|
|
||||||
|
unsigned i;
|
||||||
|
Handle handle;
|
||||||
|
|
||||||
|
|
||||||
|
handle = (Handle)GetCtlHandleFromID(MyWindow, rCtrlTE);
|
||||||
|
|
||||||
|
TESetText(teDataIsTextBlock, (Ref)"", 0, NULL, NULL, handle);
|
||||||
|
|
||||||
|
GetLETextByID(MyWindow, rCtrlLE, (StringPtr)word_to_define);
|
||||||
|
|
||||||
|
i = word_to_define[0];
|
||||||
|
while (i && isspace(word_to_define[i])) --i;
|
||||||
|
if (!i) return;
|
||||||
|
word_to_define[0] = i;
|
||||||
|
word_to_define[i+1] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/* considerations:
|
||||||
|
1. is the network connected?
|
||||||
|
2. is a tcp connection already established?
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!FlagTCP) {
|
||||||
|
|
||||||
|
MarinettiCallback("\pConnecting to network...");
|
||||||
|
TCPIPConnect(MarinettiCallback);
|
||||||
|
if (!FlagTCP) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qtick = GetTick() + 30 * 60;
|
||||||
|
|
||||||
|
DisableControls();
|
||||||
|
|
||||||
|
switch(st) {
|
||||||
|
case st_idle:
|
||||||
|
define(connection.ipid, NULL);
|
||||||
|
st = st_define1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ConnectionAbort(&connection);
|
||||||
|
case st_none:
|
||||||
|
ConnectionOpenC(&connection, "dict.org", 2628);
|
||||||
|
st = st_connect;
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EnableControls(void) {
|
||||||
|
HiliteCtlByID(noHilite, MyWindow, rCtrlLE);
|
||||||
|
HiliteCtlByID(noHilite, MyWindow, rCtrlDefine);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisableControls(void) {
|
||||||
|
HiliteCtlByID(inactiveHilite, MyWindow, rCtrlLE);
|
||||||
|
HiliteCtlByID(inactiveHilite, MyWindow, rCtrlDefine);
|
||||||
|
}
|
||||||
|
|
||||||
word NDAAction(void *param, int code) {
|
word NDAAction(void *param, int code) {
|
||||||
word eventCode;
|
word eventCode;
|
||||||
static EventRecord event = {0};
|
static EventRecord event = {0};
|
||||||
|
@ -416,11 +519,10 @@ word NDAAction(void *param, int code) {
|
||||||
case wInControl:
|
case wInControl:
|
||||||
switch (event.wmTaskData4) {
|
switch (event.wmTaskData4) {
|
||||||
/* start marinetti */
|
/* start marinetti */
|
||||||
case rCtrlDefine: {
|
case rCtrlDefine:
|
||||||
|
DoDefine();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// todo - Command-A selects all.
|
// todo - Command-A selects all.
|
||||||
}
|
}
|
||||||
} else if (code == copyAction) {
|
} else if (code == copyAction) {
|
||||||
|
|
Loading…
Reference in New Issue