Changeset 469

Show
Ignore:
Timestamp:
08/09/07 09:07:11 (1 year ago)
Author:
takkaria
Message:

Move file handling across to a new API. (#137) Sorry if this landing screws anyone up.

main-gtk is untouched, because I don't want to conflict with the work that's been going on outside the repository on main-gtk.

Showing scores from the commandline seems broken right now, but other than that, this works fine on at least Linux and Windows.

Tests included in a hacked-together file; may prove useful to e.g. making sure it works on OS X.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/configure.ac

    r399 r469  
    194194AC_C_CONST 
    195195AC_TYPE_SIGNAL 
    196 AC_CHECK_FUNCS([mkstemp setresgid setegid can_change_color]) 
     196AC_CHECK_FUNCS([setresgid setegid can_change_color stat]) 
    197197 
    198198 
  • trunk/src/Makefile.std

    r226 r469  
    8080CFLAGS += $(patsubst -l%,,$(MODULES)) $(INCLUDES) 
    8181LIBS += $(patsubst -D%,,$(patsubst -I%,, $(MODULES))) 
    82  
    83  
    84 # Extract system we're running on 
    85 uname = $(shell uname -s) 
    86  
    87 # Enable linux-specific modules, if requested. 
    88 ifeq ($(uname),Linux) 
    89   CFLAGS += -DHAVE_MKSTEMP 
    90 endif 
    9182 
    9283 
  • trunk/src/cmd4.c

    r463 r469  
    213213                                byte c, byte attr_top, byte char_left); 
    214214 
    215 static void dump_pref_file(void (*dump)(FILE*), const char *title, int row); 
     215static void dump_pref_file(void (*dump)(ang_file *), const char *title, int row); 
    216216 
    217217/* 
     
    25382538 
    25392539/* 
    2540  * Header and footer marker string for pref file dumps 
     2540 * Header and footer marker string for pref file dumps 
    25412541 */ 
    25422542static cptr dump_separator = "#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#"; 
     
    25462546 * Remove old lines from pref files 
    25472547 */ 
    2548 static void remove_old_dump(const char *orig_file, const char *mark) 
    2549 
    2550         FILE *tmp_fff, *orig_fff; 
    2551  
    2552         char tmp_file[1024]; 
    2553         char buf[1024]; 
     2548static void remove_old_dump(const char *cur_fname, const char *mark) 
     2549
    25542550        bool between_marks = FALSE; 
    25552551        bool changed = FALSE; 
    2556         char expected_line[1024]; 
    2557  
    2558  
    2559         /* Open an old dump file in read-only mode */ 
    2560         orig_fff = my_fopen(orig_file, "r"); 
    2561  
    2562         /* If original file does not exist, nothing to do */ 
    2563         if (!orig_fff) return; 
    2564  
    2565         /* Open a new temporary file */ 
    2566         tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file)); 
    2567  
    2568         if (!tmp_fff) 
    2569         { 
    2570                         msg_format("Failed to create temporary file %s.", tmp_file); 
    2571                         msg_print(NULL); 
    2572                         return; 
    2573         } 
     2552 
     2553        char buf[1024]; 
     2554 
     2555        char start_line[1024]; 
     2556        char end_line[1024]; 
     2557 
     2558        char new_fname[1024]; 
     2559 
     2560        ang_file *new_file; 
     2561        ang_file *cur_file; 
     2562 
     2563 
     2564        /* Format up some filenames */ 
     2565        strnfmt(new_fname, sizeof(new_fname), "%s.new", cur_fname); 
    25742566 
    25752567        /* Work out what we expect to find */ 
    2576         strnfmt(expected_line, sizeof(expected_line), "%s begin %s", dump_separator, mark); 
     2568        strnfmt(start_line, sizeof(start_line), "%s begin %s", dump_separator, mark); 
     2569        strnfmt(end_line,   sizeof(end_line),   "%s end %s",   dump_separator, mark); 
     2570 
     2571 
     2572 
     2573        /* Open current file */ 
     2574        cur_file = file_open(cur_fname, MODE_READ, -1); 
     2575        if (!cur_file) return; 
     2576 
     2577        /* Open new file */ 
     2578        new_file = file_open(new_fname, MODE_WRITE, FTYPE_TEXT); 
     2579        if (!new_file) 
     2580        { 
     2581                msg_format("Failed to create file %s", new_fname); 
     2582                return; 
     2583        } 
    25772584 
    25782585        /* Loop for every line */ 
    2579         while (TRUE) 
    2580         { 
    2581                 /* Read a line */ 
    2582                 if (my_fgets(orig_fff, buf, sizeof(buf))) 
    2583                 { 
    2584                         /* End of file but no end marker */ 
    2585                         if (between_marks) changed = FALSE; 
    2586  
    2587                         break; 
    2588                 } 
    2589  
    2590                 /* Is this line a header/footer? */ 
    2591                 if (strncmp(buf, dump_separator, strlen(dump_separator)) == 0) 
    2592                 { 
    2593                         /* Found the expected line? */ 
    2594                         if (strcmp(buf, expected_line) == 0) 
    2595                         { 
    2596                                 if (!between_marks) 
    2597                                 { 
    2598                                         /* Expect the footer next */ 
    2599                                         strnfmt(expected_line, sizeof(expected_line), 
    2600                                                 "%s end %s", dump_separator, mark); 
    2601  
    2602                                         between_marks = TRUE; 
    2603  
    2604                                         /* There are some changes */ 
    2605                                         changed = TRUE; 
    2606                                 } 
    2607                                 else 
    2608                                 { 
    2609                                         /* Expect a header next - XXX shouldn't happen */ 
    2610                                         strnfmt(expected_line, sizeof(expected_line), 
    2611                                                 "%s begin %s", dump_separator, mark); 
    2612  
    2613                                         between_marks = FALSE; 
    2614  
    2615                                         /* Next line */ 
    2616                                         continue; 
    2617                                 } 
    2618                         } 
    2619  
    2620                         /* Found a different line */ 
    2621                         else 
    2622                         { 
    2623                                 /* Expected a footer and got something different? */ 
    2624                                 if (between_marks) 
    2625                                 { 
    2626                                         /* Abort */ 
    2627                                         changed = FALSE; 
    2628                                         break; 
    2629                                 } 
    2630                         } 
     2586        while (file_getl(cur_file, buf, sizeof(buf))) 
     2587        { 
     2588                /* If we find the start line, turn on */ 
     2589                if (!strcmp(buf, start_line)) 
     2590                { 
     2591                        between_marks = TRUE; 
     2592                } 
     2593 
     2594                /* If we find the finish line, turn off */ 
     2595                else if (!strcmp(buf, end_line)) 
     2596                { 
     2597                        between_marks = FALSE; 
     2598                        changed = TRUE; 
    26312599                } 
    26322600 
     
    26342602                { 
    26352603                        /* Copy orginal line */ 
    2636                         fprintf(tmp_fff, "%s\n", buf); 
     2604                        file_putf(new_file, "%s\n", buf); 
    26372605                } 
    26382606        } 
    26392607 
    26402608        /* Close files */ 
    2641         my_fclose(orig_fff); 
    2642         my_fclose(tmp_fff); 
    2643  
    2644         /* If there are changes, overwrite the original file with the new one */ 
     2609        file_close(cur_file); 
     2610        file_close(new_file); 
     2611 
     2612        /* If there are changes, move things around */ 
    26452613        if (changed) 
    26462614        { 
    2647                 /* Copy contents of temporary file */ 
    2648                 tmp_fff = my_fopen(tmp_file, "r"); 
    2649                 orig_fff = my_fopen(orig_file, "w"); 
    2650  
    2651                 while (!my_fgets(tmp_fff, buf, sizeof(buf))) 
    2652                         fprintf(orig_fff, "%s\n", buf); 
    2653  
    2654                 my_fclose(orig_fff); 
    2655                 my_fclose(tmp_fff); 
    2656         } 
    2657  
    2658         /* Kill the temporary file */ 
    2659         fd_kill(tmp_file); 
     2615                char old_fname[1024]; 
     2616                strnfmt(old_fname, sizeof(old_fname), "%s.old", cur_fname); 
     2617 
     2618                if (file_move(cur_fname, old_fname)) 
     2619                { 
     2620                        file_move(new_fname, cur_fname); 
     2621                        file_delete(old_fname); 
     2622                } 
     2623        } 
     2624 
     2625        /* Otherwise just destroy the new file */ 
     2626        else 
     2627        { 
     2628                file_delete(new_fname); 
     2629        } 
    26602630} 
    26612631 
     
    26642634 * Output the header of a pref-file dump 
    26652635 */ 
    2666 static void pref_header(FILE *fff, const char *mark) 
     2636static void pref_header(ang_file *fff, const char *mark) 
    26672637{ 
    26682638        /* Start of dump */ 
    2669         fprintf(fff, "%s begin %s\n", dump_separator, mark); 
    2670  
    2671         fprintf(fff, "# *Warning!*  The lines below are an automatic dump.\n"); 
    2672         fprintf(fff, "# Don't edit them; changes will be deleted and replaced automatically.\n"); 
     2639        file_putf(fff, "%s begin %s\n", dump_separator, mark); 
     2640 
     2641        file_putf(fff, "# *Warning!*  The lines below are an automatic dump.\n"); 
     2642        file_putf(fff, "# Don't edit them; changes will be deleted and replaced automatically.\n"); 
    26732643} 
    26742644 
     
    26762646 * Output the footer of a pref-file dump 
    26772647 */ 
    2678 static void pref_footer(FILE *fff, const char *mark) 
    2679 { 
    2680         fprintf(fff, "# *Warning!*  The lines above are an automatic dump.\n"); 
    2681         fprintf(fff, "# Don't edit them; changes will be deleted and replaced automatically.\n"); 
     2648static void pref_footer(ang_file *fff, const char *mark) 
     2649{ 
     2650        file_putf(fff, "# *Warning!*  The lines above are an automatic dump.\n"); 
     2651        file_putf(fff, "# Don't edit them; changes will be deleted and replaced automatically.\n"); 
    26822652 
    26832653        /* End of dump */ 
    2684         fprintf(fff, "%s end %s\n", dump_separator, mark); 
     2654        file_putf(fff, "%s end %s\n", dump_separator, mark); 
    26852655} 
    26862656 
     
    26932663 *   Comments are generated automatically 
    26942664 */ 
    2695 static void dump_pref_file(void (*dump)(FILE*), const char *title, int row) 
     2665static void dump_pref_file(void (*dump)(ang_file *), const char *title, int row) 
    26962666{ 
    26972667        char ftmp[80]; 
    26982668        char buf[1025]; 
    2699         FILE *fff; 
     2669        ang_file *fff; 
    27002670 
    27012671        /* Prompt */ 
     
    27142684        path_build(buf, 1024, ANGBAND_DIR_USER, ftmp); 
    27152685 
    2716         FILE_TYPE(FILE_TYPE_TEXT); 
    2717  
    27182686        /* Remove old macros */ 
    27192687        remove_old_dump(buf, title); 
    27202688 
    27212689        /* Append to the file */ 
    2722         fff = my_fopen(buf, "a"); 
    2723  
    2724         /* Failure */ 
     2690        fff = file_open(buf, MODE_APPEND, FTYPE_TEXT); 
    27252691        if (!fff) 
    27262692        { 
     
    27342700 
    27352701        /* Skip some lines */ 
    2736         fprintf(fff, "\n\n"); 
     2702        file_putf(fff, "\n\n"); 
    27372703 
    27382704        /* Start dumping */ 
    2739         fprintf(fff, "# %s definitions\n\n", strstr(title, " ")); 
     2705        file_putf(fff, "# %s definitions\n\n", strstr(title, " ")); 
    27402706         
    27412707        dump(fff); 
    27422708 
    27432709        /* All done */ 
    2744         fprintf(fff, "\n\n\n"); 
     2710        file_putf(fff, "\n\n\n"); 
    27452711 
    27462712        /* Output footer */ 
     
    27482714 
    27492715        /* Close */ 
    2750         my_fclose(fff); 
     2716        file_close(fff); 
    27512717 
    27522718        /* Message */ 
     
    27582724 * Save autoinscription data to a pref file. 
    27592725 */ 
    2760 static void autoinsc_dump(FILE *fff) 
     2726static void autoinsc_dump(ang_file *fff) 
    27612727{ 
    27622728        int i; 
    2763  
    2764         if (!inscriptions) 
    2765                 return; 
    2766  
    2767         /* Start dumping */ 
    2768         fprintf(fff, "# Autoinscription settings"); 
    2769         fprintf(fff, "# B:item kind:inscription\n\n"); 
     2729        if (!inscriptions) return; 
     2730 
     2731        file_putf(fff, "# Autoinscription settings\n"); 
     2732        file_putf(fff, "# B:item kind:inscription\n\n"); 
    27702733 
    27712734        for (i = 0; i < inscriptions_count; i++) 
     
    27732736                object_kind *k_ptr = &k_info[inscriptions[i].kind_idx]; 
    27742737 
    2775                 /* Describe and write */ 
    2776                 fprintf(fff, "# Autoinscription for %s\n", k_name + k_ptr->name); 
    2777                 fprintf(fff, "B:%d:%s\n\n", inscriptions[i].kind_idx, 
     2738                file_putf(fff, "# Autoinscription for %s\n", k_name + k_ptr->name); 
     2739                file_putf(fff, "B:%d:%s\n\n", inscriptions[i].kind_idx, 
    27782740                        quark_str(inscriptions[i].inscription_idx)); 
    27792741        } 
    27802742 
    2781         /* All done */ 
    2782         fprintf(fff, "\n"); 
     2743        file_putf(fff, "\n"); 
    27832744} 
    27842745 
     
    27862747 * Save squelch data to a pref file. 
    27872748 */ 
    2788 static void squelch_dump(FILE *fff) 
     2749static void squelch_dump(ang_file *fff) 
    27892750{ 
    27902751        int i; 
    2791         int tval, sval; 
    2792         bool squelch; 
    2793  
    2794         /* Start dumping */ 
    2795         fprintf(fff, "\n\n"); 
    2796         fprintf(fff, "# Squelch bits\n\n"); 
    2797  
    2798         /* Dump squelch bits */ 
     2752        file_putf(fff, "# Squelch settings\n"); 
     2753 
    27992754        for (i = 1; i < z_info->k_max; i++) 
    28002755        { 
    2801                 tval = k_info[i].tval; 
    2802                 sval = k_info[i].sval; 
    2803                 squelch = k_info[i].squelch; 
     2756                int tval = k_info[i].tval; 
     2757                int sval = k_info[i].sval; 
     2758                bool squelch = k_info[i].squelch; 
    28042759 
    28052760                /* Dump the squelch info */ 
    28062761                if (tval || sval) 
    2807                         fprintf(fff, "Q:%d:%d:%d:%d\n", i, tval, sval, squelch); 
    2808         } 
    2809  
    2810         /* All done */ 
    2811         fprintf(fff, "\n"); 
     2762                        file_putf(fff, "Q:%d:%d:%d:%d\n", i, tval, sval, squelch); 
     2763        } 
     2764 
     2765        file_putf(fff, "\n"); 
    28122766} 
    28132767 
     
    28152769 * Write all current options to a user preference file. 
    28162770 */ 
    2817 static void option_dump(FILE *fff) 
     2771static void option_dump(ang_file *fff) 
    28182772{ 
    28192773        int i, j; 
     
    28262780 
    28272781                /* Comment */ 
    2828                 fprintf(fff, "# Option '%s'\n", option_desc(i)); 
     2782                file_putf(fff, "# Option '%s'\n", option_desc(i)); 
    28292783 
    28302784                /* Dump the option */ 
    28312785                if (op_ptr->opt[i]) 
    2832                         fprintf(fff, "Y:%s\n", name); 
     2786                        file_putf(fff, "Y:%s\n", name); 
    28332787                else 
    2834                         fprintf(fff, "X:%s\n", name); 
     2788                        file_putf(fff, "X:%s\n", name); 
    28352789 
    28362790                /* Skip a line */ 
    2837                 fprintf(fff, "\n"); 
     2791                file_putf(fff, "\n"); 
    28382792        } 
    28392793 
     
    28512805 
    28522806                        /* Comment */ 
    2853                         fprintf(fff, "# Window '%s', Flag '%s'\n", 
     2807                        file_putf(fff, "# Window '%s', Flag '%s'\n", 
    28542808                                angband_term_name[i], window_flag_desc[j]); 
    28552809 
    28562810                        /* Dump the flag */ 
    28572811                        if (op_ptr->window_flag[i] & (1L << j)) 
    2858                         { 
    2859                                 fprintf(fff, "W:%d:%d:1\n", i, j); 
    2860                         } 
     2812                                file_putf(fff, "W:%d:%d:1\n", i, j); 
    28612813                        else 
    2862                         { 
    2863                                 fprintf(fff, "W:%d:%d:0\n", i, j); 
    2864                         } 
     2814                                file_putf(fff, "W:%d:%d:0\n", i, j); 
    28652815 
    28662816                        /* Skip a line */ 
    2867                         fprintf(fff, "\n"); 
     2817                        file_putf(fff, "\n"); 
    28682818                } 
    28692819        } 
     
    28782828 
    28792829/* 
    2880  * append all current macros to the given file 
    2881  */ 
    2882 static void macro_dump(FILE *fff) 
     2830 * Append all current macros to the given file 
     2831 */ 
     2832static void macro_dump(ang_file *fff) 
    28832833{ 
    28842834        int i; 
     
    28892839        { 
    28902840                /* Start the macro */ 
    2891                 fprintf(fff, "# Macro '%d'\n\n", i); 
     2841                file_putf(fff, "# Macro '%d'\n", i); 
    28922842 
    28932843                /* Extract the macro action */ 
    28942844                ascii_to_text(buf, sizeof(buf), macro__act[i]); 
    2895  
    2896                 /* Dump the macro action */ 
    2897                 fprintf(fff, "A:%s\n", buf); 
     2845                file_putf(fff, "A:%s\n", buf); 
    28982846 
    28992847                /* Extract the macro pattern */ 
    29002848                ascii_to_text(buf, sizeof(buf), macro__pat[i]); 
    2901  
    2902                 /* Dump the macro pattern */ 
    2903                 fprintf(fff, "P:%s\n", buf); 
    2904  
    2905                 /* End the macro */ 
    2906                 fprintf(fff, "\n\n"); 
     2849                file_putf(fff, "P:%s\n", buf); 
     2850 
     2851                file_putf(fff, "\n"); 
    29072852        } 
    29082853} 
     
    30072952 * Hack -- We only append the keymaps for the "active" mode. 
    30082953 */ 
    3009 static void keymap_dump(FILE *fff) 
    3010 { 
    3011         int i; 
     2954static void keymap_dump(ang_file *fff) 
     2955{ 
     2956        size_t i; 
    30122957        int mode; 
    30132958        char buf[1024]; 
    30142959 
    3015         /* Roguelike */ 
    30162960        if (rogue_like_commands) 
    3017         { 
    30182961                mode = KEYMAP_MODE_ROGUE; 
    3019         } 
    3020  
    3021         /* Original */ 
    30222962        else 
    3023         { 
    30242963                mode = KEYMAP_MODE_ORIG; 
    3025         } 
    3026  
    3027         for (i = 0; i < (int)N_ELEMENTS(keymap_act[mode]); i++) 
     2964 
     2965        for (i = 0; i < N_ELEMENTS(keymap_act[mode]); i++) 
    30282966        { 
    30292967                char key[2] = "?"; 
    3030  
    30312968                cptr act; 
    30322969 
     
    30412978 
    30422979                /* Dump the keymap action */ 
    3043                 fprintf(fff, "A:%s\n", buf); 
     2980                file_putf(fff, "A:%s\n", buf); 
    30442981 
    30452982                /* Convert the key into a string */ 
     
    30502987 
    30512988                /* Dump the keymap pattern */ 
    3052                 fprintf(fff, "C:%d:%s\n", mode, buf); 
     2989                file_putf(fff, "C:%d:%s\n", mode, buf); 
    30532990 
    30542991                /* Skip a line */ 
    3055                 fprintf(fff, "\n"); 
     2992                file_putf(fff, "\n"); 
    30562993        } 
    30572994 
     
    30993036        region loc = {0, 0, 0, 12}; 
    31003037 
    3101         /* Roguelike */ 
    31023038        if (rogue_like_commands) 
    3103         { 
    31043039                mode = KEYMAP_MODE_ROGUE; 
    3105         } 
    3106  
    3107         /* Original */ 
    31083040        else 
    3109         { 
    31103041                mode = KEYMAP_MODE_ORIG; 
    3111         } 
    3112  
    3113  
    3114         /* File type is "TEXT" */ 
    3115         FILE_TYPE(FILE_TYPE_TEXT); 
     3042 
    31163043 
    31173044        screen_save(); 
     
    33983325 
    33993326/* Dump monsters */ 
    3400 static void dump_monsters(FILE *fff) 
     3327static void dump_monsters(ang_file *fff) 
    34013328{ 
    34023329        int i; 
     3330 
    34033331        for (i = 0; i < z_info->r_max; i++) 
    34043332        { 
    34053333                monster_race *r_ptr = &r_info[i]; 
     3334                byte attr = r_ptr->x_attr; 
     3335                byte chr = r_ptr->x_char; 
    34063336 
    34073337                /* Skip non-entries */ 
    34083338                if (!r_ptr->name) continue; 
    34093339 
    3410                 /* Dump a comment */ 
    3411                 fprintf(fff, "# %s\n", (r_name + r_ptr->name)); 
    3412  
    3413                 /* Dump the monster attr/char info */ 
    3414                 fprintf(fff, "R:%d:0x%02X:0x%02X\n\n", i, 
    3415                         (byte)(r_ptr->x_attr), (byte)(r_ptr->x_char)); 
     3340                file_putf(fff, "# Monster: %s\n", (r_name + r_ptr->name)); 
     3341                file_putf(fff, "R:%d:0x%02X:0x%02X\n", i, attr, chr); 
    34163342        } 
    34173343} 
    34183344 
    34193345/* Dump objects */ 
    3420 static void dump_objects(FILE *fff) 
     3346static void dump_objects(ang_file *fff) 
    34213347{ 
    34223348        int i; 
     3349 
    34233350        for (i = 0; i < z_info->k_max; i++) 
    34243351        { 
    34253352                object_kind *k_ptr = &k_info[i]; 
     3353                byte attr = k_ptr->x_attr; 
     3354                byte chr = k_ptr->x_char; 
    34263355 
    34273356                /* Skip non-entries */ 
    34283357                if (!k_ptr->name) continue; 
    34293358 
    3430                 /* Dump a comment */ 
    3431                 fprintf(fff, "# %s\n", (k_name + k_ptr->name)); 
    3432  
    3433                 /* Dump the object attr/char info */ 
    3434                 fprintf(fff, "K:%d:0x%02X:0x%02X\n\n", i, 
    3435                                         (byte)(k_ptr->x_attr), (byte)(k_ptr->x_char)); 
     3359                file_putf(fff, "# Object: %s\n", (k_name + k_ptr->name)); 
     3360                file_putf(fff, "K:%d:0x%02X:0x%02X\n", i, attr, chr); 
    34363361        } 
    34373362} 
    34383363 
    34393364/* Dump features */ 
    3440 static void dump_features(FILE *fff) 
     3365static void dump_features(ang_file *fff) 
    34413366{ 
    34423367        int i; 
     3368 
    34433369        for (i = 0; i < z_info->f_max; i++) 
    34443370        { 
    34453371                feature_type *f_ptr = &f_info[i]; 
     3372                byte attr = f_ptr->x_attr; 
     3373                byte chr = f_ptr->x_char; 
    34463374 
    34473375                /* Skip non-entries */ 
     
    34513379                if ((f_ptr->mimic != i) && (i != FEAT_INVIS)) continue; 
    34523380 
    3453                 /* Dump a comment */ 
    3454                 fprintf(fff, "# %s\n", (f_name + f_ptr->name)); 
    3455  
    3456                 /* Dump the feature attr/char info */ 
    3457                 /* Dump the feature attr/char info */ 
    3458                 fprintf(fff, "F:%d:0x%02X:0x%02X\n\n", i, 
    3459                                                 (byte)(f_ptr->x_attr), (byte)(f_ptr->x_char)); 
    3460  
    3461  
     3381                file_putf(fff, "# Terrain: %s\n", (f_name + f_ptr->name)); 
     3382                file_putf(fff, "F:%d:0x%02X:0x%02X\n", i, attr, chr); 
    34623383        } 
    34633384} 
    34643385 
    34653386/* Dump flavors */ 
    3466 static void dump_flavors(FILE *fff) 
     3387static void dump_flavors(ang_file *fff) 
    34673388{ 
    34683389        int i; 
     3390 
    34693391        for (i = 0; i < z_info->flavor_max; i++) 
    34703392        { 
    34713393                flavor_type *x_ptr = &flavor_info[i]; 
    3472  
    3473                 /* Dump a comment */ 
    3474                 fprintf(fff, "# %s\n", (flavor_text + x_ptr->text)); 
    3475  
    3476                 /* Dump the flavor attr/char info */ 
    3477                 fprintf(fff, "L:%d:0x%02X:0x%02X\n\n", i, 
    3478                         (byte)(x_ptr->x_attr), (byte)(x_ptr->x_char)); 
     3394                byte attr = x_ptr->x_attr; 
     3395                byte chr = x_ptr->x_char; 
     3396 
     3397                file_putf(fff, "# Item flavor: %s\n", (flavor_text + x_ptr->text)); 
     3398                file_putf(fff, "L:%d:0x%02X:0x%02X\n\n", i, attr, chr); 
    34793399        } 
    34803400} 
    34813401 
    34823402/* Dump colors */ 
    3483 static void dump_colors(FILE *fff) 
     3403static void dump_colors(ang_file *fff) 
    34843404{ 
    34853405        int i; 
     3406 
    34863407        for (i = 0; i < MAX_COLORS; i++) 
    34873408        { 
     
    34993420                if (i < BASIC_COLORS) name = color_names[i]; 
    35003421 
    3501                 /* Dump a comment */ 
    3502                 fprintf(fff, "# Color '%s'\n", name); 
    3503  
     3422                file_putf(fff, "# Color: %s\n", name); 
     3423                file_putf(fff, "V:%d:0x%02X:0x%02X:0x%02X:0x%02X\n\n", i, kv, rv, gv, bv); 
    35043424        } 
    35053425} 
     
    38013721        int cursor = 0; 
    38023722 
    3803         /* File type is "TEXT" */ 
    3804         FILE_TYPE(FILE_TYPE_TEXT); 
    3805  
    3806         /* Save screen */ 
    38073723        screen_save(); 
    38083724 
     
    44404356        bool okay = TRUE; 
    44414357 
    4442         FILE *fp; 
     4358        ang_file *fp; 
    44434359 
    44444360        char buf[1024]; 
     
    44474363        /* Build the filename */ 
    44484364        path_build(buf, 1024, ANGBAND_DIR_USER, "dump.txt"); 
    4449  
    4450         /* Open the file */ 
    4451         fp = my_fopen(buf, "r"); 
    4452  
    4453         /* Oops */ 
     4365        fp = file_open(buf, MODE_READ, -1); 
    44544366        if (!fp) return; 
    44554367 
     
    44674379        { 
    44684380                /* Get a line of data */ 
    4469                 if (my_fgets(fp, buf, sizeof(buf))) okay = FALSE; 
     4381                if (!file_getl(fp, buf, sizeof(buf))) okay = FALSE; 
    44704382 
    44714383 
     
    44794391 
    44804392        /* Get the blank line */ 
    4481         if (my_fgets(fp, buf, sizeof(buf))) okay = FALSE; 
     4393        if (!file_getl(fp, buf, sizeof(buf))) okay = FALSE; 
    44824394 
    44834395 
     
    44864398        { 
    44874399                /* Get a line of data */ 
    4488                 if (my_fgets(fp, buf, sizeof(buf))) okay = FALSE; 
     4400                if (!file_getl(fp, buf, sizeof(buf))) okay = FALSE; 
    44894401 
    44904402                /* Dump each row */ 
     
    45084420 
    45094421        /* Close it */ 
    4510         my_fclose(fp); 
     4422        file_close(fp); 
    45114423 
    45124424 
     
    45314443        char c = ' '; 
    45324444 
    4533         FILE *fff; 
     4445        ang_file *fff; 
    45344446 
    45354447        char buf[1024]; 
     
    45374449        /* Build the filename */ 
    45384450        path_build(buf, 1024, ANGBAND_DIR_USER, "dump.txt"); 
    4539  
    4540         /* File type is "DATA" -- needs to be opened in Angband to view */ 
    4541         FILE_TYPE(FILE_TYPE_DATA); 
    4542  
    4543         /* Append to the file */ 
    4544         fff = my_fopen(buf, "w"); 
    4545  
    4546         /* Oops */ 
     4451        fff = file_open(buf, MODE_WRITE, FTYPE_TEXT); 
    45474452        if (!fff) return; 
    45484453 
     
    45694474 
    45704475                /* End the row */ 
    4571                 fprintf(fff, "%s\n", buf); 
     4476                file_putf(fff, "%s\n", buf); 
    45724477        } 
    45734478 
    45744479        /* Skip a line */ 
    4575         fprintf(fff, "\n"); 
     4480        file_putf(fff, "\n"); 
    45764481 
    45774482 
     
    45934498 
    45944499                /* End the row */ 
    4595                 fprintf(fff, "%s\n", buf); 
     4500                file_putf(fff, "%s\n", buf); 
    45964501        } 
    45974502 
    45984503        /* Skip a line */ 
    4599         fprintf(fff, "\n"); 
     4504        file_putf(fff, "\n"); 
    46004505 
    46014506 
    46024507        /* Close it */ 
    4603         my_fclose(fff); 
     4508        file_close(fff); 
    46044509 
    46054510 
     
    46214526        size_t i; 
    46224527 
    4623         FILE *fff; 
     4528        ang_file *fff; 
    46244529        char file_name[1024]; 
    46254530        char tmp_val[256]; 
    46264531 
    4627         typedef void (*dump_func)(FILE *); 
     4532        typedef void (*dump_func)(ang_file *); 
    46284533        dump_func dump_visuals [] =  
    46294534                { dump_monsters, dump_features, dump_objects, dump_flavors, dump_colors }; 
    46304535 
    4631         /* File type is "TEXT" */ 
    4632         FILE_TYPE(FILE_TYPE_TEXT); 
     4536 
     4537        if (mode == 0) 
     4538                my_strcpy(tmp_val, "dump.html", sizeof(tmp_val)); 
     4539        else 
     4540                my_strcpy(tmp_val, "dump.txt", sizeof(tmp_val)); 
    46334541 
    46344542        /* Ask for a file */ 
    4635         if (mode == 0) my_strcpy(tmp_val, "dump.html", sizeof(tmp_val)); 
    4636         else my_strcpy(tmp_val, "dump.txt", sizeof(tmp_val)); 
    46374543        if (!get_string("File: ", tmp_val, sizeof(tmp_val))) return; 
    46384544 
    46394545        /* Save current preferences */ 
    46404546        path_build(file_name, 1024, ANGBAND_DIR_USER, "dump.prf"); 
    4641         fff = my_fopen(file_name, "w"); 
     4547        fff = file_open(file_name, MODE_WRITE, (mode == 0 ? FTYPE_HTML : FTYPE_TEXT)); 
    46424548 
    46434549        /* Check for failure */ 
     
    46534559                dump_visuals[i](fff); 
    46544560 
    4655         my_fclose(fff); 
     4561        file_close(fff); 
    46564562 
    46574563        /* Dump the screen with raw character attributes */ 
     
    46634569        reset_visuals(TRUE); 
    46644570        process_pref_file(file_name); 
    4665         fd_kill(file_name); 
     4571        file_delete(file_name); 
    46664572        do_cmd_redraw(); 
    46674573 
  • trunk/src/config.h

    r453 r469  
    192192 */ 
    193193#ifndef DEFAULT_PATH 
    194 # define DEFAULT_PATH "./lib/" 
     194# define DEFAULT_PATH "." PATH_SEP "lib" PATH_SEP 
    195195#endif /* DEFAULT_PATH */ 
    196196 
  • trunk/src/dungeon.c

    r450 r469  
    19141914         
    19151915        /* Check if we're overwriting a savefile */ 
    1916         while (!reusing_savefile && my_fexists(savefile)) 
     1916        while (!reusing_savefile && file_exists(savefile)) 
    19171917        { 
    19181918                /* Ask for confirmation */ 
  • trunk/src/externs.h

    r467 r469  
    133133extern bool good_item_flag; 
    134134extern bool closing_flag; 
    135 extern int player_uid; 
    136 extern int player_egid; 
    137135extern char savefile[1024]; 
    138136extern s16b macro__num; 
     
    239237extern bool (*get_obj_num_hook)(int k_idx); 
    240238extern void (*object_info_out_flags)(const object_type *o_ptr, u32b *f1, u32b *f2, u32b *f3); 
    241 extern FILE *text_out_file; 
     239extern ang_file *text_out_file; 
    242240extern void (*text_out_hook)(byte a, cptr str); 
    243241extern int text_out_wrap; 
     
    723721 
    724722/* 
    725  * Hack -- conditional (or "bizarre") externs 
     723 * Hack -- conditional externs 
    726724 */ 
    727  
    728 #ifdef RISCOS 
    729 /* main-ros.c */ 
    730 extern char *riscosify_name(cptr path); 
    731 #endif /* RISCOS */ 
    732  
    733 #if defined(MAC_MPW) || defined(MACH_O_CARBON) 
    734 /* main-mac.c, or its derivatives */ 
    735 extern u32b _fcreator; 
    736 extern u32b _ftype; 
    737 # if defined(MAC_MPW) && defined(CARBON) 
    738 extern void convert_pathname(char *path); 
    739 # endif 
    740 # if defined(MACH_O_CARBON) 
    741 extern void fsetfileinfo(cptr path, u32b fcreator, u32b ftype); 
    742 # endif 
    743 #endif 
    744725 
    745726#ifdef ALLOW_DEBUG 
  • trunk/src/files.c

    r463 r469  
    855855static errr process_pref_file_aux(cptr name) 
    856856{ 
    857         FILE *fp; 
     857        ang_file *fp; 
    858858 
    859859        char buf[1024]; 
    860  
    861860        char old[1024]; 
    862861 
     
    869868 
    870869        /* Open the file */ 
    871         fp = my_fopen(name, "r"); 
    872  
    873         /* No such file */ 
     870        fp = file_open(name, MODE_READ, -1); 
    874871        if (!fp) return (-1); 
    875872 
    876873 
    877874        /* Process the file */ 
    878         while (0 == my_fgets(fp, buf, sizeof(buf))) 
     875        while (file_getl(fp, buf, sizeof(buf))) 
    879876        { 
    880877                /* Count lines */ 
     
    886883 
    887884                /* Skip "blank" lines */ 
    888                 if (isspace((unsigned char)buf[0])) continue; 
     885                if (isspace((unsigned char) buf[0])) continue; 
    889886 
    890887                /* Skip comments */ 
     
    950947 
    951948        /* Close the file */ 
    952         my_fclose(fp); 
     949&n