Forgive me Greg for I have sinned.
This commit is contained in:
		
						commit
						459f0b41f7
					
				
					 5 changed files with 131 additions and 0 deletions
				
			
		
							
								
								
									
										4
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					hello-world
 | 
				
			||||||
 | 
					.sheclang.*.cpp
 | 
				
			||||||
 | 
					.swp*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										24
									
								
								LICENSE
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								LICENSE
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -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 <https://unlicense.org>
 | 
				
			||||||
							
								
								
									
										33
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,33 @@
 | 
				
			||||||
 | 
					# `sheclang` - A `#!` for your C++ files.
 | 
				
			||||||
 | 
					## Installation & Test
 | 
				
			||||||
 | 
					To install, just stick the bash script in your path either by a copy or a symlink.
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					git clone https://github.com/lrenaud/sheclang
 | 
				
			||||||
 | 
					cd sheclang
 | 
				
			||||||
 | 
					sudo cp -v sheclang /usr/bin/
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					To run, try the demo after installing.
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					chmod +x ./hello-world.cpp
 | 
				
			||||||
 | 
					./hello-world.cpp
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					## Use
 | 
				
			||||||
 | 
					1. Add the following line to the first line of your C++ file.
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					#!/usr/bin/env sheclang
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					2. Mark your top level `*.cpp` file as executable
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					cd ~/your-project
 | 
				
			||||||
 | 
					chmod +x your-source-code.cpp
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					3. Run the source file like it was an executable. Arguments passed to the `*.cpp` file will be forwarded onto the resulting binary directly.
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					./your-source-code.cpp --your-argument positional --this-flag
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					## Why?
 | 
				
			||||||
 | 
					Because I could. And anything that makes building performant software more
 | 
				
			||||||
 | 
					assessable to more users is worth it. I can't imagine many Python beginners are
 | 
				
			||||||
 | 
					using the debugging facilities and interactivity of the Python interactive
 | 
				
			||||||
 | 
					terminal. So why not do what I can to make building C++ as trivial to get
 | 
				
			||||||
 | 
					off the ground as trivial python.
 | 
				
			||||||
							
								
								
									
										9
									
								
								hello-world.cpp
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										9
									
								
								hello-world.cpp
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					#!/usr/bin/env sheclang
 | 
				
			||||||
 | 
					#include <stdio.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int argc, char  *argv[]) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						printf("Hello World!\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										61
									
								
								sheclang
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										61
									
								
								sheclang
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -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 ./<my code>.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" $*
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue