Rockbox Technical Forums

Rockbox Development => Starting Development and Compiling => Topic started by: Jazz00006 on September 16, 2006, 04:38:00 AM

Title: Plugin code needed please (Read text file)
Post by: Jazz00006 on September 16, 2006, 04:38:00 AM
could some one please provide me with the code to read a text file line by line and search if for some text

i have a plugin ready for everythign else but i failed to get this part working

any help given is greatly apreciated. Thanks
Title: Re: Plugin code needed please (Read text file)
Post by: Domonoky on September 16, 2006, 09:00:41 AM
Hi.
thats pretty simple, all the functions you need are in apps/plugins.h

So to read a file line by line you do something like this:

Code: [Select]
int file = rb->open("filename",?) ;   // the ? is the flag for the opening mode, look in other plugins for the right flag for you
char buffer[100];
while(rb->readline(file,buffer,100)  !=  ??? )  //search other plugins for the right abort condition
{
   char* pos =  rb->strcasestr(buffer,"Search string");
   if(pos != 0)     //check if it is really 0 if the string is not found
   {
       // string found
       //do something on the buffer
   }
}


all code right out of my head, all untested.

hope it helps..
Title: Re: Plugin code needed please (Read text file)
Post by: Jazz00006 on September 16, 2006, 09:06:00 AM
exelent, cheers, i owe u alot,

BTW, how would i split a string with the char : ? like
split("ss:aa",":") (i know thats VB)
Title: Re: Plugin code needed please (Read text file)
Post by: Domonoky on September 16, 2006, 09:21:08 AM
hm,

i think there is no string split funktion in rockbox.

so you have to do it by hand,  either by searching for your seperator with pos = strchr(string,":")
and copying the parts,
or by stepping through the charakters of the string, copying each char in another buffer, until you reach your seperator.

If you arent familiar with string handling in c, google for a tutorial, theres much doku about string handling in C.

Title: Re: Plugin code needed please (Read text file)
Post by: Jazz00006 on September 16, 2006, 09:26:04 AM
ah well, ill just have to make my own function then =)

btw what does 'structure had no member 'readline''
Title: Re: Plugin code needed please (Read text file)
Post by: Domonoky on September 16, 2006, 09:32:22 AM
This message means theres no such member in the plugin api struct.

So you should have a look in apps/plugins.h  there are all aviable functions.
i think it should be "read_line()" not "readline()" , but to be shure look in the plugins.h header.
Title: Re: Plugin code needed please (Read text file)
Post by: Rincewind on September 16, 2006, 09:34:07 AM
I don't know if rockbox provides functions for manipulating strings.

Look in plugin.h if there are functions you can use. The general route would be:
1. search the position of ":" and save it in the variable splitpoint
2. get the substring from 0 to splitpoint
3. get the substring from splitpoint to stringlength

If there aren't api functions that do what you want, you have to search ":" in a loop:
Code: [Select]
for (int i = 0; i < stringlength; i++)
   if (string\[i\] == ':')
           splitpoint = i;

This won't work exactly like this, just to give you the idea. In C, strings are arrays of char with a terminator at the end (thats the char '\0')

Then you need to copy your string up to splitpoint in a new string var  and from splitpoint to stringlength in a second var. You can do this in a loop, copiing the chars of the string array, but don't forget to terminate your new strings with \0.

I haven't worked with strings in rockbox yet, there is a chance that I am completely wrong here.

Edit: BBCode doesn't like [ in my code
Title: Re: Plugin code needed please (Read text file)
Post by: Jazz00006 on September 16, 2006, 09:37:29 AM
WOW, everyone here is so helpful :) cheers guy for helping me understand more of rockbox's code :)