DNA.
wysh
System-requirement.
platform=unix
Language.
c
Manpage.
wysh (1WY)
Testbase.
Test Script
Test Report
Export.
Command.
wysh
Executable.
wysh
Implementation.
wyrm-shell.c

Unix Shell

Sections.
Code Derived from Tcl Sources
Wyrmwif Environment
Test Base
Make.
Executable.
rule executables :: wysh
if {[string equal $::tcl_platform(platform) unix]} {
  switch $::tcl_platform(os) {
    Darwin {set setpgrp setpgrp(0,0)}
    Linux {set setpgrp setpgrp()}
    IRIX64 {set setpgrp setpgrp()}
    default {error "do not how to setpgrp for $tcl_platform(os)"}
  }
  rule wysh $bin/$tcl_platform(os)/wysh
  compile -cc '-DSETPGRP=$setpgrp' -o $bin/$tcl_platform(os)/wysh [export implementation] -exec
} else {
  error "This executable is for Unix only."
}
   
top

1 :: Unix shell for a Wyrmwif environment.

Portions are Copyright (C) 2002, 2004 SM Ryan.

Wyrmwif Tcl extensions. For non-profit uses only, provided this copyright is preserved on all copies, this work may be freely copied, modified, redistributed, compiled, and incorporated in other works. This work is distributed with no warranty of any kind; no author or distributor accepts any responsibility for the consequences of using it, or for whether it serves any particular purpose or works at all, unless he or she says so in writing.

   
   

Code Derived from Tcl Sources

   
top

/* 
 * tclAppInit.c --
 *
 *	Provides a default version of the main program and Tcl_AppInit
 *	procedure for Tcl applications (without Tk).
 *
 * Copyright (c) 1993 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-1999 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tclAppInit.c,v 1.11 2002/05/31 22:20:22 dgp Exp $
 */

		
 
section    top

<Tcl copyright>

#include <tcl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

int Tcl_AppInit(Tcl_Interp *interp);
<Communication variables between main and Tcl_AppInit>

/*
 *----------------------------------------------------------------------
 *
 * main --
 *
 *	This is the main program for the application.
 *
 * Results:
 *	None: Tcl_Main never returns here, so this procedure never
 *	returns either.
 *
 * Side effects:
 *	Whatever the application does.
 *
 *----------------------------------------------------------------------
 */

int main(int argc,char **argv) {
	<Wyrm wif shell parameters>
	Tcl_Main(nargc, nargv, Tcl_AppInit);
	return 0;			/* Needed only to prevent compiler warning. */
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_AppInit --
 *
 *	This procedure performs application-specific initialization.
 *	Most applications, especially those that incorporate additional
 *	packages, will have their own version of this procedure.
 *
 * Results:
 *	Returns a standard Tcl completion code, and leaves an error
 *	message in the interp's result if an error occurs.
 *
 * Side effects:
 *	Depends on the startup script.
 *
 *----------------------------------------------------------------------
 */

int Tcl_AppInit(Tcl_Interp *interp) {
	if (Tcl_Init(interp) == TCL_ERROR) {
		return TCL_ERROR;
	}
	<Load the wyrmwif environment>
	<Run command line sources and commands>
	Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY);
	return TCL_OK;
}

		
   
   

Wyrmwif Environment

   
top
4. Wyrm wif tcl shell manpage ::

NAME

wysh — Tclsh with Wyrmwif environment.

synopsis

wysh [ input-file ] [ -i | -n | -s file | -c command | -p package | argv-parameter ] ... [ -- argv-parameter... ]

description

The command line parameters recognised by wysh are <Wyrm wif shell parameters>

The first of any other parameters is passed through as the input file, or stdin if -, and any other parameters are passed through and appear in the argv global variable; all parameters after (but not including) -- are passed through as argv elements whether they look like wysh parameters or no.

<Load the wyrmwif environment> <Run command line sources and commands> <stdin>
 
section    top

static int oargc; static char **oargv;

		
 
section    top

#define streq(x,y) (strcmp(x,y)==0)
int nargc = 1; char **nargv = (char**)Tcl_Alloc((argc+2)*sizeof(char*));
int keepstdin = 0;
int batch = 0;
int command = 0;
int alternateinput = 0;
oargc = argc-1; oargv = argv+1;
argc--;
nargv[0] = *argv++;
while (argc>0) {
	if (streq(*argv,"-i")) {
		argc -= 1; argv += 1;
		keepstdin = 1;
	}else if (streq(*argv,"-n")) {
		argc -= 1; argv += 1;
		batch = 1;
	}else if (argc>1 && streq(*argv,"-s")) {
		argc -= 2; argv += 2;
	}else if (argc>1 && streq(*argv,"-c")) {
		argc -= 2; argv += 2;
		command = 1;
	}else if (argc>1 && streq(*argv,"-p")) {
		argc -= 2; argv += 2;
	}else if (streq(*argv,"--")) {
		argc -= 1; argv += 1;
		while (argc>0) {
			if (nargc==1) alternateinput = !streq(*argv,"-");
			nargv[nargc++] = *argv++; argc--;
		}
	}else {
		if (nargc==1) alternateinput = !streq(*argv,"-");
		nargv[nargc++] = *argv++; argc--;
	}
}
<stdin>
nargv[nargc] = 0;

		
 
section    top

7. stdin :: Without any wysh parameters, wysh reads commands from the standard input (stdin) or from the specified input file until it reaches an end of file. If a -c command is specified, stdin is not read unless the -i parameter is also specified. (If an alternate input file was specified as the first argv parameter, that is still read in any case.)

wysh -c command [ -n ]
evaluates the command, print the result, and exit the wysh shell.
wysh [ -i ]
accepts commands from stdin (with prompts if from the terminal) until the end of file (unless an alternate input file was specified).
wysh -c command -i
evaluates the command, print the result, and then accept commands from stdin until the end of file. It is assumed that in general commands will be enterred on the command line or from the input device (such as the terminal), exclusively. Specifying -c and -i allows both.
wysh -n
runs the shell as with no commands read from stdin. Commands must be given with -c, -s, read from ~/.tclshrc or an alternate input file specified.

-s source files have no effect on whether stdin is read or not.


if (batch) keepstdin = 0;
if (!command && !batch) keepstdin = 1;
if (!keepstdin && !alternateinput) {
	if (nargc==1) nargc = 2;
	nargv[1] = "/dev/null";
}

		
 
section    top

int p;
if (Tcl_VarEval(interp,"package require wyrmwif",0)!=TCL_OK) {
	static char msg[] = "require wyrmwif: ";
	char *result = Tcl_GetStringResult(interp);
	write(2,msg,sizeof(msg)-1);
	write(2,result,strlen(result));
	write(2,"\n",1);
	return TCL_ERROR;
}
for (p=0; p<oargc; p++) {
	if (p+1<oargc && streq(oargv[p],"-s")) {
		p++;
	}else if (p+1<oargc && streq(oargv[p],"-c")) {
		p++;
	}else if (p+1<oargc && streq(oargv[p],"-p")) {
		if (Tcl_VarEval(interp,"package require wyrm",oargv[p+1],0)!=TCL_OK) {
			static char msg1[] = "require wyrm";
			static char msg2[] = ": ";
			char *result = Tcl_GetStringResult(interp);
			write(2,msg1,sizeof(msg1)-1);
			write(2,oargv[p+1],strlen(oargv[p+1]));
			write(2,msg2,sizeof(msg2)-1);
			write(2,result,strlen(result));
			write(2,"\n",1);
			return TCL_ERROR;
		}
		p++;
	}else if (streq(oargv[p],"--")) {
		break;
	}
}
Tcl_VarEval(interp,"wyrm::mc -load [lindex $env(TCLLIBPATH) 0]/wyrmwif.msgs",0);
if (Tcl_VarEval(interp,"namespace import wyrm::*",0)!=TCL_OK) {
	static char msg[] = "import wyrmwif: ";
	char *result = Tcl_GetStringResult(interp);
	write(2,msg,sizeof(msg)-1);
	write(2,result,strlen(result));
	write(2,"\n",1);
	return TCL_ERROR;
}

		
 
section    top

while (oargc>0) {
	if (oargc>1 && streq(*oargv,"-s")) {
		int rc = Tcl_EvalFile(interp,oargv[1]);
		if (rc!=TCL_OK) {
			static char msg1[] = "-s ";
			static char msg2[] = ": error: ";
			char *result = Tcl_GetStringResult(interp);
			write(2,msg1,sizeof(msg1)-1);
			write(2,oargv[1],strlen(oargv[1]));
			write(2,msg2,sizeof(msg2)-1);
			write(2,result,strlen(result));
			write(2,"\n",1);
			return TCL_ERROR;
		}
		oargc -= 2; oargv += 2;
	}else if (oargc>1 && streq(*oargv,"-c")) {
		int rc = Tcl_Eval(interp,oargv[1]);
		char *result = Tcl_GetStringResult(interp);
		if (rc==TCL_OK) {
			write(1,result,strlen(result));
			write(1,"\n",1);
		}else {
			static char msg[] = ": error: ";
			char *result = Tcl_GetStringResult(interp);
			write(2,oargv[1],strlen(oargv[1]));
			write(2,msg,sizeof(msg)-1);
			write(2,result,strlen(result));
			write(2,"\n",1);
			return TCL_ERROR;
		}
		oargc -= 2; oargv += 2;
	}else if (oargc>1 && streq(*oargv,"-p")) {
		oargc -= 2; oargv += 2;
	}else if (streq(*oargv,"--")) {
		oargc = 0;
	}else {
		oargv++; oargc--;
	}
}

		
   
   

Test Base

   
top
    DSH Main program command line options.
      DSH000
      Input file.
        Specify an alternate input file.
          Specify stdin with -i.
            DSH100
          Specify stdin without -i.
            DSH101
          No stdin with -n.
            DSH102
          No stdin with -c.
            DSH103
          Specify stdin with -c -i.
            DSH104
          Alternate file.
            Does not exist.
              DSH120
            Is not readable.
              DSH121
            Readable.
              DSH122
        No alternate input file.
          Specify stdin with -i.
            DSH150
            DSH151
          Specify stdin without -i.
            DSH152
            DSH153
          No stdin with -n.
            DSH154
            DSH155
          No stdin with -n and -i.
            DSH156
            DSH157
          No stdin with -c.
            DSH158
            DSH159
          No stdin with -c and -n.
            DSH160
            DSH161
          Specify stdin with -c -i.
            DSH162
            DSH163
      Source file.
        Count.
          No source files.
            DSH200
          One source file.
            DSH201
          Multiple source files.
            DSH202
        Access.
          Does not exist.
            DSH220
          Is not readable.
            DSH221
          Readable.
            DSH222
        Main input
          Source before stdin.
            DSH250
            DSH250
          Source before alternate input.
            DSH252
          Source with no input.
            DSH253
        Error exit.
          No source errors.
            DSH270
          Source errors.
            DSH271
      Command parameter.
        Count.
          No commands.
            DSH300
          One command.
            DSH301
          Multiple commands.
            DSH302
        Error exit.
          No command errors.
            DSH350
          Command errors.
            DSH351
      Wyrm wif environment.
        wyrmwif loaded and imported.
          DSH400
        -p.
          One -p of an existing package.
            DSH401
          Multiple -p of existing packages.
            DSH402
          -p of a nonexistent package.
            DSH403
      argv.
        No argv parameters.
          DSH500
        One argv taken as the alternate input.
          DSH501
        Multiple argv parameters.
          DSH502
          DSH503
        First -- ignored and subsequent parameters all treated as argv.
          DSH504
      Use dsh as a script file shell.
        DSH600
        DSH601
      DSH999