blob: a76e49ff6c12af57df2a11ab1f74c2552afc1252 [file] [log] [blame]
Uwe Hermann7eb845e2008-11-02 17:01:06 +00001/*
2 * This file is part of the bayou project.
3 *
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 *
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.
9 *
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.
Uwe Hermann7eb845e2008-11-02 17:01:06 +000014 */
15
16#include "bayou.h"
17
18#define TIMEOUT_MESSAGE "Press ESC for the menu (%2d)...\r"
19#define TIMEOUT_KEY '\033'
20
21void run_payload(struct payload *p)
22{
23 int ret, i;
24
25 /* For chooser entries, just run the payload. */
26 if (p->pentry.type == BPT_TYPE_CHOOSER) {
27 self_load_and_run(p, &ret);
28 return;
29 }
30
31 /* For chained entries, run all the sub-chain items. */
32 for (i = 0; i < bayoucfg.n_entries; i++) {
33 struct payload *s = &(bayoucfg.entries[i]);
34
35 if (s->pentry.parent == p->pentry.index)
36 self_load_and_run(s, &ret);
37 }
38}
39
40char *payload_get_name(struct payload *p)
41{
42 if (p->pentry.type == BPT_TYPE_CHAIN)
43 return (char *)p->pentry.title;
44 else if (p->pentry.type == BPT_TYPE_CHOOSER) {
45 if (p->pentry.title[0] != 0)
46 return (char *)p->pentry.title;
47 return p->params[BAYOU_PARAM_DESC];
48 }
49
50 return NULL;
51}
52
53struct payload *payload_get_default(void)
54{
55 int i;
56
57 for (i = 0; i < bayoucfg.n_entries; i++) {
58 struct payload *s = &(bayoucfg.entries[i]);
59
60 if (s->pentry.parent == 0 && s->pentry.flags & BPT_FLAG_DEFAULT)
61 return s;
62 }
63
64 return NULL;
65}
66
67void run_payload_timeout(struct payload *p, int timeout)
68{
69 int t, ch, tval;
70
71 for (t = timeout; t >= 0; t--) {
72 printf(TIMEOUT_MESSAGE, t);
73
74 tval = 1000;
75 ch = getchar_timeout(&tval);
76
77 if (ch == TIMEOUT_KEY)
78 return;
79 }
80
81 run_payload(p);
82}
83
84void payload_parse_params(struct payload *pload, u8 *params, int len)
85{
86 char *ptr = (char *)params;
87 int i = 0;
88
89 if (ptr == NULL)
90 return;
91
92 while (ptr < ((char *)params + len)) {
93
94 if (!strncmp(ptr, "name=", 5)) {
95 pload->params[BAYOU_PARAM_NAME] = ptr + 5;
96 } else if (!strncmp(ptr, "desc=", 5)) {
97 pload->params[BAYOU_PARAM_DESC] = ptr + 5;
98 } else if (!strncmp(ptr, "listname=", 9)) {
99 pload->params[BAYOU_PARAM_LIST] = ptr + 9;
100 }
101
102 ptr += strnlen(ptr, len - i);
103
104 if (ptr < ((char *)params + len) && *ptr == 0)
105 ptr++;
106 }
107}