clang-format

This commit is contained in:
Kelvin Sherlock 2018-11-22 00:00:04 -05:00
parent 828ee953ac
commit 3ea20b057c
8 changed files with 916 additions and 1027 deletions

View File

@ -2,9 +2,9 @@
#pragma lint -1 #pragma lint -1
#pragma optimize -1 #pragma optimize -1
#include <IntMath.h>
#include <Memory.h> #include <Memory.h>
#include <Resources.h> #include <Resources.h>
#include <IntMath.h>
#include <texttool.h> #include <texttool.h>
#include "macroman.h" #include "macroman.h"
@ -23,11 +23,9 @@ char tmp[6];
} }
#endif #endif
extern pascal Word Random(void) inline(0x8604, dispatcher); extern pascal Word Random(void) inline(0x8604, dispatcher);
Handle LoadQuote(word mID, Word rFile) Handle LoadQuote(word mID, Word rFile) {
{
Word oFile; Word oFile;
Word oDepth; Word oDepth;
@ -37,7 +35,6 @@ Word rCount;
Handle rHandle; Handle rHandle;
Handle h; Handle h;
h = NULL; h = NULL;
oFile = GetCurResourceFile(); oFile = GetCurResourceFile();
@ -47,8 +44,7 @@ Handle h;
// printint("rCount: ", rCount); // printint("rCount: ", rCount);
if (rCount) if (rCount) {
{
WordDivRec wdr; WordDivRec wdr;
longword index; longword index;
@ -61,11 +57,9 @@ Handle h;
// todo - repeat above until index out of range // todo - repeat above until index out of range
// printint("index: ", index); // printint("index: ", index);
rHandle = LoadResource(rTextForLETextBox2, index); rHandle = LoadResource(rTextForLETextBox2, index);
// printint("loadres: ", _toolErr); // printint("loadres: ", _toolErr);
if (!_toolErr) if (!_toolErr) {
{
word oldLen; word oldLen;
word newLen; word newLen;
char *newText; char *newText;
@ -78,8 +72,7 @@ Handle h;
// printint("oldLen: ", oldLen); // printint("oldLen: ", oldLen);
h = NewHandle(oldLen << 2 + 2, mID, 0, NULL); h = NewHandle(oldLen << 2 + 2, mID, 0, NULL);
if (!_toolErr) if (!_toolErr) {
{
HLock(h); HLock(h);
HLock(rHandle); HLock(rHandle);
@ -88,15 +81,13 @@ Handle h;
newLen = 0; newLen = 0;
i = 0; i = 0;
while (i < oldLen) while (i < oldLen) {
{
char c; char c;
c = *oldText++; c = *oldText++;
i++; i++;
if (c == '\r') if (c == '\r') {
{
*((Word *)newText) = 0x0A0D; *((Word *)newText) = 0x0A0D;
newText += 2; newText += 2;
newLen += 2; newLen += 2;
@ -110,8 +101,7 @@ Handle h;
if (c == 0x01) // formatting codes. if (c == 0x01) // formatting codes.
{ {
c = *oldText; c = *oldText;
switch (c) switch (c) {
{
case 'F': // font case 'F': // font
oldText += 5; oldText += 5;
i += 5; i += 5;
@ -140,23 +130,21 @@ Handle h;
c &= 0x7f; c &= 0x7f;
j = macroman[c].length; j = macroman[c].length;
if (j == 0) continue; if (j == 0)
continue;
if (j > 1) if (j > 1) {
{
char *cp; char *cp;
cp = macroman[c].cp; cp = macroman[c].cp;
newLen += j; newLen += j;
do do {
{
*newText++ = *cp++; *newText++ = *cp++;
} } while (--j);
while (--j);
continue; continue;
} } else
else c = (char)macroman[c].cp; c = (char)macroman[c].cp;
} }
newLen++; newLen++;

View File

@ -14,7 +14,6 @@
#include "qserver.h" #include "qserver.h"
extern Handle rPath; extern Handle rPath;
static Word fd; static Word fd;
@ -24,8 +23,7 @@ static Word fd;
* return 0 on failure, anything else on success. * return 0 on failure, anything else on success.
*/ */
// //
Word LoadConfig(Word MyID) Word LoadConfig(Word MyID) {
{
Word t; Word t;
Word oFile; Word oFile;
Word oDepth; Word oDepth;
@ -34,8 +32,8 @@ static GSString32 filePath = {28, "*:System:Preferences:QServer"};
static GSString32 folderPath = {21, "*:System:Preferences:"}; static GSString32 folderPath = {21, "*:System:Preferences:"};
static FileInfoRecGS InfoDCB = {12, (GSString255Ptr)&filePath}; static FileInfoRecGS InfoDCB = {12, (GSString255Ptr)&filePath};
static CreateRecGS CreateDCB = {4, (GSString255Ptr)&folderPath, 0xe3, 0x0f, 0}; static CreateRecGS CreateDCB = {4, (GSString255Ptr)&folderPath, 0xe3, 0x0f,
0};
// 1 - check if file exists // 1 - check if file exists
// 2 - if no, create the folder and file // 2 - if no, create the folder and file
@ -46,20 +44,22 @@ static CreateRecGS CreateDCB = {4, (GSString255Ptr)&folderPath, 0xe3, 0x0f, 0};
GetFileInfoGS(&InfoDCB); GetFileInfoGS(&InfoDCB);
t = _toolErr; t = _toolErr;
if (_toolErr == pathNotFound) if (_toolErr == pathNotFound) {
{
CreateGS(&CreateDCB); CreateGS(&CreateDCB);
if (!_toolErr) t = fileNotFound; if (!_toolErr)
t = fileNotFound;
} }
if (t == fileNotFound) // file doesn't exist, create if (t == fileNotFound) // file doesn't exist, create
{ {
CreateResourceFile(0, 0x5A, 0xe3, (Pointer)&filePath); CreateResourceFile(0, 0x5A, 0xe3, (Pointer)&filePath);
if (_toolErr) return 0; if (_toolErr)
} return 0;
else if (t) return 0; } else if (t)
return 0;
fd = OpenResourceFile(readWriteEnable, NULL, (Pointer)&filePath); fd = OpenResourceFile(readWriteEnable, NULL, (Pointer)&filePath);
if (_toolErr) return 0; if (_toolErr)
return 0;
// make sure we're the only resource file... // make sure we're the only resource file...
oFile = GetCurResourceFile(); oFile = GetCurResourceFile();
@ -69,13 +69,11 @@ static CreateRecGS CreateDCB = {4, (GSString255Ptr)&folderPath, 0xe3, 0x0f, 0};
// load the quote path. // load the quote path.
rPath = LoadResource(rC1InputString, 1); rPath = LoadResource(rC1InputString, 1);
if (_toolErr) if (_toolErr) {
{
static GSString255 defPath = {34, "*/system/CDEVs/Twilight/QuotesFile"}; static GSString255 defPath = {34, "*/system/CDEVs/Twilight/QuotesFile"};
rPath = NewHandle(36, MyID, 0, NULL); rPath = NewHandle(36, MyID, 0, NULL);
if (rPath) if (rPath) {
{
PtrToHand((Pointer)defPath, rPath, 36); PtrToHand((Pointer)defPath, rPath, 36);
AddResource(rPath, 0, rC1InputString, 1); AddResource(rPath, 0, rC1InputString, 1);
} }
@ -89,9 +87,9 @@ static CreateRecGS CreateDCB = {4, (GSString255Ptr)&folderPath, 0xe3, 0x0f, 0};
return 1; return 1;
} }
void UnloadConfig(void) void UnloadConfig(void) {
{ if (fd)
if (fd) CloseResourceFile(fd); CloseResourceFile(fd);
fd = 0; fd = 0;
} }
@ -99,16 +97,14 @@ void UnloadConfig(void)
* callback from SFGetFile2. only allows if resource fork found. * callback from SFGetFile2. only allows if resource fork found.
*/ */
#pragma toolparms 1 #pragma toolparms 1
Word SFFilter(DirEntryRecGS *file) Word SFFilter(DirEntryRecGS *file) {
{ if (file->flags & 0x8000)
if (file->flags & 0x8000) return displaySelect; return displaySelect;
return noSelect; return noSelect;
} }
#pragma toolparms 0 #pragma toolparms 0
static void SetText(WindowPtr win, Word id, void *data) {
static void SetText(WindowPtr win, Word id, void *data)
{
GSString255 *gstr = (GSString255 *)data; GSString255 *gstr = (GSString255 *)data;
CtlRecHndl CtrlHand; CtlRecHndl CtrlHand;
Rect r; Rect r;
@ -128,8 +124,7 @@ Rect r;
} }
} }
void DoConfig(Word MyID) void DoConfig(Word MyID) {
{
static EventRecord event; static EventRecord event;
WindowPtr win; WindowPtr win;
@ -143,8 +138,8 @@ Handle newPath = NULL;
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.wmTaskMask = 0x001f0004; event.wmTaskMask = 0x001f0004;
win = NewWindow2(NULL, NULL, NULL, NULL, win = NewWindow2(NULL, NULL, NULL, NULL, refIsResource, (long)rConfigWindow,
refIsResource, (long)rConfigWindow, rWindParam1); rWindParam1);
SetPort(win); SetPort(win);
// set the current path text... // set the current path text...
@ -155,33 +150,26 @@ Handle newPath = NULL;
SetText(win, CtrlPath, NULL); SetText(win, CtrlPath, NULL);
} }
for (ok = true; ok;) for (ok = true; ok;) {
{
control = (Word)DoModalWindow(&event, NULL, NULL, NULL, 0x0008); control = (Word)DoModalWindow(&event, NULL, NULL, NULL, 0x0008);
switch(control) switch (control) {
{
case CtrlCancel: case CtrlCancel:
case CtrlOk: case CtrlOk:
ok = false; ok = false;
break; break;
case CtrlBrowse: case CtrlBrowse: {
{
SFReplyRec2 myReply; SFReplyRec2 myReply;
myReply.nameRefDesc = refIsNewHandle; myReply.nameRefDesc = refIsNewHandle;
myReply.pathRefDesc = refIsNewHandle; myReply.pathRefDesc = refIsNewHandle;
SFGetFile2( SFGetFile2(10, 35, refIsPointer, (Ref) "\pSelect quotation file.",
10, 35,
refIsPointer,
(Ref)"\pSelect quotation file.",
(WordProcPtr)SFFilter, /* filter proc */ (WordProcPtr)SFFilter, /* filter proc */
NULL, /* type list */ NULL, /* type list */
&myReply); &myReply);
if (myReply.good) if (myReply.good) {
{
Handle h; Handle h;
Word size; Word size;
@ -193,20 +181,18 @@ Handle newPath = NULL;
SetText(win, CtrlPath, *h); SetText(win, CtrlPath, *h);
if (newPath) DisposeHandle(newPath); if (newPath)
DisposeHandle(newPath);
newPath = h; newPath = h;
DisposeHandle((Handle)myReply.nameRef); DisposeHandle((Handle)myReply.nameRef);
} }
} break;
} }
break;
}
} }
if (control == CtrlOk) // update the config file. if (control == CtrlOk) // update the config file.
{ {
if (newPath) if (newPath) {
{
Word size = (Word)GetHandleSize(newPath); Word size = (Word)GetHandleSize(newPath);
ReAllocHandle(size, MyID, 0, NULL, rPath); ReAllocHandle(size, MyID, 0, NULL, rPath);
@ -220,5 +206,4 @@ Handle newPath = NULL;
SetPort(oldPort); SetPort(oldPort);
HUnlock(rPath); HUnlock(rPath);
} }

View File

@ -3,14 +3,16 @@
#include "macroman.h" #include "macroman.h"
#define ONECHAR(x) { 1, (char *)x } #define ONECHAR(x) \
{ 1, (char *)x }
#define MULTICHAR(x) { sizeof(x) -1, x } #define MULTICHAR(x) \
{ sizeof(x) - 1, x }
#define BLANK { 0, (char *)0 } #define BLANK \
{ 0, (char *)0 }
struct charmap macroman[128] = struct charmap macroman[128] = {
{
ONECHAR('A'), // 0x80 ONECHAR('A'), // 0x80
ONECHAR('A'), ONECHAR('A'),
ONECHAR('C'), ONECHAR('C'),

View File

@ -1,8 +1,7 @@
#ifndef __MACROMAN_H__ #ifndef __MACROMAN_H__
#define __MACROMAN_H__ #define __MACROMAN_H__
struct charmap struct charmap {
{
int length; int length;
char *cp; char *cp;
}; };

View File

@ -10,45 +10,42 @@
#define FLAG_CONNECTED 4 #define FLAG_CONNECTED 4
#define FLAG_ERROR 0xffff #define FLAG_ERROR 0xffff
void stopMarinetti(int flag) void stopMarinetti(int flag) {
{ if (flag == FLAG_ERROR)
if (flag == FLAG_ERROR) return; return;
if (flag == 0) return; if (flag == 0)
if (flag & FLAG_CONNECTED) return;
{ if (flag & FLAG_CONNECTED) {
TCPIPDisconnect(0, 0); TCPIPDisconnect(0, 0);
if (_toolErr) return; if (_toolErr)
return;
} }
if (flag & FLAG_STARTED) TCPIPShutDown(); if (flag & FLAG_STARTED)
if (flag & FLAG_LOADED) UnloadOneTool(0x36); TCPIPShutDown();
if (flag & FLAG_LOADED)
UnloadOneTool(0x36);
} }
/* /*
* do the various steps to start up marinetti. * do the various steps to start up marinetti.
*/ */
int startMarinetti(void) int startMarinetti(void) {
{
int flag = 0; int flag = 0;
TCPIPStatus(); TCPIPStatus();
if (_toolErr) if (_toolErr) {
{
LoadOneTool(0x36, 0x0200); // load Marinetti LoadOneTool(0x36, 0x0200); // load Marinetti
if (_toolErr) return FLAG_ERROR; if (_toolErr)
return FLAG_ERROR;
flag |= FLAG_LOADED; flag |= FLAG_LOADED;
} }
if (!TCPIPStatus()) if (!TCPIPStatus()) {
{
TCPIPStartUp(); TCPIPStartUp();
flag |= FLAG_STARTED; flag |= FLAG_STARTED;
} }
if (!TCPIPGetConnectStatus()) if (!TCPIPGetConnectStatus()) {
{
TCPIPConnect(0); TCPIPConnect(0);
if (_toolErr) if (_toolErr) {
{
stopMarinetti(flag); stopMarinetti(flag);
return FLAG_ERROR; return FLAG_ERROR;
} }
@ -57,17 +54,3 @@ int flag = 0;
return flag; return flag;
} }

262
qserver.c
View File

@ -2,35 +2,32 @@
#pragma lint -1 #pragma lint -1
#pragma optimize -1 #pragma optimize -1
#include <Types.h> #include <Control.h>
#include <GSOS.h>
#include <Memory.h>
#include <Locator.h>
#include <Loader.h>
#include <Desk.h> #include <Desk.h>
#include <Event.h> #include <Event.h>
#include <Window.h>
#include <Control.h>
#include <Resources.h>
#include <Quickdraw.h>
#include <QDAux.h>
#include <Font.h> #include <Font.h>
#include <stdfile.h> #include <GSOS.h>
#include <TextEdit.h> #include <Loader.h>
#include <intmath.h> #include <Locator.h>
#include <Memory.h>
#include <QDAux.h>
#include <Quickdraw.h>
#include <Resources.h>
#include <TCPIP.h> #include <TCPIP.h>
#include <TextEdit.h>
#include <Types.h>
#include <Window.h>
#include <intmath.h>
#include <misctool.h> #include <misctool.h>
#include <stdfile.h>
#include <stdio.h> #include <stdio.h>
#include "qserver.h" #include "qserver.h"
unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef); unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef);
void NDAShutDownTools(StartStopRecord *ssRef); void NDAShutDownTools(StartStopRecord *ssRef);
typedef struct NDAResourceCookie { typedef struct NDAResourceCookie {
Word oldPrefs; Word oldPrefs;
Word oldRApp; Word oldRApp;
@ -41,15 +38,12 @@ void NDAResourceRestore(NDAResourceCookie *cookie);
void NDAResourceShutDown(NDAResourceCookie *cookie); void NDAResourceShutDown(NDAResourceCookie *cookie);
Word NDAResourceStartUp(Word memID, Word access, NDAResourceCookie *cookie); Word NDAResourceStartUp(Word memID, Word access, NDAResourceCookie *cookie);
Handle LoadQuote(word mID, Word rfile); Handle LoadQuote(word mID, Word rfile);
Word LoadConfig(Word MemID); Word LoadConfig(Word MemID);
void UnloadConfig(void); void UnloadConfig(void);
void DoConfig(Word MemID); void DoConfig(Word MemID);
const char *ReqName = "\pTCP/IP~kelvin~qserver~"; const char *ReqName = "\pTCP/IP~kelvin~qserver~";
/* /*
@ -64,13 +58,11 @@ Boolean ToolsLoaded;
Word MyID; Word MyID;
Word Ipid; Word Ipid;
word rFile; word rFile;
Handle rPath; Handle rPath;
word rCount; word rCount;
struct qentry struct qentry {
{
Word ipid; Word ipid;
Word state; Word state;
Longword tick; Longword tick;
@ -82,9 +74,7 @@ struct qentry queue[QSIZE];
word total; word total;
word current; word current;
void fixstats(void) {
void fixstats(void)
{
static char stats[16]; static char stats[16];
Word i; Word i;
@ -95,9 +85,7 @@ Word i;
DrawInfoBar(MyWindow); DrawInfoBar(MyWindow);
} }
void InsertString(word length, char *cp) {
void InsertString(word length, char *cp)
{
Handle handle; Handle handle;
TERecord **temp; TERecord **temp;
longword oldStart, oldEnd; longword oldStart, oldEnd;
@ -110,19 +98,15 @@ longword oldStart, oldEnd;
TEGetSelection((pointer)&oldStart, (pointer)&oldEnd, handle); TEGetSelection((pointer)&oldStart, (pointer)&oldEnd, handle);
TESetSelection((Pointer)-1, (Pointer)-1, handle); TESetSelection((Pointer)-1, (Pointer)-1, handle);
TEInsert(teDataIsTextBlock, (Ref)cp, length, TEInsert(teDataIsTextBlock, (Ref)cp, length, NULL, NULL, /* no style info */
NULL, NULL, /* no style info */
handle); handle);
(**temp).textFlags |= fReadOnly; (**temp).textFlags |= fReadOnly;
TESetSelection((Pointer)oldStart, (Pointer)oldEnd, handle); TESetSelection((Pointer)oldStart, (Pointer)oldEnd, handle);
} }
enum {
enum
{
STATE_NULL = 0, STATE_NULL = 0,
STATE_ESTABLISH, // waiting to establish STATE_ESTABLISH, // waiting to establish
STATE_QUOTE, // send the quote... STATE_QUOTE, // send the quote...
@ -130,8 +114,7 @@ enum
STATE_CLOSE STATE_CLOSE
}; };
void QServer(void) void QServer(void) {
{
static srBuff srBuffer; static srBuff srBuffer;
word delta; word delta;
int i; int i;
@ -139,16 +122,15 @@ int i;
delta = false; delta = false;
TCPIPPoll(); TCPIPPoll();
for (i = 0; i < QSIZE; i++) for (i = 0; i < QSIZE; i++) {
{
word ipid; word ipid;
ipid = queue[i].ipid; ipid = queue[i].ipid;
if (!ipid) continue; if (!ipid)
continue;
TCPIPStatusTCP(ipid, &srBuffer); TCPIPStatusTCP(ipid, &srBuffer);
if (_toolErr) if (_toolErr) {
{
queue[i].ipid = 0; queue[i].ipid = 0;
queue[i].state = 0; queue[i].state = 0;
current--; current--;
@ -156,8 +138,7 @@ int i;
continue; continue;
} }
if (srBuffer.srState == TCPSCLOSED) if (srBuffer.srState == TCPSCLOSED) {
{
TCPIPLogout(ipid); TCPIPLogout(ipid);
queue[i].ipid = 0; queue[i].ipid = 0;
queue[i].state = 0; queue[i].state = 0;
@ -166,9 +147,7 @@ int i;
continue; continue;
} }
switch (queue[i].state) {
switch (queue[i].state)
{
case STATE_ESTABLISH: case STATE_ESTABLISH:
if (srBuffer.srState != TCPSESTABLISHED) if (srBuffer.srState != TCPSESTABLISHED)
break; break;
@ -176,21 +155,15 @@ int i;
queue[i].state = STATE_QUOTE; queue[i].state = STATE_QUOTE;
// drop through and send the quote. // drop through and send the quote.
case STATE_QUOTE: case STATE_QUOTE: {
{
Handle h; Handle h;
h = LoadQuote(MyID, rFile); h = LoadQuote(MyID, rFile);
if (h) if (h) {
{
HLock(h); HLock(h);
TCPIPWriteTCP(ipid, *h, TCPIPWriteTCP(ipid, *h, GetHandleSize(h), false, false);
GetHandleSize(h), false, false);
DisposeHandle(h); DisposeHandle(h);
} } else {
else TCPIPWriteTCP(ipid, "Your quote here!\r\n", 18, false, false);
{
TCPIPWriteTCP(ipid, "Your quote here!\r\n",
18, false, false);
} }
} }
queue[i].state = STATE_SEND; queue[i].state = STATE_SEND;
@ -198,8 +171,7 @@ int i;
case STATE_SEND: case STATE_SEND:
if (srBuffer.srSndQueued == 0) if (srBuffer.srSndQueued == 0) {
{
TCPIPCloseTCP(ipid); TCPIPCloseTCP(ipid);
queue[i].state = STATE_CLOSE; queue[i].state = STATE_CLOSE;
} }
@ -207,18 +179,15 @@ int i;
} }
} }
// check for a new connection. // check for a new connection.
if (current < QSIZE) if (current < QSIZE) {
{
word child; word child;
int i; int i;
child = TCPIPAcceptTCP(Ipid, 0); child = TCPIPAcceptTCP(Ipid, 0);
if (!_toolErr) for (i = 0; i < QSIZE; i++) if (!_toolErr)
{ for (i = 0; i < QSIZE; i++) {
if (!queue[i].ipid) if (!queue[i].ipid) {
{
static char buffer[16]; static char buffer[16];
static char line[32]; static char line[32];
int j; int j;
@ -238,11 +207,9 @@ int i;
total++; total++;
delta = true; delta = true;
TCPIPConvertIPToASCII(srBuffer.srDestIP, TCPIPConvertIPToASCII(srBuffer.srDestIP, buffer, 0);
buffer, 0);
j = sprintf(line, "%p:%u\r", j = sprintf(line, "%p:%u\r", buffer, srBuffer.srDestPort);
buffer, srBuffer.srDestPort);
InsertString(j, line); InsertString(j, line);
@ -250,12 +217,11 @@ int i;
} }
} }
} }
if (delta) fixstats(); // statistics changed. if (delta)
fixstats(); // statistics changed.
} }
int StartServer(void) {
int StartServer(void)
{
int i; int i;
word oFile; word oFile;
word oDepth; word oDepth;
@ -264,8 +230,7 @@ GSString255 *path;
total = current = 0; total = current = 0;
if (!rPath) if (!rPath) {
{
InsertString(32, "Fatal: No quote file specified.\r"); InsertString(32, "Fatal: No quote file specified.\r");
return false; return false;
} }
@ -273,10 +238,10 @@ GSString255 *path;
path = *(GSString255 **)rPath; path = *(GSString255 **)rPath;
rFile = OpenResourceFile(readEnable, NULL, (pointer)path); rFile = OpenResourceFile(readEnable, NULL, (pointer)path);
if (_toolErr) if (_toolErr) {
{
/* todo */ /* todo */
InsertString(sprintf(err, "Fatal: Unable to open %.*s\r", path->length, path->text), InsertString(
sprintf(err, "Fatal: Unable to open %.*s\r", path->length, path->text),
err); err);
return false; return false;
} }
@ -288,10 +253,10 @@ GSString255 *path;
SetCurResourceFile(oFile); SetCurResourceFile(oFile);
SetResourceFileDepth(oDepth); SetResourceFileDepth(oDepth);
if (!rCount) if (!rCount) {
{
/* todo */ /* todo */
InsertString(sprintf(err, "Fatal: Invalid quote file %.*s\r", path->length, path->text), InsertString(sprintf(err, "Fatal: Invalid quote file %.*s\r", path->length,
path->text),
err); err);
CloseResourceFile(rFile); CloseResourceFile(rFile);
@ -300,9 +265,7 @@ GSString255 *path;
SetRandSeed(GetTick()); SetRandSeed(GetTick());
for (i = 0; i < QSIZE; i++) {
for (i = 0; i < QSIZE; i++)
{
queue[i].ipid = 0; queue[i].ipid = 0;
queue[i].state = 0; queue[i].state = 0;
} }
@ -323,21 +286,16 @@ GSString255 *path;
InsertString(16, "QServer started\r"); InsertString(16, "QServer started\r");
return true; return true;
} }
int StopServer(void) int StopServer(void) {
{
int i; int i;
// close any q entries // close any q entries
for (i = 0; i < QSIZE; i++) for (i = 0; i < QSIZE; i++) {
{
int ipid; int ipid;
ipid = queue[i].ipid; ipid = queue[i].ipid;
if (ipid) if (ipid) {
{
TCPIPAbortTCP(ipid); TCPIPAbortTCP(ipid);
TCPIPLogout(ipid); TCPIPLogout(ipid);
queue[i].ipid = 0; queue[i].ipid = 0;
@ -355,7 +313,6 @@ int i;
CloseResourceFile(rFile); CloseResourceFile(rFile);
SetInfoRefCon((LongWord) "\pServer stopped", MyWindow); SetInfoRefCon((LongWord) "\pServer stopped", MyWindow);
DrawInfoBar(MyWindow); DrawInfoBar(MyWindow);
@ -364,10 +321,8 @@ int i;
return true; return true;
} }
// activate/inactivate controls based on Marinetti status // activate/inactivate controls based on Marinetti status
void UpdateStatus(Boolean redraw) void UpdateStatus(Boolean redraw) {
{
if (FlagTCP) // TCP started if (FlagTCP) // TCP started
{ {
// deactivate // deactivate
@ -379,9 +334,7 @@ void UpdateStatus(Boolean redraw)
HiliteCtlByID(noHilite, MyWindow, CtrlStartQS); HiliteCtlByID(noHilite, MyWindow, CtrlStartQS);
SetInfoRefCon((LongWord) "\pNetwork Connected", MyWindow); SetInfoRefCon((LongWord) "\pNetwork Connected", MyWindow);
} } else {
else
{
// activate // activate
HiliteCtlByID(noHilite, MyWindow, CtrlStartM); HiliteCtlByID(noHilite, MyWindow, CtrlStartM);
@ -394,56 +347,44 @@ void UpdateStatus(Boolean redraw)
} }
if (redraw) if (redraw)
DrawInfoBar(MyWindow); DrawInfoBar(MyWindow);
} }
#pragma databank 1 #pragma databank 1
/* /*
* watch for * watch for
*/ */
pascal word HandleRequest(word request, longword dataIn, longword dataOut) pascal word HandleRequest(word request, longword dataIn, longword dataOut) {
{
Word oldRApp; Word oldRApp;
oldRApp = GetCurResourceApp(); oldRApp = GetCurResourceApp();
SetCurResourceApp(MyID); SetCurResourceApp(MyID);
if (request == TCPIPSaysNetworkUp) if (request == TCPIPSaysNetworkUp) {
{
FlagTCP = true; FlagTCP = true;
UpdateStatus(true); UpdateStatus(true);
} }
if (request == TCPIPSaysNetworkDown) if (request == TCPIPSaysNetworkDown) {
{ if (FlagQS)
if (FlagQS) StopServer(); StopServer();
FlagTCP = false; FlagTCP = false;
Ipid = 0; Ipid = 0;
UpdateStatus(true); UpdateStatus(true);
} }
SetCurResourceApp(oldRApp); SetCurResourceApp(oldRApp);
} }
pascal void MarinettiCallback(char *str) pascal void MarinettiCallback(char *str) {
{ if (MyWindow) {
if (MyWindow)
{
SetInfoRefCon((LongWord)str, MyWindow); SetInfoRefCon((LongWord)str, MyWindow);
DrawInfoBar(MyWindow); DrawInfoBar(MyWindow);
} }
} }
pascal void DrawInfo(void *rect, const char *str, GrafPortPtr w) pascal void DrawInfo(void *rect, const char *str, GrafPortPtr w) {
{ if (str) {
if (str)
{
SetForeColor(0x00); SetForeColor(0x00);
SetBackColor(0x0f); SetBackColor(0x0f);
MoveTo(8, 22); MoveTo(8, 22);
@ -451,16 +392,14 @@ pascal void DrawInfo(void *rect, const char *str, GrafPortPtr w)
} }
} }
void DrawWindow(void) void DrawWindow(void) { DrawControls(GetPort()); }
{
DrawControls(GetPort());
}
#pragma databank 0 #pragma databank 0
static StartStopRecord ss = {0,
static StartStopRecord ss = { 0,
0, 0, 0, 0, 0,
0,
4, 4,
{ {
0x12, 0x0000, /* QD Aux */ 0x12, 0x0000, /* QD Aux */
@ -475,9 +414,7 @@ static StartStopRecord ss = {
static NDAResourceCookie resInfo; static NDAResourceCookie resInfo;
GrafPortPtr NDAOpen(void) {
GrafPortPtr NDAOpen(void)
{
MyWindow = NULL; MyWindow = NULL;
@ -489,17 +426,15 @@ GrafPortPtr NDAOpen(void)
ToolsLoaded = true; ToolsLoaded = true;
} }
// Check if Marinetti Active. // Check if Marinetti Active.
FlagTCP = TCPIPGetConnectStatus(); FlagTCP = TCPIPGetConnectStatus();
if (NDAResourceStartUp(MyID, readEnable, &resInfo)) { if (NDAResourceStartUp(MyID, readEnable, &resInfo)) {
LoadConfig(MyID); LoadConfig(MyID);
MyWindow = NewWindow2(NULL, 0, DrawWindow, NULL, MyWindow = NewWindow2(NULL, 0, DrawWindow, NULL, refIsResource, rQSWindow,
refIsResource, rQSWindow, rWindParam1); rWindParam1);
SetInfoDraw(DrawInfo, MyWindow); SetInfoDraw(DrawInfo, MyWindow);
@ -510,18 +445,17 @@ GrafPortPtr NDAOpen(void)
SetSysWindow(MyWindow); SetSysWindow(MyWindow);
ShowWindow(MyWindow); ShowWindow(MyWindow);
SelectWindow(MyWindow); SelectWindow(MyWindow);
} }
NDAResourceRestore(&resInfo); NDAResourceRestore(&resInfo);
return MyWindow; return MyWindow;
} }
void NDAClose(void) void NDAClose(void) {
{
// if running, shut down. // if running, shut down.
if (FlagQS) StopServer(); if (FlagQS)
StopServer();
AcceptRequests(ReqName, MyID, NULL); AcceptRequests(ReqName, MyID, NULL);
CloseWindow(MyWindow); CloseWindow(MyWindow);
@ -531,10 +465,8 @@ void NDAClose(void)
NDAResourceShutDown(&resInfo); NDAResourceShutDown(&resInfo);
} }
void NDAInit(Word code) void NDAInit(Word code) {
{ if (code) {
if (code)
{
MyWindow = NULL; MyWindow = NULL;
FlagTCP = false; FlagTCP = false;
FlagQS = false; FlagQS = false;
@ -542,34 +474,29 @@ void NDAInit(Word code)
MyID = MMStartUp(); MyID = MMStartUp();
Ipid = 0; Ipid = 0;
} } else {
else
{
if (ToolsLoaded) if (ToolsLoaded)
NDAShutDownTools(&ss); NDAShutDownTools(&ss);
ToolsLoaded = false; ToolsLoaded = false;
} }
} }
word NDAAction(void *param, int code) word NDAAction(void *param, int code) {
{
word eventCode; word eventCode;
static EventRecord event = {0}; static EventRecord event = {0};
static word counter = 0; static word counter = 0;
if (code == runAction) if (code == runAction) {
{ if (FlagQS)
if (FlagQS) QServer(); QServer();
return 1; return 1;
} }
else if (code == eventAction) else if (code == eventAction) {
{
BlockMove((Pointer)param, (Pointer)&event, 16); BlockMove((Pointer)param, (Pointer)&event, 16);
event.wmTaskMask = 0x001FFFFF; event.wmTaskMask = 0x001FFFFF;
eventCode = TaskMasterDA(0, &event); eventCode = TaskMasterDA(0, &event);
switch(eventCode) switch (eventCode) {
{
case updateEvt: case updateEvt:
BeginUpdate(MyWindow); BeginUpdate(MyWindow);
DrawWindow(); DrawWindow();
@ -577,32 +504,26 @@ static word counter = 0;
break; break;
case wInControl: case wInControl:
switch (event.wmTaskData4) switch (event.wmTaskData4) {
{
/* start marinetti */ /* start marinetti */
case CtrlStartM: case CtrlStartM:
// //
if (TCPIPGetConnectStatus()) if (TCPIPGetConnectStatus()) {
{
FlagTCP = true; FlagTCP = true;
UpdateStatus(true); UpdateStatus(true);
} } else {
else
{
TCPIPConnect(MarinettiCallback); TCPIPConnect(MarinettiCallback);
} }
break; break;
/* stop marinetti */ /* stop marinetti */
case CtrlStopM: case CtrlStopM:
if (!TCPIPGetConnectStatus()) if (!TCPIPGetConnectStatus()) {
{
FlagTCP = false; FlagTCP = false;
UpdateStatus(true); UpdateStatus(true);
} } else {
else if (FlagQS)
{ StopServer();
if (FlagQS) StopServer();
// if option key down, force a shutdown. // if option key down, force a shutdown.
TCPIPDisconnect(event.modifiers & optionKey, MarinettiCallback); TCPIPDisconnect(event.modifiers & optionKey, MarinettiCallback);
} }
@ -624,13 +545,10 @@ static word counter = 0;
} }
// todo - Command-A selects all. // todo - Command-A selects all.
} }
} } else if (code == copyAction) {
else if (code == copyAction)
{
TECopy(NULL); TECopy(NULL);
return 1; // yes we handled it. return 1; // yes we handled it.
} }
return 0; return 0;
} }

84
tools.c
View File

@ -1,7 +1,11 @@
/* IIgs TN #53: /* IIgs TN #53:
The greatest conflict between applications and desk accessories, especially NDAs, is the use of system tool sets. The Apple IIgs Toolbox Reference, Volume 1, defines the minimum collection of tools sets available to an NDA. The Desk Manager requires that an application start the following tool sets before calling DeskStartUp: The greatest conflict between applications and desk accessories, especially
NDAs, is the use of system tool sets. The Apple IIgs Toolbox Reference, Volume
1, defines the minimum collection of tools sets available to an NDA. The Desk
Manager requires that an application start the following tool sets before
calling DeskStartUp:
Tool Locator (#1) Tool Locator (#1)
Memory Manager (#2) Memory Manager (#2)
@ -15,7 +19,9 @@ LineEdit (#20)
Dialog Manager (#21) Dialog Manager (#21)
Scrap Manager (#22) Scrap Manager (#22)
NDAs may assume that these tools are all present and running, so they do not need to check for their presence. NDAs can also use the following tool sets without special consideration for starting them up: NDAs may assume that these tools are all present and running, so they do not
need to check for their presence. NDAs can also use the following tool sets
without special consideration for starting them up:
Desk Manager Desk Manager
Scheduler Scheduler
@ -24,22 +30,19 @@ Integer Math.
*/ */
#pragma lint -1 #pragma lint -1
#pragma noroot #pragma noroot
#pragma optimize -1 #pragma optimize -1
#include <gsos.h>
#include <intmath.h>
#include <loader.h>
#include <locator.h> #include <locator.h>
#include <memory.h> #include <memory.h>
#include <intmath.h>
#include <resources.h> #include <resources.h>
#include <gsos.h>
#include <loader.h>
extern pascal Word GetMasterSCB(void) inline(0x1704, dispatcher); extern pascal Word GetMasterSCB(void) inline(0x1704, dispatcher);
extern pascal void ListStartUp(void) inline(0x021C, dispatcher); extern pascal void ListStartUp(void) inline(0x021C, dispatcher);
extern pascal void ListShutDown(void) inline(0x031C, dispatcher); extern pascal void ListShutDown(void) inline(0x031C, dispatcher);
extern pascal Word ListVersion(void) inline(0x041C, dispatcher); extern pascal Word ListVersion(void) inline(0x041C, dispatcher);
@ -91,7 +94,8 @@ static char NullString[] = "\p";
static char ok[] = "\pContinue"; static char ok[] = "\pContinue";
static unsigned centerX(void) { static unsigned centerX(void) {
if (GetMasterSCB() & 0x80) return 180; /* (640-280) */ if (GetMasterSCB() & 0x80)
return 180; /* (640-280) */
return 20; /* 320 - 280 */ return 20; /* 320 - 280 */
} }
@ -122,7 +126,6 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
unsigned errors = 0; unsigned errors = 0;
unsigned level = 0; unsigned level = 0;
ssRef->resFileID = 0; ssRef->resFileID = 0;
ssRef->dPageHandle = 0; ssRef->dPageHandle = 0;
@ -144,37 +147,48 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
tn &= 0x00ff; tn &= 0x00ff;
switch (tn) { switch (tn) {
case 0x0a: case 0x0a:
if (SANEStatus() && !_toolErr) tn |= 0x8000; if (SANEStatus() && !_toolErr)
else dp += 0x0100; tn |= 0x8000;
else
dp += 0x0100;
break; break;
case 0x12: case 0x12:
if (QDAuxStatus() && !_toolErr) tn |= 0x8000; if (QDAuxStatus() && !_toolErr)
tn |= 0x8000;
break; break;
case 0x13: case 0x13:
if (PMStatus() && !_toolErr) tn |= 0x8000; if (PMStatus() && !_toolErr)
else dp += 0x0200; tn |= 0x8000;
else
dp += 0x0200;
break; break;
case 0x17: case 0x17:
if (SFStatus() && !_toolErr) tn |= 0x8000; if (SFStatus() && !_toolErr)
else dp += 0x0100; tn |= 0x8000;
else
dp += 0x0100;
break; break;
case 0x1b: case 0x1b:
if (FMStatus() && !_toolErr) tn |= 0x8000; if (FMStatus() && !_toolErr)
else dp += 0x0100; tn |= 0x8000;
else
dp += 0x0100;
break; break;
case 0x1c: case 0x1c:
if (ListStatus() && !_toolErr) tn |= 0x8000; if (ListStatus() && !_toolErr)
tn |= 0x8000;
break; break;
case 0x22: case 0x22:
if (TEStatus() && !_toolErr) tn |= 0x8000; if (TEStatus() && !_toolErr)
else dp += 0x0100; tn |= 0x8000;
else
dp += 0x0100;
break; break;
#if 0 #if 0
@ -185,12 +199,13 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
#endif #endif
case 0x26: case 0x26:
if (MCStatus() && !_toolErr) tn |= 0x8000; if (MCStatus() && !_toolErr)
tn |= 0x8000;
break; break;
case 0x36: case 0x36:
if (TCPIPStatus() && !_toolErr) tn |= 0x8000; if (TCPIPStatus() && !_toolErr)
tn |= 0x8000;
break; break;
default: default:
@ -201,7 +216,8 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
if (dp) { if (dp) {
Handle h = NewHandle(dp, memID, 0xc005, 0); Handle h = NewHandle(dp, memID, 0xc005, 0);
if (_toolErr) return 0; if (_toolErr)
return 0;
dptr = *(unsigned char **)h; dptr = *(unsigned char **)h;
ssRef->dPageHandle = h; ssRef->dPageHandle = h;
} }
@ -209,8 +225,10 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
for (i = 0; i < ssRef->numTools; ++i) { for (i = 0; i < ssRef->numTools; ++i) {
unsigned tn = ssRef->theTools[i].toolNumber; unsigned tn = ssRef->theTools[i].toolNumber;
unsigned version = ssRef->theTools[i].minVersion; unsigned version = ssRef->theTools[i].minVersion;
if (tn == 0) continue; if (tn == 0)
if (tn & 0x8000) continue; continue;
if (tn & 0x8000)
continue;
LoadOneTool(tn, version); LoadOneTool(tn, version);
if (_toolErr) { if (_toolErr) {
@ -291,7 +309,8 @@ void NDAShutDownTools(StartStopRecord *ssRef){
for (i = 0; i < ssRef->numTools; ++i) { for (i = 0; i < ssRef->numTools; ++i) {
unsigned tn = ssRef->theTools[i].toolNumber; unsigned tn = ssRef->theTools[i].toolNumber;
if (!(tn & 0x1000)) continue; if (!(tn & 0x1000))
continue;
switch (tn & 0xff) { switch (tn & 0xff) {
case 0x0a: case 0x0a:
SANEShutDown(); SANEShutDown();
@ -322,16 +341,12 @@ void NDAShutDownTools(StartStopRecord *ssRef){
TCPIPShutDown(); TCPIPShutDown();
break; break;
} }
} }
if (ssRef->dPageHandle) if (ssRef->dPageHandle)
DisposeHandle(ssRef->dPageHandle); DisposeHandle(ssRef->dPageHandle);
} }
typedef struct NDAResourceCookie { typedef struct NDAResourceCookie {
Word oldPrefs; Word oldPrefs;
Word oldRApp; Word oldRApp;
@ -402,4 +417,3 @@ void NDAResourceShutDown(NDAResourceCookie *cookie) {
CloseResourceFile(cookie->resFileID); CloseResourceFile(cookie->resFileID);
ResourceShutDown(); ResourceShutDown();
} }