Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search




Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Plugin code needed please (Read text file)
« previous next »
  • Print
Pages: [1]

Author Topic: Plugin code needed please (Read text file)  (Read 5172 times)

Offline Jazz00006

  • Member
  • *
  • Posts: 40
  • Master Jin
Plugin code needed please (Read text file)
« on: September 16, 2006, 03: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
Logged
Whats that got to do with the price of feet?

Offline Domonoky

  • Developer
  • Member
  • *
  • Posts: 205
Re: Plugin code needed please (Read text file)
« Reply #1 on: September 16, 2006, 08: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..
Logged

Offline Jazz00006

  • Member
  • *
  • Posts: 40
  • Master Jin
Re: Plugin code needed please (Read text file)
« Reply #2 on: September 16, 2006, 08: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)
Logged
Whats that got to do with the price of feet?

Offline Domonoky

  • Developer
  • Member
  • *
  • Posts: 205
Re: Plugin code needed please (Read text file)
« Reply #3 on: September 16, 2006, 08: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.

Logged

Offline Jazz00006

  • Member
  • *
  • Posts: 40
  • Master Jin
Re: Plugin code needed please (Read text file)
« Reply #4 on: September 16, 2006, 08:26:04 AM »
ah well, ill just have to make my own function then =)

btw what does 'structure had no member 'readline''
Logged
Whats that got to do with the price of feet?

Offline Domonoky

  • Developer
  • Member
  • *
  • Posts: 205
Re: Plugin code needed please (Read text file)
« Reply #5 on: September 16, 2006, 08: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.
Logged

Offline Rincewind

  • Member
  • *
  • Posts: 266
Re: Plugin code needed please (Read text file)
« Reply #6 on: September 16, 2006, 08: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
« Last Edit: September 16, 2006, 09:25:10 AM by Rincewind »
Logged
Iriver H120, Sansa e280

Offline Jazz00006

  • Member
  • *
  • Posts: 40
  • Master Jin
Re: Plugin code needed please (Read text file)
« Reply #7 on: September 16, 2006, 08:37:29 AM »
WOW, everyone here is so helpful :) cheers guy for helping me understand more of rockbox's code :)
Logged
Whats that got to do with the price of feet?

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  Plugin code needed please (Read text file)
 

  • SMF 2.0.6 | SMF © 2013, Simple Machines
  • XHTML
  • RSS
  • WAP2

Page created in 0.07 seconds with 53 queries.