EOF is for suckas, Modified FileToString() here...
Displaying 1-16 of 16 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
mcgrue

Here's a gift, a FileToString() that has no 255-char-per-line limit:


/// Returns the size, in bytes, of a given file.
int FileSize( string myfile )
{
int f = FileOpen(myfile, FILE_READ);
FileSeekPos(f, 0, SEEK_END);
int size = FileCurrentPos(f);
FileClose(f);
return size;
}

/// Returns the contents of a file as one large string.
/// Modified to take into account FileReadLn's 255-len buffer.
///
/// I forget who wrote the original. Someone tell me!
///
/// @param myfile the path to the text file to read in.
/// @author mcgrue
string FileToString( string myfile )
{
string s, temp, longtemp;
int size = FileSize(myfile);

int running_count, long_flag;

int f = FileOpen(myfile, FILE_READ);
long_flag = 0;

while( FileCurrentPos(f) < size )
{
temp = FileReadLn(f);

running_count += len(temp);

/// if the running count + 2 equals the current file position,
/// then we are running within FileReadLn's buffer limit
if( (running_count+2) == FileCurrentPos(f) )
{
running_count+=2;

///we're saving the end of a very long line.
if(long_flag)
{
longtemp = longtemp+temp;
long_flag = 0;

s = s + longtemp + chr(10);
longtemp = '';
}
///we're saving a short line.
else
{
s = s + temp + chr(10);
}
}
/// If the running count didn't show the 2-byte newline signature,
/// then there was no newline, we've just run into FileReadLn's buffer limit.
/// So... raise a long-line flag and continue on.
else
{
longtemp = longtemp+temp;
long_flag = 1;
}
}

FileClose(f);

return s;
}


If the original author will please stand up, I'll put the credit in the doc as well.

-Grue

Posted on 2005-04-28 09:57:58

Jesse

This assumes windows-style CR/LF line endings, since it looks for 2-byte discrepancies. For mac or unix style files, you'll want to look for a 1-byte difference. Or you could look for both.

Posted on 2005-04-28 10:44:15

Overkill

Now, that code would be excellent, if one didn't have to manually seek-replace all ' (single quotes) made by the Verge RPG database with ' (double quotes), which is the only quote type Verge 3 accepts.

Jesse, we won't really need to worry about \r for Mac, or \n for Unix until we get adequate ports of Verge 3 on such operating systems. Speaking of which, how is that Mac port of V3 coming along?

Posted on 2005-04-28 13:51:06

mcgrue

unix-style filetypes are possible on PCs!

Posted on 2005-04-28 14:21:43

Jesse

Originally posted by overkill

Jesse, we won't really need to worry about \r for Mac, or \n for Unix until we get adequate ports of Verge 3 on such operating systems. Speaking of which, how is that Mac port of V3 coming along?


The mac port is basically ready, we're just putting together a few things for its grand release. Stay tuned.

Posted on 2005-04-28 14:31:34

Omni

...What? Mac version of V3?

Posted on 2005-04-29 09:42:12

Overkill

[15:38] <McGrue> Who is this jder person saying True things?
[15:39] <McGrue> Overkill, would you like a local copy of the vrpg db and source?
[15:39] <Overkill> Sure
[15:39] <jder> I'm new around here. I'm 'Jesse' on verge-rpg.
[15:39] <Overkill> That would help, McGrue
[15:39] <jder> I haven't done anything yet, really.
[15:39] <McGrue> What brings you to our sordid clan?
[15:40] <McGrue> Also, I need to beat Gayo into doing the new newspost.
[15:40] <jder> kildorf is a friend of mine. I'd like to help him with Geas.
[15:40] <McGrue> Oh my. Are you the mac programmer? The one spoken of in legend?
[15:40] <jder> 'The' mac programmer? I didn't realize I was famous.
[15:41] <McGrue> Us in vergedev have been whispering of your existance in shadows for years.
[15:41] <McGrue> And then Kildorf tells us that he has found... The One.
[15:41] <McGrue> There have been false prophets before.
[15:41] * jder knows kung-fu
[15:42] * Overkill fears kung-fu
[15:42] <McGrue> wao
[15:42] <jder> .. not really. It just seemed to fit. But I know C++, which is just as bad-assed.
[15:42] <McGrue> Much more esoteric.
[15:42] <McGrue> Actually, hm.
[15:43] <McGrue> I wonder if there are more black belt martial artists in the world, or competant C++ coders.

...

[21:27] <jder> I'm working on a Mac version of verge. That's exciting for mac folk.
[21:28] <SDHawk> what m- nevermind.
[21:28] * jder laughs uproariously
[21:28] <Overkill> Whoa, Mac... Verge? o_O
...
[21:30] <jder> Yeah. It's working pretty well, now, too.
[21:31] <Overkill> I bet MacMaped3 is owning Maped3 for Windows :(
[21:34] <jder> Quick Screeny: http://www.cs.dal.ca/~rusak/verge.jpg

EDIT: Screenshot link linked for you, since I forgot VergeRPG can't parse links.

Posted on 2005-04-29 14:33:03 (last edited on 2005-04-29 14:36:39)

Omni

As in, porting V3 source to Mac, or developing his own reverse engineered version?

Posted on 2005-04-29 14:59:17

Jesse

The former. Vecna has been kind enough to give me access to the verge source for the port.

Posted on 2005-04-29 15:14:36

Kildorf

I have seen the MacVerge with my own eyes, running Geas, no less! The end times, prophesied in the last century, are upon us! :O

Posted on 2005-04-29 16:02:03

Tatzen

hmm.

v3 mac. not bad.

Posted on 2005-04-29 19:00:50

rpgking

Even though I don't own a Mac, that is seriously some cool stuff. I know of a few people who'd be really happy with a Mac port of V3.

Posted on 2005-04-30 00:01:26

Gayo

Yeah, it's impossible to get those mac people to buy a real computer, so this is really the only way.

Posted on 2005-05-01 07:37:07

Overkill

I noticed a problem with this code, Grue. If the last line of the file doesn't have a new line it won't read it.

Example File 'test.txt'

A
B
C


v3.log's output

VC System Compilation stats:
12 ints (24 expanded), 0 strings (0 expanded), 16 functions, 497 total lines

A
B

Posted on 2005-05-08 13:42:09 (last edited on 2005-05-08 13:42:34)

Omni

What function are you using? GetToken, ReadString, ReadLine, etc?

OH: The one above. Nevermind.

Posted on 2005-05-08 14:03:29 (last edited on 2005-05-08 14:03:47)

Jesse

Quote:Originally posted by overkill

I noticed a problem with this code, Grue. If the last line of the file doesn't have a new line it won't read it.


This could be fixed by sticking this check after the big loop (eg just before the FileClose):


if(long_flag)
{
s = s + longtemp;
}


You could use
 s = s + longtemp + chr(10);
instead if you want it to pretend there was a newline when there isn't one on the last line.

Posted on 2005-05-08 16:02:30


Displaying 1-16 of 16 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.