mirror of
https://github.com/ksherlock/profuse.git
synced 2024-06-10 17:29:32 +00:00
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@306 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
756dd6b769
commit
3d8bed44b3
67
apfm.cpp
67
apfm.cpp
|
@ -21,9 +21,12 @@
|
||||||
|
|
||||||
#include <Pascal/Pascal.h>
|
#include <Pascal/Pascal.h>
|
||||||
#include <Pascal/Date.h>
|
#include <Pascal/Date.h>
|
||||||
|
#include <Pascal/TextWriter.h>
|
||||||
|
|
||||||
#include <Device/BlockDevice.h>
|
#include <Device/BlockDevice.h>
|
||||||
|
|
||||||
#include <File/File.h>
|
#include <File/File.h>
|
||||||
|
#include <File/MappedFile.h>
|
||||||
|
|
||||||
|
|
||||||
enum commands {
|
enum commands {
|
||||||
|
@ -854,28 +857,68 @@ int action_put(int argc, char **argv, Pascal::VolumeEntry *volume)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
File::File file(infile, O_RDONLY);
|
File file(infile, File::ReadOnly);
|
||||||
|
|
||||||
|
|
||||||
unsigned blocks = (st.st_size + 511) / 511;
|
unsigned blocks = (st.st_size + 511) / 511;
|
||||||
|
|
||||||
// TODO -- if text file, ..
|
|
||||||
|
|
||||||
Pascal::FileEntry *entry = volume->create(infile, blocks);
|
|
||||||
if (!entry)
|
|
||||||
{
|
|
||||||
perror(NULL);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
entry->setFileKind(type);
|
|
||||||
|
|
||||||
|
|
||||||
if (type == Pascal::kTextFile)
|
if (type == Pascal::kTextFile)
|
||||||
{
|
{
|
||||||
//...
|
Pascal::TextWriter text;
|
||||||
|
|
||||||
|
MappedFile mf(file, File::ReadOnly, st.st_size);
|
||||||
|
|
||||||
|
const char *address = (const char *)mf.address();
|
||||||
|
|
||||||
|
unsigned start = 0;
|
||||||
|
unsigned length = st.st_size;
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < length; ++i)
|
||||||
|
{
|
||||||
|
char c = address[i];
|
||||||
|
if (c == 0x0d || c == 0x0a)
|
||||||
|
{
|
||||||
|
text.writeLine(address + start, i - start);
|
||||||
|
start = i + 1;
|
||||||
|
|
||||||
|
if (c == 0x0a && i < length && address[i +1 ] == 0x0d)
|
||||||
|
{
|
||||||
|
++start;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//any remainder.
|
||||||
|
if (start != length) text.writeLine(address + start, length - start);
|
||||||
|
|
||||||
|
blocks = text.blocks();
|
||||||
|
|
||||||
|
Pascal::FileEntry *entry = volume->create(infile, blocks);
|
||||||
|
if (!entry)
|
||||||
|
{
|
||||||
|
perror(NULL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->setFileKind(type);
|
||||||
|
entry->write(text);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Pascal::FileEntry *entry = volume->create(infile, blocks);
|
||||||
|
if (!entry)
|
||||||
|
{
|
||||||
|
perror(NULL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry->setFileKind(type);
|
||||||
|
|
||||||
|
|
||||||
uint8_t buffer[512];
|
uint8_t buffer[512];
|
||||||
unsigned remaining = st.st_size;
|
unsigned remaining = st.st_size;
|
||||||
unsigned offset = 0;
|
unsigned offset = 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user