wmail: white-space fixes.

This commit is contained in:
Jeremy Sowden 2019-06-07 09:52:10 +01:00 committed by Carlos R. Mafra
parent b78df8ed42
commit 71c126d20e
2 changed files with 50 additions and 43 deletions

View file

@ -393,20 +393,22 @@ static bool ReadString( const char *from, unsigned int line, char **to )
case 'r': *to_c = '\r'; break; case 'r': *to_c = '\r'; break;
case 't': *to_c = '\t'; break; case 't': *to_c = '\t'; break;
case '"': *to_c = '"'; break; case '"': *to_c = '"'; break;
default: { default:
int value, i; {
for( i = 0, value = 0; i < 3; ++i ) { int value, i;
if( c+i == NULL || *(c+i) < '0' || *(c+i) > '9' ) for( i = 0, value = 0; i < 3; ++i ) {
if( c+i == NULL || *(c+i) < '0' || *(c+i) > '9' )
break; break;
value = value * 10 + *(c+i) - '0'; value = value * 10 + *(c+i) - '0';
}
if( value == 0 )
WARNING( "cfg-file(%i): '\\0' in string or unknown escape sequence found\n",
line );
else {
*to_c = (char)value;
c += i-1;
}
} }
if( value == 0 )
WARNING( "cfg-file(%i): '\\0' in string or unknown escape sequence found\n", line );
else {
*to_c = (char)value;
c += i-1;
}
}
} }
} else } else
*to_c = *c; *to_c = *c;
@ -464,18 +466,21 @@ static bool ReadInt( const char *from, unsigned int line, int *to )
return false; return false;
} }
} }
} else for( ; *from != '\0' && !IsWhiteSpace( from ); ++from ) { } else
if( value > (INT_MAX - 9) / 10 ) { for( ; *from != '\0' && !IsWhiteSpace( from ); ++from ) {
WARNING( "cfg-file(%i): decimal-number too large: \">%i\"\n", line, INT_MAX ); if( value > (INT_MAX - 9) / 10 ) {
return false; WARNING( "cfg-file(%i): decimal-number too large: \">%i\"\n",
line, INT_MAX );
return false;
}
if( *from >= '0' && *from <= '9' )
value = value * 10 + *from - '0';
else {
WARNING( "cfg-file(%i): invalid decimal-digit: \"%c\"\n",
line, *from );
return false;
}
} }
if( *from >= '0' && *from <= '9' )
value = value * 10 + *from - '0';
else {
WARNING( "cfg-file(%i): invalid decimal-digit: \"%c\"\n", line, *from );
return false;
}
}
*to = value; *to = value;

View file

@ -86,7 +86,7 @@ typedef struct _name_t {
char *name; char *name;
unsigned long checksum; unsigned long checksum;
flag_t flag; flag_t flag;
bool visited; bool visited;
struct _name_t *next; struct _name_t *next;
} name_t; } name_t;
@ -230,7 +230,7 @@ int main( int argc, char **argv )
config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE ); config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE );
} }
if ( config.checksumFileName == NULL) if( config.checksumFileName == NULL )
{ {
WARNING( "Cannot allocate checksum file-name.\n"); WARNING( "Cannot allocate checksum file-name.\n");
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
@ -493,13 +493,15 @@ static void DetermineState( void )
static void ReadChecksumFile( void ) static void ReadChecksumFile( void )
{ {
FILE *f = fopen( config.checksumFileName, "rb" ); FILE *f = fopen( config.checksumFileName, "rb" );
if( f != NULL ) while( !feof( f )) { if( f != NULL )
unsigned long checksum; while( !feof( f )) {
if( fread( &checksum, sizeof(long), 1, f ) != 1 ) unsigned long checksum;
continue; if( fread( &checksum, sizeof(long), 1, f ) != 1 )
continue;
MarkName( checksum ); MarkName( checksum );
} else }
else
return; return;
fclose( f ); fclose( f );
@ -549,7 +551,7 @@ static void ExitHandler( int sig )
static void TimedOut( void ) static void TimedOut( void )
{ {
if (caughtSig) { if( caughtSig ) {
ClearAllNames(); ClearAllNames();
ResetConfigStrings(); ResetConfigStrings();
exit( EXIT_SUCCESS ); exit( EXIT_SUCCESS );
@ -567,7 +569,7 @@ static void CheckTimeOut( bool force )
unsigned long nowMs = now.tv_sec * 1000L + now.tv_usec / 1000L; unsigned long nowMs = now.tv_sec * 1000L + now.tv_usec / 1000L;
if (!force && nowMs - lastTimeOut < 1000L / config.fps) if( !force && nowMs - lastTimeOut < 1000L / config.fps )
return; return;
lastTimeOut = nowMs; lastTimeOut = nowMs;
@ -660,7 +662,7 @@ static void CheckMaildir( void )
char *fullName = MakePathName( config.mailBox, dirEnt->d_name ); char *fullName = MakePathName( config.mailBox, dirEnt->d_name );
struct stat fileStat; struct stat fileStat;
if ( fullName == NULL ) if( fullName == NULL )
{ {
WARNING( "Cannot allocate file/path\n" ); WARNING( "Cannot allocate file/path\n" );
break; break;
@ -708,7 +710,7 @@ static int TraverseDirectory( const char *name, bool isNewMail )
unsigned long checksum = 0; unsigned long checksum = 0;
name_t *name; name_t *name;
if ( fullName == NULL ) if( fullName == NULL )
{ {
WARNING( "Cannot allocate file/path\n" ); WARNING( "Cannot allocate file/path\n" );
break; break;
@ -972,7 +974,7 @@ static char *ParseFromField( char *buf )
continue; continue;
} // else do the default action } // else do the default action
default: default:
if( fullName[0] != '\0' || !isspace ( *c )) if( fullName[0] != '\0' || !isspace( *c ))
fullName[ fullNameLen++ ] = *c; fullName[ fullNameLen++ ] = *c;
} }
continue; continue;
@ -1050,12 +1052,12 @@ static char *ParseFromField( char *buf )
} }
} }
if (*comment) { if( *comment ) {
//WARNING("Comment seen: %s\nIn: %s\nFullname: %s\nAddress: %s\n", comment, buf, fullName, addressName); //WARNING("Comment seen: %s\nIn: %s\nFullname: %s\nAddress: %s\n", comment, buf, fullName, addressName);
// Comment seen: if there's an address, append to // Comment seen: if there's an address, append to
// fullname. If no address, copy fullname to address // fullname. If no address, copy fullname to address
// and comment to fullname. // and comment to fullname.
if (*addressName) { if( *addressName ) {
strcat(fullName, "("); strcat(fullName, "(");
strcat(fullName, comment); strcat(fullName, comment);
strcat(fullName, ")"); strcat(fullName, ")");
@ -1116,7 +1118,7 @@ static void InsertName( char *name, unsigned long checksum, flag_t flag )
name_t *item; name_t *item;
TRACE( "insertName: %X, \"%s\"\n", checksum, name ); TRACE( "insertName: %X, \"%s\"\n", checksum, name );
if (( item = malloc( sizeof( name_t ))) == NULL ) if(( item = malloc( sizeof( name_t ))) == NULL )
{ {
free( name ); free( name );
return; return;
@ -1193,7 +1195,7 @@ static void DrawTickerX11Font( void )
--insertAt; --insertAt;
if( insertAt < -XTextWidth( tickerFS, curTickerName->name, if( insertAt < -XTextWidth( tickerFS, curTickerName->name,
strlen( curTickerName->name )) + 6 ) strlen( curTickerName->name )) + 6 )
{ {
do { do {
curTickerName = curTickerName->next; curTickerName = curTickerName->next;
@ -1218,7 +1220,7 @@ static void DrawTickerBuildinFont( void )
unsigned char *currentChar; unsigned char *currentChar;
if( names == NULL ) if( names == NULL )
return; return;
if( curTickerName == NULL || namesChanged ) { if( curTickerName == NULL || namesChanged ) {
@ -1287,7 +1289,7 @@ static void ButtonPressed( int button, int state, int x, int y )
static void ButtonReleased( int button, int state, int x, int y ) static void ButtonReleased( int button, int state, int x, int y )
{ {
buttonPressed = false; buttonPressed = false;
forceRedraw = true; forceRedraw = true;
if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) { if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) {
int ret = system( config.runCmd ); int ret = system( config.runCmd );
@ -1359,7 +1361,7 @@ static void UpdateConfiguration( void )
PreparePixmaps( true ); PreparePixmaps( true );
DASetTimeout (1000 / config.fps); DASetTimeout( 1000 / config.fps );
} }
static void CleanupNames( void ) static void CleanupNames( void )