├── .clang-format ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── paste.ico ├── paste.png ├── paste.sln └── paste ├── Resource.rc ├── paste.cpp ├── paste.vcxproj └── resource.h /.clang-format: -------------------------------------------------------------------------------- 1 | AccessModifierOffset: -4 2 | AlignConsecutiveAssignments: false 3 | AlignTrailingComments: false 4 | AlignOperands: true 5 | AlwaysBreakTemplateDeclarations: true 6 | AllowAllArgumentsOnNextLine: true 7 | AllowAllConstructorInitializersOnNextLine: true 8 | AllowAllParametersOfDeclarationOnNextLine: true 9 | AllowShortBlocksOnASingleLine: false 10 | AllowShortCaseLabelsOnASingleLine: false 11 | AllowShortFunctionsOnASingleLine: false 12 | AllowShortEnumsOnASingleLine: false 13 | AllowShortIfStatementsOnASingleLine: Never 14 | AllowShortLambdasOnASingleLine: Inline 15 | AllowShortLoopsOnASingleLine: false 16 | BinPackArguments: true 17 | BinPackParameters: true 18 | BreakBeforeBinaryOperators: NonAssignment 19 | BreakBeforeBraces: Stroustrup 20 | BreakConstructorInitializers: AfterColon 21 | ColumnLimit: 100 22 | ContinuationIndentWidth: 4 23 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 24 | Cpp11BracedListStyle: false 25 | DerivePointerAlignment: false 26 | ExperimentalAutoDetectBinPacking: true 27 | IndentCaseLabels: true 28 | IndentPPDirectives: None 29 | IndentWidth: 4 30 | Language: Cpp 31 | MaxEmptyLinesToKeep: 1 32 | NamespaceIndentation: All 33 | PointerAlignment: Right 34 | ReflowComments: true 35 | SortIncludes: false 36 | SortUsingDeclarations: true 37 | SpaceAfterCStyleCast: true 38 | SpaceAfterLogicalNot: false 39 | SpaceBeforeCpp11BracedList: true 40 | SpaceBeforeCtorInitializerColon: true 41 | SpaceBeforeInheritanceColon: true 42 | SpaceBeforeParens: ControlStatements 43 | SpaceBeforeRangeBasedForLoopColon: true 44 | SpaceInEmptyParentheses: false 45 | SpacesInCStyleCastParentheses: false 46 | SpacesInSquareBrackets: false 47 | Standard: Cpp11 48 | TabWidth: 4 49 | 50 | # We can't both use tabs and align continuations 51 | UseTab: Never 52 | AlignAfterOpenBracket: Align 53 | # AlignAfterOpenBracket: AlwaysBreak # DontAlign + new line 54 | 55 | # AlignAfterOpenBracket: Align 56 | # UseTab: Never 57 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.sln text eol=crlf 4 | *.vcxproj text eol=crlf 5 | *.filters text eol=crlf 6 | *.cpp diff=csharp eol=crlf 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 NeoSmart Technologies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # paste 2 | A Windows utility that simply dumps the clipboard data to stdout. 3 | 4 | Tiny yet safe, `paste` includes format checks and has zero dependencies, including on the standard library. 5 | 6 | -------------------------------------------------------------------------------- /paste.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neosmart/paste/b80ab71efbabb1f26dd6fa97dbceb347630f4e0d/paste.ico -------------------------------------------------------------------------------- /paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neosmart/paste/b80ab71efbabb1f26dd6fa97dbceb347630f4e0d/paste.png -------------------------------------------------------------------------------- /paste.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26206.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "paste", "paste\paste.vcxproj", "{262F01ED-1208-4258-A63C-5B4F6A38348E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Debug|x64.ActiveCfg = Debug|x64 17 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Debug|x64.Build.0 = Debug|x64 18 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Debug|x86.Build.0 = Debug|Win32 20 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Release|x64.ActiveCfg = Release|x64 21 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Release|x64.Build.0 = Release|x64 22 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Release|x86.ActiveCfg = Release|Win32 23 | {262F01ED-1208-4258-A63C-5B4F6A38348E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /paste/Resource.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION 2,0,1,1 55 | PRODUCTVERSION 2,0,1,1 56 | FILEFLAGSMASK 0x3fL 57 | #ifdef _DEBUG 58 | FILEFLAGS 0x1L 59 | #else 60 | FILEFLAGS 0x0L 61 | #endif 62 | FILEOS 0x40004L 63 | FILETYPE 0x1L 64 | FILESUBTYPE 0x0L 65 | BEGIN 66 | BLOCK "StringFileInfo" 67 | BEGIN 68 | BLOCK "040904b0" 69 | BEGIN 70 | VALUE "CompanyName", "NeoSmart Technologies" 71 | VALUE "FileDescription", "Paste clipboard contents. Run paste.exe --help for more info." 72 | VALUE "FileVersion", "2.0.1.1" 73 | VALUE "InternalName", "paste.exe" 74 | VALUE "LegalCopyright", "Copyright NeoSmart Technologies 2017-2020" 75 | VALUE "OriginalFilename", "paste.exe" 76 | VALUE "ProductName", "NeoSmart paste" 77 | VALUE "ProductVersion", "2.0.1.1" 78 | END 79 | END 80 | BLOCK "VarFileInfo" 81 | BEGIN 82 | VALUE "Translation", 0x409, 1200 83 | END 84 | END 85 | 86 | 87 | ///////////////////////////////////////////////////////////////////////////// 88 | // 89 | // Icon 90 | // 91 | 92 | // Icon with lowest ID value placed first to ensure application icon 93 | // remains consistent on all systems. 94 | IDI_ICON1 ICON "D:\\GIT\\paste\\Paste.ico" 95 | 96 | #endif // English (United States) resources 97 | ///////////////////////////////////////////////////////////////////////////// 98 | 99 | 100 | 101 | #ifndef APSTUDIO_INVOKED 102 | ///////////////////////////////////////////////////////////////////////////// 103 | // 104 | // Generated from the TEXTINCLUDE 3 resource. 105 | // 106 | 107 | 108 | ///////////////////////////////////////////////////////////////////////////// 109 | #endif // not APSTUDIO_INVOKED 110 | 111 | -------------------------------------------------------------------------------- /paste/paste.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // The maximum number of chars to buffer before issuing a write 4 | #define MAX_BUF 1024 5 | 6 | HANDLE _processHeap; 7 | 8 | struct Utf8Buffer { 9 | char *Buffer; 10 | DWORD Length; 11 | } _utf8Buffer; 12 | 13 | enum class ExitReason : int { 14 | Success, 15 | ClipboardError, 16 | NoTextualData, 17 | SystemError, 18 | CtrlC, 19 | }; 20 | 21 | enum class LineEnding : int { 22 | AsIs, 23 | CrLf, 24 | Lf 25 | }; 26 | 27 | template 28 | T *_malloc(DWORD count) 29 | { 30 | DWORD bytes = sizeof(T) * count; 31 | return (T *) HeapAlloc(_processHeap, HEAP_ZERO_MEMORY, bytes); 32 | } 33 | 34 | template 35 | T *_realloc(T *ptr, DWORD count) 36 | { 37 | DWORD bytes = sizeof(T) * count; 38 | return (T *) HeapReAlloc(_processHeap, HEAP_ZERO_MEMORY, ptr, bytes); 39 | } 40 | 41 | template 42 | void _free(T *ptr) 43 | { 44 | HeapFree(_processHeap, 0, ptr); 45 | } 46 | 47 | int WINAPI CtrlHandler(DWORD ctrlType) 48 | { 49 | switch (ctrlType) { 50 | case CTRL_C_EVENT: 51 | case CTRL_BREAK_EVENT: 52 | case CTRL_CLOSE_EVENT: 53 | case CTRL_LOGOFF_EVENT: 54 | case CTRL_SHUTDOWN_EVENT: 55 | ExitProcess((UINT) ExitReason::CtrlC); 56 | default: 57 | return false; 58 | } 59 | return true; 60 | } 61 | 62 | void Write(const wchar_t *text, DWORD outputHandle = STD_OUTPUT_HANDLE, DWORD chars = -1) 63 | { 64 | chars = chars != -1 ? chars : lstrlen(text); 65 | 66 | HANDLE hOut = GetStdHandle(outputHandle); 67 | if (hOut == INVALID_HANDLE_VALUE || hOut == nullptr) { 68 | ExitProcess((UINT) -1); 69 | } 70 | DWORD consoleMode; 71 | bool isConsole = GetConsoleMode(hOut, &consoleMode) != 0; 72 | 73 | DWORD result = 0; 74 | DWORD charsWritten = -1; 75 | if (isConsole) { 76 | result = WriteConsoleW(hOut, text, chars, &charsWritten, nullptr); 77 | } 78 | else { 79 | // WSL fakes the console and requires UTF-8 output. Assume !isConsole to mean WSL mode. 80 | 81 | // WideCharToMultiByte does not support chunking in case of fixed output buffer size. It 82 | // assumes you can dynamically allocate memory and expects you to call it with a fixed 83 | // output buffer size of 0 and a nullptr to get back the number of bytes required to fit the 84 | // conversion, which you will then dynamically allocate. While it *does* stream its output 85 | // and abort only when there's insufficient room left in the provided buffer, it does not 86 | // report back how many source characters were consumed by the operation so it's impossible 87 | // to figure out what to pass in as the starting point for a subsequent continuation call to 88 | // WideCharToMultiByte(). Realistically, the only recourse would be to check beforehand if 89 | // the needed size exceeds the capacity of a fixed- length buffer, then test different 90 | // lengths of input to see what *would* fit in the buffer in each go. Or just use a 91 | // dynamically allocated buffer. 92 | DWORD utf8ByteCount = WideCharToMultiByte( 93 | CP_UTF8, WC_ERR_INVALID_CHARS, text, chars, nullptr, 0, nullptr, nullptr); 94 | if (_utf8Buffer.Buffer == nullptr) { 95 | _utf8Buffer.Buffer = _malloc(utf8ByteCount); 96 | _utf8Buffer.Length = utf8ByteCount; 97 | } 98 | else if (_utf8Buffer.Length < utf8ByteCount) { 99 | _utf8Buffer.Buffer = _realloc(_utf8Buffer.Buffer, utf8ByteCount); 100 | _utf8Buffer.Length = utf8ByteCount; 101 | } 102 | // "WideCharToMultiByte function operates most efficiently when both lpDefaultChar and 103 | // lpUsedDefaultChar are set to NULL." 104 | DWORD bytesConverted = WideCharToMultiByte(CP_UTF8, 105 | WC_ERR_INVALID_CHARS, 106 | text, 107 | chars, 108 | _utf8Buffer.Buffer, 109 | _utf8Buffer.Length, 110 | nullptr, 111 | nullptr); 112 | result = WriteFile(hOut, _utf8Buffer.Buffer, bytesConverted, &charsWritten, nullptr); 113 | if (charsWritten != utf8ByteCount) { 114 | ExitProcess((UINT) GetLastError()); 115 | } 116 | } 117 | 118 | if (result == 0) { 119 | ExitProcess((UINT) GetLastError()); 120 | } 121 | } 122 | 123 | void Write(const wchar_t text, DWORD outputHandle = STD_OUTPUT_HANDLE) 124 | { 125 | return Write(&text, outputHandle, 1); 126 | } 127 | 128 | void WriteError(const wchar_t *text) 129 | { 130 | return Write(text, STD_ERROR_HANDLE); 131 | } 132 | 133 | bool ClipboardContainsFormat(UINT format) 134 | { 135 | bool firstTime = true; 136 | for (UINT f = 0; firstTime || f != 0; f = EnumClipboardFormats(f)) { 137 | firstTime = false; 138 | if (f == format) { 139 | return true; 140 | } 141 | } 142 | return false; 143 | } 144 | 145 | void print(const WCHAR *text, LineEnding lineEnding) 146 | { 147 | WCHAR buf[MAX_BUF]; 148 | auto i = 0; 149 | for (auto *ptr = text; ptr && *ptr; ++ptr) { 150 | if (lineEnding == LineEnding::Lf && *ptr == L'\r') { 151 | continue; 152 | } 153 | else if (lineEnding == LineEnding::CrLf && (i == 0 || buf[i - 1] != '\r') && *ptr == '\n') { 154 | buf[i++] = '\r'; 155 | } 156 | buf[i++] = *ptr; 157 | if (i == MAX_BUF) { 158 | Write(buf, STD_OUTPUT_HANDLE, i); 159 | i = 0; 160 | } 161 | } 162 | Write(buf, STD_OUTPUT_HANDLE, i); 163 | } 164 | 165 | int wmain(void) 166 | { 167 | _processHeap = GetProcessHeap(); 168 | _utf8Buffer = {}; 169 | 170 | SetConsoleCtrlHandler(CtrlHandler, true); 171 | 172 | int argc; 173 | LPWSTR *argv = CommandLineToArgvW(GetCommandLine(), &argc); 174 | LineEnding lineEnding = LineEnding::AsIs; 175 | 176 | if (argc == 2) { 177 | if (lstrcmpi(argv[1], L"--lf") == 0) { 178 | lineEnding = LineEnding::Lf; 179 | } 180 | else if (lstrcmpi(argv[1], L"--crlf") == 0) { 181 | lineEnding = LineEnding::CrLf; 182 | } 183 | else if (lstrcmpi(argv[1], L"--help") == 0 || lstrcmpi(argv[1], L"-h") == 0 184 | || lstrcmpi(argv[1], L"/?") == 0 || lstrcmpi(argv[1], L"/help") == 0 185 | || lstrcmpi(argv[1], L"/h") == 0) { 186 | Write(L"paste.exe by NeoSmart Technologies\n"); 187 | Write(L"https://github.com/neosmart/paste\n\n"); 188 | Write(L"USAGE: paste.exe [--lf|--crlf|--help]\n"); 189 | ExitProcess(0); 190 | } 191 | } 192 | 193 | if (!OpenClipboard(nullptr)) { 194 | WriteError(L"Failed to open system clipboard!\n"); 195 | ExitProcess((UINT) ExitReason::ClipboardError); 196 | } 197 | 198 | if (!ClipboardContainsFormat(CF_UNICODETEXT)) { 199 | CloseClipboard(); 200 | WriteError(L"Clipboard contains non-text data!\n"); 201 | ExitProcess((UINT) ExitReason::NoTextualData); 202 | } 203 | 204 | HANDLE hData = GetClipboardData(CF_UNICODETEXT); 205 | if (hData == INVALID_HANDLE_VALUE || hData == nullptr) { 206 | CloseClipboard(); 207 | WriteError(L"Unable to get clipboard data!\n"); 208 | ExitProcess((UINT) ExitReason::ClipboardError); 209 | } 210 | 211 | const wchar_t *text = (const wchar_t *) GlobalLock(hData); 212 | if (text == nullptr) { 213 | CloseClipboard(); 214 | WriteError(L"Unable to get clipboard data!\n"); 215 | ExitProcess((UINT) ExitReason::ClipboardError); 216 | } 217 | 218 | print(text, lineEnding); 219 | 220 | GlobalUnlock(hData); 221 | CloseClipboard(); 222 | 223 | ExitProcess((UINT) ExitReason::Success); 224 | } 225 | -------------------------------------------------------------------------------- /paste/paste.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {262F01ED-1208-4258-A63C-5B4F6A38348E} 24 | Win32Proj 25 | paste 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v141_xp 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v141_xp 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v141_xp 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | false 84 | 85 | 86 | 87 | 88 | 89 | Level3 90 | Disabled 91 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 92 | MultiThreadedDebugDLL 93 | false 94 | Default 95 | 96 | 97 | Console 98 | user32.lib;kernel32.lib;shell32.lib 99 | true 100 | wmain 101 | 102 | 103 | 104 | 105 | 106 | 107 | Level3 108 | Disabled 109 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 110 | MultiThreadedDebugDLL 111 | false 112 | Default 113 | 114 | 115 | Console 116 | user32.lib;kernel32.lib;shell32.lib 117 | true 118 | wmain 119 | 120 | 121 | 122 | 123 | Level3 124 | 125 | 126 | MinSpace 127 | true 128 | true 129 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 130 | MultiThreaded 131 | false 132 | Size 133 | 134 | 135 | Console 136 | true 137 | true 138 | user32.lib;kernel32.lib;shell32.lib 139 | true 140 | wmain 141 | 142 | 143 | 144 | 145 | Level3 146 | 147 | 148 | MinSpace 149 | true 150 | true 151 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 152 | MultiThreadedDLL 153 | false 154 | Size 155 | 156 | 157 | Console 158 | true 159 | true 160 | user32.lib;kernel32.lib;shell32.lib 161 | true 162 | wmain 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | -------------------------------------------------------------------------------- /paste/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Resource.rc 4 | // 5 | #define IDI_ICON1 102 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 103 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | --------------------------------------------------------------------------------