{ // Competitive-programming workflow: compile the focused .cpp, feed it // inputf.in on stdin, capture stdout to outputf.out, and print the result. // // Both files live NEXT TO THE SOURCE (working_dir is the file's folder), // not at the repo root. Use "Setup" below to create them. // // Sublime expands ${name} AND bare $name in shell_cmd. Every $ meant for // bash is escaped \$ -- see https://www.sublimetext.com/docs/build_systems.html "shell_cmd": "test -n \"${file}\" || { echo 'Click into a .cpp tab, then build.'; exit 1; }; clang++ \\$(cat compile_flags.txt 2>/dev/null) \"${file}\" -o \"${file_base_name}\" || exit 1; touch inputf.in; ./\"${file_base_name}\" < inputf.in > outputf.out; echo '--- inputf.in ---'; cat inputf.in; echo '--- outputf.out ---'; cat outputf.out", "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$", "working_dir": "${file_path:${folder}}", "selector": "source.c++", "variants": [ { // Same as above, then check the answer against expectedf.out. "name": "Run + check against expectedf.out", "shell_cmd": "test -n \"${file}\" || { echo 'Click into a .cpp tab, then build.'; exit 1; }; clang++ \\$(cat compile_flags.txt 2>/dev/null) \"${file}\" -o \"${file_base_name}\" || exit 1; touch inputf.in; ./\"${file_base_name}\" < inputf.in > outputf.out; echo '--- outputf.out ---'; cat outputf.out; if [ -f expectedf.out ]; then echo '--- diff (expected vs actual) ---'; if diff -u expectedf.out outputf.out; then echo 'PASS'; else echo 'FAIL'; exit 1; fi; else echo '(no expectedf.out here - run Setup to make one)'; fi" }, { // No redirect: type the input straight into the build panel. "name": "Run (type input live)", "shell_cmd": "test -n \"${file}\" || { echo 'Click into a .cpp tab, then build.'; exit 1; }; clang++ \\$(cat compile_flags.txt 2>/dev/null) \"${file}\" -o \"${file_base_name}\" || exit 1; ./\"${file_base_name}\"", "interactive": true }, { "name": "Setup: create inputf.in / expectedf.out here", "shell_cmd": "touch inputf.in expectedf.out outputf.out; echo \"ready in \\$(pwd):\"; ls -l inputf.in expectedf.out outputf.out" }, { "name": "DIAGNOSTIC - show Sublime variables", "shell_cmd": "echo \"file = [${file}]\"; echo \"file_path = [${file_path}]\"; echo \"base_name = [${file_base_name}]\"; echo \"cwd = \\$(pwd)\"" } ] }