6b70dfa3bd3ce904530df6a577c7fbe2c02ba02d
[rodin/chimara.git] / src / strio.c
1 #include "stream.h"
2 #include <stdio.h>
3 #include <string.h>
4 #include <glib.h>
5 #include <glib/gstdio.h>
6
7 /*
8  *
9  **************** WRITING FUNCTIONS ********************************************
10  *
11  */
12
13 /* Internal function: change illegal (control) characters in a string to a
14 placeholder character. Must free returned string afterwards. */
15 static gchar *
16 remove_latin1_control_characters(unsigned char *s, gsize len)
17 {
18         /* If len == 0, then return an empty string, not NULL */
19         if(len == 0)
20                 return g_strdup("");
21                         
22         gchar *retval = g_new0(gchar, len);
23         int i;
24         for(i = 0; i < len; i++)
25                 if( (s[i] < 32 && s[i] != 10) || (s[i] >= 127 && s[i] <= 159) )
26                         retval[i] = '?';
27                         /* Our placeholder character is '?'; other options are possible,
28                         like printing "0x7F" or something */
29                 else
30                         retval[i] = s[i];
31         return retval;
32 }
33
34 /* Internal function: convert a Latin-1 string to a UTF-8 string, replacing
35 Latin-1 control characters by a placeholder first. The UTF-8 string must be
36 freed afterwards. Returns NULL on error. */
37 static gchar *
38 convert_latin1_to_utf8(gchar *s, gsize len)
39 {
40         GError *error = NULL;
41         gchar *utf8;
42         gchar *canonical = remove_latin1_control_characters( (unsigned char *)s,
43                 len);
44         utf8 = g_convert(canonical, len, "UTF-8", "ISO-8859-1", NULL, NULL, &error);
45         g_free(canonical);
46         
47         if(utf8 == NULL)
48         {
49                 error_dialog(NULL, error, "Error during latin1->utf8 conversion: ");
50                 return NULL;
51         }
52         
53         return utf8;
54 }
55
56 /* Internal function: write a UTF-8 string to a window's text buffer. */
57 static void
58 write_utf8_to_window(winid_t win, gchar *s)
59 {
60         gdk_threads_enter();
61
62         GtkTextBuffer *buffer = 
63                 gtk_text_view_get_buffer( GTK_TEXT_VIEW(win->widget) );
64
65         GtkTextIter iter;
66         gtk_text_buffer_get_end_iter(buffer, &iter);
67         gtk_text_buffer_insert(buffer, &iter, s, -1);
68
69         gdk_threads_leave();
70 }
71
72 /* Internal function: write a Latin-1 buffer with length to a stream. */
73 static void
74 write_buffer_to_stream(strid_t str, gchar *buf, glui32 len)
75 {
76         switch(str->type)
77         {
78                 case STREAM_TYPE_WINDOW:
79                         /* Each window type has a different way of printing to it */
80                         switch(str->window->type)
81                         {
82                                 /* Printing to these windows' streams does nothing */
83                                 case wintype_Blank:
84                                 case wintype_Pair:
85                                 case wintype_Graphics:
86                                         str->write_count += len;
87                                         break;
88                                 /* Text buffer window */        
89                                 case wintype_TextBuffer:
90                                 {
91                                         gchar *utf8 = convert_latin1_to_utf8(buf, len);
92                                         if(utf8)
93                                         {
94                                                 write_utf8_to_window(str->window, utf8);
95                                                 g_free(utf8);
96                                         }
97                                 }       
98                                         str->write_count += len;
99                                         break;
100                                 default:
101                                         g_warning("%s: Writing to this kind of window unsupported.", __func__);
102                         }
103                         
104                         /* Now write the same buffer to the window's echo stream */
105                         if(str->window->echo_stream != NULL)
106                                 write_buffer_to_stream(str->window->echo_stream, buf, len);
107                         
108                         break;
109                         
110                 case STREAM_TYPE_MEMORY:
111                         if(str->unicode && str->ubuffer)
112                         {
113                                 int foo = 0;
114                                 while(str->mark < str->buflen && foo < len)
115                                         str->ubuffer[str->mark++] = (unsigned char)buf[foo++];
116                         }
117                         if(!str->unicode && str->buffer)
118                         {
119                                 int copycount = MIN(len, str->buflen - str->mark);
120                                 memmove(str->buffer + str->mark, buf, copycount);
121                                 str->mark += copycount;
122                         }
123
124                         str->write_count += len;
125                         break;
126                         
127                 case STREAM_TYPE_FILE:
128                         if(str->binary) 
129                         {
130                                 if(str->unicode) 
131                                 {
132                                         /* Convert to four-byte big-endian */
133                                         gchar *writebuffer = g_new0(gchar, len * 4);
134                                         int i;
135                                         for(i = 0; i < len; i++)
136                                                 writebuffer[i * 4 + 3] = buf[i];
137                                         fwrite(writebuffer, sizeof(gchar), len * 4, 
138                                                 str->file_pointer);
139                                 } 
140                                 else /* Regular file */
141                                 {
142                                         fwrite(buf, sizeof(gchar), len, str->file_pointer);
143                                 }
144                         }
145                         else /* Text mode is the same for Unicode and regular files */
146                         {
147                                 gchar *utf8 = convert_latin1_to_utf8(buf, len);
148                                 g_fprintf(str->file_pointer, "%s", utf8);
149                                 g_free(utf8);
150                         }
151                         
152                         str->write_count += len;
153                         break;
154                 default:
155                         g_warning("%s: Writing to this kind of stream unsupported.", __func__);
156         }
157 }
158
159 /**
160  * glk_put_char_stream:
161  * @str: An output stream.
162  * @ch: A character in Latin-1 encoding.
163  *
164  * Prints one character @ch to the stream @str. It is illegal for @str to be
165  * %NULL, or an input-only stream.
166  */
167 void
168 glk_put_char_stream(strid_t str, unsigned char ch)
169 {
170         g_return_if_fail(str != NULL);
171         g_return_if_fail(str->file_mode != filemode_Read);
172         
173         write_buffer_to_stream(str, (gchar *)&ch, 1);
174 }
175
176 /**
177  * glk_put_string_stream:
178  * @str: An output stream.
179  * @s: A null-terminated string in Latin-1 encoding.
180  *
181  * Prints @s to the stream @str. It is illegal for @str to be %NULL, or an
182  * input-only stream.
183  */
184 void
185 glk_put_string_stream(strid_t str, char *s)
186 {
187         g_return_if_fail(str != NULL);
188         g_return_if_fail(str->file_mode != filemode_Read);
189
190         write_buffer_to_stream(str, (gchar *)s, strlen(s));
191 }
192
193 /**
194  * glk_put_buffer_stream:
195  * @str: An output stream.
196  * @buf: An array of characters in Latin-1 encoding.
197  * @len: Length of @buf.
198  *
199  * Prints @buf to the stream @str. It is illegal for @str to be %NULL, or an
200  * input-only stream.
201  */
202 void
203 glk_put_buffer_stream(strid_t str, char *buf, glui32 len)
204 {
205         g_return_if_fail(str != NULL);
206         g_return_if_fail(str->file_mode != filemode_Read);
207         
208         write_buffer_to_stream(str, (gchar *)buf, len);
209 }
210
211 /*
212  *
213  **************** READING FUNCTIONS ********************************************
214  *
215  */
216
217 /* Internal function: Read one big-endian four-byte character from file fp and
218 return it as a Unicode code point, or -1 on EOF */
219 static glsi32
220 read_ucs4be_char_from_file(FILE *fp)
221 {
222         unsigned char readbuffer[4];
223         if(fread(readbuffer, sizeof(unsigned char), 4, fp) < 4)
224                 return -1; /* EOF */
225         return
226                 readbuffer[0] << 24 | 
227                 readbuffer[1] << 16 | 
228                 readbuffer[2] << 8  | 
229                 readbuffer[3];
230 }
231
232 /* Internal function: Read one UTF-8 character, which may be more than one byte,
233 from file fp and return it as a Unicode code point, or -1 on EOF */
234 static glsi32
235 read_utf8_char_from_file(FILE *fp)
236 {
237         gchar readbuffer[4] = {0, 0, 0, 0}; /* Max UTF-8 width */
238         int foo;
239         gunichar charresult = (gunichar)-2;
240         for(foo = 0; foo < 4 && charresult == (gunichar)-2; foo++) 
241         {
242                 int ch = fgetc(fp);
243                 if(ch == EOF)
244                         return -1;
245                 readbuffer[foo] = (gchar)ch;
246                 charresult = g_utf8_get_char_validated(readbuffer, foo + 1);
247                 /* charresult is -1 if invalid, -2 if incomplete, and the unicode code
248                 point otherwise */
249         }
250         /* Silently return unknown characters as 0xFFFD, Replacement Character */
251         if(charresult == (gunichar)-1 || charresult == (gunichar)-2) 
252                 return 0xFFFD;
253         return charresult;
254 }
255
256 /* Internal function: Tell whether this code point is a Unicode newline. The
257 file pointer and eight-bit flag are included in case the newline is a CR 
258 (U+000D). If the next character is LF (U+000A) then it also belongs to the
259 newline. */
260 static gboolean
261 is_unicode_newline(glsi32 ch, FILE *fp, gboolean utf8)
262 {
263         if(ch == 0x0A || ch == 0x85 || ch == 0x0C || ch == 0x2028 || ch == 0x2029)
264                 return TRUE;
265         if(ch == 0x0D) {
266                 glsi32 ch2 = utf8? read_utf8_char_from_file(fp) : 
267                         read_ucs4be_char_from_file(fp);
268                 if(ch2 != 0x0A)
269                         fseek(fp, utf8? -1 : -4, SEEK_CUR);
270                 return TRUE;
271         }
272         return FALSE;
273 }
274
275 /**
276  * glk_get_char_stream:
277  * @str: An input stream.
278  *
279  * Reads one character from the stream @str. (There is no notion of a ``current
280  * input stream.'') It is illegal for @str to be %NULL, or an output-only
281  * stream.
282  *
283  * The result will be between 0 and 255. As with all basic text functions, Glk
284  * assumes the Latin-1 encoding. If the end of the stream has been reached, the
285  * result will be -1. Note that high-bit characters (128..255) are
286  * <emphasis>not</emphasis> returned as negative numbers.
287  *
288  * If the stream contains Unicode data --- for example, if it was created with
289  * glk_stream_open_file_uni() or glk_stream_open_memory_uni() --- then
290  * characters beyond 255 will be returned as 0x3F ("?").
291  *
292  * Returns: A character value between 0 and 255, or -1 on end of stream.
293  */
294 glsi32
295 glk_get_char_stream(strid_t str)
296 {
297         g_return_val_if_fail(str != NULL, -1);
298         g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, -1);
299         
300         switch(str->type)
301         {
302                 case STREAM_TYPE_MEMORY:
303                         if(str->unicode)
304                         {
305                                 if(!str->ubuffer || str->mark >= str->buflen)
306                                         return -1;
307                                 glui32 ch = str->ubuffer[str->mark++];
308                                 str->read_count++;
309                                 return (ch > 0xFF)? 0x3F : ch;
310                         }
311                         else
312                         {
313                                 if(!str->buffer || str->mark >= str->buflen)
314                                         return -1;
315                                 char ch = str->buffer[str->mark++];
316                                 str->read_count++;
317                                 return ch;
318                         }
319                         break;
320                         
321                 case STREAM_TYPE_FILE:
322                         if(str->binary) 
323                         {
324                                 if(str->unicode) 
325                                 {
326                                         glsi32 ch = read_ucs4be_char_from_file(str->file_pointer);
327                                         if(ch == -1)
328                                                 return -1;
329                                         str->read_count++;
330                                         return (ch > 0xFF)? 0x3F : ch;
331                                 }
332                                 else /* Regular file */
333                                 {
334                                         int ch = fgetc(str->file_pointer);
335                                         if(ch == EOF)
336                                                 return -1;
337                                         
338                                         str->read_count++;
339                                         return ch;
340                                 }
341                         }
342                         else /* Text mode is the same for Unicode and regular files */
343                         {
344                                 glsi32 ch = read_utf8_char_from_file(str->file_pointer);
345                                 if(ch == -1)
346                                         return -1;
347                                         
348                                 str->read_count++;
349                                 return (ch > 0xFF)? 0x3F : ch;
350                         }
351                 default:
352                         g_warning("%s: Reading from this kind of stream unsupported.", __func__);
353                         return -1;
354         }
355 }
356
357 /**
358  * glk_get_buffer_stream:
359  * @str: An input stream.
360  * @buf: A buffer with space for at least @len characters.
361  * @len: The number of characters to read.
362  *
363  * Reads @len characters from @str, unless the end of stream is reached first.
364  * No terminal null is placed in the buffer.
365  *
366  * Returns: The number of characters actually read.
367  */
368 glui32
369 glk_get_buffer_stream(strid_t str, char *buf, glui32 len)
370 {
371         g_return_val_if_fail(str != NULL, 0);
372         g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, 0);
373         g_return_val_if_fail(buf != NULL, 0);
374         
375         switch(str->type)
376         {
377                 case STREAM_TYPE_MEMORY:
378                 {
379                         int copycount = 0;
380                         if(str->unicode)
381                         {
382                                 while(copycount < len && str->ubuffer && str->mark < str->buflen) 
383                                 {
384                                         glui32 ch = str->ubuffer[str->mark++];
385                                         buf[copycount++] = (ch > 0xFF)? '?' : (char)ch;
386                                 }
387                         }
388                         else
389                         {
390                                 if(str->buffer) /* if not, copycount stays 0 */
391                                         copycount = MIN(len, str->buflen - str->mark);
392                                 memmove(buf, str->buffer + str->mark, copycount);
393                                 str->mark += copycount;
394                         }
395
396                         str->read_count += copycount;           
397                         return copycount;
398                 }       
399                 case STREAM_TYPE_FILE:
400                         if(str->binary) 
401                         {
402                                 if(str->unicode) /* Binary file with 4-byte characters */
403                                 {
404                                         /* Read len characters of 4 bytes each */
405                                         unsigned char *readbuffer = g_new0(unsigned char, 4 * len);
406                                         size_t count = fread(readbuffer, sizeof(unsigned char), 4 * len, str->file_pointer);
407                                         /* If there was an incomplete character */
408                                         if(count % 4 != 0) 
409                                         {
410                                                 count -= count % 4;
411                                                 g_warning("%s: Incomplete character in binary Unicode file.", __func__);
412                                         }
413                                         
414                                         str->read_count += count / 4;
415                                         int foo;
416                                         for(foo = 0; foo < count; foo += 4)
417                                         {
418                                                 glsi32 ch = readbuffer[foo] << 24
419                                                         | readbuffer[foo + 1] << 16
420                                                         | readbuffer[foo + 2] << 8
421                                                         | readbuffer[foo + 3];
422                                                 buf[foo / 4] = (ch > 255)? 0x3F : (char)ch;
423                                         }
424                                         g_free(readbuffer);
425                                         return count / 4;
426                                 }
427                                 else /* Regular binary file */
428                                 {
429                                         size_t count = fread(buf, sizeof(char), len, str->file_pointer);
430                                         str->read_count += count;
431                                         return count;
432                                 }
433                         }
434                         else /* Text mode is the same for Unicode and regular files */
435                         {
436                                 /* Do it character-by-character */
437                                 int foo;
438                                 for(foo = 0; foo < len; foo++)
439                                 {
440                                         glsi32 ch = read_utf8_char_from_file(str->file_pointer);
441                                         if(ch == -1)
442                                                 break;
443                                         str->read_count++;
444                                         buf[foo] = (ch > 0xFF)? 0x3F : (gchar)ch;
445                                 }
446                                 return foo;
447                         }
448                 default:
449                         g_warning("%s: Reading from this kind of stream unsupported.", __func__);
450                         return 0;
451         }
452 }
453
454 /**
455  * glk_get_line_stream:
456  * @str: An input stream.
457  * @buf: A buffer with space for at least @len characters.
458  * @len: The number of characters to read, plus one.
459  *
460  * Reads characters from @str, until either @len - 1 characters have been read
461  * or a newline has been read. It then puts a terminal null ('\0') aracter on
462  * the end. It returns the number of characters actually read, including the
463  * newline (if there is one) but not including the terminal null.
464  *
465  * It is usually more efficient to read several characters at once with
466  * glk_get_buffer_stream() or glk_get_line_stream(), as opposed to calling
467  * glk_get_char_stream() several times.
468  *
469  * Returns: The number of characters actually read.
470  */
471 glui32
472 glk_get_line_stream(strid_t str, char *buf, glui32 len)
473 {
474         g_return_val_if_fail(str != NULL, 0);
475         g_return_val_if_fail(str->file_mode == filemode_Read || str->file_mode == filemode_ReadWrite, 0);
476         g_return_val_if_fail(buf != NULL, 0);
477
478         switch(str->type)
479         {
480                 case STREAM_TYPE_MEMORY:
481                 {
482                         int copycount = 0;
483                         if(str->unicode)
484                         {
485                                 /* Do it character-by-character */
486                                 while(copycount < len - 1 && str->ubuffer && str->mark < str->buflen) 
487                                 {
488                                         glui32 ch = str->ubuffer[str->mark++];
489                                         /* Check for Unicode newline; slightly different than
490                                         in file streams */
491                                         if(ch == 0x0A || ch == 0x85 || ch == 0x0C || ch == 0x2028 || ch == 0x2029)
492                                         {
493                                                 buf[copycount++] = '\n';
494                                                 break;
495                                         }
496                                         if(ch == 0x0D)
497                                         {
498                                                 if(str->ubuffer[str->mark] == 0x0A)
499                                                         str->mark++; /* skip past next newline */
500                                                 buf[copycount++] = '\n';
501                                                 break;
502                                         }
503                                         buf[copycount++] = (ch > 0xFF)? '?' : (char)ch;
504                                 }
505                                 buf[copycount] = '\0';
506                         }
507                         else
508                         {
509                                 if(str->buffer) /* if not, copycount stays 0 */
510                                         copycount = MIN(len - 1, str->buflen - str->mark);
511                                 char *endptr = memccpy(buf, str->buffer + str->mark, '\n', copycount);
512                                 if(endptr) /* newline was found */
513                                         copycount = endptr - buf; /* Real copy count */
514                                 buf[copycount] = '\0';
515                                 str->mark += copycount;
516                         }
517                         
518                         str->read_count += copycount;
519                         return copycount;
520                 }       
521                 case STREAM_TYPE_FILE:
522                         if(str->binary) 
523                         {
524                                 if(str->unicode) /* Binary file with 4-byte characters */
525                                 {
526                                         /* Do it character-by-character */
527                                         int foo;
528                                         for(foo = 0; foo < len - 1; foo++)
529                                         {
530                                                 glsi32 ch = read_ucs4be_char_from_file(str->file_pointer);
531                                                 if(ch == -1) 
532                                                 {
533                                                         buf[foo] = '\0';
534                                                         return foo - 1;
535                                                 }
536                                                 str->read_count++;
537                                                 if(is_unicode_newline(ch, str->file_pointer, FALSE))
538                                                 {
539                                                         buf[foo] = '\n';
540                                                         buf[foo + 1] = '\0';
541                                                         return foo;
542                                                 }
543                                                 buf[foo] = (ch > 0xFF)? '?' : (char)ch;
544                                         }
545                                         buf[len] = '\0';
546                                         return foo;
547                                 }
548                                 else /* Regular binary file */
549                                 {
550                                         fgets(buf, len, str->file_pointer);
551                                         str->read_count += strlen(buf);
552                                         return strlen(buf);
553                                 }
554                         }
555                         else /* Text mode is the same for Unicode and regular files */
556                         {
557                                 /* Do it character-by-character */
558                                 int foo;
559                                 for(foo = 0; foo < len - 1; foo++)
560                                 {
561                                         glsi32 ch = read_utf8_char_from_file(str->file_pointer);
562                                         if(ch == -1)
563                                         {
564                                                 buf[foo] = '\0';
565                                                 return foo - 1;
566                                         }
567                                         str->read_count++;
568                                         if(is_unicode_newline(ch, str->file_pointer, TRUE))
569                                         {
570                                                 buf[foo] = '\n';
571                                                 buf[foo + 1] = '\0';
572                                                 return foo;
573                                         }
574                                         buf[foo] = (ch > 0xFF)? 0x3F : (char)ch;
575                                 }
576                                 buf[len] = '\0';
577                                 return foo;
578                         }
579                 default:
580                         g_warning("%s: Reading from this kind of stream unsupported.", __func__);
581                         return 0;
582         }
583 }
584
585 /*
586  *
587  **************** SEEKING FUNCTIONS ********************************************
588  *
589  */
590
591 /**
592  * glk_stream_get_position:
593  * @str: A file or memory stream.
594  *
595  * Returns the position of the read/write mark in @str. For memory streams and
596  * binary file streams, this is exactly the number of characters read or written
597  * from the beginning of the stream (unless you have moved the mark with
598  * glk_stream_set_position().) For text file streams, matters are more 
599  * ambiguous, since (for example) writing one byte to a text file may store more
600  * than one character in the platform's native encoding. You can only be sure
601  * that the position increases as you read or write to the file.
602  *
603  * Additional complication: for Latin-1 memory and file streams, a character is
604  * a byte. For Unicode memory and file streams (those created by
605  * glk_stream_open_file_uni() and glk_stream_open_memory_uni()), a character is
606  * a 32-bit word. So in a binary Unicode file, positions are multiples of four
607  * bytes.
608  *
609  * Returns: position of the read/write mark in @str.
610  */
611 glui32
612 glk_stream_get_position(strid_t str)
613 {
614         g_return_val_if_fail(str != NULL, 0);
615         
616         switch(str->type)
617         {
618                 case STREAM_TYPE_MEMORY:
619                         return str->mark;
620                 case STREAM_TYPE_FILE:
621                         return ftell(str->file_pointer);
622                 default:
623                         g_warning("%s: Seeking not supported on this type of stream.",
624                                 __func__);
625                         return 0;
626         }
627 }
628
629 /**
630  * glk_stream_set_position:
631  * @str: A file or memory stream.
632  * @pos: The position to set the mark to, relative to @seekmode.
633  * @seekmode: One of #seekmode_Start, #seekmode_Current, or #seekmode_End.
634  *
635  * Sets the position of the read/write mark in @str. The position is controlled
636  * by @pos, and the meaning of @pos is controlled by @seekmode:
637  * <itemizedlist>
638  *  <listitem>#seekmode_Start: @pos characters after the beginning of the file.
639  *  </listitem>
640  *  <listitem>#seekmode_Current: @pos characters after the current position
641  *  (moving backwards if @pos is negative.)</listitem>
642  *  <listitem>#seekmode_End: @pos characters after the end of the file. (@pos
643  *  should always be zero or negative, so that this will move backwards to a
644  *  position within the file.</listitem>
645  * </itemizedlist>
646  * It is illegal to specify a position before the beginning or after the end of
647  * the file.
648  *
649  * In binary files, the mark position is exact --- it corresponds with the
650  * number of characters you have read or written. In text files, this mapping 
651  * can vary, because of linefeed conventions or other character-set 
652  * approximations. glk_stream_set_position() and glk_stream_get_position()
653  * measure positions in the platform's native encoding --- after character
654  * cookery. Therefore, in a text stream, it is safest to use
655  * glk_stream_set_position() only to move to the beginning or end of a file, or
656  * to a position determined by glk_stream_get_position().
657  *
658  * Again, in Latin-1 streams, characters are bytes. In Unicode streams,
659  * characters are 32-bit words, or four bytes each.
660  */
661 void
662 glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekmode)
663 {
664         g_return_if_fail(str != NULL);
665         g_return_if_fail(!(seekmode == seekmode_Start && pos < 0));
666         g_return_if_fail(!(seekmode == seekmode_End || pos > 0));
667         
668         switch(str->type)
669         {
670                 case STREAM_TYPE_MEMORY:
671                         switch(seekmode)
672                         {
673                                 case seekmode_Start:   str->mark = pos;  break;
674                                 case seekmode_Current: str->mark += pos; break;
675                                 case seekmode_End:     str->mark = str->buflen + pos; break;
676                                 default:
677                                         g_assert_not_reached();
678                                         return;
679                         }
680                         break;
681                 case STREAM_TYPE_FILE:
682                 {
683                         int whence;
684                         switch(seekmode)
685                         {
686                                 case seekmode_Start:   whence = SEEK_SET; break;
687                                 case seekmode_Current: whence = SEEK_CUR; break;
688                                 case seekmode_End:     whence = SEEK_END; break;
689                                 default:
690                                         g_assert_not_reached();
691                                         return;
692                         }
693                         fseek(str->file_pointer, pos, whence);
694                         break;
695                 }
696                 default:
697                         g_warning("%s: Seeking not supported on this type of stream.", __func__);
698                         return;
699         }
700 }
701