home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume28
/
m0
/
part02
/
l_init.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-05
|
4KB
|
143 lines
/*
l_init.c
*/
/* Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
Distributed under the terms of the GNU General Public License
version 2 of june 1991 as published by the Free Software
Foundation, Inc.
This file is part of M0.
M0 is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY. No author or distributor accepts responsibility to anyone for
the consequences of using it or for whether it serves any particular
purpose or works at all, unless he says so in writing. Refer to the GNU
General Public License for full details.
Everyone is granted permission to copy, modify and redistribute M0, but
only under the conditions described in the GNU General Public License.
A copy of this license is supposed to have been given to you along with
M0 so you can know your rights and responsibilities. It should be in a
file named LICENSE. Among other things, the copyright notice and this
notice must be preserved on all copies. */
#include "l_proto.h"
#define ERRORNAMES (byteptr)"_ena"
#define ERRORHANDLER_NAME (byteptr)"_err"
#define TYPENAMES (byteptr)"_tna"
eptr global;
static byteptr msgr_start_s = (byteptr) ".'_loc.:_cod!";
eindex systemdict;
eindex queuedict;
eindex channeldict;
eindex errorhandler_name;
eindex null_val;
eindex null_key;
eindex null_name;
eindex msgr_name;
eindex code_name;
eindex data_name;
eindex orig_name;
eindex msgr_start;
eindex host_id;
eindex mark;
eindex err_name_array;
eindex type_name_array;
/* msgr must be global! */
static void
local_submit(mproc p, void *data, eindex m)
{
eindex *ip = (eindex *)data;
TRACE(4, printf("local submit (length %d)\n", elen(p, m)))
new_proc(m, ip ? *ip : 0);
}
retcode low_level_init(void)
{
eindex ei, *ip;
eptr ep;
retcode rc;
int i;
byte hid[8];
global = (eptr) calloc(MAXGLOBALS, sizeof(struct element_s));
if (!global)
return ERR_IN_INIT;
randomize();
null_val = new_element(0, T_NULL);
null_key = key_add((byteptr)"\0\0\0\0\0\0\0\0");
null_name = name_add((byteptr)"null", 4, A_EXECUTABLE);
systemdict = new_dict(0);
if (!systemdict)
return ERR_IN_INIT;
queuedict = new_dict(0);
channeldict = new_dict(0);
dict_def(0, systemdict, null_name, null_val);
decref(0, null_name);
decref(0, null_val);
msgr_name = name_add((byteptr)"_mgr", 4, A_EXECUTABLE);
code_name = name_add((byteptr)"_cod", 4, A_EXECUTABLE);
data_name = name_add((byteptr)"_dat", 4, A_EXECUTABLE);
orig_name = name_add((byteptr)"_ori", 4, A_EXECUTABLE);
mark = new_element(0, T_MARK);
msgr_start = str_import(0, msgr_start_s,
strlen((char*)msgr_start_s), 0);
ep = gaddr(msgr_start);
epattr(ep) |= A_EXECUTABLE;
epattr(ep) &= ~A_WRITE;
fillin_hostid(hid);
host_id = key_add(hid);
err_name_array = new_array(0, LAST_ERROR);
ip = gaddr(err_name_array)->V.arr.a;
for (i=0; i<LAST_ERROR; i++)
*ip++ = name_add((byteptr)error_names[i], strlen(error_names[i]), A_EXECUTABLE);
gaddr(null_val)->R -= LAST_ERROR;
ei = name_add(ERRORNAMES, strlen((char*)ERRORNAMES), A_EXECUTABLE);
dict_def(0, systemdict, ei, err_name_array);
decref(0, ei);
decref(0, err_name_array);
type_name_array = new_array(0, LAST_TYPE);
ip = gaddr(type_name_array)->V.arr.a;
for (i=0; i<LAST_TYPE; i++)
*ip++ = name_add((byteptr)type_names[i], strlen(type_names[i]), A_EXECUTABLE);
decref(0, null_name);
gaddr(null_val)->R -= LAST_TYPE;
ei = name_add(TYPENAMES, strlen((char*)TYPENAMES), A_EXECUTABLE);
dict_def(0, systemdict, ei, type_name_array);
decref(0, ei);
decref(0, type_name_array);
errorhandler_name = name_add(ERRORHANDLER_NAME,
strlen((char*)ERRORHANDLER_NAME), A_EXECUTABLE);
new_channel(null_key, 0, local_submit);
/*
decref(0, null_key);
*/
return OK;
}