diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2022-03-29 15:31:13 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2022-03-29 15:31:13 -0700 |
commit | a24b15d03a87b897494330f0c11319abb129372d (patch) | |
tree | f5cdb37c260ef30a681c6d6185c3bcb4aa9b5fc5 /src/map/amap/amapRead.c | |
parent | ee228339e5e14b7a3651454814e91b80c3cb4b1e (diff) | |
download | abc-a24b15d03a87b897494330f0c11319abb129372d.tar.gz abc-a24b15d03a87b897494330f0c11319abb129372d.tar.bz2 abc-a24b15d03a87b897494330f0c11319abb129372d.zip |
Suggested changes for the case when the file begings with a new line.
Diffstat (limited to 'src/map/amap/amapRead.c')
-rw-r--r-- | src/map/amap/amapRead.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/src/map/amap/amapRead.c b/src/map/amap/amapRead.c index 3ccfc011..9e6ee21c 100644 --- a/src/map/amap/amapRead.c +++ b/src/map/amap/amapRead.c @@ -126,41 +126,52 @@ void Amap_RemoveComments( char * pBuffer, int * pnDots, int * pnLines ) // (in the BLIF file, comments are lines starting with "#") nDots = nLines = 0; for ( pCur = pBuffer; *pCur; pCur++ ) - { + { // if this is the beginning of comment // clean it with spaces until the new line statement - if ( *pCur == '#' ) - while ( *pCur != '\n' ) - *pCur++ = ' '; - + if ( *pCur == '#' ) { + while ( *pCur != '\n' ) { + *pCur++ = ' '; + } + } // count the number of new lines and dots if ( *pCur == '\n' ) { - if (*(pCur-1)=='\r') { - // DOS(R) file support - if (*(pCur-2)!='\\') nLines++; - else { - // rewind to backslash and overwrite with a space - *(pCur-2) = ' '; - *(pCur-1) = ' '; - *pCur = ' '; - } - } else { - // UNIX(TM) file support - if (*(pCur-1)!='\\') nLines++; - else { - // rewind to backslash and overwrite with a space - *(pCur-1) = ' '; - *pCur = ' '; + if (pCur > pBuffer) { + if (*(pCur - 1) == '\r') { + // DOS(R) file support + if (pCur > (pBuffer + 1)) { + if (*(pCur - 2)!='\\') { + nLines++; + } + else { + // rewind to backslash and overwrite with a space + *(pCur - 2) = ' '; + *(pCur - 1) = ' '; + *pCur = ' '; + } + } + } else { + // UNIX(TM) file support + if (*(pCur - 1) != '\\') { + nLines++; + } + else { + // rewind to backslash and overwrite with a space + *(pCur-1) = ' '; + *pCur = ' '; + } + } + } } + else if ( *pCur == '.' ) { + nDots++; } - } - else if ( *pCur == '.' ) - nDots++; - } + } + if ( pnDots ) - *pnDots = nDots; + *pnDots = nDots; if ( pnLines ) - *pnLines = nLines; + *pnLines = nLines; } /**Function************************************************************* @@ -491,4 +502,3 @@ Amap_Lib_t * Amap_LibReadFile( char * pFileName, int fVerbose ) ABC_NAMESPACE_IMPL_END - |