File: ParseCmdLine.c

package info (click to toggle)
gnu-efi 3.0v-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,076 kB
  • ctags: 5,590
  • sloc: ansic: 13,299; asm: 467; makefile: 241
file content (38 lines) | stat: -rw-r--r-- 759 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

/*
 *  Turn an CHAR16 * command line into a CHAR16 * argv, INT argc pair.
 *
 */


#include <efi.h>
#include <efilib.h>
#include <ParseCmdLine.h>



int ParseCmdLine(CHAR16 **argv[],  CHAR16 *LoadOptions, int LoadOptionSize)
{
    CHAR16 *buf = LoadOptions;
    int     len = LoadOptionSize;
    int	    i;	  // Index into buf

    int argc = 0;	// Count of argv entries
    argv[argc++] = LoadOptions ? LoadOptions: "##NoName##";

    for ( i = 0;  len > 0;   len-= 2, i++)  {
	if ( buf[i] == L' ' ) {
	    // end of current argv entry, start next?
	    buf[i] = NULL;
	    do {
	    	len -= 2;
		i++;
	    } while( (buf[i] == L' ') && (len > 0) );
	    argv[argc] =  &buf[i];
	    if ( len > 0 ) argc++;
	}
    }
    argv[argc] = NULL;

    return argc;
}