Skip to content

Commit 8525e87

Browse files
committed
initial commit
0 parents  commit 8525e87

File tree

106 files changed

+19315
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+19315
-0
lines changed

.clang-format

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BasedOnStyle: LLVM
2+
ColumnLimit: 0
3+
DerivePointerBinding: true
4+
AllowShortIfStatementsOnASingleLine: true
5+
AllowShortBlocksOnASingleLine: true
6+
PointerAlignment: Left
7+
IndentCaseLabels: true

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true
10+
11+
[Makefile]
12+
indent_style = tab

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/

.markdownlint.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"MD013": false,
3+
"MD030": {
4+
"ol_single": 2,
5+
"ol_multi": 2
6+
},
7+
"MD033": {
8+
"allowed_elements": ["br"]
9+
},
10+
"MD041": false
11+
}

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: cpp
2+
os: osx
3+
compiler: clang
4+
install: true
5+
script: make -C tests

.vscode/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/browse.vc.db*

.vscode/c_cpp_properties.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"browse": {
6+
"path": [
7+
"${workspaceFolder}/include",
8+
"${workspaceFolder}/tests/vendor/include",
9+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
10+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
11+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include",
12+
"/opt/local/include",
13+
"/usr/include",
14+
"/usr/include/c++/4.2.1",
15+
"/usr/local/include"
16+
],
17+
"limitSymbolsToIncludedHeaders": true,
18+
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
19+
},
20+
"defines": [],
21+
"includePath": [
22+
"${workspaceFolder}/include",
23+
"${workspaceFolder}/tests/vendor/include",
24+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++",
25+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
26+
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include",
27+
"/opt/local/include",
28+
"/usr/include",
29+
"/usr/include/c++/4.2.1",
30+
"/usr/local/include"
31+
],
32+
"macFrameworkPath": []
33+
}
34+
],
35+
"version": 4
36+
}

.vscode/settings.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"files.exclude": {
3+
"**/build/": true,
4+
"**/vendor/cget/": true,
5+
".vscode/browse.vc.*": true
6+
},
7+
"search.exclude": {
8+
"**/vendor/": true
9+
}
10+
}

LICENSE.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Boost Software License - Version 1.0 - August 17th, 2003
2+
3+
Permission is hereby granted, free of charge, to any person or organization
4+
obtaining a copy of the software and accompanying documentation covered by
5+
this license (the "Software") to use, reproduce, display, distribute,
6+
execute, and transmit the Software, and to prepare derivative works of the
7+
Software, and to permit third-parties to whom the Software is furnished to
8+
do so, all subject to the following:
9+
10+
The copyright notices in the Software and this entire statement, including
11+
the above license grant, this restriction and the following disclaimer,
12+
must be included in all copies of the Software, in whole or in part, and
13+
all derivative works of the Software, unless such copies or derivative
14+
works are solely in the form of machine-executable object code generated by
15+
a source language processor.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20+
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21+
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23+
DEALINGS IN THE SOFTWARE.

README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[![Build Status](https://travis-ci.org/pqrs-org/cpp-shell.svg?branch=master)](https://travis-ci.org/pqrs-org/cpp-shell)
2+
[![License](https://img.shields.io/badge/license-Boost%20Software%20License-blue.svg)](https://github.com/pqrs-org/cpp-shell/blob/master/LICENSE.md)
3+
4+
# cpp-shell
5+
6+
A utility of `shell`.
7+
8+
## Requirements
9+
10+
cpp-shell depends the following classes.
11+
12+
- [pqrs::string](https://github.com/pqrs-org/cpp-string)
13+
14+
## Install
15+
16+
### Using package manager
17+
18+
You can install `include/pqrs` by using [cget](https://github.com/pfultz2/cget).
19+
20+
```shell
21+
cget install pqrs-org/cget-recipes
22+
cget install pqrs-org/cpp-shell
23+
```
24+
25+
### Manual install
26+
27+
Copy `include/pqrs` directory into your include directory.

example/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/cget/cget.cmake
2+
/vendor/cget/pkg/pqrs-org__cget-recipes/
3+
/vendor/etc/
4+
/vendor/**/pkgconfig/

example/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
set(CMAKE_CXX_STANDARD 17)
4+
5+
add_compile_options(-Wall)
6+
add_compile_options(-Werror)
7+
add_compile_options(-O2)
8+
9+
project (example)
10+
11+
include_directories(${CMAKE_CURRENT_LIST_DIR}/../include)
12+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/vendor/include)
13+
14+
add_executable(
15+
example
16+
main.cpp
17+
)

example/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
all:
2+
mkdir -p build \
3+
&& cd build \
4+
&& cmake .. \
5+
&& make
6+
7+
clean:
8+
rm -rf build
9+
10+
run:
11+
./build/example
12+
13+
update_vendor:
14+
rm -rf vendor
15+
cget install pqrs-org/cget-recipes --prefix vendor
16+
cget install -f cget-requirements.txt --prefix vendor

example/cget-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pqrs-org/cpp-string

example/main.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <iostream>
2+
#include <pqrs/shell.hpp>
3+
4+
int main(void) {
5+
std::cout << pqrs::shell::make_background_command_string("/bin/ls -la /") << std::endl;
6+
std::cout << pqrs::shell::make_background_command_string("/bin/ls -la &") << std::endl;
7+
8+
return 0;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
// pqrs::string v1.1
4+
5+
// (C) Copyright Takayama Fumihiko 2018.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include "string/trim.hpp"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
3+
// (C) Copyright Takayama Fumihiko 2018.
4+
// Distributed under the Boost Software License, Version 1.0.
5+
// (See http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <algorithm>
8+
#include <cctype>
9+
10+
namespace pqrs {
11+
namespace string {
12+
inline void trim_left(std::string& s) {
13+
s.erase(s.begin(),
14+
std::find_if(s.begin(),
15+
s.end(),
16+
[](int c) {
17+
return !std::isspace(c);
18+
}));
19+
}
20+
21+
inline void trim_right(std::string& s) {
22+
s.erase(std::find_if(s.rbegin(),
23+
s.rend(),
24+
[](int c) {
25+
return !std::isspace(c);
26+
})
27+
.base(),
28+
s.end());
29+
}
30+
31+
inline void trim(std::string& s) {
32+
trim_left(s);
33+
trim_right(s);
34+
}
35+
36+
inline std::string trim_left_copy(std::string s) {
37+
trim_left(s);
38+
return s;
39+
}
40+
41+
inline std::string trim_right_copy(std::string s) {
42+
trim_right(s);
43+
return s;
44+
}
45+
46+
static inline std::string trim_copy(std::string s) {
47+
trim(s);
48+
return s;
49+
}
50+
} // namespace string
51+
} // namespace pqrs
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../cget/pkg/pqrs-org__cpp-string/install/include/pqrs/string.hpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../cget/pkg/pqrs-org__cpp-string/install/include/pqrs/string/trim.hpp

include/pqrs/shell.hpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
// pqrs::shell v0.0
4+
5+
// (C) Copyright Takayama Fumihiko 2018.
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See http://www.boost.org/LICENSE_1_0.txt)
8+
9+
#include <pqrs/string.hpp>
10+
#include <sstream>
11+
12+
namespace pqrs {
13+
namespace shell {
14+
inline std::string make_background_command_string(const std::string& command) {
15+
auto trimmed_command = pqrs::string::trim_copy(command);
16+
if (trimmed_command.empty()) {
17+
return "";
18+
}
19+
20+
if (trimmed_command.back() != '&') {
21+
trimmed_command += " &";
22+
}
23+
24+
return trimmed_command;
25+
}
26+
} // namespace shell
27+
} // namespace pqrs

tests/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/cget/cget.cmake
2+
/vendor/cget/pkg/pqrs-org__cget-recipes/
3+
/vendor/etc/
4+
/vendor/**/pkgconfig/

tests/Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
all:
2+
@for d in `find * -type d`; do \
3+
if [ -f "$$d/CMakeLists.txt" ]; then \
4+
echo "[Test] $$d"; \
5+
make -C $$d || exit 1; \
6+
fi; \
7+
done
8+
9+
clean:
10+
@for d in `find * -type d`; do \
11+
if [ -f "$$d/CMakeLists.txt" ]; then \
12+
make -C $$d clean; \
13+
fi; \
14+
done
15+
16+
update_vendor:
17+
rm -rf vendor
18+
cget install pqrs-org/cget-recipes --prefix vendor
19+
cget install -f cget-requirements.txt --prefix vendor

tests/cget-requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
pqrs-org/cpp-string

tests/src/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required (VERSION 3.9)
2+
3+
set(CMAKE_CXX_STANDARD 17)
4+
5+
add_compile_options(-Wall)
6+
add_compile_options(-Werror)
7+
add_compile_options(-O2)
8+
9+
include_directories(${CMAKE_CURRENT_LIST_DIR}/../../include)
10+
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../vendor/include)
11+
12+
project (test)
13+
14+
add_executable(
15+
test
16+
test.cpp
17+
)

tests/src/Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
all:
2+
mkdir -p build \
3+
&& cd build \
4+
&& cmake .. \
5+
&& make
6+
make run
7+
8+
clean:
9+
rm -rf build
10+
11+
run:
12+
./build/test

tests/src/test.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#define CATCH_CONFIG_MAIN
2+
#include <catch2/catch.hpp>
3+
4+
#include <pqrs/shell.hpp>
5+
6+
TEST_CASE("make_background_command_string") {
7+
{
8+
std::string command = "open '/Applications/Utilities/Activity Monitor.app'";
9+
std::string expected = "open '/Applications/Utilities/Activity Monitor.app' &";
10+
REQUIRE(pqrs::shell::make_background_command_string(command) == expected);
11+
}
12+
{
13+
std::string command = "open '/Applications/Utilities/Activity Monitor.app'&";
14+
std::string expected = "open '/Applications/Utilities/Activity Monitor.app'&";
15+
REQUIRE(pqrs::shell::make_background_command_string(command) == expected);
16+
}
17+
{
18+
std::string command = "ls & echo hello";
19+
std::string expected = "ls & echo hello &";
20+
REQUIRE(pqrs::shell::make_background_command_string(command) == expected);
21+
}
22+
}

0 commit comments

Comments
 (0)