swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using Emacs on Win32 systems for Swarm development


From: Marcus G. Daniels
Subject: using Emacs on Win32 systems for Swarm development
Date: 28 Mar 1998 12:20:36 -0800

To expand on Glen's Emacs suggestions a bit, here's a configuration that
works for me.  First of all, there seem to be problems running
swarm.exe directly from Emacs as a shell.  Rather than investigate
this (and being lazy), I added an "-p" option to swarm.exe, that prints
out the environment variables that it would otherwise set before
running Bash.

First thing do is compile swarm.exe and save the output.

-----
$ cd /Swarm
$ gcc -g swarm.c -o swarm.exe
$ ./swarm -p > vars.bat
-----

Then, modify your .bash_login a bit to check for a the presence of
the vars.sh and if it exists to load it.

-----

#!/bin/sh

$CYGFS/H-i386-cygwin32/bin/cat $SWARMROOT/Readme
if [ -r $SWARMROOT/vars.sh ] ; then
  source $SWARMROOT/vars.sh
fi 
-----

Here's the relevant bit of my _emacs:

-----
(setenv "SWARMROOT" "/Swarm")
(setenv "CYGFS" "/Cygnus/B19")

(cd (getenv "SWARMROOT"))

(setq explicit-shell-file-name
      (concat (getenv "CYGFS")
              "/H-i386-cygwin32/bin/bash"))
(setq explicit-bash-args (list
                          "--rcfile"
                          (concat (getenv "SWARMROOT") "/.bash_login")
                          "-i"))

(setq win32-quote-process-args t)
(setq shell-command-switch "-c")
(setq binary-process-input t)
-----

Finally, here is the source code to swarm.exe that has the `-p' option.
With these things in place, it should be possible to start Emacs from
the program manager, do a M-x shell, and have things set up right
for Swarm hacking.

-----
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

#define VERSION "1.1"
#define SETENV(name,val) (print_flag ? printf ("export %s='%s'\n", name, val) : 
setenv (name, val, 1))

int print_flag = 0;

static const char *
convertToUnixPath (const char *dosPath)
{
  int len = strlen (dosPath);
  char *unixPath = malloc (len + 1);
  int i;
  
  if (unixPath == NULL)
    abort ();

  for (i = 0; i < len; i++)
    if (dosPath[i] == '\\')
      unixPath[i] = '/';
    else
      unixPath[i] = dosPath[i];
  unixPath[i] = '\0';
  return unixPath;
}

static const char *
copyValue (char *ptr, int keyLen)
{
  char *buf = ptr + keyLen + 1;
  char *ret;
  int bufLen = strlen (buf) - 1;
  
  if (buf[bufLen] == '\n')
    buf[bufLen] = '\0';
  
  ret = malloc (bufLen);
  if (ret == NULL)
    abort ();
  strcpy (ret, buf);
  return ret;
}

main (int argc, const char **argv)
{
  const char *exec_prefix = "\\H-i386-cygwin32\\lib\\gcc-lib\\";
  const char *share_tcl8 = "\\share\\tcl8.0\\";
  const char *share_gdbtcl = "/share/gdbtcl";
  const char *cyg_path_subdir = "\\H-i386-cygwin32\\bin";
  const char *cygRoot = NULL;
  const char *swarmRoot = NULL;
  const char *unixSwarmRoot;
  const char *cygUnixRoot;
  int cygRootLen;
  int nextarg = 1;

  if (argc > 1 && strcmp (argv[nextarg], "-p") == 0)
    {
      nextarg++;
      print_flag = 1;
    }

  {
    FILE *fp;
    char buf[80];
    char *ptr;
    const char *setKey = "SET ";
    int setKeyLen = strlen (setKey);
    const char *cygRootKey = "CYGROOT";
    int cygRootKeyLen = strlen (cygRootKey);
    const char *swarmRootKey = "SWARMROOT";
    int swarmRootKeyLen = strlen (swarmRootKey);
    const char *varsbat = "vars.bat";

    if (argc > nextarg)
      {
        const char *path = argv[nextarg];
        char buf[strlen (path) + 1 + strlen (varsbat) + 1];

        
        strcpy (buf, convertToUnixPath (path));
        strcat (buf, "/");
        strcat (buf, varsbat);
        
        if ((fp = fopen (buf, "r")) == NULL)
          abort ();
      }
    else
      if ((fp = fopen (varsbat, "r")) == NULL)
        abort ();
    
    while ((ptr = fgets (buf, sizeof (buf), fp)) != NULL)
      {
        if (strncmp (ptr, setKey, setKeyLen) == 0)
          {
            ptr += setKeyLen;
            if (strncmp (ptr, cygRootKey, cygRootKeyLen) == 0)
              cygRoot = copyValue (ptr, cygRootKeyLen);
            else if (strncmp (ptr, swarmRootKey, swarmRootKeyLen) == 0)
              swarmRoot = copyValue (ptr, swarmRootKeyLen);
          }
      }

  }
  if (cygRoot == NULL)
    abort ();
  if (swarmRoot == NULL)
    abort ();
    
  cygUnixRoot = convertToUnixPath (cygRoot);
  cygRootLen = strlen (cygRoot);
  if (cygUnixRoot[1] == ':')
    cygUnixRoot += 2;

  SETENV ("CYGFS", cygUnixRoot);
  SETENV ("CYGROOT", cygRoot);
  SETENV ("CYGREL", "B19");
  SETENV ("MAKE_MODE", "unix");

  {
    char buf[cygRootLen + strlen (exec_prefix) + 1];

    strcpy (buf, cygRoot);
    strcat (buf, exec_prefix);

    SETENV ("GCC_EXEC_PREFIX", buf);
  }
  
  {
    char buf[cygRootLen + strlen (share_tcl8) + 1];

    strcpy (buf, cygRoot);
    strcat (buf, share_tcl8);
    
    SETENV ("TCL_LIBRARY", buf);
  }

  {
    char buf[strlen (cygUnixRoot) + strlen (share_gdbtcl) + 1];
    
    strcpy (buf, cygUnixRoot);
    strcat (buf, share_gdbtcl);
    
    SETENV ("GDBTK_LIBRARY", buf);
  }
  unixSwarmRoot = convertToUnixPath (swarmRoot);
  if (unixSwarmRoot[1] == ':')
    unixSwarmRoot += 2;
  if (print_flag)
      printf ("PATH=%s:%s%s:$PATH\n",
              unixSwarmRoot,
              cygUnixRoot, 
              convertToUnixPath (cyg_path_subdir));
  else
    {
      const char *path = getenv ("PATH");
      char buf[strlen (swarmRoot) + 1 + cygRootLen + strlen (cyg_path_subdir) + 
strlen (path) + 2];
      
      strcpy (buf, swarmRoot);
      strcat (buf, ";");
      strcat (buf, cygRoot);
      strcat (buf, cyg_path_subdir);
      strcat (buf, ";");
      strcat (buf, path);
      
      SETENV ("PATH", buf);
    }
  SETENV ("HOME", unixSwarmRoot);
  SETENV ("SWARMROOT", unixSwarmRoot);
  SETENV ("SWARMSETUP", "SFI-NT");
  {
    const char *packages_subdir = "/packages";
    char pbuf[strlen (unixSwarmRoot) + strlen (packages_subdir) + 1];

    strcpy (pbuf, unixSwarmRoot);
    strcat (pbuf, packages_subdir);
    SETENV ("P", pbuf);

    {
      const char *blt8_subdir = "/blt8.0-unoff/library";
      char bltbuf[strlen (pbuf) + strlen (blt8_subdir) + 1];

      strcpy (bltbuf, pbuf);
      strcat (bltbuf, blt8_subdir);
      SETENV ("BLT_LIBRARY", bltbuf);
    }
  }
  {
    const char *swarm_subdir = "/swarm-" VERSION;
    char buf[strlen (unixSwarmRoot) + strlen (swarm_subdir) + 1];

    strcpy (buf, unixSwarmRoot);
    strcat (buf, swarm_subdir);
    SETENV ("SWARMHOME", buf);
  }
  SETENV ("PS1", "address@hidden $ ");
  if (!print_flag)
    {
      const char *bash = "bash";
      char buf[strlen (cygRoot) + strlen (cyg_path_subdir) + 1 + strlen (bash) 
+ 1];
      const char *ubuf;
      
      strcpy (buf, cygRoot);
      strcat (buf, cyg_path_subdir);
      strcat (buf, "\\");
      strcat (buf, "bash");
      ubuf = convertToUnixPath (buf);
      
      execlp (ubuf, bash, "--login", NULL); 
    }
}


                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]