From 37f0eafa9346a1d43a03b93406fbadbe594ff71a Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 12 Jun 2015 19:23:18 -0400 Subject: [PATCH] support for link-time option in #version Changes to be committed: modified: src/version.c modified: sys/share/cppregex.cpp modified: sys/share/pmatchregex.c modified: sys/share/posixregex.c modified: util/makedefs.c Some options in 3.6.0 are determined by what you link with. The choice of regex support is one. Let #version show that linked option along with the compile-time options. --- src/version.c | 71 +++++++++++++++++++++++++++++++++++++++-- sys/share/cppregex.cpp | 2 ++ sys/share/pmatchregex.c | 4 ++- sys/share/posixregex.c | 4 ++- util/makedefs.c | 7 +--- 5 files changed, 77 insertions(+), 11 deletions(-) diff --git a/src/version.c b/src/version.c index 3e3eb1750..0d0cc7c6b 100644 --- a/src/version.c +++ b/src/version.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 version.c $NHDT-Date: 1434025553 2015/06/11 12:25:53 $ $NHDT-Branch: master $:$NHDT-Revision: 1.31 $ */ +/* NetHack 3.6 version.c $NHDT-Date: 1434151385 2015/06/12 23:23:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -17,6 +17,8 @@ #define BETA_INFO "Beta2" +STATIC_DCL void FDECL(insert_rtoptions, (winid,char *)); + /* fill buffer with short version (so caller can avoid including date.h) */ char * version_string(buf) @@ -55,8 +57,9 @@ int doextversion() { dlb *f; - char *cr, buf[BUFSZ]; + char *cr, *pd, buf[BUFSZ]; winid win = create_nhwindow(NHW_TEXT); + boolean rtadded = FALSE; /* instead of using ``display_file(OPTIONS_USED,TRUE)'' we handle the file manually so we can include dynamic version info */ @@ -108,7 +111,17 @@ doextversion() if (prolog || !*buf) continue; - putstr(win, 0, buf); + if (!rtadded) { + pd = eos(buf); + pd--; + if (*pd == '.' && strlen(buf) > 1) { + insert_rtoptions(win, buf); + rtadded = TRUE; /* only do it once */ + *buf = 0; + } + } + if (*buf) + putstr(win, 0, buf); } (void) dlb_fclose(f); display_nhwindow(win, FALSE); @@ -117,6 +130,58 @@ doextversion() return 0; } +extern char regex_id[]; + +static char *rt_opts[] = { + "pattern matching via", regex_id, +}; +static const char indent[] = " "; + +/* + * 3.6.0 + * Some optional stuff is no longer available to makedefs because + * it depends which of several object files got linked into the + * game image, so we insert those options here. + */ +STATIC_OVL void +insert_rtoptions(win, buf) +winid win; +char *buf; +{ + char rtbuf[BUFSZ]; + char *pd; + int l, i = 0, j = 0; + + if (strlen(buf) >= BUFSZ - 3) + return; + + strcpy(rtbuf, buf); + pd = eos(rtbuf); + pd--; + if (*pd == '.') + *pd = 0; + Strcat(rtbuf, ", "); + l = strlen(rtbuf); + + for (i = 0; i < SIZE(rt_opts); i++) { + if (l + strlen(rt_opts[i]) > COLNO - 5) { + putstr(win, 0, rtbuf); + if (strlen(rt_opts[i]) < BUFSZ - (1 + strlen(indent))) { + Strcpy(rtbuf, indent); + } + } + Strcat(rtbuf, rt_opts[i]); + l = strlen(rtbuf); + if (i % 2) + Strcat(rtbuf, (i < SIZE(rt_opts)- 1) ? "," : "."), l++; + else + Strcat(rtbuf, " "), l++; + } + + if (l) + putstr(win, 0, rtbuf); +} + #ifdef MICRO boolean comp_times(filetime) diff --git a/sys/share/cppregex.cpp b/sys/share/cppregex.cpp index 08f928513..b2f122735 100644 --- a/sys/share/cppregex.cpp +++ b/sys/share/cppregex.cpp @@ -10,6 +10,8 @@ extern "C" { #include + char regex_id[] = "cppregex"; + struct nhregex { std::unique_ptr re; std::unique_ptr err; diff --git a/sys/share/pmatchregex.c b/sys/share/pmatchregex.c index e7fd1a504..10ee64b23 100644 --- a/sys/share/pmatchregex.c +++ b/sys/share/pmatchregex.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 posixregex.c $NHDT-Date: 1432472490 2015/05/24 13:01:30 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */ +/* NetHack 3.6 posixregex.c $NHDT-Date: 1434151360 2015/06/12 23:22:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */ /* Copyright (c) Sean Hunt 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -16,6 +16,8 @@ * NOTE: This file is untested. */ +char regex_id[] = "pmatchregex"; + struct nhregex { const char *pat; }; diff --git a/sys/share/posixregex.c b/sys/share/posixregex.c index c4deab208..60293c76f 100644 --- a/sys/share/posixregex.c +++ b/sys/share/posixregex.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 posixregex.c $NHDT-Date: 1431192778 2015/05/09 17:32:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.2 $ */ +/* NetHack 3.6 posixregex.c $NHDT-Date: 1434151361 2015/06/12 23:22:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $ */ /* Copyright (c) Sean Hunt 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -44,6 +44,8 @@ * Deallocate a regex object. */ +char regex_id[] = "posixregex"; + struct nhregex { regex_t re; int err; diff --git a/util/makedefs.c b/util/makedefs.c index 5e62e58ee..354ecd2b5 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 makedefs.c $NHDT-Date: 1432535188 2015/05/25 06:26:28 $ $NHDT-Branch: master $:$NHDT-Revision: 1.102 $ */ +/* NetHack 3.6 makedefs.c $NHDT-Date: 1434151372 2015/06/12 23:22:52 $ $NHDT-Branch: master $:$NHDT-Revision: 1.103 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) M. Stephenson, 1990, 1991. */ /* Copyright (c) Dean Luick, 1990. */ @@ -1352,11 +1352,6 @@ static const char *build_opts[] = { #ifdef NEWS "news file", #endif -#ifdef MENU_COLOR_REGEX - "menu colors via regular expressions", -#else - "menu colors via pmatch", -#endif #ifdef OVERLAY #ifdef MOVERLAY "MOVE overlays",