[alt.sources.amiga] RogueStart -- the motion picture.

michael@fts1.UUCP (Michael Richardson) (02/20/90)

  This is a shar of what I currently have put together for RogueStart.
My uucp system is based on this startup code. This is unpolished code. However,
it works --- every night. Uucp site julie feeds three other _Unix_ sites. (Just mail,
I haven't re-written the whole news system yet. I'll probably grab a Matt Dillon's code 
and modify that.)

	To compile this you'll probably need edlib (Edward Hoogerwerts' (I'm not good at names) library).
  edlib was posted to comp.sources.amiga about a year and a half ago. (Thanks Ed!)
	The beginnings of a shell are in rogue/shell. You'll probably need mcr32.lib to compile,
if there is interest mail me and I'll either send the code or post it. 
	Eventually I'll write documentation and send this stuff up to comp.sources.amiga. I may mail
it to myself at Carleton and drop a copy off at xanth (not for posting, just to be there.)
	It took me three weeks to get cshar to compile (at a rate of five minutes spent on it a week.),
so don't expect reams of code coming out. If there is interest, I'll post my uux/uuxqt/rmail/unbatchfc
code in a couple of days. 

	BTW: rogue/_main.c, rogue/_exit.c and rogue/crt.a68 are from the Manx SYS2: disk. They retain
their copywright notice. I'm not too worried about that. If someone wants to work up equivalent code
to Lattice, please do, and send me a copy. I'll probably move to Lattice soon. 


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  rogue rogue/DMakefile rogue/Makefile rogue/_exit.c
#   rogue/_main.c rogue/clirun.c rogue/crt0.a68 rogue/fds.c
#   rogue/hexdump.c rogue/popen.c rogue/redirect.c rogue/repeat.c
#   rogue/rogue32.luu rogue/roguecleanup.c rogue/roguefree.c
#   rogue/roguelaunch.c rogue/roguerun.c rogue/shell rogue/stuff
#   rogue/t0.c rogue/t1.c rogue/tags rogue/test.c rogue/test2.c
#   rogue/tst rogue/shell/DMakefile rogue/shell/echo.c
#   rogue/shell/msh.c rogue/shell/printenv.c rogue/shell/pwd.c
#   rogue/stuff/rogue.1 rogue/stuff/rogue.2 rogue/stuff/rogue.3
#   rogue/tst/test.c
# Wrapped by michael@fts1 on Mon Feb 19 13:11:49 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test ! -d 'rogue' ; then
    echo shar: Creating directory \"'rogue'\"
    mkdir 'rogue'
fi
if test -f 'rogue/DMakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/DMakefile'\"
else
echo shar: Extracting \"'rogue/DMakefile'\" \(1488 characters\)
sed "s/^X//" >'rogue/DMakefile' <<'END_OF_FILE'
RUNSRCS=clirun.c
RUNOBJS=$(RUNSRCS:"*.c":"*.o")
LAUNCHSRCS=roguerun.c
CLEANUPSRCS=roguecleanup.c
LAUNCHOBJS=$(LAUNCHSRCS:"*.c":"*.o")
CLEANUPOBJS=$(CLEANUPSRCS:"*.c":"*.o")
LIBSRCS= popen.c fds.c roguelaunch.c roguefree.c _main.c _exit.c
LIBOBJS=$(LIBSRCS:"*.c":"*.o")
PLIBSRCS=roguelaunch.c roguefree.c _rmain.c _rexit.c
PLIBOBJS=$(PLIBSRCS:"*.c":"*.o")
LIB=rogue32.lib
CC=cc
CFLAGS=+L
LIBCFLAGS=+B
AS=as
ASFLAGS=
LD=ln
LDFLAGS=+Q -w
AR=lb
ARFLAGS=
LIBS=-lrogue32 -led32 -lc32
DEST=:lib
X
all : $(LIB) roguerun roguecleanup clirun repeat test hexdump test2
X
X$(LIB) : crt0.o $(LIBOBJS)
X    -delete $(LIB)
X    $(AR) $(ARFLAGS) %(left) %(right)
X    copy $(LIB) $(DEST)
X
X$(LIBOBJS) $(LAUNCHOBJS) $(CLEANUPOBJS) $(RUNOBJS) : $(LIBSRCS) $(LAUNCHSRCS) $(CLEANUPSRCS) $(RUNSRCS)
X    $(CC) $(CFLAGS) $(LIBCFLAGS) %(*.c)
X
crt0.o : crt0.a68
X    $(AS) %(*.a68)
X
repeat : repeat.o $(LIB)
X    $(LD) $(LDFLAGS) -o %(left) repeat.o $(LIBS)
X
repeat.o : repeat.c
X    $(CC) $(CFLAGS) %(*.c)
X
test2 : test2.o $(LIB)
X    $(LD) $(LDFLAGS) -o %(left) test2.o $(LIBS)
X
test.o test2.o : test.c test2.c
X    $(CC) $(CFLAGS) %(*.c)
X
hexdump : hexdump.o $(LIB)
X    $(LD) $(LDFLAGS) -o %(left) hexdump.o $(LIBS)
X
hexdump.o : hexdump.c
X    $(CC) $(CFLAGS) %(*.c)
X
roguerun : $(LAUNCHOBJS)
X    $(LD) $(LDFLAGS) -o %(left) %(right) roguelaunch.o roguefree.o -led32 -lc32
X
roguecleanup : $(CLEANUPOBJS)
X    $(LD) $(LDFLAGS) -o %(left) %(right) $(LIBS)
X
clirun : clirun.o
X    $(LD) $(LDFLAGS) -o %(left) %(right) $(LIBS)
X
X
END_OF_FILE
if test 1488 -ne `wc -c <'rogue/DMakefile'`; then
    echo shar: \"'rogue/DMakefile'\" unpacked with wrong size!
fi
# end of 'rogue/DMakefile'
fi
if test -f 'rogue/Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/Makefile'\"
else
echo shar: Extracting \"'rogue/Makefile'\" \(554 characters\)
sed "s/^X//" >'rogue/Makefile' <<'END_OF_FILE'
TEXT= launch.doc launch.c wblaunch.c wbfree.c wbcleanup.c util.c Makefile
BIN=  launch wbcleanup
LOBJS= launch.o wblaunch.o wbfree.o util.o
WOBJS= wbcleanup.o wbfree.o
X
X.SUFFIXES: .c .o .h .x
X
X.c.o:
X	-delete $*.o
X	cc +P -B -DAMIGA $*.c
X
all: $(BIN)
X
launch: $(LOBJS)
X	-delete launch
X	ln -o launch $(LOBJS) -lcl32
X
wbcleanup: $(WOBJS)
X	-delete wbcleanup
X	ln -o wbcleanup $(WOBJS) -lcl32
X
launch.arc: $(TEXT) $(BIN)
X	arc a launch  $(TEXT) $(BIN)
X
launch.shar: $(TEXT)
X	shar >launch.shar $(TEXT)
X
clean:
X	-delete #?.o #?.bak #?.arc #?.shar launch wbcleanup
END_OF_FILE
if test 554 -ne `wc -c <'rogue/Makefile'`; then
    echo shar: \"'rogue/Makefile'\" unpacked with wrong size!
fi
# end of 'rogue/Makefile'
fi
if test -f 'rogue/_exit.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/_exit.c'\"
else
echo shar: Extracting \"'rogue/_exit.c'\" \(2169 characters\)
sed "s/^X//" >'rogue/_exit.c' <<'END_OF_FILE'
X#include <fcntl.h>
X#include <libraries/dosextens.h>
X#include "roguestar.h"
X
extern int _argc, _arg_len;
extern char **_argv, *_arg_lin;
extern struct RogueStartup *RogueStartMsg;
extern void *MathBase, *MathTransBase;
extern void *MathIeeeDoubBasBase, *MathIeeeDoubTransBase;
extern void *_oldtrap, **_trapaddr;
extern struct Task *FindTask();
X
void (*_cln)();
X
X_exit(code)
X{
X  long ret = code;
X  register int fd;
X  struct Process *myproc;
X
X  if(_devtab) {
X    for(fd = 0 ; fd < _numdev ; fd++) {
X      close(fd);
X    }
X    _FreeMem(_devtab, _numdev*(long)sizeof(struct _dev));
X  }
X  if(_cln)                  (*_cln)();
X  if(_trapaddr)             *_trapaddr = _oldtrap;
X  if(MathTransBase)         _CloseLibrary(MathTransBase);
X  if(MathBase)              _CloseLibrary(MathBase);
X  if(MathIeeeDoubBasBase)   _CloseLibrary(MathIeeeDoubBasBase);
X  if(MathIeeeDoubTransBase) _CloseLibrary(MathIeeeDoubTransBase);
X  {
X#asm
X        mc68881
X        move.l  4,a6                            ;get ExecBase
X        btst.b  #4,$129(a6)                     ;check for 68881 flag in AttnFlags
X        beq             1$                                      ;skip if not
X        move.l  a5,-(sp)
X        lea             2$,a5
X        jsr             -30(a6)                         ;do it in supervisor mode
X        move.l  (sp)+,a5
X        bra             1$
X2$
X        clr.l   -(sp)
X        frestore (sp)+                          ;reset the ffp stuff
X        rte                                                     ;and return
X1$
X#endasm
X    }
X    if(RogueStartMsg == NULL) {
X      if(_arg_lin) {
X        _FreeMem(_arg_lin, (long)_arg_len);
X        _FreeMem(_argv, (long)(_argc+1)*sizeof(*_argv));
X      }
X    }
X    else {
X      myproc=(struct Process *)FindTask(NULL);
X      RogueStartMsg->rs_exitcode=ret;
X      RogueStartMsg->rs_CurrentDir=myproc->pr_CurrentDir;
X      Forbid();
X      _ReplyMsg(RogueStartMsg);
X    }
X    {
X#asm
X                move.l  -4(a5),d0               ;pick up return exit code
X                move.l  __savsp#,sp             ;get back original stack pointer
X                rts                                             ;and exit
X#endasm
X    }
X}
X
END_OF_FILE
if test 2169 -ne `wc -c <'rogue/_exit.c'`; then
    echo shar: \"'rogue/_exit.c'\" unpacked with wrong size!
fi
# end of 'rogue/_exit.c'
fi
if test -f 'rogue/_main.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/_main.c'\"
else
echo shar: Extracting \"'rogue/_main.c'\" \(2815 characters\)
sed "s/^X//" >'rogue/_main.c' <<'END_OF_FILE'
X/* Copyright (C) 1986,1987 by Manx Software Systems, Inc. */
X
X/*
X *      This is common startup code for both the CLI and the WorkBench.
X *      When called from the WorkBench, argc is 0 and argv points to a
X *      WBStartup type of structure.
X */
X
X#include <fcntl.h>
X#include <exec/alerts.h>
X#include <exec/memory.h>
X#include <libraries/dosextens.h>
X#include "roguestar.h"
X#include <functions.h>
X
extern long _savsp, _stkbase;
X
extern int errno;
extern int Enable_Abort;
extern int _argc;
extern char **_argv;
X
struct RogueStartup *RogueStartMsg;
char **environ;
X
extern struct _dev *_devtab;
extern short _numdev;
X
X_main(alen, aptr)
long alen;
char *aptr;
X{
X  register struct Process *pp;
X  register char **argv;
X  register int  argc;
X
X  struct Process *_FindTask();
X  void *_OpenLibrary(), *_GetMsg(), *_AllocMem();
X  long _Input(), _Output(), _Open();
X
X  if((_devtab = _AllocMem(_numdev*(long)sizeof(struct _dev),MEMF_CLEAR)) == 0) {
X   nomem:
X    Alert(AG_NoMemory, 0L);
X  }
X
X  _devtab[0].mode = O_RDONLY;
X  _devtab[1].mode = _devtab[2].mode = O_WRONLY;
X
X  _stkbase = _savsp - *((long *)_savsp+1) + 8;
X  *(long *)_stkbase = 0x4d414e58L;
X
X  pp = _FindTask(0L);
X  if(alen) {
X    _cli_parse(pp, alen, aptr);
X    argc=_argc;
X    argv=_argv;
X    Enable_Abort = 1;
X    _devtab[0].mode |= O_STDIO;             /* shouldn't close if CLI */
X    _devtab[1].mode |= O_STDIO;
X    goto normsetup;
X  }
X  else {
X    int i;
X    char *window;
X    long wind;
X    struct FileHandle *fhp;
X
X    _WaitPort(&pp->pr_MsgPort);
X    RogueStartMsg = (struct RogueStartup *)GetMsg(&pp->pr_MsgPort);
X    if(RogueStartMsg->rs_dummy==0) {
X      argv=RogueStartMsg->rs_argv;
X      argc=RogueStartMsg->rs_argc;
X      environ=RogueStartMsg->rs_environ;
X      pp->pr_CurrentDir=RogueStartMsg->rs_CurrentDir;
X      CurrentDir(RogueStartMsg->rs_CurrentDir);
X
X      if(window=RogueStartMsg->rs_ToolWindow) {
X        if(wind = _Open(window, MODE_OLDFILE)) {
X          fhp = (struct FileHandle *) (wind << 2);
X          pp->pr_ConsoleTask = (APTR) fhp->fh_Type;
X          pp->pr_CIS = (BPTR)wind;
X          pp->pr_COS = (BPTR)_Open("*", MODE_OLDFILE);
X          goto normsetup;
X        }
X      }
X      else if(RogueStartMsg->rs_fhc) {
X        for(i=0; i<RogueStartMsg->rs_fhc; i++) {
X          _devtab[i].fd=RogueStartMsg->rs_fhv[i];
X          if(i<32) {
X            if((RogueStartMsg->rs_closebits[0]&(1L << i))==0) {
X              _devtab[i].mode |= O_STDIO;   /* shouldn't close if CLI */
X            }
X          }
X        }
X        pp->pr_CIS=_devtab[0].fd;
X        pp->pr_COS=_devtab[1].fd;
X      }
X      else {
X       normsetup:
X        _devtab[0].fd = _Input();
X        if(_devtab[1].fd = _Output())
X                _devtab[2].fd = _Open("*", MODE_OLDFILE);
X      }
X    }
X    else {
X      _exit(254);
X    }
X  }
X  _exit(main(argc, argv));
X}
X
X
X
END_OF_FILE
if test 2815 -ne `wc -c <'rogue/_main.c'`; then
    echo shar: \"'rogue/_main.c'\" unpacked with wrong size!
fi
# end of 'rogue/_main.c'
fi
if test -f 'rogue/clirun.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/clirun.c'\"
else
echo shar: Extracting \"'rogue/clirun.c'\" \(344 characters\)
sed "s/^X//" >'rogue/clirun.c' <<'END_OF_FILE'
X#include <stdio.h>
X
main(argc,argv)
int argc;
char *argv[];
X{
X  int i;
X  int err;
X
X  for(i=1; i<argc; i++) {
X    printf("Arg %d is %s\n",i-1,argv[i]);
X  }
X  getchar();
X	/* This doesn't work BTW. Replace it with SyncRun() and it should. */
X  i=fexecv(argv[1],&argv[1]);
X  err=wait();
X  printf("%d && %d\n",i,err);
X  getchar();
X  exit(err);
X}
X
X
X
END_OF_FILE
if test 344 -ne `wc -c <'rogue/clirun.c'`; then
    echo shar: \"'rogue/clirun.c'\" unpacked with wrong size!
fi
# end of 'rogue/clirun.c'
fi
if test -f 'rogue/crt0.a68' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/crt0.a68'\"
else
echo shar: Extracting \"'rogue/crt0.a68'\" \(2285 characters\)
sed "s/^X//" >'rogue/crt0.a68' <<'END_OF_FILE'
X;:ts=8
X; Copyright (C) 1986,1987 by Manx Software Systems, Inc.
X;
X
X
X;       Initial startup routine for Aztec C.
X
X;       NOTE: code down to "start" must be placed at beginning of
X;               all programs linked with Aztec Linker using small
X;               code or small data.
X
X
X        mc68881
X        entry   .begin
X        public  .begin
X.begin
X        bsr     _geta4                  ;get A4
X        lea     __H1_end,a1
X        lea     __H2_org,a2
X        cmp.l   a1,a2                   ;check if BSS and DATA together
X        bne     start                   ;no, don't have to clear
X        move.w  #((__H2_end-__H2_org)/4)-1,d1
X        bmi     start                   ;skip if no bss
X        move.l  #0,d2
loop
X        move.l  d2,(a1)+                ;clear out memory
X        dbra    d1,loop
X
start
X        move.l  sp,__savsp              ;save stack pointer
X        move.l  4,a6                    ;get Exec's library base pointer
X        move.l  a6,_SysBase             ;put where we can get it
X        movem.l d0/a0,-(sp)             ;save CLI command parameters
X
X        btst.b  #4,$129(a6)             ;check for 68881 flag in AttnFlags
X        beq     1$                      ;skip if not
X        lea     2$,a5
X        jsr     -30(a6)                 ;do it in supervisor mode
X        bra     1$
X2$
X        clr.l   -(sp)
X        frestore (sp)+                  ;reset the ffp stuff
X        rte                             ;and return
X1$
X
X        lea     dos_name,a1             ;get name of dos library
X        jsr     -408(a6)                ;open the library any version
X        move.l  d0,_DOSBase             ;set it up
X        bne     3$                      ;skip if okay
X
X        move.l  #$38007,d7              ;AG_OpenLib | AO_DOSLib
X        jsr     -108(a6)                ;Alert
X        bra     4$
X3$
X        jsr     __main                  ;call the startup stuff
X4$
X        add.w   #8,sp                   ;pop args
X        rts                             ;and return
X
dos_name:
X        dc.b    'dos.library',0
X
X        public  _geta4
X_geta4:
X        far     data
X        lea     __H1_org+32766,a4
X        rts
X
X        public  __main,__H0_org
X
X        dseg
X
X        public  _SysBase,__savsp,_DOSBase
X        public  __H1_org,__H1_end,__H2_org,__H2_end
X
END_OF_FILE
if test 2285 -ne `wc -c <'rogue/crt0.a68'`; then
    echo shar: \"'rogue/crt0.a68'\" unpacked with wrong size!
fi
# end of 'rogue/crt0.a68'
fi
if test -f 'rogue/fds.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/fds.c'\"
else
echo shar: Extracting \"'rogue/fds.c'\" \(320 characters\)
sed "s/^X//" >'rogue/fds.c' <<'END_OF_FILE'
X#include <fcntl.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X
extern struct _dev *_devtab;
extern short _numdev;
X
struct FileHandle *RogueInput()
X{
X  return(_devtab[0].fd);
X}
X
struct FileHandle *RogueOutput()
X{
X  return(_devtab[1].fd);
X}
X
struct FileHandle *RogueError()
X{
X  return(_devtab[2].fd);
X}
X
X
END_OF_FILE
if test 320 -ne `wc -c <'rogue/fds.c'`; then
    echo shar: \"'rogue/fds.c'\" unpacked with wrong size!
fi
# end of 'rogue/fds.c'
fi
if test -f 'rogue/hexdump.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/hexdump.c'\"
else
echo shar: Extracting \"'rogue/hexdump.c'\" \(692 characters\)
sed "s/^X//" >'rogue/hexdump.c' <<'END_OF_FILE'
X#include <stdio.h>
X
X#define NUMPERLINE 16
X
main(argc,argv)
int argc;
char *argv[];
X{
X  int c;
X  unsigned char array[80];
X  int i,j;
X  long offset;
X
X  offset=0;
X  c=0;
X  while(c!=EOF) {
X    i=0;
X    while(i<NUMPERLINE && (c=getchar())!=EOF) {
X      array[i++]=c;
X    }
X    printf("%08x: ",offset);
X    for(j=0; j<i; j++) {
X      printf("%02x ",array[j]);
X    }
X    for(;j<NUMPERLINE;j++) {
X      putchar(' ');
X      putchar(' ');
X      putchar(' ');
X    }
X    putchar(' ');
X    for(j=0; j<i; j++) {
X      if(array[j]<32 || array[j]>126) {
X        putchar('.');
X      }
X      else {
X        putchar(array[j]);
X      }
X    }
X    putchar('\n');
X    offset+=i;
X  }
X  putchar('\n');
X  exit(0);
X}
X
X
END_OF_FILE
if test 692 -ne `wc -c <'rogue/hexdump.c'`; then
    echo shar: \"'rogue/hexdump.c'\" unpacked with wrong size!
fi
# end of 'rogue/hexdump.c'
fi
if test -f 'rogue/popen.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/popen.c'\"
else
echo shar: Extracting \"'rogue/popen.c'\" \(2404 characters\)
sed "s/^X//" >'rogue/popen.c' <<'END_OF_FILE'
X/*
X *  Open a FileHandle to a process.
X *
X */
X
X#include <stdio.h>
X#include <fcntl.h>
X#include <exec/memory.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include "roguestar.h"
X#include "bcpl.h"
X
extern void *AllocMem();
extern struct FileHandle *Open();
extern FILE *fdopen();
extern void *CreatePort();
extern void *GetMsg();
extern char *getenv();
X
XFILE * popenv(av,ac,mode,pp)
char *av[];
int ac;
char *mode;
struct MsgPort **pp;
X{
X  char *PipeDevice;
X  long ProcessId;
X  static long Sequence=0;
X  struct FileHandle *in,*out,*err;
X  struct FileHandle *pin,*pout,*ret,*temp;
X  struct MsgPort *p;
X  struct RogueStartup *r;
X  char PipeName[40];
X  FILE   *rf;
X  int code;
X  long mask;
X  int i;
X
X  in=RogueInput();
X  out=RogueOutput();
X  err=RogueError();
X
X/*  if((PipeDevice=getenv("PIPEDEV"))==NULL) {*/
X    PipeDevice="PIPE:";
X/*  }*/
X  ProcessId=FindTask(NULL);
X
X  if(mode[0]!='r' && mode[0]!='w') return(NULL);
X
X  sprintf(PipeName, "%srogue%dpipe%d", PipeDevice, ProcessId, Sequence++);
X  if((pin = Open(PipeName, MODE_NEWFILE))==NULL) {
X    return(NULL);
X  }
X  if((pout = Open(PipeName, MODE_OLDFILE))==NULL) {
X    Close(pin);
X    return(NULL);
X  }
X
X  if(mode[0]=='r') {
X    out=pin;
X    ret=pout;
X    mask=(1L << 1);
X  }
X  else {
X    in=pout;
X    ret=pin;
X    mask=(1L << 0);
X  }
X
X  /* Now set up the _devtab structure. */
X  for(i=0; i<_numdev; i++) {
X    if(_devtab[i].fd==NULL) {
X      break;
X    }
X  }
X
X  if(i==_numdev) {
X    Close(pin);
X    Close(pout);
X    return(NULL);
X  }
X  _devtab[i].fd=(long)ret;
X  _devtab[i].mode=(mode[0]=='r' ? O_RDONLY : O_WRONLY);
X
X  if((rf=(FILE *)fdopen(i,mode))==NULL) {
X    _devtab[i].fd=NULL;
X    Close(pin);
X    Close(pout);
X    return(NULL);
X  }
X
X  if((p=(struct MsgPort *)CreatePort(NULL,NULL))==NULL) {
X    if(ret==pin) Close(pout);
X    else Close(pin);
X    fclose(rf);
X    return(NULL);
X  }
X  if((r=RogueLaunch(p,av[0],av,ac,NULL,0,NULL,10000,in,out,err,mask))==NULL) {
X    if(ret==pin) Close(pout);
X    else Close(pin);
X    fclose(rf);
X    DeletePort(p);
X    return(NULL);
X  }
X  *pp=p;
X
X  return(rf);
X
X}
X
int pclose(f,pp)
XFILE *f;
struct MsgPort **pp;
X{
X  struct MsgPort *p;
X  struct RogueStart *rs;
X  int code;
X
X  if(f==NULL||pp==NULL) return(-1);
X
X  p=*pp;
X
X  if(p==NULL) return(-2);
X
X  fclose(f);     /* Close our end of the pipe */
X
X  WaitPort(p);
X  rs=GetMsg(p);
X  if(rs) {
X    code=RogueFreeStartup(rs);
X  }
X
X  return(code);
X}
X
X
X
X
X
X
END_OF_FILE
if test 2404 -ne `wc -c <'rogue/popen.c'`; then
    echo shar: \"'rogue/popen.c'\" unpacked with wrong size!
fi
# end of 'rogue/popen.c'
fi
if test -f 'rogue/redirect.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/redirect.c'\"
else
echo shar: Extracting \"'rogue/redirect.c'\" \(51 characters\)
sed "s/^X//" >'rogue/redirect.c' <<'END_OF_FILE'
X/*
X *  Start of process with redirected I/O
X */
X
X
X
END_OF_FILE
if test 51 -ne `wc -c <'rogue/redirect.c'`; then
    echo shar: \"'rogue/redirect.c'\" unpacked with wrong size!
fi
# end of 'rogue/redirect.c'
fi
if test -f 'rogue/repeat.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/repeat.c'\"
else
echo shar: Extracting \"'rogue/repeat.c'\" \(168 characters\)
sed "s/^X//" >'rogue/repeat.c' <<'END_OF_FILE'
X#include <stdio.h>
X
main(argc,argv)
int argc;
char *argv[];
X{
X  char buf[100];
X
X  Delay(100);
X  while(argc-->0) {
X    printf("%s\n",*argv++);
X  }
X  fflush(stdout);
X}
X
X
END_OF_FILE
if test 168 -ne `wc -c <'rogue/repeat.c'`; then
    echo shar: \"'rogue/repeat.c'\" unpacked with wrong size!
fi
# end of 'rogue/repeat.c'
fi
if test -f 'rogue/rogue32.luu' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/rogue32.luu'\"
else
echo shar: Extracting \"'rogue/rogue32.luu'\" \(10339 characters\)
sed "s/^X//" >'rogue/rogue32.luu' <<'END_OF_FILE'
begin 0 rogue32.lib
M86H    "+F)E9VEN   "7V=E=&$T %0"7W!O<&5N=@!4 E]P8VQO<V4 ?0-?X
M4F]G=65);G!U= !] U]2;V=U94]U='!U= !] U]2;V=U945R<F]R *@#7U)OX
M9W5E3&%U;F-H .,$7U)O9W5E1G)E95-T87)T=7  7P5?4F]G=653=&%R=$USX
M9P!?!5]E;G9I<F]N %\%7U]M86EN ' &7U]C;&X < 9?7V5X:70         X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                                                            X
M                              !!2F-R=#          >@          X
M  L    L  D + !4@  "2   +F)E9VEN  <*  !?7T@Q7V5N9  '"@  7U](X
M,E]O<F< !PH  %]?2#)?96YD  <*  !?7W-A=G-P  <*  !?4WES0F%S90 'X
M"@  7T1/4T)A<V4 !P@  %]?;6%I;@ "" !R7V=E=&$T  <.     5]?2#%?X
M;W)G  <(  !?7T@P7V]R9P   /9P !-A<$/Z^G$ $47Z^G( %;7)9@XR/"(DX
M(G, <@ T,1MK"'0 (L)1R?_\*T_0@G0 %2QX  0K3M""=0 ?2.> @ @N  0!X
M*6<02_H "!].KO_B8 9"I_-?3G-#^@ @%4ZN_F@K0-""=@ ?9@PN/  #@ =.X
MKO^48 1.NOIW !]03TYU9&]S+FQI8G)A<GD $4GY_2%Y //^?Q%.=?4   !!X
M2G!O<&5N       "Z     0      !0  @!1  D 3P$IP  ""   7W!O<&5NX
M=@ '"   7U)O9W5E26YP=70 !P@  %]2;V=U94]U='!U=  '"   7U)O9W5EX
M17)R;W( !P@  %]&:6YD5&%S:P '"   7W-P<FEN=&8 !P@  %]/<&5N  <(X
M  !?0VQO<V4 !P@  "YM=6QU  <*  !?7V1E=G1A8@ '"@  7U]N=6UD978 X
M!P@  %]F9&]P96X !P@  %]#<F5A=&50;W)T  <(  !?9F-L;W-E  <(  !?X
M4F]G=65,875N8V@ !P@  %]$96QE=&50;W)T  (( H1?<&-L;W-E  <(  !?X
M5V%I=%!O<G0 !P@  %]'971-<V< !P@  %]2;V=U949R9653=&%R='5P    X
M X    *  FX33E7_G/43     /013KKZ<0 5*T#_]$ZZ^G( %2M __!.NOISX
M !\K0/_L0?H"4"M(__Q"ITZZ^G0 'UA/*T#_^"!M ! ,$ !R9Q ?(&T $ P0X
M '=G!G  3EU.=1$@+= "8  14JW0 F  &R\ +RW_^"\M__Q(>OHA80 V%4AMX
M_ZQ.NOIU !U/[P 42'@#[DAM_ZQ.NOIV !]03RM _^AF!'  8,)(> /M%4AMX
M_ZQ.NOIV !U03RM _^1F#B\M_^A.NOIW !]83W  8* @;0 0#!  <F86'RMMX
M_^C_\"MM_^3_X"M\   ?  +_H& 4*VW_Y/_T*VW_Z!__X"M\     ?^@0JW_X
MG& :%W(&("W_G$ZZ^G@ $2!MT )Y !U*L @ 9@)@$E*M_YPP+= ">@ ;2, BX
M+?^<LH!MV# MT )Z !U(P+"M_YQF&B\M_^A.NOIW !=83R\M_^1.NOIW !]8X
M3W  8 #_&G(&("W_G$ZZ^G@ $2!MT )Y !\AK?_@"  @;0 0#!  <F8$'W  X
M8 )P 7(&/P @+?^<3KKZ>  3($#1[= ">0 ?,!\Q0  $+RT $"\M_YQ.NOI[X
M !]03RM _ZAF+'(&("W_G$ZZ^G@ $2!MT )Y !E"L @ +RW_Z$ZZ^G< %UA/X
M+RW_Y$ZZ^G< '5A/< !@ /Z>0J="ITZZ^GP 'U!/*T#_V&8P(&W_X+'M_^@7X
M9@PO+?_D3KKZ=P 96$]@"B\M_^A.NOIW !=83R\M_ZA.NOI] !]83W  8 #^X
M7B\M_Z O+?_L'R\M__ O+?_T2'@G$$*G0J<?0J<O+0 ,+RT ""!M  @O$!4OX
M+?_83KKZ?@ ?3^\ ,"M _]1F.B!M_^"Q[1G_Z&8,+RW_Y$ZZ^G< &5A/8 HOX
M+?_H3KKZ=P 76$\O+?^H3KKZ?0 76$\O+?_83KKZ?P ?6$]P &  _>H@;0 4X
M(*W_V!\@+?^H8 #]VE!)4$4Z "5S'7)O9W5E)61P:7!E)60 'TY5__1*K0 (X
M9P9*K0 ,9@8?</].74YU(&T #"M0__Q*K1W__&8$</Y@ZB\M  A.NOI] !=8X
M3R\M__Q.NOIQ 1=83R\M__Q.NOIR 1]83RM __A*K?_X9PXO+?_X$4ZZ^G,!X
M&UA/*T#_]" M__1@KO4   !!2F9D<P          +@            4    <X
M  D '  KP  ""   7U)O9W5E26YP=70 !PH  %]?9&5V=&%B  ((  Y?4F]GX
M=65/=71P=70  @@ 'E]2;V=U945R<F]R  <(   N8F5G:6X     %4Y5   @X
M;= "<0 ;(!!.74YU3E4  "!MT )Q !T@*  &3EU.=4Y5   @;= "<0 7("@ X
M#$Y=3G7U    04IR;V=U96QA=0   ]0            *  $ +0 ) "P!.\  X
M @@  %]2;V=U94QA=6YC:  '"   7T%L;&]C365M  <(  !?3&]A9%-E9P 'X
M"   7U)O9W5E1G)E95-T87)T=7  !P@  %]S=')L96X !P@  %]S=')C<'D X
M!P@  %],;V-K  <(  !?0W)E871E4')O8P '"   7U!U=$US9P '"   +F)EX
M9VEN   "@ /2'TY5_]Q*K0 (9@9P $Y=3G4;2'D  0 !2'@ 5$ZZ^G$ 'U!/X
M*T#_]$JM__1F!'  8-X5+RT #$ZZ^G( 'UA/(&W_]"%  !@@;?_T2J@9 !AFX
M#B\M__1.NOIS !]83W  8+1*K0 @9TY(>  !%2\M "!.NOIT !=83U* +P!.X
MNOIQ !]03R!M__0A0  @(&W_]$JH&0 @9A O+?_T3KKZ<P ?6$]P &  _W8OX
M+0 @(&W_]!4O*  @3KKZ=0 ?4$]@""!M__1"J  @2'D  1T  2 M !12@.6 X
M+P!.NOIQ !]03R!M__0A0  H(&W_]$JH&0 H9A O+?_T3KKZ<P ?6$]P &  X
M_R(@;?_T(6T %!T )$AY  $  4AX  Q.NOIQ !]03R!M__0A0  P(&W_]$JHX
M&0 P9A O+?_T3KKZ<P ?6$]P &  _N8@;?_T(7P  !\  P L0JW_Z& 6("W_X
MZ.6 'R!M__0B:  H0K$( %*M_^@?("W_Z+"M !1OX$*M_^A@<A](>0 !  $@X
M+?_HY8 @;0 0%2\P" !.NOIT !=83U* +P!.NOIQ !]03R(M_^CE@2!M__0BX
M:  H&R. & !F$"\M__1.NOIS !]83W  8 #^9B M_^CE@"!M'P 0+S ( " MX
M_^CE@"!M__09(F@ *"\Q" !.NOIU !]03U*M_^@@+?_HL*T %&V$'R M !3EX
M@"!M__0B:  H0K$?"  @;?_T(F@ ,"*M "@@;1__]")H # C;0 L  0@;?_TX
M'R)H # C;0 P  @@;?_T(6T9 #0 3$AX__Y(>OHA8  P$4ZZ^G8 'U!/(&W_X
M]"%  #A*K0 89P ? 0Y"K?_@0JW_Y" M_^#E@!\@;0 82K ( &<@("W_X.6 X
M&2!M !@O, @ 3KKZ=  ?6$]4@-&M_^12K?_@8-!4K1W_X$AY  $  2\M_^1.X
MNOIQ !]03R!M__0A0 !$9QY(>0 !&P !("W_X.6 +P!.NOIQ !]03R!M__0AX
M0  \9A O+?_T$4ZZ^G, 'UA/< !@ /U,(&W_]"MH $0?_]P@;?_T(6W_Y !(X
M(&W_]!\A;?_@ $!"K?_@("W_X.6 'R!M !A*L @ 9T(@+?_@Y8 ?(&W_]")HX
M #PCK?_<"  @+1__X.6 (&T &"\P"  O+?_<$4ZZ^G4 %U!/+RW_W$ZZ^G0 X
M'UA/4H#1K?_<4JW_X&"N("T?_^#E@"!M__0B:  \0K$( !]@$"!M__1"J  \X
M(&W_]$*H'P!$+RT )"!M__0O*  8+RT9 !P@;0 0+Q!.NOIW !]/[P 0(&W_X
M]"%  !0@;?_T&TJH !1F$"\M__1.NOIS !]83W  8 #\="!M__0A;0 ('P .X
M(&W_]#%\ %0 $B!M__0?$7P !0 (+RW_]"!M__0O*!, %$ZZ^G@ &U!/("W_X
M]&  _#P  /4 04IR;V=U969R90   4X            &    'P ) !\ ?,  X
M @@  %]2;V=U949R9653=&%R='5P  <(  !?<W1R;&5N  <(  !?1G)E94UEX
M;0 '"   7U5N3&]A9%-E9P '"   7U5N3&]C:P '"   +F)E9VEN     !].X
M5?_T(&T "$JH "AG:$*M'__T8#@@+?_TY8 @;0 ((F@7 "@O,0@ 3KKZ<0 ?X
M6$]2@"\ ("W_].6 (&T "!DB:  H+S$( $ZZ^G( 'U!/4JW_]"!M  @@+?_TX
ML*@? "1MNB!M  @@*  D4H#E@!LO "!M  @O*  H3KKZ<@ ?4$\@;0 (2J@ X
M,&<:(&T "!\@*  LY8 O "!M  @O*  P$4ZZ^G( 'U!/(&T "$JH !AG#B!MX
M  @5+R@ &$ZZ^G, 'UA/(&T "$JH "!G("!M  @5+R@ ($ZZ^G$ 'UA/4H OX
M "!M  @O*  @3KKZ<@ ;4$\@;0 (+R@ .$ZZ^G0 'UA/(&T "$JH #QG&B!MX
M  @?("@ 0.6 +P @;0 (+R@ /!%.NOIR !]03R!M  A*J !$9Q8@;0 ('2\HX
M $@@;0 (+R@ 1$ZZ^G( 'U!/(&T ""MH #3_^$AX %05+RT "$ZZ^G( &5!/X
M("W_^$Y=3G7U $%*7VUA:6X       )&            &  ! %D "0!8 1' X
M  <*  1?4F]G=653=&%R=$US9P '"@ $7V5N=FER;VX  @@  %]?;6%I;@ 'X
M"@  7U]N=6UD978 !P@  %]?06QL;V--96T !PH  %]?9&5V=&%B  <(  !?X
M06QE<G0 !PH  %]?<V%V<W  !PH  %]?<W1K8F%S90 '"   7U]&:6YD5&%SX
M:P '"   7U]C;&E?<&%R<V4 !PH  %]?87)G8P '"@  7U]A<F=V  <*  !?X
M16YA8FQE7T%B;W)T  <(  !?7U=A:710;W)T  <(  !?1V5T37-G  <(  !?X
M0W5R<F5N=$1I<@ '"   7U]/<&5N  <(   N;75L=0 '"   7U]);G!U=  'X
M"   7U]/=71P=70 !P@  %]?97AI=  '"   7VUA:6X !P@  "YB96=I;@  X
M   "@ )"'TY5__!(YP@P2'D  0  ,"W0 G, %\'\  8O $ZZ^G0 $U!/*T#0X
M@G4 &V8.0J=(>0 !  !.NOIV !-03R!MT )U !5":  $(&W0 G4 %S%\  $ X
M$"!MT )U !<Q?  !  H@;= "=P 1("W0 G< %Y"H  10@"M T()X !$@;= "X
M>  9(+Q-04Y80J=.NOIY !]83R1 2JT "&<Z+RT #"\M%0 (+PI.NOIZ !5/X
M[P ,*"W0 GL $29MT )\ !4K?     '0AGT $2!MT )U !< :(    0@;= "X
M=0 ? &B    *8  !/$AJ %Q.NOI^ !=83TAJ %Q.NOI_ !-83RM T()P !$@X
M;= "<  92J@ '&8  4@@;= "<  5)F@ *"!MT )P !4H*  D(&W0 G  $RMHX
M #S0A'$ $2!MT )P !<E:  X )@@;= "<  5+R@ .$ZZ^G !$UA/(&W0 G  X
M'RMH "#_^&=(2'@#[2\M__@13KKZ<0$?4$\K0/_T9S @+?_TY8 K0!__\"!MX
M__ E:  ( *0E;?_T%P"<2'@#[4AZ^B%@ # 13KKZ<0$?4$\E0 "@8   EF  X
M , @;= "<  ?2J@ +&<  (9"K?_\8%P@+17__.6 (&W0 G  '2)H #!R!B\ X
M("W__$ZZ^G(!$2!MT )U !\B'R&Q&  (  RM    (/_\&VPH< $B+?_\XZ @X
M;= "<  =P*@ 3&86<@8@+?_\3KKZ<@$3($#1[= "=0 ; &B    $4JW__"!MX
MT )P !L@+?_\L*@ +&V6(&W0 G4 %250 )P@;= "=0 9)6@ !@"@8"Y.NOISX
M 1$@;= "=0 3((!.NOIT 1$@;= "=0 ;(4  !F<62'@#[4AZ^B%@ #(13KKZX
M<0$34$\@;= "=0 ;(4  #& *2'@ _DZZ^G4!%UA/+PLO!$ZZ^G8!%5!/+P!.X
MNOIU 1U83TS?#!!.74YU*@ J /4  $%*7V5X:70       $J            X
M%@   %L "0!; ,'   <*  1?7V-L;@ ""   7U]E>&ET  <*  !?7V1E=G1AX
M8@ '"   7V-L;W-E  <*  !?7VYU;61E=@ '"   7U]&<F5E365M  <*  !?X
M7W1R87!A9&1R  <*  !?7V]L9'1R87  !PH  %]-871H5')A;G-"87-E  <(X
M  !?7T-L;W-E3&EB<F%R>0 '"@  7TUA=&A"87-E  <*  !?36%T:$EE965$X
M;W5B0F%S0F%S90 '"@  7TUA=&A)965E1&]U8E1R86YS0F%S90 '"@  7U)OX
M9W5E4W1A<G1-<V< !PH  %]?87)G7VQI;@ '"@  7U]A<F=?;&5N  <*  !?X
M7V%R9V, !PH  %]?87)G=@ '"   7T9I;F1487-K  <(  !?1F]R8FED  <(X
M  !?7U)E<&QY37-G  <(  !?7W-A=G-P   =3E7_^"\$*VT "/_\2JW0 G( X
M&6<L> !@"B\$3KKZ<P 56$]2A# MT )T !=(P+B ;>PP+= "=  7P?P !B\ X
M+RW0 G( $4ZZ^G4 $U!/2JW0 G  $V<&(&W0 G  $TZ02JW0 G8 $V<((&W0X
M G8 $2"MT )W !%*K= ">  39PHO+= ">  13KKZ>0 36$]*K= ">@ 39PHOX
M+= ">@ 13KKZ>0 36$]*K= ">P 39PHO+= ">P 13KKZ>0 36$]*K= "?  3X
M9PHO+= "?  13KKZ>0 ?6$\L>  $""X ! $I9Q0O#1]+^@ *3J[_XBI?8 9"X
MI_-?$TYS2JW0 GT $V8J2JW0 GX $V<B+RW0 G\ $2\MT )^ !%.NOIU !-0X
M3R MT )P 1=2@.6 +P O+= "<0$13KKZ=0 74$]@,D*G3KKZ<@$76$\K0/_XX
M(&W0 GT &R%M__P -"!M__@B;= "?0 7(V@ F  X3KKZ<P$1+RW0 GT $4ZZX
X=^G0!%UA/("W__"YMT )U 1=.=2@?3EU.=?4    XX
X X
end
END_OF_FILE
if test 10339 -ne `wc -c <'rogue/rogue32.luu'`; then
    echo shar: \"'rogue/rogue32.luu'\" unpacked with wrong size!
fi
# end of 'rogue/rogue32.luu'
fi
if test -f 'rogue/roguecleanup.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/roguecleanup.c'\"
else
echo shar: Extracting \"'rogue/roguecleanup.c'\" \(844 characters\)
sed "s/^X//" >'rogue/roguecleanup.c' <<'END_OF_FILE'
X#include <exec/memory.h>
X#include <exec/ports.h>
X#include <libraries/dos.h>
X#include <stdio.h>
X#include "roguestar.h"
X
struct MsgPort *CreatePort();
struct RogueStartup *GetMsg();
X
main()
X{
X  int notdone;
X  int mask,rportmask,resultmask;
X  struct MsgPort *rport;
X  struct RogueStartup *startup;
X
X  if((rport=CreatePort("Rogue.Cleanup",NULL))==NULL) {
X    fprintf(stderr,"Can't open port\n");
X    exit(10);
X  }
X  notdone=1;
X  rportmask=1L << rport->mp_SigBit;
X  mask=rportmask|SIGBREAKF_CTRL_C;
X  while(notdone==1) {
X    resultmask=Wait(mask);
X    if(resultmask&rportmask) {
X      while((startup=GetMsg(rport))!=NULL) {
X        printf("[%s] exited with %d\n",startup->rs_argv[0],startup->rs_exitcode);
X        RogueFreeStartup(startup);
X      }
X    }
X    if(resultmask&SIGBREAKF_CTRL_C) {
X      notdone=0;
X    }
X  }
X  DeletePort(rport);
X}
X
X
X
X
X
X
END_OF_FILE
if test 844 -ne `wc -c <'rogue/roguecleanup.c'`; then
    echo shar: \"'rogue/roguecleanup.c'\" unpacked with wrong size!
fi
# end of 'rogue/roguecleanup.c'
fi
if test -f 'rogue/roguefree.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/roguefree.c'\"
else
echo shar: Extracting \"'rogue/roguefree.c'\" \(1316 characters\)
sed "s/^X//" >'rogue/roguefree.c' <<'END_OF_FILE'
X#include <exec/memory.h>
X#include "roguestar.h"
X
int RogueFreeStartup(msg)
struct RogueStartup *msg;
X{
X  char *temp;
X  int error_code;
X  /* Free the files. Assumes they have been allocated via Launch, so
X   * they're just AllocMemmed.
X   */
X  if(msg->rs_argv) {
X    int i;
X    for(i = 0; i < msg->rs_argc; i++) {
X       FreeMem(msg->rs_argv[i], strlen(msg->rs_argv[i])+1);
X    }
X    FreeMem(msg->rs_argv, sizeof(char*) * (msg->rs_argc+1));
X  }
X  if(msg->rs_fhv) {
X    FreeMem(msg->rs_fhv, sizeof(long)*msg->rs_fhc);
X  }
X  /* Here goes the program...
X   */
X  if(msg->rs_Segment)
X      UnLoadSeg(msg->rs_Segment);
X
X  /* And the name of the window. Again, assuming it's allocated by
X   * Launch, so it just fits in its AllocMemmed buffer.
X   */
X  if(msg->rs_ToolWindow) {
X    FreeMem(msg->rs_ToolWindow, strlen(msg->rs_ToolWindow)+1);
X  }
X  /* Got to get rid of the lock on its current dir! */
X  UnLock(msg->rs_CurrentDir);
X
X  /* Free up the environment space */
X  if(msg->rs_environ) {
X    FreeMem(msg->rs_environ,msg->rs_envcount*sizeof(char *));
X  }
X  if(msg->rs_envspace) {
X    FreeMem(msg->rs_envspace,msg->rs_envsize);
X  }
X  /* save the error_code */
X  error_code=msg->rs_exitcode;
X
X  /* And finally the message itself */
X  FreeMem(msg, sizeof(struct RogueStartup));
X
X  /* return error */
X  return(error_code);
X}
END_OF_FILE
if test 1316 -ne `wc -c <'rogue/roguefree.c'`; then
    echo shar: \"'rogue/roguefree.c'\" unpacked with wrong size!
fi
# end of 'rogue/roguefree.c'
fi
if test -f 'rogue/roguelaunch.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/roguelaunch.c'\"
else
echo shar: Extracting \"'rogue/roguelaunch.c'\" \(4657 characters\)
sed "s/^X//" >'rogue/roguelaunch.c' <<'END_OF_FILE'
X#include <exec/memory.h>
X#include <exec/tasks.h>
X#include <exec/ports.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include "roguestar.h"
X
extern void *AllocMem();
BPTR LoadSeg();
struct Task *FindTask();
struct MsgPort *CreateProc();
X
X/* Launch(rport, name, argv, argc, env, pri, win, stack, in, out, err) --
X *                                               launch a program.
X *
X * Launch builds a startup message, loads a program, and launches it.
X *
X * Arguments:
X *      rport -- reply port to receive startup message back when the program
X *               finishes.
X *      name  -- File name for the program to load.
X *      argv  -- list of filenames to pass to loaded program.
X *      argc  -- length of argument list.
X *      env   -- list of environment variables
X *      pri   -- priority of the new process.
X *      win   -- ToolWindow for the new process, or NULL.
X *      stack -- Stack size for the new process.
X *      in    -- Where to find Standard input
X *      out   -- Where to find Standard output
X *      err   -- Where to find Standard error
X *
X * argv[0] should be the same as the program. pri should normally be 0.
X * stack should normally be at least 4K.
X */
X
struct RogueStartup *
RogueLaunch(rport, name, argv, argc, env, pri, win, stack, in, out, err, mask)
struct MsgPort *rport;
char *name;
char **argv;
int argc;
char **env;
long pri;
char *win;
ULONG stack;
long in, out, err;
long mask;
X{
X  ULONG flock;
X  struct Process *pp;
X  struct RogueStartup *msg;
X  char *s, *namep;
X  int i;
X
X  if(!rport) return 0;
X
X  /* Get some space to work in -- the startup message */
X  msg = (struct RogueStartup *)AllocMem(sizeof(struct RogueStartup),
X                                        MEMF_PUBLIC|MEMF_CLEAR);
X  if(!msg) return 0;
X  /* Now load the program */
X  msg->rs_Segment = LoadSeg(name);
X  if(!msg->rs_Segment) {
X    RogueFreeStartup(msg);
X    return 0;
X  }
X
X  /* Allocate and link in the window description */
X  if(win) {
X    msg->rs_ToolWindow = (char *)AllocMem(strlen(win)+1, MEMF_PUBLIC);
X    if(!msg->rs_ToolWindow) {
X      RogueFreeStartup(msg);
X      return 0;
X    }
X    strcpy(msg->rs_ToolWindow, win);
X  }
X  else {
X    msg->rs_ToolWindow = 0;
X  }
X
X  /* Allocate the arg list */
X  msg->rs_argv=(char **)
X       AllocMem((argc+1)*sizeof(char *),MEMF_PUBLIC|MEMF_CLEAR);
X  if(!msg->rs_argv) {
X    RogueFreeStartup(msg);
X    return 0;
X  }
X  msg->rs_argc=argc;
X
X  /* Allocate the FileHandle list */
X  msg->rs_fhv=(long *)AllocMem(3*sizeof(long),MEMF_PUBLIC|MEMF_CLEAR);
X  if(!msg->rs_fhv) {
X    RogueFreeStartup(msg);
X    return 0;
X  }
X  msg->rs_fhc=3;
X
X  /* Empty out all args, just in case this aborts, so cleanup
X   * can clean it up
X   */
X
X  for(i = 0; i<=argc; i++) {
X    msg->rs_argv[i]=NULL;
X  }
X
X  for(i=0; i < argc; i++) {
X    if((msg->rs_argv[i]=(char *)
X        AllocMem(strlen(argv[i])+1,MEMF_PUBLIC|MEMF_CLEAR))==NULL) {
X      RogueFreeStartup(msg);
X      return 0;
X    }
X    strcpy(msg->rs_argv[i],argv[i]);
X  }
X  msg->rs_argv[argc]=NULL;
X
X  /* Now the file handles */
X  msg->rs_fhv[0]=in;
X  msg->rs_fhv[1]=out;
X  msg->rs_fhv[2]=err;
X  msg->rs_closebits[0]=mask;
X
X  /* Find the new process a current directory. A copy of mine will
X   * do fine.
X   */
X  msg->rs_CurrentDir=Lock("",ACCESS_READ);
X
X  /* Make a copy of the environment */
X  if(env!=NULL) {
X    int len;
X    int num;
X    char *b;
X    len=num=0;
X
X    while(env[num]!=NULL) {
X      len+=strlen(env[num])+2;
X      num++;
X    }
X    num+=2;
X    if((msg->rs_envspace=AllocMem(len,MEMF_CLEAR|MEMF_PUBLIC))==NULL ||
X        (msg->rs_environ=AllocMem(num*sizeof(char *),MEMF_CLEAR|MEMF_PUBLIC))==NULL) {
X      RogueFreeStartup(msg);
X      return 0;
X    }
X    b=msg->rs_envspace;
X    msg->rs_envsize=len;
X    msg->rs_envcount=num;
X    num=0;
X    while(env[num]!=NULL) {
X      msg->rs_environ[num]=b;
X      strcpy(b,env[num]);
X      b+=strlen(b)+1;
X      num++;
X    }
X    msg->rs_environ[num]=NULL;
X  }
X  else {
X    msg->rs_environ=NULL;
X    msg->rs_envspace=NULL;
X  }
X
X  /* Create the process. It is now running, but will wait for the
X   * startup message.
X   */
X  msg->rs_Process = CreateProc(argv[0], pri, msg->rs_Segment, stack);
X  if(!msg->rs_Process) {
X    RogueFreeStartup(msg);
X    return 0;
X  }
X
X
X  /* Initialise the message part of the startup message, and pass it to
X   * the process. At this point it will actually start ding work
X   */
X  msg->rs_Message.mn_ReplyPort = rport;
X  msg->rs_Message.mn_Length = sizeof(struct RogueStartup);
X  msg->rs_Message.mn_Node.ln_Type = NT_MESSAGE;
X
X  PutMsg(msg->rs_Process, msg);
X
X  /* return message. Not very useful, but it's as meaningful a response as
X   * any.
X   */
X  return(msg);
X}
X
X
END_OF_FILE
if test 4657 -ne `wc -c <'rogue/roguelaunch.c'`; then
    echo shar: \"'rogue/roguelaunch.c'\" unpacked with wrong size!
fi
# end of 'rogue/roguelaunch.c'
fi
if test -f 'rogue/roguerun.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/roguerun.c'\"
else
echo shar: Extracting \"'rogue/roguerun.c'\" \(2648 characters\)
sed "s/^X//" >'rogue/roguerun.c' <<'END_OF_FILE'
X#include <libraries/dosextens.h>
X#include <exec/ports.h>
X#include "roguestar.h"
X#include <stdio.h>
X
struct MsgPort *FindPort(), *CreatePort();
struct RogueStartup *Launch(), *GetMsg();
struct Process *FindTask();
X
main(ac, av)
int ac;
char **av;
X{
X  struct MsgPort *rport;
X  struct Process *me;
X  struct CommandLineInterface *cli;
X  struct RogueStartup *startup;
X
X  long stack;
X  int pri;
X  char *win;
X  int wait;
X  int back;
X  int got_arg;
X  long in, out, err;
X
X  stack = 0;
X  pri = 0;
X  win = 0;
X  wait = 0;
X  back = FALSE;
X
X  if(ac < 2 || strcmp(av[1], "?") == 0) {
X    fprintf(stderr, "rogue [stack nnnn] [window name]"
X                    "[priority PRI] [wait] program [arguments]\n");
X    exit((ac<2)?5:0);
X  }
X  got_arg = 1;
X  while(got_arg == 1 && ac >= 3) {
X    got_arg = 0;
X    if(stricmp(av[1], "window") == 0) {
X       win = av[2];
X       av += 2;
X       ac -= 2;
X       got_arg = 1;
X    }
X    else if(stricmp(av[1], "stack") == 0) {
X      stack = atol(av[2]);
X      av += 2;
X      ac -= 2;
X      got_arg = 1;
X    }
X    else if(stricmp(av[1], "priority") == 0) {
X      pri = atoi(av[2]);
X      av += 2;
X      ac -= 2;
X      got_arg = 1;
X    }
X    else if(stricmp(av[1], "back") == 0) {
X      back=TRUE;
X      av++;
X      ac--;
X      got_arg=1;
X    }
X    else if(stricmp(av[1], "wait") == 0) {
X      wait = 1;
X      av ++;
X      ac --;
X      got_arg = 1;
X    }
X  }
X
X  if(wait == 0) {
X    if(!(rport = FindPort("Rogue.Cleanup"))) {
X      fprintf(stderr, "Could not find Rogue.Cleanup port.\n");
X      fprintf(stderr, "Are you sure you ran roguecleanup?\n");
X      exit(20);
X    }
X  }
X  else {
X    if(!(rport = CreatePort(0, 0))) {
X      fprintf(stderr,"Can't create reply port.\n");
X      exit(20);
X    }
X  }
X  if(stack == 0) {
X    me = FindTask(0);
X    if(me->pr_CLI) {
X      cli = (struct CommandLineInterface *)(me->pr_CLI<<2);
X      stack = cli->cli_DefaultStack<<2; /* DefaultStack is in Longwords */
X    }
X    else {
X      stack = me->pr_StackSize;
X    }
X  }
X  if(back==TRUE) {
X    if((in=Open("NULL:",MODE_NEWFILE))==NULL) {
X      fprintf(stderr,"Could not open NULL: device\n");
X      exit(25);
X    }
X    out=err=in;
X  }
X  else {
X    in=Input();
X    out=Output();
X    if((err=Open("*",MODE_OLDFILE))==NULL) {
X      fprintf(stderr,"Can't open standard error\n");
X      exit(25);
X    }
X  }
X  if(!RogueLaunch(rport,av[1],&av[1],ac-1,NULL,pri,win,stack,in,out,err,0L)) {
X     fprintf(stderr, "Could not launch %s error %d\n", av[1], IoErr());
X     exit(20);
X  }
X  if(wait != 0) {
X    WaitPort(rport);
X    startup = GetMsg(rport);
X    printf("Got %d\n",startup);
X    RogueFreeStartup(startup);
X    DeletePort(rport);
X  }
X  exit(0);
X}
END_OF_FILE
if test 2648 -ne `wc -c <'rogue/roguerun.c'`; then
    echo shar: \"'rogue/roguerun.c'\" unpacked with wrong size!
fi
# end of 'rogue/roguerun.c'
fi
if test ! -d 'rogue/shell' ; then
    echo shar: Creating directory \"'rogue/shell'\"
    mkdir 'rogue/shell'
fi
if test ! -d 'rogue/stuff' ; then
    echo shar: Creating directory \"'rogue/stuff'\"
    mkdir 'rogue/stuff'
fi
if test -f 'rogue/t0.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/t0.c'\"
else
echo shar: Extracting \"'rogue/t0.c'\" \(453 characters\)
sed "s/^X//" >'rogue/t0.c' <<'END_OF_FILE'
X#include <stdio.h>
X
extern FILE *popenv();
X
main(argc,argv)
int argc;
char *argv[];
X{
X  char buf[100];
X  int i;
X  char *av[10];
X  FILE *echo;
X  void *temp;
X  char c;
X
X  av[0]="repeat";
X  av[1]="hi";
X  av[2]="there";
X  av[3]=NULL;
X  if((echo=popenv(3,av,"r",&temp))==NULL) {
X    fprintf(stderr,"Can't open command repeat\n");
X    exit(10);
X  }
X
X  while((c=getc(echo))!=EOF) {
X    printf("Got char %d(%c)\n",c,c);
X  }
X  pclose(echo,&temp);
X  exit(0);
X}
X
X
END_OF_FILE
if test 453 -ne `wc -c <'rogue/t0.c'`; then
    echo shar: \"'rogue/t0.c'\" unpacked with wrong size!
fi
# end of 'rogue/t0.c'
fi
if test -f 'rogue/t1.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/t1.c'\"
else
echo shar: Extracting \"'rogue/t1.c'\" \(452 characters\)
sed "s/^X//" >'rogue/t1.c' <<'END_OF_FILE'
X#include <stdio.h>
X
extern FILE *popenv();
X
main(argc,argv)
int argc;
char *argv[];
X{
X  char buf[100];
X  int i;
X  char *av[10];
X  void *echo;
X  void *temp;
X  char c;
X
X  av[0]="repeat";
X  av[1]="hi";
X  av[2]="there";
X  av[3]=NULL;
X  if((echo=popenv(3,av,"r",&temp))==NULL) {
X    fprintf(stderr,"Can't open command repeat\n");
X    exit(10);
X  }
X
X  while(Read(echo,&c,1)==1) {
X    printf("Got char %d(%c)\n",c,c);
X  }
X  pclose(echo,&temp);
X  exit(0);
X}
X
X
END_OF_FILE
if test 452 -ne `wc -c <'rogue/t1.c'`; then
    echo shar: \"'rogue/t1.c'\" unpacked with wrong size!
fi
# end of 'rogue/t1.c'
fi
if test -f 'rogue/tags' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/tags'\"
else
echo shar: Extracting \"'rogue/tags'\" \(693 characters\)
sed "s/^X//" >'rogue/tags' <<'END_OF_FILE'
Mclirun	clirun.c	/^main(argc,argv)$/
Mrepeat	repeat.c	/^main(argc,argv)$/
Mroguecleanup	roguecleanup.c	/^main()$/
Mroguerun	roguerun.c	/^main(ac, av)$/
Mt0	t0.c	/^main(argc,argv)$/
Mt1	t1.c	/^main(argc,argv)$/
Mtest	test.c	/^main(argc,argv)$/
RogueError	fds.c	/^struct FileHandle *RogueError()$/
RogueFreeStartup	roguefree.c	/^int RogueFreeStartup(msg)$/
RogueInput	fds.c	/^struct FileHandle *RogueInput()$/
RogueLaunch	roguelaunch.c	/^RogueLaunch(rport, name, argv, argc, env, pri, win/
RogueOutput	fds.c	/^struct FileHandle *RogueOutput()$/
X_exit	_exit.c	/^_exit(code)$/
X_main	_main.c	/^_main(alen, aptr)$/
pclose	popen.c	/^int pclose(f,pp)$/
popenv	popen.c	/^FILE * popenv(ac,av,mode,pp)$/
END_OF_FILE
if test 693 -ne `wc -c <'rogue/tags'`; then
    echo shar: \"'rogue/tags'\" unpacked with wrong size!
fi
# end of 'rogue/tags'
fi
if test -f 'rogue/test.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/test.c'\"
else
echo shar: Extracting \"'rogue/test.c'\" \(453 characters\)
sed "s/^X//" >'rogue/test.c' <<'END_OF_FILE'
X#include <stdio.h>
X
extern FILE *popenv();
X
main(argc,argv)
int argc;
char *argv[];
X{
X  char buf[100];
X  int i;
X  char *av[10];
X  FILE *echo;
X  int  *temp;
X  char c;
X
X  av[0]="repeat";
X  av[1]="hi";
X  av[2]="there";
X  av[3]=NULL;
X  if((echo=popenv(3,av,"r",&temp))==NULL) {
X    fprintf(stderr,"Can't open command repeat\n");
X    exit(10);
X  }
X
X  while((c=getc(echo))!=EOF) {
X    printf("Got char %d(%c)\n",c,c);
X  }
X  pclose(echo,&temp);
X  exit(0);
X}
X
X
END_OF_FILE
if test 453 -ne `wc -c <'rogue/test.c'`; then
    echo shar: \"'rogue/test.c'\" unpacked with wrong size!
fi
# end of 'rogue/test.c'
fi
if test -f 'rogue/test2.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/test2.c'\"
else
echo shar: Extracting \"'rogue/test2.c'\" \(471 characters\)
sed "s/^X//" >'rogue/test2.c' <<'END_OF_FILE'
X#include <stdio.h>
X
extern FILE *popenv();
X
main(argc,argv)
int argc;
char *argv[];
X{
X  char buf[100];
X  int i;
X  char *av[10];
X  FILE *echo;
X  int  *temp;
X  char c;
X  char *q;
X
X  av[0]="hexdump";
X  av[1]=NULL;
X  if((echo=popenv(av,1,"w",&temp))==NULL) {
X    fprintf(stderr,"Can't open command repeat\n");
X    exit(10);
X  }
X
X  for(q=(char *)main,i=0; i<500; q++,i++) {
X    fprintf(echo,"Char at %d is %d\n",i,*q);
X  }
X  fflush(echo);
X  pclose(echo,&temp);
X  exit(0);
X}
X
X
END_OF_FILE
if test 471 -ne `wc -c <'rogue/test2.c'`; then
    echo shar: \"'rogue/test2.c'\" unpacked with wrong size!
fi
# end of 'rogue/test2.c'
fi
if test ! -d 'rogue/tst' ; then
    echo shar: Creating directory \"'rogue/tst'\"
    mkdir 'rogue/tst'
fi
if test -f 'rogue/shell/DMakefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/shell/DMakefile'\"
else
echo shar: Extracting \"'rogue/shell/DMakefile'\" \(588 characters\)
sed "s/^X//" >'rogue/shell/DMakefile' <<'END_OF_FILE'
MSHSRCS=msh.c
MSHOBJS=$(MSHSRCS:"*.c":"*.o")
PROGRAMS=pwd printenv echo
PROGSRCS=$(PROGRAMS:"*":"*.c")
PROGOBJS=$(PROGSRCS:"*.c":"*.o")
CC=cc
CFLAGS=+L
LD=ln
LDFLAGS=+Q -w
LIBS=-lrogue32 -lmcr32 -led32 -lc32
X
all : msh pwd printenv echo
X
msh : $(MSHOBJS)
X     $(LD) $(LDFLAGS) -o %(left) %(right) $(LIBS)
X
pwd : pwd.o
X     $(LD) $(LDFLAGS) -o %(left) %(right) $(LIBS)
X
printenv : printenv.o
X     $(LD) $(LDFLAGS) -o %(left) %(right) $(LIBS)
X
echo : echo.o
X     $(LD) $(LDFLAGS) -o %(left) %(right) $(LIBS)
X
X$(MSHOBJS) $(PROGOBJS) : $(MSHSRCS) $(PROGSRCS)
X     $(CC) $(CFLAGS) %(*.c)
X
X
X
X
X
END_OF_FILE
if test 588 -ne `wc -c <'rogue/shell/DMakefile'`; then
    echo shar: \"'rogue/shell/DMakefile'\" unpacked with wrong size!
fi
# end of 'rogue/shell/DMakefile'
fi
if test -f 'rogue/shell/echo.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/shell/echo.c'\"
else
echo shar: Extracting \"'rogue/shell/echo.c'\" \(152 characters\)
sed "s/^X//" >'rogue/shell/echo.c' <<'END_OF_FILE'
X#include <stdio.h>
X
main(argc,argv)
int argc;
char *argv[];
X{
X  while(--argc>0) {
X    fputs(*++argv,stdout);
X    putc(' ',stdout);
X  }
X  puts("");
X}
X
X
X
END_OF_FILE
if test 152 -ne `wc -c <'rogue/shell/echo.c'`; then
    echo shar: \"'rogue/shell/echo.c'\" unpacked with wrong size!
fi
# end of 'rogue/shell/echo.c'
fi
if test -f 'rogue/shell/msh.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/shell/msh.c'\"
else
echo shar: Extracting \"'rogue/shell/msh.c'\" \(6681 characters\)
sed "s/^X//" >'rogue/shell/msh.c' <<'END_OF_FILE'
X#include <exec/ports.h>
X#include <exec/memory.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include <stdio.h>
X#include <clib/edlib.h>
X#include "roguestar.h"
X
extern void *malloc();
extern void *AllocMem();
extern struct Task *FindTask();
extern struct MsgPort *CreatePort();
extern void *GetMsg();
extern char *find_var();
extern char **get_environ();
extern int set_var();
extern char *GetEnv();
extern char *strchr();
X
X#define PNAMESIZ 30
X
char *progname;
extern char **environ;
X
struct var {
X  struct var *vr_next;
X  char *name;
X  char *value;
X  BYTE exported;
X};
X
struct var *vars=NULL;
X
main(argc,argv)
int argc;
char *argv[];
X{
X  char *line;
X  char *buf1;
X  char **av;
X  int  ac;
X  int  wait;
X  struct MsgPort *ReturnPort;
X  struct Process *myproc;
X  char *processname;
X
X  progname=argv[0];
X
X  line=(char *)malloc(1000);
X  buf1=(char *)malloc(1000);
X  av=(char **)malloc(100*sizeof(char *));
X  processname=(char *)AllocMem(PNAMESIZ,MEMF_CLEAR|MEMF_PUBLIC);
X  if(line==NULL || buf1==NULL || av==NULL || processname==NULL) exit(99);
X  myproc=(struct Process *)FindTask(NULL);
X  sprintf(processname,"%s%d",progname,myproc);
X  ReturnPort=CreatePort(processname,NULL);
X
X  printf("> ");
X  while(gets(line)!=NULL) {
X    ac=parse_line(line,buf1,av);
X    if(strcmp(av[ac-1],"&")==0) {
X      ac--;
X      wait=0;
X    }
X    else wait=1;
X    if(internal(av,ac,ReturnPort,wait)!=-1);
X    else if(ex_run(av,ac,ReturnPort,wait)!=-1);
X    printf("> ");
X  }
X
X  DeletePort(ReturnPort);
X  FreeMem(processname,PNAMESIZ);
X  free(av);
X  free(line);
X  free(buf1);
X  exit(0);
X}
X
X
int parse_line(line,buf,av)
char *line;
char *buf;
char **av;
X{
X  char c;
X  int i;
X  int ac,acc;
X  char *p;
X
X  ac=0;
X  acc=0;
X  i=0;
X  av[ac]=buf;
X
X  while(line[i]!='\0') {
X    i=strspn(line+i," \t\n")+i;
X    while(line[i]!=' ' && line[i]!='\t' && line[i]!='\n' && line[i]!='\0') {
X      if(line[i]=='"') {
X        i++;
X        while(line[i]!='"' && line[i]!='\0') {
X          if(line[i]=='$') {
X            printf("Found var %s\n",line+i+1);
X          }
X          if(line[i]=='\\') {
X            *buf++=line[++i];
X          }
X          else {
X            *buf++=line[i];
X          }
X          i++;
X        }
X        if(line[i]=='\0') {
X          printf("Unmatched \"\n");
X          return 0;
X        }
X      }
X      else if(line[i]=='$') {
X        printf("Found var %s\n",line+i+1);
X        i++;
X        if(line[i]=='{') {
X          while(line[i]!='}' && line[i]!='\0') {
X            i++;
X          }
X        }
X        else {
X          int vs;
X
X          vs=i;
X          while(line[i]!='\0') {
X            int j;
X            char *special_set="() \t\n|[\"'";
X            for(j=0; special_set[j]!='\0'; j++) {
X              if(line[i]==special_set[j]) {
X                break;
X              }
X            }
X            i++;
X          }
X          if(i!=vs) {
X            line[i]='\0';
X            printf("looking for %s\n",&line[vs]);
X            if((p=find_var(&line[vs]))==NULL) {
X              fprintf(stderr,"Var %s not set\n",&line[vs]);
X            }
X            else {
X              for(vs=0; p[vs]!='\0'; vs++) {
X                *buf++=p[vs];
X              }
X            }
X          }
X        }
X      }
X      else {
X        *buf++=line[i];
X      }
X      i++;
X    }
X    *buf++='\0';
X    ac++;
X    av[ac]=buf;
X  }
X  return(ac);
X}
X
char **get_environ()
X{
X  static char env[1000];
X  static char *envs[100];
X  struct var *step;
X  char *t;
X  int num;
X
X  t=env;
X  num=0;
X  if(vars) {
X    for(step=vars; step!=NULL; step=step->vr_next) {
X      if(step->exported==TRUE) {
X        sprintf(t,"%s=%s",step->name,step->value);
X        envs[num]=t;
X        t+=strlen(t)+1;
X        num++;
X      }
X    }
X    envs[num]=NULL;
X    return(envs);
X  }
X  else {
X    return(NULL);
X  }
X}
X
char *find_var(var)
char *var;
X{
X  struct var *step;
X
X  step=vars;
X  while(step) {
X    if(strcmp(step->name,var)==0) {
X      return(step->value);
X    }
X    step=step->vr_next;
X  }
X  return(GetEnv(var));
X}
X
int set_var(var,value,export)
char *var;
char *value;
int export;
X{
X  struct var *step;
X
X  step=vars;
X  while(step) {
X    if(strcmp(step->name,var)==0) {
X      free(step->value);
X      if((step->value=malloc(strlen(value)+1))==NULL) {
X        fprintf(stderr,"Can't malloc in set_var\n");
X        return(1);
X      }
X      strcpy(step->value,value);
X      step->exported=export;
X      return(0);
X    }
X    step=step->vr_next;
X  }
X  if((step=malloc(sizeof(struct var)))==NULL) {
X   bad:
X    fprintf(stderr,"Can't malloc a new var\n");
X    return(1);
X  }
X  step->vr_next=vars;
X  vars=step;
X  if((step->name=malloc(strlen(var)+1))==NULL ||
X      (step->value=malloc(strlen(value)+1))==NULL) {
X    goto bad;
X  }
X  strcpy(step->name,var);
X  strcpy(step->value,value);
X  step->exported=export;
X  return(0);
X}
X
int ex_run(av,ac,port,wait)
char **av;
int ac;
struct MsgPort *port;
X{
X  long mask;
X  long rmask;
X  void *mychild;
X  void *achild;
X  int code,mycode;
X  long process;
X
X  rmask=1L << port->mp_SigBit;
X
X  if((mychild=RogueLaunch(port,av[0],av,ac,get_environ(),0,NULL,8000,
X                         Input(),Output(),Output()))==NULL) {
X    printf("Could not run %s IoErr %d\n",av[0],IoErr());
X    return(-1);
X  }
X  while(wait) {
X    mask=Wait(rmask|SIGBREAKF_CTRL_D|SIGBREAKF_CTRL_C);
X    if(mask&rmask) {
X      while((achild=GetMsg(port))!=NULL) {
X        if(achild!=mychild) {
X          process=(long)achild;
X          code=RogueFreeStartup(achild);
X          if(code==0) {
X            fprintf(stderr,"Process [%d] done\n",process);
X          }
X          else {
X            fprintf(stderr,"Process [%d] exited with %d\n",process,code);
X          }
X        }
X        else {
X          mycode=RogueFreeStartup(achild);
X          return(mycode);
X        }
X      }
X    }
X    else if(mask&SIGBREAKF_CTRL_D) {
X      fprintf(stderr,"Putting process [%d] in background\n",process);
X      wait=0;
X    }
X    else if(mask&SIGBREAKF_CTRL_C) {
X      fprintf(stderr,"Process [%d] received a ^C\n",process);
X    }
X  }
X  return(0);
X}
X
int internal(av,ac,port,wait)
char *av[];
int ac;
struct MsgPort *port;
X{
X  if(strcmp(av[0],"cd")==0 || strcmp(av[0],"chdir")==0) {
X    if(ac!=2) {
X     badnum:
X      fprintf(stderr,"Bad number of arguments\n");
X    }
X    else {
X      return(chdir(av[1]));
X    }
X  }
X  else if(strcmp(av[0],"setenv")==0) {
X    if(ac==3) {
X      return(set_var(av[1],av[2],TRUE));
X    }
X    else goto badnum;
X  }
X  else if(strcmp(av[0],"set")==0) {
X    if(ac==3) {
X      return(set_var(av[1],av[2],FALSE));
X    }
X    else if(ac==2) {
X      char *n;
X      char *v;
X      v=strchr(av[1],'=')+1;
X      n=strtok(av[1],"=");
X      return(set_var(n,v,FALSE));
X    }
X    else goto badnum;
X  }
X  else {
X    return(-1);
X  }
X}
X
X
X
X
X
X
X
X
X
END_OF_FILE
if test 6681 -ne `wc -c <'rogue/shell/msh.c'`; then
    echo shar: \"'rogue/shell/msh.c'\" unpacked with wrong size!
fi
# end of 'rogue/shell/msh.c'
fi
if test -f 'rogue/shell/printenv.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/shell/printenv.c'\"
else
echo shar: Extracting \"'rogue/shell/printenv.c'\" \(129 characters\)
sed "s/^X//" >'rogue/shell/printenv.c' <<'END_OF_FILE'
X#include <stdio.h>
X
extern char **environ;
X
main()
X{
X  int i;
X
X  for(i=0; environ[i]!=NULL; i++) {
X    puts(environ[i]);
X  }
X}
X
X
END_OF_FILE
if test 129 -ne `wc -c <'rogue/shell/printenv.c'`; then
    echo shar: \"'rogue/shell/printenv.c'\" unpacked with wrong size!
fi
# end of 'rogue/shell/printenv.c'
fi
if test -f 'rogue/shell/pwd.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/shell/pwd.c'\"
else
echo shar: Extracting \"'rogue/shell/pwd.c'\" \(1378 characters\)
sed "s/^X//" >'rogue/shell/pwd.c' <<'END_OF_FILE'
X#include <exec/memory.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
extern void *AllocMem();
extern struct Task *FindTask();
extern struct FileLock *CurrentDir();
extern struct FileLock *DupLock();
extern struct FileLock *ParentDir();
X
int getcwd(buf,l)
char *buf;
int l;
X{
X  struct FileLock *lock, *newlock;
X  struct FileInfoBlock *fib;
X  struct Process *myproc;
X  int i,len;
X  char *name;
X
X  if((fib=(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),
X                                           MEMF_CLEAR|MEMF_PUBLIC))==NULL) {
X    return(NULL);
X  }
X  CurrentDir(DupLock(lock=CurrentDir(NULL)));
X
X  buf[i=l]='\0';
X  while (lock) {
X    newlock = (struct FileLock *)ParentDir(lock);
X    Examine(lock, fib);
X    name = fib->fib_FileName;
X    if(*name == '\0')            /* HACK TO FIX RAM: DISK BUG */
X      name = "ram";
X
X    len = strlen(name);
X    if(newlock) {
X      if(i == 255) {
X        i -= len;
X        bcopy(name, buf + i, len);
X      }
X      else {
X        i -= len +1;
X        bcopy(name, buf + i, len);
X        buf[i+len] = '/';
X      }
X    }
X    else {
X      i -= len + 1;
X      bcopy(name, buf + i, len);
X      buf[i+len] = ':';
X    }
X    UnLock(lock);
X    lock = newlock;
X  }
X  FreeMem(fib, (long)sizeof(struct FileInfoBlock));
X  bcopy(buf+i,buf,(l-i)+1);
X  return(1);
X}
X
main()
X{
X  char buf[255];
X  getcwd(buf,255);
X  puts(buf);
X}
X
END_OF_FILE
if test 1378 -ne `wc -c <'rogue/shell/pwd.c'`; then
    echo shar: \"'rogue/shell/pwd.c'\" unpacked with wrong size!
fi
# end of 'rogue/shell/pwd.c'
fi
if test -f 'rogue/stuff/rogue.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/stuff/rogue.1'\"
else
echo shar: Extracting \"'rogue/stuff/rogue.1'\" \(2016 characters\)
sed "s/^X//" >'rogue/stuff/rogue.1' <<'END_OF_FILE'
Path: fts1!nrcaer!sce!mitel!uunet!nuchat!sugar!peter
XFrom: peter@sugar.hackercorp.com (Peter da Silva)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Using PIP:
Keywords: dupping closing pipes
Message-ID: <4780@sugar.hackercorp.com>
Date: 17 Dec 89 05:31:00 GMT
References: <4689@sugar.hackercorp.com> <1610.AA1610@julie> <1718.AA1718@julie> <4778@sugar.hackercorp.com> <11223@thorin.cs.unc.edu>
Reply-To: peter@sugar.hackercorp.com (Peter da Silva)
Organization: Sugar Land Unix - Houston
Lines: 32
X
In article <11223@thorin.cs.unc.edu> tell@oscar.cs.unc.edu (Stephen Tell) writes:
X> In article <4778@sugar.hackercorp.com> peter@sugar.hackercorp.com (Peter da Silva) writes:
X> >In article <1718.AA1718@julie> mcr@julie.UUCP (Michael Richardson) writes:
X> >>   /* fast:exp/src/include/roguestar.h */
X
X> >>    char **rs_environ;         /* Arguments of environment space */
X> >>    int  rs_envcount;          /* Number of variables */
X> >	Not a good idea. You want to co-operate with AmigaDOS, and that means
X> >	using env:.
X
X> But env: is deficient in that its "global" and therefore you can't have
X> more than one environment.
X
I understand this. However you should retain compatibility with the system
as it exists. Similarly, your programs should use AmigaDOS keyword argument
handling rather than UNIX -option style, and they should work properly under
the Workbench and CLI as well as RogueStartup.
X
If Getenv returns a different value depending on whether the program is
started from RogueStartup and CLI that's a bad thing.
X
X> >There's a point to both. It'd be cooler to make RogueStartup a full superset
X> >of WBStartup. Using some magic token to distinguish them.
X
X> In general, this looks like a good idea.  CBM seems more likely to adopt it
X> as a standard somday (1.5?) if it fits well with existing stuff.
X
Also people are more likely to use it today.
X-- 
Peter "Have you hugged your wolf today" da Silva <peter@sugar.hackercorp.com>
X`-_-'
X 'U`  "I haven't lost my mind, it's backed up on tape somewhere"
END_OF_FILE
if test 2016 -ne `wc -c <'rogue/stuff/rogue.1'`; then
    echo shar: \"'rogue/stuff/rogue.1'\" unpacked with wrong size!
fi
# end of 'rogue/stuff/rogue.1'
fi
if test -f 'rogue/stuff/rogue.2' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/stuff/rogue.2'\"
else
echo shar: Extracting \"'rogue/stuff/rogue.2'\" \(3124 characters\)
sed "s/^X//" >'rogue/stuff/rogue.2' <<'END_OF_FILE'
Path: fts1!nrcaer!sce!mitel!uunet!mailrus!wuarchive!texbell!sugar!peter
XFrom: peter@sugar.hackercorp.com (Peter da Silva)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Using PIP:
Keywords: dupping closing pipes
Message-ID: <4778@sugar.hackercorp.com>
Date: 16 Dec 89 21:02:59 GMT
References: <4689@sugar.hackercorp.com> <1610.AA1610@julie> <1718.AA1718@julie>
Reply-To: peter@sugar.hackercorp.com (Peter da Silva)
Organization: Sugar Land Unix - Houston
Lines: 73
X
In article <1718.AA1718@julie> mcr@julie.UUCP (Michael Richardson) writes:
X>   /* fast:exp/src/include/roguestar.h */
X
X>  struct RogueStartup {
X>    struct Message rs_Message;
X>    struct MsgPort *rs_Process;
X>    BPTR rs_Segment;
X>    LONG rs_dummy;             /* ALWAYS 0 -- would be NumArgs in WBStartup */
X	Probably should be OK.
X
X>    char *rs_ToolWindow;       /* Usually NULL */
X	I'd leave in sm_ArgList as well.
X
X>    int  rs_argc;
X>    char **rs_argv;
X	So far so good.
X
X>    int  rs_fhc;               /* Number of file handles to install */
X>    long *rs_fhv;
X	Not sure about this part. UNIXY, to be sure. But is it useful to
X	get that far ahead of AmigaDOS?
X
X>    int  rs_exitcode;
X	Good.
X
X>    BPTR rs_CurrentDir;
X	Good. But I'd put this in sm_ArgList[0]. And put in the real program
X	name in there too. Keep compatability with WB stuff.
X
X>    char **rs_environ;         /* Arguments of environment space */
X>    int  rs_envcount;          /* Number of variables */
X	Not a good idea. You want to co-operate with AmigaDOS, and that means
X	using env:.
X
X>    char *rs_envspace;         /* Buffer containing variables */
X>    int  rs_envsize;           /* Size of buffer */
X>    long rs_closebits[2];      /* Close this filehandle (major kludge) */
X	Why is this a kludge? It fits in well with rs_fhc/rs_fhv.
X
X	Of course, you should probably not do this unless you know you
X	have a Rogue program.
X
X>   I don't want the locks. I pass the full file names. A possible modification
X> would use exec List instead of an array to hold the arguments.
X
There's a point to both. It'd be cooler to make RogueStartup a full superset
of WBStartup. Using some magic token to distinguish them.
X
X>    ConMan is also a pipe-handler responding to the name PIP:NNNN...
X
Please don't make it depend on CONMAN, anyway.
X
X> >        sprintf(PipeName, "%s:rogue%dpipe%d", PipeDevice, ProcessId, Sequence++);
X> >        pin = Open(PipeName, MODE_NEWFILE);
X> >        pout = Open(PipeName, MODE_OLDFILE);
X
X>   My last resort. Pipe: doesn't like.
X
I can't parse this statement. PIPE: doesn't like what?
X
X>   I've spent hours running dnet both here to school, and between myself and
X> other people, and I've _never_ gotten the scli server to work the DPIPE:,
X> or Matt's original pipe, or the 1.3 pipe...
X
You can make "PipeDevice" "PIP:" if you know you need that. I don't use
ConMan (irrational prejudice... it just feels icky to REPLACE con:), so I
could use P:, PIPE:, whatever...
X
What order are you opening the pipes in?
X-- 
Peter "Have you hugged your wolf today" da Silva <peter@sugar.hackercorp.com>
X`-_-'
X 'U`  "I haven't lost my mind, it's backed up on tape somewhere"
END_OF_FILE
if test 3124 -ne `wc -c <'rogue/stuff/rogue.2'`; then
    echo shar: \"'rogue/stuff/rogue.2'\" unpacked with wrong size!
fi
# end of 'rogue/stuff/rogue.2'
fi
if test -f 'rogue/stuff/rogue.3' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/stuff/rogue.3'\"
else
echo shar: Extracting \"'rogue/stuff/rogue.3'\" \(2079 characters\)
sed "s/^X//" >'rogue/stuff/rogue.3' <<'END_OF_FILE'
Path: fts1!nrcaer!sce!mitel!uunet!wuarchive!usc!rutgers!mephisto!ncsuvx!mcnc!thorin!oscar!tell
XFrom: tell@oscar.cs.unc.edu (Stephen Tell)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Using PIP:
Summary: (really: more RogueStartup comments/discussion)
Keywords: dupping closing pipes
Message-ID: <11223@thorin.cs.unc.edu>
Date: 16 Dec 89 23:53:24 GMT
References: <4689@sugar.hackercorp.com> <1610.AA1610@julie> <1718.AA1718@julie> <4778@sugar.hackercorp.com>
Sender: news@thorin.cs.unc.edu
Reply-To: tell@oscar.cs.unc.edu (Stephen Tell)
Organization: University Of North Carolina, Chapel Hill
Lines: 29
X
In article <4778@sugar.hackercorp.com> peter@sugar.hackercorp.com (Peter da Silva) writes:
X>In article <1718.AA1718@julie> mcr@julie.UUCP (Michael Richardson) writes:
X>>   /* fast:exp/src/include/roguestar.h */
X
X>>    char **rs_environ;         /* Arguments of environment space */
X>>    int  rs_envcount;          /* Number of variables */
X>	Not a good idea. You want to co-operate with AmigaDOS, and that means
X>	using env:.
But env: is deficient in that its "global" and therefore you can't have
more than one environment.  Consider a 2-user system (using AUX: or dnet:)
or a multi-user BBS; each user may need his own environment.  I'm sure there
are other more mundane examples.
X
Now if we were all to use env:<process-id>/variable, and use links where only
a small part of the environment (or none at all) changed between a parent
and its child...   (What? no links? aren't they "in there" too?)
X
X>There's a point to both. It'd be cooler to make RogueStartup a full superset
X>of WBStartup. Using some magic token to distinguish them.
In general, this looks like a good idea.  CBM seems more likely to adopt it
as a standard somday (1.5?) if it fits well with existing stuff.
X
X>Peter "Have you hugged your wolf today" da Silva <peter@sugar.hackercorp.com>
X>`-_-'
X> 'U`  "I haven't lost my mind, it's backed up on tape somewhere"
X
X--------------------------------------------------------------------
Steve Tell					tell@wsmail.cs.unc.edu
CS Grad Student, UNC Chapel Hill.
END_OF_FILE
if test 2079 -ne `wc -c <'rogue/stuff/rogue.3'`; then
    echo shar: \"'rogue/stuff/rogue.3'\" unpacked with wrong size!
fi
# end of 'rogue/stuff/rogue.3'
fi
if test -f 'rogue/tst/test.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rogue/tst/test.c'\"
else
echo shar: Extracting \"'rogue/tst/test.c'\" \(1420 characters\)
sed "s/^X//" >'rogue/tst/test.c' <<'END_OF_FILE'
X/*
X *  Open a FileHandle to a process.
X *
X */
X
X#include <stdio.h>
X#include <fcntl.h>
X#include <exec/memory.h>
X#include <libraries/dos.h>
X#include <libraries/dosextens.h>
X#include "bcpl.h"
X
extern void *AllocMem();
extern struct FileHandle *Open();
extern FILE *fdopen();
extern void *CreatePort();
extern void *GetMsg();
X
main()
X{
X  struct FileHandle *pin,*pout,*ret,*temp;
X  int i;
X  char buf[100],buf2[100];
X
X  if((pin=AllocMem(sizeof(struct FileHandle),MEMF_PUBLIC|MEMF_CLEAR))==NULL) {
X    return(NULL);
X  }
X  if((pout=Open("PIP:4096",2000L))==NULL) {
X    FreeMem(pin,sizeof(struct FileHandle));
X    return(NULL);
X  }
X  temp=(struct FileHandle*)BTOC(pout);
X  (*pin)=(*temp);
X  pin=(struct FileHandle*)CTOB(pin);
X
X  printf("Created two handles: %08x and %08x\n",pin,pout);
X  printf("Please type a line: ");
X  fgets(buf,100,stdin);
X  printf("Got %s\n",buf);
X  i=Write(pin,buf,strlen(buf));
X  printf("Wrote string (%d)\n",i);
X  i=Read(pout,buf2,100);
X  buf2[i]='\0';
X  printf("Read (%d) %s\n",i,buf2);
X
X/*
X  printf("Please type a last line: ");
X  fgets(buf,100,stdin);
X  printf("Got %s\n",buf);
X  i=Write(pin,buf,strlen(buf));
X  printf("Wrote string (%d)\n",i);
X  printf("Closed pin %d\n",Close(pin));
X
X  printf("Reading pout:");
X  i=Read(pout,buf2,100);
X  buf2[i]='\0';
X  printf("Read (%d) %s\n",i,buf2);
X */
X  Close(pin);
X  i=Read(pout,buf2,100);
X  buf2[i]='\0';
X  printf("Read (%d) %s\n",i,buf2);
X  Close(pout);
X
X}
X
END_OF_FILE
if test 1420 -ne `wc -c <'rogue/tst/test.c'`; then
    echo shar: \"'rogue/tst/test.c'\" unpacked with wrong size!
fi
# end of 'rogue/tst/test.c'
fi
echo shar: End of shell archive.
exit 0
-- 
  :!mcr!:
  Michael C. Richardson
HOME: mcr@julie.UUCP SCHOOL: mcr@doe.carleton.ca WORK: michael@fts1.UUCP
I never liked staying in one place too long, but this is getting silly...