-
Notifications
You must be signed in to change notification settings - Fork 0
/
flat.h.orig
220 lines (190 loc) · 6.85 KB
/
flat.h.orig
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//------------------------------------------------------------------------------
#ifndef __flat__H
#define __flat__H
#include <string>
#include <cstdlib>
#include <bitset>
#include <vector>
#include <map>
#include <stdio.h>
//#include <io.h>
#include <time.h>
#include "macros.h"
#include <math.h> // fabs
#include <algorithm> // To pick up max and min....
using namespace std;
// __BORLANDC__ is defined in all Borland compilers and its value indicates the
// compiler version - this one is 0x0560.
// In addition, if the compiler is set to work in the C++ mode (which
// practically means always) then __BCPLUSPLUS__ is also defined and has the
// same value as __BORLANDC__
// Note that I'm using Borland Builder 6.0, but the underlying compiler engine
// is 5.6 (the one where they got STL in properly.....)
#ifdef __BORLANDC__
#define BORLAND BORLAND
#pragma warn -8032 // Temporary created
#pragma warn -8058 // Cannot create pre-compiled header: initialised data
#include <dir.h>
#include <dos.h>
#undef MICROSOFT
#else
#define MICROSOFT MICROSOFT
#include <dos.h>
#include <io.h>
#undef BORLAND
#endif
// Routines for getting the time and date
//#ifdef MICROSOFT // We're using MicroSoft
//#include <time.h>
//#else // We're using Borland
//#include <stdio.h>
//#include <dos.h>
//#endif
// Debugging stuff
bool debug_trace(int);
#define TRACE(i) if(debug_trace(i))
typedef unsigned int uint;
typedef unsigned int uint32;
typedef unsigned int uint16;
typedef long int lint;
typedef unsigned char uchar;
typedef unsigned char byte;
/*inline*/ template<class T> int BYTES(T v=(T)0) {return sizeof(T);}
//inline void * operator new(size_t, void * p) {return p;}
int cmp_noc(const string &,const string &);
int cmp_noc(const string &,const char *);
uint32 GET4(uchar *);
void PUT4(uchar *,uint);
uchar EX8(uchar,int,int);
uint32 EX32(uint32,int,int);
void INS8(uchar *,uchar,int,int);
void INS32(uint32 *,uint32,int,int);
string to_binary(uchar);
string to_binary(uint);
string toupper(const string &);
bool file_exists(const char *);
bool file_readable(const char *);
char * GetDate();
char * GetTime();
long Time2long(const string &);
//int max(int,int);
//int min(int,int);
long Timer(long=long(0));
long mTimer(long=long(0));
void mSleep(long=0);
int nint(double);
void sign(double,double &);
void IError(int);
char * Ostr(int);
string UniS(const string &,int=0,bool=false);
unsigned UniU(int=0);
string bool2str(bool b);
string dbl2str(double);
//unsigned int hex2uint(string);
//unsigned int hex2int(string);
string hex2str(unsigned);
string int2str(int,int=0);
string long2str(long);
string uint2str(unsigned);
double str2dble(const string &,double=0.0);
int str2int(const string &,int=0);
unsigned str2uint(const string &,unsigned=0);
lint str2long(const string &);
bool str2bool(const string &);
//int sV2uV(vector<string> &,vector<unsigned> &);
string GetStr(FILE *);
void PutStr(FILE *,string);
//------------------------------------------------------------------------------
/* The following is intended to unify the Borland and u$oft
interpretations of the file-finding stuff.
Save you looking it up all the time:
BORLAND
=======
For a single file:
In <dir.h>
struct ffblk {
long ff_reserved;
long ff_fsize; // file size (bytes)
unsigned long ff_attrib; // attribute found
unsigned short ff_ftime; // file time (complicated compressed format)
unsigned short ff_fdate; // file date
char ff_name[256]; // found file name
};
"name" can contain wildcards, "attrib" is the OR of various attribute flags.
ans = findfirst(name,&fileblk,attrib); // Success returns 0, otherwise -1
ans = findnext(&fileblk); // Success returns 0, otherwise -1
ans = findnext(&fileblk);
ans = findnext(&fileblk);
.
.
.
ans = findclose(&fileblk); // Success returns 0, otherwise -1
For a given drive:
drive = 0 - default, 1 - A: ....
void getdfree(unsigned char drive,struct dfree * pdf)
struct dfree {
unsigned df_avail; // Number of available clusters
unsigned df_total; // Total number of clusters
unsigned df_bsec; // Bytes/sector
unsigned df_sclus; // Sectors/cluster
};
u$OFT
=====
For a single file:
struct _finddata_t {
unsigned attrib; // Attribute found
char name[260]; // Found full name
_fsize_t size; // File size (bytes)
__time64_t time_access; // Time last accessed - -1 in FAT systems
__time64_t time_create; // Time created - -1 in FAT systems
__time64_t time_write; // Time last written to
};
struct _finddata_t fileblk;
intptr_t rx = _findfirst("*.xpg",&fileblk); // Success returns file handle,
// otherwise -1
int ans;
ans = _findnext(rx,&fileblk); // Success returns 0, otherwise -1
ans = _findnext(rx,&fileblk);
ans = _findnext(rx,&fileblk);
.
.
.
ans = _findclose(rx); // Success returns 0, otherwise -1
For a given drive:
struct diskfree_t {
unsigned total_clusters; // count of all disk clusters
unsigned avail_clusters; // free unallocated clusters
unsigned sectors_per_cluster;
unsigned bytes_per_sector;
};
*/
// Finding files in a directory:
//
// A useful (and easy) intersection of the Borland and u$oft structures:
struct FindData_t {
void * FD_reserved; // Has to be void * 'cos of u$oft_64
long FD_fsize; // File size (bytes)
long FD_ftime; // File time
char FD_name[_MAX_PATH]; // Found file name
};
int FindFirst(const char *,struct FindData_t *);
int FindNext(struct FindData_t *);
int FindClose(struct FindData_t *);
// Directory stats:
//
// For some reason, the u$oft structure is in the Borland headers, (although
// there doesn't appear to be a Borland function that uses it?). But for the
// sake of uniformity, I copy it to a local struct defined here.
struct DiskFree_t {
unsigned DF_total_clusters; // Count of all disk clusters
unsigned DF_avail_clusters; // Free unallocated clusters
unsigned DF_sectors_per_cluster; // Guess
unsigned DF_bytes_per_sector;
};
void DiskFree(unsigned,struct DiskFree_t *);
//------------------------------------------------------------------------------
void freadstr(string &,FILE *);
void fwritestr(string,FILE *);
void HexDump(FILE *,unsigned char *,unsigned);
//==============================================================================
#endif