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 (add headers)
Line 1: Line 1:
 +
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 24:
 
  <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 35:
 
  <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 53:
 
  <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 65:
 
  <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 76:
 
  <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 87:
 
  <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 124:
 
  <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 154:
 
  <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 177:
 
  <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 211:
 
  <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>

Revision as of 08:04, 27 August 2006

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

1.    /*	SCCS Id: @(#)version.c	3.4	2003/12/06	*/
2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    

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.

5.    #include "hack.h"
6.    #include "date.h"
7.    /*
8.     * All the references to the contents of patchlevel.h have been moved
9.     * into makedefs....
10.    */
11.   #ifdef SHORT_FILENAMES
12.   #include "patchlev.h"
13.   #else
14.   #include "patchlevel.h"
15.   #endif
16.   
17.   /* #define BETA_INFO "" */	/* "[ beta n]" */
18.   

version_string

19.   /* fill buffer with short version (so caller can avoid including date.h) */
20.   char *
21.   version_string(buf)
22.   char *buf;
23.   {
24.   	return strcpy(buf, VERSION_STRING);
25.   }
26.   

getversionstring

27.   /* fill and return the given buffer with the long nethack version string */
28.   char *
29.   getversionstring(buf)
30.   char *buf;
31.   {
32.   	Strcpy(buf, VERSION_ID);
33.   #if defined(BETA) && defined(BETA_INFO)
34.   	Sprintf(eos(buf), " %s", BETA_INFO);
35.   #endif
36.   #if defined(RUNTIME_PORT_ID)
37.   	append_port_id(buf);
38.   #endif
39.   	return buf;
40.   }
41.   

doversion

42.   int
43.   doversion()
44.   {
45.   	char buf[BUFSZ];
46.   
47.   	pline("%s", getversionstring(buf));
48.   	return 0;
49.   }
50.   

doextversion

51.   int
52.   doextversion()
53.   {
54.   	display_file(OPTIONS_USED, TRUE);
55.   	return 0;
56.   }
57.   
58.   #ifdef MICRO

comp_times

59.   boolean
60.   comp_times(filetime)
61.   long filetime;
62.   {
63.   	return((boolean)(filetime < BUILD_TIME));
64.   }
65.   #endif
66.   

check_version

67.   boolean
68.   check_version(version_data, filename, complain)
69.   struct version_info *version_data;
70.   const char *filename;
71.   boolean complain;
72.   {
73.   	if (
74.   #ifdef VERSION_COMPATIBILITY
75.   	    version_data->incarnation < VERSION_COMPATIBILITY ||
76.   	    version_data->incarnation > VERSION_NUMBER
77.   #else
78.   	    version_data->incarnation != VERSION_NUMBER
79.   #endif
80.   	  ) {
81.   	    if (complain)
82.   		pline("Version mismatch for file \"%s\".", filename);
83.   	    return FALSE;
84.   	} else if (
85.   #ifndef IGNORED_FEATURES
86.   		   version_data->feature_set != VERSION_FEATURES ||
87.   #else
88.   		   (version_data->feature_set & ~IGNORED_FEATURES) !=
89.   			  (VERSION_FEATURES & ~IGNORED_FEATURES) ||
90.   #endif
91.   		   version_data->entity_count != VERSION_SANITY1 ||
92.   		   version_data->struct_sizes != VERSION_SANITY2) {
93.   	    if (complain)
94.   		pline("Configuration incompatibility for file \"%s\".",
95.   		      filename);
96.   	    return FALSE;
97.   	}
98.   	return TRUE;
99.   }
100.  

uptodate

101.  /* this used to be based on file date and somewhat OS-dependant,
102.     but now examines the initial part of the file's contents */
103.  boolean
104.  uptodate(fd, name)
105.  int fd;
106.  const char *name;
107.  {
108.      int rlen;
109.      struct version_info vers_info;
110.      boolean verbose = name ? TRUE : FALSE;
111.  
112.      rlen = read(fd, (genericptr_t) &vers_info, sizeof vers_info);
113.      minit();		/* ZEROCOMP */
114.      if (rlen == 0) {
115.  	if (verbose) {
116.  	    pline("File \"%s\" is empty?", name);
117.  	    wait_synch();
118.  	}
119.  	return FALSE;
120.      }
121.      if (!check_version(&vers_info, name, verbose)) {
122.  	if (verbose) wait_synch();
123.  	return FALSE;
124.      }
125.      return TRUE;
126.  }
127.  

store_version

128.  void
129.  store_version(fd)
130.  int fd;
131.  {
132.  	const static struct version_info version_data = {
133.  			VERSION_NUMBER, VERSION_FEATURES,
134.  			VERSION_SANITY1, VERSION_SANITY2
135.  	};
136.  
137.  	bufoff(fd);
138.  	/* bwrite() before bufon() uses plain write() */
139.  	bwrite(fd,(genericptr_t)&version_data,(unsigned)(sizeof version_data));
140.  	bufon(fd);
141.  	return;
142.  }
143.  
144.  #ifdef AMIGA
145.  const char amiga_version_string[] = AMIGA_VERSION_STRING;
146.  #endif
147.  

get_feature_notice_ver

148.  unsigned long
149.  get_feature_notice_ver(str)
150.  char *str;
151.  {
152.  	char buf[BUFSZ];
153.  	int ver_maj, ver_min, patch;
154.  	char *istr[3];
155.  	int j = 0;
156.  
157.  	if (!str) return 0L;
158.  	str = strcpy(buf, str);
159.  	istr[j] = str;
160.  	while (*str) {
161.  		if (*str == '.') {
162.  			*str++ = '\0';
163.  			j++;
164.  			istr[j] = str;
165.  			if (j == 2) break;
166.  		} else if (index("0123456789", *str) != 0) {
167.  			str++;
168.  		} else 
169.  			return 0L;
170.  	}
171.  	if (j != 2) return 0L;
172.  	ver_maj = atoi(istr[0]);
173.  	ver_min = atoi(istr[1]);
174.  	patch = atoi(istr[2]);
175.  	return FEATURE_NOTICE_VER(ver_maj,ver_min,patch);
176.  	/* macro from hack.h */
177.  }
178.  

get_current_feature_ver

179.  unsigned long
180.  get_current_feature_ver()
181.  {
182.  	return FEATURE_NOTICE_VER(VERSION_MAJOR,VERSION_MINOR,PATCHLEVEL);
183.  }
184.  
185.  /*version.c*/