-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfload.cpp
More file actions
110 lines (95 loc) · 2.87 KB
/
fload.cpp
File metadata and controls
110 lines (95 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
//############################################################################
//## ##
//## FLOAD.CPP ##
//## ##
//## Loads a file into a block of memory. ##
//## ##
//## OpenSourced 12/5/2000 by John W. Ratcliff ##
//## ##
//## No warranty expressed or implied. ##
//## ##
//## Part of the Q3BSP project, which converts a Quake 3 BSP file into a ##
//## polygon mesh. ##
//############################################################################
//## ##
//## Contact John W. Ratcliff at jratcliff@verant.com ##
//############################################################################
#include "fload.h"
Fload::Fload(const String& fname)
{
mName = SGET( fname );
mData = 0;
mLen = 0;
FILE *fph = fopen( mName, "rb");
if ( fph )
{
fseek(fph, 0L, SEEK_END);
mLen = ftell(fph);
if ( mLen )
{
fseek(fph, 0L, SEEK_SET);
mData = (void *) new unsigned char[mLen+1];
assert( mData );
if ( mData )
{
int r = fread(mData, mLen, 1, fph);
assert( r );
if ( !r )
{
delete (char *) mData;
mData = 0;
}
((char *)mData)[mLen]=0;
}
}
fclose(fph);
}
mReadLoc = (char *)mData;
mReadLen = mLen;
}
Fload::~Fload(void)
{
delete (char *) mData;
}
char * Fload::GetString(void)
{
if ( !mReadLoc )
{
return 0;
}
// now advance read pointer to end of string and stomp a zero
// byte on top of it as a null string terminator.
while ( *mReadLoc == 0 || *mReadLoc == 10 || *mReadLoc == 13 )
{
mReadLoc++;
mReadLen--;
if ( !mReadLen )
{
mReadLoc = 0;
return 0;
}
}
char *ret = mReadLoc; // current read location is string location
while ( *mReadLoc && *mReadLoc != 10 && *mReadLoc != 13 )
{
mReadLoc++;
mReadLen--;
if ( !mReadLen )
{
mReadLoc = 0;
break;
}
}
if ( mReadLen ) *mReadLoc = 0; // replace line feeds with null terminated strings.
if ( mReadLoc ) mReadLoc++;
mReadLen--;
if ( !mReadLen )
{
mReadLoc = 0;
}
return ret;
}