From: Dave Yost <Dave@Yost.com>
To: zsh-workers@sunsite.dk
Subject: embedding C code in a shell script
Date: Sun, 11 Jan 2009 14:12:40 -0800 [thread overview]
Message-ID: <pdy9883062408eec590187d09e8@[192.168.1.2]> (raw)
Hi.
It just occurred to me that with very little work, zsh could add this
feature using similar techniques to the what you can read about here:
http://yost.com/computers/compileAndGo/index.html#Future
So, for example, one could embed a C function to call realpath(3).
You could compile the code as a separate command, or you could do
more work and dynamically link it in and call it.
Dave
compiledFunction realpath() {
compiler = gcc
compileAndGo
#include <stdio.h>
#include <sys/param.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int ind;
int trouble = 0;
char resolvedPath[MAXPATHLEN];
// printf("Invoked as %s\n", argv[0]);
if (argc <= 1) {
fprintf(stderr, "\nUsage: realpath path ...\n\nExit 1 if any
paths fail.\n\n");
exit(2);
}
for (ind = 1; ind < argc; ++ind) {
if (realpath(argv[ind], resolvedPath) == NULL) {
fprintf(stderr, "%s: No such path: %s\n", argv[1], argv[ind]);
trouble = 1;
} else {
printf("%s\n", resolvedPath);
}
}
exit(trouble ? 1 : 0);
}
compileAndGo
next reply other threads:[~2009-01-11 22:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-11 22:12 Dave Yost [this message]
2009-01-12 4:49 ` Bart Schaefer
2009-01-12 5:28 ` Dave Yost
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='pdy9883062408eec590187d09e8@[192.168.1.2]' \
--to=dave@yost.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).