home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume14 / sharedmem / part02 < prev    next >
Encoding:
Internet Message Format  |  1988-05-17  |  54.9 KB

  1. Subject:  v14i095:  Shared memory emulation for 4.2BSD, Part02/04
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: libes@cme-durer.ARPA (Don Libes)
  7. Posting-number: Volume 14, Issue 95
  8. Archive-name: sharedmem/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 2 (of 4)."
  17. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  18. if test -f 'src/Luser.c' -a "${1}" != "-c" ; then 
  19.   echo shar: Will not clobber existing file \"'src/Luser.c'\"
  20. else
  21. echo shar: Extracting \"'src/Luser.c'\" \(2973 characters\)
  22. sed "s/^X//" >'src/Luser.c' <<'END_OF_FILE'
  23. X/*
  24. X
  25. XThese are the Lisp covering functions for the common memory system.
  26. X
  27. XThey are:
  28. X
  29. Xint Lcm_init(process_name,host,debug_level)
  30. Xvoid Lcm_exit()
  31. Xcm_variable *Lcm_declare(name,role)
  32. Xvoid Lcm_undeclare(var)
  33. Xint Lcm_sync(wait)
  34. Xvoid Lcm_set_value(var,val)
  35. Xvoid Lcm_get_value(var,val)
  36. Xint Lcm_set_new_command_value(command_out,command_value)
  37. Xint Lcm_new_command_pending(input_command)
  38. Xint Lcm_get_new_command_value(input_command,cm_value)
  39. Xint Lcm_status_equal(command_out,status_in,status_value)
  40. Xint Lcm_status_synchronized(command_out,status_in)
  41. Xvoid cm_set_status_value(status_out,status_value)
  42. Xvoid Lcm_print_variable(name)
  43. X*/
  44. X
  45. X#include <stdio.h>
  46. X#include <sys/time.h>
  47. X#include "global.h"    /* comes from /usr/local/include/franz */
  48. X#include "cm_constants.h"
  49. X#include "cm_sd.h"
  50. X#include "cm_var.h"
  51. X#include "cm_interface.h"
  52. X
  53. X#define MAXSTRLEN    1500    /* ugh */
  54. X
  55. Xlispval
  56. XLcm_init(name,host,debug_level)
  57. Xchar *name;
  58. Xchar *host;
  59. Xint *debug_level;
  60. X{
  61. X    return(inewint(cm_init(name,host,*debug_level)));
  62. X}
  63. X
  64. Xvoid
  65. XLcm_exit()
  66. X{
  67. X    cm_exit();
  68. X}
  69. X
  70. Xcm_variable *
  71. XLcm_declare(name,role)
  72. Xchar *name;
  73. Xlong int *role;
  74. X{
  75. X    cm_variable *p;
  76. X
  77. X    p = cm_declare(name,(unsigned)*role);
  78. X    eprintf(10,"cm_declare() = %x\n",p);
  79. X    return(p);
  80. X}
  81. X
  82. Xvoid
  83. XLcm_undeclare(var)
  84. Xint *var;
  85. X{
  86. X    cm_undeclare(*var);
  87. X}
  88. X
  89. Xint
  90. XLcm_sync(wait)
  91. Xlong int *wait;
  92. X{
  93. X    return(cm_sync((int)*wait));
  94. X}
  95. X
  96. Xvoid
  97. XLcm_set_value(var,val)
  98. Xint *var;
  99. Xlispval val;        /* was union structured_data **val; */
  100. X{
  101. X/*
  102. Xprintf("entering Lcm_set_value\n"); fflush(stdout);
  103. Xprintf("value is <%s>\n",(char *)val); fflush(stdout);
  104. Xprintf("var is %x\n",var); fflush(stdout);
  105. Xprintf("*var is %x\n",*var); fflush(stdout);
  106. Xprintf("**var is %x\n",*(int *)*var); fflush(stdout);
  107. X*/
  108. X    cm_set_value(*var,(char *)val);
  109. X}
  110. X
  111. X/* note this new version will not correctly return anything but 
  112. Xstructured_data objects!!! */
  113. Xvoid
  114. XLcm_get_value(var,val)
  115. Xcm_variable **var;
  116. Xlispval val;
  117. X{
  118. X    cm_get_value(*var,(char *)val);
  119. X}
  120. X
  121. Xint
  122. XLcm_set_new_command_value(var,val)
  123. Xcm_variable **var;
  124. Xunion structured_data **val;
  125. X{
  126. X    cm_set_new_command_value(*var,*val);
  127. X}
  128. X
  129. Xint
  130. XLcm_new_command_pending(cmd)
  131. Xcm_command_variable *cmd;
  132. X{
  133. X    return(cm_new_command_pending(*cmd));
  134. X}
  135. X
  136. Xint
  137. XLcm_get_new_command_value(cmd,val)
  138. Xcm_command_variable *cmd;
  139. Xunion structured_data **val;
  140. X{
  141. X    return(cm_get_new_command_value(*cmd,*val));
  142. X}
  143. X
  144. Xint
  145. XLcm_status_equal(cmd,status_in,status_val)
  146. Xcm_command_variable *cmd;
  147. Xcm_status_variable **status_in;
  148. Xunion structured_data **status_val;
  149. X{
  150. X    return(cm_status_equal(*cmd,*status_in,*status_val));
  151. X}
  152. X
  153. Xint
  154. XLcm_status_synchronized(command_out,status_in)
  155. Xcm_command_variable *command_out;
  156. Xcm_status_variable **status_in;
  157. X{
  158. X    return(cm_status_synchronized(*command_out,*status_in));
  159. X}
  160. X
  161. Xvoid
  162. XLcm_set_status_value(command_in,status_out,status_value)
  163. Xcm_command_variable **command_in;
  164. Xcm_status_variable **status_out;
  165. Xunion structured_data **status_value;
  166. X{
  167. X    cm_set_status_value(*command_in,*status_out,*status_value);
  168. X}
  169. X
  170. Xvoid
  171. XLcm_print_variable(name)
  172. Xchar *name;
  173. X{
  174. X    cm_print_variable(name);
  175. X}
  176. END_OF_FILE
  177. if test 2973 -ne `wc -c <'src/Luser.c'`; then
  178.     echo shar: \"'src/Luser.c'\" unpacked with wrong size!
  179. fi
  180. # end of 'src/Luser.c'
  181. fi
  182. if test -f 'src/Makefile' -a "${1}" != "-c" ; then 
  183.   echo shar: Will not clobber existing file \"'src/Makefile'\"
  184. else
  185. echo shar: Extracting \"'src/Makefile'\" \(4756 characters\)
  186. sed "s/^X//" >'src/Makefile' <<'END_OF_FILE'
  187. XMAN.C=man.c man_get_slot.c man_put_slot.c
  188. XMAN.O=man.o man_get_slot.o man_put_slot.o
  189. XCOMMON.C=put_slot.c name.c cm_time.c cm_sd.c msg.c cm_util.c
  190. XCOMMON.O=put_slot.o name.o cm_time.o cm_sd.o msg.o cm_util.o
  191. XUSER.C=usr_var.c usr_get_slot.c usr_put_slot.c cm_usr1.c cm_usr2.c
  192. XUSER.O=usr_var.o usr_get_slot.o usr_put_slot.o cm_usr1.o cm_usr2.o
  193. XLUSER.C=Luser.c
  194. XLUSER.O=Luser.o
  195. XLIBS=/usr/local/lib/libstream.a
  196. XCMLIB=libcm.a
  197. XMBLIB=/usr/local/lib/mailbox.o
  198. XLINCLUDE=/usr/local/include
  199. XCFLAGS=-g -I$(LINCLUDE)/inet/stream -Ifranz -DCMM_VERSION=7
  200. XLINTFLAGS=-I$(LINCLUDE)/inet/stream -Ifranz -DCMM_VERSION=7
  201. XHFILES=cm.h cm_bytestuff.h cm_constants.h cm_interface.h cm_man.h cm_msg.h \
  202. X    cm_sd.h cm_slot.h cm_sync.h cm_time.h cm_var.h
  203. XLISPHFILES=config.h dfuncs.h global.h lconf.h lstructs.h ltypes.h\
  204. X    module.h public.h sigtab.h
  205. X
  206. X# demonstrate various cm_sync options
  207. XEXAMPLE1=client1a client1b server1y server1z
  208. X
  209. X# demonstrate passing various C types (in a machine-dependent way)
  210. XEXAMPLE2=client2 server2
  211. X
  212. X# demonstrate AMRF-style mailboxes in c & Lisp
  213. X# some names are in uppercase to accomodate the outside world (nip, vax cmm)
  214. X# non-NBS people should ignore this example
  215. X# EXAMPLE6=client6 server6
  216. X
  217. X# provoke bad user behavior
  218. X# 8a is a reader that never reads its input
  219. X# 8b is designed to have a high probability of exiting while cmm is writing
  220. X# to it, thereby signalling the cmm with a SIGPIPE 
  221. XEXAMPLE8=client8 server8a server8b
  222. X
  223. Xnormal: $(CMLIB) $(LUSER.O)
  224. X
  225. Xcleanup:
  226. X    rm $(MAN.O) $(COMMON.O) $(LUSER.O) $(CMLIB)
  227. X
  228. Xinstall: $(CMLIB) $(LUSER.O) makedirs
  229. X    cp cmm /usr/local/bin
  230. X    cp $(HFILES) /usr/local/include/cm
  231. X    sh -c 'cd franz;cp `echo *` /usr/local/include/franz'
  232. X    cp $(CMLIB) $(LUSER.O) /usr/local/lib
  233. X    cp cm.lisp /usr/local/lisp
  234. X
  235. Xshar:
  236. X    ls franz > shar-input
  237. X    cat shar-input | sed 's/^/franz\//' > tmp
  238. X    ls Makefile README $(HFILES) $(MAN.C) $(COMMON.C) $(USER.C) \
  239. X        server1z.c server1y.c client1a.c client1b.c \
  240. X        server2.c client2.c server8a.c server8b.c client8.c \
  241. X        $(LUSER.C) cm.lisp  >> tmp
  242. X    cat tmp | sed 's/^/src\//' > shar-input
  243. X
  244. Xmakedirs: /usr/local/include/cm /usr/local/include/franz /usr/local/lisp
  245. X
  246. X/usr/local/lisp:
  247. X    mkdir /usr/local/lisp
  248. X
  249. X/usr/local/include/cm:
  250. X    mkdir /usr/local/include/cm
  251. X
  252. X/usr/local/include/franz:
  253. X    mkdir /usr/local/include/franz
  254. X
  255. Xvws: Lvws.o vws.o $(USER.O) $(COMMON.O) $(CMLIB)
  256. X    cc $(CFLAGS) -o vws vws.o $(MBLIB) $(CMLIB) $(LIBS)
  257. X
  258. Xlint: lintcmm lintuser
  259. X
  260. Xlintc:
  261. X    lint -Ccm $(USER.C) $(COMMON.C) -lstream
  262. X
  263. Xexamples: $(LUSER.O) $(EXAMPLE1) $(EXAMPLE2) $(EXAMPLE6) $(EXAMPLE8)
  264. X
  265. X$(CMLIB): cmm $(MAN.O) $(USER.O) $(COMMON.O)
  266. X    ar cr $(CMLIB) `lorder $(USER.O) $(COMMON.O) | tsort`
  267. X    ranlib $(CMLIB)
  268. X
  269. Xserver1z: server1z.o $(USER.O) $(COMMON.O) $(CMLIB)
  270. X    cc $(CFLAGS) -o server1z server1z.o $(CMLIB) $(LIBS)
  271. X
  272. Xserver1y: server1y.o $(USER.O) $(COMMON.O) $(CMLIB)
  273. X    cc $(CFLAGS) -o server1y server1y.o $(CMLIB) $(LIBS)
  274. X
  275. Xclient1a: client1a.o $(USER.O) $(COMMON.O) $(CMLIB)
  276. X    cc $(CFLAGS) -o client1a client1a.o $(CMLIB) $(LIBS)
  277. X
  278. Xclient1b: client1b.o $(USER.O) $(COMMON.O) $(CMLIB)
  279. X    cc $(CFLAGS) -o client1b client1b.o $(CMLIB) $(LIBS)
  280. X
  281. Xserver2: server2.o $(USER.O) $(COMMON.O) $(CMLIB)
  282. X    cc $(CFLAGS) -o server2 server2.o $(CMLIB) $(LIBS)
  283. X
  284. Xclient2: client2.o $(USER.O) $(COMMON.O) $(CMLIB)
  285. X    cc $(CFLAGS) -o client2 client2.o $(CMLIB) $(LIBS)
  286. X
  287. Xclient6: client6.o $(USER.O) $(COMMON.O) $(CMLIB)
  288. X    cc $(CFLAGS) -o client6 client6.o $(MBLIB) $(CMLIB) $(LIBS)
  289. X
  290. Xserver6: server6.o $(USER.O) $(COMMON.O) $(CMLIB)
  291. X    cc $(CFLAGS) -o server6 server6.c $(MBLIB) $(CMLIB) $(LIBS)
  292. X
  293. Xclient8: client8.o $(USER.O) $(COMMON.O) $(CMLIB)
  294. X    cc $(CFLAGS) -o client8 client8.c $(CMLIB) $(LIBS)
  295. X
  296. Xserver8a: server8a.o $(USER.O) $(COMMON.O) $(CMLIB)
  297. X    cc $(CFLAGS) -o server8a server8a.c $(CMLIB) $(LIBS)
  298. X
  299. Xserver8b: server8b.o $(USER.O) $(COMMON.O) $(CMLIB)
  300. X    cc $(CFLAGS) -o server8b server8b.c $(CMLIB) $(LIBS)
  301. X
  302. Xcmm: $(MAN.O) $(COMMON.O)
  303. X    cc $(CFLAGS) -o cmm $(MAN.O) $(COMMON.O) $(LIBS)
  304. X
  305. Xlintcmm:
  306. X    lint $(LINTFLAGS) $(MAN.C) $(COMMON.C) -lstream | tee cmm.lint
  307. X
  308. Xlintuser:
  309. X    lint -u $(LINTFLAGS) $(USER.C) $(COMMON.C) -lstream | tee user.lint
  310. X
  311. XLuser.o: cm_constants.h cm_sd.h cm_var.h cm_interface.h
  312. X
  313. Xcm_usr1.o: cm_constants.h cm_sd.h cm_interface.h cm_sync.h cm_msg.h cm_slot.h cm_time.h
  314. X
  315. Xcm_usr2.o: cm_constants.h cm_sd.h cm_var.h cm_interface.h
  316. X
  317. Xusr_put_slot.o: cm_bytestuff.h cm_msg.h cm_slot.h cm_interface.h
  318. X
  319. Xmsg.o: cm_constants.h cm_slot.h cm_sd.h cm_msg.h
  320. X
  321. Xput_slot.o: cm_constants.h cm_slot.h cm_sd.h cm_msg.h
  322. X
  323. Xman_get_slot.o: cm_constants.h cm_var.h cm_slot.h cm_man.h cm_sd.h cm_msg.h cm_time.h
  324. X
  325. Xman_put_slot.o: cm_constants.h cm_slot.h cm_sd.h
  326. X
  327. Xman.o: cm_constants.h cm_var.h cm_slot.h cm_time.h cm_man.h cm_sd.h cm_msg.h
  328. X
  329. Xcm_sd.o: cm_sd.h cm_var.h
  330. X
  331. Xusr_get_slot.o: cm_constants.h cm_sd.h cm_interface.h cm_slot.h
  332. X
  333. Xusr_var.o: cm_sd.h cm_interface.h
  334. END_OF_FILE
  335. if test 4756 -ne `wc -c <'src/Makefile'`; then
  336.     echo shar: \"'src/Makefile'\" unpacked with wrong size!
  337. fi
  338. # end of 'src/Makefile'
  339. fi
  340. if test -f 'src/cm_interface.h' -a "${1}" != "-c" ; then 
  341.   echo shar: Will not clobber existing file \"'src/cm_interface.h'\"
  342. else
  343. echo shar: Extracting \"'src/cm_interface.h'\" \(2918 characters\)
  344. sed "s/^X//" >'src/cm_interface.h' <<'END_OF_FILE'
  345. X/* cm_interface.h - interface to common memory
  346. XDefinitions of types used in the handshaking package
  347. X*/
  348. X
  349. X#ifndef TRUE
  350. X#define TRUE        1
  351. X#define FALSE        0
  352. X#endif
  353. X
  354. X#define or        ||
  355. X#define and        &&
  356. X#define OR        ||
  357. X#define AND        &&
  358. X
  359. X#ifndef BOOLEAN
  360. X#define BOOLEAN
  361. Xtypedef int boolean;
  362. X#endif
  363. X
  364. X#define ANY_STATUS        0
  365. X
  366. X/* definitions for command associations */
  367. Xtypedef int cm_command_association;
  368. X#define cm_set_command_association(cmd,assoc) \
  369. X        cmd->command_association = (assoc)
  370. X#define cm_get_command_association(cmd,assoc) \
  371. X        ((assoc) = cmd->command_association)
  372. X/* was        ((*(assoc)) = cmd->command_association) */
  373. Xextern cm_command_association input_command_association;
  374. X
  375. X#define var_in_use(v)    (v->inuse)
  376. X
  377. Xstruct usr_var_role {
  378. X        unsigned reader : 1;
  379. X        unsigned nonxwriter : 1;
  380. X        unsigned xwriter : 1;
  381. X        unsigned wakeup : 1;
  382. X};
  383. X
  384. Xtypedef struct {
  385. X    char name[CM_VARIABLENAMELENGTH];
  386. X    cm_value data;    /* actual user data */
  387. X    struct usr_var_role role;
  388. X    unsigned long old_count;    /* when last read */
  389. X    unsigned long count;        /* nth definition of this var */
  390. X                    /* zero means "never been written" */
  391. X
  392. X                    /* the following are tags noting: */
  393. X    int old_command_association;    /* when last read */
  394. X    int command_association;    /* unique identifier tieing this to a
  395. X                       single command and multiple
  396. X                       statii */
  397. X    struct timeval timestamp;    /* when this data was written */
  398. X    /* the following is not transmitted to the cmm */
  399. X    struct {
  400. X        unsigned declared    : 1;
  401. X        unsigned written     : 1;
  402. X        unsigned inuse        : 1;
  403. X        unsigned undeclared    : 1;
  404. X    } status;
  405. X} cm_variable, cm_command_variable, cm_status_variable;
  406. X
  407. X/* the following definitions are correctly eaten by the C compiler */
  408. Xcm_value *cm_get_value();
  409. Xvoid cm_set_value();
  410. Xboolean cm_get_new_command_value();
  411. Xvoid cm_set_new_command_value();
  412. Xboolean cm_new_command_pendingp();
  413. X/* if these remain as macros, the C preprocessor no longer cares for */
  414. X/* these lines */
  415. X/*cm_command_association cm_get_command_association();*/
  416. X/*cm_set_command_association cm_command_association();*/
  417. Xboolean cm_status_equal();
  418. Xboolean cm_status_synchronizedp();
  419. Xvoid cm_set_status_value();
  420. Xcm_variable *cm_declare();
  421. Xcm_variable *next_user_variable();
  422. X
  423. X#define cm_command_association int
  424. X
  425. X/*    
  426. XFunctions used in the handshaking package
  427. X
  428. XThis is a list of definitions that includes arguments which the current C
  429. Xcompilers do not care for.
  430. X
  431. Xcm_get_value(cm_variable,cm_value)
  432. Xcm_set_value(cm_variable,cm_value)
  433. Xboolean cm_get_new_command_value(cm_variable,value)
  434. Xcm_set_new_command_value(cm_variable,value)
  435. Xboolean cm_new_command_pending?(cm_variable)
  436. Xcm_command_association cm_get_command_association(cm_variable,
  437. X    command_association)
  438. Xcm_set_command_association cm_command_association(cm_variable,
  439. X    command_association)
  440. Xboolean cm_status_equal(command_variable,status_variable,status_value)
  441. Xboolean cm_status_synchronized(command_variable,status_variable)
  442. Xcm_set_status_value(status_variable,cm_value)
  443. X
  444. X*/
  445. X
  446. END_OF_FILE
  447. if test 2918 -ne `wc -c <'src/cm_interface.h'`; then
  448.     echo shar: \"'src/cm_interface.h'\" unpacked with wrong size!
  449. fi
  450. # end of 'src/cm_interface.h'
  451. fi
  452. if test -f 'src/cm_sd.c' -a "${1}" != "-c" ; then 
  453.   echo shar: Will not clobber existing file \"'src/cm_sd.c'\"
  454. else
  455. echo shar: Extracting \"'src/cm_sd.c'\" \(3111 characters\)
  456. sed "s/^X//" >'src/cm_sd.c' <<'END_OF_FILE'
  457. X/* cm_sd.c 
  458. Xstructured data functions
  459. X
  460. XThese functions will be used by the user when doing cm_set_value's
  461. X
  462. Xi.e.  cm_set_value(variable,value)
  463. X
  464. XThese will also be used when sending/receiving values to/from the cmm.
  465. X
  466. Xcm_sd_to_flat(sd,flat)
  467. Xcm_flat_to_sd(flat,sd)
  468. Xcm_sd_copy(from,to)
  469. Xcm_sd_clear(sd)            - clear initially
  470. Xcm_sd_free(sd)            - release old storage and clear
  471. Xcm_sd_equal(value1,value2)    - returns true if value1 == value2
  472. X
  473. X*/
  474. X
  475. X#include <stdio.h>
  476. X#include <strings.h>
  477. X#include "cm_sd.h"
  478. X#include "cm_var.h"
  479. X
  480. X#define min(x,y)    (((x)<(y))?(x):(y))
  481. X
  482. X#define TRUE 1
  483. X#define FALSE 0
  484. X
  485. Xchar *malloc();
  486. X
  487. Xstatic int ssresize();
  488. X
  489. X/* return 0 if success, negative if failure */
  490. Xint
  491. Xcm_sd_copy(from,to)
  492. Xcm_value *from;
  493. Xcm_value *to;
  494. X{
  495. X    if (from->data == 0) {
  496. X        /* can happen if read before set */
  497. X        to->size = 0;
  498. X        return(0);
  499. X    }
  500. X
  501. X    if (0 > ssresize(to,from->size)) return(-1);
  502. X    /* if not mallocable, it is possible to->msize < from->size */
  503. X    to->size = min(from->size,to->msize);
  504. X
  505. X    /* if user supplied us with 0 size, then to->data may still == 0,
  506. X    /* so, don't call safebcopy which checks for zero pointers */
  507. X    if (to->data != 0) {
  508. X        safebcopy(from->data,to->data,to->size);
  509. X    } /* else to->size = 0; */
  510. X    return(0);
  511. X}
  512. X
  513. X/* convert sd style data to flattened out data - ready for transmission */
  514. X/* return size of flattened result */
  515. Xint
  516. Xcm_sd_to_flat(sd,f)
  517. Xstruct cm_value *sd;
  518. Xstruct cm_flattened_data *f;
  519. X{
  520. X    safebcopy(sd->data,f->data,sd->size);
  521. X    f->size = sd->size;
  522. X    return(sd->size + sizeof(f->size));
  523. X}
  524. X
  525. X/* convert transmitted data to sd style data - ready for local storage */
  526. X/* return 0 if ok, negative if problems */
  527. Xint
  528. Xcm_flat_to_sd(f,sd)
  529. Xstruct cm_flattened_data *f;
  530. Xcm_value *sd;
  531. X{
  532. X    if (0 > ssresize(sd,f->size)) return(-1);
  533. X
  534. X    sd->size = min(f->size,sd->msize);
  535. X
  536. X    if (sd->data != NULL) {
  537. X        /* if user supplied us with zero-size, then */
  538. X        /* sd->...size may still equal zero, so don't call */
  539. X        /* safebcopy which may check for zero pointers. */
  540. X        safebcopy(f->data,sd->data,sd->size);
  541. X    }
  542. X
  543. X    return(0);
  544. X}
  545. X
  546. X/* resize that takes short ints */
  547. X/* return 0 if resize succeeded or not mallocable */
  548. X/* return -1 if resize failed */
  549. Xstatic int
  550. Xssresize(s,newsize)
  551. Xcm_value *s;
  552. Xint newsize;
  553. X{
  554. X    if (!s->mallocable) return(0);
  555. X
  556. X    eprintf(9,"ssresize(data:%x,old:%x,new:%x)  ",s->data,s->msize,newsize);
  557. X    if (s->msize >= newsize) {
  558. X        eprintf(9,"msize >= newsize\n");
  559. X        return(0);
  560. X    }
  561. X    if (s->data != NULL) {
  562. X        eprintf(9,"free(data)");
  563. X        free(s->data);
  564. X    }
  565. X    eprintf(9,"  malloc(%x)",newsize);
  566. X    if (NULL == (s->data = malloc((unsigned int)newsize))) {
  567. X        fprintf(stderr,"resized failed! - out of space\n");
  568. X        s->msize = s->size = 0;
  569. X        return(-1);
  570. X    } else s->msize = newsize;
  571. X    return(0);
  572. X}
  573. X
  574. X/* zero the various fields in the sd structures */
  575. Xcm_sd_clear(sd)
  576. Xcm_value *sd;
  577. X{
  578. X    sd->msize = 0;
  579. X    sd->size = 0;
  580. X    sd->data = NULL;
  581. X    sd->mallocable = TRUE;
  582. X}
  583. X
  584. Xcm_sd_free(sd)
  585. Xcm_value *sd;
  586. X{
  587. X    if (!sd->mallocable) {
  588. X        fprintf(stderr,"cm_sd_free() called on nonmallocable object?\n");
  589. X        return;
  590. X    }
  591. X
  592. X    free(sd->data);
  593. X    cm_sd_clear(sd);
  594. X}
  595. X
  596. Xint
  597. Xcm_sd_equal(x,y)
  598. Xstruct cm_value *x, *y;
  599. X{
  600. X    return(bcmp(x->data,y->data,x->size));
  601. X}
  602. END_OF_FILE
  603. if test 3111 -ne `wc -c <'src/cm_sd.c'`; then
  604.     echo shar: \"'src/cm_sd.c'\" unpacked with wrong size!
  605. fi
  606. # end of 'src/cm_sd.c'
  607. fi
  608. if test -f 'src/cm_slot.h' -a "${1}" != "-c" ; then 
  609.   echo shar: Will not clobber existing file \"'src/cm_slot.h'\"
  610. else
  611. echo shar: Extracting \"'src/cm_slot.h'\" \(3894 characters\)
  612. sed "s/^X//" >'src/cm_slot.h' <<'END_OF_FILE'
  613. X/*
  614. X
  615. XThis file contains definitions relating to message passing between
  616. Xthe CM manager and user.
  617. X
  618. XSlots types are
  619. X*/
  620. X
  621. X#define CM_SLOT_NULL        0
  622. X#define CM_SLOT_DECLARE        1
  623. X#define CM_SLOT_WRITE        2
  624. X#define CM_SLOT_READ        3
  625. X#define CM_SLOT_READ_RESPONSE    4
  626. X#define CM_SLOT_ERROR        6
  627. X#define CM_SLOT_UNDECLARE        7
  628. X
  629. X/* slot handling errors */
  630. X#define E_CM_SLOT_OK                0
  631. X#define E_CM_GET_SLOT_UNKNOWN_SLOT_TYPE        -1
  632. X#define E_CM_GET_SLOT_GET_VARIABLE        -2
  633. X#define E_CM_GET_SLOT_FLAT_TO_SD        -3
  634. X#define E_CM_GET_SLOT_BAD_INUSE            -4    /* we have received a
  635. X        /* declaration, declared it, and yet it ended up with
  636. X        /* no readers or writers? */
  637. X
  638. X/* semantic user errors */
  639. X#define E_CM_DECLARE_CANT_GET_XWRITE_ACCESS    -4
  640. X#define E_CM_DECLARE_GET_VARIABLE_NO_SPACE        -6
  641. X
  642. X#define E_CM_WRITE_NOT_DECLARED_YET        -7
  643. X#define E_CM_WRITE_NOT_WRITER            -8
  644. X
  645. X#define E_CM_READ_NOT_DECLARED_YET            -9
  646. X#define E_CM_READ_NOT_READER            -10
  647. X
  648. X#define E_CM_UNDECLARE_UNDECLARE            -11
  649. X
  650. X/*
  651. XThis slot is sent by the manager back to the user in response to a
  652. XSLOT_READ.
  653. X*/
  654. X
  655. Xstruct slot_read_response_hdr {
  656. X    unsigned long count;
  657. X    struct timeval timestamp;
  658. X    int command_association;
  659. X};
  660. X
  661. X#define srr_count        srr_hdr.count
  662. X#define srr_timestamp        srr_hdr.timestamp
  663. X#define srr_command_association    srr_hdr.command_association
  664. X
  665. Xstruct slot_read_response {
  666. X    struct slot_read_response_hdr srr_hdr;
  667. X    /* the following two entries are the flattened out sdata structure */
  668. X    /* and should probably be declared that way */
  669. X    struct cm_flattened_data fdata;    /* flattened data */
  670. X};
  671. X
  672. X/*
  673. XThis slot is sent by the user to the manager when writing a value
  674. X*/
  675. X
  676. Xstruct slot_write_hdr {
  677. X    int command_association;
  678. X/*    union flattened_data fdata;*/
  679. X};
  680. X
  681. X#define sw_command_association    sw_hdr.command_association
  682. X
  683. Xstruct slot_write {
  684. X    struct slot_write_hdr sw_hdr;
  685. X    struct cm_flattened_data fdata;
  686. X};
  687. X
  688. X#if 0
  689. X/* this slot is sent to the manager when requesting a variable value.
  690. XCurrently, it is empty, but since the C compiler doesn't like empty
  691. Xstructures we put in a single character (that will never be looked at)
  692. X*/
  693. Xstruct slot_read {
  694. X    char dummy;    /* this is not used except to take up space */
  695. X};
  696. X#endif
  697. X
  698. Xstruct slot_role {
  699. X    unsigned reader : 1;
  700. X    unsigned wakeup : 1;
  701. X    unsigned xwriter : 1;
  702. X    unsigned nonxwriter : 1;
  703. X};
  704. X
  705. X/* this slot is sent by the user to the manager when declaring variables */
  706. Xstruct slot_declare {
  707. X    int command_association;
  708. X    struct slot_role role;
  709. X};
  710. X
  711. X/* this slot is sent by the user to the manager when undeclaring variables */
  712. Xstruct slot_undeclare {
  713. X    char dummy;    /* this is not used except to take up space */
  714. X};
  715. X
  716. X/* this slot is sent to the user for a number of reasons (all bad!) */
  717. Xstruct slot_error_hdr {
  718. X    /* unsigned size; */
  719. X    int type;    /* type of error */
  720. X};
  721. X
  722. X#define se_type            se_hdr.type
  723. X
  724. Xstruct slot_error {
  725. X    struct slot_error_hdr se_hdr;
  726. X    char msg[1];
  727. X};
  728. X
  729. X/*
  730. XEach slot structure is different depending on what slot type it is.
  731. XAll slots however, contain a slot type and slot name.
  732. X*/
  733. Xunion slot_generic {
  734. X    struct slot_declare declare;
  735. X#if 0
  736. X    struct slot_read read;
  737. X#endif
  738. X    struct slot_write write;
  739. X    struct slot_read_response read_response;
  740. X    struct slot_error error;
  741. X    struct slot_undeclare undeclare;
  742. X/* a command slot is for variables that should be directly interpreted
  743. X/* by the CMM itself.  However, this is not currently used.  */
  744. X/*    struct slot_command command; what the hell is this? */
  745. X};
  746. X
  747. Xstruct slot_hdr {
  748. X    char name[CM_VARIABLENAMELENGTH];
  749. X    int type;        /* type of the slot structure */
  750. X    int size;        /* size of the slot structure */
  751. X};
  752. X
  753. X#define s_name slot_hdr.name
  754. X#define s_type slot_hdr.type
  755. X#define s_size slot_hdr.size
  756. X
  757. Xstruct slot {
  758. X    struct slot_hdr slot_hdr;
  759. X    union slot_generic subslot;
  760. X};
  761. X
  762. X/* same as slot but has buffer space at end */
  763. X/* the others are used for handing to sizeof */
  764. Xstruct big_slot {
  765. X    char name[CM_VARIABLENAMELENGTH];
  766. X    int type;
  767. X    int size;
  768. X    union slot_generic subslot;
  769. X    char buffer[CM_SLOTSIZE];
  770. X};
  771. END_OF_FILE
  772. if test 3894 -ne `wc -c <'src/cm_slot.h'`; then
  773.     echo shar: \"'src/cm_slot.h'\" unpacked with wrong size!
  774. fi
  775. # end of 'src/cm_slot.h'
  776. fi
  777. if test -f 'src/cm_usr2.c' -a "${1}" != "-c" ; then 
  778.   echo shar: Will not clobber existing file \"'src/cm_usr2.c'\"
  779. else
  780. echo shar: Extracting \"'src/cm_usr2.c'\" \(2844 characters\)
  781. sed "s/^X//" >'src/cm_usr2.c' <<'END_OF_FILE'
  782. X#include <stdio.h>
  783. X#include <sys/time.h>
  784. X#include <strings.h>
  785. X#include "cm_constants.h"
  786. X#include "cm_sd.h"
  787. X#include "cm_var.h"
  788. X#include "cm_interface.h"
  789. X
  790. Xvoid
  791. Xcm_set_value(var,val)
  792. Xcm_variable *var;
  793. Xcm_value *val;
  794. X{
  795. X    eprintf(5,"var = %x\n",var);
  796. X    eprintf(5,"var->name = %s\n",var->name);
  797. X    cm_sd_copy(val,&var->data);
  798. X    var->status.written = TRUE;
  799. X    var->count++;
  800. X}
  801. X
  802. X
  803. Xcm_value *
  804. Xcm_get_value(var,val)
  805. Xcm_variable *var;
  806. Xcm_value *val;
  807. X{
  808. X    cm_sd_copy(&var->data,val);
  809. X    var->old_count = var->count;
  810. X    return(val);
  811. X}
  812. X
  813. Xvoid
  814. Xcm_set_new_command_value(command_out,command_value)
  815. Xcm_command_variable *command_out;
  816. Xcm_value *command_value;
  817. X{
  818. X    cm_set_value(command_out,command_value);
  819. X    command_out->command_association++;
  820. X    /* or
  821. X    command_out->command_association = time_of_day;
  822. X    */
  823. X}
  824. X
  825. X/*
  826. XNote that whether we use a timestamp or a counter is implementation dependent.
  827. XThe user should only see the association as an object that guarantees
  828. Xuniqueness between commands.  Indeed, it is expected that variables will also
  829. Xhave timestamps and read/write counters, but this is irrelevent.
  830. X*/
  831. X
  832. Xboolean cm_new_command_pending(input_command)
  833. Xcm_command_variable *input_command;
  834. X{
  835. X    return (input_command->command_association !=
  836. X        input_command->old_command_association);
  837. X}
  838. X
  839. X/* returns true if variable has a new value since cm_get_value() or
  840. X   cm_get_new_command_value() has been called */
  841. Xboolean cm_new_value_pending(var)
  842. Xcm_variable *var;
  843. X{
  844. X    return (var->count != var->old_count);
  845. X}
  846. X
  847. Xboolean cm_get_new_value(var,val)
  848. Xcm_variable *var;
  849. Xcm_value *val;
  850. X{
  851. X    if (!cm_new_value_pending(var)) return(FALSE);
  852. X
  853. X    cm_get_value(var,val);
  854. X    return(TRUE);
  855. X}
  856. X
  857. X/* returns true if new command received.  turns off new flag */
  858. Xboolean cm_get_new_command_value(input_command,value)
  859. Xcm_command_variable *input_command;
  860. Xcm_value *value;
  861. X{
  862. X    if (!cm_new_command_pending(input_command)) return(FALSE);
  863. X
  864. X    /* turn off strobe for next time around */
  865. X    input_command->old_command_association =
  866. X        input_command->command_association;
  867. X    cm_get_value(input_command,value);
  868. X    return(TRUE);
  869. X}    
  870. X
  871. Xboolean
  872. Xcm_status_equal(command_out,status_in,status_value)
  873. Xcm_command_variable *command_out;
  874. Xcm_status_variable *status_in;
  875. Xcm_value *status_value;
  876. X{
  877. X    return(cm_status_synchronized(command_out,status_in) &&
  878. X        (cm_sd_equal(status_value,&status_in->data)
  879. X           || (status_value == ANY_STATUS)));
  880. X}
  881. X
  882. Xboolean cm_status_synchronized(command_out,status_in)
  883. Xcm_command_variable *command_out;
  884. Xcm_status_variable *status_in;
  885. X{
  886. X    return(command_out->command_association ==
  887. X             status_in->command_association);
  888. X}
  889. X
  890. X/* NOTE: command_in argument is new!!! */
  891. Xvoid cm_set_status_value(command_in,status_out,status_value)
  892. Xcm_command_variable *command_in;
  893. Xcm_status_variable *status_out;
  894. Xcm_value *status_value;
  895. X{
  896. X    cm_set_value(status_out,status_value);
  897. X    status_out->command_association = command_in->command_association;
  898. X}
  899. END_OF_FILE
  900. if test 2844 -ne `wc -c <'src/cm_usr2.c'`; then
  901.     echo shar: \"'src/cm_usr2.c'\" unpacked with wrong size!
  902. fi
  903. # end of 'src/cm_usr2.c'
  904. fi
  905. if test -f 'src/franz/global.h' -a "${1}" != "-c" ; then 
  906.   echo shar: Will not clobber existing file \"'src/franz/global.h'\"
  907. else
  908. echo shar: Extracting \"'src/franz/global.h'\" \(5801 characters\)
  909. sed "s/^X//" >'src/franz/global.h' <<'END_OF_FILE'
  910. X/*                    -[Wed Jun 12 07:59:36 1985 by jkf]-
  911. X *     global.h            $Locker:  $
  912. X * main include file 
  913. X *
  914. X * $Header: global.h,v 40.27 85/06/26 14:24:02 smh Exp $
  915. X *
  916. X * (c) copyright 1982, Regents of the University of California
  917. X * Enhancements (c) copyright 1984, Franz Inc., Berkeley California
  918. X */
  919. X
  920. X#include <stdio.h>
  921. X
  922. X/*
  923. X** if you change VERNO, then also change the compiler version number
  924. X** in the file /usr/franz/liszt/sys/const.l
  925. X*/
  926. X/* the fasl file version number */
  927. X#define VERNO    422
  928. X/* the current opus number */
  929. X#define OPUS    42
  930. X
  931. X#include "module.h"
  932. X#include "config.h"
  933. X#include "ltypes.h"
  934. X#include "lstructs.h"
  935. X#include "sigtab.h"   /* table of all pointers to lisp data */
  936. X#include "dfuncs.h"
  937. X#include "public.h"
  938. X
  939. X#define FALSE    0
  940. X#define    TRUE    1
  941. X#define EVER    ;;
  942. X
  943. X/* used by Imakeht() and anyone who calls it */
  944. X# define HASHKEY_EQ    1
  945. X# define HASHKEY_EQUAL    2
  946. X
  947. X/* STRBLEN is used in many places as a good size for a char array */ 
  948. X#define STRBLEN 512
  949. X
  950. X/* LBPG is 'bytes per lisp page'. */
  951. X#define LBPG    512
  952. X
  953. X#define    NULL_CHAR    0
  954. X
  955. X/* maximum and minimum fixnums */
  956. X#define MaxINT 0x3fffffff
  957. X#define MinINT (- 0x4000000)
  958. X
  959. Xextern char unbound[];
  960. X
  961. X/* 
  962. X * macros for saving state and restoring state
  963. X *
  964. X * Savestack and Restorestack are required at the beginning and end of
  965. X * functions which modify the stack pointers np and lbot.
  966. X * The Savestack(n) should appear at the end of the variable declarations
  967. X * The n refers to the number of register variables declared in this routine.
  968. X * The information is required for the Vax version only.
  969. X *** this ifdef should be broken up into ifdefs
  970. X */
  971. X#ifndef NPINREG
  972. Xextern struct atom nilatom, eofatom;
  973. X#define nil    ((lispval) &nilatom)
  974. X#define eofa    ((lispval) &eofatom)
  975. X#define Savestack(n) struct argent *OLDlbot = lbot, *OLDnp = np
  976. X#define Restorestack() (lbot = OLDlbot), np = OLDnp
  977. X#else
  978. X#define nil    ((lispval) 0)
  979. X#define eofa    ((lispval) 20)
  980. X#define Savestack(n) snpand(n)
  981. X#define Restorestack() 
  982. X#endif
  983. X
  984. X#ifdef SIXONLY
  985. X#define errorh1 errh1
  986. X#define errorh2 errh2
  987. X#endif
  988. X
  989. X#define    CNIL    ((lispval) (OFFSET-4))
  990. X#define NOTNIL(a)    (nil!=a)
  991. X#define ISNIL(a)    (nil==a)
  992. X
  993. X#ifdef SPISFP
  994. X#define initxstack()    xsp = exsp = xstack + xstksize;
  995. Xextern word *xsp, *exsp, xstack[];
  996. Xextern int xstksize;
  997. X#define sp() (word*)xsp
  998. X#define stack(z) (xsp > xstack ? (*--xsp = z): xserr())
  999. X#define unstack() (*xsp++)
  1000. X#define Keepxs() word *oxsp = xsp;
  1001. X#define Freexs() xsp = oxsp;
  1002. X#else
  1003. X#define initxstack()    /* nothing */
  1004. Xextern word *sp(), stack(), unstack();
  1005. X#define Keepxs() /* */
  1006. X#define Freexs() /* */
  1007. X#endif
  1008. X
  1009. X#ifdef apollo
  1010. Xextern char textstart[], datastart[];
  1011. Xextern char textend[], dataend[];
  1012. Xextern char heapstart[];
  1013. Xextern char heapend[];
  1014. X#endif apollo
  1015. X
  1016. X#define UPTR(x)    ((unsigned)(((word)(x))-(word)CNIL))
  1017. X#define VALID(a)    (UPTR(a) <= UPTR(datalim))
  1018. X
  1019. X#define roundup(x,inc)    (((x - 1) | (inc - 1)) + 1)
  1020. X#define NPAGES(b)    ONPAGE(roundup(b, LBPG))
  1021. X#define ONPAGE(a1)    (((word) (a1)) >> 9)
  1022. X#define ATOX(a1)    ((((word)(a1)) - OFFSET) >> 9)
  1023. X
  1024. X#define    TYPE(a1)    ((typetable+1)[ATOX(a1)])
  1025. X#define SETTYPE(s,typ)    (typetable+1)[ATOX(s)] = typ
  1026. X#define    HUNKSIZE(a1)    ((TYPE(a1)+5) & 15)
  1027. X
  1028. X#define Popframe() (errp->olderrp)
  1029. X
  1030. X/* TNP - test np to see if it has exceeded the limit of the namestack */
  1031. X#define TNP    if(np >= nplim) namerr();
  1032. X
  1033. X/*
  1034. X * protect - stack the given value on the namestack, 'protect'ing from
  1035. X * the garbage collector
  1036. X */
  1037. X#define protect(p) ((np++)->val = (p))
  1038. X
  1039. X/*
  1040. X * chkarg - If there aren't p arguments on the namestack,
  1041. X * print an argument error with x being the name of the function called.
  1042. X */
  1043. X#define chkarg(p,x) if((p)!=np-lbot) argerr(x);
  1044. X#define chkrange(low,high,x)    if ((np-lbot < low) || (np-lbot > high))\
  1045. X                    argerr(x);
  1046. X
  1047. X
  1048. X/* number of counters for fasl to use in a profiling lisp  */
  1049. X#define NMCOUNT 5000
  1050. X
  1051. X
  1052. X
  1053. X/*
  1054. X * big string buffer for whomever needs it
  1055. X *** this should be in public.h but can't until we initialize the
  1056. X *** string buffer correctly.
  1057. X */
  1058. Xextern char    *strbuf;
  1059. Xextern char    *endstrb;
  1060. X
  1061. X
  1062. X/*
  1063. X * PUSHDOWN stores the given 'atom' and its old value on the bindstack
  1064. X * and then sets 'atom' to 'value'
  1065. X */
  1066. X
  1067. X#define PUSHDOWN(atom,value)\
  1068. X    {bnp->atm=(atom);bnp->bindv=(atom)->a.bindv;\
  1069. X    (bnp++)->val=(atom)->a.clb;(atom)->a.clb=value;\
  1070. X    (atom)->a.bindv=(atom);\
  1071. X    if(bnp>bnplim) binderr();}
  1072. X
  1073. X/* PUSHDOWNB is like PUSHDOWN but allows specification of both the clb
  1074. X * and bindv of the new binding.  Presently used only for instance
  1075. X * variables during interpreted method code.
  1076. X */
  1077. X
  1078. X#define PUSHDOWNB(atom,vclb,vbindv)\
  1079. X    {bnp->atm=(atom);bnp->bindv=(atom)->a.bindv;\
  1080. X    (bnp++)->val=(atom)->a.clb;(atom)->a.clb=(vclb);\
  1081. X    (atom)->a.bindv=(vbindv);\
  1082. X    if(bnp>bnplim) binderr();}
  1083. X
  1084. X/*
  1085. X * POP pops off the top value on the bindstack, restoring the value
  1086. X * of the atom.
  1087. X */
  1088. X    
  1089. X#define POP\
  1090. X    {--bnp; bnp->atm->a.clb=bnp->val; bnp->atm->a.bindv=bnp->bindv;}
  1091. X
  1092. X/* PUSHVAL  is used to store a specific atom and value on the
  1093. X * bindstack.   Currently only used by closure code
  1094. X */  
  1095. X#define PUSHVAL(atom,value)\
  1096. X    {bnp->atm=(atom);bnp->bindv=(atom)->a.bindv;(bnp++)->val=value;\
  1097. X    if(bnp>bnplim) binderr();}
  1098. X
  1099. X
  1100. X/*
  1101. X * the Fixzero table is a table of fixnums from -1024 to 1023, with
  1102. X * Fixzero[0] being zero.  The SMALL(n) macro return the fixnum n
  1103. X */
  1104. Xextern word Fixzero[];
  1105. X#define SMALL(i)    ((lispval)(Fixzero + i))
  1106. X
  1107. X/*
  1108. X * register lisp macros for registers only used in non-portable vax version
  1109. X * These place code in the assembler stream which tells 'fixmask'
  1110. X * to alter the register save mask
  1111. X * saveonly(n) - save the first n registers (r11,r10,...,r6)
  1112. X * snpand(n)   - save np and lbot (r6+r7) then the first n registers
  1113. X */
  1114. X#ifdef NPINREG
  1115. X# define saveonly(n)    asm("#save    n")
  1116. X# define snpand(n)    asm("#protect    n")
  1117. X#endif
  1118. X
  1119. X
  1120. X/*
  1121. X * Chkint - macro to check if an interrupt has occured, and if
  1122. X * it does then to process it
  1123. X */
  1124. X#define Chkint() if (sigintcnt > 0) dosigint()
  1125. END_OF_FILE
  1126. if test 5801 -ne `wc -c <'src/franz/global.h'`; then
  1127.     echo shar: \"'src/franz/global.h'\" unpacked with wrong size!
  1128. fi
  1129. # end of 'src/franz/global.h'
  1130. fi
  1131. if test -f 'src/franz/lstructs.h' -a "${1}" != "-c" ; then 
  1132.   echo shar: Will not clobber existing file \"'src/franz/lstructs.h'\"
  1133. else
  1134. echo shar: Extracting \"'src/franz/lstructs.h'\" \(4369 characters\)
  1135. sed "s/^X//" >'src/franz/lstructs.h' <<'END_OF_FILE'
  1136. X/*                    -[Wed Jun  5 21:16:25 1985 by layer]-
  1137. X**     lstructs.h            $Locker:  $
  1138. X**   lisp data object structure definitions
  1139. X**
  1140. X** $Header: lstructs.h,v 40.17 85/06/06 16:03:19 layer Exp $ *
  1141. X** 
  1142. X** (c) copyright 1984, Franz Inc., Berkeley California
  1143. X*/
  1144. X
  1145. Xtypedef union lispobj *lispval;
  1146. X
  1147. Xstruct dtpr {
  1148. X    lispval    cdr, car;
  1149. X};
  1150. X
  1151. Xstruct sdot {
  1152. X    word     I;
  1153. X    lispval    CDR;
  1154. X};
  1155. X
  1156. X
  1157. X/*
  1158. X** If you change the size of the following structure, then
  1159. X** you must also do the following:
  1160. X**    1. give ATOMSPP a new value (in structs.h), which is:
  1161. X**        integer part of (512 / sizeof (struct atom))
  1162. X**    2. fix the initialization of nilatom and eofatom in low.c
  1163. X**    3. fix the init of atom_str in data.c
  1164. X**
  1165. X** NOTE: there are places in the imterpreter and compiler which
  1166. X**    know about offsets in the atom structure, and they are:
  1167. X**     1. {vax,68k}/qfuncl (the #define Atomfnbnd)
  1168. X**     2. const.l in the compiler (bindv-offset and clb-offset).
  1169. X*/
  1170. Xstruct    atom    {
  1171. X    lispval        clb;        /* current level binding */
  1172. X    lispval            bindv;        /* pointer to the current value */
  1173. X    char        *pname;        /* print name */
  1174. X    lispval        fnbnd;        /* function binding */
  1175. X    lispval        pkg;        /* home package (for printing) */
  1176. X    lispval        plist;        /* property list */
  1177. X};
  1178. X
  1179. X/* all references to the value of a symbol should use the following macro */
  1180. X#define SymValue(x) (((x)->a.bindv)->a.clb)
  1181. X
  1182. Xstruct array {
  1183. X    lispval accfun,        /*  access function--may be anything  */
  1184. X        aux;        /*  slot for dimensions or auxilliary data  */
  1185. X    char *data;            /*  pointer to first byte of array    */
  1186. X    lispval length, delta;    /* length in items and length of one item */
  1187. X};
  1188. X
  1189. Xstruct bfun {
  1190. X    lispval (*start)();    /*  entry point to routine  */
  1191. X    lispval    discipline;    /*  argument-passing discipline  */
  1192. X#ifdef apollo
  1193. X    lispval    canlink;    /* can link this function in trantb */
  1194. X    lispval    (*ecb)();    /*  pointer to ecb */
  1195. X    lispval    (*ecb2)();    /*  second pointer to ecb */
  1196. X#endif apollo
  1197. X};
  1198. X
  1199. Xstruct Hunk {
  1200. X    lispval hunk[1];
  1201. X};
  1202. X
  1203. Xstruct Vector {
  1204. X        lispval vector[1];
  1205. X};
  1206. X
  1207. X/* the vectori types */
  1208. Xstruct Vectorb {
  1209. X        char vectorb[1];
  1210. X};
  1211. X
  1212. X/* The manual says this must be 16 bits */
  1213. Xstruct Vectorw {
  1214. X       short  vectorw[1];
  1215. X};
  1216. X
  1217. Xstruct Vectorl {
  1218. X    int32 vectorl[1];
  1219. X};
  1220. X
  1221. Xstruct Vectorf {
  1222. X    float vectorf[1];
  1223. X};
  1224. X
  1225. Xstruct Vectord {
  1226. X    double vectord[1];
  1227. X};
  1228. X
  1229. Xstruct Hasht {
  1230. X    lispval size;
  1231. X    lispval test;
  1232. X    lispval count;
  1233. X    lispval rehash_size;
  1234. X    lispval rehash_thres;
  1235. X    lispval bucket;
  1236. X};
  1237. X
  1238. X/*
  1239. X** if you change the size of this structure, then
  1240. X** change the initialization of boguslp in data.c
  1241. X*/
  1242. Xstruct package {
  1243. X    lispval tables;
  1244. X    lispval name;
  1245. X    lispval nicknames;
  1246. X    lispval use_list;
  1247. X    lispval used_by_list;
  1248. X    lispval internal_symbols;
  1249. X    lispval external_symbols;
  1250. X    lispval shadowing_symbols;
  1251. X};
  1252. X
  1253. Xunion lispobj {
  1254. X    struct atom a;
  1255. X    struct array ar;
  1256. X    struct bfun bcd;
  1257. X    char c;
  1258. X    char *st;    /* string */
  1259. X    struct dtpr d;
  1260. X    lispval (*f)();
  1261. X    struct Hunk h;
  1262. X    struct Hasht ht;
  1263. X    word i;
  1264. X    word *j;
  1265. X    lispval l;
  1266. X    FILE *p;
  1267. X    struct package pk;
  1268. X    double r;
  1269. X    struct sdot s;
  1270. X    struct Vector v;
  1271. X    struct Vectorb vb;
  1272. X    struct Vectorw vw;
  1273. X    struct Vectorl vl;
  1274. X    struct Vectorf vf;
  1275. X    struct Vectord vd;
  1276. X};
  1277. X
  1278. X/* offset of size info from beginning of vector, 
  1279. X    in longwords (ie 32 bit words) */
  1280. X/* these values are not valid when a vector is stored in the free */
  1281. X/* list, in which case the chaining is done through the propery field */
  1282. X#define VSizeOff -2
  1283. X#define VPropOff -1
  1284. X
  1285. X/* VecTotSize: the total number of longwords for the data segment of
  1286. X * the vector. Takes a byte count and rounds up to nearest long.
  1287. X */
  1288. X
  1289. X#define VecTotSize(x)  (((x)+3) >> 2)
  1290. X#define VecTotToByte(x) ((x) * sizeof(word))
  1291. X
  1292. X/* these vector size macros determine the number of complete objects
  1293. X   in the vector
  1294. X */
  1295. X#define VecSize(x)     ((x) >> 2)
  1296. X#define VecWordSize(x)    ((x) >> 1)
  1297. X#define VecByteSize(x)    (x)
  1298. X#define VecFloatSize(x)    ((x) >> 2)    /* not used yet */
  1299. X#define VecDoubSize(x)    ((x) >> 3)    /* not used yet */
  1300. X
  1301. X#define VSIZE(vec)    VecSize((int)vec->v.vector[VSizeOff])
  1302. X/*
  1303. X * internal lisp structures
  1304. X */
  1305. X
  1306. X/*
  1307. X * nament is misnamed. It is actually the structure of a bindstack entry
  1308. X * recording the saved value (val) of a symbol (atm) and bindv
  1309. X */
  1310. Xstruct nament {
  1311. X    lispval    val,
  1312. X        atm,
  1313. X        bindv;
  1314. X};
  1315. X
  1316. X/*
  1317. X * argent is the structure of an object on the namestack, which
  1318. X * is a stack of lisp values, usually arguments to functions and
  1319. X * local variables in compiled code.
  1320. X */
  1321. Xstruct argent {
  1322. X    lispval    val;
  1323. X};
  1324. END_OF_FILE
  1325. if test 4369 -ne `wc -c <'src/franz/lstructs.h'`; then
  1326.     echo shar: \"'src/franz/lstructs.h'\" unpacked with wrong size!
  1327. fi
  1328. # end of 'src/franz/lstructs.h'
  1329. fi
  1330. if test -f 'src/franz/sigtab.h' -a "${1}" != "-c" ; then 
  1331.   echo shar: Will not clobber existing file \"'src/franz/sigtab.h'\"
  1332. else
  1333. echo shar: Extracting \"'src/franz/sigtab.h'\" \(4580 characters\)
  1334. sed "s/^X//" >'src/franz/sigtab.h' <<'END_OF_FILE'
  1335. X/*                    -[Wed Jun  5 21:45:38 1985 by layer]-
  1336. X *     sigtab.h            $Locker:  $
  1337. X * table of lispvals needed by C 
  1338. X *
  1339. X * $Header: sigtab.h,v 40.10 85/06/06 16:03:43 layer Exp $
  1340. X *
  1341. X * (c) copyright 1982, Regents of the University of California
  1342. X * Enhancements (c) copyright 1984, Franz Inc., Oakland California
  1343. X */
  1344. X
  1345. X/*
  1346. X *  lispvals in use by the program should be in this table.
  1347. X *  Otherwise they may get garbage-collected.
  1348. X */
  1349. X
  1350. X# define SIGNIF 148
  1351. X
  1352. XPublic lispval lispsys[SIGNIF];
  1353. X
  1354. X#define tatom (lispsys[1])
  1355. X#define lambda (lispsys[2])
  1356. X#define nlambda (lispsys[3])
  1357. X#define perda (lispsys[4])
  1358. X#define lpara (lispsys[5])
  1359. X#define rpara (lispsys[6])
  1360. X#define lbkta (lispsys[7])
  1361. X#define rbkta (lispsys[8])
  1362. X#define Eofa (lispsys[9])
  1363. X#define snqta (lispsys[10])
  1364. X#define exclpa (lispsys[11])
  1365. X#define quota (lispsys[12])
  1366. X#define xatom (lispsys[13])
  1367. X#define cara (lispsys[14])
  1368. X#define cdra (lispsys[15])
  1369. X#define gcafter (lispsys[16])
  1370. X    /* gap */ 
  1371. X#define int_name (lispsys[19])
  1372. X#define str_name (lispsys[20])
  1373. X#define atom_name (lispsys[21])
  1374. X#define doub_name (lispsys[22])
  1375. X#define dtpr_name (lispsys[23])
  1376. X#define int_items (lispsys[24])
  1377. X#define int_pages (lispsys[25])
  1378. X#define str_items (lispsys[26])
  1379. X#define str_pages (lispsys[27])
  1380. X#define dtpr_items (lispsys[28])
  1381. X#define dtpr_pages (lispsys[29])
  1382. X#define doub_items (lispsys[30])
  1383. X#define doub_pages (lispsys[31])
  1384. X#define atom_items (lispsys[32])
  1385. X#define atom_pages (lispsys[33])
  1386. X#define gccall1 (lispsys[34])
  1387. X#define gccall2 (lispsys[35])
  1388. X#define sysa (lispsys[36])
  1389. X#define plima (lispsys[37])
  1390. X#define macro (lispsys[38])
  1391. X#define startup (lispsys[39])
  1392. X#define rcomms (lispsys[40])
  1393. X#define commta (lispsys[41])
  1394. X#define plimit (lispsys[44])
  1395. X#define array_items (lispsys[45])
  1396. X#define array_pages (lispsys[46])
  1397. X#define array_name  (lispsys[47])
  1398. X#define sdot_items (lispsys[48])
  1399. X#define sdot_pages (lispsys[49])
  1400. X#define sdot_name (lispsys[50])
  1401. X#define val_items (lispsys[51])
  1402. X#define val_pages (lispsys[52])
  1403. X#define val_name  (lispsys[53])
  1404. X#define splice    (lispsys[54])
  1405. X#define rdrsdot (lispsys[55])
  1406. X#define funct_items (lispsys[56])
  1407. X#define funct_pages (lispsys[57])
  1408. X#define funct_name (lispsys[58])
  1409. X#define nstack (lispsys[59])
  1410. X#define rdrint (lispsys[63])
  1411. X#define nilplist (lispsys[64])
  1412. X#define Vprintsym (lispsys[65])
  1413. X    /* gap */
  1414. X#define gcdis (lispsys[68])
  1415. X    /* gap */
  1416. X#define bstack (lispsys[83])
  1417. X#define lexpr_atom (lispsys[84])
  1418. X#define lexpr (lispsys[85])
  1419. X#define ibase (lispsys[86])
  1420. X#define Vpiport (lispsys[87])
  1421. X#define Vpoport (lispsys[88])
  1422. X#define Veval (lispsys[89])
  1423. X#define Vererr (lispsys[90])
  1424. X#define Vertpl (lispsys[91])
  1425. X#define Verall (lispsys[92])
  1426. X#define Vermisc (lispsys[93])
  1427. X#define Vlerall (lispsys[94])
  1428. X#define stlist (lispsys[95])
  1429. X#define Vreadtable (lispsys[96])
  1430. X#define strtab (lispsys[97])
  1431. X#define Verbrk (lispsys[98])
  1432. X#define Vnogbar (lispsys[99])
  1433. X#define rdrsdot2 (lispsys[100])
  1434. X#define Veruwpt (lispsys[101])
  1435. X
  1436. X#define hunkfree (lispsys[102])
  1437. X#define port_name (lispsys[103])
  1438. X#define reseta (lispsys[104])
  1439. X#define rsetatom (lispsys[105])
  1440. X#define bptr_atom (lispsys[106])
  1441. X#define evalhatom (lispsys[107])
  1442. X#define funhatom (lispsys[108])
  1443. X#define Vptport (lispsys[109])
  1444. X#define Vcntlw  (lispsys[110])
  1445. X#define Verrset (lispsys[111])
  1446. X#define Verundef (lispsys[112])
  1447. X#define Vsubrou (lispsys[113])
  1448. X#define Vprinlevel (lispsys[114])
  1449. X#define Vprinlength (lispsys[115])
  1450. X#define Vfloatformat (lispsys[116])
  1451. X#define Vldprt  (lispsys[117])
  1452. X#define Verdepth  (lispsys[118])
  1453. X#define mrtabspace (lispsys[119])
  1454. X#define pnameprot (lispsys[120])
  1455. X#define other_name (lispsys[121])
  1456. X#define Vevalframe (lispsys[122])
  1457. X#define Vpurcopylits (lispsys[123])
  1458. X#define vect_name (lispsys[124])
  1459. X#define vecti_name (lispsys[125])
  1460. X#define vect_items (lispsys[126])
  1461. X#define vecti_items (lispsys[127])
  1462. X#define vect_pages (lispsys[128])
  1463. X#define vecti_pages (lispsys[129])
  1464. X#define Vdisplacemacros (lispsys[130])
  1465. X#define other_pages (lispsys[131])
  1466. X#define other_items (lispsys[132])
  1467. X#define fclosure (lispsys[133])
  1468. X#define Vgcprint (lispsys[134])
  1469. X#define clos_marker (lispsys[135])
  1470. X#define Vpbv (lispsys[136])
  1471. X#define atom_buffer (lispsys[137])
  1472. X#define Vlibdir (lispsys[138])
  1473. X#define flavor (lispsys[139])
  1474. X#define self (lispsys[140])
  1475. X#define self_map (lispsys[141])
  1476. X#define gccall3 (lispsys[142])
  1477. X#define hasht_atom (lispsys[143])
  1478. X#define pkg_atom (lispsys[144])
  1479. X#define print_self (lispsys[145])
  1480. X#define clos_prop (lispsys[146])
  1481. X#define vector_print (lispsys[147])
  1482. X
  1483. X/* various status switches */
  1484. X#define STSIZE 16
  1485. XPublic lispval stattab[STSIZE];
  1486. X
  1487. X#define Schainp (stattab[0])
  1488. X#define Sautor (stattab[1])
  1489. X#define Strans (stattab[2])
  1490. X#define evalhsw (stattab[3])
  1491. END_OF_FILE
  1492. if test 4580 -ne `wc -c <'src/franz/sigtab.h'`; then
  1493.     echo shar: \"'src/franz/sigtab.h'\" unpacked with wrong size!
  1494. fi
  1495. # end of 'src/franz/sigtab.h'
  1496. fi
  1497. if test -f 'src/man_get_slot.c' -a "${1}" != "-c" ; then 
  1498.   echo shar: Will not clobber existing file \"'src/man_get_slot.c'\"
  1499. else
  1500. echo shar: Extracting \"'src/man_get_slot.c'\" \(5392 characters\)
  1501. sed "s/^X//" >'src/man_get_slot.c' <<'END_OF_FILE'
  1502. X/* 
  1503. X
  1504. Xthese functions are used by the CMM to read and process information from
  1505. Xincoming slots
  1506. X
  1507. X*/
  1508. X
  1509. X#include <sys/time.h>
  1510. X#include <sys/types.h>
  1511. X#include <netinet/in.h>
  1512. X#include "cm_constants.h"
  1513. X#include "cm_var.h"
  1514. X#include "cm_sd.h"
  1515. X#include "cm_slot.h"
  1516. X#include "cm_man.h"
  1517. X#include "cm_msg.h"
  1518. X#include "cm_time.h"
  1519. X
  1520. Xstruct variable *get_variable();
  1521. X
  1522. Xextern struct process processes[];
  1523. Xextern struct msg *cm_omsg;    /* defined in man.c */
  1524. X
  1525. X#define TRUE 1
  1526. X#define FALSE 0
  1527. X
  1528. Xint /* returns 0 if ok, negative if error */
  1529. Xman_decode_slot(s,pin)
  1530. Xstruct slot *s;
  1531. Xint pin;        /* process index */
  1532. X{
  1533. X    int rc = 0;
  1534. X
  1535. X    switch (s->s_type) {
  1536. X    case CM_SLOT_DECLARE:
  1537. X        eprintf(5,"slot declare\n");
  1538. X        rc = get_slot_declare(s->s_name,&s->subslot.declare,pin);
  1539. X        break;
  1540. X    case CM_SLOT_WRITE:
  1541. X        eprintf(5,"slot write\n");
  1542. X        rc = get_slot_write(s->s_name,&s->subslot.write,pin);
  1543. X        break;
  1544. X#if 0
  1545. X    case CM_SLOT_READ:
  1546. X        eprintf(5,"slot read\n");
  1547. X        /* note this destroys the message first, so this should */
  1548. X        /* always appear as the last slot */
  1549. X        send_read_vars_to(cm_omsg,pin);
  1550. X        break;
  1551. X#endif
  1552. X    case CM_SLOT_UNDECLARE:
  1553. X        eprintf(5,"slot undeclare\n");
  1554. X        rc = get_slot_undeclare(s->s_name,&s->subslot.undeclare,pin);
  1555. X        break;
  1556. X    default:
  1557. X        printf("slot bad");
  1558. X        put_slot_error(cm_omsg,s->s_name,CM_SLOT_NULL,
  1559. X            "bad slot type");
  1560. X        rc = E_CM_GET_SLOT_UNKNOWN_SLOT_TYPE;
  1561. X        break;
  1562. X    }
  1563. X    eprintf(5,"successfully decoded slot (%s %s)\n",
  1564. X            s->s_name,cm_slot_type(s->s_type));
  1565. X    return(rc);
  1566. X}
  1567. X
  1568. Xint /* returns 0 if ok */
  1569. Xget_slot_declare(name,s,pin)
  1570. Xchar *name;
  1571. Xstruct slot_declare *s;
  1572. Xint pin;
  1573. X{
  1574. X    struct variable *v;
  1575. X
  1576. X    if (!(v = get_variable(name))) {
  1577. X        put_slot_error(cm_omsg,name,CM_SLOT_DECLARE,
  1578. X        "not enough common memory to declare variable");
  1579. X        return(E_GET_VARIABLE_NO_SPACE);
  1580. X    }
  1581. X
  1582. X    /* check access rights */
  1583. X    if (s->role.reader) {
  1584. X        set_reader(pin,v);
  1585. X        /* if it's been written, note that */
  1586. X        if (v->count) set_new(pin,v);
  1587. X    }
  1588. X    if (s->role.wakeup) {
  1589. X        set_wakeup(pin,v);
  1590. X        /* if it has a new value, wake us up */
  1591. X        if (is_new(pin,v)) processes[pin].wakeup = TRUE;
  1592. X    }
  1593. X    if (s->role.nonxwriter) {
  1594. X        if (v->xwriter == CM_NULL_PROCESS)
  1595. X            set_nonxwriter(pin,v);
  1596. X        else {
  1597. X            put_slot_error(cm_omsg,name,CM_SLOT_DECLARE,
  1598. X                "cannot get nonexclusive write access");
  1599. X            return(E_CM_DECLARE_CANT_GET_XWRITE_ACCESS);
  1600. X        }
  1601. X    }
  1602. X    if (s->role.xwriter) {
  1603. X        if (v->xwriter == CM_NULL_PROCESS
  1604. X            || is_xwriter(pin,v)) {
  1605. X            set_xwriter(pin,v);
  1606. X        } else {
  1607. X            put_slot_error(cm_omsg,name,CM_SLOT_DECLARE,
  1608. X                "cannot get exclusive write access");
  1609. X            return(E_CM_DECLARE_CANT_GET_XWRITE_ACCESS);
  1610. X        }
  1611. X    }
  1612. X
  1613. X#if 0
  1614. X    /* update cm_variable_list */
  1615. X    for (i=0;
  1616. X#endif
  1617. X
  1618. X    return(0);
  1619. X}
  1620. X
  1621. X/*ARGSUSED*/
  1622. Xint
  1623. Xget_slot_undeclare(name,s,pin)
  1624. Xchar *name;
  1625. Xstruct slot_undeclare *s;
  1626. Xint pin;
  1627. X{
  1628. X    struct variable *v;
  1629. X
  1630. X    if (!(v = get_variable(name))) {
  1631. X        put_slot_error(cm_omsg,name,CM_SLOT_UNDECLARE,
  1632. X            "undeclare of undeclared variable");
  1633. X        return(E_CM_UNDECLARE_UNDECLARE);
  1634. X    }
  1635. X    if (!var_inuse(v)) {
  1636. X        put_slot_error(cm_omsg,name,CM_SLOT_UNDECLARE,
  1637. X            "undeclare of undeclared variable");
  1638. X        return(E_CM_UNDECLARE_UNDECLARE);
  1639. X    }    
  1640. X    unset_reader(pin,v);
  1641. X    unset_writer(pin,v);
  1642. X    unset_wakeup(pin,v);
  1643. X
  1644. X    /* note: var_inuse may have different value now */
  1645. X    if (!var_inuse(v)) {
  1646. X        /* if var had been set, free up any space taken by it */
  1647. X        if (v->count) {
  1648. X            cm_sd_free(&v->data);
  1649. X            v->count = 0;
  1650. X        }
  1651. X
  1652. X        /* remove from cm_variable_list */
  1653. X    }
  1654. X    return(E_CM_SLOT_OK);
  1655. X}
  1656. X
  1657. Xint /* returns 0 if ok, error otherwise */
  1658. Xget_slot_write(name,s,pin)
  1659. Xchar *name;
  1660. Xstruct slot_write *s;
  1661. Xint pin;
  1662. X{
  1663. X    int i;
  1664. X    struct variable *v;
  1665. X
  1666. X    if (!(v = get_variable(name))) {
  1667. X        put_slot_error(cm_omsg,name,CM_SLOT_WRITE,
  1668. X        "not enough common memory to declare variable");
  1669. X        return(E_CM_DECLARE_GET_VARIABLE_NO_SPACE);
  1670. X    }
  1671. X
  1672. X    /* if variable has not been declared, error */
  1673. X    if (!var_inuse(v)) {
  1674. X        put_slot_error(cm_omsg,name,CM_SLOT_WRITE,
  1675. X        "variable has not been declared");
  1676. X        return(E_CM_WRITE_NOT_DECLARED_YET);
  1677. X    }
  1678. X
  1679. X    /* check access */
  1680. X    if (!(is_writer(pin,v))) {
  1681. X        put_slot_error(cm_omsg,name,CM_SLOT_WRITE,
  1682. X        "not declared as writer");
  1683. X        return(E_CM_WRITE_NOT_WRITER);
  1684. X    }
  1685. X
  1686. X    /* write new value */
  1687. X    if (0 > cm_flat_to_sd(&s->fdata,&v->data)) {
  1688. X        put_slot_error(cm_omsg,name,CM_SLOT_WRITE,
  1689. X        "get_slot_write: cm_flat_to_sd() failed!  no space?\n");
  1690. X        return(E_CM_GET_SLOT_FLAT_TO_SD);
  1691. X    }
  1692. X    /* the CMM generates new values for count and timestamp */
  1693. X    v->count++;
  1694. X    time_now(&v->timestamp);
  1695. X    /* the user generates new values for command_association */
  1696. X    v->command_association = s->sw_hdr.command_association;
  1697. X
  1698. X    for (i=0;i<CM_MAXPROCESSES;i++) {
  1699. X        set_new(i,v);
  1700. X        /* flag any processes to be woken up */
  1701. X        if (is_wakeup(i,v)) {
  1702. X            processes[i].wakeup = TRUE;
  1703. X        }
  1704. X    }
  1705. X    return(E_CM_SLOT_OK);
  1706. X}
  1707. X
  1708. X#if 0
  1709. X/*ARGSUSED*/
  1710. Xint /* returns 0 if ok, error otherwise */
  1711. Xget_slot_read(name,s,pin)
  1712. Xchar *name;
  1713. Xchar *s; /*struct slot_read *s;*/
  1714. Xint pin;
  1715. X{
  1716. X    struct variable *v;
  1717. X
  1718. X    v = get_variable(name);
  1719. X
  1720. X    if (!var_inuse(v)) {
  1721. X        put_slot_error(cm_omsg,name,CM_SLOT_READ,
  1722. X            "variable not defined");
  1723. X        return(E_CM_READ_NOT_DECLARED_YET);
  1724. X    }
  1725. X
  1726. X    /* check access */
  1727. X    if (!(is_reader(pin,v))) {
  1728. X        put_slot_error(cm_omsg,name,CM_SLOT_READ,
  1729. X        "not declared as reader");
  1730. X        return(E_CM_READ_NOT_READER);
  1731. X    }
  1732. X
  1733. X    /* read value, create slot, and add to outgoing message buffer */
  1734. X    put_slot_read_response(cm_omsg,name,v->count,
  1735. X        &v->timestamp,v->command_association,&v->data);
  1736. X    return(E_CM_SLOT_OK);
  1737. X}
  1738. X#endif
  1739. END_OF_FILE
  1740. if test 5392 -ne `wc -c <'src/man_get_slot.c'`; then
  1741.     echo shar: \"'src/man_get_slot.c'\" unpacked with wrong size!
  1742. fi
  1743. # end of 'src/man_get_slot.c'
  1744. fi
  1745. if test -f 'stream/sized_io.c' -a "${1}" != "-c" ; then 
  1746.   echo shar: Will not clobber existing file \"'stream/sized_io.c'\"
  1747. else
  1748. echo shar: Extracting \"'stream/sized_io.c'\" \(3534 characters\)
  1749. sed "s/^X//" >'stream/sized_io.c' <<'END_OF_FILE'
  1750. X/*
  1751. X
  1752. Xthese two routines enable us to have use stream io, but still detect end of
  1753. Xrecord marks.  Each call to sized_read() returns a complete buffer, that is
  1754. Xwhat was written by one call to sized_write().
  1755. X
  1756. XNotes:
  1757. X
  1758. XThe IPC system seems to be a confusing mess.  I.e. unusual conditions are
  1759. Xhandled in all different ways.  Specifically,
  1760. X
  1761. XWhile we are reading, if the writer goes away, we sometimes get a read()
  1762. X== -1 && errno == ECONNRESET.  Sometimes we get a read() == 0.  Why the
  1763. Xdifference?
  1764. X
  1765. XWhile we are writing, if the reader goes away, we get a signal (SIGPIPE).
  1766. X
  1767. X
  1768. X*/
  1769. X
  1770. X#include <stdio.h>
  1771. X#include <errno.h>
  1772. Xextern int errno;
  1773. X#include <sys/types.h>        /* defines u_long */
  1774. X#include <netinet/in.h>        /* defines htonl(), etc */
  1775. X
  1776. Xint    /* returns number of bytes read or -1 if error (i.e. EOF) */
  1777. Xsized_read(fd,buffer,maxbytes)
  1778. Xint fd;
  1779. Xchar *buffer;
  1780. Xint maxbytes;    /* unlike read(), this parameter is the maximum size of */
  1781. X        /* the buffer */
  1782. X{
  1783. X    int size;    /* size of incoming packet */
  1784. X    int cc;
  1785. X    int rembytes;    /* remaining bytes */
  1786. X    u_long netlong;    /* network byte ordered length */
  1787. X
  1788. X    /* read header */
  1789. X    if (sizeof(size) != (cc = read(fd,(char *)&netlong,sizeof(netlong)))){
  1790. X        /* if the connection is broken, we end up here */
  1791. X#ifdef DEBUG
  1792. X        fprintf(stderr,"sized_read: expecting buffer size but only read %d chars\n",cc);
  1793. X#endif
  1794. X        if (cc == -1)
  1795. X            if (errno != ECONNRESET) perror("read");
  1796. X        return(-1);
  1797. X    }
  1798. X
  1799. X    size = ntohl(netlong);
  1800. X
  1801. X    /* read data */
  1802. X    if (size == 0) return(0);
  1803. X    else if (size > maxbytes) {
  1804. X        fprintf(stderr,"sized_read: buffer too small.  ");
  1805. X        fprintf(stderr,"buffer size was %d  actual size was %d\n",
  1806. X            maxbytes,size);
  1807. X        return(-1);
  1808. X    }
  1809. X
  1810. X    /* handle buffers to large to fit in one transfer */
  1811. X    rembytes = size;
  1812. X    while (rembytes) {
  1813. X        if (-1 == (cc = read(fd,buffer,rembytes))) {
  1814. X            fprintf(stderr,"sized_read(,,%d) = read(,,%d) = %d\n",
  1815. X                            size,rembytes,cc);
  1816. X            if (errno != ECONNRESET) perror("read");
  1817. X            return(-1);
  1818. X        }
  1819. X
  1820. X        /* new! */
  1821. X        if (0 == cc) {    /* EOF - process died */
  1822. X            return(-1);
  1823. X        }
  1824. X
  1825. X#ifdef DEBUG
  1826. X        if (rembytes != cc)
  1827. X            fprintf(stderr,"sized_read(,,%d) = read(,,%d) = %d\n",
  1828. X                            size,rembytes,cc);
  1829. X#endif
  1830. X        /* read() returned more bytes than requested!?!?!?! */
  1831. X        /* this can't happen, but appears to be anyway */
  1832. X        if (cc > rembytes) {
  1833. X            fprintf(stderr,"sized_read(,,%d) = read(,,%d) = %d!?!?!\n",
  1834. X                            size,rembytes,cc);
  1835. X            fprintf(stderr,"read() returned more chars than requested!  Aborting program.\n");
  1836. X            abort();
  1837. X        }
  1838. X        buffer += cc;
  1839. X        rembytes -= cc;
  1840. X    }
  1841. X    return(size);
  1842. X}
  1843. X
  1844. Xint    /* returns number of data bytes written or -1 if error */
  1845. Xsized_write(fd,buffer,nbytes)
  1846. Xint fd;
  1847. Xchar *buffer;
  1848. Xint nbytes;
  1849. X{
  1850. X    int cc;
  1851. X    int rembytes;
  1852. X    u_long netlong;    /* network byte ordered length */
  1853. X
  1854. X    /* write header */
  1855. X    netlong = htonl(nbytes);
  1856. X    if (sizeof(nbytes) != (cc = write(fd,(char *)&netlong,
  1857. X                            sizeof(netlong)))) {
  1858. X#ifdef DEBUG
  1859. X        /* this can never happen (SIGPIPE will always occur first) */
  1860. X        fprintf(stderr,"sized_write: tried to write buffer size but only wrote %d chars\n",cc);
  1861. X#endif
  1862. X        if (cc == -1) perror("write");
  1863. X        return(-1);
  1864. X    }
  1865. X
  1866. X    /* write data */
  1867. X    if (nbytes == 0) return(0);
  1868. X
  1869. X    rembytes = nbytes;
  1870. X    while (rembytes) {
  1871. X        if (-1 == (cc = write(fd,buffer,rembytes))) {
  1872. X              fprintf(stderr,"sized_write(,,%d) = write(,,%d) = %d\n",
  1873. X                            nbytes,rembytes,cc);
  1874. X            perror("write");
  1875. X            return(-1);
  1876. X        }
  1877. X#ifdef DEBUG
  1878. X        if (rembytes != cc) 
  1879. X              fprintf(stderr,"sized_write(,,%d) = write(,,%d) = %d\n",
  1880. X                            nbytes,rembytes,cc);
  1881. X#endif
  1882. X        buffer += cc;
  1883. X        rembytes -= cc;
  1884. X    }
  1885. X    return(nbytes);
  1886. X}
  1887. END_OF_FILE
  1888. if test 3534 -ne `wc -c <'stream/sized_io.c'`; then
  1889.     echo shar: \"'stream/sized_io.c'\" unpacked with wrong size!
  1890. fi
  1891. # end of 'stream/sized_io.c'
  1892. fi
  1893. if test -f 'stream/stream.c' -a "${1}" != "-c" ; then 
  1894.   echo shar: Will not clobber existing file \"'stream/stream.c'\"
  1895. else
  1896. echo shar: Extracting \"'stream/stream.c'\" \(4225 characters\)
  1897. sed "s/^X//" >'stream/stream.c' <<'END_OF_FILE'
  1898. X#include <stdio.h>
  1899. X#include <sys/types.h>
  1900. X#include <sys/socket.h>
  1901. X#include <sys/time.h>
  1902. X#include <netinet/in.h>
  1903. X#include <netdb.h>
  1904. X#include <errno.h>
  1905. X#include "inet.h"
  1906. X
  1907. X#define MAXHOSTNAMELENGTH 255
  1908. Xchar hostname[MAXHOSTNAMELENGTH];
  1909. X
  1910. Xextern errno;
  1911. Xstatic int maxfds;
  1912. Xstatic struct timeval zerotime;
  1913. X
  1914. Xint        /* returns a socket, or -1 for failure */
  1915. Xinitport(porttype,port_name,port_number,role,sockettype,host_in)
  1916. Xint porttype;
  1917. Xchar *port_name;
  1918. Xu_short port_number;
  1919. Xint role;
  1920. Xint sockettype;
  1921. Xchar *host_in;            /* host to provide service */
  1922. X{
  1923. X    int s;        /* the socket */
  1924. X    struct sockaddr_in sin;
  1925. X    struct hostent *h;
  1926. X    struct servent *sp;    /* used by getservbyname - may not be nec. */
  1927. X
  1928. X    maxfds = getdtablesize();    /* for future reference */
  1929. X    zerotime.tv_sec = zerotime.tv_usec = 0L;
  1930. X
  1931. X    if (client) {
  1932. X    if (host_in && strcmp(host_in,"")) strcpy(hostname,host_in);
  1933. X    else {
  1934. X        if (gethostname(hostname,MAXHOSTNAMELENGTH)) {
  1935. X        fprintf(stderr,"gethostname() failed\n");
  1936. X        perror("initport(client)");
  1937. X        return(-1);
  1938. X        }
  1939. X    }
  1940. X
  1941. X    if (!(h = gethostbyname(hostname))) {
  1942. X        fprintf(stderr,"gethostbyname() failed\n");
  1943. X        perror("initport(client)");
  1944. X        return(-1);
  1945. X    }
  1946. X    }
  1947. X
  1948. X    if (porttype == PORT_TYPE_NAME) {
  1949. X    if (!(sp = getservbyname(port_name,NULL))) {
  1950. X            fprintf(stderr,"getservbyname() failed to find %s\n",port_name);
  1951. X            exit(-1);
  1952. X    }
  1953. X    }
  1954. X
  1955. X    if (-1 == (s = socket(AF_INET,sockettype,0))) {
  1956. X    fprintf(stderr,"socket() failed\n");
  1957. X    perror("initport");
  1958. X    return(-1);
  1959. X    }
  1960. X
  1961. X    sin.sin_family = AF_INET;
  1962. X    sin.sin_addr.s_addr = (server?INADDR_ANY:*(u_long *) h->h_addr);
  1963. X    sin.sin_port = (porttype == PORT_TYPE_NAME?sp->s_port:port_number);
  1964. X
  1965. X    if (client) {
  1966. X    if (connect(s,(struct sockaddr *)&sin,sizeof(struct sockaddr_in))) {
  1967. X        fprintf(stderr,"connect() failed\n");
  1968. X        perror("initport(client)");
  1969. X        return(-1);
  1970. X    }
  1971. X    } else {
  1972. X    /* bind the socket */
  1973. X    /* following line is for debugging, see IPC primer, p. 25 */
  1974. X    setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)0,0);
  1975. X    if (-1 == (bind(s,(struct sockaddr *)&sin,sizeof(sin)))) {
  1976. X        fprintf(stderr,"bind() failed\n");
  1977. X        perror("initport(server)");
  1978. X        return(-1);
  1979. X    }
  1980. X    if (listen(s,1)) {
  1981. X        perror("listen");
  1982. X        return(-1);
  1983. X    }
  1984. X    }
  1985. X    return(s);
  1986. X}
  1987. X
  1988. Xselect_server_stream(connection_socket,readers)
  1989. Xint connection_socket;
  1990. Xint *readers;    /* file descriptors of client sockets */
  1991. X{
  1992. X    struct sockaddr_in from;
  1993. X    int fromlen;
  1994. X    static int fd;    /* next file descriptor to look at */
  1995. X    int readfds, c;
  1996. X    int user;
  1997. X
  1998. X    /* how do you get sockets to block?  there is some hint (recv(2)) */
  1999. X    /* in the manual that you can but I can't find the reference! */
  2000. X
  2001. X    /* select does not like bogus file descriptors, so keep track of */
  2002. X    /* them by hand */
  2003. X    *readers |= 1<<connection_socket;
  2004. X
  2005. Xrestart:
  2006. X    do {
  2007. X    /* save readers because select wipes them out */
  2008. X    readfds = *readers;
  2009. X    c = select(maxfds,&readfds,(int *)0,(int *)0,(struct timeval *)0);
  2010. X    if (c == -1) {
  2011. X        if (errno == EBADF) {
  2012. X        int i, suspect;
  2013. X        /* someone augered in, lets forget about'm */
  2014. X        for (i=0;i<maxfds;i++) {
  2015. X            if ((1<<i) & *readers) {
  2016. X            /* use a temporary for the suspect because select() */
  2017. X            /* requires an address */
  2018. X            suspect = 1<<i;
  2019. X            if (-1 == select(maxfds,&suspect,(int *)0,(int *)0,
  2020. X                                &zerotime)) {
  2021. X                /* found a reader who closed his socket */
  2022. X                /* so get rid of him */
  2023. X                *readers &= ~(1<<i);
  2024. X            }
  2025. X            }
  2026. X        }
  2027. X        } else {
  2028. X        /* lets hope it was a recoverable interrupt and try again */
  2029. X        perror("select");
  2030. X        exit(-1);
  2031. X        }
  2032. X    }
  2033. X    } while (c == -1);
  2034. X    /* given the set of ready file descriptors pick one out that is ready */
  2035. X    /* start from where we left off, so as to give everyone service */
  2036. X    while (!(readfds & 1<<(fd = (1+fd)%maxfds))) ;
  2037. X
  2038. X    if (fd == connection_socket) {    /* check for new connections */
  2039. X    fromlen = sizeof(from);
  2040. X    user = accept(connection_socket,(struct sockaddr *)&from,&fromlen);
  2041. X    *readers |= 1<<user;
  2042. X    goto restart;
  2043. X    }
  2044. X
  2045. X    return(fd);
  2046. X}
  2047. X
  2048. Xprint_address(x)
  2049. Xstruct sockaddr_in *x;
  2050. X{
  2051. X    printf("x->sin_family = %d\n",(int)x->sin_family);
  2052. X    printf("x->sin_port = %d\n",(int)x->sin_port);
  2053. X    printf("x->sin_addr.s_addr = %d\n",(int)x->sin_port);
  2054. X    printf("x->sin_zero[0] = %c\n",x->sin_zero[0]);
  2055. X}
  2056. END_OF_FILE
  2057. if test 4225 -ne `wc -c <'stream/stream.c'`; then
  2058.     echo shar: \"'stream/stream.c'\" unpacked with wrong size!
  2059. fi
  2060. # end of 'stream/stream.c'
  2061. fi
  2062. echo shar: End of archive 2 \(of 4\).
  2063. cp /dev/null ark2isdone
  2064. MISSING=""
  2065. for I in 1 2 3 4 ; do
  2066.     if test ! -f ark${I}isdone ; then
  2067.     MISSING="${MISSING} ${I}"
  2068.     fi
  2069. done
  2070. if test "${MISSING}" = "" ; then
  2071.     echo You have unpacked all 4 archives.
  2072.     rm -f ark[1-9]isdone
  2073. else
  2074.     echo You still need to unpack the following archives:
  2075.     echo "        " ${MISSING}
  2076. fi
  2077. ##  End of shell archive.
  2078. exit 0
  2079.  
  2080.