English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 01 May 2020, 17:02   #1
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 815
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).
Sim085 is offline  
Old 01 May 2020, 17:06   #2
Samurai_Crow
Total Chaos forever!

Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 46
Posts: 1,699
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.
Samurai_Crow is offline  
Old 01 May 2020, 17:31   #3
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 50
Posts: 583
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 is offline  
Old 01 May 2020, 17:32   #4
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 50
Posts: 583
Quote:
Originally Posted by Sim085 View Post
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?
alkis is offline  
Old 01 May 2020, 17:45   #5
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 815
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 View Post
What's the use case for that? What are you trying to do?
Sim085 is offline  
Old 01 May 2020, 17:50   #6
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 815
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 View Post
Also, if you use OS functions you lose C portability and you make your code amiga-specific.
Sim085 is offline  
Old 01 May 2020, 19:07   #7
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 50
Posts: 583
Quote:
Originally Posted by Sim085 View Post
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
alkis is offline  
Old 01 May 2020, 21:05   #8
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 1,152
Quote:
Originally Posted by alkis View Post
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.
Thomas Richter is offline  
Old 02 May 2020, 17:56   #9
bebbo
botcher

 
Join Date: Jun 2016
Location: Hamburg/Germany
Posts: 518
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.
bebbo is offline  
Old 03 May 2020, 10:02   #10
Sim085
Registered User
 
Join Date: Apr 2009
Location: N/A
Posts: 815
Thanks bebbo, will go through those implementations.
Sim085 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading files from current directory in assembly hukka Coders. System 40 21 May 2021 12:14
Reading / writing files and the keyboard jimmy2x2x Coders. Asm / Hardware 3 07 December 2014 19:58
UAE4Droid hard disk files and stuff Angus support.OtherUAE 1 12 November 2013 13:36
Stuff for sale amiga a1200 plus more retro stuff blast MarketPlace 23 22 June 2010 19:05

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 18:53.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.12346 seconds with 15 queries