void LoadSE_AUX(SAVESTATE_t* save, SE_AUX_t *se_aux) { int i; if (!se_aux) { return; } CHUNK_t* chunk = FindChunk(save, SE_AUX_tag); if (!chunk) { return; } BOOL is_83p = save->model < TI_83PSE && save->version_minor == 1; if (is_83p) { LINKASSIST_t *linka = (LINKASSIST_t *) se_aux; linka->link_enable = ReadChar(chunk); linka->in = ReadChar(chunk); linka->out = ReadChar(chunk); linka->working = ReadChar(chunk); linka->receiving = ReadInt(chunk); linka->read = ReadInt(chunk); linka->ready = ReadInt(chunk); linka->error = ReadInt(chunk); linka->sending = ReadInt(chunk); linka->last_access = ReadDouble(chunk); linka->bit = ReadInt(chunk); return; } se_aux->clock.enable = ReadChar(chunk); se_aux->clock.set = ReadInt(chunk); se_aux->clock.base = ReadInt(chunk); se_aux->clock.lasttime = ReadDouble(chunk); for(i = 0; i < 7; i++) { se_aux->delay.reg[i] = ReadChar(chunk); } for(i = 0; i < NumElm(se_aux->md5.reg); i++) { se_aux->md5.reg[i] = ReadInt(chunk); } se_aux->md5.s = ReadChar(chunk); se_aux->md5.mode = ReadChar(chunk); se_aux->linka.link_enable = ReadChar(chunk); se_aux->linka.in = ReadChar(chunk); se_aux->linka.out = ReadChar(chunk); se_aux->linka.working = ReadChar(chunk); se_aux->linka.receiving = ReadInt(chunk); se_aux->linka.read = ReadInt(chunk); se_aux->linka.ready = ReadInt(chunk); se_aux->linka.error = ReadInt(chunk); se_aux->linka.sending = ReadInt(chunk); se_aux->linka.last_access = ReadDouble(chunk); se_aux->linka.bit = ReadInt(chunk); se_aux->xtal.lastTime = ReadDouble(chunk); se_aux->xtal.ticks = ReadLong(chunk); for(i = 0; i < 3; i++) { se_aux->xtal.timers[i].lastTstates = ReadLong(chunk); se_aux->xtal.timers[i].lastTicks = ReadDouble(chunk); se_aux->xtal.timers[i].divsor = ReadDouble(chunk); se_aux->xtal.timers[i].loop = ReadInt(chunk); se_aux->xtal.timers[i].interrupt = ReadInt(chunk); se_aux->xtal.timers[i].underflow = ReadInt(chunk); se_aux->xtal.timers[i].generate = ReadInt(chunk); se_aux->xtal.timers[i].active = ReadInt(chunk); se_aux->xtal.timers[i].clock = ReadChar(chunk); se_aux->xtal.timers[i].count = ReadChar(chunk); se_aux->xtal.timers[i].max = ReadChar(chunk); } if (save->version_minor >= 1) se_aux->model_bits = ReadInt(chunk); else se_aux->model_bits = save->model == TI_84P ? 0 : 1; chunk = FindChunk(save, USB_tag); if (!chunk) return; chunk->pnt = 0; se_aux->usb.USBLineState = ReadInt(chunk); se_aux->usb.USBEvents = ReadInt(chunk); se_aux->usb.USBEventMask = ReadInt(chunk); se_aux->usb.LineInterrupt = ReadInt(chunk); se_aux->usb.ProtocolInterrupt = ReadInt(chunk); se_aux->usb.ProtocolInterruptEnabled = ReadInt(chunk); se_aux->usb.DevAddress = ReadInt(chunk); se_aux->usb.Port4A = ReadChar(chunk); se_aux->usb.Port4C = ReadChar(chunk); se_aux->usb.Port54 = ReadChar(chunk); }
void LoadMEM(SAVESTATE_t* save, memc* mem) { int i; CHUNK_t* chunk = FindChunk(save, MEM_tag); chunk->pnt = 0; mem->flash_size = ReadInt(chunk); mem->flash_pages= ReadInt(chunk); mem->ram_size = ReadInt(chunk); mem->ram_pages = ReadInt(chunk); mem->step = ReadInt(chunk); mem->cmd = ReadChar(chunk); mem->boot_mapped= ReadInt(chunk); mem->flash_locked= ReadInt(chunk); mem->flash_version = ReadInt(chunk); for(i = 0; i < 5; i++) { mem->normal_banks[i].page = ReadInt(chunk); mem->normal_banks[i].read_only = ReadInt(chunk); mem->normal_banks[i].ram = ReadInt(chunk); mem->normal_banks[i].no_exec = ReadInt(chunk); if (mem->normal_banks[i].ram) { mem->normal_banks[i].addr = mem->ram+(mem->normal_banks[i].page*PAGE_SIZE); } else { mem->normal_banks[i].addr = mem->flash+(mem->normal_banks[i].page*PAGE_SIZE); } } if (mem->boot_mapped) { update_bootmap_pages(mem); mem->banks = mem->bootmap_banks; } else mem->banks = mem->normal_banks; mem->read_OP_flash_tstates = ReadInt(chunk); mem->read_NOP_flash_tstates = ReadInt(chunk); mem->write_flash_tstates = ReadInt(chunk); mem->read_OP_ram_tstates = ReadInt(chunk); mem->read_NOP_ram_tstates = ReadInt(chunk); mem->write_ram_tstates = ReadInt(chunk); mem->flash_upper = ReadInt(chunk); mem->flash_lower = ReadInt(chunk); chunk = FindChunk(save, ROM_tag); chunk->pnt = 0; ReadBlock(chunk, (unsigned char *)mem->flash, mem->flash_size); chunk = FindChunk(save, RAM_tag); chunk->pnt = 0; ReadBlock(chunk, (unsigned char *)mem->ram, mem->ram_size); chunk = FindChunk(save, REMAP_tag); if (chunk) { chunk->pnt = 0; mem->port27_remap_count = ReadInt(chunk); mem->port28_remap_count = ReadInt(chunk); } chunk = FindChunk(save, RAM_LIMIT_tag); if (chunk) { chunk->pnt = 0; mem->ram_upper = ReadInt(chunk); mem->ram_lower = ReadInt(chunk); } chunk = FindChunk(save, NUM_FLASH_BREAKS_tag); if (chunk) { int num_flash_breaks = ReadInt(chunk); chunk = FindChunk(save, FLASH_BREAKS_tag); if (chunk) { for (int i = 0; i < num_flash_breaks; i++) { int addr = ReadInt(chunk); waddr_t waddr; waddr.addr = addr % PAGE_SIZE; waddr.page = addr / PAGE_SIZE; waddr.is_ram = FALSE; BREAK_TYPE type = (BREAK_TYPE) ReadInt(chunk); switch (type) { case MEM_READ_BREAK: set_mem_read_break(mem, waddr); break; case MEM_WRITE_BREAK: set_mem_read_break(mem, waddr); break; default: set_break(mem, waddr); break; } } } } chunk = FindChunk(save, NUM_RAM_BREAKS_tag); if (chunk) { int num_ram_breaks = ReadInt(chunk); chunk = FindChunk(save, RAM_BREAKS_tag); if (chunk) { for (int i = 0; i < num_ram_breaks; i++) { int addr = ReadInt(chunk); waddr_t waddr; waddr.addr = addr % PAGE_SIZE; waddr.page = addr / PAGE_SIZE; waddr.is_ram = TRUE; BREAK_TYPE type = (BREAK_TYPE) ReadInt(chunk); switch (type) { case MEM_READ_BREAK: set_mem_read_break(mem, waddr); break; case MEM_WRITE_BREAK: set_mem_read_break(mem, waddr); break; default: set_break(mem, waddr); break; } } } } }
void LoadLINK(SAVESTATE_t* save, link_t* link) { CHUNK_t* chunk = FindChunk(save,LINK_tag); chunk->pnt = 0; link->host = ReadChar(chunk); }
/*** DoPrint - Does the printing * * If a <printcmd> has been defined * queue up the job for the <print> thread (synchronous exec under DOS) * else * send the file to the printer, each line at a time * * Input: * pFile = File to be printed. * * Output: * Returns True if the printing has been succesful, False otherwise * *************************************************************************/ flagType DoPrint ( PFILE pFile, flagType fDelete ) { assert (pFile); if (pPrintCmd) { buffer pCmdBuf; // Buffer for command construction if (TESTFLAG (FLAGS (pFile), DIRTY) && confirmx ("File %s is dirty, do you want to save it ?", pFile->pName)) FileWrite (pFile->pName, pFile); sprintf (pCmdBuf, pPrintCmd, pFile->pName); if (pBTDPrint->cBTQ > MAXBTQ-2) disperr (MSGERR_PRTFULL); else if (BTAdd (pBTDPrint, (PFUNCTION)NULL, pCmdBuf) && (!fDelete || BTAdd (pBTDPrint, (PFUNCTION)CleanPrint, pFile->pName))) return TRUE; else disperr (MSGERR_PRTCANT); if (fDelete) _unlink (pFile->pName); return FALSE; } else { static char szPrn[] = "PRN"; flagType fOK = TRUE; // Holds the return value LINE lCur; // Number of line we're printing char pLineBuf[sizeof(linebuf)+1]; // Holds the line we're printing unsigned int cLen; // Length of line we're printing EDITOR_KEY Key; // User input (for abortion) int hPrn; // PRN file handle dispmsg (MSG_PRINTING,pFile->pName); if ((hPrn = _open (szPrn, O_WRONLY)) == -1) { disperr (MSGERR_OPEN, szPrn, error()); fOK = FALSE; } else { for (lCur = 0; lCur < pFile->cLines; lCur++) { if (TypeAhead () && (Key = TranslateKey(ReadChar()), (Key.KeyCode == 0x130)) && (!Key.KeyInfo.KeyData.Flags)) { fOK = FALSE; break; } cLen = GetLine (lCur, pLineBuf, pFile); // * (int UNALIGNED *) (pLineBuf + cLen++) = '\n'; * (pLineBuf + cLen++) = '\n'; if (_write (hPrn, pLineBuf, cLen) == -1) { disperr (MSGERR_PRTCANT); fOK = FALSE; break; } } _close (hPrn); } domessage (NULL); if (fDelete) { _unlink (pFile->pName); } return fOK; } }
void LoadCPU(SAVESTATE_t* save, CPU_t* cpu) { CHUNK_t* chunk = FindChunk(save, CPU_tag); chunk->pnt = 0; cpu->a = ReadChar(chunk); cpu->f = ReadChar(chunk); cpu->b = ReadChar(chunk); cpu->c = ReadChar(chunk); cpu->d = ReadChar(chunk); cpu->e = ReadChar(chunk); cpu->h = ReadChar(chunk); cpu->l = ReadChar(chunk); cpu->ap = ReadChar(chunk); cpu->fp = ReadChar(chunk); cpu->bp = ReadChar(chunk); cpu->cp = ReadChar(chunk); cpu->dp = ReadChar(chunk); cpu->ep = ReadChar(chunk); cpu->hp = ReadChar(chunk); cpu->lp = ReadChar(chunk); cpu->ixl = ReadChar(chunk); cpu->ixh = ReadChar(chunk); cpu->iyl = ReadChar(chunk); cpu->iyh = ReadChar(chunk); cpu->pc = ReadShort(chunk); cpu->sp = ReadShort(chunk); cpu->i = ReadChar(chunk); cpu->r = ReadChar(chunk); cpu->bus = ReadChar(chunk); cpu->imode = ReadInt(chunk); cpu->interrupt = ReadInt(chunk); cpu->ei_block = ReadInt(chunk); cpu->iff1 = ReadInt(chunk); cpu->iff2 = ReadInt(chunk); cpu->halt = ReadInt(chunk); cpu->read = ReadInt(chunk); cpu->write = ReadInt(chunk); cpu->output = ReadInt(chunk); cpu->input = ReadInt(chunk); cpu->prefix = ReadInt(chunk); int i; for(i = 0; i < 256; i++) { interrupt_t *val = &cpu->pio.interrupt[i]; val->interrupt_val = ReadInt(chunk); val->skip_factor = ReadInt(chunk); val->skip_count = ReadInt(chunk); } }
int main() { char c = ReadChar(); PrintChar(c); return 0; }
int main (void) { uint8_t SequenceNumber = 0; uint8_t Char; int8_t NumberSent = 0, NumberToSend = 0, LoopCount = 0, UnexpectedPacketCount = 0, NoAckCount = 0; InitPinInActive (RED_LED_PIN); InitPinInActive (GREEN_LED_PIN); SerialInit (57600); SendString (UI8_P("JeeNodeRfm12B (1.8 wcb)\r\n")); SendString (UI8_P("a(uto-test), e(nd-test), (r)eset, [n](s)end\r\n")); Radio.Initialize (); while(1) { if ((Char = ReadChar())) switch (Char) { case 'a': if (NumberToSend == -1) break; SendString (UI8_P("Starting auto-test\r\n")); NumberToSend = -1; SequenceNumber = MacLayer.MakeRequestPacket (PacketBfr, 1, 2, UI8_P("123"), 3); SendPacket (PacketBfr, SequenceNumber); LoopCount = UnexpectedPacketCount = NoAckCount = 0; SetPinActive (GREEN_LED_PIN); break; case 'e': if (NumberToSend == 0) break; SendString (UI8_P("Ending auto-test\r\n")); sprintf ((char*) StrBfr, "unexpected # = %d, no_ack # = %d\r\n", UnexpectedPacketCount, NoAckCount); SendString (StrBfr); NumberToSend = 0; break; case 'r': SendString (UI8_P("RESETING!\r\n")); cli(); // irq's off wdt_enable (WDTO_15MS); // watch dog on, 15ms while(1); // loop until watch dog fires case 's': if (NumberToSend <= 0) NumberToSend = 1; SendStringAndInt (UI8_P("Sending "), NumberToSend, UI8_P(" packets\r\n")); NumberSent = -1; while (NumberToSend > ++NumberSent) { SequenceNumber = MacLayer.MakeRequestPacket (PacketBfr, 1, 2, UI8_P("123"), 3); if (0 == SendPacket (PacketBfr, SequenceNumber)) { NumberSent = -1; break; } } if (NumberToSend == NumberSent) { SetPinActive (GREEN_LED_PIN); _delay_ms (100); SetPinInActive (GREEN_LED_PIN); } NumberToSend = 0; break; default : if ((0x30 <= Char) && (Char <= 0x39)) NumberToSend = (NumberToSend * 10) + Char - 0x30; else { sprintf ((char*) StrBfr, "Unexpected input character %c\r\n", Char); SendString (StrBfr); } } if (Radio.Recv (&Input[0]) > 0) { DisplayInput (); if ((Input[PACKET_TYPE_INDEX] == MAC_RESPONSE_PACKET_TYPE) && (Input[PACKET_SEQUENCE_INDEX] == SequenceNumber)) { sprintf ((char*) StrBfr, "Got ack response for %d\r\n", SequenceNumber); SendString (StrBfr); if (NumberToSend < 0) { _delay_ms (100); SequenceNumber = MacLayer.MakeRequestPacket (PacketBfr, 1, 2, UI8_P("123"), 3); SendPacket (PacketBfr, SequenceNumber); SetPinActive (GREEN_LED_PIN); LoopCount = 0; } //Radio.DisplayStatus (); //Radio.ResetStatus(); //NumberSent = 0; } else if (Input[PACKET_TYPE_INDEX] == MAC_REQUEST_PACKET_TYPE) { sprintf ((char*) StrBfr, "Got request packet with sequence %d\r\n", Input[PACKET_SEQUENCE_INDEX]); SendString (StrBfr); SetPinActive (GREEN_LED_PIN); LoopCount = 0; SequenceNumber = Input[PACKET_SEQUENCE_INDEX]; MacLayer.MakeResponsePacket (PacketBfr, 1, 2, SequenceNumber, UI8_P("123"), 3); if (0 == SendPacket (PacketBfr, SequenceNumber)) SendStringAndInt (UI8_P("Could not send response for "), Input[PACKET_SEQUENCE_INDEX], UI8_P("\r\n")); } else { sprintf ((char*) StrBfr, "\r\nGot unexpected packet !!!!!!!!!!!!!!!!!!!!!!\r\n\n"); SendString (StrBfr); UnexpectedPacketCount++; } } _delay_ms (10); LoopCount++; if (LoopCount == 10) SetPinInActive (GREEN_LED_PIN); else if ((NumberToSend < 0) && (LoopCount == 100)) { SendStringAndInt (UI8_P("!!!!!!!!!!!!!!!!!!!!!!! Did not get Ack for "), SequenceNumber, UI8_P(" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n")); NoAckCount++; SendPacket (PacketBfr, SequenceNumber); LoopCount = 0; SetPinActive (GREEN_LED_PIN); } //else if (NumberSent > 0) { //Radio.DisplayStatus (); //Radio.ResetStatus(); //NumberSent = 0; //} } }
UINT CLiteHTMLReader::parseDocument(void) { ASSERT(m_lpszBuffer != NULL); bool bAbort = false; // continue parsing or abort? bool bIsClosingTag = false; // tag parsed is a closing tag? bool bIsOpeningTag = false; // tag parsed is an opening tag? CString strCharacters; // character data CString strComment; // comment data CString strT; // temporary storage DWORD dwCharDataStart = 0L; // starting position of character data DWORD dwCharDataLen = 0L; // length of character data LONG lTemp = 0L; // temporary storage TCHAR ch = 0; // character at current buffer position CLiteHTMLTag oTag; // tag information if ( (!m_lpszBuffer) || (!m_dwBufLen) ) return (0U); // reset seek pointer to beginning ResetSeekPointer(); // notify event handler about parsing startup if (getEventNotify(notifyStartStop)) { bAbort = false; m_pEventHandler->BeginParse(m_dwAppData, bAbort); if (bAbort) goto LEndParse; } // skip leading white-space characters while (isWhiteSpace(ReadChar())) ; ch = UngetChar(); while ((ch = ReadChar()) != NULL) { switch (ch) { // tag starting delimeter? case _T('<'): { UngetChar(); strComment.Empty(); if (!parseComment(strComment)) { bIsOpeningTag = false; bIsClosingTag = false; if (!parseTag(oTag, bIsOpeningTag, bIsClosingTag)) { ++dwCharDataLen; // manually advance buffer position // because the last call to UngetChar() // moved it back one character ch = ReadChar(); break; } } // clear pending notifications if ( (dwCharDataLen) || (strCharacters.GetLength()) ) { strCharacters += CString(&m_lpszBuffer[dwCharDataStart], dwCharDataLen); NormalizeCharacters(strCharacters); if ( (strCharacters.GetLength()) && (getEventNotify(notifyCharacters)) ) { bAbort = false; m_pEventHandler->Characters(strCharacters, m_dwAppData, bAbort); if (bAbort) goto LEndParse; } strCharacters.Empty(); } dwCharDataLen = 0L; dwCharDataStart = m_dwBufPos; if (strComment.GetLength()) { if (getEventNotify(notifyComment)) { bAbort = false; m_pEventHandler->Comment(strComment, m_dwAppData, bAbort); if (bAbort) goto LEndParse; } } else { if ( (bIsOpeningTag) && (getEventNotify(notifyTagStart)) ) { bAbort = false; m_pEventHandler->StartTag(&oTag, m_dwAppData, bAbort); if (bAbort) goto LEndParse; } if ( (bIsClosingTag) && (getEventNotify(notifyTagEnd)) ) { bAbort = false; m_pEventHandler->EndTag(&oTag, m_dwAppData, bAbort); if (bAbort) goto LEndParse; } } break; } // entity reference beginning delimeter? case _T('&'): { UngetChar(); lTemp = 0; if (m_bResolveEntities) lTemp = CLiteHTMLEntityResolver::resolveEntity(&m_lpszBuffer[m_dwBufPos], ch); if (lTemp) { strCharacters += CString(&m_lpszBuffer[dwCharDataStart], dwCharDataLen) + ch; m_dwBufPos += lTemp; dwCharDataStart = m_dwBufPos; dwCharDataLen = 0L; } else { ch = ReadChar(); ++dwCharDataLen; } break; } // any other character default: { ++dwCharDataLen; break; } } } // clear pending notifications if ( (dwCharDataLen) || (strCharacters.GetLength()) ) { strCharacters += CString(&m_lpszBuffer[dwCharDataStart], dwCharDataLen) + ch; NormalizeCharacters(strCharacters); strCharacters.TrimRight(); // explicit trailing white-space removal if ( (strCharacters.GetLength()) && (getEventNotify(notifyCharacters)) ) { bAbort = false; m_pEventHandler->Characters(strCharacters, m_dwAppData, bAbort); if (bAbort) goto LEndParse; } } LEndParse: // notify event handler about parsing completion if (getEventNotify(notifyStartStop)) m_pEventHandler->EndParse(m_dwAppData, bAbort); m_lpszBuffer = NULL; m_dwBufLen = 0L; return (m_dwBufPos); }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int ReadStructure( source_t *source, structdef_t *def, char *structure ) { token_t token; fielddef_t *fd; void *p; int num; if ( !PC_ExpectTokenString( source, "{" ) ) { return 0; } while ( 1 ) { if ( !PC_ExpectAnyToken( source, &token ) ) { return qfalse; } //if end of structure if ( !strcmp( token.string, "}" ) ) { break; } //find the field with the name fd = FindField( def->fields, token.string ); if ( !fd ) { SourceError( source, "unknown structure field %s", token.string ); return qfalse; } //end if if ( fd->type & FT_ARRAY ) { num = fd->maxarray; if ( !PC_ExpectTokenString( source, "{" ) ) { return qfalse; } } //end if else { num = 1; } //end else p = ( void * )( structure + fd->offset ); while ( num-- > 0 ) { if ( fd->type & FT_ARRAY ) { if ( PC_CheckTokenString( source, "}" ) ) { break; } } //end if switch ( fd->type & FT_TYPE ) { case FT_CHAR: { if ( !ReadChar( source, fd, p ) ) { return qfalse; } p = (char *) p + sizeof( char ); break; } //end case case FT_INT: { if ( !ReadNumber( source, fd, p ) ) { return qfalse; } p = (char *) p + sizeof( int ); break; } //end case case FT_FLOAT: { if ( !ReadNumber( source, fd, p ) ) { return qfalse; } p = (char *) p + sizeof( float ); break; } //end case case FT_STRING: { if ( !ReadString( source, fd, p ) ) { return qfalse; } p = (char *) p + MAX_STRINGFIELD; break; } //end case case FT_STRUCT: { if ( !fd->substruct ) { SourceError( source, "BUG: no sub structure defined" ); return qfalse; } //end if ReadStructure( source, fd->substruct, (char *) p ); p = (char *) p + fd->substruct->size; break; } //end case } //end switch if ( fd->type & FT_ARRAY ) { if ( !PC_ExpectAnyToken( source, &token ) ) { return qfalse; } if ( !strcmp( token.string, "}" ) ) { break; } if ( strcmp( token.string, "," ) ) { SourceError( source, "expected a comma, found %s", token.string ); return qfalse; } //end if } //end if } //end while } //end while return qtrue; } //end of the function ReadStructure
bool CResourceHTMLItem::Start ( void ) { if ( !m_bIsRaw ) { // go through and search for <* or *> FILE * pFile = fopen ( m_strResourceFileName.c_str (), "r" ); if ( !pFile ) return false; bool bInCode = false; bool bJustStartedCodeBlock = false; bool bIsShorthandCodeBlock = false; std::string strScript; strScript += "function renderPage ( requestHeaders, form, cookies, hostname, url, querystring, user )\n"; strScript += "\nhttpWrite ( \""; // bit hacky, possibly can be terminated straight away unsigned char c; int i = 0; while ( !feof ( pFile ) ) { c = ReadChar ( pFile ); if ( feof ( pFile ) ) break; if ( bInCode == false ) // we're in a plain HTML section { if ( c == '<' && !feof ( pFile ) ) { c = ReadChar ( pFile ); if ( c == '*' ) // we've found <* { bInCode = true; bJustStartedCodeBlock = true; strScript.append("\" )\n"); // add ") to the end to terminate our last non-code section } else { // we found < but not a *, so just output both characters we read strScript += '<'; strScript += c; } } else { if ( c == '\r' ) { strScript += "\\r"; } else if ( c == '\n' ) { strScript += "\\n"; } else if ( c == '\\' ) { strScript += "\\\\"; } else if ( c == '\"' ) { strScript += "\\\""; } else strScript += c; } } else { // we're in a code block if ( c == '*' && !feof ( pFile ) ) { c = ReadChar ( pFile ); if ( c == '>' ) // we've found *> { bInCode = false; if ( bIsShorthandCodeBlock ) { bIsShorthandCodeBlock = false; strScript += ')'; // terminate the 'httpWrite' function } strScript.append ( "\nhttpWrite ( \"" ); // add httpWrite ( " to start a new non-code section } else { // we found * but not a >, so just output both characters we read strScript += '*'; strScript += c; } } else if ( c == '=' && bJustStartedCodeBlock ) { strScript.append("httpWrite ( "); bIsShorthandCodeBlock = true; } else { if ( c != '\t' && c != ' ' ) // we allow whitespace before the shorthand '=' sign bJustStartedCodeBlock = false; strScript += c; } } i++; } if ( !bInCode ) strScript.append("\" )\n"); strScript.append("\nend"); /* FILE * debug = fopen ("debug.lua", "w" ); fwrite ( m_szBuffer, 1, strlen(m_szBuffer), debug ); fclose ( debug );*/ m_pVM = g_pGame->GetLuaManager()->CreateVirtualMachine ( m_resource ); m_pVM->LoadScript ( strScript.c_str () ); m_pVM->SetResourceFile ( this ); m_pVM->RegisterHTMLDFunctions(); fclose ( pFile ); GetMimeType ( m_strResourceFileName.c_str () ); return true; } else { // its a raw page FILE * file = fopen ( m_strResourceFileName.c_str (), "rb" ); if ( file ) { GetMimeType ( m_strResourceFileName.c_str () ); // don't actually read it here, it could be way too large fclose ( file ); return true; } return false; } }
void iglasses_init_tracking(int serial_port) { fix t1,t2; int c; if (iglasses_headset_installed) return; if ( (serial_port < 1) || (serial_port > 4) ) { Error( TXT_IGLASSES_ERROR_1 ); } printf( "\n\n"); printf( TXT_IGLASSES_INIT, serial_port ); printf( "\n%s\n", TXT_IGLASSES_ON); printf( "Looking for glasses - %s", TXT_PRESS_ESC_TO_ABORT); Iport = PortOpenGreenleafFast(serial_port-1, 9600, 'N', 8, 1 ); if ( !Iport ) { printf( "%s\n", TXT_SERIAL_FAILURE, Iport->status ); return; } SetDtr( Iport, 1 ); SetRts( Iport, 1 ); UseRtsCts( Iport, 0 ); t2 = timer_get_fixed_seconds() + i2f(20); while(timer_get_fixed_seconds() < t2) { printf( "." ); t1 = timer_get_fixed_seconds() + F1_0; ClearRXBuffer(Iport); ClearTXBuffer(Iport); WriteBuffer( Iport, "!\r", 2 ); while ( timer_get_fixed_seconds() < t1 ) { if ( key_inkey() == KEY_ESC ) goto NotOK; c = ReadChar( Iport ); if ( c == 'O' ) { goto TrackerOK1; } } } NotOK:; printf( "\n\nWarning: Cannot find i-glasses! on port %d\n" " Press Esc to abort D2, any other key to continue without i-glasses support.\n" " Use SETUP to disable i-glasses support.\n",serial_port); if ( key_getch() == KEY_ESC ) exit(1); else return; TrackerOK1: while( 1 ) { printf( "." ); t1 = timer_get_fixed_seconds() + F1_0; ClearRXBuffer(Iport); ClearTXBuffer(Iport); // M2 = p,b,h // M1 = all data WriteBuffer( Iport, "!M1,P,B\r", 8 ); while ( timer_get_fixed_seconds() < t1 ) { if ( key_inkey() == KEY_ESC ) return; c = ReadChar( Iport ); if ( c == 'O' ) { goto TrackerOK2; } } } TrackerOK2: printf( ".\n" ); ClearRXBuffer(Iport); ClearTXBuffer(Iport); WriteChar( Iport, 'S' ); iglasses_headset_installed = 1; atexit( iglasses_close_tracking ); #ifdef USE_FILTERS initFIR( &X_filter ); initFIR( &Y_filter ); initFIR( &Z_filter ); #endif // { // fix y,p,r; // while( 1 ) { // iglasses_read_headset( &y, &p, &r); // //printf( "%d\t%d\t%d\n", y, p, r ); // printf( "%8.2f\n", f2fl(y) ); // if (key_inkey()==KEY_ESC) break; // } // } }
bool StreamTokenizer::GetNext(Token *next) { if (!is_.good()) { eof_reached_ = true; return false; } // Get first character of next token. char c; bool is_whitespace = true; while (is_whitespace) { if (!ReadChar(&c)) { return false; } is_whitespace = isspace(c); // If we find a comment character, then read to the end of the line. if (!is_whitespace && c == '/' && is_.peek() == '/') { while (c != '\n') { if (!ReadChar(&c)) { return false; } } is_whitespace = true; } } // In case we're successful in reading the next token, we fill in // the two stream state data available now. next->start = num_read_ - 1; next->line_number = line_number_; bool next_tok_complete = false; next->tok.clear(); if (ReservedChar(c)) { next->tok += c; next_tok_complete = true; next->type = RESERVED_CHAR; } else if (c == '"') { // We've got a string literal, so keep reading characters, // until hitting a non-escaped double quote. streampos string_literal_start_pos = num_read_ - 1; bool found_closing_quote = false; while (is_.good()) { bool success = ReadChar(&c); if (success) { if (c == '"') { found_closing_quote = true; break; } else if (c == '\\') { success = ReadChar(&c); } } if (success) { next->tok += c; } } if (!found_closing_quote) { cerr << "StreamTokenizer: error: could not find closing " << "double quote for string literal beginning at stream index " << string_literal_start_pos << "; partial string literal read: \"" << next->tok << endl; throw std::runtime_error("unclosed string literal"); } next_tok_complete = true; next->type = STRING; } else { // This is a number, a reserved word or C++ identifier token, so // add first character; the remainder of the token will be handled // in the next block. next->tok += c; next->type = (c == '-' || (c >= '0' && c <= '9')) ? NUMBER : IDENTIFIER; } if (!next_tok_complete) { // The current token is a number, a reserved word or C++ // identifier, so we keep reading characters until hitting a // "reserved character", a whitespace character or EOF. bool done = false; while (!done && is_.good()) { // We don't call ReadChar below because the next character might // tell us that the current token has ended (i.e., if it's a // reserved character, a double quote or a whitespace // character). int peek = is_.peek(); if (peek != EOF) { char next_char = static_cast<char>(peek); if (ReservedChar(next_char) || next_char == '"' || isspace(next_char)) { // Now that we've finished reading something that is not a // string literal, change its type to be RESERVED_WORD if it // exactly matches something in the set of reserved words. if (reserved_words_.count(next->tok) != 0) { next->type = RESERVED_WORD; } done = true; } else { ReadChar(&c); next->tok += c; } } else { eof_reached_ = true; } } } // We're about to return a successfully read token, so we make sure to record // the stream position at this point in the Token object. next->curr_pos = num_read_; return true; }
static tchar GetC( TidyConfigImpl* config ) { if ( config->cfgIn ) return ReadChar( config->cfgIn ); return EndOfStream; }
PUBLIC TOKEN GetToken( void ) { int state = 0, scanning = 1, ch; TOKEN token; /* The following two initialisations are only needed because * Microsoft's CL compiler complains that the fields are * potentially unitialised if they are left out. (Only at the * strictest (/W4) level of error checking.) */ token.code = ERROR; token.value = 0; while ( scanning ) { scanning = 0; switch ( state ) { case 0 : token.value = 0; NewString(); state = 1; scanning = 1; break; case 1 : token.pos = CurrentCharPos(); ch = ReadChar(); switch ( ch ) { case '!' : state = 2; break; case ';' : state = 3; break; case ',' : state = 4; break; case '.' : state = 5; break; case '(' : state = 6; break; case ')' : state = 7; break; case ':' : state = 8; break; case '+' : state = 11; break; case '-' : state = 12; break; case '*' : state = 13; break; case '/' : state = 14; break; case '=' : state = 15; break; case '<' : state = 16; break; case '>' : state = 19; break; case EOF : state = 22; break; default : if ( isspace( ch ) ) state = 1; else if ( isdigit( ch ) ) { token.value *= 10; token.value += ch - '0'; state = 23; } else if ( isalpha( ch ) ) { AddChar( ch ); state = 25; } else state = 27; break; } scanning = 1; break; case 2 : ch = ReadChar(); if ( ch == '\n' || ch == EOF ) state = 1; else state = 2; scanning = 1; break; case 3 : token.code = SEMICOLON; break; case 4 : token.code = COMMA; break; case 5 : token.code = ENDOFPROGRAM; break; case 6 : token.code = LEFTPARENTHESIS; break; case 7 : token.code = RIGHTPARENTHESIS; break; case 8 : ch = ReadChar(); if ( ch == '=' ) state = 9; else state = 10; scanning = 1; break; case 9 : token.code = ASSIGNMENT; break; case 10 : token.code = ERROR; UnReadChar(); break; case 11 : token.code = ADD; break; case 12 : token.code = SUBTRACT; break; case 13 : token.code = MULTIPLY; break; case 14 : token.code = DIVIDE; break; case 15 : token.code = EQUALITY; break; case 16 : ch = ReadChar(); if ( ch == '=' ) state = 17; else state = 18; scanning = 1; break; case 17 : token.code = LESSEQUAL; break; case 18 : token.code = LESS; UnReadChar(); break; case 19 : ch = ReadChar(); if ( ch == '=' ) state = 20; else state = 21; scanning = 1; break; case 20 : token.code = GREATEREQUAL; break; case 21 : token.code = GREATER; UnReadChar(); break; case 22 : token.code = ENDOFINPUT; break; case 23 : ch = ReadChar(); if ( isdigit( ch ) ) { token.value *= 10; token.value += ch - '0'; state = 23; } else state = 24; scanning = 1; break; case 24 : token.code = INTCONST; UnReadChar(); break; case 25 : ch = ReadChar(); if ( isalnum( ch ) ) { AddChar( ch ); state = 25; } else state = 26; scanning = 1; break; case 26 : token.code = IDENTIFIER; UnReadChar(); break; case 27 : token.code = ILLEGALCHAR; break; default : fprintf(stderr, "Error, GetToken, invalid state %d\n", state); exit( EXIT_FAILURE ); break; } } if ( token.code == IDENTIFIER ) { AddChar( '\0' ); /* null-terminate the string */ token.s = GetString(); token.code = SearchKeywords( token.s ); if ( token.code != IDENTIFIER ) token.s = NULL; } return token; }