English Amiga Board

English Amiga Board (http://eab.abime.net/index.php)
-   Coders. C/C++ (http://eab.abime.net/forumdisplay.php?f=118)
-   -   Reading files and other stuff. (http://eab.abime.net/showthread.php?t=102051)

Sim085 01 May 2020 17:02

Reading files and other stuff.
 
I am writing a small solution, mostly using it as an excuse to write something in C for the Amiga platform.

I have searched over the internet and from what I can see there are at least two approaches one can use to open a file, either use the DOS library (Open, Read, Close) or else use the STDIO library (fopen, fread, fclose).

I wrote examples using both approaches but I am interested to know; are there any reasons why to prefer one approach over the other?

Unrelated to this; are there helper functions available to just read a file till the end rather than having to write my own implementation of this? (which would probably not consider things that may be obvious to more experienced developers and therefore be ridden with bugs).

Samurai_Crow 01 May 2020 17:06

Using the OS functions allows you to use custom or minimal startup code while the C libraries depend on having the full startup code and result in bigger executables if you do link in their code.

alkis 01 May 2020 17:31

Also, if you use OS functions you lose C portability and you make your code amiga-specific.

For example, you could write a 'cat' command line application with the standard C libs. It would produce a bigger size executable, but you could compile/run in amiga, in linux, in windows.

If you did the same with OS functions, the executable would be smaller and you could compiler/run only for amiga.

alkis 01 May 2020 17:32

Quote:

Originally Posted by Sim085 (Post 1396789)
Unrelated to this; are there helper functions available to just read a file till the end rather than having to write my own implementation of this? (which would probably not consider things that may be obvious to more experienced developers and therefore be ridden with bugs).

What's the use case for that? What are you trying to do?

Sim085 01 May 2020 17:45

That was another question I was going to ask. Basically I have a simple property file.
Code:

key1=value1
key2=value2
etc..

At the moment I am reading the file to memory and then traverse the memory checking each character and using flags to determine if I am building a key (at start or after new line is reached) or a value (after the '=' is seen). At the moment I am ignoring extra spaces at the start and end of a key or a value.

Are there helper function readily available to which I can pass a stream of characters and get the key,value list for it rather than have to do this myself?

Quote:

Originally Posted by alkis (Post 1396810)
What's the use case for that? What are you trying to do?


Sim085 01 May 2020 17:50

Ok I understand. In that case for the moment will try and use the standard libraries and then maybe go through it again and re-write with amiga specific functions.

Quote:

Originally Posted by alkis (Post 1396809)
Also, if you use OS functions you lose C portability and you make your code amiga-specific.


alkis 01 May 2020 19:07

Quote:

Originally Posted by Sim085 (Post 1396817)
That was another question I was going to ask. Basically I have a simple property file.
Code:

key1=value1
key2=value2
etc..

At the moment I am reading the file to memory and then traverse the memory checking each character and using flags to determine if I am building a key (at start or after new line is reached) or a value (after the '=' is seen). At the moment I am ignoring extra spaces at the start and end of a key or a value.

Are there helper function readily available to which I can pass a stream of characters and get the key,value list for it rather than have to do this myself?

I am not aware of standard C lib implementation on this one. I think you have to write your own. This might help https://stackoverflow.com/questions/...edirect=1&lq=1

Thomas Richter 01 May 2020 21:05

Quote:

Originally Posted by alkis (Post 1396850)
I am not aware of standard C lib implementation on this one.

Not in the stdlib, but the dos.library has something to offer, namely ReadItem() and FindArg(). It is designed to parse off exactly such argument-value pairs.

bebbo 02 May 2020 17:56

Always these futile arguments. You can deal with saved bytes and the like, or simply solve a problem.

As long as you don't want to program games or other hardware related things, I recommend to use the C/C++ standard.

And for C there are solutions for the INI reading problem:
https://github.com/compuphase/minIni
https://github.com/brofield/simpleini

But you are welcome to add one more.

Sim085 03 May 2020 10:02

Thanks bebbo, will go through those implementations.


All times are GMT +2. The time now is 19:16.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.

Page generated in 0.05298 seconds with 11 queries