Source:NetHack 5.0.0/src/sfbase.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to sfbase.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/src/sfbase.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	sfbase.c.template $NHDT-Date$  $NHDT-Branch$:$NHDT-Revision$ */
2. /* Copyright (c) Michael Allison, 2025. */
3. /* NetHack may be freely redistributed.  See license for details. */
4. 
5. #include "hack.h"
6. #include "sfprocs.h"
7. 
8. #ifdef SFCTOOL
9. //#include "sfproto.h"
10. #endif
11. 
12. /* #define DO_DEBUG */
13. 
14. //#define TURN_OFF_LOGGING 0x20
15. #define TURN_OFF_LOGGING (UNCONVERTING << 1)
16. 
17. struct sf_structlevel_procs sfoprocs[NUM_SAVEFORMATS], sfiprocs[NUM_SAVEFORMATS],
18.                 zerosfoprocs = {0}, zerosfiprocs = {0};
19. struct sf_fieldlevel_procs sfoflprocs[NUM_SAVEFORMATS], sfiflprocs[NUM_SAVEFORMATS],
20.                 zerosfoflprocs = {0}, zerosfiflprocs = {0};
21. 
22. char *sfvalue_aligntyp(aligntyp *a);
23. char *sfvalue_any(anything *a);
24. char *sfvalue_genericptr(genericptr a);
25. char *sfvalue_int16(int16 *a);
26. char *sfvalue_int32(int32 *a);
27. char *sfvalue_int64(int64 *a);
28. char *sfvalue_uchar(uchar *a);
29. char *sfvalue_uint16(uint16 *a);
30. char *sfvalue_uint32(uint32 *a);
31. char *sfvalue_uint64(uint64 *a);
32. char *sfvalue_size_t(size_t *a);
33. char *sfvalue_time_t(time_t *a);
34. char *sfvalue_short(short *a);
35. char *sfvalue_ushort(ushort *a);
36. char *sfvalue_int(int *a);
37. char *sfvalue_unsigned(unsigned *a);
38. char *sfvalue_long(long *a);
39. char *sfvalue_ulong(ulong *a);
40. char *sfvalue_xint8(xint8 *a);
41. char *sfvalue_xint16(xint16 *a);
42. char *sfvalue_char(char *a, int n);
43. char *sfvalue_boolean(boolean *a);
44. char *sfvalue_schar(schar *a);
45. char *sfvalue_bitfield(uint8 *a);
46. char *complex_dump(uchar *a);
47. char *bitfield_dump(uint8 *a);
48. 
49. void sf_log(NHFILE *, const char *, size_t, int, char *);
50. 
51. #if NH_C < 202300L
52. #define Sfvalue_aligntyp(a) sfvalue_aligntyp(a)
53. #define Sfvalue_any(a) sfvalue_any(a)
54. #define Sfvalue_genericptr(a) sfvalue_genericptr(a)
55. #define Sfvalue_coordxy(a) sfvalue_int16(a)
56. #define Sfvalue_int16(a) sfvalue_int16(a)
57. #define Sfvalue_int32(a) sfvalue_int32(a)
58. #define Sfvalue_int64(a) sfvalue_int64(a)
59. #define Sfvalue_uchar(a) sfvalue_uchar(a)
60. #define Sfvalue_uint16(a) sfvalue_uint16(a)
61. #define Sfvalue_uint32(a) sfvalue_uint32(a)
62. #define Sfvalue_uint64(a) sfvalue_uint64(a)
63. #define Sfvalue_size_t(a) sfvalue_size_t(a)
64. #define Sfvalue_time_t(a) sfvalue_time_t(a)
65. #define Sfvalue_short(a) sfvalue_short(a)
66. #define Sfvalue_ushort(a) sfvalue_ushort(a)
67. #define Sfvalue_int(a) sfvalue_int(a)
68. #define Sfvalue_unsigned(a) sfvalue_unsigned(a)
69. #define Sfvalue_xint8(a) sfvalue_xint8(a)
70. #define Sfvalue_xint16(a) sfvalue_xint16(a)
71. 
72. #else
73. 
74. #define sfvalue(x)                          \
75.     _Generic( (x),                          \
76.         anything *: sfvalue_any,            \
77.         genericptr_t *: sfvalue_genericptr, \
78.         int16_t *: sfvalue_int16,           \
79.         int32_t *: sfvalue_int32,           \
80.         int64_t *: sfvalue_int64,           \
81.         uchar *: sfvalue_uchar,             \
82.         uint16_t *: sfvalue_uint16,         \
83.         uint32_t *: sfvalue_uint32,         \
84.         uint64_t *: sfvalue_uint64,         \
85.         xint8 *: sfvalue_xint8              \
86.     )(x)
87. 
88. #define Sfvalue_any(a) sfvalue(a)
89. #define Sfvalue_aligntyp(a) sfvalue(a)
90. #define Sfvalue_genericptr(a) sfvalue(a)
91. #define Sfvalue_coordxy(a) sfvalue(a)
92. #define Sfvalue_int16(a) sfvalue(a)
93. #define Sfvalue_int32(a) sfvalue(a)
94. #define Sfvalue_int64(a) sfvalue(a)
95. #define Sfvalue_uchar(a) sfvalue(a)
96. #define Sfvalue_unsigned(a) sfvalue(a)
97. #define Sfvalue_uchar(a) sfvalue(a)
98. #define Sfvalue_uint16(a) sfvalue(a)
99. #define Sfvalue_uint32(a) sfvalue(a)
100. #define Sfvalue_uint64(a) sfvalue(a)
101. #define Sfvalue_short(a) sfvalue(a)
102. #define Sfvalue_ushort(a) sfvalue(a)
103. #define Sfvalue_int(a) sfvalue(a)
104. #define Sfvalue_unsigned(a) sfvalue(a)
105. #define Sfvalue_xint8(a) sfvalue(a)
106. #define Sfvalue_xint16(a) sfvalue(a)
107. #endif
108. 
109. /* not in _Generic */ 
110. #define Sfvalue_long(a) sfvalue_long(a)
111. #define Sfvalue_ulong(a) sfvalue_ulong(a)
112. #define Sfvalue_char(a, d) sfvalue_char(a, d)
113. #define Sfvalue_boolean(a) sfvalue_boolean(a)
114. #define Sfvalue_schar(a) sfvalue_schar(a)
115. #define Sfvalue_bitfield(a) sfvalue_bitfield(a)
116. #define Sfvalue_time_t(a) sfvalue_time_t(a)
117. #define Sfvalue_size_t(a) sfvalue_size_t(a)
118. 
119. #define SF_A(dtyp) \
120. void sfo_##dtyp(NHFILE *nhfp, dtyp *d_##dtyp, const char *myname)               \
121. {                                                                               \
122.     if (nhfp->fplog)                                                            \
123.         sf_log(nhfp, myname, sizeof *d_##dtyp, 1, Sfvalue_##dtyp(d_##dtyp));    \
124.     if (nhfp->structlevel) {                                                    \
125.         (*sfoprocs[nhfp->fnidx].fn.sf_##dtyp)(nhfp, d_##dtyp, myname);          \
126.     } else {                                                                    \
127.         FILE *save_fplog = nhfp->fplog;                                         \
128.                                                                                 \
129.         nhfp->fplog = 0;                                                        \
130.         (*sfoflprocs[nhfp->fnidx].fn_x.sf_##dtyp)(nhfp, d_##dtyp, myname);      \
131.         nhfp->fplog = save_fplog;                                               \
132.     }                                                                           \
133. }                                                                               \
134.                                                                                 \
135. void sfi_##dtyp(NHFILE *nhfp, dtyp *d_##dtyp, const char *myname)               \
136. {                                                                               \
137.     if (nhfp->structlevel) {                                                    \
138.         (*sfiprocs[nhfp->fnidx].fn.sf_##dtyp)(nhfp, d_##dtyp, myname);          \
139.     } else {                                                                    \
140.         int save_mode = nhfp->mode;                                             \
141.                                                                                 \
142.         nhfp->mode &= ~(CONVERTING | UNCONVERTING);                             \
143.         nhfp->mode |= TURN_OFF_LOGGING;                                         \
144.         (*sfiflprocs[nhfp->fnidx].fn_x.sf_##dtyp)(nhfp, d_##dtyp, myname);      \
145.         nhfp->mode = save_mode;                                                 \
146.     }                                                                           \
147.     if (!nhfp->eof) {                                                           \
148.         if ((((nhfp->mode & CONVERTING) != 0)                                   \
149.             || ((nhfp->mode & UNCONVERTING) != 0)) && nhfp->nhfpconvert)  {     \
150.             sfo_##dtyp(nhfp->nhfpconvert, d_##dtyp, myname);                    \
151.         }                                                                       \
152.         if (nhfp->fplog)                                                        \
153.             sf_log(nhfp, myname, sizeof *d_##dtyp, 1,                           \
154.                    Sfvalue_##dtyp(d_##dtyp));                                   \
155.     }                                                                           \
156. }
157. 
158. #define SF_C(keyw, dtyp) \
159. void sfo_##dtyp(NHFILE *nhfp, keyw dtyp *d_##dtyp, const char *myname)          \
160. {                                                                               \
161.     if (nhfp->fplog)                                                            \
162.         sf_log(nhfp, myname, sizeof *d_##dtyp, 1,                               \
163.                complex_dump((uchar *) d_##dtyp));                               \
164.     if (nhfp->structlevel) {                                                    \
165.         (*sfoprocs[nhfp->fnidx].fn.sf_##dtyp)(nhfp, d_##dtyp, myname);          \
166.     } else {                                                                    \
167.         FILE *save_fplog = nhfp->fplog;                                         \
168.                                                                                 \
169.         nhfp->fplog = 0;                                                        \
170.         (*sfoflprocs[nhfp->fnidx].fn_x.sf_##dtyp)(nhfp, d_##dtyp, myname);      \
171.         nhfp->fplog = save_fplog;                                               \
172.     }                                                                           \
173. }                                                                               \
174.                                                                                 \
175. void sfi_##dtyp(NHFILE *nhfp, keyw dtyp *d_##dtyp, const char *myname)          \
176. {                                                                               \
177.     if (nhfp->structlevel) {                                                    \
178.         (*sfiprocs[nhfp->fnidx].fn.sf_##dtyp)(nhfp, d_##dtyp, myname);          \
179.     } else {                                                                    \
180.         int save_mode = nhfp->mode;                                             \
181.                                                                                 \
182.         nhfp->mode &= ~(CONVERTING | UNCONVERTING);                             \
183.         nhfp->mode |= TURN_OFF_LOGGING;                                         \
184.         (*sfiflprocs[nhfp->fnidx].fn_x.sf_##dtyp)(nhfp, d_##dtyp, myname);      \
185.         nhfp->mode = save_mode;                                                 \
186.     }                                                                           \
187.     if (!nhfp->eof) {                                                           \
188.         if ((((nhfp->mode & CONVERTING) != 0)                                   \
189.             || ((nhfp->mode & UNCONVERTING) != 0))                              \
190.             && nhfp->nhfpconvert) {                                             \
191.             sfo_##dtyp(nhfp->nhfpconvert, d_##dtyp, myname);                    \
192.         }                                                                       \
193.         if (nhfp->fplog)                                                        \
194.             sf_log(nhfp, myname, sizeof *d_##dtyp, 1,                           \
195.                        complex_dump((uchar *) d_##dtyp));                       \
196.     }                                                                           \
197. }
198.   
199. #define SF_X(xxx, dtyp) \
200. void sfo_##dtyp(NHFILE *nhfp, xxx *d_##dtyp, const char *myname, int bfsz)      \
201. {                                                                               \
202.     if (nhfp->fplog)                                                            \
203.             sf_log(nhfp, myname, sizeof *d_##dtyp, 1,                           \
204.                    Sfvalue_##dtyp(d_##dtyp));                                   \
205.     if (nhfp->structlevel) {                                                    \
206.         (*sfoprocs[nhfp->fnidx].fn.sf_##dtyp)(nhfp, d_##dtyp, myname, bfsz);    \
207.     } else {                                                                    \
208.         FILE *save_fplog = nhfp->fplog;                                         \
209.                                                                                 \
210.         nhfp->fplog = 0;                                                        \
211.         (*sfoflprocs[nhfp->fnidx].fn_x.sf_##dtyp)(nhfp, d_##dtyp,               \
212.                                                   myname, bfsz);                \
213.         nhfp->fplog = save_fplog;                                               \
214.     }                                                                           \
215.     if (nhfp->fplog && !nhfp->eof)                                              \
216.         sf_log(nhfp, myname, sizeof *d_##dtyp, 1, Sfvalue_##dtyp(d_##dtyp));    \
217. }                                                                               \
218.                                                                                 \
219. void sfi_##dtyp(NHFILE *nhfp, xxx *d_##dtyp, const char *myname, int bfsz)      \
220. {                                                                               \
221.     if (nhfp->structlevel) {                                                    \
222.         (*sfiprocs[nhfp->fnidx].fn.sf_##dtyp)(nhfp, d_##dtyp, myname, bfsz);    \
223.     } else {                                                                    \
224.         int save_mode = nhfp->mode;                                             \
225.                                                                                 \
226.         nhfp->mode &= ~(CONVERTING | UNCONVERTING);                             \
227.         nhfp->mode |= TURN_OFF_LOGGING;                                         \
228.         (*sfiflprocs[nhfp->fnidx].fn_x.sf_##dtyp)(nhfp, d_##dtyp,               \
229.                                                   myname, bfsz);                \
230.         nhfp->mode = save_mode;                                                 \
231.     }                                                                           \
232.     if (!nhfp->eof) {                                                           \
233.         if ((((nhfp->mode & CONVERTING) != 0)                                   \
234.             || ((nhfp->mode & UNCONVERTING) != 0))                              \
235.                        && nhfp->nhfpconvert) {                                  \
236.             sfo_##dtyp(nhfp->nhfpconvert, d_##dtyp, myname, bfsz);              \
237.         }                                                                       \
238.         if (nhfp->fplog)                                                        \
239.             sf_log(nhfp, myname, sizeof *d_##dtyp, 1,                           \
240.                    dtyp##_dump(d_##dtyp));                                      \
241.     }                                                                           \
242. }
243. 
244. #include "sfmacros.h"
245. 
246. SF_X(uint8_t, bitfield)
247. 
248. void
249. sfo_char(NHFILE *nhfp, char *d_char, const char *myname, int cnt)
250. {
251.     if (nhfp->fplog)
252.         sf_log(nhfp, myname, sizeof(char), cnt, Sfvalue_char(d_char, cnt));
253.     if (nhfp->structlevel) {
254.         (*sfoprocs[nhfp->fnidx].fn.sf_char)(nhfp, d_char, myname, cnt);
255.     } else {
256.         FILE *save_fplog = nhfp->fplog;
257. 
258.         nhfp->fplog = 0;
259.         (*sfoflprocs[nhfp->fnidx].fn_x.sf_char)(nhfp, d_char, myname, cnt);
260.         nhfp->fplog = save_fplog;
261.     }
262. }
263. 
264. void
265. sfi_char(NHFILE *nhfp, char *d_char, const char *myname, int cnt)
266. {
267.     if (nhfp->structlevel) {
268.         (*sfiprocs[nhfp->fnidx].fn.sf_char)(nhfp, d_char, myname, cnt);
269.     } else {
270.         int save_mode = nhfp->mode;
271. 
272.         nhfp->mode &= ~(CONVERTING | UNCONVERTING);
273.         nhfp->mode |= TURN_OFF_LOGGING;
274.         (*sfiflprocs[nhfp->fnidx].fn_x.sf_char)(nhfp, d_char, myname, cnt);
275.         nhfp->mode = save_mode;
276.     }
277.     if (!nhfp->eof) {
278.         if ((((nhfp->mode & CONVERTING) != 0)
279.              || ((nhfp->mode & UNCONVERTING) != 0))
280.             && nhfp->nhfpconvert) {
281.             sfo_char(nhfp->nhfpconvert, d_char, myname, cnt);
282.         }
283.         if (nhfp->fplog)
284.             sf_log(nhfp, myname, sizeof(char), cnt,
285.                    Sfvalue_char(d_char, cnt));
286.     }
287. }
288. 
289. void
290. sfo_genericptr(NHFILE *nhfp, void **d_genericptr, const char *myname)
291. {
292.     if (nhfp->fplog)
293.         sf_log(nhfp, myname, sizeof *d_genericptr, 1,
294.                Sfvalue_genericptr(d_genericptr));
295.     if (nhfp->structlevel) {
296.         (*sfoprocs[nhfp->fnidx].fn.sf_genericptr)(nhfp, d_genericptr, myname);
297.     } else {
298.         FILE *save_fplog = nhfp->fplog;
299.         nhfp->fplog = 0;
300.         (*sfoflprocs[nhfp->fnidx].fn_x.sf_genericptr)(nhfp, d_genericptr,
301.                                                     myname);
302.         nhfp->fplog = save_fplog;
303.     }
304. }
305. void
306. sfi_genericptr(NHFILE *nhfp, void **d_genericptr, const char *myname)
307. {
308.     if (nhfp->structlevel) {
309.         (*sfiprocs[nhfp->fnidx].fn.sf_genericptr)(nhfp, d_genericptr, myname);
310.     } else {
311.         int save_mode = nhfp->mode;
312.         nhfp->mode &= ~(CONVERTING | UNCONVERTING);
313.         nhfp->mode |= TURN_OFF_LOGGING;
314.         (*sfiflprocs[nhfp->fnidx].fn_x.sf_genericptr)(nhfp, d_genericptr,
315.                                                     myname);
316.         nhfp->mode = save_mode;
317.     }
318.     if (!nhfp->eof) {
319.         if ((((nhfp->mode & CONVERTING) != 0) || ((nhfp->mode & UNCONVERTING) != 0))
320.             && nhfp->nhfpconvert) {
321.             sfo_genericptr(nhfp->nhfpconvert, d_genericptr, myname);
322.         }
323.         if (nhfp->fplog)
324.             sf_log(nhfp, myname, sizeof *d_genericptr, 1,
325.                    Sfvalue_genericptr(d_genericptr));
326.     }
327. }
328. 
329. void
330. sfo_version_info(NHFILE *nhfp, struct version_info *d_version_info,
331.                  const char *myname)
332. {
333.     if (nhfp->fplog)
334.         sf_log(nhfp, myname, sizeof *d_version_info, 1,
335.                complex_dump((uchar *) d_version_info));
336.     if (nhfp->structlevel) {
337.         (*sfoprocs[nhfp->fnidx].fn.sf_version_info)(nhfp, d_version_info,
338.                                                     myname);
339.     } else {
340.         FILE *save_fplog = nhfp->fplog;
341.         nhfp->fplog = 0;
342.         (*sfoflprocs[nhfp->fnidx].fn_x.sf_version_info)(nhfp, d_version_info,
343.                                                       myname);
344.         nhfp->fplog = save_fplog;
345.     }
346. }
347. void
348. sfi_version_info(NHFILE *nhfp, struct version_info *d_version_info,
349.                  const char *myname)
350. {
351.     if (nhfp->structlevel) {
352.         (*sfiprocs[nhfp->fnidx].fn.sf_version_info)(nhfp, d_version_info,
353.                                                     myname);
354.     } else {
355.         int save_mode = nhfp->mode;
356.         nhfp->mode &= ~(CONVERTING | UNCONVERTING);
357.         nhfp->mode |= TURN_OFF_LOGGING;
358.         (*sfiflprocs[nhfp->fnidx].fn_x.sf_version_info)(nhfp, d_version_info,
359.                                                       myname);
360.         nhfp->mode = save_mode;
361.     }
362.     if (!nhfp->eof) {
363.         if ((((nhfp->mode & CONVERTING) != 0) || ((nhfp->mode & UNCONVERTING) != 0))
364.             && nhfp->nhfpconvert) {
365.             d_version_info->feature_set |= SFCTOOL_BIT;
366.             sfo_version_info(nhfp->nhfpconvert, d_version_info, myname);
367.         }
368.         if (nhfp->fplog)
369.             sf_log(nhfp, myname, sizeof *d_version_info, 1,
370.                    complex_dump((uchar *) d_version_info));
371.     }
372. }
373. 
374. /* ---------------------------------------------------------------*/
375. 
376. void
377. sf_log(NHFILE *nhfp, const char *t1, size_t sz, int cnt, char *txtvalue)
378. {
379.     FILE *fp = nhfp->fplog;
380.     long *iocount;
381.     boolean dolog = ((nhfp->mode & TURN_OFF_LOGGING) == 0);
382. 
383.     if (fp && dolog) {
384.         iocount = ((nhfp->mode & WRITING) == 0) ? &nhfp->rcount : &nhfp->wcount;
385.         (void) fprintf(fp,
386. #ifndef VMS
387.                        "%08ld %s sz=%zu cnt=%d |%s|\n",
388. #else
389.                        "%08ld %s sz=%lu cnt=%d |%s|\n",
390. #endif
391.                        *iocount,
392.                        t1,
393. #ifndef VMS
394.                        sz,
395. #else
396.                        (unsigned long) sz,
397. #endif
398.                        cnt, txtvalue);
399. //        (*iocount)++;
400. //        if (*iocount == 87)
401. //            __debugbreak();
402.         fflush(fp);
403.     }
404. }
405. 
406. char *sfvalue_char(char *a, int n)
407. {
408.     int i;
409.     static char buf[120];
410.     char *cp;
411. 
412.     cp = &buf[0];
413.     if (n < (int) (sizeof buf - 1))
414.         buf[n] = '\0';
415.     else
416.         buf[(int) (sizeof buf - 1)] = '\0';
417.     for (i = 0; i < n; ++i, ++cp, ++a)
418.         *cp = *a;
419.     *cp = '\0';
420.     return buf;
421. }
422. 
423. char *sfvalue_boolean(boolean *a)
424. {
425.     static char buf[20];
426. 
427.     Snprintf(buf, sizeof buf, "%s",
428.              (*a == 0) ? "false" : "true");
429.     return buf;
430. }
431. 
432. char *sfvalue_schar(schar *a)
433. {
434.     static char buf[20];
435. 
436.     Snprintf(buf, sizeof buf, "%d", (int) *a);
437.     return buf;
438. }
439. 
440. char * sfvalue_aligntyp(aligntyp *a)
441. {
442.     static char buf[20];
443. 
444.     Snprintf(buf, sizeof buf, "%d", (int) *a);
445.     return buf;
446. }
447. 
448. char *
449. sfvalue_any(anything *a)
450. {
451.     static char buf[20];
452. 
453.     Snprintf(buf, sizeof buf,
454.              "%" PRId64,
455.              a->a_int64);
456.     return buf;
457. }
458. 
459. char *
460. sfvalue_genericptr(genericptr a)
461. {
462.     static char buf[20];
463. 
464.     Snprintf(buf, sizeof buf, "%s", 
465.              (a == 0) ? "0" : "glorkum");
466.     return buf;
467. }
468. 
469. char * sfvalue_int16(int16 *a)
470. {
471.     static char buf[20];
472. 
473.     Snprintf(buf, sizeof buf, "%d", *a);
474.     return buf;
475. }
476. 
477. char * sfvalue_int32(int32 *a)
478. {
479.     static char buf[20];
480. 
481.     Snprintf(buf, sizeof buf, "%" PRId32, *a);
482.     return buf;
483. }
484. 
485. char * sfvalue_int64(int64 *a)
486. {
487.     static char buf[20];
488.     Snprintf(buf, sizeof buf, "%" PRId64, *a);
489.     return buf;
490. }
491. 
492. char * sfvalue_uchar(uchar *a)
493. {
494.     static char buf[20];
495.     unsigned x;
496. 
497.     x = *a;
498.     Snprintf(buf, sizeof buf, "%03u", x);
499.     return buf;
500. }
501. 
502. char * sfvalue_uint16(uint16 *a)
503. {
504.     static char buf[20];
505. 
506.     Snprintf(buf, sizeof buf, "%u", (uint) *a);
507.     return buf;
508. }
509. 
510. char * sfvalue_uint32(uint32 *a)
511. {
512.     static char buf[20];
513. 
514.     Snprintf(buf, sizeof buf, "%" PRIu32, *a);
515.     return buf;
516. }
517. 
518. char * sfvalue_uint64(uint64 *a)
519. {
520.     static char buf[20];
521. 
522.     Snprintf(buf, sizeof buf, "%" PRIu64, *a);
523.     return buf;
524. }
525. 
526. char * sfvalue_size_t(size_t *a UNUSED)
527. {
528.     static char buf[20];
529. 
530.     Snprintf(buf, sizeof buf, "%s", (char *) "");
531.     return buf;
532. }
533. 
534. char * sfvalue_time_t(time_t *a UNUSED)
535. {
536.     static char buf[20];
537. 
538.     Snprintf(buf, sizeof buf, "%s", (char *) "");
539.     return buf;
540. }
541. 
542. char * sfvalue_short(short *a)
543. {
544.     static char buf[20];
545. 
546.     Snprintf(buf, sizeof buf, "%d", (int) *a);
547.     return buf;
548. }
549. 
550. char * sfvalue_ushort(ushort *a)
551. {
552.     static char buf[20];
553. 
554.     Snprintf(buf, sizeof buf, "%u", (unsigned) *a);
555.     return buf;
556. }
557. 
558. char * sfvalue_int(int *a)
559. {
560.     static char buf[20];
561. 
562.     Snprintf(buf, sizeof buf, "%d", *a);
563.     return buf;
564. }
565. 
566. char * sfvalue_unsigned(unsigned *a)
567. {
568.     static char buf[20];
569. 
570.     Snprintf(buf, sizeof buf, "%u", *a);
571.     return buf;
572. }
573. 
574. char * sfvalue_long(long *a)
575. {
576.     static char buf[20];
577. 
578.     Snprintf(buf, sizeof buf, "%ld", *a);
579.     return buf;
580. }
581. 
582. char * sfvalue_ulong(ulong *a)
583. {
584.     static char buf[20];
585. 
586.     Snprintf(buf, sizeof buf, "%lu", *a);
587.     return buf;
588. }
589. 
590. char * sfvalue_xint8(xint8 *a)
591. {
592.     static char buf[20];
593. 
594.     Snprintf(buf, sizeof buf, "%d", (int) *a);
595.     return buf;
596. }
597. 
598. char * sfvalue_xint16(xint16 *a)
599. {
600.     static char buf[20];
601. 
602. 
603.     Snprintf(buf, sizeof buf, "%d", (int) *a);
604.     return buf;
605. }
606. 
607. char *
608. sfvalue_bitfield(uint8 *a)
609. {
610.     static char buf[20];
611. 
612.     Snprintf(buf, sizeof buf, "%u", (uint) *a);
613.     return buf;
614. }
615. 
616. char *
617. bitfield_dump(uint8 *a)
618. {
619.     static char buf[20];
620. 
621.     Snprintf(buf, sizeof buf, "%u", (uint) *a);
622.     return buf;
623. }
624. char *
625. complex_dump(uchar *a)
626. {
627.     int i;
628.     uchar *uc = a;
629.     static char buf[50];
630.     unsigned x[10];
631. 
632.     for (i = 0; i < SIZE(x); ++i) {
633.         x[i] = *uc++;
634.     }
635.     Snprintf(buf, sizeof buf, "%03x %03x %03x %03x %03x %03x %03x %03x %03x %03x", 
636.              x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], x[8], x[9]);
637.     buf[40] = '\0';
638.     return buf;
639. }
640. /*
641.  *----------------------------------------------------------------------------
642.  * initialize the function pointers. These are called from initoptions_init().
643.  *----------------------------------------------------------------------------
644.  */
645. 
646. void
647. sf_init(void)
648. {
649.     sfoprocs[invalid] = zerosfoprocs;
650.     sfiprocs[invalid] = zerosfiprocs;
651.     sfoprocs[historical] = historical_sfo_procs;
652.     sfiprocs[historical] = historical_sfi_procs;
653.     sfoflprocs[exportascii] = zerosfoflprocs;
654.     sfiflprocs[exportascii] = zerosfiflprocs;
655. }
656. 
657. void
658. sf_setprocs(int idx, struct sf_structlevel_procs *sfi, struct sf_structlevel_procs *sfo)
659. {
660.     sfoprocs[idx] = *sfo;
661.     sfiprocs[idx] = *sfi;
662. }
663. void
664. sf_setflprocs(int idx, struct sf_fieldlevel_procs *flsfi,
665.             struct sf_fieldlevel_procs *flsfo)
666. {
667.     sfoflprocs[idx] = *flsfo;
668.     sfiflprocs[idx] = *flsfi;
669. }
670. 
671. #ifndef SFCTOOL
672. void norm_ptrs_any(union any *d_any);
673. void norm_ptrs_align(struct align *d_align);
674. void norm_ptrs_arti_info(struct arti_info *d_arti_info);
675. void norm_ptrs_attribs(struct attribs *d_attribs);
676. void norm_ptrs_bill_x(struct bill_x *d_bill_x);
677. void norm_ptrs_branch(struct branch *d_branch);
678. void norm_ptrs_bubble(struct bubble *d_bubble);
679. void norm_ptrs_cemetery(struct cemetery *d_cemetery);
680. void norm_ptrs_context_info(struct context_info *d_context_info);
681. void norm_ptrs_achievement_tracking(
682.     struct achievement_tracking *d_achievement_tracking);
683. void norm_ptrs_book_info(struct book_info *d_book_info);
684. void norm_ptrs_dig_info(struct dig_info *d_dig_info);
685. void norm_ptrs_engrave_info(struct engrave_info *d_engrave_info);
686. void norm_ptrs_obj_split(struct obj_split *d_obj_split);
687. void norm_ptrs_polearm_info(struct polearm_info *d_polearm_info);
688. void norm_ptrs_takeoff_info(struct takeoff_info *d_takeoff_info);
689. void norm_ptrs_tin_info(struct tin_info *d_tin_info);
690. void norm_ptrs_tribute_info(struct tribute_info *d_tribute_info);
691. void norm_ptrs_victual_info(struct victual_info *d_victual_info);
692. void norm_ptrs_warntype_info(struct warntype_info *d_warntype_info);
693. void norm_ptrs_d_flags(struct d_flags *d_d_flags);
694. void norm_ptrs_d_level(struct d_level *d_d_level);
695. void norm_ptrs_damage(struct damage *d_damage);
696. void norm_ptrs_dest_area(struct dest_area *d_dest_area);
697. void norm_ptrs_dgn_topology(struct dgn_topology *d_dgn_topology);
698. void norm_ptrs_dungeon(struct dungeon *d_dungeon);
699. void norm_ptrs_ebones(struct ebones *d_ebones);
700. void norm_ptrs_edog(struct edog *d_edog);
701. void norm_ptrs_egd(struct egd *d_egd);
702. void norm_ptrs_emin(struct emin *d_emin);
703. void norm_ptrs_engr(struct engr *d_engr);
704. void norm_ptrs_epri(struct epri *d_epri);
705. void norm_ptrs_eshk(struct eshk *d_eshk);
706. void norm_ptrs_fakecorridor(struct fakecorridor *d_fakecorridor);
707. void norm_ptrs_fe(struct fe *d_fe);
708. void norm_ptrs_flag(struct flag *d_flag);
709. void norm_ptrs_fruit(struct fruit *d_fruit);
710. void norm_ptrs_gamelog_line(struct gamelog_line *d_gamelog_line);
711. void norm_ptrs_kinfo(struct kinfo *d_kinfo);
712. void norm_ptrs_levelflags(struct levelflags *d_levelflags);
713. void norm_ptrs_linfo(struct linfo *d_linfo);
714. void norm_ptrs_ls_t(struct ls_t *d_ls_t);
715. void norm_ptrs_mapseen_feat(struct mapseen_feat *d_mapseen_feat);
716. void norm_ptrs_mapseen_flags(struct mapseen_flags *d_mapseen_flags);
717. void norm_ptrs_mapseen_rooms(struct mapseen_rooms *d_mapseen_rooms);
718. void norm_ptrs_mapseen(struct mapseen *d_mapseen);
719. void norm_ptrs_mextra(struct mextra *d_mextra);
720. void norm_ptrs_mkroom(struct mkroom *d_mkroom);
721. void norm_ptrs_monst(struct monst *d_monst);
722. void norm_ptrs_mvitals(struct mvitals *d_mvitals);
723. void norm_ptrs_nhcoord(struct nhcoord *d_nhcoord);
724. void norm_ptrs_nhrect(struct nhrect *d_nhrect);
725. void norm_ptrs_novel_tracking(struct novel_tracking *d_novel_tracking);
726. void norm_ptrs_obj(struct obj *d_obj);
727. void norm_ptrs_objclass(struct objclass *d_objclass);
728. void norm_ptrs_oextra(struct oextra *d_oextra);
729. void norm_ptrs_prop(struct prop *d_prop);
730. void norm_ptrs_q_score(struct q_score *d_q_score);
731. void norm_ptrs_rm(struct rm *d_rm);
732. void norm_ptrs_s_level(struct s_level *d_s_level);
733. void norm_ptrs_skills(struct skills *d_skills);
734. void norm_ptrs_spell(struct spell *d_spell);
735. void norm_ptrs_stairway(struct stairway *d_stairway);
736. void norm_ptrs_trap(struct trap *d_trap);
737. void norm_ptrs_u_conduct(struct u_conduct *d_u_conduct);
738. void norm_ptrs_u_event(struct u_event *d_u_event);
739. void norm_ptrs_u_have(struct u_have *d_u_have);
740. void norm_ptrs_u_realtime(struct u_realtime *d_u_realtime);
741. void norm_ptrs_u_roleplay(struct u_roleplay *d_u_roleplay);
742. void norm_ptrs_version_info(struct version_info *d_version_info);
743. void norm_ptrs_vlaunchinfo(union vlaunchinfo *d_vlaunchinfo);
744. void norm_ptrs_vptrs(union vptrs *d_vptrs);
745. void norm_ptrs_you(struct you *d_you);
746. 
747. void
748. norm_ptrs_any(union any *d_any UNUSED)
749. {
750. }
751. void
752. norm_ptrs_align(struct align *d_align UNUSED)
753. {
754. }
755. 
756. void
757. norm_ptrs_arti_info(struct arti_info *d_arti_info UNUSED)
758. {
759. }
760. 
761. void
762. norm_ptrs_attribs(struct attribs *d_attribs UNUSED)
763. {
764. }
765. 
766. void
767. norm_ptrs_bill_x(struct bill_x *d_bill_x UNUSED)
768. {
769. }
770. 
771. void
772. norm_ptrs_branch(struct branch *d_branch UNUSED)
773. {
774. }
775. 
776. void
777. norm_ptrs_bubble(struct bubble *d_bubble UNUSED)
778. {
779. }
780. 
781. void
782. norm_ptrs_cemetery(struct cemetery *d_cemetery UNUSED)
783. {
784. }
785. 
786. void
787. norm_ptrs_context_info(struct context_info *d_context_info UNUSED)
788. {
789. }
790. 
791. void
792. norm_ptrs_achievement_tracking(struct achievement_tracking *d_achievement_tracking UNUSED)
793. {
794. }
795. 
796. void
797. norm_ptrs_book_info(struct book_info *d_book_info UNUSED)
798. {
799. }
800. 
801. void
802. norm_ptrs_dig_info(struct dig_info *d_dig_info UNUSED)
803. {
804. }
805. 
806. void
807. norm_ptrs_engrave_info(struct engrave_info *d_engrave_info UNUSED)
808. {
809. }
810. 
811. void
812. norm_ptrs_obj_split(struct obj_split *d_obj_split UNUSED)
813. {
814. }
815. 
816. void
817. norm_ptrs_polearm_info(struct polearm_info *d_polearm_info UNUSED)
818. {
819. }
820. 
821. void
822. norm_ptrs_takeoff_info(struct takeoff_info *d_takeoff_info UNUSED)
823. {
824. }
825. 
826. void
827. norm_ptrs_tin_info(struct tin_info *d_tin_info UNUSED)
828. {
829. }
830. 
831. void
832. norm_ptrs_tribute_info(struct tribute_info *d_tribute_info UNUSED)
833. {
834. }
835. 
836. void
837. norm_ptrs_victual_info(struct victual_info *d_victual_info UNUSED)
838. {
839. }
840. 
841. void
842. norm_ptrs_warntype_info(struct warntype_info *d_warntype_info UNUSED)
843. {
844. }
845. 
846. void
847. norm_ptrs_d_flags(struct d_flags *d_d_flags UNUSED)
848. {
849. }
850. 
851. void
852. norm_ptrs_d_level(struct d_level *d_d_level UNUSED)
853. {
854. }
855. 
856. void
857. norm_ptrs_damage(struct damage *d_damage UNUSED)
858. {
859. }
860. 
861. void
862. norm_ptrs_dest_area(struct dest_area *d_dest_area UNUSED)
863. {
864. }
865. 
866. void
867. norm_ptrs_dgn_topology(struct dgn_topology *d_dgn_topology UNUSED)
868. {
869. }
870. 
871. void
872. norm_ptrs_dungeon(struct dungeon *d_dungeon UNUSED)
873. {
874. }
875. 
876. void
877. norm_ptrs_ebones(struct ebones *d_ebones UNUSED)
878. {
879. }
880. 
881. void
882. norm_ptrs_edog(struct edog *d_edog UNUSED)
883. {
884. }
885. 
886. void
887. norm_ptrs_egd(struct egd *d_egd UNUSED)
888. {
889. }
890. 
891. void
892. norm_ptrs_emin(struct emin *d_emin UNUSED)
893. {
894. }
895. 
896. void
897. norm_ptrs_engr(struct engr *d_engr UNUSED)
898. {
899. }
900. 
901. void
902. norm_ptrs_epri(struct epri *d_epri UNUSED)
903. {
904. }
905. 
906. void
907. norm_ptrs_eshk(struct eshk *d_eshk UNUSED)
908. {
909. }
910. 
911. void
912. norm_ptrs_fakecorridor(struct fakecorridor *d_fakecorridor UNUSED)
913. {
914. }
915. 
916. void
917. norm_ptrs_fe(struct fe *d_fe UNUSED)
918. {
919. }
920. 
921. void
922. norm_ptrs_flag(struct flag *d_flag UNUSED)
923. {
924. }
925. 
926. void
927. norm_ptrs_fruit(struct fruit *d_fruit UNUSED)
928. {
929. }
930. 
931. void
932. norm_ptrs_gamelog_line(struct gamelog_line *d_gamelog_line UNUSED)
933. {
934. }
935. 
936. void
937. norm_ptrs_kinfo(struct kinfo *d_kinfo UNUSED)
938. {
939. }
940. 
941. void
942. norm_ptrs_levelflags(struct levelflags *d_levelflags UNUSED)
943. {
944. }
945. 
946. void
947. norm_ptrs_linfo(struct linfo *d_linfo UNUSED)
948. {
949. }
950. 
951. void
952. norm_ptrs_ls_t(struct ls_t *d_ls_t UNUSED)
953. {
954. }
955. 
956. void
957. norm_ptrs_mapseen_feat(struct mapseen_feat *d_mapseen_feat UNUSED)
958. {
959. }
960. 
961. void
962. norm_ptrs_mapseen_flags(struct mapseen_flags *d_mapseen_flags UNUSED)
963. {
964. }
965. 
966. void
967. norm_ptrs_mapseen_rooms(struct mapseen_rooms *d_mapseen_rooms UNUSED)
968. {
969. }
970. 
971. void
972. norm_ptrs_mapseen(struct mapseen *d_mapseen UNUSED)
973. {
974. }
975. 
976. void
977. norm_ptrs_mextra(struct mextra *d_mextra UNUSED)
978. {
979. }
980. 
981. void
982. norm_ptrs_mkroom(struct mkroom *d_mkroom UNUSED)
983. {
984. }
985. 
986. void
987. norm_ptrs_monst(struct monst *d_monst UNUSED)
988. {
989. }
990. 
991. void
992. norm_ptrs_mvitals(struct mvitals *d_mvitals UNUSED)
993. {
994. }
995. 
996. void
997. norm_ptrs_nhcoord(struct nhcoord *d_nhcoord UNUSED)
998. {
999. }
1000. 
1001. void
1002. norm_ptrs_nhrect(struct nhrect *d_nhrect UNUSED)
1003. {
1004. }
1005. 
1006. void
1007. norm_ptrs_novel_tracking(struct novel_tracking *d_novel_tracking UNUSED)
1008. {
1009. }
1010. 
1011. void
1012. norm_ptrs_obj(struct obj *d_obj UNUSED)
1013. {
1014. }
1015. 
1016. void
1017. norm_ptrs_objclass(struct objclass *d_objclass UNUSED)
1018. {
1019. }
1020. 
1021. void
1022. norm_ptrs_oextra(struct oextra *d_oextra UNUSED)
1023. {
1024. }
1025. 
1026. void
1027. norm_ptrs_prop(struct prop *d_prop UNUSED)
1028. {
1029. }
1030. 
1031. void
1032. norm_ptrs_q_score(struct q_score *d_q_score UNUSED)
1033. {
1034. }
1035. 
1036. void
1037. norm_ptrs_rm(struct rm *d_rm UNUSED)
1038. {
1039. }
1040. 
1041. void
1042. norm_ptrs_s_level(struct s_level *d_s_level UNUSED)
1043. {
1044. }
1045. 
1046. void
1047. norm_ptrs_skills(struct skills *d_skills UNUSED)
1048. {
1049. }
1050. 
1051. void
1052. norm_ptrs_spell(struct spell *d_spell UNUSED)
1053. {
1054. }
1055. 
1056. void
1057. norm_ptrs_stairway(struct stairway *d_stairway UNUSED)
1058. {
1059. }
1060. 
1061. void
1062. norm_ptrs_trap(struct trap *d_trap UNUSED)
1063. {
1064. }
1065. 
1066. void
1067. norm_ptrs_u_conduct(struct u_conduct *d_u_conduct UNUSED)
1068. {
1069. }
1070. 
1071. void
1072. norm_ptrs_u_event(struct u_event *d_u_event UNUSED)
1073. {
1074. }
1075. 
1076. void
1077. norm_ptrs_u_have(struct u_have *d_u_have UNUSED)
1078. {
1079. }
1080. 
1081. void
1082. norm_ptrs_u_realtime(struct u_realtime *d_u_realtime UNUSED)
1083. {
1084. }
1085. 
1086. void
1087. norm_ptrs_u_roleplay(struct u_roleplay *d_u_roleplay UNUSED)
1088. {
1089. }
1090. 
1091. void
1092. norm_ptrs_version_info(struct version_info *d_version_info UNUSED)
1093. {
1094. }
1095. 
1096. void
1097. norm_ptrs_vlaunchinfo(union vlaunchinfo *d_vlaunchinfo UNUSED)
1098. {
1099. }
1100. 
1101. void
1102. norm_ptrs_vptrs(union vptrs *d_vptrs UNUSED)
1103. {
1104. }
1105. 
1106. void
1107. norm_ptrs_you(struct you *d_you UNUSED)
1108. {
1109. }
1110. #endif  /* SFCTOOL */
1111. 
1112. #undef SF_X
1113. #undef SF_C
1114. #undef SF_A
1115. 
1116. /* end of sfbase.c */
1117.