/*Copyright (C) 2006 Matteo Lucarelli

*This program is free software; you can redistribute it and/or
*modify it under the terms of the GNU General Public License
*as published by the Free Software Foundation; either version 2
*of the License, or (at your option) any later version.
*
*This program is distributed in the hope that it will be useful,
*but WITHOUT ANY WARRANTY; without even the implied warranty of
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License
*along with this program; if not, write to the Free Software
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
******************************************************************************/

// parse a sentence in single words
// using space, tab and newline
// return the words count
// the array terminates with a NULL element 
//
// having the complete command string in char* cmd
// for exec syscall use:
//
//	char* cmd_ary[256];
//	parseline(cmd,cmd_ary,256); 
//	execv(*cmd_ary, cmd_ary);
//

int  parseline(char *line, char **argv, int maxarg)
{
	int argc=0;
	while (*line!=0 && argc<maxarg) {      
		while (*line==' ' || *line=='\t' || *line =='\n') *line++=0;     
		*argv++ = line;
		argc++;
		while (*line!=0 && *line!=' ' && *line!='\t' && *line!='\n') line++;             
	}
	*argv = 0;
	return argc;
}