Dear fellow lovers of Icon,

  Herewith I send a patch attached which does the following things to
the latest unicon CVS:

1. support for libtp.so, liburi.so and librt.so. All of the libraries
   go into refpath="../../lib" (from where icon{t,c} was started).
   This allows the generated program for the "hello icon" script
   to be around 5k rather than 170k.

2. support for autoexec'ing .icn scripts. In fact, this adds the
   following things:

   a) generation of temporary files under TmpDir rather than TargetDir
      TmpDir is generated using sprintf("/tmp/icon%05i/",getpid()).

   b) generation of the default icon binray script in
      sprintf("/tmp/icon%05i%s",basename)

   c) automatic removal of TmpDir by "icon" (the "icont" replacement)

   d) automatic removal of the binary script by "iconx" (enabled by
      "-r" option)

   Of course all of these things are only done when autoexec'ing
is enabled, which is, whenever the .icn file is interpreted by an
"icon" interpreter. The "icon" interpreter is a copy of "icont"
with all of the above things enabled.

  The patch was tested on Unix (Linux) and a.o., the following
test program:

#!/usr/local/src/unicon/bin/icon -s
procedure main()
write("hello icon")
end 

  Keep up the good work!

Caveat emptor
     The script thus run still requires "-x" to separate dependent
     modules and options. I am still considering whether this
     behaviour is good or not;-)

  Pjotr Kourzanov

P.S. I happen to use Debian, any objections if I take the latest CVS
     and Debianise it? 

Index: src/iconc/ccomp.c
===================================================================
RCS file: /cvsroot/unicon/unicon/src/iconc/ccomp.c,v
retrieving revision 1.3
diff -u -r1.3 ccomp.c
--- src/iconc/ccomp.c   24 Dec 2003 09:50:16 -0000      1.3
+++ src/iconc/ccomp.c   14 Dec 2004 16:07:37 -0000
@@ -212,6 +212,8 @@
    strcpy(s," -L");
    strcat(s, refpath);
 
+   strcat(s, " -luri ");
+
 #ifdef Messaging
    strcat(s, " -ltp ");
 #endif
@@ -285,6 +287,7 @@
    strcat(s, "X11.opt/opt");
 #endif                                         /* Graphics */
 
+
    if (system(buf) == 0)
       return EXIT_FAILURE;
 #endif                                         /* VMS */
Index: src/iconc/cmain.c
===================================================================
RCS file: /cvsroot/unicon/unicon/src/iconc/cmain.c,v
retrieving revision 1.3
diff -u -r1.3 cmain.c
--- src/iconc/cmain.c   15 Jan 2002 22:45:26 -0000      1.3
+++ src/iconc/cmain.c   14 Dec 2004 16:07:37 -0000
@@ -93,8 +93,8 @@
    if ((int)strlen(patchpath) > 18)
       refpath = patchpath+18;
 #endif                                 /* ExpTools */
-   else
-     refpath = relfile(argv[0], "/../");
+   else 
+     refpath = relfile(argv[0], "/../../lib/");
 
    /*
     * Process options.
@@ -243,11 +243,12 @@
       readdb(db_lst);
       addlib(salloc(makename(buf,SourceDir, db_lst, LibSuffix)));
       }
-   db_path = (char *)alloc((unsigned int)strlen(refpath) + strlen(db_name) + 
1);
+   db_path = (char *)alloc((unsigned int)strlen(refpath) + 3 + strlen(db_name) 
+ 1);
    strcpy(db_path, refpath);
+   strcat(db_path, "lib");
    strcat(db_path, db_name);
    readdb(db_path);
-   addlib(salloc(makename(buf,SourceDir, db_path, LibSuffix)));
+   addlib(salloc(makename(buf,SourceDir, db_path, ".so")));
 
    /*
     * Scan the rest of the command line for file name arguments.
Index: src/icont/link.c
===================================================================
RCS file: /cvsroot/unicon/unicon/src/icont/link.c,v
retrieving revision 1.5
diff -u -r1.5 link.c
--- src/icont/link.c    13 Jun 2002 22:39:38 -0000      1.5
+++ src/icont/link.c    14 Dec 2004 16:07:37 -0000
@@ -376,6 +376,21 @@
     *  of "$@" by some shells in the absence of any arguments.
     *  Thanks to the Unix-haters handbook for this trick.
     */
+   extern int autoexec;
+   if (autoexec)
+   sprintf(script, "%s\n%s%-72s\n%s\n\n%s\n\n%s\n%s\n%s\n%s%s%s\n\n%s\n",
+      "#!/bin/sh",
+      "IXBIN=", iconxloc,
+      "IXLCL=`echo $0 | sed 's=[^/]*$=iconx='`",
+      "args=\"-r $0 ${1+\"[EMAIL PROTECTED]"}\"",
+      "[ -n \"$ICONX\" ] && exec \"$ICONX\" $args",
+      "[ -x $IXLCL ] && exec $IXLCL $args",
+      "[ -x $IXBIN ] && exec $IXBIN $args",
+      "exec ",
+      "iconx",
+      " $args",
+      "[executable Icon binary follows]");
+   else
    sprintf(script, "%s\n%s%-72s\n%s\n\n%s\n%s\n%s\n%s%s%s\n\n%s\n",
       "#!/bin/sh",
       "IXBIN=", iconxloc,
Index: src/icont/tglobals.h
===================================================================
RCS file: /cvsroot/unicon/unicon/src/icont/tglobals.h,v
retrieving revision 1.8
diff -u -r1.8 tglobals.h
--- src/icont/tglobals.h        27 May 2003 17:24:57 -0000      1.8
+++ src/icont/tglobals.h        14 Dec 2004 16:07:37 -0000
@@ -98,3 +98,6 @@
 #endif                                 /* MSWindows && MSVC */
 
 Global int Zflag       Init(1);        /* -Z disables icode-gz compression */
+
+
+extern char TmpDir[];
Index: src/icont/tmain.c
===================================================================
RCS file: /cvsroot/unicon/unicon/src/icont/tmain.c,v
retrieving revision 1.12
diff -u -r1.12 tmain.c
--- src/icont/tmain.c   26 Jun 2004 03:31:23 -0000      1.12
+++ src/icont/tmain.c   14 Dec 2004 16:07:38 -0000
@@ -67,6 +67,7 @@
  * Prototypes.
  */
 
+int autoexec = 0;
 static void    execute (char *ofile,char *efile,char * *args);
 static void    usage (void);
 char *libpath (char *prog, char *envname);
@@ -425,6 +426,8 @@
  *  main program
  */
 
+char TmpDir[]="/tmp/iconXXXXX/";
+
 #if !THINK_C
    int main(int argc, char **argv)
 #else                           /* THINK_C */
@@ -442,6 +445,21 @@
    char ch;
    struct fileparts *fp;
 
+#define PROGNAME "icon"
+
+   autoexec = !strncmp(PROGNAME,
+                      &argv[0][strlen(argv[0])-sizeof(PROGNAME)+1],
+                      sizeof(PROGNAME));
+
+   TmpDir[0]='\0';
+   if (autoexec) {
+       snprintf(TmpDir,sizeof(TmpDir),"/tmp/icon%05i/",getpid());
+       if (mkdir(TmpDir,0700) == -1) {
+          fprintf(stderr,"can not make %s\n",TmpDir);
+          return 1;
+       }
+   }
+   
 #if WildCards
    FINDDATA_T fd;
    int j;
@@ -894,6 +912,8 @@
       exit(EXIT_SUCCESS);
       }
 
+   optind -= autoexec;
+
 #if MSDOS
    {
    if (ofile == NULL)  {                /* if no -o file, synthesize a name */
@@ -910,7 +930,10 @@
 #else                                   /* MSDOS */
 
    if (ofile == NULL)  {               /* if no -o file, synthesize a name */
-      ofile = salloc(makename(buf,TargetDir,lfiles[0],IcodeSuffix));
+      char Prefix[sizeof(TargetDir)];
+      strncpy(Prefix,TargetDir,sizeof(TargetDir));
+      Prefix[strlen(Prefix)-1]=0;
+      ofile = salloc(makename(buf,Prefix,lfiles[0],IcodeSuffix));
    } else {                            /* add extension in necessary */
       fp = fparse(ofile);
       if (*fp->ext == '\0' && *IcodeSuffix != '\0') /* if no ext given */
@@ -1027,8 +1050,13 @@
       report("No errors\n");
 #endif                                 /* ConsoleWindow */
 
+   if (autoexec && rmdir(TmpDir) == -1) {
+          fprintf(stderr,"can not remove %s\n",TmpDir);
+          return 1;
+   }
+
 #if !(MACINTOSH && MPW)
-   if (optind < argc)  {
+   if (optind < argc || autoexec) {
       report("Executing");
       execute (ofile, efile, argv+optind+1);
       }
Index: src/runtime/imain.r
===================================================================
RCS file: /cvsroot/unicon/unicon/src/runtime/imain.r,v
retrieving revision 1.11
diff -u -r1.11 imain.r
--- src/runtime/imain.r 13 Jun 2004 08:32:25 -0000      1.11
+++ src/runtime/imain.r 14 Dec 2004 16:07:39 -0000
@@ -931,6 +931,7 @@
 #ifdef TallyOpt
    extern int tallyopt;
 #endif                                 /* TallyOpt */
+   extern int do_remove;
 
    *ip = 0;                    /* number of arguments processed */
 
@@ -1038,6 +1039,7 @@
 #if MACINTOSH && MPW
    if (!NoOptions)
 #endif                                 /* MACINTOSH && MPW */
+   do_remove = 0;
    while ( argv[1] != 0 && *argv[1] == '-' ) {
       switch ( *(argv[1]+1) ) {
 
@@ -1050,6 +1052,9 @@
            break;
 #endif                                 /* TallyOpt */
 
+        case 'r':
+           do_remove = 1;
+           break;
       /*
        * Set stderr to new file if -e option is given.
        */
Index: src/runtime/init.r
===================================================================
RCS file: /cvsroot/unicon/unicon/src/runtime/init.r,v
retrieving revision 1.14
diff -u -r1.14 init.r
--- src/runtime/init.r  13 Jun 2004 08:26:21 -0000      1.14
+++ src/runtime/init.r  14 Dec 2004 16:07:40 -0000
@@ -227,6 +227,8 @@
 int tallyopt = 0;                      /* want tally results output? */
 #endif                                 /* TallyOpt */
 
+int do_remove = 0;                     /* remove script on exec? */
+
 #ifdef ExecImages
 int dumped = 0;                                /* non-zero if reloaded from 
dump */
 #endif                                 /* ExecImages */
@@ -1022,6 +1024,12 @@
    }
 #endif                                 /* HAVE_LIBZ */
 
+
+   if (do_remove) {
+     if (unlink(name)==-1) {
+       fprintf(stderr,"unlink %s failed\n",name);
+     }
+   }
    /*
     * Read the interpretable code and data into memory.
     */

Reply via email to