void PrintMemory() { bool MonitoringState = MonitoringEnabled; MonitoringEnabled = false; if (CallNewDeleteVector || CallNewDeleteScalar || AllocatedMemoryBlocks || AllocatedMemorySize) { std::wostringstream oss; oss << L"Memory leaks detected:" << std::endl; if (CallNewDeleteVector) oss << L" delete[]: " << CallNewDeleteVector << std::endl; if (CallNewDeleteScalar) oss << L" delete: " << CallNewDeleteScalar << std::endl; if (AllocatedMemoryBlocks) oss << L"Total blocks: " << AllocatedMemoryBlocks << std::endl; if (AllocatedMemorySize) oss << L"Total bytes: " << AllocatedMemorySize - AllocatedMemoryBlocks * sizeof(MEMINFO) << L" payload, " << AllocatedMemoryBlocks * sizeof(MEMINFO) << L" overhead" << std::endl; oss << std::endl; oss << "Not freed blocks:" << std::endl; std::wcerr << oss.str(); OutputDebugString(oss.str().data()); oss.str(string()); for(auto i = FirstMemBlock.next; i; i = i->next) { oss << FormatLine(i->File, i->Line, i->Function, i->AllocationType, i->Size - sizeof(MEMINFO)).data() << std::endl; std::wcerr << oss.str(); OutputDebugString(oss.str().data()); oss.str(string()); } } MonitoringEnabled = MonitoringState; }
void PacketLogger::FormatLine( char* into, const char* dir, const char* type, unsigned int packet, unsigned int frame, unsigned char id , const BitSize_t bitLen, unsigned long long time, const SystemAddress& local, const SystemAddress& remote, unsigned int splitPacketId, unsigned int splitPacketIndex, unsigned int splitPacketCount, unsigned int orderingIndex) { char numericID[16]; const char* idToPrint = NULL; if(printId) { if (splitPacketCount>0) idToPrint="(SPLIT PACKET)"; else idToPrint = IDTOString(id); } // If printId is false, idToPrint will be NULL, as it will // in the case of an unrecognized id. Testing printId for false // would just be redundant. if(idToPrint == NULL) { sprintf(numericID, "%5u", id); idToPrint = numericID; } FormatLine(into, dir, type, packet, frame, idToPrint, bitLen, time, local, remote,splitPacketId,splitPacketIndex,splitPacketCount, orderingIndex); }
void PacketLogger::OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, RakNetTime time, bool isSend) { char str[256]; const char* sendType = (isSend) ? "Snd" : "Rcv"; SystemAddress localSystemAddress = rakPeer->GetInternalID(); // TODO - put this back in a different form /* if (internalPacket->isAcknowledgement) { if (printAcks) { if (printId==false) sprintf(str, "%s,Ack,%5i,%5i, NIL, 1,%i,%u:%i,%u:%i\n",sendType, internalPacket->messageNumber,frameNumber,time, localSystemAddress.binaryAddress, localSystemAddress.port, remoteSystemAddress.binaryAddress, remoteSystemAddress.port); else sprintf(str, "%s,Ack,%i,%i,NIL,1,%i,%u:%i,%u:%i\n",sendType, internalPacket->messageNumber,frameNumber,time, localSystemAddress.binaryAddress, localSystemAddress.port, remoteSystemAddress.binaryAddress, remoteSystemAddress.port); } else str[0]=0; } else */ { if (internalPacket->data[0]==ID_TIMESTAMP && internalPacket->data[sizeof(unsigned char)+sizeof(RakNetTime)]!=ID_RPC) { FormatLine(str, sendType, "Tms", internalPacket->messageNumber, frameNumber, internalPacket->data[1+sizeof(int)], internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); } else if (internalPacket->data[0]==ID_RPC || (internalPacket->dataBitLength>(sizeof(unsigned char)+sizeof(RakNetTime))*8 && internalPacket->data[0]==ID_TIMESTAMP && internalPacket->data[sizeof(unsigned char)+sizeof(RakNetTime)]==ID_RPC)) { const char *uniqueIdentifier = rakPeer->GetRPCString((const char*) internalPacket->data, internalPacket->dataBitLength, isSend==true ? remoteSystemAddress : UNASSIGNED_SYSTEM_ADDRESS); if (internalPacket->data[0]==ID_TIMESTAMP) FormatLine(str, sendType, "RpT", internalPacket->messageNumber, frameNumber, uniqueIdentifier, internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); else FormatLine(str, sendType, "Rpc", internalPacket->messageNumber, frameNumber, uniqueIdentifier, internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); } else { FormatLine(str, sendType, "Nrm", internalPacket->messageNumber, frameNumber, internalPacket->data[0], internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); } } AddToLog(str); }
void PacketLogger::OnDirectSocketSend(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) { if (logDirectMessages==false) return; char str[256]; FormatLine(str, "Snd", "Raw", 0, 0, data[0], bitsUsed, RakNet::GetTime(), rakPeerInterface->GetExternalID(remoteSystemAddress), remoteSystemAddress, (unsigned int)-1,(unsigned int)-1,(unsigned int)-1,(unsigned int)-1); AddToLog(str); }
void PacketLogger::OnInternalPacket(InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, RakNetTime time, int isSend) { char str[256]; const char *sendTypes[] = { "Rcv", "Snd", "Err1", "Err2", "Err3", "Err4", "Err5", "Err6", }; const char *sendType = sendTypes[isSend]; SystemAddress localSystemAddress = rakPeerInterface->GetExternalID(remoteSystemAddress); if (internalPacket->data[0]==ID_TIMESTAMP && internalPacket->data[sizeof(unsigned char)+sizeof(RakNetTime)]!=ID_RPC) { FormatLine(str, sendType, "Tms", internalPacket->reliableMessageNumber, frameNumber, internalPacket->data[1+sizeof(int)], internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); } else if (internalPacket->data[0]==ID_RPC || (internalPacket->dataBitLength>(sizeof(unsigned char)+sizeof(RakNetTime))*8 && internalPacket->data[0]==ID_TIMESTAMP && internalPacket->data[sizeof(unsigned char)+sizeof(RakNetTime)]==ID_RPC)) { const char *uniqueIdentifier = rakPeerInterface->GetRPCString((const char*) internalPacket->data, internalPacket->dataBitLength, isSend==1 ? remoteSystemAddress : UNASSIGNED_SYSTEM_ADDRESS); if (internalPacket->data[0]==ID_TIMESTAMP) FormatLine(str, sendType, "RpT", internalPacket->reliableMessageNumber, frameNumber, uniqueIdentifier, internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); else FormatLine(str, sendType, "Rpc", internalPacket->reliableMessageNumber, frameNumber, uniqueIdentifier, internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); } else { FormatLine(str, sendType, "Nrm", internalPacket->reliableMessageNumber, frameNumber, internalPacket->data[0], internalPacket->dataBitLength, (unsigned long long)time, localSystemAddress, remoteSystemAddress, internalPacket->splitPacketId, internalPacket->splitPacketIndex, internalPacket->splitPacketCount, internalPacket->orderingIndex); } AddToLog(str); }
far_bad_alloc(const char* File, int Line, const char* Function, ALLOCATION_TYPE Type, size_t Size) noexcept { if (!inside_far_bad_alloc) { inside_far_bad_alloc = true; try { m_What = "bad allocation at " + FormatLine(File, Line, Function, Type, Size); } catch (...) { } inside_far_bad_alloc = false; } }
// Sends gcode command. Performs formating and waits for reply. The line starts at command_scratch + max_command_prefix. If buffer_response, the reply is entered into the response_buffer. char *PrinterSerial::SendCommand( void ) { char *formated; char *recvd; bool send_text = true; if ( ( formated = FormatLine() ) == NULL ) { // Printer can't handle blank lines // Don't send them, just return an "ok" response // They won't show up in the log, since no data was actually sent char *loc = recv_buffer; *loc++ = 'o'; *loc++ = 'k'; *loc++ = '\n'; *loc++ = '\0'; return recv_buffer; } while ( true ) { if ( send_text ) { if ( ! SendText( formated ) ) return NULL; } if ( ( recvd = RecvLine() ) == NULL ) return NULL; if ( strncasecmp( recvd, "ok", 2 ) == 0 || strncasecmp( recvd, "!!", 2 ) == 0 ) { return recvd; } if ( strncasecmp( recvd, "rs", 2 ) == 0 || strncasecmp( recvd, "resend:", 7 ) == 0 ) { // Checksum error, resend the line send_text = true; } else { send_text = false; } } }
static int OnKeyPressed(void *wnd, int key) { GEM_WINDOW *gwnd = (GEM_WINDOW *) wnd ; HEX_DUMP *hex_dump = (HEX_DUMP *) gwnd->Extension ; long old_xcursor, old_ycursor, old_ystart, offset ; int htline, code = GW_EVTCONTINUEROUTING ; unsigned char new_val, input_valid = 0, plus = 0 ; old_xcursor = hex_dump->xcursor ; old_ycursor = hex_dump->ycursor ; old_ystart = hex_dump->ystart ; ShowCursor( gwnd, 0 ) ; switch( key ) { case FERMER : gwnd->OnClose( gwnd ) ; code = GW_EVTSTOPROUTING ; break ; case SAUVE : SaveFile( gwnd, 0 ) ; code = GW_EVTSTOPROUTING ; break ; case SAUVES : SaveFile( gwnd, 1 ) ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_RT : hex_dump->xcursor++ ; if ( hex_dump->xcursor >= hex_dump->sizeof_raw_offset_array ) hex_dump->xcursor = hex_dump->sizeof_raw_offset_array - 1 ; plus = 1 ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_SLT : hex_dump->xcursor = SearchNextBlock( hex_dump, hex_dump->xcursor, -1L ) ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_LT : hex_dump->xcursor-- ; if ( hex_dump->xcursor < 0 ) hex_dump->xcursor = 0 ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_SRT : hex_dump->xcursor = SearchNextBlock( hex_dump, hex_dump->xcursor, 1L ) ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_UP : hex_dump->ycursor-- ; if ( hex_dump->ycursor < 0 ) hex_dump->ycursor = 0 ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_SUP : hex_dump->ystart -= hex_dump->nb_lines_on_window ; hex_dump->ycursor -= hex_dump->nb_lines_on_window ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_DN : hex_dump->ycursor++ ; if ( hex_dump->ycursor > hex_dump->total_nb_lines ) hex_dump->ycursor = hex_dump->total_nb_lines ; code = GW_EVTSTOPROUTING ; break ; case CURSOR_SDN : hex_dump->ystart += hex_dump->nb_lines_on_window ; hex_dump->ycursor += hex_dump->nb_lines_on_window ; code = GW_EVTSTOPROUTING ; break ; default : offset = GetOffset( hex_dump, GetRawOffsetForXCursor( hex_dump, hex_dump->xcursor ), hex_dump->ycursor ) ; key &= 0xFF ; input_valid = KeyPressed( hex_dump, offset, key, &new_val ) ; if ( input_valid ) { int xy[4] ; hex_dump->raw_data[offset] = new_val ; FormatLine( hex_dump, hex_dump->ycursor ) ; hex_dump->xcursor++ ; if ( hex_dump->xcursor >= hex_dump->sizeof_raw_offset_array ) hex_dump->xcursor = hex_dump->sizeof_raw_offset_array - 1 ; htline = hex_dump->h_char + hex_dump->interline ; GWGetWorkXYWH( gwnd, &xy[0], &xy[1], &xy[2], &xy[3] ) ; xy[1] += (int)( hex_dump->ycursor - hex_dump->ystart ) * htline ; xy[3] = htline ; v_hide_c( handle ) ; OnDraw( gwnd, xy ) ; v_show_c( handle, 1 ) ; plus = 1 ; SetModif( gwnd, 1 ) ; code = GW_EVTSTOPROUTING ; } break ; } CheckYCursorValid( hex_dump ) ; CheckXCursorValid( hex_dump, plus ) ; CheckValid( hex_dump ) ; if ( ( old_xcursor != hex_dump->xcursor ) || ( old_ycursor != hex_dump->ycursor ) ) SmartInfos( gwnd ) ; if ( old_ystart != hex_dump->ystart ) SmartRePaint( gwnd, old_ystart ) ; return( code ) ; }
static void SmartRePaint(GEM_WINDOW *gwnd, long old_ystart) { HEX_DUMP *hex_dump = (HEX_DUMP *) gwnd->Extension ; long i, dy, line_size ; int xy[8], xyr[8], xyc[4] ; int rx, ry, rw, rh, x, y, w, h ; int htline ; int smart_possible = 0 ; unsigned char *fmt_txt = (unsigned char*)hex_dump->formatted_txt + hex_dump->nb_max_lines_on_window * sizeof(char*) ; wind_get( gwnd->window_handle, WF_FIRSTXYWH, &rx, &ry, &rw, &rh ) ; GWGetWorkXYWH( gwnd, &x, &y, &w, &h ) ; if ( ( rx == x ) && ( ry == y ) && ( rw == w ) && ( rh == h ) ) smart_possible = 1 ; hex_dump->ystart_fmt = hex_dump->ystart ; if ( smart_possible ) { line_size = 1L + hex_dump->total_nb_char_on_line ; htline = hex_dump->h_char + hex_dump->interline ; dy = hex_dump->ystart - old_ystart ; if ( labs( dy ) < hex_dump->nb_lines_on_window ) { xy[0] = xy[4] = xyr[0] = x ; xy[2] = xy[6] = xyr[2] = x + w - 1 ; if ( dy > 0 ) { xy[1] = y + (int)dy * htline ; xy[3] = y + (int)hex_dump->nb_lines_on_window * htline - 1 ; xy[5] = y ; xy[7] = y + (int)( hex_dump->nb_lines_on_window - dy ) * htline - 1 ; xyr[1] = 1 + xy[7] ; xyr[3] = (int)dy * htline - 1 ; memmove( fmt_txt, fmt_txt + dy * line_size, ( hex_dump->nb_lines_on_window - dy ) * line_size ) ; for ( i = dy; i > 0; i-- ) FormatLine( hex_dump, old_ystart + hex_dump->nb_lines_on_window + i - 1 ) ; } else { xy[1] = y ; xy[3] = y + (int)( hex_dump->nb_lines_on_window + dy ) * htline - 1 ; xy[5] = y - (int)dy * htline ; xy[7] = y + (int)hex_dump->nb_lines_on_window * htline - 1 ; xyr[1] = xy[1] ; xyr[3] = (int)( hex_dump->nb_lines_on_window + dy ) * htline - 1 ; memmove( fmt_txt - dy * line_size, fmt_txt, ( hex_dump->nb_lines_on_window + dy ) * line_size ) ; for ( i = dy; i < 0; i++ ) FormatLine( hex_dump, old_ystart + i ) ; } v_hide_c( handle ) ; vro_cpyfm( handle, S_ONLY, xy, &screen, &screen ) ; xyc[0] = x ; xyc[1] = y ; xyc[2] = x + w - 1 ; xyc[3] = y + h - 1 ; vs_clip( handle, 1, xyc ) ; OnDraw( gwnd, xyr ) ; vs_clip( handle, 0, xyc ) ; v_show_c( handle, 1 ) ; } else smart_possible = 0 ; } if ( !smart_possible ) { for ( i = hex_dump->ystart_fmt; i < hex_dump->ystart_fmt + hex_dump->nb_lines_on_window; i++ ) FormatLine( hex_dump, i ) ; GWRePaint( gwnd ) ; } UpdateVSlider( gwnd ) ; }
GEM_WINDOW *CreateHexDump(char *filename) { HEX_DUMP tmp_hex_dump ; GEM_WINDOW *gwnd ; long i, size, modulo ; int xywh[4], cxywh[4] ; int wkind ; char buf[300] ; unsigned char *c ; wkind = NAME|CLOSER|FULLER|MOVER|INFO|SIZER|UPARROW|DNARROW|VSLIDE ; if ( !config.w_info ) wkind &= ~INFO ; wkind |= SMALLER ; gwnd = GWCreateWindow( wkind, sizeof(HEX_DUMP), HEXDUMP_CLASSNAME ) ; if ( gwnd ) { HEX_DUMP *hex_dump = (HEX_DUMP *) gwnd->Extension ; FILE *stream ; long len, alloc_size ; int w, h, xo, yo, wo, ho ; strcpy( hex_dump->filename, filename ) ; stream = fopen( filename, "rb" ) ; if ( stream == NULL ) { GWDestroyWindow( gwnd ) ; form_stop(1, msg[MSG_FILENOTEXIST]) ; return( NULL ) ; } hex_dump->len = filelength( fileno( stream ) ) ; for ( len = hex_dump->len, w = 0; w < 8; w++, len >>= 4, hex_dump->nb_digits++ ) if ( len == 0 ) break ; BuildFormatLine( hex_dump, DT_MIXED ) ; alloc_size = hex_dump->len ; modulo = alloc_size % hex_dump->nb_raw_bytes_on_line ; if ( modulo ) alloc_size += hex_dump->nb_raw_bytes_on_line ; hex_dump->raw_data = (unsigned char *) malloc( alloc_size ) ; if ( hex_dump->raw_data == NULL ) { fclose( stream ) ; GWDestroyWindow( gwnd ) ; form_error( 8 ) ; return( NULL ) ; } if ( modulo ) { modulo = hex_dump->nb_raw_bytes_on_line - modulo ; memset( &hex_dump->raw_data[hex_dump->len], ' ', modulo ) ; hex_dump->modulo = modulo ; } hex_dump->ttype.hcar = 13 ; hex_dump->ttype.angle = 0 ; hex_dump->ttype.font = 1 ; hex_dump->ttype.color = 1 ; hex_dump->ttype.attribute = 0 ; hex_dump->ttype.hdisp = 0 ; hex_dump->ttype.vdisp = 5 ; set_texttype( &hex_dump->ttype ) ; hex_dump->w_char = hex_dump->ttype.wcell ; hex_dump->h_char = hex_dump->ttype.hcell ; hex_dump->interline = 0 ; hex_dump->total_nb_char_on_line = hex_dump->nb_char_on_line ; hex_dump->total_nb_lines = hex_dump->len / (long)hex_dump->nb_raw_bytes_on_line ; if ( hex_dump->len % hex_dump->nb_char_on_line ) hex_dump->total_nb_lines++ ; c = hex_dump->raw_data ; sprintf( buf, hex_dump->fmt, 0L, c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9], c[10], c[11], c[12], c[13], c[14], c[15] ) ; hex_dump->nb_bytes_for_hexa_dump = (int) strlen( buf ) ; BuildFormatLine( hex_dump, DT_MIXED ) ; w = hex_dump->nb_char_on_line * hex_dump->w_char ; h = (int) ((90L * (long)(Ymax-yopen)) / 100L) ; h = SetupNbLines( hex_dump, h ) ; cxywh[0] = xdesk ; cxywh[1] = ydesk ; cxywh[2] = wdesk ; cxywh[3] = hdesk ; wind_calc( WC_WORK, gwnd->window_kind, cxywh[0], cxywh[1], cxywh[2], cxywh[3], &xywh[0], &xywh[1], &xywh[2], &xywh[3] ) ; memcpy( &tmp_hex_dump, hex_dump, sizeof(HEX_DUMP) ) ; SetupNbLines( &tmp_hex_dump, xywh[3] ) ; hex_dump->nb_max_lines_on_window = tmp_hex_dump.nb_lines_on_window ; size = (sizeof(char*) + (long)hex_dump->total_nb_char_on_line + 1L) * hex_dump->nb_max_lines_on_window ; hex_dump->formatted_txt = (unsigned char**) calloc( 1, size ) ; if ( hex_dump->formatted_txt == NULL ) { free( hex_dump->raw_data ) ; GWDestroyWindow( gwnd ) ; form_error( 8 ) ; return( NULL ) ; } open_where( gwnd->window_kind, w, h, &xo, &yo, &wo, &ho ) ; if ( GWOpenWindow( gwnd, xo, yo, wo, ho ) != 0 ) { free( hex_dump->formatted_txt ) ; free( hex_dump->raw_data ) ; GWDestroyWindow( gwnd ) ; form_stop(1, msg[MSG_NOMOREWINDOW]) ; return( NULL ) ; } AttachHexDumpToWindow( gwnd ) ; if ( hex_dump->len > 512L*1024L ) { size_t offset = 0 ; size_t packet_size = 64L*1024L ; int pc ; while ( !feof( stream) && ( offset < hex_dump->len ) ) { offset += fread( &hex_dump->raw_data[offset], sizeof(char), packet_size, stream ) ; pc = (int) (( 100L * offset ) / hex_dump->len) ; gwnd->ProgPc( gwnd, pc, "" ) ; } GWSetWindowInfo( gwnd, "" ) ; } else fread( hex_dump->raw_data, hex_dump->len, 1, stream ) ; fclose( stream ) ; c = (unsigned char*) hex_dump->formatted_txt + hex_dump->nb_max_lines_on_window * sizeof(char*) ; hex_dump->ystart_fmt = 0 ; for ( i = hex_dump->ystart_fmt; i < hex_dump->ystart_fmt + hex_dump->nb_max_lines_on_window; i++, c += 1L + hex_dump->total_nb_char_on_line ) { hex_dump->formatted_txt[i] = c ; FormatLine( hex_dump, i ) ; } /* CreateTestFile( "I:\\DUMP.HEX" ) ;*/ } return( gwnd ) ; }
int CG16bitFont::BreakText (const CString &sText, int cxWidth, TArray<CString> *retLines, DWORD dwFlags) const // BreakText // // Splits the given string into multiple lines so that they fit // in the given width { char *pPos = sText.GetASCIIZPointer(); char *pStartLine = pPos; int iCharsInLine = 0; char *pStartWord = pPos; int iCharsInWord = 0; int cxWordWidth = 0; int cxRemainingWidth = cxWidth; int iLines = 0; // Can't handle 0 widths if (cxWidth == 0) return 0; // Smart quotes bool bInSmartQuotes = false; bool *ioInSmartQuotes; if (dwFlags & SmartQuotes) ioInSmartQuotes = &bInSmartQuotes; else ioInSmartQuotes = NULL; // If we need to truncate, then we need to adjust the width if (dwFlags & TruncateLine) { cxWidth -= MeasureText(STR_ELLIPSIS); if (cxWidth < 0) return 0; } // Do it bool bTruncate = false; while (*pPos != '\0') { // If we've got a carriage return then we immediately end // the line. if (*pPos == '\n') { // Add the current word to the line iCharsInLine += iCharsInWord; // Add the line to the array FormatLine(pStartLine, iCharsInLine, ioInSmartQuotes, retLines); iLines++; // Reset the line and word pStartLine = pPos + 1; pStartWord = pStartLine; iCharsInLine = 0; iCharsInWord = 0; cxWordWidth = 0; cxRemainingWidth = cxWidth; // Reset smartquotes (sometimes we end a paragraph without closing // a quote. In that case, we need to start with an open quote). bInSmartQuotes = false; // If we're truncating, we're out of here (we don't add an ellipsis) if (dwFlags & TruncateLine) break; } // Otherwise, continue by trying to add the character to the word else { char chChar = *pPos; if (chChar == '"' && ioInSmartQuotes) chChar = '“'; // Get the metrics for the character int iIndex = (int)(BYTE)chChar - g_iStartChar; iIndex = max(0, iIndex); CharMetrics *pMetrics = (CharMetrics *)m_Metrics.GetStruct(iIndex); // Does the character fit in the line? bool bCharFits = ((cxRemainingWidth - cxWordWidth) >= pMetrics->cxWidth); // If the character doesn't fit, then we've reached the end // of the line. if (!bCharFits) { // If the character is a space then the entire word should // fit on the line if (*pPos == ' ') { iCharsInLine += iCharsInWord; // Reset the word pStartWord = pPos + 1; iCharsInWord = 0; cxWordWidth = 0; } // If this is the first word in the line then we need to break // up the word across lines. if (iCharsInLine == 0) { // Add what we've got to the array FormatLine(pStartWord, iCharsInWord, ioInSmartQuotes, retLines); iLines++; // Reset the word pStartWord = pPos; iCharsInWord = 1; cxWordWidth = pMetrics->cxAdvance; } // Otherwise, add the line to the array else { FormatLine(pStartLine, iCharsInLine, ioInSmartQuotes, retLines); iLines++; // Reset the line pStartLine = pStartWord; iCharsInLine = 0; cxRemainingWidth = cxWidth; // Add the character that didn't fit to the word if (*pPos != ' ') { iCharsInWord++; cxWordWidth += pMetrics->cxAdvance; } } // Done if we're truncating if (dwFlags & TruncateLine) { iCharsInLine = 0; iCharsInWord = 0; bTruncate = true; break; } } // Otherwise, if it does fit, add it to the end of the word else { iCharsInWord++; cxWordWidth += pMetrics->cxAdvance; // If this character is a space or a hyphen, add it to the // end of the line if (*pPos == ' ' || *pPos == '-') { iCharsInLine += iCharsInWord; cxRemainingWidth -= cxWordWidth; // Reset the word pStartWord = pPos + 1; iCharsInWord = 0; cxWordWidth = 0; } } } // Next character pPos++; } // Add the remainder iCharsInLine += iCharsInWord; if (iCharsInLine) { FormatLine(pStartLine, iCharsInLine, ioInSmartQuotes, retLines); iLines++; } // Add ellipsis, if necessary if (bTruncate && retLines) retLines->GetAt(0).Append(STR_ELLIPSIS); // Return the lines return iLines; }
void PacketLogger::OnReliabilityLayerPacketError(const char *errorMessage, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) { char str[1024]; FormatLine(str, "RcvErr", errorMessage, 0, 0, "", bitsUsed, RakNet::GetTime(), rakPeerInterface->GetExternalID(remoteSystemAddress), remoteSystemAddress,(unsigned int)-1,(unsigned int)-1,(unsigned int)-1,(unsigned int)-1); AddToLog(str); }
void TrafficInformation::DrawInfos(time_t tm) { char str[ MAX_TRAF_WIDTH+1 ]; char key[ MAX_TRAF_WIDTH+1 ]; int n,i; Count = 0; _snprintf(key,ARRAYSIZE(key),"CopyDialog\\%s",FTP_Info->GetMsg(MLanguage)); LineCount = Min(MAX_TRAF_LINES,FTP_Info->GetRegKeyFullInt(key,"Count", 0)); if(!LineCount) { LineCount = ARRAYSIZE(StdDialogLines); for(i = 0; i < LineCount; i++) FormatLine(i,StdDialogLines[i],tm); } else { for(i = 0; i < LineCount; i++) { FTP_Info->GetRegKeyFullStr(key, FTP_Info->Message("Line%02d",i+1), str,"",ARRAYSIZE(str)); if(!str[0]) break; FormatLine(i,str,tm); } LineCount = i; } if(!Count) return; int w; for(w = n = 0; n < LineCount; n++) w = Max(w,static_cast<int>(strlen(Lines[n]))); for(n = 0; n < LineCount; n++) if(Lines[n][0] != '\x1' && Lines[n][0] != '\x2') { for(i = static_cast<int>(strlen(Lines[n])); i < w; i++) Lines[n][i] = ' '; Lines[n][i] = 0; } for(n = 0; n < Count; n++) { //Center if(Items[n].Align == tCenter) Items[n].Pos = w/2 - Items[n].Size/2; else if(Items[n].Align == tRightFill) Items[n].Size = w - Items[n].Pos; if(static_cast<int>(strlen(Lines[Items[n].Line])) > Items[n].Pos) DrawInfo(&Items[n],tm); } for(n = 0; n < LineCount; n++) Lines[n][w] = 0; }
void PacketLogger::OnDirectSocketReceive(const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress) { char str[256]; FormatLine(str, "Rcv", "Raw", 0, 0, data[0], bitsUsed, RakNet::GetTime(), rakPeer->GetInternalID(), remoteSystemAddress,(unsigned int)-1,(unsigned int)-1,(unsigned int)-1,(unsigned int)-1); AddToLog(str); }
int main() { /* std::string test = "int main()\n" "{\n" " int i = 1;\n" " float f = 1.0;\n" " vec4 v4;\n" " i = 2;\n" " i = 3 * 4;\n" " v4 = v4 * 7.0;\n" //" int main = 1;\n" //" int i = 8;\n" //" 1 += 2;\n" " v4 *= 1;\n" //" i = j;\n" " return i;\n" "}"; */ /* std::string test = "export void main()\n" "{\n" " g_projected_position = g_projection * g_view * g_model * g_position;\n" " g_projected_position[0] /= g_projected_position[3];\n" " g_projected_position[1] /= g_projected_position[3];\n" " g_projected_position[2] /= g_projected_position[3];\n" " g_world_position = normalize(g_model * g_normal);\n" " return;\n" "}\n"; */ /* std::string test = "export void main()\n" "{\n" " vec4 directionToLight = g_light0_position - g_world_position;\n" " float lightDistance = length(directionToLight);\n" "\n" " directionToLight = normalize(directionToLight);\n" "\n" " vec4 ambient;\n" " ambient[0] = 0.2;\n" " ambient[1] = 0.2;\n" " ambient[2] = 0.2;\n" "\n" " vec4 diffuse;\n" " diffuse[0] = 1.0;\n" " diffuse[1] = 1.0;\n" " diffuse[2] = 1.0;\n" "\n" " float dp = dot(g_world_normal, directionToLight);\n" " float clamped = clamp(dp, 0.0, dp);\n" "\n" " float k = 0.1;\n" " float attenuation = 1.0 / (lightDistance * k);\n" "\n" " vec4 colour = ambient + (diffuse * clamped * attenuation);\n" "\n" " g_colour[0] = clamp(colour[0], 0.0, 1.0);\n" " g_colour[1] = clamp(colour[1], 0.0, 1.0);\n" " g_colour[2] = clamp(colour[2], 0.0, 1.0);\n" "\n" " return;\n" "}\n"; */ std::string test = "export void main()\n" "{\n" " int x = 100;\n" " int y = 200;\n" " float f = 1.0;\n" "\n" " if (x < y)\n" " { x = 1; }\n" " else if (x > 0)\n" " { y = 2; }\n" //" if (f >= 100.0)\n" " else\n" " { f = 100.0; }\n" "\n" " return;\n" "}\n"; tokeniser::TextStream text(test); tokeniser::TokenDefinitions definitions(CreateDefinitions()); tokeniser::TokenStream tokens(text, definitions); std::string error; if (! tokens.Parse(error)) return 1; tokeniser::Token errorToken; //SyntaxTree tree(ProgramContext::VertexShaderContext()); SyntaxTree tree(ProgramContext::FragmentShaderContext()); if (! tree.Parse(tokens.GetTokens(), error, errorToken)) { if (errorToken.m_type == static_cast<int>(TokenType::EndOfInput)) { std::cout << error << " at end of input\n"; return 1; } std::string line = text.GetLineText(errorToken.m_line); std::string spaces(6, ' '); for (uint32_t i = 0; i < (errorToken.m_column - 1); ++i) { if (line[i] == '\t') spaces.append(1, '\t'); else spaces.append(1, ' '); } std::string message; if (errorToken.m_line > 1) { message += FormatLine(text, errorToken.m_line - 1); } message += FormatLine(text, errorToken.m_line); message += spaces + "^ " + error + "\n"; std::string after = FormatLine(text, errorToken.m_line + 1); if (! after.empty()) { message += "\n"; message += after; } std::cout << message; return 1; } ShadyObject object(0x1000); CodeGenerator generator(object.GetStart(), ProgramContext::FragmentShaderContext(), tree.GetSymbolTable(), tree.GetFunctionTable()); generator.Generate(&object, tree.GetRoot()); return 0; }
// print the file on the default printer void ListPrintFile( void ) { register int i, n; int c, nRows, nBytesPrinted, nFH; long lTemp; POPWINDOWPTR wn; TCHAR szBuffer[MAXLISTLINE+1]; int fKBHit; // disable ^C / ^BREAK handling HoldSignals(); wn = wOpen( 2, 1, 4, strlen( LIST_PRINTING ) + 8, nInverse, LIST_PRINT_TITLE, NULL ); wn->nAttrib = nNormal; wClear(); sprintf( szBuffer, LIST_QUERY_PRINT, LIST_PRINT_FILE_CHAR, LIST_PRINT_PAGE_CHAR ); wWriteListStr( 0, 1, wn, szBuffer ); if ((( c = GetKeystroke( EDIT_ECHO | EDIT_UC_SHIFT | EDIT_BIOS_KEY )) == LIST_PRINT_FILE_CHAR ) || ( c == LIST_PRINT_PAGE_CHAR )) { // save start position lTemp = LFile.lViewPtr; // display "Printing ..." wWriteListStr( 0, 1, wn, LIST_PRINTING ); if (( nFH = _sopen((( gpIniptr->Printer != INI_EMPTYSTR ) ? gpIniptr->StrData + gpIniptr->Printer : _TEXT("LPT1") ), (_O_BINARY | _O_WRONLY | _O_CREAT), _SH_DENYNO, _S_IWRITE | _S_IREAD )) >= 0 ) { if ( setjmp( cv.env ) == -1 ) { _close( nFH ); return; } // reset to beginning of file if ( c == LIST_PRINT_FILE_CHAR ) ListSetCurrent( 0L ); else { nRows = GetScrRows(); ListSetCurrent( LFile.lViewPtr ); } // print the header (filename, date & time) qprintf( nFH, _TEXT("%s %s %s\r\n\r\n"), LFile.szName, gdate( 0 ), gtime( gaCountryInfo.fsTimeFmt ) ); do { // abort printing if a key is hit // kbhit() in DOS tries to read from STDIN, which screws // up a LIST /S pipe _asm { mov ah, 1 int 16h mov fKBHit, 1 jnz KBHDone mov fKBHit, 0 KBHDone: } if ( fKBHit && ( GetKeystroke( EDIT_NO_ECHO | EDIT_BIOS_KEY ) == ESC )) break; i = FormatLine( szBuffer, MAXLISTLINE, LFile.lViewPtr, &nBytesPrinted, TRUE ); LFile.lViewPtr += 16; // replace 0-31 with "." if ( lListFlags & LIST_HEX ) { for ( n = 0; ( n < i ); n++ ) { if ( szBuffer[n] < 32 ) szBuffer[n] = _TEXT('.'); } } if (( c == LIST_PRINT_PAGE_CHAR ) && ( nRows-- <= 0 )) break; } while (( nBytesPrinted > 0 ) && ( qprintf( nFH, _TEXT("%.*s\r\n"), i, szBuffer ) > 0 )); // print a formfeed qputc( nFH, _TEXT('\014') ); _close( nFH ); // restore start position LFile.lViewPtr = lTemp; ListSetCurrent( LFile.lViewPtr ); } else honk(); } wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); }