Source:NetHack 3.4.0/version.c

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

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)version.c	3.4	1999/12/01	*/ 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 "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.   /* fill and return the given buffer with the nethack version string */ 18.  char * 19.  getversionstring(buf) 20.  char *buf; 21.  {  22.   	return strcpy(buf, VERSION_ID); 23.  }  24.    25.   int 26.  doversion 27.  {  28.   	char buf[BUFSZ]; 29.   30.   	pline(getversionstring(buf)); 31.  	return 0; 32.  }  33.    34.   int 35.  doextversion 36.  {  37.   	display_file(OPTIONS_USED, TRUE); 38.  	return 0; 39.  }  40.    41.   #ifdef MICRO 42.  boolean 43.  comp_times(filetime) 44.  long filetime; 45.  {  46.   	return((boolean)(filetime < BUILD_TIME)); 47.  }  48.   #endif 49.   50.   boolean 51.  check_version(version_data, filename, complain) 52.  struct version_info *version_data; 53.  const char *filename; 54.  boolean complain; 55.  {  56.   	if (  57.   #ifdef VERSION_COMPATIBILITY  58.   	    version_data->incarnation < VERSION_COMPATIBILITY ||  59.   	    version_data->incarnation > VERSION_NUMBER  60.   #else  61.   	    version_data->incarnation != VERSION_NUMBER  62.   #endif  63.   	  ) { 64.  	    if (complain) 65.  		pline("Version mismatch for file \"%s\".", filename); 66.  	    return FALSE; 67.  	} else if (version_data->feature_set != VERSION_FEATURES ||  68.   		   version_data->entity_count != VERSION_SANITY1 ||  69.   		   version_data->struct_sizes != VERSION_SANITY2) { 70.  	    if (complain) 71.  		pline("Configuration incompatibility for file \"%s\".",  72.   		      filename); 73.  	    return FALSE; 74.  	}  75.   	return TRUE; 76.  }  77.    78.   /* this used to be based on file date and somewhat OS-dependant, 79.     but now examines the initial part of the file's contents */ 80.  boolean 81.  uptodate(fd, name) 82.  int fd; 83.  const char *name; 84.  {  85.       int rlen; 86.      struct version_info vers_info; 87.      boolean verbose = name ? TRUE : FALSE; 88.   89.       rlen = read(fd, (genericptr_t) &vers_info, sizeof vers_info); 90.      minit;		/* ZEROCOMP */ 91.      if (rlen == 0) { 92.  	if (verbose) { 93.  	    pline("File \"%s\" is empty?", name); 94.  	    wait_synch; 95.  	}  96.   	return FALSE; 97.      }  98.       if (!check_version(&vers_info, name, verbose)) { 99.  	if (verbose) wait_synch; 100. 	return FALSE; 101.     }  102.      return TRUE; 103. }  104.   105.  void 106. store_version(fd) 107. int fd; 108. {  109.  	static struct version_info version_data = { 110. 			VERSION_NUMBER, VERSION_FEATURES, 111. 			VERSION_SANITY1, VERSION_SANITY2 112. 	};  113.   114.  	bufoff(fd); 115. 	/* bwrite before bufon uses plain write */ 116. 	bwrite(fd,(genericptr_t)&version_data,(unsigned)(sizeof version_data)); 117. 	bufon(fd); 118. 	return; 119. }  120.   121.  #ifdef AMIGA 122. const char amiga_version_string[] = AMIGA_VERSION_STRING; 123. #endif 124.  125.  unsigned long 126. get_feature_notice_ver(str) 127. char *str; 128. {  129.  	char buf[BUFSZ]; 130. 	int ver_maj, ver_min, patch; 131. 	char *istr[3]; 132. 	int j = 0; 133.  134.  	if (!str) return 0L; 135. 	str = strcpy(buf, str); 136. 	istr[j] = str; 137. 	while (*str) { 138. 		if (*str == '.') { 139. 			*str++ = '\0'; 140. 			j++; 141. 			istr[j] = str; 142. 			if (j == 2) break; 143. 		} else if (index("0123456789", *str) != 0) { 144. 			str++; 145. 		} else 146. 			return 0L; 147. 	}  148.  	if (j != 2) return 0L; 149. 	ver_maj = atoi(istr[0]); 150. 	ver_min = atoi(istr[1]); 151. 	patch = atoi(istr[2]); 152. 	return FEATURE_NOTICE_VER(ver_maj,ver_min,patch); 153. 	/* macro from hack.h */ 154. }  155.   156.  unsigned long 157. get_current_feature_ver 158. {  159.  	return FEATURE_NOTICE_VER(VERSION_MAJOR,VERSION_MINOR,PATCHLEVEL); 160. }  161.   162.  /*version.c*/