From: P. F. Chimento Date: Wed, 20 Apr 2011 15:20:47 +0000 (+0200) Subject: Add new Glk Unix extension from CheapGlk X-Git-Tag: v0.9~98 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=c5345e6e7a3c04992e39821fa3d41bb08c6fe961;p=projects%2Fchimara%2Fchimara.git Add new Glk Unix extension from CheapGlk There is a new function glkunix_stream_open_pathname_gen() that supersedes glkunix_stream_open_pathname(). --- diff --git a/docs/reference/chimara-sections.txt b/docs/reference/chimara-sections.txt index 5f6e31e..6952d18 100644 --- a/docs/reference/chimara-sections.txt +++ b/docs/reference/chimara-sections.txt @@ -681,6 +681,7 @@ NULL
glkext-unix Unix Extensions +glkunix_stream_open_pathname_gen glkunix_stream_open_pathname glkunix_set_base_file
diff --git a/libchimara/glkstart.h b/libchimara/glkstart.h index e6b9010..b8b7ae7 100644 --- a/libchimara/glkstart.h +++ b/libchimara/glkstart.h @@ -50,6 +50,8 @@ extern glkunix_argumentlist_t glkunix_arguments[]; extern int glkunix_startup_code(glkunix_startup_t *data); extern void glkunix_set_base_file(char *filename); +extern strid_t glkunix_stream_open_pathname_gen(char *pathname, + glui32 writemode, glui32 textmode, glui32 rock); extern strid_t glkunix_stream_open_pathname(char *pathname, glui32 textmode, glui32 rock); diff --git a/libchimara/glkunix.c b/libchimara/glkunix.c index 83d8989..284fc1c 100644 --- a/libchimara/glkunix.c +++ b/libchimara/glkunix.c @@ -10,15 +10,48 @@ extern GPrivate *glk_data_key; /** - * glkunix_stream_open_pathname: - * @pathname: A path to a file, in the system filename encoding. - * @textmode: Bitfield with one or more of the fileusage_ constants. + * glkunix_stream_open_pathname_gen: + * @pathname: A path to a file, in the system filename encoding. + * @writemode: 0 for read-only mode, 1 for write mode. + * @textmode: 0 for binary mode, 1 for text mode. * @rock: The new stream's rock value. * - * Opens an arbitrary file, in read-only mode. Note that this function is + * Opens an arbitrary file for reading or writing. (You cannot open a file for + * appending using this call.) Note that this function is * only available during glkunix_startup_code(). It is * inherently non-portable; it should not and cannot be called from inside * glk_main(). + * + * Returns: A new stream, or %NULL if the file operation failed. + */ +strid_t +glkunix_stream_open_pathname_gen(char *pathname, glui32 writemode, glui32 textmode, glui32 rock) +{ + ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); + + if(!glk_data->in_startup) + ILLEGAL("glkunix_stream_open_pathname_gen() may only be called from " + "glkunix_startup_code()."); + + g_return_val_if_fail(pathname, NULL); + g_return_val_if_fail(strlen(pathname) > 0, NULL); + + frefid_t fileref = fileref_new(pathname, rock, + textmode? fileusage_TextMode : fileusage_BinaryMode, + writemode? filemode_Write : filemode_Read); + return file_stream_new(fileref, writemode? filemode_Write : filemode_Read, rock, FALSE); +} + +/** + * glkunix_stream_open_pathname: + * @pathname: A path to a file, in the system filename encoding. + * @textmode: 0 for binary mode, 1 for text mode. + * @rock: The new stream's rock value. + * + * This opens a file for reading. It is a less-general form of + * glkunix_stream_open_pathname_gen(), preserved for backwards compatibility. + * + * This should be used only by glkunix_startup_code(). * * Returns: A new stream, or %NULL if the file operation failed. */ @@ -26,15 +59,15 @@ strid_t glkunix_stream_open_pathname(char *pathname, glui32 textmode, glui32 rock) { ChimaraGlkPrivate *glk_data = g_private_get(glk_data_key); - + if(!glk_data->in_startup) ILLEGAL("glkunix_stream_open_pathname() may only be called from " "glkunix_startup_code()."); - + g_return_val_if_fail(pathname, NULL); g_return_val_if_fail(strlen(pathname) > 0, NULL); - - frefid_t fileref = fileref_new(pathname, rock, textmode, filemode_Read); + + frefid_t fileref = fileref_new(pathname, rock, textmode? fileusage_TextMode : fileusage_BinaryMode, filemode_Read); return file_stream_new(fileref, filemode_Read, rock, FALSE); }