home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / veos-2.0 / part04 < prev    next >
Encoding:
Text File  |  1993-04-25  |  87.0 KB  |  3,138 lines

  1. Newsgroups: comp.sources.unix
  2. From: voodoo@hitl.washington.edu (Geoffery Coco)
  3. Subject: v26i187: veos-2.0 - The Virtual Environment Operating Shell, V2.0, Part04/16
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: voodoo@hitl.washington.edu (Geoffery Coco)
  8. Posting-Number: Volume 26, Issue 187
  9. Archive-Name: veos-2.0/part04
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 4 (of 16)."
  18. # Contents:  kernel_private/src/fern/fx.lsp
  19. #   kernel_private/src/include/kernel.h
  20. #   kernel_private/src/shell/shell.c src/kernel_current/fern/fx.lsp
  21. #   src/kernel_current/include/kernel.h
  22. #   src/kernel_current/shell/shell.c src/xlisp/xcore/c/xlinit.c
  23. #   src/xlisp/xcore/c/xlprin.c
  24. # Wrapped by vixie@efficacy.home.vix.com on Sun Apr 25 23:10:34 1993
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'kernel_private/src/fern/fx.lsp' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'kernel_private/src/fern/fx.lsp'\"
  28. else
  29. echo shar: Extracting \"'kernel_private/src/fern/fx.lsp'\" \(9543 characters\)
  30. sed "s/^X//" >'kernel_private/src/fern/fx.lsp' <<'END_OF_FILE'
  31. X;;-----------------------------------------------------------
  32. X;; file: fx.lsp
  33. X;;
  34. X;; FERN is the Fractal Entity Relativity Node.
  35. X;; This file is the trans compenent of the Fern System.
  36. X;;
  37. X;; creation: March 28, 1992
  38. X;;
  39. X;; by Geoffrey P. Coco at the HITLab, Seattle
  40. X;;-----------------------------------------------------------
  41. X
  42. X;;-----------------------------------------------------------
  43. X;; Copyright (C) 1992  Geoffrey P. Coco,
  44. X;; Human Interface Technology Lab, Seattle
  45. X;;-----------------------------------------------------------
  46. X
  47. X
  48. X;;-----------------------------------------------------------
  49. X#|
  50. X
  51. XThe FX component of the Fern System is concerned with normal
  52. Xcommunications between space and entity.
  53. X
  54. XA primary purpose of the Fern System is to transparently
  55. Xmaintain the distributed world database.  These functions
  56. Xprovide the inter-entity transport mechanism for the Fern
  57. XSystem and they compose the FX component of the Fern System.
  58. X
  59. X|#
  60. X;;-----------------------------------------------------------
  61. X
  62. X
  63. X
  64. X;;===========================================================
  65. X;;
  66. X;;             FX PUBLIC FUNCTIONS
  67. X;;
  68. X;;===========================================================
  69. X
  70. X
  71. X;;-----------------------------------------------------------
  72. X;;           Entity Level Binding Entry Pts
  73. X;;-----------------------------------------------------------
  74. X
  75. X
  76. X;;-----------------------------------------------------------
  77. X
  78. X;; instigate a space/entity relationship between your entity
  79. X;; and the given entity.  sp-uid becomes a space of yours.
  80. X;; any entity/space token loop begins here.
  81. X
  82. X(defun fx-enter (sp-uid)
  83. X  (cond ((fe-copy.ext.sps.ent sp-uid))
  84. X    (t
  85. X     (cond (fern-debug
  86. X        (printf "fx-enter... new space: " (uid2str sp-uid))))
  87. X
  88. X     ;; add new space to external partition 
  89. X     (fe-put.ext.sps.ent (list sp-uid ()))
  90. X
  91. X     ;; add delta time-stamp to hash table
  92. X     (fbase-put-hash fern-ent-htab sp-uid (vmintime))
  93. X
  94. X     ;; pass first boundary update (i.e. the token) to space
  95. X     (vthrow (list sp-uid) 
  96. X         `(fx-sp-enter ,self (quote ,(fx-ent-exude sp-uid))))
  97. X     t)))
  98. X
  99. X;;-----------------------------------------------------------
  100. X
  101. X;; instagate the exit procedure.
  102. X;; terminate a space/entity relationship between your entity
  103. X;; and the given entity.  the token will travel one more time
  104. X;; around.     
  105. X
  106. X(defun fx-exit (sp-uid)
  107. X
  108. X
  109. X  (cond ((fe-copy.ext.sps.ent sp-uid)
  110. X
  111. X     (cond (fern-debug
  112. X        (printf "fx-exit... space: " (uid2str sp-uid))))
  113. X
  114. X     ;; remove space from space list.
  115. X     (fe-get.ext.sps.ent sp-uid)
  116. X
  117. X     ;; remove this entry from timestamp hash table
  118. X     (fbase-get-hash fern-ent-htab sp-uid)
  119. X
  120. X     ;; assume that entity has the token.
  121. X     ;; NOTE: this is not a safe assumption.
  122. X     ;; In other words, it is only safe to call
  123. X     ;; fx-exit from within a react proc.
  124. X
  125. X     ;; token now passes one more time through it's loop
  126. X     ;; to the space (fx-sp-exit, fx-sp-unperceive)
  127. X     ;; then, ending at (fx-ent-unperceive)
  128. X     (vthrow (list sp-uid) 
  129. X         `(fx-sp-exit ,self))
  130. X     )))
  131. X
  132. X;;-----------------------------------------------------------
  133. X
  134. X
  135. X
  136. X;;===========================================================
  137. X;;
  138. X;;             FX PRIVATE FUNCTIONS
  139. X;;
  140. X;;===========================================================
  141. X
  142. X
  143. X;;-----------------------------------------------------------
  144. X
  145. X(defun fx-init ()
  146. X  (setq fern-sp-htab (fbase-new-htab))
  147. X  (setq fern-ent-htab (fbase-new-htab))
  148. X  )
  149. X
  150. X;;-----------------------------------------------------------
  151. X
  152. X
  153. X
  154. X;;-----------------------------------------------------------
  155. X;;        Space Level Binding Entry Pts
  156. X;;-----------------------------------------------------------
  157. X
  158. X
  159. X;;-----------------------------------------------------------
  160. X
  161. X;; accept a space/entity relationship between from another 
  162. X;; entity.  setup initial data structures, pass included
  163. X;; entity->space token into token loop.
  164. X
  165. X(defun fx-sp-enter (ent-uid vbf)
  166. X  (progn
  167. X    (cond (fern-debug
  168. X       (printf "fx-sp-enter... new entity: " (uid2str ent-uid))))
  169. X
  170. X    ;; the entering entity has already checked for duplicates.
  171. X    ;; add new entity to sublings partition,
  172. X    ;; overiding a possible previous deletion.
  173. X    (fe-put.int.subs.ent (list ent-uid nil))
  174. X
  175. X    ;; add new entity with delta time-stamp to fern hash table
  176. X    (fbase-put-hash fern-sp-htab ent-uid (vmintime))
  177. X
  178. X    ;; pass included token to normal space entry point
  179. X    (fx-sp-perceive ent-uid vbf)
  180. X    ))
  181. X
  182. X;;-----------------------------------------------------------
  183. X
  184. X;; accept a termination request of space/entity relationship
  185. X;; from another entity.  takedown data structures, pass included
  186. X;; entity->space token into final token loop.
  187. X
  188. X(defun fx-sp-exit (ent-uid)
  189. X  (progn
  190. X    (cond (fern-debug
  191. X       (printf "fx-sp-exit... retiring entity: " (uid2str ent-uid))))
  192. X
  193. X    ;; remove entity timestamp hash table
  194. X    (fbase-get-hash fern-sp-htab ent-uid)
  195. X
  196. X    ;; remove entity from sublings partition..
  197. X    ;; and thus from the externals of all other entities in this space.
  198. X    (fe-get.int.subs.ent ent-uid)
  199. X
  200. X    ;; eliminate perceptual references to this entity
  201. X    (fx-sp-unperceive ent-uid)
  202. X    ))
  203. X
  204. X;;-----------------------------------------------------------
  205. X
  206. X
  207. X
  208. X;;-----------------------------------------------------------
  209. X;;        Space Token Normal Operation
  210. X;;-----------------------------------------------------------
  211. X
  212. X
  213. X;;-----------------------------------------------------------
  214. X
  215. X(defun fx-ent-perceive (which-sp bndry-list)
  216. X  (progn
  217. X    (cond (fern-debug
  218. X       (printf "fx-ent-perceive ... from space: " (uid2str which-sp))
  219. X       (printf "the goods:")
  220. X       (pprint bndry-list)))
  221. X
  222. X    ;;;
  223. X    ;;; update external siblings partition of local grouplespace
  224. X    ;;;
  225. X
  226. X    (dolist (ent bndry-list)
  227. X
  228. X        (cond
  229. X         ((equal (car ent) self))
  230. X         ((consp (cadr ent))
  231. X          (dolist (ob (cadr ent))
  232. X              
  233. X              (cond
  234. X               ((consp (cadr ob))
  235. X            (dolist (attr (cadr ob))
  236. X
  237. X                (fe-put.ext.sibs.ent.ob.attr (car ent) (car ob) attr)))
  238. X
  239. X               ((fe-put.ext.sibs.ent.ob (car ent) ob)))))
  240. X
  241. X         ((fe-put.ext.sibs.ent ent))))
  242. X
  243. X    ;; dispatch reactive behaviors
  244. X    (do-procs react-procs)
  245. X    
  246. X    ;; repost to space all instant changes
  247. X    ;; this is the bottom of the entity-space token loop
  248. X    (vthrow (list which-sp) 
  249. X        `(fx-sp-perceive ,self (quote ,(fx-ent-exude which-sp))))
  250. X
  251. X    (gc)
  252. X    ))
  253. X
  254. X;;-----------------------------------------------------------
  255. X
  256. X(defun fx-ent-exude (sp-uid)
  257. X
  258. X  ;; generate a vbf structure to match space protocol.
  259. X  ;; a vbf structure is (uid virt-bndry fltr).
  260. X
  261. X  ;; as of 5/1/92, filters are omitted and
  262. X  ;; the uid is passed as a separate argument.
  263. X
  264. X  (let* ((ts 0.0) vbf)
  265. X
  266. X    (fbase-hash fern-ent-htab sp-uid ts)
  267. X    (setq vbf (fe-copy.bndry.vrt :test-time ts))
  268. X
  269. X    ;; replace time stamp for this space
  270. X    (fbase-put-hash fern-ent-htab sp-uid ts)
  271. X    
  272. X    (cond (fern-debug
  273. X       (printf "fx-ent-exude ... to space: " (uid2str sp-uid))
  274. X       (printf "the goods:")
  275. X       (pprint vbf)))
  276. X
  277. X    ;; return the entity->space token to caller
  278. X    vbf))
  279. X
  280. X;;-----------------------------------------------------------
  281. X
  282. X
  283. X
  284. X;;-----------------------------------------------------------
  285. X
  286. X(defun fx-sp-perceive (uid vbf)
  287. X  (progn
  288. X    ;; top of the entity-space token loop.
  289. X    
  290. X    (cond (fern-debug
  291. X       (printf "fx-sp-perceive ... from entity: " (uid2str uid))
  292. X       (printf "the goods:")
  293. X       (pprint vbf)))
  294. X    
  295. X    ;;;
  296. X    ;;; update internal sublings partition of grouplepsace
  297. X    ;;;
  298. X
  299. X    (cond 
  300. X     ((listp vbf)
  301. X      (dolist (ob vbf) 
  302. X          
  303. X          (cond
  304. X           ((consp (cadr ob))
  305. X        (dolist (attr (cadr ob))
  306. X             
  307. X            (fe-put.int.subs.ent.ob.attr uid (car ob) attr)))
  308. X           
  309. X           ((fe-put.int.subs.ent.ob uid ob)))))
  310. X     
  311. X     ((fe-put.int.subs.ent (list uid vbf))))
  312. X
  313. X             
  314. X    ;;;
  315. X    ;;; space takes no reactive action...
  316. X    ;;;
  317. X    (cond (fern-debug
  318. X       (printf "\nthe world:")
  319. X       (pprint (fe-copy.int.subs))
  320. X       (printf "")))
  321. X    
  322. X    ;; repost to entity all world activity
  323. X    (vthrow (list uid)
  324. X        `(fx-ent-perceive ,self (quote ,(fx-sp-exude uid))))
  325. X    ))
  326. X
  327. X;;-----------------------------------------------------------
  328. X
  329. X(defun fx-sp-exude (uid)
  330. X  (progn
  331. X    ;; generate message to match entity protocol:
  332. X    ;; list of sibling entities
  333. X
  334. X    (let* ((ts 0.0) sibs)
  335. X
  336. X      (fbase-hash fern-sp-htab uid ts)
  337. X      (setq sibs (fe-copy.int.subs :test-time ts))
  338. X
  339. X      ;; reset this entity's time-stamp
  340. X      (fbase-put-hash fern-sp-htab uid ts)
  341. X
  342. X      (cond (fern-debug
  343. X         (printf "fx-sp-exude ... to entity: " (uid2str uid))
  344. X         (printf "the goods:")
  345. X         (pprint sibs)))
  346. X
  347. X      ;; return the space->entity token to caller
  348. X      sibs)))
  349. X
  350. X;;-----------------------------------------------------------
  351. X
  352. X
  353. X
  354. X
  355. X
  356. X;;-----------------------------------------------------------
  357. X;;            Token Loop Unbinding
  358. X;;-----------------------------------------------------------
  359. X
  360. X
  361. X;;-----------------------------------------------------------
  362. X
  363. X;; end of line for space/entity token.
  364. X
  365. X(defun fx-ent-unperceive (which-sp ent-list)
  366. X  (progn
  367. X    (cond (fern-debug
  368. X       (printf "fx-ent-UNperceive ... from space: " (uid2str which-sp))))
  369. X    
  370. X    ;; update external perception partition of local grouplespace
  371. X    ;; so that all that entities from that space are removed.
  372. X    (mapcar 'fe-get.ext.sibs.ent ent-list)
  373. X    ))
  374. X
  375. X;;-----------------------------------------------------------
  376. X
  377. X(defun fx-sp-unperceive (uid)
  378. X  (progn 
  379. X    (cond (fern-debug
  380. X       (printf "fx-sp-UNperceive ... from entity: " (uid2str uid))))
  381. X
  382. X    ;; rid subling of any perceptions of this space
  383. X    (vthrow (list uid) 
  384. X        `(fx-ent-unperceive ,self (quote ,(fe-copy.int.subs.uids))))
  385. X    ))
  386. X
  387. X;;-----------------------------------------------------------
  388. X
  389. X
  390. END_OF_FILE
  391. if test 9543 -ne `wc -c <'kernel_private/src/fern/fx.lsp'`; then
  392.     echo shar: \"'kernel_private/src/fern/fx.lsp'\" unpacked with wrong size!
  393. fi
  394. # end of 'kernel_private/src/fern/fx.lsp'
  395. fi
  396. if test -f 'kernel_private/src/include/kernel.h' -a "${1}" != "-c" ; then 
  397.   echo shar: Will not clobber existing file \"'kernel_private/src/include/kernel.h'\"
  398. else
  399. echo shar: Extracting \"'kernel_private/src/include/kernel.h'\" \(9869 characters\)
  400. sed "s/^X//" >'kernel_private/src/include/kernel.h' <<'END_OF_FILE'
  401. X/****************************************************************************************
  402. X * file: kernel.h                                    *
  403. X *                                            *
  404. X * May 18, 1991:  the kernel's private defines, and structures.                *
  405. X *                                                    *
  406. X * by Geoffrey P. Coco at the HITLab, Seattle.                          *
  407. X *                                            *
  408. X ****************************************************************************************/
  409. X
  410. X
  411. X/****************************************************************************************
  412. X * Copyright (C) 1992  Geoffrey P. Coco, Human Interface Technology Lab, Seattle    *
  413. X ****************************************************************************************/
  414. X
  415. X
  416. X#include "world.h"
  417. X
  418. X#ifdef _SG_
  419. X#include <ulocks.h>
  420. X#endif
  421. X
  422. X#ifdef MAIN_MODULE
  423. X#define EXTERN
  424. X#else
  425. X#define EXTERN extern
  426. X#endif
  427. X
  428. X/****************************************************************************************
  429. X                       Talk Module
  430. X ****************************************************************************************/
  431. X
  432. X
  433. X#define TALK_CREATE        -11        /* socket() error */
  434. X#define TALK_HOST        -12        /* gethostbyname() error */
  435. X#define TALK_PROTOCOL        -13        /* getprotobyname() error */
  436. X#define TALK_SERVICE        -14        /* getservbyname() error */
  437. X
  438. X#define TALK_CONNECT        -15        /* connect() error */
  439. X#define TALK_BIND        -16        /* bind(): bind to an address */
  440. X#define TALK_NAME        -17        /* getsockname(): can't name socket */
  441. X#define TALK_LISTEN        -18        /* listen() error */
  442. X#define TALK_FLAGS        -23        /* ioctl error **/
  443. X#define TALK_SELECT        -19        /* select() error */
  444. X#define TALK_SELECT_TIMEOUT    -20        /* select() time out; nonfatal error */
  445. X#define TALK_NOCONN        -21        /* FD_ISSET() failed, try again */
  446. X#define TALK_ACCEPT        -22        /* accept(): can't accept selection */
  447. X#define TALK_CLOSE        -90        /* close() error */
  448. X#define TALK_CONN_CLOSED      -30
  449. X
  450. X#define TALK_SPEAK_BLOCKED    -252
  451. X#define TALK_LISTEN_BLOCKED    -253
  452. X
  453. X#define TALK_DEFAULT_PROTOCOL    "tcp"        /* standard for messages */
  454. X#define TALK_DEFAULT_HOST    "localhost"    /* standard loop-back */
  455. X
  456. X#define TALK_SELECT_TIME    0        /* quick check for incoming conns */
  457. X#define TALK_QUEUE_SIZE        5        /* size of listening queue */
  458. X#define TALK_MAX_BUFFER        8192
  459. X#define TALK_MAX_SPEAK_FAIL    20
  460. X
  461. X#define TALK_AGRESSIVE      -25        /* forcefully take listen port */
  462. X#define TALK_PASSIVE        -24        /* leave used ports alone */
  463. X
  464. X#define TALK_MIN_PORT        5500
  465. X#define TALK_MAX_PORT        20000
  466. X
  467. X#define TALK_SOCK_CONN        1
  468. X#define TALK_SHMEM_CONN        2
  469. X
  470. X#define SHMEM_SHARED_BUF_SIZE    0xFFFF
  471. X#define SHMEM_RW_BUF_SIZE    0x0FFF
  472. X
  473. X#define SHMEM_FULL        -272
  474. X#define SHMEM_INIT_ERR        -270
  475. X#define SHMEM_ARENA_FILE    "/tmp/veos_shmem_arena"
  476. X
  477. X#define UID_COMPARE(uid1, uid2)  ((uid1)->iPort == (uid2)->iPort && \
  478. X                  (uid1)->lHost == (uid2)->lHost)
  479. X
  480. X/****************************************************************************************
  481. X                    Entity Addressing
  482. X ****************************************************************************************/
  483. X
  484. Xtypedef struct {
  485. X    u_long        lHost;
  486. X    int            iPort;
  487. X    }   TUid,
  488. X        *TPUid,
  489. X        **THUid;
  490. X
  491. Xtypedef struct uidnode {
  492. X    TUid        addr;
  493. X    struct uidnode     *pNext;
  494. X    } TUidNode,
  495. X      *TPUidNode,
  496. X      **THUidNode;
  497. X
  498. X/****************************************************************************************
  499. X                      Shared Memory
  500. X ****************************************************************************************/
  501. X
  502. X#ifdef _SG_
  503. Xtypedef usptr_t     *TPShMem;
  504. Xtypedef usema_t     *TPSemaphor;
  505. X#else
  506. Xtypedef char         *TPShMem;
  507. Xtypedef char         *TPSemaphor;
  508. X#endif
  509. X
  510. Xtypedef struct memrec {
  511. X    int            iPort;
  512. X    TPSemaphor        pSem;
  513. X    char        pBuffer[SHMEM_RW_BUF_SIZE];
  514. X    char        *pAvail, *pEnd;
  515. X    struct memrec    *pNext;
  516. X
  517. X    } TSharedRec,
  518. X      *TPSharedRec,
  519. X      **THSharedRec;
  520. X
  521. X
  522. Xtypedef struct {
  523. X    TPSemaphor        pChainSem;
  524. X    TPSharedRec        pChannelChain;
  525. X
  526. X    } TShDomainRec,
  527. X      *TPShDomainRec,
  528. X      **THShDomainRec;
  529. X
  530. X/****************************************************************************************
  531. X                  Talk Message Queueing
  532. X ****************************************************************************************/
  533. X
  534. Xtypedef struct listennode {
  535. X
  536. X    int                iSocketFD;
  537. X    struct listennode    *pLink;
  538. X
  539. X    }    TListenNode,
  540. X        *TPListenNode,
  541. X        **THListenNode;
  542. X
  543. Xtypedef struct {
  544. X    char        *sMessage;
  545. X    int            iLen;
  546. X
  547. X    }    TMsgRec,
  548. X        *TPMsgRec,
  549. X        **THMsgRec;
  550. X
  551. Xtypedef struct messageq {
  552. X
  553. X    char        *sMessage;
  554. X    int            iMsgLen;
  555. X    struct messageq    *pLink;
  556. X
  557. X    }    TMessageNode,
  558. X        *TPMessageNode,
  559. X        **THMessageNode;
  560. X
  561. Xtypedef    struct speaknode {
  562. X
  563. X    TUid        destRec;
  564. X    int            iConnType;
  565. X    int            iSocketFD;
  566. X    TPMessageNode    pMessageQ;
  567. X    struct speaknode    *pLink;
  568. X
  569. X    }     TSpeakNode,
  570. X        *TPSpeakNode,
  571. X        **THSpeakNode;
  572. X
  573. X/****************************************************************************************
  574. X                   Hostname Hash Table Entries
  575. X ****************************************************************************************/
  576. X
  577. Xtypedef struct hostnode {
  578. X    char        *sHostName;
  579. X    u_long        lHost;
  580. X    struct hostnode    *pNext;
  581. X
  582. X    } THostNode,
  583. X      *TPHostNode,
  584. X      **THHostNode;
  585. X
  586. X/****************************************************************************************
  587. X                      Talk Globals
  588. X ****************************************************************************************/
  589. X
  590. XEXTERN int            talk_iListenFD;
  591. XEXTERN char            *talk_pTransBuffer;
  592. XEXTERN TUid            talk_selfRec;
  593. X
  594. XEXTERN fd_set            talk_InetSocket_OpenWriteSockets;
  595. XEXTERN fd_set            talk_InetSocket_OpenReadSockets;
  596. X
  597. XEXTERN TPHostNode        talk_pHostHash[26];
  598. XEXTERN TPSpeakNode        talk_pOutConns;
  599. XEXTERN TPListenNode        talk_pInConns;
  600. X
  601. XEXTERN boolean            talk_bTalkDebugging;
  602. XEXTERN boolean            talk_bOutDirty;
  603. XEXTERN long            talk_lTasks;
  604. X
  605. XEXTERN TPShDomainRec        talk_pPublicDomain;
  606. XEXTERN TPShMem            talk_pTheArena;
  607. XEXTERN TPSharedRec        talk_pListenChannel;
  608. XEXTERN TVeosErr            (*talk_pIncomingMsgFun) ();
  609. X
  610. X/** quick access to talk globals **/
  611. X
  612. X#define SPEAK_SET        talk_pOutConns
  613. X#define LISTEN_SOCKETFD        talk_iListenFD
  614. X#define LISTEN_SET        talk_pInConns
  615. X#define TASKS            talk_lTasks
  616. X#define TALK_BUFFER          talk_pTransBuffer
  617. X#define TALK_BUGS          talk_bTalkDebugging
  618. X#define SPEAK_DIRTY          talk_bOutDirty
  619. X#define OPEN_READ_SOCKETS     talk_InetSocket_OpenReadSockets
  620. X#define OPEN_WRITE_SOCKETS     talk_InetSocket_OpenWriteSockets
  621. X#define IDENT_ADDR        talk_selfRec
  622. X
  623. X#define SHMEM_DOMAIN        talk_pPublicDomain
  624. X#define SHMEM_ARENA        talk_pTheArena
  625. X#define SHMEM_CHANNEL        talk_pListenChannel
  626. X
  627. X#define TALK_MSG_FUNC        talk_pIncomingMsgFun
  628. X#define SOCK_HOSTS        talk_pHostHash
  629. X
  630. X/****************************************************************************************
  631. X                      Nancy Module
  632. X ****************************************************************************************/
  633. X
  634. Xtypedef struct {
  635. X    int            iLeft, iRight;
  636. X
  637. X    }   TInterval,
  638. X        *TPInterval;
  639. X
  640. Xtypedef struct repnode {
  641. X    TPGrouple        pEnviron;
  642. X    TInterval        pWipeList[10];
  643. X    int            iZones;
  644. X    int            iInsertElt;
  645. X    struct repnode    *pNext;
  646. X
  647. X    }    TReplaceRec,
  648. X        *TPReplaceRec,
  649. X        **THReplaceRec;
  650. X
  651. Xtypedef struct {
  652. X    TPGrouple        pPatGr, pSrcGr;
  653. X    int            iDestroyFlag, iFreqFlag;
  654. X    TPReplaceRec    pReplaceList;
  655. X    TPReplaceRec    pTouchList;
  656. X
  657. X    }   TMatchRec,
  658. X        *TPMatchRec,
  659. X        **THMatchRec;
  660. X
  661. X/****************************************************************************************/
  662. X
  663. X#define VEOS_GROUPLE_BUF_SIZE          1024
  664. X#define NANCY_EltListInc        8
  665. X#define NANCY_AllocHashMax        30
  666. X
  667. X/****************************************************************************************/
  668. X
  669. X#define ELTS_TO_ALLOCATE(iElts) \
  670. X    ((((iElts - 1) / NANCY_EltListInc) + 1) * NANCY_EltListInc)
  671. X
  672. X#define ELTS_ALLOCATED(elts)        ((elts < NANCY_AllocHashMax) ? \
  673. X                     ALLOC_ELTS[elts] : ELTS_TO_ALLOCATE(elts))
  674. X
  675. X#define BLOCKS_ALLOCATED(iBlocks, iSegSize) \
  676. X    ((((iBlocks - 1) / iSegSize) + 1) * iSegSize)
  677. X
  678. X#define GET_TIME(time)            (time) = ++NANCY_TIME
  679. X#define PRINT_TIME(time, stream)        fprintf(stream, "(ts: %d) ", time)
  680. X
  681. X/****************************************************************************************/
  682. X
  683. X
  684. X/** nancy global declarations **/
  685. X
  686. XEXTERN FILE            *nancy_pStreamGlob;
  687. XEXTERN int                nancy_iLineCount;
  688. XEXTERN TPGrouple        nancy_pInSpace, nancy_pWorkSpace;
  689. XEXTERN TElt            nancy_eltNil;
  690. XEXTERN char            *nancy_pAllPurposeBuf;
  691. XEXTERN int            nancy_pAllocElts[NANCY_AllocHashMax];
  692. XEXTERN int            nancy_pTypeSizes[30];
  693. XEXTERN boolean            nancy_bNancyDebugging;
  694. XEXTERN TTimeStamp        nancy_lTime;
  695. XEXTERN TTimeStamp        nancy_lMinTime;
  696. X
  697. X
  698. X/** quick access to nancy globals **/
  699. X
  700. X#define WORK_SPACE        nancy_pWorkSpace
  701. X#define GR_INSPACE        nancy_pInSpace
  702. X
  703. X#define LINE_COUNT        nancy_iLineCount
  704. X#define GR_STREAM        nancy_pStreamGlob
  705. X#define NANCY_BUF        nancy_pAllPurposeBuf
  706. X#define TYPE_SIZES        nancy_pTypeSizes
  707. X#define ALLOC_ELTS        nancy_pAllocElts
  708. X#define NANCY_BUGS        nancy_bNancyDebugging
  709. X#define NIL_ELT            nancy_eltNil
  710. X#define NANCY_TIME        nancy_lTime
  711. X#define NANCY_MINTIME        nancy_lMinTime
  712. X    
  713. X/****************************************************************************************
  714. X                      Shell Module
  715. X ****************************************************************************************/
  716. X
  717. X#define SHELL_CHAIN_HASH_MAX    65
  718. X
  719. X/****************************************************************************************/
  720. X
  721. XEXTERN long            shell_lTrapFlags;
  722. XEXTERN boolean            shell_bShellDebugging;
  723. XEXTERN char            *shell_pChains[SHELL_CHAIN_HASH_MAX];
  724. XEXTERN int            shell_pBlocks[SHELL_CHAIN_HASH_MAX];
  725. X
  726. X#ifdef MAIN_MODULE
  727. Xboolean             shell_bSignals = TRUE;
  728. Xboolean                shell_bKernelSetup = FALSE;
  729. X#else
  730. Xextern boolean             shell_bSignals;
  731. Xextern boolean             shell_bKernelSetup;
  732. X#endif
  733. X
  734. X
  735. X/** quick access to shell globals **/
  736. X
  737. X#define TRAP_FLAGS        shell_lTrapFlags
  738. X#define MEM_CHAINS        shell_pChains
  739. X#define BLOCKS_OUT        shell_pBlocks
  740. X#define SIG_ENABLE        shell_bSignals
  741. X#define SHELL_BUGS        shell_bShellDebugging
  742. X#define KERNEL_INIT        shell_bKernelSetup
  743. X
  744. X/****************************************************************************************/
  745. X
  746. X
  747. X
  748. END_OF_FILE
  749. if test 9869 -ne `wc -c <'kernel_private/src/include/kernel.h'`; then
  750.     echo shar: \"'kernel_private/src/include/kernel.h'\" unpacked with wrong size!
  751. fi
  752. # end of 'kernel_private/src/include/kernel.h'
  753. fi
  754. if test -f 'kernel_private/src/shell/shell.c' -a "${1}" != "-c" ; then 
  755.   echo shar: Will not clobber existing file \"'kernel_private/src/shell/shell.c'\"
  756. else
  757. echo shar: Extracting \"'kernel_private/src/shell/shell.c'\" \(10711 characters\)
  758. sed "s/^X//" >'kernel_private/src/shell/shell.c' <<'END_OF_FILE'
  759. X/****************************************************************************************
  760. X *                                            *
  761. X * file: shell.c                                           *
  762. X *                                            *
  763. X * September 7, 1990:  Wow, that's old.                            *
  764. X *                                            *
  765. X * by Geoffrey P. Coco at the HITLab, Seattle.                          *
  766. X *                                            *
  767. X ****************************************************************************************/
  768. X
  769. X
  770. X/****************************************************************************************
  771. X * Copyright (C) 1992  Geoffrey P. Coco, Human Interface Technology Lab, Seattle    *
  772. X ****************************************************************************************/
  773. X
  774. X
  775. X
  776. X/****************************************************************************************
  777. X *                      include the papa include file                */
  778. X
  779. X#include <signal.h>
  780. X
  781. X#define MAIN_MODULE
  782. X#include "kernel.h"
  783. X
  784. X/****************************************************************************************/
  785. X
  786. X
  787. X/****************************************************************************************
  788. X * Kernel_Init                                        */
  789. X
  790. XTVeosErr Kernel_Init(iPort, pMessFun)
  791. X    int            iPort;
  792. X    TVeosErr        (*pMessFun) ();
  793. X{
  794. X    TVeosErr        iErr = VEOS_FAILURE;
  795. X
  796. X    if (KERNEL_INIT) {
  797. X    fprintf(stderr, "veos kernel already initialized...\n");
  798. X    fprintf(stderr, "no action was taken.\n");
  799. X    }
  800. X    else {
  801. X    /** initialize often-used globals with defualt values **/
  802. X    
  803. X    iErr = Shell_InitCaches();
  804. X    if (iErr == VEOS_SUCCESS) {
  805. X        
  806. X        
  807. X        /** perform one-time nancy initialization **/
  808. X        
  809. X        iErr = Nancy_Init();
  810. X        if (iErr == VEOS_SUCCESS) {
  811. X        
  812. X        
  813. X        /** initialize inter-entity communication handler **/
  814. X        /** this puts an ear to the network **/
  815. X        
  816. X        iErr = Talk_HelloTalk(iPort, pMessFun);
  817. X        if (iErr == VEOS_SUCCESS) {
  818. X            
  819. X            
  820. X            /** provide for graceful exit **/
  821. X            
  822. X            Shell_SetupErrorTraps();
  823. X            
  824. X            
  825. X            /** print gratuitous credits **/
  826. X            
  827. X            Shell_StartUpMessage();
  828. X            
  829. X            KERNEL_INIT = TRUE;
  830. X            }
  831. X        }
  832. X        }
  833. X    
  834. X    if (iErr != VEOS_SUCCESS)
  835. X        fprintf(stderr, "shell %s: kernel initialization failed, error: %d\n",
  836. X            WHOAMI, iErr);
  837. X    }
  838. X
  839. X    return(iErr);
  840. X
  841. X    } /* Kernel_Init */
  842. X/****************************************************************************************/
  843. X
  844. X
  845. X
  846. X/****************************************************************************************
  847. X * Kernel_Shutdown                                    */
  848. X
  849. XTVeosErr Kernel_Shutdown()
  850. X{
  851. X    TVeosErr        iSuccess = VEOS_FAILURE;
  852. X
  853. X    if (KERNEL_INIT) {
  854. X    
  855. X    /** cleanup network loose ends **/
  856. X    
  857. X    iSuccess = Talk_ByeTalk();
  858. X    
  859. X    
  860. X    /** dispose all memory **/
  861. X    
  862. X    fprintf(stderr, "\n");
  863. X
  864. X
  865. X    KERNEL_INIT = FALSE;
  866. X    }
  867. X
  868. X
  869. X    return(iSuccess);
  870. X
  871. X    } /* Kernel_Shutdown */
  872. X/****************************************************************************************/
  873. X    
  874. X
  875. X
  876. X
  877. X/****************************************************************************************
  878. X * Kernel_SystemTask                                    */
  879. X
  880. XTVeosErr Kernel_SystemTask()
  881. X{
  882. X    /** inspect every open connection for queued outgoing messages **/
  883. X    
  884. X    if (SPEAK_DIRTY)
  885. X    Talk_DispatchQedSpeakMessages();
  886. X
  887. X
  888. X    /** accept new entity connections **/
  889. X/*
  890. X    if (++TASKS % 10 == 0)
  891. X*/
  892. X    Talk_EstNewListenConnections();
  893. X    
  894. X
  895. X    /** check each open listen connection for incoming messages **/
  896. X    
  897. X    Talk_GatherListenMessages();
  898. X    
  899. X
  900. X    return(VEOS_SUCCESS);
  901. X
  902. X    } /* Kernel_SystemTask */
  903. X/****************************************************************************************/
  904. X
  905. X
  906. X
  907. X/****************************************************************************************/
  908. XTVeosErr Shell_NewBlock(iSize, hBlock, sDebug)
  909. X    int            iSize;
  910. X    char *        *hBlock;
  911. X    char        *sDebug;
  912. X{
  913. X    char *        *pBlock;
  914. X    TVeosErr        iSuccess;
  915. X    
  916. X    if (iSize >= SHELL_CHAIN_HASH_MAX) {
  917. X    
  918. X    NEWPTR(pBlock, char **, iSize);
  919. X#ifndef OPTIMAL        
  920. X    if (SHELL_BUGS)
  921. X        fprintf(stderr, "shell %s: %s >> size: %d, regular\n",
  922. X            WHOAMI, sDebug ? sDebug : "", iSize);
  923. X#endif
  924. X    }
  925. X    
  926. X    else {
  927. X    if (pBlock = (char **) MEM_CHAINS[iSize]) {
  928. X        
  929. X        BLOCKS_OUT[iSize] ++;
  930. X        
  931. X        /** remove nearest block in chain **/
  932. X        
  933. X        MEM_CHAINS[iSize] = *pBlock;
  934. X        *pBlock = nil;
  935. X#ifndef OPTIMAL        
  936. X        if (SHELL_BUGS)
  937. X        fprintf(stderr, "shell %s: %s >> size: %d, recycle, blocks out: %d\n",
  938. X            WHOAMI, sDebug ? sDebug : "", iSize, BLOCKS_OUT[iSize]);
  939. X#endif
  940. X        }
  941. X    
  942. X    else {
  943. X        BLOCKS_OUT[iSize] ++;
  944. X        NEWPTR(pBlock, char **, iSize);
  945. X#ifndef OPTIMAL        
  946. X        if (SHELL_BUGS)
  947. X        fprintf(stderr, "shell %s: %s >> size: %d, new, blocks out: %d\n",
  948. X            WHOAMI, sDebug ? sDebug : "", iSize, BLOCKS_OUT[iSize]);
  949. X#endif
  950. X        }
  951. X    }    
  952. X    
  953. X    if (*hBlock = (char *) pBlock)
  954. X    iSuccess = VEOS_SUCCESS;
  955. X    else
  956. X    iSuccess = VEOS_FAILURE;
  957. X
  958. X
  959. X    return(iSuccess);
  960. X    
  961. X    } /* Shell_NewBlock */
  962. X/****************************************************************************************/
  963. X
  964. X
  965. X
  966. X
  967. X/****************************************************************************************/
  968. XTVeosErr Shell_ReturnBlock(pBlock, iSize, sDebug)
  969. X    char *        *pBlock;
  970. X    int            iSize;
  971. X    char        *sDebug;
  972. X{
  973. X    int            iSuccess;
  974. X
  975. X    iSuccess = VEOS_SUCCESS;
  976. X
  977. X    if (iSize >= SHELL_CHAIN_HASH_MAX) {
  978. X
  979. X    DUMP(pBlock);
  980. X#ifndef OPTIMAL
  981. X    if (SHELL_BUGS)
  982. X        fprintf(stderr, "shell %s: %s << size: %d, regular\n",
  983. X            WHOAMI, sDebug ? sDebug : "", iSize);
  984. X#endif
  985. X    }
  986. X
  987. X    else {
  988. X    BLOCKS_OUT[iSize] --;
  989. X    
  990. X    *pBlock = MEM_CHAINS[iSize];
  991. X    
  992. X    MEM_CHAINS[iSize] = (char *) pBlock;
  993. X#ifndef OPTIMAL    
  994. X    if (SHELL_BUGS) {
  995. X        fprintf(stderr, "shell %s: %s << size: %d, blocks out: %d\n",
  996. X            WHOAMI, sDebug ? sDebug : "", iSize, BLOCKS_OUT[iSize]);
  997. X        }
  998. X#endif
  999. X    }    
  1000. X
  1001. X    return(iSuccess);
  1002. X    
  1003. X    } /* Shell_ReturnBlock */
  1004. X/****************************************************************************************/
  1005. X
  1006. X
  1007. X
  1008. X/****************************************************************************************
  1009. X *                    local functions                    *
  1010. X ****************************************************************************************/
  1011. X
  1012. X
  1013. X
  1014. X/****************************************************************************************/
  1015. XTVeosErr Shell_InitCaches()
  1016. X{
  1017. X    TVeosErr        iSuccess;
  1018. X    int            iChain;
  1019. X    str63        sHostName;
  1020. X
  1021. X    iSuccess = VEOS_FAILURE;
  1022. X
  1023. X
  1024. X    /** chain list is as long as largest possible block size **/
  1025. X    
  1026. X    for (iChain = 0; iChain < SHELL_CHAIN_HASH_MAX; iChain ++) {
  1027. X    MEM_CHAINS[iChain] = nil;
  1028. X    BLOCKS_OUT[iChain] = 0;
  1029. X    }
  1030. X
  1031. X
  1032. X    /** publicly accessible globals  **/
  1033. X
  1034. X    if (gethostname(sHostName, sizeof(sHostName)) != -1)
  1035. X    iSuccess = Sock_StrHost2IP(sHostName, &IDENT_ADDR.lHost);
  1036. X
  1037. X    IDENT_ADDR.iPort = TALK_BOGUS_FD;
  1038. X    
  1039. X    Shell_UpdateUid();
  1040. X
  1041. X    
  1042. X    TERMINATE = FALSE;
  1043. X
  1044. X    
  1045. X    /** kernel debugging flags **/
  1046. X    
  1047. X    TALK_BUGS = FALSE;
  1048. X    SHELL_BUGS = FALSE;
  1049. X    NANCY_BUGS = FALSE;
  1050. X    
  1051. X    
  1052. X    /** other kernel globals **/
  1053. X    
  1054. X    TRAP_FLAGS = 0;
  1055. X    TASKS = 0;
  1056. X
  1057. X    iSuccess = VEOS_SUCCESS;
  1058. X
  1059. X
  1060. X    return(iSuccess);
  1061. X
  1062. X    } /* Shell_InitCaches */
  1063. X/****************************************************************************************/
  1064. X
  1065. X
  1066. X
  1067. X/****************************************************************************************/
  1068. Xvoid Shell_TrapErr(iSignal, iCode, context, pAddr)
  1069. X    int            iSignal, iCode;
  1070. X    struct sigcontext    *context;
  1071. X    char        *pAddr;
  1072. X{
  1073. X    str255        sErr;
  1074. X    str63        sSignal;
  1075. X    static boolean    bGone = FALSE;
  1076. X
  1077. X    /** interupt was already trapped once with no service **/
  1078. X
  1079. X    if (TRAP_FLAGS & 0x00000001 << iSignal) {
  1080. X    Shell_Signal2String(iSignal, sSignal);
  1081. X    sprintf(sErr, "fatal signal: %s, entity: %s\n", sSignal, WHOAMI);
  1082. X
  1083. X    if (bGone)
  1084. X        exit(0);
  1085. X
  1086. X    else {
  1087. X        bGone = TRUE;
  1088. X        Shell_BailOut(sErr);
  1089. X        }
  1090. X    }
  1091. X    else {
  1092. X#ifndef OPTIMAL
  1093. X    if (SHELL_BUGS) {
  1094. X        Shell_Signal2String(iSignal, sSignal);
  1095. X        fprintf(stderr, "shell %s: interrupt occurred: %s.\n", WHOAMI, sSignal);
  1096. X        }
  1097. X#endif    
  1098. X    TRAP_FLAGS |= 0x00000001 << iSignal;
  1099. X    }
  1100. X
  1101. X    } /* Shell_TrapErr */
  1102. X/****************************************************************************************/
  1103. X
  1104. X
  1105. X
  1106. X/****************************************************************************************/
  1107. XTVeosErr Shell_Signal2String(iSignal, sSignal)
  1108. X    int        iSignal;
  1109. X    char    *sSignal;
  1110. X{
  1111. X    switch (iSignal) {
  1112. X
  1113. X    case SIGBUS:
  1114. X    strcpy(sSignal, "bus error");
  1115. X    break;
  1116. X
  1117. X    case SIGKILL:
  1118. X    strcpy(sSignal, "forceful kill");
  1119. X    break;
  1120. X
  1121. X    case SIGQUIT:
  1122. X    strcpy(sSignal, "user quit request");
  1123. X    break;
  1124. X
  1125. X    case SIGSEGV:
  1126. X    strcpy(sSignal, "segmentation fault");
  1127. X    break;
  1128. X
  1129. X    case SIGINT:
  1130. X    strcpy(sSignal, "keyboard interrupt");
  1131. X    break;
  1132. X
  1133. X    case SIGPIPE:
  1134. X    strcpy(sSignal, "broken pipe");
  1135. X    break;
  1136. X
  1137. X    default:
  1138. X    strcpy(sSignal, "unknown signal");
  1139. X    break;
  1140. X    }
  1141. X
  1142. X    return(VEOS_SUCCESS);
  1143. X
  1144. X    } /* Shell_Signal2String */
  1145. X/****************************************************************************************/
  1146. X
  1147. X
  1148. X
  1149. X/****************************************************************************************/
  1150. XTVeosErr Shell_SetupErrorTraps()
  1151. X{
  1152. X    if (SIG_ENABLE) {
  1153. X    signal(SIGINT, Shell_TrapErr);
  1154. X    signal(SIGQUIT, Shell_TrapErr);
  1155. X    signal(SIGBUS, Shell_TrapErr); 
  1156. X    signal(SIGSEGV, Shell_TrapErr); 
  1157. X    signal(SIGPIPE, Shell_TrapErr);
  1158. X    }
  1159. X
  1160. X    } /* Shell_SetupErrorTraps */
  1161. X/****************************************************************************************/
  1162. X
  1163. X
  1164. X
  1165. X/****************************************************************************************/
  1166. XTVeosErr Shell_StartUpMessage()
  1167. X{
  1168. X    fprintf(stderr, "\n\n\n");
  1169. X    fprintf(stderr, "----------------------------------------------------\n");
  1170. X    fprintf(stderr, "             VEOS 2.0   by Geoffrey Coco            \n");
  1171. X    fprintf(stderr, " Copyright (C) 1992, Human Interface Technology Lab \n");
  1172. X    fprintf(stderr, "----------------------------------------------------\n\n\n\n");
  1173. X
  1174. X    return(VEOS_SUCCESS);
  1175. X
  1176. X    } /* Shell_StartUpMessage */
  1177. X/****************************************************************************************/
  1178. X
  1179. X
  1180. X
  1181. X
  1182. X/****************************************************************************************/
  1183. XTVeosErr Shell_UpdateUid()
  1184. X{
  1185. X    TVeosErr         iSuccess;
  1186. X    str63        sHostName;
  1187. X
  1188. X    /** update WHOAMI C variable **/
  1189. X
  1190. X    iSuccess = Sock_IP2StrHost(IDENT_ADDR.lHost, sHostName);
  1191. X    if (iSuccess == VEOS_SUCCESS)
  1192. X
  1193. X    sprintf(WHOAMI, "%s_%d", sHostName, IDENT_ADDR.iPort);
  1194. X
  1195. X
  1196. X    return(iSuccess);
  1197. X
  1198. X    } /* Shell_UpdateUid */
  1199. X/****************************************************************************************/
  1200. X
  1201. X
  1202. X
  1203. X#ifdef _DEC_
  1204. X/****************************************************************************************/
  1205. Xchar *strdup(sSrc)
  1206. X    char    *sSrc;
  1207. X{
  1208. X    char    *sReturn;
  1209. X
  1210. X    sReturn = nil;
  1211. X
  1212. X    if (sSrc) {
  1213. X    if (NEWPTR(sReturn, char *, strlen(sSrc) + 1))
  1214. X        strcpy(sReturn, sSrc);
  1215. X    }
  1216. X
  1217. X    return(sReturn);
  1218. X
  1219. X    } /* strdup */
  1220. X/****************************************************************************************/
  1221. X#endif
  1222. X
  1223. X
  1224. X
  1225. END_OF_FILE
  1226. if test 10711 -ne `wc -c <'kernel_private/src/shell/shell.c'`; then
  1227.     echo shar: \"'kernel_private/src/shell/shell.c'\" unpacked with wrong size!
  1228. fi
  1229. # end of 'kernel_private/src/shell/shell.c'
  1230. fi
  1231. if test -f 'src/kernel_current/fern/fx.lsp' -a "${1}" != "-c" ; then 
  1232.   echo shar: Will not clobber existing file \"'src/kernel_current/fern/fx.lsp'\"
  1233. else
  1234. echo shar: Extracting \"'src/kernel_current/fern/fx.lsp'\" \(9543 characters\)
  1235. sed "s/^X//" >'src/kernel_current/fern/fx.lsp' <<'END_OF_FILE'
  1236. X;;-----------------------------------------------------------
  1237. X;; file: fx.lsp
  1238. X;;
  1239. X;; FERN is the Fractal Entity Relativity Node.
  1240. X;; This file is the trans compenent of the Fern System.
  1241. X;;
  1242. X;; creation: March 28, 1992
  1243. X;;
  1244. X;; by Geoffrey P. Coco at the HITLab, Seattle
  1245. X;;-----------------------------------------------------------
  1246. X
  1247. X;;-----------------------------------------------------------
  1248. X;; Copyright (C) 1992  Geoffrey P. Coco,
  1249. X;; Human Interface Technology Lab, Seattle
  1250. X;;-----------------------------------------------------------
  1251. X
  1252. X
  1253. X;;-----------------------------------------------------------
  1254. X#|
  1255. X
  1256. XThe FX component of the Fern System is concerned with normal
  1257. Xcommunications between space and entity.
  1258. X
  1259. XA primary purpose of the Fern System is to transparently
  1260. Xmaintain the distributed world database.  These functions
  1261. Xprovide the inter-entity transport mechanism for the Fern
  1262. XSystem and they compose the FX component of the Fern System.
  1263. X
  1264. X|#
  1265. X;;-----------------------------------------------------------
  1266. X
  1267. X
  1268. X
  1269. X;;===========================================================
  1270. X;;
  1271. X;;             FX PUBLIC FUNCTIONS
  1272. X;;
  1273. X;;===========================================================
  1274. X
  1275. X
  1276. X;;-----------------------------------------------------------
  1277. X;;           Entity Level Binding Entry Pts
  1278. X;;-----------------------------------------------------------
  1279. X
  1280. X
  1281. X;;-----------------------------------------------------------
  1282. X
  1283. X;; instigate a space/entity relationship between your entity
  1284. X;; and the given entity.  sp-uid becomes a space of yours.
  1285. X;; any entity/space token loop begins here.
  1286. X
  1287. X(defun fx-enter (sp-uid)
  1288. X  (cond ((fe-copy.ext.sps.ent sp-uid))
  1289. X    (t
  1290. X     (cond (fern-debug
  1291. X        (printf "fx-enter... new space: " (uid2str sp-uid))))
  1292. X
  1293. X     ;; add new space to external partition 
  1294. X     (fe-put.ext.sps.ent (list sp-uid ()))
  1295. X
  1296. X     ;; add delta time-stamp to hash table
  1297. X     (fbase-put-hash fern-ent-htab sp-uid (vmintime))
  1298. X
  1299. X     ;; pass first boundary update (i.e. the token) to space
  1300. X     (vthrow (list sp-uid) 
  1301. X         `(fx-sp-enter ,self (quote ,(fx-ent-exude sp-uid))))
  1302. X     t)))
  1303. X
  1304. X;;-----------------------------------------------------------
  1305. X
  1306. X;; instagate the exit procedure.
  1307. X;; terminate a space/entity relationship between your entity
  1308. X;; and the given entity.  the token will travel one more time
  1309. X;; around.     
  1310. X
  1311. X(defun fx-exit (sp-uid)
  1312. X
  1313. X
  1314. X  (cond ((fe-copy.ext.sps.ent sp-uid)
  1315. X
  1316. X     (cond (fern-debug
  1317. X        (printf "fx-exit... space: " (uid2str sp-uid))))
  1318. X
  1319. X     ;; remove space from space list.
  1320. X     (fe-get.ext.sps.ent sp-uid)
  1321. X
  1322. X     ;; remove this entry from timestamp hash table
  1323. X     (fbase-get-hash fern-ent-htab sp-uid)
  1324. X
  1325. X     ;; assume that entity has the token.
  1326. X     ;; NOTE: this is not a safe assumption.
  1327. X     ;; In other words, it is only safe to call
  1328. X     ;; fx-exit from within a react proc.
  1329. X
  1330. X     ;; token now passes one more time through it's loop
  1331. X     ;; to the space (fx-sp-exit, fx-sp-unperceive)
  1332. X     ;; then, ending at (fx-ent-unperceive)
  1333. X     (vthrow (list sp-uid) 
  1334. X         `(fx-sp-exit ,self))
  1335. X     )))
  1336. X
  1337. X;;-----------------------------------------------------------
  1338. X
  1339. X
  1340. X
  1341. X;;===========================================================
  1342. X;;
  1343. X;;             FX PRIVATE FUNCTIONS
  1344. X;;
  1345. X;;===========================================================
  1346. X
  1347. X
  1348. X;;-----------------------------------------------------------
  1349. X
  1350. X(defun fx-init ()
  1351. X  (setq fern-sp-htab (fbase-new-htab))
  1352. X  (setq fern-ent-htab (fbase-new-htab))
  1353. X  )
  1354. X
  1355. X;;-----------------------------------------------------------
  1356. X
  1357. X
  1358. X
  1359. X;;-----------------------------------------------------------
  1360. X;;        Space Level Binding Entry Pts
  1361. X;;-----------------------------------------------------------
  1362. X
  1363. X
  1364. X;;-----------------------------------------------------------
  1365. X
  1366. X;; accept a space/entity relationship between from another 
  1367. X;; entity.  setup initial data structures, pass included
  1368. X;; entity->space token into token loop.
  1369. X
  1370. X(defun fx-sp-enter (ent-uid vbf)
  1371. X  (progn
  1372. X    (cond (fern-debug
  1373. X       (printf "fx-sp-enter... new entity: " (uid2str ent-uid))))
  1374. X
  1375. X    ;; the entering entity has already checked for duplicates.
  1376. X    ;; add new entity to sublings partition,
  1377. X    ;; overiding a possible previous deletion.
  1378. X    (fe-put.int.subs.ent (list ent-uid nil))
  1379. X
  1380. X    ;; add new entity with delta time-stamp to fern hash table
  1381. X    (fbase-put-hash fern-sp-htab ent-uid (vmintime))
  1382. X
  1383. X    ;; pass included token to normal space entry point
  1384. X    (fx-sp-perceive ent-uid vbf)
  1385. X    ))
  1386. X
  1387. X;;-----------------------------------------------------------
  1388. X
  1389. X;; accept a termination request of space/entity relationship
  1390. X;; from another entity.  takedown data structures, pass included
  1391. X;; entity->space token into final token loop.
  1392. X
  1393. X(defun fx-sp-exit (ent-uid)
  1394. X  (progn
  1395. X    (cond (fern-debug
  1396. X       (printf "fx-sp-exit... retiring entity: " (uid2str ent-uid))))
  1397. X
  1398. X    ;; remove entity timestamp hash table
  1399. X    (fbase-get-hash fern-sp-htab ent-uid)
  1400. X
  1401. X    ;; remove entity from sublings partition..
  1402. X    ;; and thus from the externals of all other entities in this space.
  1403. X    (fe-get.int.subs.ent ent-uid)
  1404. X
  1405. X    ;; eliminate perceptual references to this entity
  1406. X    (fx-sp-unperceive ent-uid)
  1407. X    ))
  1408. X
  1409. X;;-----------------------------------------------------------
  1410. X
  1411. X
  1412. X
  1413. X;;-----------------------------------------------------------
  1414. X;;        Space Token Normal Operation
  1415. X;;-----------------------------------------------------------
  1416. X
  1417. X
  1418. X;;-----------------------------------------------------------
  1419. X
  1420. X(defun fx-ent-perceive (which-sp bndry-list)
  1421. X  (progn
  1422. X    (cond (fern-debug
  1423. X       (printf "fx-ent-perceive ... from space: " (uid2str which-sp))
  1424. X       (printf "the goods:")
  1425. X       (pprint bndry-list)))
  1426. X
  1427. X    ;;;
  1428. X    ;;; update external siblings partition of local grouplespace
  1429. X    ;;;
  1430. X
  1431. X    (dolist (ent bndry-list)
  1432. X
  1433. X        (cond
  1434. X         ((equal (car ent) self))
  1435. X         ((consp (cadr ent))
  1436. X          (dolist (ob (cadr ent))
  1437. X              
  1438. X              (cond
  1439. X               ((consp (cadr ob))
  1440. X            (dolist (attr (cadr ob))
  1441. X
  1442. X                (fe-put.ext.sibs.ent.ob.attr (car ent) (car ob) attr)))
  1443. X
  1444. X               ((fe-put.ext.sibs.ent.ob (car ent) ob)))))
  1445. X
  1446. X         ((fe-put.ext.sibs.ent ent))))
  1447. X
  1448. X    ;; dispatch reactive behaviors
  1449. X    (do-procs react-procs)
  1450. X    
  1451. X    ;; repost to space all instant changes
  1452. X    ;; this is the bottom of the entity-space token loop
  1453. X    (vthrow (list which-sp) 
  1454. X        `(fx-sp-perceive ,self (quote ,(fx-ent-exude which-sp))))
  1455. X
  1456. X    (gc)
  1457. X    ))
  1458. X
  1459. X;;-----------------------------------------------------------
  1460. X
  1461. X(defun fx-ent-exude (sp-uid)
  1462. X
  1463. X  ;; generate a vbf structure to match space protocol.
  1464. X  ;; a vbf structure is (uid virt-bndry fltr).
  1465. X
  1466. X  ;; as of 5/1/92, filters are omitted and
  1467. X  ;; the uid is passed as a separate argument.
  1468. X
  1469. X  (let* ((ts 0.0) vbf)
  1470. X
  1471. X    (fbase-hash fern-ent-htab sp-uid ts)
  1472. X    (setq vbf (fe-copy.bndry.vrt :test-time ts))
  1473. X
  1474. X    ;; replace time stamp for this space
  1475. X    (fbase-put-hash fern-ent-htab sp-uid ts)
  1476. X    
  1477. X    (cond (fern-debug
  1478. X       (printf "fx-ent-exude ... to space: " (uid2str sp-uid))
  1479. X       (printf "the goods:")
  1480. X       (pprint vbf)))
  1481. X
  1482. X    ;; return the entity->space token to caller
  1483. X    vbf))
  1484. X
  1485. X;;-----------------------------------------------------------
  1486. X
  1487. X
  1488. X
  1489. X;;-----------------------------------------------------------
  1490. X
  1491. X(defun fx-sp-perceive (uid vbf)
  1492. X  (progn
  1493. X    ;; top of the entity-space token loop.
  1494. X    
  1495. X    (cond (fern-debug
  1496. X       (printf "fx-sp-perceive ... from entity: " (uid2str uid))
  1497. X       (printf "the goods:")
  1498. X       (pprint vbf)))
  1499. X    
  1500. X    ;;;
  1501. X    ;;; update internal sublings partition of grouplepsace
  1502. X    ;;;
  1503. X
  1504. X    (cond 
  1505. X     ((listp vbf)
  1506. X      (dolist (ob vbf) 
  1507. X          
  1508. X          (cond
  1509. X           ((consp (cadr ob))
  1510. X        (dolist (attr (cadr ob))
  1511. X             
  1512. X            (fe-put.int.subs.ent.ob.attr uid (car ob) attr)))
  1513. X           
  1514. X           ((fe-put.int.subs.ent.ob uid ob)))))
  1515. X     
  1516. X     ((fe-put.int.subs.ent (list uid vbf))))
  1517. X
  1518. X             
  1519. X    ;;;
  1520. X    ;;; space takes no reactive action...
  1521. X    ;;;
  1522. X    (cond (fern-debug
  1523. X       (printf "\nthe world:")
  1524. X       (pprint (fe-copy.int.subs))
  1525. X       (printf "")))
  1526. X    
  1527. X    ;; repost to entity all world activity
  1528. X    (vthrow (list uid)
  1529. X        `(fx-ent-perceive ,self (quote ,(fx-sp-exude uid))))
  1530. X    ))
  1531. X
  1532. X;;-----------------------------------------------------------
  1533. X
  1534. X(defun fx-sp-exude (uid)
  1535. X  (progn
  1536. X    ;; generate message to match entity protocol:
  1537. X    ;; list of sibling entities
  1538. X
  1539. X    (let* ((ts 0.0) sibs)
  1540. X
  1541. X      (fbase-hash fern-sp-htab uid ts)
  1542. X      (setq sibs (fe-copy.int.subs :test-time ts))
  1543. X
  1544. X      ;; reset this entity's time-stamp
  1545. X      (fbase-put-hash fern-sp-htab uid ts)
  1546. X
  1547. X      (cond (fern-debug
  1548. X         (printf "fx-sp-exude ... to entity: " (uid2str uid))
  1549. X         (printf "the goods:")
  1550. X         (pprint sibs)))
  1551. X
  1552. X      ;; return the space->entity token to caller
  1553. X      sibs)))
  1554. X
  1555. X;;-----------------------------------------------------------
  1556. X
  1557. X
  1558. X
  1559. X
  1560. X
  1561. X;;-----------------------------------------------------------
  1562. X;;            Token Loop Unbinding
  1563. X;;-----------------------------------------------------------
  1564. X
  1565. X
  1566. X;;-----------------------------------------------------------
  1567. X
  1568. X;; end of line for space/entity token.
  1569. X
  1570. X(defun fx-ent-unperceive (which-sp ent-list)
  1571. X  (progn
  1572. X    (cond (fern-debug
  1573. X       (printf "fx-ent-UNperceive ... from space: " (uid2str which-sp))))
  1574. X    
  1575. X    ;; update external perception partition of local grouplespace
  1576. X    ;; so that all that entities from that space are removed.
  1577. X    (mapcar 'fe-get.ext.sibs.ent ent-list)
  1578. X    ))
  1579. X
  1580. X;;-----------------------------------------------------------
  1581. X
  1582. X(defun fx-sp-unperceive (uid)
  1583. X  (progn 
  1584. X    (cond (fern-debug
  1585. X       (printf "fx-sp-UNperceive ... from entity: " (uid2str uid))))
  1586. X
  1587. X    ;; rid subling of any perceptions of this space
  1588. X    (vthrow (list uid) 
  1589. X        `(fx-ent-unperceive ,self (quote ,(fe-copy.int.subs.uids))))
  1590. X    ))
  1591. X
  1592. X;;-----------------------------------------------------------
  1593. X
  1594. X
  1595. END_OF_FILE
  1596. if test 9543 -ne `wc -c <'src/kernel_current/fern/fx.lsp'`; then
  1597.     echo shar: \"'src/kernel_current/fern/fx.lsp'\" unpacked with wrong size!
  1598. fi
  1599. # end of 'src/kernel_current/fern/fx.lsp'
  1600. fi
  1601. if test -f 'src/kernel_current/include/kernel.h' -a "${1}" != "-c" ; then 
  1602.   echo shar: Will not clobber existing file \"'src/kernel_current/include/kernel.h'\"
  1603. else
  1604. echo shar: Extracting \"'src/kernel_current/include/kernel.h'\" \(9869 characters\)
  1605. sed "s/^X//" >'src/kernel_current/include/kernel.h' <<'END_OF_FILE'
  1606. X/****************************************************************************************
  1607. X * file: kernel.h                                    *
  1608. X *                                            *
  1609. X * May 18, 1991:  the kernel's private defines, and structures.                *
  1610. X *                                                    *
  1611. X * by Geoffrey P. Coco at the HITLab, Seattle.                          *
  1612. X *                                            *
  1613. X ****************************************************************************************/
  1614. X
  1615. X
  1616. X/****************************************************************************************
  1617. X * Copyright (C) 1992  Geoffrey P. Coco, Human Interface Technology Lab, Seattle    *
  1618. X ****************************************************************************************/
  1619. X
  1620. X
  1621. X#include "world.h"
  1622. X
  1623. X#ifdef _SG_
  1624. X#include <ulocks.h>
  1625. X#endif
  1626. X
  1627. X#ifdef MAIN_MODULE
  1628. X#define EXTERN
  1629. X#else
  1630. X#define EXTERN extern
  1631. X#endif
  1632. X
  1633. X/****************************************************************************************
  1634. X                       Talk Module
  1635. X ****************************************************************************************/
  1636. X
  1637. X
  1638. X#define TALK_CREATE        -11        /* socket() error */
  1639. X#define TALK_HOST        -12        /* gethostbyname() error */
  1640. X#define TALK_PROTOCOL        -13        /* getprotobyname() error */
  1641. X#define TALK_SERVICE        -14        /* getservbyname() error */
  1642. X
  1643. X#define TALK_CONNECT        -15        /* connect() error */
  1644. X#define TALK_BIND        -16        /* bind(): bind to an address */
  1645. X#define TALK_NAME        -17        /* getsockname(): can't name socket */
  1646. X#define TALK_LISTEN        -18        /* listen() error */
  1647. X#define TALK_FLAGS        -23        /* ioctl error **/
  1648. X#define TALK_SELECT        -19        /* select() error */
  1649. X#define TALK_SELECT_TIMEOUT    -20        /* select() time out; nonfatal error */
  1650. X#define TALK_NOCONN        -21        /* FD_ISSET() failed, try again */
  1651. X#define TALK_ACCEPT        -22        /* accept(): can't accept selection */
  1652. X#define TALK_CLOSE        -90        /* close() error */
  1653. X#define TALK_CONN_CLOSED      -30
  1654. X
  1655. X#define TALK_SPEAK_BLOCKED    -252
  1656. X#define TALK_LISTEN_BLOCKED    -253
  1657. X
  1658. X#define TALK_DEFAULT_PROTOCOL    "tcp"        /* standard for messages */
  1659. X#define TALK_DEFAULT_HOST    "localhost"    /* standard loop-back */
  1660. X
  1661. X#define TALK_SELECT_TIME    0        /* quick check for incoming conns */
  1662. X#define TALK_QUEUE_SIZE        5        /* size of listening queue */
  1663. X#define TALK_MAX_BUFFER        8192
  1664. X#define TALK_MAX_SPEAK_FAIL    20
  1665. X
  1666. X#define TALK_AGRESSIVE      -25        /* forcefully take listen port */
  1667. X#define TALK_PASSIVE        -24        /* leave used ports alone */
  1668. X
  1669. X#define TALK_MIN_PORT        5500
  1670. X#define TALK_MAX_PORT        20000
  1671. X
  1672. X#define TALK_SOCK_CONN        1
  1673. X#define TALK_SHMEM_CONN        2
  1674. X
  1675. X#define SHMEM_SHARED_BUF_SIZE    0xFFFF
  1676. X#define SHMEM_RW_BUF_SIZE    0x0FFF
  1677. X
  1678. X#define SHMEM_FULL        -272
  1679. X#define SHMEM_INIT_ERR        -270
  1680. X#define SHMEM_ARENA_FILE    "/tmp/veos_shmem_arena"
  1681. X
  1682. X#define UID_COMPARE(uid1, uid2)  ((uid1)->iPort == (uid2)->iPort && \
  1683. X                  (uid1)->lHost == (uid2)->lHost)
  1684. X
  1685. X/****************************************************************************************
  1686. X                    Entity Addressing
  1687. X ****************************************************************************************/
  1688. X
  1689. Xtypedef struct {
  1690. X    u_long        lHost;
  1691. X    int            iPort;
  1692. X    }   TUid,
  1693. X        *TPUid,
  1694. X        **THUid;
  1695. X
  1696. Xtypedef struct uidnode {
  1697. X    TUid        addr;
  1698. X    struct uidnode     *pNext;
  1699. X    } TUidNode,
  1700. X      *TPUidNode,
  1701. X      **THUidNode;
  1702. X
  1703. X/****************************************************************************************
  1704. X                      Shared Memory
  1705. X ****************************************************************************************/
  1706. X
  1707. X#ifdef _SG_
  1708. Xtypedef usptr_t     *TPShMem;
  1709. Xtypedef usema_t     *TPSemaphor;
  1710. X#else
  1711. Xtypedef char         *TPShMem;
  1712. Xtypedef char         *TPSemaphor;
  1713. X#endif
  1714. X
  1715. Xtypedef struct memrec {
  1716. X    int            iPort;
  1717. X    TPSemaphor        pSem;
  1718. X    char        pBuffer[SHMEM_RW_BUF_SIZE];
  1719. X    char        *pAvail, *pEnd;
  1720. X    struct memrec    *pNext;
  1721. X
  1722. X    } TSharedRec,
  1723. X      *TPSharedRec,
  1724. X      **THSharedRec;
  1725. X
  1726. X
  1727. Xtypedef struct {
  1728. X    TPSemaphor        pChainSem;
  1729. X    TPSharedRec        pChannelChain;
  1730. X
  1731. X    } TShDomainRec,
  1732. X      *TPShDomainRec,
  1733. X      **THShDomainRec;
  1734. X
  1735. X/****************************************************************************************
  1736. X                  Talk Message Queueing
  1737. X ****************************************************************************************/
  1738. X
  1739. Xtypedef struct listennode {
  1740. X
  1741. X    int                iSocketFD;
  1742. X    struct listennode    *pLink;
  1743. X
  1744. X    }    TListenNode,
  1745. X        *TPListenNode,
  1746. X        **THListenNode;
  1747. X
  1748. Xtypedef struct {
  1749. X    char        *sMessage;
  1750. X    int            iLen;
  1751. X
  1752. X    }    TMsgRec,
  1753. X        *TPMsgRec,
  1754. X        **THMsgRec;
  1755. X
  1756. Xtypedef struct messageq {
  1757. X
  1758. X    char        *sMessage;
  1759. X    int            iMsgLen;
  1760. X    struct messageq    *pLink;
  1761. X
  1762. X    }    TMessageNode,
  1763. X        *TPMessageNode,
  1764. X        **THMessageNode;
  1765. X
  1766. Xtypedef    struct speaknode {
  1767. X
  1768. X    TUid        destRec;
  1769. X    int            iConnType;
  1770. X    int            iSocketFD;
  1771. X    TPMessageNode    pMessageQ;
  1772. X    struct speaknode    *pLink;
  1773. X
  1774. X    }     TSpeakNode,
  1775. X        *TPSpeakNode,
  1776. X        **THSpeakNode;
  1777. X
  1778. X/****************************************************************************************
  1779. X                   Hostname Hash Table Entries
  1780. X ****************************************************************************************/
  1781. X
  1782. Xtypedef struct hostnode {
  1783. X    char        *sHostName;
  1784. X    u_long        lHost;
  1785. X    struct hostnode    *pNext;
  1786. X
  1787. X    } THostNode,
  1788. X      *TPHostNode,
  1789. X      **THHostNode;
  1790. X
  1791. X/****************************************************************************************
  1792. X                      Talk Globals
  1793. X ****************************************************************************************/
  1794. X
  1795. XEXTERN int            talk_iListenFD;
  1796. XEXTERN char            *talk_pTransBuffer;
  1797. XEXTERN TUid            talk_selfRec;
  1798. X
  1799. XEXTERN fd_set            talk_InetSocket_OpenWriteSockets;
  1800. XEXTERN fd_set            talk_InetSocket_OpenReadSockets;
  1801. X
  1802. XEXTERN TPHostNode        talk_pHostHash[26];
  1803. XEXTERN TPSpeakNode        talk_pOutConns;
  1804. XEXTERN TPListenNode        talk_pInConns;
  1805. X
  1806. XEXTERN boolean            talk_bTalkDebugging;
  1807. XEXTERN boolean            talk_bOutDirty;
  1808. XEXTERN long            talk_lTasks;
  1809. X
  1810. XEXTERN TPShDomainRec        talk_pPublicDomain;
  1811. XEXTERN TPShMem            talk_pTheArena;
  1812. XEXTERN TPSharedRec        talk_pListenChannel;
  1813. XEXTERN TVeosErr            (*talk_pIncomingMsgFun) ();
  1814. X
  1815. X/** quick access to talk globals **/
  1816. X
  1817. X#define SPEAK_SET        talk_pOutConns
  1818. X#define LISTEN_SOCKETFD        talk_iListenFD
  1819. X#define LISTEN_SET        talk_pInConns
  1820. X#define TASKS            talk_lTasks
  1821. X#define TALK_BUFFER          talk_pTransBuffer
  1822. X#define TALK_BUGS          talk_bTalkDebugging
  1823. X#define SPEAK_DIRTY          talk_bOutDirty
  1824. X#define OPEN_READ_SOCKETS     talk_InetSocket_OpenReadSockets
  1825. X#define OPEN_WRITE_SOCKETS     talk_InetSocket_OpenWriteSockets
  1826. X#define IDENT_ADDR        talk_selfRec
  1827. X
  1828. X#define SHMEM_DOMAIN        talk_pPublicDomain
  1829. X#define SHMEM_ARENA        talk_pTheArena
  1830. X#define SHMEM_CHANNEL        talk_pListenChannel
  1831. X
  1832. X#define TALK_MSG_FUNC        talk_pIncomingMsgFun
  1833. X#define SOCK_HOSTS        talk_pHostHash
  1834. X
  1835. X/****************************************************************************************
  1836. X                      Nancy Module
  1837. X ****************************************************************************************/
  1838. X
  1839. Xtypedef struct {
  1840. X    int            iLeft, iRight;
  1841. X
  1842. X    }   TInterval,
  1843. X        *TPInterval;
  1844. X
  1845. Xtypedef struct repnode {
  1846. X    TPGrouple        pEnviron;
  1847. X    TInterval        pWipeList[10];
  1848. X    int            iZones;
  1849. X    int            iInsertElt;
  1850. X    struct repnode    *pNext;
  1851. X
  1852. X    }    TReplaceRec,
  1853. X        *TPReplaceRec,
  1854. X        **THReplaceRec;
  1855. X
  1856. Xtypedef struct {
  1857. X    TPGrouple        pPatGr, pSrcGr;
  1858. X    int            iDestroyFlag, iFreqFlag;
  1859. X    TPReplaceRec    pReplaceList;
  1860. X    TPReplaceRec    pTouchList;
  1861. X
  1862. X    }   TMatchRec,
  1863. X        *TPMatchRec,
  1864. X        **THMatchRec;
  1865. X
  1866. X/****************************************************************************************/
  1867. X
  1868. X#define VEOS_GROUPLE_BUF_SIZE          1024
  1869. X#define NANCY_EltListInc        8
  1870. X#define NANCY_AllocHashMax        30
  1871. X
  1872. X/****************************************************************************************/
  1873. X
  1874. X#define ELTS_TO_ALLOCATE(iElts) \
  1875. X    ((((iElts - 1) / NANCY_EltListInc) + 1) * NANCY_EltListInc)
  1876. X
  1877. X#define ELTS_ALLOCATED(elts)        ((elts < NANCY_AllocHashMax) ? \
  1878. X                     ALLOC_ELTS[elts] : ELTS_TO_ALLOCATE(elts))
  1879. X
  1880. X#define BLOCKS_ALLOCATED(iBlocks, iSegSize) \
  1881. X    ((((iBlocks - 1) / iSegSize) + 1) * iSegSize)
  1882. X
  1883. X#define GET_TIME(time)            (time) = ++NANCY_TIME
  1884. X#define PRINT_TIME(time, stream)        fprintf(stream, "(ts: %d) ", time)
  1885. X
  1886. X/****************************************************************************************/
  1887. X
  1888. X
  1889. X/** nancy global declarations **/
  1890. X
  1891. XEXTERN FILE            *nancy_pStreamGlob;
  1892. XEXTERN int                nancy_iLineCount;
  1893. XEXTERN TPGrouple        nancy_pInSpace, nancy_pWorkSpace;
  1894. XEXTERN TElt            nancy_eltNil;
  1895. XEXTERN char            *nancy_pAllPurposeBuf;
  1896. XEXTERN int            nancy_pAllocElts[NANCY_AllocHashMax];
  1897. XEXTERN int            nancy_pTypeSizes[30];
  1898. XEXTERN boolean            nancy_bNancyDebugging;
  1899. XEXTERN TTimeStamp        nancy_lTime;
  1900. XEXTERN TTimeStamp        nancy_lMinTime;
  1901. X
  1902. X
  1903. X/** quick access to nancy globals **/
  1904. X
  1905. X#define WORK_SPACE        nancy_pWorkSpace
  1906. X#define GR_INSPACE        nancy_pInSpace
  1907. X
  1908. X#define LINE_COUNT        nancy_iLineCount
  1909. X#define GR_STREAM        nancy_pStreamGlob
  1910. X#define NANCY_BUF        nancy_pAllPurposeBuf
  1911. X#define TYPE_SIZES        nancy_pTypeSizes
  1912. X#define ALLOC_ELTS        nancy_pAllocElts
  1913. X#define NANCY_BUGS        nancy_bNancyDebugging
  1914. X#define NIL_ELT            nancy_eltNil
  1915. X#define NANCY_TIME        nancy_lTime
  1916. X#define NANCY_MINTIME        nancy_lMinTime
  1917. X    
  1918. X/****************************************************************************************
  1919. X                      Shell Module
  1920. X ****************************************************************************************/
  1921. X
  1922. X#define SHELL_CHAIN_HASH_MAX    65
  1923. X
  1924. X/****************************************************************************************/
  1925. X
  1926. XEXTERN long            shell_lTrapFlags;
  1927. XEXTERN boolean            shell_bShellDebugging;
  1928. XEXTERN char            *shell_pChains[SHELL_CHAIN_HASH_MAX];
  1929. XEXTERN int            shell_pBlocks[SHELL_CHAIN_HASH_MAX];
  1930. X
  1931. X#ifdef MAIN_MODULE
  1932. Xboolean             shell_bSignals = TRUE;
  1933. Xboolean                shell_bKernelSetup = FALSE;
  1934. X#else
  1935. Xextern boolean             shell_bSignals;
  1936. Xextern boolean             shell_bKernelSetup;
  1937. X#endif
  1938. X
  1939. X
  1940. X/** quick access to shell globals **/
  1941. X
  1942. X#define TRAP_FLAGS        shell_lTrapFlags
  1943. X#define MEM_CHAINS        shell_pChains
  1944. X#define BLOCKS_OUT        shell_pBlocks
  1945. X#define SIG_ENABLE        shell_bSignals
  1946. X#define SHELL_BUGS        shell_bShellDebugging
  1947. X#define KERNEL_INIT        shell_bKernelSetup
  1948. X
  1949. X/****************************************************************************************/
  1950. X
  1951. X
  1952. X
  1953. END_OF_FILE
  1954. if test 9869 -ne `wc -c <'src/kernel_current/include/kernel.h'`; then
  1955.     echo shar: \"'src/kernel_current/include/kernel.h'\" unpacked with wrong size!
  1956. fi
  1957. # end of 'src/kernel_current/include/kernel.h'
  1958. fi
  1959. if test -f 'src/kernel_current/shell/shell.c' -a "${1}" != "-c" ; then 
  1960.   echo shar: Will not clobber existing file \"'src/kernel_current/shell/shell.c'\"
  1961. else
  1962. echo shar: Extracting \"'src/kernel_current/shell/shell.c'\" \(10711 characters\)
  1963. sed "s/^X//" >'src/kernel_current/shell/shell.c' <<'END_OF_FILE'
  1964. X/****************************************************************************************
  1965. X *                                            *
  1966. X * file: shell.c                                           *
  1967. X *                                            *
  1968. X * September 7, 1990:  Wow, that's old.                            *
  1969. X *                                            *
  1970. X * by Geoffrey P. Coco at the HITLab, Seattle.                          *
  1971. X *                                            *
  1972. X ****************************************************************************************/
  1973. X
  1974. X
  1975. X/****************************************************************************************
  1976. X * Copyright (C) 1992  Geoffrey P. Coco, Human Interface Technology Lab, Seattle    *
  1977. X ****************************************************************************************/
  1978. X
  1979. X
  1980. X
  1981. X/****************************************************************************************
  1982. X *                      include the papa include file                */
  1983. X
  1984. X#include <signal.h>
  1985. X
  1986. X#define MAIN_MODULE
  1987. X#include "kernel.h"
  1988. X
  1989. X/****************************************************************************************/
  1990. X
  1991. X
  1992. X/****************************************************************************************
  1993. X * Kernel_Init                                        */
  1994. X
  1995. XTVeosErr Kernel_Init(iPort, pMessFun)
  1996. X    int            iPort;
  1997. X    TVeosErr        (*pMessFun) ();
  1998. X{
  1999. X    TVeosErr        iErr = VEOS_FAILURE;
  2000. X
  2001. X    if (KERNEL_INIT) {
  2002. X    fprintf(stderr, "veos kernel already initialized...\n");
  2003. X    fprintf(stderr, "no action was taken.\n");
  2004. X    }
  2005. X    else {
  2006. X    /** initialize often-used globals with defualt values **/
  2007. X    
  2008. X    iErr = Shell_InitCaches();
  2009. X    if (iErr == VEOS_SUCCESS) {
  2010. X        
  2011. X        
  2012. X        /** perform one-time nancy initialization **/
  2013. X        
  2014. X        iErr = Nancy_Init();
  2015. X        if (iErr == VEOS_SUCCESS) {
  2016. X        
  2017. X        
  2018. X        /** initialize inter-entity communication handler **/
  2019. X        /** this puts an ear to the network **/
  2020. X        
  2021. X        iErr = Talk_HelloTalk(iPort, pMessFun);
  2022. X        if (iErr == VEOS_SUCCESS) {
  2023. X            
  2024. X            
  2025. X            /** provide for graceful exit **/
  2026. X            
  2027. X            Shell_SetupErrorTraps();
  2028. X            
  2029. X            
  2030. X            /** print gratuitous credits **/
  2031. X            
  2032. X            Shell_StartUpMessage();
  2033. X            
  2034. X            KERNEL_INIT = TRUE;
  2035. X            }
  2036. X        }
  2037. X        }
  2038. X    
  2039. X    if (iErr != VEOS_SUCCESS)
  2040. X        fprintf(stderr, "shell %s: kernel initialization failed, error: %d\n",
  2041. X            WHOAMI, iErr);
  2042. X    }
  2043. X
  2044. X    return(iErr);
  2045. X
  2046. X    } /* Kernel_Init */
  2047. X/****************************************************************************************/
  2048. X
  2049. X
  2050. X
  2051. X/****************************************************************************************
  2052. X * Kernel_Shutdown                                    */
  2053. X
  2054. XTVeosErr Kernel_Shutdown()
  2055. X{
  2056. X    TVeosErr        iSuccess = VEOS_FAILURE;
  2057. X
  2058. X    if (KERNEL_INIT) {
  2059. X    
  2060. X    /** cleanup network loose ends **/
  2061. X    
  2062. X    iSuccess = Talk_ByeTalk();
  2063. X    
  2064. X    
  2065. X    /** dispose all memory **/
  2066. X    
  2067. X    fprintf(stderr, "\n");
  2068. X
  2069. X
  2070. X    KERNEL_INIT = FALSE;
  2071. X    }
  2072. X
  2073. X
  2074. X    return(iSuccess);
  2075. X
  2076. X    } /* Kernel_Shutdown */
  2077. X/****************************************************************************************/
  2078. X    
  2079. X
  2080. X
  2081. X
  2082. X/****************************************************************************************
  2083. X * Kernel_SystemTask                                    */
  2084. X
  2085. XTVeosErr Kernel_SystemTask()
  2086. X{
  2087. X    /** inspect every open connection for queued outgoing messages **/
  2088. X    
  2089. X    if (SPEAK_DIRTY)
  2090. X    Talk_DispatchQedSpeakMessages();
  2091. X
  2092. X
  2093. X    /** accept new entity connections **/
  2094. X/*
  2095. X    if (++TASKS % 10 == 0)
  2096. X*/
  2097. X    Talk_EstNewListenConnections();
  2098. X    
  2099. X
  2100. X    /** check each open listen connection for incoming messages **/
  2101. X    
  2102. X    Talk_GatherListenMessages();
  2103. X    
  2104. X
  2105. X    return(VEOS_SUCCESS);
  2106. X
  2107. X    } /* Kernel_SystemTask */
  2108. X/****************************************************************************************/
  2109. X
  2110. X
  2111. X
  2112. X/****************************************************************************************/
  2113. XTVeosErr Shell_NewBlock(iSize, hBlock, sDebug)
  2114. X    int            iSize;
  2115. X    char *        *hBlock;
  2116. X    char        *sDebug;
  2117. X{
  2118. X    char *        *pBlock;
  2119. X    TVeosErr        iSuccess;
  2120. X    
  2121. X    if (iSize >= SHELL_CHAIN_HASH_MAX) {
  2122. X    
  2123. X    NEWPTR(pBlock, char **, iSize);
  2124. X#ifndef OPTIMAL        
  2125. X    if (SHELL_BUGS)
  2126. X        fprintf(stderr, "shell %s: %s >> size: %d, regular\n",
  2127. X            WHOAMI, sDebug ? sDebug : "", iSize);
  2128. X#endif
  2129. X    }
  2130. X    
  2131. X    else {
  2132. X    if (pBlock = (char **) MEM_CHAINS[iSize]) {
  2133. X        
  2134. X        BLOCKS_OUT[iSize] ++;
  2135. X        
  2136. X        /** remove nearest block in chain **/
  2137. X        
  2138. X        MEM_CHAINS[iSize] = *pBlock;
  2139. X        *pBlock = nil;
  2140. X#ifndef OPTIMAL        
  2141. X        if (SHELL_BUGS)
  2142. X        fprintf(stderr, "shell %s: %s >> size: %d, recycle, blocks out: %d\n",
  2143. X            WHOAMI, sDebug ? sDebug : "", iSize, BLOCKS_OUT[iSize]);
  2144. X#endif
  2145. X        }
  2146. X    
  2147. X    else {
  2148. X        BLOCKS_OUT[iSize] ++;
  2149. X        NEWPTR(pBlock, char **, iSize);
  2150. X#ifndef OPTIMAL        
  2151. X        if (SHELL_BUGS)
  2152. X        fprintf(stderr, "shell %s: %s >> size: %d, new, blocks out: %d\n",
  2153. X            WHOAMI, sDebug ? sDebug : "", iSize, BLOCKS_OUT[iSize]);
  2154. X#endif
  2155. X        }
  2156. X    }    
  2157. X    
  2158. X    if (*hBlock = (char *) pBlock)
  2159. X    iSuccess = VEOS_SUCCESS;
  2160. X    else
  2161. X    iSuccess = VEOS_FAILURE;
  2162. X
  2163. X
  2164. X    return(iSuccess);
  2165. X    
  2166. X    } /* Shell_NewBlock */
  2167. X/****************************************************************************************/
  2168. X
  2169. X
  2170. X
  2171. X
  2172. X/****************************************************************************************/
  2173. XTVeosErr Shell_ReturnBlock(pBlock, iSize, sDebug)
  2174. X    char *        *pBlock;
  2175. X    int            iSize;
  2176. X    char        *sDebug;
  2177. X{
  2178. X    int            iSuccess;
  2179. X
  2180. X    iSuccess = VEOS_SUCCESS;
  2181. X
  2182. X    if (iSize >= SHELL_CHAIN_HASH_MAX) {
  2183. X
  2184. X    DUMP(pBlock);
  2185. X#ifndef OPTIMAL
  2186. X    if (SHELL_BUGS)
  2187. X        fprintf(stderr, "shell %s: %s << size: %d, regular\n",
  2188. X            WHOAMI, sDebug ? sDebug : "", iSize);
  2189. X#endif
  2190. X    }
  2191. X
  2192. X    else {
  2193. X    BLOCKS_OUT[iSize] --;
  2194. X    
  2195. X    *pBlock = MEM_CHAINS[iSize];
  2196. X    
  2197. X    MEM_CHAINS[iSize] = (char *) pBlock;
  2198. X#ifndef OPTIMAL    
  2199. X    if (SHELL_BUGS) {
  2200. X        fprintf(stderr, "shell %s: %s << size: %d, blocks out: %d\n",
  2201. X            WHOAMI, sDebug ? sDebug : "", iSize, BLOCKS_OUT[iSize]);
  2202. X        }
  2203. X#endif
  2204. X    }    
  2205. X
  2206. X    return(iSuccess);
  2207. X    
  2208. X    } /* Shell_ReturnBlock */
  2209. X/****************************************************************************************/
  2210. X
  2211. X
  2212. X
  2213. X/****************************************************************************************
  2214. X *                    local functions                    *
  2215. X ****************************************************************************************/
  2216. X
  2217. X
  2218. X
  2219. X/****************************************************************************************/
  2220. XTVeosErr Shell_InitCaches()
  2221. X{
  2222. X    TVeosErr        iSuccess;
  2223. X    int            iChain;
  2224. X    str63        sHostName;
  2225. X
  2226. X    iSuccess = VEOS_FAILURE;
  2227. X
  2228. X
  2229. X    /** chain list is as long as largest possible block size **/
  2230. X    
  2231. X    for (iChain = 0; iChain < SHELL_CHAIN_HASH_MAX; iChain ++) {
  2232. X    MEM_CHAINS[iChain] = nil;
  2233. X    BLOCKS_OUT[iChain] = 0;
  2234. X    }
  2235. X
  2236. X
  2237. X    /** publicly accessible globals  **/
  2238. X
  2239. X    if (gethostname(sHostName, sizeof(sHostName)) != -1)
  2240. X    iSuccess = Sock_StrHost2IP(sHostName, &IDENT_ADDR.lHost);
  2241. X
  2242. X    IDENT_ADDR.iPort = TALK_BOGUS_FD;
  2243. X    
  2244. X    Shell_UpdateUid();
  2245. X
  2246. X    
  2247. X    TERMINATE = FALSE;
  2248. X
  2249. X    
  2250. X    /** kernel debugging flags **/
  2251. X    
  2252. X    TALK_BUGS = FALSE;
  2253. X    SHELL_BUGS = FALSE;
  2254. X    NANCY_BUGS = FALSE;
  2255. X    
  2256. X    
  2257. X    /** other kernel globals **/
  2258. X    
  2259. X    TRAP_FLAGS = 0;
  2260. X    TASKS = 0;
  2261. X
  2262. X    iSuccess = VEOS_SUCCESS;
  2263. X
  2264. X
  2265. X    return(iSuccess);
  2266. X
  2267. X    } /* Shell_InitCaches */
  2268. X/****************************************************************************************/
  2269. X
  2270. X
  2271. X
  2272. X/****************************************************************************************/
  2273. Xvoid Shell_TrapErr(iSignal, iCode, context, pAddr)
  2274. X    int            iSignal, iCode;
  2275. X    struct sigcontext    *context;
  2276. X    char        *pAddr;
  2277. X{
  2278. X    str255        sErr;
  2279. X    str63        sSignal;
  2280. X    static boolean    bGone = FALSE;
  2281. X
  2282. X    /** interupt was already trapped once with no service **/
  2283. X
  2284. X    if (TRAP_FLAGS & 0x00000001 << iSignal) {
  2285. X    Shell_Signal2String(iSignal, sSignal);
  2286. X    sprintf(sErr, "fatal signal: %s, entity: %s\n", sSignal, WHOAMI);
  2287. X
  2288. X    if (bGone)
  2289. X        exit(0);
  2290. X
  2291. X    else {
  2292. X        bGone = TRUE;
  2293. X        Shell_BailOut(sErr);
  2294. X        }
  2295. X    }
  2296. X    else {
  2297. X#ifndef OPTIMAL
  2298. X    if (SHELL_BUGS) {
  2299. X        Shell_Signal2String(iSignal, sSignal);
  2300. X        fprintf(stderr, "shell %s: interrupt occurred: %s.\n", WHOAMI, sSignal);
  2301. X        }
  2302. X#endif    
  2303. X    TRAP_FLAGS |= 0x00000001 << iSignal;
  2304. X    }
  2305. X
  2306. X    } /* Shell_TrapErr */
  2307. X/****************************************************************************************/
  2308. X
  2309. X
  2310. X
  2311. X/****************************************************************************************/
  2312. XTVeosErr Shell_Signal2String(iSignal, sSignal)
  2313. X    int        iSignal;
  2314. X    char    *sSignal;
  2315. X{
  2316. X    switch (iSignal) {
  2317. X
  2318. X    case SIGBUS:
  2319. X    strcpy(sSignal, "bus error");
  2320. X    break;
  2321. X
  2322. X    case SIGKILL:
  2323. X    strcpy(sSignal, "forceful kill");
  2324. X    break;
  2325. X
  2326. X    case SIGQUIT:
  2327. X    strcpy(sSignal, "user quit request");
  2328. X    break;
  2329. X
  2330. X    case SIGSEGV:
  2331. X    strcpy(sSignal, "segmentation fault");
  2332. X    break;
  2333. X
  2334. X    case SIGINT:
  2335. X    strcpy(sSignal, "keyboard interrupt");
  2336. X    break;
  2337. X
  2338. X    case SIGPIPE:
  2339. X    strcpy(sSignal, "broken pipe");
  2340. X    break;
  2341. X
  2342. X    default:
  2343. X    strcpy(sSignal, "unknown signal");
  2344. X    break;
  2345. X    }
  2346. X
  2347. X    return(VEOS_SUCCESS);
  2348. X
  2349. X    } /* Shell_Signal2String */
  2350. X/****************************************************************************************/
  2351. X
  2352. X
  2353. X
  2354. X/****************************************************************************************/
  2355. XTVeosErr Shell_SetupErrorTraps()
  2356. X{
  2357. X    if (SIG_ENABLE) {
  2358. X    signal(SIGINT, Shell_TrapErr);
  2359. X    signal(SIGQUIT, Shell_TrapErr);
  2360. X    signal(SIGBUS, Shell_TrapErr); 
  2361. X    signal(SIGSEGV, Shell_TrapErr); 
  2362. X    signal(SIGPIPE, Shell_TrapErr);
  2363. X    }
  2364. X
  2365. X    } /* Shell_SetupErrorTraps */
  2366. X/****************************************************************************************/
  2367. X
  2368. X
  2369. X
  2370. X/****************************************************************************************/
  2371. XTVeosErr Shell_StartUpMessage()
  2372. X{
  2373. X    fprintf(stderr, "\n\n\n");
  2374. X    fprintf(stderr, "----------------------------------------------------\n");
  2375. X    fprintf(stderr, "             VEOS 2.0   by Geoffrey Coco            \n");
  2376. X    fprintf(stderr, " Copyright (C) 1992, Human Interface Technology Lab \n");
  2377. X    fprintf(stderr, "----------------------------------------------------\n\n\n\n");
  2378. X
  2379. X    return(VEOS_SUCCESS);
  2380. X
  2381. X    } /* Shell_StartUpMessage */
  2382. X/****************************************************************************************/
  2383. X
  2384. X
  2385. X
  2386. X
  2387. X/****************************************************************************************/
  2388. XTVeosErr Shell_UpdateUid()
  2389. X{
  2390. X    TVeosErr         iSuccess;
  2391. X    str63        sHostName;
  2392. X
  2393. X    /** update WHOAMI C variable **/
  2394. X
  2395. X    iSuccess = Sock_IP2StrHost(IDENT_ADDR.lHost, sHostName);
  2396. X    if (iSuccess == VEOS_SUCCESS)
  2397. X
  2398. X    sprintf(WHOAMI, "%s_%d", sHostName, IDENT_ADDR.iPort);
  2399. X
  2400. X
  2401. X    return(iSuccess);
  2402. X
  2403. X    } /* Shell_UpdateUid */
  2404. X/****************************************************************************************/
  2405. X
  2406. X
  2407. X
  2408. X#ifdef _DEC_
  2409. X/****************************************************************************************/
  2410. Xchar *strdup(sSrc)
  2411. X    char    *sSrc;
  2412. X{
  2413. X    char    *sReturn;
  2414. X
  2415. X    sReturn = nil;
  2416. X
  2417. X    if (sSrc) {
  2418. X    if (NEWPTR(sReturn, char *, strlen(sSrc) + 1))
  2419. X        strcpy(sReturn, sSrc);
  2420. X    }
  2421. X
  2422. X    return(sReturn);
  2423. X
  2424. X    } /* strdup */
  2425. X/****************************************************************************************/
  2426. X#endif
  2427. X
  2428. X
  2429. X
  2430. END_OF_FILE
  2431. if test 10711 -ne `wc -c <'src/kernel_current/shell/shell.c'`; then
  2432.     echo shar: \"'src/kernel_current/shell/shell.c'\" unpacked with wrong size!
  2433. fi
  2434. # end of 'src/kernel_current/shell/shell.c'
  2435. fi
  2436. if test -f 'src/xlisp/xcore/c/xlinit.c' -a "${1}" != "-c" ; then 
  2437.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlinit.c'\"
  2438. else
  2439. echo shar: Extracting \"'src/xlisp/xcore/c/xlinit.c'\" \(10643 characters\)
  2440. sed "s/^X//" >'src/xlisp/xcore/c/xlinit.c' <<'END_OF_FILE'
  2441. X/* -*-C-*-
  2442. X********************************************************************************
  2443. X*
  2444. X* File:         xlinit.c
  2445. X* RCS:          $Header: xlinit.c,v 1.3 89/11/25 05:31:53 mayer Exp $
  2446. X* Description:  xlisp initialization module
  2447. X* Author:       David Michael Betz
  2448. X* Created:      
  2449. X* Modified:     Sat Nov 25 05:31:30 1989 (Niels Mayer) mayer@hplnpm
  2450. X* Language:     C
  2451. X* Package:      N/A
  2452. X* Status:       X11r4 contrib tape release
  2453. X*
  2454. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2455. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2456. X*
  2457. X* Permission to use, copy, modify, distribute, and sell this software and its
  2458. X* documentation for any purpose is hereby granted without fee, provided that
  2459. X* the above copyright notice appear in all copies and that both that
  2460. X* copyright notice and this permission notice appear in supporting
  2461. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2462. X* used in advertising or publicity pertaining to distribution of the software
  2463. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2464. X* make no representations about the suitability of this software for any
  2465. X* purpose. It is provided "as is" without express or implied warranty.
  2466. X*
  2467. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2468. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2469. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2470. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2471. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2472. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2473. X* PERFORMANCE OF THIS SOFTWARE.
  2474. X*
  2475. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2476. X* 
  2477. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2478. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2479. X*
  2480. X********************************************************************************
  2481. X*/
  2482. Xstatic char rcs_identity[] = "@(#)$Header: xlinit.c,v 1.3 89/11/25 05:31:53 mayer Exp $";
  2483. X
  2484. X#include "xlisp.h"
  2485. X
  2486. X/* external variables */
  2487. Xextern LVAL true,s_dot,s_unbound;
  2488. Xextern LVAL s_quote,s_function,s_bquote,s_comma,s_comat;
  2489. Xextern LVAL s_lambda,s_macro;
  2490. Xextern LVAL s_send;/*91Jun15jsp*/
  2491. Xextern LVAL s_stdin,s_stdout,s_stderr,s_debugio,s_traceout;
  2492. Xextern LVAL s_evalhook,s_applyhook,s_tracelist;
  2493. Xextern LVAL s_tracenable,s_tlimit,s_breakenable;
  2494. Xextern LVAL s_setf,s_car,s_cdr,s_nth,s_aref,s_get,s_eql;
  2495. Xextern LVAL s_svalue,s_sfunction,s_splist;
  2496. Xextern LVAL s_rtable,k_wspace,k_const,k_nmacro,k_tmacro;
  2497. Xextern LVAL k_sescape,k_mescape;
  2498. Xextern LVAL s_ifmt,s_ffmt,s_printcase;
  2499. Xextern LVAL s_1plus,s_2plus,s_3plus,s_1star,s_2star,s_3star,s_minus;
  2500. Xextern LVAL k_test,k_tnot;
  2501. Xextern LVAL k_direction,k_input,k_output;
  2502. Xextern LVAL k_start,k_end,k_1start,k_1end,k_2start,k_2end;
  2503. Xextern LVAL k_verbose,k_print,k_count,k_key,k_upcase,k_downcase;
  2504. Xextern LVAL lk_optional,lk_rest,lk_key,lk_aux,lk_allow_other_keys;
  2505. Xextern LVAL a_subr,a_fsubr,a_cons,a_symbol;
  2506. Xextern LVAL a_fixnum,a_flonum,a_string,a_stream,a_object;
  2507. Xextern LVAL a_vector,a_closure,a_char,a_ustream;
  2508. Xextern LVAL s_gcflag,s_gchook;
  2509. Xextern FUNDEF *funtab;
  2510. X
  2511. X/* Include hybrid-class functions: *//* JSP */
  2512. X#define MODULE_XLINIT_C_GLOBALS
  2513. X#include "../../xmodules.h"
  2514. X#undef MODULE_XLINIT_C_GLOBALS
  2515. X
  2516. X/* xlinit - xlisp initialization routine */
  2517. Xxlinit()
  2518. X{
  2519. X    /* initialize xlisp (must be in this order) */
  2520. X    xlfinit();  /* initialize the function table */    /* Voodoo */
  2521. X    xlminit();    /* initialize xldmem.c */
  2522. X    xldinit();    /* initialize xldbug.c */
  2523. X
  2524. X    /* finish initializing */
  2525. X#ifdef SAVERESTORE
  2526. X    if (!xlirestore("xlisp.wks"))
  2527. X#endif
  2528. X    initwks();
  2529. X
  2530. X/* Include hybrid-class functions: *//* JSP */
  2531. X#define MODULE_XLINIT_C_XLINIT
  2532. X#include "../../xmodules.h"
  2533. X#undef MODULE_XLINIT_C_XLINIT
  2534. X}
  2535. X
  2536. X/* initwks - build an initial workspace */
  2537. XLOCAL initwks()
  2538. X{
  2539. X    FUNDEF *p;
  2540. X    int i;
  2541. X    
  2542. X    xlsinit();    /* initialize xlsym.c */
  2543. X
  2544. X    /* To prevent obscure gc() crashes during initialization, it is   */
  2545. X    /* important to establish s_gcflag and s_gchook early, and to set */
  2546. X    /* them to NIL immediately.  This is Tom Almy's improvement on my */
  2547. X    /* earlier kludge: (91Jan18jsp)                                   */
  2548. X    s_gcflag = xlenter("*GC-FLAG*");    setvalue(s_gcflag,NIL);
  2549. X    s_gchook = xlenter("*GC-HOOK*");    setvalue(s_gchook,NIL);
  2550. X
  2551. X    xlsymbols();/* enter all symbols used by the interpreter */
  2552. X    xlrinit();    /* initialize xlread.c */
  2553. X    xloinit();    /* initialize xlobj.c */
  2554. X
  2555. X    /* setup defaults */
  2556. X    setvalue(s_evalhook,NIL);        /* no evalhook function */
  2557. X    setvalue(s_applyhook,NIL);        /* no applyhook function */
  2558. X    setvalue(s_tracelist,NIL);        /* no functions being traced */
  2559. X    setvalue(s_tracenable,NIL);        /* traceback disabled */
  2560. X    setvalue(s_tlimit,NIL);         /* trace limit infinite */
  2561. X    setvalue(s_breakenable,NIL);    /* don't enter break loop on errors */
  2562. X    setvalue(s_ifmt,cvstring(IFMT));    /* integer print format */
  2563. X    setvalue(s_ffmt,cvstring("%g"));    /* float print format */
  2564. X    setvalue(s_printcase,k_upcase);    /* upper case output of symbols */
  2565. X
  2566. X    /* install the built-in functions and special forms */
  2567. X    for (i = 0, p = funtab; p->fd_subr != NULL; ++i, ++p)
  2568. X    if (p->fd_name)
  2569. X        xlsubr(p->fd_name,p->fd_type,p->fd_subr,i);
  2570. X
  2571. X    /* add some synonyms */
  2572. X    setfunction(xlenter("NOT"),getfunction(xlenter("NULL")));
  2573. X    setfunction(xlenter("FIRST"),getfunction(xlenter("CAR")));
  2574. X    setfunction(xlenter("SECOND"),getfunction(xlenter("CADR")));
  2575. X    setfunction(xlenter("THIRD"),getfunction(xlenter("CADDR")));
  2576. X    setfunction(xlenter("FOURTH"),getfunction(xlenter("CADDDR")));
  2577. X    setfunction(xlenter("REST"),getfunction(xlenter("CDR")));
  2578. X}
  2579. X
  2580. X/* xlsymbols - enter all of the symbols used by the interpreter */
  2581. Xxlsymbols()
  2582. X{
  2583. X    LVAL sym;
  2584. X
  2585. X    /* enter the unbound variable indicator (must be first) */
  2586. X    s_unbound = xlenter("*UNBOUND*");
  2587. X    setvalue(s_unbound,s_unbound);
  2588. X
  2589. X    /* enter the 't' symbol */
  2590. X    true = xlenter("T");
  2591. X    setvalue(true,true);
  2592. X
  2593. X    /* enter some important symbols */
  2594. X    s_dot    = xlenter(".");
  2595. X    s_quote    = xlenter("QUOTE");
  2596. X    s_function    = xlenter("FUNCTION");
  2597. X    s_bquote    = xlenter("BACKQUOTE");
  2598. X    s_comma    = xlenter("COMMA");
  2599. X    s_comat    = xlenter("COMMA-AT");
  2600. X    s_lambda    = xlenter("LAMBDA");
  2601. X    s_send    = xlenter("SEND"); /*91Jun15jsp*/
  2602. X    s_macro    = xlenter("MACRO");
  2603. X    s_eql    = xlenter("EQL");
  2604. X    s_ifmt    = xlenter("*INTEGER-FORMAT*");
  2605. X    s_ffmt    = xlenter("*FLOAT-FORMAT*");
  2606. X
  2607. X    /* symbols set by the read-eval-print loop */
  2608. X    s_1plus    = xlenter("+");
  2609. X    s_2plus    = xlenter("++");
  2610. X    s_3plus    = xlenter("+++");
  2611. X    s_1star    = xlenter("*");
  2612. X    s_2star    = xlenter("**");
  2613. X    s_3star    = xlenter("***");
  2614. X    s_minus    = xlenter("-");
  2615. X
  2616. X    /* enter setf place specifiers */
  2617. X    s_setf    = xlenter("*SETF*");
  2618. X    s_car    = xlenter("CAR");
  2619. X    s_cdr    = xlenter("CDR");
  2620. X    s_nth    = xlenter("NTH");
  2621. X    s_aref    = xlenter("AREF");
  2622. X    s_get    = xlenter("GET");
  2623. X    s_svalue    = xlenter("SYMBOL-VALUE");
  2624. X    s_sfunction    = xlenter("SYMBOL-FUNCTION");
  2625. X    s_splist    = xlenter("SYMBOL-PLIST");
  2626. X
  2627. X    /* enter the readtable variable and keywords */
  2628. X    s_rtable    = xlenter("*READTABLE*");
  2629. X    k_wspace    = xlenter(":WHITE-SPACE");
  2630. X    k_const    = xlenter(":CONSTITUENT");
  2631. X    k_nmacro    = xlenter(":NMACRO");
  2632. X    k_tmacro    = xlenter(":TMACRO");
  2633. X    k_sescape    = xlenter(":SESCAPE");
  2634. X    k_mescape    = xlenter(":MESCAPE");
  2635. X
  2636. X    /* enter parameter list keywords */
  2637. X    k_test    = xlenter(":TEST");
  2638. X    k_tnot    = xlenter(":TEST-NOT");
  2639. X
  2640. X    /* "open" keywords */
  2641. X    k_direction = xlenter(":DIRECTION");
  2642. X    k_input     = xlenter(":INPUT");
  2643. X    k_output    = xlenter(":OUTPUT");
  2644. X
  2645. X    /* enter *print-case* symbol and keywords */
  2646. X    s_printcase = xlenter("*PRINT-CASE*");
  2647. X    k_upcase    = xlenter(":UPCASE");
  2648. X    k_downcase  = xlenter(":DOWNCASE");
  2649. X
  2650. X    /* other keywords */
  2651. X    k_start    = xlenter(":START");
  2652. X    k_end    = xlenter(":END");
  2653. X    k_1start    = xlenter(":START1");
  2654. X    k_1end    = xlenter(":END1");
  2655. X    k_2start    = xlenter(":START2");
  2656. X    k_2end    = xlenter(":END2");
  2657. X    k_verbose    = xlenter(":VERBOSE");
  2658. X    k_print    = xlenter(":PRINT");
  2659. X    k_count    = xlenter(":COUNT");
  2660. X    k_key    = xlenter(":KEY");
  2661. X
  2662. X    /* enter lambda list keywords */
  2663. X    lk_optional    = xlenter("&OPTIONAL");
  2664. X    lk_rest    = xlenter("&REST");
  2665. X    lk_key    = xlenter("&KEY");
  2666. X    lk_aux    = xlenter("&AUX");
  2667. X    lk_allow_other_keys = xlenter("&ALLOW-OTHER-KEYS");
  2668. X
  2669. X    /* enter *standard-input*, *standard-output* and *error-output* */
  2670. X    s_stdin = xlenter("*STANDARD-INPUT*");
  2671. X    setvalue(s_stdin,cvfile(stdin));
  2672. X    s_stdout = xlenter("*STANDARD-OUTPUT*");
  2673. X    setvalue(s_stdout,cvfile(stdout));
  2674. X    s_stderr = xlenter("*ERROR-OUTPUT*");
  2675. X    setvalue(s_stderr,cvfile(stderr));
  2676. X
  2677. X    /* enter *debug-io* and *trace-output* */
  2678. X    s_debugio = xlenter("*DEBUG-IO*");
  2679. X    setvalue(s_debugio,getvalue(s_stderr));
  2680. X    s_traceout = xlenter("*TRACE-OUTPUT*");
  2681. X    setvalue(s_traceout,getvalue(s_stderr));
  2682. X
  2683. X    /* enter the eval and apply hook variables */
  2684. X    s_evalhook = xlenter("*EVALHOOK*");
  2685. X    s_applyhook = xlenter("*APPLYHOOK*");
  2686. X
  2687. X    /* enter the symbol pointing to the list of functions being traced */
  2688. X    s_tracelist = xlenter("*TRACELIST*");
  2689. X
  2690. X    /* enter the error traceback and the error break enable flags */
  2691. X    s_tracenable = xlenter("*TRACENABLE*");
  2692. X    s_tlimit = xlenter("*TRACELIMIT*");
  2693. X    s_breakenable = xlenter("*BREAKENABLE*");
  2694. X
  2695. X    /* Enter a symbol to control printing of garbage collection messages. */
  2696. X    s_gcflag = xlenter("*GC-FLAG*");
  2697. X    s_gchook = xlenter("*GC-HOOK*");
  2698. X
  2699. X    /* enter a copyright notice into the oblist */
  2700. X#ifdef PROVIDE_sWINTERP
  2701. X    sym = xlenter("**Copyright-1989-by-David-Betz-and-Niels-Mayer**");
  2702. X#else
  2703. X    sym = xlenter("**Copyright-1989-by-David-Betz**");
  2704. X#endif
  2705. X    setvalue(sym,true);
  2706. X
  2707. X    /* enter type names */
  2708. X    a_subr    = xlenter("SUBR");
  2709. X    a_fsubr    = xlenter("FSUBR");
  2710. X    a_cons    = xlenter("CONS");
  2711. X    a_symbol    = xlenter("SYMBOL");
  2712. X    a_fixnum    = xlenter("FIXNUM");
  2713. X    a_flonum    = xlenter("FLONUM");
  2714. X    a_string    = xlenter("STRING");
  2715. X    a_object    = xlenter("OBJECT");
  2716. X    a_stream    = xlenter("FILE-STREAM");
  2717. X    a_vector    = xlenter("ARRAY");
  2718. X    a_closure    = xlenter("CLOSURE");
  2719. X    a_char      = xlenter("CHARACTER");
  2720. X    a_ustream    = xlenter("UNNAMED-STREAM");
  2721. X
  2722. X    /* add the object-oriented programming symbols and os specific stuff */
  2723. X    obsymbols();    /* object-oriented programming symbols */
  2724. X    ossymbols();    /* os specific symbols */
  2725. X
  2726. X/* Include hybrid-class functions: *//* JSP */
  2727. X#define MODULE_XLINIT_C_XLSYMBOLS
  2728. X#include "../../xmodules.h"
  2729. X#undef MODULE_XLINIT_C_XLSYMBOLS
  2730. X}
  2731. X
  2732. END_OF_FILE
  2733. if test 10643 -ne `wc -c <'src/xlisp/xcore/c/xlinit.c'`; then
  2734.     echo shar: \"'src/xlisp/xcore/c/xlinit.c'\" unpacked with wrong size!
  2735. fi
  2736. # end of 'src/xlisp/xcore/c/xlinit.c'
  2737. fi
  2738. if test -f 'src/xlisp/xcore/c/xlprin.c' -a "${1}" != "-c" ; then 
  2739.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlprin.c'\"
  2740. else
  2741. echo shar: Extracting \"'src/xlisp/xcore/c/xlprin.c'\" \(9502 characters\)
  2742. sed "s/^X//" >'src/xlisp/xcore/c/xlprin.c' <<'END_OF_FILE'
  2743. X/* -*-C-*-
  2744. X********************************************************************************
  2745. X*
  2746. X* File:         xlprint.c
  2747. X* RCS:          $Header: xlprin.c,v 1.5 89/11/25 05:42:42 mayer Exp $
  2748. X* Description:  xlisp print routine
  2749. X* Author:       David Michael Betz
  2750. X* Created:      
  2751. X* Modified:     Sat Nov 25 05:42:35 1989 (Niels Mayer) mayer@hplnpm
  2752. X* Language:     C
  2753. X* Package:      N/A
  2754. X* Status:       X11r4 contrib tape release
  2755. X*
  2756. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2757. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2758. X*
  2759. X* Permission to use, copy, modify, distribute, and sell this software and its
  2760. X* documentation for any purpose is hereby granted without fee, provided that
  2761. X* the above copyright notice appear in all copies and that both that
  2762. X* copyright notice and this permission notice appear in supporting
  2763. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2764. X* used in advertising or publicity pertaining to distribution of the software
  2765. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2766. X* make no representations about the suitability of this software for any
  2767. X* purpose. It is provided "as is" without express or implied warranty.
  2768. X*
  2769. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2770. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2771. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2772. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2773. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2774. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2775. X* PERFORMANCE OF THIS SOFTWARE.
  2776. X*
  2777. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2778. X* 
  2779. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2780. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2781. X*
  2782. X********************************************************************************
  2783. X*/
  2784. Xstatic char rcs_identity[] = "@(#)$Header: xlprin.c,v 1.5 89/11/25 05:42:42 mayer Exp $";
  2785. X
  2786. X
  2787. X#include "xlisp.h"
  2788. X
  2789. X/* external variables */
  2790. Xextern LVAL tentry();
  2791. Xextern LVAL s_printcase,k_downcase,k_const,k_nmacro;
  2792. Xextern LVAL s_ifmt,s_ffmt;
  2793. Xextern FUNDEF *funtab;
  2794. Xextern char buf[];
  2795. X
  2796. X/* Include hybrid-class functions: *//* JSP */
  2797. X#define MODULE_XLPRIN_C_GLOBALS
  2798. X#include "../../xmodules.h"
  2799. X#undef MODULE_XLPRIN_C_GLOBALS
  2800. X
  2801. X/* xlprint - print an xlisp value */
  2802. Xxlprint(fptr,vptr,flag)
  2803. X  LVAL fptr,vptr; int flag;
  2804. X{
  2805. X    LVAL nptr,next;
  2806. X    int n,i;
  2807. X
  2808. X    /* print nil */
  2809. X    if (vptr == NIL) {
  2810. X    putsymbol(fptr,"NIL",flag);
  2811. X    return;
  2812. X    }
  2813. X
  2814. X    /* check value type */
  2815. X    switch (ntype(vptr)) {
  2816. X    case SUBR:
  2817. X        putsubr(fptr,"Subr",vptr);
  2818. X        break;
  2819. X    case FSUBR:
  2820. X        putsubr(fptr,"FSubr",vptr);
  2821. X        break;
  2822. X    case CONS:
  2823. X        xlputc(fptr,'(');
  2824. X        for (nptr = vptr; nptr != NIL; nptr = next) {
  2825. X            xlprint(fptr,car(nptr),flag);
  2826. X        if (next = cdr(nptr))
  2827. X            if (consp(next))
  2828. X            xlputc(fptr,' ');
  2829. X            else {
  2830. X            xlputstr(fptr," . ");
  2831. X            xlprint(fptr,next,flag);
  2832. X            break;
  2833. X            }
  2834. X        }
  2835. X        xlputc(fptr,')');
  2836. X        break;
  2837. X    case SYMBOL:
  2838. X        putsymbol(fptr,getstring(getpname(vptr)),flag);
  2839. X        break;
  2840. X    case FIXNUM:
  2841. X        putfixnum(fptr,getfixnum(vptr));
  2842. X        break;
  2843. X    case FLONUM:
  2844. X        putflonum(fptr,getflonum(vptr));
  2845. X        break;
  2846. X    case CHAR:
  2847. X        putchcode(fptr,getchcode(vptr),flag);
  2848. X        break;
  2849. X    case STRING:
  2850. X        if (flag)
  2851. X        putqstring(fptr,vptr);
  2852. X        else
  2853. X        putstring(fptr,vptr);
  2854. X        break;
  2855. X    case STREAM:
  2856. X        putatm(fptr,"File-Stream",vptr);
  2857. X        break;
  2858. X    case USTREAM:
  2859. X        putatm(fptr,"Unnamed-Stream",vptr);
  2860. X        break;
  2861. X    case OBJECT:
  2862. X        putatm(fptr,"Object",vptr);
  2863. X        break;
  2864. X    case VECTOR:
  2865. X        xlputc(fptr,'#'); xlputc(fptr,'(');
  2866. X        for (i = 0, n = getsz(vptr) - 1; i <= n; ++i) {
  2867. X        xlprint(fptr,getelement(vptr,i),flag);
  2868. X        if (i != n) xlputc(fptr,' ');
  2869. X        }
  2870. X        xlputc(fptr,')');
  2871. X        break;
  2872. X    case STRUCT:
  2873. X        xlprstruct(fptr,vptr,flag);
  2874. X        break;
  2875. X    case CLOSURE:
  2876. X        putclosure(fptr,vptr);
  2877. X        break;
  2878. X    case FREE:
  2879. X        putatm(fptr,"Free",vptr);
  2880. X        break;
  2881. X
  2882. X/* Include hybrid-class functions: *//* JSP */
  2883. X#define MODULE_XLPRIN_C_XLPRINT
  2884. X#include "../../xmodules.h"
  2885. X#undef MODULE_XLPRIN_C_XLPRINT
  2886. X
  2887. X    default:
  2888. X        putatm(fptr,"Foo",vptr);
  2889. X        break;
  2890. X    }
  2891. X}
  2892. X
  2893. X/* xlterpri - terminate the current print line */
  2894. Xxlterpri(fptr)
  2895. X  LVAL fptr;
  2896. X{
  2897. X    xlputc(fptr,'\n');
  2898. X}
  2899. X
  2900. X/* xlputstr - output a string */
  2901. Xxlputstr(fptr,str)
  2902. X  LVAL fptr; char *str;
  2903. X{
  2904. X    while (*str)
  2905. X    xlputc(fptr,*str++);
  2906. X}
  2907. X
  2908. X/* putsymbol - output a symbol */
  2909. XLOCAL putsymbol(fptr,str,escflag)
  2910. X  LVAL fptr; char *str; int escflag;
  2911. X{
  2912. X    int downcase,ch;
  2913. X    LVAL type;
  2914. X    char *p;
  2915. X
  2916. X    /* check for printing without escapes */
  2917. X    if (!escflag) {
  2918. X    xlputstr(fptr,str);
  2919. X    return;
  2920. X    }
  2921. X
  2922. X    /* check to see if symbol needs escape characters */
  2923. X    if (tentry(*str) == k_const) {
  2924. X    for (p = str; *p; ++p)
  2925. X        if (islower(*p)
  2926. X        ||  ((type = tentry(*p)) != k_const
  2927. X          && (!consp(type) || car(type) != k_nmacro))) {
  2928. X        xlputc(fptr,'|');
  2929. X        while (*str) {
  2930. X            if (*str == '\\' || *str == '|')
  2931. X            xlputc(fptr,'\\');
  2932. X            xlputc(fptr,*str++);
  2933. X        }
  2934. X        xlputc(fptr,'|');
  2935. X        return;
  2936. X        }
  2937. X    }
  2938. X
  2939. X    /* get the case translation flag */
  2940. X    downcase = (getvalue(s_printcase) == k_downcase);
  2941. X
  2942. X    /* check for the first character being '#' */
  2943. X    if (*str == '#' || *str == '.' || isnumber(str,NULL))
  2944. X    xlputc(fptr,'\\');
  2945. X
  2946. X    /* output each character */
  2947. X    while ((ch = *str++) != '\0') {
  2948. X    /* don't escape colon until we add support for packages */
  2949. X    if (ch == '\\' || ch == '|' /* || ch == ':' */)
  2950. X        xlputc(fptr,'\\');
  2951. X    xlputc(fptr,(downcase && isupper(ch) ? tolower(ch) : ch));
  2952. X    }
  2953. X}
  2954. X
  2955. X/* putstring - output a string */
  2956. XLOCAL putstring(fptr,str)
  2957. X  LVAL fptr,str;
  2958. X{
  2959. X    unsigned char *p;
  2960. X    int ch;
  2961. X
  2962. X    /* output each character */
  2963. X    for (p = getstring(str); (ch = *p) != '\0'; ++p)
  2964. X    xlputc(fptr,ch);
  2965. X}
  2966. X
  2967. X/* putqstring - output a quoted string */
  2968. XLOCAL putqstring(fptr,str)
  2969. X  LVAL fptr,str;
  2970. X{
  2971. X    unsigned char *p;
  2972. X    int ch;
  2973. X
  2974. X    /* get the string pointer */
  2975. X    p = getstring(str);
  2976. X
  2977. X    /* output the initial quote */
  2978. X    xlputc(fptr,'"');
  2979. X
  2980. X    /* output each character in the string */
  2981. X    for (p = getstring(str); (ch = *p) != '\0'; ++p)
  2982. X
  2983. X    /* check for a control character */
  2984. X    if (ch < 040 || ch == '\\' || ch > 0176) {
  2985. X        xlputc(fptr,'\\');
  2986. X        switch (ch) {
  2987. X        case '\011':
  2988. X            xlputc(fptr,'t');
  2989. X            break;
  2990. X        case '\012':
  2991. X            xlputc(fptr,'n');
  2992. X            break;
  2993. X        case '\014':
  2994. X            xlputc(fptr,'f');
  2995. X            break;
  2996. X        case '\015':
  2997. X            xlputc(fptr,'r');
  2998. X            break;
  2999. X        case '\\':
  3000. X            xlputc(fptr,'\\');
  3001. X            break;
  3002. X        default:
  3003. X            putoct(fptr,ch);
  3004. X            break;
  3005. X        }
  3006. X    }
  3007. X
  3008. X    /* output a normal character */
  3009. X    else
  3010. X        xlputc(fptr,ch);
  3011. X
  3012. X    /* output the terminating quote */
  3013. X    xlputc(fptr,'"');
  3014. X}
  3015. X
  3016. X/* putatm - output an atom */
  3017. XLOCAL putatm(fptr,tag,val)
  3018. X  LVAL fptr; char *tag; LVAL val;
  3019. X{
  3020. X    sprintf(buf,"#<%s: #",tag); xlputstr(fptr,buf);
  3021. X    sprintf(buf,AFMT,val); xlputstr(fptr,buf);
  3022. X    xlputc(fptr,'>');
  3023. X}
  3024. X
  3025. X/* putsubr - output a subr/fsubr */
  3026. XLOCAL putsubr(fptr,tag,val)
  3027. X  LVAL fptr; char *tag; LVAL val;
  3028. X{
  3029. X    sprintf(buf,"#<%s-%s: #",tag,funtab[getoffset(val)].fd_name);
  3030. X    xlputstr(fptr,buf);
  3031. X    sprintf(buf,AFMT,val); xlputstr(fptr,buf);
  3032. X    xlputc(fptr,'>');
  3033. X}
  3034. X
  3035. X/* putclosure - output a closure */
  3036. XLOCAL putclosure(fptr,val)
  3037. X  LVAL fptr,val;
  3038. X{
  3039. X    LVAL name;
  3040. X    if (name = getname(val))
  3041. X    sprintf(buf,"#<Closure-%s: #",getstring(getpname(name)));
  3042. X    else
  3043. X    strcpy(buf,"#<Closure: #");
  3044. X    xlputstr(fptr,buf);
  3045. X    sprintf(buf,AFMT,val); xlputstr(fptr,buf);
  3046. X    xlputc(fptr,'>');
  3047. X/*
  3048. X    xlputstr(fptr,"\nName:   "); xlprint(fptr,getname(val),TRUE);
  3049. X    xlputstr(fptr,"\nType:   "); xlprint(fptr,gettype(val),TRUE);
  3050. X    xlputstr(fptr,"\nLambda: "); xlprint(fptr,getlambda(val),TRUE);
  3051. X    xlputstr(fptr,"\nArgs:   "); xlprint(fptr,getargs(val),TRUE);
  3052. X    xlputstr(fptr,"\nOargs:  "); xlprint(fptr,getoargs(val),TRUE);
  3053. X    xlputstr(fptr,"\nRest:   "); xlprint(fptr,getrest(val),TRUE);
  3054. X    xlputstr(fptr,"\nKargs:  "); xlprint(fptr,getkargs(val),TRUE);
  3055. X    xlputstr(fptr,"\nAargs:  "); xlprint(fptr,getaargs(val),TRUE);
  3056. X    xlputstr(fptr,"\nBody:   "); xlprint(fptr,getbody(val),TRUE);
  3057. X    xlputstr(fptr,"\nEnv:    "); xlprint(fptr,xlgetenv(val),TRUE);
  3058. X    xlputstr(fptr,"\nFenv:   "); xlprint(fptr,getfenv(val),TRUE);
  3059. X*/
  3060. X}
  3061. X
  3062. X/* putfixnum - output a fixnum */
  3063. XLOCAL putfixnum(fptr,n)
  3064. X  LVAL fptr; FIXTYPE n;
  3065. X{
  3066. X    unsigned char *fmt;
  3067. X    LVAL val;
  3068. X    fmt = ((val = getvalue(s_ifmt)) && stringp(val) ? getstring(val)
  3069. X                            : (unsigned char *)IFMT);
  3070. X    sprintf(buf,(char *)fmt,n);
  3071. X    xlputstr(fptr,buf);
  3072. X}
  3073. X
  3074. X/* putflonum - output a flonum */
  3075. XLOCAL putflonum(fptr,n)
  3076. X  LVAL fptr; FLOTYPE n;
  3077. X{
  3078. X    unsigned char *fmt;
  3079. X    LVAL val;
  3080. X    fmt = ((val = getvalue(s_ffmt)) && stringp(val) ? getstring(val)
  3081. X                            : (unsigned char *)"%g");
  3082. X    sprintf(buf,(char *)fmt,n);
  3083. X    xlputstr(fptr,buf);
  3084. X}
  3085. X
  3086. X/* putchcode - output a character */
  3087. XLOCAL putchcode(fptr,ch,escflag)
  3088. X  LVAL fptr; int ch,escflag;
  3089. X{
  3090. X    if (escflag) {
  3091. X    switch (ch) {
  3092. X    case '\n':
  3093. X        xlputstr(fptr,"#\\Newline");
  3094. X        break;
  3095. X    case ' ':
  3096. X        xlputstr(fptr,"#\\Space");
  3097. X        break;
  3098. X    default:
  3099. X        sprintf(buf,"#\\%c",ch);
  3100. X        xlputstr(fptr,buf);
  3101. X        break;
  3102. X    }
  3103. X    }
  3104. X    else
  3105. X    xlputc(fptr,ch);
  3106. X}
  3107. X
  3108. X/* putoct - output an octal byte value */
  3109. XLOCAL putoct(fptr,n)
  3110. X  LVAL fptr; int n;
  3111. X{
  3112. X    sprintf(buf,"%03o",n);
  3113. X    xlputstr(fptr,buf);
  3114. X}
  3115. END_OF_FILE
  3116. if test 9502 -ne `wc -c <'src/xlisp/xcore/c/xlprin.c'`; then
  3117.     echo shar: \"'src/xlisp/xcore/c/xlprin.c'\" unpacked with wrong size!
  3118. fi
  3119. # end of 'src/xlisp/xcore/c/xlprin.c'
  3120. fi
  3121. echo shar: End of archive 4 \(of 16\).
  3122. cp /dev/null ark4isdone
  3123. MISSING=""
  3124. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  3125.     if test ! -f ark${I}isdone ; then
  3126.     MISSING="${MISSING} ${I}"
  3127.     fi
  3128. done
  3129. if test "${MISSING}" = "" ; then
  3130.     echo You have unpacked all 16 archives.
  3131.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3132. else
  3133.     echo You still need to unpack the following archives:
  3134.     echo "        " ${MISSING}
  3135. fi
  3136. ##  End of shell archive.
  3137. exit 0
  3138.