From 7428120d37820cfc6a16c324e1d23366039a21d3 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Wed, 28 Oct 1998 01:32:54 +0000 Subject: [PATCH] new function for file input. rewind the filedescriptor to the current Tue Oct 27 07:25:53 1998 Tim Janik * glib.h: * gscanner.c: (g_scanner_sync_file_offset): new function for file input. rewind the filedescriptor to the current buffer position and blow the file read ahead buffer. usefull for third party uses of our filedescriptor, which hooks onto the current scanning position. (this became neccessary with the implementation of buffered reads). (g_scanner_input_file): (g_scanner_input_text): automatically blow the read ahead buffer. (g_scanner_get_char): blow the read ahead buffer when the end of input is reached, i.e. a '\000' char is read. --- ChangeLog | 15 +++++++++++++++ ChangeLog.pre-2-0 | 15 +++++++++++++++ ChangeLog.pre-2-10 | 15 +++++++++++++++ ChangeLog.pre-2-12 | 15 +++++++++++++++ ChangeLog.pre-2-2 | 15 +++++++++++++++ ChangeLog.pre-2-4 | 15 +++++++++++++++ ChangeLog.pre-2-6 | 15 +++++++++++++++ ChangeLog.pre-2-8 | 15 +++++++++++++++ glib.h | 1 + glib/glib.h | 1 + glib/gscanner.c | 39 +++++++++++++++++++++++++++++++++++++++ gscanner.c | 39 +++++++++++++++++++++++++++++++++++++++ 12 files changed, 200 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8e34d63..c6c9fbc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 8e34d63..c6c9fbc 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 8e34d63..c6c9fbc 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 8e34d63..c6c9fbc 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 8e34d63..c6c9fbc 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 8e34d63..c6c9fbc 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 8e34d63..c6c9fbc 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 8e34d63..c6c9fbc 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,18 @@ +Tue Oct 27 07:25:53 1998 Tim Janik + + * glib.h: + * gscanner.c: + (g_scanner_sync_file_offset): new function for file input. + rewind the filedescriptor to the current buffer position and blow + the file read ahead buffer. usefull for third party uses of our + filedescriptor, which hooks onto the current scanning position. + (this became neccessary with the implementation of buffered + reads). + (g_scanner_input_file): + (g_scanner_input_text): automatically blow the read ahead buffer. + (g_scanner_get_char): blow the read ahead buffer when the end of + input is reached, i.e. a '\000' char is read. + Tue Oct 27 00:27:31 PST 1998 Manish Singh * glib.h: get rid of duplicate #g_htonl and friends in the diff --git a/glib.h b/glib.h index 64ed88e..8e8c8cb 100644 --- a/glib.h +++ b/glib.h @@ -2085,6 +2085,7 @@ GScanner* g_scanner_new (GScannerConfig *config_templ); void g_scanner_destroy (GScanner *scanner); void g_scanner_input_file (GScanner *scanner, gint input_fd); +void g_scanner_sync_file_offset (GScanner *scanner); void g_scanner_input_text (GScanner *scanner, const gchar *text, guint text_len); diff --git a/glib/glib.h b/glib/glib.h index 64ed88e..8e8c8cb 100644 --- a/glib/glib.h +++ b/glib/glib.h @@ -2085,6 +2085,7 @@ GScanner* g_scanner_new (GScannerConfig *config_templ); void g_scanner_destroy (GScanner *scanner); void g_scanner_input_file (GScanner *scanner, gint input_fd); +void g_scanner_sync_file_offset (GScanner *scanner); void g_scanner_input_text (GScanner *scanner, const gchar *text, guint text_len); diff --git a/glib/gscanner.c b/glib/gscanner.c index 0372b18..2bb0f47 100644 --- a/glib/gscanner.c +++ b/glib/gscanner.c @@ -658,6 +658,9 @@ g_scanner_input_file (GScanner *scanner, g_return_if_fail (scanner != NULL); g_return_if_fail (input_fd >= 0); + if (scanner->input_fd >= 0) + g_scanner_sync_file_offset (scanner); + scanner->token = G_TOKEN_NONE; scanner->value.v_int = 0; scanner->line = 1; @@ -683,6 +686,9 @@ g_scanner_input_text (GScanner *scanner, else text = NULL; + if (scanner->input_fd >= 0) + g_scanner_sync_file_offset (scanner); + scanner->token = G_TOKEN_NONE; scanner->value.v_int = 0; scanner->line = 1; @@ -737,6 +743,33 @@ g_scanner_peek_next_char (GScanner *scanner) return 0; } +void +g_scanner_sync_file_offset (GScanner *scanner) +{ + g_return_if_fail (scanner != NULL); + + /* for file input, rewind the filedescriptor to the current + * buffer position and blow the file read ahead buffer. usefull for + * third party uses of our filedescriptor, which hooks onto the current + * scanning position. + */ + + if (scanner->input_fd >= 0 && scanner->text_end > scanner->text) + { + gint buffered; + + buffered = scanner->text_end - scanner->text; + if (lseek (scanner->input_fd, - buffered, SEEK_CUR) >= 0) + { + /* we succeeded, blow our buffer's contents now */ + scanner->text = NULL; + scanner->text_end = NULL; + } + else + errno = 0; + } +} + static guchar g_scanner_get_char (GScanner *scanner, guint *line_p, @@ -768,6 +801,12 @@ g_scanner_get_char (GScanner *scanner, scanner->text = buffer + 1; scanner->text_end = buffer + count; fchar = *buffer; + if (!fchar) + { + g_scanner_sync_file_offset (scanner); + scanner->text_end = scanner->text; + scanner->input_fd = -1; + } } } else diff --git a/gscanner.c b/gscanner.c index 0372b18..2bb0f47 100644 --- a/gscanner.c +++ b/gscanner.c @@ -658,6 +658,9 @@ g_scanner_input_file (GScanner *scanner, g_return_if_fail (scanner != NULL); g_return_if_fail (input_fd >= 0); + if (scanner->input_fd >= 0) + g_scanner_sync_file_offset (scanner); + scanner->token = G_TOKEN_NONE; scanner->value.v_int = 0; scanner->line = 1; @@ -683,6 +686,9 @@ g_scanner_input_text (GScanner *scanner, else text = NULL; + if (scanner->input_fd >= 0) + g_scanner_sync_file_offset (scanner); + scanner->token = G_TOKEN_NONE; scanner->value.v_int = 0; scanner->line = 1; @@ -737,6 +743,33 @@ g_scanner_peek_next_char (GScanner *scanner) return 0; } +void +g_scanner_sync_file_offset (GScanner *scanner) +{ + g_return_if_fail (scanner != NULL); + + /* for file input, rewind the filedescriptor to the current + * buffer position and blow the file read ahead buffer. usefull for + * third party uses of our filedescriptor, which hooks onto the current + * scanning position. + */ + + if (scanner->input_fd >= 0 && scanner->text_end > scanner->text) + { + gint buffered; + + buffered = scanner->text_end - scanner->text; + if (lseek (scanner->input_fd, - buffered, SEEK_CUR) >= 0) + { + /* we succeeded, blow our buffer's contents now */ + scanner->text = NULL; + scanner->text_end = NULL; + } + else + errno = 0; + } +} + static guchar g_scanner_get_char (GScanner *scanner, guint *line_p, @@ -768,6 +801,12 @@ g_scanner_get_char (GScanner *scanner, scanner->text = buffer + 1; scanner->text_end = buffer + count; fchar = *buffer; + if (!fchar) + { + g_scanner_sync_file_offset (scanner); + scanner->text_end = scanner->text; + scanner->input_fd = -1; + } } } else -- 2.7.4