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/ex_docmd.c b/src/ex_docmd.c
index 0a51d8e..f913fb5 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -204,7 +204,8 @@
 #else
 # define ex_tearoff		ex_ni
 #endif
-#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
+#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) \
+	|| defined(FEAT_TERM_POPUP_MENU)) && defined(FEAT_MENU)
 static void	ex_popup(exarg_T *eap);
 #else
 # define ex_popup		ex_ni
@@ -8741,11 +8742,21 @@
 }
 #endif
 
-#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)) && defined(FEAT_MENU)
+#if (defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK) \
+	|| defined(FEAT_TERM_POPUP_MENU)) && defined(FEAT_MENU)
     static void
 ex_popup(exarg_T *eap)
 {
-    gui_make_popup(eap->arg, eap->forceit);
+# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_GTK)
+    if (gui.in_use)
+	gui_make_popup(eap->arg, eap->forceit);
+#  ifdef FEAT_TERM_POPUP_MENU
+    else
+#  endif
+# endif
+# ifdef FEAT_TERM_POPUP_MENU
+	pum_make_popup(eap->arg, eap->forceit);
+# endif
 }
 #endif