patch 8.0.1570: can't use :popup for a menu in the terminal

Problem:    Can't use :popup for a menu in the terminal. (Wei Zhang)
Solution:   Make :popup work in the terminal.  Also fix that entries were
            included that don't work in the current state.
diff --git a/src/popupmnu.c b/src/popupmnu.c
index 6cfd95a..9b5f750 100644
--- a/src/popupmnu.c
+++ b/src/popupmnu.c
@@ -1132,12 +1132,16 @@
 #ifdef FEAT_BEVAL_TERM
     int		save_bevalterm = p_bevalterm;
 #endif
+    int		mode;
 
     pum_undisplay();
     pum_size = 0;
+    mode = get_menu_mode_flag();
 
     for (mp = menu->children; mp != NULL; mp = mp->next)
-	++pum_size;
+	if (menu_is_separator(mp->dname)
+		|| (mp->modes & mp->enabled & mode))
+	    ++pum_size;
 
     array = (pumitem_T *)alloc_clear((unsigned)sizeof(pumitem_T) * pum_size);
     if (array == NULL)
@@ -1146,7 +1150,7 @@
     for (mp = menu->children; mp != NULL; mp = mp->next)
 	if (menu_is_separator(mp->dname))
 	    array[idx++].pum_text = (char_u *)"";
-	else
+	else if (mp->modes & mp->enabled & mode)
 	    array[idx++].pum_text = mp->dname;
 
     pum_array = array;
@@ -1232,6 +1236,24 @@
     mch_setmouse(TRUE);
 #  endif
 }
+
+    void
+pum_make_popup(char_u *path_name, int use_mouse_pos)
+{
+    vimmenu_T *menu;
+
+    if (!use_mouse_pos)
+    {
+	/* Hack: set mouse position at the cursor so that the menu pops up
+	 * around there. */
+	mouse_row = curwin->w_winrow + curwin->w_wrow;
+	mouse_col = curwin->w_wincol + curwin->w_wcol;
+    }
+
+    menu = gui_find_menu(path_name);
+    if (menu != NULL)
+	pum_show_popupmenu(menu);
+}
 # endif
 
 #endif