ryanmjacobs / c Goto Github PK
View Code? Open in Web Editor NEWCompile and execute C "scripts" in one go!
License: MIT License
Compile and execute C "scripts" in one go!
License: MIT License
Hi, can we please get this on brew?
Hi @ryanmjacobs,
I just want to mention similar work. You might consider adding a link to your readme or taking inspiration from the ~/.c99shrc
config file.
it would be great to have a --debug
flag to launch gdb
~ ⍉
▶ brew install https://raw.githubusercontent.com/ryanmjacobs/c/master/c.rb
######################################################################## 100.0%
==> Downloading https://github.com/ryanmjacobs/c/archive/v0.12.tar.gz
==> Downloading from https://codeload.github.com/ryanmjacobs/c/tar.gz/v0.12
curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource "c"
Download failed: https://github.com/ryanmjacobs/c/archive/v0.12.tar.gz
A better "shebang" would be
///bin/true; /usr/bin/c "$0" "$*"; exit $?
as it would keep file compileable with normal gcc
invocation. See example of this here (also discussion on StackOverflow).
What do you think about using
#!/usr/bin/env c
as shebang to support prefixed install. Then you can e.g. install in /usr/local and still run the examples:
PREFIX=/usr/local bpkg install ryanmjacobs/c
Having the license in the same file as the readme makes this more difficult to package than it needs to be., as I would need to manually parse the readme file. If the license was in a separate file, I could just copy it into place.
At the top of the script searches your path for 'c' and execute that script.
Means you can use it no matter where your 'c' is installed (~/bin/ /usr/local/bin or /usr/bin et al).
Thanks for this tool. I've been looking for something like this for a while.
I'm running into an issue where, if I run c ./main.c
, and the contents is something like this:
#include <stdio.h>
int main(void)
{
printf("%s\n", "Hello, World");
return 0;
}
I get the following output:
Hello, World
du: illegal option -- -
usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] [-h | -k | -m | -g] [-x] [-I mask] [file ...]
Seems like --block-size
in size="$(du --block-size=1024 -s "$tmproot" | tail -n1 | cut -f1)"
isn't valid on Catalina.
Any ideas? #38 mentions this error.
Instead of always hashing to check if cache is invalidated, why not use stat
or date
to check if a script has been modified since last compilation? If the script has been modified, we can fallback to hashing, as usual
It would be awesome if we could pass comma separated RPATH's in the shebang.
I'm just very curios to know how its possible that just by putting shebang, no 'c' prefix command requred. just run it directly like this:
$ chmod +x hello.c
$ ./hello.c
Hello World
its the feature of bash?
i cant find where you implemented this feauture.
root@niuyuling:/mnt/c/Users/niuyuling/Desktop/libini# ../c/c test.c -L./ -lini -static
/usr/bin/ld: /tmp/cc3AcSun.o: in function main': test.c:(.text.startup+0x21): undefined reference to
getinikeystring'
/usr/bin/ld: test.c:(.text.startup+0x5f): undefined reference to getinikeystring' /usr/bin/ld: test.c:(.text.startup+0x9a): undefined reference to
getinikeyint'
/usr/bin/ld: test.c:(.text.startup+0xdd): undefined reference to getinikeylong' /usr/bin/ld: test.c:(.text.startup+0x121): undefined reference to
getinikeyfloat'
/usr/bin/ld: test.c:(.text.startup+0x170): undefined reference to putinikeystring' /usr/bin/ld: test.c:(.text.startup+0x18d): undefined reference to
getinikeystring'
/usr/bin/ld: test.c:(.text.startup+0x1cd): undefined reference to `getinikeystring'
collect2: error: ld returned 1 exit status
root@niuyuling:/mnt/c/Users/niuyuling/Desktop/libini#
root@niuyuling:/mnt/c/Users/niuyuling/Desktop/libini# ../c/c 'test.c -L./ -lini -static'
/usr/bin/ld: 找不到 -lini
collect2: error: ld returned 1 exit status
root@niuyuling:/mnt/c/Users/niuyuling/Desktop/libini#
可不可以支持多文件或者链接库文件
Can I support multiple files or link library files?
The script does not work on files with paths containing whitespaces.
[jimmy@toolbox my folder]$ pwd
/home/jimmy/my folder
[jimmy@toolbox my folder]$ ./foo.c
cc: error: folder: No such file or directory
[jimmy@toolbox my folder]$ c foo.c
cc: error: folder: No such file or directory
[jimmy@toolbox my folder]$ c "/home/jimmy/my folder/foo.c"
cc: error: /home/jimmy/my: No such file or directory
cc: error: folder/foo.c: No such file or directory
cc: error: folder: No such file or directory
cc: fatal error: no input files
compilation terminated.
Hi, I noticed that depending upon what I pass to C sometimes result is not what I expect. Having looked at https://github.com/ryanmjacobs/c/blob/master/c#L54
I am a bit confused and thought it is worth raising this question. I see that here instead of trying to process all command line arguments, we there is a for arg in $1
, which even if we do a shift later won't mean that this for look is going to run more than once. I assumed that maybe that should have been $@
, but it would break some of this logic also.
Anyway, I think my question, since there are not comments there to help me understand, is whether or not this loop at line 54 was meant to be gone through more than once. If so, I think there may be problems with it.
Thanks!
hello man can you help me in C ?
i now how to extract ANCII chars and concaternate them..
what i need to know its how can i execute that ancii string after concaternation ..
example:
1º i what to extract the string whoami from ancii chart
2º concaternate the chars to build whoami command
3º and execute the string concaternated ..
this code does allmost everything..
it extracts the chars, concaternate them ...
but it only prints the string ..
but i dont what to print ..i want to execute ..
#include <stdio.h>
#include <string.h>
int main(void)
{
/* variable declarations */
char a = 119; /* ancii character w */
char b = 104; /* ancii character h */
char c = 111; /* ancii character o */
char d = 97; /* ancii character a */
char e = 109; /* ancii character m */
char f = 105; /* ancii character i */
/* concaternate and transform decimal values to ancii chars using putchar */
//char command = putchar('a');putchar('b');putchar('c');putchar('d');putchar('e');putchar('f');
/* execute command using system() */
int system(char command);
system(command);
}
Currently we can't pipe stdin
input into a C program, e.g.
#include <stdio.h>
int main(void) {
char buf[1024];
while (fgets(buf, 1024, stdin) != NULL) {
puts(buf);
}
}
$ c file.c arg1 arg2 < /dev/urandom
$ ./file.c arg1 arg2 < /dev/urandom
Because we use stdin
for file input, I don't think we can also use it for program input as well. I'm not quite sure how to approach this... maybe we can only choose one or the other?
(btw, stdin
input without piping works just fine)
$ c file.c arg1 arg2
hello
hello
world
world
^C
just like this cli
sudo install -m 755 c /usr/local/bin/c
What is the license for this code? I'm interested in it, as I am the maintainer of awesome-c, and would prefer to have license terms to include.
I found a "c" file in the "~/bin" directory of an old computer.
I figured what it was for pretty soon, took me a long while to find the source of the file :)
When I use Shebang as described in README.md, I get an error.
This seems to be a compatibility issue with FishShell at the moment, as it works fine with Bash and Zsh.
I checked the source code of FishShell and I think the problem is here https://github.com/fish-shell/fish-shell/blob/master/src/exec.cpp#L177
Currently still looking for a solution
The sed command that removes/replaces the shebang appears to fail on OSX yosemite:
$ c << EOF
#include <stdio.h>
int main()
{
printf("Hello World!\n");
return 0;
}
EOF
sed: 1: "/tmp/c.ox3.stdin.c": command c expects \ followed by text
Hello World!
sed: 1: "/tmp/c.ox3.stdin.c": command c expects \ followed by text
I got your script working on freebsd with multiple parameters using this as my first line
#!/usr/bin/env -S c "-I/usr/local/include/ -g -L/usr/local/lib/mysql/ -lmysqlclient --"
might be worth mentioning in the readme
It would be great to be able to pipe into c
:
cat file.c | c
c < file.c
This would allow the use of tools that compile into c such as awib.
While caching is great in general, I found it to be hard if you are developing code in a header file. Is there a way to shut off the caching?
We need a command that doesn't require gnu-sed
to be installed with brew.
This should work on both GNU and BSD systems:
$ cat > file.c
#!/usr/bin/c blah blah blah
^D
$ sed -i.bak '1!b;s/^#!/\/\/#!/' file.c
$ cat file.c
//#!/usr/bin/c blah blah blah
However, I don't have access to a BSD system...
It works just fine on GNU. Can someone confirm that it works on BSD systems, too? Thanks.
Hi,
pretty useful tool. In order to make it work on MacOS I had to make this change:
- size="$(du --block-size=1024 -s "$tmproot" | tail -n1 | cut -f1)"
+ size="$(du -k -s "$tmproot" | tail -n1 | cut -f1)"
The reason is that du
on MacOS does not support --block-size
. I can try to fix the script to detect MacOS and use du -k
, but I noticed that this line has been edited in commit 91b66a0, so I don't know which is the best solution.
Thanks!
Giovanni
In my Emacs config, I have clang-format
do most of my formatting.
Adding a shebang: #!/usr/bin/c -Wall -Wextra -Werror
seems to mess with the formatter.
Perhaps it might be possible to put the shebang in a comment:
// #!/usr/bin/c -Wall -Wextra -Werror
and have c
look for it with regex: ^\/\/[\s]?#!.*?
BSD install
doesn't have the -D
option, which causes installation to fail on systems that use this version of install
.
My (probably incomplete) understanding is that this can be resolved by splitting this into a mkdir -p
followed by install
sans the -D
option, but I don't know if there is a better way that works with the bpkg 'install' field.
For reference, the relevant install
command: https://github.com/ryanmjacobs/c/blob/master/package.json#L6
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.