Source:NetHack 3.6.1/src/version.c

From NetHackWiki
(Redirected from Source:Ref/uptodate)
Jump to: navigation, search

Below is the full text to version.c from the source code of NetHack 3.6.1. To link to a particular line, write [[Source:NetHack 3.6.1/src/version.c#line123]], for example.

Top of file

  1.  /* NetHack 3.6	version.c	$NHDT-Date: 1524693365 2018/04/25 21:56:05 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.49 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /*-Copyright (c) Michael Allison, 2018. */
  4.  /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1.  
  2.  #include "hack.h"
  3.  #include "dlb.h"
  4.  #include "date.h"
  5.  /*
  6.   * All the references to the contents of patchlevel.h have been moved
  7.   * into makedefs....
  8.   */
  9.  #ifdef SHORT_FILENAMES
  10.  #include "patchlev.h"
  11.  #else
  12.  #include "patchlevel.h"
  13.  #endif
  14.  
  15.  #if defined(NETHACK_GIT_SHA)
  16.  const char * NetHack_git_sha = NETHACK_GIT_SHA;
  17.  #endif
  18.  #if defined(NETHACK_GIT_BRANCH)
  19.  const char * NetHack_git_branch = NETHACK_GIT_BRANCH;
  20.  #endif
  21.  
  22.  STATIC_DCL void FDECL(insert_rtoption, (char *));
  23.  

version_string

  1.  /* fill buffer with short version (so caller can avoid including date.h) */
  2.  char *
  3.  version_string(buf)
  4.  char *buf;
  5.  {
  6.      return strcpy(buf, VERSION_STRING);
  7.  }
  8.  

getversionstring

  1.  /* fill and return the given buffer with the long nethack version string */
  2.  char *
  3.  getversionstring(buf)
  4.  char *buf;
  5.  {
  6.      boolean details = FALSE;
  7.  
  8.      Strcpy(buf, VERSION_ID);
  9.  #if defined(RUNTIME_PORT_ID) || \
  10.      defined(NETHACK_GIT_SHA) || defined(NETHACK_GIT_BRANCH)
  11.      details = TRUE;
  12.  #endif
  13.  
  14.      if (details) {
  15.  #if defined(RUNTIME_PORT_ID) || defined(NETHACK_GIT_SHA) || defined(NETHACK_GIT_BRANCH)
  16.          int c = 0;
  17.  #endif
  18.  #if defined(RUNTIME_PORT_ID)
  19.          char tmpbuf[BUFSZ];
  20.          char *tmp = (char *)0;
  21.  #endif
  22.  
  23.          Sprintf(eos(buf), " (");
  24.  #if defined(RUNTIME_PORT_ID)
  25.          tmp = get_port_id(tmpbuf);        
  26.          if (tmp)
  27.              Sprintf(eos(buf), "%s%s", c++ ? "," : "", tmp);
  28.  #endif
  29.  #if defined(NETHACK_GIT_SHA)
  30.          if (NetHack_git_sha)
  31.              Sprintf(eos(buf), "%s%s", c++ ? "," : "", NetHack_git_sha);
  32.  #endif
  33.  #if defined(NETHACK_GIT_BRANCH)
  34.  #if defined(BETA)
  35.          if (NetHack_git_branch)
  36.              Sprintf(eos(buf), "%sbranch:%s", c++ ? "," : "", NetHack_git_branch);
  37.  #endif
  38.  #endif
  39.          Sprintf(eos(buf), ")");
  40.      }
  41.      return buf;
  42.  }
  43.  

doversion

  1.  /* the 'v' command */
  2.  int
  3.  doversion()
  4.  {
  5.      char buf[BUFSZ];
  6.  
  7.      pline("%s", getversionstring(buf));
  8.      return 0;
  9.  }
  10.  

doextversion

  1.  /* the '#version' command; also a choice for '?' */
  2.  int
  3.  doextversion()
  4.  {
  5.      dlb *f;
  6.      char buf[BUFSZ];
  7.      winid win = create_nhwindow(NHW_TEXT);
  8.  
  9.      /* instead of using ``display_file(OPTIONS_USED,TRUE)'' we handle
  10.         the file manually so we can include dynamic version info */
  11.      putstr(win, 0, getversionstring(buf));
  12.  
  13.      f = dlb_fopen(OPTIONS_USED, "r");
  14.      if (!f) {
  15.          putstr(win, 0, "");
  16.          Sprintf(buf, "[Configuration '%s' not available?]", OPTIONS_USED);
  17.          putstr(win, 0, buf);
  18.      } else {
  19.          /*
  20.           * already inserted above:
  21.           * + outdented program name and version plus build date and time
  22.           * dat/options; display contents with lines prefixed by '-' deleted:
  23.           * - blank-line
  24.           * -     indented program name and version
  25.           *   blank-line
  26.           *   outdented feature header
  27.           * - blank-line
  28.           *       indented feature list
  29.           *       spread over multiple lines
  30.           *   blank-line
  31.           *   outdented windowing header
  32.           * - blank-line
  33.           *       indented windowing choices with
  34.           *       optional second line for default
  35.           * - blank-line
  36.           * - EOF
  37.           */
  38.          boolean prolog = TRUE; /* to skip indented program name */
  39.  
  40.          while (dlb_fgets(buf, BUFSZ, f)) {
  41.              (void) strip_newline(buf);
  42.              if (index(buf, '\t') != 0)
  43.                  (void) tabexpand(buf);
  44.  
  45.              if (*buf && *buf != ' ') {
  46.                  /* found outdented header; insert a separator since we'll
  47.                     have skipped corresponding blank line inside the file */
  48.                  putstr(win, 0, "");
  49.                  prolog = FALSE;
  50.              }
  51.              /* skip blank lines and prolog (progame name plus version) */
  52.              if (prolog || !*buf)
  53.                  continue;
  54.  
  55.              if (index(buf, ':'))
  56.                  insert_rtoption(buf);
  57.  
  58.              if (*buf)
  59.                  putstr(win, 0, buf);
  60.          }
  61.          (void) dlb_fclose(f);
  62.          display_nhwindow(win, FALSE);
  63.          destroy_nhwindow(win);
  64.      }
  65.      return 0;
  66.  }
  67.  

early_version_info

  1.  void early_version_info(pastebuf)
  2.  boolean pastebuf;
  3.  {
  4.      char buf[BUFSZ], buf2[BUFSZ];
  5.      char *tmp = getversionstring(buf);
  6.  
  7.      /* this is early enough that we have to do
  8.         our own line-splitting */
  9.      if (tmp) {
  10.          tmp = strstri(buf," (");
  11.          if (tmp) *tmp++ = '\0';
  12.      }
  13.  
  14.      Sprintf(buf2, "%s\n", buf);
  15.      if (tmp) Sprintf(eos(buf2), "%s\n", tmp);
  16.      raw_printf("%s", buf2);
  17.  
  18.      if (pastebuf) {
  19.  #ifdef RUNTIME_PASTEBUF_SUPPORT
  20.          /*
  21.           * Call a platform/port-specific routine to insert the
  22.           * version information into a paste buffer. Useful for
  23.           * easy inclusion in bug reports.
  24.           */
  25.          port_insert_pastebuf(buf2);
  26.  #else
  27.          raw_printf("%s", "Paste buffer copy is not available.\n");
  28.  #endif
  29.      }
  30.  }
  31.  
  32.  extern const char regex_id[];
  33.  
  34.  /*
  35.   * makedefs should put the first token into dat/options; we'll substitute
  36.   * the second value for it.  The token must contain at least one colon
  37.   * so that we can spot it, and should not contain spaces so that makedefs
  38.   * won't split it across lines.  Ideally the length should be close to
  39.   * that of the substituted value since we don't do phrase-splitting/line-
  40.   * wrapping when displaying it.
  41.   */
  42.  static struct rt_opt {
  43.      const char *token, *value;
  44.  } rt_opts[] = {
  45.      { ":PATMATCH:", regex_id },
  46.  };
  47.  

insert_rtoption

  1.  /*
  2.   * 3.6.0
  3.   * Some optional stuff is no longer available to makedefs because
  4.   * it depends which of several object files got linked into the
  5.   * game image, so we insert those options here.
  6.   */
  7.  STATIC_OVL void
  8.  insert_rtoption(buf)
  9.  char *buf;
  10.  {
  11.      int i;
  12.  
  13.      for (i = 0; i < SIZE(rt_opts); ++i) {
  14.          if (strstri(buf, rt_opts[i].token))
  15.              (void) strsubst(buf, rt_opts[i].token, rt_opts[i].value);
  16.          /* we don't break out of the loop after a match; there might be
  17.             other matches on the same line */
  18.      }
  19.  }
  20.  

comp_times

  1.  #ifdef MICRO
  2.  boolean
  3.  comp_times(filetime)
  4.  long filetime;
  5.  {
  6.      /* BUILD_TIME is constant but might have L suffix rather than UL;
  7.         'filetime' is historically signed but ought to have been unsigned */
  8.      return (boolean) ((unsigned long) filetime < (unsigned long) BUILD_TIME);
  9.  }
  10.  #endif
  11.  

check_version

  1.  boolean
  2.  check_version(version_data, filename, complain)
  3.  struct version_info *version_data;
  4.  const char *filename;
  5.  boolean complain;
  6.  {
  7.      if (
  8.  #ifdef VERSION_COMPATIBILITY
  9.          version_data->incarnation < VERSION_COMPATIBILITY
  10.          || version_data->incarnation > VERSION_NUMBER
  11.  #else
  12.          version_data->incarnation != VERSION_NUMBER
  13.  #endif
  14.          ) {
  15.          if (complain)
  16.              pline("Version mismatch for file \"%s\".", filename);
  17.          return FALSE;
  18.      } else if (
  19.  #ifndef IGNORED_FEATURES
  20.          version_data->feature_set != VERSION_FEATURES
  21.  #else
  22.          (version_data->feature_set & ~IGNORED_FEATURES)
  23.              != (VERSION_FEATURES & ~IGNORED_FEATURES)
  24.  #endif
  25.          || version_data->entity_count != VERSION_SANITY1
  26.          || version_data->struct_sizes1 != VERSION_SANITY2
  27.          || version_data->struct_sizes2 != VERSION_SANITY3) {
  28.          if (complain)
  29.              pline("Configuration incompatibility for file \"%s\".", filename);
  30.          return FALSE;
  31.      }
  32.      return TRUE;
  33.  }
  34.  

uptodate

  1.  /* this used to be based on file date and somewhat OS-dependant,
  2.     but now examines the initial part of the file's contents */
  3.  boolean
  4.  uptodate(fd, name)
  5.  int fd;
  6.  const char *name;
  7.  {
  8.      int rlen;
  9.      struct version_info vers_info;
  10.      boolean verbose = name ? TRUE : FALSE;
  11.  
  12.      rlen = read(fd, (genericptr_t) &vers_info, sizeof vers_info);
  13.      minit(); /* ZEROCOMP */
  14.      if (rlen == 0) {
  15.          if (verbose) {
  16.              pline("File \"%s\" is empty?", name);
  17.              wait_synch();
  18.          }
  19.          return FALSE;
  20.      }
  21.      if (!check_version(&vers_info, name, verbose)) {
  22.          if (verbose)
  23.              wait_synch();
  24.          return FALSE;
  25.      }
  26.      return TRUE;
  27.  }
  28.  

store_version

  1.  void
  2.  store_version(fd)
  3.  int fd;
  4.  {
  5.      static const struct version_info version_data = {
  6.          VERSION_NUMBER, VERSION_FEATURES,
  7.          VERSION_SANITY1, VERSION_SANITY2, VERSION_SANITY3
  8.      };
  9.  
  10.      bufoff(fd);
  11.      /* bwrite() before bufon() uses plain write() */
  12.      bwrite(fd, (genericptr_t) &version_data,
  13.             (unsigned) (sizeof version_data));
  14.      bufon(fd);
  15.      return;
  16.  }
  17.  
  18.  #ifdef AMIGA
  19.  const char amiga_version_string[] = AMIGA_VERSION_STRING;
  20.  #endif
  21.  

get_feature_notice_ver

  1.  unsigned long
  2.  get_feature_notice_ver(str)
  3.  char *str;
  4.  {
  5.      char buf[BUFSZ];
  6.      int ver_maj, ver_min, patch;
  7.      char *istr[3];
  8.      int j = 0;
  9.  
  10.      if (!str)
  11.          return 0L;
  12.      str = strcpy(buf, str);
  13.      istr[j] = str;
  14.      while (*str) {
  15.          if (*str == '.') {
  16.              *str++ = '\0';
  17.              j++;
  18.              istr[j] = str;
  19.              if (j == 2)
  20.                  break;
  21.          } else if (index("0123456789", *str) != 0) {
  22.              str++;
  23.          } else
  24.              return 0L;
  25.      }
  26.      if (j != 2)
  27.          return 0L;
  28.      ver_maj = atoi(istr[0]);
  29.      ver_min = atoi(istr[1]);
  30.      patch = atoi(istr[2]);
  31.      return FEATURE_NOTICE_VER(ver_maj, ver_min, patch);
  32.      /* macro from hack.h */
  33.  }
  34.  

get_current_feature_ver

  1.  unsigned long
  2.  get_current_feature_ver()
  3.  {
  4.      return FEATURE_NOTICE_VER(VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
  5.  }
  6.  
  7.  /*ARGUSED*/

copyright_banner_line

  1.  const char *
  2.  copyright_banner_line(indx)
  3.  int indx;
  4.  {
  5.  #ifdef COPYRIGHT_BANNER_A
  6.      if (indx == 1)
  7.          return COPYRIGHT_BANNER_A;
  8.  #endif
  9.  #ifdef COPYRIGHT_BANNER_B
  10.      if (indx == 2)
  11.          return COPYRIGHT_BANNER_B;
  12.  #endif
  13.  #ifdef COPYRIGHT_BANNER_C
  14.      if (indx == 3)
  15.          return COPYRIGHT_BANNER_C;
  16.  #endif
  17.  #ifdef COPYRIGHT_BANNER_D
  18.      if (indx == 4)
  19.          return COPYRIGHT_BANNER_D;
  20.  #endif
  21.      return "";
  22.  }
  23.  
  24.  /*version.c*/