From 2aea1cf664188867c17909b56448056d790efe9d Mon Sep 17 00:00:00 2001 From: Luke Renaud Date: Mon, 6 Sep 2021 18:15:26 -0700 Subject: [PATCH] Forgive me Greg for I have sinned. --- .gitignore | 4 ++++ LICENSE | 24 +++++++++++++++++++ hello-world.cpp | 10 ++++++++ sheclang | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100755 hello-world.cpp create mode 100755 sheclang diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4cecca --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +hello-world +.sheclang.*.cpp +.swp* + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c577b0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +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 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. + +For more information, please refer to \ No newline at end of file diff --git a/hello-world.cpp b/hello-world.cpp new file mode 100755 index 0000000..064c2c6 --- /dev/null +++ b/hello-world.cpp @@ -0,0 +1,10 @@ +#!/usr/bin/env sheclang + +#include + +int main(int argc, char *argv[]) { + + printf("Hello World!\n"); + + return 0; +} diff --git a/sheclang b/sheclang new file mode 100755 index 0000000..8124708 --- /dev/null +++ b/sheclang @@ -0,0 +1,61 @@ +#!/bin/bash +# sheclang - shebang (#!) meets automatic clang. +# Luke Renaud +# 2021-09-06 (Public Domain) +# _____________________________________________________________________________ +# I got tired of the turnaround time when debugging my code, and I don't want +# to make a full build system or frankly even maintain a ./build.sh script for +# each project. I'm well on the road to re-inventing another build system, but +# if we can make python a simple ./.py, why can't we do the same for +# C and C++? +# +# See hello-world.cpp for the source code. Install this guy wherever your bins +# are stored, try it, weep, then rejoice that you have one less buffer open. +# +# _____________________________________________________________________________ +# LICENSE: +# Public Domain (y'all really care?) + +set -e +export IFS=$'\n' + +## Phase 1: Input Collection & Argument Checking +if [[ $# -lt 1 ]]; then + printf "sheclang requires exactly one build file arugment.\n" >&2 + exit +fi + +file_input="$1" +target_dir="$(dirname "${file_input}")" + +# TODO: Validate the extension of the output file before fucking with it. +file_input_name="$(basename "${file_input}")" +file_output="${file_input_name%.*}" +file_extension="${file_input_name##*.}" +if [[ "$file_input_name" == "$file_output" ]]; then + ( + printf "ERROR! Input and output file names match.\n" + printf " file input: %s\n" "$file_input_name" + printf " file output: %s\n" "$file_output" + ) >&2 + exit; +fi + +## Phase 2: File cleanup +# Build the copy the main source file without a hashbang line +file_input_corrected="${target_dir}/.sheclang.${file_output}.${file_extension}" +cp "${file_input}" "${file_input_corrected}" + +printf "//" | dd conv=notrunc of="${file_input_corrected}" \ + count=2 bs=1 status=none + +file_output="${target_dir}/${file_output}" + +## Phase 3: Build the file, and execute it with the remaining arguments. +shift # remove the source file from the BASH argument tree. + +# Runn my prefered build script. Customize to your tastes +clang++ -o "$file_output" "$file_input_corrected" + +# And execute with the remaining arguments +"$file_output" $* \ No newline at end of file