2 * This file is part of the bayou project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #define TIMEOUT_MESSAGE "Press ESC for the menu (%2d)...\r"
23 #define TIMEOUT_KEY '\033'
25 void run_payload(struct payload *p)
29 /* For chooser entries, just run the payload. */
30 if (p->pentry.type == BPT_TYPE_CHOOSER) {
31 self_load_and_run(p, &ret);
35 /* For chained entries, run all the sub-chain items. */
36 for (i = 0; i < bayoucfg.n_entries; i++) {
37 struct payload *s = &(bayoucfg.entries[i]);
39 if (s->pentry.parent == p->pentry.index)
40 self_load_and_run(s, &ret);
44 char *payload_get_name(struct payload *p)
46 if (p->pentry.type == BPT_TYPE_CHAIN)
47 return (char *)p->pentry.title;
48 else if (p->pentry.type == BPT_TYPE_CHOOSER) {
49 if (p->pentry.title[0] != 0)
50 return (char *)p->pentry.title;
51 return p->params[BAYOU_PARAM_DESC];
57 struct payload *payload_get_default(void)
61 for (i = 0; i < bayoucfg.n_entries; i++) {
62 struct payload *s = &(bayoucfg.entries[i]);
64 if (s->pentry.parent == 0 && s->pentry.flags & BPT_FLAG_DEFAULT)
71 void run_payload_timeout(struct payload *p, int timeout)
75 for (t = timeout; t >= 0; t--) {
76 printf(TIMEOUT_MESSAGE, t);
79 ch = getchar_timeout(&tval);
81 if (ch == TIMEOUT_KEY)
88 void payload_parse_params(struct payload *pload, u8 *params, int len)
90 char *ptr = (char *)params;
96 while (ptr < ((char *)params + len)) {
98 if (!strncmp(ptr, "name=", 5)) {
99 pload->params[BAYOU_PARAM_NAME] = ptr + 5;
100 } else if (!strncmp(ptr, "desc=", 5)) {
101 pload->params[BAYOU_PARAM_DESC] = ptr + 5;
102 } else if (!strncmp(ptr, "listname=", 9)) {
103 pload->params[BAYOU_PARAM_LIST] = ptr + 9;
106 ptr += strnlen(ptr, len - i);
108 if (ptr < ((char *)params + len) && *ptr == 0)