Changeset 15

Show
Ignore:
Timestamp:
03/26/07 13:10:15 (2 years ago)
Author:
takkaria
Message:

I didn't realise I had uncommitted changes around, so this one's a little messy:

  • #4: create z-file.c, move file stuff into it and its header file (this cleans up h-define.h a bit)
  • I ran autotools for the first time, so it regenerated various files (this is just noise)
  • Kill massive comment at top of save.c
  • Clean up Makefile.inc a bit
  • Add comment to top of compile.txt
  • Add Windows packaging script

+935 lines, -1486 lines, -551 net.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/compile.txt

    r1 r15  
    22================= 
    33 
    4 Last updated on 13th March 2005 by Robert Ruehlmann 
     4Last updated on 23rd March 2007 by Andrew Sidwell 
     5 
     6If you are able to construct "main-xxx.c" and/or "Makefile.xxx" files for 
     7a currently unsupported system, please write to the Angband newsgroup 
     8(rec.games.roguelike.angband) with details, and it will probably be included 
     9in a future version. 
    510 
    611 
  • trunk/configure

    r1 r15  
    67006700 
    67016701fi 
    6702  
    67036702 
    67046703 
  • trunk/src/Makefile.am

    r7 r15  
    2828  h-config.h h-define.h h-system.h h-type.h init.h \ 
    2929  types.h z-form.h z-rand.h z-term.h z-util.h \ 
    30   z-virt.h main.h \ 
     30  z-virt.h z-file.h main.h \ 
    3131  script.h 
    3232 
  • trunk/src/Makefile.in

    r7 r15  
    6565        main-x11.$(OBJEXT) main-xaw.$(OBJEXT) main.$(OBJEXT) \ 
    6666        main-win.$(OBJEXT) main-xpj.$(OBJEXT) main-vcs.$(OBJEXT) \ 
    67         main-gtk.$(OBJEXT) generate.$(OBJEXT) dungeon.$(OBJEXT) \ 
    68         init1.$(OBJEXT) init2.$(OBJEXT) randart.$(OBJEXT) \ 
    69         use-obj.$(OBJEXT) x-spell.$(OBJEXT) obj-info.$(OBJEXT) \ 
    70         squelch.$(OBJEXT) script.$(OBJEXT) 
     67        main-gtk.$(OBJEXT) main-lfb.$(OBJEXT) generate.$(OBJEXT) \ 
     68        dungeon.$(OBJEXT) init1.$(OBJEXT) init2.$(OBJEXT) \ 
     69        randart.$(OBJEXT) use-obj.$(OBJEXT) x-spell.$(OBJEXT) \ 
     70        obj-info.$(OBJEXT) squelch.$(OBJEXT) 
    7171angband_OBJECTS = $(am_angband_OBJECTS) 
    7272DEFAULT_INCLUDES = -I. -I$(srcdir) -I. 
     
    195195  wizard1.c wizard2.c \ 
    196196  main-cap.c main-gcu.c main-x11.c main-xaw.c main.c \ 
    197   main-win.c main-xpj.c main-vcs.c main-gtk.c
     197  main-win.c main-xpj.c main-vcs.c main-gtk.c main-lfb.c
    198198  generate.c dungeon.c init1.c init2.c randart.c \ 
    199199  use-obj.c x-spell.c obj-info.c squelch.c \ 
     
    201201  h-config.h h-define.h h-system.h h-type.h init.h \ 
    202202  types.h z-form.h z-rand.h z-term.h z-util.h \ 
    203   z-virt.h main.h \ 
     203  z-virt.h z-file.h main.h \ 
    204204  script.h 
    205205 
     
    322322@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main-gtk.Po@am__quote@ 
    323323@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main-ibm.Po@am__quote@ 
     324@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main-lfb.Po@am__quote@ 
    324325@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main-lsl.Po@am__quote@ 
    325326@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main-mac.Po@am__quote@ 
     
    343344@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/readdib.Po@am__quote@ 
    344345@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/save.Po@am__quote@ 
    345 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/script.Po@am__quote@ 
    346346@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/spells1.Po@am__quote@ 
    347347@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/spells2.Po@am__quote@ 
  • trunk/src/Makefile.inc

    r7 r15  
    1010       z-term.h z-rand.h z-util.h z-virt.h z-form.h $(HDRS) 
    1111 
    12 BASEOBJS=
    13   birth$(OBJEXT)
    14   cave$(OBJEXT)
    15   cmd1$(OBJEXT)
    16   cmd2$(OBJEXT)
    17   cmd3$(OBJEXT)
    18   cmd4$(OBJEXT)
    19   cmd5$(OBJEXT)
    20   cmd6$(OBJEXT)
    21   dungeon$(OBJEXT)
    22   files$(OBJEXT)
    23   generate$(OBJEXT)
    24   init1$(OBJEXT)
    25   init2$(OBJEXT)
    26   load$(OBJEXT)
    27   melee1$(OBJEXT)
    28   melee2$(OBJEXT)
    29   monster1$(OBJEXT)
    30   monster2$(OBJEXT)
    31   object1$(OBJEXT)
    32   object2$(OBJEXT)
    33   obj-info$(OBJEXT)
    34   randart$(OBJEXT)
    35   save$(OBJEXT)
    36   spells1$(OBJEXT)
    37   spells2$(OBJEXT)
    38   squelch$(OBJEXT)
    39   store$(OBJEXT)
    40   tables$(OBJEXT)
    41   use-obj$(OBJEXT)
    42   util$(OBJEXT)
    43   variable$(OBJEXT)
    44   wizard1$(OBJEXT)
    45   wizard2$(OBJEXT)
    46   x-spell$(OBJEXT)
    47   xtra1$(OBJEXT)
    48   xtra2$(OBJEXT
     12BASEOBJS := $(addsuffix $(OBJEXT),
     13  birth
     14  cave
     15  cmd1
     16  cmd2
     17  cmd3
     18  cmd4
     19  cmd5
     20  cmd6
     21  dungeon
     22  files
     23  generate
     24  init1
     25  init2
     26  load
     27  melee1
     28  melee2
     29  monster1
     30  monster2
     31  object1
     32  object2
     33  obj-info
     34  randart
     35  save
     36  spells1
     37  spells2
     38  squelch
     39  store
     40  tables
     41  use-obj
     42  util
     43  variable
     44  wizard1
     45  wizard2
     46  x-spell
     47  xtra1
     48  xtra2
    4949 
    50 ZOBJS= \ 
    51   z-form$(OBJEXT) \ 
    52   z-rand$(OBJEXT) \ 
    53   z-term$(OBJEXT) \ 
    54   z-util$(OBJEXT) \ 
    55   z-virt$(OBJEXT) 
     50ZOBJS := $(addsuffix $(OBJEXT), z-file z-form z-rand z-term z-util z-virt) 
    5651 
    5752# Just print out a list of object files 
     
    6964z-util$(OBJEXT): z-util.h 
    7065z-virt$(OBJEXT): z-virt.h z-util.h 
     66z-file$(OBJEXT): z-file.h 
    7167 
    72 # Depend on script.h 
    73 SCRIPTOBJS = cmd5$(OBJEXT) cmd6$(OBJEXT) init2$(OBJEXT) \ 
    74              script$(OBJEXT) wizard2$(OBJEXT) xtra1$(OBJEXT) 
    75 $(SCRIPTOBJS): script.h 
    76  
    77 # Depend on init.h 
    78 INITOBJS = init1$(OBJEXT) init2$(OBJEXT) randart$(OBJEXT) 
    79 $(INITOBJS): init.h 
     68# Various files depend on various headers 
     69$(addsuffix $(OBJEXT), cmd5 cmd6 init2 script wizard2 xtra1): script.h 
     70$(addsuffix $(OBJEXT), init1 init2 randart): init.h 
     71$(addsuffix $(OBJEXT), cmd4 files init1 init2 util squelch save load wizard1): z-file.h 
  • trunk/src/autoconf.h.in

    r1 r15  
    8888#undef HAVE_VPRINTF 
    8989 
    90 /* Define to 1 if you have the <\ 
    91 > header file. */ 
    92 #undef HAVE___ 
    93  
    9490/* Name of package */ 
    9591#undef PACKAGE 
  • trunk/src/cmd4.c

    r1 r15  
    1010 
    1111#include "angband.h" 
     12#include "z-file.h" 
    1213 
    1314 
  • trunk/src/externs.h

    r1 r15  
    672672 
    673673/* util.c */ 
    674 extern errr path_parse(char *buf, size_t max, cptr file); 
    675 extern errr path_build(char *buf, size_t max, cptr path, cptr file); 
    676 extern FILE *my_fopen(cptr file, cptr mode); 
    677 extern FILE *my_fopen_temp(char *buf, size_t max); 
    678 extern errr my_fclose(FILE *fff); 
    679 extern errr my_fgets(FILE *fff, char *buf, size_t n); 
    680 extern errr my_fputs(FILE *fff, cptr buf, size_t n); 
    681 extern errr fd_kill(cptr file); 
    682 extern errr fd_move(cptr file, cptr what); 
    683 extern int fd_make(cptr file, int mode); 
    684 extern int fd_open(cptr file, int flags); 
    685 extern errr fd_lock(int fd, int what); 
    686 extern errr fd_seek(int fd, long n); 
    687 extern errr fd_read(int fd, char *buf, size_t n); 
    688 extern errr fd_write(int fd, cptr buf, size_t n); 
    689 extern errr fd_close(int fd); 
    690 extern errr check_modification_date(int fd, cptr template_file); 
    691674extern void text_to_ascii(char *buf, size_t len, cptr str); 
    692675extern void ascii_to_text(char *buf, size_t len, cptr str); 
  • trunk/src/files.c

    r1 r15  
    1010 
    1111#include "angband.h" 
     12#include "z-file.h" 
    1213 
    1314 
  • trunk/src/h-define.h

    r1 r15  
    1515# define NULL ((void*)0) 
    1616#endif /* NULL */ 
    17  
    18  
    19 /* 
    20  * Hack -- assist "main-ros.c" XXX XXX XXX 
    21  */ 
    22 #ifdef RISCOS 
    23 # define O_RDONLY       0 
    24 # define O_WRONLY       1 
    25 # define O_RDWR         2 
    26 #endif 
    27  
    28  
    29 /* 
    30  * Hack -- force definitions -- see fd_seek() 
    31  */ 
    32 #ifndef SEEK_SET 
    33 # define SEEK_SET       0 
    34 #endif 
    35 #ifndef SEEK_CUR 
    36 # define SEEK_CUR       1 
    37 #endif 
    38 #ifndef SEEK_END 
    39 # define SEEK_END       2 
    40 #endif 
    41  
    42 /* 
    43  * Hack -- force definitions -- see fd_lock()  XXX XXX XXX 
    44  */ 
    45 #ifndef F_UNLCK 
    46 # define F_UNLCK        0 
    47 #endif 
    48 #ifndef F_RDLCK 
    49 # define F_RDLCK        1 
    50 #endif 
    51 #ifndef F_WRLCK 
    52 # define F_WRLCK        2 
    53 #endif 
    5417 
    5518 
  • trunk/src/init1.c

    r1 r15  
    1010 
    1111#include "angband.h" 
     12#include "z-file.h" 
    1213 
    1314 
  • trunk/src/init2.c

    r1 r15  
    1111 
    1212#include "angband.h" 
     13#include "z-file.h" 
    1314 
    1415#include "init.h" 
  • trunk/src/load.c

    r11 r15  
    1010 
    1111#include "angband.h" 
     12#include "z-file.h" 
    1213 
    1314 
  • trunk/src/save.c

    r11 r15  
    1010 
    1111#include "angband.h" 
    12  
    13  
    14 #ifdef FUTURE_SAVEFILES 
    15  
    16 /* 
    17  * XXX XXX XXX Ignore this for now... 
    18  * 
    19  * The basic format of Angband 2.8.0 (and later) savefiles is simple. 
    20  * 
    21  * The savefile itself is a "header" (4 bytes) plus a series of "blocks", 
    22  * plus, perhaps, some form of "footer" at the end. 
    23  * 
    24  * The "header" contains information about the "version" of the savefile. 
    25  * Conveniently, pre-2.8.0 savefiles also use a 4 byte header, though the 
    26  * interpretation of the "sf_extra" byte is very different.  Unfortunately, 
    27  * savefiles from Angband 2.5.X reverse the sf_major and sf_minor fields, 
    28  * and must be handled specially, until we decide to start ignoring them. 
    29  * 
    30  * Each "block" is a "type" (2 bytes), plus a "size" (2 bytes), plus "data", 
    31  * plus a "check" (2 bytes), plus a "stamp" (2 bytes).  The format of the 
    32  * "check" and "stamp" bytes is still being contemplated, but it would be 
    33  * nice for one to be a simple byte-checksum, and the other to be a complex 
    34  * additive checksum of some kind.  Both should be zero if the block is empty. 
    35  * 
    36  * Standard types: 
    37  *   TYPE_BIRTH --> creation info 
    38  *   TYPE_OPTIONS --> option settings 
    39  *   TYPE_MESSAGES --> message recall 
    40  *   TYPE_PLAYER --> player information 
    41  *   TYPE_SPELLS --> spell information 
    42  *   TYPE_INVEN --> player inven/equip 
    43  *   TYPE_STORES --> store information 
    44  *   TYPE_RACES --> monster race data 
    45  *   TYPE_KINDS --> object kind data 
    46  *   TYPE_UNIQUES --> unique info 
    47  *   TYPE_ARTIFACTS --> artifact info 
    48  *   TYPE_QUESTS --> quest info 
    49  * 
    50  * Dungeon information: 
    51  *   TYPE_DUNGEON --> dungeon info 
    52  *   TYPE_FEATURES --> dungeon features 
    53  *   TYPE_OBJECTS --> dungeon objects 
    54  *   TYPE_MONSTERS --> dungeon monsters 
    55  * 
    56  * Conversions: 
    57  *   Break old "races" into normals/uniques 
    58  *   Extract info about the "unique" monsters 
    59  * 
    60  * Question: 
    61  *   Should there be a single "block" for info about all the stores, or one 
    62  *   "block" for each store?  Or one "block", which contains "sub-blocks" of 
    63  *   some kind?  Should we dump every "sub-block", or just the "useful" ones? 
    64  * 
    65  * Question: 
    66  *   Should the normals/uniques be broken for 2.8.0, or should 2.8.0 simply 
    67  *   be a "fixed point" into which older savefiles are converted, and then 
    68  *   future versions could ignore older savefiles, and the "conversions" 
    69  *   would be much simpler. 
    70  */ 
    71  
    72  
    73 /* 
    74  * XXX XXX XXX 
    75  */ 
    76 #define TYPE_OPTIONS 17362 
    77  
    78  
    79 /* 
    80  * Hack -- current savefile 
    81  */ 
    82 static int data_fd = -1; 
    83  
    84  
    85 /* 
    86  * Hack -- current block type 
    87  */ 
    88 static u16b data_type; 
    89  
    90 /* 
    91  * Hack -- current block size 
    92  */ 
    93 static u16b data_size; 
    94  
    95 /* 
    96  * Hack -- pointer to the data buffer 
    97  */ 
    98 static byte *data_head; 
    99  
    100 /* 
    101  * Hack -- pointer into the data buffer 
    102  */ 
    103 static byte *data_next; 
    104  
    105  
    106  
    107 /* 
    108  * Hack -- write the current "block" to the savefile 
    109  */ 
    110 static errr wr_block(void) 
    111 
    112         errr err; 
    113  
    114         byte fake[4]; 
    115  
    116         /* Save the type and size */ 
    117         fake[0] = (byte)(data_type); 
    118         fake[1] = (byte)(data_type >> 8); 
    119         fake[2] = (byte)(data_size); 
    120         fake[3] = (byte)(data_size >> 8); 
    121  
    122         /* Dump the head */ 
    123         err = fd_write(data_fd, (cptr)&fake, sizeof(fake)); 
    124  
    125         /* Dump the actual data */ 
    126         err = fd_write(data_fd, (cptr)data_head, data_size); 
    127  
    128         /* XXX XXX XXX */ 
    129         fake[0] = 0; 
    130         fake[1] = 0; 
    131         fake[2] = 0; 
    132         fake[3] = 0; 
    133  
    134         /* Dump the tail */ 
    135         err = fd_write(data_fd, (cptr)&fake, sizeof(fake)); 
    136  
    137         /* Hack -- reset */ 
    138         data_next = data_head; 
    139  
    140         /* Wipe the data block */ 
    141         C_WIPE(data_head, 65535, byte); 
    142  
    143         /* Success */ 
    144         return (0); 
    145 
    146  
    147  
    148  
    149 /* 
    150  * Hack -- add data to the current block 
    151  */ 
    152 static void put_byte(byte v) 
    153 
    154         *data_next++ = v; 
    155 
    156  
    157 /* 
    158  * Hack -- add data to the current block 
    159  */ 
    160 static void put_char(char v) 
    161 
    162         put_byte((byte)(v)); 
    163 
    164  
    165 /* 
    166  * Hack -- add data to the current block 
    167  */ 
    168 static void put_u16b(u16b v) 
    169 
    170         *data_next++ = (byte)(v); 
    171         *data_next++ = (byte)(v >> 8); 
    172 
    173  
    174 /* 
    175  * Hack -- add data to the current block 
    176  */ 
    177 static void put_s16b(s16b v) 
    178 
    179         put_u16b((u16b)(v)); 
    180 
    181  
    182 /* 
    183  * Hack -- add data to the current block 
    184  */ 
    185 static void put_u32b(u32b v) 
    186 
    187         *data_next++ = (byte)(v); 
    188         *data_next++ = (byte)(v >> 8); 
    189         *data_next++ = (byte)(v >> 16); 
    190         *data_next++ = (byte)(v >> 24); 
    191 
    192  
    193 /* 
    194  * Hack -- add data to the current block 
    195  */ 
    196 static void put_s32b(s32b v) 
    197 
    198         put_u32b((u32b)(v)); 
    199 
    200  
    201 /* 
    202  * Hack -- add data to the current block 
    203  */ 
    204 static void put_string(char *str) 
    205 
    206         while ((*data_next++ = *str++) != '\0'); 
    207 
    208  
    209  
    210  
    211 /* 
    212  * Write a savefile for Angband 2.8.0 
    213  */ 
    214 static errr wr_savefile(void) 
    215 
    216         int i; 
    217  
    218         u32b now; 
    219  
    220         byte tmp8u; 
    221         u16b tmp16u; 
    222  
    223         errr err; 
    224  
    225         byte fake[4]; 
    226  
    227  
    228         /*** Hack -- extract some data ***/ 
    229  
    230         /* Hack -- Get the current time */ 
    231         now = time((time_t*)(NULL)); 
    232  
    233         /* Note the operating system */ 
    234         sf_xtra = 0L; 
    235  
    236         /* Note when the file was saved */ 
    237         sf_when = now; 
    238  
    239         /* Note the number of saves */ 
    240         sf_saves++; 
    241  
    242  
    243         /*** Actually write the file ***/ 
    244  
    245         /* Open the file XXX XXX XXX */ 
    246         data_fd = -1; 
    247  
    248         /* Dump the version */ 
    249         fake[0] = (byte)(VERSION_MAJOR); 
    250         fake[1] = (byte)(VERSION_MINOR); 
    251         fake[2] = (byte)(VERSION_PATCH); 
    252         fake[3] = (byte)(VERSION_EXTRA); 
    253  
    254         /* Dump the data */ 
    255         err = fd_write(data_fd, (cptr)&fake, sizeof(fake)); 
    256  
    257  
    258         /* Make array XXX XXX XXX */ 
    259         C_MAKE(data_head, 65535, byte); 
    260  
    261         /* Hack -- reset */ 
    262         data_next = data_head; 
    263  
    264  
    265 #if 0 
    266         /* Operating system */ 
    267         wr_u32b(sf_xtra); 
    268  
    269         /* Time file last saved */ 
    270         wr_u32b(sf_when); 
    271  
    272         /* Number of past lives */ 
    273         wr_u16b(sf_lives); 
    274  
    275         /* Number of times saved */ 
    276         wr_u16b(sf_saves); 
    277  
    278         /* XXX XXX XXX */ 
    279  
    280         /* Set the type */ 
    281         data_type = TYPE_BASIC; 
    282  
    283         /* Set the "options" size */ 
    284         data_size = (data_next - data_head); 
    285  
    286         /* Write the block */ 
    287         wr_block(); 
    288 #endif 
    289  
    290  
    291         /* Dump the "options" */ 
    292         put_options(); 
    293  
    294         /* Set the type */ 
    295         data_type = TYPE_OPTIONS; 
    296  
    297         /* Set the "options" size */ 
    298         data_size = (data_next - data_head); 
    299  
    300         /* Write the block */ 
    301         wr_block(); 
    302  
    303         /* XXX XXX XXX */ 
    304  
    305 #if 0 
    306  
    307         /* Dump the "messages" */ 
    308  
    309         /* Dump the number of "messages" */ 
    310         tmp16u = message_num(); 
    311         if (compress_savefile && (tmp16u > 40)) tmp16u = 40; 
    312         wr_u16b(tmp16u); 
    313  
    314         /* Dump the messages and types (oldest first!) */ 
    315         for (i = tmp16u - 1; i >= 0; i--) 
    316         { 
    317                 wr_string(message_str(i)); 
    318                 wr_u16b(message_type(i)); 
    319         } 
    320  
    321         /* Dump the monster lore */ 
    322         tmp16u = z_info->r_max; 
    323         wr_u16b(tmp16u); 
    324         for (i = 0; i < tmp16u; i++) wr_lore(i); 
    325  
    326  
    327         /* Dump the object memory */ 
    328         tmp16u = z_info->k_max; 
    329         wr_u16b(tmp16u); 
    330         for (i = 0; i < tmp16u; i++) wr_xtra(i); 
    331  
    332  
    333         /* Hack -- Dump the quests */ 
    334         tmp16u = MAX_Q_IDX; 
    335         wr_u16b(tmp16u); 
    336         for (i = 0; i < tmp16u; i++) 
    337         { 
    338                 wr_byte(q_list[i].level); 
    339                 wr_byte(0); 
    340                 wr_byte(0); 
    341                 wr_byte(0); 
    342         } 
    343  
    344         /* Hack -- Dump the artifacts */ 
    345         tmp16u = z_info->a_max; 
    346         wr_u16b(tmp16u); 
    347         for (i = 0; i < tmp16u; i++) 
    348         { 
    349                 artifact_type *a_ptr = &a_info[i]; 
    350                 wr_byte(a_ptr->cur_num); 
    351                 wr_byte(0); 
    352                 wr_byte(0); 
    353                 wr_byte(0); 
    354         } 
    355  
    356  
    357  
    358         /* Write the "extra" information */ 
    359         wr_extra(); 
    360  
    361  
    362         /* Dump the "player hp" entries */ 
    363         tmp16u = PY_MAX_LEVEL; 
    364         wr_u16b(tmp16u); 
    365         for (i = 0; i < tmp16u; i++) 
    366         { 
    367                 wr_s16b(player_hp[i]); 
    368         } 
    369  
    370  
    371         /* Write spell data */ 
    372         wr_u32b(spell_learned1); 
    373         wr_u32b(spell_learned2); 
    374         wr_u32b(spell_worked1); 
    375         wr_u32b(spell_worked2); 
    376         wr_u32b(spell_forgotten1); 
    377         wr_u32b(spell_forgotten2); 
    378  
    379         /* Dump the ordered spells */ 
    380         for (i = 0; i < PY_MAX_SPELLS; i++) 
    381         { 
    382                 wr_byte(spell_order[i]); 
    383         } 
    384  
    385  
    386         /* Write the inventory */ 
    387         for (i = 0; i < INVEN_TOTAL; i++) 
    388         { 
    389                 object_type *o_ptr = &inventory[i]; 
    390  
    391                 /* Skip non-objects */ 
    392                 if (!o_ptr->k_idx) continue; 
    393  
    394                 /* Dump index */ 
    395                 wr_u16b(i); 
    396  
    397                 /* Dump object */ 
    398                 wr_item(o_ptr); 
    399         } 
    400  
    401         /* Add a sentinel */ 
    402         wr_u16b(0xFFFF); 
    403  
    404  
    405         /* Note the stores */ 
    406         tmp16u = MAX_STORES; 
    407         wr_u16b(tmp16u); 
    408  
    409         /* Dump the stores */ 
    410         for (i = 0; i < tmp16u; i++) wr_store(&store[i]); 
    411  
    412  
    413         /* Player is not dead, write the dungeon */ 
    414         if (!p_ptr->is_dead) 
    415         { 
    416                 /* Dump the dungeon */ 
    417                 wr_dungeon(); 
    418  
    419                 /* Dump the ghost */ 
    420                 wr_ghost(); 
    421         } 
    422  
    423 #endif 
    424  
    425         /* Dump the "final" marker XXX XXX XXX */ 
    426         /* Type zero, Size zero, Contents zero, etc */ 
    427  
    428  
    429         /* XXX XXX XXX Check for errors */ 
    430  
    431  
    432         /* Kill array XXX XXX XXX */ 
    433         KILL(data_head); 
    434  
    435  
    436         /* Success */ 
    437         return (0); 
    438 
    439  
    440  
    441  
    442  
    443  
    444 /* 
    445  * Hack -- read the next "block" from the savefile 
    446  */ 
    447 static errr rd_block(void) 
    448 
    449         errr err; 
    450  
    451         byte fake[4]; 
    452  
    453         /* Read the head data */ 
    454         err = fd_read(data_fd, (char*)&fake, sizeof(fake)); 
    455  
    456         /* Extract the type and size */ 
    457         data_type = (fake[0] | ((u16b)fake[1] << 8)); 
    458         data_size = (fake[2] | ((u16b)fake[3] << 8)); 
    459  
    460         /* Wipe the data block */ 
    461         C_WIPE(data_head, 65535, byte); 
    462  
    463         /* Read the actual data */ 
    464         err = fd_read(data_fd, (char*)data_head, data_size); 
    465  
    466         /* Read the tail data */ 
    467         err = fd_read(data_fd, (char*)&fake, sizeof(fake)); 
    468  
    469         /* XXX XXX XXX Verify */ 
    470  
    471         /* Hack -- reset */ 
    472         data_next = data_head; 
    473  
    474         /* Success */ 
    475         return (0); 
    476 
    477  
    478  
    479 /* 
    480  * Hack -- get data from the current block 
    481  */ 
    482 static void get_byte(byte *ip) 
    483 
    484         byte d1; 
    485         d1 = (*data_next++); 
    486         (*ip) = (d1); 
    487 
    488  
    489 /* 
    490  * Hack -- get data from the current block 
    491  */ 
    492 static void get_char(char *ip) 
    493 
    494         get_byte((byte*)ip); 
    495 
    496  
    497 /* 
    498  * Hack -- get data from the current block 
    499  */ 
    500 static void get_u16b(u16b *ip) 
    501 
    502         u16b d0, d1; 
    503         d0 = (*data_next++); 
    504         d1 = (*data_next++); 
    505         (*ip) = (d0 | (d1 << 8)); 
    506 
    507  
    508 /* 
    509  * Hack -- get data from the current block 
    510  */ 
    511 static void get_s16b(s16b *ip) 
    512 
    513         get_u16b((u16b*)ip); 
    514 
    515  
    516 /* 
    517  * Hack -- get data from the current block 
    518  */ 
    519 static void get_u32b(u32b *ip) 
    520 
    521         u32b d0, d1, d2, d3; 
    522         d0 = (*data_next++); 
    523         d1 = (*data_next++); 
    524         d2 = (*data_next++); 
    525         d3 = (*data_next++); 
    526         (*ip) = (d0 | (d1 << 8) | (d2 << 16) | (d3 << 24)); 
    527 
    528  
    529 /* 
    530  * Hack -- get data from the current block 
    531  */ 
    532 static void get_s32b(s32b *ip) 
    533 
    534         get_u32b((u32b*)ip); 
    535 
    536  
    537  
    538  
    539 /* 
    540  * Read a savefile for Angband 2.8.0 
    541  */ 
    542 static errr rd_savefile(void) 
    543 
    544         bool done = FALSE; 
    545  
    546         byte fake[4]; 
    547  
    548  
    549         /* Open the savefile */ 
    550         data_fd = fd_open(savefile, O_RDONLY); 
    551  
    552         /* No file */ 
    553         if (data_fd < 0) return (1); 
    554  
    555         /* Strip the first four bytes (see below) */ 
    556         if (fd_read(data_fd, (char*)(fake), sizeof(fake))) return (1); 
    557  
    558  
    559         /* Make array XXX XXX XXX */ 
    560         C_MAKE(data_head, 65535, byte); 
    561  
    562         /* Hack -- reset */ 
    563         data_next = data_head; 
    564  
    565  
    566         /* Read blocks */ 
    567         while (!done) 
    568         { 
    569                 /* Read the block */ 
    570                 if (rd_block()) break; 
    571  
    572                 /* Analyze the type */ 
    573                 switch (data_type) 
    574                 { 
    575                         /* Done XXX XXX XXX */ 
    576                         case 0: 
    577                         { 
    578                                 done = TRUE; 
    579                                 break; 
    580                         } 
    581  
    582                         /* Grab the options */ 
    583                         case TYPE_OPTIONS: 
    584                         { 
    585                                 if (get_options()) err = -1; 
    586                                 break; 
    587                         } 
    588                 } 
    589  
    590                 /* XXX XXX XXX verify "data_next" */ 
    591                 if (data_next - data_head > data_size) break; 
    592         } 
    593  
    594  
    595         /* XXX XXX XXX Check for errors */ 
    596  
    597  
    598         /* Kill array XXX XXX XXX */ 
    599         KILL(data_head); 
    600  
    601  
    602         /* Success */ 
    603         return (0); 
    604 
    605  
    606  
    607 #endif /* FUTURE_SAVEFILES */ 
     12#include "z-file.h" 
    60813 
    60914 
  • trunk/src/squelch.c

    r1 r15  
    1010 */ 
    1111#include "angband.h" 
     12#include "z-file.h" 
    1213 
    1314/* Structure to describe tval/description pairings. */ 
  • trunk/src/util.c

    r1 r15  
    1414 
    1515#ifdef SET_UID 
    16  
    1716# ifndef HAVE_USLEEP 
    1817 
     
    4544 
    4645# endif /* HAVE_USLEEP */ 
    47  
    48  
    49 /* 
    50  * Find a default user name from the system. 
    51  */ 
    52 void user_name(char *buf, size_t len, int id) 
    53 { 
    54         struct passwd *pw; 
    55  
    56         /* Look up the user name */ 
    57         if ((pw = getpwuid(id))) 
    58         { 
    59                 /* Get the first 15 characters of the user name */ 
    60                 my_strcpy(buf, pw->pw_name, len); 
    61  
    62 #ifdef CAPITALIZE_USER_NAME 
    63                 /* Hack -- capitalize the user name */ 
    64                 if (islower((unsigned char)buf[0])) 
    65                         buf[0] = toupper((unsigned char)buf[0]); 
    66 #endif /* CAPITALIZE_USER_NAME */ 
    67  
    68                 return; 
    69         } 
    70  
    71         /* Oops.  Hack -- default to "PLAYER" */ 
    72         my_strcpy(buf, "PLAYER", len); 
    73 } 
    74  
    7546#endif /* SET_UID */ 
    76  
    77  
    78 /* 
    79  * The concept of the "file" routines below (and elsewhere) is that all 
    80  * file handling should be done using as few routines as possible, since 
    81  * every machine is slightly different, but these routines always have the 
    82  * same semantics. 
    83  * 
    84  * In fact, perhaps we should use the "path_parse()" routine below to convert 
    85  * from "canonical" filenames (optional leading tilde's, internal wildcards, 
    86  * slash as the path seperator, etc) to "system" filenames (no special symbols, 
    87  * system-specific path seperator, etc).  This would allow the program itself 
    88  * to assume that all filenames are "Unix" filenames, and explicitly "extract" 
    89  * such filenames if needed (by "path_parse()", or perhaps "path_canon()"). 
    90  * 
    91  * Note that "path_temp" should probably return a "canonical" filename. 
    92  * 
    93  * Note that "my_fopen()" and "my_open()" and "my_make()" and "my_kill()" 
    94  * and "my_move()" and "my_copy()" should all take "canonical" filenames. 
    95  * 
    96  * Note that "canonical" filenames use a leading "slash" to indicate an absolute 
    97  * path, and a leading "tilde" to indicate a special directory, and default to a 
    98  * relative path, but MSDOS uses a leading "drivename plus colon" to indicate the 
    99  * use of a "special drive", and then the rest of the path is parsed "normally", 
    100  * and MACINTOSH uses a leading colon to indicate a relative path, and an embedded 
    101  * colon to indicate a "drive plus absolute path", and finally defaults to a file 
    102  * in the current working directory, which may or may not be defined. 
    103  * 
    104  * We should probably parse a leading "~~/" as referring to "ANGBAND_DIR". (?) 
    105  */ 
    106  
    107  
    108 #ifdef RISCOS 
    109  
    110  
    111 /* 
    112  * Most of the "file" routines for "RISCOS" should be in "main-ros.c" 
    113  */ 
    114  
    115  
    116 #else /* RISCOS */ 
    117  
    118 #if defined(SET_UID) || defined(USE_PRIVATE_PATHS) 
    119  
    120 /* 
    121  * Extract a "parsed" path from an initial filename 
    122  * Normally, we simply copy the filename into the buffer 
    123  * But leading tilde symbols must be handled in a special way 
    124  * Replace "~user/" by the home directory of the user named "user" 
    125  * Replace "~/" by the home directory of the current user 
    126  */ 
    127 errr path_parse(char *buf, size_t max, cptr file) 
    128 { 
    129         cptr u, s; 
    130         struct passwd   *pw; 
    131         char user[128]; 
    132  
    133  
    134         /* Assume no result */ 
    135         buf[0] = '\0'; 
    136  
    137         /* No file? */ 
    138         if (!file) return (-1); 
    139  
    140         /* File needs no parsing */ 
    141         if (file[0] != '~') 
    142         { 
    143                 my_strcpy(buf, file, max); 
    144                 return (0); 
    145         } 
    146  
    147         /* Point at the user */ 
    148         u = file+1; 
    149  
    150         /* Look for non-user portion of the file */ 
    151         s = strstr(u, PATH_SEP); 
    152  
    153         /* Hack -- no long user names */ 
    154         if (s && (s >= u + sizeof(user))) return (1); 
    155  
    156         /* Extract a user name */ 
    157         if (s) 
    158         { 
    159                 int i; 
    160                 for (i = 0; u < s; ++i) user[i] = *u++; 
    161                 user[i] = '\0'; 
    162                 u = user; 
    163         } 
    164  
    165         /* Look up the "current" user */ 
    166         if (u[0] == '\0') u = getlogin(); 
    167  
    168         /* Look up a user (or "current" user) */ 
    169         if (u) pw = getpwnam(u); 
    170         else pw = getpwuid(getuid()); 
    171  
    172         /* Nothing found? */ 
    173         if (!pw) return (1); 
    174  
    175         /* Make use of the info */ 
    176         my_strcpy(buf, pw->pw_dir, max); 
    177  
    178         /* Append the rest of the filename, if any */ 
    179         if (s) my_strcat(buf, s, max); 
    180  
    181         /* Success */ 
    182         return (0); 
    183 } 
    184  
    185  
    186 #else /* SET_UID */ 
    187  
    188  
    189 /* 
    190  * Extract a "parsed" path from an initial filename 
    191  * 
    192  * This requires no special processing on simple machines, 
    193  * except for verifying the size of the filename. 
    194  */ 
    195 errr path_parse(char *buf, size_t max, cptr file) 
    196 { 
    197         /* Accept the filename */ 
    198         my_strcpy(buf, file, max); 
    199  
    200 # ifdef MACH_O_CARBON 
    201  
    202         /* Fix it according to the current operating system */ 
    203         convert_pathname(buf); 
    204  
    205 # endif 
    206  
    207         /* Success */ 
    208         return (0); 
    209 } 
    210  
    211  
    212 #endif /* SET_UID */ 
    213  
    214  
    215 #ifndef HAVE_MKSTEMP 
    216  
    217 /* 
    218  * Hack -- acquire a "temporary" file name if possible 
    219  * 
    220  * This filename is always in "system-specific" form. 
    221  */ 
    222 static errr path_temp(char *buf, size_t max) 
    223 { 
    224         cptr s; 
    225  
    226         /* Temp file */ 
    227         s = tmpnam(NULL); 
    228  
    229         /* Oops */ 
    230         if (!s) return (-1); 
    231  
    232         /* Copy to buffer */ 
    233         my_strcpy(buf, s, max); 
    234  
    235         /* Success */ 
    236         return (0); 
    237 } 
    238  
    239 #endif /* HAVE_MKSTEMP */ 
    240  
    241  
    242 /* 
    243  * Create a new path by appending a file (or directory) to a path 
    244  * 
    245  * This requires no special processing on simple machines, except 
    246  * for verifying the size of the filename, but note the ability to 
    247  * bypass the given "path" with certain special file-names. 
    248  * 
    249  * Note that the "file" may actually be a "sub-path", including 
    250  * a path and a file. 
    251  * 
    252  * Note that this function yields a path which must be "parsed" 
    253  * using the "parse" function above. 
    254  */ 
    255 errr path_build(char *buf, size_t max, cptr path, cptr file) 
    256 { 
    257         /* Special file */ 
    258         if (file[0] == '~') 
    259         { 
    260                 /* Use the file itself */ 
    261                 my_strcpy(buf, file, max); 
    262         } 
    263  
    264         /* Absolute file, on "normal" systems */ 
    265         else if (prefix(file, PATH_SEP) && !streq(PATH_SEP, "")) 
    266         { 
    267                 /* Use the file itself */ 
    268                 my_strcpy(buf, file, max); 
    269         } 
    270  
    271         /* No path given */ 
    272         else if (!path[0]) 
    273         { 
    274                 /* Use the file itself */ 
    275                 my_strcpy(buf, file, max); 
    276         }