X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=libchimara%2Ffileref.c;h=97c6e487bb62a02c79b4af9c8665a50f220b9edd;hb=d5610e149e0384a24d00727a5815df12e85de026;hp=516af027f6bf44157fd41b985b80458b53722fb3;hpb=46271bc1f196ef9c6d0c69a84a55c9eac1deb8b3;p=projects%2Fchimara%2Fchimara.git diff --git a/libchimara/fileref.c b/libchimara/fileref.c index 516af02..97c6e48 100644 --- a/libchimara/fileref.c +++ b/libchimara/fileref.c @@ -7,7 +7,7 @@ #include "magic.h" #include "chimara-glk-private.h" -extern ChimaraGlkPrivate *glk_data; +extern GPrivate *glk_data_key; /** * glk_fileref_iterate: @@ -24,7 +24,8 @@ frefid_t glk_fileref_iterate(frefid_t fref, glui32 *rockptr) { VALID_FILEREF_OR_NULL(fref, return NULL); - + + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); GList *retnode; if(fref == NULL) @@ -62,6 +63,8 @@ fileref_new(gchar *filename, glui32 rock, glui32 usage, glui32 orig_filemode) { g_return_val_if_fail(filename != NULL, NULL); + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + frefid_t f = g_new0(struct glk_fileref_struct, 1); f->magic = MAGIC_FILEREF; f->rock = rock; @@ -144,24 +147,24 @@ glk_fileref_create_temp(glui32 usage, glui32 rock) * @fmode must be one of these values: * * - * #filemode_Read + * %filemode_Read * The file must already exist; and the player will be asked * to select from existing files which match the usage. * * - * #filemode_Write + * %filemode_Write * The file should not exist; if the player selects an * existing file, he will be warned that it will be replaced. * * * - * #filemode_ReadWrite + * %filemode_ReadWrite * The file may or may not exist; if it already exists, the * player will be warned that it will be modified. * * - * #filemode_WriteAppend - * Same behavior as #filemode_ReadWrite. + * %filemode_WriteAppend + * Same behavior as %filemode_ReadWrite. * * * @@ -185,6 +188,8 @@ glk_fileref_create_by_prompt(glui32 usage, glui32 fmode, glui32 rock) for each usage */ GtkWidget *chooser; + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + gdk_threads_enter(); switch(fmode) @@ -289,13 +294,11 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock) { g_return_val_if_fail(name != NULL && strlen(name) > 0, NULL); + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + /* Do any string-munging here to remove illegal Latin-1 characters from filename. On ext3, the only illegal characters are '/' and '\0'. */ - - char *ptr = name; - while(*ptr++) - if(*ptr == '/') - *ptr = '_'; + g_strdelimit(name, "/", '_'); /* Find out what encoding filenames are in */ const gchar **charsets; /* Do not free */ @@ -333,7 +336,7 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock) * original fileref is not modified.) * * The use of this function can be tricky. If you change the type of the fileref - * (#fileusage_Data, #fileusage_SavedGame, etc), the new reference may or may + * (%fileusage_Data, %fileusage_SavedGame, etc), the new reference may or may * not point to the same actual disk file. * * @@ -345,8 +348,8 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock) * unpredictable. It is safest to change the type of a fileref only if it refers * to a nonexistent file. * - * If you change the mode of a fileref (#fileusage_TextMode, - * #fileusage_BinaryMode), but leave the rest of the type unchanged, the new + * If you change the mode of a fileref (%fileusage_TextMode, + * %fileusage_BinaryMode), but leave the rest of the type unchanged, the new * fileref will definitely point to the same disk file as the old one. * * Obviously, if you write to a file in text mode and then read from it in @@ -377,6 +380,8 @@ void glk_fileref_destroy(frefid_t fref) { VALID_FILEREF(fref, return); + + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); glk_data->fileref_list = g_list_delete_link(glk_data->fileref_list, fref->fileref_list); if(fref->filename)