Difference between revisions of "Source:NetHack 3.4.3/src/version.c"

From NetHackWiki
Jump to navigation Jump to search
(Automated source code upload)
 
m (moved Source:Version.c to Source:NetHack 3.4.3/src/version.c: Moving src to subdirs)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
__MIXEDSYNTAXHIGHLIGHT__
 +
Below is the full text to src/version.c from NetHack 3.4.3. To link to a particular line, write [[version.c#line123|<nowiki>[[version.c#line123]]</nowiki>]], for example.
 +
 +
== Top of file ==
  
Below is the full text to src/version.c from NetHack 3.4.3. To link to a particular line, write [[version.c#line123|<nowiki>[[version.c#line123]]</nowiki>]], for example.
 
 
  <span id="line1">1.    /* SCCS Id: @(#)version.c 3.4 2003/12/06 */</span>
 
  <span id="line1">1.    /* SCCS Id: @(#)version.c 3.4 2003/12/06 */</span>
 
  <span id="line2">2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */</span>
 
  <span id="line2">2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */</span>
Line 22: Line 25:
 
  <span id="line17">17.  /* #define BETA_INFO "" */ /* "[ beta n]" */</span>
 
  <span id="line17">17.  /* #define BETA_INFO "" */ /* "[ beta n]" */</span>
 
  <span id="line18">18.  </span>
 
  <span id="line18">18.  </span>
 +
 +
== version_string ==
 +
 
  <span id="line19">19.  /* fill buffer with short version (so caller can avoid including date.h) */</span>
 
  <span id="line19">19.  /* fill buffer with short version (so caller can avoid including date.h) */</span>
 
  <span id="line20">20.  char *</span>
 
  <span id="line20">20.  char *</span>
Line 30: Line 36:
 
  <span id="line25">25.  }</span>
 
  <span id="line25">25.  }</span>
 
  <span id="line26">26.  </span>
 
  <span id="line26">26.  </span>
 +
 +
== getversionstring ==
 +
 
  <span id="line27">27.  /* fill and return the given buffer with the long nethack version string */</span>
 
  <span id="line27">27.  /* fill and return the given buffer with the long nethack version string */</span>
 
  <span id="line28">28.  char *</span>
 
  <span id="line28">28.  char *</span>
Line 45: Line 54:
 
  <span id="line40">40.  }</span>
 
  <span id="line40">40.  }</span>
 
  <span id="line41">41.  </span>
 
  <span id="line41">41.  </span>
 +
 +
== doversion ==
 +
 
  <span id="line42">42.  int</span>
 
  <span id="line42">42.  int</span>
 
  <span id="line43">43.  doversion()</span>
 
  <span id="line43">43.  doversion()</span>
Line 54: Line 66:
 
  <span id="line49">49.  }</span>
 
  <span id="line49">49.  }</span>
 
  <span id="line50">50.  </span>
 
  <span id="line50">50.  </span>
 +
 +
== doextversion ==
 +
 
  <span id="line51">51.  int</span>
 
  <span id="line51">51.  int</span>
 
  <span id="line52">52.  doextversion()</span>
 
  <span id="line52">52.  doextversion()</span>
Line 62: Line 77:
 
  <span id="line57">57.  </span>
 
  <span id="line57">57.  </span>
 
  <span id="line58">58.  #ifdef MICRO</span>
 
  <span id="line58">58.  #ifdef MICRO</span>
 +
 +
== comp_times ==
 +
 
  <span id="line59">59.  boolean</span>
 
  <span id="line59">59.  boolean</span>
 
  <span id="line60">60.  comp_times(filetime)</span>
 
  <span id="line60">60.  comp_times(filetime)</span>
Line 70: Line 88:
 
  <span id="line65">65.  #endif</span>
 
  <span id="line65">65.  #endif</span>
 
  <span id="line66">66.  </span>
 
  <span id="line66">66.  </span>
 +
 +
== check_version ==
 +
 
  <span id="line67">67.  boolean</span>
 
  <span id="line67">67.  boolean</span>
 
  <span id="line68">68.  check_version(version_data, filename, complain)</span>
 
  <span id="line68">68.  check_version(version_data, filename, complain)</span>
Line 104: Line 125:
 
  <span id="line99">99.  }</span>
 
  <span id="line99">99.  }</span>
 
  <span id="line100">100.  </span>
 
  <span id="line100">100.  </span>
 +
 +
== uptodate ==
 +
 
  <span id="line101">101.  /* this used to be based on file date and somewhat OS-dependant,</span>
 
  <span id="line101">101.  /* this used to be based on file date and somewhat OS-dependant,</span>
 
  <span id="line102">102.    but now examines the initial part of the file's contents */</span>
 
  <span id="line102">102.    but now examines the initial part of the file's contents */</span>
Line 131: Line 155:
 
  <span id="line126">126.  }</span>
 
  <span id="line126">126.  }</span>
 
  <span id="line127">127.  </span>
 
  <span id="line127">127.  </span>
 +
 +
== store_version ==
 +
 
  <span id="line128">128.  void</span>
 
  <span id="line128">128.  void</span>
 
  <span id="line129">129.  store_version(fd)</span>
 
  <span id="line129">129.  store_version(fd)</span>
Line 151: Line 178:
 
  <span id="line146">146.  #endif</span>
 
  <span id="line146">146.  #endif</span>
 
  <span id="line147">147.  </span>
 
  <span id="line147">147.  </span>
 +
 +
== get_feature_notice_ver ==
 +
 
  <span id="line148">148.  unsigned long</span>
 
  <span id="line148">148.  unsigned long</span>
 
  <span id="line149">149.  get_feature_notice_ver(str)</span>
 
  <span id="line149">149.  get_feature_notice_ver(str)</span>
Line 182: Line 212:
 
  <span id="line177">177.  }</span>
 
  <span id="line177">177.  }</span>
 
  <span id="line178">178.  </span>
 
  <span id="line178">178.  </span>
 +
 +
== get_current_feature_ver ==
 +
 
  <span id="line179">179.  unsigned long</span>
 
  <span id="line179">179.  unsigned long</span>
 
  <span id="line180">180.  get_current_feature_ver()</span>
 
  <span id="line180">180.  get_current_feature_ver()</span>

Latest revision as of 19:24, 31 January 2011

Below is the full text to src/version.c from NetHack 3.4.3. To link to a particular line, write [[version.c#line123]], for example.

Top of file

/*	SCCS Id: @(#)version.c	3.4	2003/12/06	*/
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* 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.

#include "hack.h"
#include "date.h"
/*
* All the references to the contents of patchlevel.h have been moved
* into makedefs....
*/
#ifdef SHORT_FILENAMES
#include "patchlev.h"
#else
#include "patchlevel.h"
#endif

/* #define BETA_INFO "" */	/* "[ beta n]" */

version_string

/* fill buffer with short version (so caller can avoid including date.h) */
char *
version_string(buf)
char *buf;
{
	return strcpy(buf, VERSION_STRING);
}

getversionstring

/* fill and return the given buffer with the long nethack version string */
char *
getversionstring(buf)
char *buf;
{
	Strcpy(buf, VERSION_ID);
#if defined(BETA) && defined(BETA_INFO)
	Sprintf(eos(buf), " %s", BETA_INFO);
#endif
#if defined(RUNTIME_PORT_ID)
	append_port_id(buf);
#endif
	return buf;
}

doversion

int
doversion()
{
	char buf[BUFSZ];

	pline("%s", getversionstring(buf));
	return 0;
}

doextversion

int
doextversion()
{
	display_file(OPTIONS_USED, TRUE);
	return 0;
}

#ifdef MICRO

comp_times

boolean
comp_times(filetime)
long filetime;
{
	return((boolean)(filetime < BUILD_TIME));
}
#endif

check_version

boolean
check_version(version_data, filename, complain)
struct version_info *version_data;
const char *filename;
boolean complain;
{
	if (
#ifdef VERSION_COMPATIBILITY
	    version_data->incarnation < VERSION_COMPATIBILITY ||
	    version_data->incarnation > VERSION_NUMBER
#else
	    version_data->incarnation != VERSION_NUMBER
#endif
	  ) {
	    if (complain)
		pline("Version mismatch for file \"%s\".", filename);
	    return FALSE;
	} else if (
#ifndef IGNORED_FEATURES
		   version_data->feature_set != VERSION_FEATURES ||
#else
		   (version_data->feature_set & ~IGNORED_FEATURES) !=
			  (VERSION_FEATURES & ~IGNORED_FEATURES) ||
#endif
		   version_data->entity_count != VERSION_SANITY1 ||
		   version_data->struct_sizes != VERSION_SANITY2) {
	    if (complain)
		pline("Configuration incompatibility for file \"%s\".",
		      filename);
	    return FALSE;
	}
	return TRUE;
}

uptodate

/* this used to be based on file date and somewhat OS-dependant,
but now examines the initial part of the file's contents */
boolean
uptodate(fd, name)
int fd;
const char *name;
{
int rlen;
struct version_info vers_info;
boolean verbose = name ? TRUE : FALSE;

rlen = read(fd, (genericptr_t) &vers_info, sizeof vers_info);
minit();		/* ZEROCOMP */
if (rlen == 0) {
	if (verbose) {
	    pline("File \"%s\" is empty?", name);
	    wait_synch();
	}
	return FALSE;
}
if (!check_version(&vers_info, name, verbose)) {
	if (verbose) wait_synch();
	return FALSE;
}
return TRUE;
}

store_version

void
store_version(fd)
int fd;
{
	const static struct version_info version_data = {
			VERSION_NUMBER, VERSION_FEATURES,
			VERSION_SANITY1, VERSION_SANITY2
	};

	bufoff(fd);
	/* bwrite() before bufon() uses plain write() */
	bwrite(fd,(genericptr_t)&version_data,(unsigned)(sizeof version_data));
	bufon(fd);
	return;
}

#ifdef AMIGA
const char amiga_version_string[] = AMIGA_VERSION_STRING;
#endif

get_feature_notice_ver

unsigned long
get_feature_notice_ver(str)
char *str;
{
	char buf[BUFSZ];
	int ver_maj, ver_min, patch;
	char *istr[3];
	int j = 0;

	if (!str) return 0L;
	str = strcpy(buf, str);
	istr[j] = str;
	while (*str) {
		if (*str == '.') {
			*str++ = '\0';
			j++;
			istr[j] = str;
			if (j == 2) break;
		} else if (index("0123456789", *str) != 0) {
			str++;
		} else 
			return 0L;
	}
	if (j != 2) return 0L;
	ver_maj = atoi(istr[0]);
	ver_min = atoi(istr[1]);
	patch = atoi(istr[2]);
	return FEATURE_NOTICE_VER(ver_maj,ver_min,patch);
	/* macro from hack.h */
}

get_current_feature_ver

unsigned long
get_current_feature_ver()
{
	return FEATURE_NOTICE_VER(VERSION_MAJOR,VERSION_MINOR,PATCHLEVEL);
}

/*version.c*/