Advice for searching a file for a particular string
Timothy D. Swieter
Posts: 1,613
I'm using Kye's SD2.0_FATEngine and his string object, STREngine. I'm setting up the core portion of the SPINNERET Module which will pull address settings (if not specified in firmware and not specified to be DHCP) from a config.txt file on an SD card. I imagine I will have other settings on the SD card as well.
What I am looking to do is to search through a ascii text file to find the settings. I want there to be comments in the file, so the system should ignore those lines. Here is a sample file, but the file could have much more elaborate comments:
What is the most efficient way to extract the data - the address settings?
I was thinking something along the lines of searching for the NewLine character, noting the position and then, copying a whole line from the file to a buffer and then using the functions in the STREngine to see if it is a comment or a variable. if a comment, discard and move on to the next line. If variable gather the data using ASCII to DEC or hex conversion appropriately.
Good idea?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, P.E.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" 16:9 LCD Composite video display, eProto for SunSPOT, PropNET, PolkaDOT-51
www.tdswieter.com
What I am looking to do is to search through a ascii text file to find the settings. I want there to be comments in the file, so the system should ignore those lines. Here is a sample file, but the file could have much more elaborate comments:
' this is a comment line ' another comment line MAC: 00:00:00:00:00:00 IP: 192.168.1.13 SUBNET: 255.255.255.0 GATWAY: 192.168.1.1
What is the most efficient way to extract the data - the address settings?
I was thinking something along the lines of searching for the NewLine character, noting the position and then, copying a whole line from the file to a buffer and then using the functions in the STREngine to see if it is a comment or a variable. if a comment, discard and move on to the next line. If variable gather the data using ASCII to DEC or hex conversion appropriately.
Good idea?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, P.E.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" 16:9 LCD Composite video display, eProto for SunSPOT, PropNET, PolkaDOT-51
www.tdswieter.com
Comments
Have you looked at my regular expression engine? It would make quick work of skipping the comments and ferreting out the variable/value pairs:
http://forums.parallax.com/showthread.php?p=855253
-Phil
Cheers,
--Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Pages: Propeller JVM
The test program works. Now, getting the file data to an array to work with, what is suggested? I mean, I don't want to have a huge buffer to pull the whole file into, so it should probably be worked on in chunks. Should the routine be something like:
-Check file size.
-calculate the number of chunks based on buffer size
-read a chunk, check it
-repeat
With this method though, you risk breaking a line into two. So perhaps the process of checking the beginning of each line for a comment character, then skip to the next line is best way to go. If a line doesn't start with a comment character, it can be processed with the regular expression.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, P.E.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" 16:9 LCD Composite video display, eProto for SunSPOT, PropNET, PolkaDOT-51
www.tdswieter.com
Post Edited (Timothy D. Swieter) : 7/3/2010 6:03:05 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, P.E.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" 16:9 LCD Composite video display, eProto for SunSPOT, PropNET, PolkaDOT-51
www.tdswieter.com
Quick analysis of kuroneko's point:
Most likely the variable strtokp contains 0 at startup.
Using strtokp instead of @strtokp would damage the clock frequency.
Cheers,
--Steve
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Propeller Pages: Propeller JVM
Post Edited (jazzed) : 7/3/2010 1:35:33 PM GMT
http://obex.parallax.com/objects/598/
Instead of having a list of regular expressions or a list of strings which name the configurations, you only need a list of hash-values. It already parses numbers and returns a string address for text-parameters.
It's based on FSRW, but it should be easy to change it to Kye's SD driver.