[Libreoffice-commits] core.git: vcl/workben

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 14 14:50:30 UTC 2021


 vcl/workben/pasteboard.mm |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

New commits:
commit 1dacb8cb94162310345b7f63f7ceda35a7152d0a
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Thu Jan 14 16:39:37 2021 +0200
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Thu Jan 14 15:49:49 2021 +0100

    Add an option to dump pasteboard data for a type to stdout
    
    Change-Id: Iafa24799c5c18abef93f032a2f637c39f4a9cf5e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109296
    Tested-by: Tor Lillqvist <tml at collabora.com>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>

diff --git a/vcl/workben/pasteboard.mm b/vcl/workben/pasteboard.mm
index b38b19387602..3d523afeb383 100644
--- a/vcl/workben/pasteboard.mm
+++ b/vcl/workben/pasteboard.mm
@@ -12,13 +12,59 @@
 
 // Build with: clang++ -Wall -o pasteboard vcl/workben/pasteboard.mm -framework AppKit
 
+#import <unistd.h>
+
 #import <iostream>
 #import <AppKit/AppKit.h>
 
+static void usage()
+{
+    std::cout <<
+        "Usage: pastebord\n"
+        "        --List the types on the pasteboard and in each pasteboard item.\n"
+        "       pasteboard -t type\n"
+        "        --Output the data for the type in question to stdout. Note: output will in many cases be binary.\n";
+}
+
 int main(int argc, char** argv)
 {
+    NSString* requestedType;
+
+    int ch;
+
+    while ((ch = getopt(argc, argv, "t:")) != -1)
+    {
+        switch (ch)
+        {
+        case 't':
+            requestedType = [NSString stringWithUTF8String:optarg];
+            break;
+        case '?':
+            usage();
+            break;
+        }
+    }
+
+    argc -= optind;
+    argv += optind;
+
+    if (argc > 0)
+    {
+        usage();
+        return 1;
+    }
+
     NSPasteboard* pb = [NSPasteboard generalPasteboard];
 
+    if ([requestedType length] > 0)
+    {
+        NSData *data = [pb dataForType:requestedType];
+
+        std::cout.write((const char *)[data bytes], [data length]);
+
+        return 0;
+    }
+
     {
         NSArray<NSPasteboardType>* types = [pb types];
         std::cout << "Types directly on pasteboard:\n";


More information about the Libreoffice-commits mailing list