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
|
/*
* Baltisot
* Copyright (C) 1999-2008 Nicolas "Pixel" Noble
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __INPUT_H__
#define __INPUT_H__
#include <sys/types.h>
#include <time.h>
#include <BString.h>
#include <Handle.h>
#include <Atomic.h>
#include <LockSmith.h>
enum ArchiveType {
ARCHIVE_BUILTIN = 0,
ARCHIVE_EXECUTABLE
};
class Input : public Handle {
public:
Input(const String & = "") throw (GeneralException);
Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) { Atomic::Increment(&nb_input); }
virtual ~Input() { Atomic::Decrement(&nb_input); }
virtual bool CanWrite() const { return false; }
virtual bool CanRead() const { return true; }
virtual bool CanSeek() const;
virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException);
virtual String GetName() const { return n; }
virtual ssize_t GetSize() const { return size; }
virtual time_t GetModif() const { return date_modif; }
virtual void SetZ(int = 9) throw (GeneralException);
static int GetNbInput() { return nb_input; }
struct openresults_t {
String name;
int type;
size_t size;
size_t ptr;
};
protected:
String n;
off_t size;
time_t date_modif;
openresults_t results;
bool fromarchive;
private:
int wrapopen(const String &, openresults_t *);
static int nb_input;
};
class Stdin_t : public Input {
public:
Stdin_t() {}
virtual ~Stdin_t() {}
virtual bool CanSeek() const { return false; }
virtual String GetName() const { return "Stdin"; }
};
extern Stdin_t Stdin;
class Archive : public Base {
public:
Archive(const String &, int = ARCHIVE_BUILTIN);
Archive(Handle *, int = ARCHIVE_BUILTIN);
virtual ~Archive() throw(GeneralException) { throw GeneralException("Archives ain't meant to be deleted."); }
protected:
static Archive * inarchive(const String &);
Handle * GetHandle() { return archive; }
int open(const String &, Input::openresults_t *);
private:
void create() throw (GeneralException);
bool inarchivein(const String &);
int openin(const String &, Input::openresults_t *) throw (GeneralException);
class FileTree : public Base {
public:
FileTree(const String & = "", size_t = 0, int = 0, FileTree * = 0);
int compute_ptrs(size_t = 0);
FileTree * Father() { return father; }
FileTree * Child() { return child; }
FileTree * Next() { return next; }
FileTree * Prev() { return prev; }
String name;
int type;
size_t size;
size_t ptr;
private:
void touched();
FileTree * next, * prev, * father, * child;
} filetree;
String name;
Handle * archive;
int type;
Archive * next, * prev;
static Archive * header;
static iLock lock;
friend class Input;
};
#endif
|