home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / tclx / part12 < prev    next >
Encoding:
Text File  |  1991-11-19  |  46.2 KB  |  1,391 lines

  1. Newsgroups: comp.sources.misc
  2. From: karl@sugar.neosoft.com (Karl Lehenbauer)
  3. Subject:  v26i012:  tclx - extensions and on-line help for tcl 6.1, Part12/23
  4. Message-ID: <1991Nov19.135344.884@sparky.imd.sterling.com>
  5. X-Md4-Signature: 945da10336be275391c8af059ff01fa7
  6. Date: Tue, 19 Nov 1991 13:53:44 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: karl@sugar.neosoft.com (Karl Lehenbauer)
  10. Posting-number: Volume 26, Issue 12
  11. Archive-name: tclx/part12
  12. Environment: UNIX
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then unpack
  16. # it by saving it into a file and typing "sh file".  To overwrite existing
  17. # files, type "sh file -c".  You can also feed this as standard input via
  18. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  19. # will see the following message at the end:
  20. #        "End of archive 12 (of 23)."
  21. # Contents:  extended/src/cmdloop.c extended/tcllib/help/brief
  22. #   extended/tests/chmod.test extended/tests/unixcmds.test
  23. # Wrapped by karl@one on Wed Nov 13 21:50:24 1991
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. if test -f 'extended/src/cmdloop.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'extended/src/cmdloop.c'\"
  27. else
  28. echo shar: Extracting \"'extended/src/cmdloop.c'\" \(11049 characters\)
  29. sed "s/^X//" >'extended/src/cmdloop.c' <<'END_OF_FILE'
  30. X/* 
  31. X * cmdloop --
  32. X *
  33. X *   Interactive command loop, C and Tcl callable.
  34. X *---------------------------------------------------------------------------
  35. X * Copyright 1991 Karl Lehenbauer and Mark Diekhans.
  36. X *
  37. X * Permission to use, copy, modify, and distribute this software and its
  38. X * documentation for any purpose and without fee is hereby granted, provided
  39. X * that the above copyright notice appear in all copies.  Karl Lehenbauer and
  40. X * Mark Diekhans make no representations about the suitability of this
  41. X * software for any purpose.  It is provided "as is" without express or
  42. X * implied warranty.
  43. X */
  44. X
  45. X#include "tclExtdInt.h"
  46. X
  47. X
  48. X/*
  49. X * Pointer to eval procedure to use.  This way bring in the history module
  50. X * from a library can be made optional.  This only works because the calling
  51. X * sequence of Tcl_Eval is a superset of Tcl_RecordAndEval.  This defaults
  52. X * to no history, set this variable to Tcl_RecordAndEval to use history.
  53. X */
  54. X
  55. Xint (*tclShellCmdEvalProc) () = Tcl_Eval;
  56. X
  57. X/*
  58. X * Prototypes of internal functions.
  59. X */
  60. Xint
  61. XIsSetVarCmd _ANSI_ARGS_((Tcl_Interp *interp,
  62. X                         char       *command));
  63. X
  64. Xvoid
  65. XOutStr _ANSI_ARGS_((FILE *filePtr,
  66. X                    char *string));
  67. X
  68. Xvoid
  69. XOutFlush _ANSI_ARGS_((FILE *filePtr));
  70. X
  71. Xvoid
  72. XTcl_PrintResult _ANSI_ARGS_((FILE   *fp,
  73. X                             int     returnval,
  74. X                             char   *resultText));
  75. X
  76. Xvoid
  77. XOutputPrompt _ANSI_ARGS_((Tcl_Interp *interp,
  78. X                          FILE       *outFP,
  79. X                          int         topLevel));
  80. X
  81. Xint
  82. XSetPromptVar _ANSI_ARGS_((Tcl_Interp  *interp,
  83. X                          char        *hookVarName,
  84. X                          char        *newHookValue,
  85. X                          char       **oldHookValuePtr));
  86. X
  87. X
  88. X/*
  89. X *----------------------------------------------------------------------
  90. X *
  91. X * IsSetVarCmd --
  92. X *
  93. X *      Determine if the current command is a `set' command that set
  94. X *      a variable (i.e. two arguments).  This routine should only be
  95. X *      called if the command returned TCL_OK, due to it calling
  96. X *      Tcl_SplitList, which might alter the interpreter in the result
  97. X *      buffer if the command is not a valid list.
  98. X *
  99. X *----------------------------------------------------------------------
  100. X */
  101. Xstatic int
  102. XIsSetVarCmd (interp, command)
  103. X    Tcl_Interp *interp;
  104. X    char       *command;
  105. X{
  106. X    int    cmdArgc;
  107. X    char **cmdArgv;
  108. X    int    isSet;
  109. X
  110. X    if ((!STRNEQU (command, "set", 3)) || (!isspace (command [3])))
  111. X        return FALSE;  /* Quick check */
  112. X    if (Tcl_SplitList (interp, command, &cmdArgc, &cmdArgv) != TCL_OK)
  113. X       return FALSE;
  114. X    isSet = STREQU (cmdArgv[0], "set") && (cmdArgc >= 3);
  115. X    ckfree ((char *) cmdArgv);
  116. X    return isSet;
  117. X
  118. X}
  119. X
  120. X/*
  121. X *----------------------------------------------------------------------
  122. X *
  123. X * OutStr --
  124. X *
  125. X *   Print a string to the specified file handle and check for errors.
  126. X *
  127. X *----------------------------------------------------------------------
  128. X */
  129. Xstatic void
  130. XOutStr (filePtr, string)
  131. X    FILE *filePtr;
  132. X    char *string;
  133. X{
  134. X    int stat;
  135. X
  136. X    stat = fputs (string, filePtr);
  137. X    if (stat == EOF)
  138. X        panic ("command loop: error writting to output file: %s\n",
  139. X               strerror (errno));
  140. X}
  141. X
  142. X/*
  143. X *----------------------------------------------------------------------
  144. X *
  145. X * OutFlush --
  146. X *
  147. X *   Flush a stdio file and check for errors.
  148. X *
  149. X *----------------------------------------------------------------------
  150. X */
  151. Xstatic void
  152. XOutFlush (filePtr)
  153. X    FILE *filePtr;
  154. X{
  155. X    int stat;
  156. X
  157. X    stat = fflush (filePtr);
  158. X    if (stat == EOF)
  159. X        panic ("command loop: error flushing output file: %s\n",
  160. X               strerror (errno));
  161. X}
  162. X
  163. X/*
  164. X *----------------------------------------------------------------------
  165. X *
  166. X * Tcl_PrintResult --
  167. X *
  168. X *      Print a Tcl result
  169. X *
  170. X * Results:
  171. X *
  172. X *      Takes an open file pointer, a return value and some result
  173. X *      text.  Prints the result text if the return value is TCL_OK,
  174. X *      prints "Error:" and the result text if it's TCL_ERROR,
  175. X *      else prints "Bad return code:" and the result text.
  176. X *
  177. X *----------------------------------------------------------------------
  178. X */
  179. Xstatic void
  180. XTcl_PrintResult (fp, returnval, resultText)
  181. X    FILE   *fp;
  182. X    int     returnval;
  183. X    char   *resultText;
  184. X{
  185. X
  186. X    if (returnval == TCL_OK) {
  187. X        if (resultText [0] != '\0') {
  188. X            OutStr (fp, resultText);
  189. X            OutStr (fp, "\n");
  190. X        }
  191. X    } else {
  192. X        OutFlush (fp);
  193. X        OutStr (stderr, (returnval == TCL_ERROR) ? "Error" : 
  194. X                                                   "Bad return code");
  195. X        OutStr (stderr, ": ");
  196. X        OutStr (stderr, resultText);
  197. X        OutStr (stderr, "\n");
  198. X    }
  199. X}
  200. X
  201. X/*
  202. X *----------------------------------------------------------------------
  203. X *
  204. X * OutputPrompt --
  205. X *     Outputs a prompt by executing either the command string in
  206. X *     TCLENV(topLevelPromptHook) or TCLENV(downLevelPromptHook).
  207. X *
  208. X *----------------------------------------------------------------------
  209. X */
  210. Xstatic void
  211. XOutputPrompt (interp, outFP, topLevel)
  212. X    Tcl_Interp *interp;
  213. X    FILE       *outFP;
  214. X    int         topLevel;
  215. X{
  216. X    char *hookName;
  217. X    char *promptHook;
  218. X    int   result;
  219. X    int   promptDone = FALSE;
  220. X
  221. X    hookName = topLevel ? "topLevelPromptHook"
  222. X                        : "downLevelPromptHook";
  223. X    if (((promptHook = Tcl_GetVar2 (interp, "TCLENV", hookName, 1)) != 
  224. X          NULL) && (*promptHook != '\0')) {
  225. X        result = Tcl_Eval(interp, promptHook, 0, (char **)NULL);
  226. X        if (!((result == TCL_OK) || (result == TCL_RETURN))) {
  227. X            OutStr (stderr, "Error in prompt hook: ");
  228. X            OutStr (stderr, interp->result);
  229. X            OutStr (stderr, "\n");
  230. X            Tcl_PrintResult (outFP, result, interp->result);
  231. X        } else {
  232. X            OutStr (outFP, interp->result);
  233. X            promptDone = TRUE;
  234. X        }
  235. X    } 
  236. X    if (!promptDone) {
  237. X        if (topLevel)
  238. X            OutStr (outFP, "%");
  239. X        else
  240. X            OutStr (outFP, ">");
  241. X    }
  242. X    OutFlush (outFP);
  243. X
  244. X}
  245. X
  246. X/*
  247. X *----------------------------------------------------------------------
  248. X *
  249. X * Tcl_CommandLoop --
  250. X *
  251. X *      Run a Tcl command loop
  252. X *
  253. X * Results:
  254. X *
  255. X *      Takes an interpreter, in and out file handles and an
  256. X *      interactive flag and reads and executes everything
  257. X *      it reads from input.
  258. X *
  259. X *----------------------------------------------------------------------
  260. X */
  261. Xvoid
  262. XTcl_CommandLoop (interp, in, out, interactive)
  263. X    Tcl_Interp *interp;
  264. X    FILE       *in;
  265. X    FILE       *out;
  266. X    int         interactive;
  267. X{
  268. X    Tcl_CmdBuf cmdBuf;
  269. X    char       inputBuf[256];
  270. X    int        topLevel = TRUE;
  271. X    int        result;
  272. X    char      *cmd;
  273. X
  274. X    cmdBuf = Tcl_CreateCmdBuf();
  275. X
  276. X    while (TRUE) {
  277. X
  278. X        clearerr(in);
  279. X        clearerr(out);
  280. X        OutputPrompt (interp, out, topLevel);
  281. X        errno = 0;
  282. X        if (fgets(inputBuf, sizeof(inputBuf), in) == NULL) {
  283. X            if (!feof(in) && interactive && (errno == EINTR)) {
  284. X                Tcl_ResetSignals ();
  285. X                putchar('\n');
  286. X                continue;  /* Go get the next command */
  287. X            }
  288. X            if (ferror (in))
  289. X                panic ("command loop: error on input file: %s\n",
  290. X                       strerror (errno));
  291. X            goto endOfFile;
  292. X        }
  293. X        cmd = Tcl_AssembleCmd(cmdBuf, inputBuf);
  294. X
  295. X        if (cmd == NULL)
  296. X            topLevel = FALSE;
  297. X        else {
  298. X            result = (*tclShellCmdEvalProc) (interp, cmd, 0, (char **)NULL);
  299. X            if ((result != TCL_OK) || 
  300. X                   (interactive && !IsSetVarCmd (interp, cmd)))
  301. X                Tcl_PrintResult (out, result, interp->result);
  302. X
  303. X            topLevel = TRUE;
  304. X        }
  305. X    }
  306. XendOfFile:
  307. X    Tcl_DeleteCmdBuf(cmdBuf);
  308. X}
  309. X
  310. X/*
  311. X *----------------------------------------------------------------------
  312. X *
  313. X * SetPromptVar --
  314. X *     Set one of the prompt hook variables, saving a copy of the old
  315. X *     value, if it exists.
  316. X *
  317. X * Parameters:
  318. X *   o hookVarName (I) - The name of the prompt hook, which is an element
  319. X *     of the TCLENV array.  One of topLevelPromptHook or downLevelPromptHook.
  320. X *   o newHookValue (I) - The new value for the prompt hook.
  321. X *   o oldHookValuePtr (O) - If not NULL, then a pointer to a copy of the
  322. X *     old prompt value is returned here.  NULL is returned if there was not
  323. X *     old value.  This is a pointer to a malloc-ed string that must be
  324. X *     freed when no longer needed.
  325. X * Result:
  326. X *   TCL_OK if the hook variable was set ok, TCL_ERROR if an error occured.
  327. X *----------------------------------------------------------------------
  328. X */
  329. Xstatic int
  330. XSetPromptVar (interp, hookVarName, newHookValue, oldHookValuePtr)
  331. X    Tcl_Interp *interp;
  332. X    char       *hookVarName;
  333. X    char       *newHookValue;
  334. X    char      **oldHookValuePtr;
  335. X{
  336. X    char *hookValue;    
  337. X    char *oldHookPtr = NULL;
  338. X
  339. X    if (oldHookValuePtr != NULL) {
  340. X        hookValue = Tcl_GetVar2 (interp, "TCLENV", hookVarName, 
  341. X                                 TCL_GLOBAL_ONLY);
  342. X        if (hookValue != NULL) {
  343. X            oldHookPtr = ckalloc (strlen (hookValue) + 1);
  344. X            strcpy (oldHookPtr, hookValue);
  345. X        }
  346. X    }
  347. X    if (Tcl_SetVar2 (interp, "TCLENV", hookVarName, newHookValue, 
  348. X                     TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) == NULL) {
  349. X        if (oldHookPtr != NULL)
  350. X            ckfree (oldHookPtr);
  351. X        return TCL_ERROR;
  352. X    }    
  353. X    if (oldHookValuePtr != NULL)
  354. X        *oldHookValuePtr = oldHookPtr;
  355. X    return TCL_OK;
  356. X}
  357. X
  358. X/*
  359. X *----------------------------------------------------------------------
  360. X *
  361. X * Tcl_CommandloopCmd --
  362. X *     Implements the TCL commandloop command:
  363. X *       commandloop prompt prompt2
  364. X *
  365. X * Results:
  366. X *     Standard TCL results.
  367. X *
  368. X *----------------------------------------------------------------------
  369. X */
  370. Xint
  371. XTcl_CommandloopCmd(clientData, interp, argc, argv)
  372. X    ClientData  clientData;
  373. X    Tcl_Interp *interp;
  374. X    int         argc;
  375. X    char      **argv;
  376. X{
  377. X    char *oldTopLevelHook  = NULL;
  378. X    char *oldDownLevelHook = NULL;
  379. X    int   result = TCL_ERROR;
  380. X
  381. X    if (argc > 3) {
  382. X        Tcl_AppendResult (interp, "wrong # args: ", argv[0],
  383. X                          " [prompt] [prompt2]", (char *) NULL);
  384. X        return TCL_ERROR;
  385. X    }
  386. X    if (argc > 1) {
  387. X        if (SetPromptVar (interp, "topLevelPromptHook", argv[1],
  388. X                          &oldTopLevelHook) != TCL_OK)
  389. X            goto exitPoint;
  390. X    }
  391. X    if (argc > 2) {
  392. X        if (SetPromptVar (interp, "downLevelPromptHook", argv[2], 
  393. X                          &oldDownLevelHook) != TCL_OK)
  394. X            goto exitPoint;
  395. X    }
  396. X
  397. X    Tcl_CommandLoop (interp, stdin, stdout, TRUE);
  398. X
  399. X    if (oldTopLevelHook != NULL)
  400. X        SetPromptVar (interp, "topLevelPromptHook", oldTopLevelHook, NULL);
  401. X    if (oldDownLevelHook != NULL)
  402. X        SetPromptVar (interp, "downLevelPromptHook", oldDownLevelHook, NULL);
  403. X        
  404. X    result = TCL_OK;
  405. XexitPoint:
  406. X    if (oldTopLevelHook != NULL)
  407. X        ckfree (oldTopLevelHook);
  408. X    if (oldDownLevelHook != NULL)
  409. X        ckfree (oldDownLevelHook);
  410. X    return result;
  411. X}
  412. END_OF_FILE
  413. if test 11049 -ne `wc -c <'extended/src/cmdloop.c'`; then
  414.     echo shar: \"'extended/src/cmdloop.c'\" unpacked with wrong size!
  415. fi
  416. # end of 'extended/src/cmdloop.c'
  417. fi
  418. if test -f 'extended/tcllib/help/brief' -a "${1}" != "-c" ; then 
  419.   echo shar: Will not clobber existing file \"'extended/tcllib/help/brief'\"
  420. else
  421. echo shar: Extracting \"'extended/tcllib/help/brief'\" \(9981 characters\)
  422. sed "s/^X//" >'extended/tcllib/help/brief' <<'END_OF_FILE'
  423. X
  424. Xcommands/append    Append strings to a variable.
  425. Xcommands/array    Return information about an array variable.
  426. Xcommands/break    Exit the current loop.
  427. Xcommands/case    Select code block to execute base on matching a string against a pattern.
  428. Xcommands/catch    Trap errors while executing a command.
  429. Xcommands/cd    Change the current working directory.
  430. Xcommands/close    Close an open file or pipeline.
  431. Xcommands/concat    Concatenates lists into a single list.
  432. Xcommands/continue    Continue execution of the next iteration of a loop.
  433. Xcommands/env    Variable for accessing the program's environment.
  434. Xcommands/eof    Test for end-of-file.
  435. Xcommands/error    Return an error.
  436. Xcommands/errorCode    Variable holding symbolic error information.
  437. Xcommands/errorInfo    Variable holding stack trace of an error.
  438. Xcommands/eval    Command to evaluate strings as Tcl code.
  439. Xcommands/exec    Run a Unix process.
  440. Xcommands/exit    Terminate the current process.
  441. Xcommands/expr    Evaluate an expression.
  442. Xcommands/file    Return status information about an file name, including parsing the name.
  443. Xcommands/flush    Flush a file buffer.
  444. Xcommands/for    Loop control command.
  445. Xcommands/foreach    Loop on each element of a list.
  446. Xcommands/format    Generate a formated string using a format specification.
  447. Xcommands/gets    Read a line from a file.
  448. Xcommands/glob    Perform file name globbing.
  449. Xcommands/global    Declare a variable as global.
  450. Xcommands/history    Redo or list previously executed interactive commands.
  451. Xcommands/if    Conditional command execution based on evaluating an expression.
  452. Xcommands/incr    Increment a variable.
  453. Xcommands/info    Provide state information on the Tcl interpreter.
  454. Xcommands/join    Join elements of a list into a string.
  455. Xcommands/lappend    Append elements to an array variable.
  456. Xcommands/lindex    Extract an element of a list.
  457. Xcommands/linsert    Insert an new element in a list.
  458. Xcommands/list    Generate a list.
  459. Xcommands/llength    Return the number of elements in a list.
  460. Xcommands/lrange    Extract a range of elements from a list.
  461. Xcommands/lreplace    Replace elements of a list.
  462. Xcommands/lsearch    Search a list for a pattern.
  463. Xcommands/lsort    Sort the elements of a list.
  464. Xcommands/open    Open a file or pipeline.
  465. Xcommands/proc    Define a Tcl procedure.
  466. Xcommands/puts    Write a string to a file.
  467. Xcommands/pwd    Return the current working directory.
  468. Xcommands/read    Read bytes from a file.
  469. Xcommands/regexp    Match a string against a regular expression.
  470. Xcommands/regsub    Match a string against a regular expression and perform substitution on it.
  471. Xcommands/rename    Rename or delete a command or procedure.
  472. Xcommands/return    Exit the current procedure, optionally returning a value.
  473. Xcommands/scan    Parse a string based on a format specification.
  474. Xcommands/seek    Change the access position of a file.
  475. Xcommands/set    Return or set the value of a variable.
  476. Xcommands/source    Read and evaluate a file of Tcl code.
  477. Xcommands/split    Split a string into a list of elements.
  478. Xcommands/string    Perform operations on a string.
  479. Xcommands/tell    Return the current access position of a file.
  480. Xcommands/time    Return the execution time for a Tcl command.
  481. Xcommands/trace    Trace access to variables.
  482. Xcommands/unknown    Unknown command trap handler.
  483. Xcommands/unset    
  484. Xcommands/uplevel    Execute a command in another environment up the procedure call stack.
  485. Xcommands/upvar    Bind a variable to another variable up the procedure call stack.
  486. Xcommands/while    Loop while an expression is true.
  487. Xextended/acos     Return the arccosine of a number.
  488. Xextended/alarm     Set a process alarm clock.
  489. Xextended/asin     Return the arcsin of a number.
  490. Xextended/atan     Return the arctangent of a number..
  491. Xextended/ceil     Return the smallest integer not less than a floating point number.
  492. Xextended/chgrp     Change file group.
  493. Xextended/chmod     Set file permissions.
  494. Xextended/chown     Change file owner and/or group.
  495. Xextended/cindex     Return indexed character from string.
  496. Xextended/clength     Return length of specified string.
  497. Xextended/cmdtrace     Trace Tcl execution.
  498. Xextended/commandloop     Create an interactive command loop.
  499. Xextended/copyfile     Copy remainder of one open file into another.
  500. Xextended/cos     Return the cosine of a number.
  501. Xextended/cosh     Return the hyperbolic cosine of a number.
  502. Xextended/crange     Return range of characters from string.
  503. Xextended/csubstr     Return a substring from within a string.
  504. Xextended/ctype     Determine if string has various characteristics.
  505. Xextended/dup     Duplicate an open filehandle.
  506. Xextended/echo     Echo one or more strings to stdout, followed by a newline.
  507. Xextended/execvp     Perform a process exec, executing a file.
  508. Xextended/exp     Return e to the power of a number.
  509. Xextended/fabs     Return the absolute value of the floating point number.
  510. Xextended/fcntl     Get or set open file access options.
  511. Xextended/floor     Return the largest integer not greater than a floating point number.
  512. Xextended/fmod     Perform a floating point modulus operation.
  513. Xextended/fmtclock     Convert integer time to human-readable format.
  514. Xextended/fork     Fork the current Tcl process.
  515. Xextended/fstat     Obtain status information about a open file.
  516. Xextended/getclock     Return current date and time as an integer value.
  517. Xextended/id     Access, set or convert process, user and group information.
  518. Xextended/infox     Return information about extended Tcl or the current application.
  519. Xextended/keyedlists     Introduction to keyed lists
  520. Xextended/keyldel     Delete a field of a keyed list.
  521. Xextended/keylget     Get the value of a field of a keyed list.
  522. Xextended/keylset     Set the value of a field of a keyed list.
  523. Xextended/kill     Send a signal to the specified process.
  524. Xextended/lempty     Determine if a list is empty. 
  525. Xextended/link     Make a link to a file.
  526. Xextended/log     Return the natural logarithm of a number.
  527. Xextended/log10     Return the logarithm base 10 of a number.
  528. Xextended/loop     Higher-performance for-style loop.
  529. Xextended/lvarpop     Pop or replace the specified element from a list.
  530. Xextended/max     Return the argument that has the highest numeric value.
  531. Xextended/min     Return the argument that has the lowest numeric value.
  532. Xextended/mkdir     Create a new directory
  533. Xextended/pipe     Create a pipe.
  534. Xextended/pow     Return a number to the power of another number.
  535. Xextended/random     Return a pseudorandom integer or set the seed.
  536. Xextended/replicate     Replicate string a number of times.
  537. Xextended/rmdir     Remove directories
  538. Xextended/scancontext     Manage file scan contexts.
  539. Xextended/scanfile     Scan a file, executing match code when their patterns are matched.
  540. Xextended/scanmatch     Specify tcl code to execute when scanfile pattern is matched.
  541. Xextended/select     Synchronous I/O multiplexing.
  542. Xextended/signal     Specify action to take when a signal is received.
  543. Xextended/sin     Return the sin of a number.
  544. Xextended/sinh     Return the hyperbolic sin of a number.
  545. Xextended/sleep     Sleep Tcl for the specified number of seconds.
  546. Xextended/sqrt     Return the square root of a number.
  547. Xextended/system     Execute command via `system' call.
  548. Xextended/tan     Return the tangent of a number.
  549. Xextended/tanh     Return the hyperbolic tangent of a number.
  550. Xextended/times     Get process and child execution times.
  551. Xextended/translit     Translate characters in string according to patterns.
  552. Xextended/umask     Get or set the file-creation mode mask.
  553. Xextended/unlink     Delete (unlink) files.
  554. Xextended/wait     Wait for a child process to terminate.
  555. Xhelp     Tcl shell help facility.
  556. Xintro/backslash    Tcl backslash substitution.
  557. Xintro/braces    Grouping arguments with braces.
  558. Xintro/brackets    Command substitution with brackets.
  559. Xintro/comments    Inserting comments in Tcl code.
  560. Xintro/data_types    Tcl data types.
  561. Xintro/dollar    Variable Substitution With $.
  562. Xintro/double_quotes    Grouping arguments with double-quotes.
  563. Xintro/expressions    Tcl expressions.
  564. Xintro/procedures    Tcl procedures.
  565. Xintro/regexps    Regular expressions.
  566. Xintro/results    Results of a command execution.
  567. Xintro/semi-colons    Separating commands with semi-colons.
  568. Xintro/syntax    Basic Tcl command syntax.
  569. Xintro/variables    Tcl variables and arrays.
  570. Xmisc/memory     display and debug memory problems
  571. Xtcl.tlib/assign_fields     Assign successive elements in a list to specified variables.
  572. Xtcl.tlib/dirs     List the directories in the directory stack.
  573. Xtcl.tlib/edprocs     Edit named procs, or all procs.
  574. Xtcl.tlib/for_array_keys     Do a foreach-style loop on each key in an array.
  575. Xtcl.tlib/for_file     Do a foreach-style loop on each line in a file.
  576. Xtcl.tlib/for_recursive_glob     Perform a foreach-style loop for all globbed files and directories.
  577. Xtcl.tlib/intersect     Return a list containing every element present in both lists.
  578. Xtcl.tlib/intersect3     Return three lists from an intersection of two lists.
  579. Xtcl.tlib/lrmdups     Given a list, remove all of the duplicated elements.
  580. Xtcl.tlib/popd     Pop a directory from a stack of directories and cd to it.
  581. Xtcl.tlib/pushd     Push a directory to a stack of directories.
  582. Xtcl.tlib/read_file     Read in a file to a string (less overhead than "exec cat").
  583. Xtcl.tlib/recursive_glob     Do filename globbing, recursively descending all matched directories.
  584. Xtcl.tlib/saveprocs     Save named procs to a file, or all procs.
  585. Xtcl.tlib/showproc     List the definition of the named procedure.
  586. Xtcl.tlib/showprocs     List the definition of the named, or all, procedures.
  587. Xtcl.tlib/union     Return the logical union of two lists.
  588. Xtcl.tlib/write_file     Write a string out as a file.
  589. Xtclshell/autoload     Autoloading of commands.
  590. Xtclshell/autoprocs     List names of autload and package library procs.
  591. Xtclshell/buildpackageindex     Build an index to a package library.
  592. Xtclshell/demand_load     Force an autoload proc or a package to be loaded.
  593. Xtclshell/flags     Tcl shell command line flags.
  594. Xtclshell/initialize     Tcl shell initialization sequence.
  595. Xtclshell/intro     Introduction to the tcl shell.
  596. Xtclshell/load     Search the TCLPATH for a file to source.
  597. Xtclshell/loadlibindex     Load the index of a package library
  598. Xtclshell/packagelib     Tcl shell package libraries.
  599. Xtclshell/packages     List all known packages.
  600. Xtclshell/results     Tcl shell command result processsing.
  601. Xtclshell/tclinit     Tcl shell initialization file.
  602. Xtclshell/unixcommands     Tcl shell Unix command execution.
  603. Xtclshell/utilprocs     Search a path list for a file.
  604. Xtclshell/variables     Tcl shell variables.
  605. END_OF_FILE
  606. if test 9981 -ne `wc -c <'extended/tcllib/help/brief'`; then
  607.     echo shar: \"'extended/tcllib/help/brief'\" unpacked with wrong size!
  608. fi
  609. # end of 'extended/tcllib/help/brief'
  610. fi
  611. if test -f 'extended/tests/chmod.test' -a "${1}" != "-c" ; then 
  612.   echo shar: Will not clobber existing file \"'extended/tests/chmod.test'\"
  613. else
  614. echo shar: Extracting \"'extended/tests/chmod.test'\" \(10272 characters\)
  615. sed "s/^X//" >'extended/tests/chmod.test' <<'END_OF_FILE'
  616. X#
  617. X# chmod.test
  618. X#
  619. X# Tests for the chmod, chown and chgrp commands.
  620. X#---------------------------------------------------------------------------
  621. X# Copyright 1991 Karl Lehenbauer and Mark Diekhans.
  622. X#
  623. X# Permission to use, copy, modify, and distribute this software and its
  624. X# documentation for any purpose and without fee is hereby granted, provided
  625. X# that the above copyright notice appear in all copies.  Karl Lehenbauer and
  626. X# Mark Diekhans make no representations about the suitability of this
  627. X# software for any purpose.  It is provided "as is" without express or
  628. X# implied warranty.
  629. X#
  630. Xif {[info procs test] != "test"} then {source defs}
  631. X
  632. X#-----------------------------------------------------------------------------
  633. X# This routine to the the mode of a file.  It is returned formated in octal.
  634. Xproc GetMode {filename} {
  635. X    file stat $filename stat
  636. X    return [format "%o" [expr {$stat(mode) & 07777}]]
  637. X}
  638. X
  639. X#-----------------------------------------------------------------------------
  640. X# Certain Unix systems don't handle chmod the same.  This routine test if the
  641. X# system chmod produces the expected results.
  642. X#   o mode - symbolic mode to set the file to.
  643. X#   o expect - expected result from ls.
  644. X#
  645. Xproc CheckChmod {mode expect} {
  646. X    chmod 000 CHMOD-CHECK.TMP
  647. X    exec chmod $mode CHMOD-CHECK.TMP
  648. X    set sysMode [lindex [exec ls -l CHMOD-CHECK.TMP] 0]
  649. X    return [expr {"$sysMode" == "$expect"}]
  650. X}
  651. X
  652. X
  653. X#-----------------------------------------------------------------------------
  654. X# Procedure to return the owner id and group id of a file as a list
  655. X
  656. Xproc GetOwner {file} {
  657. X    file stat $file stat
  658. X    return [list $stat(uid) $stat(gid)]
  659. X}
  660. X
  661. X#-----------------------------------------------------------------------------
  662. X# If a user does not have a group name assigned, then some tests will not work,
  663. X# just blow off the tests and let the user make things right. 
  664. X
  665. Xif {[catch {id group}] != 0} {
  666. X    echo "User '[id user]' does not have group name. Chmod tests skipped"
  667. X    return
  668. X}
  669. X
  670. X# Create the test files.
  671. X
  672. Xexec touch CHMOD-CHECK.TMP CHMOD-TEST.TMP CHMOD-TEST2.TMP
  673. X
  674. X# Set the umask so that no bits are masked.  Some system chmods use umask
  675. X# if u, g, o or a are not specified in a symbolic chmod.
  676. X
  677. Xumask 000
  678. X
  679. Xtest chmod-1.1 {chmod absolute mode tests} {
  680. X    chmod 000 CHMOD-TEST.TMP
  681. X    chmod 101 CHMOD-TEST.TMP
  682. X    GetMode   CHMOD-TEST.TMP
  683. X} {101}
  684. X
  685. Xtest chmod-1.2 {chmod absolute mode tests} {
  686. X    chmod 000 CHMOD-TEST.TMP
  687. X    chmod 010 CHMOD-TEST.TMP
  688. X    GetMode   CHMOD-TEST.TMP
  689. X} {10}
  690. X
  691. Xtest chmod-1.3 {chmod absolute mode tests} {
  692. X    chmod 000 CHMOD-TEST.TMP
  693. X    chmod 777 CHMOD-TEST.TMP
  694. X    GetMode   CHMOD-TEST.TMP
  695. X} {777}
  696. X
  697. Xtest chmod-1.4 {chmod absolute mode tests} {
  698. X    chmod 000 CHMOD-TEST.TMP
  699. X    chmod 666 CHMOD-TEST.TMP
  700. X    GetMode   CHMOD-TEST.TMP
  701. X} {666}
  702. X
  703. Xtest chmod-1.5 {chmod absolute mode tests} {
  704. X    chmod 000 CHMOD-TEST.TMP
  705. X    chmod 705 CHMOD-TEST.TMP
  706. X    GetMode   CHMOD-TEST.TMP
  707. X} {705}
  708. X
  709. Xtest chmod-1.7 {chmod absolute mode tests} {
  710. X    chmod  000 CHMOD-TEST.TMP
  711. X    chmod 4111 CHMOD-TEST.TMP
  712. X    GetMode    CHMOD-TEST.TMP
  713. X} {4111}
  714. X
  715. Xtest chmod-2.1 {chmod absolute integer mode tests} {
  716. X    chmod 000   {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  717. X    chmod -i 65 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  718. X    list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
  719. X} {101 101}
  720. X
  721. Xtest chmod-2.2 {chmod absolute integer mode tests} {
  722. X    chmod 000  {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  723. X    chmod -i 8 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  724. X    list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
  725. X} {10 10}
  726. X
  727. Xtest chmod-2.3 {chmod absolute integer mode tests} {
  728. X    chmod 000    {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  729. X    chmod -i 511 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  730. X    list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
  731. X} {777 777}
  732. X
  733. Xtest chmod-2.4 {chmod absolute integer mode tests} {
  734. X    chmod 000    {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  735. X    chmod -i 438 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  736. X    list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
  737. X} {666 666}
  738. X
  739. Xtest chmod-2.5 {chmod absolute integer mode tests} {
  740. X    chmod 000    {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  741. X    chmod -i 453 {CHMOD-TEST.TMP  CHMOD-TEST2.TMP}
  742. X    list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
  743. X} {705 705}
  744. X
  745. Xtest chmod-2.6 {chmod absolute integer mode tests} {
  746. X    chmod 000     CHMOD-TEST.TMP
  747. X    chmod -i 2121 CHMOD-TEST.TMP
  748. X    GetMode       CHMOD-TEST.TMP
  749. X} {4111}
  750. X
  751. X# Test symbolic mode.
  752. X
  753. Xtest chmod-3.1 {chmod symbolic mode tests} {
  754. X    chmod 000 CHMOD-TEST.TMP
  755. X    chmod +r  CHMOD-TEST.TMP
  756. X    GetMode   CHMOD-TEST.TMP
  757. X} {444}
  758. X
  759. Xtest chmod-3.2 {chmod symbolic mode tests} {
  760. X    chmod 000 CHMOD-TEST.TMP
  761. X    chmod +r  CHMOD-TEST.TMP
  762. X    chmod +w  CHMOD-TEST.TMP
  763. X    GetMode   CHMOD-TEST.TMP
  764. X} {666}
  765. X
  766. Xtest chmod-3.3 {chmod symbolic mode tests} {
  767. X    chmod 000 CHMOD-TEST.TMP
  768. X    chmod +r  CHMOD-TEST.TMP
  769. X    chmod +w  CHMOD-TEST.TMP
  770. X    chmod +x  CHMOD-TEST.TMP
  771. X    GetMode   CHMOD-TEST.TMP
  772. X} {777}
  773. X
  774. Xtest chmod-3.4 {chmod symbolic mode tests} {
  775. X    chmod 000 CHMOD-TEST.TMP
  776. X    chmod +r  CHMOD-TEST.TMP
  777. X    chmod +w  CHMOD-TEST.TMP
  778. X    chmod +x  CHMOD-TEST.TMP
  779. X    chmod -r  CHMOD-TEST.TMP
  780. X    GetMode   CHMOD-TEST.TMP
  781. X} {333}
  782. X
  783. Xtest chmod-3.5 {chmod symbolic mode tests} {
  784. X    chmod 000 CHMOD-TEST.TMP
  785. X    chmod +r  CHMOD-TEST.TMP
  786. X    chmod +w  CHMOD-TEST.TMP
  787. X    chmod +x  CHMOD-TEST.TMP
  788. X    chmod -r  CHMOD-TEST.TMP
  789. X    chmod -w  CHMOD-TEST.TMP
  790. X    GetMode   CHMOD-TEST.TMP
  791. X} {111}
  792. X
  793. Xtest chmod-3.6 {chmod symbolic mode tests} {
  794. X    chmod 000 {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  795. X    chmod +r  {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  796. X    chmod +w  {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  797. X    chmod +x  {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  798. X    chmod -r  {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  799. X    chmod -w  {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  800. X    chmod -x  {CHMOD-TEST.TMP  CHMOD-TEST2.TMP}
  801. X    list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
  802. X} {0 0}
  803. X
  804. Xtest chmod-3.7 {chmod symbolic mode tests} {
  805. X    chmod 000     CHMOD-TEST.TMP
  806. X    chmod u+x,g+x CHMOD-TEST.TMP
  807. X    GetMode       CHMOD-TEST.TMP
  808. X} {110}
  809. X
  810. Xtest chmod-3.8 {chmod symbolic mode tests} {
  811. X    chmod 000     {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  812. X    chmod u+x,g+x {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  813. X    chmod u-x,g-x {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  814. X    list [GetMode CHMOD-TEST.TMP] [GetMode CHMOD-TEST2.TMP]
  815. X} {0 0}
  816. X
  817. X# Cann't +s on some systems
  818. X
  819. Xif [CheckChmod "ugo+x,ug+s" "---s--s--x"] {
  820. X    test chmod-3.9 {chmod symbolic mode tests} {
  821. X        chmod 000        CHMOD-TEST.TMP
  822. X        chmod ugo+x,ug+s CHMOD-TEST.TMP
  823. X        GetMode          CHMOD-TEST.TMP
  824. X    } {6111}
  825. X}
  826. X
  827. Xtest chmod-3.10 {chmod symbolic mode tests} {
  828. X    chmod 000   CHMOD-TEST.TMP
  829. X    chmod a+rwx CHMOD-TEST.TMP
  830. X    GetMode     CHMOD-TEST.TMP
  831. X} {777}
  832. X
  833. Xtest chmod-3.11 {chmod symbolic mode tests} {
  834. X    chmod 000   CHMOD-TEST.TMP
  835. X    chmod a+rwx CHMOD-TEST.TMP
  836. X    chmod a-rw  CHMOD-TEST.TMP
  837. X    GetMode     CHMOD-TEST.TMP
  838. X} {111}
  839. X
  840. Xtest chmod-3.12 {chmod symbolic mode tests} {
  841. X    chmod 000   CHMOD-TEST.TMP
  842. X    chmod a=rwx CHMOD-TEST.TMP
  843. X    GetMode     CHMOD-TEST.TMP
  844. X} {777}
  845. X
  846. Xtest chmod-3.13 {chmod symbolic mode tests} {
  847. X    chmod 000 CHMOD-TEST.TMP
  848. X    chmod u+t CHMOD-TEST.TMP
  849. X    GetMode   CHMOD-TEST.TMP
  850. X} {0}
  851. X
  852. X# +t is dificult to test if not root, just make sure it execute and hope
  853. X# for the best.
  854. X
  855. Xtest chmod-3.14 {chmod symbolic mode tests} {
  856. X    chmod 000 CHMOD-TEST.TMP
  857. X    catch {chmod u+t CHMOD-TEST.TMP}
  858. X} {0}
  859. X
  860. Xtest chmod-3.15 {chmod symbolic mode tests} {
  861. X    chmod 000   CHMOD-TEST.TMP
  862. X    list [catch {chmod u+t   CHMOD-TEST.TMP}] \
  863. X         [catch {chmod u-t   CHMOD-TEST.TMP}]
  864. X} {0 0}
  865. X
  866. Xtest chmod-3.16 {chmod symbolic mode tests} {
  867. X    chmod 000         CHMOD-TEST.TMP
  868. X    chmod a+rwx       CHMOD-TEST.TMP
  869. X    chmod u-r,g-w,o-x CHMOD-TEST.TMP
  870. X    GetMode           CHMOD-TEST.TMP
  871. X} {356}
  872. X
  873. Xtest chmod-4.1 {chmod error tests} {
  874. X    list [catch {chmod +z CHMOD-TEST.TMP} msg] $msg
  875. X} {1 {invalid file mode}}
  876. X
  877. Xtest chmod-4.2 {chmod error tests} {
  878. X    list [catch {chmod} msg] $msg
  879. X} {1 {wrong # args: chmod [-i] mode filelist}}
  880. X
  881. X# chown and chgrp tests
  882. X
  883. Xset uidGidPairs [list [list [id userid] [id groupid]] \
  884. X                      [list [id userid] [id groupid]]]
  885. X
  886. Xtest chmod-5.1 {chown tests} {
  887. X    chown [id user] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  888. X    list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
  889. X} $uidGidPairs
  890. X
  891. Xtest chmod-5.2 {chown tests} {
  892. X    chown [id userid] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  893. X    list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
  894. X} $uidGidPairs
  895. X
  896. X
  897. Xtest chmod-5.3 {chown tests} {
  898. X    chown [list [id userid] [id groupid]] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  899. X    list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
  900. X} $uidGidPairs
  901. X
  902. Xtest chmod-5.4 {chown tests} {
  903. X    chown [list [id user] [id group]] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  904. X    list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
  905. X} $uidGidPairs
  906. X
  907. Xtest chmod-5.5 {chown tests} {
  908. X    chown [list [id user] [id group]] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  909. X    list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
  910. X} $uidGidPairs
  911. X
  912. Xtest chmod-6.1 {chown error tests} {
  913. X    list [catch {chown XXXXXXXXX CHMOD-TEST.TMP} msg] $msg
  914. X} {1 {unknown user id: XXXXXXXXX}}
  915. X
  916. Xtest chmod-6.2 {chown error tests} {
  917. X    list [catch {chown [list XXXXXXXXX [id groupid]] CHMOD-TEST.TMP} msg] $msg
  918. X} {1 {unknown user id: XXXXXXXXX}}
  919. X
  920. Xtest chmod-6.3 {chown error tests} {
  921. X    list [catch {chown [list [id user] XXXXXXXXX] CHMOD-TEST.TMP} msg] $msg
  922. X} {1 {unknown group id: XXXXXXXXX}}
  923. X
  924. Xtest chmod-6.4 {chown error tests} {
  925. X    list [catch {chown {XXXXXXXXX YYYY} CHMOD-TEST.TMP} msg] $msg
  926. X} {1 {unknown user id: XXXXXXXXX}}
  927. X
  928. Xtest chmod-6.5 {chown error tests} {
  929. X    list [catch {chown} msg] $msg
  930. X} {1 {wrong # args: chown owner|{owner group} filelist}}
  931. X
  932. Xtest chmod-7.1 {chgrp tests} {
  933. X    chgrp [id group]  {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  934. X    list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
  935. X} $uidGidPairs
  936. X
  937. Xtest chmod-7.2 {chgrp tests} {
  938. X    chgrp [id groupid] {CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  939. X    list [GetOwner CHMOD-TEST.TMP] [GetOwner CHMOD-TEST2.TMP]
  940. X} $uidGidPairs
  941. X
  942. Xtest chmod-8.1 {chgrp error tests} {
  943. X    list [catch {chgrp} msg] $msg
  944. X} {1 {wrong # args: chgrp group filelist}}
  945. X
  946. Xtest chmod-8.2 {chgrp error tests} {
  947. X    list [catch {chgrp XXXXXXXXX CHMOD-TEST.TMP} msg] $msg
  948. X} {1 {unknown group id: XXXXXXXXX}}
  949. X
  950. Xunlink {CHMOD-CHECK.TMP CHMOD-TEST.TMP CHMOD-TEST2.TMP}
  951. X
  952. END_OF_FILE
  953. if test 10272 -ne `wc -c <'extended/tests/chmod.test'`; then
  954.     echo shar: \"'extended/tests/chmod.test'\" unpacked with wrong size!
  955. fi
  956. # end of 'extended/tests/chmod.test'
  957. fi
  958. if test -f 'extended/tests/unixcmds.test' -a "${1}" != "-c" ; then 
  959.   echo shar: Will not clobber existing file \"'extended/tests/unixcmds.test'\"
  960. else
  961. echo shar: Extracting \"'extended/tests/unixcmds.test'\" \(10954 characters\)
  962. sed "s/^X//" >'extended/tests/unixcmds.test' <<'END_OF_FILE'
  963. X#
  964. X# unixcmds.test
  965. X#
  966. X# Tests for the fork, execvp, wait, kill, link, unlink, times, umask, system,
  967. X# signal, and sleep commands.
  968. X#---------------------------------------------------------------------------
  969. X# Copyright 1991 Karl Lehenbauer and Mark Diekhans.
  970. X#
  971. X# Permission to use, copy, modify, and distribute this software and its
  972. X# documentation for any purpose and without fee is hereby granted, provided
  973. X# that the above copyright notice appear in all copies.  Karl Lehenbauer and
  974. X# Mark Diekhans make no representations about the suitability of this
  975. X# software for any purpose.  It is provided "as is" without express or
  976. X# implied warranty.
  977. X#
  978. Xif {[info procs test] != "test"} then {source defs}
  979. X
  980. X# Test fork, execvp, wait and kill commands.
  981. X
  982. Xset newPid [fork]
  983. Xif {$newPid == 0} {
  984. X    execvp ../tcl "-qc sleep 1;exit 12"
  985. X    error "Should never make it here"
  986. X}
  987. Xtest unix-cmds-1.1 {fork, execvp, wait and kill tests} {
  988. X    wait $newPid
  989. X} "$newPid EXIT 12"
  990. X
  991. Xtest unix-cmds-1.2 {fork, execvp, wait and kill tests} {
  992. X    list [catch {kill} msg] $msg
  993. X} {1 {wrong # args: kill [signal] processlist}}
  994. X
  995. Xset newPid [fork]
  996. Xif {$newPid == 0} {
  997. X    execvp ../tcl "-qc catch {while {1} {sleep 1}}; exit 10"
  998. X    error "Should never make it here"
  999. X}
  1000. Xsleep 1
  1001. X
  1002. Xtest unix-cmds-1.3 {fork, execvp, wait and kill tests} {
  1003. X    kill $newPid
  1004. X    wait $newPid
  1005. X} "$newPid SIG SIGTERM"
  1006. X
  1007. X# Try kill of multiple processes; the test is complicated by the fact that
  1008. X# either process could die first.
  1009. X
  1010. Xset newPid1 [fork]
  1011. Xif {$newPid1 == 0} {
  1012. X    execvp ../tcl "-qc catch {while {1} {sleep 1}}; exit 10"
  1013. X    error "should never make it here #1"
  1014. X}
  1015. X
  1016. Xset newPid2 [fork]
  1017. Xif {$newPid2 == 0} {
  1018. X    execvp ../tcl "-qc catch {while {1} {sleep 1}}; exit 10"
  1019. X    error "should never make it here #2"
  1020. X}
  1021. X
  1022. Xtest unix-cmds-1.4 {fork, execvp, wait and kill tests} {
  1023. X    sleep 3
  1024. X
  1025. X    kill [list $newPid1 $newPid2]
  1026. X
  1027. X    set result1 [wait [list $newPid1 $newPid2]]
  1028. X    if {[lindex $result1 0] == $newPid1} {
  1029. X        set result2 [wait $newPid2]
  1030. X    } else {
  1031. X        set result2 [wait $newPid1]
  1032. X    }
  1033. X    lsort [list $result1 $result2]
  1034. X} [lsort [list "$newPid1 SIG SIGTERM" "$newPid2 SIG SIGTERM"]]
  1035. X
  1036. Xtest unix-cmds-1.5 {fork, execvp, wait and kill tests} {
  1037. X    list [catch {fork foo} msg] $msg
  1038. X} {1 {wrong # args: fork}}
  1039. X
  1040. Xtest unix-cmds-1.6 {fork, execvp, wait and kill tests} {
  1041. X    list [catch {wait baz} msg] $msg
  1042. X} {1 {expected integer but got "baz"}}
  1043. X
  1044. Xsignal error SIGINT
  1045. X
  1046. Xtest unix-cmds-1.7 {fork, execvp, wait and kill tests} {
  1047. X    list [catch {kill 2 [id process]} msg] $msg
  1048. X} {1 {SIGINT signal received}}
  1049. X
  1050. Xtest unix-cmds-1.8 {fork, execvp, wait and kill tests} {
  1051. X    list [catch {kill INT [id process]} msg] $msg
  1052. X} {1 {SIGINT signal received}}
  1053. X
  1054. Xtest unix-cmds-1.9 {fork, execvp, wait and kill tests} {
  1055. X    list [catch {kill SIGINT [id process]} msg] $msg
  1056. X} {1 {SIGINT signal received}}
  1057. X
  1058. Xtest unix-cmds-1.10 {fork, execvp, wait and kill tests} {
  1059. X    list [catch {kill SIGINT [id process]} msg] $msg
  1060. X} {1 {SIGINT signal received}}
  1061. X
  1062. Xtest unix-cmds-1.11 {fork, execvp, wait and kill tests} {
  1063. X    list [catch {kill 10000 [id process]} msg] $msg
  1064. X} {1 {kill: invalid signal}}
  1065. X
  1066. Xtest unix-cmds-1.12 {fork, execvp, wait and kill tests} {
  1067. X    list [catch {kill SIGFOO [id process]} msg] $msg
  1068. X} {1 {kill: invalid signal}}
  1069. X
  1070. Xtest unix-cmds-1.13 {fork, execvp, wait and kill tests} {
  1071. X    kill 0 [id process]
  1072. X} {}
  1073. X
  1074. X# Test link and unlink commands.
  1075. X
  1076. Xtest unix-cmds-2.1 {link and unlink tests} {
  1077. X    set fh [open LINK1.TMP w]
  1078. X    puts $fh "Hello, world"
  1079. X    close $fh
  1080. X    link LINK1.TMP LINK2.TMP
  1081. X    file stat LINK1.TMP stat
  1082. X    set ino1 $stat(ino)
  1083. X    set dev1 $stat(dev)
  1084. X    file stat LINK2.TMP stat
  1085. X    set ino2 $stat(ino)
  1086. X    set dev2 $stat(dev)
  1087. X    set result [list [file exists LINK2.TMP] [expr $ino1==$ino2] \
  1088. X                     [expr $dev1==$dev2]]
  1089. X    unlink {LINK1.TMP LINK2.TMP}
  1090. X    set result
  1091. X} {1 1 1}
  1092. X
  1093. Xtest unix-cmds-2.2 {link and unlink tests} {
  1094. X    list [catch {link LINK1.TMP LINK2.TMP} msg] [string tolower $msg]
  1095. X} {1 {link: no such file or directory}}
  1096. X
  1097. Xtest unix-cmds-2.3 {link and unlink tests} {
  1098. X    list [catch {link} msg] $msg
  1099. X} {1 {wrong # args: link srcpath destpath}}
  1100. X
  1101. X# Test unlink command.
  1102. X
  1103. Xtest unix-cmds-2.4 {unlink and unlink tests} {
  1104. X    set fh [open UNLINK.TMP w]
  1105. X    puts $fh "Hello, world"
  1106. X    close $fh
  1107. X    unlink UNLINK.TMP
  1108. X    file exists UNLINK.TMP
  1109. X} {0}
  1110. X
  1111. Xtest unix-cmds-2.5 {unlink and unlink tests} {
  1112. X    list [catch {unlink UNLINK.TMP} msg] [string tolower $msg]
  1113. X} {1 {unlink: unlink.tmp: no such file or directory}}
  1114. X
  1115. Xtest unix-cmds-2.6 {unlink and unlink tests} {
  1116. X    list [catch {unlink} msg] $msg
  1117. X} {1 {wrong # args: unlink filelist}}
  1118. X
  1119. X# Test the times command (the best we can).
  1120. X
  1121. Xtest unix-cmds-3.1 {times tests} {
  1122. X    llength [times]
  1123. X} {4}
  1124. X
  1125. Xtest unix-cmds-3.2 {times tests} {
  1126. X    list [catch {times foo} msg] $msg
  1127. X} {1 {wrong # args: times}}
  1128. X
  1129. X# Test umask command.
  1130. X
  1131. Xtest unix-cmds-4.1 {umask tests} {
  1132. X    set oldMask [umask]
  1133. X    umask 666
  1134. X    set newMask [umask]
  1135. X    umask $oldMask
  1136. X    set newMask
  1137. X} {666}
  1138. X
  1139. Xtest unix-cmds-4.2 {umask tests} {
  1140. X    list [catch {umask 999} msg] $msg
  1141. X} {1 {Expected octal number got: 999}}
  1142. X
  1143. Xtest unix-cmds-4.3 {umask tests} {
  1144. X    list [catch {umask 7 7} msg] $msg
  1145. X} {1 {wrong # args: umask octalmask}}
  1146. X
  1147. X# Test the system command
  1148. X
  1149. Xtest unix-cmds-5.1 {system tests} {
  1150. X    system "ls / >/dev/null"
  1151. X} {0}
  1152. X
  1153. Xtest unix-cmds-5.2 {system tests} {
  1154. X    list [catch {system} msg] $msg
  1155. X} {1 {wrong # args: system command}}
  1156. X
  1157. X# Test the signal command
  1158. X
  1159. Xtest unix-cmds-6.1 {signal tests} {
  1160. X    signal ignore SIGHUP
  1161. X    list [catch {kill HUP [id process]} msg] $msg
  1162. X} {0 {}}
  1163. X
  1164. Xtest unix-cmds-6.2 {signal tests} {
  1165. X    global errorInfo
  1166. X    set errorInfo {}
  1167. X    signal error HUP
  1168. X    proc KillMe3 {} {kill SIGHUP [id process]}
  1169. X    proc KillMe2 {} {KillMe3}
  1170. X    proc KillMe1 {} {KillMe2}
  1171. X    list [catch {KillMe1} msg] $msg $errorInfo
  1172. X} {1 {SIGHUP signal received} {SIGHUP signal received
  1173. X    while executing
  1174. X"kill SIGHUP [id process]"
  1175. X    (procedure "KillMe3" line 1)
  1176. X    invoked from within
  1177. X"KillMe3"
  1178. X    (procedure "KillMe2" line 1)
  1179. X    invoked from within
  1180. X"KillMe2"
  1181. X    (procedure "KillMe1" line 1)
  1182. X    invoked from within
  1183. X"KillMe1"}}
  1184. X
  1185. Xtest unix-cmds-6.3 {signal tests} {
  1186. X    signal error HUP SIGINT
  1187. X    set one [list [catch {kill HUP [id process]} msg] $msg]
  1188. X    set two [list [catch {kill INT [id process]} msg] $msg]
  1189. X    list $one $two
  1190. X} {{1 {SIGHUP signal received}} {1 {SIGINT signal received}}}
  1191. X
  1192. Xtest unix-cmds-6.4 {signal tests} {
  1193. X    set signalWeGot {}
  1194. X    signal trap 1 {set signalWeGot $signalRecieved} 
  1195. X    kill SIGHUP [id process]
  1196. X    signal default 1
  1197. X    set signalWeGot
  1198. X} {SIGHUP}
  1199. X
  1200. Xtest unix-cmds-6.5 {signal tests} {
  1201. X    signal default {SIGHUP SIGINT}
  1202. X    signal get {SIGHUP SIGINT}
  1203. X} {default default}
  1204. X
  1205. Xtest unix-cmds-6.6 {signal tests} {
  1206. X    signal default SIGHUP
  1207. X    signal ignore  SIGINT
  1208. X    signal get {SIGHUP SIGINT}
  1209. X} {default ignore}
  1210. X
  1211. Xtest unix-cmds-6.7 {signal tests} {
  1212. X    signal trap {SIGHUP SIGINT} {error "Should not get this signal"}
  1213. X    signal get {SIGHUP SIGINT}
  1214. X} {trap trap}
  1215. X
  1216. Xtest unix-cmds-6.8 {signal tests} {
  1217. X    signal error {SIGHUP SIGINT}
  1218. X    signal get {SIGHUP SIGINT}
  1219. X} {error error}
  1220. X
  1221. Xtest unix-cmds-6.9 {signal tests} {
  1222. X    global errorInfo
  1223. X    set errorInfo {}
  1224. X    proc KillMe3 {} {kill SIGHUP [id process]}
  1225. X    proc KillMe2 {} {KillMe3}
  1226. X    proc KillMe1 {} {KillMe2}
  1227. X    signal trap SIGHUP {error "Blew it in the trap code"}
  1228. X    list [catch {KillMe1} msg ] $msg $errorInfo
  1229. X} {1 {Blew it in the trap code} {Blew it in the trap code
  1230. X    while executing
  1231. X"error "Blew it in the trap code""
  1232. X    while executing signal trap code for SIGHUP signal
  1233. X    invoked from within
  1234. X"kill SIGHUP [id process]"
  1235. X    (procedure "KillMe3" line 1)
  1236. X    invoked from within
  1237. X"KillMe3"
  1238. X    (procedure "KillMe2" line 1)
  1239. X    invoked from within
  1240. X"KillMe2"
  1241. X    (procedure "KillMe1" line 1)
  1242. X    invoked from within
  1243. X"KillMe1"}}
  1244. X
  1245. Xtest unix-cmds-6.10 {signal tests} {
  1246. X    list [catch {signal} msg] $msg
  1247. X} {1 {wrong # args: signal action signalList [commands]}}
  1248. X
  1249. Xtest unix-cmds-6.11 {signal tests} {
  1250. X    list [catch {signal ignore foo} msg] $msg
  1251. X} {1 {invalid signal name: foo}}
  1252. X
  1253. X#
  1254. X# Complex test for the death of a child.
  1255. X#
  1256. X
  1257. Xproc PollSigChld {} {
  1258. X    global G_gotChild
  1259. X    set sleepCnt 0
  1260. X    while {!$G_gotChild} {
  1261. X        incr sleepCnt
  1262. X        if {$sleepCnt > 90} {
  1263. X            error "unix-cmds-6.12: SIGCHLD for pid=$childPid lost"
  1264. X        }
  1265. X        sleep 1
  1266. X    }
  1267. X}
  1268. X
  1269. Xproc ForkChild {exitCode} {
  1270. X    flush stdout  ;# Not going to exec, must clean up the buffers.
  1271. X    flush stderr
  1272. X    set childPid [fork]
  1273. X    if {$childPid == 0} {
  1274. X        exit $exitCode
  1275. X    }
  1276. X    return $childPid
  1277. X}
  1278. X
  1279. Xtest unix-cmds-6.12 {signal tests} {
  1280. X    global G_gotChild
  1281. X    set G_gotChild 0
  1282. X    signal trap SIGCHLD {global G_gotChild;set G_gotChild 1;sleep 1}
  1283. X    # Fork two childern
  1284. X    set pidList [list [ForkChild 123] [ForkChild 111]]
  1285. X    PollSigChld
  1286. X
  1287. X    # Wait on one process and delete if from the list.
  1288. X    set status1 [wait $pidList]
  1289. X    lvarpop pidList [lsearch $pidList [lindex $status1 0]]
  1290. X
  1291. X    # Wait on the second child
  1292. X    set G_gotChild 0
  1293. X    signal trap SIGCHLD {global G_gotChild;set G_gotChild 1}
  1294. X    set status2 [wait $pidList]
  1295. X
  1296. X    signal default SIGCHLD
  1297. X
  1298. X    lsort [list [lindex $status1 2] [lindex $status2 2]]
  1299. X} {111 123}
  1300. X
  1301. X# Test the sleep command, as well as we can.
  1302. X
  1303. Xtest unix-cmds-7.1 {sleep tests} {
  1304. X    sleep 1
  1305. X} {}
  1306. X
  1307. Xtest unix-cmds-7.2 {sleep tests} {
  1308. X    list [catch {sleep} msg] $msg
  1309. X} {1 {wrong # args: sleep seconds}}
  1310. X
  1311. X# Test mkdir and rmdir commands.
  1312. X
  1313. Xtest unix-cmds-8.1 {mkdir and rmdir tests} {
  1314. X    catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
  1315. X    mkdir {MKDIR1.TMP MKDIR2.TMP}
  1316. X    set result [list [file isdirectory MKDIR1.TMP] \
  1317. X                     [file isdirectory MKDIR2.TMP]]
  1318. X    catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
  1319. X    set result
  1320. X} {1 1}
  1321. X
  1322. Xtest unix-cmds-8.2 {mkdir and rmdir tests} {
  1323. X    catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
  1324. X    mkdir -path MKDIR1.TMP/a/b/c
  1325. X    set result [file isdirectory MKDIR1.TMP/a/b/c] 
  1326. X    catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
  1327. X    set result
  1328. X} {1}
  1329. X
  1330. Xtest unix-cmds-8.3 {mkdir and rmdir tests} {
  1331. X    catch {mkdir {MKDIR1.TMP MKDIR2.TMP}}
  1332. X    rmdir {MKDIR1.TMP MKDIR2.TMP}
  1333. X    list [file isdirectory MKDIR1.TMP] [file isdirectory MKDIR2.TMP]
  1334. X} {0 0}
  1335. X
  1336. Xtest unix-cmds-8.4 {mkdir and rmdir tests} {
  1337. X    catch {mkdir MKDIR1.TMP}
  1338. X    set result [list [catch {mkdir MKDIR1.TMP} msg] [string tolower $msg]]
  1339. X    catch {rmdir MKDIR1.TMP}
  1340. X    set result
  1341. X} {1 {mkdir: mkdir1.tmp: file exists}}
  1342. X
  1343. Xtest unix-cmds-8.5 {mkdir and rmdir tests} {
  1344. X    list [catch {mkdir} msg] $msg
  1345. X} {1 {wrong # args: mkdir [-path] dirlist}}
  1346. X
  1347. Xtest unix-cmds-8.6 {mkdir and rmdir tests} {
  1348. X    catch {rmdir MKDIR1.TMP}
  1349. X    set result [list [catch {rmdir MKDIR1.TMP} msg] [string tolower $msg]]
  1350. X    set result
  1351. X} {1 {rmdir: mkdir1.tmp: no such file or directory}}
  1352. X
  1353. Xtest unix-cmds-8.7 {mkdir and rmdir tests} {
  1354. X    list [catch {rmdir} msg] $msg
  1355. X} {1 {wrong # args: rmdir dirlist}}
  1356. X
  1357. X
  1358. X
  1359. END_OF_FILE
  1360. if test 10954 -ne `wc -c <'extended/tests/unixcmds.test'`; then
  1361.     echo shar: \"'extended/tests/unixcmds.test'\" unpacked with wrong size!
  1362. fi
  1363. # end of 'extended/tests/unixcmds.test'
  1364. fi
  1365. echo shar: End of archive 12 \(of 23\).
  1366. cp /dev/null ark12isdone
  1367. MISSING=""
  1368. 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
  1369.     if test ! -f ark${I}isdone ; then
  1370.     MISSING="${MISSING} ${I}"
  1371.     fi
  1372. done
  1373. if test "${MISSING}" = "" ; then
  1374.     echo You have unpacked all 23 archives.
  1375.     echo "Now cd to "extended", edit the makefile, then do a "make""
  1376.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1377. else
  1378.     echo You still need to unpack the following archives:
  1379.     echo "        " ${MISSING}
  1380. fi
  1381. ##  End of shell archive.
  1382. exit 0
  1383.  
  1384. exit 0 # Just in case...
  1385. -- 
  1386. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1387. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1388. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1389. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1390.