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

242
common.c
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,160 +23,148 @@ 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) {
Word oFile;
Word oDepth;
Handle LoadQuote(word mID, Word rFile) int rID;
{ Word rCount;
Word oFile;
Word oDepth;
int rID; Handle rHandle;
Word rCount; Handle h;
Handle rHandle; h = NULL;
Handle h;
oFile = GetCurResourceFile();
SetCurResourceFile(rFile);
oDepth = SetResourceFileDepth(1);
rCount = CountResources(rTextForLETextBox2);
h = NULL; // printint("rCount: ", rCount);
oFile = GetCurResourceFile(); if (rCount) {
SetCurResourceFile(rFile); WordDivRec wdr;
oDepth = SetResourceFileDepth(1); longword index;
rCount = CountResources(rTextForLETextBox2);
//printint("rCount: ", rCount); wdr = UDivide(Random(), (word)rCount);
if (rCount) // printint("remainder: ", wdr.remainder);
{
WordDivRec wdr;
longword index;
wdr = UDivide(Random(), (word)rCount); index = GetIndResource(rTextForLETextBox2, wdr.remainder + 1);
//printint("remainder: ", wdr.remainder); // todo - repeat above until index out of range
// printint("index: ", index);
index = GetIndResource(rTextForLETextBox2, wdr.remainder + 1); rHandle = LoadResource(rTextForLETextBox2, index);
// printint("loadres: ", _toolErr);
if (!_toolErr) {
word oldLen;
word newLen;
char *newText;
char *oldText;
// todo - repeat above until index out of range word len;
//printint("index: ", index); word i;
oldLen = (word)GetHandleSize(rHandle);
// printint("oldLen: ", oldLen);
rHandle = LoadResource(rTextForLETextBox2, index); h = NewHandle(oldLen << 2 + 2, mID, 0, NULL);
//printint("loadres: ", _toolErr); if (!_toolErr) {
if (!_toolErr) HLock(h);
{ HLock(rHandle);
word oldLen;
word newLen;
char *newText;
char *oldText;
word len; oldText = *rHandle;
word i; newText = *h;
newLen = 0;
oldLen = (word)GetHandleSize(rHandle); i = 0;
//printint("oldLen: ", oldLen); while (i < oldLen) {
char c;
h = NewHandle(oldLen << 2 + 2, mID, 0, NULL); c = *oldText++;
if (!_toolErr) i++;
{
HLock(h);
HLock(rHandle);
oldText = *rHandle; if (c == '\r') {
newText = *h; *((Word *)newText) = 0x0A0D;
newLen = 0; newText += 2;
newLen += 2;
continue;
i = 0; //*newText++ = '\r';
while (i < oldLen) //*newText++ = '\n';
{ // newLen += 2;
char c; // continue;
}
if (c == 0x01) // formatting codes.
{
c = *oldText;
switch (c) {
case 'F': // font
oldText += 5;
i += 5;
break;
c = *oldText++; case 'S': // set style
i++; oldText += 5;
i += 4;
break;
if (c == '\r') case 'C': // fore color
{ case 'B': // back color
*((Word *)newText) = 0x0A0D; case 'J': // justify
newText += 2; case 'L': // left margin
newLen += 2; case 'R': // right margin
continue; case 'X': // extra space
oldText += 3;
i += 3;
break;
}
continue;
}
if (c & 0x80) // macroman encoding.
{
int j;
c &= 0x7f;
j = macroman[c].length;
//*newText++ = '\r'; if (j == 0)
//*newText++ = '\n'; continue;
//newLen += 2;
//continue;
}
if (c == 0x01) // formatting codes.
{
c = *oldText;
switch (c)
{
case 'F': // font
oldText += 5;
i += 5;
break;
case 'S': // set style if (j > 1) {
oldText += 5; char *cp;
i += 4; cp = macroman[c].cp;
break;
case 'C': // fore color newLen += j;
case 'B': // back color do {
case 'J': // justify *newText++ = *cp++;
case 'L': // left margin } while (--j);
case 'R': // right margin
case 'X': // extra space
oldText += 3;
i += 3;
break;
}
continue;
}
if (c & 0x80) // macroman encoding.
{
int j;
c &= 0x7f;
j = macroman[c].length;
if (j == 0) continue; continue;
} else
c = (char)macroman[c].cp;
}
if (j > 1) newLen++;
{ *newText++ = c;
char *cp; }
cp = macroman[c].cp;
newLen += j; //*newText++ = '\r';
do //*newText++ = '\n';
{ *((Word *)newText) = 0x0A0D;
*newText++ = *cp++; newLen += 2;
} HUnlock(h);
while (--j); SetHandleSize(newLen, h);
}
continue; HUnlock(rHandle);
} ReleaseResource(0, rTextForLETextBox2, index);
else c = (char)macroman[c].cp; }
} }
SetCurResourceFile(oFile);
SetResourceFileDepth(oDepth);
newLen++; return h;
*newText++ = c;
}
//*newText++ = '\r';
//*newText++ = '\n';
*((Word *)newText) = 0x0A0D;
newLen += 2;
HUnlock(h);
SetHandleSize(newLen, h);
}
HUnlock(rHandle);
ReleaseResource(0, rTextForLETextBox2, index);
}
}
SetCurResourceFile(oFile);
SetResourceFileDepth(oDepth);
return h;
} }

155
config.c
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,42 +23,43 @@ 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;
static GSString32 filePath = {28, "*:System:Preferences:QServer"}; 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
// 3 - load up the data // 3 - load up the data
// 4 - if data doesn't exist, store a default value. // 4 - if data doesn't exist, store a default value.
fd = 0; fd = 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,19 +97,17 @@ 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;
{ CtlRecHndl CtrlHand;
GSString255 * gstr = (GSString255 *)data; Rect r;
CtlRecHndl CtrlHand;
Rect r;
CtrlHand = GetCtlHandleFromID(win, id); CtrlHand = GetCtlHandleFromID(win, id);
@ -124,27 +120,26 @@ Rect r;
SetCtlTitle(gstr->text, (Handle)CtrlHand); SetCtlTitle(gstr->text, (Handle)CtrlHand);
} else { } else {
SetCtlValue(0, CtrlHand); SetCtlValue(0, CtrlHand);
SetCtlTitle("", (Handle)CtrlHand); SetCtlTitle("", (Handle)CtrlHand);
} }
} }
void DoConfig(Word MyID) void DoConfig(Word MyID) {
{ static EventRecord event;
static EventRecord event;
WindowPtr win; WindowPtr win;
Word control; Word control;
Word ok; Word ok;
GrafPortPtr oldPort; GrafPortPtr oldPort;
Handle newPath = NULL; Handle newPath = NULL;
oldPort = GetPort(); oldPort = GetPort();
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,58 +150,49 @@ 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, (WordProcPtr)SFFilter, /* filter proc */
refIsPointer, NULL, /* type list */
(Ref)"\pSelect quotation file.", &myReply);
(WordProcPtr)SFFilter, /* filter proc */ if (myReply.good) {
NULL, /* type list */ Handle h;
&myReply); Word size;
if (myReply.good)
{
Handle h;
Word size;
h = (Handle)myReply.pathRef; h = (Handle)myReply.pathRef;
HLock(h); HLock(h);
size = GetHandleSize(h) - 2; size = GetHandleSize(h) - 2;
BlockMove(*h + 2, *h, size); BlockMove(*h + 2, *h, size);
ReAllocHandle(size, MyID, 0x8000, NULL, h); ReAllocHandle(size, MyID, 0x8000, NULL, h);
SetText(win, CtrlPath, *h); SetText(win, CtrlPath, *h);
if (newPath) DisposeHandle(newPath); if (newPath)
newPath = h; DisposeHandle(newPath);
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,148 +3,150 @@
#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'), ONECHAR('E'),
ONECHAR('E'), ONECHAR('N'),
ONECHAR('N'), ONECHAR('O'),
ONECHAR('O'), ONECHAR('U'),
ONECHAR('U'), ONECHAR('a'),
ONECHAR('a'), ONECHAR('a'),
ONECHAR('a'), ONECHAR('a'),
ONECHAR('a'), ONECHAR('a'),
ONECHAR('a'), ONECHAR('a'),
ONECHAR('a'), ONECHAR('a'),
ONECHAR('a'), ONECHAR('c'),
ONECHAR('c'), ONECHAR('e'),
ONECHAR('e'), ONECHAR('e'),
ONECHAR('e'),
ONECHAR('e'), // 0x90 ONECHAR('e'), // 0x90
ONECHAR('e'), ONECHAR('e'),
ONECHAR('i'), ONECHAR('i'),
ONECHAR('i'), ONECHAR('i'),
ONECHAR('i'), ONECHAR('i'),
ONECHAR('i'), ONECHAR('i'),
ONECHAR('n'), ONECHAR('n'),
ONECHAR('o'), ONECHAR('o'),
ONECHAR('o'), ONECHAR('o'),
ONECHAR('o'), ONECHAR('o'),
ONECHAR('o'), ONECHAR('o'),
ONECHAR('o'), ONECHAR('o'),
ONECHAR('u'), ONECHAR('u'),
ONECHAR('u'), ONECHAR('u'),
ONECHAR('u'), ONECHAR('u'),
ONECHAR('u'), ONECHAR('u'),
BLANK, // 0xA0 BLANK, // 0xA0
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
ONECHAR('*'), ONECHAR('*'),
BLANK, BLANK,
BLANK, BLANK,
MULTICHAR("(r)"), MULTICHAR("(r)"),
MULTICHAR("(c)"), MULTICHAR("(c)"),
MULTICHAR("tm"), MULTICHAR("tm"),
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
MULTICHAR("AE"), MULTICHAR("AE"),
ONECHAR('O'), ONECHAR('O'),
BLANK, // 0xB0 BLANK, // 0xB0
BLANK, BLANK,
MULTICHAR("<="), MULTICHAR("<="),
MULTICHAR(">="), MULTICHAR(">="),
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
BLANK, BLANK,
MULTICHAR("ae"), MULTICHAR("ae"),
ONECHAR('o'), ONECHAR('o'),
ONECHAR('?'), // 0xC0 ONECHAR('?'), // 0xC0
ONECHAR('!'), ONECHAR('!'),
BLANK, BLANK,
BLANK, BLANK,
ONECHAR('f'), ONECHAR('f'),
BLANK, BLANK,
BLANK, BLANK,
MULTICHAR("<<"), MULTICHAR("<<"),
MULTICHAR(">>"), MULTICHAR(">>"),
MULTICHAR("..."), MULTICHAR("..."),
ONECHAR(' '), ONECHAR(' '),
ONECHAR('A'), ONECHAR('A'),
ONECHAR('A'), ONECHAR('A'),
ONECHAR('O'), ONECHAR('O'),
MULTICHAR("OE"), MULTICHAR("OE"),
MULTICHAR("oe"), MULTICHAR("oe"),
MULTICHAR("--"), // 0xD0
MULTICHAR("---"),
ONECHAR('"'),
ONECHAR('"'),
ONECHAR('\''),
ONECHAR('\''),
BLANK,
BLANK,
ONECHAR('y'),
ONECHAR('Y'),
ONECHAR('/'),
BLANK,
BLANK,
BLANK,
MULTICHAR("fi"),
MULTICHAR("fl"),
BLANK, // 0xE0 MULTICHAR("--"), // 0xD0
BLANK, MULTICHAR("---"),
BLANK, ONECHAR('"'),
BLANK, ONECHAR('"'),
BLANK, ONECHAR('\''),
ONECHAR('A'), ONECHAR('\''),
ONECHAR('E'), BLANK,
ONECHAR('A'), BLANK,
ONECHAR('E'), ONECHAR('y'),
ONECHAR('E'), ONECHAR('Y'),
ONECHAR('I'), ONECHAR('/'),
ONECHAR('I'), BLANK,
ONECHAR('I'), BLANK,
ONECHAR('I'), BLANK,
ONECHAR('O'), MULTICHAR("fi"),
ONECHAR('O'), MULTICHAR("fl"),
ONECHAR('?'), // 0xF0 BLANK, // 0xE0
ONECHAR('O'), BLANK,
ONECHAR('U'), BLANK,
ONECHAR('U'), BLANK,
ONECHAR('U'), BLANK,
BLANK, ONECHAR('A'),
BLANK, ONECHAR('E'),
BLANK, ONECHAR('A'),
BLANK, ONECHAR('E'),
BLANK, ONECHAR('E'),
BLANK, ONECHAR('I'),
BLANK, ONECHAR('I'),
BLANK, ONECHAR('I'),
BLANK, ONECHAR('I'),
BLANK, ONECHAR('O'),
BLANK, ONECHAR('O'),
ONECHAR('?'), // 0xF0
ONECHAR('O'),
ONECHAR('U'),
ONECHAR('U'),
ONECHAR('U'),
BLANK,
BLANK,
BLANK,
BLANK,
BLANK,
BLANK,
BLANK,
BLANK,
BLANK,
BLANK,
BLANK,
}; };

View File

@ -1,10 +1,9 @@
#ifndef __MACROMAN_H__ #ifndef __MACROMAN_H__
#define __MACROMAN_H__ #define __MACROMAN_H__
struct charmap struct charmap {
{ int length;
int length; char *cp;
char *cp;
}; };
extern struct charmap macroman[128]; extern struct charmap macroman[128];

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)
if (_toolErr) return FLAG_ERROR; 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;
} }

630
qserver.c
View File

@ -1,36 +1,33 @@
#pragma nda NDAOpen NDAClose NDAAction NDAInit 30 0xffff "--Quote Server\\H**" #pragma nda NDAOpen NDAClose NDAAction NDAInit 30 0xffff "--Quote Server\\H**"
#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,16 +58,14 @@ 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;
}; };
#define QSIZE 16 #define QSIZE 16
@ -82,11 +74,9 @@ struct qentry queue[QSIZE];
word total; word total;
word current; word current;
void fixstats(void) {
void fixstats(void) static char stats[16];
{ Word i;
static char stats[16];
Word i;
i = sprintf(stats + 1, "%u : %u", current, total); i = sprintf(stats + 1, "%u : %u", current, total);
stats[0] = i; // pascal string stats[0] = i; // pascal string
@ -95,282 +85,247 @@ Word i;
DrawInfoBar(MyWindow); DrawInfoBar(MyWindow);
} }
void InsertString(word length, char *cp) {
Handle handle;
TERecord **temp;
longword oldStart, oldEnd;
void InsertString(word length, char *cp) handle = (Handle)GetCtlHandleFromID(MyWindow, CtrlTE);
{ temp = (TERecord **)handle;
Handle handle;
TERecord **temp;
longword oldStart, oldEnd;
handle = (Handle)GetCtlHandleFromID(MyWindow, CtrlTE); (**temp).textFlags &= (~fReadOnly);
temp = (TERecord **)handle;
(**temp).textFlags &= (~fReadOnly); TEGetSelection((pointer)&oldStart, (pointer)&oldEnd, handle);
TEGetSelection((pointer)&oldStart, (pointer)&oldEnd, handle); TESetSelection((Pointer)-1, (Pointer)-1, handle);
TEInsert(teDataIsTextBlock, (Ref)cp, length, NULL, NULL, /* no style info */
handle);
TESetSelection((Pointer)-1, (Pointer)-1, handle); (**temp).textFlags |= fReadOnly;
TEInsert(teDataIsTextBlock, (Ref)cp, length,
NULL, NULL, /* no style info */
handle);
(**temp).textFlags |= fReadOnly;
TESetSelection((Pointer)oldStart, (Pointer)oldEnd, handle);
TESetSelection((Pointer)oldStart, (Pointer)oldEnd, handle);
} }
enum {
enum STATE_NULL = 0,
{ STATE_ESTABLISH, // waiting to establish
STATE_NULL = 0, STATE_QUOTE, // send the quote...
STATE_ESTABLISH, // waiting to establish STATE_SEND, // waiting for data to send
STATE_QUOTE, // send the quote... STATE_CLOSE
STATE_SEND, // waiting for data to send
STATE_CLOSE
}; };
void QServer(void) void QServer(void) {
{ static srBuff srBuffer;
static srBuff srBuffer; word delta;
word delta; int i;
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--; delta = true;
delta = true; 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; current--;
current--; delta = true;
delta = true; continue;
continue; }
}
switch (queue[i].state) {
case STATE_ESTABLISH:
if (srBuffer.srState != TCPSESTABLISHED)
break;
switch (queue[i].state) queue[i].state = STATE_QUOTE;
{ // drop through and send the quote.
case STATE_ESTABLISH:
if (srBuffer.srState != TCPSESTABLISHED)
break;
queue[i].state = STATE_QUOTE; case STATE_QUOTE: {
// drop through and send the quote. Handle h;
h = LoadQuote(MyID, rFile);
if (h) {
HLock(h);
TCPIPWriteTCP(ipid, *h, GetHandleSize(h), false, false);
DisposeHandle(h);
} else {
TCPIPWriteTCP(ipid, "Your quote here!\r\n", 18, false, false);
}
}
queue[i].state = STATE_SEND;
break;
case STATE_QUOTE: case STATE_SEND:
{
Handle h;
h = LoadQuote(MyID, rFile);
if (h)
{
HLock(h);
TCPIPWriteTCP(ipid, *h,
GetHandleSize(h), false, false);
DisposeHandle(h);
}
else
{
TCPIPWriteTCP(ipid, "Your quote here!\r\n",
18, false, false);
}
}
queue[i].state = STATE_SEND;
break;
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; }
} break;
break; }
} }
}
// check for a new connection.
if (current < QSIZE) {
word child;
int i;
child = TCPIPAcceptTCP(Ipid, 0);
// check for a new connection. if (!_toolErr)
if (current < QSIZE) for (i = 0; i < QSIZE; i++) {
{ if (!queue[i].ipid) {
word child; static char buffer[16];
int i; static char line[32];
child = TCPIPAcceptTCP(Ipid, 0); int j;
if (!_toolErr) for (i = 0; i < QSIZE; i++)
{
if (!queue[i].ipid)
{
static char buffer[16];
static char line[32];
int j;
TCPIPStatusTCP(child, &srBuffer); TCPIPStatusTCP(child, &srBuffer);
queue[i].ipid = child; queue[i].ipid = child;
if (srBuffer.srState == TCPSESTABLISHED) if (srBuffer.srState == TCPSESTABLISHED)
queue[i].state = STATE_SEND; queue[i].state = STATE_SEND;
else else
queue[i].state = STATE_ESTABLISH; queue[i].state = STATE_ESTABLISH;
queue[i].tick = GetTick(); queue[i].tick = GetTick();
current++; current++;
total++; total++;
delta = true; delta = true;
TCPIPConvertIPToASCII(srBuffer.srDestIP,
buffer, 0);
j = sprintf(line, "%p:%u\r", TCPIPConvertIPToASCII(srBuffer.srDestIP, buffer, 0);
buffer, srBuffer.srDestPort);
InsertString(j, line);
break; j = sprintf(line, "%p:%u\r", buffer, srBuffer.srDestPort);
}
} InsertString(j, line);
}
if (delta) fixstats(); // statistics changed. break;
}
}
}
if (delta)
fixstats(); // statistics changed.
} }
int StartServer(void) {
int i;
word oFile;
word oDepth;
static char err[256];
GSString255 *path;
int StartServer(void) total = current = 0;
{
int i;
word oFile;
word oDepth;
static char err[256];
GSString255 *path;
total = current = 0; if (!rPath) {
InsertString(32, "Fatal: No quote file specified.\r");
if (!rPath) return false;
{ }
InsertString(32, "Fatal: No quote file specified.\r"); HLock(rPath);
return false;
}
HLock(rPath);
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(
InsertString(sprintf(err, "Fatal: Unable to open %.*s\r", path->length, path->text), sprintf(err, "Fatal: Unable to open %.*s\r", path->length, path->text),
err); err);
return false; return false;
} }
oFile = GetCurResourceFile(); oFile = GetCurResourceFile();
SetCurResourceFile(rFile); SetCurResourceFile(rFile);
oDepth = SetResourceFileDepth(1); oDepth = SetResourceFileDepth(1);
rCount = CountResources(rTextForLETextBox2); rCount = CountResources(rTextForLETextBox2);
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,
InsertString(sprintf(err, "Fatal: Invalid quote file %.*s\r", path->length, path->text), path->text),
err); err);
CloseResourceFile(rFile); CloseResourceFile(rFile);
return false; return false;
} }
SetRandSeed(GetTick()); SetRandSeed(GetTick());
for (i = 0; i < QSIZE; i++) {
queue[i].ipid = 0;
queue[i].state = 0;
}
for (i = 0; i < QSIZE; i++) Ipid = TCPIPLogin(MyID, 0, 0, 0, 64);
{
queue[i].ipid = 0;
queue[i].state = 0;
}
Ipid = TCPIPLogin(MyID, 0, 0, 0, 64); TCPIPSetSourcePort(Ipid, PORT_QOTD);
TCPIPSetSourcePort(Ipid, PORT_QOTD); TCPIPListenTCP(Ipid);
TCPIPListenTCP(Ipid); FlagQS = true;
FlagQS = true; HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartQS);
HiliteCtlByID(noHilite, MyWindow, CtrlStopQS);
HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartQS); fixstats();
HiliteCtlByID(noHilite, MyWindow, CtrlStopQS); HUnlock(rPath);
fixstats();
HUnlock(rPath);
InsertString(16, "QServer started\r");
return true;
InsertString(16, "QServer started\r");
return true;
} }
int StopServer(void) int StopServer(void) {
{ int i;
int i;
// close any q entries
for (i = 0; i < QSIZE; i++) {
int ipid;
ipid = queue[i].ipid;
if (ipid) {
TCPIPAbortTCP(ipid);
TCPIPLogout(ipid);
queue[i].ipid = 0;
}
}
// close any q entries TCPIPCloseTCP(Ipid);
for (i = 0; i < QSIZE; i++) TCPIPLogout(Ipid);
{
int ipid;
ipid = queue[i].ipid;
if (ipid)
{
TCPIPAbortTCP(ipid);
TCPIPLogout(ipid);
queue[i].ipid = 0;
}
}
TCPIPCloseTCP(Ipid); FlagQS = false;
TCPIPLogout(Ipid); Ipid = 0;
FlagQS = false; HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS);
Ipid = 0; HiliteCtlByID(noHilite, MyWindow, CtrlStartQS);
HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS); CloseResourceFile(rFile);
HiliteCtlByID(noHilite, MyWindow, CtrlStartQS);
CloseResourceFile(rFile); SetInfoRefCon((LongWord) "\pServer stopped", MyWindow);
DrawInfoBar(MyWindow);
InsertString(16, "QServer stopped\r");
SetInfoRefCon((LongWord)"\pServer stopped", MyWindow); return true;
DrawInfoBar(MyWindow);
InsertString(16, "QServer stopped\r");
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
HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartM); HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartM);
HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS); HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS);
@ -378,11 +333,9 @@ void UpdateStatus(Boolean redraw)
HiliteCtlByID(noHilite, MyWindow, CtrlStopM); HiliteCtlByID(noHilite, MyWindow, CtrlStopM);
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);
// deactivate // deactivate
@ -390,94 +343,78 @@ void UpdateStatus(Boolean redraw)
HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartQS); HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartQS);
HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS); HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS);
SetInfoRefCon((LongWord)"\pNetwork Disconnected", MyWindow); SetInfoRefCon((LongWord) "\pNetwork Disconnected", MyWindow);
} }
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);
DrawString(str); DrawString(str);
} }
} }
void DrawWindow(void) void DrawWindow(void) { DrawControls(GetPort()); }
{
DrawControls(GetPort());
}
#pragma databank 0 #pragma databank 0
static StartStopRecord ss = {0,
0,
0,
0,
4,
{
0x12, 0x0000, /* QD Aux */
0x17, 0x0000, /* Std File */
0x1b, 0x0000, /* Font Manager */
0x22, 0x0000, /* Text Edit */
0x36, 0x0300, /* TCP */
static StartStopRecord ss = { }
0, 0, 0, 0,
4,
{
0x12, 0x0000, /* QD Aux */
0x17, 0x0000, /* Std File */
0x1b, 0x0000, /* Font Manager */
0x22, 0x0000, /* Text Edit */
0x36, 0x0300, /* TCP */
}
}; };
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,31 +445,28 @@ 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);
MyWindow = NULL; MyWindow = NULL;
UnloadConfig(); UnloadConfig();
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,60 +504,51 @@ 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);
} }
break; break;
/* start the server */ /* start the server */
case CtrlStartQS: case CtrlStartQS:
StartServer(); StartServer();
break; break;
/* stop the server */ /* stop the server */
case CtrlStopQS: case CtrlStopQS:
StopServer(); StopServer();
break; break;
case CtrlConfig: case CtrlConfig:
DoConfig(MyID); DoConfig(MyID);
break; break;
} }
// 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;
} }

View File

@ -3,27 +3,27 @@
* *
*/ */
#define rQSWindow 0x1000 #define rQSWindow 0x1000
#define CtrlStartM 0x1001 #define CtrlStartM 0x1001
#define CtrlStopM 0x1002 #define CtrlStopM 0x1002
#define CtrlStartQS 0x1003 #define CtrlStartQS 0x1003
#define CtrlStopQS 0x1004 #define CtrlStopQS 0x1004
#define CtrlTE 0x1005 #define CtrlTE 0x1005
#define CtrlLogo 0x1006 #define CtrlLogo 0x1006
#define CtrlConfig 0x1007 #define CtrlConfig 0x1007
#define rConfigWindow 0x2000 #define rConfigWindow 0x2000
#define CtrlBrowse 0x2001 #define CtrlBrowse 0x2001
//#define CtrlPortLE 0x2002 //#define CtrlPortLE 0x2002
//#define CtrlPathLE 0x2003 //#define CtrlPathLE 0x2003
//#define CtrlPortStat 0x2004 //#define CtrlPortStat 0x2004
#define CtrlPathStat 0x2005 #define CtrlPathStat 0x2005
#define CtrlPath 0x2006 #define CtrlPath 0x2006
#define CtrlCancel 0x2007 #define CtrlCancel 0x2007
#define CtrlOk 0x2008 #define CtrlOk 0x2008
#define PORT_QOTD 17 #define PORT_QOTD 17
#define ConfigWindowWidth 300 #define ConfigWindowWidth 300
#define ConfigWindowHeight 52 #define ConfigWindowHeight 52

548
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,158 +30,166 @@ 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 ListShutDown(void) inline(0x031C, dispatcher);
extern pascal Word ListVersion(void) inline(0x041C, dispatcher);
extern pascal Boolean ListStatus(void) inline(0x061C, dispatcher);
extern pascal void ListStartUp(void) inline(0x021C,dispatcher); extern pascal void TCPIPStartUp(void) inline(0x0236, dispatcher);
extern pascal void ListShutDown(void) inline(0x031C,dispatcher); extern pascal void TCPIPShutDown(void) inline(0x0336, dispatcher);
extern pascal Word ListVersion(void) inline(0x041C,dispatcher); extern pascal Word TCPIPVersion(void) inline(0x0436, dispatcher);
extern pascal Boolean ListStatus(void) inline(0x061C,dispatcher); extern pascal Boolean TCPIPStatus(void) inline(0x0636, dispatcher);
extern pascal Long TCPIPLongVersion(void) inline(0x0836, dispatcher);
extern pascal Boolean TCPIPGetConnectStatus(void) inline(0x0936, dispatcher);
extern pascal void TCPIPStartUp (void) inline(0x0236,dispatcher); extern pascal void SANEStartUp(Word) inline(0x020A, dispatcher);
extern pascal void TCPIPShutDown (void) inline(0x0336,dispatcher); extern pascal void SANEShutDown(void) inline(0x030A, dispatcher);
extern pascal Word TCPIPVersion (void) inline(0x0436,dispatcher); extern pascal Word SANEVersion(void) inline(0x040A, dispatcher);
extern pascal Boolean TCPIPStatus (void) inline(0x0636,dispatcher); extern pascal Word SANEStatus(void) inline(0x060A, dispatcher);
extern pascal Long TCPIPLongVersion (void) inline(0x0836,dispatcher);
extern pascal Boolean TCPIPGetConnectStatus (void) inline(0x0936,dispatcher);
extern pascal void SANEStartUp(Word) inline(0x020A,dispatcher); extern pascal void TEStartUp(Word, Word) inline(0x0222, dispatcher);
extern pascal void SANEShutDown(void) inline(0x030A,dispatcher); extern pascal void TEShutDown(void) inline(0x0322, dispatcher);
extern pascal Word SANEVersion(void) inline(0x040A,dispatcher); extern pascal Word TEVersion(void) inline(0x0422, dispatcher);
extern pascal Word SANEStatus(void) inline(0x060A,dispatcher); extern pascal Word TEStatus(void) inline(0x0622, dispatcher);
extern pascal void TEStartUp(Word, Word) inline(0x0222,dispatcher); extern pascal void PMStartUp(Word, Word) inline(0x0213, dispatcher);
extern pascal void TEShutDown(void) inline(0x0322,dispatcher); extern pascal void PMShutDown(void) inline(0x0313, dispatcher);
extern pascal Word TEVersion(void) inline(0x0422,dispatcher); extern pascal Word PMVersion(void) inline(0x0413, dispatcher);
extern pascal Word TEStatus(void) inline(0x0622,dispatcher); extern pascal Boolean PMStatus(void) inline(0x0613, dispatcher);
extern pascal void PMStartUp(Word, Word) inline(0x0213,dispatcher); extern pascal void FMStartUp(Word, Word) inline(0x021B, dispatcher);
extern pascal void PMShutDown(void) inline(0x0313,dispatcher); extern pascal void FMShutDown(void) inline(0x031B, dispatcher);
extern pascal Word PMVersion(void) inline(0x0413,dispatcher); extern pascal Word FMVersion(void) inline(0x041B, dispatcher);
extern pascal Boolean PMStatus(void) inline(0x0613,dispatcher); extern pascal Boolean FMStatus(void) inline(0x061B, dispatcher);
extern pascal void FMStartUp(Word, Word) inline(0x021B,dispatcher); extern pascal void QDAuxStartUp(void) inline(0x0212, dispatcher);
extern pascal void FMShutDown(void) inline(0x031B,dispatcher); extern pascal void QDAuxShutDown(void) inline(0x0312, dispatcher);
extern pascal Word FMVersion(void) inline(0x041B,dispatcher); extern pascal Word QDAuxVersion(void) inline(0x0412, dispatcher);
extern pascal Boolean FMStatus(void) inline(0x061B,dispatcher); extern pascal Boolean QDAuxStatus(void) inline(0x0612, dispatcher);
extern pascal void QDAuxStartUp(void) inline(0x0212,dispatcher); extern pascal void SFStartUp(Word, Word) inline(0x0217, dispatcher);
extern pascal void QDAuxShutDown(void) inline(0x0312,dispatcher); extern pascal void SFShutDown(void) inline(0x0317, dispatcher);
extern pascal Word QDAuxVersion(void) inline(0x0412,dispatcher); extern pascal Word SFVersion(void) inline(0x0417, dispatcher);
extern pascal Boolean QDAuxStatus(void) inline(0x0612,dispatcher); extern pascal Boolean SFStatus(void) inline(0x0617, dispatcher);
extern pascal void SFStartUp(Word, Word) inline(0x0217,dispatcher); extern pascal void MCStartUp(Word) inline(0x0226, dispatcher);
extern pascal void SFShutDown(void) inline(0x0317,dispatcher); extern pascal void MCShutDown(void) inline(0x0326, dispatcher);
extern pascal Word SFVersion(void) inline(0x0417,dispatcher); extern pascal Word MCVersion(void) inline(0x0426, dispatcher);
extern pascal Boolean SFStatus(void) inline(0x0617,dispatcher); extern pascal Boolean MCStatus(void) inline(0x0626, dispatcher);
extern pascal void MCStartUp(Word) inline(0x0226,dispatcher);
extern pascal void MCShutDown(void) inline(0x0326,dispatcher);
extern pascal Word MCVersion(void) inline(0x0426,dispatcher);
extern pascal Boolean MCStatus(void) inline(0x0626,dispatcher);
static char NullString[] = "\p"; 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 20; /* 320 - 280 */ return 180; /* (640-280) */
return 20; /* 320 - 280 */
} }
static void ErrorLoading(unsigned tool) { static void ErrorLoading(unsigned tool) {
static char msg1[] = "\pThis desk accessory needs Tool000"; static char msg1[] = "\pThis desk accessory needs Tool000";
static char msg2[] = "\pin the System:Tools folder."; static char msg2[] = "\pin the System:Tools folder.";
Int2Dec(tool, msg1+31, 3, 0); Int2Dec(tool, msg1 + 31, 3, 0);
msg1[31] |= 0x10; /* ' ' -> '0' */ msg1[31] |= 0x10; /* ' ' -> '0' */
TLMountVolume(centerX(), 67, msg1, msg2, ok, ok); TLMountVolume(centerX(), 67, msg1, msg2, ok, ok);
} }
void ErrorStarting(unsigned tool) { void ErrorStarting(unsigned tool) {
static char msg1[] = "\pError starting Tool000"; static char msg1[] = "\pError starting Tool000";
Int2Dec(tool, msg1+20, 3, 0); Int2Dec(tool, msg1 + 20, 3, 0);
msg1[20] |= 0x10; /* ' ' -> '0' */ msg1[20] |= 0x10; /* ' ' -> '0' */
TLMountVolume(centerX(), 67, msg1, NullString, ok, ok); TLMountVolume(centerX(), 67, msg1, NullString, ok, ok);
} }
unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) { unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
unsigned i;
unsigned dp = 0;
unsigned char *dptr = 0;
unsigned errors = 0;
unsigned level = 0;
unsigned i;
unsigned dp = 0;
unsigned char *dptr = 0;
unsigned errors = 0;
unsigned level = 0;
ssRef->resFileID = 0; ssRef->resFileID = 0;
ssRef->dPageHandle = 0; ssRef->dPageHandle = 0;
/* /*
todo: todo:
25 - note synth 25 - note synth
26 - note seq 26 - note seq
29 - ACE 29 - ACE
30 - resource manager 30 - resource manager
32 - MIDI 32 - MIDI
33 - VOC 33 - VOC
35 - MidiSynth 35 - MidiSynth
37 - Animation 37 - Animation
*/ */
/* check which ones are already loaded */ /* check which ones are already loaded */
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;
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;
break; else
dp += 0x0100;
break;
case 0x12: case 0x12:
if (QDAuxStatus() && !_toolErr) tn |= 0x8000; if (QDAuxStatus() && !_toolErr)
break; tn |= 0x8000;
break;
case 0x13: case 0x13:
if (PMStatus() && !_toolErr) tn |= 0x8000; if (PMStatus() && !_toolErr)
else dp += 0x0200; tn |= 0x8000;
break; else
dp += 0x0200;
break;
case 0x17: case 0x17:
if (SFStatus() && !_toolErr) tn |= 0x8000; if (SFStatus() && !_toolErr)
else dp += 0x0100; tn |= 0x8000;
break; else
dp += 0x0100;
break;
case 0x1b: case 0x1b:
if (FMStatus() && !_toolErr) tn |= 0x8000; if (FMStatus() && !_toolErr)
else dp += 0x0100; tn |= 0x8000;
break; else
dp += 0x0100;
break;
case 0x1c: case 0x1c:
if (ListStatus() && !_toolErr) tn |= 0x8000; if (ListStatus() && !_toolErr)
break; tn |= 0x8000;
break;
case 0x22:
case 0x22: if (TEStatus() && !_toolErr)
if (TEStatus() && !_toolErr) tn |= 0x8000; tn |= 0x8000;
else dp += 0x0100; else
break; dp += 0x0100;
break;
#if 0 #if 0
case 0x23: case 0x23:
@ -184,78 +198,82 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
break; break;
#endif #endif
case 0x26: case 0x26:
if (MCStatus() && !_toolErr) tn |= 0x8000; if (MCStatus() && !_toolErr)
break; tn |= 0x8000;
break;
case 0x36:
if (TCPIPStatus() && !_toolErr)
tn |= 0x8000;
break;
case 0x36: default:
if (TCPIPStatus() && !_toolErr) tn |= 0x8000; tn = 0;
break; }
ssRef->theTools[i].toolNumber = tn;
}
default: if (dp) {
tn = 0; Handle h = NewHandle(dp, memID, 0xc005, 0);
} if (_toolErr)
ssRef->theTools[i].toolNumber = tn; return 0;
} dptr = *(unsigned char **)h;
ssRef->dPageHandle = h;
}
if (dp) { for (i = 0; i < ssRef->numTools; ++i) {
Handle h = NewHandle(dp, memID, 0xc005, 0); unsigned tn = ssRef->theTools[i].toolNumber;
if (_toolErr) return 0; unsigned version = ssRef->theTools[i].minVersion;
dptr = *(unsigned char **)h; if (tn == 0)
ssRef->dPageHandle = h; continue;
} if (tn & 0x8000)
continue;
for (i = 0; i < ssRef->numTools; ++i) { LoadOneTool(tn, version);
unsigned tn = ssRef->theTools[i].toolNumber; if (_toolErr) {
unsigned version = ssRef->theTools[i].minVersion; ErrorLoading(tn);
if (tn == 0) continue;
if (tn & 0x8000) continue;
LoadOneTool(tn, version); tn |= 0x4000;
if (_toolErr) { ssRef->theTools[i].toolNumber = tn;
ErrorLoading(tn); ++errors;
continue;
}
tn |= 0x4000; _toolErr = 0;
ssRef->theTools[i].toolNumber = tn; switch (tn) {
++errors; case 0x0a:
continue; SANEStartUp((Word)dptr);
} dptr += 0x0100;
break;
_toolErr = 0; case 0x12:
switch(tn) { QDAuxStartUp();
case 0x0a: break;
SANEStartUp((Word)dptr);
dptr += 0x0100;
break;
case 0x12: case 0x13:
QDAuxStartUp(); PMStartUp(memID, (Word)dptr);
break; dptr += 0x0200;
break;
case 0x13: case 0x17:
PMStartUp(memID, (Word)dptr); SFStartUp(memID, (Word)dptr);
dptr += 0x0200; dptr += 0x0100;
break; break;
case 0x17: case 0x1b:
SFStartUp(memID, (Word)dptr); FMStartUp(memID, (Word)dptr);
dptr += 0x0100; dptr += 0x0100;
break; break;
case 0x1b: case 0x1c:
FMStartUp(memID, (Word)dptr); ListStartUp();
dptr += 0x0100; break;
break;
case 0x1c: case 0x22:
ListStartUp(); TEStartUp(memID, (Word)dptr);
break; dptr += 0x0100;
break;
case 0x22:
TEStartUp(memID, (Word)dptr);
dptr += 0x0100;
break;
#if 0 #if 0
case 0x23: case 0x23:
@ -264,78 +282,75 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
break; break;
#endif #endif
case 0x26: case 0x26:
MCStartUp(memID); MCStartUp(memID);
break; break;
case 0x36: case 0x36:
TCPIPStartUp(); TCPIPStartUp();
break; break;
} }
if (_toolErr) { if (_toolErr) {
ErrorStarting(tn); ErrorStarting(tn);
++errors; ++errors;
tn |= 0x2000; tn |= 0x2000;
} else { } else {
tn |= 0x1000; tn |= 0x1000;
} }
ssRef->theTools[i].toolNumber = tn; ssRef->theTools[i].toolNumber = tn;
} }
exit: exit:
return errors; return errors;
} }
void NDAShutDownTools(StartStopRecord *ssRef){ void NDAShutDownTools(StartStopRecord *ssRef) {
unsigned i; unsigned i;
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))
switch(tn & 0xff) { continue;
case 0x0a: switch (tn & 0xff) {
SANEShutDown(); case 0x0a:
break; SANEShutDown();
case 0x12: break;
QDAuxShutDown(); case 0x12:
break; QDAuxShutDown();
case 0x13: break;
PMShutDown(); case 0x13:
break; PMShutDown();
case 0x17: break;
SFShutDown(); case 0x17:
break; SFShutDown();
case 0x1b: break;
FMShutDown(); case 0x1b:
break; FMShutDown();
case 0x1c: break;
ListShutDown(); case 0x1c:
break; ListShutDown();
case 0x22: break;
TEShutDown(); case 0x22:
break; TEShutDown();
case 0x26: break;
MCShutDown(); case 0x26:
break; MCShutDown();
case 0x36: break;
if (TCPIPGetConnectStatus() == 0) case 0x36:
TCPIPShutDown(); if (TCPIPGetConnectStatus() == 0)
break; TCPIPShutDown();
} break;
}
}
}
if (ssRef->dPageHandle)
DisposeHandle(ssRef->dPageHandle);
if (ssRef->dPageHandle)
DisposeHandle(ssRef->dPageHandle);
} }
typedef struct NDAResourceCookie { typedef struct NDAResourceCookie {
Word oldPrefs; Word oldPrefs;
Word oldRApp; Word oldRApp;
Word resFileID; Word resFileID;
} NDAResourceCookie; } NDAResourceCookie;
/* /*
@ -344,41 +359,41 @@ typedef struct NDAResourceCookie {
*/ */
Word NDAResourceStartUp(Word memID, Word access, NDAResourceCookie *cookie) { Word NDAResourceStartUp(Word memID, Word access, NDAResourceCookie *cookie) {
Pointer myPath; Pointer myPath;
LevelRecGS levelDCB; LevelRecGS levelDCB;
SysPrefsRecGS prefsDCB; SysPrefsRecGS prefsDCB;
Word resFileID; Word resFileID;
Word oldLevel; Word oldLevel;
cookie->oldPrefs = 0; cookie->oldPrefs = 0;
cookie->resFileID = 0; cookie->resFileID = 0;
cookie->oldRApp = GetCurResourceApp(); cookie->oldRApp = GetCurResourceApp();
levelDCB.pCount = 2; levelDCB.pCount = 2;
GetLevelGS(&levelDCB); GetLevelGS(&levelDCB);
oldLevel = levelDCB.level; oldLevel = levelDCB.level;
levelDCB.level = 0; levelDCB.level = 0;
SetLevelGS(&levelDCB); SetLevelGS(&levelDCB);
levelDCB.level = oldLevel; levelDCB.level = oldLevel;
prefsDCB.pCount = 1; prefsDCB.pCount = 1;
GetSysPrefsGS(&prefsDCB); GetSysPrefsGS(&prefsDCB);
cookie->oldPrefs = prefsDCB.preferences; cookie->oldPrefs = prefsDCB.preferences;
prefsDCB.preferences = (prefsDCB.preferences & 0x1fff) | 0x8000; prefsDCB.preferences = (prefsDCB.preferences & 0x1fff) | 0x8000;
SetSysPrefsGS(&prefsDCB); SetSysPrefsGS(&prefsDCB);
ResourceStartUp(memID); ResourceStartUp(memID);
myPath = LGetPathname2(memID, 1); myPath = LGetPathname2(memID, 1);
resFileID = OpenResourceFile(access, NULL, myPath); resFileID = OpenResourceFile(access, NULL, myPath);
if (_toolErr) { if (_toolErr) {
ResourceShutDown(); ResourceShutDown();
resFileID = 0; resFileID = 0;
} }
cookie->resFileID = resFileID; cookie->resFileID = resFileID;
SetLevelGS(&levelDCB); SetLevelGS(&levelDCB);
return resFileID; return resFileID;
} }
/* /*
@ -386,20 +401,19 @@ Word NDAResourceStartUp(Word memID, Word access, NDAResourceCookie *cookie) {
*/ */
void NDAResourceRestore(NDAResourceCookie *cookie) { void NDAResourceRestore(NDAResourceCookie *cookie) {
SysPrefsRecGS prefsDCB; SysPrefsRecGS prefsDCB;
prefsDCB.pCount = 1; prefsDCB.pCount = 1;
prefsDCB.preferences = cookie->oldPrefs; prefsDCB.preferences = cookie->oldPrefs;
SetSysPrefsGS(&prefsDCB); SetSysPrefsGS(&prefsDCB);
SetCurResourceApp(cookie->oldRApp); SetCurResourceApp(cookie->oldRApp);
} }
/* /*
* close the resource fork. * close the resource fork.
*/ */
void NDAResourceShutDown(NDAResourceCookie *cookie) { void NDAResourceShutDown(NDAResourceCookie *cookie) {
CloseResourceFile(cookie->resFileID); CloseResourceFile(cookie->resFileID);
ResourceShutDown(); ResourceShutDown();
} }