├── LICENSE ├── README.md ├── assets └── logo.png ├── install.sh ├── lacy ├── test.sh └── test ├── hello.c └── snip.c /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Francois Alcover 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![logo](assets/logo.png) 2 | 3 | # lacy - *Compile/run for the lazy* 4 | 5 | (Linux only) 6 | 7 | Want to test a few lines of C ? 8 | 9 | Normally you'd have to : 10 | - create `test.c` 11 | - write headers `#include #include ...` 12 | - write entry-point `int main (int argc ...) {}` 13 | - write your code 14 | - save 15 | - finally run `gcc test.c -Wall -Wbar && ./a.out` 16 | 17 | Forgot a header ? To link math (`-lm`) ? 18 | Bad luck... Now you have to edit `test.c`... 19 | 20 | No such hassle with **lacy** : 21 | ``` 22 | $ lacy 23 | int i = pow(2,8); 24 | printf ("%d\n", i); 25 | [CTRL+D] 26 | 256 27 | ``` 28 | 29 | **lacy** can also run files. 30 | `$ lacy hello.c` 31 | 32 | If your code has no `main()`, **lacy** adds classic headers and puts your statements into `main()`. 33 | 34 | ## Usage 35 | 36 | #### File : 37 | ``` 38 | $ lacy hello.c 39 | Hello! 40 | ``` 41 | 42 | #### File + arguments : 43 | ``` 44 | $ lacy hello.c Bob 45 | Hello Bob! 46 | ``` 47 | 48 | #### Pipe : 49 | ``` 50 | $ cat hello.c | lacy 51 | Hello! 52 | ``` 53 | 54 | #### Prompt : 55 | ``` 56 | $ lacy 57 | printf ("%s\n", "Hello!"); 58 | [CTRL+D] 59 | Hello! 60 | ``` 61 | 62 | #### Inline : 63 | ``` 64 | $ lacy 'printf ("%s\n", "Hello!");' 65 | Hello! 66 | ``` 67 | 68 | #### Print template : 69 | `$ lacy > new_project.c` (gets you a fresh all-included source) 70 | 71 | ## Options 72 | 73 | `$ lacy -h` (help) 74 | `$ lacy -v` (version) -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alcover/lacy/994a263e58509d50b5dff84bccff13abfc3df4f1/assets/logo.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # home/bin installer 4 | # author: alco 5 | 6 | app=lacy 7 | 8 | echo "$app installer" 9 | echo "will make '$app' command accessible from anywhere in your home." 10 | 11 | bin="$HOME/bin" 12 | dotbin="$HOME/.bin" 13 | 14 | if [ ! -d "$bin" ]; then 15 | if [ ! -d "$dotbin" ]; then 16 | read -p "Your home has no 'bin' dir. Create one ? y/n : " rsp 17 | if [ $rsp = 'y' ]; then 18 | echo "Creating $bin" 19 | mkdir -p "$bin" 20 | echo "Adding $bin to PATH and bashrc" 21 | echo 'export PATH=$PATH:$HOME/bin' >> $HOME/.bashrc && source $HOME/.bashrc 22 | else 23 | echo "Aborting.." 24 | exit 0 25 | fi 26 | else 27 | bin="$dotbin" 28 | fi 29 | fi 30 | 31 | echo "Adding $app to $bin and chmod'ing +x" 32 | 33 | if [ -f "$bin/$app" ]; then 34 | read -p "$bin/$app already exists. Replace ? y/n : " rsp 35 | if [ $rsp = 'y' ]; then 36 | rm "$bin/$app" 37 | else 38 | echo "Aborting.." 39 | exit 0 40 | fi 41 | fi 42 | 43 | ln -f $app "$bin/$app" 44 | chmod +x "$bin/$app" -------------------------------------------------------------------------------- /lacy: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # lacy - Compile and run C 4 | # 5 | # Takes your C code, compiles it with gcc, then runs. 6 | # The source can be a complete C file or just statements. 7 | # In that case, lacy adds classic headers 8 | # and puts your statements into main(). 9 | # 10 | # USAGE 11 | # 12 | # File : 13 | # $ lacy hello.c 14 | # Hello! 15 | # 16 | # File + args : 17 | # $ lacy hello.c Bob 18 | # Hello Bob! 19 | # 20 | # Pipe : 21 | # $ cat hello.c | lacy 22 | # 23 | # Prompt : 24 | # $ lacy 25 | # int i = 10; 26 | # printf("%d\n", i); 27 | # [CTRL+D] 28 | # 10 29 | # 30 | # Inline : 31 | # $ lacy 'printf("%s\n", "Hello!");' 32 | # 33 | # Reuse template : 34 | # $ lacy > new_project.c 35 | # 36 | # $ lacy -h (help) 37 | # $ lacy -v (version) 38 | # 39 | # AUTHOR : Francois Alcover 40 | 41 | #============================================================= 42 | 43 | # strict mode 44 | set -e 45 | set -u 46 | set -o pipefail 47 | 48 | app=lacy 49 | runc_version='0.2' 50 | 51 | runc_headers="\ 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | " 72 | 73 | runc_tpl="\ 74 | // file generated by $app 75 | 76 | $runc_headers 77 | int main (int argc, char **argv) 78 | { 79 | @code 80 | return 0; 81 | } 82 | " 83 | 84 | # -lc ? 85 | runc_flags="-std=gnu11 -lm -Wno-pedantic -Wno-unused-variable" 86 | 87 | bold=$(tput bold) 88 | norm=$(tput sgr0) 89 | 90 | runc_help="\ 91 | $app - compile and run C 92 | 93 | Takes your C code, compiles it with gcc, then runs. 94 | If the source has no 'main()' $app adds classic headers 95 | and a 'main()' holding your statements. 96 | 97 | Usage: 98 | 99 | - File : 100 | ${bold}$ $app hello.c 101 | Hello!${norm} 102 | 103 | - File + args : 104 | ${bold}$ $app hello.c Bob 105 | Hello Bob!${norm} 106 | 107 | - Pipe : 108 | ${bold}$ cat hello.c | $app 109 | Hello!${norm} 110 | 111 | - Prompt (enter statements then CTRL+D) : 112 | ${bold}$ $app${norm} 113 | int i = 10; 114 | printf (\"%d\n\", i); 115 | [CTRL+D] 116 | 10 117 | 118 | - Inline : 119 | ${bold}$ $app 'printf(\"Hello!\");'${norm} 120 | 121 | - Get nice template : 122 | ${bold}$ $app > new_project.c${norm} 123 | 124 | - Get version : 125 | ${bold}$ $app -v${norm} 126 | " 127 | 128 | #============================================================= 129 | 130 | srcpath='' 131 | code='' 132 | args='' 133 | 134 | # no arguments 135 | if [ $# -eq 0 ]; then 136 | 137 | # term in 138 | if [[ -t 0 ]]; then 139 | # term out 140 | if [[ -t 1 ]]; then 141 | echo "(Help : $app -h)" 142 | echo "Enter lines of code then hit CTRL+D :" 143 | else 144 | # print template 145 | echo -n "${runc_tpl/@code/}" 146 | exit 0 147 | fi 148 | fi 149 | 150 | code=$( "$srcpath" 196 | echo "(saved as $srcpath)" 197 | fi 198 | 199 | exepath="$tmp" 200 | 201 | gcc $runc_flags "$srcpath" -o "$exepath" \ 202 | && "$exepath" "$args" \ 203 | && rm -f "$exepath" \ 204 | && exit 0 -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | app=lacy 4 | 5 | unit(){ 6 | echo "$1" 7 | eval $1 8 | echo 9 | } 10 | 11 | unit "./$app test/hello.c" 12 | unit "./$app test/hello.c Bob" 13 | unit "./$app test/snip.c" 14 | 15 | unit "cat test/hello.c | ./$app" 16 | unit "cat test/snip.c | ./$app" 17 | 18 | unit "./$app 'printf(\"%s\\n\", \"Hello\");'" 19 | 20 | # unit "./$app > /tmp/new.c" 21 | # cat /tmp/new.c 22 | # echo 23 | 24 | unit "./$app -h" 25 | unit "./$app -v" 26 | 27 | unit "./$app" -------------------------------------------------------------------------------- /test/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main (int argc, char **argv) 4 | { 5 | char* name = argv[1] ?: "?"; 6 | printf ("%s %s\n", "Hello", name); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /test/snip.c: -------------------------------------------------------------------------------- 1 | int i = 10; 2 | printf ("%d\n", i); --------------------------------------------------------------------------------