//------------------------------------------------ //--- 010 Editor v3.0 Script File // // File: CopyAsCpp.1sc // Authors: SweetScape, ADACH // Version: 1.1 // Purpose: Copies the selection to the clipboard as hex // bytes suitable for inclusion in an C/C++ program. // If no selection is made the whole file is copied. // Note that this functionality is now built into // 010 Editor using 'Copy > Copy As > Copy as C Code'. // Category: Clipboard // History: // 1.1 2016-02-10 SweetScape Software: Updated header for repository submission. // 1.0 ADACH: Initial release. // // (Based on SweetScape Software CopyAsAsm script) //------------------------------------------------ int i, origfile, newfile, start, size, col, writeHeader; // Determine range to copy if( GetSelSize() == 0 ) { start = 0; size = FileSize(); } else { start = GetSelStart(); size = GetSelSize(); } // Create a new file for writing data origfile = GetFileNum(); newfile = FileNew(); FileSelect( origfile ); // Convert each int to hex FPrintf( newfile, "unsigned char table[%d] =\r\n{\r\n ",size); col = 0; writeHeader = false; for( i = 0; i < size; i++ ) { // Write header at the beginning of the file if( writeHeader ) { FPrintf( newfile, " " ); writeHeader = false; } // Write int converted to hex if( col > 0 ) FPrintf( newfile, ", " ); FPrintf( newfile, "\'\\x%02X\'", (int)ReadUByte(start+i) ); // Write end of line every 8 bytes if( ++col == 8 ) { if((size - i) >= 8) FPrintf( newfile, ", \r\n" ); writeHeader = true; col = 0; } } FPrintf( newfile, "\n};" ); // Copy to clipboard and close the file FileSelect( newfile ); SetSelection( 0, FileSize() ); CutToClipboard(); FileClose(); FileSelect( origfile );