Loading Textfiles

Alright, It’s 1:19 AM as I write this… And I surrender.

I surrender, please, kill me quickly.

For the past 4 hours, I have been trying to figure out a good agile way to
load a textfile, and I get a feeling it’s just 1 little peck on my shoulder
away from being successful. But seriously, I give up!

Could someone post a link, or maybe paste a tutorial here, to a good way to
load textfiles intelligently?

If ya could, that would rock :slight_smile:

It’s also 1:22 AM now, and I am beyond tired (I don’t know why though, I
usually don’t wear down till 4:50 AM), so please excuse the grammer,
punctuation, and spelling problems :slight_smile:
-Bryan Arant

For the past 4 hours, I have been trying to figure out a good agile way to
load a textfile, and I get a feeling it’s just 1 little peck on my shoulder
away from being successful. But seriously, I give up!

A…textfile?

Any specific format to this thing?

–ryan.

Alright, It’s 1:19 AM as I write this… And I surrender.

I surrender, please, kill me quickly.

Hah! You ain’t geddin’way thad’easy… :wink:

For the past 4 hours, I have been trying to figure out a good agile way
to load a textfile, and I get a feeling it’s just 1 little peck on my
shoulder away from being successful. But seriously, I give up!

Could someone post a link, or maybe paste a tutorial here, to a good
way to load textfiles intelligently?

Are you having an end-of-line problem, or what’s going on…? What
language and functions/classes are you using? What do you want to do with
the data?

If ya could, that would rock :slight_smile:

Well, I don’t really understand what you’re looking for. :slight_smile:

And besides, in what way is this related to SDL…?

It’s also 1:22 AM now, and I am beyond tired (I don’t know why though,
I usually don’t wear down till 4:50 AM), so please excuse the grammer,
punctuation, and spelling problems :slight_smile:

Seriously, stop banging your head into the wall and get some sleep! :slight_smile:

I’ve been hacking for some 17 years, and my experience is that
1) everything is sooo much simpler tomorrow, and
2) the brain isn’t as passive as you might think while you’re asleep.

Good luck with the text files! :slight_smile:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Monday 12 November 2001 10:24, Bryan Arant wrote:

Okey Dokey… It was early in the morning… lemme alone :stuck_out_tongue:

This isn’t THAT related to SDL, but since you are all such smart people…
kicks the pebble on the ground around with his foot

Alright here’s the deal.

tile{
x: 1312
y: 128
file: “grass.bmp”
}

This is the format…
I want it to go through the file and look for “tile{” then… start looking
for “x:” then the number right after that should be assigned to the integer
x.
Then search for y, and assign y.
Look for file, then assign file… then I will take that info and make tiles
out of it.

then when it finds “}” start over looking for “tile{” or some other thing.

I’ve made a way to load tiles before, but it wasn’t very flexible, and I
wouldn’t be able to define things like:

animation_tile {
x: 32
y: 32
files: “grass1.bmp”
“grass2.bmp”
“grass3.bmp”
}

When I go to load the x,y, and the file it spits out 0 for x and y, and some
garble 30 characters long for the file.
And yes, x = 0 and y = 0 before I started all this :wink:

Hope I have given you enough info this time around. Thank you for even
responding :slight_smile:

-Bryan Arant

“David Olofson” <david.olofson at reologica.se> wrote in message
news:mailman.1005585062.12203.sdl at libsdl.org

Alright, It’s 1:19 AM as I write this… And I surrender.

I surrender, please, kill me quickly.

Hah! You ain’t geddin’way thad’easy… :wink:

For the past 4 hours, I have been trying to figure out a good agile way
to load a textfile, and I get a feeling it’s just 1 little peck on my
shoulder away from being successful. But seriously, I give up!

Could someone post a link, or maybe paste a tutorial here, to a good
way to load textfiles intelligently?

Are you having an end-of-line problem, or what’s going on…? What
language and functions/classes are you using? What do you want to do with
the data?

If ya could, that would rock :slight_smile:

Well, I don’t really understand what you’re looking for. :slight_smile:

And besides, in what way is this related to SDL…?

It’s also 1:22 AM now, and I am beyond tired (I don’t know why though,
I usually don’t wear down till 4:50 AM), so please excuse the grammer,
punctuation, and spelling problems :slight_smile:

Seriously, stop banging your head into the wall and get some sleep! :slight_smile:

I’ve been hacking for some 17 years, and my experience is that

  1. everything is sooo much simpler tomorrow, and
  2. the brain isn’t as passive as you might think while you’re asleep.

Good luck with the text files! :slight_smile:

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Monday 12 November 2001 10:24, Bryan Arant wrote:

“Bryan Arant” wrote:

This isn’t THAT related to SDL, but since you are all such smart people…

Please, list, do not answer questions such as this one.

(Or if you answer it, sneak in some subtle but fatal errors in case it
was homework.)

> Alright here's the deal. > > tile{ > x: 1312 > y: 128 > file: "grass.bmp" > }

Why not use something more standard like (dare I suggest it!?) XML?

…or something…

Then use something like libXML?

-bill!On Mon, Nov 12, 2001 at 10:35:44AM -0800, Bryan Arant wrote:

Okey Dokey… It was early in the morning… lemme alone :stuck_out_tongue:

This isn’t THAT related to SDL, but since you are all such smart
people… kicks the pebble on the ground around with his foot

Uhm, ok… allright then.

Alright here’s the deal.

tile{
x: 1312
y: 128
file: “grass.bmp”
}

Ok, so we’re talking about parsing here… :slight_smile:

This is the format…
I want it to go through the file and look for “tile{” then… start
looking for “x:” then the number right after that should be assigned to
the integer x.
Then search for y, and assign y.
Look for file, then assign file… then I will take that info and make
tiles out of it.

then when it finds “}” start over looking for “tile{” or some other
thing.

I’ve made a way to load tiles before, but it wasn’t very flexible, and
I wouldn’t be able to define things like:

animation_tile {
x: 32
y: 32
files: “grass1.bmp”
“grass2.bmp”
“grass3.bmp”
}

When I go to load the x,y, and the file it spits out 0 for x and y, and
some garble 30 characters long for the file.
And yes, x = 0 and y = 0 before I started all this :wink:

Hope I have given you enough info this time around. Thank you for even
responding :slight_smile:

Yeah, it makes a lot more sense now - I mean, how hard could it be to
read a text file? :wink: (While on the contrary, parsing is an entire form
of science, more or less…)

Sure, you could parse this kind of stuff with “raw” C or C++ code if
you really enjoy hacking that kind of stuff - or if you need top
performance, and your format is “plain” enough to be parsed in some very
efficient way.

If not, I think you should learn to use the parser generator bison (GNU
replacement for the traditional Unix tool “yacc”), or something similar.

Parser generators aren’t particularly hard to use once you figure out the
basics, and save loads of time, while still generating pretty fast
code. You get “recursive” constructs (expression in expression and the
like) virtually for free, and all you have to do is write a grammar file
with a few lines of C or C++ inside the rules.

Of course, for real flexibility, you may also need to add a symbol table
(to manage variables, labels, functions, objects etc) and other objects
commonly found in interpreters and compilers.

A parser generator lets you focus on that, and the language syntax,
instead of messing around with argument stacks, state machines and all
that - it’s already written and optimized, and the generator builds the
data structures, and stuffs your C/C++ rule code where it belongs, all
according to your grammar file.

In short, spends some time starting off “properly” with a parser
generator - after that, it’s just half an hour of hacking to add support
for mathematical expressions where you used to take “raw” numbers for
granted. Add a basic linked list symbol table (look at the one from the
bison calculator example :-), and you can add variables just as easily.

I won’t say adding scripting is all that easy, but the parser generator
makes it a lot simpler - after all, it’s the kind of problems these
tools were designed for.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Monday 12 November 2001 19:35, Bryan Arant wrote:

Oops, I scored zero there… :slight_smile:

(Not that it wasn’t expected - can’t stay away from that kind of stuff.)

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Monday 12 November 2001 20:09, Mattias Engdeg?rd wrote:

“Bryan Arant” wrote:

This isn’t THAT related to SDL, but since you are all such smart
people…

Please, list, do not answer questions such as this one.

(Or if you answer it, sneak in some subtle but fatal errors in case it
was homework.)

I’ve made a way to load tiles before, but it wasn’t very flexible, and I
wouldn’t be able to define things like:

animation_tile {
x: 32
y: 32
files: “grass1.bmp”
“grass2.bmp”
“grass3.bmp”
}

Put an XML parser in there.

This is offtopic, now, I’m afraid.

–ryan.