diff --git a/config/ax_require_defined.m4 b/config/ax_require_defined.m4 new file mode 100644 index 000000000..17c3eab7d --- /dev/null +++ b/config/ax_require_defined.m4 @@ -0,0 +1,37 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_require_defined.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_REQUIRE_DEFINED(MACRO) +# +# DESCRIPTION +# +# AX_REQUIRE_DEFINED is a simple helper for making sure other macros have +# been defined and thus are available for use. This avoids random issues +# where a macro isn't expanded. Instead the configure script emits a +# non-fatal: +# +# ./configure: line 1673: AX_CFLAGS_WARN_ALL: command not found +# +# It's like AC_REQUIRE except it doesn't expand the required macro. +# +# Here's an example: +# +# AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG]) +# +# LICENSE +# +# Copyright (c) 2014 Mike Frysinger +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 2 + +AC_DEFUN([AX_REQUIRE_DEFINED], [dnl + m4_ifndef([$1], [m4_fatal([macro ]$1[ is not defined; is a m4 file missing?])]) +])dnl AX_REQUIRE_DEFINED diff --git a/config/ax_with_curses.m4 b/config/ax_with_curses.m4 new file mode 100644 index 000000000..dcdc1297f --- /dev/null +++ b/config/ax_with_curses.m4 @@ -0,0 +1,582 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_with_curses.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_WITH_CURSES +# +# DESCRIPTION +# +# This macro checks whether a SysV or X/Open-compatible Curses library is +# present, along with the associated header file. The NcursesW +# (wide-character) library is searched for first, followed by Ncurses, +# then the system-default plain Curses. The first library found is the +# one returned. Finding libraries will first be attempted by using +# pkg-config, and should the pkg-config files not be available, will +# fallback to combinations of known flags itself. +# +# The following options are understood: --with-ncursesw, --with-ncurses, +# --without-ncursesw, --without-ncurses. The "--with" options force the +# macro to use that particular library, terminating with an error if not +# found. The "--without" options simply skip the check for that library. +# The effect on the search pattern is: +# +# (no options) - NcursesW, Ncurses, Curses +# --with-ncurses --with-ncursesw - NcursesW only [*] +# --without-ncurses --with-ncursesw - NcursesW only [*] +# --with-ncursesw - NcursesW only [*] +# --with-ncurses --without-ncursesw - Ncurses only [*] +# --with-ncurses - NcursesW, Ncurses [**] +# --without-ncurses --without-ncursesw - Curses only +# --without-ncursesw - Ncurses, Curses +# --without-ncurses - NcursesW, Curses +# +# [*] If the library is not found, abort the configure script. +# +# [**] If the second library (Ncurses) is not found, abort configure. +# +# The following preprocessor symbols may be defined by this macro if the +# appropriate conditions are met: +# +# HAVE_CURSES - if any SysV or X/Open Curses library found +# HAVE_CURSES_ENHANCED - if library supports X/Open Enhanced functions +# HAVE_CURSES_COLOR - if library supports color (enhanced functions) +# HAVE_CURSES_OBSOLETE - if library supports certain obsolete features +# HAVE_NCURSESW - if NcursesW (wide char) library is to be used +# HAVE_NCURSES - if the Ncurses library is to be used +# +# HAVE_CURSES_H - if is present and should be used +# HAVE_NCURSESW_H - if should be used +# HAVE_NCURSES_H - if should be used +# HAVE_NCURSESW_CURSES_H - if should be used +# HAVE_NCURSES_CURSES_H - if should be used +# +# (These preprocessor symbols are discussed later in this document.) +# +# The following output variables are defined by this macro; they are +# precious and may be overridden on the ./configure command line: +# +# CURSES_LIBS - library to add to xxx_LDADD +# CURSES_CFLAGS - include paths to add to xxx_CPPFLAGS +# +# In previous versions of this macro, the flags CURSES_LIB and +# CURSES_CPPFLAGS were defined. These have been renamed, in keeping with +# AX_WITH_CURSES's close bigger brother, PKG_CHECK_MODULES, which should +# eventually supersede the use of AX_WITH_CURSES. Neither the library +# listed in CURSES_LIBS, nor the flags in CURSES_CFLAGS are added to LIBS, +# respectively CPPFLAGS, by default. You need to add both to the +# appropriate xxx_LDADD/xxx_CPPFLAGS line in your Makefile.am. For +# example: +# +# prog_LDADD = @CURSES_LIBS@ +# prog_CPPFLAGS = @CURSES_CFLAGS@ +# +# If CURSES_LIBS is set on the configure command line (such as by running +# "./configure CURSES_LIBS=-lmycurses"), then the only header searched for +# is . If the user needs to specify an alternative path for a +# library (such as for a non-standard NcurseW), the user should use the +# LDFLAGS variable. +# +# The following shell variables may be defined by this macro: +# +# ax_cv_curses - set to "yes" if any Curses library found +# ax_cv_curses_enhanced - set to "yes" if Enhanced functions present +# ax_cv_curses_color - set to "yes" if color functions present +# ax_cv_curses_obsolete - set to "yes" if obsolete features present +# +# ax_cv_ncursesw - set to "yes" if NcursesW library found +# ax_cv_ncurses - set to "yes" if Ncurses library found +# ax_cv_plaincurses - set to "yes" if plain Curses library found +# ax_cv_curses_which - set to "ncursesw", "ncurses", "plaincurses" or "no" +# +# These variables can be used in your configure.ac to determine the level +# of support you need from the Curses library. For example, if you must +# have either Ncurses or NcursesW, you could include: +# +# AX_WITH_CURSES +# if test "x$ax_cv_ncursesw" != xyes && test "x$ax_cv_ncurses" != xyes; then +# AC_MSG_ERROR([requires either NcursesW or Ncurses library]) +# fi +# +# If any Curses library will do (but one must be present and must support +# color), you could use: +# +# AX_WITH_CURSES +# if test "x$ax_cv_curses" != xyes || test "x$ax_cv_curses_color" != xyes; then +# AC_MSG_ERROR([requires an X/Open-compatible Curses library with color]) +# fi +# +# Certain preprocessor symbols and shell variables defined by this macro +# can be used to determine various features of the Curses library. In +# particular, HAVE_CURSES and ax_cv_curses are defined if the Curses +# library found conforms to the traditional SysV and/or X/Open Base Curses +# definition. Any working Curses library conforms to this level. +# +# HAVE_CURSES_ENHANCED and ax_cv_curses_enhanced are defined if the +# library supports the X/Open Enhanced Curses definition. In particular, +# the wide-character types attr_t, cchar_t and wint_t, the functions +# wattr_set() and wget_wch() and the macros WA_NORMAL and _XOPEN_CURSES +# are checked. The Ncurses library does NOT conform to this definition, +# although NcursesW does. +# +# HAVE_CURSES_COLOR and ax_cv_curses_color are defined if the library +# supports color functions and macros such as COLOR_PAIR, A_COLOR, +# COLOR_WHITE, COLOR_RED and init_pair(). These are NOT part of the +# X/Open Base Curses definition, but are part of the Enhanced set of +# functions. The Ncurses library DOES support these functions, as does +# NcursesW. +# +# HAVE_CURSES_OBSOLETE and ax_cv_curses_obsolete are defined if the +# library supports certain features present in SysV and BSD Curses but not +# defined in the X/Open definition. In particular, the functions +# getattrs(), getcurx() and getmaxx() are checked. +# +# To use the HAVE_xxx_H preprocessor symbols, insert the following into +# your system.h (or equivalent) header file: +# +# #if defined HAVE_NCURSESW_CURSES_H +# # include +# #elif defined HAVE_NCURSESW_H +# # include +# #elif defined HAVE_NCURSES_CURSES_H +# # include +# #elif defined HAVE_NCURSES_H +# # include +# #elif defined HAVE_CURSES_H +# # include +# #else +# # error "SysV or X/Open-compatible Curses header file required" +# #endif +# +# For previous users of this macro: you should not need to change anything +# in your configure.ac or Makefile.am, as the previous (serial 10) +# semantics are still valid. However, you should update your system.h (or +# equivalent) header file to the fragment shown above. You are encouraged +# also to make use of the extended functionality provided by this version +# of AX_WITH_CURSES, as well as in the additional macros +# AX_WITH_CURSES_PANEL, AX_WITH_CURSES_MENU and AX_WITH_CURSES_FORM. +# +# LICENSE +# +# Copyright (c) 2009 Mark Pulford +# Copyright (c) 2009 Damian Pietras +# Copyright (c) 2012 Reuben Thomas +# Copyright (c) 2011 John Zaitseff +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . +# +# As a special exception, the respective Autoconf Macro's copyright owner +# gives unlimited permission to copy, distribute and modify the configure +# scripts that are the output of Autoconf when processing the Macro. You +# need not follow the terms of the GNU General Public License when using +# or distributing such scripts, even though portions of the text of the +# Macro appear in them. The GNU General Public License (GPL) does govern +# all other use of the material that constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the Autoconf +# Macro released by the Autoconf Archive. When you make and distribute a +# modified version of the Autoconf Macro, you may extend this special +# exception to the GPL to apply to your modified version as well. + +#serial 18 + +# internal function to factorize common code that is used by both ncurses +# and ncursesw +AC_DEFUN([_FIND_CURSES_FLAGS], [ + AC_MSG_CHECKING([for $1 via pkg-config]) + + AX_REQUIRE_DEFINED([PKG_CHECK_EXISTS]) + _PKG_CONFIG([_ax_cv_$1_libs], [libs], [$1]) + _PKG_CONFIG([_ax_cv_$1_cppflags], [cflags], [$1]) + + AS_IF([test "x$pkg_failed" = "xyes" || test "x$pkg_failed" = "xuntried"],[ + AC_MSG_RESULT([no]) + # No suitable .pc file found, have to find flags via fallback + AC_CACHE_CHECK([for $1 via fallback], [ax_cv_$1], [ + AS_ECHO() + pkg_cv__ax_cv_$1_libs="-l$1" + pkg_cv__ax_cv_$1_cppflags="-D_GNU_SOURCE $CURSES_CFLAGS" + LIBS="$ax_saved_LIBS $pkg_cv__ax_cv_$1_libs" + CPPFLAGS="$ax_saved_CPPFLAGS $pkg_cv__ax_cv_$1_cppflags" + + AC_MSG_CHECKING([for initscr() with $pkg_cv__ax_cv_$1_libs]) + AC_LINK_IFELSE([AC_LANG_CALL([], [initscr])], + [ + AC_MSG_RESULT([yes]) + AC_MSG_CHECKING([for nodelay() with $pkg_cv__ax_cv_$1_libs]) + AC_LINK_IFELSE([AC_LANG_CALL([], [nodelay])],[ + ax_cv_$1=yes + ],[ + AC_MSG_RESULT([no]) + m4_if( + [$1],[ncursesw],[pkg_cv__ax_cv_$1_libs="$pkg_cv__ax_cv_$1_libs -ltinfow"], + [$1],[ncurses],[pkg_cv__ax_cv_$1_libs="$pkg_cv__ax_cv_$1_libs -ltinfo"] + ) + LIBS="$ax_saved_LIBS $pkg_cv__ax_cv_$1_libs" + + AC_MSG_CHECKING([for nodelay() with $pkg_cv__ax_cv_$1_libs]) + AC_LINK_IFELSE([AC_LANG_CALL([], [nodelay])],[ + ax_cv_$1=yes + ],[ + ax_cv_$1=no + ]) + ]) + ],[ + ax_cv_$1=no + ]) + ]) + ],[ + AC_MSG_RESULT([yes]) + # Found .pc file, using its information + LIBS="$ax_saved_LIBS $pkg_cv__ax_cv_$1_libs" + CPPFLAGS="$ax_saved_CPPFLAGS $pkg_cv__ax_cv_$1_cppflags" + ax_cv_$1=yes + ]) +]) + +AU_ALIAS([MP_WITH_CURSES], [AX_WITH_CURSES]) +AC_DEFUN([AX_WITH_CURSES], [ + AC_ARG_VAR([CURSES_LIBS], [linker library for Curses, e.g. -lcurses]) + AC_ARG_VAR([CURSES_CFLAGS], [preprocessor flags for Curses, e.g. -I/usr/include/ncursesw]) + AC_ARG_WITH([ncurses], [AS_HELP_STRING([--with-ncurses], + [force the use of Ncurses or NcursesW])], + [], [with_ncurses=check]) + AC_ARG_WITH([ncursesw], [AS_HELP_STRING([--without-ncursesw], + [do not use NcursesW (wide character support)])], + [], [with_ncursesw=check]) + + ax_saved_LIBS=$LIBS + ax_saved_CPPFLAGS=$CPPFLAGS + + AS_IF([test "x$with_ncurses" = xyes || test "x$with_ncursesw" = xyes], + [ax_with_plaincurses=no], [ax_with_plaincurses=check]) + + ax_cv_curses_which=no + + # Test for NcursesW + AS_IF([test "x$CURSES_LIBS" = x && test "x$with_ncursesw" != xno], [ + _FIND_CURSES_FLAGS([ncursesw]) + + AS_IF([test "x$ax_cv_ncursesw" = xno && test "x$with_ncursesw" = xyes], [ + AC_MSG_ERROR([--with-ncursesw specified but could not find NcursesW library]) + ]) + + AS_IF([test "x$ax_cv_ncursesw" = xyes], [ + ax_cv_curses=yes + ax_cv_curses_which=ncursesw + CURSES_LIBS="$pkg_cv__ax_cv_ncursesw_libs" + CURSES_CFLAGS="$pkg_cv__ax_cv_ncursesw_cppflags" + AC_DEFINE([HAVE_NCURSESW], [1], [Define to 1 if the NcursesW library is present]) + AC_DEFINE([HAVE_CURSES], [1], [Define to 1 if a SysV or X/Open compatible Curses library is present]) + + AC_CACHE_CHECK([for working ncursesw/curses.h], [ax_cv_header_ncursesw_curses_h], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@define _XOPEN_SOURCE_EXTENDED 1 + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + chtype c = COLOR_PAIR(1) & A_COLOR; + attr_t d = WA_NORMAL; + cchar_t e; + wint_t f; + int g = getattrs(stdscr); + int h = getcurx(stdscr) + getmaxx(stdscr); + initscr(); + init_pair(1, COLOR_WHITE, COLOR_RED); + wattr_set(stdscr, d, 0, NULL); + wget_wch(stdscr, &f); + ]])], + [ax_cv_header_ncursesw_curses_h=yes], + [ax_cv_header_ncursesw_curses_h=no]) + ]) + AS_IF([test "x$ax_cv_header_ncursesw_curses_h" = xyes], [ + ax_cv_curses_enhanced=yes + ax_cv_curses_color=yes + ax_cv_curses_obsolete=yes + AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions]) + AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)]) + AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features]) + AC_DEFINE([HAVE_NCURSESW_CURSES_H], [1], [Define to 1 if is present]) + ]) + + AC_CACHE_CHECK([for working ncursesw.h], [ax_cv_header_ncursesw_h], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@define _XOPEN_SOURCE_EXTENDED 1 + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + chtype c = COLOR_PAIR(1) & A_COLOR; + attr_t d = WA_NORMAL; + cchar_t e; + wint_t f; + int g = getattrs(stdscr); + int h = getcurx(stdscr) + getmaxx(stdscr); + initscr(); + init_pair(1, COLOR_WHITE, COLOR_RED); + wattr_set(stdscr, d, 0, NULL); + wget_wch(stdscr, &f); + ]])], + [ax_cv_header_ncursesw_h=yes], + [ax_cv_header_ncursesw_h=no]) + ]) + AS_IF([test "x$ax_cv_header_ncursesw_h" = xyes], [ + ax_cv_curses_enhanced=yes + ax_cv_curses_color=yes + ax_cv_curses_obsolete=yes + AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions]) + AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)]) + AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features]) + AC_DEFINE([HAVE_NCURSESW_H], [1], [Define to 1 if is present]) + ]) + + AC_CACHE_CHECK([for working ncurses.h], [ax_cv_header_ncurses_h_with_ncursesw], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@define _XOPEN_SOURCE_EXTENDED 1 + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + chtype c = COLOR_PAIR(1) & A_COLOR; + attr_t d = WA_NORMAL; + cchar_t e; + wint_t f; + int g = getattrs(stdscr); + int h = getcurx(stdscr) + getmaxx(stdscr); + initscr(); + init_pair(1, COLOR_WHITE, COLOR_RED); + wattr_set(stdscr, d, 0, NULL); + wget_wch(stdscr, &f); + ]])], + [ax_cv_header_ncurses_h_with_ncursesw=yes], + [ax_cv_header_ncurses_h_with_ncursesw=no]) + ]) + AS_IF([test "x$ax_cv_header_ncurses_h_with_ncursesw" = xyes], [ + ax_cv_curses_enhanced=yes + ax_cv_curses_color=yes + ax_cv_curses_obsolete=yes + AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions]) + AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)]) + AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features]) + AC_DEFINE([HAVE_NCURSES_H], [1], [Define to 1 if is present]) + ]) + + AS_IF([test "x$ax_cv_header_ncursesw_curses_h" = xno && test "x$ax_cv_header_ncursesw_h" = xno && test "x$ax_cv_header_ncurses_h_with_ncursesw" = xno], [ + AC_MSG_WARN([could not find a working ncursesw/curses.h, ncursesw.h or ncurses.h]) + ]) + ]) + ]) + unset pkg_cv__ax_cv_ncursesw_libs + unset pkg_cv__ax_cv_ncursesw_cppflags + + # Test for Ncurses + AS_IF([test "x$CURSES_LIBS" = x && test "x$with_ncurses" != xno && test "x$ax_cv_curses_which" = xno], [ + _FIND_CURSES_FLAGS([ncurses]) + + AS_IF([test "x$ax_cv_ncurses" = xno && test "x$with_ncurses" = xyes], [ + AC_MSG_ERROR([--with-ncurses specified but could not find Ncurses library]) + ]) + + AS_IF([test "x$ax_cv_ncurses" = xyes], [ + ax_cv_curses=yes + ax_cv_curses_which=ncurses + CURSES_LIBS="$pkg_cv__ax_cv_ncurses_libs" + CURSES_CFLAGS="$pkg_cv__ax_cv_ncurses_cppflags" + AC_DEFINE([HAVE_NCURSES], [1], [Define to 1 if the Ncurses library is present]) + AC_DEFINE([HAVE_CURSES], [1], [Define to 1 if a SysV or X/Open compatible Curses library is present]) + + AC_CACHE_CHECK([for working ncurses/curses.h], [ax_cv_header_ncurses_curses_h], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + chtype c = COLOR_PAIR(1) & A_COLOR; + int g = getattrs(stdscr); + int h = getcurx(stdscr) + getmaxx(stdscr); + initscr(); + init_pair(1, COLOR_WHITE, COLOR_RED); + ]])], + [ax_cv_header_ncurses_curses_h=yes], + [ax_cv_header_ncurses_curses_h=no]) + ]) + AS_IF([test "x$ax_cv_header_ncurses_curses_h" = xyes], [ + ax_cv_curses_color=yes + ax_cv_curses_obsolete=yes + AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)]) + AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features]) + AC_DEFINE([HAVE_NCURSES_CURSES_H], [1], [Define to 1 if is present]) + ]) + + AC_CACHE_CHECK([for working ncurses.h], [ax_cv_header_ncurses_h], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + chtype c = COLOR_PAIR(1) & A_COLOR; + int g = getattrs(stdscr); + int h = getcurx(stdscr) + getmaxx(stdscr); + initscr(); + init_pair(1, COLOR_WHITE, COLOR_RED); + ]])], + [ax_cv_header_ncurses_h=yes], + [ax_cv_header_ncurses_h=no]) + ]) + AS_IF([test "x$ax_cv_header_ncurses_h" = xyes], [ + ax_cv_curses_color=yes + ax_cv_curses_obsolete=yes + AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)]) + AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features]) + AC_DEFINE([HAVE_NCURSES_H], [1], [Define to 1 if is present]) + ]) + + AS_IF([test "x$ax_cv_header_ncurses_curses_h" = xno && test "x$ax_cv_header_ncurses_h" = xno], [ + AC_MSG_WARN([could not find a working ncurses/curses.h or ncurses.h]) + ]) + ]) + ]) + unset pkg_cv__ax_cv_ncurses_libs + unset pkg_cv__ax_cv_ncurses_cppflags + + # Test for plain Curses (or if CURSES_LIBS was set by user) + AS_IF([test "x$with_plaincurses" != xno && test "x$ax_cv_curses_which" = xno], [ + AS_IF([test "x$CURSES_LIBS" != x], [ + LIBS="$ax_saved_LIBS $CURSES_LIBS" + ], [ + LIBS="$ax_saved_LIBS -lcurses" + ]) + + AC_CACHE_CHECK([for Curses library], [ax_cv_plaincurses], [ + AC_LINK_IFELSE([AC_LANG_CALL([], [initscr])], + [ax_cv_plaincurses=yes], [ax_cv_plaincurses=no]) + ]) + + AS_IF([test "x$ax_cv_plaincurses" = xyes], [ + ax_cv_curses=yes + ax_cv_curses_which=plaincurses + AS_IF([test "x$CURSES_LIBS" = x], [ + CURSES_LIBS="-lcurses" + ]) + AC_DEFINE([HAVE_CURSES], [1], [Define to 1 if a SysV or X/Open compatible Curses library is present]) + + # Check for base conformance (and header file) + + AC_CACHE_CHECK([for working curses.h], [ax_cv_header_curses_h], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + initscr(); + ]])], + [ax_cv_header_curses_h=yes], + [ax_cv_header_curses_h=no]) + ]) + AS_IF([test "x$ax_cv_header_curses_h" = xyes], [ + AC_DEFINE([HAVE_CURSES_H], [1], [Define to 1 if is present]) + + # Check for X/Open Enhanced conformance + + AC_CACHE_CHECK([for X/Open Enhanced Curses conformance], [ax_cv_plaincurses_enhanced], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@define _XOPEN_SOURCE_EXTENDED 1 + @%:@include + @%:@ifndef _XOPEN_CURSES + @%:@error "this Curses library is not enhanced" + "this Curses library is not enhanced" + @%:@endif + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + chtype c = COLOR_PAIR(1) & A_COLOR; + attr_t d = WA_NORMAL; + cchar_t e; + wint_t f; + initscr(); + init_pair(1, COLOR_WHITE, COLOR_RED); + wattr_set(stdscr, d, 0, NULL); + wget_wch(stdscr, &f); + ]])], + [ax_cv_plaincurses_enhanced=yes], + [ax_cv_plaincurses_enhanced=no]) + ]) + AS_IF([test "x$ax_cv_plaincurses_enhanced" = xyes], [ + ax_cv_curses_enhanced=yes + ax_cv_curses_color=yes + AC_DEFINE([HAVE_CURSES_ENHANCED], [1], [Define to 1 if library supports X/Open Enhanced functions]) + AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)]) + ]) + + # Check for color functions + + AC_CACHE_CHECK([for Curses color functions], [ax_cv_plaincurses_color], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@define _XOPEN_SOURCE_EXTENDED 1 + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + chtype c = COLOR_PAIR(1) & A_COLOR; + initscr(); + init_pair(1, COLOR_WHITE, COLOR_RED); + ]])], + [ax_cv_plaincurses_color=yes], + [ax_cv_plaincurses_color=no]) + ]) + AS_IF([test "x$ax_cv_plaincurses_color" = xyes], [ + ax_cv_curses_color=yes + AC_DEFINE([HAVE_CURSES_COLOR], [1], [Define to 1 if library supports color (enhanced functions)]) + ]) + + # Check for obsolete functions + + AC_CACHE_CHECK([for obsolete Curses functions], [ax_cv_plaincurses_obsolete], [ + AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + chtype a = A_BOLD; + int b = KEY_LEFT; + int g = getattrs(stdscr); + int h = getcurx(stdscr) + getmaxx(stdscr); + initscr(); + ]])], + [ax_cv_plaincurses_obsolete=yes], + [ax_cv_plaincurses_obsolete=no]) + ]) + AS_IF([test "x$ax_cv_plaincurses_obsolete" = xyes], [ + ax_cv_curses_obsolete=yes + AC_DEFINE([HAVE_CURSES_OBSOLETE], [1], [Define to 1 if library supports certain obsolete features]) + ]) + ]) + + AS_IF([test "x$ax_cv_header_curses_h" = xno], [ + AC_MSG_WARN([could not find a working curses.h]) + ]) + ]) + ]) + + AS_IF([test "x$ax_cv_curses" != xyes], [ax_cv_curses=no]) + AS_IF([test "x$ax_cv_curses_enhanced" != xyes], [ax_cv_curses_enhanced=no]) + AS_IF([test "x$ax_cv_curses_color" != xyes], [ax_cv_curses_color=no]) + AS_IF([test "x$ax_cv_curses_obsolete" != xyes], [ax_cv_curses_obsolete=no]) + + LIBS=$ax_saved_LIBS + CPPFLAGS=$ax_saved_CPPFLAGS + + unset ax_saved_LIBS + unset ax_saved_CPPFLAGS +])dnl diff --git a/configure.ac b/configure.ac index 3e3036fe6..78d73be7b 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,12 @@ AC_CACHE_SAVE LT_INIT([shared disable-static dlopen]) +AX_WITH_CURSES +if test "x$ax_cv_ncursesw" != xyes && test "x$ax_cv_ncurses" != xyes; then + AC_MSG_ERROR([requires either NcursesW or Ncurses library]) +fi +LDFLAGS="$LDFLAGS -lncurses" + dnl Work out the C++ standard which we are going to use AX_CXX_COMPILE_STDCXX_17(noext) diff --git a/src/sst/core/sstinfo.cc b/src/sst/core/sstinfo.cc index 9e6e96d27..7c34bd91f 100644 --- a/src/sst/core/sstinfo.cc +++ b/src/sst/core/sstinfo.cc @@ -31,6 +31,8 @@ #include #include #include +#include + using namespace std; using namespace SST; @@ -42,6 +44,11 @@ static std::string g_searchPath; static std::vector g_libInfoArray; static SSTInfoConfig g_configuration(false); static std::map g_foundGenerators; +static WINDOW *info; +static WINDOW *console; +static std::vector g_infoText; +static unsigned int g_textPos; + void dprintf(FILE* fp, const char* fmt, ...) @@ -74,7 +81,7 @@ xmlComment(TiXmlNode* owner, const char* fmt...) TiXmlComment* comment = new TiXmlComment(buf); owner->LinkEndChild(comment); } - + class OverallOutputter { public: @@ -82,12 +89,30 @@ class OverallOutputter void outputXML(); } g_Outputter; +struct SearchableData { + const std::map componentTags = + {{"description", " Description"}, + {"version", " ELI Version"}, + {"compiledate", " Compiled on"}, + {"category", " Category"}}; + // Can add more in the future +} g_searchData; + // Forward Declarations -void initLTDL(const std::string& searchPath); -void shutdownLTDL(); -static void processSSTElementFiles(); -void outputSSTElementInfo(); -void generateXMLOutputFile(); +void initLTDL(const std::string& searchPath); +void shutdownLTDL(); +static void processSSTElementFiles(); +void outputSSTElementInfo(); +void generateXMLOutputFile(); +void runInteractive(); +void drawWindows(); +void getInput(); +std::string parseInput(std::string); +std::string listLibraryInfo(std::list); +std::string findLibraryInfo(std::list); +void setInfoText(std::string); +void printInfo(); + int main(int argc, char* argv[]) @@ -99,14 +124,344 @@ main(int argc, char* argv[]) return 1; } + // Process all specified libraries g_searchPath = g_configuration.getLibPath(); - - // Read in the Element files and process them processSSTElementFiles(); + // Run interactive mode + if ( g_configuration.interactiveEnabled() ) { runInteractive(); } + return 0; } +int +getCursorPos(WINDOW *console) +{ + int pos, h; + getyx(console, h, pos); + h += 1; //to please the compiler + return pos; +} + +void +runInteractive() +{ + initscr(); + cbreak(); + noecho(); + + // Initialize console screen + drawWindows(); + + // Set initial text to help text + setInfoText(parseInput("help")); + printInfo(); + + // Loop for input + getInput(); + endwin(); +} + +void +drawWindows() +{ + // Hard reset windows for redraws + werase(info); + werase(console); + delwin(info); + delwin(console); + + info = newwin(LINES-3, COLS, 0, 0); + console = newwin(3, COLS, LINES-3, 0); + + // Parameters + scrollok(info, true); + scrollok(console, false); + keypad(console, true); + + box(console, 0, 0); + mvwprintw(console, 0, 1, " Console "); + wmove(console, 1, 1); + wrefresh(info); + wrefresh(console); +} + +void +getInput() +{ + // Main loop for console input + std::string input = ""; + while(true) { + std::string output = ""; + int c = wgetch(console); + + // Parse entered text + if(c == '\n') { + if (input != "") { + output = parseInput(input); + setInfoText(output); + + drawWindows(); + printInfo(); + input = ""; + } + } + // Resizing the window + else if (c == KEY_RESIZE) { + drawWindows(); + printInfo(); + } + // Handle backspaces + else if (c == KEY_BACKSPACE) { + int pos = getCursorPos(console); + if (pos > 1) { + wprintw(console, "\b \b"); + input.pop_back(); + } + } + // Scrolling + else if (c == KEY_UP) { + if (g_textPos > 0) { + g_textPos -= 1; + printInfo(); + } + } + else if (c == KEY_DOWN) { + if ((int)g_textPos < (int)g_infoText.size() - (int)LINES) { + g_textPos += 1; + printInfo(); + } + } + // Regular characters + else if (c <= 255) { + input += c; + wprintw(console, "%c", c); + wrefresh(console); + } + + // Make sure the cursor resets to the correct place + wmove(console, 1, input.size()+1); + } +} + +std::string +parseInput(std::string input) +{ + // Split into set of strings + std::istringstream stream(input); + std::string word; + std::vector inputWords; + + while (stream >> word) { + inputWords.push_back(word); + } + + // Parse + std::string text = "\n"; + std::string command = inputWords[0]; + transform(command.begin(), command.end(), command.begin(), ::tolower); // Convert command to lowercase + + // Help messages + if (inputWords.size() == 1) { + if (command == "help") { + text += "=== SST-INFO ===\n" + "This program lists documented Components, SubComponents, Events, Modules, and Partitioners within an Element Library.\n\n" + "=== COMMANDS ===\n" + "- Help : Displays this help message\n" + "- List {element.subelement} : Displays element libraries and component information\n" + "- Find {field} {search string} : Displays all components with the given search string in its field\n" + "- Path {subelement} : ... (PLANNED)\n\n" + "To see more detailed instructions, type in a command without parameters."; + } + else if (command == "list") { + text += "=== LIST ===\n" + "Displays specified element libraries.\n\n" + "=== USAGE ===\n" + "- List all : Display all available element libraries and their components/subcomponents\n" + "- List [element[.component|subcomponent]] : Display the specified element/subelement(s)\n\n" + "'element' - Element Library\n" + "'type' - Type of Component/Subcomponent\n" + "'component|subcomponent' - Either a Component or SubComponent defined in the Element Library\n\n" + "=== EXAMPLES ===\n" + "list coreTestElement\n" + "list sst.linear\n" + "list ariel miranda\n" + "list ariel miranda.ReverseSingleStreamGenerator\n"; + } + else if (command == "find") { + text += "=== FIND ===\n" + "Search for text within component/subcomponent fields. " + "Displays all loaded components/subcomponents with the specified text.\n" + "Currently only supports searching within Description, ELI Version, Compile Date, and Category.\n\n" + "=== USAGE ===\n" + "- Find {field} [search term] \n\n" + "'field' - Component/subcomponent fields.\n" + "Valid keywords - [Description, Version, Compiledate, Category] (case-insensitive)\n" + "Search term can be multiple words, but is case-sensitive\n\n" + "=== EXAMPLES ===\n" + "find Description test\n" + "find compiledate Oct 17\n" + "find category UNCATEGORIZED\n"; + } + else { + text += "ERROR: Unknown command '" + command + "'\n\nUse the command 'Help' to see usage options."; + } + } + + // Parse commands + else { + //Get args + auto start = std::next(inputWords.begin(), 1); + auto end = inputWords.end(); + std::list args(start, end); + + if (command == "list") { + text += listLibraryInfo(args); + } + + else if (command == "find"){ + text += findLibraryInfo(args); + } + } + + return text; +} + +int +addLibFilter(std::string libFilter, std::string componentFilter = "") +{ + for (auto& library : g_libInfoArray) { + if (library.getLibraryName() == libFilter) { + library.setLibraryFilter(true); + + if (componentFilter != "") { + library.setComponentFilter(componentFilter); + } + return 0; + } + } + + //Error - library not found + return 1; +} + +std::string +listLibraryInfo(std::list args) +{ + std::stringstream outputStream; + + if (args == std::list{"all"}) { + outputStream << "\n-Displaying All Libraries-"; + for (auto& library : g_libInfoArray) { + library.resetFilters(true); + } + } + else { + for (auto& library : g_libInfoArray) { + library.resetFilters(false); + } + + outputStream << "\n-Displaying:"; + for (std::string arg : args) { + outputStream << " " + arg; + std::string library = ""; + std::string component = ""; + + // Parse library.component + size_t split = arg.find('.'); + if (split == std::string::npos) { + library = arg; + } + else { + library = arg.substr(0, split); + component = arg.substr(split+1); + } + + // Check for invalid input + if (addLibFilter(library, component)) { + return "ERR - Could not find Library/Component '" + library + "." + component + "'"; + } + } + outputStream << "-"; + } + + for (auto& library : g_libInfoArray) { + library.outputText(outputStream); + } + + return outputStream.str(); +} + +std::string +findLibraryInfo(std::list args) +{ + std::stringstream outputStream; + + // Error handling + if (args.size() < 2) { + return "Invalid input. Your command should be in the format of 'find {tag} {search term}'\n\n" + "For example, `Find Description Profiler`"; + } + + std::string inputTag = args.front(); + std::transform(inputTag.begin(), inputTag.end(), inputTag.begin(), ::tolower); // Convert tag to lowercase + + // Compare to tag list and convert to proper string + auto mapIter = g_searchData.componentTags.find(inputTag); + + if (mapIter != g_searchData.componentTags.end()) { + std::string tag = mapIter->second; + + args.pop_front(); + std::string searchTerm = ""; + for (std::string arg : args) { + if (arg == args.back()) { searchTerm += arg; } + else { searchTerm += arg + " "; } + } + + // Search through libraries + for (auto& library : g_libInfoArray) { + library.resetFilters(false); + library.filterSearch(outputStream, tag, searchTerm); + library.outputText(outputStream); + } + return outputStream.str(); + } + + return "Invalid component tag. Choose from [Description, Version, Compiledate, Category]"; +} + +void +setInfoText(std::string infoString) +{ + std::vector stringVec; + g_textPos = 0; + + // Splits the string into individual lines and stores them into the infoText vector + std::stringstream infoStream(infoString); + std::string line; + + while(std::getline(infoStream, line, '\n')){ + stringVec.push_back((line + "\n")); + } + g_infoText.clear(); //clears memory + g_infoText = stringVec; +} + +void +printInfo() +{ + unsigned int posMax = ((int)g_infoText.size() < LINES-3) ? g_textPos + g_infoText.size() : g_textPos + (LINES-3); + + for (unsigned int i = g_textPos; i < posMax; i++) { + const char *cstr = g_infoText[i].c_str(); + wprintw(info, cstr); + } + wrefresh(info); + wrefresh(console); //moves the cursor back into the console window + wmove(console, 1, 1); +} + static void addELI(ElemLoader& loader, const std::string& lib, bool optional) { @@ -152,25 +507,34 @@ processSSTElementFiles() addELI(loader, l, g_configuration.processAllElements()); } - // Do we output in Human Readable form - if ( g_configuration.getOptionBits() & CFG_OUTPUTHUMAN ) { outputSSTElementInfo(); } + // Store info strings for interactive mode + if ( g_configuration.interactiveEnabled() ) { + for ( size_t x = 0; x < g_libInfoArray.size(); x++ ) { + g_libInfoArray[x].setAllLibraryInfo(); + } + } + else { + // Do we output in Human Readable form + if ( g_configuration.getOptionBits() & CFG_OUTPUTHUMAN ) { outputSSTElementInfo(); } - // Do we output an XML File - if ( g_configuration.getOptionBits() & CFG_OUTPUTXML ) { generateXMLOutputFile(); } + // Do we output an XML File + if ( g_configuration.getOptionBits() & CFG_OUTPUTXML ) { generateXMLOutputFile(); } + } } void -generateXMLOutputFile() +outputSSTElementInfo() { - g_Outputter.outputXML(); + g_Outputter.outputHumanReadable(std::cout); } void -outputSSTElementInfo() +generateXMLOutputFile() { - g_Outputter.outputHumanReadable(std::cout); + g_Outputter.outputXML(); } + void OverallOutputter::outputHumanReadable(std::ostream& os) { @@ -265,6 +629,8 @@ SSTInfoConfig::SSTInfoConfig(bool suppress_print) : ConfigShared(suppress_print, DEF_FLAG("debug", 'd', "Enable debugging messages", std::bind(&SSTInfoConfig::setEnableDebug, this, _1)); DEF_FLAG( "nodisplay", 'n', "Do not display output [default: off]", std::bind(&SSTInfoConfig::setNoDisplay, this, _1)); + DEF_FLAG( + "interactive", 'i', "(EXPERIMENTAL) Enable interactive command line mode", std::bind(&SSTInfoConfig::setInteractive, this, _1)); DEF_SECTION_HEADING("XML Options"); DEF_FLAG("xml", 'x', "Generate XML data [default:off]", std::bind(&SSTInfoConfig::setXML, this, _1)); DEF_ARG( @@ -299,89 +665,17 @@ SSTInfoConfig::getUsagePrelude() void SSTInfoConfig::outputUsage() { - cout << "Usage: " << m_AppName << " [] " - << " [options]" << endl; + cout << "Usage: " << m_AppName << " [options]" << endl; cout << " -h, --help Print Help Message\n"; cout << " -v, --version Print SST Package Release Version\n"; cout << " -d, --debug Enabled debugging messages\n"; cout << " -n, --nodisplay Do not display output - default is off\n"; cout << " -x, --xml Generate XML data - default is off\n"; cout << " -o, --outputxml=FILE File path to XML file. Default is SSTInfo.xml\n"; - cout << " -l, --libs=LIBS {all, } - Element Library(s) to process\n"; cout << " -q, --quiet Quiet/print summary only\n"; cout << endl; } -#if 0 -void -SSTInfoConfig::outputVersion() -{ - cout << "SST Release Version " PACKAGE_VERSION << endl; -} - -int -SSTInfoConfig::parseCmdLine(int argc, char* argv[]) -{ - m_AppName = argv[0]; - - static const struct option longOpts[] = { { "help", no_argument, nullptr, 'h' }, - { "version", no_argument, nullptr, 'v' }, - { "debug", no_argument, nullptr, 'd' }, - { "nodisplay", no_argument, nullptr, 'n' }, - { "xml", no_argument, nullptr, 'x' }, - { "quiet", no_argument, nullptr, 'q' }, - { "outputxml", required_argument, nullptr, 'o' }, - { "libs", required_argument, nullptr, 'l' }, - { "elemenfilt", required_argument, nullptr, 0 }, - { nullptr, 0, nullptr, 0 } }; - while ( 1 ) { - int opt_idx = 0; - const int intC = getopt_long(argc, argv, "hvqdnxo:l:", longOpts, &opt_idx); - if ( intC == -1 ) break; - - const char c = static_cast(intC); - - switch ( c ) { - case 'h': - outputUsage(); - return 1; - case 'v': - outputVersion(); - return 1; - case 'q': - m_optionBits &= ~CFG_VERBOSE; - break; - case 'd': - m_debugEnabled = true; - break; - case 'n': - m_optionBits &= ~CFG_OUTPUTHUMAN; - break; - case 'x': - m_optionBits |= CFG_OUTPUTXML; - break; - case 'o': - m_XMLFilePath = optarg; - break; - case 'l': - { - addFilter(optarg); - break; - } - case 0: - if ( !strcmp(longOpts[opt_idx].name, "elemnfilt") ) { addFilter(optarg); } - break; - } - } - - while ( optind < argc ) { - addFilter(argv[optind++]); - } - - return 0; -} -#endif - void SSTInfoConfig::addFilter(const std::string& name_str) { @@ -417,6 +711,136 @@ shouldPrintElement(const std::string& libName, const std::string& elemName) return false; } +void +SSTLibraryInfo::setLibraryInfo(std::string baseName, std::string componentName, std::string info) { + ComponentInfo componentInfo; + std::map infoMap; + + // Split string into lines and map each key:value pair + std::stringstream infoStream(info); + std::string line; + while(std::getline(infoStream, line, '\n')){ + size_t split = line.find(':'); + + std::string tag; + std::string value; + + if (split == std::string::npos) { + tag = line; + value = ""; + } + else { + tag = line.substr(0, split); + value = line.substr(split+1); + } + + infoMap.insert(make_pair(tag, value)); + componentInfo.stringIndexer.push_back(tag); + } + + componentInfo.componentName = componentName; + componentInfo.infoMap = infoMap; + + // Add to component list + m_components[baseName].push_back(componentInfo); +} + +void +SSTLibraryInfo::outputText(std::stringstream& outputStream) +{ + if (this->m_libraryFilter) { + outputStream << "\n================================================================================\n"; + outputStream << "ELEMENT LIBRARY: " << this->m_name << endl; + + // Loop over component types + for (auto& pair : this->m_components) { + std::string componentType = pair.first; + outputStream << componentType << "s (" << pair.second.size() << " total)\n"; + + // Loop over each component + for (int idx = 0; idx < int(pair.second.size()); idx++) { + auto component = pair.second[idx]; + + // Apply filter + bool filtered = std::find(m_componentFilters.begin(), m_componentFilters.end(), component.componentName) != m_componentFilters.end(); + if ((m_componentFilters.size() == 0) || filtered) { + outputStream << " " << componentType << " " << idx << ": " << component.componentName << endl; + + // Iterate through infoMap using the string indexer + for (auto key : component.stringIndexer) { + std::string val = component.infoMap[key]; + + if (val == "") { outputStream << key << endl; } + else { outputStream << key << ": " << val << endl; } + } + outputStream << endl; + } + } + } + } +} + +void +SSTLibraryInfo::filterSearch(std::stringstream& outputStream, std::string tag, std::string searchTerm) +{ + int count = 0; + + for (auto& pair : m_components) { + for (auto& component : pair.second) { + std::string searchString = component.infoMap[tag]; + size_t found = searchString.find(searchTerm); + + // If term is found, set Library to show and add component to filters + if (found != std::string::npos) { + m_libraryFilter = true; + m_componentFilters.push_back(component.componentName); + count++; + } + } + } + + outputStream << "-Found " << count << " components in " + m_name + " with '" + searchTerm + "' in '" + tag.substr(6) + "'-\n"; +} + +template +void +SSTLibraryInfo::setAllLibraryInfo() +{ + // lib is an InfoLibrary + auto* lib = ELI::InfoDatabase::getLibrary(getLibraryName()); + if ( lib ) { + // Only print if there is something of that type in the library + if ( lib->numEntries() != 0 ) { + // Create map keys based on type name + std::string baseName = std::string(BaseType::ELI_baseName()); + + // lib->getMap returns a map. BaseInfo is + // actually a Base::BuilderInfo and the implementation is in + // eli/elementinfo as BuilderInfoImpl + for ( auto& map : lib->getMap() ) { + std::stringstream infoStream; + map.second->toString(infoStream); + + setLibraryInfo(baseName, map.first, infoStream.str()); + } + } + } + else { + //os << "No " << BaseType::ELI_baseName() << "s\n"; + } +} + +void +SSTLibraryInfo::setAllLibraryInfo() +{ + + setAllLibraryInfo(); + setAllLibraryInfo(); + setAllLibraryInfo(); + setAllLibraryInfo(); + setAllLibraryInfo(); +} + template void SSTLibraryInfo::outputHumanReadable(std::ostream& os, bool printAll) diff --git a/src/sst/core/sstinfo.h b/src/sst/core/sstinfo.h index a63bb18eb..8221f1c3d 100644 --- a/src/sst/core/sstinfo.h +++ b/src/sst/core/sstinfo.h @@ -15,6 +15,7 @@ #include "sst/core/configShared.h" #include "sst/core/eli/elementinfo.h" +#include #include #include #include @@ -53,6 +54,9 @@ class SSTInfoConfig : public ConfigShared return res; } + /** Clears the current filter map */ + void clearFilterMap() { m_filters.clear(); } + /** Return the filter map */ FilterMap_t& getFilterMap() { return m_filters; } @@ -66,13 +70,14 @@ class SSTInfoConfig : public ConfigShared bool debugEnabled() const { return m_debugEnabled; } bool processAllElements() const { return m_filters.empty(); } bool doVerbose() const { return m_optionBits & CFG_VERBOSE; } + bool interactiveEnabled() const{ return m_interactive; } + void addFilter(const std::string& name); protected: std::string getUsagePrelude() override; private: void outputUsage(); - void addFilter(const std::string& name); int setPositionalArg(int UNUSED(num), const std::string& arg) { @@ -105,6 +110,12 @@ class SSTInfoConfig : public ConfigShared return 0; } + int setInteractive(const std::string& UNUSED(arg)) + { + m_interactive = true; + return 0; + } + int setXML(const std::string& UNUSED(arg)) { m_optionBits |= CFG_OUTPUTXML; @@ -135,6 +146,7 @@ class SSTInfoConfig : public ConfigShared unsigned int m_optionBits; std::string m_XMLFilePath; bool m_debugEnabled; + bool m_interactive; FilterMap_t m_filters; }; @@ -157,17 +169,37 @@ class SSTLibraryInfo // std::string getLibraryName() {if (m_eli && m_eli->name) return m_eli->name; else return ""; } std::string getLibraryName() { return m_name; } + /** Store all Library Information. */ + void setAllLibraryInfo(); + /** Output the Library Information. * @param LibIndex The Index of the Library. */ void outputHumanReadable(std::ostream& os, int LibIndex); /** Create the formatted XML data of the Library. - * @param LibIndex The Index of the Library. + * @param Index The Index of the Library. * @param XMLParentElement The parent element to receive the XML data. */ void outputXML(int Index, TiXmlNode* XMLParentElement); + /** Put text into info map*/ + void setLibraryInfo(std::string baseName, std::string componentName, std::string info); + + /** Return text from info map based on filters */ + void outputText(std::stringstream& os); + + /** Set filters based on search term */ + void filterSearch(std::stringstream& outputStream, std::string tag, std::string searchTerm); + + /** Filter output from info map*/ + bool getFilter() { return m_libraryFilter; } + void resetFilters(bool libFilter) { m_libraryFilter = libFilter, m_componentFilters.clear(); } + void setLibraryFilter(bool filter) { m_libraryFilter = filter; } + void setComponentFilter(std::string component) { m_componentFilters.push_back(component); } + + template + void setAllLibraryInfo(); template void outputHumanReadable(std::ostream& os, bool printAll); template @@ -176,9 +208,22 @@ class SSTLibraryInfo std::string getLibraryDescription() { return ""; } private: + // Contains info strings for each individual component, subcomponent, etc. + struct ComponentInfo + { + std::string componentName; + std::vector stringIndexer; // Used to maintain order of strings in infoMap + std::map infoMap; + }; + + // Stores all component info, keyed by their "BaseTypes" (component, subcomponent, module, etc.) + std::map> m_components; + bool m_libraryFilter = false; + std::vector m_componentFilters; + std::string m_name; }; - + } // namespace SST #endif // SST_CORE_SST_INFO_H