source: golgotha/src/i4/loaders/load.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 15 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: 1.9 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 "loaders/load.hh"
10#include "memory/malloc.hh"
11#include "file/file.hh"
12#include "image/image.hh"
13#include "error/alert.hh"
14
15#include <stdlib.h>
16
17static i4_image_loader_class *loader_list=NULL;
18static w16 max_header_need=0;
19
20void i4_image_loader_class::init()
21{
22  i4_image_loader_class *who=this;
23
24  who->next=loader_list;
25  loader_list=who;
26  w16 mh=who->max_header_size();
27  if (mh>max_header_need)
28    max_header_need=mh;
29}
30
31void close_file(i4_file_class *fp)
32{
33  delete fp;
34}
35
36i4_image_class *i4_load_image(const i4_const_str &filename,
37                              i4_status_class *status)
38{
39  i4_file_class *fp;
40  fp=i4_open(filename);
41
42  if (!fp)
43    return NULL;
44 
45  i4_image_class *im=i4_load_image(fp, status);
46  if (!im)
47    i4_alert(i4gets("load_failed"),200,&filename);
48
49  delete fp;
50  return im;
51}
52
53
54i4_image_class *i4_load_image(i4_file_class *fp,
55                              i4_status_class *status)
56{
57  if (max_header_need==0)   // cannot identify any formats
58    return NULL;
59
60  i4_image_loader_class *il=loader_list;
61  i4_image_class *im=0;
62 
63
64  w8 *buf=(w8 *)i4_malloc(max_header_need,"sig buf");
65  w16 size_read=fp->read(buf,max_header_need);
66 
67  for (;!im && il;il=il->next)
68  {
69    if (size_read>=il->max_header_size())
70    {
71      if (il->recognize_header(buf))
72      {
73        fp->seek(0);
74        im=il->load(fp, status);
75      }
76    }   
77  }
78
79  i4_free(buf);
80  return im;
81}
Note: See TracBrowser for help on using the repository browser.