static int MyRead (unsigned char *pmBuffer, int pmBytesToRead, NetRecord *pmNetRecord) { int myBytesTillWrap = BUFFER_SIZE - pmNetRecord -> tail; int myAvail = MyBytesAvailable (pmNetRecord); int myRemainingBytes; if (pmNetRecord -> seenEOF) { ABORT_WITH_ERRNO (E_NET_READ_PAST_EOF); return 0; } // A hasevent call should have been made to ensure bytes were // available. Verify. if (myAvail < pmBytesToRead) { if ((myAvail == 0) && (pmNetRecord -> atEOF)) { pmNetRecord -> seenEOF = TRUE; return 0; } ABORT_WITH_ERRNO (E_NET_UNKNOWN_ERROR); return 0; } // // Read data from the buffer // if (pmBytesToRead <= myBytesTillWrap) { memcpy (pmBuffer, pmNetRecord -> buf + pmNetRecord -> tail, pmBytesToRead); pmNetRecord -> tail += pmBytesToRead; if (pmNetRecord -> tail == BUFFER_SIZE) { pmNetRecord -> tail = 0; } } else { myRemainingBytes = pmBytesToRead - myBytesTillWrap; memcpy (pmBuffer, pmNetRecord -> buf + pmNetRecord -> tail, myBytesTillWrap); memcpy (pmBuffer + myBytesTillWrap, pmNetRecord -> buf, myRemainingBytes); pmNetRecord -> tail = myRemainingBytes; } return pmBytesToRead; } // MyRead
int MIONet_Getc (void *pmFilePtr) { NetRecord *myNetRecord = (NetRecord *) pmFilePtr; unsigned char myChar; // It is possible that MIONet_Getc gets called without the appropriate // HasEvent having been called and passed because 'eof' doesn't call // HasEvent first. So, we risk a busy wait... if (MyBytesAvailable (myNetRecord) == 0) { // Do Nothing - the MyBytesAvailable reads the buffer ABORT_WITH_ERRNO (E_NET_DONT_USE_EOF); } if (MyRead (&myChar, 1, myNetRecord) != 1) { return EOF; } if (myNetRecord -> binary) { return myChar; } // If the last character we read was a CR and this is a LF, skip over // it. This should be alright, as the HasEvent also takes the // newline conversion into account if (myNetRecord -> lastCharWasCR && (myChar == '\n')) { if (MyRead (&myChar, 1, myNetRecord) != 1) { return EOF; } } // If the char just read is not a CR, return the char if (myChar != '\r') { myNetRecord -> lastCharWasCR = FALSE; return myChar; } myNetRecord -> lastCharWasCR = TRUE; // We've read a CR. See if the next character is a NL and // clear it off the buffer if it is. if ((!myNetRecord -> seenEOF) && (myNetRecord -> tail != myNetRecord -> head) && (* (char *) (myNetRecord -> buf + myNetRecord -> tail) == '\n')) { // The next char *is* a LF. So read the LF. MyRead (&myChar, 1, myNetRecord); } return '\n'; } // MIONet_Getc
void MIONet_GetHostNameByAddress (OOTstring pmNetName, const OOTstring pmNetAddress) { if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } MDIONet_GetHostNameByAddress (pmNetName, pmNetAddress); } // MIONet_GetHostNameByAddress
void MIONet_GetLocalName (OOTstring pmNetName) { if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } pmNetName [0] = 0; MDIONet_GetHostName (pmNetName, 255); } // MIONet_GetLocalName
int MIONet_ConnectionStatus (OOTint pmNetID) { NetRecord *myNetRecord = MyGetNetRecord (pmNetID); if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } return myNetRecord -> status; } // MIONet_ConnectionStatus
OOTint MIONet_Available (OOTint pmNetID, OOTint pmType) { NetRecord *myNetRecord = MyGetNetRecord (pmNetID); int myPos; if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } MyReadAhead (myNetRecord); myPos = myNetRecord -> tail; switch (pmType) { case NA_BYTES: return MyBytesAvailable (myNetRecord); case NA_TOKEN: while ((myPos != myNetRecord -> head) && isspace (myNetRecord -> buf [myPos])) myPos = SUCC (myPos); if (myPos == myNetRecord -> head) return 0; while (myPos != myNetRecord->head) { if (!isspace(myNetRecord -> buf[myPos])) { return 1; } myPos = SUCC (myPos); } return 0; case NA_LINE: while (myPos != myNetRecord -> head) { if (myNetRecord -> buf[myPos] == '\n') { return 1; } myPos = SUCC(myPos); } return 0; default: return 0; } // switch } // MIONet_Available
void MIONet_GetLocalAddress (OOTstring pmNetAddress) { char myNetName [256]; if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } MIONet_GetLocalName (myNetName); MIONet_GetHostAddressByName (pmNetAddress, myNetName); } // MIONet_GetLocalAddress
void MIONet_RegisterOpen (OOTint pmNetID, SRCPOS *pmSrcPos) { if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } EdInt_NotifyDebuggerObjectAllocated (NET_STREAM, pmNetID, pmSrcPos, stLastOpenDescription); stStreams [pmNetID] = stLastStreamOpened; stLastStreamOpened = NULL; } // MIONet_RegisterOpen
void MIONet_RegisterClose (OOTint pmNetID) { if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } // Tell the debugger it is no longer in use. // TW: Actually the debugger already deallocated the stream when // it closed the stream in mio.c // EdInt_NotifyDebuggerObjectDeallocated (pmNetID); stStreams [pmNetID] = NET_STREAM_CLOSED; } // MIONet_RegisterClose
void MIOMouse_ButtonChoose (OOTstring pmString) { if ((_stricmp (pmString, "singlebutton") == 0) || (_stricmp (pmString, "onebutton") == 0)) { stMultiButtonMode = FALSE; } else if (_stricmp (pmString, "multibutton") == 0) { stMultiButtonMode = TRUE; } else { ABORT_WITH_ERRNO (E_MOUSE_BAD_BUTTONCHOOSE_STR); } } // MIOMouse_ButtonChoose
BOOL MIONet_WaitForConnect (OOTint pmNetID, EventDescriptor *pmEvent) { NetRecord *myNetRecord = MyGetNetRecord (pmNetID); if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } if (myNetRecord == NULL) { return FALSE; } pmEvent -> mode = EventMode_NetAccept; return TRUE; } // MIONet_WaitForConnect
void MIONet_GetAddress (OOTint pmNetID, OOTstring pmNetAddress) { NetRecord *myNetRecord = MyGetNetRecord (pmNetID); if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } if (myNetRecord == NULL) { pmNetAddress [0] = 0; } else { MDIONet_GetNetAddress (myNetRecord -> sockAddr, pmNetAddress); } } // MIONet_GetAddress
static int MyConvertButtonString (OOTstring pmString) { if (_stricmp ((char *) pmString, "up") == 0) { return BUTTON_UP; } else if (_stricmp ((char *) pmString, "down") == 0) { return BUTTON_DOWN; } else if ((_stricmp ((char *) pmString, "updown") == 0) || (_stricmp ((char *) pmString, "downup") == 0)) { return BUTTON_UP_OR_DOWN; } ABORT_WITH_ERRNO (E_MOUSE_BAD_BUTTONMOTION_STR); return BUTTON_UP; } // MyConvertButtonString
void *MIONet_Open (char *pmOpenString) { NetRecord *myNetRecord; char myNetAddr[256]; char myDoc [256]; int myPort; if (!stMDNetInitialized) { ABORT_WITH_ERRNO (E_NET_INIT_FAILED); // Never reaches here } // Allocate the NetRecord myNetRecord = (NetRecord *) malloc (sizeof (NetRecord)); if (myNetRecord == NULL) { SET_ERRNO (E_INSUFFICIENT_MEMORY); return NULL; } // Initialize the entire record to zeroes memset (myNetRecord, 0, sizeof (NetRecord)); // Allocate the socket myNetRecord -> socket = MDIONet_CreateSocket (); if (myNetRecord -> socket == NULL) { free (myNetRecord); return NULL; } // Allocate the socket address myNetRecord -> sockAddr = MDIO_AllocateSockAddr (); if (myNetRecord -> sockAddr == NULL) { free (myNetRecord); return NULL; } // Allocate the buffer myNetRecord -> buf = (BYTE *) malloc(BUFFER_SIZE); if (myNetRecord -> buf == NULL) { MDIONet_CloseSocket (myNetRecord -> socket); free (myNetRecord); SET_ERRNO (E_INSUFFICIENT_MEMORY); return NULL; } memset (myNetRecord -> buf, 128, BUFFER_SIZE); switch (pmOpenString[0]) { case 'C': // Connect to arbitrary port if (MyDoConnect (myNetRecord, pmOpenString + 2, &myPort, myNetAddr)) { MDIO_sprintf (stLastOpenDescription, "Connect to port %d on %s", &myPort, myNetAddr); stLastStreamOpened = myNetRecord; return myNetRecord; } break; case 'A': // Open for accepting a connection on a port if (MyDoOpenForAccept (myNetRecord, pmOpenString + 2, &myPort)) { MDIO_sprintf (stLastOpenDescription, "Accepted connection on port %d", &myPort); stLastStreamOpened = myNetRecord; return myNetRecord; } break; case 'U': // Open a URL for read { if (MyGetURLAddressAndDocument (myNetAddr, myDoc, pmOpenString + 2)) { if (MyDoConnect (myNetRecord, myNetAddr, &myPort, NULL)) { MySendURLGet (myNetRecord, myDoc); if (myPort == 80) { MDIO_sprintf (stLastOpenDescription, "Connect to URL %s", myNetAddr); } else { MDIO_sprintf (stLastOpenDescription, "Connect to URL %s (port %d)", myNetAddr, myPort); } stLastStreamOpened = myNetRecord; return myNetRecord; } } } break; } MDIONet_CloseSocket (myNetRecord -> socket); if (myNetRecord -> sockAddr != NULL) { free (myNetRecord -> sockAddr); } free (myNetRecord -> buf); free (myNetRecord); stLastStreamOpened = NULL; return NULL; } // MIONet_Open
void MIOText_WhatChar (void) { ABORT_WITH_ERRNO (E_TEXT_WHATTEXTCHAR_DEAD); } // MIOText_WhatChar