menu_add_prompt() is the only function that calls menu_add_prop() with non-NULL prompt. So, the code inside the if-conditional block of menu_add_prop() can be moved to menu_add_prompt().
Unified · Split
| @@ -132,53 +132,51 @@ static struct property *menu_add_prop(enum prop_type type, char *prompt, struct · 131 unmodified lines | ||
| 132 | 132 | prop->expr = expr; |
| 133 | 133 | prop->visible.expr = dep; |
| 134 | 134 | |
| 135 | − if (prompt) { | |
| 136 | − if (isspace(*prompt)) { | |
| 137 | − prop_warn(prop, "leading whitespace ignored"); | |
| 138 | − while (isspace(*prompt)) | |
| 139 | − prompt++; | |
| 140 | − } | |
| 141 | − if (current_entry->prompt) | |
| 142 | − prop_warn(prop, "prompt redefined"); | |
| 135 | + return prop; | |
| 136 | +} | |
| 143 | 137 | |
| 144 | − /* Apply all upper menus' visibilities to actual prompts. */ | |
| 145 | − if(type == P_PROMPT) { | |
| 146 | − struct menu *menu = current_entry; | |
| 138 | +struct property *menu_add_prompt(enum prop_type type, char *prompt, | |
| 139 | + struct expr *dep) | |
| 140 | +{ | |
| 141 | + struct property *prop = menu_add_prop(type, prompt, NULL, dep); | |
| 147 | 142 | |
| 148 | − while ((menu = menu->parent) != NULL) { | |
| 149 | − struct expr *dup_expr; | |
| 143 | + if (isspace(*prompt)) { | |
| 144 | + prop_warn(prop, "leading whitespace ignored"); | |
| 145 | + while (isspace(*prompt)) | |
| 146 | + prompt++; | |
| 147 | + } | |
| 148 | + if (current_entry->prompt) | |
| 149 | + prop_warn(prop, "prompt redefined"); | |
| 150 | 150 | |
| 151 | − if (!menu->visibility) | |
| 152 | − continue; | |
| 153 | − /* | |
| 154 | − * Do not add a reference to the | |
| 155 | − * menu's visibility expression but | |
| 156 | − * use a copy of it. Otherwise the | |
| 157 | − * expression reduction functions | |
| 158 | − * will modify expressions that have | |
| 159 | − * multiple references which can | |
| 160 | − * cause unwanted side effects. | |
| 161 | − */ | |
| 162 | − dup_expr = expr_copy(menu->visibility); | |
| 151 | + /* Apply all upper menus' visibilities to actual prompts. */ | |
| 152 | + if (type == P_PROMPT) { | |
| 153 | + struct menu *menu = current_entry; | |
| 163 | 154 | |
| 164 | − prop->visible.expr | |
| 165 | − = expr_alloc_and(prop->visible.expr, | |
| 166 | − dup_expr); | |
| 167 | − } | |
| 168 | − } | |
| 155 | + while ((menu = menu->parent) != NULL) { | |
| 156 | + struct expr *dup_expr; | |
| 169 | 157 | |
| 170 | − current_entry->prompt = prop; | |
| 158 | + if (!menu->visibility) | |
| 159 | + continue; | |
| 160 | + /* | |
| 161 | + * Do not add a reference to the menu's visibility | |
| 162 | + * expression but use a copy of it. Otherwise the | |
| 163 | + * expression reduction functions will modify | |
| 164 | + * expressions that have multiple references which | |
| 165 | + * can cause unwanted side effects. | |
| 166 | + */ | |
| 167 | + dup_expr = expr_copy(menu->visibility); | |
| 168 | + | |
| 169 | + prop->visible.expr = expr_alloc_and(prop->visible.expr, | |
| 170 | + dup_expr); | |
| 171 | + } | |
| 171 | 172 | } |
| 173 | + | |
| 174 | + current_entry->prompt = prop; | |
| 172 | 175 | prop->text = prompt; |
| 173 | 176 | |
| 174 | 177 | return prop; |
| 175 | 178 | } |
| 176 | 179 | |
| 177 | −struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep) | |
| 178 | −{ | |
| 179 | − return menu_add_prop(type, prompt, NULL, dep); | |
| 180 | −} | |
| 181 | − | |
| 182 | 180 | void menu_add_visibility(struct expr *expr) |
| 183 | 181 | { |
| 184 | 182 | current_entry->visibility = expr_alloc_and(current_entry->visibility, |