home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / m0 / part02 / l_init.c < prev    next >
C/C++ Source or Header  |  1994-06-05  |  4KB  |  143 lines

  1. /*
  2.     l_init.c
  3. */
  4. /*  Copyright (c) 1994 Christian F. Tschudin. All rights reserved.
  5.  
  6.     Distributed under the terms of the GNU General Public License
  7.     version 2 of june 1991 as published by the Free Software
  8.     Foundation, Inc.
  9.  
  10.              This file is part of M0.
  11.  
  12. M0 is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY.  No author or distributor accepts responsibility to anyone for
  14. the consequences of using it or for whether it serves any particular
  15. purpose or works at all, unless he says so in writing.  Refer to the GNU
  16. General Public License for full details. 
  17.  
  18. Everyone is granted permission to copy, modify and redistribute M0, but
  19. only under the conditions described in the GNU General Public License. 
  20. A copy of this license is supposed to have been given to you along with
  21. M0 so you can know your rights and responsibilities.  It should be in a
  22. file named LICENSE.  Among other things, the copyright notice and this
  23. notice must be preserved on all copies.  */
  24.  
  25. #include "l_proto.h"
  26.  
  27. #define ERRORNAMES        (byteptr)"_ena"
  28. #define ERRORHANDLER_NAME    (byteptr)"_err"
  29. #define TYPENAMES        (byteptr)"_tna"
  30.  
  31. eptr global;
  32.  
  33. static byteptr msgr_start_s = (byteptr) ".'_loc.:_cod!";
  34.  
  35. eindex systemdict;
  36. eindex queuedict;
  37. eindex channeldict;
  38.  
  39. eindex errorhandler_name;
  40.  
  41. eindex null_val;
  42. eindex null_key;
  43. eindex null_name;
  44. eindex msgr_name;
  45. eindex code_name;
  46. eindex data_name;
  47. eindex orig_name;
  48. eindex msgr_start;
  49. eindex host_id;
  50.  
  51. eindex mark;
  52.  
  53. eindex err_name_array;
  54. eindex type_name_array;
  55.  
  56.  
  57. /* msgr must be global! */
  58.  
  59. static void
  60. local_submit(mproc p, void *data, eindex m)
  61. {
  62.     eindex *ip = (eindex *)data;
  63.     TRACE(4, printf("local submit (length %d)\n", elen(p, m)))
  64.  
  65.     new_proc(m, ip ? *ip : 0);
  66. }
  67.  
  68.  
  69. retcode low_level_init(void)
  70. {
  71.     eindex ei, *ip;
  72.     eptr ep;
  73.     retcode rc;
  74.     int i;
  75.     byte hid[8];
  76.  
  77.     global = (eptr) calloc(MAXGLOBALS, sizeof(struct element_s));
  78.     if (!global)
  79.         return ERR_IN_INIT;
  80.  
  81.     randomize();
  82.  
  83.     null_val = new_element(0, T_NULL);
  84.     null_key = key_add((byteptr)"\0\0\0\0\0\0\0\0");
  85.     null_name = name_add((byteptr)"null", 4, A_EXECUTABLE);
  86.  
  87.     systemdict = new_dict(0);
  88.     if (!systemdict)
  89.         return ERR_IN_INIT;
  90.     queuedict = new_dict(0);
  91.     channeldict = new_dict(0);
  92.  
  93.     dict_def(0, systemdict, null_name, null_val);
  94.     decref(0, null_name);
  95.     decref(0, null_val);
  96.  
  97.     msgr_name = name_add((byteptr)"_mgr", 4, A_EXECUTABLE);
  98.     code_name = name_add((byteptr)"_cod", 4, A_EXECUTABLE);
  99.     data_name = name_add((byteptr)"_dat", 4, A_EXECUTABLE);
  100.     orig_name = name_add((byteptr)"_ori", 4, A_EXECUTABLE);
  101.  
  102.     mark = new_element(0, T_MARK);
  103.     msgr_start = str_import(0, msgr_start_s,
  104.                     strlen((char*)msgr_start_s), 0);
  105.     ep = gaddr(msgr_start);
  106.     epattr(ep) |= A_EXECUTABLE;
  107.     epattr(ep) &= ~A_WRITE;
  108.  
  109.     fillin_hostid(hid);
  110.     host_id = key_add(hid);
  111.  
  112.     err_name_array = new_array(0, LAST_ERROR);
  113.     ip = gaddr(err_name_array)->V.arr.a;
  114.     for (i=0; i<LAST_ERROR; i++)
  115.         *ip++ = name_add((byteptr)error_names[i], strlen(error_names[i]), A_EXECUTABLE);
  116.     gaddr(null_val)->R -= LAST_ERROR;
  117.     ei = name_add(ERRORNAMES, strlen((char*)ERRORNAMES), A_EXECUTABLE);
  118.     dict_def(0, systemdict, ei, err_name_array);
  119.     decref(0, ei);
  120.     decref(0, err_name_array);
  121.  
  122.     type_name_array = new_array(0, LAST_TYPE);
  123.     ip = gaddr(type_name_array)->V.arr.a;
  124.     for (i=0; i<LAST_TYPE; i++)
  125.         *ip++ = name_add((byteptr)type_names[i], strlen(type_names[i]), A_EXECUTABLE);
  126.     decref(0, null_name);
  127.     gaddr(null_val)->R -= LAST_TYPE;
  128.     ei = name_add(TYPENAMES, strlen((char*)TYPENAMES), A_EXECUTABLE);
  129.     dict_def(0, systemdict, ei, type_name_array);
  130.     decref(0, ei);
  131.     decref(0, type_name_array);
  132.  
  133.     errorhandler_name = name_add(ERRORHANDLER_NAME,
  134.             strlen((char*)ERRORHANDLER_NAME), A_EXECUTABLE);
  135.  
  136.     new_channel(null_key, 0, local_submit);
  137. /*
  138.     decref(0, null_key);
  139. */
  140.  
  141.     return OK;
  142. }
  143.