mirror of
https://gitlab.com/rnger/amath
synced 2025-10-06 02:49:59 +00:00
218 lines
5.3 KiB
Groff
218 lines
5.3 KiB
Groff
.TH "StandardFilesystem" 3 "Tue Jan 24 2017" "Version 1.6.2" "amath" \" -*- nroff -*-
|
|
.ad l
|
|
.nh
|
|
.SH NAME
|
|
StandardFilesystem \-
|
|
.SH SYNOPSIS
|
|
.br
|
|
.PP
|
|
.PP
|
|
\fC#include <filesystem_stdc\&.h>\fP
|
|
.PP
|
|
Inherits \fBFilesystemBase\fP\&.
|
|
.SS "Public Member Functions"
|
|
|
|
.in +1c
|
|
.ti -1c
|
|
.RI "\fBCharBuffer\fP * \fBListDirectory\fP (const char *path)"
|
|
.br
|
|
.ti -1c
|
|
.RI "\fBCharBuffer\fP * \fBLoadTextFile\fP (const char *name)"
|
|
.br
|
|
.ti -1c
|
|
.RI "\fBbool\fP \fBSaveTextFile\fP (const char *name, const char *text)"
|
|
.br
|
|
.in -1c
|
|
.SS "Static Private Attributes"
|
|
|
|
.in +1c
|
|
.ti -1c
|
|
.RI "static const int \fBblocksize\fP = 512"
|
|
.br
|
|
.in -1c
|
|
.SH "Detailed Description"
|
|
.PP
|
|
Definition at line 42 of file filesystem_stdc\&.h\&.
|
|
.SH "Member Function Documentation"
|
|
.PP
|
|
.SS "\fBCharBuffer\fP * StandardFilesystem::ListDirectory (const char * path)\fC [virtual]\fP"
|
|
|
|
.PP
|
|
Implements \fBFilesystemBase\fP\&.
|
|
.PP
|
|
Definition at line 39 of file filesystem_stdc\&.cpp\&.
|
|
.PP
|
|
References CharBuffer::Append(), CharBuffer::CharBuffer(), CharBuffer::Empty(), CharBuffer::EnsureGrowth(), CharBuffer::EnsureSize(), CharBuffer::GetString(), StrIsEqual(), and StrLen()\&.
|
|
.PP
|
|
.nf
|
|
40 {
|
|
41 #ifdef UNIX
|
|
42 CharBuffer *pathbuf = new CharBuffer();
|
|
43 pathbuf->Empty();
|
|
44 if (path == NOMEM) {
|
|
45 pathbuf->Append("\&.");
|
|
46 } else {
|
|
47 pathbuf->EnsureSize(StrLen(path) + 1);
|
|
48 pathbuf->Append(path);
|
|
49 }
|
|
50
|
|
51 DIR *dir;
|
|
52 if ((dir = opendir(pathbuf->GetString())) == NULL) {
|
|
53 CharBuffer *res = new CharBuffer();
|
|
54 const char *msg = MSGNODIR;
|
|
55 res->EnsureSize(StrLen(msg) + StrLen(pathbuf->GetString()) + StrLen(NEWLINE) + 1);
|
|
56 res->Empty();
|
|
57 res->Append(msg);
|
|
58 res->Append(pathbuf->GetString());
|
|
59 res->Append(NEWLINE);
|
|
60
|
|
61 delete pathbuf;
|
|
62 return res;
|
|
63 }
|
|
64
|
|
65 CharBuffer *lines = new CharBuffer();
|
|
66 lines->Empty();
|
|
67
|
|
68 bool first = true;
|
|
69 struct dirent *entry;
|
|
70 while ((entry = readdir(dir)) != NULL) {
|
|
71 if (StrIsEqual(entry->d_name, "\&.") || StrIsEqual(entry->d_name, "\&.\&.")) {
|
|
72 continue;
|
|
73 }
|
|
74
|
|
75 if (first) {
|
|
76 const char *header = TXTLISTDIRHEADER;
|
|
77 lines->EnsureSize(StrLen(header) + 1);
|
|
78 lines->Empty();
|
|
79 lines->Append(header);
|
|
80 first = false;
|
|
81 }
|
|
82
|
|
83 const char *type;
|
|
84
|
|
85 switch (entry->d_type) {
|
|
86 case DT_REG:
|
|
87 type = TXTLISTDIRTFILE;
|
|
88 break;
|
|
89 case DT_DIR:
|
|
90 type = TXTLISTDIRTDIR;
|
|
91 break;
|
|
92 default:
|
|
93 type = TXTLISTDIRTUNKNOWN;
|
|
94 }
|
|
95
|
|
96 const unsigned short colsize = 12;
|
|
97 unsigned int a = StrLen(type) > colsize ? colsize : StrLen(type);
|
|
98 unsigned int b = colsize - a;
|
|
99
|
|
100 lines->EnsureGrowth(colsize + StrLen(entry->d_name) + StrLen(NEWLINE) + 1);
|
|
101 lines->Append(type);
|
|
102 lines->Append(' ', b);
|
|
103 lines->Append(entry->d_name);
|
|
104 lines->Append(NEWLINE);
|
|
105 }
|
|
106
|
|
107 closedir(dir);
|
|
108 delete pathbuf;
|
|
109 return lines;
|
|
110 #else
|
|
111 CharBuffer *lines = new CharBuffer();
|
|
112 lines->Empty();
|
|
113 return lines;
|
|
114 #endif
|
|
115 }
|
|
.fi
|
|
.SS "\fBCharBuffer\fP * StandardFilesystem::LoadTextFile (const char * name)\fC [virtual]\fP"
|
|
|
|
.PP
|
|
Implements \fBFilesystemBase\fP\&.
|
|
.PP
|
|
Definition at line 117 of file filesystem_stdc\&.cpp\&.
|
|
.PP
|
|
References CharBuffer::Append(), blocksize, CharBuffer::CharBuffer(), CharBuffer::Empty(), and CharBuffer::EnsureSize()\&.
|
|
.PP
|
|
.nf
|
|
118 {
|
|
119 FILE *file;
|
|
120
|
|
121 #if !defined(_WIN32)
|
|
122 file = fopen(name, "r");
|
|
123 #else
|
|
124 fopen_s(&file, name, "r");
|
|
125 #endif
|
|
126
|
|
127 if (!file) {
|
|
128 return NOMEM;
|
|
129 }
|
|
130
|
|
131 CharBuffer *text = new CharBuffer();
|
|
132 text->Empty();
|
|
133
|
|
134 int blocks = 0;
|
|
135 bool eof = false;
|
|
136
|
|
137 while (!eof) {
|
|
138 blocks++;
|
|
139 text->EnsureSize(blocksize, blocks);
|
|
140 int count = 0;
|
|
141
|
|
142 do
|
|
143 {
|
|
144 int c = fgetc(file);
|
|
145 eof = c == EOF;
|
|
146
|
|
147 if (!eof) {
|
|
148 text->Append((char)c);
|
|
149 count++;
|
|
150 }
|
|
151 } while (!eof && count < blocksize);
|
|
152 }
|
|
153
|
|
154 fclose(file);
|
|
155 return text;
|
|
156 }
|
|
.fi
|
|
.SS "\fBbool\fP StandardFilesystem::SaveTextFile (const char * name, const char * text)\fC [virtual]\fP"
|
|
|
|
.PP
|
|
Implements \fBFilesystemBase\fP\&.
|
|
.PP
|
|
Definition at line 158 of file filesystem_stdc\&.cpp\&.
|
|
.PP
|
|
.nf
|
|
159 {
|
|
160 FILE *file;
|
|
161
|
|
162 #if !defined(_WIN32)
|
|
163 file = fopen(name, "w");
|
|
164 #else
|
|
165 fopen_s(&file, name, "w");
|
|
166 #endif
|
|
167
|
|
168 if (!file) {
|
|
169 return false;
|
|
170 }
|
|
171
|
|
172 char *i = (char*)text;
|
|
173 int r = EOF + 11;
|
|
174 while (r != EOF && *i) {
|
|
175 r = fputc(*i++, file);
|
|
176 }
|
|
177
|
|
178 fclose(file);
|
|
179 return true;
|
|
180 }
|
|
.fi
|
|
.SH "Member Data Documentation"
|
|
.PP
|
|
.SS "const int StandardFilesystem::blocksize = 512\fC [static]\fP, \fC [private]\fP"
|
|
|
|
.PP
|
|
Definition at line 49 of file filesystem_stdc\&.h\&.
|
|
.PP
|
|
Referenced by LoadTextFile()\&.
|
|
|
|
.SH "Author"
|
|
.PP
|
|
Generated automatically by Doxygen for amath from the source code\&.
|