pipasic_src/inspect/PySVM/PySVM.c
// Copy one line (up to a \r or \n character) from a source buffer to a target buffer.
// Optionally, strip out spaces.  Return the position just AFTER the end of the line.
// (If a line ends in \r\n, we'll end up processing the line, and then one empty line; that's okay)
// If a line is very long, we stop copying, and skip over the rest of it.
Copy one line (up to a \r or \n character) from a source buffer to a target buffer.
Optionally, strip out spaces.  Return the position just AFTER the end of the line.
(If a line ends in \r\n, we'll end up processing the line, and then one empty line; that's okay)
If a line is very long, we stop copying, and skip over the rest of it.
Copy one line ( up to a \ r or \ n character ) from a source buffer to a target buffer . Optionally strip out spaces . Return the position just AFTER the end of the line . ( If a line ends in \ r \ n we ' ll end up processing the line and then one empty line ; that ' s okay ) If a line is very long we stop copying and skip over the rest of it .
int CopyBufferLine(char* Source, int BufferPos, int BufferEnd, char* LineBuffer, int StripWhitespace)
{
    int LinePos = 0;
    int LineComplete = 0;
    int Chars = 0;
    int Skipping = 0;
    while (!LineComplete)
    {
        if (BufferPos > BufferEnd)
        {
             Our line extends off the edge of the buffer.  That's probably a Bad Thing.
            printf("** Warning: Ran off the edge of the buffer in CopyBufferLine.  Line too ling?\n");
            LineBuffer[LinePos] = '\0';
            return BufferPos;
        }
        switch (Source[BufferPos])
        {
        case ' ':
            if (StripWhitespace)
            {
                BufferPos++;
            }
            else
            {
                if (!Skipping)
                {
                    LineBuffer[LinePos++] = Source[BufferPos];
                }
                BufferPos++;
                Chars++;
            }
            break;
        case '\r':
        case '\n':
            LineBuffer[LinePos] = '\0';
            BufferPos++;
            LineComplete = 1;
            break;
        case '\0':
            LineBuffer[LinePos] = '\0';
            LineComplete = 1;
            break;
        default:
            if (!Skipping)
            {
                LineBuffer[LinePos++] = Source[BufferPos];
            }
            BufferPos++;
            Chars++;
            break;
        }
        if (Chars == MAX_LINE_LENGTH - 1)
        {
            printf("** Error: Line too long!  Truncating line.");
             Read the rest of the chars, but don't write them:
            Chars = 0;
            Skipping = 1;
        }
    }
    return BufferPos;
}
int CopyBufferLine ( char * Source , int BufferPos , int BufferEnd , char * LineBuffer , int StripWhitespace ) { int LinePos = 0 ; int LineComplete = 0 ; int Chars = 0 ; int Skipping = 0 ; while ( ! LineComplete ) { if ( BufferPos > BufferEnd ) { printf ( " \n " ) ; LineBuffer [ LinePos ] = ' \0 ' ; return BufferPos ; } switch ( Source [ BufferPos ] ) { case ' ' : if ( StripWhitespace ) { BufferPos ++ ; } else { if ( ! Skipping ) { LineBuffer [ LinePos ++ ] = Source [ BufferPos ] ; } BufferPos ++ ; Chars ++ ; } break ; case ' \r ' : case ' \n ' : LineBuffer [ LinePos ] = ' \0 ' ; BufferPos ++ ; LineComplete = 1 ; break ; case ' \0 ' : LineBuffer [ LinePos ] = ' \0 ' ; LineComplete = 1 ; break ; default : if ( ! Skipping ) { LineBuffer [ LinePos ++ ] = Source [ BufferPos ] ; } BufferPos ++ ; Chars ++ ; break ; } if ( Chars == MAX_LINE_LENGTH - 1 ) { printf ( " " ) ; Chars = 0 ; Skipping = 1 ; } } return BufferPos ; }
Copy one line (up to a \r or \n character) from a source buffer to a target buffer.
Copy one line ( up to a \ r or \ n character ) from a source buffer to a target buffer .
// // Our line extends off the edge of the buffer.  That's probably a Bad Thing. // Read the rest of the chars, but don't write them: