1 | |
---|
2 | /* |
---|
3 | * Copyright (C) 2001-2003 Hewlett-Packard Co. |
---|
4 | * Contributed by Stephane Eranian <eranian@hpl.hp.com> |
---|
5 | * |
---|
6 | * Copyright (C) 2001 Silicon Graphics, Inc. |
---|
7 | * Contributed by Brent Casavant <bcasavan@sgi.com> |
---|
8 | * |
---|
9 | * Copyright (C) 2006-2009 Intel Corporation |
---|
10 | * Contributed by Fenghua Yu <fenghua.yu@intel.com> |
---|
11 | * Contributed by Bibo Mao <bibo.mao@intel.com> |
---|
12 | * Contributed by Chandramouli Narayanan <mouli@linux.intel.com> |
---|
13 | * |
---|
14 | * This file is part of the ELILO, the EFI Linux boot loader. |
---|
15 | * |
---|
16 | * ELILO is free software; you can redistribute it and/or modify |
---|
17 | * it under the terms of the GNU General Public License as published by |
---|
18 | * the Free Software Foundation; either version 2, or (at your option) |
---|
19 | * any later version. |
---|
20 | * |
---|
21 | * ELILO is distributed in the hope that it will be useful, |
---|
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
24 | * GNU General Public License for more details. |
---|
25 | * |
---|
26 | * You should have received a copy of the GNU General Public License |
---|
27 | * along with ELILO; see the file COPYING. If not, write to the Free |
---|
28 | * Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
---|
29 | * 02111-1307, USA. |
---|
30 | * |
---|
31 | * Please check out the elilo.txt for complete documentation on how |
---|
32 | * to use this program. |
---|
33 | */ |
---|
34 | |
---|
35 | |
---|
36 | #include <efi.h> |
---|
37 | #include <efilib.h> |
---|
38 | #include <argify.h> |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | #define MAX_ARGS 256 |
---|
43 | |
---|
44 | #define CHAR_SPACE L' ' |
---|
45 | |
---|
46 | #define DEBUG 0 |
---|
47 | |
---|
48 | INTN |
---|
49 | argify(CHAR16 *buf, UINTN len, CHAR16 **argv) |
---|
50 | { |
---|
51 | |
---|
52 | UINTN i=0, j=0; |
---|
53 | CHAR16 *p = buf; |
---|
54 | |
---|
55 | if (buf == 0) { |
---|
56 | argv[0] = NULL; |
---|
57 | return 0; |
---|
58 | } |
---|
59 | /* len represents the number of bytes, not the number of 16 bytes chars */ |
---|
60 | len = len >> 1; |
---|
61 | |
---|
62 | /* |
---|
63 | * Here we use CHAR_NULL as the terminator rather than the length |
---|
64 | * because it seems like the EFI shell return rather bogus values for it. |
---|
65 | * Apparently, we are guaranteed to find the '\0' character in the buffer |
---|
66 | * where the real input arguments stop, so we use it instead. |
---|
67 | */ |
---|
68 | for(;;) { |
---|
69 | while (buf[i] == CHAR_SPACE && buf[i] != CHAR_NULL && i < len) i++; |
---|
70 | |
---|
71 | if (buf[i] == CHAR_NULL || i == len) goto end; |
---|
72 | |
---|
73 | p = buf+i; |
---|
74 | i++; |
---|
75 | |
---|
76 | while (buf[i] != CHAR_SPACE && buf[i] != CHAR_NULL && i < len) i++; |
---|
77 | |
---|
78 | argv[j++] = p; |
---|
79 | |
---|
80 | if (buf[i] == CHAR_NULL) goto end; |
---|
81 | |
---|
82 | buf[i] = CHAR_NULL; |
---|
83 | |
---|
84 | if (i == len) goto end; |
---|
85 | |
---|
86 | i++; |
---|
87 | |
---|
88 | if (j == MAX_ARGS-1) { |
---|
89 | Print(L"too many arguments (%d) truncating\n", j); |
---|
90 | goto end; |
---|
91 | } |
---|
92 | } |
---|
93 | end: |
---|
94 | argv[j] = NULL; |
---|
95 | return j; |
---|
96 | } |
---|
97 | |
---|