Forgive me Greg for I have sinned.
This commit is contained in:
		
						commit
						2aea1cf664
					
				
					 4 changed files with 99 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>
 | 
			
		||||
							
								
								
									
										10
									
								
								hello-world.cpp
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										10
									
								
								hello-world.cpp
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,10 @@
 | 
			
		|||
#!/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