Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!mach1!torn!utnut!cs.utexas.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!darwin.sura.net!news-feed-1.peachnet.edu!umn.edu!csus.edu!sfsuvax1.sfsu.edu!vpcsc4
From: vpcsc4@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: A useful hack
Message-ID: <1993May15.232510.19372@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1993May15.231328.18776@csus.edu>
Date: Sat, 15 May 1993 23:25:10 GMT
Lines: 69

Here is a message from David Gurr at gurr@phase.mcg.edu . His
account is presently not set up to post so here goes.

I'm going to add some J code so that 

   freq% jhell fun: arg1 arg2 arg3 arg4 -> res1 res2 res3 res4

reads in the files named arg1 ... puts them in a J boxed array called arg,
reads in a J script in the file called fun: 
writes out the elements of the J boxed array called res to the files res1 ... .

This is part of my devious plan to get unixoids to use J without their informed consent.
-David


=======================================================================
/* Jhell, a linkJ like wrapper for calling J from unix shells */
#include "lj.h"
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <malloc.h>

main(argc,argv) int argc; char *argv[];{
A arg, tempstring, retcode;
 jinit();
/* read argv into a j vector of boxed char vectors */
 GA(arg,BOX,argc,1L,argc);
 for(i;i<argc;i++){
    GA(tempstring,CHAR,strlen(argv[i]),1L,strlen(argv[i]));
    MC(AV(tempstring),argv[i],strlen(argv[i])); 
    AV(arg)[i] = (A*)tempstring; }
/* assign the vector to the j variable argv */
 jset("argv", arg);

/* jx up a storm using the j variable argv to access the */
/* info from the unix shell command that called jhell.   */
/* use j to parse argv */







/* jx("   >>>>>>put your J code here<<<<<    ");          */
/* take your character vector arguments from the boxed    */
/* array argv and put an intger return code in the scalar */
/* returncode.                                            */









/* assign your return code to the j variable returncode */
/* returncode should be a scalar integer, but J may     */
/* represent an integer in many ways, so coerce to INT, */
/* Return a -1 if returncode is not set correctly.      */
 retcode = jx("0 { , returncode");
 switch(coerce1(&retcode,INT)){
   case INT:  exit(AV(retcode)[0]);
   default:   exit(-1); }
}


