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

  1. Newsgroups: comp.sources.unix
  2. From: voodoo@hitl.washington.edu (Geoffery Coco)
  3. Subject: v26i190: veos-2.0 - The Virtual Environment Operating Shell, V2.0, Part07/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 190
  9. Archive-Name: veos-2.0/part07
  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 7 (of 16)."
  18. # Contents:  kernel_private/src/fern/fe_int.lsp
  19. #   kernel_private/src/talk/socket.c
  20. #   src/kernel_current/fern/fe_int.lsp src/xlisp/xcore/c/xlobj.c
  21. #   src/xlisp/xcore/c/xlstr.c
  22. # Wrapped by vixie@efficacy.home.vix.com on Sun Apr 25 23:10:38 1993
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'kernel_private/src/fern/fe_int.lsp' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'kernel_private/src/fern/fe_int.lsp'\"
  26. else
  27. echo shar: Extracting \"'kernel_private/src/fern/fe_int.lsp'\" \(16110 characters\)
  28. sed "s/^X//" >'kernel_private/src/fern/fe_int.lsp' <<'END_OF_FILE'
  29. X;;-----------------------------------------------------------
  30. X;; file: fe_int.lsp
  31. X;;
  32. X;; FERN is the Fractal Entity Relativity Node.
  33. X;; Part of the FE component of the Fern System.
  34. X;;
  35. X;; creation: March 28, 1992
  36. X;;
  37. X;; by Geoffrey P. Coco at the HITLab, Seattle
  38. X;;-----------------------------------------------------------
  39. X
  40. X
  41. X;;-----------------------------------------------------------
  42. X;; Copyright (C) 1992  Geoffrey P. Coco,
  43. X;; Human Interface Technology Lab, Seattle
  44. X;;-----------------------------------------------------------
  45. X
  46. X
  47. X;;===========================================================
  48. X;;              Internal
  49. X;;===========================================================
  50. X
  51. X(defun fe-put.int (int)
  52. X  (vput int '((~ "perc"
  53. X         @
  54. X         @
  55. X         > @) **)))
  56. X
  57. X;;-----------------------------------------------------------
  58. X
  59. X(defun fe-copy.int (&key (test-time nil))
  60. X  (car (vcopy '(("perc"
  61. X         @
  62. X         @
  63. X         > @) **)
  64. X          :test-time test-time)))
  65. X
  66. X;;-----------------------------------------------------------
  67. X
  68. X(defun fe-xtrct.int ()
  69. X  (vget '(("perc"
  70. X       @
  71. X       @
  72. X       (> @@) **))))
  73. X
  74. X;;-----------------------------------------------------------
  75. X
  76. X(defun fe-get.int ()
  77. X  (car (vput "%" '((~ "perc"
  78. X              @
  79. X              @
  80. X              > @) **))))
  81. X
  82. X;;-----------------------------------------------------------
  83. X
  84. X
  85. X
  86. X
  87. X;;-----------------------------------------------------------
  88. X;; The following functions which manipulate the locl
  89. X;; sub-partition were composed by Andy MacDonald
  90. X;;-----------------------------------------------------------
  91. X
  92. X
  93. X;;===========================================================
  94. X;;                Local
  95. X;;===========================================================
  96. X
  97. X(defun fe-put.int.locl (locl)
  98. X  (vput locl '((~ "perc"
  99. X          @2
  100. X          (> @ @2)) **)))
  101. X
  102. X;;-----------------------------------------------------------
  103. X
  104. X(defun fe-copy.int.locl (&key (test-time nil))
  105. X  (car (vcopy '(("perc"
  106. X         @2
  107. X         (> @ @2)) **)
  108. X          :test-time test-time)))
  109. X
  110. X;;-----------------------------------------------------------
  111. X
  112. X(defun fe-xtrct.int.locl ()
  113. X  (vget '(("perc"
  114. X       @2
  115. X       ((> @@) @2)) **)))
  116. X
  117. X;;-----------------------------------------------------------
  118. X
  119. X(defun fe-get.int.locl ()
  120. X  (car (vput '((~ "perc"
  121. X          @2
  122. X          (> @ @2)) **))))
  123. X
  124. X;;-----------------------------------------------------------
  125. X
  126. X
  127. X
  128. X;;===========================================================
  129. X;;               Local Objects
  130. X;;===========================================================
  131. X
  132. X(defun fe-jam.int.locl.ob (ob)
  133. X  (vput ob '((~ "perc"
  134. X        @2
  135. X        ((^ @@) @2)) **)))
  136. X  
  137. X;;-----------------------------------------------------------
  138. X
  139. X;; objects are (ob-name (attr-list))
  140. X(defun fe-put.int.locl.ob (ob)
  141. X  (cond
  142. X
  143. X   ;; assume object is already there
  144. X   ((car (vput ob `((~ "perc"
  145. X               @2
  146. X               ((> (,(car ob) @) **) @2)) **))))
  147. X
  148. X   ;; object wasn't there, insert new one
  149. X   ((fe-jam.int.locl.ob ob))
  150. X   ))
  151. X
  152. X;;-----------------------------------------------------------
  153. X
  154. X;; pass object name
  155. X(defun fe-copy.int.locl.ob (ob-name &key (test-time nil))
  156. X  (car (vcopy `(("perc"
  157. X         @2
  158. X         ((> (,ob-name @) **) @2)) **)
  159. X          :test-time test-time)))
  160. X
  161. X;;-----------------------------------------------------------
  162. X
  163. X;; pass object name, returns entire object
  164. X(defun fe-xtrct.int.locl.ob (ob-name)
  165. X  (car (vget `(("perc"
  166. X        @2
  167. X        ((> (,ob-name @) **) @2)) **))))
  168. X
  169. X;;-----------------------------------------------------------
  170. X
  171. X(defun fe-get.int.locl.ob (ob-name)
  172. X  (car (vput "%" `((~ "perc"
  173. X              @2
  174. X              (((~ ,ob-name > @) **) @2)) **))))
  175. X
  176. X;;-----------------------------------------------------------
  177. X
  178. X
  179. X
  180. X;;===========================================================
  181. X;;          Local Object - Complex
  182. X;;===========================================================
  183. X
  184. X(defun fe-copy.int.locl.ob.names ()
  185. X  (vcopy `(("perc"
  186. X        @2
  187. X        (((> @ @) **) @2)) **)
  188. X     :freq "all"))
  189. X
  190. X;;-----------------------------------------------------------
  191. X
  192. X
  193. X
  194. X
  195. X;;===========================================================
  196. X;;          Local Object Attributes
  197. X;;===========================================================
  198. X
  199. X(defun fe-jam.int.locl.ob.attr (ob-name attr)
  200. X  (cond
  201. X   ;; assume object exists, add new attr
  202. X   ((vput attr `((~ "perc"
  203. X            @2
  204. X            (((~ ,ob-name (^ @@)) **) @2)) **)))
  205. X
  206. X   ;; object didn't exist, add new object with new attr.
  207. X   ((fe-jam.int.locl.ob `(,ob-name (,attr))))
  208. X   ))
  209. X
  210. X;;-----------------------------------------------------------
  211. X
  212. X(defun fe-put.int.locl.ob.attr (ob-name attr)
  213. X  (cond
  214. X   
  215. X   ;; assume the object and attr exist, swap in new attr
  216. X   ((car (vput attr `((~ "perc"
  217. X             @2
  218. X             (((~ ,ob-name (> (,(car attr) @) **)) **) @2)) **))))
  219. X    
  220. X   ;; attr didn't exist, add new attr
  221. X   ((fe-jam.int.locl.ob.attr ob-name attr))
  222. X   ))
  223. X
  224. X;;-----------------------------------------------------------
  225. X
  226. X(defun fe-xtrct.int.locl.ob.attr (ob-name attr-name)
  227. X  (car (vget `(("perc"
  228. X        @2
  229. X        (((,ob-name (> (,attr-name @) **)) **) @2)) **))))
  230. X
  231. X;;-----------------------------------------------------------
  232. X
  233. X(defun fe-get.int.locl.ob.attr (ob-name attr-name)
  234. X  (car (vput "%" `((~ "perc"
  235. X              @2
  236. X              (((~ ,ob-name ((~ ,attr-name > @) **)) **) @2)) **))))
  237. X
  238. X;;-----------------------------------------------------------
  239. X
  240. X;; returns attr struct
  241. X(defun fe-copy.int.locl.ob.attr (ob-name attr-name &key (test-time nil))
  242. X  (car (vcopy `(("perc"
  243. X         @2
  244. X         (((,ob-name (> (,attr-name @) **)) **) @2)) **)
  245. X          :test-time test-time)))
  246. X  
  247. X;;-----------------------------------------------------------
  248. X
  249. X
  250. X
  251. X;;===========================================================
  252. X;;         Local Object Attributes - Complex
  253. X;;===========================================================
  254. X
  255. X;; returns list of boundary attribute names
  256. X(defun fe-copy.int.locl.ob.attr.names (ob-name)
  257. X  (vcopy `(("perc"
  258. X        @2
  259. X        (((,ob-name ((> @ @) **)) **) @2)) **)
  260. X     :freq "all"))
  261. X
  262. X;;-----------------------------------------------------------
  263. X
  264. X;; returns attr val
  265. X(defun fe-copy.int.locl.ob.attr.val (ob-name attr-name)
  266. X  (car (vcopy `(("perc"
  267. X         @2
  268. X         (((,ob-name ((,attr-name > @) **)) **) @2)) **))))
  269. X  
  270. X;;-----------------------------------------------------------
  271. X
  272. X
  273. X
  274. X;;===========================================================
  275. X;;              Sublings
  276. X;;===========================================================
  277. X
  278. X(defun fe-put.int.subs (subs)
  279. X  (vput subs '((~ "perc"
  280. X          @2
  281. X          (@ > @ @)) **)))
  282. X
  283. X;;-----------------------------------------------------------
  284. X
  285. X;; cache this frequently used pattern in C level fern.
  286. X;; later, calls to fe-copy.int.subs use precomputed pattern.
  287. X
  288. X(fbase-init-copy.int.subs '(("perc"
  289. X                 @2
  290. X                 (@ > @ @)) **))
  291. X
  292. X#|
  293. X(defun fe-copy.int.subs (&key (test-time nil))
  294. X  (car (vcopy '(("perc"
  295. X         @2
  296. X         (@ > @ @)) **)
  297. X          :test-time test-time)))
  298. X|#
  299. X;;-----------------------------------------------------------
  300. X
  301. X(defun fe-xtrct.int.subs ()
  302. X  (vget '(("perc"
  303. X       @2
  304. X       (@ (> @@) @)) **)))
  305. X
  306. X;;-----------------------------------------------------------
  307. X
  308. X(defun fe-get.int.subs ()
  309. X  (car (vput "%" '((~ "perc"
  310. X              @2
  311. X              (@ > @ @)) **))))
  312. X
  313. X;;-----------------------------------------------------------
  314. X
  315. X
  316. X;;===========================================================
  317. X;;              Sublings Entities
  318. X;;===========================================================
  319. X
  320. X(defun fe-jam.int.subs.ent (ent)
  321. X  (vput ent '((~ "perc"
  322. X         @2
  323. X         (@ (^ @@) @)) **)))
  324. X
  325. X;;-----------------------------------------------------------
  326. X
  327. X;; an ent is: (uid (ob-list))
  328. X(defun fe-put.int.subs.ent (ent)
  329. X  (cond
  330. X
  331. X   ;; assume the ent exists, swap in the new ent
  332. X   ((car (vput ent `((~ "perc"
  333. X            @2
  334. X            (@ (> (,(car ent) @) **) @)
  335. X            ) **))))
  336. X
  337. X   ;; ent didn't exist, insert new ent
  338. X   ((fe-jam.int.subs.ent ent))
  339. X   ))
  340. X              
  341. X;;-----------------------------------------------------------
  342. X
  343. X(defun fe-copy.int.subs.ent (uid &key (test-time nil))
  344. X  (car (vcopy `(("perc"
  345. X         @2
  346. X         (@ (> (,uid @) **) @)
  347. X         ) **)
  348. X          :test-time test-time)))
  349. X
  350. X;;-----------------------------------------------------------
  351. X
  352. X(defun fe-xtrct.int.subs.ent (uid)
  353. X  (car (vget `(("perc"
  354. X        @2
  355. X        (@ (> (,uid @) **) @)
  356. X        ) **))))
  357. X
  358. X;;-----------------------------------------------------------
  359. X
  360. X(defun fe-get.int.subs.ent (uid)
  361. X  (car (vput "%" `((~ "perc"
  362. X              @2
  363. X              (@ ((~ ,uid > @) **) @)
  364. X              ) **))))
  365. X
  366. X;;-----------------------------------------------------------
  367. X
  368. X
  369. X
  370. X;;===========================================================
  371. X;;         Sublings Entities - Complex
  372. X;;===========================================================
  373. X
  374. X(defun fe-copy.int.subs.uids ()
  375. X  (vcopy '(("perc"
  376. X        @2
  377. X        (@ ((> @ @) **) @)
  378. X        ) **)
  379. X     :freq "all"))
  380. X
  381. X;;-----------------------------------------------------------
  382. X
  383. X
  384. X
  385. X
  386. X;;===========================================================
  387. X;;          Sublings Entities Objects
  388. X;;===========================================================
  389. X
  390. X
  391. X(defun fe-jam.int.subs.ent.ob (uid ob)
  392. X  (cond
  393. X
  394. X   ;; assume entity exists, insert new object
  395. X   ((vput ob `((~ "perc"
  396. X          @2
  397. X          (@ ((~ ,uid (^ @@)) **) @)
  398. X          ) **)))
  399. X
  400. X   ;; entity wasn't there, insert new entity with new object
  401. X   ((fe-jam.int.subs.ent `(,uid (,ob))))
  402. X   ))
  403. X   
  404. X;;-----------------------------------------------------------
  405. X
  406. X;; ob is a normal object structure: (name (attr-list))
  407. X(defun fe-put.int.subs.ent.ob (uid ob)
  408. X  (cond
  409. X
  410. X   ;; assume entity and object exist, swap in new object
  411. X   ((car (vput ob `((~ "perc"
  412. X               @2               
  413. X               (@ ((~ ,uid (> (,(car ob) @) **)) **) @)
  414. X               ) **))))
  415. X   
  416. X   ;; object wasn't there, assume entity exists, insert new object
  417. X   ((fe-jam.int.subs.ent.ob uid ob))
  418. X   ))
  419. X   
  420. X;;-----------------------------------------------------------
  421. X
  422. X(defun fe-copy.int.subs.ent.ob (uid ob-name &key (test-time nil))
  423. X  (car (vcopy `(("perc"
  424. X         @2
  425. X         (@ ((,uid (> (,ob-name @) **)) **) @)
  426. X         ) **)
  427. X          :test-time test-time)))
  428. X
  429. X;;-----------------------------------------------------------
  430. X
  431. X(defun fe-xtrct.int.subs.ent.ob (uid ob-name)
  432. X  (car (vget `(("perc"
  433. X        @2
  434. X        (@ ((,uid (> (,ob-name @) **)) **) @)
  435. X        ) **))))
  436. X
  437. X;;-----------------------------------------------------------
  438. X
  439. X(defun fe-get.int.subs.ent.ob (uid ob-name)
  440. X  (car (vput "%" `((~ "perc"
  441. X              @2
  442. X              (@ ((~ ,uid ((~ ,ob-name > @) **)) **) @)
  443. X              ) **))))
  444. X
  445. X;;-----------------------------------------------------------
  446. X
  447. X
  448. X
  449. X;;===========================================================
  450. X;;         Subling Entities Objects - Complex
  451. X;;===========================================================
  452. X
  453. X;; pass uid, get list of it's ob names
  454. X(defun fe-copy.int.subs.ent.ob.names (uid)
  455. X  (vcopy `(("perc"
  456. X        @2
  457. X        (@ ((,uid ((> @ @) **)) **) @)
  458. X        ) **)
  459. X     :freq "all"))
  460. X
  461. X;;-----------------------------------------------------------
  462. X
  463. X
  464. X
  465. X
  466. X;;===========================================================
  467. X;;         Subling Entities Objects Attributes
  468. X;;===========================================================
  469. X
  470. X
  471. X(defun fe-jam.int.subs.ent.ob.attr (uid ob-name attr)
  472. X  (cond
  473. X   ;; assume entity and ob exists, insert new attr
  474. X   ((vput attr `((~ "perc"
  475. X            @2
  476. X            (@
  477. X             ((~ ,uid ((~ ,ob-name (^ @@)) **)) **)
  478. X             @)
  479. X            ) **)))
  480. X  
  481. X   ;; ob wasn't there, insert new ob with new attr
  482. X   ((fe-jam.int.subs.ent.ob uid `(,ob-name (,attr))))
  483. X   ))
  484. X
  485. X;;-----------------------------------------------------------
  486. X
  487. X;; attr is ("attr-name" attr-val)
  488. X(defun fe-put.int.subs.ent.ob.attr (uid ob-name attr)
  489. X  (cond
  490. X   ;; assume the ent, ob and attr exist, swap in new attr
  491. X   ((car (vput attr `((~ "perc"
  492. X             @2
  493. X             (@ 
  494. X              ((~ ,uid ((~ ,ob-name (> (,(car attr) @) **)) **)) **)
  495. X              @)
  496. X             ) **))))
  497. X
  498. X   ;; attr wasn't there, insert new attr
  499. X   ((fe-jam.int.subs.ent.ob.attr uid ob-name attr))
  500. X   ))
  501. X   
  502. X;;-----------------------------------------------------------
  503. X
  504. X;; pass uid, ob-num, attr-name
  505. X(defun fe-copy.int.subs.ent.ob.attr (uid ob-num attr-name &key (test-time nil))
  506. X  (car (vcopy `(("perc"
  507. X         @2
  508. X         (@
  509. X          ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  510. X          @)
  511. X         ) **)
  512. X          :test-time test-time)))
  513. X
  514. X;;-----------------------------------------------------------
  515. X
  516. X;; pass uid, ob-num, attr-name
  517. X(defun fe-xtrct.int.subs.ent.ob.attr (uid ob-num attr-name)
  518. X  (car (vget `(("perc"
  519. X        @2
  520. X        (@
  521. X         ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  522. X         @)
  523. X        ) **))))
  524. X
  525. X;;-----------------------------------------------------------
  526. X
  527. X;; pass uid, ob-num, attr-name
  528. X(defun fe-get.int.subs.ent.ob.attr (uid ob-num attr-name)
  529. X  (car (vput "%" `((~ "perc"
  530. X              @2
  531. X              (@
  532. X               ((~ ,uid ((~ ,ob-num ((~ ,attr-name > @) **)) **)) **)
  533. X               @)
  534. X              ) **))))
  535. X
  536. X;;-----------------------------------------------------------
  537. X
  538. X
  539. X
  540. X;;===========================================================
  541. X;;    Subling Entities Objects Attributes - Complex
  542. X;;===========================================================
  543. X
  544. X;; pass uid and ob, return attr-list
  545. X(defun fe-copy.int.subs.ent.ob.attr.names (uid ob-name)
  546. X  (vcopy `(("perc"
  547. X        @2
  548. X        (@
  549. X         ((,uid ((,ob-name ((> @ @) **)) **)) **)
  550. X         @)
  551. X        ) **)
  552. X     :freq "all"))
  553. X
  554. X;;-----------------------------------------------------------
  555. X
  556. X;; pass attr, return values of all objects of all sibs
  557. X(defun fe-copy.int.subs.attr.vals (attr-name)
  558. X  (vcopy `(("perc"
  559. X        @2
  560. X        (@
  561. X         ((@ ((@ ((,attr-name > @) **)) **)) **)
  562. X         @)
  563. X        ) **)
  564. X     :freq "all"))
  565. X
  566. X;;-----------------------------------------------------------
  567. X
  568. X;; pass uid, ob-num, attr-name
  569. X(defun fe-copy.int.subs.ent.ob.attr.val (uid ob-num attr-name)
  570. X  (car (vcopy `(("perc"
  571. X         @2
  572. X         (@
  573. X          ((,uid ((,ob-num ((,attr-name > @) **)) **)) **)
  574. X          @)
  575. X         ) **))))
  576. X
  577. X;;-----------------------------------------------------------
  578. X
  579. X
  580. X
  581. X
  582. X
  583. X;;===========================================================
  584. X;;               Filters
  585. X;;===========================================================
  586. X
  587. X(defun fe-put.int.fltrs (fltr)
  588. X  (vput fltr '((~ "perc"
  589. X          @2
  590. X          (@2 > @)) **)))
  591. X
  592. X;;-----------------------------------------------------------
  593. X
  594. X(defun fe-copy.int.fltrs (&key (test-time nil))
  595. X  (car (vcopy '(("perc"
  596. X         @2
  597. X         (@2 > @)) **)
  598. X          :test-time test-time)))
  599. X
  600. X;;-----------------------------------------------------------
  601. X
  602. X(defun fe-xtrct.int.fltrs ()
  603. X  (vget '(("perc"
  604. X       @2
  605. X       (@2 (> @@))) **)))
  606. X
  607. X;;-----------------------------------------------------------
  608. X
  609. X(defun fe-get.int.fltrs ()
  610. X  (car (vput "%" '((~ "perc"
  611. X              @2
  612. X              (@2 > @)) **))))
  613. X
  614. X;;-----------------------------------------------------------
  615. X
  616. X
  617. X
  618. X;;===========================================================
  619. X;;               Fltrs Entities
  620. X;;===========================================================
  621. X
  622. X(defun fe-jam.int.fltrs.ent (ent)
  623. X  (vput ent '((~ "perc"
  624. X         @2
  625. X         (@2 (^ @@))) **)))
  626. X
  627. X;;-----------------------------------------------------------
  628. X
  629. X;; an ent is: (uid (ob-list))
  630. X(defun fe-put.int.fltrs.ent (ent)
  631. X  (cond
  632. X
  633. X   ;; assume the ent exists, swap in the new ent
  634. X   ((car (vput ent `((~ "perc"
  635. X            @2
  636. X            (@2 (> (,(car ent) @) **))
  637. X            ) **))))
  638. X
  639. X   ;; ent didn't exist, insert new ent
  640. X   ((fe-jam.int.fltrs.ent ent))
  641. X   ))
  642. X              
  643. X;;-----------------------------------------------------------
  644. X
  645. X(defun fe-copy.int.fltrs.ent (uid &key (test-time nil))
  646. X  (car (vcopy `(("perc"
  647. X         @2
  648. X         (@2 (> (,uid @) **))
  649. X         ) **)
  650. X          :test-time test-time)))
  651. X
  652. X;;-----------------------------------------------------------
  653. X
  654. X(defun fe-xtrct.int.fltrs.ent (uid)
  655. X  (car (vget `(("perc"
  656. X        @2
  657. X        (@2 (> (,uid @) **))
  658. X        ) **))))
  659. X
  660. X;;-----------------------------------------------------------
  661. X
  662. X(defun fe-get.int.fltrs.ent (uid)
  663. X  (car (vput "%" `((~ "perc"
  664. X              @2
  665. X              (@2 ((~ ,uid > @) **))
  666. X              ) **))))
  667. X
  668. X;;-----------------------------------------------------------
  669. X
  670. X
  671. X
  672. X
  673. X;;===========================================================
  674. X;;          Internal Entity Filter Processing
  675. X;;===========================================================
  676. X
  677. X
  678. X;;-----------------------------------------------------------
  679. X
  680. X(defun fe-fltr.int.subs (uid &key (test-time nil))
  681. X  (delete uid
  682. X      (fe-copy.int.subs :test-time test-time)
  683. X      :test (lambda (x y) (equal x (car y)))))
  684. X  
  685. X;;-----------------------------------------------------------
  686. X
  687. X(defun fe-fltr.int.subs.uids (uid)
  688. X  (delete uid 
  689. X      (fe-copy.int.subs.uids)
  690. X      :test 'equal))
  691. X  
  692. X;;-----------------------------------------------------------
  693. X
  694. X
  695. X
  696. X
  697. END_OF_FILE
  698. if test 16110 -ne `wc -c <'kernel_private/src/fern/fe_int.lsp'`; then
  699.     echo shar: \"'kernel_private/src/fern/fe_int.lsp'\" unpacked with wrong size!
  700. fi
  701. # end of 'kernel_private/src/fern/fe_int.lsp'
  702. fi
  703. if test -f 'kernel_private/src/talk/socket.c' -a "${1}" != "-c" ; then 
  704.   echo shar: Will not clobber existing file \"'kernel_private/src/talk/socket.c'\"
  705. else
  706. echo shar: Extracting \"'kernel_private/src/talk/socket.c'\" \(16709 characters\)
  707. sed "s/^X//" >'kernel_private/src/talk/socket.c' <<'END_OF_FILE'
  708. X/****************************************************************************************
  709. X *                                            *
  710. X * file: socket.c                                                *
  711. X *                                            *
  712. X * November 14, 1990: The network and transport layer for inter-entity message passing    *
  713. X *               library, 'talk' for the VEOS project.                             *
  714. X *                                            *
  715. X * by Geoffrey P. Coco at the HITLab, Seattle.                          *
  716. X * these functions are based on BSD socket code by Dan Pezely.                       *
  717. X *                                            *
  718. X ****************************************************************************************/
  719. X
  720. X/****************************************************************************************
  721. X * Copyright (C) 1992  Geoffrey P. Coco, Human Interface Technology Lab, Seattle    *
  722. X ****************************************************************************************/
  723. X
  724. X
  725. X
  726. X/****************************************************************************************
  727. X *                      include the papa include file                */
  728. X
  729. X#include "kernel.h"
  730. X
  731. X#include <sys/types.h>
  732. X#include <sys/socket.h>
  733. X#include <netinet/in.h>
  734. X#include <netinet/tcp.h>
  735. X#include <netdb.h>            /* for get_*_byname() */
  736. X#include <stropts.h>            /* ioctl() streamio */
  737. X#include <fcntl.h>
  738. X#include "signal.h"
  739. X
  740. X/****************************************************************************************/
  741. X
  742. X
  743. X
  744. X/****************************************************************************************
  745. X *                     forward function declarations                */
  746. X
  747. XTVeosErr Sock_Connect();
  748. XTVeosErr Sock_Listen();
  749. XTVeosErr Sock_ReadSelect();
  750. XTVeosErr Sock_WriteSelect();
  751. XTVeosErr Sock_Accept();
  752. XTVeosErr Sock_Transmit();
  753. XTVeosErr Sock_Receive();
  754. XTVeosErr Sock_Close();
  755. X
  756. X/****************************************************************************************/
  757. X
  758. X
  759. X
  760. X/****************************************************************************************
  761. X *                     local function declarations                */
  762. X
  763. XTVeosErr Sock_MixItUp();
  764. XTVeosErr Sock_ResolveHost();
  765. Xu_long Sock_ConvertAddr();
  766. X
  767. X/****************************************************************************************/
  768. X
  769. X
  770. X
  771. X
  772. X/****************************************************************************************/
  773. XTVeosErr Sock_Connect(iSocketFD, pUid, sProtocolName)
  774. X    int         *iSocketFD;
  775. X    TPUid        pUid;
  776. X    char         *sProtocolName;
  777. X{
  778. X    struct sockaddr_in  socketName;
  779. X    TVeosErr        iErr;
  780. X    int            iProto, iOption, iBufSize;
  781. X    
  782. X
  783. X    /** translate given network params into useable form **/
  784. X
  785. X    iErr = Sock_MixItUp(&pUid->iPort, sProtocolName, &iProto);
  786. X    if (iErr == VEOS_SUCCESS) {
  787. X
  788. X
  789. X    /** copy the address of the receiving host **/
  790. X
  791. X    socketName.sin_addr.s_addr = pUid->lHost;
  792. X
  793. X        
  794. X    /** create socket with specified protocol **/
  795. X    
  796. X    socketName.sin_family = AF_INET;
  797. X    socketName.sin_port = htons(pUid->iPort);
  798. X    
  799. X    *iSocketFD = socket(socketName.sin_family, SOCK_STREAM, iProto);
  800. X    
  801. X    if (*iSocketFD == TALK_BOGUS_FD)
  802. X        iErr = TALK_CREATE;
  803. X    
  804. X    else {
  805. X        
  806. X        
  807. X        /** attempt to connect to given address **/
  808. X        
  809. X        if (connect(*iSocketFD, &socketName, sizeof(socketName)) < 0)
  810. X        
  811. X        iErr = TALK_CONNECT;
  812. X        
  813. X        
  814. X        else {
  815. X/*
  816. X        iBufSize = 16384;
  817. X        if (setsockopt(*iSocketFD, SOL_SOCKET, SO_SNDBUF,
  818. X                   (char *) &iBufSize, sizeof(int)) < 0)
  819. X            iErr = TALK_FLAGS;
  820. X*/            
  821. X        iOption = TRUE;
  822. X        if (setsockopt(*iSocketFD, IPPROTO_TCP, TCP_NODELAY,
  823. X                   &iOption, sizeof(int)) == -1)
  824. X            iErr = TALK_FLAGS;
  825. X
  826. X        /** set non-blocking write bit **/
  827. X        
  828. X        fcntl(*iSocketFD, F_SETFL, FNDELAY);
  829. X        
  830. X        FD_SET(*iSocketFD, &OPEN_WRITE_SOCKETS);
  831. X        }
  832. X        
  833. X        if (iErr != VEOS_SUCCESS)
  834. X        Sock_Close(iSocketFD);
  835. X        }
  836. X    }
  837. X
  838. X    return(iErr);
  839. X
  840. X    } /* Sock_Connect */
  841. X/****************************************************************************************/
  842. X
  843. X
  844. X
  845. X
  846. X/****************************************************************************************/
  847. XTVeosErr Sock_Listen(iSocketFD, iPortNumber, sProtocolName, iAttitude)
  848. X    int         *iSocketFD;
  849. X    int         iPortNumber;
  850. X    char         *sProtocolName;
  851. X    int            iAttitude;
  852. X{
  853. X    struct sockaddr_in  socketName;
  854. X    TVeosErr        iErr;
  855. X    int            iProto, iOption;
  856. X    int            iZoot;
  857. X
  858. X    iErr = Sock_MixItUp(&iPortNumber, sProtocolName, &iProto);
  859. X    if (iErr == VEOS_SUCCESS) {
  860. X
  861. X
  862. X
  863. X    /** create socket with specified protocol **/
  864. X
  865. X    socketName.sin_family = AF_INET;   /* specify socket to be of INTERNET family */
  866. X
  867. X    *iSocketFD = socket(socketName.sin_family, SOCK_STREAM, iProto);
  868. X
  869. X    if (*iSocketFD == TALK_BOGUS_FD)
  870. X        iErr = TALK_CREATE;
  871. X
  872. X    else {
  873. X        socketName.sin_addr.s_addr = htonl(INADDR_ANY);
  874. X        socketName.sin_port = htons(iPortNumber);
  875. X        
  876. X        if (iAttitude == TALK_AGRESSIVE) {
  877. X        iOption = TRUE;
  878. X        if (setsockopt(*iSocketFD, SOL_SOCKET, SO_REUSEADDR,
  879. X                   &iOption, sizeof(int)) == -1)
  880. X            iErr = TALK_FLAGS;
  881. X        }
  882. X        
  883. X        if (iErr == VEOS_SUCCESS) {
  884. X        
  885. X        /** register this socket with system for us **/
  886. X        
  887. X        if (bind(*iSocketFD, &socketName, sizeof(socketName)) < 0) {
  888. X            
  889. X            iErr = TALK_BIND;
  890. X            }
  891. X        
  892. X        else {
  893. X            /** listen on the socket **/
  894. X            
  895. X            if (listen(*iSocketFD, TALK_QUEUE_SIZE ) < 0)
  896. X            iErr = TALK_LISTEN;
  897. X            
  898. X            else {
  899. X            /** have this socket generate an interrupt
  900. X             ** when another entity connects.
  901. X             **/
  902. X/*
  903. X            fcntl(*iSocketFD, F_SETOWN, getpid());
  904. X            fcntl(*iSocketFD, F_SETFL, FASYNC);
  905. X*/            
  906. X            FD_SET(*iSocketFD, &OPEN_READ_SOCKETS);
  907. X            }
  908. X            }
  909. X        }        
  910. X        }
  911. X    if (iErr != VEOS_SUCCESS) {
  912. X        
  913. X        Sock_Close(iSocketFD);
  914. X        *iSocketFD = TALK_BOGUS_FD;
  915. X        }
  916. X    }
  917. X
  918. X    return(iErr);
  919. X    
  920. X    } /* Sock_Listen */
  921. X/****************************************************************************************/
  922. X
  923. X
  924. X
  925. X
  926. X/****************************************************************************************/
  927. XTVeosErr Sock_ReadSelect(iSocketFD)
  928. X    int        iSocketFD;
  929. X{
  930. X    struct timeval      timeVal;
  931. X    fd_set          tempFDSet;
  932. X    int         iSize;
  933. X    TVeosErr        iErr;
  934. X    
  935. X    
  936. X    iErr = VEOS_SUCCESS;
  937. X    
  938. X    
  939. X    /** create a local copy of the fd_set since it gets modified by select() **/
  940. X    
  941. X    bcopy((char*) &OPEN_READ_SOCKETS, (char*) &tempFDSet, sizeof(fd_set));
  942. X    
  943. X    
  944. X    
  945. X    /** some implementations of select() might modify timeVal, so we    **
  946. X     ** must keep resetting it rather then making it global or static.    **/
  947. X    
  948. X    timeVal.tv_sec = 0;
  949. X    timeVal.tv_usec = 0;
  950. X    
  951. X    iSize = select(FD_SETSIZE, &tempFDSet, nil, nil, &timeVal);
  952. X    
  953. X    if (iSize <  0)
  954. X    iErr = TALK_SELECT;
  955. X    
  956. X    else if (iSize == 0)
  957. X    iErr = TALK_SELECT_TIMEOUT;
  958. X    
  959. X    else if (!FD_ISSET(iSocketFD, &tempFDSet))
  960. X    iErr = TALK_NOCONN;
  961. X    
  962. X    
  963. X    return(iErr);
  964. X    
  965. X    } /* Sock_ReadSelect */
  966. X/****************************************************************************************/
  967. X
  968. X
  969. X
  970. X
  971. X/****************************************************************************************
  972. X * Sock_ReadSelect                                    */
  973. X
  974. XTVeosErr Sock_WriteSelect(iSocketFD)
  975. X     int        iSocketFD;
  976. X{
  977. X    struct timeval      timeVal;
  978. X    fd_set          tempFDSet;
  979. X    int         iSize;
  980. X    TVeosErr        iErr;
  981. X    
  982. X    
  983. X    iErr = VEOS_SUCCESS;
  984. X    
  985. X    
  986. X    /** create a local copy of the fd_set since it gets modified by select() **/
  987. X    
  988. X    bcopy((char*) &OPEN_WRITE_SOCKETS, (char*) &tempFDSet, sizeof(fd_set));
  989. X    
  990. X    
  991. X    
  992. X    /** some implementations of select() might modify timeVal, so we    **
  993. X     ** must keep resetting it rather then making it global or static.    **/
  994. X    
  995. X    timeVal.tv_sec = 0;
  996. X    timeVal.tv_usec = 0;
  997. X    
  998. X    iSize = select(FD_SETSIZE, nil, &tempFDSet, nil, &timeVal);
  999. X    
  1000. X    if (TRAP_FLAGS & 0x00000001 << SIGPIPE) {
  1001. X    TRAP_FLAGS = TRAP_FLAGS & ~(0x00000001 << SIGPIPE);
  1002. X    TERMINATE = FALSE;
  1003. X    iErr = TALK_CONN_CLOSED;
  1004. X    }
  1005. X
  1006. X    else if (iSize <  0)
  1007. X    iErr = TALK_SELECT;
  1008. X    
  1009. X    else if (iSize == 0)
  1010. X    iErr = TALK_SELECT_TIMEOUT;
  1011. X    
  1012. X    else if (!FD_ISSET(iSocketFD, &tempFDSet))
  1013. X    iErr = TALK_NOCONN;
  1014. X    
  1015. X    
  1016. X    return(iErr);
  1017. X    
  1018. X    } /* Sock_WriteSelect */
  1019. X/****************************************************************************************/
  1020. X
  1021. X
  1022. X
  1023. X
  1024. X/****************************************************************************************
  1025. X * Sock_Accept                                        */
  1026. X
  1027. XTVeosErr Sock_Accept(iSocketFD, iSocketIOFD)
  1028. X    int         iSocketFD;
  1029. X    int         *iSocketIOFD;
  1030. X{
  1031. X    TVeosErr        iErr;
  1032. X    int            iBufSize;
  1033. X
  1034. X    iErr = TALK_ACCEPT;
  1035. X    
  1036. X    *iSocketIOFD = accept(iSocketFD, nil, nil);
  1037. X    if (*iSocketIOFD >= 0) {
  1038. X
  1039. X        /** setup socket for large buffers and non-blocking reading **/
  1040. X/*
  1041. X    iBufSize = 16384;
  1042. X    if (setsockopt(*iSocketIOFD, SOL_SOCKET, SO_RCVBUF,
  1043. X               (char *) &iBufSize, sizeof(int)) < 0 ||
  1044. X*/
  1045. X    /** convert msgsock to streams message-nondiscard-mode **/
  1046. X
  1047. X    if (fcntl(*iSocketIOFD, F_SETFL, FNDELAY) == -1)
  1048. X        Sock_Close(iSocketIOFD);
  1049. X
  1050. X    else {
  1051. X        FD_SET(*iSocketIOFD, &OPEN_READ_SOCKETS);
  1052. X        iErr = VEOS_SUCCESS;
  1053. X        }
  1054. X    }
  1055. X
  1056. X    return(iErr);
  1057. X    
  1058. X} /* Sock_Accept */
  1059. X/****************************************************************************************/
  1060. X
  1061. X
  1062. X
  1063. X
  1064. X/****************************************************************************************
  1065. X * Sock_Transmit                                        */
  1066. X
  1067. XTVeosErr Sock_Transmit(iSocketFD, sMessage, pLen)
  1068. X    int            iSocketFD;
  1069. X    char        *sMessage;
  1070. X    int            *pLen;
  1071. X{    
  1072. X    int            iNetAction;
  1073. X    TVeosErr        iErr;
  1074. X    boolean        bTrap;
  1075. X
  1076. X    iErr = VEOS_FAILURE;    
  1077. X    
  1078. X
  1079. X    /** send the string to the given socket destination **/
  1080. X    
  1081. X    iNetAction = write(iSocketFD, sMessage, *pLen);
  1082. X
  1083. X    CATCH_TRAP(SIGPIPE, bTrap);
  1084. X    if (bTrap)
  1085. X    iErr = TALK_CONN_CLOSED;
  1086. X
  1087. X
  1088. X    else if (iNetAction < 0) {
  1089. X
  1090. X    /** expected result when can't write **/
  1091. X
  1092. X    if (errno == EAGAIN || errno == EWOULDBLOCK)        
  1093. X        iErr = TALK_SPEAK_BLOCKED;
  1094. X
  1095. X    else
  1096. X        perror("shell: write");
  1097. X        }
  1098. X
  1099. X    else if (iNetAction > 0) {
  1100. X
  1101. X    *pLen = iNetAction;
  1102. X    iErr = VEOS_SUCCESS;
  1103. X    }
  1104. X
  1105. X    return(iErr);
  1106. X
  1107. X    } /* Sock_Transmit */
  1108. X/****************************************************************************************/
  1109. X
  1110. X
  1111. X
  1112. X
  1113. X/****************************************************************************************
  1114. X * Sock_Receive                                            */
  1115. X
  1116. XTVeosErr Sock_Receive(iSocketFD, sBuffer, iBufferSize)
  1117. X    int            iSocketFD;
  1118. X    char        *sBuffer;
  1119. X    int            *iBufferSize;
  1120. X{
  1121. X    TVeosErr            iErr;
  1122. X    int            iNetAction;
  1123. X
  1124. X
  1125. X    iErr = VEOS_FAILURE;                /* pessimism */
  1126. X
  1127. X
  1128. X    /** look for unread data in socket **/
  1129. X
  1130. X    iNetAction = read(iSocketFD, sBuffer, *iBufferSize);
  1131. X
  1132. X
  1133. X
  1134. X    /** connection still open, but no data **/
  1135. X
  1136. X    if (iNetAction < 0) {
  1137. X
  1138. X    /** expected result when no data **/
  1139. X
  1140. X    if (errno == EAGAIN || errno == EWOULDBLOCK)        
  1141. X        iErr = TALK_LISTEN_BLOCKED;
  1142. X
  1143. X    else
  1144. X        perror("shell: read");
  1145. X        }
  1146. X
  1147. X
  1148. X    /** there was some data in the socket **/
  1149. X
  1150. X    else if (iNetAction > 0) {
  1151. X
  1152. X    iErr = VEOS_SUCCESS;
  1153. X    *iBufferSize = iNetAction;
  1154. X    }
  1155. X
  1156. X
  1157. X    /** conneciton closed from other end **/
  1158. X
  1159. X    else
  1160. X        iErr = TALK_CONN_CLOSED;
  1161. X
  1162. X
  1163. X    return(iErr);
  1164. X
  1165. X    } /* Sock_Receive */
  1166. X/****************************************************************************************/
  1167. X
  1168. X
  1169. X
  1170. X
  1171. X/****************************************************************************************
  1172. X ** Inet Socket Close
  1173. X **
  1174. X ** usage:  status = Sock_Close( &socketFD );
  1175. X ** params: pointer to file descriptor of socket
  1176. X ** returns: VEOS_SUCCESS or TALK_CLOSE
  1177. X **/
  1178. X
  1179. XTVeosErr Sock_Close(iSocketFD)
  1180. X    int           *iSocketFD;
  1181. X{
  1182. X    TVeosErr    iErr;
  1183. X    
  1184. X    iErr = VEOS_SUCCESS;    
  1185. X
  1186. X
  1187. X    if (*iSocketFD != TALK_BOGUS_FD) {
  1188. X    
  1189. X    FD_CLR(*iSocketFD, &OPEN_WRITE_SOCKETS);
  1190. X    FD_CLR(*iSocketFD, &OPEN_READ_SOCKETS);
  1191. X
  1192. X    shutdown(*iSocketFD, 2);
  1193. X
  1194. X    if (close(*iSocketFD) == -1)
  1195. X        iErr = TALK_CLOSE;
  1196. X
  1197. X    else
  1198. X        *iSocketFD = TALK_BOGUS_FD;
  1199. X    }
  1200. X
  1201. X    return(iErr);
  1202. X
  1203. X} /* Sock_Close */
  1204. X/****************************************************************************************/
  1205. X
  1206. X
  1207. X
  1208. X
  1209. X/****************************************************************************************
  1210. X *                           local routines                    *
  1211. X ****************************************************************************************/
  1212. X
  1213. X
  1214. X
  1215. X/****************************************************************************************
  1216. X * Sock_MixItUp                                        */
  1217. X
  1218. XTVeosErr Sock_MixItUp(iPortNumber, sProtocolName, iProto)
  1219. X    char        *sProtocolName;
  1220. X    int            *iPortNumber, *iProto;
  1221. X{
  1222. X    struct protoent     *protocolInfo, *getprotobyname();
  1223. X    TVeosErr        iErr;
  1224. X
  1225. X    iErr = VEOS_FAILURE;
  1226. X
  1227. X    if (*iPortNumber > 0) {
  1228. X
  1229. X    protocolInfo = getprotobyname(sProtocolName);
  1230. X    if (protocolInfo == nil)
  1231. X        iErr = TALK_PROTOCOL;
  1232. X
  1233. X    else {
  1234. X        *iProto = protocolInfo->p_proto;
  1235. X        iErr = VEOS_SUCCESS;
  1236. X        }
  1237. X    }
  1238. X
  1239. X    return(iErr);
  1240. X
  1241. X    } /* Sock_MixItUp */
  1242. X/****************************************************************************************/
  1243. X
  1244. X
  1245. X
  1246. X
  1247. X/****************************************************************************************/
  1248. XTVeosErr Sock_ResolveHost(sHostName, pIpAddr)
  1249. X    char        *sHostName;
  1250. X    u_long        *pIpAddr;
  1251. X{
  1252. X    TVeosErr        iErr;
  1253. X
  1254. X
  1255. X    /** host address may already be in internet form **/
  1256. X
  1257. X    if (isdigit(sHostName[0]))
  1258. X    iErr = Sock_StrAddr2IP(sHostName, pIpAddr);
  1259. X
  1260. X    else
  1261. X    iErr = Sock_StrHost2IP(sHostName, pIpAddr);
  1262. X
  1263. X
  1264. X    return(iErr);
  1265. X
  1266. X} /* Sock_ResolveHost */
  1267. X/****************************************************************************************/
  1268. X
  1269. X
  1270. X
  1271. X/****************************************************************************************/
  1272. XTVeosErr Sock_StrHost2IP(sHostName, pIpAddr)
  1273. X    char     *sHostName;
  1274. X    u_long    *pIpAddr;
  1275. X{
  1276. X    TVeosErr        iErr;
  1277. X    struct hostent      *hostInfo, *gethostbyname();
  1278. X    TPHostNode        pFinger;
  1279. X
  1280. X    iErr = VEOS_FAILURE;
  1281. X
  1282. X    if (sHostName) {
  1283. X
  1284. X    /** try to find this host in hash table first **/
  1285. X
  1286. X    for (pFinger = SOCK_HOSTS[sHostName[0] - 'a'];
  1287. X         pFinger;
  1288. X         pFinger = pFinger->pNext) {
  1289. X
  1290. X        if (strcmp(pFinger->sHostName, sHostName) == 0) {
  1291. X        iErr = VEOS_SUCCESS;
  1292. X        break;
  1293. X        }
  1294. X        }
  1295. X
  1296. X
  1297. X    if (!pFinger) {
  1298. X
  1299. X        /** find host by calling unix kernel **/
  1300. X
  1301. X        iErr = TALK_HOST;            
  1302. X        if (hostInfo = gethostbyname(sHostName)) {
  1303. X
  1304. X        iErr = Shell_NewBlock(sizeof(THostNode), &pFinger, "host-node");
  1305. X        if (iErr == VEOS_SUCCESS) {
  1306. X            
  1307. X            pFinger->sHostName = strdup(sHostName);
  1308. X            pFinger->lHost = *(u_long *) hostInfo->h_addr_list[0];
  1309. X            
  1310. X            
  1311. X            /** insert new host into hash table **/
  1312. X            
  1313. X            pFinger->pNext = SOCK_HOSTS[sHostName[0] - 'a'];
  1314. X            SOCK_HOSTS[sHostName[0] - 'a'] = pFinger;
  1315. X            }
  1316. X        }
  1317. X        }
  1318. X
  1319. X    if (pFinger)
  1320. X        *pIpAddr = pFinger->lHost;
  1321. X    }
  1322. X
  1323. X    return(iErr);
  1324. X
  1325. X    } /* Sock_StrHost2IP */
  1326. X/****************************************************************************************/
  1327. X
  1328. X
  1329. X
  1330. X
  1331. X/****************************************************************************************/
  1332. XTVeosErr Sock_IP2StrHost(lIPAddr, sHostName)
  1333. X    u_long    lIPAddr;
  1334. X    char     *sHostName;
  1335. X{
  1336. X    TVeosErr        iErr;
  1337. X    struct hostent      *hostInfo, *gethostbyaddr();
  1338. X    char        *pFinger;
  1339. X
  1340. X    iErr = VEOS_FAILURE;
  1341. X
  1342. X    if (sHostName) {
  1343. X
  1344. X    if (hostInfo = gethostbyaddr((char *) &lIPAddr, sizeof(u_long), AF_INET)) {
  1345. X        strcpy(sHostName, hostInfo->h_name);
  1346. X
  1347. X        if (pFinger = strchr(sHostName, '.'))
  1348. X        pFinger[0] = '\0';
  1349. X
  1350. X        iErr = VEOS_SUCCESS;
  1351. X        }
  1352. X    else
  1353. X        iErr = TALK_HOST;            
  1354. X    }
  1355. X
  1356. X    return(iErr);
  1357. X
  1358. X    } /* Sock_IP2StrHost */
  1359. X/****************************************************************************************/
  1360. X
  1361. X
  1362. X
  1363. X
  1364. X/****************************************************************************************/
  1365. XTVeosErr Sock_StrAddr2IP(sHostName, pIpAddr)
  1366. X    char     *sHostName;
  1367. X    u_long    *pIpAddr;
  1368. X{
  1369. X    u_long    lResult, lTemp;
  1370. X    char     *pCharFinger;
  1371. X    TVeosErr    iErr;
  1372. X
  1373. X    iErr = VEOS_FAILURE;
  1374. X    if (sHostName) {
  1375. X    
  1376. X    lResult = 0;
  1377. X    pCharFinger = sHostName;  
  1378. X    
  1379. X    
  1380. X    /* first byte */
  1381. X    lTemp = (u_long) atoi(pCharFinger);
  1382. X    lResult |= lTemp << 24;
  1383. X    
  1384. X    
  1385. X    /* second byte */
  1386. X    pCharFinger = strchr(pCharFinger, '.');
  1387. X    pCharFinger ++;
  1388. X    
  1389. X    lTemp = (u_long) atoi(pCharFinger);
  1390. X    lResult |= lTemp << 16;
  1391. X    
  1392. X    
  1393. X    /* third byte */
  1394. X    pCharFinger = strchr(pCharFinger, '.');
  1395. X    pCharFinger ++;
  1396. X    
  1397. X    lTemp = (u_long) atoi(pCharFinger);
  1398. X    lResult |= lTemp << 8;
  1399. X    
  1400. X    
  1401. X    /* fourth byte */
  1402. X    pCharFinger = strchr(pCharFinger, '.');
  1403. X    pCharFinger ++;
  1404. X    
  1405. X    lTemp = (u_long) atoi(pCharFinger);
  1406. X    lResult |= lTemp;
  1407. X    
  1408. X    
  1409. X    *pIpAddr = lResult;
  1410. X
  1411. X    iErr = VEOS_SUCCESS;
  1412. X    }
  1413. X
  1414. X    return(iErr);
  1415. X
  1416. X    } /* Sock_StrAddr2IP */
  1417. X/****************************************************************************************/
  1418. X
  1419. X
  1420. X
  1421. X/****************************************************************************************/
  1422. XTVeosErr Sock_IP2StrAddr(lIpAddr, sHostName)
  1423. X    u_long    lIpAddr;
  1424. X    char     *sHostName;
  1425. X{
  1426. X    TVeosErr        iErr;
  1427. X
  1428. X    iErr = VEOS_FAILURE;
  1429. X    if (sHostName) {
  1430. X    
  1431. X    sprintf(sHostName, "%d.%d.%d.%d",
  1432. X        (lIpAddr >> 24) & 0x000000FF,
  1433. X        (lIpAddr >> 16) & 0x000000FF,
  1434. X        (lIpAddr >> 8) & 0x000000FF,
  1435. X        lIpAddr & 0x000000FF);
  1436. X
  1437. X    iErr = VEOS_SUCCESS;
  1438. X    }
  1439. X
  1440. X    return(iErr);
  1441. X
  1442. X    } /* Sock_IP2StrAddr */
  1443. X/****************************************************************************************/
  1444. X
  1445. X
  1446. X
  1447. X
  1448. X
  1449. X
  1450. END_OF_FILE
  1451. if test 16709 -ne `wc -c <'kernel_private/src/talk/socket.c'`; then
  1452.     echo shar: \"'kernel_private/src/talk/socket.c'\" unpacked with wrong size!
  1453. fi
  1454. # end of 'kernel_private/src/talk/socket.c'
  1455. fi
  1456. if test -f 'src/kernel_current/fern/fe_int.lsp' -a "${1}" != "-c" ; then 
  1457.   echo shar: Will not clobber existing file \"'src/kernel_current/fern/fe_int.lsp'\"
  1458. else
  1459. echo shar: Extracting \"'src/kernel_current/fern/fe_int.lsp'\" \(16110 characters\)
  1460. sed "s/^X//" >'src/kernel_current/fern/fe_int.lsp' <<'END_OF_FILE'
  1461. X;;-----------------------------------------------------------
  1462. X;; file: fe_int.lsp
  1463. X;;
  1464. X;; FERN is the Fractal Entity Relativity Node.
  1465. X;; Part of the FE component of the Fern System.
  1466. X;;
  1467. X;; creation: March 28, 1992
  1468. X;;
  1469. X;; by Geoffrey P. Coco at the HITLab, Seattle
  1470. X;;-----------------------------------------------------------
  1471. X
  1472. X
  1473. X;;-----------------------------------------------------------
  1474. X;; Copyright (C) 1992  Geoffrey P. Coco,
  1475. X;; Human Interface Technology Lab, Seattle
  1476. X;;-----------------------------------------------------------
  1477. X
  1478. X
  1479. X;;===========================================================
  1480. X;;              Internal
  1481. X;;===========================================================
  1482. X
  1483. X(defun fe-put.int (int)
  1484. X  (vput int '((~ "perc"
  1485. X         @
  1486. X         @
  1487. X         > @) **)))
  1488. X
  1489. X;;-----------------------------------------------------------
  1490. X
  1491. X(defun fe-copy.int (&key (test-time nil))
  1492. X  (car (vcopy '(("perc"
  1493. X         @
  1494. X         @
  1495. X         > @) **)
  1496. X          :test-time test-time)))
  1497. X
  1498. X;;-----------------------------------------------------------
  1499. X
  1500. X(defun fe-xtrct.int ()
  1501. X  (vget '(("perc"
  1502. X       @
  1503. X       @
  1504. X       (> @@) **))))
  1505. X
  1506. X;;-----------------------------------------------------------
  1507. X
  1508. X(defun fe-get.int ()
  1509. X  (car (vput "%" '((~ "perc"
  1510. X              @
  1511. X              @
  1512. X              > @) **))))
  1513. X
  1514. X;;-----------------------------------------------------------
  1515. X
  1516. X
  1517. X
  1518. X
  1519. X;;-----------------------------------------------------------
  1520. X;; The following functions which manipulate the locl
  1521. X;; sub-partition were composed by Andy MacDonald
  1522. X;;-----------------------------------------------------------
  1523. X
  1524. X
  1525. X;;===========================================================
  1526. X;;                Local
  1527. X;;===========================================================
  1528. X
  1529. X(defun fe-put.int.locl (locl)
  1530. X  (vput locl '((~ "perc"
  1531. X          @2
  1532. X          (> @ @2)) **)))
  1533. X
  1534. X;;-----------------------------------------------------------
  1535. X
  1536. X(defun fe-copy.int.locl (&key (test-time nil))
  1537. X  (car (vcopy '(("perc"
  1538. X         @2
  1539. X         (> @ @2)) **)
  1540. X          :test-time test-time)))
  1541. X
  1542. X;;-----------------------------------------------------------
  1543. X
  1544. X(defun fe-xtrct.int.locl ()
  1545. X  (vget '(("perc"
  1546. X       @2
  1547. X       ((> @@) @2)) **)))
  1548. X
  1549. X;;-----------------------------------------------------------
  1550. X
  1551. X(defun fe-get.int.locl ()
  1552. X  (car (vput '((~ "perc"
  1553. X          @2
  1554. X          (> @ @2)) **))))
  1555. X
  1556. X;;-----------------------------------------------------------
  1557. X
  1558. X
  1559. X
  1560. X;;===========================================================
  1561. X;;               Local Objects
  1562. X;;===========================================================
  1563. X
  1564. X(defun fe-jam.int.locl.ob (ob)
  1565. X  (vput ob '((~ "perc"
  1566. X        @2
  1567. X        ((^ @@) @2)) **)))
  1568. X  
  1569. X;;-----------------------------------------------------------
  1570. X
  1571. X;; objects are (ob-name (attr-list))
  1572. X(defun fe-put.int.locl.ob (ob)
  1573. X  (cond
  1574. X
  1575. X   ;; assume object is already there
  1576. X   ((car (vput ob `((~ "perc"
  1577. X               @2
  1578. X               ((> (,(car ob) @) **) @2)) **))))
  1579. X
  1580. X   ;; object wasn't there, insert new one
  1581. X   ((fe-jam.int.locl.ob ob))
  1582. X   ))
  1583. X
  1584. X;;-----------------------------------------------------------
  1585. X
  1586. X;; pass object name
  1587. X(defun fe-copy.int.locl.ob (ob-name &key (test-time nil))
  1588. X  (car (vcopy `(("perc"
  1589. X         @2
  1590. X         ((> (,ob-name @) **) @2)) **)
  1591. X          :test-time test-time)))
  1592. X
  1593. X;;-----------------------------------------------------------
  1594. X
  1595. X;; pass object name, returns entire object
  1596. X(defun fe-xtrct.int.locl.ob (ob-name)
  1597. X  (car (vget `(("perc"
  1598. X        @2
  1599. X        ((> (,ob-name @) **) @2)) **))))
  1600. X
  1601. X;;-----------------------------------------------------------
  1602. X
  1603. X(defun fe-get.int.locl.ob (ob-name)
  1604. X  (car (vput "%" `((~ "perc"
  1605. X              @2
  1606. X              (((~ ,ob-name > @) **) @2)) **))))
  1607. X
  1608. X;;-----------------------------------------------------------
  1609. X
  1610. X
  1611. X
  1612. X;;===========================================================
  1613. X;;          Local Object - Complex
  1614. X;;===========================================================
  1615. X
  1616. X(defun fe-copy.int.locl.ob.names ()
  1617. X  (vcopy `(("perc"
  1618. X        @2
  1619. X        (((> @ @) **) @2)) **)
  1620. X     :freq "all"))
  1621. X
  1622. X;;-----------------------------------------------------------
  1623. X
  1624. X
  1625. X
  1626. X
  1627. X;;===========================================================
  1628. X;;          Local Object Attributes
  1629. X;;===========================================================
  1630. X
  1631. X(defun fe-jam.int.locl.ob.attr (ob-name attr)
  1632. X  (cond
  1633. X   ;; assume object exists, add new attr
  1634. X   ((vput attr `((~ "perc"
  1635. X            @2
  1636. X            (((~ ,ob-name (^ @@)) **) @2)) **)))
  1637. X
  1638. X   ;; object didn't exist, add new object with new attr.
  1639. X   ((fe-jam.int.locl.ob `(,ob-name (,attr))))
  1640. X   ))
  1641. X
  1642. X;;-----------------------------------------------------------
  1643. X
  1644. X(defun fe-put.int.locl.ob.attr (ob-name attr)
  1645. X  (cond
  1646. X   
  1647. X   ;; assume the object and attr exist, swap in new attr
  1648. X   ((car (vput attr `((~ "perc"
  1649. X             @2
  1650. X             (((~ ,ob-name (> (,(car attr) @) **)) **) @2)) **))))
  1651. X    
  1652. X   ;; attr didn't exist, add new attr
  1653. X   ((fe-jam.int.locl.ob.attr ob-name attr))
  1654. X   ))
  1655. X
  1656. X;;-----------------------------------------------------------
  1657. X
  1658. X(defun fe-xtrct.int.locl.ob.attr (ob-name attr-name)
  1659. X  (car (vget `(("perc"
  1660. X        @2
  1661. X        (((,ob-name (> (,attr-name @) **)) **) @2)) **))))
  1662. X
  1663. X;;-----------------------------------------------------------
  1664. X
  1665. X(defun fe-get.int.locl.ob.attr (ob-name attr-name)
  1666. X  (car (vput "%" `((~ "perc"
  1667. X              @2
  1668. X              (((~ ,ob-name ((~ ,attr-name > @) **)) **) @2)) **))))
  1669. X
  1670. X;;-----------------------------------------------------------
  1671. X
  1672. X;; returns attr struct
  1673. X(defun fe-copy.int.locl.ob.attr (ob-name attr-name &key (test-time nil))
  1674. X  (car (vcopy `(("perc"
  1675. X         @2
  1676. X         (((,ob-name (> (,attr-name @) **)) **) @2)) **)
  1677. X          :test-time test-time)))
  1678. X  
  1679. X;;-----------------------------------------------------------
  1680. X
  1681. X
  1682. X
  1683. X;;===========================================================
  1684. X;;         Local Object Attributes - Complex
  1685. X;;===========================================================
  1686. X
  1687. X;; returns list of boundary attribute names
  1688. X(defun fe-copy.int.locl.ob.attr.names (ob-name)
  1689. X  (vcopy `(("perc"
  1690. X        @2
  1691. X        (((,ob-name ((> @ @) **)) **) @2)) **)
  1692. X     :freq "all"))
  1693. X
  1694. X;;-----------------------------------------------------------
  1695. X
  1696. X;; returns attr val
  1697. X(defun fe-copy.int.locl.ob.attr.val (ob-name attr-name)
  1698. X  (car (vcopy `(("perc"
  1699. X         @2
  1700. X         (((,ob-name ((,attr-name > @) **)) **) @2)) **))))
  1701. X  
  1702. X;;-----------------------------------------------------------
  1703. X
  1704. X
  1705. X
  1706. X;;===========================================================
  1707. X;;              Sublings
  1708. X;;===========================================================
  1709. X
  1710. X(defun fe-put.int.subs (subs)
  1711. X  (vput subs '((~ "perc"
  1712. X          @2
  1713. X          (@ > @ @)) **)))
  1714. X
  1715. X;;-----------------------------------------------------------
  1716. X
  1717. X;; cache this frequently used pattern in C level fern.
  1718. X;; later, calls to fe-copy.int.subs use precomputed pattern.
  1719. X
  1720. X(fbase-init-copy.int.subs '(("perc"
  1721. X                 @2
  1722. X                 (@ > @ @)) **))
  1723. X
  1724. X#|
  1725. X(defun fe-copy.int.subs (&key (test-time nil))
  1726. X  (car (vcopy '(("perc"
  1727. X         @2
  1728. X         (@ > @ @)) **)
  1729. X          :test-time test-time)))
  1730. X|#
  1731. X;;-----------------------------------------------------------
  1732. X
  1733. X(defun fe-xtrct.int.subs ()
  1734. X  (vget '(("perc"
  1735. X       @2
  1736. X       (@ (> @@) @)) **)))
  1737. X
  1738. X;;-----------------------------------------------------------
  1739. X
  1740. X(defun fe-get.int.subs ()
  1741. X  (car (vput "%" '((~ "perc"
  1742. X              @2
  1743. X              (@ > @ @)) **))))
  1744. X
  1745. X;;-----------------------------------------------------------
  1746. X
  1747. X
  1748. X;;===========================================================
  1749. X;;              Sublings Entities
  1750. X;;===========================================================
  1751. X
  1752. X(defun fe-jam.int.subs.ent (ent)
  1753. X  (vput ent '((~ "perc"
  1754. X         @2
  1755. X         (@ (^ @@) @)) **)))
  1756. X
  1757. X;;-----------------------------------------------------------
  1758. X
  1759. X;; an ent is: (uid (ob-list))
  1760. X(defun fe-put.int.subs.ent (ent)
  1761. X  (cond
  1762. X
  1763. X   ;; assume the ent exists, swap in the new ent
  1764. X   ((car (vput ent `((~ "perc"
  1765. X            @2
  1766. X            (@ (> (,(car ent) @) **) @)
  1767. X            ) **))))
  1768. X
  1769. X   ;; ent didn't exist, insert new ent
  1770. X   ((fe-jam.int.subs.ent ent))
  1771. X   ))
  1772. X              
  1773. X;;-----------------------------------------------------------
  1774. X
  1775. X(defun fe-copy.int.subs.ent (uid &key (test-time nil))
  1776. X  (car (vcopy `(("perc"
  1777. X         @2
  1778. X         (@ (> (,uid @) **) @)
  1779. X         ) **)
  1780. X          :test-time test-time)))
  1781. X
  1782. X;;-----------------------------------------------------------
  1783. X
  1784. X(defun fe-xtrct.int.subs.ent (uid)
  1785. X  (car (vget `(("perc"
  1786. X        @2
  1787. X        (@ (> (,uid @) **) @)
  1788. X        ) **))))
  1789. X
  1790. X;;-----------------------------------------------------------
  1791. X
  1792. X(defun fe-get.int.subs.ent (uid)
  1793. X  (car (vput "%" `((~ "perc"
  1794. X              @2
  1795. X              (@ ((~ ,uid > @) **) @)
  1796. X              ) **))))
  1797. X
  1798. X;;-----------------------------------------------------------
  1799. X
  1800. X
  1801. X
  1802. X;;===========================================================
  1803. X;;         Sublings Entities - Complex
  1804. X;;===========================================================
  1805. X
  1806. X(defun fe-copy.int.subs.uids ()
  1807. X  (vcopy '(("perc"
  1808. X        @2
  1809. X        (@ ((> @ @) **) @)
  1810. X        ) **)
  1811. X     :freq "all"))
  1812. X
  1813. X;;-----------------------------------------------------------
  1814. X
  1815. X
  1816. X
  1817. X
  1818. X;;===========================================================
  1819. X;;          Sublings Entities Objects
  1820. X;;===========================================================
  1821. X
  1822. X
  1823. X(defun fe-jam.int.subs.ent.ob (uid ob)
  1824. X  (cond
  1825. X
  1826. X   ;; assume entity exists, insert new object
  1827. X   ((vput ob `((~ "perc"
  1828. X          @2
  1829. X          (@ ((~ ,uid (^ @@)) **) @)
  1830. X          ) **)))
  1831. X
  1832. X   ;; entity wasn't there, insert new entity with new object
  1833. X   ((fe-jam.int.subs.ent `(,uid (,ob))))
  1834. X   ))
  1835. X   
  1836. X;;-----------------------------------------------------------
  1837. X
  1838. X;; ob is a normal object structure: (name (attr-list))
  1839. X(defun fe-put.int.subs.ent.ob (uid ob)
  1840. X  (cond
  1841. X
  1842. X   ;; assume entity and object exist, swap in new object
  1843. X   ((car (vput ob `((~ "perc"
  1844. X               @2               
  1845. X               (@ ((~ ,uid (> (,(car ob) @) **)) **) @)
  1846. X               ) **))))
  1847. X   
  1848. X   ;; object wasn't there, assume entity exists, insert new object
  1849. X   ((fe-jam.int.subs.ent.ob uid ob))
  1850. X   ))
  1851. X   
  1852. X;;-----------------------------------------------------------
  1853. X
  1854. X(defun fe-copy.int.subs.ent.ob (uid ob-name &key (test-time nil))
  1855. X  (car (vcopy `(("perc"
  1856. X         @2
  1857. X         (@ ((,uid (> (,ob-name @) **)) **) @)
  1858. X         ) **)
  1859. X          :test-time test-time)))
  1860. X
  1861. X;;-----------------------------------------------------------
  1862. X
  1863. X(defun fe-xtrct.int.subs.ent.ob (uid ob-name)
  1864. X  (car (vget `(("perc"
  1865. X        @2
  1866. X        (@ ((,uid (> (,ob-name @) **)) **) @)
  1867. X        ) **))))
  1868. X
  1869. X;;-----------------------------------------------------------
  1870. X
  1871. X(defun fe-get.int.subs.ent.ob (uid ob-name)
  1872. X  (car (vput "%" `((~ "perc"
  1873. X              @2
  1874. X              (@ ((~ ,uid ((~ ,ob-name > @) **)) **) @)
  1875. X              ) **))))
  1876. X
  1877. X;;-----------------------------------------------------------
  1878. X
  1879. X
  1880. X
  1881. X;;===========================================================
  1882. X;;         Subling Entities Objects - Complex
  1883. X;;===========================================================
  1884. X
  1885. X;; pass uid, get list of it's ob names
  1886. X(defun fe-copy.int.subs.ent.ob.names (uid)
  1887. X  (vcopy `(("perc"
  1888. X        @2
  1889. X        (@ ((,uid ((> @ @) **)) **) @)
  1890. X        ) **)
  1891. X     :freq "all"))
  1892. X
  1893. X;;-----------------------------------------------------------
  1894. X
  1895. X
  1896. X
  1897. X
  1898. X;;===========================================================
  1899. X;;         Subling Entities Objects Attributes
  1900. X;;===========================================================
  1901. X
  1902. X
  1903. X(defun fe-jam.int.subs.ent.ob.attr (uid ob-name attr)
  1904. X  (cond
  1905. X   ;; assume entity and ob exists, insert new attr
  1906. X   ((vput attr `((~ "perc"
  1907. X            @2
  1908. X            (@
  1909. X             ((~ ,uid ((~ ,ob-name (^ @@)) **)) **)
  1910. X             @)
  1911. X            ) **)))
  1912. X  
  1913. X   ;; ob wasn't there, insert new ob with new attr
  1914. X   ((fe-jam.int.subs.ent.ob uid `(,ob-name (,attr))))
  1915. X   ))
  1916. X
  1917. X;;-----------------------------------------------------------
  1918. X
  1919. X;; attr is ("attr-name" attr-val)
  1920. X(defun fe-put.int.subs.ent.ob.attr (uid ob-name attr)
  1921. X  (cond
  1922. X   ;; assume the ent, ob and attr exist, swap in new attr
  1923. X   ((car (vput attr `((~ "perc"
  1924. X             @2
  1925. X             (@ 
  1926. X              ((~ ,uid ((~ ,ob-name (> (,(car attr) @) **)) **)) **)
  1927. X              @)
  1928. X             ) **))))
  1929. X
  1930. X   ;; attr wasn't there, insert new attr
  1931. X   ((fe-jam.int.subs.ent.ob.attr uid ob-name attr))
  1932. X   ))
  1933. X   
  1934. X;;-----------------------------------------------------------
  1935. X
  1936. X;; pass uid, ob-num, attr-name
  1937. X(defun fe-copy.int.subs.ent.ob.attr (uid ob-num attr-name &key (test-time nil))
  1938. X  (car (vcopy `(("perc"
  1939. X         @2
  1940. X         (@
  1941. X          ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  1942. X          @)
  1943. X         ) **)
  1944. X          :test-time test-time)))
  1945. X
  1946. X;;-----------------------------------------------------------
  1947. X
  1948. X;; pass uid, ob-num, attr-name
  1949. X(defun fe-xtrct.int.subs.ent.ob.attr (uid ob-num attr-name)
  1950. X  (car (vget `(("perc"
  1951. X        @2
  1952. X        (@
  1953. X         ((,uid ((,ob-num (> (,attr-name @) **)) **)) **)
  1954. X         @)
  1955. X        ) **))))
  1956. X
  1957. X;;-----------------------------------------------------------
  1958. X
  1959. X;; pass uid, ob-num, attr-name
  1960. X(defun fe-get.int.subs.ent.ob.attr (uid ob-num attr-name)
  1961. X  (car (vput "%" `((~ "perc"
  1962. X              @2
  1963. X              (@
  1964. X               ((~ ,uid ((~ ,ob-num ((~ ,attr-name > @) **)) **)) **)
  1965. X               @)
  1966. X              ) **))))
  1967. X
  1968. X;;-----------------------------------------------------------
  1969. X
  1970. X
  1971. X
  1972. X;;===========================================================
  1973. X;;    Subling Entities Objects Attributes - Complex
  1974. X;;===========================================================
  1975. X
  1976. X;; pass uid and ob, return attr-list
  1977. X(defun fe-copy.int.subs.ent.ob.attr.names (uid ob-name)
  1978. X  (vcopy `(("perc"
  1979. X        @2
  1980. X        (@
  1981. X         ((,uid ((,ob-name ((> @ @) **)) **)) **)
  1982. X         @)
  1983. X        ) **)
  1984. X     :freq "all"))
  1985. X
  1986. X;;-----------------------------------------------------------
  1987. X
  1988. X;; pass attr, return values of all objects of all sibs
  1989. X(defun fe-copy.int.subs.attr.vals (attr-name)
  1990. X  (vcopy `(("perc"
  1991. X        @2
  1992. X        (@
  1993. X         ((@ ((@ ((,attr-name > @) **)) **)) **)
  1994. X         @)
  1995. X        ) **)
  1996. X     :freq "all"))
  1997. X
  1998. X;;-----------------------------------------------------------
  1999. X
  2000. X;; pass uid, ob-num, attr-name
  2001. X(defun fe-copy.int.subs.ent.ob.attr.val (uid ob-num attr-name)
  2002. X  (car (vcopy `(("perc"
  2003. X         @2
  2004. X         (@
  2005. X          ((,uid ((,ob-num ((,attr-name > @) **)) **)) **)
  2006. X          @)
  2007. X         ) **))))
  2008. X
  2009. X;;-----------------------------------------------------------
  2010. X
  2011. X
  2012. X
  2013. X
  2014. X
  2015. X;;===========================================================
  2016. X;;               Filters
  2017. X;;===========================================================
  2018. X
  2019. X(defun fe-put.int.fltrs (fltr)
  2020. X  (vput fltr '((~ "perc"
  2021. X          @2
  2022. X          (@2 > @)) **)))
  2023. X
  2024. X;;-----------------------------------------------------------
  2025. X
  2026. X(defun fe-copy.int.fltrs (&key (test-time nil))
  2027. X  (car (vcopy '(("perc"
  2028. X         @2
  2029. X         (@2 > @)) **)
  2030. X          :test-time test-time)))
  2031. X
  2032. X;;-----------------------------------------------------------
  2033. X
  2034. X(defun fe-xtrct.int.fltrs ()
  2035. X  (vget '(("perc"
  2036. X       @2
  2037. X       (@2 (> @@))) **)))
  2038. X
  2039. X;;-----------------------------------------------------------
  2040. X
  2041. X(defun fe-get.int.fltrs ()
  2042. X  (car (vput "%" '((~ "perc"
  2043. X              @2
  2044. X              (@2 > @)) **))))
  2045. X
  2046. X;;-----------------------------------------------------------
  2047. X
  2048. X
  2049. X
  2050. X;;===========================================================
  2051. X;;               Fltrs Entities
  2052. X;;===========================================================
  2053. X
  2054. X(defun fe-jam.int.fltrs.ent (ent)
  2055. X  (vput ent '((~ "perc"
  2056. X         @2
  2057. X         (@2 (^ @@))) **)))
  2058. X
  2059. X;;-----------------------------------------------------------
  2060. X
  2061. X;; an ent is: (uid (ob-list))
  2062. X(defun fe-put.int.fltrs.ent (ent)
  2063. X  (cond
  2064. X
  2065. X   ;; assume the ent exists, swap in the new ent
  2066. X   ((car (vput ent `((~ "perc"
  2067. X            @2
  2068. X            (@2 (> (,(car ent) @) **))
  2069. X            ) **))))
  2070. X
  2071. X   ;; ent didn't exist, insert new ent
  2072. X   ((fe-jam.int.fltrs.ent ent))
  2073. X   ))
  2074. X              
  2075. X;;-----------------------------------------------------------
  2076. X
  2077. X(defun fe-copy.int.fltrs.ent (uid &key (test-time nil))
  2078. X  (car (vcopy `(("perc"
  2079. X         @2
  2080. X         (@2 (> (,uid @) **))
  2081. X         ) **)
  2082. X          :test-time test-time)))
  2083. X
  2084. X;;-----------------------------------------------------------
  2085. X
  2086. X(defun fe-xtrct.int.fltrs.ent (uid)
  2087. X  (car (vget `(("perc"
  2088. X        @2
  2089. X        (@2 (> (,uid @) **))
  2090. X        ) **))))
  2091. X
  2092. X;;-----------------------------------------------------------
  2093. X
  2094. X(defun fe-get.int.fltrs.ent (uid)
  2095. X  (car (vput "%" `((~ "perc"
  2096. X              @2
  2097. X              (@2 ((~ ,uid > @) **))
  2098. X              ) **))))
  2099. X
  2100. X;;-----------------------------------------------------------
  2101. X
  2102. X
  2103. X
  2104. X
  2105. X;;===========================================================
  2106. X;;          Internal Entity Filter Processing
  2107. X;;===========================================================
  2108. X
  2109. X
  2110. X;;-----------------------------------------------------------
  2111. X
  2112. X(defun fe-fltr.int.subs (uid &key (test-time nil))
  2113. X  (delete uid
  2114. X      (fe-copy.int.subs :test-time test-time)
  2115. X      :test (lambda (x y) (equal x (car y)))))
  2116. X  
  2117. X;;-----------------------------------------------------------
  2118. X
  2119. X(defun fe-fltr.int.subs.uids (uid)
  2120. X  (delete uid 
  2121. X      (fe-copy.int.subs.uids)
  2122. X      :test 'equal))
  2123. X  
  2124. X;;-----------------------------------------------------------
  2125. X
  2126. X
  2127. X
  2128. X
  2129. END_OF_FILE
  2130. if test 16110 -ne `wc -c <'src/kernel_current/fern/fe_int.lsp'`; then
  2131.     echo shar: \"'src/kernel_current/fern/fe_int.lsp'\" unpacked with wrong size!
  2132. fi
  2133. # end of 'src/kernel_current/fern/fe_int.lsp'
  2134. fi
  2135. if test -f 'src/xlisp/xcore/c/xlobj.c' -a "${1}" != "-c" ; then 
  2136.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlobj.c'\"
  2137. else
  2138. echo shar: Extracting \"'src/xlisp/xcore/c/xlobj.c'\" \(16437 characters\)
  2139. sed "s/^X//" >'src/xlisp/xcore/c/xlobj.c' <<'END_OF_FILE'
  2140. X/* -*-C-*-
  2141. X********************************************************************************
  2142. X*
  2143. X* File:         xlobj.c
  2144. X* RCS:          $Header: xlobj.c,v 1.3 89/11/25 05:41:26 mayer Exp $
  2145. X* Description:  xlisp object functions
  2146. X* Author:       David Michael Betz
  2147. X* Created:      
  2148. X* Modified:     Sat Nov 25 05:41:13 1989 (Niels Mayer) mayer@hplnpm
  2149. X* Language:     C
  2150. X* Package:      N/A
  2151. X* Status:       X11r4 contrib tape release
  2152. X*
  2153. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2154. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2155. X*
  2156. X* Permission to use, copy, modify, distribute, and sell this software and its
  2157. X* documentation for any purpose is hereby granted without fee, provided that
  2158. X* the above copyright notice appear in all copies and that both that
  2159. X* copyright notice and this permission notice appear in supporting
  2160. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2161. X* used in advertising or publicity pertaining to distribution of the software
  2162. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2163. X* make no representations about the suitability of this software for any
  2164. X* purpose. It is provided "as is" without express or implied warranty.
  2165. X*
  2166. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2167. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2168. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2169. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2170. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2171. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2172. X* PERFORMANCE OF THIS SOFTWARE.
  2173. X*
  2174. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2175. X* 
  2176. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2177. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2178. X*
  2179. X********************************************************************************
  2180. X*/
  2181. Xstatic char rcs_identity[] = "@(#)$Header: xlobj.c,v 1.3 89/11/25 05:41:26 mayer Exp $";
  2182. X
  2183. X
  2184. X#include "xlisp.h"
  2185. X
  2186. X/* external variables */
  2187. Xextern LVAL xlenv,xlfenv,xlvalue;
  2188. Xextern LVAL s_stdout,s_stderr,s_lambda;
  2189. Xextern LVAL s_send;/*91Jun15jsp*/
  2190. X
  2191. X/* local variables *//* 90Nov28 jsp exported READ ONLY! */
  2192. XLVAL s_self,k_new,k_isnew;/*JSP*/
  2193. XLVAL cls_class,cls_object;/*JSP*/
  2194. X
  2195. X/* forward declarations */
  2196. XFORWARD LVAL entermsg();
  2197. XFORWARD LVAL x_sendmsg();
  2198. XFORWARD LVAL evmethod();
  2199. X
  2200. X/* Include hybrid-class functions: *//* JSP */
  2201. X#define MODULE_XLOBJ_C_GLOBALS
  2202. X#include "../../xmodules.h"
  2203. X#undef MODULE_XLOBJ_C_GLOBALS
  2204. X
  2205. X/* xsend - send a message to an object */
  2206. XLVAL xsend()
  2207. X{
  2208. X    LVAL obj;
  2209. X    obj = xlgaobject();
  2210. X    return (x_sendmsg(obj,getclass(obj),xlgasymbol()));
  2211. X}
  2212. X
  2213. X/* xsendsuper - send a message to the superclass of an object */
  2214. XLVAL xsendsuper()
  2215. X{
  2216. X    LVAL env,p;
  2217. X    for (env = xlenv; env; env = cdr(env))
  2218. X    if ((p = car(env)) && objectp(car(p)))
  2219. X        return (x_sendmsg(car(p),
  2220. X                getivar(cdr(p),SUPERCLASS),
  2221. X                xlgasymbol()));
  2222. X    xlfail("not in a method");
  2223. X}
  2224. X
  2225. X/* xlclass - define a class */
  2226. XLVAL xlclass(name,vcnt)
  2227. X  char *name; int vcnt;
  2228. X{
  2229. X    LVAL sym,cls;
  2230. X
  2231. X    /* create the class */
  2232. X    sym = xlenter(name);
  2233. X    cls = newobject(cls_class,CLASSSIZE);
  2234. X    setvalue(sym,cls);
  2235. X
  2236. X    /* set the instance variable counts */
  2237. X    setivar(cls,IVARCNT,cvfixnum((FIXTYPE)vcnt));
  2238. X    setivar(cls,IVARTOTAL,cvfixnum((FIXTYPE)vcnt));
  2239. X
  2240. X    /* set the superclass to 'Object' */
  2241. X    setivar(cls,SUPERCLASS,cls_object);
  2242. X
  2243. X    /* return the new class */
  2244. X    return (cls);
  2245. X}
  2246. X
  2247. X#ifdef PROVIDE_WINTERP
  2248. X/* xlclass_p -- check if object is a class object as created by xlclass() */
  2249. Xint xlclass_p(o_class)
  2250. X     LVAL o_class;        /* assume type==OBJECT */
  2251. X{
  2252. X  return (getclass(o_class) == cls_class);
  2253. X}
  2254. X#endif
  2255. X
  2256. X/* xladdivar - enter an instance variable */
  2257. Xxladdivar(cls,var)
  2258. X  LVAL cls; char *var;
  2259. X{
  2260. X    setivar(cls,IVARS,cons(xlenter(var),getivar(cls,IVARS)));
  2261. X}
  2262. X
  2263. X/* xladdmsg - add a message to a class */
  2264. Xxladdmsg(cls,msg,offset)
  2265. X  LVAL cls; char *msg; int offset;
  2266. X{
  2267. X    extern FUNDEF *funtab;
  2268. X    LVAL mptr;
  2269. X
  2270. X    /* enter the message selector */
  2271. X    mptr = entermsg(cls,xlenter(msg));
  2272. X
  2273. X    /* store the method for this message */
  2274. X    rplacd(mptr,cvsubr(funtab[offset].fd_subr,funtab[offset].fd_type,offset));
  2275. X}
  2276. X
  2277. X/* xlobgetvalue - get the value of an instance variable */
  2278. Xint xlobgetvalue(pair,sym,pval)
  2279. X  LVAL pair;  /* pair is from an xlenv environment frame.   */
  2280. X              /* car(pair) is an object.                    */
  2281. X              /* cdr(pair) a [maybe super-]class of object. */
  2282. X  LVAL sym;   /* Symbol whose value we're trying to locate. */
  2283. X  LVAL *pval; /* Return path for value.                     */
  2284. X{             /* Return TRUE if we find sym, else FALSE.    */
  2285. X    LVAL cls,names;
  2286. X    int ivtotal,n;
  2287. X
  2288. X    /* find the instance or class variable */
  2289. X    for (cls = cdr(pair); objectp(cls); cls = getivar(cls,SUPERCLASS)) {
  2290. X
  2291. X    /* check the instance variables */
  2292. X    names = getivar(cls,IVARS);
  2293. X    ivtotal = getivcnt(cls,IVARTOTAL);
  2294. X    for (n = ivtotal - getivcnt(cls,IVARCNT); n < ivtotal; ++n) {
  2295. X        if (car(names) == sym) {
  2296. X        *pval = getivar(car(pair),n);
  2297. X        return (TRUE);
  2298. X        }
  2299. X        names = cdr(names);
  2300. X    }
  2301. X
  2302. X    /* check the class variables */
  2303. X    names = getivar(cls,CVARS);
  2304. X    for (n = 0; consp(names); ++n) {
  2305. X        if (car(names) == sym) {
  2306. X        *pval = getelement(getivar(cls,CVALS),n);
  2307. X        return (TRUE);
  2308. X        }
  2309. X        names = cdr(names);
  2310. X    }
  2311. X    }
  2312. X
  2313. X    /* variable not found */
  2314. X    return (FALSE);
  2315. X}
  2316. X
  2317. X/* xlobsetvalue - set the value of an instance variable */
  2318. Xint xlobsetvalue(pair,sym,val)
  2319. X  LVAL pair,sym,val;
  2320. X{
  2321. X    LVAL cls,names;
  2322. X    int ivtotal,n;
  2323. X
  2324. X    /* find the instance or class variable */
  2325. X    for (cls = cdr(pair); objectp(cls); cls = getivar(cls,SUPERCLASS)) {
  2326. X
  2327. X    /* check the instance variables */
  2328. X    names = getivar(cls,IVARS);
  2329. X    ivtotal = getivcnt(cls,IVARTOTAL);
  2330. X    for (n = ivtotal - getivcnt(cls,IVARCNT); n < ivtotal; ++n) {
  2331. X        if (car(names) == sym) {
  2332. X        setivar(car(pair),n,val);
  2333. X        return (TRUE);
  2334. X        }
  2335. X        names = cdr(names);
  2336. X    }
  2337. X
  2338. X    /* check the class variables */
  2339. X    names = getivar(cls,CVARS);
  2340. X    for (n = 0; consp(names); ++n) {
  2341. X        if (car(names) == sym) {
  2342. X        setelement(getivar(cls,CVALS),n,val);
  2343. X        return (TRUE);
  2344. X        }
  2345. X        names = cdr(names);
  2346. X    }
  2347. X    }
  2348. X
  2349. X    /* variable not found */
  2350. X    return (FALSE);
  2351. X}
  2352. X
  2353. X/* obisnew - default 'isnew' method */
  2354. XLVAL obisnew()
  2355. X{
  2356. X    LVAL self;
  2357. X    self = xlgaobject();
  2358. X    xllastarg();
  2359. X    return (self);
  2360. X}
  2361. X
  2362. X/* obclass - get the class of an object */
  2363. XLVAL obclass()
  2364. X{
  2365. X    LVAL self;
  2366. X    self = xlgaobject();
  2367. X    xllastarg();
  2368. X    return (getclass(self));
  2369. X}
  2370. X
  2371. X/* obshow - show the instance variables of an object */
  2372. XLVAL obshow()
  2373. X{
  2374. X    LVAL self,fptr,cls,names;
  2375. X    int ivtotal,n;
  2376. X
  2377. X    /* get self and the file pointer */
  2378. X    self = xlgaobject();
  2379. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  2380. X    xllastarg();
  2381. X
  2382. X    /* get the object's class */
  2383. X    cls = getclass(self);
  2384. X
  2385. X    /* print the object and class */
  2386. X    xlputstr(fptr,"Object is ");
  2387. X    xlprint(fptr,self,TRUE);
  2388. X    xlputstr(fptr,", Class is ");
  2389. X    xlprint(fptr,cls,TRUE);
  2390. X    xlterpri(fptr);
  2391. X
  2392. X    /* print the object's instance variables */
  2393. X    for (; cls; cls = getivar(cls,SUPERCLASS)) {
  2394. X    names = getivar(cls,IVARS);
  2395. X    ivtotal = getivcnt(cls,IVARTOTAL);
  2396. X    for (n = ivtotal - getivcnt(cls,IVARCNT); n < ivtotal; ++n) {
  2397. X
  2398. X        xlputstr(fptr,"  ");
  2399. X        xlprint(fptr,car(names),TRUE);
  2400. X        xlputstr(fptr," = ");
  2401. X        xlprint(fptr,getivar(self,n),TRUE);
  2402. X        xlterpri(fptr);
  2403. X        names = cdr(names);
  2404. X    }
  2405. X    }
  2406. X
  2407. X    /* return the object */
  2408. X    return (self);
  2409. X}
  2410. X
  2411. X
  2412. X/* clnew - create a new object instance */
  2413. XLVAL clnew()
  2414. X{
  2415. X    LVAL self;
  2416. X    self = xlgaobject();
  2417. X
  2418. X/* Include hybrid-class functions: *//* JSP */
  2419. X#define MODULE_XLOBJ_C_CLNEW
  2420. X#include "../../xmodules.h"
  2421. X#undef MODULE_XLOBJ_C_CLNEW
  2422. X
  2423. X    return     (newobject( self,getivcnt(self,IVARTOTAL)));
  2424. X}
  2425. X
  2426. X/* clisnew - initialize a new class */
  2427. XLVAL clisnew()
  2428. X{
  2429. X    LVAL self,ivars,cvars,super;
  2430. X    int n;
  2431. X
  2432. X    /* get self, the ivars, cvars and superclass */
  2433. X    self = xlgaobject();
  2434. X    ivars = xlgalist();
  2435. X    cvars = (moreargs() ? xlgalist() : NIL);
  2436. X    super = (moreargs() ? xlgaobject() : cls_object);
  2437. X    xllastarg();
  2438. X
  2439. X    /* store the instance and class variable lists and the superclass */
  2440. X    setivar(self,IVARS,ivars);
  2441. X    setivar(self,CVARS,cvars);
  2442. X    setivar(self,CVALS,(cvars ? newvector(listlength(cvars)) : NIL));
  2443. X    setivar(self,SUPERCLASS,super);
  2444. X
  2445. X    /* compute the instance variable count */
  2446. X    n = listlength(ivars);
  2447. X    setivar(self,IVARCNT,cvfixnum((FIXTYPE)n));
  2448. X    n += getivcnt(super,IVARTOTAL);
  2449. X    setivar(self,IVARTOTAL,cvfixnum((FIXTYPE)n));
  2450. X
  2451. X    /* return the new class object */
  2452. X    return (self);
  2453. X}
  2454. X
  2455. X/* clanswer - define a method for answering a message */
  2456. XLVAL clanswer()
  2457. X{
  2458. X    LVAL self,msg,fargs,code,mptr;
  2459. X
  2460. X    /* message symbol, formal argument list and code */
  2461. X    self = xlgaobject();
  2462. X    msg = xlgasymbol();
  2463. X    fargs = xlgalist();
  2464. X    code = xlgalist();
  2465. X    xllastarg();
  2466. X
  2467. X    /* make a new message list entry */
  2468. X    mptr = entermsg(self,msg);
  2469. X
  2470. X    /* set up the message node */
  2471. X    xlprot1(fargs);
  2472. X    fargs = cons(s_self,fargs); /* add 'self' as the first argument */
  2473. X    rplacd(mptr,xlclose(msg,s_lambda,fargs,code,xlenv,xlfenv));    /* changed by NPM -- pass in lexical and functional environment */
  2474. X    xlpop();
  2475. X
  2476. X    /* return the object */
  2477. X    return (self);
  2478. X}
  2479. X
  2480. X/* entermsg - add a message to a class */
  2481. XLOCAL LVAL entermsg(cls,msg)
  2482. X  LVAL cls,msg;
  2483. X{
  2484. X    LVAL lptr,mptr;
  2485. X
  2486. X    /* look up the message */
  2487. X    for (lptr = getivar(cls,MESSAGES); lptr; lptr = cdr(lptr))
  2488. X    if (car(mptr = car(lptr)) == msg)
  2489. X        return (mptr);
  2490. X
  2491. X    /* allocate a new message entry if one wasn't found */
  2492. X    xlsave1(mptr);
  2493. X    mptr = consa(msg);
  2494. X    setivar(cls,MESSAGES,cons(mptr,getivar(cls,MESSAGES)));
  2495. X    xlpop();
  2496. X
  2497. X    /* return the symbol node */
  2498. X    return (mptr);
  2499. X}
  2500. X
  2501. X/* xsendmsgN - external entry to send a message to an object, N args: */
  2502. XLVAL xsendmsgN(obj,sym,args,arg1,arg2,arg3) /*Created 91Jun15jsp*/
  2503. XLVAL obj,sym;
  2504. Xint args;
  2505. XLVAL arg1,arg2,arg3;
  2506. X{
  2507. X    /* This is basically ripped off from the SUBR case of xleval.c:evform(). */
  2508. X    LVAL  val;
  2509. X    LVAL *argv;
  2510. X    int argc;
  2511. X
  2512. X    xllastarg(); /* Make sure nothing on stack */
  2513. X    argv = xlargv;
  2514. X    argc = xlargc;
  2515. X
  2516. X    args+= 2;    /* Count obj and sym as args.   */
  2517. X    {   /* Begin inlineed simplified pushargs() */
  2518. X    /* build a new argument stack frame */
  2519. X    LVAL*newfp = xlsp;
  2520. X    pusharg(cvfixnum((FIXTYPE)(newfp - xlfp)));
  2521. X    pusharg(xlgetfunction(s_send));
  2522. X    pusharg(cvfixnum((FIXTYPE)args)); /* argc(ount) */
  2523. X    pusharg( obj );    /* Push message recipient.           */
  2524. X    pusharg( sym );    /* Push message selector.            */
  2525. X    if (args > 2) pusharg( arg1 );
  2526. X    if (args > 3) pusharg( arg2 );
  2527. X    if (args > 4) pusharg( arg3 );
  2528. X    xlfp = newfp;    /* Establish the new stack frame.    */
  2529. X        xlargc = args;    /* Remember the number of arguments. */
  2530. X    } /* End   inlineed simplified pushargs() */
  2531. X
  2532. X    xlargv = xlfp + 3;
  2533. X    val = xsend();
  2534. X    xlsp = xlfp;
  2535. X    xlfp = xlfp - (int)getfixnum(*xlfp);
  2536. X    xlargv = argv;
  2537. X    xlargc = argc;
  2538. X    return val;
  2539. X}
  2540. X/* xsendmsg0 - external entry to send a message to an object, no arg */
  2541. XLVAL xsendmsg0(obj,sym) /*Created 91Jun16jsp*/
  2542. XLVAL obj,sym;
  2543. X{
  2544. X    return xsendmsgN(obj,sym,0,NIL,NIL,NIL);
  2545. X}
  2546. X/* xsendmsg1 - external entry to send a message to an object, 1 arg */
  2547. XLVAL xsendmsg1(obj,sym,arg1) /*Created 91Jun15jsp*/
  2548. XLVAL obj,sym,arg1;
  2549. X{
  2550. X    return xsendmsgN(obj,sym,1,arg1,NIL,NIL);
  2551. X}
  2552. X/* xsendmsg2 - external entry to send a message to an object, 2 args */
  2553. XLVAL xsendmsg2(obj,sym,arg1,arg2) /*Created 91Jun16jsp*/
  2554. XLVAL obj,sym,arg1,arg2;
  2555. X{
  2556. X    return xsendmsgN(obj,sym,2,arg1,arg2,NIL);
  2557. X}
  2558. X/* xsendmsg3 - external entry to send a message to an object, 3 args */
  2559. XLVAL xsendmsg3(obj,sym,arg1,arg2,arg3) /*Created 91Jun16jsp*/
  2560. XLVAL obj,sym,arg1,arg2,arg3;
  2561. X{
  2562. X    return xsendmsgN(obj,sym,3,arg1,arg2,arg3);
  2563. X}
  2564. X
  2565. X/* x_sendmsg - internal entry to send a message to an object */
  2566. XLOCAL LVAL x_sendmsg(obj,cls,sym)
  2567. X  LVAL obj,cls,sym;
  2568. X{
  2569. X    LVAL msg,msgcls,method,val,p;
  2570. X
  2571. X    /* look for the message in the class or superclasses */
  2572. X    for (msgcls = cls; msgcls; ) {
  2573. X
  2574. X    /* lookup the message in this class */
  2575. X    for (p = getivar(msgcls,MESSAGES); p; p = cdr(p))
  2576. X        if ((msg = car(p)) && car(msg) == sym)
  2577. X        goto send_message;
  2578. X
  2579. X    /* look in class's superclass */
  2580. X    msgcls = getivar(msgcls,SUPERCLASS);
  2581. X    }
  2582. X
  2583. X    /* message not found */
  2584. X    xlerror("no method for this message",sym);
  2585. X
  2586. Xsend_message:
  2587. X
  2588. X    /* insert the value for 'self' (overwrites message selector) */
  2589. X    *--xlargv = obj;
  2590. X    ++xlargc;
  2591. X    
  2592. X    /* invoke the method */
  2593. X    if ((method = cdr(msg)) == NULL)
  2594. X    xlerror("bad method",method);
  2595. X    switch (ntype(method)) {
  2596. X    case SUBR:
  2597. X    val = (*getsubr(method))();
  2598. X    break;
  2599. X    case CLOSURE:
  2600. X    if (gettype(method) != s_lambda)
  2601. X        xlerror("bad method",method);
  2602. X    val = evmethod(obj,msgcls,method);
  2603. X    break;
  2604. X    default:
  2605. X    xlerror("bad method",method);
  2606. X    }
  2607. X
  2608. X    /* after creating an object, send it the ":isnew" message */
  2609. X    if (car(msg) == k_new && val) {
  2610. X    xlprot1(val);
  2611. X    x_sendmsg(val,getclass(val),k_isnew);
  2612. X    xlpop();
  2613. X    }
  2614. X    
  2615. X    /* return the result value */
  2616. X    return (val);
  2617. X}
  2618. X
  2619. X/* evmethod - evaluate a method */
  2620. XLOCAL LVAL evmethod(obj,msgcls,method)
  2621. X  LVAL obj,msgcls,method;
  2622. X{
  2623. X    LVAL oldenv,oldfenv,cptr,name,val;
  2624. X    CONTEXT cntxt;
  2625. X
  2626. X    /* protect some pointers */
  2627. X    xlstkcheck(3);
  2628. X    xlsave(oldenv);
  2629. X    xlsave(oldfenv);
  2630. X    xlsave(cptr);
  2631. X
  2632. X    /* create an 'object' stack entry and a new environment frame */
  2633. X    oldenv = xlenv;
  2634. X    oldfenv = xlfenv;
  2635. X    xlenv = cons(cons(obj,msgcls),xlgetenv(method));
  2636. X    xlenv = xlframe(xlenv);
  2637. X    xlfenv = getfenv(method);
  2638. X
  2639. X    /* bind the formal parameters */
  2640. X    xlabind(method,xlargc,xlargv);
  2641. X
  2642. X    /* set up the implicit block */
  2643. X    if (name = getname(method))
  2644. X    xlbegin(&cntxt,CF_RETURN,name);
  2645. X
  2646. X    /* execute the block */
  2647. X    if (name && xlsetjmp(cntxt.c_jmpbuf))
  2648. X    val = xlvalue;
  2649. X    else
  2650. X    for (cptr = getbody(method); consp(cptr); cptr = cdr(cptr))
  2651. X        val = xleval(car(cptr));
  2652. X
  2653. X    /* finish the block context */
  2654. X    if (name)
  2655. X    xlend(&cntxt);
  2656. X
  2657. X    /* restore the environment */
  2658. X    xlenv = oldenv;
  2659. X    xlfenv = oldfenv;
  2660. X
  2661. X    /* restore the stack */
  2662. X    xlpopn(3);
  2663. X
  2664. X    /* return the result value */
  2665. X    return (val);
  2666. X}
  2667. X
  2668. X/* getivcnt - get the number of instance variables for a class */
  2669. Xint getivcnt(cls,ivar)
  2670. X  LVAL cls; int ivar;
  2671. X{
  2672. X    LVAL cnt;
  2673. X    if ((cnt = getivar(cls,ivar)) == NIL || !fixp(cnt))
  2674. X    xlfail("bad value for instance variable count");
  2675. X    return ((int)getfixnum(cnt));
  2676. X}
  2677. X
  2678. X/* listlength - find the length of a list */
  2679. XLOCAL int listlength(list)
  2680. X  LVAL list;
  2681. X{
  2682. X    int len;
  2683. X    for (len = 0; consp(list); len++)
  2684. X    list = cdr(list);
  2685. X    return (len);
  2686. X}
  2687. X
  2688. X/* obsymbols - initialize symbols */
  2689. Xobsymbols()
  2690. X{
  2691. X    /* enter the object related symbols */
  2692. X    s_self  = xlenter("SELF");
  2693. X    k_new   = xlenter(":NEW");
  2694. X    k_isnew = xlenter(":ISNEW");
  2695. X
  2696. X    /* get the Object and Class symbol values */
  2697. X    cls_object = getvalue(xlenter("OBJECT"));
  2698. X    cls_class  = getvalue(xlenter("CLASS"));
  2699. X
  2700. X/* Include hybrid-class functions: *//* JSP */
  2701. X#define MODULE_XLOBJ_C_OBSYMBOLS
  2702. X#include "../../xmodules.h"
  2703. X#undef MODULE_XLOBJ_C_OBSYMBOLS
  2704. X}
  2705. X
  2706. X/* xloinit - object function initialization routine */
  2707. Xxloinit()
  2708. X{
  2709. X    /* create the 'Class' object */
  2710. X    cls_class = xlclass("CLASS",CLASSSIZE);
  2711. X    setelement(cls_class,0,cls_class);
  2712. X
  2713. X    /* create the 'Object' object */
  2714. X    cls_object = xlclass("OBJECT",0);
  2715. X
  2716. X    /* finish initializing 'class' */
  2717. X    setivar(cls_class,SUPERCLASS,cls_object);
  2718. X    xladdivar(cls_class,"IVARTOTAL");    /* ivar number 6 */
  2719. X    xladdivar(cls_class,"IVARCNT");    /* ivar number 5 */
  2720. X    xladdivar(cls_class,"SUPERCLASS");    /* ivar number 4 */
  2721. X    xladdivar(cls_class,"CVALS");    /* ivar number 3 */
  2722. X    xladdivar(cls_class,"CVARS");    /* ivar number 2 */
  2723. X    xladdivar(cls_class,"IVARS");    /* ivar number 1 */
  2724. X    xladdivar(cls_class,"MESSAGES");    /* ivar number 0 */
  2725. X    xladdmsg(cls_class,":NEW",FT_CLNEW);
  2726. X    xladdmsg(cls_class,":ISNEW",FT_CLISNEW);
  2727. X    xladdmsg(cls_class,":ANSWER",FT_CLANSWER);
  2728. X
  2729. X    /* finish initializing 'object' */
  2730. X    setivar(cls_object,SUPERCLASS,NIL);
  2731. X    xladdmsg(cls_object,":ISNEW",FT_OBISNEW);
  2732. X    xladdmsg(cls_object,":CLASS",FT_OBCLASS);
  2733. X    xladdmsg(cls_object,":SHOW",FT_OBSHOW);
  2734. X
  2735. X/* Include hybrid-class functions: *//* JSP */
  2736. X#define MODULE_XLOBJ_C_XLOINIT
  2737. X#include "../../xmodules.h"
  2738. X#undef MODULE_XLOBJ_C_XLOINIT
  2739. X}
  2740. X
  2741. END_OF_FILE
  2742. if test 16437 -ne `wc -c <'src/xlisp/xcore/c/xlobj.c'`; then
  2743.     echo shar: \"'src/xlisp/xcore/c/xlobj.c'\" unpacked with wrong size!
  2744. fi
  2745. # end of 'src/xlisp/xcore/c/xlobj.c'
  2746. fi
  2747. if test -f 'src/xlisp/xcore/c/xlstr.c' -a "${1}" != "-c" ; then 
  2748.   echo shar: Will not clobber existing file \"'src/xlisp/xcore/c/xlstr.c'\"
  2749. else
  2750. echo shar: Extracting \"'src/xlisp/xcore/c/xlstr.c'\" \(15062 characters\)
  2751. sed "s/^X//" >'src/xlisp/xcore/c/xlstr.c' <<'END_OF_FILE'
  2752. X/* -*-C-*-
  2753. X********************************************************************************
  2754. X*
  2755. X* File:         xlstr.c
  2756. X* RCS:          $Header: xlstr.c,v 1.2 89/11/25 05:44:25 mayer Exp $
  2757. X* Description:  xlisp string and character built-in functions
  2758. X* Author:       David Michael Betz
  2759. X* Created:      
  2760. X* Modified:     Sat Nov 25 05:44:13 1989 (Niels Mayer) mayer@hplnpm
  2761. X* Language:     C
  2762. X* Package:      N/A
  2763. X* Status:       X11r4 contrib tape release
  2764. X*
  2765. X* WINTERP 1.0 Copyright 1989 Hewlett-Packard Company (by Niels Mayer).
  2766. X* XLISP version 2.1, Copyright (c) 1989, by David Betz.
  2767. X*
  2768. X* Permission to use, copy, modify, distribute, and sell this software and its
  2769. X* documentation for any purpose is hereby granted without fee, provided that
  2770. X* the above copyright notice appear in all copies and that both that
  2771. X* copyright notice and this permission notice appear in supporting
  2772. X* documentation, and that the name of Hewlett-Packard and David Betz not be
  2773. X* used in advertising or publicity pertaining to distribution of the software
  2774. X* without specific, written prior permission.  Hewlett-Packard and David Betz
  2775. X* make no representations about the suitability of this software for any
  2776. X* purpose. It is provided "as is" without express or implied warranty.
  2777. X*
  2778. X* HEWLETT-PACKARD AND DAVID BETZ DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
  2779. X* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  2780. X* IN NO EVENT SHALL HEWLETT-PACKARD NOR DAVID BETZ BE LIABLE FOR ANY SPECIAL,
  2781. X* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  2782. X* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  2783. X* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  2784. X* PERFORMANCE OF THIS SOFTWARE.
  2785. X*
  2786. X* See ./winterp/COPYRIGHT for information on contacting the authors.
  2787. X* 
  2788. X* Please send modifications, improvements and bugfixes to mayer@hplabs.hp.com
  2789. X* Post XLISP-specific questions/information to the newsgroup comp.lang.lisp.x
  2790. X*
  2791. X********************************************************************************
  2792. X*/
  2793. Xstatic char rcs_identity[] = "@(#)$Header: xlstr.c,v 1.2 89/11/25 05:44:25 mayer Exp $";
  2794. X
  2795. X
  2796. X
  2797. X#include "xlisp.h"
  2798. X
  2799. X/* local definitions */
  2800. X#define fix(n)    cvfixnum((FIXTYPE)(n))
  2801. X#define TLEFT    1
  2802. X#define TRIGHT    2
  2803. X
  2804. X/* external variables */
  2805. Xextern LVAL k_start,k_end,k_1start,k_1end,k_2start,k_2end;
  2806. Xextern LVAL true;
  2807. Xextern char buf[];
  2808. X
  2809. X/* external procedures */
  2810. Xextern char *strcat();
  2811. X
  2812. X/* forward declarations */
  2813. XFORWARD LVAL strcompare();
  2814. XFORWARD LVAL chrcompare();
  2815. XFORWARD LVAL changecase();
  2816. XFORWARD LVAL trim();
  2817. X
  2818. X/* string comparision functions */
  2819. XLVAL xstrlss() { return (strcompare('<',FALSE)); } /* string< */
  2820. XLVAL xstrleq() { return (strcompare('L',FALSE)); } /* string<= */
  2821. XLVAL xstreql() { return (strcompare('=',FALSE)); } /* string= */
  2822. XLVAL xstrneq() { return (strcompare('#',FALSE)); } /* string/= */
  2823. XLVAL xstrgeq() { return (strcompare('G',FALSE)); } /* string>= */
  2824. XLVAL xstrgtr() { return (strcompare('>',FALSE)); } /* string> */
  2825. X
  2826. X/* string comparison functions (not case sensitive) */
  2827. XLVAL xstrilss() { return (strcompare('<',TRUE)); } /* string-lessp */
  2828. XLVAL xstrileq() { return (strcompare('L',TRUE)); } /* string-not-greaterp */
  2829. XLVAL xstrieql() { return (strcompare('=',TRUE)); } /* string-equal */
  2830. XLVAL xstrineq() { return (strcompare('#',TRUE)); } /* string-not-equal */
  2831. XLVAL xstrigeq() { return (strcompare('G',TRUE)); } /* string-not-lessp */
  2832. XLVAL xstrigtr() { return (strcompare('>',TRUE)); } /* string-greaterp */
  2833. X
  2834. X/* strcompare - compare strings */
  2835. XLOCAL LVAL strcompare(fcn,icase)
  2836. X  int fcn,icase;
  2837. X{
  2838. X    int start1,end1,start2,end2,ch1,ch2;
  2839. X    unsigned char *p1,*p2;
  2840. X    LVAL str1,str2;
  2841. X
  2842. X    /* get the strings */
  2843. X    str1 = xlgastring();
  2844. X    str2 = xlgastring();
  2845. X
  2846. X    /* get the substring specifiers */
  2847. X    getbounds(str1,k_1start,k_1end,&start1,&end1);
  2848. X    getbounds(str2,k_2start,k_2end,&start2,&end2);
  2849. X
  2850. X    /* setup the string pointers */
  2851. X    p1 = &getstring(str1)[start1];
  2852. X    p2 = &getstring(str2)[start2];
  2853. X
  2854. X    /* compare the strings */
  2855. X    for (; start1 < end1 && start2 < end2; ++start1,++start2) {
  2856. X    ch1 = *p1++;
  2857. X    ch2 = *p2++;
  2858. X    if (icase) {
  2859. X        if (isupper(ch1)) ch1 = tolower(ch1);
  2860. X        if (isupper(ch2)) ch2 = tolower(ch2);
  2861. X    }
  2862. X    if (ch1 != ch2)
  2863. X        switch (fcn) {
  2864. X        case '<':    return (ch1 < ch2 ? fix(start1) : NIL);
  2865. X        case 'L':    return (ch1 <= ch2 ? fix(start1) : NIL);
  2866. X        case '=':    return (NIL);
  2867. X        case '#':    return (fix(start1));
  2868. X        case 'G':    return (ch1 >= ch2 ? fix(start1) : NIL);
  2869. X        case '>':    return (ch1 > ch2 ? fix(start1) : NIL);
  2870. X        }
  2871. X    }
  2872. X
  2873. X    /* check the termination condition */
  2874. X    switch (fcn) {
  2875. X    case '<':    return (start1 >= end1 && start2 < end2 ? fix(start1) : NIL);
  2876. X    case 'L':    return (start1 >= end1 ? fix(start1) : NIL);
  2877. X    case '=':    return (start1 >= end1 && start2 >= end2 ? true : NIL);
  2878. X    case '#':    return (start1 >= end1 && start2 >= end2 ? NIL : fix(start1));
  2879. X    case 'G':    return (start2 >= end2 ? fix(start1) : NIL);
  2880. X    case '>':    return (start2 >= end2 && start1 < end1 ? fix(start1) : NIL);
  2881. X    }
  2882. X}
  2883. X
  2884. X/* case conversion functions */
  2885. XLVAL xupcase()   { return (changecase('U',FALSE)); }
  2886. XLVAL xdowncase() { return (changecase('D',FALSE)); }
  2887. X
  2888. X/* destructive case conversion functions */
  2889. XLVAL xnupcase()   { return (changecase('U',TRUE)); }
  2890. XLVAL xndowncase() { return (changecase('D',TRUE)); }
  2891. X
  2892. X/* changecase - change case */
  2893. XLOCAL LVAL changecase(fcn,destructive)
  2894. X  int fcn,destructive;
  2895. X{
  2896. X    unsigned char *srcp,*dstp;
  2897. X    int start,end,len,ch,i;
  2898. X    LVAL src,dst;
  2899. X
  2900. X    /* get the string */
  2901. X    src = xlgastring();
  2902. X
  2903. X    /* get the substring specifiers */
  2904. X    getbounds(src,k_start,k_end,&start,&end);
  2905. X    len = getslength(src) - 1;
  2906. X
  2907. X    /* make a destination string */
  2908. X    dst = (destructive ? src : newstring(len+1));
  2909. X
  2910. X    /* setup the string pointers */
  2911. X    srcp = getstring(src);
  2912. X    dstp = getstring(dst);
  2913. X
  2914. X    /* copy the source to the destination */
  2915. X    for (i = 0; i < len; ++i) {
  2916. X    ch = *srcp++;
  2917. X    if (i >= start && i < end)
  2918. X        switch (fcn) {
  2919. X        case 'U':    if (islower(ch)) ch = toupper(ch); break;
  2920. X        case 'D':    if (isupper(ch)) ch = tolower(ch); break;
  2921. X        }
  2922. X    *dstp++ = ch;
  2923. X    }
  2924. X    *dstp = '\0';
  2925. X
  2926. X    /* return the new string */
  2927. X    return (dst);
  2928. X}
  2929. X
  2930. X/* trim functions */
  2931. XLVAL xtrim()      { return (trim(TLEFT|TRIGHT)); }
  2932. XLVAL xlefttrim()  { return (trim(TLEFT)); }
  2933. XLVAL xrighttrim() { return (trim(TRIGHT)); }
  2934. X
  2935. X/* trim - trim character from a string */
  2936. XLOCAL LVAL trim(fcn)
  2937. X  int fcn;
  2938. X{
  2939. X    unsigned char *leftp,*rightp,*dstp;
  2940. X    LVAL bag,src,dst;
  2941. X
  2942. X    /* get the bag and the string */
  2943. X    bag = xlgastring();
  2944. X    src = xlgastring();
  2945. X    xllastarg();
  2946. X
  2947. X    /* setup the string pointers */
  2948. X    leftp = getstring(src);
  2949. X    rightp = leftp + getslength(src) - 2;
  2950. X
  2951. X    /* trim leading characters */
  2952. X    if (fcn & TLEFT)
  2953. X    while (leftp <= rightp && inbag(*leftp,bag))
  2954. X        ++leftp;
  2955. X
  2956. X    /* trim character from the right */
  2957. X    if (fcn & TRIGHT)
  2958. X    while (rightp >= leftp && inbag(*rightp,bag))
  2959. X        --rightp;
  2960. X
  2961. X    /* make a destination string and setup the pointer */
  2962. X    dst = newstring((int)(rightp-leftp+2));
  2963. X    dstp = getstring(dst);
  2964. X
  2965. X    /* copy the source to the destination */
  2966. X    while (leftp <= rightp)
  2967. X    *dstp++ = *leftp++;
  2968. X    *dstp = '\0';
  2969. X
  2970. X    /* return the new string */
  2971. X    return (dst);
  2972. X}
  2973. X
  2974. X/* getbounds - get the start and end bounds of a string */
  2975. XLOCAL getbounds(str,skey,ekey,pstart,pend)
  2976. X  LVAL str,skey,ekey; int *pstart,*pend;
  2977. X{
  2978. X    LVAL arg;
  2979. X    int len;
  2980. X
  2981. X    /* get the length of the string */
  2982. X    len = getslength(str) - 1;
  2983. X
  2984. X    /* get the starting index */
  2985. X    if (xlgkfixnum(skey,&arg)) {
  2986. X    *pstart = (int)getfixnum(arg);
  2987. X    if (*pstart < 0 || *pstart > len)
  2988. X        xlerror("string index out of bounds",arg);
  2989. X    }
  2990. X    else
  2991. X    *pstart = 0;
  2992. X
  2993. X    /* get the ending index */
  2994. X    if (xlgkfixnum(ekey,&arg)) {
  2995. X    *pend = (int)getfixnum(arg);
  2996. X    if (*pend < 0 || *pend > len)
  2997. X        xlerror("string index out of bounds",arg);
  2998. X    }
  2999. X    else
  3000. X    *pend = len;
  3001. X
  3002. X    /* make sure the start is less than or equal to the end */
  3003. X    if (*pstart > *pend)
  3004. X    xlerror("starting index error",cvfixnum((FIXTYPE)*pstart));
  3005. X}
  3006. X
  3007. X/* inbag - test if a character is in a bag */
  3008. XLOCAL int inbag(ch,bag)
  3009. X  int ch; LVAL bag;
  3010. X{
  3011. X    unsigned char *p;
  3012. X    for (p = getstring(bag); *p != '\0'; ++p)
  3013. X    if (*p == ch)
  3014. X        return (TRUE);
  3015. X    return (FALSE);
  3016. X}
  3017. X
  3018. X/* xstrcat - concatenate a bunch of strings */
  3019. XLVAL xstrcat()
  3020. X{
  3021. X    LVAL *saveargv,tmp,val;
  3022. X    unsigned char *str;
  3023. X    int saveargc,len;
  3024. X
  3025. X    /* save the argument list */
  3026. X    saveargv = xlargv;
  3027. X    saveargc = xlargc;
  3028. X
  3029. X    /* find the length of the new string */
  3030. X    for (len = 0; moreargs(); ) {
  3031. X    tmp = xlgastring();
  3032. X    len += (int)getslength(tmp) - 1;
  3033. X    }
  3034. X
  3035. X    /* create the result string */
  3036. X    val = newstring(len+1);
  3037. X    str = getstring(val);
  3038. X
  3039. X    /* restore the argument list */
  3040. X    xlargv = saveargv;
  3041. X    xlargc = saveargc;
  3042. X    
  3043. X    /* combine the strings */
  3044. X    for (*str = '\0'; moreargs(); ) {
  3045. X    tmp = nextarg();
  3046. X    strcat(str,getstring(tmp));
  3047. X    }
  3048. X
  3049. X    /* return the new string */
  3050. X    return (val);
  3051. X}
  3052. X
  3053. X/* xsubseq - return a subsequence */
  3054. XLVAL xsubseq()
  3055. X{
  3056. X    unsigned char *srcp,*dstp;
  3057. X    int start,end,len;
  3058. X    LVAL src,dst;
  3059. X
  3060. X    /* get string and starting and ending positions */
  3061. X    src = xlgastring();
  3062. X
  3063. X    /* get the starting position */
  3064. X    dst = xlgafixnum(); start = (int)getfixnum(dst);
  3065. X    if (start < 0 || start > getslength(src) - 1)
  3066. X    xlerror("string index out of bounds",dst);
  3067. X
  3068. X    /* get the ending position */
  3069. X    if (moreargs()) {
  3070. X    dst = xlgafixnum(); end = (int)getfixnum(dst);
  3071. X    if (end < 0 || end > getslength(src) - 1)
  3072. X        xlerror("string index out of bounds",dst);
  3073. X    }
  3074. X    else
  3075. X    end = getslength(src) - 1;
  3076. X    xllastarg();
  3077. X
  3078. X    /* setup the source pointer */
  3079. X    srcp = getstring(src) + start;
  3080. X    len = end - start;
  3081. X
  3082. X    /* make a destination string and setup the pointer */
  3083. X    dst = newstring(len+1);
  3084. X    dstp = getstring(dst);
  3085. X
  3086. X    /* copy the source to the destination */
  3087. X    while (--len >= 0)
  3088. X    *dstp++ = *srcp++;
  3089. X    *dstp = '\0';
  3090. X
  3091. X    /* return the substring */
  3092. X    return (dst);
  3093. X}
  3094. X
  3095. X/* xstring - return a string consisting of a single character */
  3096. XLVAL xstring()
  3097. X{
  3098. X    LVAL arg;
  3099. X
  3100. X    /* get the argument */
  3101. X    arg = xlgetarg();
  3102. X    xllastarg();
  3103. X
  3104. X    /* make sure its not NIL */
  3105. X    if (null(arg))
  3106. X    xlbadtype(arg);
  3107. X
  3108. X    /* check the argument type */
  3109. X    switch (ntype(arg)) {
  3110. X    case STRING:
  3111. X    return (arg);
  3112. X    case SYMBOL:
  3113. X    return (getpname(arg));
  3114. X    case CHAR:
  3115. X    buf[0] = (int)getchcode(arg);
  3116. X    buf[1] = '\0';
  3117. X    return (cvstring(buf));
  3118. X    default:
  3119. X    xlbadtype(arg);
  3120. X    }
  3121. X}
  3122. X
  3123. X/* xchar - extract a character from a string */
  3124. XLVAL xchar()
  3125. X{
  3126. X    LVAL str,num;
  3127. X    int n;
  3128. X
  3129. X    /* get the string and the index */
  3130. X    str = xlgastring();
  3131. X    num = xlgafixnum();
  3132. X    xllastarg();
  3133. X
  3134. X    /* range check the index */
  3135. X    if ((n = (int)getfixnum(num)) < 0 || n >= getslength(str) - 1)
  3136. X    xlerror("index out of range",num);
  3137. X
  3138. X    /* return the character */
  3139. X    return (cvchar(getstring(str)[n]));
  3140. X}
  3141. X
  3142. X/* xcharint - convert an integer to a character */
  3143. XLVAL xcharint()
  3144. X{
  3145. X    LVAL arg;
  3146. X    arg = xlgachar();
  3147. X    xllastarg();
  3148. X    return (cvfixnum((FIXTYPE)getchcode(arg)));
  3149. X}
  3150. X
  3151. X/* xintchar - convert a character to an integer */
  3152. XLVAL xintchar()
  3153. X{
  3154. X    LVAL arg;
  3155. X    arg = xlgafixnum();
  3156. X    xllastarg();
  3157. X    return (cvchar((int)getfixnum(arg)));
  3158. X}
  3159. X
  3160. X/* xuppercasep - built-in function 'upper-case-p' */
  3161. XLVAL xuppercasep()
  3162. X{
  3163. X    int ch;
  3164. X    ch = getchcode(xlgachar());
  3165. X    xllastarg();
  3166. X    return (isupper(ch) ? true : NIL);
  3167. X}
  3168. X
  3169. X/* xlowercasep - built-in function 'lower-case-p' */
  3170. XLVAL xlowercasep()
  3171. X{
  3172. X    int ch;
  3173. X    ch = getchcode(xlgachar());
  3174. X    xllastarg();
  3175. X    return (islower(ch) ? true : NIL);
  3176. X}
  3177. X
  3178. X/* xbothcasep - built-in function 'both-case-p' */
  3179. XLVAL xbothcasep()
  3180. X{
  3181. X    int ch;
  3182. X    ch = getchcode(xlgachar());
  3183. X    xllastarg();
  3184. X    return (isupper(ch) || islower(ch) ? true : NIL);
  3185. X}
  3186. X
  3187. X/* xdigitp - built-in function 'digit-char-p' */
  3188. XLVAL xdigitp()
  3189. X{
  3190. X    int ch;
  3191. X    ch = getchcode(xlgachar());
  3192. X    xllastarg();
  3193. X    return (isdigit(ch) ? cvfixnum((FIXTYPE)(ch - '0')) : NIL);
  3194. X}
  3195. X
  3196. X/* xcharcode - built-in function 'char-code' */
  3197. XLVAL xcharcode()
  3198. X{
  3199. X    int ch;
  3200. X    ch = getchcode(xlgachar());
  3201. X    xllastarg();
  3202. X    return (cvfixnum((FIXTYPE)ch));
  3203. X}
  3204. X
  3205. X/* xcodechar - built-in function 'code-char' */
  3206. XLVAL xcodechar()
  3207. X{
  3208. X    LVAL arg;
  3209. X    int ch;
  3210. X    arg = xlgafixnum(); ch = getfixnum(arg);
  3211. X    xllastarg();
  3212. X    return (ch >= 0 && ch <= 127 ? cvchar(ch) : NIL);
  3213. X}
  3214. X
  3215. X/* xchupcase - built-in function 'char-upcase' */
  3216. XLVAL xchupcase()
  3217. X{
  3218. X    LVAL arg;
  3219. X    int ch;
  3220. X    arg = xlgachar(); ch = getchcode(arg);
  3221. X    xllastarg();
  3222. X    return (islower(ch) ? cvchar(toupper(ch)) : arg);
  3223. X}
  3224. X
  3225. X/* xchdowncase - built-in function 'char-downcase' */
  3226. XLVAL xchdowncase()
  3227. X{
  3228. X    LVAL arg;
  3229. X    int ch;
  3230. X    arg = xlgachar(); ch = getchcode(arg);
  3231. X    xllastarg();
  3232. X    return (isupper(ch) ? cvchar(tolower(ch)) : arg);
  3233. X}
  3234. X
  3235. X/* xdigitchar - built-in function 'digit-char' */
  3236. XLVAL xdigitchar()
  3237. X{
  3238. X    LVAL arg;
  3239. X    int n;
  3240. X    arg = xlgafixnum(); n = getfixnum(arg);
  3241. X    xllastarg();
  3242. X    return (n >= 0 && n <= 9 ? cvchar(n + '0') : NIL);
  3243. X}
  3244. X
  3245. X/* xalphanumericp - built-in function 'alphanumericp' */
  3246. XLVAL xalphanumericp()
  3247. X{
  3248. X    int ch;
  3249. X    ch = getchcode(xlgachar());
  3250. X    xllastarg();
  3251. X    return (isupper(ch) || islower(ch) || isdigit(ch) ? true : NIL);
  3252. X}
  3253. X
  3254. X/* character comparision functions */
  3255. XLVAL xchrlss() { return (chrcompare('<',FALSE)); } /* char< */
  3256. XLVAL xchrleq() { return (chrcompare('L',FALSE)); } /* char<= */
  3257. XLVAL xchreql() { return (chrcompare('=',FALSE)); } /* char= */
  3258. XLVAL xchrneq() { return (chrcompare('#',FALSE)); } /* char/= */
  3259. XLVAL xchrgeq() { return (chrcompare('G',FALSE)); } /* char>= */
  3260. XLVAL xchrgtr() { return (chrcompare('>',FALSE)); } /* char> */
  3261. X
  3262. X/* character comparision functions (case insensitive) */
  3263. XLVAL xchrilss() { return (chrcompare('<',TRUE)); } /* char-lessp */
  3264. XLVAL xchrileq() { return (chrcompare('L',TRUE)); } /* char-not-greaterp */
  3265. XLVAL xchrieql() { return (chrcompare('=',TRUE)); } /* char-equalp */
  3266. XLVAL xchrineq() { return (chrcompare('#',TRUE)); } /* char-not-equalp */
  3267. XLVAL xchrigeq() { return (chrcompare('G',TRUE)); } /* char-not-lessp */
  3268. XLVAL xchrigtr() { return (chrcompare('>',TRUE)); } /* char-greaterp */
  3269. X
  3270. X/* chrcompare - compare characters */
  3271. XLOCAL LVAL chrcompare(fcn,icase)
  3272. X  int fcn,icase;
  3273. X{
  3274. X    int ch1,ch2,icmp;
  3275. X    LVAL arg;
  3276. X    
  3277. X    /* get the characters */
  3278. X    arg = xlgachar(); ch1 = getchcode(arg);
  3279. X
  3280. X    /* convert to lowercase if case insensitive */
  3281. X    if (icase && isupper(ch1))
  3282. X    ch1 = tolower(ch1);
  3283. X
  3284. X    /* handle each remaining argument */
  3285. X    for (icmp = TRUE; icmp && moreargs(); ch1 = ch2) {
  3286. X
  3287. X    /* get the next argument */
  3288. X    arg = xlgachar(); ch2 = getchcode(arg);
  3289. X
  3290. X    /* convert to lowercase if case insensitive */
  3291. X    if (icase && isupper(ch2))
  3292. X        ch2 = tolower(ch2);
  3293. X
  3294. X    /* compare the characters */
  3295. X    switch (fcn) {
  3296. X    case '<':    icmp = (ch1 < ch2); break;
  3297. X    case 'L':    icmp = (ch1 <= ch2); break;
  3298. X    case '=':    icmp = (ch1 == ch2); break;
  3299. X    case '#':    icmp = (ch1 != ch2); break;
  3300. X    case 'G':    icmp = (ch1 >= ch2); break;
  3301. X    case '>':    icmp = (ch1 > ch2); break;
  3302. X    }
  3303. X    }
  3304. X
  3305. X    /* return the result */
  3306. X    return (icmp ? true : NIL);
  3307. X}
  3308. X
  3309. END_OF_FILE
  3310. if test 15062 -ne `wc -c <'src/xlisp/xcore/c/xlstr.c'`; then
  3311.     echo shar: \"'src/xlisp/xcore/c/xlstr.c'\" unpacked with wrong size!
  3312. fi
  3313. # end of 'src/xlisp/xcore/c/xlstr.c'
  3314. fi
  3315. echo shar: End of archive 7 \(of 16\).
  3316. cp /dev/null ark7isdone
  3317. MISSING=""
  3318. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  3319.     if test ! -f ark${I}isdone ; then
  3320.     MISSING="${MISSING} ${I}"
  3321.     fi
  3322. done
  3323. if test "${MISSING}" = "" ; then
  3324.     echo You have unpacked all 16 archives.
  3325.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  3326. else
  3327.     echo You still need to unpack the following archives:
  3328.     echo "        " ${MISSING}
  3329. fi
  3330. ##  End of shell archive.
  3331. exit 0
  3332.