1
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8-*- */
4
* This file is part of The Croco Library
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of version 2.1 of the GNU Lesser General Public
8
* License as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
* Author: Dodji Seketeli
21
* See COPYRIGHTS file for copyright information.
27
#include "cr-enc-handler.h"
31
*The definition of the #CRInput class.
39
*The private attributes of
40
*the #CRInputPriv class.
52
*The index of the next byte
55
gulong next_byte_index;
58
*The current line number
63
*The current col number
68
gboolean end_of_input;
71
*the reference count of this
78
#define PRIVATE(object) (object)->priv
80
/***************************
82
**************************/
83
#define CR_INPUT_MEM_CHUNK_SIZE 1024 * 4
85
static CRInput *cr_input_new_real (void);
88
cr_input_new_real (void)
90
CRInput *result = NULL;
92
result = g_try_malloc (sizeof (CRInput));
94
cr_utils_trace_info ("Out of memory");
97
memset (result, 0, sizeof (CRInput));
99
PRIVATE (result) = g_try_malloc (sizeof (CRInputPriv));
100
if (!PRIVATE (result)) {
101
cr_utils_trace_info ("Out of memory");
105
memset (PRIVATE (result), 0, sizeof (CRInputPriv));
106
PRIVATE (result)->free_in_buf = TRUE;
115
*Creates a new input stream from a memory buffer.
116
*@param a_buf the memory buffer to create the input stream from.
117
*The #CRInput keeps this pointer so user should not free it !.
118
*@param a_len the size of the input buffer.
119
*@param a_enc the buffer's encoding.
120
*@param a_free_buf if set to TRUE, this a_buf will be freed
121
*at the destruction of this instance. If set to false, it is up
122
*to the caller to free it.
123
*@return the newly built instance of #CRInput.
126
cr_input_new_from_buf (guchar * a_buf,
128
enum CREncoding a_enc,
131
CRInput *result = NULL;
132
enum CRStatus status = CR_OK;
133
CREncHandler *enc_handler = NULL;
136
g_return_val_if_fail (a_buf, NULL);
138
result = cr_input_new_real ();
139
g_return_val_if_fail (result, NULL);
141
/*transform the encoding in utf8 */
142
if (a_enc != CR_UTF_8) {
143
enc_handler = cr_enc_handler_get_instance (a_enc);
148
status = cr_enc_handler_convert_input
149
(enc_handler, a_buf, &len,
150
&PRIVATE (result)->in_buf,
151
&PRIVATE (result)->in_buf_size);
154
PRIVATE (result)->free_in_buf = TRUE;
155
if (a_free_buf == TRUE && a_buf) {
159
PRIVATE (result)->nb_bytes = PRIVATE (result)->in_buf_size;
161
PRIVATE (result)->in_buf = (guchar *) a_buf;
162
PRIVATE (result)->in_buf_size = a_len;
163
PRIVATE (result)->nb_bytes = a_len;
164
PRIVATE (result)->free_in_buf = a_free_buf;
166
PRIVATE (result)->line = 1;
167
PRIVATE (result)->col = 0;
172
cr_input_destroy (result);
180
*Creates a new input stream from
182
*@param a_file_uri the file to create
183
*the input stream from.
184
*@param a_enc the encoding of the file
185
*to create the input from
186
*@return the newly created input stream if
187
*this method could read the file and create it,
192
cr_input_new_from_uri (const gchar * a_file_uri, enum CREncoding a_enc)
194
CRInput *result = NULL;
195
enum CRStatus status = CR_OK;
196
FILE *file_ptr = NULL;
197
guchar tmp_buf[CR_INPUT_MEM_CHUNK_SIZE] = { 0 };
201
gboolean loop = TRUE;
204
g_return_val_if_fail (a_file_uri, NULL);
206
file_ptr = fopen (a_file_uri, "r");
208
if (file_ptr == NULL) {
211
cr_utils_trace_debug ("could not open file");
213
g_warning ("Could not open file %s\n", a_file_uri);
220
nb_read = fread (tmp_buf, 1 /*read bytes */ ,
221
CR_INPUT_MEM_CHUNK_SIZE /*nb of bytes */ ,
224
if (nb_read != CR_INPUT_MEM_CHUNK_SIZE) {
225
/*we read less chars than we wanted */
226
if (feof (file_ptr)) {
231
cr_utils_trace_debug ("an io error occured");
237
if (status == CR_OK) {
239
buf = g_realloc (buf, len + CR_INPUT_MEM_CHUNK_SIZE);
240
memcpy (buf + len, tmp_buf, nb_read);
242
buf_size += CR_INPUT_MEM_CHUNK_SIZE;
246
if (status == CR_OK) {
247
result = cr_input_new_from_buf (buf, len, a_enc, TRUE);
252
*we should free buf here because it's own by CRInput.
253
*(see the last parameter of cr_input_new_from_buf().
273
*The destructor of the #CRInput class.
274
*@param a_this the current instance of #CRInput.
277
cr_input_destroy (CRInput * a_this)
282
if (PRIVATE (a_this)) {
283
if (PRIVATE (a_this)->in_buf && PRIVATE (a_this)->free_in_buf) {
284
g_free (PRIVATE (a_this)->in_buf);
285
PRIVATE (a_this)->in_buf = NULL;
288
g_free (PRIVATE (a_this));
289
PRIVATE (a_this) = NULL;
296
*Increments the reference count of the current
297
*instance of #CRInput.
298
*@param a_this the current instance of #CRInput.
301
cr_input_ref (CRInput * a_this)
303
g_return_if_fail (a_this && PRIVATE (a_this));
305
PRIVATE (a_this)->ref_count++;
309
*Decrements the reference count of this instance
310
*of #CRInput. If the reference count goes down to
311
*zero, this instance is destroyed.
312
*@param a_this the current instance of #CRInput.
316
cr_input_unref (CRInput * a_this)
318
g_return_val_if_fail (a_this && PRIVATE (a_this), FALSE);
320
if (PRIVATE (a_this)->ref_count) {
321
PRIVATE (a_this)->ref_count--;
324
if (PRIVATE (a_this)->ref_count == 0) {
325
cr_input_destroy (a_this);
332
*Tests wether the current instance of
333
*#CRInput has reached its input buffer.
334
*@param a_this the current instance of #CRInput.
335
*@param a_end_of_input out parameter. Is set to TRUE if
336
*the current instance has reached the end of its input buffer,
338
*@param CR_OK upon successful completion, an error code otherwise.
339
*Note that all the out parameters of this method are valid if
340
*and only if this method returns CR_OK.
343
cr_input_end_of_input (CRInput * a_this, gboolean * a_end_of_input)
345
g_return_val_if_fail (a_this && PRIVATE (a_this)
346
&& a_end_of_input, CR_BAD_PARAM_ERROR);
348
*a_end_of_input = (PRIVATE (a_this)->next_byte_index
349
>= PRIVATE (a_this)->in_buf_size) ? TRUE : FALSE;
355
*Returns the number of bytes left in the input stream
357
*@param a_this the current instance of #CRInput.
358
*@return the number of characters left or -1 in case of error.
361
cr_input_get_nb_bytes_left (CRInput * a_this)
363
g_return_val_if_fail (a_this && PRIVATE (a_this), -1);
364
g_return_val_if_fail (PRIVATE (a_this)->nb_bytes
365
<= PRIVATE (a_this)->in_buf_size, -1);
366
g_return_val_if_fail (PRIVATE (a_this)->next_byte_index
367
<= PRIVATE (a_this)->nb_bytes, -1);
369
if (PRIVATE (a_this)->end_of_input)
372
return PRIVATE (a_this)->nb_bytes - PRIVATE (a_this)->next_byte_index;
376
*Returns the next byte of the input.
377
*Update the state of the input so that
378
*the next invocation of this method returns
379
*the next coming byte.
381
*@param a_this the current instance of #CRInput.
382
*@param a_byte out parameter the returned byte.
383
*@return CR_OK upon successful completion, an error code
384
*otherwise. All the out parameters of this method are valid if
385
*and only if this method returns CR_OK.
388
cr_input_read_byte (CRInput * a_this, guchar * a_byte)
390
g_return_val_if_fail (a_this && PRIVATE (a_this)
391
&& a_byte, CR_BAD_PARAM_ERROR);
393
g_return_val_if_fail (PRIVATE (a_this)->next_byte_index <=
394
PRIVATE (a_this)->nb_bytes, CR_BAD_PARAM_ERROR);
396
if (PRIVATE (a_this)->end_of_input == TRUE)
397
return CR_END_OF_INPUT_ERROR;
399
*a_byte = PRIVATE (a_this)->in_buf[PRIVATE (a_this)->next_byte_index];
401
if (PRIVATE (a_this)->nb_bytes -
402
PRIVATE (a_this)->next_byte_index < 2) {
403
PRIVATE (a_this)->end_of_input = TRUE;
405
PRIVATE (a_this)->next_byte_index++;
412
*Reads an unicode character from the current instance of
414
*@param a_this the current instance of CRInput.
415
*@param a_char out parameter. The read character.
416
*@return CR_OK upon successful completion, an error code
420
cr_input_read_char (CRInput * a_this, guint32 * a_char)
422
enum CRStatus status = CR_OK;
426
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_char,
429
if (PRIVATE (a_this)->end_of_input == TRUE)
430
return CR_END_OF_INPUT_ERROR;
432
nb_bytes_left = cr_input_get_nb_bytes_left (a_this);
434
if (nb_bytes_left < 1) {
435
return CR_END_OF_INPUT_ERROR;
438
status = cr_utils_read_char_from_utf8_buf
439
(PRIVATE (a_this)->in_buf
441
PRIVATE (a_this)->next_byte_index,
442
nb_bytes_left, a_char, &consumed);
444
if (status == CR_OK) {
445
/*update next byte index */
446
PRIVATE (a_this)->next_byte_index += consumed;
448
/*update line and column number */
449
if (PRIVATE (a_this)->end_of_line == TRUE) {
450
PRIVATE (a_this)->col = 1;
451
PRIVATE (a_this)->line++;
452
PRIVATE (a_this)->end_of_line = FALSE;
453
} else if (*a_char != '\n') {
454
PRIVATE (a_this)->col++;
457
if (*a_char == '\n') {
458
PRIVATE (a_this)->end_of_line = TRUE;
467
*Setter of the current line number.
468
*@param a_this the "this pointer" of the current instance of
470
*@param a_line_num the new line number.
471
*@return CR_OK upon successful completion, an error code otherwise.
474
cr_input_set_line_num (CRInput * a_this, glong a_line_num)
476
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
478
PRIVATE (a_this)->line = a_line_num;
484
*Getter of the current line number.
485
*@param a_this the "this pointer" of the current instance of
487
*@param a_line_num the returned line number.
488
*@return CR_OK upon successful completion, an error code otherwise.
491
cr_input_get_line_num (CRInput * a_this, glong * a_line_num)
493
g_return_val_if_fail (a_this && PRIVATE (a_this)
494
&& a_line_num, CR_BAD_PARAM_ERROR);
496
*a_line_num = PRIVATE (a_this)->line;
502
*Setter of the current column number.
503
*@param a_this the "this pointer" of the current instance of
505
*@param a_col the new column number.
506
*@return CR_OK upon successful completion, an error code otherwise.
509
cr_input_set_column_num (CRInput * a_this, glong a_col)
511
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
513
PRIVATE (a_this)->col = a_col;
519
*Getter of the current column number.
520
*@param a_this the "this pointer" of the current instance of
522
*@param a_col out parameter
523
*@return CR_OK upon successful completion, an error code otherwise.
526
cr_input_get_column_num (CRInput * a_this, glong * a_col)
528
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_col,
531
*a_col = PRIVATE (a_this)->col;
537
*Increments the current line number.
538
*@param a_this the "this pointer" of the current instance of
540
*@return CR_OK upon successful completion, an error code otherwise.
543
cr_input_increment_line_num (CRInput * a_this, glong a_increment)
545
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
547
PRIVATE (a_this)->line += a_increment;
553
*Increments the current column number.
554
*@param a_this the "this pointer" of the current instance of
556
*@return CR_OK upon successful completion, an error code otherwise.
559
cr_input_increment_col_num (CRInput * a_this, glong a_increment)
561
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
563
PRIVATE (a_this)->col += a_increment;
569
*Consumes the next character of the input stream if
570
*and only if that character equals a_char.
572
*@param a_this the this pointer.
573
*@param a_char the character to consume. If set to zero,
574
*consumes any character.
575
*@return CR_OK upon successful completion, CR_PARSING_ERROR if
576
*next char is different from a_char, an other error code otherwise
579
cr_input_consume_char (CRInput * a_this, guint32 a_char)
582
enum CRStatus status;
584
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
586
if ((status = cr_input_peek_char (a_this, &c)) != CR_OK) {
590
if (c == a_char || a_char == 0) {
591
status = cr_input_read_char (a_this, &c);
593
return CR_PARSING_ERROR;
600
*Consumes up to a_nb_char occurences of the next contiguous characters
601
*which equal a_char. Note that the next character of the input stream
602
**MUST* equal a_char to trigger the consumption, or else, the error
603
*code CR_PARSING_ERROR is returned.
604
*If the number of contiguous characters that equals a_char is less than
605
*a_nb_char, then this function consumes all the characters it can consume.
607
*@param a_this the this pointer of the current instance of #CRInput.
608
*@param a_char the character to consume.
609
*@param a_nb_char in/out parameter. The number of characters to consume.
610
*If set to a negative value, the function will consume all the occurences
612
*After return, if the return value equals CR_OK, this variable contains
613
*the number of characters actually consumed.
614
*@return CR_OK if at least one character has been consumed, an error code
618
cr_input_consume_chars (CRInput * a_this, guint32 a_char, gulong * a_nb_char)
620
enum CRStatus status = CR_OK;
621
gulong nb_consumed = 0;
623
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_nb_char,
626
g_return_val_if_fail (a_char != 0 || a_nb_char != NULL,
629
for (nb_consumed = 0; ((status == CR_OK)
631
&& nb_consumed < *a_nb_char));
633
status = cr_input_consume_char (a_this, a_char);
636
*a_nb_char = nb_consumed;
638
if ((nb_consumed > 0)
639
&& ((status == CR_PARSING_ERROR)
640
|| (status == CR_END_OF_INPUT_ERROR))) {
648
*Same as cr_input_consume_chars() but this one consumes white
651
*@param a_this the "this pointer" of the current instance of #CRInput.
652
*@param a_nb_chars in/out parameter. The number of white spaces to
653
*consume. After return, holds the number of white spaces actually consumed.
654
*@return CR_OK upon successful completion, an error code otherwise.
657
cr_input_consume_white_spaces (CRInput * a_this, gulong * a_nb_chars)
659
enum CRStatus status = CR_OK;
660
guint32 cur_char = 0,
663
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_nb_chars,
666
for (nb_consumed = 0;
667
((*a_nb_chars > 0) && (nb_consumed < *a_nb_chars));
669
status = cr_input_peek_char (a_this, &cur_char);
673
/*if the next char is a white space, consume it ! */
674
if (cr_utils_is_white_space (cur_char) == TRUE) {
675
status = cr_input_read_char (a_this, &cur_char);
685
if (nb_consumed && status == CR_END_OF_INPUT_ERROR) {
693
*Same as cr_input_read_char() but does not update the
694
*internal state of the input stream. The next call
695
*to cr_input_peek_char() or cr_input_read_char() will thus
696
*return the same character as the current one.
697
*@param a_this the current instance of #CRInput.
698
*@param a_char out parameter. The returned character.
699
*@return CR_OK upon successful completion, an error code
703
cr_input_peek_char (CRInput * a_this, guint32 * a_char)
705
enum CRStatus status = CR_OK;
709
g_return_val_if_fail (a_this && PRIVATE (a_this)
710
&& a_char, CR_BAD_PARAM_ERROR);
712
if (PRIVATE (a_this)->next_byte_index >=
713
PRIVATE (a_this)->in_buf_size) {
714
return CR_END_OF_INPUT_ERROR;
717
nb_bytes_left = cr_input_get_nb_bytes_left (a_this);
719
if (nb_bytes_left < 1) {
720
return CR_END_OF_INPUT_ERROR;
723
status = cr_utils_read_char_from_utf8_buf
724
(PRIVATE (a_this)->in_buf +
725
PRIVATE (a_this)->next_byte_index,
726
nb_bytes_left, a_char, &consumed);
732
*Gets a byte from the input stream,
733
*starting from the current position in the input stream.
734
*Unlike cr_input_peek_next_byte() this method
735
*does not update the state of the current input stream.
736
*Subsequent calls to cr_input_peek_byte with the same arguments
737
*will return the same byte.
739
*@param a_this the current instance of #CRInput.
740
*@param a_origin the origin to consider in the calculation
741
*of the position of the byte to peek.
742
*@param a_offset the offset of the byte to peek, starting from
743
*the origin specified by a_origin.
744
*@param a_byte out parameter the peeked byte.
745
*@return CR_OK upon successful completion or,
748
*<li>CR_BAD_PARAM_ERROR if at least one of the parameters is invalid</li>
749
*<li>CR_OUT_OF_BOUNDS_ERROR if the indexed byte is out of bounds</li>
753
cr_input_peek_byte (CRInput * a_this, enum CRSeekPos a_origin,
754
gulong a_offset, guchar * a_byte)
756
gulong abs_offset = 0;
758
g_return_val_if_fail (a_this && PRIVATE (a_this)
759
&& a_byte, CR_BAD_PARAM_ERROR);
764
abs_offset = PRIVATE (a_this)->next_byte_index - 1 + a_offset;
768
abs_offset = a_offset;
772
abs_offset = PRIVATE (a_this)->in_buf_size - 1 - a_offset;
776
return CR_BAD_PARAM_ERROR;
779
if (abs_offset < PRIVATE (a_this)->in_buf_size) {
781
*a_byte = PRIVATE (a_this)->in_buf[abs_offset];
786
return CR_END_OF_INPUT_ERROR;
791
*Same as cr_input_peek_byte() but with a simplified
793
*@param a_this the current byte input stream.
794
*@param a_offset the offset of the byte to peek, starting
795
*from the current input position pointer.
796
*@param a_eof out parameter. Is set to true is we reach end of
797
*stream. If set to NULL by the caller, this parameter is not taken
799
*@return the read byte or 0 if something bad happened.
802
cr_input_peek_byte2 (CRInput * a_this, gulong a_offset, gboolean * a_eof)
805
enum CRStatus status = CR_ERROR;
807
g_return_val_if_fail (a_this && PRIVATE (a_this), 0);
812
status = cr_input_peek_byte (a_this, CR_SEEK_CUR, a_offset, &result);
814
if ((status == CR_END_OF_INPUT_ERROR)
822
*Returns the memory address of the byte located at a given offset
823
*in the input stream.
824
*@param a_this the current instance of #CRInput.
825
*@param a_offset the offset of the byte in the input stream starting
826
*from the beginning of the stream.
827
*@return the address, otherwise NULL if an error occured.
830
cr_input_get_byte_addr (CRInput * a_this, gulong a_offset)
832
g_return_val_if_fail (a_this && PRIVATE (a_this), NULL);
834
if (a_offset >= PRIVATE (a_this)->nb_bytes) {
838
return &PRIVATE (a_this)->in_buf[a_offset];
842
*Returns the address of the current character pointer.
843
*@param a_this the current input stream
844
*@param a_offset out parameter. The returned address.
845
*@return CR_OK upon successful completion, an error code otherwise.
848
cr_input_get_cur_byte_addr (CRInput * a_this, guchar ** a_offset)
850
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_offset,
853
if (!PRIVATE (a_this)->next_byte_index) {
854
return CR_START_OF_INPUT_ERROR;
857
*a_offset = cr_input_get_byte_addr
858
(a_this, PRIVATE (a_this)->next_byte_index - 1);
864
*Sets the "current byte index" of the current instance
865
*of #CRInput. Next call to cr_input_get_byte() will return
866
*the byte next after the new "current byte index".
868
*@param a_this the current instance of #CRInput.
870
*@param a_origin the origin to consider during the calculation
871
*of the absolute position of the new "current byte index".
873
*@param a_pos the relative offset of the new "current byte index."
874
*This offset is relative to the origin a_origin.
876
*@return CR_OK upon successful completion otherwise returns
878
*<li>CR_BAD_PARAM_ERROR if at least one of the parameters is not valid</li>
879
*<li>CR_OUT_BOUNDS_ERROR</li>
883
cr_input_seek_index (CRInput * a_this, enum CRSeekPos a_origin, gint a_pos)
886
glong abs_offset = 0;
888
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
893
abs_offset = PRIVATE (a_this)->next_byte_index - 1 + a_pos;
901
abs_offset = PRIVATE (a_this)->in_buf_size - 1 - a_pos;
905
return CR_BAD_PARAM_ERROR;
909
&& (gulong) abs_offset < PRIVATE (a_this)->nb_bytes) {
911
/*update the input stream's internal state */
912
PRIVATE (a_this)->next_byte_index = abs_offset + 1;
917
return CR_OUT_OF_BOUNDS_ERROR;
921
*Gets the position of the "current byte index" which
922
*is basically the position of the last returned byte in the
925
*@param a_this the current instance of #CRInput.
927
*@param a_pos out parameter. The returned position.
929
*@return CR_OK upon successful completion. Otherwise,
931
*<li>CR_BAD_PARAMETER_ERROR if at least one of the arguments is invalid.</li>
932
*<li>CR_START_OF_INPUT if no call to either cr_input_read_byte()
933
*or cr_input_seek_index() have been issued before calling
934
*cr_input_get_cur_pos()</li>
936
*Note that the out parameters of this function are valid if and only if this
937
*function returns CR_OK.
940
cr_input_get_cur_pos (CRInput * a_this, CRInputPos * a_pos)
942
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pos,
945
a_pos->next_byte_index = PRIVATE (a_this)->next_byte_index;
946
a_pos->line = PRIVATE (a_this)->line;
947
a_pos->col = PRIVATE (a_this)->col;
948
a_pos->end_of_line = PRIVATE (a_this)->end_of_line;
949
a_pos->end_of_file = PRIVATE (a_this)->end_of_input;
955
*Gets the current parsing location.
956
*The Parsing location is a public datastructure that
957
*represents the current line/column/byte offset/ in the input
959
*@param a_this the current instance of #CRInput
960
*@param a_loc the set parsing location.
961
*@return CR_OK upon successful completion, an error
965
cr_input_get_parsing_location (CRInput *a_this,
966
CRParsingLocation *a_loc)
968
g_return_val_if_fail (a_this
971
CR_BAD_PARAM_ERROR) ;
973
a_loc->line = PRIVATE (a_this)->line ;
974
a_loc->column = PRIVATE (a_this)->col ;
975
if (PRIVATE (a_this)->next_byte_index) {
976
a_loc->byte_offset = PRIVATE (a_this)->next_byte_index - 1 ;
978
a_loc->byte_offset = PRIVATE (a_this)->next_byte_index ;
984
*Getter of the next byte index.
985
*It actually returns the index of the
986
*next byte to be read.
987
*@param a_this the "this pointer" of the current instance of
989
*@param a_index out parameter. The returned index.
990
*@return CR_OK upon successful completion, an error code
994
cr_input_get_cur_index (CRInput * a_this, glong * a_index)
996
g_return_val_if_fail (a_this && PRIVATE (a_this)
997
&& a_index, CR_BAD_PARAM_ERROR);
999
*a_index = PRIVATE (a_this)->next_byte_index;
1005
*Setter of the next byte index.
1006
*It sets the index of the next byte to be read.
1007
*@param a_this the "this pointer" of the current instance
1009
*@param a_index the new index to set.
1010
*@return CR_OK upon successful completion, an error code otherwise.
1013
cr_input_set_cur_index (CRInput * a_this, glong a_index)
1015
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
1017
PRIVATE (a_this)->next_byte_index = a_index;
1023
*Sets the end of file flag.
1024
*@param a_this the current instance of #CRInput.
1025
*@param a_eof the new end of file flag.
1026
*@return CR_OK upon successful completion, an error code otherwise.
1029
cr_input_set_end_of_file (CRInput * a_this, gboolean a_eof)
1031
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
1033
PRIVATE (a_this)->end_of_input = a_eof;
1039
*Gets the end of file flag.
1040
*@param a_this the current instance of #CRInput.
1041
*@param a_eof out parameter the place to put the end of
1043
*@return CR_OK upon successful completion, an error code otherwise.
1046
cr_input_get_end_of_file (CRInput * a_this, gboolean * a_eof)
1048
g_return_val_if_fail (a_this && PRIVATE (a_this)
1049
&& a_eof, CR_BAD_PARAM_ERROR);
1051
*a_eof = PRIVATE (a_this)->end_of_input;
1057
*Sets the end of line flag.
1058
*@param a_this the current instance of #CRInput.
1059
*@param a_eol the new end of line flag.
1060
*@return CR_OK upon successful completion, an error code
1064
cr_input_set_end_of_line (CRInput * a_this, gboolean a_eol)
1066
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
1068
PRIVATE (a_this)->end_of_line = a_eol;
1074
*Gets the end of line flag of the current input.
1075
*@param a_this the current instance of #CRInput
1076
*@param a_eol out parameter. The place to put
1078
*@return CR_OK upon successful completion, an error code
1082
cr_input_get_end_of_line (CRInput * a_this, gboolean * a_eol)
1084
g_return_val_if_fail (a_this && PRIVATE (a_this)
1085
&& a_eol, CR_BAD_PARAM_ERROR);
1087
*a_eol = PRIVATE (a_this)->end_of_line;
1093
*Sets the current position in the input stream.
1095
*@param a_this the "this pointer" of the current instance of
1097
*@param a_pos the new position.
1100
cr_input_set_cur_pos (CRInput * a_this, CRInputPos * a_pos)
1102
g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pos,
1103
CR_BAD_PARAM_ERROR);
1105
cr_input_set_column_num (a_this, a_pos->col);
1106
cr_input_set_line_num (a_this, a_pos->line);
1107
cr_input_set_cur_index (a_this, a_pos->next_byte_index);
1108
cr_input_set_end_of_line (a_this, a_pos->end_of_line);
1109
cr_input_set_end_of_file (a_this, a_pos->end_of_file);