clang-format.

This commit is contained in:
Kelvin Sherlock 2018-11-12 19:38:22 -05:00
parent 56f1b1422f
commit 5891e6f842
3 changed files with 255 additions and 281 deletions

View File

@ -1,25 +1,21 @@
#pragma optimize 79 #pragma optimize 79
#pragma noroot #pragma noroot
#pragma lint -1 #pragma lint - 1
#include <Memory.h>
#include <IntMath.h> #include <IntMath.h>
#include "Memory.h"
#include "connection.h" #include "connection.h"
#include <string.h> #include <string.h>
//#include "s16debug.h" //#include "s16debug.h"
static char pstring[256]; static char pstring[256];
static Word LoginAndOpen(Connection *buffer) {
static Word LoginAndOpen(Connection *buffer)
{
Word ipid; Word ipid;
Word terr; Word terr;
if (buffer->displayPtr) if (buffer->displayPtr) {
{
static char message[] = "\pConnecting to xxx.xxx.xxx.xxx:xxxxx"; static char message[] = "\pConnecting to xxx.xxx.xxx.xxx:xxxxx";
Word length; Word length;
@ -39,21 +35,16 @@ static Word LoginAndOpen(Connection *buffer)
buffer->displayPtr(message); buffer->displayPtr(message);
} }
ipid = TCPIPLogin( ipid = TCPIPLogin(buffer->memID, buffer->dnr.DNRIPaddress, buffer->port,
buffer->memID, 0x0000, 0x0040);
buffer->dnr.DNRIPaddress,
buffer->port,
0x0000, 0x0040);
if (_toolErr) if (_toolErr) {
{
buffer->state = kConnectionStateError; buffer->state = kConnectionStateError;
return -1; return -1;
} }
terr = TCPIPOpenTCP(ipid); terr = TCPIPOpenTCP(ipid);
if (_toolErr || terr) if (_toolErr || terr) {
{
TCPIPLogout(ipid); TCPIPLogout(ipid);
buffer->state = kConnectionStateError; buffer->state = kConnectionStateError;
buffer->terr = terr; buffer->terr = terr;
@ -67,32 +58,30 @@ static Word LoginAndOpen(Connection *buffer)
return 0; return 0;
} }
Word ConnectionPoll(Connection *buffer) {
Word ConnectionPoll(Connection *buffer)
{
Word state; Word state;
if (!buffer) return -1; if (!buffer)
return -1;
state = buffer->state; state = buffer->state;
if (state == 0) return -1; if (state == 0)
if (state == kConnectionStateConnected) return 1; return -1;
if (state == kConnectionStateDisconnected) return 1; if (state == kConnectionStateConnected)
if (state == kConnectionStateError) return -1; return 1;
if (state == kConnectionStateDisconnected)
return 1;
if (state == kConnectionStateError)
return -1;
TCPIPPoll(); TCPIPPoll();
if (state == kConnectionStateDNR) if (state == kConnectionStateDNR) {
{ if (buffer->dnr.DNRstatus == DNR_OK) {
if (buffer->dnr.DNRstatus == DNR_OK) return LoginAndOpen(buffer);
{ } else if (buffer->dnr.DNRstatus != DNR_Pending) {
return LoginAndOpen(buffer);
}
else if (buffer->dnr.DNRstatus != DNR_Pending)
{
buffer->state = kConnectionStateError; buffer->state = kConnectionStateError;
if (buffer->displayPtr) if (buffer->displayPtr) {
{
static char message[] = "\pDNR lookup failed: $xxxx"; static char message[] = "\pDNR lookup failed: $xxxx";
Int2Hex(buffer->dnr.DNRstatus, message + 21, 4); Int2Hex(buffer->dnr.DNRstatus, message + 21, 4);
buffer->displayPtr(message); buffer->displayPtr(message);
@ -101,26 +90,24 @@ Word ConnectionPoll(Connection *buffer)
} }
} }
if (state == kConnectionStateConnecting || state == kConnectionStateDisconnecting) if (state == kConnectionStateConnecting ||
{ state == kConnectionStateDisconnecting) {
Word terr; Word terr;
static srBuff sr; static srBuff sr;
terr = TCPIPStatusTCP(buffer->ipid, &sr); terr = TCPIPStatusTCP(buffer->ipid, &sr);
if (state == kConnectionStateDisconnecting) if (state == kConnectionStateDisconnecting) {
{
// these are not errors. // these are not errors.
if (terr == tcperrConClosing || terr == tcperrClosing) if (terr == tcperrConClosing || terr == tcperrClosing)
terr = tcperrOK; terr = tcperrOK;
} }
if (terr || _toolErr) if (terr || _toolErr) {
{ // CloseAndLogout(buffer);
//CloseAndLogout(buffer);
//s16_debug_printf("terr = %04x tool error = %04x\n", terr, _toolErr); // s16_debug_printf("terr = %04x tool error = %04x\n", terr, _toolErr);
//s16_debug_srbuff(&sr); // s16_debug_srbuff(&sr);
TCPIPCloseTCP(buffer->ipid); TCPIPCloseTCP(buffer->ipid);
TCPIPLogout(buffer->ipid); TCPIPLogout(buffer->ipid);
@ -130,16 +117,16 @@ Word ConnectionPoll(Connection *buffer)
return -1; return -1;
} }
if (sr.srState == TCPSESTABLISHED) // && state == kConnectionStateConnecting) if (sr.srState ==
TCPSESTABLISHED) // && state == kConnectionStateConnecting)
{ {
buffer->state = kConnectionStateConnected; buffer->state = kConnectionStateConnected;
return 1; return 1;
} }
if (sr.srState == TCPSCLOSED || sr.srState == TCPSTIMEWAIT) if (sr.srState == TCPSCLOSED || sr.srState == TCPSTIMEWAIT) {
{
// s16_debug_srbuff(&sr);
//s16_debug_srbuff(&sr);
TCPIPLogout(buffer->ipid); TCPIPLogout(buffer->ipid);
buffer->ipid = 0; buffer->ipid = 0;
@ -151,14 +138,15 @@ Word ConnectionPoll(Connection *buffer)
return 0; return 0;
} }
Word ConnectionOpenC(Connection *buffer, const char *host, Word port) Word ConnectionOpenC(Connection *buffer, const char *host, Word port) {
{
Word length; Word length;
if (!host) return -1; if (!host)
return -1;
length = strlen(host); length = strlen(host);
if (length > 255) return -1; if (length > 255)
return -1;
pstring[0] = length & 0xff; pstring[0] = length & 0xff;
memcpy(pstring + 1, host, length); memcpy(pstring + 1, host, length);
@ -166,39 +154,38 @@ Word ConnectionOpenC(Connection *buffer, const char *host, Word port)
return ConnectionOpen(buffer, pstring, port); return ConnectionOpen(buffer, pstring, port);
} }
Word ConnectionOpenGS(Connection *buffer, const GSString255 *host, Word port) Word ConnectionOpenGS(Connection *buffer, const GSString255 *host, Word port) {
{ if (!host)
if (!host) return -1; return -1;
if (host->length > 255) return -1; if (host->length > 255)
return -1;
pstring[0] = host->length & 0xff; pstring[0] = host->length & 0xff;
memcpy(pstring + 1, host->text, host->length); memcpy(pstring + 1, host->text, host->length);
return ConnectionOpen(buffer, pstring, port); return ConnectionOpen(buffer, pstring, port);
} }
Word ConnectionOpen(Connection *buffer, const char *host, Word port) Word ConnectionOpen(Connection *buffer, const char *host, Word port) {
{
buffer->state = 0; buffer->state = 0;
buffer->ipid = 0; buffer->ipid = 0;
buffer->terr = 0; buffer->terr = 0;
buffer->port = port; buffer->port = port;
if (!buffer || !*buffer || !host || !*host) return -1; if (!buffer || !*buffer || !host || !*host)
return -1;
// 1. check if we need to do DNR. // 1. check if we need to do DNR.
if (TCPIPValidateIPString(host)) if (TCPIPValidateIPString(host)) {
{
cvtRec cvt; cvtRec cvt;
TCPIPConvertIPToHex(&cvt, host); TCPIPConvertIPToHex(&cvt, host);
buffer->dnr.DNRIPaddress = cvt.cvtIPAddress; buffer->dnr.DNRIPaddress = cvt.cvtIPAddress;
buffer->dnr.DNRstatus = DNR_OK; // fake it. buffer->dnr.DNRstatus = DNR_OK; // fake it.
return LoginAndOpen(buffer); return LoginAndOpen(buffer);
} }
// do dnr. // do dnr.
if (buffer->displayPtr) if (buffer->displayPtr) {
{
static char message[256] = "\pDNR lookup: "; static char message[256] = "\pDNR lookup: ";
BlockMove(host + 1, message + 13, host[0]); BlockMove(host + 1, message + 13, host[0]);
message[0] = 13 + host[0]; message[0] = 13 + host[0];
@ -206,11 +193,9 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port)
} }
TCPIPDNRNameToIP(host, &buffer->dnr); TCPIPDNRNameToIP(host, &buffer->dnr);
if (_toolErr) if (_toolErr) {
{
buffer->state = kConnectionStateError; buffer->state = kConnectionStateError;
if (buffer->displayPtr) if (buffer->displayPtr) {
{
static char message[] = "\pDNR lookup tool error: $xxxx"; static char message[] = "\pDNR lookup tool error: $xxxx";
Int2Hex(_toolErr, message + 25, 4); Int2Hex(_toolErr, message + 25, 4);
buffer->displayPtr(message); buffer->displayPtr(message);
@ -221,8 +206,8 @@ Word ConnectionOpen(Connection *buffer, const char *host, Word port)
return 0; return 0;
} }
void ConnectionInit(Connection *buffer, Word memID, ConnectionCallback displayPtr) void ConnectionInit(Connection *buffer, Word memID,
{ ConnectionCallback displayPtr) {
buffer->memID = memID; buffer->memID = memID;
buffer->ipid = 0; buffer->ipid = 0;
buffer->terr = 0; buffer->terr = 0;
@ -233,18 +218,15 @@ void ConnectionInit(Connection *buffer, Word memID, ConnectionCallback displayPt
buffer->displayPtr = displayPtr; buffer->displayPtr = displayPtr;
} }
Word ConnectionClose(Connection *buffer) Word ConnectionClose(Connection *buffer) {
{
Word state = buffer->state; Word state = buffer->state;
// todo -- how do you close if not yet connected? // todo -- how do you close if not yet connected?
if (state == kConnectionStateConnected) if (state == kConnectionStateConnected) {
{
buffer->state = kConnectionStateDisconnecting; buffer->state = kConnectionStateDisconnecting;
buffer->terr = TCPIPCloseTCP(buffer->ipid); buffer->terr = TCPIPCloseTCP(buffer->ipid);
if (buffer->displayPtr) if (buffer->displayPtr) {
{
static char message[] = "\pClosing connection: $0000"; static char message[] = "\pClosing connection: $0000";
Int2Hex(buffer->terr, message + 22, 4); Int2Hex(buffer->terr, message + 22, 4);
buffer->displayPtr(message); buffer->displayPtr(message);
@ -252,13 +234,11 @@ Word ConnectionClose(Connection *buffer)
return 0; return 0;
} }
if (state == kConnectionStateDNR) if (state == kConnectionStateDNR) {
{
TCPIPCancelDNR(&buffer->dnr); TCPIPCancelDNR(&buffer->dnr);
buffer->state = 0; buffer->state = 0;
if (buffer->displayPtr) if (buffer->displayPtr) {
{
static char message[] = "\pDNR lookup canceled"; static char message[] = "\pDNR lookup canceled";
buffer->displayPtr(message); buffer->displayPtr(message);
} }
@ -267,4 +247,3 @@ Word ConnectionClose(Connection *buffer)
return -1; return -1;
} }

View File

@ -25,8 +25,6 @@ typedef struct Connection {
ConnectionCallback displayPtr; ConnectionCallback displayPtr;
} Connection; } Connection;
void ConnectionInit(Connection *, Word memID, ConnectionCallback displayPtr); void ConnectionInit(Connection *, Word memID, ConnectionCallback displayPtr);
Word ConnectionOpen(Connection *, const char *host, Word port); Word ConnectionOpen(Connection *, const char *host, Word port);
@ -36,5 +34,4 @@ Word ConnectionOpenGS(Connection *, const GSString255 *host, Word port);
Word ConnectionClose(Connection *); Word ConnectionClose(Connection *);
Word ConnectionPoll(Connection *); Word ConnectionPoll(Connection *);
#endif #endif

382
main.c
View File

@ -1,25 +1,24 @@
#pragma optimize 79 #pragma optimize 79
#pragma lint -1 #pragma lint - 1
#include <Locator.h> #include <Locator.h>
#include <tcpip.h>
#include <MiscTool.h>
#include <Memory.h> #include <Memory.h>
#include <MiscTool.h>
#include <tcpip.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include "connection.h" #include "connection.h"
#define IncBusy() asm { jsl 0xE10064 } #define IncBusy() asm { jsl 0xE10064}
#define DecBusy() asm { jsl 0xE10068 } #define DecBusy() asm { jsl 0xE10068}
#define Resched() asm { cop 0x7f } #define Resched() asm { cop 0x7f}
#define BusyFlag ((byte *)0xE100FFl) #define BusyFlag ((byte *)0xE100FFl)
// startup/shutdown flags. // startup/shutdown flags.
enum { enum {
kLoaded = 1, kLoaded = 1,
@ -30,45 +29,42 @@ enum {
kVersionError = -2 kVersionError = -2
}; };
int StartUpTCP(displayPtr fx) int StartUpTCP(displayPtr fx) {
{
word status; word status;
word flags = 0; word flags = 0;
// TCPIP is an init, not a tool, so it should always // TCPIP is an init, not a tool, so it should always
// be loaded. // be loaded.
status = TCPIPStatus(); status = TCPIPStatus();
if (_toolErr) if (_toolErr) {
{
LoadOneTool(54, 0x0300); LoadOneTool(54, 0x0300);
if (_toolErr == toolVersionErr) return kVersionError; if (_toolErr == toolVersionErr)
if (_toolErr) return kLoadError; return kVersionError;
if (_toolErr)
return kLoadError;
status = 0; status = 0;
flags |= kLoaded; flags |= kLoaded;
} }
// require 3.0b3 // require 3.0b3
if (TCPIPLongVersion() < 0x03006003) if (TCPIPLongVersion() < 0x03006003) {
{
if (flags & kLoaded) if (flags & kLoaded)
UnloadOneTool(54); UnloadOneTool(54);
return kVersionError; return kVersionError;
} }
if (!status) if (!status) {
{
TCPIPStartUp(); TCPIPStartUp();
if (_toolErr) return kLoadError; if (_toolErr)
return kLoadError;
flags |= kStarted; flags |= kStarted;
} }
status = TCPIPGetConnectStatus(); status = TCPIPGetConnectStatus();
if (!status) if (!status) {
{
TCPIPConnect(fx); TCPIPConnect(fx);
flags |= kConnected; flags |= kConnected;
} }
@ -76,89 +72,77 @@ int StartUpTCP(displayPtr fx)
return flags; return flags;
} }
void ShutDownTCP(int flags, Boolean force, displayPtr fx) void ShutDownTCP(int flags, Boolean force, displayPtr fx) {
{ if (flags <= 0)
if (flags <= 0) return; return;
if (flags & kConnected) if (flags & kConnected) {
{
TCPIPDisconnect(force, fx); TCPIPDisconnect(force, fx);
if (_toolErr) return; if (_toolErr)
return;
} }
if (flags & kStarted) if (flags & kStarted) {
{
TCPIPShutDown(); TCPIPShutDown();
if (_toolErr) return; if (_toolErr)
return;
} }
if (flags & kLoaded) if (flags & kLoaded) {
{
UnloadOneTool(54); UnloadOneTool(54);
} }
} }
// #pragma databank [push | pop] would be nice... // #pragma databank [push | pop] would be nice...
#pragma databank 1 #pragma databank 1
pascal void DisplayCallback(const char *message) pascal void DisplayCallback(const char *message) {
{
unsigned length; unsigned length;
// message is a p-string. // message is a p-string.
length = message ? message[0] : 0; length = message ? message[0] : 0;
if (!length) return; if (!length)
return;
fprintf(stderr, "%.*s\n", length, message + 1); fprintf(stderr, "%.*s\n", length, message + 1);
} }
#pragma databank 0 #pragma databank 0
int ConnectLoop(char *host, Word port, Connection *connection) {
int ConnectLoop(char *host, Word port, Connection *connection)
{
LongWord qtick; LongWord qtick;
ConnectionInit(connection, MMStartUp(), DisplayCallback); ConnectionInit(connection, MMStartUp(), DisplayCallback);
ConnectionOpenC(connection, host, port); ConnectionOpenC(connection, host, port);
// 30 second timeout. // 30 second timeout.
qtick = GetTick() + 30 * 60; qtick = GetTick() + 30 * 60;
while (!ConnectionPoll(connection)) while (!ConnectionPoll(connection)) {
{ if (GetTick() >= qtick) {
if (GetTick() >= qtick)
{
fprintf(stderr, "Connection timed out.\n"); fprintf(stderr, "Connection timed out.\n");
IncBusy(); IncBusy();
TCPIPAbortTCP(connection->ipid); TCPIPAbortTCP(connection->ipid);
TCPIPLogout(connection->ipid); TCPIPLogout(connection->ipid);
DecBusy(); DecBusy();
return 0; return 0;
} }
} }
if (connection->state != kConnectionStateConnected) if (connection->state != kConnectionStateConnected) {
{ fprintf(stderr, "Unable to open host: %s:%u\n", host, port);
fprintf(stderr, "Unable to open host: %s:%u\n",
host,
port);
return 0; return 0;
} }
return 1; return 1;
} }
int CloseLoop(Connection *connection) {
ConnectionClose(connection);
int CloseLoop(Connection *connection) while (!ConnectionPoll(connection))
{ ; // wait for it to close.
ConnectionClose(connection);
while (!ConnectionPoll(connection)) ; // wait for it to close. return 1;
return 1;
} }
static char buffer[512]; static char buffer[512];
int ReadLineSync(word ipid) { int ReadLineSync(word ipid) {
@ -169,171 +153,184 @@ int ReadLineSync(word ipid) {
unsigned x; unsigned x;
word terr; word terr;
// asm { brk 0xea }
//asm { brk 0xea }
buffer[0] = 0; buffer[0] = 0;
qtick = GetTick() + 30 * 60; qtick = GetTick() + 30 * 60;
for(;;) { for (;;) {
Word terr; Word terr;
TCPIPPoll(); TCPIPPoll();
terr = TCPIPStatusTCP(ipid, &sr); terr = TCPIPStatusTCP(ipid, &sr);
if (sr.srRcvQueued) break; if (sr.srRcvQueued)
break;
if (terr) return -1; if (terr)
return -1;
if (GetTick() >= qtick) { if (GetTick() >= qtick) {
fprintf(stderr, "Read timed out.\n"); fprintf(stderr, "Read timed out.\n");
return -1; return -1;
} }
} }
for(;;) { for (;;) {
terr = TCPIPReadLineTCP(ipid, "\p\r\n", 0x0000, (Ref)&buffer, sizeof(buffer) - 1, &rlr); terr = TCPIPReadLineTCP(ipid, "\p\r\n", 0x0000, (Ref)&buffer,
/* if (terr) return -1; */ /* nb - marinetti return bug */ sizeof(buffer) - 1, &rlr);
if (!rlr.rlrIsDataFlag) { /* if (terr) return -1; */ /* nb - marinetti return bug */
if (!rlr.rlrIsDataFlag) {
if (GetTick() >= qtick) { if (GetTick() >= qtick) {
fprintf(stderr, "Read timed out.\n"); fprintf(stderr, "Read timed out.\n");
return -1; return -1;
} }
TCPIPPoll(); TCPIPPoll();
continue; continue;
} }
break; break;
} }
x = rlr.rlrBuffCount; x = rlr.rlrBuffCount;
buffer[x] = 0; buffer[x] = 0;
return x; return x;
} }
int status(void) { int status(void) {
unsigned x; unsigned x;
if (sscanf(buffer, "%u", &x) == 1) { if (sscanf(buffer, "%u", &x) == 1) {
fprintf(stderr, "status: %d\n", x); fprintf(stderr, "status: %d\n", x);
return x; return x;
} }
return -1; return -1;
} }
int client(word ipid) { int client(word ipid) {
word terr; word terr;
int ok; int ok;
/* also checks for 220 header. */ /* also checks for 220 header. */
ok = ReadLineSync(ipid); ok = ReadLineSync(ipid);
if (ok < 0) return ok; if (ok < 0)
ok = status(); return ok;
if (ok != 220) return -1; ok = status();
if (ok != 220)
return -1;
terr = TCPIPWriteTCP(ipid, "CLIENT dict-iigs\r\n", 18, 1, 0); terr = TCPIPWriteTCP(ipid, "CLIENT dict-iigs\r\n", 18, 1, 0);
if (terr != 0) fprintf(stderr, "terr: %04x\n", terr); if (terr != 0)
fprintf(stderr, "terr: %04x\n", terr);
ok = ReadLineSync(ipid); ok = ReadLineSync(ipid);
if (ok < 0) return ok; if (ok < 0)
return ok;
/* /*
3.6.2. Responses 3.6.2. Responses
250 ok (optional timing information here) 250 ok (optional timing information here)
*/ */
ok = status(); ok = status();
if (ok != 250) return -1; if (ok != 250)
return 0; return -1;
return 0;
} }
int quit(word ipid) { int quit(word ipid) {
word terr; word terr;
int ok; int ok;
terr = TCPIPWriteTCP(ipid, "QUIT\r\n", 6, 1, 0); terr = TCPIPWriteTCP(ipid, "QUIT\r\n", 6, 1, 0);
if (terr != 0) fprintf(stderr, "terr: %04x\n", terr); if (terr != 0)
ok = ReadLineSync(ipid); fprintf(stderr, "terr: %04x\n", terr);
if (ok < 0) return ok; ok = ReadLineSync(ipid);
if (ok < 0)
return ok;
/* /*
3.9.2. Responses 3.9.2. Responses
221 Closing Connection 221 Closing Connection
*/ */
return 0;
return 0;
} }
int one_def(Word ipid) { int one_def(Word ipid) {
int ok; int ok;
for(;;) { for (;;) {
ok = ReadLineSync(ipid); ok = ReadLineSync(ipid);
if (ok < 0) return ok; if (ok < 0)
ok = status(); return ok;
if (ok == 250) return 0; ok = status();
if (ok != 151) return -1; if (ok == 250)
for(;;) { return 0;
ok = ReadLineSync(ipid); if (ok != 151)
if (ok < 0) return ok; return -1;
if (buffer[0] == '.') { for (;;) {
fputc('\n', stdout); ok = ReadLineSync(ipid);
break; if (ok < 0)
} return ok;
fputs(buffer, stdout); if (buffer[0] == '.') {
fputc('\n', stdout); fputc('\n', stdout);
} break;
}
fputs(buffer, stdout);
} fputc('\n', stdout);
fputc('\n', stdout); }
return 0; }
fputc('\n', stdout);
return 0;
} }
int define(Word ipid, const char *term, const char *dict) { int define(Word ipid, const char *term, const char *dict) {
word terr; word terr;
int ok; int ok;
unsigned x; unsigned x;
static char buffer[512]; static char buffer[512];
if (!dict || !*dict) dict = "!"; if (!dict || !*dict)
if (!term || !*term) return -1; dict = "!";
if (!term || !*term)
return -1;
x = sprintf(buffer, "DEFINE %s \"%s\"\r\n", dict, term); x = sprintf(buffer, "DEFINE %s \"%s\"\r\n", dict, term);
terr = TCPIPWriteTCP(ipid, buffer, x, 1, 0); terr = TCPIPWriteTCP(ipid, buffer, x, 1, 0);
if (terr != 0) fprintf(stderr, "terr: %04x\n", terr); if (terr != 0)
fprintf(stderr, "terr: %04x\n", terr);
/* /*
3.2.2. Responses 3.2.2. Responses
550 Invalid database, use "SHOW DB" for list of databases 550 Invalid database, use "SHOW DB" for list of databases
552 No match 552 No match
150 n definitions retrieved - definitions follow 150 n definitions retrieved - definitions follow
151 word database name - text follows 151 word database name - text follows
250 ok (optional timing information here) 250 ok (optional timing information here)
*/ */
ok = ReadLineSync(ipid); ok = ReadLineSync(ipid);
if (ok < 0) return ok; if (ok < 0)
return ok;
ok = status(); ok = status();
switch(status()) { switch (status()) {
default: return -1; default:
return -1;
case 550: case 550:
fprintf(stdout, "Invalid database.\n"); fprintf(stdout, "Invalid database.\n");
return -1; return -1;
case 552: case 552:
fprintf(stdout, "No match.\n"); fprintf(stdout, "No match.\n");
return 0; return 0;
case 150: case 150:
return one_def(ipid); return one_def(ipid);
} }
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
Connection connection; Connection connection;
int mf; int mf;
int ok; int ok;
@ -341,31 +338,32 @@ int main(int argc, char **argv) {
mf = StartUpTCP(DisplayCallback); mf = StartUpTCP(DisplayCallback);
if (argc < 1) exit(1); if (argc < 1)
exit(1);
if (mf < 0) { if (mf < 0) {
fprintf(stderr, "Marinetti 3.0b3 or greater is required.\n"); fprintf(stderr, "Marinetti 3.0b3 or greater is required.\n");
exit(1); exit(1);
} }
ok = ConnectLoop("dict.org", 2628, &connection); ok = ConnectLoop("dict.org", 2628, &connection);
if (ok) { if (ok) {
unsigned i; unsigned i;
int ok; int ok;
ok = client(connection.ipid); ok = client(connection.ipid);
if (ok == 0) { if (ok == 0) {
for (i = 1; i < argc; ++i) { for (i = 1; i < argc; ++i) {
ok = define(connection.ipid, argv[i], NULL); ok = define(connection.ipid, argv[i], NULL);
if (ok < 0) break; if (ok < 0)
} break;
} }
}
quit(connection.ipid); quit(connection.ipid);
CloseLoop(&connection); CloseLoop(&connection);
} }
ShutDownTCP(mf, false, DisplayCallback); ShutDownTCP(mf, false, DisplayCallback);
return 0; return 0;
} }