static BOOL MyGetURLAddressAndDocument (char *pmNetAddr, char *pmDoc, char *pmHTTP) { int myLen = strlen (pmHTTP); int myStart = 0; char *myPtr; MyConvertToForwardSlash (pmHTTP); if ((myLen > 7) && (_strnicmp (pmHTTP, "http://", 7) == 0)) { myStart = 7; } myPtr = strchr (pmHTTP + myStart, '/'); if (myPtr == NULL) { // If there's no slash in the URL, then doc is set to "/index.html" strcpy (pmDoc, "/index.html"); } else if (myPtr [1] == 0) { // If the URL ends in a '/', then doc is set to "/index.html" strcpy (pmDoc, "/index.html"); *myPtr = 0; } else { // doc is set to the document name in the URL strcpy (pmDoc, myPtr); *myPtr = 0; } // Find the port number in the URL, if there is one myPtr = strchr (pmHTTP + myStart, ':'); if (myPtr) { *myPtr = 0; MDIO_sprintf("%s:%s", myPtr + 1, pmHTTP + myStart); } else { MDIO_sprintf (pmNetAddr, "80:%s", pmHTTP + myStart); } return TRUE; } // MyGetURLAddressAndDocument
static void MySendURLGet (NetRecord *pmNetRecord, char *pmDoc) { char myMessage [512]; MDIO_sprintf (myMessage, "GET %s\r\n", pmDoc); MDIONet_Send (pmNetRecord -> socket, myMessage, &pmNetRecord -> status); } // MySendURLGet
static NetRecord *MyGetNetRecord (int pmNetID) { char myMessage [1024]; if ((pmNetID < 1) || (pmNetID > 20)) { MDIO_sprintf (myMessage, "%d is not a legal net stream id", pmNetID); ABORT_WITH_ERRMSG (E_NET_NOT_AN_ID, myMessage); } if (stStreams [pmNetID] == NULL) { MDIO_sprintf (myMessage, "Net stream d is not been opened", pmNetID); ABORT_WITH_ERRMSG (E_NET_NEVER_OPENED, myMessage); } if (stStreams [pmNetID] == NET_STREAM_CLOSED) { MDIO_sprintf (myMessage, "Net stream id of %d is closed", pmNetID); ABORT_WITH_ERRMSG (E_NET_CLOSED, myMessage); } return stStreams [pmNetID]; } // MyGetNetRecord
void MIOText_Locate (OOTint pmRow, OOTint pmCol) { MIOWinInfoPtr myInfo = MIOWin_GetInfo (MIO_selectedRunWindow); char myMessage [1024]; MIO_CheckOuputIsToWindow ("Text.Locate"); MIO_CheckOuputWindowIsInGraphicsMode ("Text.Locate"); if (pmRow < 1) { MDIO_sprintf (myMessage, "Row of %d is less than 1", pmRow); ABORT_WITH_ERRMSG (E_TEXT_ROW_TOO_SMALL, myMessage); } if (pmRow > myInfo -> maxRow) { MDIO_sprintf (myMessage, "Row of %d is greater than maxrow (%d)", pmRow, myInfo -> maxRow); ABORT_WITH_ERRMSG (E_TEXT_ROW_TOO_LARGE, myMessage); } if (pmCol < 1) { MDIO_sprintf (myMessage, "Column of %d is less than 1", pmCol); ABORT_WITH_ERRMSG (E_TEXT_COL_TOO_SMALL, myMessage); } if (pmCol > myInfo -> maxCol) { MDIO_sprintf (myMessage, "Column of %d is greater than maxcol (%d)", pmCol, myInfo -> maxCol); ABORT_WITH_ERRMSG (E_TEXT_COL_TOO_LARGE, myMessage); } myInfo -> row = pmRow - 1; myInfo -> col = pmCol - 1; myInfo -> actualRow = myInfo -> row; myInfo -> actualCol = myInfo -> col; // Display the caret, if appropriate MIOWin_CaretDisplay (MIO_selectedRunWindow); } // MIOText_Locate
OOTint MIOSprite_New (OOTint pmPicID, SRCPOS *pmSrcPos) { SpriteInfo *mySpriteInfo; char myAllocMessage [4096]; static int myStSpriteCount = 1; MIO_CheckOuputIsToWindow ("Sprite.New"); MIO_CheckOuputWindowIsInGraphicsMode ("Sprite.New"); MIO_MakePopupWindowVisible (); mySpriteInfo = (SpriteInfo *) malloc (sizeof (SpriteInfo)); if (mySpriteInfo == NULL) { SET_ERRNO (E_PIC_CANT_ALLOC_MEM_FOR_PIC); return 0; } // mySpriteInfo -> picID = pmPicID; MIOPic_GetInfoForSprite (pmPicID, &(mySpriteInfo -> picWidth), &(mySpriteInfo -> picHeight), &(mySpriteInfo -> picTransparentColour), &(mySpriteInfo -> picMDPicInfo)); mySpriteInfo -> x = MIO_selectedRunWindowInfo -> width / 2; mySpriteInfo -> y = MIO_selectedRunWindowInfo -> height / 2; mySpriteInfo -> spriteRect = MyGetSpriteRect (mySpriteInfo); mySpriteInfo -> spriteHeight = FOREGROUND_HEIGHT + myStSpriteCount; mySpriteInfo -> centered = FALSE; mySpriteInfo -> visible = FALSE; myStSpriteCount++; MDIO_sprintf (myAllocMessage, "Allocated from picture %d", pmPicID); mySpriteInfo -> spriteID = MIO_IDAdd (SPRITE_ID, mySpriteInfo, pmSrcPos, myAllocMessage, NULL); // Couldn't allocate an identifier. Return the default font ID. if (mySpriteInfo -> spriteID == 0) { MyFreeSprite (mySpriteInfo); return 0; } MIOPic_IncremementSpriteUse (pmPicID); MyAddToQueue (MIO_selectedRunWindowInfo, mySpriteInfo); return mySpriteInfo -> spriteID; } // MIOSprite_New
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