exeflat failed to advance str so didn't actually skip whitespace at beginning of string, additional comments

This commit is contained in:
Kenneth J Davis 2024-08-18 16:22:15 -04:00
parent 8f056cce6d
commit 2ce6dc00de
No known key found for this signature in database
GPG Key ID: 59D5F216C38F11FD
1 changed files with 11 additions and 2 deletions

View File

@ -424,15 +424,18 @@ int my_isspace( int c )
}
}
/* read command line argument from open FILE referenced by fp */
char *getarg( FILE *fp )
{
static char buff[256];
char *str;
size_t len;
/* loop reading through file until end or new line or max characters */
while( (str = fgets( buff, sizeof(buff) - 1, fp )) != NULL ) {
buff[sizeof(buff) - 1] = '\0';
buff[sizeof(buff) - 1] = '\0'; /* ensure buffer is terminated */
len = strlen(buff);
/* strip whitespace from end of string, i.e. "blah " --> "blah" */
while( len > 0 ) {
len--;
if( my_isspace( buff[len] ) ) {
@ -442,11 +445,17 @@ char *getarg( FILE *fp )
len++;
break;
}
while( len-- > 0 ) {
/* skip past whitespace at beginning of string */
/* str initially points to start of buff */
while( len > 0 ) {
/* stop when str points to end of string or 1st non-space character */
if( !my_isspace(*str) ) {
break;
}
str++;
len--;
}
/* if we got a blank line (*str=='\0') then keep looping, otherwise return what found */
if( *str != '\0' ) {
break;
}