-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbinlib.h
More file actions
162 lines (129 loc) · 3.66 KB
/
binlib.h
File metadata and controls
162 lines (129 loc) · 3.66 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
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
/*
IL : Intlog Language
Object Oriented Prolog Project
Copyright (C) 1992-2021 - Ing. Capelli Carlo
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef BINLIB_H_
#define BINLIB_H_
#include "term.h"
// defined classes
class SourceBinaryLib;
class BinFile;
class BinIFile;
class BinOFile;
//-----------------------
// an element of library
//
class BinFile : public e_slist {
public:
kstring get_id() const;
virtual void end_data() = 0;
protected:
BinFile(kstring, SourceBinaryLib *);
BinFile(); // for file data only
// directory data
kstring id; // source identifier
unsigned nobjects; // counter of file elements
/*
streampos begdata; // track begin data in library file
streampos enddata; // file dimension
*/
streamoff begdata; // track begin data in library file
streamoff enddata; // file dimension
SourceBinaryLib *plib; // owner of this file
};
//-----------
// for input
//
class BinIFile : public BinFile {
public:
BinIFile(SourceBinaryLib *);
int read_term(Term *, kstr_list *);
int ateof() const;
virtual void end_data();
void restart();
private:
int read_term(Term *);
int read_op(Operator **);
kstring readkstr();
streampos fcursor;
};
//----------------------------------------------
// building an output section
// rely on a temporary file, to avoid problems
// in input data sequencing
//
class BinOFile : public BinFile {
public:
BinOFile(kstring, SourceBinaryLib *);
~BinOFile();
int echo_term(Term, kstr_list &);
virtual void end_data();
private:
ostream* out;
char tfn[L_tmpnam];
enum {
created, dumping, done, saved, err
} status;
int echo_term(Term);
int save_op(Operator *);
void writekstr(kstring);
friend class SourceBinaryLib;
void cat_data(ostream &);
void write_dir(ostream &) const;
};
//----------------------------------------------
// support binary data format
// a library is a list of sources, i.e.
// a set of files, each with its clauses saved
//
class SourceBinaryLib : slist {
public:
enum openMode {
toRead, toWrite
};
SourceBinaryLib(kstring, openMode);
~SourceBinaryLib();
void add_name(kstring);
BinIFile *is_input(kstring) const;
BinOFile *is_output(kstring) const;
int making() const;
int extracting() const;
private:
friend class BinIFile;
friend class BinOFile;
kstring idfile;
int match(e_slist *, void *) const;
BinFile* is_name(kstring) const;
int chkerr(int, ios * = nullptr, CCP = nullptr) const;
// on output
kstr_list kstrl;
void check_done_out();
// on input
istream *inp;
kstring *kstrv;
unsigned maxks;
void load_directory();
void check_done_inp();
};
/*************
INLINEs
**************/
inline int SourceBinaryLib::making() const {
return inp == nullptr;
}
inline int SourceBinaryLib::extracting() const {
return inp != nullptr;
}
#endif