下载源码和可执行文件 xclip.7z

 // The MIT License (MIT)

 // Copyright (c) 2014 Rapptz

 // Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions: // The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <windows.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdlib> struct clipboard {
private:
bool open;
public:
clipboard(HWND owner = nullptr): open(OpenClipboard(owner)) {} clipboard(const clipboard&) = delete;
clipboard(clipboard&&) = delete;
clipboard& operator=(const clipboard&) = delete;
clipboard& operator=(clipboard&&) = delete; ~clipboard() {
if(open) {
CloseClipboard();
}
} bool clear() const noexcept {
return EmptyClipboard();
} bool is_open() const noexcept {
return open;
} bool copy(const std::string& str) const {
if(open) {
clear();
HGLOBAL buffer = GlobalAlloc(GMEM_DDESHARE, str.size() + );
if(buffer) {
std::copy(std::begin(str), std::end(str), static_cast<char*>(GlobalLock(buffer)));
GlobalUnlock(buffer);
return SetClipboardData(CF_TEXT, buffer) != nullptr;
}
}
return false;
} // no error checking on purpose
std::string paste() const {
return static_cast<char*>(GetClipboardData(CF_TEXT));
}
}; int help() {
std::cout <<
"usage: xclip [options]\n\n"
" -i, --in reads text from stdin (default)\n"
" -o, --out outputs text to stdout\n"
" -f, --file <filename> reads text from a file\n"
" -v, --version outputs version information\n"
" -h, --help prints this message and exits\n";
return EXIT_SUCCESS;
} int version() {
std::cout <<
"xclip version 1.0 (Windows native port)\n"
"Written by Rapptz\n\n"
"Copyright (C) 2014 Rapptz\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n";
return EXIT_SUCCESS;
} int error(const char* str) {
std::cout << "xclip: error: " << str << '\n';
return EXIT_FAILURE;
} int read_text(const clipboard& clip) {
std::ostringstream ss;
for(std::string line; std::getline(std::cin, line); ) {
ss << line;
}
return clip.copy(ss.str()) ? EXIT_SUCCESS : EXIT_FAILURE;
} int read_file(const clipboard& clip, const std::string& filename) {
if(filename.empty()) {
return error("no input file given");
}
std::ifstream in(filename);
std::ostringstream ss;
ss << in.rdbuf();
return clip.copy(ss.str()) ? EXIT_SUCCESS : EXIT_FAILURE;
} int main(int argc, char** argv) {
clipboard clip;
if(!clip.is_open()) {
return error("unable to open clipboard");
} std::vector<std::string> args{argv, argv + argc}; if(argc < ) {
return read_text(clip);
} for(int i = ; i < argc; ++i) {
auto&& arg = args[i]; if(arg == "-h" || arg == "--help") {
return help();
} if(arg == "-v" || arg == "--version") {
return version();
} if(arg == "-i" || arg == "--in") {
return read_text(clip);
} if(arg == "-o" || arg == "--out") {
std::cout << clip.paste();
return EXIT_SUCCESS;
} if(arg == "-f") {
if(i + < argc) {
return read_file(clip, args[i + ]);
}
return error("no input file given");
} auto&& pos = arg.find("--file");
if(pos == ) {
// len(--file) == 6
if(i + < argc && arg.size() == ) {
return read_file(clip, args[i + ]);
}
else if(arg[] == '=') {
return read_file(clip, arg.substr());
}
return error("no input file given");
}
}
}

xclip for windows的更多相关文章

  1. Git 配置ssh key的步骤

    First start by setting up your own public/private key pair set. This can use either DSA or RSA, so b ...

  2. linux与windows共享剪贴板(clipboard)

    linux与windows共享剪贴板(clipboard)的方法 先说两句废话,其实linux和windows之间不需要共享剪贴板,直接在putty中,按住SHIFT+鼠标选择就可以了. 但是作为一种 ...

  3. 在Windows下搭建Gitlab服务器

    一.GitLab简介 GitLab 是一个用于仓库管理系统的开源项目.使用Git作为代码管理工具,并在此基础上搭建起来的web服务. 可通过Web界面进行访问公开的或者私人项目.它拥有与Github类 ...

  4. Windows server 2012 添加中文语言包(英文转为中文)(离线)

    Windows server 2012 添加中文语言包(英文转为中文)(离线) 相关资料: 公司环境:亚马孙aws虚拟机 英文版Windows2012 中文SQL Server2012安装包,需要安装 ...

  5. Windows Server 2012 NIC Teaming介绍及注意事项

    Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...

  6. C# 注册 Windows 热键

    闲扯: 前几日,一个朋友问我如何实现按 F1 键实现粘贴(Ctrl+V)功能,百度了一个方法,发给他,他看不懂(已经是 Boss 的曾经的码农),我就做了个Demo给他参考.今日得空,将 Demo 整 ...

  7. Windows 7上执行Cake 报错原因是Powershell 版本问题

    在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...

  8. 在离线环境中发布.NET Core至Windows Server 2008

    在离线环境中发布.NET Core至Windows Server 2008 0x00 写在开始 之前一篇博客中写了在离线环境中使用.NET Core,之后一边学习一边写了一些页面作为测试,现在打算发布 ...

  9. Windows平台分布式架构实践 - 负载均衡

    概述 最近.NET的世界开始闹腾了,微软官方终于加入到了对.NET跨平台的支持,并且在不久的将来,我们在VS里面写的代码可能就可以通过Mono直接在Linux和Mac上运行.那么大家(开发者和企业)为 ...

随机推荐

  1. GET和POST传输方式

    GET和POST传输 在很多人看来,get和post的区别有比如安不安全,传输有大小限制等,在这里,我将对get和post做出客观的评价: GET: 传输方法:get传输数据一般是在地址栏的url的问 ...

  2. Gerrit的安装和使用说明

    Gerrit安装和使用说明 搞了几天,资料也查了不少,终于磨出来了.有什么不对的地方,大家及时提出来...,开始吧 系统 Centos6.5 x64 内存 2G 硬盘 20G 数据库 Mysql5.1 ...

  3. Springboot中Feign的使用总结

    Feign是Webservice服务的客户端,创建接口+注解就可完成,实现简单 客户端通过@EnableFeignClients开启Feign的支持功能 @SpringBootApplication ...

  4. 关于selenium的那些坑

    selenium 辅助工具 splinter 总有人看不明白,以防万一,先在开头大写加粗说明一下: frameset不用切,frame需层层切! 很多人在用selenium定位页面元素的时候会遇到定位 ...

  5. JDK源码之数组

    序言 <1>栈内存和堆内存当一个方法执行时,每个方法都会建立自己的内存栈,在这方法内定义的变量将会逐个放入这块栈内存里,随着方法的执行结束,这个方法的内存栈也将自然销毁.所有在方法中定义的 ...

  6. IScroll基本用法

    一.为了防止手机上卡顿:1.从新设置一下焦点.2. <script>try { window.PointerEvent = undefined; } catch (e) { } </ ...

  7. 使用select正确处理EOF的str_cli函数

    void str_cli(FILE *fp, int sockfd) { int maxfdp1, stdineof; fd_set rset; char buf[MAXLINE]; int n; s ...

  8. C++ 中容器

    容器为模板类 顺序容器 vector deque (双端队列) list  (双向链表) forward_list(单向链表) array (固定大小数组) string ( 与vector 相似)保 ...

  9. RSA加解密-2

    Java使用RSA加密解密签名及校验   package com.ihep; import java.io.BufferedReader; import java.io.BufferedWriter; ...

  10. Luogu P2490「JSOI2016」黑白棋

    我博弈基础好差.. Luogu P2490 题意 有一个长度为$ n$的棋盘,黑白相间的放$ k$个棋子,保证$ k$是偶数且最左边为白子 每次小$ A$可以移动不超过$ d$个白子,然后小$ B$可 ...