Commit a24b15d0 by Alan Mishchenko

Suggested changes for the case when the file begings with a new line.

parent ee228339
...@@ -129,24 +129,32 @@ void Amap_RemoveComments( char * pBuffer, int * pnDots, int * pnLines ) ...@@ -129,24 +129,32 @@ void Amap_RemoveComments( char * pBuffer, int * pnDots, int * pnLines )
{ {
// if this is the beginning of comment // if this is the beginning of comment
// clean it with spaces until the new line statement // clean it with spaces until the new line statement
if ( *pCur == '#' ) if ( *pCur == '#' ) {
while ( *pCur != '\n' ) while ( *pCur != '\n' ) {
*pCur++ = ' '; *pCur++ = ' ';
}
}
// count the number of new lines and dots // count the number of new lines and dots
if ( *pCur == '\n' ) { if ( *pCur == '\n' ) {
if (*(pCur-1)=='\r') { if (pCur > pBuffer) {
if (*(pCur - 1) == '\r') {
// DOS(R) file support // DOS(R) file support
if (*(pCur-2)!='\\') nLines++; if (pCur > (pBuffer + 1)) {
if (*(pCur - 2)!='\\') {
nLines++;
}
else { else {
// rewind to backslash and overwrite with a space // rewind to backslash and overwrite with a space
*(pCur-2) = ' '; *(pCur - 2) = ' ';
*(pCur-1) = ' '; *(pCur - 1) = ' ';
*pCur = ' '; *pCur = ' ';
} }
}
} else { } else {
// UNIX(TM) file support // UNIX(TM) file support
if (*(pCur-1)!='\\') nLines++; if (*(pCur - 1) != '\\') {
nLines++;
}
else { else {
// rewind to backslash and overwrite with a space // rewind to backslash and overwrite with a space
*(pCur-1) = ' '; *(pCur-1) = ' ';
...@@ -154,9 +162,12 @@ void Amap_RemoveComments( char * pBuffer, int * pnDots, int * pnLines ) ...@@ -154,9 +162,12 @@ void Amap_RemoveComments( char * pBuffer, int * pnDots, int * pnLines )
} }
} }
} }
else if ( *pCur == '.' ) }
else if ( *pCur == '.' ) {
nDots++; nDots++;
} }
}
if ( pnDots ) if ( pnDots )
*pnDots = nDots; *pnDots = nDots;
if ( pnLines ) if ( pnLines )
...@@ -491,4 +502,3 @@ Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose ) ...@@ -491,4 +502,3 @@ Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose )
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_END
...@@ -737,34 +737,45 @@ void Io_ReadFileRemoveComments( char * pBuffer, int * pnDots, int * pnLines ) ...@@ -737,34 +737,45 @@ void Io_ReadFileRemoveComments( char * pBuffer, int * pnDots, int * pnLines )
{ {
// if this is the beginning of comment // if this is the beginning of comment
// clean it with spaces until the new line statement // clean it with spaces until the new line statement
if ( *pCur == '#' ) if ( *pCur == '#' ) {
while ( *pCur != '\n' ) while ( *pCur != '\n' ) {
*pCur++ = ' '; *pCur++ = ' ';
}
}
// count the number of new lines and dots // count the number of new lines and dots
if ( *pCur == '\n' ) { if ( *pCur == '\n' ) {
if (*(pCur-1)=='\r') { if (pCur > pBuffer) {
if (*(pCur - 1) == '\r') {
// DOS(R) file support // DOS(R) file support
if (*(pCur-2)!='\\') nLines++; if (pCur > (pBuffer + 1)) {
if (*(pCur - 2) != '\\') {
nLines++;
}
else { else {
// rewind to backslash and overwrite with a space // rewind to backslash and overwrite with a space
*(pCur-2) = ' '; *(pCur - 2) = ' ';
*(pCur-1) = ' '; *(pCur - 1) = ' ';
*pCur = ' '; *pCur = ' ';
} }
}
} else { } else {
// UNIX(TM) file support // UNIX(TM) file support
if (*(pCur-1)!='\\') nLines++; if (*(pCur - 1) != '\\') {
nLines++;
}
else { else {
// rewind to backslash and overwrite with a space // rewind to backslash and overwrite with a space
*(pCur-1) = ' '; *(pCur - 1) = ' ';
*pCur = ' '; *pCur = ' ';
} }
} }
} }
else if ( *pCur == '.' ) }
else if ( *pCur == '.' ) {
nDots++; nDots++;
} }
}
if ( pnDots ) if ( pnDots )
*pnDots = nDots; *pnDots = nDots;
if ( pnLines ) if ( pnLines )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment