home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / IINIT.C < prev    next >
C/C++ Source or Header  |  1992-09-20  |  7KB  |  234 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* iinit.c */
  21. /* Initialize internally known objects for Ghostscript interpreter */
  22. #include "string_.h"
  23. #include "ghost.h"
  24. #include "alloc.h"
  25. #include "dict.h"
  26. #include "dstack.h"
  27. #define INCLUDE_ERROR_NAMES        /* see errors.h */
  28. #include "errors.h"
  29. #include "name.h"
  30. #include "oper.h"
  31. #include "save.h"            /* for alloc_refs */
  32. #include "store.h"
  33.  
  34. /* Define the revision and revision date of this interpreter. */
  35. /* The revision is the Ghostscript release number x 100 + the sub-release. */
  36. const int gs_revision = 252;
  37. const char *gs_revisiondate = "9/20/92";
  38.  
  39. /* Implementation parameters. */
  40. /* The size of systemdict can be set in the makefile. */
  41. #ifndef SYSTEMDICT_SIZE
  42. /* We want the size to be a prime number large enough to cover */
  43. /* all the operators, plus everything in the init files, */
  44. /* even if all the optional features are selected. */
  45. #  define SYSTEMDICT_SIZE 479
  46. #endif
  47. /* The number of permanent dstack entries can be set in the makefile. */
  48. #ifndef MIN_DSTACK_SIZE
  49. #  define MIN_DSTACK_SIZE 2
  50. #endif
  51. #define op_array_table_size 100        /* arbitrary */
  52.  
  53. /* Standard dictionaries */
  54. ref name_errordict;
  55. /* Error names */
  56. ref name_ErrorNames;
  57.  
  58. /* The operator tables */
  59. op_def_ptr *op_def_table;
  60. uint op_def_count;
  61. ref op_array_table;    /* t_array, definitions of `operator' procedures */
  62. ushort *op_array_nx_table;        /* name indices for same */
  63. uint op_array_count;
  64.  
  65. /* Enter a name and value into systemdict */
  66. void
  67. initial_enter_name(const char *nstr, ref *pref)
  68. {    ref nref;
  69.     name_enter(nstr, &nref);
  70.     if ( dict_put(&systemdict, &nref, pref) )
  71.         lprintf("dict_put failed!\n"),
  72.         gs_exit(1);
  73. }
  74.  
  75. /* Initialize objects other than operators */
  76. void
  77. obj_init()
  78. {
  79.     /* Create the system dictionary */
  80.     dict_create(SYSTEMDICT_SIZE, &systemdict);
  81.     min_dstack_size = MIN_DSTACK_SIZE;
  82.     { int i;
  83.       for ( i = 1; i < MIN_DSTACK_SIZE; i++ )
  84.         dstack[i] = dstack[0]; /* just during initialization */
  85.     }
  86.  
  87.     /* Initialize the predefined names other than operators */
  88.     {    ref vtemp;
  89.         make_tv(&vtemp, t_null, intval, 0);
  90.         initial_enter_name("null", &vtemp);
  91.         make_int(&vtemp, gs_revision);
  92.         initial_enter_name("revision", &vtemp);
  93.         make_tasv(&vtemp, t_string, a_readonly,
  94.               strlen(gs_revisiondate),
  95.               const_bytes, (const byte *)gs_revisiondate);
  96.         initial_enter_name("revisiondate", &vtemp);
  97.     }
  98.  
  99.     /* Create other system-known names */
  100.     name_enter("errordict", &name_errordict);
  101.     name_enter("ErrorNames", &name_ErrorNames);
  102.  
  103.     /* Create the error name table */
  104.        {    int n = sizeof(gs_error_names) / sizeof(char _ds *) - 1;
  105.         int i;
  106.         ref era;
  107.         make_tasv(&era, t_array, a_readonly, n, refs,
  108.               alloc_refs(n, "obj_init(ErrorNames)"));
  109.         for ( i = 0; i < n; i++ )
  110.           name_enter((char *)gs_error_names[i], era.value.refs + i);
  111.         dict_put(&systemdict, &name_ErrorNames, &era);
  112.        }
  113. }
  114.  
  115. /* Optional devices and .ps files are handled in gconfig.c. */
  116. /* Compiled fonts are handled in iccfont.c. */
  117. #define device_(dev)
  118. #define font_(fname, fproc, zfproc)
  119. #define psfile_(fns)
  120.  
  121. /* Initialize the operators */
  122. #define oper_(defs) defs[],
  123.     /* Non-graphics operators */
  124. extern op_def
  125. #include "gconfig.h"
  126.   interp_op_defs[],
  127.   zarith_op_defs[], zarray_op_defs[], zcontrol_op_defs[],
  128.   zdict_op_defs[], zfile_op_defs[], zfileio_op_defs[],
  129.   zfilter_op_defs[], zgeneric_op_defs[],
  130.   zmath_op_defs[], zmisc_op_defs[], zpacked_op_defs[], zprops_op_defs[],
  131.   zrelbit_op_defs[], zstack_op_defs[], zstring_op_defs[],
  132.   ztype_op_defs[], zvmem_op_defs[],
  133.     /* Graphics operators */
  134.   zchar_op_defs[], zcolor_op_defs[], zdevice_op_defs[],
  135.   zfont_op_defs[], zfont1_op_defs[], zfont2_op_defs[],
  136.   zgstate_op_defs[], zht_op_defs[],
  137.   zmatrix_op_defs[], zpaint_op_defs[], zpath_op_defs[],
  138.   zpath2_op_defs[];
  139. #undef oper_
  140. #define oper_(defs) defs,
  141. private op_def_ptr op_defs_all[] = {
  142. #include "gconfig.h"
  143.     /* Non-graphics operators */
  144.   interp_op_defs,
  145.   zarith_op_defs, zarray_op_defs, zcontrol_op_defs,
  146.   zdict_op_defs, zfile_op_defs, zfileio_op_defs,
  147.   zfilter_op_defs, zgeneric_op_defs,
  148.   zmath_op_defs, zmisc_op_defs, zpacked_op_defs, zprops_op_defs,
  149.   zrelbit_op_defs, zstack_op_defs, zstring_op_defs,
  150.   ztype_op_defs, zvmem_op_defs,
  151.     /* Graphics operators */
  152.   zchar_op_defs, zcolor_op_defs, zdevice_op_defs,
  153.   zfont_op_defs, zfont1_op_defs, zfont2_op_defs,
  154.   zgstate_op_defs, zht_op_defs,
  155.   zmatrix_op_defs, zpaint_op_defs, zpath_op_defs,
  156.   zpath2_op_defs,
  157.     /* end marker */
  158.   (op_def_ptr)0
  159. };
  160. #undef oper_
  161. #undef device_
  162.  
  163. /* Run the initialization procedures of the individual operator files. */
  164. void
  165. zop_init()
  166. {    op_def_ptr _ds *tptr;
  167.     op_def_ptr def;
  168.     for ( tptr = op_defs_all; *tptr != 0; tptr++ )
  169.        {    for ( def = *tptr; def->oname != 0; def++ ) ;
  170.         if ( def->proc != 0 )
  171.             ((void (*)(P0()))(def->proc))();
  172.        }
  173. }
  174. /* Initialize the operator table. */
  175. void
  176. op_init()
  177. {    int count = 1;
  178.     op_def_ptr _ds *tptr;
  179.     op_def_ptr def;
  180.     const char _ds *nstr;
  181.  
  182.     /* Do a first pass just to count the operators. */
  183.  
  184.     for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
  185.      for ( def = *tptr; def->oname != 0; count++, def++ )
  186.       ;
  187.  
  188.     /* Do a second pass to construct the operator table, */
  189.     /* and enter the operators in systemdict. */
  190.  
  191.     op_def_table = (op_def_ptr *)alloc(count, sizeof(op_def_ptr),
  192.                        "op_init(op_def_table)");
  193.     op_def_count = count;
  194.     count = 1;
  195.     for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
  196.      for ( def = *tptr; (nstr = def->oname) != 0; count++, def++ )
  197.        {    ref nref, oper;
  198.         make_oper(&oper, count, (dummy_op_proc_p)(def->proc));
  199.         interp_fix_op(&oper);        /* optimize if possible */
  200.         /* The first character of the name is a digit */
  201.         /* giving the minimum acceptable number of operands. */
  202.         /* For now, we just skip over it. */
  203.         nstr++;
  204.         /* Don't enter internal operators into systemdict. */
  205.         if ( *nstr == '%' )
  206.             name_enter(nstr, &nref);
  207.         else
  208.             initial_enter_name(nstr, &oper);
  209.         if ( def->oindex != 0 )
  210.             *def->oindex = count;
  211.         op_def_table[count] = def;
  212.        }
  213.  
  214.     /* Allocate the table for `operator' procedures. */
  215.        {    ref *tbody =
  216.           alloc_refs(op_array_table_size, "op_array table");
  217.         make_tasv(&op_array_table, t_array, a_readonly,
  218.               op_array_table_size, refs, tbody);
  219.         refset_null(tbody, op_array_table_size);
  220.         op_array_nx_table =
  221.           (ushort *)alloc(op_array_table_size, sizeof(ushort),
  222.                   "op_array nx table");
  223.         op_array_count = 0;
  224.        }
  225.  
  226. }
  227.  
  228. /* Initialize variables that hold name constants. */
  229. void
  230. init_names(register const names_def _ds *pnd)
  231. {    for ( ; pnd->vname != 0; pnd++ )
  232.         name_enter(pnd->vname, pnd->pvref);
  233. }
  234.