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

View File

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

View File

@ -3,14 +3,16 @@
#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'),
ONECHAR('C'),

View File

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

View File

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

262
qserver.c
View File

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

84
tools.c
View File

@ -1,7 +1,11 @@
/* 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)
Memory Manager (#2)
@ -15,7 +19,9 @@ LineEdit (#20)
Dialog Manager (#21)
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
Scheduler
@ -24,22 +30,19 @@ Integer Math.
*/
#pragma lint -1
#pragma noroot
#pragma optimize -1
#include <gsos.h>
#include <intmath.h>
#include <loader.h>
#include <locator.h>
#include <memory.h>
#include <intmath.h>
#include <resources.h>
#include <gsos.h>
#include <loader.h>
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);
@ -91,7 +94,8 @@ static char NullString[] = "\p";
static char ok[] = "\pContinue";
static unsigned centerX(void) {
if (GetMasterSCB() & 0x80) return 180; /* (640-280) */
if (GetMasterSCB() & 0x80)
return 180; /* (640-280) */
return 20; /* 320 - 280 */
}
@ -122,7 +126,6 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
unsigned errors = 0;
unsigned level = 0;
ssRef->resFileID = 0;
ssRef->dPageHandle = 0;
@ -144,37 +147,48 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
tn &= 0x00ff;
switch (tn) {
case 0x0a:
if (SANEStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
if (SANEStatus() && !_toolErr)
tn |= 0x8000;
else
dp += 0x0100;
break;
case 0x12:
if (QDAuxStatus() && !_toolErr) tn |= 0x8000;
if (QDAuxStatus() && !_toolErr)
tn |= 0x8000;
break;
case 0x13:
if (PMStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0200;
if (PMStatus() && !_toolErr)
tn |= 0x8000;
else
dp += 0x0200;
break;
case 0x17:
if (SFStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
if (SFStatus() && !_toolErr)
tn |= 0x8000;
else
dp += 0x0100;
break;
case 0x1b:
if (FMStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
if (FMStatus() && !_toolErr)
tn |= 0x8000;
else
dp += 0x0100;
break;
case 0x1c:
if (ListStatus() && !_toolErr) tn |= 0x8000;
if (ListStatus() && !_toolErr)
tn |= 0x8000;
break;
case 0x22:
if (TEStatus() && !_toolErr) tn |= 0x8000;
else dp += 0x0100;
if (TEStatus() && !_toolErr)
tn |= 0x8000;
else
dp += 0x0100;
break;
#if 0
@ -185,12 +199,13 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
#endif
case 0x26:
if (MCStatus() && !_toolErr) tn |= 0x8000;
if (MCStatus() && !_toolErr)
tn |= 0x8000;
break;
case 0x36:
if (TCPIPStatus() && !_toolErr) tn |= 0x8000;
if (TCPIPStatus() && !_toolErr)
tn |= 0x8000;
break;
default:
@ -201,7 +216,8 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
if (dp) {
Handle h = NewHandle(dp, memID, 0xc005, 0);
if (_toolErr) return 0;
if (_toolErr)
return 0;
dptr = *(unsigned char **)h;
ssRef->dPageHandle = h;
}
@ -209,8 +225,10 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) {
for (i = 0; i < ssRef->numTools; ++i) {
unsigned tn = ssRef->theTools[i].toolNumber;
unsigned version = ssRef->theTools[i].minVersion;
if (tn == 0) continue;
if (tn & 0x8000) continue;
if (tn == 0)
continue;
if (tn & 0x8000)
continue;
LoadOneTool(tn, version);
if (_toolErr) {
@ -291,7 +309,8 @@ void NDAShutDownTools(StartStopRecord *ssRef){
for (i = 0; i < ssRef->numTools; ++i) {
unsigned tn = ssRef->theTools[i].toolNumber;
if (!(tn & 0x1000)) continue;
if (!(tn & 0x1000))
continue;
switch (tn & 0xff) {
case 0x0a:
SANEShutDown();
@ -322,16 +341,12 @@ void NDAShutDownTools(StartStopRecord *ssRef){
TCPIPShutDown();
break;
}
}
if (ssRef->dPageHandle)
DisposeHandle(ssRef->dPageHandle);
}
typedef struct NDAResourceCookie {
Word oldPrefs;
Word oldRApp;
@ -402,4 +417,3 @@ void NDAResourceShutDown(NDAResourceCookie *cookie) {
CloseResourceFile(cookie->resFileID);
ResourceShutDown();
}