Changeset 1106

Show
Ignore:
Timestamp:
01/09/09 07:55:46 (9 hours ago)
Author:
takkaria
Message:

Bug: #513

  • Refactor the code that prompts for character dump filenames so that it can be overriden by platform-native ports.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd4.c

    r1103 r1106  
    20212021                else if (ke.key == 'f') 
    20222022                { 
    2023                         char ftmp[80]; 
    2024  
    2025                         strnfmt(ftmp, sizeof ftmp, "%s.txt", op_ptr->base_name); 
    2026  
    2027                         if (get_string("File name: ", ftmp, 80)) 
     2023                        char buf[1024]; 
     2024                        char fname[80]; 
     2025 
     2026                        strnfmt(fname, sizeof fname, "%s.txt", op_ptr->base_name); 
     2027 
     2028                        if (get_file(fname, buf, sizeof buf)) 
    20282029                        { 
    2029                                 if (ftmp[0] && (ftmp[0] != ' ')) 
    2030                                 { 
    2031                                         if (file_character(ftmp, FALSE)) 
    2032                                                 msg_print("Character dump failed!"); 
    2033                                         else 
    2034                                                 msg_print("Character dump successful."); 
    2035                                 } 
     2030                                if (file_character(buf, FALSE) != 0) 
     2031                                        msg_print("Character dump failed!"); 
     2032                                else 
     2033                                        msg_print("Character dump successful."); 
    20362034                        } 
    20372035                } 
  • trunk/src/death.c

    r966 r1106  
    180180static void death_file(void *unused, const char *title) 
    181181{ 
     182        char buf[1024]; 
    182183        char ftmp[80]; 
     184 
     185        (void)unused; 
     186        (void)title; 
     187 
    183188        strnfmt(ftmp, sizeof(ftmp), "%s.txt", op_ptr->base_name); 
    184189 
    185         (void)unused; 
    186         (void)title; 
    187  
    188         if (!get_string("File name: ", ftmp, sizeof(ftmp))) 
    189                 return; 
    190  
    191         if (ftmp[0] && (ftmp[0] != ' ')) 
     190        if (get_file(ftmp, buf, sizeof buf)) 
    192191        { 
    193192                errr err; 
     
    195194                /* Dump a character file */ 
    196195                screen_save(); 
    197                 err = file_character(ftmp, FALSE); 
     196                err = file_character(buf, FALSE); 
    198197                screen_load(); 
    199198 
  • trunk/src/externs.h

    r1067 r1106  
    626626extern s16b get_quantity(cptr prompt, int max); 
    627627extern bool get_check(cptr prompt); 
     628bool (*get_file)(const char *suggested_name, char *path, size_t len); 
    628629extern bool get_com(cptr prompt, char *command); 
    629630extern bool get_com_ex(cptr prompt, ui_event_data *command); 
  • trunk/src/files.c

    r1078 r1106  
    19091909 * and trigger its usage from various places in the code. 
    19101910 */ 
    1911 errr file_character(cptr name, bool full) 
     1911errr file_character(const char *path, bool full) 
    19121912{ 
    19131913        int i, x, y; 
     
    19281928        (void)full; 
    19291929 
    1930         /* Build the filename */ 
    1931         path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name); 
    1932  
    1933         /* Check if the file currently exists */ 
    1934         if (file_exists(buf)) 
    1935         { 
    1936                 char out_val[160]; 
    1937  
    1938                 /* Build query */ 
    1939                 strnfmt(out_val, sizeof(out_val), "Replace existing file %s? ", buf); 
    1940  
    1941                 /* Ask */ 
    1942                 if (!get_check(out_val)) 
    1943                         return -1; 
    1944         } 
    19451930 
    19461931        /* Open the file for writing */ 
    1947         fp = file_open(buf, MODE_WRITE, FTYPE_TEXT); 
     1932        fp = file_open(path, MODE_WRITE, FTYPE_TEXT); 
    19481933        if (!fp) return (-1); 
    19491934 
  • trunk/src/util.c

    r1103 r1106  
    26202620 
    26212621 
     2622/** 
     2623 * Text-native way of getting a filename. 
     2624 */ 
     2625bool get_file_text(const char *suggested_name, char *path, size_t len) 
     2626{ 
     2627        char buf[160]; 
     2628 
     2629        /* Get filename */ 
     2630        my_strcpy(buf, suggested_name, sizeof buf); 
     2631        if (!get_string("File name: ", buf, sizeof buf)) return FALSE; 
     2632 
     2633        /* Make sure it's actually a filename */ 
     2634        if (buf[0] == '\0' || buf[0] == ' ') return FALSE; 
     2635 
     2636        /* Build the path */ 
     2637        path_build(path, len, ANGBAND_DIR_USER, buf); 
     2638 
     2639        /* Check if it already exists */ 
     2640        if (file_exists(buf)) 
     2641        { 
     2642                char buf2[160]; 
     2643                strnfmt(buf2, sizeof(buf2), "Replace existing file %s?", buf); 
     2644 
     2645                if (get_check(buf2) == FALSE) 
     2646                        return FALSE; 
     2647        } 
     2648 
     2649        return TRUE; 
     2650} 
     2651 
     2652 
     2653 
     2654 
     2655/** 
     2656 * Get a pathname to save a file to, given the suggested name.  Returns the 
     2657 * result in "path". 
     2658 */ 
     2659bool (*get_file)(const char *suggested_name, char *path, size_t len) = get_file_text; 
     2660 
     2661 
     2662 
     2663 
    26222664/* 
    26232665 * Prompts for a keypress