Source:NetHack 3.4.3/src/version.c

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

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[edit]

  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. */

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. #include "hack.h"
  2. #include "date.h"
  3. /*
  4. * All the references to the contents of patchlevel.h have been moved
  5. * into makedefs....
  6. */
  7. #ifdef SHORT_FILENAMES
  8. #include "patchlev.h"
  9. #else
  10. #include "patchlevel.h"
  11. #endif
  12.  
  13. /* #define BETA_INFO "" */	/* "[ beta n]" */

version_string[edit]

  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. }

getversionstring[edit]

  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. }

doversion[edit]

  1. int
  2. doversion()
  3. {
  4. 	char buf[BUFSZ];
  5.  
  6. 	pline("%s", getversionstring(buf));
  7. 	return 0;
  8. }

doextversion[edit]

  1. int
  2. doextversion()
  3. {
  4. 	display_file(OPTIONS_USED, TRUE);
  5. 	return 0;
  6. }
  7.  
  8. #ifdef MICRO

comp_times[edit]

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

check_version[edit]

  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_sizes != VERSION_SANITY2) {
  27. 	    if (complain)
  28. 		pline("Configuration incompatibility for file \"%s\".",
  29. 		      filename);
  30. 	    return FALSE;
  31. 	}
  32. 	return TRUE;
  33. }

uptodate[edit]

  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) wait_synch();
  23. 	return FALSE;
  24. }
  25. return TRUE;
  26. }

store_version[edit]

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

get_feature_notice_ver[edit]

  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) return 0L;
  11. 	str = strcpy(buf, str);
  12. 	istr[j] = str;
  13. 	while (*str) {
  14. 		if (*str == '.') {
  15. 			*str++ = '\0';
  16. 			j++;
  17. 			istr[j] = str;
  18. 			if (j == 2) break;
  19. 		} else if (index("0123456789", *str) != 0) {
  20. 			str++;
  21. 		} else 
  22. 			return 0L;
  23. 	}
  24. 	if (j != 2) return 0L;
  25. 	ver_maj = atoi(istr[0]);
  26. 	ver_min = atoi(istr[1]);
  27. 	patch = atoi(istr[2]);
  28. 	return FEATURE_NOTICE_VER(ver_maj,ver_min,patch);
  29. 	/* macro from hack.h */
  30. }

get_current_feature_ver[edit]

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