OSDN Git Service

add translation
[jnethack/source.git] / src / version.c
1 /* NetHack 3.6  version.c       $NHDT-Date: 1449328116 2015/12/05 15:08:36 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.41 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 /* JNetHack Copyright */
6 /* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000  */
7 /* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016            */
8 /* JNetHack may be freely redistributed.  See license for details. */
9
10 #include "hack.h"
11 #include "dlb.h"
12 #include "date.h"
13 /*
14  * All the references to the contents of patchlevel.h have been moved
15  * into makedefs....
16  */
17 #ifdef SHORT_FILENAMES
18 #include "patchlev.h"
19 #include "../japanese/jpatchle.h"
20 #else
21 #include "patchlevel.h"
22 #include "../japanese/jpatchlevel.h"
23 #endif
24
25 #define BETA_INFO ""
26
27 STATIC_DCL void FDECL(insert_rtoptions, (winid,char *,const char *));
28
29 /* fill buffer with short version (so caller can avoid including date.h) */
30 char *
31 version_string(buf)
32 char *buf;
33 {
34     return strcpy(buf, VERSION_STRING);
35 }
36
37 /* fill and return the given buffer with the long nethack version string */
38 char *
39 getversionstring(buf)
40 char *buf;
41 {
42     Strcpy(buf, VERSION_ID);
43 #if defined(BETA) && defined(BETA_INFO)
44     Sprintf(eos(buf), " %s", BETA_INFO);
45 #endif
46 #if defined(RUNTIME_PORT_ID)
47     append_port_id(buf);
48 #endif
49     return buf;
50 }
51
52 /* the 'v' command */
53 int
54 doversion()
55 {
56     char buf[BUFSZ];
57
58     pline("%s", getversionstring(buf));
59 #if 1 /*JP*/
60     pline("%s", JVERSION_ID);
61 #endif
62     return 0;
63 }
64
65 /* the '#version' command; also a choice for '?' */
66 int
67 doextversion()
68 {
69     dlb *f;
70     char *cr, *pd, buf[BUFSZ];
71     winid win = create_nhwindow(NHW_TEXT);
72     boolean rtadded = FALSE;
73
74     /* instead of using ``display_file(OPTIONS_USED,TRUE)'' we handle
75        the file manually so we can include dynamic version info */
76     putstr(win, 0, getversionstring(buf));
77
78     f = dlb_fopen(OPTIONS_USED, "r");
79     if (!f) {
80         putstr(win, 0, "");
81         Sprintf(buf, "[Configuration '%s' not available?]", OPTIONS_USED);
82         putstr(win, 0, buf);
83     } else {
84         /*
85          * already inserted above:
86          * + outdented program name and version plus build date and time
87          * dat/options; display the contents with lines prefixed by '-'
88          * deleted:
89          * - blank-line
90          * -     indented program name and version
91          *   blank-line
92          *   outdented feature header
93          * - blank-line
94          *       indented feature list
95          *       spread over multiple lines
96          *   blank-line
97          *   outdented windowing header
98          * - blank-line
99          *       indented windowing choices with
100          *       optional second line for default
101          * - blank-line
102          * - EOF
103          */
104         boolean prolog = TRUE; /* to skip indented program name */
105
106         while (dlb_fgets(buf, BUFSZ, f)) {
107             if ((cr = index(buf, '\n')) != 0)
108                 *cr = 0;
109             if ((cr = index(buf, '\r')) != 0)
110                 *cr = 0;
111             if (index(buf, '\t') != 0)
112                 (void) tabexpand(buf);
113
114             if (*buf && *buf != ' ') {
115                 /* found outdented header; insert a separator since we'll
116                    have skipped corresponding blank line inside the file */
117                 putstr(win, 0, "");
118                 prolog = FALSE;
119             }
120             /* skip blank lines and prolog (progame name plus version) */
121             if (prolog || !*buf)
122                 continue;
123
124             if (!rtadded) {
125                 const char *catchphrase = ", and basic NetHack features.";
126
127                 pd = strstri(buf, catchphrase);
128                 if (pd) {
129                     *pd = '\0';
130                     insert_rtoptions(win, buf, &catchphrase[2]);
131                     rtadded = TRUE; /* only do it once */
132                }
133             }
134             if (*buf)
135                 putstr(win, 0, buf);
136         }
137         (void) dlb_fclose(f);
138         display_nhwindow(win, FALSE);
139         destroy_nhwindow(win);
140     }
141     return 0;
142 }
143
144 extern const char regex_id[];
145
146 static const char *rt_opts[] = {
147     "pattern matching via", regex_id,
148 };
149 static const char indent[] = "    ";
150
151 /*
152  * 3.6.0
153  * Some optional stuff is no longer available to makedefs because
154  * it depends which of several object files got linked into the
155  * game image, so we insert those options here.
156  */
157 STATIC_OVL void
158 insert_rtoptions(win, buf, finalphrase)
159 winid win;
160 char *buf;
161 const char *finalphrase;
162 {
163     char rtbuf[BUFSZ];
164     int l, i;
165     const char *s1 = 0, *s2 = 0, *s3 = 0, *s4 = 0;
166
167     if ((int) strlen(buf) >= (BUFSZ - 1))
168         return;
169
170     strcpy(rtbuf, buf);
171     for (i = 0; i < (SIZE(rt_opts) + 1); i += 2) {
172         if (i < SIZE(rt_opts)) {
173             s1 = ", ";
174             s2 = rt_opts[i];
175             s3 = " ";
176             s4 = rt_opts[i+1];
177         } else {
178             s1 = " ";
179             s2 = finalphrase;
180             s3 = "";
181             s4 = "";
182         }
183         l = (int) strlen(rtbuf) + (int) strlen(s1) + (int) strlen(s2)
184             + (int) strlen(s3) + (int) strlen(s4) + 1;
185         if (l <= (COLNO - 5) && l < (BUFSZ - 1)) {
186             Strcat(rtbuf, s1);
187             Strcat(rtbuf, s2);
188             Strcat(rtbuf, s3);
189             Strcat(rtbuf, s4);
190         } else {
191             putstr(win, 0, rtbuf);
192             if (i >= SIZE(rt_opts))
193                 s1 = "";
194             l = (int) strlen(indent) + (int) strlen(s1) + (int) strlen(s2)
195                 + (int) strlen(s3) + (int) strlen(s4) + 1;
196             if (l <= (COLNO - 5) && l < (BUFSZ - 1)) {
197                 Strcpy(rtbuf, indent);
198                 Strcat(rtbuf, s1);
199                 Strcat(rtbuf, s2);
200                 Strcat(rtbuf, s3);
201                 Strcat(rtbuf, s4);
202             }
203         }
204     }
205
206     if (l)
207         putstr(win, 0, rtbuf);
208     *buf = '\0';
209 }
210
211 #ifdef MICRO
212 boolean
213 comp_times(filetime)
214 long filetime;
215 {
216     return (boolean) (filetime < BUILD_TIME);
217 }
218 #endif
219
220 boolean
221 check_version(version_data, filename, complain)
222 struct version_info *version_data;
223 const char *filename;
224 boolean complain;
225 {
226     if (
227 #ifdef VERSION_COMPATIBILITY
228         version_data->incarnation < VERSION_COMPATIBILITY
229         || version_data->incarnation > VERSION_NUMBER
230 #else
231         version_data->incarnation != VERSION_NUMBER
232 #endif
233         ) {
234         if (complain)
235             pline("Version mismatch for file \"%s\".", filename);
236         return FALSE;
237     } else if (
238 #ifndef IGNORED_FEATURES
239         version_data->feature_set != VERSION_FEATURES
240 #else
241         (version_data->feature_set & ~IGNORED_FEATURES)
242             != (VERSION_FEATURES & ~IGNORED_FEATURES)
243 #endif
244         || version_data->entity_count != VERSION_SANITY1
245         || version_data->struct_sizes1 != VERSION_SANITY2
246         || version_data->struct_sizes2 != VERSION_SANITY3) {
247         if (complain)
248             pline("Configuration incompatibility for file \"%s\".", filename);
249         return FALSE;
250     }
251     return TRUE;
252 }
253
254 /* this used to be based on file date and somewhat OS-dependant,
255    but now examines the initial part of the file's contents */
256 boolean
257 uptodate(fd, name)
258 int fd;
259 const char *name;
260 {
261     int rlen;
262     struct version_info vers_info;
263     boolean verbose = name ? TRUE : FALSE;
264
265     rlen = read(fd, (genericptr_t) &vers_info, sizeof vers_info);
266     minit(); /* ZEROCOMP */
267     if (rlen == 0) {
268         if (verbose) {
269             pline("File \"%s\" is empty?", name);
270             wait_synch();
271         }
272         return FALSE;
273     }
274     if (!check_version(&vers_info, name, verbose)) {
275         if (verbose)
276             wait_synch();
277         return FALSE;
278     }
279     return TRUE;
280 }
281
282 void
283 store_version(fd)
284 int fd;
285 {
286     static const struct version_info version_data = {
287         VERSION_NUMBER, VERSION_FEATURES,
288         VERSION_SANITY1, VERSION_SANITY2, VERSION_SANITY3
289     };
290
291     bufoff(fd);
292     /* bwrite() before bufon() uses plain write() */
293     bwrite(fd, (genericptr_t) &version_data,
294            (unsigned) (sizeof version_data));
295     bufon(fd);
296     return;
297 }
298
299 #ifdef AMIGA
300 const char amiga_version_string[] = AMIGA_VERSION_STRING;
301 #endif
302
303 unsigned long
304 get_feature_notice_ver(str)
305 char *str;
306 {
307     char buf[BUFSZ];
308     int ver_maj, ver_min, patch;
309     char *istr[3];
310     int j = 0;
311
312     if (!str)
313         return 0L;
314     str = strcpy(buf, str);
315     istr[j] = str;
316     while (*str) {
317         if (*str == '.') {
318             *str++ = '\0';
319             j++;
320             istr[j] = str;
321             if (j == 2)
322                 break;
323         } else if (index("0123456789", *str) != 0) {
324             str++;
325         } else
326             return 0L;
327     }
328     if (j != 2)
329         return 0L;
330     ver_maj = atoi(istr[0]);
331     ver_min = atoi(istr[1]);
332     patch = atoi(istr[2]);
333     return FEATURE_NOTICE_VER(ver_maj, ver_min, patch);
334     /* macro from hack.h */
335 }
336
337 unsigned long
338 get_current_feature_ver()
339 {
340     return FEATURE_NOTICE_VER(VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL);
341 }
342
343 /*ARGUSED*/
344 const char *
345 copyright_banner_line(indx)
346 int indx;
347 {
348 #ifdef COPYRIGHT_BANNER_A
349     if (indx == 1)
350         return COPYRIGHT_BANNER_A;
351 #endif
352 #ifdef COPYRIGHT_BANNER_B
353     if (indx == 2)
354         return COPYRIGHT_BANNER_B;
355 #endif
356 #ifdef COPYRIGHT_BANNER_C
357     if (indx == 3)
358         return COPYRIGHT_BANNER_C;
359 #endif
360 #ifdef COPYRIGHT_BANNER_D
361     if (indx == 4)
362         return COPYRIGHT_BANNER_D;
363 #endif
364     return "";
365 }
366
367 /*version.c*/