Source:NetHack 3.6.0/src/version.c

From NetHackWiki
(Redirected from Source:Version.c)
Jump to: navigation, search

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

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.

Top of file

  1.  /* NetHack 3.6	version.c	$NHDT-Date: 1449328116 2015/12/05 15:08:36 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.41 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  #include "dlb.h"
  7.  #include "date.h"
  8.  /*
  9.   * All the references to the contents of patchlevel.h have been moved
  10.   * into makedefs....
  11.   */
  12.  #ifdef SHORT_FILENAMES
  13.  #include "patchlev.h"
  14.  #else
  15.  #include "patchlevel.h"
  16.  #endif
  17.  
  18.  #define BETA_INFO ""
  19.  
  20.  STATIC_DCL void FDECL(insert_rtoptions, (winid,char *,const char *));
  21.  

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.      Strcpy(buf, VERSION_ID);
  7.  #if defined(BETA) && defined(BETA_INFO)
  8.      Sprintf(eos(buf), " %s", BETA_INFO);
  9.  #endif
  10.  #if defined(RUNTIME_PORT_ID)
  11.      append_port_id(buf);
  12.  #endif
  13.      return buf;
  14.  }
  15.  

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

insert_rtoptions

  1.  extern const char regex_id[];
  2.  
  3.  static const char *rt_opts[] = {
  4.      "pattern matching via", regex_id,
  5.  };
  6.  static const char indent[] = "    ";
  7.  
  8.  /*
  9.   * 3.6.0
  10.   * Some optional stuff is no longer available to makedefs because
  11.   * it depends which of several object files got linked into the
  12.   * game image, so we insert those options here.
  13.   */
  14.  STATIC_OVL void
  15.  insert_rtoptions(win, buf, finalphrase)
  16.  winid win;
  17.  char *buf;
  18.  const char *finalphrase;
  19.  {
  20.      char rtbuf[BUFSZ];
  21.      int l, i;
  22.      const char *s1 = 0, *s2 = 0, *s3 = 0, *s4 = 0;
  23.  
  24.      if ((int) strlen(buf) >= (BUFSZ - 1))
  25.          return;
  26.  
  27.      strcpy(rtbuf, buf);
  28.      for (i = 0; i < (SIZE(rt_opts) + 1); i += 2) {
  29.          if (i < SIZE(rt_opts)) {
  30.              s1 = ", ";
  31.              s2 = rt_opts[i];
  32.              s3 = " ";
  33.              s4 = rt_opts[i+1];
  34.          } else {
  35.              s1 = " ";
  36.              s2 = finalphrase;
  37.              s3 = "";
  38.              s4 = "";
  39.          }
  40.          l = (int) strlen(rtbuf) + (int) strlen(s1) + (int) strlen(s2)
  41.              + (int) strlen(s3) + (int) strlen(s4) + 1;
  42.          if (l <= (COLNO - 5) && l < (BUFSZ - 1)) {
  43.              Strcat(rtbuf, s1);
  44.              Strcat(rtbuf, s2);
  45.              Strcat(rtbuf, s3);
  46.              Strcat(rtbuf, s4);
  47.          } else {
  48.              putstr(win, 0, rtbuf);
  49.              if (i >= SIZE(rt_opts))
  50.                  s1 = "";
  51.              l = (int) strlen(indent) + (int) strlen(s1) + (int) strlen(s2)
  52.                  + (int) strlen(s3) + (int) strlen(s4) + 1;
  53.              if (l <= (COLNO - 5) && l < (BUFSZ - 1)) {
  54.                  Strcpy(rtbuf, indent);
  55.                  Strcat(rtbuf, s1);
  56.                  Strcat(rtbuf, s2);
  57.                  Strcat(rtbuf, s3);
  58.                  Strcat(rtbuf, s4);
  59.              }
  60.          }
  61.      }
  62.  
  63.      if (l)
  64.          putstr(win, 0, rtbuf);
  65.      *buf = '\0';
  66.  }
  67.  

comp_times

  1.  #ifdef MICRO
  2.  boolean
  3.  comp_times(filetime)
  4.  long filetime;
  5.  {
  6.      return (boolean) (filetime < BUILD_TIME);
  7.  }
  8.  #endif
  9.  

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.  


  1.  #ifdef AMIGA
  2.  const char amiga_version_string[] = AMIGA_VERSION_STRING;
  3.  #endif
  4.  

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.  

copyright_banner_line

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