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

  1. Newsgroups: comp.sources.misc
  2. From: karl@sugar.neosoft.com (Karl Lehenbauer)
  3. Subject:  v26i011:  tclx - extensions and on-line help for tcl 6.1, Part11/23
  4. Message-ID: <1991Nov19.005615.8995@sparky.imd.sterling.com>
  5. X-Md4-Signature: dca3169a9ef38cc92288aa68ccb614d2
  6. Date: Tue, 19 Nov 1991 00:56:15 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: karl@sugar.neosoft.com (Karl Lehenbauer)
  10. Posting-number: Volume 26, Issue 11
  11. Archive-name: tclx/part11
  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 11 (of 23)."
  21. # Contents:  extended/man/Handles.man extended/src/createExtd.c
  22. #   extended/src/debug.c extended/src/id.c
  23. #   extended/tcllib/help/commands/trace
  24. # Wrapped by karl@one on Wed Nov 13 21:50:23 1991
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'extended/man/Handles.man' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'extended/man/Handles.man'\"
  28. else
  29. echo shar: Extracting \"'extended/man/Handles.man'\" \(9032 characters\)
  30. sed "s/^X//" >'extended/man/Handles.man' <<'END_OF_FILE'
  31. X.\"----------------------------------------------------------------------------
  32. X.\" The definitions below are for supplemental macros used in Sprite
  33. X.\" manual entries.
  34. X.\"
  35. X.\" .HS name section [date [version]]
  36. X.\"    Replacement for .TH in other man pages.  See below for valid
  37. X.\"    section names.
  38. X.\"
  39. X.\" .AP type name in/out [indent]
  40. X.\"    Start paragraph describing an argument to a library procedure.
  41. X.\"    type is type of argument (int, etc.), in/out is either "in", "out",
  42. X.\"    or "in/out" to describe whether procedure reads or modifies arg,
  43. X.\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  44. X.\"    needed;  use .AS below instead)
  45. X.\"
  46. X.\" .AS [type [name]]
  47. X.\"    Give maximum sizes of arguments for setting tab stops.  Type and
  48. X.\"    name are examples of largest possible arguments that will be passed
  49. X.\"    to .AP later.  If args are omitted, default tab stops are used.
  50. X.\"
  51. X.\" .BS
  52. X.\"    Start box enclosure.  From here until next .BE, everything will be
  53. X.\"    enclosed in one large box.
  54. X.\"
  55. X.\" .BE
  56. X.\"    End of box enclosure.
  57. X.\"
  58. X.\" .VS
  59. X.\"    Begin vertical sidebar, for use in marking newly-changed parts
  60. X.\"    of man pages.
  61. X.\"
  62. X.\" .VE
  63. X.\"    End of vertical sidebar.
  64. X.\"
  65. X.\" .DS
  66. X.\"    Begin an indented unfilled display.
  67. X.\"
  68. X.\" .DE
  69. X.\"    End of indented unfilled display.
  70. X.\"
  71. X'    # Heading for Sprite man pages
  72. X.de HS
  73. X.if '\\$2'cmds'       .TH \\$1 1 \\$3 \\$4
  74. X.if '\\$2'lib'        .TH \\$1 3 \\$3 \\$4
  75. X.if '\\$2'tcl'        .TH \\$1 3 \\$3 \\$4
  76. X.if '\\$2'tk'         .TH \\$1 3 \\$3 \\$4
  77. X.if t .wh -1.3i ^B
  78. X.nr ^l \\n(.l
  79. X.ad b
  80. X..
  81. X'    # Start an argument description
  82. X.de AP
  83. X.ie !"\\$4"" .TP \\$4
  84. X.el \{\
  85. X.   ie !"\\$2"" .TP \\n()Cu
  86. X.   el          .TP 15
  87. X.\}
  88. X.ie !"\\$3"" \{\
  89. X.ta \\n()Au \\n()Bu
  90. X\&\\$1    \\fI\\$2\\fP    (\\$3)
  91. X.\".b
  92. X.\}
  93. X.el \{\
  94. X.br
  95. X.ie !"\\$2"" \{\
  96. X\&\\$1    \\fI\\$2\\fP
  97. X.\}
  98. X.el \{\
  99. X\&\\fI\\$1\\fP
  100. X.\}
  101. X.\}
  102. X..
  103. X'    # define tabbing values for .AP
  104. X.de AS
  105. X.nr )A 10n
  106. X.if !"\\$1"" .nr )A \\w'\\$1'u+3n
  107. X.nr )B \\n()Au+15n
  108. X.\"
  109. X.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  110. X.nr )C \\n()Bu+\\w'(in/out)'u+2n
  111. X..
  112. X'    # BS - start boxed text
  113. X'    # ^y = starting y location
  114. X'    # ^b = 1
  115. X.de BS
  116. X.br
  117. X.mk ^y
  118. X.nr ^b 1u
  119. X.if n .nf
  120. X.if n .ti 0
  121. X.if n \l'\\n(.lu\(ul'
  122. X.if n .fi
  123. X..
  124. X'    # BE - end boxed text (draw box now)
  125. X.de BE
  126. X.nf
  127. X.ti 0
  128. X.mk ^t
  129. X.ie n \l'\\n(^lu\(ul'
  130. X.el \{\
  131. X.\"    Draw four-sided box normally, but don't draw top of
  132. X.\"    box if the box started on an earlier page.
  133. X.ie !\\n(^b-1 \{\
  134. X\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  135. X.\}
  136. X.el \}\
  137. X\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  138. X.\}
  139. X.\}
  140. X.fi
  141. X.br
  142. X.nr ^b 0
  143. X..
  144. X'    # VS - start vertical sidebar
  145. X'    # ^Y = starting y location
  146. X'    # ^v = 1 (for troff;  for nroff this doesn't matter)
  147. X.de VS
  148. X.mk ^Y
  149. X.ie n 'mc \s12\(br\s0
  150. X.el .nr ^v 1u
  151. X..
  152. X'    # VE - end of vertical sidebar
  153. X.de VE
  154. X.ie n 'mc
  155. X.el \{\
  156. X.ev 2
  157. X.nf
  158. X.ti 0
  159. X.mk ^t
  160. X\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  161. X.sp -1
  162. X.fi
  163. X.ev
  164. X.\}
  165. X.nr ^v 0
  166. X..
  167. X'    # Special macro to handle page bottom:  finish off current
  168. X'    # box/sidebar if in box/sidebar mode, then invoked standard
  169. X'    # page bottom macro.
  170. X.de ^B
  171. X.ev 2
  172. X'ti 0
  173. X'nf
  174. X.mk ^t
  175. X.if \\n(^b \{\
  176. X.\"    Draw three-sided box if this is the box's first page,
  177. X.\"    draw two sides but no top otherwise.
  178. X.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  179. X.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  180. X.\}
  181. X.if \\n(^v \{\
  182. X.nr ^x \\n(^tu+1v-\\n(^Yu
  183. X\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  184. X.\}
  185. X.bp
  186. X'fi
  187. X.ev
  188. X.if \\n(^b \{\
  189. X.mk ^y
  190. X.nr ^b 2
  191. X.\}
  192. X.if \\n(^v \{\
  193. X.mk ^Y
  194. X.\}
  195. X..
  196. X'    # DS - begin display
  197. X.de DS
  198. X.RS
  199. X.nf
  200. X.sp
  201. X..
  202. X'    # DE - end display
  203. X.de DE
  204. X.fi
  205. X.RE
  206. X.sp .5
  207. X..
  208. X.\"----------------------------------------------------------------------------
  209. X.HS Handles tcl
  210. X.ad b
  211. X.BS
  212. X'@index: Tcl_HandleAlloc Tcl_HandleFree Tcl_HandleTblInit Tcl_HandleTblRelease Tcl_HandleTblUseCount Tcl_HandleWalk Tcl_HandleXlate
  213. X.SH NAME
  214. XTcl_HandleAlloc, Tcl_HandleFree, Tcl_HandleTblInit,
  215. XTcl_HandleTblRelease, Tcl_HandleTblUseCount Tcl_HandleWalk, 
  216. XTcl_HandleXlate \- Dynamic, handle addressable tables.
  217. X
  218. X.SH SYNOPSIS
  219. X.nf
  220. X\fB#include <tclExtend.h>\fR
  221. X.sp
  222. Xvoid_pt
  223. X\fBTcl_HandleTblInit\fR (\fIhandleBase, entrySize, initEntries\fR)
  224. X.sp
  225. Xint
  226. X\fBTcl_HandleTblUseCount\fR (\fIheaderPtr, amount\fR)
  227. X.sp
  228. Xvoid
  229. X\fBTcl_HandleTblRelease\fR (\fIheaderPtr\fR)
  230. X.sp
  231. Xvoid_pt
  232. X\fBTcl_HandleAlloc\fR (\fIheaderPtr, handlePtr\fR)
  233. X.sp
  234. Xvoid
  235. X\fBTcl_HandleFree\fR (\fIheaderPtr, entryPtr\fR)
  236. X.sp
  237. Xvoid_pt
  238. X\fBTcl_HandleWalk\fR (\fIheaderPtr, walkKeyPtr\fR)
  239. X.sp
  240. Xvoid
  241. X\fBTcl_WalkKeyToHandle\fR (\fIheaderPtr, walkKey, handlePtr\fR)
  242. X.sp
  243. Xvoid_pt
  244. X\fBTcl_HandleXlate\fR (\fIinterp, headerPtr, handle\fR)
  245. X.SH ARGUMENTS
  246. X.AS Tcl_Interp *walkKeyPtr
  247. X.AP char *handleBase in
  248. XBase name for the handle, numeric entry number will be appended. 
  249. X.AP int entrySize in
  250. XSize of the table entries, in bytes.
  251. X.AP int initEntries in
  252. XInitial number of entries to allocate.
  253. X.AP int amount in
  254. XAmount to alter the use count by.
  255. X.AP void_pt headerPtr in
  256. XPointer to the header.
  257. X.AP char *handlePtr out
  258. XThe handle name is returned here.  It must be large enough to hold the handle
  259. Xbase name with a number appended.
  260. X.AP Tcl_Interp *interp in
  261. XInterpreter to use for error reporting.
  262. X.AP char *handle in
  263. XName of handle to operate on.
  264. X.AP void_pt entryPtr in
  265. XPointer to a handle table entry.
  266. X.AP int *walkKeyPtr i/o
  267. XKey used to walk the table, initialize to -1 before the first call.
  268. X.AP int walkKey in
  269. XKey returned from walking the table.
  270. X.BE
  271. X
  272. X.SH DESCRIPTION
  273. X.PP
  274. XThe Tcl handle facility provides a way to manage table entries that may be
  275. Xreferenced by a textual handle from Tcl code.  This is provided for 
  276. Xapplications that need to create data structures in one command, return a
  277. Xreference (i.e. pointer) to that particular data structure and then access
  278. Xthat data structure in other commands. An example application is file handles.
  279. X.PP
  280. XA handle consists of a base name, which is some unique, meaningful name, such
  281. Xas `\fBfile\fR' and a numeric value appended to the base name (e.g. `file3').
  282. XThe handle facility is designed to provide a standard mechanism for building
  283. XTcl commands that allocate and access table entries based on an entry index.
  284. XThe tables are expanded when needed, consequently pointers to entries should
  285. Xnot be kept, as they will become invalid when the table is expanded.  If the
  286. Xtable entries are large or pointers must be kept to the entries, then the
  287. Xthe entries should be allocated separately and pointers kept in the handle 
  288. Xtable.  A use count is kept on the table.  This use count is intended to
  289. Xdetermine when a table shared by multiple commands is to be release.
  290. X.PP
  291. X\fBTcl_HandleTblInit\fR creates and initialize a Tcl dynamic handle table. 
  292. XThe specified initial number of entries will be allocated and added to the free
  293. Xlist.  The use count will be set to one.
  294. X.PP
  295. X\fBTcl_HandleTblUseCount\fR alters the use count on a table and returns the
  296. Xnew value.  The use count has \fIamount\fR added to it, where \fIamount\fR may
  297. Xbe positive, zero or negative.  A zero value retrieves the current use count.
  298. XThis is normally used to increment the use count when multiple commands are
  299. Xsharing the table.
  300. X.PP
  301. X\fBTcl_HandleTblRelease\fR decrements the use count on a table. If it becomes
  302. Xzero (or negative), the the table will be released. Note that no clean up is
  303. Xdone on the table entry client supplied data.  If clean up must be done, 
  304. Xthen \fBTcl_HandleTblUseCount\fR can be used to decrement the use count.
  305. XWhen it goes to zero, the table may be walked and then released.
  306. X\fIHeaderPtr\fR is declared as \fBClientData\fR so that the procedure may
  307. Xbe passed as a command deletion procedure.
  308. X.PP
  309. X\fBTcl_HandleAlloc\fR allocates an entry and associates a handle with it.
  310. XThe handle is returned to the buffer pointed to by \fIhandlePtr\fR can then
  311. Xbe used to access the entry.  The buffer must be large enough to accommodate
  312. Xthe base handle name with 2 to 4 digits appended along with a terminating null
  313. Xbyte.
  314. XA pointer is returned to the allocated entry.  If \fBTcl_HandleFree\fR
  315. Xhas not been called since initialization, handles will be handed out
  316. Xsequentially from zero.  This behavior is useful in setting
  317. Xup initial entries, such as ``\fBstdin\fR'' for a file table.
  318. X.PP
  319. X\fBTcl_HandleXlate\fR translates a handle to a pointer to the corresponding
  320. Xtable entry.  If the handle is not allocated (open) or is invalid, NULL is
  321. Xreturned and an error message is set in \fIinterp->result\fR.
  322. X.PP
  323. X\fBTcl_HandleWalk\fR walks through and finds every allocated entry in a table.
  324. XEntries may be deallocated during a walk, but should not be allocated.
  325. X\fBTcl_HandleWalk\fR
  326. Xwill return a pointer to the entry, or NULL if no more entries are available.
  327. XThe integer pointed to by \fBwalkKeyPtr\fR should be set to `-1' before the
  328. Xfirst call, and then the pointer passed to each subsequent call left 
  329. Xunmodified.
  330. X.PP
  331. X\fBTcl_WalkKeyToHandle\fR converts a walk key, as returned from a call to
  332. X\fBTcl_HandleWalk\fR into a handle.
  333. X.PP
  334. X\fBTcl_HandleFree\fR frees a handle table entry.
  335. X.SH KEYWORDS
  336. Xhandle, table, allocate
  337. END_OF_FILE
  338. if test 9032 -ne `wc -c <'extended/man/Handles.man'`; then
  339.     echo shar: \"'extended/man/Handles.man'\" unpacked with wrong size!
  340. fi
  341. # end of 'extended/man/Handles.man'
  342. fi
  343. if test -f 'extended/src/createExtd.c' -a "${1}" != "-c" ; then 
  344.   echo shar: Will not clobber existing file \"'extended/src/createExtd.c'\"
  345. else
  346. echo shar: Extracting \"'extended/src/createExtd.c'\" \(9419 characters\)
  347. sed "s/^X//" >'extended/src/createExtd.c' <<'END_OF_FILE'
  348. X/*
  349. X * createExtd.c
  350. X *
  351. X * Contains a routine to create an interpreter and initialize all the Extended
  352. X * Tcl commands.  It is is a seperate file so that an application may create
  353. X * the interpreter and add in only a subset of the Extended Tcl commands.
  354. X *---------------------------------------------------------------------------
  355. X * Copyright 1991 Karl Lehenbauer and Mark Diekhans.
  356. X *
  357. X * Permission to use, copy, modify, and distribute this software and its
  358. X * documentation for any purpose and without fee is hereby granted, provided
  359. X * that the above copyright notice appear in all copies.  Karl Lehenbauer and
  360. X * Mark Diekhans make no representations about the suitability of this
  361. X * software for any purpose.  It is provided "as is" without express or
  362. X * implied warranty.
  363. X */
  364. X
  365. X#include "tclExtdInt.h"
  366. X
  367. Xint matherr ();
  368. X
  369. X
  370. X/*
  371. X *----------------------------------------------------------------------
  372. X *
  373. X * Tcl_CreateExtendedInterp --
  374. X *
  375. X *      Create a new TCL command interpreter and initialize all of the
  376. X *      extended Tcl commands..
  377. X *
  378. X * Results:
  379. X *      The return value is a token for the interpreter.
  380. X *----------------------------------------------------------------------
  381. X */
  382. XTcl_Interp *
  383. XTcl_CreateExtendedInterp ()
  384. X{
  385. X    Tcl_Interp *interp;
  386. X    int         (*bringIn)();
  387. X
  388. X    interp = Tcl_CreateInterp ();
  389. X
  390. X    /*
  391. X     * This is a little kludge to make sure matherr is brought in from the
  392. X     * Tcl library if it is not already defined.  This could be done on the
  393. X     * link line, but this makes sure it happens.
  394. X     */
  395. X    bringIn = matherr;
  396. X
  397. X    /*
  398. X     * from tclCkalloc.c (now part of the UCB Tcl).
  399. X     */
  400. X#ifdef TCL_MEM_DEBUG    
  401. X    Tcl_InitMemory (interp);
  402. X#endif
  403. X
  404. X    /*
  405. X     * from chmod.c
  406. X     */
  407. X    Tcl_CreateCommand (interp, "chgrp", Tcl_ChgrpCmd, (ClientData)NULL,
  408. X                      (void (*)())NULL);
  409. X    Tcl_CreateCommand (interp, "chmod", Tcl_ChmodCmd, (ClientData)NULL,
  410. X                      (void (*)())NULL);
  411. X    Tcl_CreateCommand (interp, "chown", Tcl_ChownCmd, (ClientData)NULL,
  412. X                      (void (*)())NULL);
  413. X
  414. X    /*
  415. X     * from clock.c
  416. X     */
  417. X    Tcl_CreateCommand (interp, "getclock", Tcl_GetclockCmd, 
  418. X                      (ClientData)NULL, (void (*)())NULL);
  419. X    Tcl_CreateCommand (interp, "fmtclock", Tcl_FmtclockCmd, 
  420. X                      (ClientData)NULL, (void (*)())NULL);
  421. X
  422. X    /*
  423. X     * from cmdloop.c
  424. X     */
  425. X    Tcl_CreateCommand (interp, "commandloop", Tcl_CommandloopCmd, 
  426. X                      (ClientData)NULL, (void (*)())NULL);
  427. X
  428. X    /*
  429. X     * from debug.c
  430. X     */
  431. X    Tcl_InitDebug (interp);
  432. X
  433. X    /*
  434. X     * from filescan.c
  435. X     */
  436. X    Tcl_InitFilescan (interp);
  437. X
  438. X    /*
  439. X     * from fmath.c
  440. X     */
  441. X    Tcl_CreateCommand(interp, "acos", Tcl_AcosCmd, 
  442. X                     (ClientData)NULL, (void (*)())NULL);
  443. X    Tcl_CreateCommand(interp, "asin", Tcl_AsinCmd, 
  444. X                     (ClientData)NULL, (void (*)())NULL);
  445. X    Tcl_CreateCommand(interp, "atan", Tcl_AtanCmd, 
  446. X                     (ClientData)NULL, (void (*)())NULL);
  447. X    Tcl_CreateCommand(interp, "cos", Tcl_CosCmd, 
  448. X                     (ClientData)NULL, (void (*)())NULL);
  449. X    Tcl_CreateCommand(interp, "sin", Tcl_SinCmd, 
  450. X                     (ClientData)NULL, (void (*)())NULL);
  451. X    Tcl_CreateCommand(interp, "tan", Tcl_TanCmd, 
  452. X                     (ClientData)NULL, (void (*)())NULL);
  453. X    Tcl_CreateCommand(interp, "cosh", Tcl_CoshCmd, 
  454. X                     (ClientData)NULL, (void (*)())NULL);
  455. X    Tcl_CreateCommand(interp, "sinh", Tcl_SinhCmd, 
  456. X                     (ClientData)NULL, (void (*)())NULL);
  457. X    Tcl_CreateCommand(interp, "tanh", Tcl_TanhCmd, 
  458. X                     (ClientData)NULL, (void (*)())NULL);
  459. X    Tcl_CreateCommand(interp, "exp", Tcl_ExpCmd, 
  460. X                     (ClientData)NULL, (void (*)())NULL);
  461. X    Tcl_CreateCommand(interp, "log", Tcl_LogCmd, 
  462. X                     (ClientData)NULL, (void (*)())NULL);
  463. X    Tcl_CreateCommand(interp, "log10", Tcl_Log10Cmd, 
  464. X                     (ClientData)NULL, (void (*)())NULL);
  465. X    Tcl_CreateCommand(interp, "sqrt", Tcl_SqrtCmd, 
  466. X                     (ClientData)NULL, (void (*)())NULL);
  467. X    Tcl_CreateCommand(interp, "fabs", Tcl_FabsCmd, 
  468. X                     (ClientData)NULL, (void (*)())NULL);
  469. X    Tcl_CreateCommand(interp, "floor", Tcl_FloorCmd, 
  470. X                     (ClientData)NULL, (void (*)())NULL);
  471. X    Tcl_CreateCommand(interp, "ceil", Tcl_CeilCmd, 
  472. X                     (ClientData)NULL, (void (*)())NULL);
  473. X    Tcl_CreateCommand(interp, "fmod", Tcl_FmodCmd, 
  474. X                     (ClientData)NULL, (void (*)())NULL);
  475. X    Tcl_CreateCommand(interp, "pow", Tcl_PowCmd, 
  476. X                     (ClientData)NULL, (void (*)())NULL);
  477. X
  478. X    /*
  479. X     * from general.c
  480. X     */
  481. X    Tcl_CreateCommand(interp, "echo", Tcl_EchoCmd, 
  482. X                     (ClientData)NULL, (void (*)())NULL);
  483. X    Tcl_CreateCommand(interp, "infox", Tcl_InfoxCmd, 
  484. X                     (ClientData)NULL, (void (*)())NULL);
  485. X    Tcl_CreateCommand(interp, "loop", Tcl_LoopCmd, 
  486. X                     (ClientData)NULL, (void (*)())NULL);
  487. X
  488. X    /*
  489. X     * from id.c
  490. X     */
  491. X    Tcl_CreateCommand (interp, "id", Tcl_IdCmd, (ClientData)NULL,
  492. X                      (void (*)())NULL);
  493. X
  494. X    /*
  495. X     * from iocmds.c
  496. X     */
  497. X    Tcl_CreateCommand (interp, "bsearch", Tcl_BsearchCmd, 
  498. X                      (ClientData)NULL, (void (*)())NULL);
  499. X    Tcl_CreateCommand (interp, "dup",  Tcl_DupCmd, 
  500. X                       (ClientData) NULL, (void (*)())NULL);
  501. X    Tcl_CreateCommand (interp, "pipe", Tcl_PipeCmd,
  502. X                       (ClientData) NULL, (void (*)())NULL);
  503. X    Tcl_CreateCommand (interp, "copyfile", Tcl_CopyfileCmd,
  504. X                       (ClientData) NULL, (void (*)())NULL);
  505. X    Tcl_CreateCommand (interp, "fstat", Tcl_FstatCmd,
  506. X                       (ClientData) NULL, (void (*)())NULL);
  507. X    Tcl_CreateCommand (interp, "fcntl", Tcl_FcntlCmd,
  508. X                       (ClientData) NULL, (void (*)())NULL);
  509. X    Tcl_CreateCommand (interp, "select", Tcl_SelectCmd,
  510. X                       (ClientData) NULL, (void (*)())NULL);
  511. X
  512. X    /*
  513. X     * from list.c
  514. X     */
  515. X    Tcl_CreateCommand(interp, "lvarpop", Tcl_LvarpopCmd, 
  516. X                     (ClientData)NULL, (void (*)())NULL);
  517. X    Tcl_CreateCommand(interp, "lempty", Tcl_LemptyCmd, 
  518. X                     (ClientData)NULL, (void (*)())NULL);
  519. X    Tcl_CreateCommand(interp, "keyldel", Tcl_KeyldelCmd,
  520. X                     (ClientData)NULL, (void (*)())NULL);
  521. X    Tcl_CreateCommand(interp, "keylget", Tcl_KeylgetCmd,
  522. X                     (ClientData)NULL, (void (*)())NULL);
  523. X    Tcl_CreateCommand(interp, "keylset", Tcl_KeylsetCmd,
  524. X                     (ClientData)NULL, (void (*)())NULL);
  525. X
  526. X    /*
  527. X     * from math.c
  528. X     */
  529. X    Tcl_CreateCommand (interp, "max", Tcl_MaxCmd, (ClientData)NULL, 
  530. X              (void (*)())NULL);
  531. X    Tcl_CreateCommand (interp, "min", Tcl_MinCmd, (ClientData)NULL, 
  532. X              (void (*)())NULL);
  533. X    Tcl_CreateCommand (interp, "random", Tcl_RandomCmd, (ClientData)NULL, 
  534. X              (void (*)())NULL);
  535. X
  536. X    /*
  537. X     * from signal.c
  538. X     */
  539. X    Tcl_InitSignalHandling (interp);
  540. X
  541. X    /*
  542. X     * from string.c
  543. X     */
  544. X    Tcl_CreateCommand(interp, "cindex", Tcl_CindexCmd, 
  545. X                     (ClientData)NULL, (void (*)())NULL);
  546. X    Tcl_CreateCommand(interp, "clength", Tcl_ClengthCmd, 
  547. X                     (ClientData)NULL, (void (*)())NULL);
  548. X    Tcl_CreateCommand(interp, "crange", Tcl_CrangeCmd, 
  549. X                     (ClientData)NULL, (void (*)())NULL);
  550. X    Tcl_CreateCommand(interp, "csubstr", Tcl_CrangeCmd, 
  551. X                     (ClientData)NULL, (void (*)())NULL);
  552. X    Tcl_CreateCommand(interp, "replicate", Tcl_ReplicateCmd, 
  553. X                     (ClientData)NULL, (void (*)())NULL);
  554. X    Tcl_CreateCommand (interp, "translit", Tcl_TranslitCmd, (ClientData)NULL,
  555. X                       (void (*)())NULL);
  556. X    Tcl_CreateCommand (interp, "ctype", Tcl_CtypeCmd,
  557. X                       (ClientData)NULL, (void (*)())NULL);
  558. X
  559. X    /*
  560. X     * from unixcmds.c
  561. X     */
  562. X    Tcl_CreateCommand (interp, "execvp", Tcl_ExecvpCmd, (ClientData)NULL,
  563. X                      (void (*)())NULL);
  564. X    Tcl_CreateCommand (interp, "fork", Tcl_ForkCmd, (ClientData)NULL,
  565. X                      (void (*)())NULL);
  566. X    Tcl_CreateCommand (interp, "kill", Tcl_KillCmd, (ClientData)NULL,
  567. X                      (void (*)())NULL);
  568. X    Tcl_CreateCommand (interp, "system", Tcl_SystemCmd, (ClientData)NULL,
  569. X                      (void (*)())NULL);
  570. X    Tcl_CreateCommand (interp, "times", Tcl_TimesCmd, (ClientData)NULL,
  571. X                      (void (*)())NULL);
  572. X    Tcl_CreateCommand (interp, "umask", Tcl_UmaskCmd, (ClientData)NULL,
  573. X                      (void (*)())NULL);
  574. X    Tcl_CreateCommand (interp, "wait", Tcl_WaitCmd, (ClientData)NULL,
  575. X                      (void (*)())NULL);
  576. X    Tcl_CreateCommand (interp, "link", Tcl_LinkCmd, (ClientData)NULL,
  577. X                      (void (*)())NULL);
  578. X    Tcl_CreateCommand (interp, "unlink", Tcl_UnlinkCmd, (ClientData)NULL,
  579. X                      (void (*)())NULL);
  580. X    Tcl_CreateCommand (interp, "mkdir", Tcl_MkdirCmd, (ClientData)NULL,
  581. X                      (void (*)())NULL);
  582. X    Tcl_CreateCommand (interp, "rmdir", Tcl_RmdirCmd, (ClientData)NULL,
  583. X                      (void (*)())NULL);
  584. X    Tcl_CreateCommand (interp, "alarm", Tcl_AlarmCmd, (ClientData)NULL, 
  585. X                      (void (*)())NULL);
  586. X    Tcl_CreateCommand (interp, "sleep", Tcl_SleepCmd, (ClientData)NULL, 
  587. X                      (void (*)())NULL);
  588. X    return interp;
  589. X}
  590. END_OF_FILE
  591. if test 9419 -ne `wc -c <'extended/src/createExtd.c'`; then
  592.     echo shar: \"'extended/src/createExtd.c'\" unpacked with wrong size!
  593. fi
  594. # end of 'extended/src/createExtd.c'
  595. fi
  596. if test -f 'extended/src/debug.c' -a "${1}" != "-c" ; then 
  597.   echo shar: Will not clobber existing file \"'extended/src/debug.c'\"
  598. else
  599. echo shar: Extracting \"'extended/src/debug.c'\" \(9678 characters\)
  600. sed "s/^X//" >'extended/src/debug.c' <<'END_OF_FILE'
  601. X/*
  602. X * debug.c --
  603. X *
  604. X * Tcl command execution trace command.
  605. X *---------------------------------------------------------------------------
  606. X * Copyright 1991 Karl Lehenbauer and Mark Diekhans.
  607. X *
  608. X * Permission to use, copy, modify, and distribute this software and its
  609. X * documentation for any purpose and without fee is hereby granted, provided
  610. X * that the above copyright notice appear in all copies.  Karl Lehenbauer and
  611. X * Mark Diekhans make no representations about the suitability of this
  612. X * software for any purpose.  It is provided "as is" without express or
  613. X * implied warranty.
  614. X */
  615. X
  616. X#include "tclExtdInt.h"
  617. X
  618. X/*
  619. X * Clientdata structure for trace commands.
  620. X */
  621. X#define ARG_TRUNCATE_SIZE 40
  622. X#define CMD_TRUNCATE_SIZE 60
  623. X
  624. Xstruct traceInfo_t {
  625. X    Tcl_Interp *interp;
  626. X    Tcl_Trace   traceHolder;
  627. X    int         noEval;
  628. X    int         noTruncate;
  629. X    int         flush;
  630. X    int         depth;
  631. X    FILE       *filePtr;
  632. X    };
  633. Xtypedef struct traceInfo_t *traceInfo_pt;
  634. X
  635. X/*
  636. X * Prototypes of internal functions.
  637. X */
  638. Xstatic void
  639. XPrintStr _ANSI_ARGS_((FILE *filePtr,
  640. X                      char *string,
  641. X                      int   numChars));
  642. X
  643. Xstatic void
  644. XPrintArg _ANSI_ARGS_((FILE *filePtr,
  645. X                      char *argStr,
  646. X                      int   noTruncate));
  647. X
  648. Xstatic void
  649. XTraceRoutine _ANSI_ARGS_((ClientData    clientData,
  650. X                          Tcl_Interp   *interp,
  651. X                          int           level,
  652. X                          char         *command,
  653. X                          int           (*cmdProc)(),
  654. X                          ClientData    cmdClientData,
  655. X                          int           argc,
  656. X                          char         *argv[]));
  657. X
  658. Xstatic void
  659. XCleanUpDebug _ANSI_ARGS_((ClientData clientData));
  660. X
  661. X/*
  662. X *----------------------------------------------------------------------
  663. X *
  664. X * PrintStr --
  665. X *     Print an string, truncating it to the specified number of characters.
  666. X * If the string contains newlines, \n is substituted.
  667. X *
  668. X *----------------------------------------------------------------------
  669. X */
  670. Xstatic void
  671. XPrintStr (filePtr, string, numChars)
  672. X    FILE *filePtr;
  673. X    char *string;
  674. X    int   numChars;
  675. X{
  676. X    int idx;
  677. X
  678. X    for (idx = 0; idx < numChars; idx++) {
  679. X        if (string [idx] == '\n') {
  680. X           putc ('\\', filePtr);
  681. X           putc ('n', filePtr);
  682. X        } else
  683. X           putc (string [idx], filePtr);
  684. X    }
  685. X    if (numChars < strlen (string))
  686. X        fprintf (filePtr, "...");
  687. X}
  688. X
  689. X/*
  690. X *----------------------------------------------------------------------
  691. X *
  692. X * PrintArg --
  693. X *     Print an argument string, truncating and adding "..." if its longer
  694. X *     then ARG_TRUNCATE_SIZE.  If the string contains white spaces, quote
  695. X *     it with angle brackets.
  696. X *
  697. X *----------------------------------------------------------------------
  698. X */
  699. Xstatic void
  700. XPrintArg (filePtr, argStr, noTruncate)
  701. X    FILE *filePtr;
  702. X    char *argStr;
  703. X    int   noTruncate;
  704. X{
  705. X    int idx, argLen, printLen;
  706. X    int quote_it;
  707. X
  708. X    argLen = strlen (argStr);
  709. X    printLen = argLen;
  710. X    if ((!noTruncate) && (printLen > ARG_TRUNCATE_SIZE))
  711. X        printLen = ARG_TRUNCATE_SIZE;
  712. X
  713. X    quote_it = (printLen == 0);
  714. X
  715. X    for (idx = 0; idx < printLen; idx++)
  716. X        if (isspace (argStr [idx])) {
  717. X            quote_it = TRUE;
  718. X            break;
  719. X        }
  720. X
  721. X    if (quote_it) 
  722. X        putc ('{', filePtr);
  723. X    PrintStr (filePtr, argStr, printLen);
  724. X    if (quote_it) 
  725. X        putc ('}', filePtr);
  726. X}
  727. X
  728. X/*
  729. X *----------------------------------------------------------------------
  730. X *
  731. X * TraceRoutine --
  732. X *  Routine called by Tcl_Eval to trace a command.
  733. X *
  734. X *----------------------------------------------------------------------
  735. X */
  736. Xstatic void
  737. XTraceRoutine (clientData, interp, level, command, cmdProc, cmdClientData, 
  738. X              argc, argv)
  739. X    ClientData    clientData;
  740. X    Tcl_Interp   *interp;
  741. X    int           level;
  742. X    char         *command;
  743. X    int           (*cmdProc)();
  744. X    ClientData    cmdClientData;
  745. X    int           argc;
  746. X    char         *argv[];
  747. X{
  748. X    traceInfo_pt traceInfoPtr = (traceInfo_pt) clientData;
  749. X    int          idx, cmdLen, printLen;
  750. X
  751. X    fprintf (traceInfoPtr->filePtr, "%2d", level);
  752. X
  753. X    if (level > 20) level = 20;
  754. X    for (idx = 0; idx < level; idx++) 
  755. X        fprintf (traceInfoPtr->filePtr, "  ");
  756. X
  757. X    if (traceInfoPtr->noEval) {
  758. X        cmdLen = printLen = strlen (command);
  759. X        if ((!traceInfoPtr->noTruncate) && (printLen > CMD_TRUNCATE_SIZE))
  760. X            printLen = CMD_TRUNCATE_SIZE;
  761. X
  762. X        PrintStr (traceInfoPtr->filePtr, command, printLen);
  763. X      } else {
  764. X          for (idx = 0; idx < argc; idx++) {
  765. X              if (idx > 0)
  766. X                  putc (' ', traceInfoPtr->filePtr);
  767. X              PrintArg (traceInfoPtr->filePtr, argv[idx], 
  768. X                        traceInfoPtr->noTruncate);
  769. X          }
  770. X    }
  771. X
  772. X    putc ('\n', traceInfoPtr->filePtr);
  773. X    if (traceInfoPtr->flush)
  774. X        fflush (traceInfoPtr->filePtr);
  775. X    return;
  776. X}
  777. X
  778. X/*
  779. X *----------------------------------------------------------------------
  780. X *
  781. X * Tcl_CmdtraceCmd --
  782. X *     Implements the TCL trace command:
  783. X *     cmdtrace level|on [noeval] [notruncate]
  784. X *     cmdtrace off
  785. X *     cmdtrace depth
  786. X *
  787. X * Results:
  788. X *  Standard TCL results.
  789. X *
  790. X *----------------------------------------------------------------------
  791. X */
  792. Xstatic int
  793. XTcl_CmdtraceCmd (clientData, interp, argc, argv)
  794. X    ClientData    clientData;
  795. X    Tcl_Interp   *interp;
  796. X    int           argc;
  797. X    char        **argv;
  798. X{
  799. X    traceInfo_pt infoPtr = (traceInfo_pt) clientData;
  800. X    int          idx;
  801. X    char        *fileHandle;
  802. X
  803. X    if (argc < 2)
  804. X        goto argumentError;
  805. X
  806. X    /*
  807. X     * Handle `depth' sub-command.
  808. X     */
  809. X    if (STREQU (argv[1], "depth")) {
  810. X        if (argc != 2)
  811. X            goto argumentError;
  812. X        sprintf(interp->result, "%d", infoPtr->depth);
  813. X        return TCL_OK;
  814. X    }
  815. X
  816. X    /*
  817. X     * If a trace is in progress, delete it now.
  818. X     */
  819. X    if (infoPtr->traceHolder != NULL) {
  820. X        Tcl_DeleteTrace(interp, infoPtr->traceHolder);
  821. X        infoPtr->depth = 0;
  822. X        infoPtr->traceHolder = NULL;
  823. X    }
  824. X
  825. X    /*
  826. X     * Handle off sub-command.
  827. X     */
  828. X    if (STREQU (argv[1], "off")) {
  829. X        if (argc != 2)
  830. X            goto argumentError;
  831. X        return TCL_OK;
  832. X    }
  833. X
  834. X    infoPtr->noEval = FALSE;
  835. X    infoPtr->noTruncate = FALSE;
  836. X    infoPtr->flush = FALSE;
  837. X    infoPtr->filePtr = stdout;
  838. X    fileHandle = NULL;
  839. X
  840. X    for (idx = 2; idx < argc; idx++) {
  841. X        if (STREQU (argv[idx], "notruncate")) {
  842. X            if (infoPtr->noTruncate)
  843. X                goto argumentError;
  844. X            infoPtr->noTruncate = TRUE;
  845. X            continue;
  846. X        }
  847. X        if (STREQU (argv[idx], "noeval")) {
  848. X            if (infoPtr->noEval)
  849. X                goto argumentError;
  850. X            infoPtr->noEval = TRUE;
  851. X            continue;
  852. X        }
  853. X        if (STREQU (argv[idx], "flush")) {
  854. X            if (infoPtr->flush)
  855. X                goto argumentError;
  856. X            infoPtr->flush = TRUE;
  857. X            continue;
  858. X        }
  859. X        if (STRNEQU (argv [idx], "std", 3) || 
  860. X                STRNEQU (argv [idx], "file", 4)) {
  861. X            if (fileHandle != NULL)
  862. X                goto argumentError;
  863. X            fileHandle = argv [idx];
  864. X            continue;
  865. X        }
  866. X        goto invalidOption;
  867. X    }
  868. X
  869. X    if (STREQU (argv[1], "on")) {
  870. X        infoPtr->depth = MAXINT;
  871. X    } else {
  872. X        if (Tcl_GetInt (interp, argv[1], &(infoPtr->depth)) != TCL_OK)
  873. X            return TCL_ERROR;
  874. X    }
  875. X    if (fileHandle != NULL) {
  876. X        OpenFile *tclFilePtr;
  877. X
  878. X        if (TclGetOpenFile (interp, fileHandle, &tclFilePtr) != TCL_OK)
  879. X        return TCL_ERROR;
  880. X        if (!tclFilePtr->writable) {
  881. X            Tcl_AppendResult (interp, "file not writable: ", fileHandle,
  882. X                              (char *) NULL);
  883. X            return TCL_ERROR;
  884. X        }
  885. X        infoPtr->filePtr = tclFilePtr->f;
  886. X    }
  887. X      
  888. X    infoPtr->traceHolder = 
  889. X        Tcl_CreateTrace (interp, infoPtr->depth, TraceRoutine, 
  890. X                         (ClientData)infoPtr);
  891. X    return TCL_OK;
  892. X
  893. XargumentError:
  894. X    Tcl_AppendResult (interp, "wrong # args: ", argv [0], 
  895. X                      " level | on [noeval] [notruncate] [flush] ",
  896. X                      "[handle] | off | depth", (char *) NULL);
  897. X    return TCL_ERROR;
  898. X
  899. XinvalidOption:
  900. X    Tcl_AppendResult (interp, argv [0], ":invalid option: expected ",
  901. X                      "one of noeval, notruncate, flush or a ",
  902. X                      "file handle", (char *) NULL);
  903. X    return TCL_ERROR;
  904. X}
  905. X
  906. X/*
  907. X *----------------------------------------------------------------------
  908. X *
  909. X *  CleanUpDebug --
  910. X *
  911. X *  Release the client data area when the trace command is deleted.
  912. X *
  913. X *----------------------------------------------------------------------
  914. X */
  915. Xstatic void
  916. XCleanUpDebug (clientData)
  917. X    ClientData clientData;
  918. X{
  919. X    traceInfo_pt infoPtr = (traceInfo_pt) clientData;
  920. X
  921. X    if (infoPtr->traceHolder != NULL)
  922. X        Tcl_DeleteTrace (infoPtr->interp, infoPtr->traceHolder);
  923. X    ckfree ((char *) infoPtr);
  924. X}
  925. X
  926. X/*
  927. X *----------------------------------------------------------------------
  928. X *
  929. X *  Tcl_InitDebug --
  930. X *
  931. X *  Initialize the TCL debugging commands.
  932. X *
  933. X *----------------------------------------------------------------------
  934. X */
  935. Xvoid
  936. XTcl_InitDebug (interp)
  937. X    Tcl_Interp *interp;
  938. X{
  939. X    traceInfo_pt infoPtr;
  940. X
  941. X    infoPtr = (traceInfo_pt)ckalloc (sizeof (struct traceInfo_t));
  942. X
  943. X    infoPtr->interp=interp;  /* Save just so we can delete traces at the end */
  944. X    infoPtr->traceHolder = NULL;
  945. X    infoPtr->noEval = FALSE;
  946. X    infoPtr->noTruncate = FALSE;
  947. X    infoPtr->flush = FALSE;
  948. X    infoPtr->depth = 0;
  949. X
  950. X    Tcl_CreateCommand (interp, "cmdtrace", Tcl_CmdtraceCmd, 
  951. X                       (ClientData)infoPtr, CleanUpDebug);
  952. X}
  953. X
  954. X
  955. END_OF_FILE
  956. if test 9678 -ne `wc -c <'extended/src/debug.c'`; then
  957.     echo shar: \"'extended/src/debug.c'\" unpacked with wrong size!
  958. fi
  959. # end of 'extended/src/debug.c'
  960. fi
  961. if test -f 'extended/src/id.c' -a "${1}" != "-c" ; then 
  962.   echo shar: Will not clobber existing file \"'extended/src/id.c'\"
  963. else
  964. echo shar: Extracting \"'extended/src/id.c'\" \(9404 characters\)
  965. sed "s/^X//" >'extended/src/id.c' <<'END_OF_FILE'
  966. X/*
  967. X * id.c --
  968. X *
  969. X * Tcl commands to access getuid, setuid, getgid, setgid and friends.
  970. X *---------------------------------------------------------------------------
  971. X * Copyright 1991 Karl Lehenbauer and Mark Diekhans.
  972. X *
  973. X * Permission to use, copy, modify, and distribute this software and its
  974. X * documentation for any purpose and without fee is hereby granted, provided
  975. X * that the above copyright notice appear in all copies.  Karl Lehenbauer and
  976. X * Mark Diekhans make no representations about the suitability of this
  977. X * software for any purpose.  It is provided "as is" without express or
  978. X * implied warranty.
  979. X */
  980. X
  981. X#include "tclExtdInt.h"
  982. X
  983. X/*
  984. X * Prototypes of internal functions.
  985. X */
  986. Xint
  987. XUseridToUsernameResult _ANSI_ARGS_((Tcl_Interp *interp,
  988. X                                    int         userId));
  989. X
  990. Xint
  991. XUsernameToUseridResult _ANSI_ARGS_((Tcl_Interp *interp,
  992. X                                    char       *userName));
  993. X
  994. Xint
  995. XGroupidToGroupnameResult _ANSI_ARGS_((Tcl_Interp *interp,
  996. X                                      int         groupId));
  997. X
  998. Xint
  999. XGroupnameToGroupidResult _ANSI_ARGS_((Tcl_Interp *interp,
  1000. X                                      char       *groupName));
  1001. X
  1002. X
  1003. X/*
  1004. X *----------------------------------------------------------------------
  1005. X *
  1006. X * Tcl_IdCmd --
  1007. X *     Implements the TCL id command:
  1008. X *
  1009. X *        id user [name]
  1010. X *        id convert user <name>
  1011. X *
  1012. X *        id userid [uid]
  1013. X *        id convert userid <uid>
  1014. X *
  1015. X *        id group [name]
  1016. X *        id convert group <name>
  1017. X *
  1018. X *        id groupid [gid]
  1019. X *        id convert groupid <gid>
  1020. X *
  1021. X *        id process
  1022. X *        id process parent
  1023. X *        id process group
  1024. X *        id process group set
  1025. X *
  1026. X *        id effective user
  1027. X *        id effective userid
  1028. X *
  1029. X *        id effective group
  1030. X *        id effective groupid
  1031. X *
  1032. X * Results:
  1033. X *  Standard TCL results, may return the UNIX system error message.
  1034. X *
  1035. X *----------------------------------------------------------------------
  1036. X */
  1037. X
  1038. Xstatic int
  1039. XUseridToUsernameResult (interp, userId)
  1040. X    Tcl_Interp *interp;
  1041. X    int         userId;
  1042. X{
  1043. X    struct passwd *pw = getpwuid (userId);
  1044. X    if (pw == NULL) {
  1045. X        char numBuf [32];
  1046. X
  1047. X        sprintf (numBuf, "%d", userId);
  1048. X        Tcl_AppendResult (interp, "unknown user id: ", numBuf, (char *) NULL);
  1049. X        return TCL_ERROR;
  1050. X    }
  1051. X    strcpy (interp->result, pw->pw_name);
  1052. X    return TCL_OK;
  1053. X}
  1054. X
  1055. Xstatic int
  1056. XUsernameToUseridResult (interp, userName)
  1057. X    Tcl_Interp *interp;
  1058. X    char       *userName;
  1059. X{
  1060. X    struct passwd *pw = getpwnam (userName);
  1061. X    if (pw == NULL) {
  1062. X        Tcl_AppendResult (interp, "unknown user id: ", userName, 
  1063. X                          (char *) NULL);
  1064. X        return TCL_ERROR;
  1065. X    }
  1066. X    sprintf (interp->result, "%d", pw->pw_uid);
  1067. X    return TCL_OK;
  1068. X}
  1069. X
  1070. Xstatic int
  1071. XGroupidToGroupnameResult (interp, groupId)
  1072. X    Tcl_Interp *interp;
  1073. X    int         groupId;
  1074. X{
  1075. X    struct group *grp = getgrgid (groupId);
  1076. X    if (grp == NULL) {
  1077. X        char numBuf [32];
  1078. X
  1079. X        sprintf (numBuf, "%d", groupId);
  1080. X        Tcl_AppendResult (interp, "unknown group id: ", numBuf, (char *) NULL);
  1081. X        return TCL_ERROR;
  1082. X    }
  1083. X    strcpy (interp->result, grp->gr_name);
  1084. X    return TCL_OK;
  1085. X}
  1086. X
  1087. Xstatic int
  1088. XGroupnameToGroupidResult (interp, groupName)
  1089. X    Tcl_Interp *interp;
  1090. X    char       *groupName;
  1091. X{
  1092. X    struct group *grp = getgrnam (groupName);
  1093. X    if (grp == NULL) {
  1094. X        Tcl_AppendResult (interp, "unknown group id: ", groupName,
  1095. X                          (char *) NULL);
  1096. X        return TCL_ERROR;
  1097. X    }
  1098. X    sprintf (interp->result, "%d", grp->gr_gid);
  1099. X    return TCL_OK;
  1100. X}
  1101. X
  1102. Xint
  1103. XTcl_IdCmd (clientData, interp, argc, argv)
  1104. X    ClientData  clientData;
  1105. X    Tcl_Interp *interp;
  1106. X    int         argc;
  1107. X    char      **argv;
  1108. X{
  1109. X    struct passwd *pw;
  1110. X    struct group *grp;
  1111. X    int uid, gid;
  1112. X
  1113. X    if (argc < 2) goto bad_args;
  1114. X
  1115. X    /*
  1116. X     * If the first argument is "convert", handle the conversion.
  1117. X     */
  1118. X    if (STREQU (argv[1], "convert")) {
  1119. X        if (argc != 4) {
  1120. X            Tcl_AppendResult (interp, "wrong # args: ", argv [0], 
  1121. X                              " convert arg arg", (char *) NULL);
  1122. X            return TCL_ERROR;
  1123. X        }
  1124. X
  1125. X        if (STREQU (argv[2], "user"))
  1126. X            return UsernameToUseridResult (interp, argv[3]);
  1127. X
  1128. X        if (STREQU (argv[2], "userid")) {
  1129. X            if (Tcl_GetInt (interp, argv[3], &uid) != TCL_OK) 
  1130. X                return TCL_ERROR;
  1131. X            return UseridToUsernameResult (interp, uid);
  1132. X        }
  1133. X
  1134. X        if (STREQU (argv[2], "group"))
  1135. X            return GroupnameToGroupidResult (interp, argv[3]);
  1136. X
  1137. X        if (STREQU (argv[2], "groupid")) {
  1138. X            if (Tcl_GetInt (interp, argv[3], &gid) != TCL_OK) return TCL_ERROR;
  1139. X            return GroupidToGroupnameResult (interp, gid);
  1140. X
  1141. X        }
  1142. X        goto bad_three_arg;
  1143. X    }
  1144. X
  1145. X    /*
  1146. X     * If the first argument is "effective", return the effective user ID,
  1147. X     * name, group ID or name.
  1148. X     */
  1149. X    if (STREQU (argv[1], "effective")) {
  1150. X        if (argc != 3) {
  1151. X            Tcl_AppendResult (interp, "wrong # args: ", argv [0], 
  1152. X                              " effective arg", (char *) NULL);
  1153. X            return TCL_ERROR;
  1154. X        }
  1155. X
  1156. X        if (STREQU (argv[2], "user"))
  1157. X            return UseridToUsernameResult (interp, geteuid ());
  1158. X
  1159. X        if (STREQU (argv[2], "userid")) {
  1160. X            sprintf (interp->result, "%d", geteuid ());
  1161. X            return TCL_OK;
  1162. X        }
  1163. X
  1164. X        if (STREQU (argv[2], "group"))
  1165. X            return GroupidToGroupnameResult (interp, getegid ());
  1166. X
  1167. X        if (STREQU (argv[2], "groupid")) {
  1168. X            sprintf (interp->result, "%d", getegid ());
  1169. X            return TCL_OK;
  1170. X        }
  1171. X      goto bad_three_arg;
  1172. X    }
  1173. X
  1174. X    /*
  1175. X     * If the first argument is "process", return the process ID, parent's
  1176. X     * process ID, process group or set the process group depending on args.
  1177. X     */
  1178. X    if (STREQU (argv[1], "process")) {
  1179. X        if (argc == 2) {
  1180. X            sprintf (interp->result, "%d", getpid ());
  1181. X            return TCL_OK;
  1182. X        }
  1183. X
  1184. X        if (STREQU (argv[2], "parent")) {
  1185. X            if (argc != 3) {
  1186. X                Tcl_AppendResult (interp, "wrong # args: ", argv [0], 
  1187. X                                  " process parent", (char *) NULL);
  1188. X                return TCL_ERROR;
  1189. X            }
  1190. X            sprintf (interp->result, "%d", getppid ());
  1191. X            return TCL_OK;
  1192. X        }
  1193. X        if (STREQU (argv[2], "group")) {
  1194. X            if (argc == 3) {
  1195. X                sprintf (interp->result, "%d", getpgrp ());
  1196. X                return TCL_OK;
  1197. X            }
  1198. X            if ((argc != 4) || !STREQU (argv[3], "set")) {
  1199. X                Tcl_AppendResult (interp, "wrong # args: ", argv [0], 
  1200. X                                  " process group [set]", (char *) NULL);
  1201. X                return TCL_ERROR;
  1202. X            }
  1203. X            setpgrp ();
  1204. X            return TCL_OK;
  1205. X        }
  1206. X        Tcl_AppendResult (interp, "wrong # args: ", argv [0], 
  1207. X                          " process [parent|group|group set]", (char *) NULL);
  1208. X        return TCL_ERROR;
  1209. X    }
  1210. X
  1211. X    /*
  1212. X     * Handle setting or returning the user ID or group ID (by name or number).
  1213. X     */
  1214. X    if (argc > 3)
  1215. X        goto bad_args;
  1216. X
  1217. X    if (STREQU (argv[1], "user")) {
  1218. X        if (argc == 2) {
  1219. X            return UseridToUsernameResult (interp, getuid ());
  1220. X        } else {
  1221. X            pw = getpwnam (argv[2]);
  1222. X            if (pw == NULL)
  1223. X                goto name_doesnt_exist;
  1224. X            if (setuid (pw->pw_uid) < 0)
  1225. X                goto cannot_set_name;
  1226. X            return TCL_OK;
  1227. X        }
  1228. X    }
  1229. X
  1230. X    if (STREQU (argv[1], "userid")) {
  1231. X        if (argc == 2) {
  1232. X            sprintf (interp->result, "%d", getuid ());
  1233. X            return TCL_OK;
  1234. X        } else {
  1235. X            if (Tcl_GetInt (interp, argv[2], &uid) != TCL_OK)
  1236. X                return TCL_ERROR;
  1237. X            if (setuid (uid) < 0) goto cannot_set_name;
  1238. X            return TCL_OK;
  1239. X        }
  1240. X    }
  1241. X
  1242. X    if (STREQU (argv[1], "group")) {
  1243. X        if (argc == 2) {
  1244. X            return GroupidToGroupnameResult (interp, getgid ());
  1245. X        } else {
  1246. X            grp = getgrnam (argv[2]);
  1247. X            if (grp == NULL) goto name_doesnt_exist;
  1248. X            if (setgid (grp->gr_gid) < 0) goto cannot_set_name;
  1249. X            return TCL_OK;
  1250. X        }
  1251. X    }
  1252. X
  1253. X    if (STREQU (argv[1], "groupid")) {
  1254. X        if (argc == 2) {
  1255. X            sprintf (interp->result, "%d", getgid ());
  1256. X            return TCL_OK;
  1257. X        } else {
  1258. X            if (Tcl_GetInt (interp, argv[2], &gid) != TCL_OK)
  1259. X                return TCL_ERROR;
  1260. X            if (setgid (gid) < 0) goto cannot_set_name;
  1261. X            return TCL_OK;
  1262. X        }
  1263. X    }
  1264. X    Tcl_AppendResult (interp, "bad arg: ", argv [0], 
  1265. X                      " second arg must be convert, effective, process, ",
  1266. X                      "user, userid, group or groupid", (char *) NULL);
  1267. X    return TCL_ERROR;
  1268. X
  1269. X
  1270. X  bad_three_arg:
  1271. X    Tcl_AppendResult (interp, "bad arg: ", argv [0], ": ", argv[1],
  1272. X                      ": third arg must be user, userid, group or groupid",
  1273. X                      (char *) NULL);
  1274. X    return TCL_ERROR;
  1275. X  bad_args:
  1276. X    Tcl_AppendResult (interp, "wrong # args: ", argv [0], " arg [arg..]",
  1277. X                      (char *) NULL);
  1278. X    return TCL_ERROR;
  1279. X
  1280. X  name_doesnt_exist:
  1281. X    Tcl_AppendResult (interp, argv[0], ": ", argv[1], argv[2], (char *) NULL);
  1282. X    return TCL_ERROR;
  1283. X
  1284. X  cannot_set_name:
  1285. X    Tcl_AppendResult (interp, argv [0], ": ", Tcl_UnixError (interp),
  1286. X                      (char *) NULL);
  1287. X    return TCL_ERROR;
  1288. X}
  1289. END_OF_FILE
  1290. if test 9404 -ne `wc -c <'extended/src/id.c'`; then
  1291.     echo shar: \"'extended/src/id.c'\" unpacked with wrong size!
  1292. fi
  1293. # end of 'extended/src/id.c'
  1294. fi
  1295. if test -f 'extended/tcllib/help/commands/trace' -a "${1}" != "-c" ; then 
  1296.   echo shar: Will not clobber existing file \"'extended/tcllib/help/commands/trace'\"
  1297. else
  1298. echo shar: Extracting \"'extended/tcllib/help/commands/trace'\" \(8226 characters\)
  1299. sed "s/^X//" >'extended/tcllib/help/commands/trace' <<'END_OF_FILE'
  1300. X          trace option ?arg arg ...?
  1301. X               Cause Tcl commands  to  be  executed  whenever  certain
  1302. X               operations  are  invoked.   At  present,  only variable
  1303. X               tracing is implemented. The legal option's  (which  may
  1304. X               be abbreviated) are:
  1305. X
  1306. X               trace variable name ops command
  1307. X                    Arrange   for  command  to  be  executed  whenever
  1308. X                    variable name is accessed in one of the ways given
  1309. X                    by  ops.   Name may refer to a normal variable, an
  1310. X                    element of an array, or to an  array  as  a  whole
  1311. X                    (i.e.  name may be just the name of an array, with
  1312. X                    no parenthesized index).   If  name  refers  to  a
  1313. X                    whole  array, then command is invoked whenever any
  1314. X                    element of the array is manipulated.
  1315. X
  1316. X                    Ops indicates which operations  are  of  interest,
  1317. X                    and  consists  of  one  or  more  of the following
  1318. X                    letters:
  1319. X
  1320. X                         r
  1321. X                              Invoke  command whenever the variable is
  1322. X                              read.
  1323. X
  1324. X                         w
  1325. X                              Invoke  command whenever the variable is
  1326. X                              written.
  1327. X
  1328. X                         u
  1329. X                              Invoke  command whenever the variable is
  1330. X                              unset.    Variables   can    be    unset
  1331. X                              explicitly  with  the  unset command, or
  1332. X                              implicitly when procedures  return  (all
  1333. X                              of  their  local  variables  are unset).
  1334. X                              Variables   are    also    unset    when
  1335. X                              interpreters  are  deleted,  but  traces
  1336. X                              will not be invoked because there is  no
  1337. X                              interpreter in which to execute them.
  1338. X
  1339. X                    When  the  trace  triggers,  three  arguments  are
  1340. X                    appended  to command so that the actual command is
  1341. X                    as follows:
  1342. X
  1343. X                         command name1 name2 op
  1344. X
  1345. X                    Name1 and name2 give the name(s) for the  variable
  1346. X                    being  accessed:  if the variable is a scalar then
  1347. X                    name1 gives the variable's name and  name2  is  an
  1348. X                    empty  string; if the variable is an array element
  1349. X                    then name1 gives the name of the array  and  name2
  1350. X                    gives the index into the array; if an entire array
  1351. X                    is being deleted and the trace was  registered  on
  1352. X                    the  overall  array, rather than a single element,
  1353. X                    then name1 gives the array name and  name2  is  an
  1354. X                    empty  string.   Op  indicates  what  operation is
  1355. X                    being performed on the variable, and is one of  r,
  1356. X                    w, or u as defined above.
  1357. X
  1358. X                    Command executes in the same context as  the  code
  1359. X                    that   invoked   the  traced  operation:   if  the
  1360. X                    variable was accessed as part of a Tcl  procedure,
  1361. X                    then  command  will  have access to the same local
  1362. X                    variables as code in the procedure.  This  context
  1363. X                    may  be  different  than  the context in which the
  1364. X                    trace  was  created.   Note  that  name1  may  not
  1365. X                    necessarily  be  the  same as the name used to set
  1366. X                    the trace on the variable;  differences can  occur
  1367. X                    if  the  access is made through a variable defined
  1368. X                    with the upvar command.
  1369. X
  1370. X                    For read and write traces, command can modify  the
  1371. X                    variable  to  affect  the  result  of  the  traced
  1372. X                    operation.  If command modifies  the  value  of  a
  1373. X                    variable  during  a  read  trace,  then  the value
  1374. X                    returned by the traced read operation will be  the
  1375. X                    value  of  the  variable  after command completes.
  1376. X                    For write traces, command  is  invoked  after  the
  1377. X                    variable's  value has been changed; it can write a
  1378. X                    new  value  into  the  variable  to  override  the
  1379. X                    original  value  specified in the write operation.
  1380. X                    The value returned by the traced  write  operation
  1381. X                    will  be  the  value  of the variable when command
  1382. X                    completes.  If command returns an error  during  a
  1383. X                    read  or write trace, then the traced operation is
  1384. X                    aborted with an error.  This mechanism can be used
  1385. X                    to  implement  read-only  variables,  for example.
  1386. X                    Command's result is always ignored.
  1387. X
  1388. X                    While command is executing during a read or  write
  1389. X                    trace,  traces  on  the  variable  are temporarily
  1390. X                    disabled.   This  means  that  reads  and   writes
  1391. X                    invoked  by  command  will occur directly, without
  1392. X                    invoking command (or any other traces) again.   It
  1393. X                    is  illegal  to  unset a variable while a trace is
  1394. X                    active for it.  It is also  illegal  to  unset  an
  1395. X                    array  if  there  are traces active for any of the
  1396. X                    array's elements.
  1397. X
  1398. X                    When an unset trace is invoked, the  variable  has
  1399. X                    already  been  deleted:   it  will  appear  to  be
  1400. X                    undefined with no  traces.   If  an  unset  occurs
  1401. X                    because of a procedure return, then the trace will
  1402. X                    be  invoked  in  the  variable  context   of   the
  1403. X                    procedure  being  returned to:  the stack frame of
  1404. X                    the returning  procedure  will  no  longer  exist.
  1405. X                    Traces are not disabled during unset traces, so if
  1406. X                    an unset trace command creates  a  new  trace  and
  1407. X                    accesses the variable, the trace will be invoked.
  1408. X
  1409. X                    If there are multiple traces on  a  variable  they
  1410. X                    are  invoked  in  order  of  creation, most-recent
  1411. X                    first.  If one trace returns  an  error,  then  no
  1412. X                    further  traces  are invoked for the variable.  If
  1413. X                    an array element has a trace  set,  and  there  is
  1414. X                    also  a  trace  set  on  the array as a whole, the
  1415. X                    trace on the overall array is invoked  before  the
  1416. X                    one on the element.
  1417. X
  1418. X                    Once created, the trace remains in  effect  either
  1419. X                    until  the trace is removed with the trace vdelete
  1420. X                    command described below,  until  the  variable  is
  1421. X                    unset,   or  until  the  interpreter  is  deleted.
  1422. X                    Unsetting an element  of  array  will  remove  any
  1423. X                    traces on that element, but will not remove traces
  1424. X                    on the overall array.
  1425. X
  1426. X                    This command returns an empty string.
  1427. X
  1428. X               trace vdelete name ops command
  1429. X                    If  there is a trace set on variable name with the
  1430. X                    operations and command given by ops  and  command,
  1431. X                    then  the  trace  is removed, so that command will
  1432. X                    never again be invoked.  Returns an empty string.
  1433. X
  1434. X               trace vinfo name
  1435. X                    Returns  a  list  containing  one element for each
  1436. X                    trace  currently  set  on  variable  name.    Each
  1437. X                    element  of  the  list is itself a list containing
  1438. X                    two  elements,  which  are  the  ops  and  command
  1439. X                    associated  with the trace.  If name doesn't exist
  1440. X                    or doesn't have any traces set, then the result of
  1441. X                    the command will be an empty string.
  1442. END_OF_FILE
  1443. if test 8226 -ne `wc -c <'extended/tcllib/help/commands/trace'`; then
  1444.     echo shar: \"'extended/tcllib/help/commands/trace'\" unpacked with wrong size!
  1445. fi
  1446. # end of 'extended/tcllib/help/commands/trace'
  1447. fi
  1448. echo shar: End of archive 11 \(of 23\).
  1449. cp /dev/null ark11isdone
  1450. MISSING=""
  1451. 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
  1452.     if test ! -f ark${I}isdone ; then
  1453.     MISSING="${MISSING} ${I}"
  1454.     fi
  1455. done
  1456. if test "${MISSING}" = "" ; then
  1457.     echo You have unpacked all 23 archives.
  1458.     echo "Now cd to "extended", edit the makefile, then do a "make""
  1459.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1460. else
  1461.     echo You still need to unpack the following archives:
  1462.     echo "        " ${MISSING}
  1463. fi
  1464. ##  End of shell archive.
  1465. exit 0
  1466.  
  1467. exit 0 # Just in case...
  1468. -- 
  1469. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1470. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1471. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1472. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1473.