home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-19 | 46.2 KB | 1,391 lines |
- Newsgroups: comp.sources.misc
- From: karl@sugar.neosoft.com (Karl Lehenbauer)
- Subject: v26i012: tclx - extensions and on-line help for tcl 6.1, Part12/23
- Message-ID: <1991Nov19.135344.884@sparky.imd.sterling.com>
- X-Md4-Signature: 945da10336be275391c8af059ff01fa7
- Date: Tue, 19 Nov 1991 13:53:44 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: karl@sugar.neosoft.com (Karl Lehenbauer)
- Posting-number: Volume 26, Issue 12
- Archive-name: tclx/part12
- Environment: UNIX
-
- #! /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 archive 12 (of 23)."
- # Contents: extended/src/cmdloop.c extended/tcllib/help/brief
- # extended/tests/chmod.test extended/tests/unixcmds.test
- # Wrapped by karl@one on Wed Nov 13 21:50:24 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'extended/src/cmdloop.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'extended/src/cmdloop.c'\"
- else
- echo shar: Extracting \"'extended/src/cmdloop.c'\" \(11049 characters\)
- sed "s/^X//" >'extended/src/cmdloop.c' <<'END_OF_FILE'
- X/*
- X * cmdloop --
- X *
- X * Interactive command loop, C and Tcl callable.
- X *---------------------------------------------------------------------------
- X * Copyright 1991 Karl Lehenbauer and Mark Diekhans.
- X *
- X * Permission to use, copy, modify, and distribute this software and its
- X * documentation for any purpose and without fee is hereby granted, provided
- X * that the above copyright notice appear in all copies. Karl Lehenbauer and
- X * Mark Diekhans make no representations about the suitability of this
- X * software for any purpose. It is provided "as is" without express or
- X * implied warranty.
- X */
- X
- X#include "tclExtdInt.h"
- X
- X
- X/*
- X * Pointer to eval procedure to use. This way bring in the history module
- X * from a library can be made optional. This only works because the calling
- X * sequence of Tcl_Eval is a superset of Tcl_RecordAndEval. This defaults
- X * to no history, set this variable to Tcl_RecordAndEval to use history.
- X */
- X
- Xint (*tclShellCmdEvalProc) () = Tcl_Eval;
- X
- X/*
- X * Prototypes of internal functions.
- X */
- Xint
- XIsSetVarCmd _ANSI_ARGS_((Tcl_Interp *interp,
- X char *command));
- X
- Xvoid
- XOutStr _ANSI_ARGS_((FILE *filePtr,
- X char *string));
- X
- Xvoid
- XOutFlush _ANSI_ARGS_((FILE *filePtr));
- X
- Xvoid
- XTcl_PrintResult _ANSI_ARGS_((FILE *fp,
- X int returnval,
- X char *resultText));
- X
- Xvoid
- XOutputPrompt _ANSI_ARGS_((Tcl_Interp *interp,
- X FILE *outFP,
- X int topLevel));
- X
- Xint
- XSetPromptVar _ANSI_ARGS_((Tcl_Interp *interp,
- X char *hookVarName,
- X char *newHookValue,
- X char **oldHookValuePtr));
- X
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * IsSetVarCmd --
- X *
- X * Determine if the current command is a `set' command that set
- X * a variable (i.e. two arguments). This routine should only be
- X * called if the command returned TCL_OK, due to it calling
- X * Tcl_SplitList, which might alter the interpreter in the result
- X * buffer if the command is not a valid list.
- X *
- X *----------------------------------------------------------------------
- X */
- Xstatic int
- XIsSetVarCmd (interp, command)
- X Tcl_Interp *interp;
- X char *command;
- X{
- X int cmdArgc;
- X char **cmdArgv;
- X int isSet;
- X
- X if ((!STRNEQU (command, "set", 3)) || (!isspace (command [3])))
- X return FALSE; /* Quick check */
- X if (Tcl_SplitList (interp, command, &cmdArgc, &cmdArgv) != TCL_OK)
- X return FALSE;
- X isSet = STREQU (cmdArgv[0], "set") && (cmdArgc >= 3);
- X ckfree ((char *) cmdArgv);
- X return isSet;
- X
- X}
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * OutStr --
- X *
- X * Print a string to the specified file handle and check for errors.
- X *
- X *----------------------------------------------------------------------
- X */
- Xstatic void
- XOutStr (filePtr, string)
- X FILE *filePtr;
- X char *string;
- X{
- X int stat;
- X
- X stat = fputs (string, filePtr);
- X if (stat == EOF)
- X panic ("command loop: error writting to output file: %s\n",
- X strerror (errno));
- X}
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * OutFlush --
- X *
- X * Flush a stdio file and check for errors.
- X *
- X *----------------------------------------------------------------------
- X */
- Xstatic void
- XOutFlush (filePtr)
- X FILE *filePtr;
- X{
- X int stat;
- X
- X stat = fflush (filePtr);
- X if (stat == EOF)
- X panic ("command loop: error flushing output file: %s\n",
- X strerror (errno));
- X}
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * Tcl_PrintResult --
- X *
- X * Print a Tcl result
- X *
- X * Results:
- X *
- X * Takes an open file pointer, a return value and some result
- X * text. Prints the result text if the return value is TCL_OK,
- X * prints "Error:" and the result text if it's TCL_ERROR,
- X * else prints "Bad return code:" and the result text.
- X *
- X *----------------------------------------------------------------------
- X */
- Xstatic void
- XTcl_PrintResult (fp, returnval, resultText)
- X FILE *fp;
- X int returnval;
- X char *resultText;
- X{
- X
- X if (returnval == TCL_OK) {
- X if (resultText [0] != '\0') {
- X OutStr (fp, resultText);
- X OutStr (fp, "\n");
- X }
- X } else {
- X OutFlush (fp);
- X OutStr (stderr, (returnval == TCL_ERROR) ? "Error" :
- X "Bad return code");
- X OutStr (stderr, ": ");
- X OutStr (stderr, resultText);
- X OutStr (stderr, "\n");
- X }
- X}
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * OutputPrompt --
- X * Outputs a prompt by executing either the command string in
- X * TCLENV(topLevelPromptHook) or TCLENV(downLevelPromptHook).
- X *
- X *----------------------------------------------------------------------
- X */
- Xstatic void
- XOutputPrompt (interp, outFP, topLevel)
- X Tcl_Interp *interp;
- X FILE *outFP;
- X int topLevel;
- X{
- X char *hookName;
- X char *promptHook;
- X int result;
- X int promptDone = FALSE;
- X
- X hookName = topLevel ? "topLevelPromptHook"
- X : "downLevelPromptHook";
- X if (((promptHook = Tcl_GetVar2 (interp, "TCLENV", hookName, 1)) !=
- X NULL) && (*promptHook != '\0')) {
- X result = Tcl_Eval(interp, promptHook, 0, (char **)NULL);
- X if (!((result == TCL_OK) || (result == TCL_RETURN))) {
- X OutStr (stderr, "Error in prompt hook: ");
- X OutStr (stderr, interp->result);
- X OutStr (stderr, "\n");
- X Tcl_PrintResult (outFP, result, interp->result);
- X } else {
- X OutStr (outFP, interp->result);
- X promptDone = TRUE;
- X }
- X }
- X if (!promptDone) {
- X if (topLevel)
- X OutStr (outFP, "%");
- X else
- X OutStr (outFP, ">");
- X }
- X OutFlush (outFP);
- X
- X}
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * Tcl_CommandLoop --
- X *
- X * Run a Tcl command loop
- X *
- X * Results:
- X *
- X * Takes an interpreter, in and out file handles and an
- X * interactive flag and reads and executes everything
- X * it reads from input.
- X *
- X *----------------------------------------------------------------------
- X */
- Xvoid
- XTcl_CommandLoop (interp, in, out, interactive)
- X Tcl_Interp *interp;
- X FILE *in;
- X FILE *out;
- X int interactive;
- X{
- X Tcl_CmdBuf cmdBuf;
- X char inputBuf[256];
- X int topLevel = TRUE;
- X int result;
- X char *cmd;
- X
- X cmdBuf = Tcl_CreateCmdBuf();
- X
- X while (TRUE) {
- X
- X clearerr(in);
- X clearerr(out);
- X OutputPrompt (interp, out, topLevel);
- X errno = 0;
- X if (fgets(inputBuf, sizeof(inputBuf), in) == NULL) {
- X if (!feof(in) && interactive && (errno == EINTR)) {
- X Tcl_ResetSignals ();
- X putchar('\n');
- X continue; /* Go get the next command */
- X }
- X if (ferror (in))
- X panic ("command loop: error on input file: %s\n",
- X strerror (errno));
- X goto endOfFile;
- X }
- X cmd = Tcl_AssembleCmd(cmdBuf, inputBuf);
- X
- X if (cmd == NULL)
- X topLevel = FALSE;
- X else {
- X result = (*tclShellCmdEvalProc) (interp, cmd, 0, (char **)NULL);
- X if ((result != TCL_OK) ||
- X (interactive && !IsSetVarCmd (interp, cmd)))
- X Tcl_PrintResult (out, result, interp->result);
- X
- X topLevel = TRUE;
- X }
- X }
- XendOfFile:
- X Tcl_DeleteCmdBuf(cmdBuf);
- X}
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * SetPromptVar --
- X * Set one of the prompt hook variables, saving a copy of the old
- X * value, if it exists.
- X *
- X * Parameters:
- X * o hookVarName (I) - The name of the prompt hook, which is an element
- X * of the TCLENV array. One of topLevelPromptHook or downLevelPromptHook.
- X * o newHookValue (I) - The new value for the prompt hook.
- X * o oldHookValuePtr (O) - If not NULL, then a pointer to a copy of the
- X * old prompt value is returned here. NULL is returned if there was not
- X * old value. This is a pointer to a malloc-ed string that must be
- X * freed when no longer needed.
- X * Result:
- X * TCL_OK if the hook variable was set ok, TCL_ERROR if an error occured.
- X *----------------------------------------------------------------------
- X */
- Xstatic int
- XSetPromptVar (interp, hookVarName, newHookValue, oldHookValuePtr)
- X Tcl_Interp *interp;
- X char *hookVarName;
- X char *newHookValue;
- X char **oldHookValuePtr;
- X{
- X char *hookValue;
- X char *oldHookPtr = NULL;
- X
- X if (oldHookValuePtr != NULL) {
- X hookValue = Tcl_GetVar2 (interp, "TCLENV", hookVarName,
- X TCL_GLOBAL_ONLY);
- X if (hookValue != NULL) {
- X oldHookPtr = ckalloc (strlen (hookValue) + 1);
- X strcpy (oldHookPtr, hookValue);
- X }
- X }
- X if (Tcl_SetVar2 (interp, "TCLENV", hookVarName, newHookValue,
- X TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) == NULL) {
- X if (oldHookPtr != NULL)
- X ckfree (oldHookPtr);
- X return TCL_ERROR;
- X }
- X if (oldHookValuePtr != NULL)
- X *oldHookValuePtr = oldHookPtr;
- X return TCL_OK;
- X}
- X
- X/*
- X *----------------------------------------------------------------------
- X *
- X * Tcl_CommandloopCmd --
- X * Implements the TCL commandloop command:
- X * commandloop prompt prompt2
- X *
- X * Results:
- X * Standard TCL results.
- X *
- X *----------------------------------------------------------------------
- X */
- Xint
- XTcl_CommandloopCmd(clientData, interp, argc, argv)
- X ClientData clientData;
- X Tcl_Interp *interp;
- X int argc;
- X char **argv;
- X{
- X char *oldTopLevelHook = NULL;
- X char *oldDownLevelHook = NULL;
- X int result = TCL_ERROR;
- X
- X if (argc > 3) {
- X Tcl_AppendResult (interp, "wrong # args: ", argv[0],
- X " [prompt] [prompt2]", (char *) NULL);
- X return TCL_ERROR;
- X }
- X if (argc > 1) {
- X if (SetPromptVar (interp, "topLevelPromptHook", argv[1],
- X &oldTopLevelHook) != TCL_OK)
- X goto exitPoint;
- X }
- X if (argc > 2) {
- X if (SetPromptVar (interp, "downLevelPromptHook", argv[2],
- X &oldDownLevelHook) != TCL_OK)
- X goto exitPoint;
- X }
- X
- X Tcl_CommandLoop (interp, stdin, stdout, TRUE);
- X
- X if (oldTopLevelHook != NULL)
- X SetPromptVar (interp, "topLevelPromptHook", oldTopLevelHook, NULL);
- X if (oldDownLevelHook != NULL)
- X SetPromptVar (interp, "downLevelPromptHook", oldDownLevelHook, NULL);
- X
- X result = TCL_OK;
- XexitPoint:
- X if (oldTopLevelHook != NULL)
- X ckfree (oldTopLevelHook);
- X if (oldDownLevelHook != NULL)
- X ckfree (oldDownLevelHook);
- X return result;
- X}
- END_OF_FILE
- if test 11049 -ne `wc -c <'extended/src/cmdloop.c'`; then
- echo shar: \"'extended/src/cmdloop.c'\" unpacked with wrong size!
- fi
- # end of 'extended/src/cmdloop.c'
- fi
- if test -f 'extended/tcllib/help/brief' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'extended/tcllib/help/brief'\"
- else
- echo shar: Extracting \"'extended/tcllib/help/brief'\" \(9981 characters\)
- sed "s/^X//" >'extended/tcllib/help/brief' <<'END_OF_FILE'
- X
- Xcommands/append Append strings to a variable.
- Xcommands/array Return information about an array variable.
- Xcommands/break Exit the current loop.
- Xcommands/case Select code block to execute base on matching a string against a pattern.
- Xcommands/catch Trap errors while executing a command.
- Xcommands/cd Change the current working directory.
- Xcommands/close Close an open file or pipeline.
- Xcommands/concat Concatenates lists into a single list.
- Xcommands/continue Continue execution of the next iteration of a loop.
- Xcommands/env Variable for accessing the program's environment.
- Xcommands/eof Test for end-of-file.
- Xcommands/error Return an error.
- Xcommands/errorCode Variable holding symbolic error information.
- Xcommands/errorInfo Variable holding stack trace of an error.
- Xcommands/eval Command to evaluate strings as Tcl code.
- Xcommands/exec Run a Unix process.
- Xcommands/exit Terminate the current process.
- Xcommands/expr Evaluate an expression.
- Xcommands/file Return status information about an file name, including parsing the name.
- Xcommands/flush Flush a file buffer.
- Xcommands/for Loop control command.
- Xcommands/foreach Loop on each element of a list.
- Xcommands/format Generate a formated string using a format specification.
- Xcommands/gets Read a line from a file.
- Xcommands/glob Perform file name globbing.
- Xcommands/global Declare a variable as global.
- Xcommands/history Redo or list previously executed interactive commands.
- Xcommands/if Conditional command execution based on evaluating an expression.
- Xcommands/incr Increment a variable.
- Xcommands/info Provide state information on the Tcl interpreter.
- Xcommands/join Join elements of a list into a string.
- Xcommands/lappend Append elements to an array variable.
- Xcommands/lindex Extract an element of a list.
- Xcommands/linsert Insert an new element in a list.
- Xcommands/list Generate a list.
- Xcommands/llength Return the number of elements in a list.
- Xcommands/lrange Extract a range of elements from a list.
- Xcommands/lreplace Replace elements of a list.
- Xcommands/lsearch Search a list for a pattern.
- Xcommands/lsort Sort the elements of a list.
- Xcommands/open Open a file or pipeline.
- Xcommands/proc Define a Tcl procedure.
- Xcommands/puts Write a string to a file.
- Xcommands/pwd Return the current working directory.
- Xcommands/read Read bytes from a file.
- Xcommands/regexp Match a string against a regular expression.
- Xcommands/regsub Match a string against a regular expression and perform substitution on it.
- Xcommands/rename Rename or delete a command or procedure.
- Xcommands/return Exit the current procedure, optionally returning a value.
- Xcommands/scan Parse a string based on a format specification.
- Xcommands/seek Change the access position of a file.
- Xcommands/set Return or set the value of a variable.
- Xcommands/source Read and evaluate a file of Tcl code.
- Xcommands/split Split a string into a list of elements.
- Xcommands/string Perform operations on a string.
- Xcommands/tell Return the current access position of a file.
- Xcommands/time Return the execution time for a Tcl command.
- Xcommands/trace Trace access to variables.
- Xcommands/unknown Unknown command trap handler.
- Xcommands/unset
- Xcommands/uplevel Execute a command in another environment up the procedure call stack.
- Xcommands/upvar Bind a variable to another variable up the procedure call stack.
- Xcommands/while Loop while an expression is true.
- Xextended/acos Return the arccosine of a number.
- Xextended/alarm Set a process alarm clock.
- Xextended/asin Return the arcsin of a number.
- Xextended/atan Return the arctangent of a number..
- Xextended/ceil Return the smallest integer not less than a floating point number.
- Xextended/chgrp Change file group.
- Xextended/chmod Set file permissions.
- Xextended/chown Change file owner and/or group.
- Xextended/cindex Return indexed character from string.
- Xextended/clength Return length of specified string.
- Xextended/cmdtrace Trace Tcl execution.
- Xextended/commandloop Create an interactive command loop.
- Xextended/copyfile Copy remainder of one open file into another.
- Xextended/cos Return the cosine of a number.
- Xextended/cosh Return the hyperbolic cosine of a number.
- Xextended/crange Return range of characters from string.
- Xextended/csubstr Return a substring from within a string.
- Xextended/ctype Determine if string has various characteristics.
- Xextended/dup Duplicate an open filehandle.
- Xextended/echo Echo one or more strings to stdout, followed by a newline.
- Xextended/execvp Perform a process exec, executing a file.
- Xextended/exp Return e to the power of a number.
- Xextended/fabs Return the absolute value of the floating point number.
- Xextended/fcntl Get or set open file access options.
- Xextended/floor Return the largest integer not greater than a floating point number.
- Xextended/fmod Perform a floating point modulus operation.
- Xextended/fmtclock Convert integer time to human-readable format.
- Xextended/fork Fork the current Tcl process.
- Xextended/fstat Obtain status information about a open file.
- Xextended/getclock Return current date and time as an integer value.
- Xextended/id Access, set or convert process, user and group information.
- Xextended/infox Return information about extended Tcl or the current application.
- Xextended/keyedlists Introduction to keyed lists
- Xextended/keyldel Delete a field of a keyed list.
- Xextended/keylget Get the value of a field of a keyed list.
- Xextended/keylset Set the value of a field of a keyed list.
- Xextended/kill Send a signal to the specified process.
- Xextended/lempty Determine if a list is empty.
- Xextended/link Make a link to a file.
- Xextended/log Return the natural logarithm of a number.
- Xextended/log10 Return the logarithm base 10 of a number.
- Xextended/loop Higher-performance for-style loop.
- Xextended/lvarpop Pop or replace the specified element from a list.
- Xextended/max Return the argument that has the highest numeric value.
- Xextended/min Return the argument that has the lowest numeric value.
- Xextended/mkdir Create a new directory
- Xextended/pipe Create a pipe.
- Xextended/pow Return a number to the power of another number.
- Xextended/random Return a pseudorandom integer or set the seed.
- Xextended/replicate Replicate string a number of times.
- Xextended/rmdir Remove directories
- Xextended/scancontext Manage file scan contexts.
- Xextended/scanfile Scan a file, executing match code when their patterns are matched.
- Xextended/scanmatch Specify tcl code to execute when scanfile pattern is matched.
- Xextended/select Synchronous I/O multiplexing.
- Xextended/signal Specify action to take when a signal is received.
- Xextended/sin Return the sin of a number.
- Xextended/sinh Return the hyperbolic sin of a number.
- Xextended/sleep Sleep Tcl for the specified number of seconds.
- Xextended/sqrt Return the square root of a number.
- Xextended/system Execute command via `system' call.
- Xextended/tan Return the tangent of a number.
- Xextended/tanh Return the hyperbolic tangent of a number.
- Xextended/times Get process and child execution times.
- Xextended/translit Translate characters in string according to patterns.
- Xextended/umask Get or set the file-creation mode mask.
- Xextended/unlink Delete (unlink) files.
- Xextended/wait Wait for a child process to terminate.
- Xhelp Tcl shell help facility.
- Xintro/backslash Tcl backslash substitution.
- Xintro/braces Grouping arguments with braces.
- Xintro/brackets Command substitution with brackets.
- Xintro/comments Inserting comments in Tcl code.
- Xintro/data_types Tcl data types.
- Xintro/dollar Variable Substitution With $.
- Xintro/double_quotes Grouping arguments with double-quotes.
- Xintro/expressions Tcl expressions.
- Xintro/procedures Tcl procedures.
- Xintro/regexps Regular expressions.
- Xintro/results Results of a command execution.
- Xintro/semi-colons Separating commands with semi-colons.
- Xintro/syntax Basic Tcl command syntax.
- Xintro/variables Tcl variables and arrays.
- Xmisc/memory display and debug memory problems
- Xtcl.tlib/assign_fields Assign successive elements in a list to specified variables.
- Xtcl.tlib/dirs List the directories in the directory stack.
- Xtcl.tlib/edprocs Edit named procs, or all procs.
- Xtcl.tlib/for_array_keys Do a foreach-style loop on each key in an array.
- Xtcl.tlib/for_file Do a foreach-style loop on each line in a file.
- Xtcl.tlib/for_recursive_glob Perform a foreach-style loop for all globbed files and directories.
- Xtcl.tlib/intersect Return a list containing every element present in both lists.
- Xtcl.tlib/intersect3 Return three lists from an intersection of two lists.
- Xtcl.tlib/lrmdups Given a list, remove all of the duplicated elements.
- Xtcl.tlib/popd Pop a directory from a stack of directories and cd to it.
- Xtcl.tlib/pushd Push a directory to a stack of directories.
- Xtcl.tlib/read_file Read in a file to a string (less overhead than "exec cat").
- Xtcl.tlib/recursive_glob Do filename globbing, recursively descending all matched directories.
- Xtcl.tlib/saveprocs Save named procs to a file, or all procs.
- Xtcl.tlib/showproc List the definition of the named procedure.
- Xtcl.tlib/showprocs List the definition of the named, or all, procedures.
- Xtcl.tlib/union Return the logical union of two lists.
- Xtcl.tlib/write_file Write a string out as a file.
- Xtclshell/autoload Autoloading of commands.
- Xtclshell/autoprocs List names of autload and package library procs.
- Xtclshell/buildpackageindex Build an index to a package library.
- Xtclshell/demand_load Force an autoload proc or a package to be loaded.
- Xtclshell/flags Tcl shell command line flags.
- Xtclshell/initialize Tcl shell initialization sequence.
- Xtclshell/intro Introduction to the tcl shell.
- Xtclshell/load Search the TCLPATH for a file to source.
- Xtclshell/loadlibindex Load the index of a package library
- Xtclshell/packagelib Tcl shell package libraries.
- Xtclshell/packages List all known packages.
- Xtclshell/results Tcl shell command result processsing.
- Xtclshell/tclinit Tcl shell initialization file.
- Xtclshell/unixcommands Tcl shell Unix command execution.
- Xtclshell/utilprocs Search a path list for a file.
- Xtclshell/variables Tcl shell variables.
- END_OF_FILE
- if test 9981 -ne `wc -c <'extended/tcllib/help/brief'`; then
- echo shar: \"'extended/tcllib/help/brief'\" unpacked with wrong size!
- fi
- # end of 'extended/tcllib/help/brief'
- fi
- if test -f 'extended/tests/chmod.test' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'extended/tests/chmod.test'\"
- else
- echo shar: Extracting \"'extended/tests/chmod.test'\" \(10272 characters\)
- sed "s/^X//" >'extended/tests/chmod.test' <<'END_OF_FILE'
- X#
- X# chmod.test
- X#
- X# Tests for the chmod, chown and chgrp commands.
- X#---------------------------------------------------------------------------
- X# Copyright 1991 Karl Lehenbauer and Mark Diekhans.
- X#
- X# Permission to use, copy, modify, and distribute this software and its
- X# documentation for any purpose and without fee is hereby granted, provided
- X# that the above copyright notice appear in all copies. Karl Lehenbauer and
- X# Mark Diekhans make no representations about the suitability of this
- X# software for any purpose. It is provided "as is" without express or
- X# implied warranty.
- X#
- Xif {[info procs test] != "test"} then {source defs}
- X
- X#-----------------------------------------------------------------------------
- X# This routine to the the mode of a file. It is returned formated in octal.
- X
- Xproc GetMode {filename} {
- X file stat $filename stat
- X return [format "%o" [expr {$stat(mode) & 07777}]]
- X}
- X
- X#-----------------------------------------------------------------------------
- X# Certain Unix systems don't handle chmod the same. This routine test if the
- X# system chmod produces the expected results.
- X# o mode - symbolic mode to set the file to.
- X# o expect - expected result from ls.
- X#
- Xproc CheckChmod {mode expect} {
- X chmod 000 CHMOD-CHECK.TMP
- X exec chmod $mode CHMOD-CHECK.TMP
- X set sysMode [lindex [exec ls -l CHMOD-CHECK.TMP] 0]
- X return [expr {"$sysMode" == "$expect"}]
- X}
- X
- X
- X#-----------------------------------------------------------------------------
- X# Procedure to return the owner id and group id of a file as a list
- X
- Xproc GetOwner {file} {
- X file stat $file stat
- X return [list $stat(uid) $stat(gid)]
- X}
- X
- X#-----------------------------------------------------------------------------
- X# If a user does not have a group name assigned, then some tests will not work,
- X# just blow off the tests and let the user make things right.
- X
- Xif {[catch {id group}] != 0} {
- X echo "User '[id user]' does not have group name. Chmod tests skipped"
- X return
- X}
- X
- X# Create the test files.
- X
- Xexec touch CHMOD-CHECK.TMP CHMOD-TEST.TMP CHMOD-TEST2.TMP
- X
- X# Set the umask so that no bits are masked. Some system chmods use umask
- X# if u, g, o or a are not specified in a symbolic chmod.
- X
- Xumask 000
- X
- Xtest chmod-1.1 {chmod absolute mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod 101 CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {101}
- X
- Xtest chmod-1.2 {chmod absolute mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod 010 CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {10}
- X
- Xtest chmod-1.3 {chmod absolute mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod 777 CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {777}
- X
- Xtest chmod-1.4 {chmod absolute mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod 666 CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {666}
- X
- Xtest chmod-1.5 {chmod absolute mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod 705 CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {705}
- X
- Xtest chmod-1.7 {chmod absolute mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod 4111 CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {4111}
- X
- Xtest chmod-2.1 {chmod absolute integer mode tests} {
- X chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -i 65 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
- X} {101 101}
- X
- Xtest chmod-2.2 {chmod absolute integer mode tests} {
- X chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -i 8 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
- X} {10 10}
- X
- Xtest chmod-2.3 {chmod absolute integer mode tests} {
- X chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -i 511 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
- X} {777 777}
- X
- Xtest chmod-2.4 {chmod absolute integer mode tests} {
- X chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -i 438 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
- X} {666 666}
- X
- Xtest chmod-2.5 {chmod absolute integer mode tests} {
- X chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -i 453 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
- X} {705 705}
- X
- Xtest chmod-2.6 {chmod absolute integer mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod -i 2121 CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {4111}
- X
- X# Test symbolic mode.
- X
- Xtest chmod-3.1 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod +r CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {444}
- X
- Xtest chmod-3.2 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod +r CHMOD-TEST.TMP
- X chmod +w CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {666}
- X
- Xtest chmod-3.3 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod +r CHMOD-TEST.TMP
- X chmod +w CHMOD-TEST.TMP
- X chmod +x CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {777}
- X
- Xtest chmod-3.4 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod +r CHMOD-TEST.TMP
- X chmod +w CHMOD-TEST.TMP
- X chmod +x CHMOD-TEST.TMP
- X chmod -r CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {333}
- X
- Xtest chmod-3.5 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod +r CHMOD-TEST.TMP
- X chmod +w CHMOD-TEST.TMP
- X chmod +x CHMOD-TEST.TMP
- X chmod -r CHMOD-TEST.TMP
- X chmod -w CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {111}
- X
- Xtest chmod-3.6 {chmod symbolic mode tests} {
- X chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod +r {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod +w {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod +x {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -r {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -w {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod -x {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
- X} {0 0}
- X
- Xtest chmod-3.7 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod u+x,g+x CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {110}
- X
- Xtest chmod-3.8 {chmod symbolic mode tests} {
- X chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod u+x,g+x {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X chmod u-x,g-x {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
- X} {0 0}
- X
- X# Cann't +s on some systems
- X
- Xif [CheckChmod "ugo+x,ug+s" "---s--s--x"] {
- X test chmod-3.9 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod ugo+x,ug+s CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X } {6111}
- X}
- X
- Xtest chmod-3.10 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod a+rwx CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {777}
- X
- Xtest chmod-3.11 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod a+rwx CHMOD-TEST.TMP
- X chmod a-rw CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {111}
- X
- Xtest chmod-3.12 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod a=rwx CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {777}
- X
- Xtest chmod-3.13 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod u+t CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {0}
- X
- X# +t is dificult to test if not root, just make sure it execute and hope
- X# for the best.
- X
- Xtest chmod-3.14 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X catch {chmod u+t CHMOD-TEST.TMP}
- X} {0}
- X
- Xtest chmod-3.15 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X list [catch {chmod u+t CHMOD-TEST.TMP}] \
- X [catch {chmod u-t CHMOD-TEST.TMP}]
- X} {0 0}
- X
- Xtest chmod-3.16 {chmod symbolic mode tests} {
- X chmod 000 CHMOD-TEST.TMP
- X chmod a+rwx CHMOD-TEST.TMP
- X chmod u-r,g-w,o-x CHMOD-TEST.TMP
- X GetMode CHMOD-TEST.TMP
- X} {356}
- X
- Xtest chmod-4.1 {chmod error tests} {
- X list [catch {chmod +z CHMOD-TEST.TMP} msg] $msg
- X} {1 {invalid file mode}}
- X
- Xtest chmod-4.2 {chmod error tests} {
- X list [catch {chmod} msg] $msg
- X} {1 {wrong # args: chmod [-i] mode filelist}}
- X
- X# chown and chgrp tests
- X
- Xset uidGidPairs [list [list [id userid] [id groupid]] \
- X [list [id userid] [id groupid]]]
- X
- Xtest chmod-5.1 {chown tests} {
- X chown [id user] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
- X} $uidGidPairs
- X
- Xtest chmod-5.2 {chown tests} {
- X chown [id userid] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
- X} $uidGidPairs
- X
- X
- Xtest chmod-5.3 {chown tests} {
- X chown [list [id userid] [id groupid]] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
- X} $uidGidPairs
- X
- Xtest chmod-5.4 {chown tests} {
- X chown [list [id user] [id group]] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
- X} $uidGidPairs
- X
- Xtest chmod-5.5 {chown tests} {
- X chown [list [id user] [id group]] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
- X} $uidGidPairs
- X
- Xtest chmod-6.1 {chown error tests} {
- X list [catch {chown XXXXXXXXX CHMOD-TEST.TMP} msg] $msg
- X} {1 {unknown user id: XXXXXXXXX}}
- X
- Xtest chmod-6.2 {chown error tests} {
- X list [catch {chown [list XXXXXXXXX [id groupid]] CHMOD-TEST.TMP} msg] $msg
- X} {1 {unknown user id: XXXXXXXXX}}
- X
- Xtest chmod-6.3 {chown error tests} {
- X list [catch {chown [list [id user] XXXXXXXXX] CHMOD-TEST.TMP} msg] $msg
- X} {1 {unknown group id: XXXXXXXXX}}
- X
- Xtest chmod-6.4 {chown error tests} {
- X list [catch {chown {XXXXXXXXX YYYY} CHMOD-TEST.TMP} msg] $msg
- X} {1 {unknown user id: XXXXXXXXX}}
- X
- Xtest chmod-6.5 {chown error tests} {
- X list [catch {chown} msg] $msg
- X} {1 {wrong # args: chown owner|{owner group} filelist}}
- X
- Xtest chmod-7.1 {chgrp tests} {
- X chgrp [id group] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
- X} $uidGidPairs
- X
- Xtest chmod-7.2 {chgrp tests} {
- X chgrp [id groupid] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
- X} $uidGidPairs
- X
- Xtest chmod-8.1 {chgrp error tests} {
- X list [catch {chgrp} msg] $msg
- X} {1 {wrong # args: chgrp group filelist}}
- X
- Xtest chmod-8.2 {chgrp error tests} {
- X list [catch {chgrp XXXXXXXXX CHMOD-TEST.TMP} msg] $msg
- X} {1 {unknown group id: XXXXXXXXX}}
- X
- Xunlink {CHMOD-CHECK.TMP CHMOD-TEST.TMP CHMOD-TEST2.TMP}
- X
- END_OF_FILE
- if test 10272 -ne `wc -c <'extended/tests/chmod.test'`; then
- echo shar: \"'extended/tests/chmod.test'\" unpacked with wrong size!
- fi
- # end of 'extended/tests/chmod.test'
- fi
- if test -f 'extended/tests/unixcmds.test' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'extended/tests/unixcmds.test'\"
- else
- echo shar: Extracting \"'extended/tests/unixcmds.test'\" \(10954 characters\)
- sed "s/^X//" >'extended/tests/unixcmds.test' <<'END_OF_FILE'
- X#
- X# unixcmds.test
- X#
- X# Tests for the fork, execvp, wait, kill, link, unlink, times, umask, system,
- X# signal, and sleep commands.
- X#---------------------------------------------------------------------------
- X# Copyright 1991 Karl Lehenbauer and Mark Diekhans.
- X#
- X# Permission to use, copy, modify, and distribute this software and its
- X# documentation for any purpose and without fee is hereby granted, provided
- X# that the above copyright notice appear in all copies. Karl Lehenbauer and
- X# Mark Diekhans make no representations about the suitability of this
- X# software for any purpose. It is provided "as is" without express or
- X# implied warranty.
- X#
- Xif {[info procs test] != "test"} then {source defs}
- X
- X# Test fork, execvp, wait and kill commands.
- X
- Xset newPid [fork]
- Xif {$newPid == 0} {
- X execvp ../tcl "-qc sleep 1;exit 12"
- X error "Should never make it here"
- X}
- Xtest unix-cmds-1.1 {fork, execvp, wait and kill tests} {
- X wait $newPid
- X} "$newPid EXIT 12"
- X
- Xtest unix-cmds-1.2 {fork, execvp, wait and kill tests} {
- X list [catch {kill} msg] $msg
- X} {1 {wrong # args: kill [signal] processlist}}
- X
- Xset newPid [fork]
- Xif {$newPid == 0} {
- X execvp ../tcl "-qc catch {while {1} {sleep 1}}; exit 10"
- X error "Should never make it here"
- X}
- Xsleep 1
- X
- Xtest unix-cmds-1.3 {fork, execvp, wait and kill tests} {
- X kill $newPid
- X wait $newPid
- X} "$newPid SIG SIGTERM"
- X
- X# Try kill of multiple processes; the test is complicated by the fact that
- X# either process could die first.
- X
- Xset newPid1 [fork]
- Xif {$newPid1 == 0} {
- X execvp ../tcl "-qc catch {while {1} {sleep 1}}; exit 10"
- X error "should never make it here #1"
- X}
- X
- Xset newPid2 [fork]
- Xif {$newPid2 == 0} {
- X execvp ../tcl "-qc catch {while {1} {sleep 1}}; exit 10"
- X error "should never make it here #2"
- X}
- X
- Xtest unix-cmds-1.4 {fork, execvp, wait and kill tests} {
- X sleep 3
- X
- X kill [list $newPid1 $newPid2]
- X
- X set result1 [wait [list $newPid1 $newPid2]]
- X if {[lindex $result1 0] == $newPid1} {
- X set result2 [wait $newPid2]
- X } else {
- X set result2 [wait $newPid1]
- X }
- X lsort [list $result1 $result2]
- X} [lsort [list "$newPid1 SIG SIGTERM" "$newPid2 SIG SIGTERM"]]
- X
- Xtest unix-cmds-1.5 {fork, execvp, wait and kill tests} {
- X list [catch {fork foo} msg] $msg
- X} {1 {wrong # args: fork}}
- X
- Xtest unix-cmds-1.6 {fork, execvp, wait and kill tests} {
- X list [catch {wait baz} msg] $msg
- X} {1 {expected integer but got "baz"}}
- X
- Xsignal error SIGINT
- X
- Xtest unix-cmds-1.7 {fork, execvp, wait and kill tests} {
- X list [catch {kill 2 [id process]} msg] $msg
- X} {1 {SIGINT signal received}}
- X
- Xtest unix-cmds-1.8 {fork, execvp, wait and kill tests} {
- X list [catch {kill INT [id process]} msg] $msg
- X} {1 {SIGINT signal received}}
- X
- Xtest unix-cmds-1.9 {fork, execvp, wait and kill tests} {
- X list [catch {kill SIGINT [id process]} msg] $msg
- X} {1 {SIGINT signal received}}
- X
- Xtest unix-cmds-1.10 {fork, execvp, wait and kill tests} {
- X list [catch {kill SIGINT [id process]} msg] $msg
- X} {1 {SIGINT signal received}}
- X
- Xtest unix-cmds-1.11 {fork, execvp, wait and kill tests} {
- X list [catch {kill 10000 [id process]} msg] $msg
- X} {1 {kill: invalid signal}}
- X
- Xtest unix-cmds-1.12 {fork, execvp, wait and kill tests} {
- X list [catch {kill SIGFOO [id process]} msg] $msg
- X} {1 {kill: invalid signal}}
- X
- Xtest unix-cmds-1.13 {fork, execvp, wait and kill tests} {
- X kill 0 [id process]
- X} {}
- X
- X# Test link and unlink commands.
- X
- Xtest unix-cmds-2.1 {link and unlink tests} {
- X set fh [open LINK1.TMP w]
- X puts $fh "Hello, world"
- X close $fh
- X link LINK1.TMP LINK2.TMP
- X file stat LINK1.TMP stat
- X set ino1 $stat(ino)
- X set dev1 $stat(dev)
- X file stat LINK2.TMP stat
- X set ino2 $stat(ino)
- X set dev2 $stat(dev)
- X set result [list [file exists LINK2.TMP] [expr $ino1==$ino2] \
- X [expr $dev1==$dev2]]
- X unlink {LINK1.TMP LINK2.TMP}
- X set result
- X} {1 1 1}
- X
- Xtest unix-cmds-2.2 {link and unlink tests} {
- X list [catch {link LINK1.TMP LINK2.TMP} msg] [string tolower $msg]
- X} {1 {link: no such file or directory}}
- X
- Xtest unix-cmds-2.3 {link and unlink tests} {
- X list [catch {link} msg] $msg
- X} {1 {wrong # args: link srcpath destpath}}
- X
- X# Test unlink command.
- X
- Xtest unix-cmds-2.4 {unlink and unlink tests} {
- X set fh [open UNLINK.TMP w]
- X puts $fh "Hello, world"
- X close $fh
- X unlink UNLINK.TMP
- X file exists UNLINK.TMP
- X} {0}
- X
- Xtest unix-cmds-2.5 {unlink and unlink tests} {
- X list [catch {unlink UNLINK.TMP} msg] [string tolower $msg]
- X} {1 {unlink: unlink.tmp: no such file or directory}}
- X
- Xtest unix-cmds-2.6 {unlink and unlink tests} {
- X list [catch {unlink} msg] $msg
- X} {1 {wrong # args: unlink filelist}}
- X
- X# Test the times command (the best we can).
- X
- Xtest unix-cmds-3.1 {times tests} {
- X llength [times]
- X} {4}
- X
- Xtest unix-cmds-3.2 {times tests} {
- X list [catch {times foo} msg] $msg
- X} {1 {wrong # args: times}}
- X
- X# Test umask command.
- X
- Xtest unix-cmds-4.1 {umask tests} {
- X set oldMask [umask]
- X umask 666
- X set newMask [umask]
- X umask $oldMask
- X set newMask
- X} {666}
- X
- Xtest unix-cmds-4.2 {umask tests} {
- X list [catch {umask 999} msg] $msg
- X} {1 {Expected octal number got: 999}}
- X
- Xtest unix-cmds-4.3 {umask tests} {
- X list [catch {umask 7 7} msg] $msg
- X} {1 {wrong # args: umask octalmask}}
- X
- X# Test the system command
- X
- Xtest unix-cmds-5.1 {system tests} {
- X system "ls / >/dev/null"
- X} {0}
- X
- Xtest unix-cmds-5.2 {system tests} {
- X list [catch {system} msg] $msg
- X} {1 {wrong # args: system command}}
- X
- X# Test the signal command
- X
- Xtest unix-cmds-6.1 {signal tests} {
- X signal ignore SIGHUP
- X list [catch {kill HUP [id process]} msg] $msg
- X} {0 {}}
- X
- Xtest unix-cmds-6.2 {signal tests} {
- X global errorInfo
- X set errorInfo {}
- X signal error HUP
- X proc KillMe3 {} {kill SIGHUP [id process]}
- X proc KillMe2 {} {KillMe3}
- X proc KillMe1 {} {KillMe2}
- X list [catch {KillMe1} msg] $msg $errorInfo
- X} {1 {SIGHUP signal received} {SIGHUP signal received
- X while executing
- X"kill SIGHUP [id process]"
- X (procedure "KillMe3" line 1)
- X invoked from within
- X"KillMe3"
- X (procedure "KillMe2" line 1)
- X invoked from within
- X"KillMe2"
- X (procedure "KillMe1" line 1)
- X invoked from within
- X"KillMe1"}}
- X
- Xtest unix-cmds-6.3 {signal tests} {
- X signal error HUP SIGINT
- X set one [list [catch {kill HUP [id process]} msg] $msg]
- X set two [list [catch {kill INT [id process]} msg] $msg]
- X list $one $two
- X} {{1 {SIGHUP signal received}} {1 {SIGINT signal received}}}
- X
- Xtest unix-cmds-6.4 {signal tests} {
- X set signalWeGot {}
- X signal trap 1 {set signalWeGot $signalRecieved}
- X kill SIGHUP [id process]
- X signal default 1
- X set signalWeGot
- X} {SIGHUP}
- X
- Xtest unix-cmds-6.5 {signal tests} {
- X signal default {SIGHUP SIGINT}
- X signal get {SIGHUP SIGINT}
- X} {default default}
- X
- Xtest unix-cmds-6.6 {signal tests} {
- X signal default SIGHUP
- X signal ignore SIGINT
- X signal get {SIGHUP SIGINT}
- X} {default ignore}
- X
- Xtest unix-cmds-6.7 {signal tests} {
- X signal trap {SIGHUP SIGINT} {error "Should not get this signal"}
- X signal get {SIGHUP SIGINT}
- X} {trap trap}
- X
- Xtest unix-cmds-6.8 {signal tests} {
- X signal error {SIGHUP SIGINT}
- X signal get {SIGHUP SIGINT}
- X} {error error}
- X
- Xtest unix-cmds-6.9 {signal tests} {
- X global errorInfo
- X set errorInfo {}
- X proc KillMe3 {} {kill SIGHUP [id process]}
- X proc KillMe2 {} {KillMe3}
- X proc KillMe1 {} {KillMe2}
- X signal trap SIGHUP {error "Blew it in the trap code"}
- X list [catch {KillMe1} msg ] $msg $errorInfo
- X} {1 {Blew it in the trap code} {Blew it in the trap code
- X while executing
- X"error "Blew it in the trap code""
- X while executing signal trap code for SIGHUP signal
- X invoked from within
- X"kill SIGHUP [id process]"
- X (procedure "KillMe3" line 1)
- X invoked from within
- X"KillMe3"
- X (procedure "KillMe2" line 1)
- X invoked from within
- X"KillMe2"
- X (procedure "KillMe1" line 1)
- X invoked from within
- X"KillMe1"}}
- X
- Xtest unix-cmds-6.10 {signal tests} {
- X list [catch {signal} msg] $msg
- X} {1 {wrong # args: signal action signalList [commands]}}
- X
- Xtest unix-cmds-6.11 {signal tests} {
- X list [catch {signal ignore foo} msg] $msg
- X} {1 {invalid signal name: foo}}
- X
- X#
- X# Complex test for the death of a child.
- X#
- X
- Xproc PollSigChld {} {
- X global G_gotChild
- X set sleepCnt 0
- X while {!$G_gotChild} {
- X incr sleepCnt
- X if {$sleepCnt > 90} {
- X error "unix-cmds-6.12: SIGCHLD for pid=$childPid lost"
- X }
- X sleep 1
- X }
- X}
- X
- Xproc ForkChild {exitCode} {
- X flush stdout ;# Not going to exec, must clean up the buffers.
- X flush stderr
- X set childPid [fork]
- X if {$childPid == 0} {
- X exit $exitCode
- X }
- X return $childPid
- X}
- X
- Xtest unix-cmds-6.12 {signal tests} {
- X global G_gotChild
- X set G_gotChild 0
- X signal trap SIGCHLD {global G_gotChild;set G_gotChild 1;sleep 1}
- X # Fork two childern
- X set pidList [list [ForkChild 123] [ForkChild 111]]
- X PollSigChld
- X
- X # Wait on one process and delete if from the list.
- X set status1 [wait $pidList]
- X lvarpop pidList [lsearch $pidList [lindex $status1 0]]
- X
- X # Wait on the second child
- X set G_gotChild 0
- X signal trap SIGCHLD {global G_gotChild;set G_gotChild 1}
- X set status2 [wait $pidList]
- X
- X signal default SIGCHLD
- X
- X lsort [list [lindex $status1 2] [lindex $status2 2]]
- X} {111 123}
- X
- X# Test the sleep command, as well as we can.
- X
- Xtest unix-cmds-7.1 {sleep tests} {
- X sleep 1
- X} {}
- X
- Xtest unix-cmds-7.2 {sleep tests} {
- X list [catch {sleep} msg] $msg
- X} {1 {wrong # args: sleep seconds}}
- X
- X# Test mkdir and rmdir commands.
- X
- Xtest unix-cmds-8.1 {mkdir and rmdir tests} {
- X catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
- X mkdir {MKDIR1.TMP MKDIR2.TMP}
- X set result [list [file isdirectory MKDIR1.TMP] \
- X [file isdirectory MKDIR2.TMP]]
- X catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
- X set result
- X} {1 1}
- X
- Xtest unix-cmds-8.2 {mkdir and rmdir tests} {
- X catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
- X mkdir -path MKDIR1.TMP/a/b/c
- X set result [file isdirectory MKDIR1.TMP/a/b/c]
- X catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
- X set result
- X} {1}
- X
- Xtest unix-cmds-8.3 {mkdir and rmdir tests} {
- X catch {mkdir {MKDIR1.TMP MKDIR2.TMP}}
- X rmdir {MKDIR1.TMP MKDIR2.TMP}
- X list [file isdirectory MKDIR1.TMP] [file isdirectory MKDIR2.TMP]
- X} {0 0}
- X
- Xtest unix-cmds-8.4 {mkdir and rmdir tests} {
- X catch {mkdir MKDIR1.TMP}
- X set result [list [catch {mkdir MKDIR1.TMP} msg] [string tolower $msg]]
- X catch {rmdir MKDIR1.TMP}
- X set result
- X} {1 {mkdir: mkdir1.tmp: file exists}}
- X
- Xtest unix-cmds-8.5 {mkdir and rmdir tests} {
- X list [catch {mkdir} msg] $msg
- X} {1 {wrong # args: mkdir [-path] dirlist}}
- X
- Xtest unix-cmds-8.6 {mkdir and rmdir tests} {
- X catch {rmdir MKDIR1.TMP}
- X set result [list [catch {rmdir MKDIR1.TMP} msg] [string tolower $msg]]
- X set result
- X} {1 {rmdir: mkdir1.tmp: no such file or directory}}
- X
- Xtest unix-cmds-8.7 {mkdir and rmdir tests} {
- X list [catch {rmdir} msg] $msg
- X} {1 {wrong # args: rmdir dirlist}}
- X
- X
- X
- END_OF_FILE
- if test 10954 -ne `wc -c <'extended/tests/unixcmds.test'`; then
- echo shar: \"'extended/tests/unixcmds.test'\" unpacked with wrong size!
- fi
- # end of 'extended/tests/unixcmds.test'
- fi
- echo shar: End of archive 12 \(of 23\).
- cp /dev/null ark12isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 23 archives.
- echo "Now cd to "extended", edit the makefile, then do a "make""
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-