forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

file io->fgets equivalent?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Stellar



Joined: 12 Dec 2005
Posts: 48

PostPosted: Mon Jan 09, 2006 10:30 am    Post subject: file io->fgets equivalent? Reply with quote

Im porting one of my works from pc in directx to psp. I need to port my file routines, which i usually use FILE* and fread/fgets/.... . It seems now, that we should be using file descriptors and psp specific io functions.

therefore, what is the equivalent for fgets?

thanks,
-stellar
_________________
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Jan 09, 2006 11:11 am    Post subject: Re: file io->fgets equivalent? Reply with quote

Stellar wrote:
Im porting one of my works from pc in directx to psp. I need to port my file routines, which i usually use FILE* and fread/fgets/.... . It seems now, that we should be using file descriptors and psp specific io functions.

No, unless you have a specific reason you can't use newlib, just go ahead and keep using fopen and fgets. Newlib is linked by default in build.mak.
Back to top
View user's profile Send private message
Stellar



Joined: 12 Dec 2005
Posts: 48

PostPosted: Mon Jan 09, 2006 11:29 am    Post subject: Reply with quote

I tried using it. it compiles no problem, but it acts just like read does. It wont stop reading at a newline the way fgets on pc does. instead, it reads the size that is passed in :( ?
_________________
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Jan 09, 2006 11:51 am    Post subject: Reply with quote

It might not treat newlines the same (ie. your PC might accept just "\r" while the PSP might want "\n", etc). If you post an example of code that has a problem, and upload a zip somewhere with the text file you're trying to read, maybe we can see a problem.
Back to top
View user's profile Send private message
Stellar



Joined: 12 Dec 2005
Posts: 48

PostPosted: Mon Jan 09, 2006 12:13 pm    Post subject: Reply with quote

the text file was converted using ' dos2unix rocket.x3d rocket.x3d '

i have attached the source code, which is in its simplest form, it should just write the file out to the screen.

zip attached here

Code:

void ReadFile()
{
   char szBuffer[128];
   FILE *fd = fopen( "rocket.x3d", "r" );

   if ( fd )
   {
      while ( fgets( szBuffer, sizeof( szBuffer ), fd ) )
      {
         printf( "%s", szBuffer );
      }

      fclose( fd );
   }
   else
   {
      printf( "failed to open (%s)\n", "rocket.x3d" );
   }
}


and thanks for you generosity :)
_________________
Back to top
View user's profile Send private message
dbeyer3069



Joined: 19 Dec 2005
Posts: 81

PostPosted: Mon Jan 09, 2006 12:15 pm    Post subject: Reply with quote

Stellar wrote:
I tried using it. it compiles no problem, but it acts just like read does. It wont stop reading at a newline the way fgets on pc does. instead, it reads the size that is passed in :( ?


I played with this one day and couldn't get results I was happy with. I was lucky that the data I was working with (array of structures) could be (and is) stored in a structure so I just did a read (sizeof(structure) * number of entries) and did a write for the same thing. It's faster too with only one read and write. I got nothing but general wierdness with the linefeeds (\n) in the files. If your data is setup this way, you may want to try this.

Note: Many string functions are not implemented yet (or not fully) and there's no guarantee things work as they do in standard libs. Look at the source for those libraries and you'll see what I mean.

If you can do your reads/writes in the same way I do (arrays of structures), you may consider converting them on the pc side and moving the data over to be read by the psp app (without linefeeds).

David Beyer
Back to top
View user's profile Send private message
Stellar



Joined: 12 Dec 2005
Posts: 48

PostPosted: Mon Jan 09, 2006 12:49 pm    Post subject: Reply with quote

Ive already started adding a binary option for my exporter. I know ill have to do it eventually just to keep file sizes down and make thinks simpler. in terms of tring functions. I stay exclusive to standard c routines, so im assuming you're not referring to strcat, strcmp, strcpy. thats pretty much all i use :)

anyway, i wanted to read text cause thats the way my pc model class works and I just wanted to see some results on the psp since this is my first program, just anxious i guess.
_________________
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Jan 09, 2006 12:59 pm    Post subject: Reply with quote

Stellar wrote:
i have attached the source code, which is in its simplest form, it should just write the file out to the screen.

OK, now I'm confused. Your program works perfectly. The entire file gets copied to the screen. Where's the problem? I also modified it to make sure fgets() was only returning one line at a time, and it is.
dbeyer3069 wrote:
Note: Many string functions are not implemented yet (or not fully) and there's no guarantee things work as they do in standard libs. Look at the source for those libraries and you'll see what I mean.

What string functions are not implemented or are not complete? Newlib is a pretty standard library.
Back to top
View user's profile Send private message
dbeyer3069



Joined: 19 Dec 2005
Posts: 81

PostPosted: Mon Jan 09, 2006 1:42 pm    Post subject: Reply with quote

Quote:
What string functions are not implemented or are not complete? Newlib is a pretty standard library.


Good question. I reinstalled and updated all my pspdev (cygwin) today and I cannot find the sources I was looking at (must have been much older ones). The source code (stdio) had numerous functions commented out and said they weren't implemented fully (and I tried with no luck). Looks like I have replaced all that.

I had been looking at sscanf() which wasn't implemented into the sources I had. Glad you mentioned this -- I can try it again. Not sure how I got such old stuff.

David Beyer
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group