From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13701 invoked from network); 11 Jan 2009 22:13:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 11 Jan 2009 22:13:33 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 146 invoked from network); 11 Jan 2009 22:13:27 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Jan 2009 22:13:27 -0000 Received: (qmail 28541 invoked by alias); 11 Jan 2009 22:13:21 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26288 Received: (qmail 28532 invoked from network); 11 Jan 2009 22:13:21 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 11 Jan 2009 22:13:21 -0000 Received: from QMTA09.emeryville.ca.mail.comcast.net (qmta09.emeryville.ca.mail.comcast.net [76.96.30.96]) by bifrost.dotsrc.org (Postfix) with ESMTP id 615BF80271F0 for ; Sun, 11 Jan 2009 23:13:05 +0100 (CET) Received: from OMTA09.emeryville.ca.mail.comcast.net ([76.96.30.20]) by QMTA09.emeryville.ca.mail.comcast.net with comcast id 2E0c1b00G0S2fkCA9ND58c; Sun, 11 Jan 2009 22:13:05 +0000 Received: from [192.168.1.2] ([24.130.147.109]) by OMTA09.emeryville.ca.mail.comcast.net with comcast id 2NCy1b0082Mr27L8VND4F4; Sun, 11 Jan 2009 22:13:05 +0000 Mime-Version: 1.0 Message-Id: Date: Sun, 11 Jan 2009 14:12:40 -0800 To: zsh-workers@sunsite.dk From: Dave Yost Subject: embedding C code in a shell script Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Virus-Scanned: ClamAV 0.92.1/8852/Sun Jan 11 20:31:01 2009 on bifrost X-Virus-Status: Clean 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 #include #include 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