Parsing Bootload Command Lines

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
TomMan
Posts: 4
Joined: Mon May 03, 2010 5:58 am

Parsing Bootload Command Lines

Post by TomMan »

Hi,

I am currently writing a simple kernel, but I need a way of parsing the boot loader commands that I set with GRUB. I have got to the stage of having a char* with all the commands on one line: but I need to split them up into the individual commands. I tried writing my own strtok function but couldn't get very far, so if someone could help I would be very grateful.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Parsing Bootload Command Lines

Post by gerryg400 »

If you want to spend more time having fun writing your OS and less time writing code that already exists, my advice is to get an open source c library and use it as much as possible.

Newlib is good, I use it in my kernel. The wiki has instructions on building it. You could also try PDCLIB which is smaller and perhaps more easily understood.

Of course some people enjoy writing their own c lib. It depends on your goal.

- gerryg400
If a trainstation is where trains stop, what is a workstation ?
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Parsing Bootload Command Lines

Post by qw »

This is how ReactOS does it: __getmainargs().
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Parsing Bootload Command Lines

Post by NickJohnson »

If you don't care about modifying that command line string, you can parse it pretty easily with a single for loop. The idea is to have an array of char* that end up pointing to each token in the string, and to change all whitespace characters to null characters to null terminate the tokens. Start with the first token as the entire string; just go along the string, and when you encounter whitespace, replace it with a null, and add a pointer to the next character to the token array. You will end up with an argv[]-style token list. strtok is a better way to do this, but if you can't implement it, this algorithm will work in a pinch.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Parsing Bootload Command Lines

Post by Gigasoft »

Seriously, if you're up to writing an OS, shouldn't you at least know how to split up a string first?
Post Reply