| 155 | } |
| 156 | |
| 157 | struct property *menu_add_prompt(enum prop_type type, char *prompt, |
| 158 | struct expr *dep) |
| 159 | { |
| 160 | struct property *prop = menu_add_prop(type, NULL, dep); |
| 161 | |
| 162 | if (isspace(*prompt)) { |
| 163 | prop_warn(prop, "leading whitespace ignored"); |
| 164 | while (isspace(*prompt)) |
| 165 | prompt++; |
| 166 | } |
| 167 | if (current_entry->prompt) |
| 168 | prop_warn(prop, "prompt redefined"); |
| 169 | |
| 170 | /* Apply all upper menus' visibilities to actual prompts. */ |
| 171 | if (type == P_PROMPT) { |
| 172 | struct menu *menu = current_entry; |
| 173 | |
| 174 | while ((menu = menu->parent) != NULL) { |
| 175 | struct expr *dup_expr; |
| 176 | |
| 177 | if (!menu->visibility) |
| 178 | continue; |
| 179 | /* |
| 180 | * Do not add a reference to the menu's visibility |
| 181 | * expression but use a copy of it. Otherwise the |
| 182 | * expression reduction functions will modify |
| 183 | * expressions that have multiple references which |
| 184 | * can cause unwanted side effects. |
| 185 | */ |
| 186 | dup_expr = expr_copy(menu->visibility); |
| 187 | |
| 188 | prop->visible.expr = expr_alloc_and(prop->visible.expr, |
| 189 | dup_expr); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | current_entry->prompt = prop; |
| 194 | prop->text = prompt; |
| 195 | |
| 196 | return prop; |
| 197 | } |
| 198 | |
| 199 | void menu_add_visibility(struct expr *expr) |
| 200 | { |
no test coverage detected