Blindfold removal fix
[slashemextended.git] / src / version.c
blob78e2041e003c89b977db64d1457249005aa9d306
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. */
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....
11 #include "patchlevel.h"
13 /* #define BETA_INFO "" */ /* "[ beta n]" */
15 /* fill buffer with short version (so caller can avoid including date.h) */
16 char *
17 version_string(buf)
18 char *buf;
20 return strcpy(buf, VERSION_STRING);
23 /* fill and return the given buffer with the long nethack version string */
24 char *
25 getversionstring(buf)
26 char *buf;
28 strcpy(buf, VERSION_ID);
29 #if defined(BETA) && defined(BETA_INFO)
30 sprintf(eos(buf), " %s", BETA_INFO);
31 #endif
32 #if defined(RUNTIME_PORT_ID)
33 append_port_id(buf);
34 #endif
35 return buf;
38 int
39 doversion()
41 char buf[BUFSZ];
43 pline("%s", getversionstring(buf));
44 return 0;
47 int
48 doextversion()
50 display_file_area(NH_OPTIONS_USED_AREA, NH_OPTIONS_USED, TRUE);
51 return 0;
54 #ifdef MICRO
55 boolean
56 comp_times(filetime)
57 long filetime;
59 return((boolean)(filetime < BUILD_TIME));
61 #endif
63 boolean
64 check_version(version_data, filename, complain)
65 struct version_info *version_data;
66 const char *filename;
67 boolean complain;
69 if (
70 #ifdef VERSION_COMPATIBILITY
71 version_data->incarnation < VERSION_COMPATIBILITY ||
72 version_data->incarnation > VERSION_NUMBER
73 #else
74 version_data->incarnation != VERSION_NUMBER
75 #endif
76 ) {
77 if (complain)
78 pline("Version mismatch for file \"%s\".", filename);
79 return FALSE;
80 } else if (
81 #ifndef IGNORED_FEATURES
82 version_data->feature_set != VERSION_FEATURES ||
83 #else
84 (version_data->feature_set & ~IGNORED_FEATURES) !=
85 (VERSION_FEATURES & ~IGNORED_FEATURES) ||
86 #endif
87 version_data->entity_count != VERSION_SANITY1 ||
88 version_data->struct_sizes != VERSION_SANITY2) {
89 if (complain)
90 pline("Configuration incompatibility for file \"%s\".",
91 filename);
92 return FALSE;
94 return TRUE;
97 /* this used to be based on file date and somewhat OS-dependant,
98 but now examines the initial part of the file's contents */
99 boolean
100 uptodate(fd, name)
101 int fd;
102 const char *name;
104 int rlen;
105 struct version_info vers_info;
106 boolean verbose = name ? TRUE : FALSE;
108 rlen = read(fd, (void *) &vers_info, sizeof vers_info);
109 minit(); /* ZEROCOMP */
110 if (rlen == 0) {
111 if (verbose) {
112 pline("File \"%s\" is empty?", name);
113 wait_synch();
115 return FALSE;
117 if (!check_version(&vers_info, name, verbose)) {
118 if (verbose) wait_synch();
119 return FALSE;
121 return TRUE;
124 void
125 store_version(fd)
126 int fd;
128 const static struct version_info version_data = {
129 VERSION_NUMBER, VERSION_FEATURES,
130 VERSION_SANITY1, VERSION_SANITY2
133 bufoff(fd);
134 /* bwrite() before bufon() uses plain write() */
135 bwrite(fd,(void *)&version_data,(unsigned)(sizeof version_data));
136 bufon(fd);
137 return;
140 #ifdef AMIGA
141 const char amiga_version_string[] = AMIGA_VERSION_STRING;
142 #endif
144 unsigned long
145 get_feature_notice_ver(str)
146 char *str;
148 char buf[BUFSZ];
149 int ver_maj, ver_min, patch;
150 char *istr[3];
151 int j = 0;
153 if (!str) return 0L;
154 str = strcpy(buf, str);
155 istr[j] = str;
156 while (*str) {
157 if (*str == '.') {
158 *str++ = '\0';
159 j++;
160 istr[j] = str;
161 if (j == 2) break;
162 } else if (index("0123456789", *str) != 0) {
163 str++;
164 } else
165 return 0L;
167 if (j != 2) return 0L;
168 ver_maj = atoi(istr[0]);
169 ver_min = atoi(istr[1]);
170 patch = atoi(istr[2]);
171 return FEATURE_NOTICE_VER(ver_maj,ver_min,patch);
172 /* macro from hack.h */
175 unsigned long
176 get_current_feature_ver()
178 return FEATURE_NOTICE_VER(VERSION_MAJOR,VERSION_MINOR,PATCHLEVEL);
181 /*version.c*/