plptools
Loading...
Searching...
No Matches
plpdirent.cc
Go to the documentation of this file.
1/*
2 * This file is part of plptools.
3 *
4 * Copyright (C) 1999-2001 Fritz Elfert <felfert@to.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 *
19 */
20#include "config.h"
21
22#include "plpdirent.h"
23
24#include <iomanip>
25
26using namespace std;
27
29 memset(uid, 0, sizeof(uid));
30}
31
32PlpUID::PlpUID(const uint32_t u1, const uint32_t u2, const uint32_t u3) {
33 uid[0] = u1; uid[1] = u2; uid[2] = u3;
34}
35
36uint32_t PlpUID::
37operator[](int idx) {
38 assert ((idx > -1) && (idx < 3));
39 return uid[idx];
40}
41
43 : size(0), attr(0), name(""), time(time_t(0)), attrstr("") {
44}
45
47 size = e.size;
48 attr = e.attr;
49 time = e.time;
50 UID = e.UID;
51 name = e.name;
52 attrstr = e.attrstr;
53}
54
55PlpDirent::PlpDirent(const uint32_t _size, const uint32_t _attr,
56 const uint32_t tHi, const uint32_t tLo,
57 const char * const _name) {
58 size = _size;
59 attr = _attr;
60 time = PsiTime(tHi, tLo);
61 UID = PlpUID();
62 name = _name;
63 attrstr = "";
64}
65
67getSize() {
68 return size;
69}
70
72getAttr() {
73 return attr;
74}
75
77getUID(int uididx) {
78 if ((uididx >= 0) && (uididx < 4))
79 return UID[uididx];
80 return 0;
81}
82
84getUID() {
85 return UID;
86}
87
88const char *PlpDirent::
89getName() {
90 return name.c_str();
91}
92
94getPsiTime() {
95 return time;
96}
97
99setName(const char *str) {
100 name = str;
101}
102
104operator=(const PlpDirent &e) {
105 size = e.size;
106 attr = e.attr;
107 time = e.time;
108 UID = e.UID;
109 name = e.name;
110 attrstr = e.attrstr;
111 return *this;
112}
113
115operator<<(ostream &o, const PlpDirent &e) {
116 ostream::fmtflags old = o.flags();
117
118 o << e.attrstr << " " << dec << setw(10)
119 << setfill(' ') << e.size << " " << e.time
120 << " " << e.name;
121 o.flags(old);
122 return o;
123}
124
126}
127
129}
130
132setMediaType(uint32_t type) {
133 mediatype = type;
134}
135
137setDriveAttribute(uint32_t attr) {
138 driveattr = attr;
139}
140
142setMediaAttribute(uint32_t attr) {
143 mediaattr = attr;
144}
145
147setUID(uint32_t attr) {
148 uid = attr;
149}
150
152setSize(uint32_t sizeLo, uint32_t sizeHi) {
153 size = ((unsigned long long)sizeHi << 32) + sizeLo;
154}
155
157setSpace(uint32_t spaceLo, uint32_t spaceHi) {
158 space = ((unsigned long long)spaceHi << 32) + spaceLo;
159}
160
162setName(char drive, const char * const volname) {
163 drivechar = drive;
164 name = "";
165 name += volname;
166}
167
169getMediaType() {
170 return mediatype;
171}
172
173static const char * const media_types[] = {
174 N_("Not present"),
175 N_("Unknown"),
176 N_("Floppy"),
177 N_("Disk"),
178 N_("CD-ROM"),
179 N_("RAM"),
180 N_("Flash Disk"),
181 N_("ROM"),
182 N_("Remote"),
183};
184
186getMediaType(std::string &ret) {
187 ret = media_types[mediatype];
188}
189
192 return driveattr;
193}
194
195static void
196appendWithDelim(string &s1, const char * const s2) {
197 if (!s1.empty())
198 s1 += ',';
199 s1 += s2;
200}
201
203getDriveAttribute(std::string &ret) {
204 ret = "";
205 if (driveattr & 1)
206 appendWithDelim(ret, _("local"));
207 if (driveattr & 2)
208 appendWithDelim(ret, _("ROM"));
209 if (driveattr & 4)
210 appendWithDelim(ret, _("redirected"));
211 if (driveattr & 8)
212 appendWithDelim(ret, _("substituted"));
213 if (driveattr & 16)
214 appendWithDelim(ret, _("internal"));
215 if (driveattr & 32)
216 appendWithDelim(ret, _("removable"));
217}
218
221 return mediaattr;
222}
223
225getMediaAttribute(std::string &ret) {
226 ret = "";
227
228 if (mediaattr & 1)
229 appendWithDelim(ret, _("variable size"));
230 if (mediaattr & 2)
231 appendWithDelim(ret, _("dual density"));
232 if (mediaattr & 4)
233 appendWithDelim(ret, _("formattable"));
234 if (mediaattr & 8)
235 appendWithDelim(ret, _("write protected"));
236}
237
239getUID() {
240 return uid;
241}
242
244getSize() {
245 return size;
246}
247
249getSpace() {
250 return space;
251}
252
254getName() {
255 return name;
256}
257
259getDrivechar() {
260 return drivechar;
261}
A class, representing a directory entry of the Psion.
Definition: plpdirent.h:78
PlpUID & getUID()
Retrieves the PlpUID object of a directory entry.
Definition: plpdirent.cc:84
std::string attrstr
Definition: plpdirent.h:184
uint32_t getSize()
Retrieves the file size of a directory entry.
Definition: plpdirent.cc:67
uint32_t getAttr()
Retrieves the file attributes of a directory entry.
Definition: plpdirent.cc:72
const char * getName()
Retrieve the file name of a directory entry.
Definition: plpdirent.cc:89
PsiTime time
Definition: plpdirent.h:183
std::string name
Definition: plpdirent.h:185
PlpDirent()
Default constructor.
Definition: plpdirent.cc:42
PlpUID UID
Definition: plpdirent.h:182
void setName(const char *str)
Set the file name of a directory entry.
Definition: plpdirent.cc:99
uint32_t attr
Definition: plpdirent.h:181
PsiTime getPsiTime()
Retrieve the modification time of a directory entry.
Definition: plpdirent.cc:94
uint32_t size
Definition: plpdirent.h:180
PlpDirent & operator=(const PlpDirent &e)
Assignment operator Mainly used by STL container classes.
Definition: plpdirent.cc:104
A class representing information about a Disk drive on the psion.
Definition: plpdirent.h:196
PlpDrive()
Default constructor.
Definition: plpdirent.cc:125
void setUID(uint32_t uid)
Definition: plpdirent.cc:147
uint32_t getMediaAttribute()
Retrieve the attributes of the media.
Definition: plpdirent.cc:220
void setSpace(uint32_t spaceLo, uint32_t spaceHi)
Definition: plpdirent.cc:157
void setSize(uint32_t sizeLo, uint32_t sizeHi)
Definition: plpdirent.cc:152
std::string getName()
Retrieve the volume name of the drive.
Definition: plpdirent.cc:254
uint32_t uid
Definition: plpdirent.h:345
std::string name
Definition: plpdirent.h:349
char getDrivechar()
Retrieve the drive letter of the drive.
Definition: plpdirent.cc:259
uint64_t getSize()
Retrieve the total capacity of the drive.
Definition: plpdirent.cc:244
void setMediaAttribute(uint32_t attr)
Definition: plpdirent.cc:142
uint32_t getDriveAttribute()
Retrieve the attributes of the drive.
Definition: plpdirent.cc:191
uint32_t driveattr
Definition: plpdirent.h:343
uint32_t mediatype
Definition: plpdirent.h:342
uint32_t getMediaType()
Retrieve the media type of the drive.
Definition: plpdirent.cc:169
uint64_t size
Definition: plpdirent.h:346
uint64_t space
Definition: plpdirent.h:347
void setName(char drive, const char *const volname)
Definition: plpdirent.cc:162
void setMediaType(uint32_t type)
Definition: plpdirent.cc:132
char drivechar
Definition: plpdirent.h:348
uint32_t getUID()
Retrieve the UID of the drive.
Definition: plpdirent.cc:239
void setDriveAttribute(uint32_t attr)
Definition: plpdirent.cc:137
uint32_t mediaattr
Definition: plpdirent.h:344
uint64_t getSpace()
Retrieve the free capacity on the drive.
Definition: plpdirent.cc:249
A class, representing the UIDs of a file on the Psion.
Definition: plpdirent.h:40
long uid[3]
Definition: plpdirent.h:63
PlpUID()
Default constructor.
Definition: plpdirent.cc:28
uint32_t operator[](int idx)
Retrieve a UID value.
Definition: plpdirent.cc:37
Psion time related utility class.
Definition: psitime.h:125
Definition: doctest.h:522
static const char *const media_types[]
Definition: plpdirent.cc:173
ostream & operator<<(ostream &o, const PlpDirent &e)
Definition: plpdirent.cc:115
static void appendWithDelim(string &s1, const char *const s2)
Definition: plpdirent.cc:196
#define _(String)
Definition: plpintl.h:35
#define N_(String)
Definition: plpintl.h:36