enhanced record handling for CRLF

This commit is contained in:
hyung-hwan 2011-05-02 08:37:17 +00:00
parent 9514c71a03
commit 12adaea5a3
2 changed files with 69 additions and 27 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: rio.c 447 2011-05-01 13:28:51Z hyunghwan.chung $
* $Id: rio.c 449 2011-05-01 14:37:17Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -365,7 +365,16 @@ int qse_awk_rtx_readio (
/* drop the line terminator from the record
* if RS is a blank line and EOF is reached. */
if (QSE_STR_LASTCHAR(buf) == QSE_T('\n'))
{
QSE_STR_LEN(buf) -= 1;
if (run->awk->option & QSE_AWK_CRLF)
{
/* drop preceding CR */
if (QSE_STR_LEN(buf) > 0 &&
QSE_STR_LASTCHAR(buf) == QSE_T('\r'))
QSE_STR_LEN(buf) -= 1;
}
}
}
else if (rrs.len >= 2)
{
@ -412,16 +421,16 @@ int qse_awk_rtx_readio (
{
if (end_pos > start_pos)
{
/* '\r' is the part of the read buffer.
/* CR is the part of the read buffer.
* decrementing the end_pos variable can
* simply drop it */
end_pos--;
}
else
{
/* '\r' must have come from the previous
* read. the record buffer must contain
* it at the end. */
/* CR must have come from the previous
* read. drop CR that must be found at
* the end of the record buffer. */
QSE_ASSERT (end_pos == start_pos);
QSE_ASSERT (QSE_STR_LEN(buf) > 0);
QSE_ASSERT (QSE_STR_LASTCHAR(buf) == QSE_T('\r'));
@ -467,12 +476,26 @@ int qse_awk_rtx_readio (
* by dropping of CR before NL */
QSE_ASSERT (line_len > 0);
line_len--;
/* we don't drop CR from the record buffer
* if we're in CRLF mode. POINT-X */
if (!(run->awk->option & QSE_AWK_CRLF))
QSE_STR_LEN(buf) -= 1;
}
if (line_len == 0)
{
/* we got a blank line */
if (run->awk->option & QSE_AWK_CRLF)
{
if (QSE_STR_LEN(buf) > 0 &&
QSE_STR_LASTCHAR(buf) == QSE_T('\r'))
{
/* drop CR not dropped in POINT-X above */
QSE_STR_LEN(buf) -= 1;
}
if (QSE_STR_LEN(buf) <= 0)
{
/* if the record is empty when a blank
@ -482,10 +505,29 @@ int qse_awk_rtx_readio (
continue;
}
/* when a blank line is encountered,
* it needs to snip off the line
* terminator of the previous line */
/* drop NL */
QSE_STR_LEN(buf) -= 1;
/* drop preceding CR */
if (QSE_STR_LEN(buf) > 0 &&
QSE_STR_LASTCHAR(buf) == QSE_T('\r'))
QSE_STR_LEN(buf) -= 1;
}
else
{
if (QSE_STR_LEN(buf) <= 0)
{
/* if the record is empty when a blank
* line is encountered, the line
* terminator should not be added to
* the record */
continue;
}
/* drop NL of the previous line */
QSE_STR_LEN(buf) -= 1; /* simply drop NL */
}
done = 1;
break;
}

View File

@ -84,14 +84,14 @@ WRect
1880
5700
4240
0
1
0
22
WFileName
30
release/os2/lib/cmn/qsecmn.tgt
28
30
29
23
VComponent
24
@ -145,10 +145,10 @@ VComponent
33
WRect
380
-160
0
5700
4240
0
1
0
34
WFileName
@ -260,14 +260,14 @@ WRect
80
5700
4240
1
0
0
55
WFileName
28
debug/os2/lib/awk/qseawk.tgt
8
10
12
56
VComponent
57
@ -289,7 +289,7 @@ VComponent
60
WRect
2920
893
880
5700
4240
0
@ -300,4 +300,4 @@ WFileName
debug/os2/cmd/awk/qseawk.tgt
0
1
32
59