home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / m0 / part02 / o_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  3.3 KB  |  165 lines

  1. /*
  2.     o_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 <stdlib.h>
  26.  
  27. #include "l_proto.h"
  28. #include "o_proto.h"
  29.  
  30.  
  31. static struct built_in_s {
  32.     char *n;
  33.     retcode (*fct)();
  34. } b[] = {
  35.     {"!", o_exec},
  36.     {"$", o_submit},
  37.     {"%", o_mod},
  38.     {"&", o_and},
  39.     {"`", o_length},
  40.     {"(", o_begin},
  41.     {")", o_end},
  42.     {"*", o_mul},
  43.     {"+", o_add},
  44.     {",", o_currentqueue},
  45.     {"-", o_sub},
  46.     {".", o_currentdict},
  47.     {"/", o_div},
  48.     {":", o_put},
  49.     {";", o_random},
  50.     {"<", o_lt},
  51.     {"=", o_eq},
  52.     {">", o_gt},
  53.     {"?", o_ifelse},
  54.     {"@", o_gmt},
  55.  
  56.     {"A", o_array},
  57.     {"B", o_bind},
  58.     {"C", o_copy},
  59.     {"D", o_dict},
  60.     {"E", o_enter},
  61.     {"F", o_find},
  62.     {"G", o_get},
  63.     {"H", o_halted},
  64.     {"I", o_index},
  65.     {"J", o_exit},
  66.     {"K", o_known},
  67.     {"L", o_loop},
  68. /* M checksum */
  69.     {"N", o_neg},
  70.     {"O", o_count},
  71.     {"P", o_pop},
  72.     {"Q", o_qstate},
  73.     {"R", o_roll},
  74.     {"S", o_string},
  75.     {"T", o_getattr},
  76.     {"U", o_undef},
  77.     {"V", o_leave},
  78.     {"W", o_setattr},
  79.     {"X", o_exch},
  80.     {"Y", o_type},
  81.     {"Z", o_halt},
  82.     {"[", o_mark},
  83.     {"]", o_makearray},
  84.     {"^", o_xor},
  85.  
  86.     {"|", o_or},
  87.  
  88.     {"~", o_not},
  89.  
  90.     {"_cta", o_toarray},
  91.     {"_cte", o_toextern},
  92.     {"_cti", o_toint},
  93.     {"_ctk", o_tokey},
  94.     {"_ctl", o_toliteral},
  95.     {"_ctm", o_tomsgr},
  96.     {"_ctn", o_toname},
  97.     {"_cts", o_tostring},
  98.     {"_ctt", o_totime},
  99.     {"_ctx", o_toexecutable},
  100.  
  101.     {"_hid", o_hostid},
  102.     {"_stk", o_stack},
  103.  
  104.     {0, 0}
  105. };
  106.  
  107.  
  108. eindex loop_mark;
  109. eindex loop_iproc;
  110. eindex loop_aproc;
  111. eindex loop_dproc;
  112. eindex loop_sproc;
  113. eindex halt_mark;
  114. eindex halted_proc;
  115.  
  116. static struct loops_s {
  117.     eindex *e;
  118.     retcode (*fct)();
  119. } loops[] = {
  120.     {&loop_iproc, the_loop_iproc},
  121.     {&loop_aproc, the_loop_aproc},
  122.     {&loop_dproc, the_loop_dproc},
  123.     {&loop_sproc, the_loop_sproc},
  124.     {&halted_proc, the_halted_proc}
  125. };
  126.  
  127. retcode
  128. operator_init()
  129. {
  130.     struct built_in_s *bp;
  131.     eindex ei, ce, fe;
  132.     eptr ep;
  133.     retcode rc;
  134.     int i;
  135.  
  136.     for (bp = b; bp->n; bp++) {
  137.         ce = name_add((byteptr)(bp->n), strlen(bp->n), A_EXECUTABLE);
  138.         fe = new_element(0, T_PROC);
  139.         if (!ce || !fe)
  140.             return ERR_IN_INIT;
  141.         ep = gaddr(fe);
  142.         epattr(ep) |= A_EXECUTABLE;
  143.         ep->V.pro.fct = bp->fct;
  144.         rc = dict_def(0, systemdict, ce, fe);
  145.         if (rc!=OK)
  146.             return rc;
  147.         decref(0, ce);
  148.         decref(0, fe);
  149.     }
  150.  
  151.     halt_mark = new_element(0, T_MARK);
  152.     loop_mark = new_element(0, T_MARK);
  153.  
  154.     for (i=0; i < sizeof(loops)/sizeof(struct loops_s); i++) {
  155.         ei = new_element(0, T_PROC);
  156.         ep = gaddr(ei);
  157.  
  158.         epattr(ep) |= A_EXECUTABLE;
  159.         ep->V.pro.fct = loops[i].fct;
  160.         *(loops[i].e) = ei;
  161.     }
  162.  
  163.     return OK;
  164. }
  165.