source: golgotha/src/i4/lisp/li_load.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.2 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9#include "lisp/lisp.hh"
10#include "loaders/dir_load.hh"
11#include "loaders/dir_save.hh"
12#include "lisp/li_load.hh"
13
14li_type_number *li_load_type_info(i4_loader_class *fp, li_environment *env)
15{
16  int t_types=fp->read_16(), i;
17  if (!t_types)
18    return 0;
19
20 
21  li_type_number *remap=(li_type_number *)i4_malloc(sizeof(li_type_number) * t_types, "");
22  memset(remap, 0, sizeof(li_type_number) * t_types);
23
24  for (i=1; i<t_types; i++)
25  {
26    char buf[300];
27    int l=fp->read_16();
28    if (l>sizeof(buf))
29      li_error(env, "load type name too long");
30
31    fp->read(buf, l);
32   
33    for (int j=1; j<li_max_types(); j++)
34      if (li_valid_type(j))
35        if (strcmp(buf, li_get_type(j)->name())==0)
36          remap[i]=j;   
37  }
38
39  for (i=1; i<t_types; i++)
40  {
41    w32 skip=fp->read_32();
42
43    if (remap[i])
44    {
45      //      i4_warning("%d : remap for %s", i, li_get_type(remap[i])->name());
46      li_get_type(remap[i])->load(fp, remap, env);
47    }
48    else
49      fp->seek(fp->tell() + skip);
50  }
51
52
53  return remap;
54}
55
56
57void li_free_type_info(li_type_number *remap)
58{
59  if (remap)
60    i4_free(remap);
61
62  for (int i=1; i<li_max_types(); i++)
63    if (li_valid_type(i))
64      li_get_type(i)->load_done();
65}
66
67void li_save_type_info(i4_saver_class *fp, li_environment *env)
68{
69  int t_types=1, i;
70  for (i=1; i<li_max_types(); i++)
71    if (li_valid_type(i))
72      t_types++;
73
74  // save the name and number of each type
75  fp->write_16(t_types);
76  for (i=1; i<li_max_types(); i++)
77  {
78    if (li_valid_type(i))
79    {
80      char *n=li_get_type(i)->name();
81      int nl=strlen(n)+1;
82      fp->write_16(nl);
83      fp->write(n,nl);
84    }
85    else
86      fp->write_16(0);
87  }
88
89  for (i=1; i<li_max_types(); i++)
90  {
91    if (li_valid_type(i))
92    {
93      int handle=fp->mark_size();
94      li_get_type(i)->save(fp, env);
95      fp->end_mark_size(handle);
96    }
97
98  }
99}
100
101
102
103li_object *li_load_typed_object(char *type_name, i4_loader_class *fp,
104                                li_type_number *type_remap,
105                                li_environment *env)
106{
107  int type=li_find_type(type_name);
108  if (!type)
109    li_error(env,"no type %s", type_name);
110  else
111  {
112    li_object *o=li_load_object(fp, type_remap, env);
113    if (!o || o->type()!=type)
114      return li_new(type);
115    else
116      return o;
117  }
118
119  return 0;
120}
121
122li_object *li_load_typed_object(int type, i4_loader_class *fp, li_type_number *type_remap,
123                                li_environment *env)
124
125  li_object *o=li_load_object(fp, type_remap, env);
126  if (!o || o->type()!=type)
127  {
128    if (type)   
129      return li_new(type);
130    else return 0;
131  }
132  else
133    return o;
134}
Note: See TracBrowser for help on using the repository browser.