Source:NetHack 5.0.0/src/version.c
Jump to navigation
Jump to search
Below is the full text to version.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/version.c#line12]], for example.
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. /* NetHack 5.0 version.c $NHDT-Date: 1737622664 2025/01/23 00:57:44 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.105 $ */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /*-Copyright (c) Michael Allison, 2018. */ 4. /* NetHack may be freely redistributed. See license for details. */ 5. 6. 7. #include "hack.h" 8. #include "dlb.h" 9. 10. #ifndef MINIMAL_FOR_RECOVER 11. #ifndef SFCTOOL 12. 13. #ifndef OPTIONS_AT_RUNTIME 14. #define OPTIONS_AT_RUNTIME 15. #endif 16. 17. staticfn void insert_rtoption(char *) NONNULLARG1; 18. 19. /* fill buffer with short version (so caller can avoid including date.h) 20. * buf cannot be NULL */ 21. char * 22. version_string(char *buf, size_t bufsz) 23. { 24. Snprintf(buf, bufsz, "%s", 25. ((nomakedefs.version_string && nomakedefs.version_string[0]) 26. ? nomakedefs.version_string 27. /* in case we try to write a paniclog entry after releasing 28. the 'nomakedefs' data */ 29. : mdlib_version_string(buf, "."))); 30. return buf; 31. } 32. 33. /* fill and return the given buffer with the long nethack version string */ 34. char * 35. getversionstring(char *buf, size_t bufsz) 36. { 37. Strcpy(buf, nomakedefs.version_id); 38. 39. { 40. int c = 0; 41. #if defined(RUNTIME_PORT_ID) 42. char tmpbuf[BUFSZ], *tmp; 43. #endif 44. char *p = eos(buf); 45. boolean dotoff = (p > buf && p[-1] == '.'); 46. 47. if (dotoff) 48. --p; 49. Strcpy(p, " ("); 50. #if defined(RUNTIME_PORT_ID) 51. tmp = get_port_id(tmpbuf); 52. if (tmp) 53. Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, 54. "%s%s", c++ ? "," : "", tmp); 55. #endif 56. if (nomakedefs.git_sha) 57. Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, 58. "%s%s", c++ ? "," : "", nomakedefs.git_sha); 59. #if (NH_DEVEL_STATUS != NH_STATUS_RELEASED) 60. if (nomakedefs.git_branch) 61. Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, 62. "%sbranch:%s", 63. c++ ? "," : "", nomakedefs.git_branch); 64. #endif 65. if (nomakedefs.git_prefix) 66. Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, 67. "%sprefix:%s", 68. c++ ? "," : "", nomakedefs.git_prefix); 69. if (c) 70. Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, 71. "%s", ")"); 72. else /* if nothing has been added, strip " (" back off */ 73. *p = '\0'; 74. if (dotoff) 75. Snprintf(eos(buf), (bufsz - strlen(buf)) - 1, 76. "%s", "."); 77. } 78. return buf; 79. } 80. 81. /* version info that could be displayed on status lines; 82. "<game name> <git branch name> <x.y.z version number>"; 83. if game name is a prefix of--or same as--branch name, it is omitted 84. "<git branch name> <x.y.z version number>"; 85. after release--or if branch info is unavailable--it will be 86. "<game name> <x.y.z version number>"; 87. game name or branch name or both can be requested via flags */ 88. char * 89. status_version(char *buf, size_t bufsz, boolean indent) 90. { 91. const char *name = NULL, *altname = NULL, *indentation; 92. unsigned vflags = flags.versinfo; 93. boolean shownum = ((vflags & VI_NUMBER) != 0), 94. showname = ((vflags & VI_NAME) != 0), 95. showbranch = ((vflags & VI_BRANCH) != 0); 96. 97. /* game's name {variants should use own name, not "NetHack"} */ 98. if (showname) { 99. #ifdef VERS_GAME_NAME /* can be set to override default (base of filename) */ 100. name = VERS_GAME_NAME; 101. #else 102. name = nh_basename(gh.hname, FALSE); /* hname is from xxxmain.c */ 103. #endif 104. if (!name || !*name) /* shouldn't happen */ 105. showname = FALSE; 106. } 107. /* git branch name, if available */ 108. if (showbranch) { 109. #if 1 /*#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)*/ 110. altname = nomakedefs.git_branch; 111. #endif 112. if (!altname || !*altname) 113. showbranch = FALSE; 114. } 115. if (showname && showbranch) { 116. if (!strncmpi(name, altname, strlen(name))) 117. showname = FALSE; 118. #if 0 119. /* note: it's possible for branch name to be a prefix of game name 120. but that's unlikely enough that we won't bother with it; having 121. branch "nethack-5.0" be a superset of game "nethack" seems like 122. including both is redundant, but having branch "net" be a subset 123. of game "nethack" doesn't feel that way; optimizing "net" out 124. seems like it would be a mistake */ 125. else if (!strncmpi(altname, name, strlen(altname))) 126. showbranch = FALSE; 127. #endif 128. } else if (!showname && !showbranch) { 129. /* flags.versinfo could be set to only 'branch' but it might not 130. be available */ 131. shownum = TRUE; 132. } 133. 134. *buf = '\0'; 135. indentation = indent ? " " : ""; 136. if (showname) { 137. Snprintf(eos(buf), bufsz - strlen(buf), "%s%s", indentation, name); 138. indentation = " "; /* forced separator rather than optional indent */ 139. } 140. if (showbranch) { 141. Snprintf(eos(buf), bufsz - strlen(buf), "%s%s", indentation, altname); 142. indentation = " "; 143. } 144. if (shownum) { 145. /* x.y.z version number */ 146. Snprintf(eos(buf), bufsz - strlen(buf), "%s%s", indentation, 147. (nomakedefs.version_string && nomakedefs.version_string[0]) 148. ? nomakedefs.version_string 149. : mdlib_version_string(buf, ".")); 150. } 151. return buf; 152. } 153. 154. /* the #versionshort command */ 155. int 156. doversion(void) 157. { 158. char buf[BUFSZ]; 159. 160. if (iflags.menu_requested) 161. return doextversion(); 162. 163. pline("%s", getversionstring(buf, sizeof buf)); 164. return ECMD_OK; 165. } 166. 167. /* the '#version' command; also a choice for '?' */ 168. int 169. doextversion(void) 170. { 171. int rtcontext = 0; 172. const char *rtbuf; 173. dlb *f = (dlb *) 0; 174. char buf[BUFSZ], *p = 0; 175. winid win = create_nhwindow(NHW_TEXT); 176. boolean use_dlb = TRUE, 177. done_rt = FALSE, 178. done_dlb = FALSE, 179. prolog; 180. /* lua_info[] moved to util/mdlib.c and rendered via do_runtime_info() */ 181. 182. #if defined(OPTIONS_AT_RUNTIME) 183. use_dlb = FALSE; 184. #else 185. done_rt = TRUE; 186. #endif 187. 188. /* instead of using ``display_file(OPTIONS_USED,TRUE) we handle 189. the file manually so we can include dynamic version info */ 190. 191. (void) getversionstring(buf, sizeof buf); 192. /* if extra text (git info) is present, put it on separate line 193. but don't wrap on (x86) */ 194. if (strlen(buf) >= COLNO) 195. p = strrchr(buf, '('); 196. if (p && p > buf && p[-1] == ' ' && p[1] != 'x') 197. p[-1] = '\0'; 198. else 199. p = 0; 200. putstr(win, 0, buf); 201. if (p) { 202. *--p = ' '; 203. putstr(win, 0, p); 204. } 205. 206. if (use_dlb) { 207. f = dlb_fopen(OPTIONS_USED, "r"); 208. if (!f) { 209. putstr(win, 0, ""); 210. Sprintf(buf, "[Configuration '%s' not available?]", OPTIONS_USED); 211. putstr(win, 0, buf); 212. done_dlb = TRUE; 213. } 214. } 215. /* 216. * already inserted above: 217. * + outdented program name and version plus build date and time 218. * dat/options; display contents with lines prefixed by '-' deleted: 219. * - blank-line 220. * - indented program name and version 221. * blank-line 222. * outdented feature header 223. * - blank-line 224. * indented feature list 225. * spread over multiple lines 226. * blank-line 227. * outdented windowing header 228. * - blank-line 229. * indented windowing choices with 230. * optional second line for default 231. * - blank-line 232. * - EOF 233. */ 234. 235. prolog = TRUE; /* to skip indented program name */ 236. for (;;) { 237. if (use_dlb && !done_dlb) { 238. if (!dlb_fgets(buf, BUFSZ, f)) { 239. done_dlb = TRUE; 240. continue; 241. } 242. } else if (!done_rt) { 243. if (!(rtbuf = do_runtime_info(&rtcontext))) { 244. done_rt = TRUE; 245. continue; 246. } 247. (void) strncpy(buf, rtbuf, BUFSZ - 1); 248. buf[BUFSZ - 1] = '\0'; 249. } else { 250. break; 251. } 252. (void) strip_newline(buf); 253. if (strchr(buf, '\t') != 0) 254. (void) tabexpand(buf); 255. 256. if (*buf && *buf != ' ') { 257. /* found outdented header; insert a separator since we'll 258. have skipped corresponding blank line inside the file */ 259. putstr(win, 0, ""); 260. prolog = FALSE; 261. } 262. /* skip blank lines and prolog (progame name plus version) */ 263. if (prolog || !*buf) 264. continue; 265. 266. if (strchr(buf, ':')) 267. insert_rtoption(buf); 268. 269. if (*buf) 270. putstr(win, 0, buf); 271. } 272. if (use_dlb) 273. (void) dlb_fclose(f); 274. display_nhwindow(win, FALSE); 275. destroy_nhwindow(win); 276. return ECMD_OK; 277. } 278. 279. void 280. early_version_info(boolean pastebuf) 281. { 282. char buf1[BUFSZ], buf2[BUFSZ]; 283. char *buf, *tmp; 284. 285. Snprintf(buf1, sizeof buf1, "test"); 286. /* this is early enough that we have to do our own line-splitting */ 287. getversionstring(buf1, sizeof buf1); 288. tmp = strstri(buf1, " ("); /* split at start of version info */ 289. if (tmp) { 290. /* retain one buffer so that it all goes into the paste buffer */ 291. *tmp++ = '\0'; 292. Snprintf(buf2, sizeof (buf2),"%s\n%s", buf1, tmp); 293. buf = buf2; 294. } else { 295. buf = buf1; 296. } 297. 298. raw_printf("%s", buf); 299. 300. if (pastebuf) { 301. #if defined(RUNTIME_PASTEBUF_SUPPORT) && !defined(LIBNH) 302. /* 303. * Call a platform/port-specific routine to insert the 304. * version information into a paste buffer. Useful for 305. * easy inclusion in bug reports. 306. */ 307. port_insert_pastebuf(buf); 308. #else 309. raw_printf("%s", "Paste buffer copy is not available.\n"); 310. #endif 311. } 312. } 313. 314. extern const char regex_id[]; 315. 316. /* 317. * makedefs should put the first token into dat/options; we'll substitute 318. * the second value for it. The token must contain at least one colon 319. * so that we can spot it, and should not contain spaces so that makedefs 320. * won't split it across lines. Ideally the length should be close to 321. * that of the substituted value since we don't do phrase-splitting/line- 322. * wrapping when displaying it. 323. */ 324. static struct rt_opt { 325. const char *token, *value; 326. } rt_opts[] = { 327. { ":PATMATCH:", regex_id }, 328. { ":LUAVERSION:", (const char *) gl.lua_ver }, 329. { ":LUACOPYRIGHT:", (const char *) gl.lua_copyright }, 330. }; 331. 332. /* 333. * 3.6.0 334. * Some optional stuff is no longer available to makedefs because 335. * it depends which of several object files got linked into the 336. * game image, so we insert those options here. 337. */ 338. staticfn void 339. insert_rtoption(char *buf) 340. { 341. int i; 342. 343. if (!gl.lua_ver[0]) 344. get_lua_version(); 345. 346. for (i = 0; i < SIZE(rt_opts); ++i) { 347. if (strstri(buf, rt_opts[i].token) && *rt_opts[i].value) { 348. (void) strsubst(buf, rt_opts[i].token, rt_opts[i].value); 349. } 350. /* we don't break out of the loop after a match; there might be 351. other matches on the same line */ 352. } 353. } 354. 355. #ifdef MICRO 356. boolean 357. comp_times(long filetime) 358. { 359. /* BUILD_TIME is constant but might have L suffix rather than UL; 360. 'filetime' is historically signed but ought to have been unsigned */ 361. return ((unsigned long) filetime < (unsigned long) nomakedefs.build_time); 362. } 363. #endif 364. #endif /* !SFCTOOL */ 365. 366. #ifdef SFCTOOL 367. #ifdef wait_synch 368. #undef wait_synch 369. #endif 370. #define wait_synch() 371. #endif /* SFCTOOL */ 372. 373. boolean 374. check_version( 375. struct version_info *version_data, 376. const char *filename, 377. boolean complain, 378. unsigned long utdflags) 379. { 380. if (!filename) { 381. #ifdef EXTRA_SANITY_CHECKS 382. if (complain) 383. impossible("check_version() called with" 384. " 'complain'=True but 'filename'=Null"); 385. #endif 386. complain = FALSE; /* 'complain' requires 'filename' for pline("%s") */ 387. } 388. if ((version_data->feature_set & SFCTOOL_BIT) != 0) { 389. gc.converted_savefile_loaded = TRUE; 390. version_data->feature_set &= ~(SFCTOOL_BIT); 391. } 392. if ( 393. #ifdef VERSION_COMPATIBILITY /* patchlevel.h */ 394. version_data->incarnation < VERSION_COMPATIBILITY 395. || version_data->incarnation > nomakedefs.version_number 396. #else 397. version_data->incarnation != nomakedefs.version_number 398. #endif 399. ) { 400. #ifndef SFCTOOL 401. if (complain) { 402. pline("Version mismatch for file \"%s\".", filename); 403. if (WIN_MESSAGE != WIN_ERR) 404. display_nhwindow(WIN_MESSAGE, TRUE); 405. } 406. #endif 407. return FALSE; 408. } else if ( 409. (version_data->feature_set & ~nomakedefs.ignored_features) 410. != (nomakedefs.version_features & ~nomakedefs.ignored_features) 411. || ((utdflags & UTD_SKIP_SANITY1) == 0 412. && version_data->entity_count != nomakedefs.version_sanity1) 413. ) { 414. #ifndef SFCTOOL 415. if (complain) { 416. pline("Configuration incompatibility for file \"%s\".", filename); 417. display_nhwindow(WIN_MESSAGE, TRUE); 418. } 419. #endif 420. return FALSE; 421. } 422. return TRUE; 423. } 424. 425. #ifndef SFCTOOL 426. #ifdef AMIGA 427. const char amiga_version_string[] = AMIGA_VERSION_STRING; 428. #endif 429. 430. unsigned long 431. get_feature_notice_ver(char *str) 432. { 433. char buf[BUFSZ]; 434. int ver_maj, ver_min, patch; 435. char *istr[3]; 436. int j = 0; 437. 438. if (!str) 439. return 0L; 440. str = strcpy(buf, str); 441. istr[j] = str; 442. while (*str) { 443. if (*str == '.') { 444. *str++ = '\0'; 445. j++; 446. istr[j] = str; 447. if (j == 2) 448. break; 449. } else if (strchr("0123456789", *str) != 0) { 450. str++; 451. } else 452. return 0L; 453. } 454. if (j != 2) 455. return 0L; 456. ver_maj = atoi(istr[0]); 457. ver_min = atoi(istr[1]); 458. patch = atoi(istr[2]); 459. return FEATURE_NOTICE_VER(ver_maj, ver_min, patch); 460. /* macro from hack.h */ 461. } 462. 463. unsigned long 464. get_current_feature_ver(void) 465. { 466. return FEATURE_NOTICE_VER(VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL); 467. } 468. 469. /*ARGUSED*/ 470. const char * 471. copyright_banner_line(int indx) 472. { 473. #ifdef COPYRIGHT_BANNER_A 474. if (indx == 1) 475. return COPYRIGHT_BANNER_A; 476. #endif 477. #ifdef COPYRIGHT_BANNER_B 478. if (indx == 2) 479. return COPYRIGHT_BANNER_B; 480. #endif 481. 482. if (indx == 3) 483. return nomakedefs.copyright_banner_c; 484. 485. #ifdef COPYRIGHT_BANNER_D 486. if (indx == 4) 487. return COPYRIGHT_BANNER_D; 488. #endif 489. return ""; 490. } 491. 492. /* called by argcheck(allmain.c) from early_options(sys/xxx/xxxmain.c) */ 493. void 494. dump_version_info(void) 495. { 496. char buf[BUFSZ]; 497. const char *hname = gh.hname ? gh.hname : "nethack"; 498. 499. if (strlen(hname) > 33) 500. hname = eos(nhStr(hname)) - 33; /* discard const for eos() */ 501. runtime_info_init(); 502. Snprintf(buf, sizeof buf, "%-12.33s %08lx %08lx %08lx", 503. hname, 504. nomakedefs.version_number, 505. (nomakedefs.version_features & ~nomakedefs.ignored_features), 506. nomakedefs.version_sanity1); 507. raw_print(buf); 508. release_runtime_info(); 509. return; 510. } 511. void 512. store_version(NHFILE *nhfp) 513. { 514. struct version_info version_data = { 515. 0UL, 516. 0UL, 517. 0UL, 518. }; 519. /* actual version number */ 520. version_data.incarnation = nomakedefs.version_number; 521. /* bitmask of config settings */ 522. version_data.feature_set = nomakedefs.version_features; 523. /* # of monsters and objects */ 524. version_data.entity_count = nomakedefs.version_sanity1; 525. 526. /* bwrite() before bufon() uses plain write() */ 527. if (nhfp->structlevel) 528. bufoff(nhfp->fd); 529. 530. store_critical_bytes(nhfp); 531. Sfo_version_info(nhfp, (struct version_info *) &version_data, 532. "version_info"); 533. 534. if (nhfp->structlevel) 535. bufon(nhfp->fd); 536. return; 537. } 538. #endif /* !SFCTOOL */ 539. #endif /* MINIMAL_FOR_RECOVER */ 540. 541. struct critical_sizes_with_names { 542. uchar ucsize; 543. const char *nm; 544. }; 545. 546. struct critical_sizes_with_names critical_sizes[] = { 547. { 0, "unused" }, 548. /* simple types, that don't have subfields */ 549. { (uchar) sizeof(short), "short" }, 550. { (uchar) sizeof(int), "int" }, 551. { (uchar) sizeof(long), "long" }, 552. { (uchar) sizeof(long long), "long long" }, 553. { (uchar) sizeof(genericptr_t), "genericptr_t" }, 554. { (uchar) sizeof(aligntyp), "aligntyp" }, 555. { (uchar) sizeof(boolean), "boolean" }, 556. { (uchar) sizeof(coordxy), "coordxy" }, 557. { (uchar) sizeof(int16), "int16" }, 558. { (uchar) sizeof(int32), "int32" }, 559. { (uchar) sizeof(int64), "int64" }, 560. { (uchar) sizeof(schar), "schar" }, 561. { (uchar) sizeof(size_t), "size_t" }, 562. { (uchar) sizeof(uchar), "uchar" }, 563. { (uchar) sizeof(uint16), "uint16" }, 564. { (uchar) sizeof(uint32), "uint32" }, 565. { (uchar) sizeof(uint64), "uint64" }, 566. { (uchar) sizeof(ulong), "ulong" }, 567. { (uchar) sizeof(unsigned), "unsigned" }, 568. { (uchar) sizeof(ushort), "ushort" }, 569. { (uchar) sizeof(xint16), "xint16" }, 570. { (uchar) sizeof(xint8), "xint8" }, 571. /* complex - they break down into one or more simple types */ 572. { (uchar) sizeof(struct arti_info), "struct arti_info" }, 573. { (uchar) sizeof(struct nhrect), "struct nhrect" }, 574. { (uchar) sizeof(struct branch), "struct branch" }, 575. { (uchar) sizeof(struct bubble), "struct bubble" }, 576. { (uchar) sizeof(struct cemetery), "struct cemetery" }, 577. { (uchar) sizeof(struct context_info), "struct context_info" }, 578. { (uchar) sizeof(struct nhcoord), "struct nhcoord" }, 579. { (uchar) sizeof(struct damage), "struct damage" }, 580. { (uchar) sizeof(struct dest_area), "struct dest_area" }, 581. { (uchar) sizeof(struct dgn_topology), "struct dgn_topology" }, 582. { (uchar) sizeof(struct dungeon), "struct dungeon" }, 583. { (uchar) sizeof(struct d_level), "struct d_level" }, 584. { (uchar) sizeof(struct ebones), "struct ebones" }, 585. { (uchar) sizeof(struct edog), "struct edog" }, 586. { (uchar) sizeof(struct egd), "struct egd" }, 587. { (uchar) sizeof(struct emin), "struct emin" }, 588. { (uchar) sizeof(struct engr), "struct engr" }, 589. { (uchar) sizeof(struct epri), "struct epri" }, 590. { (uchar) sizeof(struct eshk), "struct eshk" }, 591. { (uchar) sizeof(struct fe), "struct fe" }, 592. { (uchar) sizeof(struct flag), "struct flag" }, 593. { (uchar) sizeof(struct fruit), "struct fruit" }, 594. { (uchar) sizeof(struct gamelog_line), "struct gamelog_line" }, 595. { (uchar) sizeof(struct kinfo), "struct kinfo" }, 596. { (uchar) sizeof(struct levelflags), "struct levelflags" }, 597. { (uchar) sizeof(struct ls_t), "struct ls_t" }, 598. { (uchar) sizeof(struct linfo), "struct linfo" }, 599. { (uchar) sizeof(struct mapseen_feat), "struct mapseen_feat" }, 600. { (uchar) sizeof(struct mapseen_flags), "struct mapseen_flags" }, 601. { (uchar) sizeof(struct mapseen_rooms), "struct mapseen_rooms" }, 602. { (uchar) sizeof(struct mextra), "struct mextra" }, 603. { (uchar) sizeof(struct mkroom), "struct mkroom" }, 604. { (uchar) sizeof(struct monst), "struct monst" }, 605. { (uchar) sizeof(struct mvitals), "struct mvitals" }, 606. { (uchar) sizeof(struct obj), "struct obj" }, 607. { (uchar) sizeof(struct objclass), "struct objclass" }, 608. { (uchar) sizeof(struct oextra), "struct oextra" }, 609. { (uchar) sizeof(struct q_score), "struct q_score" }, 610. { (uchar) sizeof(struct rm), "struct rm" }, 611. { (uchar) sizeof(struct spell), "struct spell" }, 612. { (uchar) sizeof(struct stairway), "struct stairway" }, 613. { (uchar) sizeof(struct s_level), "struct s_level" }, 614. { (uchar) sizeof(struct trap), "struct trap" }, 615. { (uchar) sizeof(struct version_info), "struct version_info" }, 616. { (uchar) sizeof(anything), "anything" }, 617. /* struct you requires 2 bytes */ 618. { (uchar) ((sizeof(struct you) & 0x00FF)), "you_LO" }, 619. { (uchar) ((sizeof(struct you) & 0xFF00) >> 8), "you_HI" }, 620. #ifdef SF_INCLUDE_SUBSTRUCTS 621. /* 622. * the ones below are substructures of the ones 623. * above, so there is no need to check these directly. 624. */ 625. { (uchar) sizeof(struct attribs), "struct attribs" }, 626. { (uchar) sizeof(struct dig_info), "struct dig_info" }, 627. { (uchar) sizeof(struct tin_info), "struct tin_info" }, 628. { (uchar) sizeof(struct book_info), "struct book_info" }, 629. { (uchar) sizeof(struct takeoff_info), "struct takeoff_info" }, 630. { (uchar) sizeof(struct victual_info), "struct victual_info" }, 631. { (uchar) sizeof(struct engrave_info), "struct engrave_info" }, 632. { (uchar) sizeof(struct warntype_info), "struct warntype_info" }, 633. { (uchar) sizeof(struct polearm_info), "struct polearm_info" }, 634. { (uchar) sizeof(struct obj_split), "struct obj_split" }, 635. { (uchar) sizeof(struct tribute_info), "struct tribute_info" }, 636. { (uchar) sizeof(struct novel_tracking), "struct novel_tracking" }, 637. { (uchar) sizeof(struct achievement_tracking), 638. "struct achievement_tracking" }, 639. { (uchar) sizeof(struct d_flags), "struct d_flags" }, 640. { (uchar) sizeof(struct mapseen), "struct mapseen" }, 641. { (uchar) sizeof(struct fakecorridor), "struct fakecorridor" }, 642. { (uchar) sizeof(struct bill_x), "struct bill_x" }, 643. { (uchar) sizeof(union vptrs), "union vptrs" }, 644. { (uchar) sizeof(struct prop), "struct prop" }, 645. { (uchar) sizeof(struct skills), "struct skills" }, 646. { (uchar) sizeof(union vlaunchinfo), "union vlaunchinfo" }, 647. { (uchar) sizeof(struct u_have), "struct u_have" }, 648. { (uchar) sizeof(struct u_event), "struct u_event" }, 649. { (uchar) sizeof(struct u_realtime), "struct u_realtime" }, 650. { (uchar) sizeof(struct u_conduct), "struct u_conduct" }, 651. { (uchar) sizeof(struct u_roleplay), "struct u_roleplay" }, 652. #endif /* SF_INCLUDE_SUBSTRUCTS */ 653. /* 10 for future expansion without changing array size */ 654. { 0, "" }, 655. { 0, "" }, 656. { 0, "" }, 657. { 0, "" }, 658. { 0, "" }, 659. { 0, "" }, 660. { 0, "" }, 661. { 0, "" }, 662. { 0, "" }, 663. { 0, "" }, 664. }; 665. 666. uchar cscbuf[SIZE(critical_sizes)]; 667. 668. int 669. get_critical_size_count(void) 670. { 671. return SIZE(critical_sizes); 672. } 673. 674. #ifndef MINIMAL_FOR_RECOVER 675. void 676. store_critical_bytes(NHFILE *nhfp) 677. { 678. int i, cnt; 679. char indicate = 'u', csc_count = (char) SIZE(critical_sizes); 680. /* int cmc = 0; */ 681. 682. if (nhfp->mode & WRITING) { 683. indicate = (nhfp->structlevel) ? 'h' 684. : (nhfp->fnidx == exportascii) 685. ? 'a' 686. : '?'; 687. Sfo_char(nhfp, &indicate, "indicate-format", 1); 688. Sfo_char(nhfp, &csc_count, "count-critical_sizes", 1); 689. cnt = (int) csc_count; 690. for (i = 0; i < cnt; ++i) { 691. Sfo_uchar(nhfp, &critical_sizes[i].ucsize, "critical_sizes"); 692. } 693. } 694. } 695. 696. /* this used to be based on file date and somewhat OS-dependent, 697. * but now examines the initial part of the file's contents. 698. * 699. * returns: 700. * 701. * SF_UPTODATE (0) everything matched and looks good 702. * SF_OUTDATED (1) savefile is outdated 703. * SF_CRITICAL_BYTE_COUNT_MISMATCH (2) critical size count mismatch 704. * SF_DM_IL32LLP64_ON_ILP32LL64 (3) Windows x64 savefile on x86 705. * SF_DM_I32LP64_ON_ILP32LL64 (4) Unix 64 savefile on x86 706. * SF_DM_ILP32LL64_ON_I32LP64 (5) x86 savefile on Unix 64 707. * SF_DM_ILP32LL64_ON_IL32LLP64 (6) x86 savefile on Windows x64 708. * SF_DM_I32LP64_ON_IL32LLP64 (7) Unix 64 savefile on Windows x64 709. * SF_DM_IL32LLP64_ON_I32LP64 (8) Windows x64 savefile on Unix 64 710. * SF_DM_MISMATCH (9) some other mismatch 711. */ 712. int 713. uptodate(NHFILE *nhfp, const char *name, unsigned long utdflags) 714. { 715. #ifdef SFCTOOL 716. extern struct version_info vers_info; 717. #else 718. struct version_info vers_info; 719. #endif 720. char indicator; 721. int sfstatus = 0, idx_1st_mismatch = 0; 722. boolean quietly = (utdflags & UTD_QUIETLY) != 0; 723. boolean verbose = name ? TRUE : FALSE; 724. 725. Sfi_char(nhfp, &indicator, "indicate-format", 1); 726. if ((sfstatus = compare_critical_bytes(nhfp, &idx_1st_mismatch, utdflags)) 727. != SF_UPTODATE) { 728. if (sfstatus > 0 && idx_1st_mismatch) { 729. if (!quietly) 730. raw_printf("comparison of critical bytes mismatched at %d (%s).", 731. critical_sizes[idx_1st_mismatch].ucsize, 732. critical_sizes[idx_1st_mismatch].nm); 733. } 734. } 735. 736. Sfi_version_info(nhfp, &vers_info, "version_info"); 737. if (!check_version(&vers_info, name, verbose, utdflags)) { 738. if (verbose) { 739. if ((utdflags & UTD_WITHOUT_WAITSYNCH_PERFILE) == 0) { 740. wait_synch(); 741. } 742. } 743. return SF_OUTDATED; 744. } 745. return sfstatus; 746. } 747. 748. /* 749. * returns: 750. * 751. * SF_UPTODATE (0) everything matched and looks good 752. * SF_OUTDATED (1) savefile is outdated 753. * SF_CRITICAL_BYTE_COUNT_MISMATCH (2) critical size count mismatch 754. * SF_DM_IL32LLP64_ON_ILP32LL64 (3) Windows x64 savefile on x86 755. * SF_DM_I32LP64_ON_ILP32LL64 (4) Unix 64 savefile on x86 756. * SF_DM_ILP32LL64_ON_I32LP64 (5) x86 savefile on Unix 64 757. * SF_DM_ILP32LL64_ON_IL32LLP64 (6) x86 savefile on Windows x64 758. * SF_DM_I32LP64_ON_IL32LLP64 (7) Unix 64 savefile on Windows x64 759. * SF_DM_IL32LLP64_ON_I32LP64 (8) Windows x64 savefile on Unix 64 760. * SF_DM_MISMATCH (9) some other mismatch 761. */ 762. int 763. compare_critical_bytes(NHFILE *nhfp, int *idx_1st_mismatch, unsigned long utdflags) 764. { 765. char active_csc_count = (char) SIZE(critical_sizes), 766. file_csc_count; 767. int i, cnt = (int) active_csc_count, 768. dmmismatch = SF_DM_MISMATCH; 769. boolean quietly = (utdflags & UTD_QUIETLY) != 0; 770. 771. Sfi_char(nhfp, &file_csc_count, "count-critical_sizes", 1); 772. if (file_csc_count > cnt) { 773. if (!quietly) 774. raw_printf("critical byte counts do not match" 775. ", file:%d, critical_sizes:%d.", 776. file_csc_count, SIZE(critical_sizes)); 777. return SF_CRITICAL_BYTE_COUNT_MISMATCH; 778. } 779. for (i = 0; i < (int) file_csc_count; ++i) { 780. Sfi_uchar(nhfp, &cscbuf[i], "critical_sizes"); 781. } 782. for (i = 1; i < cnt; ++i) { 783. if (cscbuf[i] != critical_sizes[i].ucsize) { 784. const char *dm = datamodel(0), *dmfile; 785. 786. dmfile = what_datamodel_is_this(0, 787. cscbuf[1], /* short */ 788. cscbuf[2], /* int */ 789. cscbuf[3], /* long */ 790. cscbuf[4], /* long long */ 791. cscbuf[5]); /* ptr */ 792. 793. if (!strcmp(dmfile, "IL32LLP64") && !strcmp(dm, "ILP32LL64")) { 794. /* Windows x64 savefile on x86 */ 795. dmmismatch = SF_DM_IL32LLP64_ON_ILP32LL64; 796. } else if (!strcmp(dmfile, "I32LP64") 797. && !strcmp(dm, "ILP32LL64")) { 798. /* Unix 64 savefile on x86*/ 799. dmmismatch = SF_DM_I32LP64_ON_ILP32LL64; 800. } else if (!strcmp(dmfile, "ILP32LL64") 801. && !strcmp(dm, "I32LP64")) { 802. /* x86 savefile on Unix 64 */ 803. dmmismatch = SF_DM_ILP32LL64_ON_I32LP64; 804. } else if (!strcmp(dmfile, "ILP32LL64") 805. && !strcmp(dm, "IL32LLP64")) { 806. /* x86 savefile on Windows x64 */ 807. dmmismatch = SF_DM_ILP32LL64_ON_IL32LLP64; 808. } else if (!strcmp(dmfile, "I32LP64") 809. && !strcmp(dm, "IL32LLP64")) { 810. /* Unix 64 savefile on Windows x64 */ 811. dmmismatch = SF_DM_I32LP64_ON_IL32LLP64; 812. } else if (!strcmp(dmfile, "IL32LLP64") 813. && !strcmp(dm, "I32LP64")) { 814. /* Windows x64 savefile on Unix 64 */ 815. dmmismatch = SF_DM_IL32LLP64_ON_I32LP64; 816. } 817. if (idx_1st_mismatch) 818. *idx_1st_mismatch = i; 819. return dmmismatch; 820. } 821. } 822. return SF_UPTODATE; /* everything matched */ 823. } 824. 825. /* 826. * returns: 827. * 828. * SF_UPTODATE (0) everything matched and looks good 829. * SF_OUTDATED (1) savefile is outdated 830. * SF_CRITICAL_BYTE_COUNT_MISMATCH (2) critical size count mismatch 831. * SF_DM_IL32LLP64_ON_ILP32LL64 (3) Windows x64 savefile on x86 832. * SF_DM_I32LP64_ON_ILP32LL64 (4) Unix 64 savefile on x86 833. * SF_DM_ILP32LL64_ON_I32LP64 (5) x86 savefile on Unix 64 834. * SF_DM_ILP32LL64_ON_IL32LLP64 (6) x86 savefile on Windows x64 835. * SF_DM_I32LP64_ON_IL32LLP64 (7) Unix 64 savefile on Windows x64 836. * SF_DM_IL32LLP64_ON_I32LP64 (8) Windows x64 savefile on Unix 64 837. * SF_DM_MISMATCH (9) some other mismatch 838. */ 839. int 840. validate(NHFILE *nhfp, const char *name, boolean without_waitsynch_perfile) 841. { 842. unsigned long utdflags = 0L; 843. int validsf = 0; 844. 845. #ifdef SFCTOOL 846. utdflags |= UTD_QUIETLY; 847. #endif 848. if (nhfp->structlevel) 849. utdflags |= UTD_CHECKSIZES; 850. if (without_waitsynch_perfile) 851. utdflags |= UTD_WITHOUT_WAITSYNCH_PERFILE; 852. if (nhfp->fieldlevel) 853. utdflags |= UTD_CHECKFIELDCOUNTS | UTD_SKIP_SANITY1; 854. validsf = uptodate(nhfp, name, utdflags); 855. return validsf; 856. } 857. #endif /* MINIMAL_FOR_RECOVER */ 858. 859. /*version.c*/