void CleanupTransport(CFragConnectionID connID) { OSErr error; ConnHandle connection; unsigned long value; ser_t* ser; error = GetData(connID, &value); //Debugger(); if (value != nil) { ser = (ser_t*)value; if (ser->sConnection != nil) { error = CMClose(ser->sConnection, false, nil, 0, false); CMDispose(ser->sConnection); } DisposePtr((Ptr)ser); error = SetData(connID, nil); } }
OSErr OpenCTBConnection(ConnHandle* connection) { Str255 toolName; Point where; Ptr configStream; Ptr tempString; EventRecord event; Rect dialogLoc; OSErr error = noErr; char* here; char* end; long baud; Boolean done; short result = noErr; if (*connection != nil) { // put our A5 value into the connection record so that the search callbacks // can get it and restore it CMSetUserData(*connection,(long) LMGetCurrentA5()); // CMChoose Dialog has to hang off this point (global coordinates) SetRect(&dialogLoc, 0, 0, 495, 285); CenterOnCurrentScreen(&dialogLoc); where.h = dialogLoc.left; where.v = dialogLoc.top; // now do CMChoose et al: done = false; do { result = CMChoose(connection, where, NULL); // MAD fprintf(mfp,"result is %d. major = %d minor = %d\n",result,chooseOKMajor,chooseOKMinor); if ((result == chooseOKMajor) || (result == chooseOKMinor)) { configStream = CMGetConfig(*connection); if (configStream == NULL) { done = true; error = -1; } else { CMGetToolName((***connection).procID, toolName); tempString = NewPtrClear(GetPtrSize(configStream) + 5); strcpy(tempString, "Baud "); here = strstr(configStream, tempString); if (here != nil) { here += strlen(tempString); baud = strtol(here, &end, 10); if (baud < 38400) { // MAD: PC seems to default to this, baud = 38400; // no matter what the user tries to set! strcpy(tempString, configStream); sprintf(tempString + (here - configStream), "%ld", baud); strcat(tempString, end); error = CMSetConfig(*connection, tempString); // Try to use the modified configuration if (error == noErr) { // It worked; save it DisposePtr(configStream); configStream = NewPtrClear(GetPtrSize(tempString)); memcpy(configStream, tempString, GetPtrSize(tempString)); DisposePtr(tempString); } } } strcpy(tempString, "CTS"); here = strstr(configStream, tempString); if (here != nil) { result = CautionAlert(CTSWarningdlog, nil); if (result == 2) { // The Continue option error = CreateConfigRes(configStream); error = CreateToolNameRes(toolName); done = true; } } else { error = CreateConfigRes(configStream); // MAD fprintf(mfp,"CreateConfigRes = %d\n",error); error = CreateToolNameRes(toolName); // MAD fprintf(mfp,"CreateToolNames = %d\n",error); done = true; } DisposePtr(configStream); } } else { //ErrorTerminate(-2, "\pее CMChoose failed. ее"); // MAD fprintf(mfp,"CMChoose failed\n"); if (*connection != nil) { CMDispose(*connection); *connection = nil; } error = -2; done = true; } } while (!done); // open the connection, send some data, and then close the connection if (error == noErr) { error = CMOpen(*connection, false, nil, 0); // MAD fprintf(mfp,"CMOpen = %d\n",error); } } return error; }