git-svn-id: https://profuse.googlecode.com/svn/branches/v2@306 aa027e90-d47c-11dd-86d7-074df07e0730

This commit is contained in:
ksherlock 2010-05-31 00:07:17 +00:00
parent 756dd6b769
commit 3d8bed44b3
1 changed files with 55 additions and 12 deletions

View File

@ -21,9 +21,12 @@
#include <Pascal/Pascal.h>
#include <Pascal/Date.h>
#include <Pascal/TextWriter.h>
#include <Device/BlockDevice.h>
#include <File/File.h>
#include <File/MappedFile.h>
enum commands {
@ -854,28 +857,68 @@ int action_put(int argc, char **argv, Pascal::VolumeEntry *volume)
return -1;
}
File::File file(infile, O_RDONLY);
File file(infile, File::ReadOnly);
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)
{
//...
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
{
Pascal::FileEntry *entry = volume->create(infile, blocks);
if (!entry)
{
perror(NULL);
return -1;
}
entry->setFileKind(type);
uint8_t buffer[512];
unsigned remaining = st.st_size;
unsigned offset = 0;