diff --git a/common.c b/common.c index c1c42c9..f0a2c34 100644 --- a/common.c +++ b/common.c @@ -2,9 +2,9 @@ #pragma lint -1 #pragma optimize -1 +#include #include #include -#include #include #include "macroman.h" @@ -23,160 +23,148 @@ char tmp[6]; } #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) -{ -Word oFile; -Word oDepth; + int rID; + Word rCount; -int rID; -Word rCount; + Handle rHandle; + Handle h; -Handle rHandle; -Handle h; + h = NULL; + oFile = GetCurResourceFile(); + SetCurResourceFile(rFile); + oDepth = SetResourceFileDepth(1); + rCount = CountResources(rTextForLETextBox2); - h = NULL; + // printint("rCount: ", rCount); - oFile = GetCurResourceFile(); - SetCurResourceFile(rFile); - oDepth = SetResourceFileDepth(1); - rCount = CountResources(rTextForLETextBox2); + if (rCount) { + WordDivRec wdr; + longword index; - //printint("rCount: ", rCount); + wdr = UDivide(Random(), (word)rCount); - if (rCount) - { - WordDivRec wdr; - longword index; + // printint("remainder: ", wdr.remainder); - 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 - //printint("index: ", index); + word len; + word i; + oldLen = (word)GetHandleSize(rHandle); + // printint("oldLen: ", oldLen); - rHandle = LoadResource(rTextForLETextBox2, index); - //printint("loadres: ", _toolErr); - if (!_toolErr) - { - word oldLen; - word newLen; - char *newText; - char *oldText; + h = NewHandle(oldLen << 2 + 2, mID, 0, NULL); + if (!_toolErr) { + HLock(h); + HLock(rHandle); - word len; - word i; + oldText = *rHandle; + newText = *h; + newLen = 0; - oldLen = (word)GetHandleSize(rHandle); - //printint("oldLen: ", oldLen); + i = 0; + while (i < oldLen) { + char c; - h = NewHandle(oldLen << 2 + 2, mID, 0, NULL); - if (!_toolErr) - { - HLock(h); - HLock(rHandle); + c = *oldText++; + i++; - oldText = *rHandle; - newText = *h; - newLen = 0; + if (c == '\r') { + *((Word *)newText) = 0x0A0D; + newText += 2; + newLen += 2; + continue; - i = 0; - while (i < oldLen) - { - char c; + //*newText++ = '\r'; + //*newText++ = '\n'; + // newLen += 2; + // continue; + } + if (c == 0x01) // formatting codes. + { + c = *oldText; + switch (c) { + case 'F': // font + oldText += 5; + i += 5; + break; - c = *oldText++; - i++; + case 'S': // set style + oldText += 5; + i += 4; + break; - if (c == '\r') - { - *((Word *)newText) = 0x0A0D; - newText += 2; - newLen += 2; - continue; + case 'C': // fore color + case 'B': // back color + case 'J': // justify + case 'L': // left margin + 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; - //*newText++ = '\r'; - //*newText++ = '\n'; - //newLen += 2; - //continue; - } - if (c == 0x01) // formatting codes. - { - c = *oldText; - switch (c) - { - case 'F': // font - oldText += 5; - i += 5; - break; + if (j == 0) + continue; - case 'S': // set style - oldText += 5; - i += 4; - break; + if (j > 1) { + char *cp; + cp = macroman[c].cp; - case 'C': // fore color - case 'B': // back color - case 'J': // justify - case 'L': // left margin - 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; + newLen += j; + do { + *newText++ = *cp++; + } while (--j); - if (j == 0) continue; + continue; + } else + c = (char)macroman[c].cp; + } - if (j > 1) - { - char *cp; - cp = macroman[c].cp; + newLen++; + *newText++ = c; + } - newLen += j; - do - { - *newText++ = *cp++; - } - while (--j); + //*newText++ = '\r'; + //*newText++ = '\n'; + *((Word *)newText) = 0x0A0D; + newLen += 2; + HUnlock(h); + SetHandleSize(newLen, h); + } - continue; - } - else c = (char)macroman[c].cp; - } + HUnlock(rHandle); + ReleaseResource(0, rTextForLETextBox2, index); + } + } + SetCurResourceFile(oFile); + SetResourceFileDepth(oDepth); - newLen++; - *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; + return h; } diff --git a/config.c b/config.c index 318256b..0454078 100644 --- a/config.c +++ b/config.c @@ -14,7 +14,6 @@ #include "qserver.h" - extern Handle rPath; static Word fd; @@ -24,42 +23,43 @@ static Word fd; * return 0 on failure, anything else on success. */ // -Word LoadConfig(Word MyID) -{ -Word t; -Word oFile; -Word oDepth; +Word LoadConfig(Word MyID) { + Word t; + Word oFile; + Word oDepth; -static GSString32 filePath = {28, "*:System:Preferences:QServer"}; -static GSString32 folderPath = {21, "*:System:Preferences:"}; + 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 FileInfoRecGS InfoDCB = {12, (GSString255Ptr)&filePath}; + static CreateRecGS CreateDCB = {4, (GSString255Ptr)&folderPath, 0xe3, 0x0f, + 0}; -// 1 - check if file exists -// 2 - if no, create the folder and file -// 3 - load up the data -// 4 - if data doesn't exist, store a default value. + // 1 - check if file exists + // 2 - if no, create the folder and file + // 3 - load up the data + // 4 - if data doesn't exist, store a default value. fd = 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; + CreateResourceFile(0, 0x5A, 0xe3, (Pointer)&filePath); + 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) - { - static GSString255 defPath = { 34, "*/system/CDEVs/Twilight/QuotesFile"}; + 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,19 +97,17 @@ 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) -{ -GSString255 * gstr = (GSString255 *)data; -CtlRecHndl CtrlHand; -Rect r; +static void SetText(WindowPtr win, Word id, void *data) { + GSString255 *gstr = (GSString255 *)data; + CtlRecHndl CtrlHand; + Rect r; CtrlHand = GetCtlHandleFromID(win, id); @@ -124,27 +120,26 @@ Rect r; SetCtlTitle(gstr->text, (Handle)CtrlHand); } else { SetCtlValue(0, CtrlHand); - SetCtlTitle("", (Handle)CtrlHand); + SetCtlTitle("", (Handle)CtrlHand); } } -void DoConfig(Word MyID) -{ -static EventRecord event; +void DoConfig(Word MyID) { + static EventRecord event; -WindowPtr win; -Word control; -Word ok; -GrafPortPtr oldPort; -Handle newPath = NULL; + WindowPtr win; + Word control; + Word ok; + GrafPortPtr oldPort; + Handle newPath = NULL; oldPort = GetPort(); 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,58 +150,49 @@ 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; + myReply.nameRefDesc = refIsNewHandle; + myReply.pathRefDesc = refIsNewHandle; - SFGetFile2( - 10, 35, - refIsPointer, - (Ref)"\pSelect quotation file.", - (WordProcPtr)SFFilter, /* filter proc */ - NULL, /* type list */ - &myReply); - if (myReply.good) - { - Handle h; - Word size; + SFGetFile2(10, 35, refIsPointer, (Ref) "\pSelect quotation file.", + (WordProcPtr)SFFilter, /* filter proc */ + NULL, /* type list */ + &myReply); + if (myReply.good) { + Handle h; + Word size; - h = (Handle)myReply.pathRef; - HLock(h); - size = GetHandleSize(h) - 2; - BlockMove(*h + 2, *h, size); - ReAllocHandle(size, MyID, 0x8000, NULL, h); + h = (Handle)myReply.pathRef; + HLock(h); + size = GetHandleSize(h) - 2; + BlockMove(*h + 2, *h, size); + ReAllocHandle(size, MyID, 0x8000, NULL, h); - SetText(win, CtrlPath, *h); + SetText(win, CtrlPath, *h); - if (newPath) DisposeHandle(newPath); - newPath = h; + if (newPath) + DisposeHandle(newPath); + newPath = h; - DisposeHandle((Handle)myReply.nameRef); - } + 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); - } diff --git a/macroman.c b/macroman.c index e2aa0a4..96e541c 100644 --- a/macroman.c +++ b/macroman.c @@ -3,148 +3,150 @@ #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] = -{ - ONECHAR('A'), // 0x80 - ONECHAR('A'), - ONECHAR('C'), - ONECHAR('E'), - ONECHAR('N'), - ONECHAR('O'), - ONECHAR('U'), - ONECHAR('a'), - ONECHAR('a'), - ONECHAR('a'), - ONECHAR('a'), - ONECHAR('a'), - ONECHAR('a'), - ONECHAR('c'), - ONECHAR('e'), - ONECHAR('e'), +struct charmap macroman[128] = { + ONECHAR('A'), // 0x80 + ONECHAR('A'), + ONECHAR('C'), + ONECHAR('E'), + ONECHAR('N'), + ONECHAR('O'), + ONECHAR('U'), + ONECHAR('a'), + ONECHAR('a'), + ONECHAR('a'), + ONECHAR('a'), + ONECHAR('a'), + ONECHAR('a'), + ONECHAR('c'), + ONECHAR('e'), + ONECHAR('e'), - ONECHAR('e'), // 0x90 - ONECHAR('e'), - ONECHAR('i'), - ONECHAR('i'), - ONECHAR('i'), - ONECHAR('i'), - ONECHAR('n'), - ONECHAR('o'), - ONECHAR('o'), - ONECHAR('o'), - ONECHAR('o'), - ONECHAR('o'), - ONECHAR('u'), - ONECHAR('u'), - ONECHAR('u'), - ONECHAR('u'), + ONECHAR('e'), // 0x90 + ONECHAR('e'), + ONECHAR('i'), + ONECHAR('i'), + ONECHAR('i'), + ONECHAR('i'), + ONECHAR('n'), + ONECHAR('o'), + ONECHAR('o'), + ONECHAR('o'), + ONECHAR('o'), + ONECHAR('o'), + ONECHAR('u'), + ONECHAR('u'), + ONECHAR('u'), + ONECHAR('u'), - BLANK, // 0xA0 - BLANK, - BLANK, - BLANK, - BLANK, - ONECHAR('*'), - BLANK, - BLANK, - MULTICHAR("(r)"), - MULTICHAR("(c)"), - MULTICHAR("tm"), - BLANK, - BLANK, - BLANK, - MULTICHAR("AE"), - ONECHAR('O'), + BLANK, // 0xA0 + BLANK, + BLANK, + BLANK, + BLANK, + ONECHAR('*'), + BLANK, + BLANK, + MULTICHAR("(r)"), + MULTICHAR("(c)"), + MULTICHAR("tm"), + BLANK, + BLANK, + BLANK, + MULTICHAR("AE"), + ONECHAR('O'), - BLANK, // 0xB0 - BLANK, - MULTICHAR("<="), - MULTICHAR(">="), - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - MULTICHAR("ae"), - ONECHAR('o'), + BLANK, // 0xB0 + BLANK, + MULTICHAR("<="), + MULTICHAR(">="), + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + MULTICHAR("ae"), + ONECHAR('o'), - ONECHAR('?'), // 0xC0 - ONECHAR('!'), - BLANK, - BLANK, - ONECHAR('f'), - BLANK, - BLANK, - MULTICHAR("<<"), - MULTICHAR(">>"), - MULTICHAR("..."), - ONECHAR(' '), - ONECHAR('A'), - ONECHAR('A'), - ONECHAR('O'), - 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"), + ONECHAR('?'), // 0xC0 + ONECHAR('!'), + BLANK, + BLANK, + ONECHAR('f'), + BLANK, + BLANK, + MULTICHAR("<<"), + MULTICHAR(">>"), + MULTICHAR("..."), + ONECHAR(' '), + ONECHAR('A'), + ONECHAR('A'), + ONECHAR('O'), + MULTICHAR("OE"), + MULTICHAR("oe"), - BLANK, // 0xE0 - BLANK, - BLANK, - BLANK, - BLANK, - ONECHAR('A'), - ONECHAR('E'), - ONECHAR('A'), - ONECHAR('E'), - ONECHAR('E'), - ONECHAR('I'), - ONECHAR('I'), - ONECHAR('I'), - ONECHAR('I'), - ONECHAR('O'), - ONECHAR('O'), - - ONECHAR('?'), // 0xF0 - ONECHAR('O'), - ONECHAR('U'), - ONECHAR('U'), - ONECHAR('U'), - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, - BLANK, + MULTICHAR("--"), // 0xD0 + MULTICHAR("---"), + ONECHAR('"'), + ONECHAR('"'), + ONECHAR('\''), + ONECHAR('\''), + BLANK, + BLANK, + ONECHAR('y'), + ONECHAR('Y'), + ONECHAR('/'), + BLANK, + BLANK, + BLANK, + MULTICHAR("fi"), + MULTICHAR("fl"), + + BLANK, // 0xE0 + BLANK, + BLANK, + BLANK, + BLANK, + ONECHAR('A'), + ONECHAR('E'), + ONECHAR('A'), + ONECHAR('E'), + ONECHAR('E'), + ONECHAR('I'), + ONECHAR('I'), + ONECHAR('I'), + ONECHAR('I'), + ONECHAR('O'), + ONECHAR('O'), + + ONECHAR('?'), // 0xF0 + ONECHAR('O'), + ONECHAR('U'), + ONECHAR('U'), + ONECHAR('U'), + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, + BLANK, }; diff --git a/macroman.h b/macroman.h index 653aa5e..0c22ed1 100644 --- a/macroman.h +++ b/macroman.h @@ -1,10 +1,9 @@ #ifndef __MACROMAN_H__ #define __MACROMAN_H__ -struct charmap -{ - int length; - char *cp; +struct charmap { + int length; + char *cp; }; extern struct charmap macroman[128]; diff --git a/marinetti.c b/marinetti.c index baea902..dacb99e 100644 --- a/marinetti.c +++ b/marinetti.c @@ -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 flag = 0; +int startMarinetti(void) { + int flag = 0; TCPIPStatus(); - if (_toolErr) - { - LoadOneTool(0x36, 0x0200); //load Marinetti - if (_toolErr) return FLAG_ERROR; + if (_toolErr) { + LoadOneTool(0x36, 0x0200); // load Marinetti + 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; } - - - - - - - - - - - - - - diff --git a/qserver.c b/qserver.c index b42b338..5eb42ba 100644 --- a/qserver.c +++ b/qserver.c @@ -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 optimize -1 -#include -#include -#include -#include -#include +#include #include #include -#include -#include -#include -#include -#include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include #include +#include #include #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,16 +58,14 @@ Boolean ToolsLoaded; Word MyID; Word Ipid; - word rFile; Handle rPath; word rCount; -struct qentry -{ - Word ipid; - Word state; - Longword tick; +struct qentry { + Word ipid; + Word state; + Longword tick; }; #define QSIZE 16 @@ -82,11 +74,9 @@ struct qentry queue[QSIZE]; word total; word current; - -void fixstats(void) -{ -static char stats[16]; -Word i; +void fixstats(void) { + static char stats[16]; + Word i; i = sprintf(stats + 1, "%u : %u", current, total); stats[0] = i; // pascal string @@ -95,282 +85,247 @@ Word i; DrawInfoBar(MyWindow); } +void InsertString(word length, char *cp) { + Handle handle; + TERecord **temp; + longword oldStart, oldEnd; -void InsertString(word length, char *cp) -{ -Handle handle; -TERecord **temp; -longword oldStart, oldEnd; + handle = (Handle)GetCtlHandleFromID(MyWindow, CtrlTE); + temp = (TERecord **)handle; - handle = (Handle)GetCtlHandleFromID(MyWindow, CtrlTE); - temp = (TERecord **)handle; + (**temp).textFlags &= (~fReadOnly); - (**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); - TEInsert(teDataIsTextBlock, (Ref)cp, length, - NULL, NULL, /* no style info */ - handle); - - (**temp).textFlags |= fReadOnly; - - TESetSelection((Pointer)oldStart, (Pointer)oldEnd, handle); + (**temp).textFlags |= fReadOnly; + TESetSelection((Pointer)oldStart, (Pointer)oldEnd, handle); } - -enum -{ - STATE_NULL = 0, - STATE_ESTABLISH, // waiting to establish - STATE_QUOTE, // send the quote... - STATE_SEND, // waiting for data to send - STATE_CLOSE +enum { + STATE_NULL = 0, + STATE_ESTABLISH, // waiting to establish + STATE_QUOTE, // send the quote... + STATE_SEND, // waiting for data to send + STATE_CLOSE }; -void QServer(void) -{ -static srBuff srBuffer; -word delta; -int i; +void QServer(void) { + static srBuff srBuffer; + word delta; + int i; - delta = false; + delta = false; - TCPIPPoll(); - for (i = 0; i < QSIZE; i++) - { - word ipid; + TCPIPPoll(); + for (i = 0; i < QSIZE; i++) { + word ipid; - ipid = queue[i].ipid; - if (!ipid) continue; + ipid = queue[i].ipid; + if (!ipid) + continue; - TCPIPStatusTCP(ipid, &srBuffer); - if (_toolErr) - { - queue[i].ipid = 0; - queue[i].state = 0; - current--; - delta = true; - continue; - } + TCPIPStatusTCP(ipid, &srBuffer); + if (_toolErr) { + queue[i].ipid = 0; + queue[i].state = 0; + current--; + delta = true; + continue; + } - if (srBuffer.srState == TCPSCLOSED) - { - TCPIPLogout(ipid); - queue[i].ipid = 0; - queue[i].state = 0; - current--; - delta = true; - continue; - } + if (srBuffer.srState == TCPSCLOSED) { + TCPIPLogout(ipid); + queue[i].ipid = 0; + queue[i].state = 0; + current--; + delta = true; + continue; + } + switch (queue[i].state) { + case STATE_ESTABLISH: + if (srBuffer.srState != TCPSESTABLISHED) + break; - switch (queue[i].state) - { - case STATE_ESTABLISH: - if (srBuffer.srState != TCPSESTABLISHED) - break; + queue[i].state = STATE_QUOTE; + // drop through and send the quote. - queue[i].state = STATE_QUOTE; - // drop through and send the quote. + case STATE_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: - { - 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: + case STATE_SEND: - if (srBuffer.srSndQueued == 0) - { - TCPIPCloseTCP(ipid); - queue[i].state = STATE_CLOSE; - } - break; - } - } + if (srBuffer.srSndQueued == 0) { + TCPIPCloseTCP(ipid); + queue[i].state = STATE_CLOSE; + } + break; + } + } + // check for a new connection. + if (current < QSIZE) { + word child; + int i; + child = TCPIPAcceptTCP(Ipid, 0); - // check for a new connection. - if (current < QSIZE) - { - word child; - int i; - child = TCPIPAcceptTCP(Ipid, 0); - - if (!_toolErr) for (i = 0; i < QSIZE; i++) - { - if (!queue[i].ipid) - { - static char buffer[16]; - static char line[32]; - 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) - queue[i].state = STATE_SEND; - else - queue[i].state = STATE_ESTABLISH; + if (srBuffer.srState == TCPSESTABLISHED) + queue[i].state = STATE_SEND; + else + queue[i].state = STATE_ESTABLISH; - queue[i].tick = GetTick(); + queue[i].tick = GetTick(); - current++; - total++; - delta = true; - - TCPIPConvertIPToASCII(srBuffer.srDestIP, - buffer, 0); + current++; + total++; + delta = true; - j = sprintf(line, "%p:%u\r", - buffer, srBuffer.srDestPort); - - InsertString(j, line); + TCPIPConvertIPToASCII(srBuffer.srDestIP, buffer, 0); - break; - } - } - } - if (delta) fixstats(); // statistics changed. + j = sprintf(line, "%p:%u\r", buffer, srBuffer.srDestPort); + + InsertString(j, line); + + break; + } + } + } + if (delta) + fixstats(); // statistics changed. } +int StartServer(void) { + int i; + word oFile; + word oDepth; + static char err[256]; + GSString255 *path; -int StartServer(void) -{ -int i; -word oFile; -word oDepth; -static char err[256]; -GSString255 *path; + total = current = 0; - total = current = 0; - - if (!rPath) - { - InsertString(32, "Fatal: No quote file specified.\r"); - return false; - } - HLock(rPath); + if (!rPath) { + InsertString(32, "Fatal: No quote file specified.\r"); + return false; + } + HLock(rPath); path = *(GSString255 **)rPath; - rFile = OpenResourceFile(readEnable, NULL, (pointer)path); - if (_toolErr) - { - /* todo */ - InsertString(sprintf(err, "Fatal: Unable to open %.*s\r", path->length, path->text), - err); - return false; - } + rFile = OpenResourceFile(readEnable, NULL, (pointer)path); + if (_toolErr) { + /* todo */ + InsertString( + sprintf(err, "Fatal: Unable to open %.*s\r", path->length, path->text), + err); + return false; + } - oFile = GetCurResourceFile(); - SetCurResourceFile(rFile); - oDepth = SetResourceFileDepth(1); - rCount = CountResources(rTextForLETextBox2); - SetCurResourceFile(oFile); - SetResourceFileDepth(oDepth); + oFile = GetCurResourceFile(); + SetCurResourceFile(rFile); + oDepth = SetResourceFileDepth(1); + rCount = CountResources(rTextForLETextBox2); + SetCurResourceFile(oFile); + SetResourceFileDepth(oDepth); - if (!rCount) - { - /* todo */ - InsertString(sprintf(err, "Fatal: Invalid quote file %.*s\r", path->length, path->text), - err); + if (!rCount) { + /* todo */ + InsertString(sprintf(err, "Fatal: Invalid quote file %.*s\r", path->length, + path->text), + err); - CloseResourceFile(rFile); - return false; - } + CloseResourceFile(rFile); + 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++) - { - queue[i].ipid = 0; - queue[i].state = 0; - } + Ipid = TCPIPLogin(MyID, 0, 0, 0, 64); - 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); - HiliteCtlByID(noHilite, MyWindow, CtrlStopQS); - - fixstats(); - HUnlock(rPath); - - InsertString(16, "QServer started\r"); - return true; + fixstats(); + HUnlock(rPath); + InsertString(16, "QServer started\r"); + return true; } -int StopServer(void) -{ -int i; +int StopServer(void) { + 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 - for (i = 0; i < QSIZE; i++) - { - int ipid; - ipid = queue[i].ipid; - if (ipid) - { - TCPIPAbortTCP(ipid); - TCPIPLogout(ipid); - queue[i].ipid = 0; - } - } + TCPIPCloseTCP(Ipid); + TCPIPLogout(Ipid); - TCPIPCloseTCP(Ipid); - TCPIPLogout(Ipid); + FlagQS = false; + Ipid = 0; - FlagQS = false; - Ipid = 0; + HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS); + HiliteCtlByID(noHilite, MyWindow, CtrlStartQS); - HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS); - HiliteCtlByID(noHilite, MyWindow, CtrlStartQS); + CloseResourceFile(rFile); - CloseResourceFile(rFile); + SetInfoRefCon((LongWord) "\pServer stopped", MyWindow); + DrawInfoBar(MyWindow); + InsertString(16, "QServer stopped\r"); - SetInfoRefCon((LongWord)"\pServer stopped", MyWindow); - DrawInfoBar(MyWindow); - - InsertString(16, "QServer stopped\r"); - - return true; + return true; } - // activate/inactivate controls based on Marinetti status -void UpdateStatus(Boolean redraw) -{ +void UpdateStatus(Boolean redraw) { if (FlagTCP) // TCP started { - // deactivate + // deactivate HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartM); HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS); @@ -378,11 +333,9 @@ void UpdateStatus(Boolean redraw) HiliteCtlByID(noHilite, MyWindow, CtrlStopM); HiliteCtlByID(noHilite, MyWindow, CtrlStartQS); - SetInfoRefCon((LongWord)"\pNetwork Connected", MyWindow); - } - else - { - // activate + SetInfoRefCon((LongWord) "\pNetwork Connected", MyWindow); + } else { + // activate HiliteCtlByID(noHilite, MyWindow, CtrlStartM); // deactivate @@ -390,94 +343,78 @@ void UpdateStatus(Boolean redraw) HiliteCtlByID(inactiveHilite, MyWindow, CtrlStartQS); HiliteCtlByID(inactiveHilite, MyWindow, CtrlStopQS); - SetInfoRefCon((LongWord)"\pNetwork Disconnected", MyWindow); + SetInfoRefCon((LongWord) "\pNetwork Disconnected", MyWindow); } - if (redraw) + if (redraw) DrawInfoBar(MyWindow); - } - - - - -#pragma databank 1 +#pragma databank 1 /* * watch for */ -pascal word HandleRequest(word request, longword dataIn, longword dataOut) -{ -Word oldRApp; +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); + MoveTo(8, 22); DrawString(str); } } -void DrawWindow(void) -{ - DrawControls(GetPort()); -} +void DrawWindow(void) { DrawControls(GetPort()); } #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; - -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,31 +445,28 @@ GrafPortPtr NDAOpen(void) SetSysWindow(MyWindow); ShowWindow(MyWindow); SelectWindow(MyWindow); - } NDAResourceRestore(&resInfo); return MyWindow; } -void NDAClose(void) -{ - // if running, shut down. +void NDAClose(void) { + // if running, shut down. - if (FlagQS) StopServer(); + if (FlagQS) + StopServer(); - AcceptRequests(ReqName, MyID, NULL); - CloseWindow(MyWindow); - MyWindow = NULL; + AcceptRequests(ReqName, MyID, NULL); + CloseWindow(MyWindow); + MyWindow = NULL; - UnloadConfig(); - NDAResourceShutDown(&resInfo); + UnloadConfig(); + 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 eventCode; -static EventRecord event = { 0 }; -static word counter = 0; +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,60 +504,51 @@ 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); } break; - /* start the server */ - case CtrlStartQS: - StartServer(); - break; + /* start the server */ + case CtrlStartQS: + StartServer(); + break; - /* stop the server */ - case CtrlStopQS: - StopServer(); - break; + /* stop the server */ + case CtrlStopQS: + StopServer(); + break; - case CtrlConfig: - DoConfig(MyID); - break; + case CtrlConfig: + DoConfig(MyID); + break; } // todo - Command-A selects all. } - } - else if (code == copyAction) - { + } else if (code == copyAction) { TECopy(NULL); return 1; // yes we handled it. } - return 0; - + return 0; } diff --git a/qserver.h b/qserver.h index f90a836..3700c18 100644 --- a/qserver.h +++ b/qserver.h @@ -3,27 +3,27 @@ * */ -#define rQSWindow 0x1000 +#define rQSWindow 0x1000 -#define CtrlStartM 0x1001 -#define CtrlStopM 0x1002 -#define CtrlStartQS 0x1003 -#define CtrlStopQS 0x1004 -#define CtrlTE 0x1005 -#define CtrlLogo 0x1006 -#define CtrlConfig 0x1007 +#define CtrlStartM 0x1001 +#define CtrlStopM 0x1002 +#define CtrlStartQS 0x1003 +#define CtrlStopQS 0x1004 +#define CtrlTE 0x1005 +#define CtrlLogo 0x1006 +#define CtrlConfig 0x1007 -#define rConfigWindow 0x2000 -#define CtrlBrowse 0x2001 +#define rConfigWindow 0x2000 +#define CtrlBrowse 0x2001 //#define CtrlPortLE 0x2002 //#define CtrlPathLE 0x2003 //#define CtrlPortStat 0x2004 -#define CtrlPathStat 0x2005 -#define CtrlPath 0x2006 -#define CtrlCancel 0x2007 -#define CtrlOk 0x2008 +#define CtrlPathStat 0x2005 +#define CtrlPath 0x2006 +#define CtrlCancel 0x2007 +#define CtrlOk 0x2008 -#define PORT_QOTD 17 +#define PORT_QOTD 17 #define ConfigWindowWidth 300 #define ConfigWindowHeight 52 diff --git a/tools.c b/tools.c index c10bdf6..53ddb19 100644 --- a/tools.c +++ b/tools.c @@ -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,158 +30,166 @@ Integer Math. */ - - #pragma lint -1 #pragma noroot #pragma optimize -1 +#include +#include +#include #include #include -#include #include -#include -#include -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 ListShutDown(void) inline(0x031C,dispatcher); -extern pascal Word ListVersion(void) inline(0x041C,dispatcher); -extern pascal Boolean ListStatus(void) inline(0x061C,dispatcher); +extern pascal void TCPIPStartUp(void) inline(0x0236, dispatcher); +extern pascal void TCPIPShutDown(void) inline(0x0336, dispatcher); +extern pascal Word TCPIPVersion(void) inline(0x0436, 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 TCPIPShutDown (void) inline(0x0336,dispatcher); -extern pascal Word TCPIPVersion (void) inline(0x0436,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 SANEStartUp(Word) inline(0x020A, dispatcher); +extern pascal void SANEShutDown(void) inline(0x030A, dispatcher); +extern pascal Word SANEVersion(void) inline(0x040A, dispatcher); +extern pascal Word SANEStatus(void) inline(0x060A, dispatcher); -extern pascal void SANEStartUp(Word) inline(0x020A,dispatcher); -extern pascal void SANEShutDown(void) inline(0x030A,dispatcher); -extern pascal Word SANEVersion(void) inline(0x040A,dispatcher); -extern pascal Word SANEStatus(void) inline(0x060A,dispatcher); +extern pascal void TEStartUp(Word, Word) inline(0x0222, dispatcher); +extern pascal void TEShutDown(void) inline(0x0322, dispatcher); +extern pascal Word TEVersion(void) inline(0x0422, dispatcher); +extern pascal Word TEStatus(void) inline(0x0622, dispatcher); -extern pascal void TEStartUp(Word, Word) inline(0x0222,dispatcher); -extern pascal void TEShutDown(void) inline(0x0322,dispatcher); -extern pascal Word TEVersion(void) inline(0x0422,dispatcher); -extern pascal Word TEStatus(void) inline(0x0622,dispatcher); +extern pascal void PMStartUp(Word, Word) inline(0x0213, dispatcher); +extern pascal void PMShutDown(void) inline(0x0313, dispatcher); +extern pascal Word PMVersion(void) inline(0x0413, dispatcher); +extern pascal Boolean PMStatus(void) inline(0x0613, dispatcher); -extern pascal void PMStartUp(Word, Word) inline(0x0213,dispatcher); -extern pascal void PMShutDown(void) inline(0x0313,dispatcher); -extern pascal Word PMVersion(void) inline(0x0413,dispatcher); -extern pascal Boolean PMStatus(void) inline(0x0613,dispatcher); +extern pascal void FMStartUp(Word, Word) inline(0x021B, dispatcher); +extern pascal void FMShutDown(void) inline(0x031B, dispatcher); +extern pascal Word FMVersion(void) inline(0x041B, dispatcher); +extern pascal Boolean FMStatus(void) inline(0x061B, dispatcher); -extern pascal void FMStartUp(Word, Word) inline(0x021B,dispatcher); -extern pascal void FMShutDown(void) inline(0x031B,dispatcher); -extern pascal Word FMVersion(void) inline(0x041B,dispatcher); -extern pascal Boolean FMStatus(void) inline(0x061B,dispatcher); +extern pascal void QDAuxStartUp(void) inline(0x0212, dispatcher); +extern pascal void QDAuxShutDown(void) inline(0x0312, dispatcher); +extern pascal Word QDAuxVersion(void) inline(0x0412, dispatcher); +extern pascal Boolean QDAuxStatus(void) inline(0x0612, dispatcher); -extern pascal void QDAuxStartUp(void) inline(0x0212,dispatcher); -extern pascal void QDAuxShutDown(void) inline(0x0312,dispatcher); -extern pascal Word QDAuxVersion(void) inline(0x0412,dispatcher); -extern pascal Boolean QDAuxStatus(void) inline(0x0612,dispatcher); +extern pascal void SFStartUp(Word, Word) inline(0x0217, dispatcher); +extern pascal void SFShutDown(void) inline(0x0317, dispatcher); +extern pascal Word SFVersion(void) inline(0x0417, dispatcher); +extern pascal Boolean SFStatus(void) inline(0x0617, dispatcher); -extern pascal void SFStartUp(Word, Word) inline(0x0217,dispatcher); -extern pascal void SFShutDown(void) inline(0x0317,dispatcher); -extern pascal Word SFVersion(void) inline(0x0417,dispatcher); -extern pascal Boolean SFStatus(void) inline(0x0617,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); +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 ok[] = "\pContinue"; static unsigned centerX(void) { - if (GetMasterSCB() & 0x80) return 180; /* (640-280) */ - return 20; /* 320 - 280 */ + if (GetMasterSCB() & 0x80) + return 180; /* (640-280) */ + return 20; /* 320 - 280 */ } static void ErrorLoading(unsigned tool) { - static char msg1[] = "\pThis desk accessory needs Tool000"; - static char msg2[] = "\pin the System:Tools folder."; + static char msg1[] = "\pThis desk accessory needs Tool000"; + static char msg2[] = "\pin the System:Tools folder."; - Int2Dec(tool, msg1+31, 3, 0); - msg1[31] |= 0x10; /* ' ' -> '0' */ - TLMountVolume(centerX(), 67, msg1, msg2, ok, ok); + Int2Dec(tool, msg1 + 31, 3, 0); + msg1[31] |= 0x10; /* ' ' -> '0' */ + TLMountVolume(centerX(), 67, msg1, msg2, ok, ok); } void ErrorStarting(unsigned tool) { - static char msg1[] = "\pError starting Tool000"; + static char msg1[] = "\pError starting Tool000"; - Int2Dec(tool, msg1+20, 3, 0); - msg1[20] |= 0x10; /* ' ' -> '0' */ - TLMountVolume(centerX(), 67, msg1, NullString, ok, ok); + Int2Dec(tool, msg1 + 20, 3, 0); + msg1[20] |= 0x10; /* ' ' -> '0' */ + TLMountVolume(centerX(), 67, msg1, NullString, ok, ok); } 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->dPageHandle = 0; + ssRef->resFileID = 0; + ssRef->dPageHandle = 0; - /* - todo: - 25 - note synth - 26 - note seq - 29 - ACE - 30 - resource manager - 32 - MIDI - 33 - VOC - 35 - MidiSynth - 37 - Animation + /* + todo: + 25 - note synth + 26 - note seq + 29 - ACE + 30 - resource manager + 32 - MIDI + 33 - VOC + 35 - MidiSynth + 37 - Animation - */ - /* check which ones are already loaded */ - for (i = 0; i < ssRef->numTools; ++i) { - unsigned tn = ssRef->theTools[i].toolNumber; - tn &= 0x00ff; - switch(tn) { - case 0x0a: - if (SANEStatus() && !_toolErr) tn |= 0x8000; - else dp += 0x0100; - break; + */ + /* check which ones are already loaded */ + for (i = 0; i < ssRef->numTools; ++i) { + unsigned tn = ssRef->theTools[i].toolNumber; + tn &= 0x00ff; + switch (tn) { + case 0x0a: + if (SANEStatus() && !_toolErr) + tn |= 0x8000; + else + dp += 0x0100; + break; - case 0x12: - if (QDAuxStatus() && !_toolErr) tn |= 0x8000; - break; + case 0x12: + if (QDAuxStatus() && !_toolErr) + tn |= 0x8000; + break; - case 0x13: - if (PMStatus() && !_toolErr) tn |= 0x8000; - else dp += 0x0200; - break; + case 0x13: + if (PMStatus() && !_toolErr) + tn |= 0x8000; + else + dp += 0x0200; + break; - case 0x17: - if (SFStatus() && !_toolErr) tn |= 0x8000; - else dp += 0x0100; - break; + case 0x17: + if (SFStatus() && !_toolErr) + tn |= 0x8000; + else + dp += 0x0100; + break; - case 0x1b: - if (FMStatus() && !_toolErr) tn |= 0x8000; - else dp += 0x0100; - break; + case 0x1b: + if (FMStatus() && !_toolErr) + tn |= 0x8000; + else + dp += 0x0100; + break; - case 0x1c: - if (ListStatus() && !_toolErr) tn |= 0x8000; - break; + case 0x1c: + if (ListStatus() && !_toolErr) + tn |= 0x8000; + break; - - case 0x22: - if (TEStatus() && !_toolErr) tn |= 0x8000; - else dp += 0x0100; - break; + case 0x22: + if (TEStatus() && !_toolErr) + tn |= 0x8000; + else + dp += 0x0100; + break; #if 0 case 0x23: @@ -184,78 +198,82 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) { break; #endif - case 0x26: - if (MCStatus() && !_toolErr) tn |= 0x8000; - break; + case 0x26: + if (MCStatus() && !_toolErr) + tn |= 0x8000; + break; + case 0x36: + if (TCPIPStatus() && !_toolErr) + tn |= 0x8000; + break; - case 0x36: - if (TCPIPStatus() && !_toolErr) tn |= 0x8000; - break; + default: + tn = 0; + } + ssRef->theTools[i].toolNumber = tn; + } - default: - tn = 0; - } - ssRef->theTools[i].toolNumber = tn; - } + if (dp) { + Handle h = NewHandle(dp, memID, 0xc005, 0); + if (_toolErr) + return 0; + dptr = *(unsigned char **)h; + ssRef->dPageHandle = h; + } - if (dp) { - Handle h = NewHandle(dp, memID, 0xc005, 0); - if (_toolErr) return 0; - dptr = *(unsigned char **)h; - ssRef->dPageHandle = h; - } + 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; - 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; + LoadOneTool(tn, version); + if (_toolErr) { + ErrorLoading(tn); - LoadOneTool(tn, version); - if (_toolErr) { - ErrorLoading(tn); + tn |= 0x4000; + ssRef->theTools[i].toolNumber = tn; + ++errors; + continue; + } - tn |= 0x4000; - ssRef->theTools[i].toolNumber = tn; - ++errors; - continue; - } + _toolErr = 0; + switch (tn) { + case 0x0a: + SANEStartUp((Word)dptr); + dptr += 0x0100; + break; - _toolErr = 0; - switch(tn) { - case 0x0a: - SANEStartUp((Word)dptr); - dptr += 0x0100; - break; + case 0x12: + QDAuxStartUp(); + break; - case 0x12: - QDAuxStartUp(); - break; + case 0x13: + PMStartUp(memID, (Word)dptr); + dptr += 0x0200; + break; - case 0x13: - PMStartUp(memID, (Word)dptr); - dptr += 0x0200; - break; + case 0x17: + SFStartUp(memID, (Word)dptr); + dptr += 0x0100; + break; - case 0x17: - SFStartUp(memID, (Word)dptr); - dptr += 0x0100; - break; + case 0x1b: + FMStartUp(memID, (Word)dptr); + dptr += 0x0100; + break; - case 0x1b: - FMStartUp(memID, (Word)dptr); - dptr += 0x0100; - break; + case 0x1c: + ListStartUp(); + break; - case 0x1c: - ListStartUp(); - break; - - case 0x22: - TEStartUp(memID, (Word)dptr); - dptr += 0x0100; - break; + case 0x22: + TEStartUp(memID, (Word)dptr); + dptr += 0x0100; + break; #if 0 case 0x23: @@ -264,78 +282,75 @@ unsigned NDAStartUpTools(Word memID, StartStopRecord *ssRef) { break; #endif - case 0x26: - MCStartUp(memID); - break; + case 0x26: + MCStartUp(memID); + break; - case 0x36: - TCPIPStartUp(); - break; - } - if (_toolErr) { - ErrorStarting(tn); - ++errors; - tn |= 0x2000; - } else { - tn |= 0x1000; - } - ssRef->theTools[i].toolNumber = tn; - } + case 0x36: + TCPIPStartUp(); + break; + } + if (_toolErr) { + ErrorStarting(tn); + ++errors; + tn |= 0x2000; + } else { + tn |= 0x1000; + } + ssRef->theTools[i].toolNumber = tn; + } exit: - return errors; + return errors; } -void NDAShutDownTools(StartStopRecord *ssRef){ - unsigned i; +void NDAShutDownTools(StartStopRecord *ssRef) { + unsigned i; - for (i = 0; i < ssRef->numTools; ++i) { + for (i = 0; i < ssRef->numTools; ++i) { - unsigned tn = ssRef->theTools[i].toolNumber; - if (!(tn & 0x1000)) continue; - switch(tn & 0xff) { - case 0x0a: - SANEShutDown(); - break; - case 0x12: - QDAuxShutDown(); - break; - case 0x13: - PMShutDown(); - break; - case 0x17: - SFShutDown(); - break; - case 0x1b: - FMShutDown(); - break; - case 0x1c: - ListShutDown(); - break; - case 0x22: - TEShutDown(); - break; - case 0x26: - MCShutDown(); - break; - case 0x36: - if (TCPIPGetConnectStatus() == 0) - TCPIPShutDown(); - break; - } - - - } - - if (ssRef->dPageHandle) - DisposeHandle(ssRef->dPageHandle); + unsigned tn = ssRef->theTools[i].toolNumber; + if (!(tn & 0x1000)) + continue; + switch (tn & 0xff) { + case 0x0a: + SANEShutDown(); + break; + case 0x12: + QDAuxShutDown(); + break; + case 0x13: + PMShutDown(); + break; + case 0x17: + SFShutDown(); + break; + case 0x1b: + FMShutDown(); + break; + case 0x1c: + ListShutDown(); + break; + case 0x22: + TEShutDown(); + break; + case 0x26: + MCShutDown(); + break; + case 0x36: + if (TCPIPGetConnectStatus() == 0) + TCPIPShutDown(); + break; + } + } + if (ssRef->dPageHandle) + DisposeHandle(ssRef->dPageHandle); } - typedef struct NDAResourceCookie { - Word oldPrefs; - Word oldRApp; - Word resFileID; + Word oldPrefs; + Word oldRApp; + Word resFileID; } NDAResourceCookie; /* @@ -344,41 +359,41 @@ typedef struct NDAResourceCookie { */ Word NDAResourceStartUp(Word memID, Word access, NDAResourceCookie *cookie) { - Pointer myPath; - LevelRecGS levelDCB; - SysPrefsRecGS prefsDCB; - Word resFileID; - Word oldLevel; + Pointer myPath; + LevelRecGS levelDCB; + SysPrefsRecGS prefsDCB; + Word resFileID; + Word oldLevel; - cookie->oldPrefs = 0; - cookie->resFileID = 0; + cookie->oldPrefs = 0; + cookie->resFileID = 0; - cookie->oldRApp = GetCurResourceApp(); + cookie->oldRApp = GetCurResourceApp(); - levelDCB.pCount = 2; - GetLevelGS(&levelDCB); - oldLevel = levelDCB.level; - levelDCB.level = 0; - SetLevelGS(&levelDCB); - levelDCB.level = oldLevel; + levelDCB.pCount = 2; + GetLevelGS(&levelDCB); + oldLevel = levelDCB.level; + levelDCB.level = 0; + SetLevelGS(&levelDCB); + levelDCB.level = oldLevel; - prefsDCB.pCount = 1; - GetSysPrefsGS(&prefsDCB); - cookie->oldPrefs = prefsDCB.preferences; - prefsDCB.preferences = (prefsDCB.preferences & 0x1fff) | 0x8000; - SetSysPrefsGS(&prefsDCB); + prefsDCB.pCount = 1; + GetSysPrefsGS(&prefsDCB); + cookie->oldPrefs = prefsDCB.preferences; + prefsDCB.preferences = (prefsDCB.preferences & 0x1fff) | 0x8000; + SetSysPrefsGS(&prefsDCB); - ResourceStartUp(memID); - myPath = LGetPathname2(memID, 1); - resFileID = OpenResourceFile(access, NULL, myPath); - if (_toolErr) { - ResourceShutDown(); - resFileID = 0; - } - cookie->resFileID = resFileID; + ResourceStartUp(memID); + myPath = LGetPathname2(memID, 1); + resFileID = OpenResourceFile(access, NULL, myPath); + if (_toolErr) { + ResourceShutDown(); + resFileID = 0; + } + cookie->resFileID = resFileID; - SetLevelGS(&levelDCB); - return resFileID; + SetLevelGS(&levelDCB); + return resFileID; } /* @@ -386,20 +401,19 @@ Word NDAResourceStartUp(Word memID, Word access, NDAResourceCookie *cookie) { */ void NDAResourceRestore(NDAResourceCookie *cookie) { - SysPrefsRecGS prefsDCB; + SysPrefsRecGS prefsDCB; - prefsDCB.pCount = 1; - prefsDCB.preferences = cookie->oldPrefs; - SetSysPrefsGS(&prefsDCB); + prefsDCB.pCount = 1; + prefsDCB.preferences = cookie->oldPrefs; + SetSysPrefsGS(&prefsDCB); - SetCurResourceApp(cookie->oldRApp); + SetCurResourceApp(cookie->oldRApp); } /* * close the resource fork. */ void NDAResourceShutDown(NDAResourceCookie *cookie) { - CloseResourceFile(cookie->resFileID); - ResourceShutDown(); + CloseResourceFile(cookie->resFileID); + ResourceShutDown(); } -