From adf1164fba7fe8ba7236c81a26c348a299620484 Mon Sep 17 00:00:00 2001 From: Jeremy Sowden Date: Mon, 27 May 2019 22:52:05 +0100 Subject: [PATCH] wmail: consistent 4-column indentation with 8-character tabs. --- wmail/src/config.c | 318 +++++------ wmail/src/config.h | 44 +- wmail/src/wmail.c | 1366 ++++++++++++++++++++++---------------------- 3 files changed, 864 insertions(+), 864 deletions(-) diff --git a/wmail/src/config.c b/wmail/src/config.c index 80df0f2..02b9ae1 100644 --- a/wmail/src/config.c +++ b/wmail/src/config.c @@ -101,9 +101,9 @@ config_t config = { NULL, NULL, false, - NULL, + NULL, 0, - 0 + 0 }; // enumeration names for ticker mode @@ -121,23 +121,23 @@ bool Tokenize( const char *line, const char **id, const char **value ) const char *token1, *token2; if( line != NULL ) + { + token1 = SkipWhiteSpaces( line ); + + if(( len = strlen( token1 )) != 0 && token1[0] != '#' ) { - token1 = SkipWhiteSpaces( line ); + token2 = strchr( token1, '=' ); + if( token2 != NULL ) + token2 = SkipWhiteSpaces( token2+1 ); - if(( len = strlen( token1 )) != 0 && token1[0] != '#' ) - { - token2 = strchr( token1, '=' ); - if( token2 != NULL ) - token2 = SkipWhiteSpaces( token2+1 ); + if( !IsWhiteSpace( token2 )) + { + *id = token1; + *value = token2; - if( !IsWhiteSpace( token2 )) - { - *id = token1; - *value = token2; - - return true; - } - } + return true; + } + } } return false; @@ -149,19 +149,19 @@ void AddSenderToSkipList( char *sender ) char **skipName, **newList; for( skipName = config.skipNames, numNames = 0; - skipName != NULL && *skipName != NULL; skipName++ ) + skipName != NULL && *skipName != NULL; skipName++ ) { - if( !strcmp( *skipName, sender )) - return; + if( !strcmp( *skipName, sender )) + return; - numNames++; + numNames++; } TRACE( "adding \"%s\" to skip-list of currently %d names\n", sender, numNames ); newList = malloc( sizeof(char *) * (numNames + 2) ); for( i = 0; i < numNames; ++i ) - newList[i] = config.skipNames[i]; + newList[i] = config.skipNames[i]; newList[i] = strdup( sender ); newList[i+1] = NULL; @@ -171,177 +171,177 @@ void AddSenderToSkipList( char *sender ) void ResetConfigStrings() { - if( !( config.givenOptions & CL_MAILBOX )) { - free( config.mailBox ); - config.mailBox = NULL; - } + if( !( config.givenOptions & CL_MAILBOX )) { + free( config.mailBox ); + config.mailBox = NULL; + } - if( !( config.givenOptions & CL_RUNCMD )) { - free( config.runCmd ); - config.runCmd = NULL; - } + if( !( config.givenOptions & CL_RUNCMD )) { + free( config.runCmd ); + config.runCmd = NULL; + } - if( !( config.givenOptions & CL_SYMBOLCOLOR )) { - free( config.symbolColor ); - config.symbolColor = NULL; - } + if( !( config.givenOptions & CL_SYMBOLCOLOR )) { + free( config.symbolColor ); + config.symbolColor = NULL; + } - if( !( config.givenOptions & CL_FONTCOLOR )) { - free( config.fontColor ); - config.fontColor = NULL; - } + if( !( config.givenOptions & CL_FONTCOLOR )) { + free( config.fontColor ); + config.fontColor = NULL; + } - if( !( config.givenOptions & CL_BACKCOLOR )) { - free( config.backColor ); - config.backColor = NULL; - } + if( !( config.givenOptions & CL_BACKCOLOR )) { + free( config.backColor ); + config.backColor = NULL; + } - if( !( config.givenOptions & CL_OFFLIGHTCOLOR )) { - free( config.offlightColor ); - config.offlightColor = NULL; - } + if( !( config.givenOptions & CL_OFFLIGHTCOLOR )) { + free( config.offlightColor ); + config.offlightColor = NULL; + } - if( !( config.givenOptions & CL_BACKGROUNDCOLOR )) { - free( config.backgroundColor ); - config.backgroundColor = NULL; - } + if( !( config.givenOptions & CL_BACKGROUNDCOLOR )) { + free( config.backgroundColor ); + config.backgroundColor = NULL; + } - if( !( config.givenOptions & CL_CHECKSUMFILENAME )) { - free( config.checksumFileName ); - config.checksumFileName = NULL; - } + if( !( config.givenOptions & CL_CHECKSUMFILENAME )) { + free( config.checksumFileName ); + config.checksumFileName = NULL; + } - if( !( config.givenOptions & CL_CMDONMAIL )) { - free( config.cmdOnMail ); - config.cmdOnMail = NULL; - } + if( !( config.givenOptions & CL_CMDONMAIL )) { + free( config.cmdOnMail ); + config.cmdOnMail = NULL; + } - if( !( config.givenOptions & CL_USEX11FONT )) { - free( config.useX11Font ); - config.useX11Font = NULL; - } + if( !( config.givenOptions & CL_USEX11FONT )) { + free( config.useX11Font ); + config.useX11Font = NULL; + } } void PostProcessConfiguration() { if( config.display == NULL ) - config.display = strdup( WMAIL_DISPLAY ); + config.display = strdup( WMAIL_DISPLAY ); - if( config.runCmd == NULL ) - config.runCmd = strdup( WMAIL_CLIENT_CMD ); + if( config.runCmd == NULL ) + config.runCmd = strdup( WMAIL_CLIENT_CMD ); - if( config.mailBox == NULL ) - { - char *envMBox = getenv( "MAIL" ); - if( envMBox != NULL ) - config.mailBox = strdup( envMBox ); - } + if( config.mailBox == NULL ) + { + char *envMBox = getenv( "MAIL" ); + if( envMBox != NULL ) + config.mailBox = strdup( envMBox ); + } } void ReadConfigFile( bool resetConfigStrings ) { char *usersHome; - // free all config strings and reset their pointers if required - if( resetConfigStrings ) - ResetConfigStrings(); + // free all config strings and reset their pointers if required + if( resetConfigStrings ) + ResetConfigStrings(); if(( usersHome = getenv( "HOME" )) != NULL ) + { + char *fileName = MakePathName( usersHome, WMAIL_RC_FILE ); + FILE *f = fopen( fileName, "rt" ); + + if( f != NULL ) { - char *fileName = MakePathName( usersHome, WMAIL_RC_FILE ); - FILE *f = fopen( fileName, "rt" ); + char buf[1024]; + int line = 1; - if( f != NULL ) - { - char buf[1024]; - int line = 1; + for( ; !feof( f ); ++line ) + { + const char *id, *value; + unsigned int len; - for( ; !feof( f ); ++line ) - { - const char *id, *value; - unsigned int len; + if( fgets( buf, 1024, f ) == NULL ) + break; - if( fgets( buf, 1024, f ) == NULL ) - break; + // first eliminate the trailing whitespaces + for( len = strlen( buf ); + len > 0 && IsWhiteSpace(buf+(--len)); ) + *(buf+len) = '\0'; - // first eliminate the trailing whitespaces - for( len = strlen( buf ); - len > 0 && IsWhiteSpace(buf+(--len)); ) - *(buf+len) = '\0'; + if( !Tokenize( buf, &id, &value )) + continue; - if( !Tokenize( buf, &id, &value )) - continue; + if( !strncasecmp( id, "Window.Display", 14 )) { + if( !( config.givenOptions & CL_DISPLAY )) + ReadString( value, line, &config.display ); + } else if( !strncasecmp( id, "Window.NonShaped", 16 )) { + if( !( config.givenOptions & CL_NOSHAPE )) + ReadBool( value, line, &config.noshape ); + } else if( !strncasecmp( id, "Window.Button.Command", 21 )) { + if( !( config.givenOptions & CL_RUNCMD )) + ReadString( value, line, &config.runCmd ); + } else if( !strncasecmp( id, "Mail.MailBox", 12 )) { + if( !( config.givenOptions & CL_MAILBOX )) + ReadString( value, line, &config.mailBox ); + } else if( !strncasecmp( id, "Mail.ChecksumFile", 17 )) // no corresponding cmdline option + ReadString( value, line, &config.checksumFileName ); + else if( !strncasecmp( id, "Mail.CheckIntervall", 19 )) { + if( !( config.givenOptions & CL_CHECKINTERVAL )) + ReadInt( value, line, &config.checkInterval ); + } else if( !strncasecmp( id, "Mail.ShowOnlyNew", 16 )) { + if( !( config.givenOptions & CL_NEWMAILONLY )) + ReadBool( value, line, &config.newMailsOnly ); + } else if( !strncasecmp( id, "Ticker.Mode", 11 )) { + if( !( config.givenOptions & CL_TICKERMODE )) + ReadEnum( value, line, (int *)&config.tickerMode, tickerEnum ); + } else if( !strncasecmp( id, "Ticker.Frames", 13 )) { + if( !( config.givenOptions & CL_FPS )) + ReadInt( value, line, &config.fps ); + } else if( !strncasecmp( id, "Colors.Symbols", 14 )) { + if( !( config.givenOptions & CL_SYMBOLCOLOR )) + ReadString( value, line, &config.symbolColor ); + } else if( !strncasecmp( id, "Colors.Font", 11 )) { + if( !( config.givenOptions & CL_FONTCOLOR )) + ReadString( value, line, &config.fontColor ); + } else if( !strncasecmp( id, "Colors.Backlight", 16 )) { + if( !( config.givenOptions & CL_BACKCOLOR )) + ReadString( value, line, &config.backColor ); + } else if( !strncasecmp( id, "Colors.OffLight", 15 )) { + if( !( config.givenOptions & CL_OFFLIGHTCOLOR )) + ReadString( value, line, &config.offlightColor ); + } else if( !strncasecmp( id, "Colors.NonShapedFrame", 21 )) { + if( !( config.givenOptions & CL_NOSHAPE )) + ReadString( value, line, &config.backgroundColor ); + } else if( !strncasecmp( id, "Ticker.X11Font", 14 )) { + if( !( config.givenOptions & CL_USEX11FONT )) + ReadString( value, line, &config.useX11Font ); + } else if( !strncasecmp( id, "Mail.SkipSender", 15 )) { // no corresponding cmdline options + char *skip; + if( ReadString( value, line, &skip )) + AddSenderToSkipList( skip ); + } else if( !strncasecmp( id, "Mail.OnNew.Command", 18 )) { + if( !( config.givenOptions & CL_CMDONMAIL )) + ReadString( value, line, &config.cmdOnMail ); + } else if( !strncasecmp( id, "Mail.UseStatusField", 19 )) { + if( !( config.givenOptions & CL_CONSIDERSTATUSFIELD )) + ReadBool( value, line, &config.considerStatusField ); + } else if( !strncasecmp( id, "Mail.ReadStatus", 15 )) { + if( !( config.givenOptions & CL_READSTATUS )) + ReadString( value, line, &config.readStatus ); + } else + WARNING( "cfg-file(%i): unrecognized: \"%s\"\n", line, buf ); + } - if( !strncasecmp( id, "Window.Display", 14 )) { - if( !( config.givenOptions & CL_DISPLAY )) - ReadString( value, line, &config.display ); - } else if( !strncasecmp( id, "Window.NonShaped", 16 )) { - if( !( config.givenOptions & CL_NOSHAPE )) - ReadBool( value, line, &config.noshape ); - } else if( !strncasecmp( id, "Window.Button.Command", 21 )) { - if( !( config.givenOptions & CL_RUNCMD )) - ReadString( value, line, &config.runCmd ); - } else if( !strncasecmp( id, "Mail.MailBox", 12 )) { - if( !( config.givenOptions & CL_MAILBOX )) - ReadString( value, line, &config.mailBox ); - } else if( !strncasecmp( id, "Mail.ChecksumFile", 17 )) // no corresponding cmdline option - ReadString( value, line, &config.checksumFileName ); - else if( !strncasecmp( id, "Mail.CheckIntervall", 19 )) { - if( !( config.givenOptions & CL_CHECKINTERVAL )) - ReadInt( value, line, &config.checkInterval ); - } else if( !strncasecmp( id, "Mail.ShowOnlyNew", 16 )) { - if( !( config.givenOptions & CL_NEWMAILONLY )) - ReadBool( value, line, &config.newMailsOnly ); - } else if( !strncasecmp( id, "Ticker.Mode", 11 )) { - if( !( config.givenOptions & CL_TICKERMODE )) - ReadEnum( value, line, (int *)&config.tickerMode, tickerEnum ); - } else if( !strncasecmp( id, "Ticker.Frames", 13 )) { - if( !( config.givenOptions & CL_FPS )) - ReadInt( value, line, &config.fps ); - } else if( !strncasecmp( id, "Colors.Symbols", 14 )) { - if( !( config.givenOptions & CL_SYMBOLCOLOR )) - ReadString( value, line, &config.symbolColor ); - } else if( !strncasecmp( id, "Colors.Font", 11 )) { - if( !( config.givenOptions & CL_FONTCOLOR )) - ReadString( value, line, &config.fontColor ); - } else if( !strncasecmp( id, "Colors.Backlight", 16 )) { - if( !( config.givenOptions & CL_BACKCOLOR )) - ReadString( value, line, &config.backColor ); - } else if( !strncasecmp( id, "Colors.OffLight", 15 )) { - if( !( config.givenOptions & CL_OFFLIGHTCOLOR )) - ReadString( value, line, &config.offlightColor ); - } else if( !strncasecmp( id, "Colors.NonShapedFrame", 21 )) { - if( !( config.givenOptions & CL_NOSHAPE )) - ReadString( value, line, &config.backgroundColor ); - } else if( !strncasecmp( id, "Ticker.X11Font", 14 )) { - if( !( config.givenOptions & CL_USEX11FONT )) - ReadString( value, line, &config.useX11Font ); - } else if( !strncasecmp( id, "Mail.SkipSender", 15 )) { // no corresponding cmdline options - char *skip; - if( ReadString( value, line, &skip )) - AddSenderToSkipList( skip ); - } else if( !strncasecmp( id, "Mail.OnNew.Command", 18 )) { - if( !( config.givenOptions & CL_CMDONMAIL )) - ReadString( value, line, &config.cmdOnMail ); - } else if( !strncasecmp( id, "Mail.UseStatusField", 19 )) { - if( !( config.givenOptions & CL_CONSIDERSTATUSFIELD )) - ReadBool( value, line, &config.considerStatusField ); - } else if( !strncasecmp( id, "Mail.ReadStatus", 15 )) { - if( !( config.givenOptions & CL_READSTATUS )) - ReadString( value, line, &config.readStatus ); - } else - WARNING( "cfg-file(%i): unrecognized: \"%s\"\n", line, buf ); - } - - fclose( f ); - } else { - TRACE( "unable to open config-file \"%s\"\n", fileName ); - } + fclose( f ); + } else { + TRACE( "unable to open config-file \"%s\"\n", fileName ); + } } else { - TRACE( "no $HOME defined - config-file not read\n" ); + TRACE( "no $HOME defined - config-file not read\n" ); } - PostProcessConfiguration(); + PostProcessConfiguration(); } bool ReadString( const char *from, unsigned int line, char **to ) @@ -449,7 +449,7 @@ bool ReadInt( const char *from, unsigned int line, int *to ) } } } else for( ; *from != '\0' && !IsWhiteSpace( from ); ++from ) { - if( value > (INT_MAX - 9) / 10 ) { + if( value > (INT_MAX - 9) / 10 ) { WARNING( "cfg-file(%i): decimal-number too large: \">%i\"\n", line, INT_MAX ); return false; } diff --git a/wmail/src/config.h b/wmail/src/config.h index d69a6f1..ec3928b 100644 --- a/wmail/src/config.h +++ b/wmail/src/config.h @@ -48,25 +48,25 @@ enum { // flags to mark used cmdline options enum { - CL_DISPLAY = 1<<0, - CL_MAILBOX = 1<<1, - CL_RUNCMD = 1<<2, - CL_SYMBOLCOLOR = 1<<3, - CL_FONTCOLOR = 1<<4, - CL_BACKCOLOR = 1<<5, - CL_OFFLIGHTCOLOR = 1<<6, - CL_BACKGROUNDCOLOR = 1<<7, - CL_CHECKSUMFILENAME = 1<<8, - CL_CHECKINTERVAL = 1<<9, - CL_FPS = 1<<10, - CL_NEWMAILONLY = 1<<11, - CL_NOSHAPE = 1<<12, - CL_TICKERMODE = 1<<13, - CL_SKIPNAMES = 1<<14, - CL_CMDONMAIL = 1<<15, - CL_CONSIDERSTATUSFIELD = 1<<16, - CL_READSTATUS = 1<<17, - CL_USEX11FONT = 1<<18 + CL_DISPLAY = 1<<0, + CL_MAILBOX = 1<<1, + CL_RUNCMD = 1<<2, + CL_SYMBOLCOLOR = 1<<3, + CL_FONTCOLOR = 1<<4, + CL_BACKCOLOR = 1<<5, + CL_OFFLIGHTCOLOR = 1<<6, + CL_BACKGROUNDCOLOR = 1<<7, + CL_CHECKSUMFILENAME = 1<<8, + CL_CHECKINTERVAL = 1<<9, + CL_FPS = 1<<10, + CL_NEWMAILONLY = 1<<11, + CL_NOSHAPE = 1<<12, + CL_TICKERMODE = 1<<13, + CL_SKIPNAMES = 1<<14, + CL_CMDONMAIL = 1<<15, + CL_CONSIDERSTATUSFIELD = 1<<16, + CL_READSTATUS = 1<<17, + CL_USEX11FONT = 1<<18 }; typedef struct _config_t { @@ -87,11 +87,11 @@ typedef struct _config_t { char **skipNames; // sender-names that wmail has to skip char *cmdOnMail; // command to execute when a new mail has received bool considerStatusField; // use the status-field of the mail-header to determine its read-status - char *readStatus; // status field content that indicates read mails ("O" for netscape, "ro" for pine etc.) - char *useX11Font; // X11 font to render the ticker (NULL -> fallback to buildin font) + char *readStatus; // status field content that indicates read mails ("O" for netscape, "ro" for pine etc.) + char *useX11Font; // X11 font to render the ticker (NULL -> fallback to buildin font) // ---------------------- // int colorsUsed; // used (malloced) color-names - int givenOptions; // bitfield flags all options specified on the cmd-line + int givenOptions; // bitfield flags all options specified on the cmd-line } config_t; diff --git a/wmail/src/wmail.c b/wmail/src/wmail.c index 28d3d41..5bbebb9 100644 --- a/wmail/src/wmail.c +++ b/wmail/src/wmail.c @@ -93,7 +93,7 @@ typedef enum { STATE_FULLNAME, STATE_QUOTED_FULLNAME, STATE_ENCODED_FULLNAME, - STATE_COMMENT + STATE_COMMENT } parse_state_t; @@ -168,7 +168,7 @@ name_t *GetMail( unsigned long checksum ); void UpdatePixmap( bool flashMailSymbol ); void ParseMBoxFile( struct stat *fileStat ); void ParseMaildirFile( const char *fileName, unsigned long checksum, - struct stat *fileStat, bool isNewMail ); + struct stat *fileStat, bool isNewMail ); char *ParseFromField( char *buf ); bool SkipSender( char *address ); void InsertName( char *name, unsigned long checksum, flag_t flag ); @@ -213,88 +213,88 @@ int main( int argc, char **argv ) char *usersHome; struct sigaction sa; int ret; - struct stat fileStat; - XTextProperty windowName; - char *name = argv[0]; + struct stat fileStat; + XTextProperty windowName; + char *name = argv[0]; DACallbacks callbacks = { NULL, &ButtonPressed, &ButtonReleased, - NULL, NULL, NULL, NULL }; + NULL, NULL, NULL, NULL }; // read the config file and overide the default-settings ReadConfigFile( false ); if( config.checksumFileName == NULL ) { - if(( usersHome = getenv( "HOME" )) == NULL ) { - WARNING( "HOME environment-variable is not set, placing %s in current directory!\n", WMAIL_CHECKSUM_FILE ); - config.checksumFileName = WMAIL_CHECKSUM_FILE; - } else - config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE ); + if(( usersHome = getenv( "HOME" )) == NULL ) { + WARNING( "HOME environment-variable is not set, placing %s in current directory!\n", WMAIL_CHECKSUM_FILE ); + config.checksumFileName = WMAIL_CHECKSUM_FILE; + } else + config.checksumFileName = MakePathName( usersHome, WMAIL_CHECKSUM_FILE ); } TRACE( "using checksum-file \"%s\"\n", config.checksumFileName ); // parse cmdline-args and overide defaults and cfg-file settings DAParseArguments( argc, argv, options, - sizeof(options) / sizeof(DAProgramOption), - WMAIL_NAME, WMAIL_VERSION ); + sizeof(options) / sizeof(DAProgramOption), + WMAIL_NAME, WMAIL_VERSION ); - if( options[0].used ) - config.givenOptions |= CL_DISPLAY; - if( options[1].used ) - config.givenOptions |= CL_RUNCMD; - if( options[2].used ) - config.givenOptions |= CL_CHECKINTERVAL; - if( options[3].used ) { - config.givenOptions |= CL_TICKERMODE; - config.tickerMode = TICKER_FAMILYNAME; - } - if( options[4].used ) - config.givenOptions |= CL_FPS; - if( options[5].used ) { - config.givenOptions |= CL_TICKERMODE; - config.tickerMode = TICKER_NICKNAME; - } - if( options[6].used ) - config.givenOptions |= CL_SYMBOLCOLOR; - if( options[7].used ) - config.givenOptions |= CL_FONTCOLOR; - if( options[8].used ) - config.givenOptions |= CL_BACKCOLOR; - if( options[9].used ) - config.givenOptions |= CL_OFFLIGHTCOLOR; - if( options[10].used ) - config.givenOptions |= CL_BACKGROUNDCOLOR; - if( options[11].used ) { - config.givenOptions |= CL_NOSHAPE; - config.noshape = true; - } - if( options[12].used ) { - config.givenOptions |= CL_NEWMAILONLY; - config.newMailsOnly = true; - } - if( options[13].used ) - config.givenOptions |= CL_MAILBOX; - if( options[14].used ) - config.givenOptions |= CL_CMDONMAIL; + if( options[0].used ) + config.givenOptions |= CL_DISPLAY; + if( options[1].used ) + config.givenOptions |= CL_RUNCMD; + if( options[2].used ) + config.givenOptions |= CL_CHECKINTERVAL; + if( options[3].used ) { + config.givenOptions |= CL_TICKERMODE; + config.tickerMode = TICKER_FAMILYNAME; + } + if( options[4].used ) + config.givenOptions |= CL_FPS; + if( options[5].used ) { + config.givenOptions |= CL_TICKERMODE; + config.tickerMode = TICKER_NICKNAME; + } + if( options[6].used ) + config.givenOptions |= CL_SYMBOLCOLOR; + if( options[7].used ) + config.givenOptions |= CL_FONTCOLOR; + if( options[8].used ) + config.givenOptions |= CL_BACKCOLOR; + if( options[9].used ) + config.givenOptions |= CL_OFFLIGHTCOLOR; + if( options[10].used ) + config.givenOptions |= CL_BACKGROUNDCOLOR; + if( options[11].used ) { + config.givenOptions |= CL_NOSHAPE; + config.noshape = true; + } + if( options[12].used ) { + config.givenOptions |= CL_NEWMAILONLY; + config.newMailsOnly = true; + } + if( options[13].used ) + config.givenOptions |= CL_MAILBOX; + if( options[14].used ) + config.givenOptions |= CL_CMDONMAIL; if( options[15].used ) { - config.givenOptions |= CL_CONSIDERSTATUSFIELD; - config.considerStatusField = true; - } - if( options[16].used ) - config.givenOptions |= CL_READSTATUS; - if( options[17].used ) - config.givenOptions |= CL_USEX11FONT; + config.givenOptions |= CL_CONSIDERSTATUSFIELD; + config.considerStatusField = true; + } + if( options[16].used ) + config.givenOptions |= CL_READSTATUS; + if( options[17].used ) + config.givenOptions |= CL_USEX11FONT; if( config.mailBox == NULL ) - ABORT( "no mailbox specified - please define at least your $MAIL environment-variable!\n" ); - else if( stat( config.mailBox, &fileStat ) == 0 ) - isMaildir = S_ISDIR( fileStat.st_mode ) != 0; + ABORT( "no mailbox specified - please define at least your $MAIL environment-variable!\n" ); + else if( stat( config.mailBox, &fileStat ) == 0 ) + isMaildir = S_ISDIR( fileStat.st_mode ) != 0; - TRACE( "mailbox is of type %s\n", isMaildir ? "maildir" : "mbox" ); + TRACE( "mailbox is of type %s\n", isMaildir ? "maildir" : "mbox" ); // dockapp size hard wired - sorry... DAInitialize( config.display, "wmail", 64, 64, argc, argv ); - outPixmap = DAMakePixmap(); + outPixmap = DAMakePixmap(); PreparePixmaps( false ); DASetCallbacks( &callbacks ); @@ -306,12 +306,12 @@ int main( int argc, char **argv ) ret = sigaction( SIGALRM, &sa, 0 ); if( ret ) { - perror( "wmail error: sigaction" ); - exit( 1 ); + perror( "wmail error: sigaction" ); + exit( 1 ); } - XStringListToTextProperty( &name, 1, &windowName ); - XSetWMName( DADisplay, DAWindow, &windowName ); + XStringListToTextProperty( &name, 1, &windowName ); + XSetWMName( DADisplay, DAWindow, &windowName ); UpdatePixmap( false ); DAShow(); @@ -328,92 +328,92 @@ void PreparePixmaps( bool freeMem ) // this works as long as you don't "touch" the images... unsigned dummy; - XGCValues values; + XGCValues values; if( config.symbolColor != NULL ) { // symbol color ? - symbols_xpm[2] = XpmColorLine( config.symbolColor, symbols_xpm[2], - freeMem && ( config.colorsUsed & SYM_COLOR )); - config.colorsUsed |= SYM_COLOR; + symbols_xpm[2] = XpmColorLine( config.symbolColor, symbols_xpm[2], + freeMem && ( config.colorsUsed & SYM_COLOR )); + config.colorsUsed |= SYM_COLOR; } else { - symbols_xpm[2] = XpmColorLine( "#20B2AA", symbols_xpm[2], - freeMem && ( config.colorsUsed & SYM_COLOR )); - config.colorsUsed |= SYM_COLOR; - } + symbols_xpm[2] = XpmColorLine( "#20B2AA", symbols_xpm[2], + freeMem && ( config.colorsUsed & SYM_COLOR )); + config.colorsUsed |= SYM_COLOR; + } if( config.fontColor != NULL ) { // font color ? - chars_xpm[3] = XpmColorLine( config.fontColor, chars_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); - numbers_xpm[3] = XpmColorLine( config.fontColor, numbers_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); - config.colorsUsed |= FNT_COLOR; + chars_xpm[3] = XpmColorLine( config.fontColor, chars_xpm[3], + freeMem && ( config.colorsUsed & FNT_COLOR )); + numbers_xpm[3] = XpmColorLine( config.fontColor, numbers_xpm[3], + freeMem && ( config.colorsUsed & FNT_COLOR )); + config.colorsUsed |= FNT_COLOR; } else { - chars_xpm[3] = XpmColorLine( "#D3D3D3", chars_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); - numbers_xpm[3] = XpmColorLine( "#D3D3D3", numbers_xpm[3], - freeMem && ( config.colorsUsed & FNT_COLOR )); - config.colorsUsed |= FNT_COLOR; - } + chars_xpm[3] = XpmColorLine( "#D3D3D3", chars_xpm[3], + freeMem && ( config.colorsUsed & FNT_COLOR )); + numbers_xpm[3] = XpmColorLine( "#D3D3D3", numbers_xpm[3], + freeMem && ( config.colorsUsed & FNT_COLOR )); + config.colorsUsed |= FNT_COLOR; + } if( config.backColor != NULL ) { // backlight color ? - main_xpm[3] = XpmColorLine( config.backColor, main_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - symbols_xpm[3] = XpmColorLine( config.backColor, symbols_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - chars_xpm[2] = XpmColorLine( config.backColor, chars_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); - numbers_xpm[2] = XpmColorLine( config.backColor, numbers_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); - config.colorsUsed |= BCK_COLOR; + main_xpm[3] = XpmColorLine( config.backColor, main_xpm[3], + freeMem && ( config.colorsUsed & BCK_COLOR )); + symbols_xpm[3] = XpmColorLine( config.backColor, symbols_xpm[3], + freeMem && ( config.colorsUsed & BCK_COLOR )); + chars_xpm[2] = XpmColorLine( config.backColor, chars_xpm[2], + freeMem && ( config.colorsUsed & BCK_COLOR )); + numbers_xpm[2] = XpmColorLine( config.backColor, numbers_xpm[2], + freeMem && ( config.colorsUsed & BCK_COLOR )); + config.colorsUsed |= BCK_COLOR; } else { - main_xpm[3] = XpmColorLine( "#282828", main_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - symbols_xpm[3] = XpmColorLine( "#282828", symbols_xpm[3], - freeMem && ( config.colorsUsed & BCK_COLOR )); - chars_xpm[2] = XpmColorLine( "#282828", chars_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); - numbers_xpm[2] = XpmColorLine( "#282828", numbers_xpm[2], - freeMem && ( config.colorsUsed & BCK_COLOR )); - config.colorsUsed |= BCK_COLOR; - } + main_xpm[3] = XpmColorLine( "#282828", main_xpm[3], + freeMem && ( config.colorsUsed & BCK_COLOR )); + symbols_xpm[3] = XpmColorLine( "#282828", symbols_xpm[3], + freeMem && ( config.colorsUsed & BCK_COLOR )); + chars_xpm[2] = XpmColorLine( "#282828", chars_xpm[2], + freeMem && ( config.colorsUsed & BCK_COLOR )); + numbers_xpm[2] = XpmColorLine( "#282828", numbers_xpm[2], + freeMem && ( config.colorsUsed & BCK_COLOR )); + config.colorsUsed |= BCK_COLOR; + } if( config.offlightColor != NULL ) { // off-light color ? - main_xpm[2] = XpmColorLine( config.offlightColor, main_xpm[2], - freeMem && ( config.colorsUsed & OFF_COLOR )); - numbers_xpm[4] = XpmColorLine( config.offlightColor, numbers_xpm[4], - freeMem && ( config.colorsUsed & OFF_COLOR )); - config.colorsUsed |= OFF_COLOR; + main_xpm[2] = XpmColorLine( config.offlightColor, main_xpm[2], + freeMem && ( config.colorsUsed & OFF_COLOR )); + numbers_xpm[4] = XpmColorLine( config.offlightColor, numbers_xpm[4], + freeMem && ( config.colorsUsed & OFF_COLOR )); + config.colorsUsed |= OFF_COLOR; } else { - main_xpm[2] = XpmColorLine( "#000000", main_xpm[2], - freeMem && ( config.colorsUsed & OFF_COLOR )); - numbers_xpm[4] = XpmColorLine( "#000000", numbers_xpm[4], - freeMem && ( config.colorsUsed & OFF_COLOR )); - config.colorsUsed |= OFF_COLOR; - } + main_xpm[2] = XpmColorLine( "#000000", main_xpm[2], + freeMem && ( config.colorsUsed & OFF_COLOR )); + numbers_xpm[4] = XpmColorLine( "#000000", numbers_xpm[4], + freeMem && ( config.colorsUsed & OFF_COLOR )); + config.colorsUsed |= OFF_COLOR; + } if( config.backgroundColor != NULL ) { // window-frame background (only seen if nonshaped) ? - main_xpm[1] = XpmColorLine( config.backgroundColor, main_xpm[1], - freeMem && ( config.colorsUsed & BGR_COLOR )); - config.colorsUsed |= BGR_COLOR; + main_xpm[1] = XpmColorLine( config.backgroundColor, main_xpm[1], + freeMem && ( config.colorsUsed & BGR_COLOR )); + config.colorsUsed |= BGR_COLOR; } if( freeMem ) - { - XFreePixmap( DADisplay, mainPixmap ); - XFreePixmap( DADisplay, mainPixmap_mask ); - XFreePixmap( DADisplay, symbolsPixmap ); - XFreePixmap( DADisplay, charsPixmap ); - XFreePixmap( DADisplay, numbersPixmap ); - XFreePixmap( DADisplay, buttonPixmap ); + { + XFreePixmap( DADisplay, mainPixmap ); + XFreePixmap( DADisplay, mainPixmap_mask ); + XFreePixmap( DADisplay, symbolsPixmap ); + XFreePixmap( DADisplay, charsPixmap ); + XFreePixmap( DADisplay, numbersPixmap ); + XFreePixmap( DADisplay, buttonPixmap ); - if( tickerGC != NULL ) - { - XFreeGC( DADisplay, tickerGC ); - tickerGC = NULL; - if( tickerFS != NULL ) { - XFreeFont( DADisplay, tickerFS ); - tickerFS = NULL; - } - } + if( tickerGC != NULL ) + { + XFreeGC( DADisplay, tickerGC ); + tickerGC = NULL; + if( tickerFS != NULL ) { + XFreeFont( DADisplay, tickerFS ); + tickerFS = NULL; + } + } } DAMakePixmapFromData( main_xpm, &mainPixmap, &mainPixmap_mask, &dummy, &dummy ); @@ -422,34 +422,34 @@ void PreparePixmaps( bool freeMem ) DAMakePixmapFromData( numbers_xpm, &numbersPixmap, NULL, &dummy, &dummy ); DAMakePixmapFromData( button_xpm, &buttonPixmap, NULL, &dummy, &dummy ); - if( config.useX11Font != NULL ) - { - XRectangle clipRect; + if( config.useX11Font != NULL ) + { + XRectangle clipRect; - if( config.fontColor != NULL ) - values.foreground = DAGetColor( config.fontColor ); - else - values.foreground = DAGetColor( "#D3D3D3" ); + if( config.fontColor != NULL ) + values.foreground = DAGetColor( config.fontColor ); + else + values.foreground = DAGetColor( "#D3D3D3" ); - tickerFS = XLoadQueryFont( DADisplay, config.useX11Font ); - if( tickerFS == NULL ) - ABORT( "Cannot load font \"%s\"", config.useX11Font ); + tickerFS = XLoadQueryFont( DADisplay, config.useX11Font ); + if( tickerFS == NULL ) + ABORT( "Cannot load font \"%s\"", config.useX11Font ); - values.font = tickerFS->fid; - tickerGC = XCreateGC( DADisplay, DAWindow, GCForeground | GCFont, - &values ); - clipRect.x = 6; - clipRect.y = 19; - clipRect.width = 52; - clipRect.height = 23; + values.font = tickerFS->fid; + tickerGC = XCreateGC( DADisplay, DAWindow, GCForeground | GCFont, + &values ); + clipRect.x = 6; + clipRect.y = 19; + clipRect.width = 52; + clipRect.height = 23; - XSetClipRectangles( DADisplay, tickerGC, 0, 0, &clipRect, 1, Unsorted ); - } + XSetClipRectangles( DADisplay, tickerGC, 0, 0, &clipRect, 1, Unsorted ); + } if( config.noshape ) // non-shaped dockapp ? - DASetShape( None ); + DASetShape( None ); else - DASetShape( mainPixmap_mask ); + DASetShape( mainPixmap_mask ); } void MarkName( unsigned long checksum ) @@ -457,12 +457,12 @@ void MarkName( unsigned long checksum ) name_t *name; for( name = names; name != NULL; name = name->next ) { - if( name->checksum == checksum ) { - name->flag |= FLAG_READ; - if( config.newMailsOnly ) - numMails--; - break; - } + if( name->checksum == checksum ) { + name->flag |= FLAG_READ; + if( config.newMailsOnly ) + numMails--; + break; + } } } @@ -471,31 +471,31 @@ void DetermineState() name_t *name; for( name = names; name != NULL; name = name->next ) - if(!( name->flag & FLAG_READ )) { - state = STATE_NEWMAIL; + if(!( name->flag & FLAG_READ )) { + state = STATE_NEWMAIL; - if( config.cmdOnMail != NULL ) { - int ret = system( config.cmdOnMail ); + if( config.cmdOnMail != NULL ) { + int ret = system( config.cmdOnMail ); - if( ret == 127 || ret == -1 ) - WARNING( "execution of command \"%s\" failed.\n", config.cmdOnMail ); - } + if( ret == 127 || ret == -1 ) + WARNING( "execution of command \"%s\" failed.\n", config.cmdOnMail ); + } - break; - } + break; + } } void ReadChecksumFile() { FILE *f = fopen( config.checksumFileName, "rb" ); if( f != NULL ) while( !feof( f )) { - unsigned long checksum; - if( fread( &checksum, sizeof(long), 1, f ) != 1 ) - continue; + unsigned long checksum; + if( fread( &checksum, sizeof(long), 1, f ) != 1 ) + continue; - MarkName( checksum ); + MarkName( checksum ); } else - return; + return; fclose( f ); } @@ -506,15 +506,15 @@ void WriteChecksumFile( bool writeAll ) TRACE( "writing checksums:" ); if(( f = fopen( config.checksumFileName, "wb" )) != NULL ) { - name_t *name; - for( name = names; name != NULL; name = name->next ) { - if( writeAll || (name->flag & FLAG_READ)) { - fwrite( &name->checksum, sizeof(long), 1, f ); - TRACE( " %X", name->checksum ); - } - } + name_t *name; + for( name = names; name != NULL; name = name->next ) { + if( writeAll || (name->flag & FLAG_READ)) { + fwrite( &name->checksum, sizeof(long), 1, f ); + TRACE( " %X", name->checksum ); + } + } } else - return; + return; TRACE( "\n" ); @@ -524,10 +524,10 @@ void WriteChecksumFile( bool writeAll ) void UpdateChecksum( unsigned long *checksum, const char *buf ) { if( buf != NULL ) { - unsigned int i, len = strlen( buf ); + unsigned int i, len = strlen( buf ); - for( i = 0; i < len; ++i ) - *checksum += buf[i] << (( i % sizeof(long) ) * 8 ); + for( i = 0; i < len; ++i ) + *checksum += buf[i] << (( i % sizeof(long) ) * 8 ); } } @@ -543,194 +543,194 @@ void TimerHandler( int dummy ) static int checkMail = 0; if( readConfigFile ) { - readConfigFile = false; - UpdateConfiguration(); - checkMail = 0; - forceRead = true; + readConfigFile = false; + UpdateConfiguration(); + checkMail = 0; + forceRead = true; } if( checkMail == 0 ) - { - TRACE( "checking for new mail...\n" ); + { + TRACE( "checking for new mail...\n" ); - if( isMaildir ) - CheckMaildir(); - else - CheckMBox(); - } + if( isMaildir ) + CheckMaildir(); + else + CheckMBox(); + } UpdatePixmap( checkMail % config.fps < config.fps/2 ); if( ++checkMail >= config.fps * config.checkInterval ) - checkMail = 0; + checkMail = 0; } void CheckMBox() { - struct stat fileStat; + struct stat fileStat; - // error retrieving file-stats -> no/zero-size file and no new/read mails - // available - if( stat( config.mailBox, &fileStat ) == -1 || fileStat.st_size == 0 ) { - if( state != STATE_NOMAIL ) { - state = STATE_NOMAIL; - ClearAllNames(); - RemoveChecksumFile(); - forceRedraw = true; - } - } else { - // file has changed -> new mails arrived or some mails removed - if( lastModifySeconds != fileStat.st_mtime || forceRead ) { - forceRead = false; - ParseMBoxFile( &fileStat ); - stat( config.mailBox, &fileStat ); - forceRedraw = true; - // file has accessed (read) -> mark all mails as "read", because - // it cannot be decided which mails the user has read... - } else if( lastAccessSeconds != fileStat.st_atime ) { - state = STATE_READMAIL; - WriteChecksumFile( true ); - if( config.newMailsOnly ) { - numMails = 0; - SetMailFlags( FLAG_READ ); - } - forceRedraw = true; - } - - lastModifySeconds = fileStat.st_mtime; - lastAccessSeconds = fileStat.st_atime; + // error retrieving file-stats -> no/zero-size file and no new/read mails + // available + if( stat( config.mailBox, &fileStat ) == -1 || fileStat.st_size == 0 ) { + if( state != STATE_NOMAIL ) { + state = STATE_NOMAIL; + ClearAllNames(); + RemoveChecksumFile(); + forceRedraw = true; } + } else { + // file has changed -> new mails arrived or some mails removed + if( lastModifySeconds != fileStat.st_mtime || forceRead ) { + forceRead = false; + ParseMBoxFile( &fileStat ); + stat( config.mailBox, &fileStat ); + forceRedraw = true; + // file has accessed (read) -> mark all mails as "read", because + // it cannot be decided which mails the user has read... + } else if( lastAccessSeconds != fileStat.st_atime ) { + state = STATE_READMAIL; + WriteChecksumFile( true ); + if( config.newMailsOnly ) { + numMails = 0; + SetMailFlags( FLAG_READ ); + } + forceRedraw = true; + } + + lastModifySeconds = fileStat.st_mtime; + lastAccessSeconds = fileStat.st_atime; + } } void CheckMaildir() { - DIR *dir = NULL; - int lastState = state; - int lastMailCount = numMails; + DIR *dir = NULL; + int lastState = state; + int lastMailCount = numMails; - if( forceRead ) { - forceRead = false; - ClearAllNames(); - TRACE( "all names cleared\n" ); - } + if( forceRead ) { + forceRead = false; + ClearAllNames(); + TRACE( "all names cleared\n" ); + } - state = STATE_NOMAIL; + state = STATE_NOMAIL; - if(( dir = opendir( config.mailBox )) != NULL ) + if(( dir = opendir( config.mailBox )) != NULL ) + { + struct dirent *dirEnt = NULL; + //bool writeChecksums = false; + name_t *name; + + for( name = names; name != NULL; name = name->next ) + name->visited = false; + + while(( dirEnt = readdir( dir )) != NULL ) { - struct dirent *dirEnt = NULL; - //bool writeChecksums = false; - name_t *name; + char *fullName = FileNameConcat( config.mailBox, dirEnt->d_name ); + struct stat fileStat; - for( name = names; name != NULL; name = name->next ) - name->visited = false; + if( !stat( fullName, &fileStat ) == 0 ) { + WARNING( "Can't stat file/path \"%s\"\n", fullName ); + free( fullName ); + continue; + } - while(( dirEnt = readdir( dir )) != NULL ) - { - char *fullName = FileNameConcat( config.mailBox, dirEnt->d_name ); - struct stat fileStat; - - if( !stat( fullName, &fileStat ) == 0 ) { - WARNING( "Can't stat file/path \"%s\"\n", fullName ); - free( fullName ); - continue; - } - - if( S_ISDIR( fileStat.st_mode )) - { - if( strcmp( dirEnt->d_name, "new" ) == 0 ) { - if( TraverseDirectory( fullName, true ) > 0 ) - state = STATE_NEWMAIL; - } - else if( strcmp( dirEnt->d_name, "cur" ) == 0 ) { - if( TraverseDirectory( fullName, false ) > 0 ) - if( state != STATE_NEWMAIL ) - state = STATE_READMAIL; - } - // directories ".", ".." and "tmp" discarded - } + if( S_ISDIR( fileStat.st_mode )) + { + if( strcmp( dirEnt->d_name, "new" ) == 0 ) { + if( TraverseDirectory( fullName, true ) > 0 ) + state = STATE_NEWMAIL; } - closedir( dir ); - CleanupNames(); - } else - WARNING( "can't open directory \"%s\"\n", config.mailBox ); + else if( strcmp( dirEnt->d_name, "cur" ) == 0 ) { + if( TraverseDirectory( fullName, false ) > 0 ) + if( state != STATE_NEWMAIL ) + state = STATE_READMAIL; + } + // directories ".", ".." and "tmp" discarded + } + } + closedir( dir ); + CleanupNames(); + } else + WARNING( "can't open directory \"%s\"\n", config.mailBox ); - if( lastState != state || lastMailCount != numMails ) - forceRedraw = true; + if( lastState != state || lastMailCount != numMails ) + forceRedraw = true; } int TraverseDirectory( const char *name, bool isNewMail ) { - DIR *dir = NULL; - int mails = 0; + DIR *dir = NULL; + int mails = 0; - if(( dir = opendir( name )) != NULL ) + if(( dir = opendir( name )) != NULL ) + { + struct dirent *dirEnt = NULL; + + while(( dirEnt = readdir( dir )) != NULL ) { - struct dirent *dirEnt = NULL; + char *fullName = FileNameConcat( name, dirEnt->d_name ); + struct stat fileStat; + unsigned long checksum = 0; + name_t *name; - while(( dirEnt = readdir( dir )) != NULL ) + if( !stat( fullName, &fileStat ) == 0 ) { + WARNING( "Can't stat file/path \"%s\"\n", fullName ); + free( fullName ); + continue; + } + + if( !S_ISDIR( fileStat.st_mode )) + { + TRACE( "found email-file \"%s\"\n", fullName ); + UpdateChecksum( &checksum, dirEnt->d_name ); + + if(( name = GetMail( checksum )) == NULL ) { - char *fullName = FileNameConcat( name, dirEnt->d_name ); - struct stat fileStat; - unsigned long checksum = 0; - name_t *name; - - if( !stat( fullName, &fileStat ) == 0 ) { - WARNING( "Can't stat file/path \"%s\"\n", fullName ); - free( fullName ); - continue; - } - - if( !S_ISDIR( fileStat.st_mode )) - { - TRACE( "found email-file \"%s\"\n", fullName ); - UpdateChecksum( &checksum, dirEnt->d_name ); - - if(( name = GetMail( checksum )) == NULL ) - { - TRACE( "-> new file - parsing it\n" ); - ParseMaildirFile( fullName, checksum, &fileStat, isNewMail ); - } - else { - name->flag = isNewMail ? FLAG_INITIAL : FLAG_READ; - name->visited = true; - } - ++mails; - } + TRACE( "-> new file - parsing it\n" ); + ParseMaildirFile( fullName, checksum, &fileStat, isNewMail ); } + else { + name->flag = isNewMail ? FLAG_INITIAL : FLAG_READ; + name->visited = true; + } + ++mails; + } } + } - closedir( dir ); + closedir( dir ); - return mails; + return mails; } char *FileNameConcat( const char *path, const char *fileName ) { - int len1 = strlen( path ); - int len2 = strlen( fileName ); - char *buf; + int len1 = strlen( path ); + int len2 = strlen( fileName ); + char *buf; - if( path[len1-1] == '/' ) - --len1; + if( path[len1-1] == '/' ) + --len1; - buf = (char *)malloc( len1 + len2 + 2 ); + buf = (char *)malloc( len1 + len2 + 2 ); - memcpy( buf, path, len1 ); - buf[len1] = '/'; - memcpy( &buf[len1+1], fileName, len2 ); - buf[len1+len2+1] = '\0'; + memcpy( buf, path, len1 ); + buf[len1] = '/'; + memcpy( &buf[len1+1], fileName, len2 ); + buf[len1+len2+1] = '\0'; - return buf; + return buf; } name_t *GetMail( unsigned long checksum ) { - name_t *name; + name_t *name; for( name = names; name != NULL; name = name->next ) - if( name->checksum == checksum ) - return name; + if( name->checksum == checksum ) + return name; return NULL; } @@ -739,51 +739,51 @@ void UpdatePixmap( bool flashMailSymbol ) { int drawCount, i; - if( !forceRedraw && !HasTickerWork() ) - return; + if( !forceRedraw && !HasTickerWork() ) + return; - forceRedraw = false; + forceRedraw = false; XCopyArea( DADisplay, mainPixmap, outPixmap, DAGC, - 0, 0, 64, 64, 0, 0 ); + 0, 0, 64, 64, 0, 0 ); if( numMails > 999 ) - { - XCopyArea( DADisplay, numbersPixmap, outPixmap, DAGC, - 50, 0, 5, 9, 6, 49 ); - drawCount = 999; + { + XCopyArea( DADisplay, numbersPixmap, outPixmap, DAGC, + 50, 0, 5, 9, 6, 49 ); + drawCount = 999; } else - drawCount = numMails; + drawCount = numMails; for( i = 0; i < 3; ++i, drawCount /= 10 ) - { - XCopyArea( DADisplay, numbersPixmap, outPixmap, DAGC, - (drawCount%10)*5, 0, 5, 9, 24-i*6, 49 ); - if( drawCount <= 9 ) - break; + { + XCopyArea( DADisplay, numbersPixmap, outPixmap, DAGC, + (drawCount%10)*5, 0, 5, 9, 24-i*6, 49 ); + if( drawCount <= 9 ) + break; } if( buttonPressed ) - { - XCopyArea( DADisplay, buttonPixmap, outPixmap, DAGC, - 0, 0, 23, 11, 36, 48 ); - } + { + XCopyArea( DADisplay, buttonPixmap, outPixmap, DAGC, + 0, 0, 23, 11, 36, 48 ); + } switch( state ) { case STATE_NEWMAIL: - if( flashMailSymbol ) - XCopyArea( DADisplay, symbolsPixmap, outPixmap, DAGC, - 13, 0, 37, 12, 20, 7 ); + if( flashMailSymbol ) + XCopyArea( DADisplay, symbolsPixmap, outPixmap, DAGC, + 13, 0, 37, 12, 20, 7 ); case STATE_READMAIL: - XCopyArea( DADisplay, symbolsPixmap, outPixmap, DAGC, - 0, 0, 13, 12, 7, 7 ); + XCopyArea( DADisplay, symbolsPixmap, outPixmap, DAGC, + 0, 0, 13, 12, 7, 7 ); - if( config.useX11Font == NULL ) - DrawTickerBuildinFont(); - else - DrawTickerX11Font(); + if( config.useX11Font == NULL ) + DrawTickerBuildinFont(); + else + DrawTickerX11Font(); default: // make compiler happy - ; + ; } DASetPixmap( outPixmap ); @@ -803,39 +803,39 @@ void ParseMBoxFile( struct stat *fileStat ) numMails = 0; if( f == NULL ) { - WARNING( "can't open mbox \"%s\"\n", config.mailBox ); - return; + WARNING( "can't open mbox \"%s\"\n", config.mailBox ); + return; } while( fgets( buf, 1024, f ) != NULL ) + { + if( strncmp( buf, "From ", 5 ) == 0 ) { + fromFound = 1; + checksum = 0; + continue; + } + + if( fromFound ) + UpdateChecksum( &checksum, buf ); + + if( fromFound && strncasecmp( buf, "from: ", 6 ) == 0 ) { - if( strncmp( buf, "From ", 5 ) == 0 ) { - fromFound = 1; - checksum = 0; - continue; - } + if( SkipSender( buf+6 )) + goto NEXTMAIL; - if( fromFound ) - UpdateChecksum( &checksum, buf ); + InsertName( ParseFromField( buf+6 ), checksum, FLAG_INITIAL ); - if( fromFound && strncasecmp( buf, "from: ", 6 ) == 0 ) - { - if( SkipSender( buf+6 )) - goto NEXTMAIL; - - InsertName( ParseFromField( buf+6 ), checksum, FLAG_INITIAL ); - - ++numMails; - fromFound = 0; - checksum = 0; - } else if( config.considerStatusField && strncasecmp( buf, "status: ", 8 ) == 0 && - strstr( buf+8, config.readStatus ) == NULL ) - { - RemoveLastName(); - --numMails; - } - NEXTMAIL: - ; + ++numMails; + fromFound = 0; + checksum = 0; + } else if( config.considerStatusField && strncasecmp( buf, "status: ", 8 ) == 0 && + strstr( buf+8, config.readStatus ) == NULL ) + { + RemoveLastName(); + --numMails; + } +NEXTMAIL: + ; } fclose( f ); @@ -849,230 +849,230 @@ void ParseMBoxFile( struct stat *fileStat ) } void ParseMaildirFile( const char *fileName, unsigned long checksum, - struct stat *fileStat, bool isNewMail ) + struct stat *fileStat, bool isNewMail ) { - char buf[1024]; - struct utimbuf timeStruct; - FILE *f = fopen( fileName, "rt" ); + char buf[1024]; + struct utimbuf timeStruct; + FILE *f = fopen( fileName, "rt" ); - if( f == NULL ) + if( f == NULL ) + { + WARNING( "can't open maildir file \"%s\"\n", fileName ); + return; + } + + while( fgets( buf, 1024, f ) != NULL ) + { + if( strncasecmp( buf, "from: ", 6 ) == 0 ) { - WARNING( "can't open maildir file \"%s\"\n", fileName ); - return; + if( SkipSender( buf+6 )) + break; + + InsertName( ParseFromField( buf+6 ), checksum, + isNewMail ? FLAG_INITIAL : FLAG_READ ); + + //++numMails; } + } - while( fgets( buf, 1024, f ) != NULL ) - { - if( strncasecmp( buf, "from: ", 6 ) == 0 ) - { - if( SkipSender( buf+6 )) - break; + fclose( f ); - InsertName( ParseFromField( buf+6 ), checksum, - isNewMail ? FLAG_INITIAL : FLAG_READ ); - - //++numMails; - } - } - - fclose( f ); - - timeStruct.actime = fileStat->st_atime; + timeStruct.actime = fileStat->st_atime; timeStruct.modtime = fileStat->st_mtime; utime( fileName, &timeStruct ); } char *ParseFromField( char *buf ) { - parse_state_t state = STATE_FULLNAME; - int fullNameEncoded = 0; - int saveAtCharPos = -1; - char *fullName; - char *addressName; - char *atChar = NULL; - char *c; - int maxLen = strlen( buf ) + 1; - char *comment; + parse_state_t state = STATE_FULLNAME; + int fullNameEncoded = 0; + int saveAtCharPos = -1; + char *fullName; + char *addressName; + char *atChar = NULL; + char *c; + int maxLen = strlen( buf ) + 1; + char *comment; - // FIXME: Uhm, those mallocs might fail... + // FIXME: Uhm, those mallocs might fail... - fullName = malloc( maxLen ); - addressName = malloc( maxLen ); - comment = malloc( maxLen ); + fullName = malloc( maxLen ); + addressName = malloc( maxLen ); + comment = malloc( maxLen ); - memset( fullName, '\0', maxLen ); - memset( addressName, '\0', maxLen ); - memset( comment, '\0', maxLen ); + memset( fullName, '\0', maxLen ); + memset( addressName, '\0', maxLen ); + memset( comment, '\0', maxLen ); - // FIXME: Don't do that "encoded" dance. It's not intended by - // RFC2047, and it's better to just do it in the end. - // Cleaner. + // FIXME: Don't do that "encoded" dance. It's not intended by + // RFC2047, and it's better to just do it in the end. + // Cleaner. - for( c = buf; *c != '\0'; ++c ) - { - switch( state ) { - case STATE_FULLNAME: + for( c = buf; *c != '\0'; ++c ) + { + switch( state ) { + case STATE_FULLNAME: - switch( *c ) { - case '"': - state = STATE_QUOTED_FULLNAME; - continue; - case '<': - if( fullName[0] != '\0' && - fullName[ strlen( fullName ) - 1 ] == ' ' ) - fullName[ strlen( fullName ) - 1 ] = '\0'; - state = STATE_ADDRESS; - continue; - case '@': - saveAtCharPos = strlen( fullName ); - fullName[ saveAtCharPos ] = *c; - continue; - case '(': - state = STATE_COMMENT; - continue; - case '=': - if( *(c+1) == '?' ) { - ++c; - fullNameEncoded = 1; - state = STATE_ENCODED_FULLNAME; - continue; - } // else do the default action - default: - fullName[ strlen( fullName ) ] = *c; - } - continue; + switch( *c ) { + case '"': + state = STATE_QUOTED_FULLNAME; + continue; + case '<': + if( fullName[0] != '\0' && + fullName[ strlen( fullName ) - 1 ] == ' ' ) + fullName[ strlen( fullName ) - 1 ] = '\0'; + state = STATE_ADDRESS; + continue; + case '@': + saveAtCharPos = strlen( fullName ); + fullName[ saveAtCharPos ] = *c; + continue; + case '(': + state = STATE_COMMENT; + continue; + case '=': + if( *(c+1) == '?' ) { + ++c; + fullNameEncoded = 1; + state = STATE_ENCODED_FULLNAME; + continue; + } // else do the default action + default: + fullName[ strlen( fullName ) ] = *c; + } + continue; - case STATE_QUOTED_FULLNAME: + case STATE_QUOTED_FULLNAME: - switch( *c ) { - case '\\': - fullName[ strlen( fullName ) ] = *(++c); - continue; - case '"': - state = STATE_FULLNAME; - continue; - default: - fullName[ strlen( fullName ) ] = *c; - } - continue; + switch( *c ) { + case '\\': + fullName[ strlen( fullName ) ] = *(++c); + continue; + case '"': + state = STATE_FULLNAME; + continue; + default: + fullName[ strlen( fullName ) ] = *c; + } + continue; - case STATE_ENCODED_FULLNAME: + case STATE_ENCODED_FULLNAME: - switch( *c ) { - case '?': - if( *(c+1) == '=' ) { - ++c; - state = STATE_FULLNAME; - continue; - } - default: - ; // do nothing... COMING SOON: decode at least latin1 - } - continue; - - case STATE_ADDRESS: - - switch( *c ) { - case '"': - state = STATE_QUOTED_ADDRESS; - case '>': - case '\n': - // FIXME: Shouldn't it break here? - // Since the address is finished? - continue; - case '@': - atChar = &addressName[ strlen( addressName ) ]; - *atChar = *c; - continue; - default: - addressName[ strlen( addressName ) ] = *c; - } - continue; - - case STATE_QUOTED_ADDRESS: - - switch( *c ) { - case '"': - state = STATE_ADDRESS; - continue; - case '\\': - addressName[ strlen( addressName ) ] = *(++c); - continue; - default: - addressName[ strlen( addressName ) ] = *c; - } - continue; - case STATE_COMMENT: - switch( *c ) { - case ')': - state = STATE_FULLNAME; - continue; - default: - comment[ strlen( comment ) ] = *c; - continue; - } - continue; + switch( *c ) { + case '?': + if( *(c+1) == '=' ) { + ++c; + state = STATE_FULLNAME; + continue; } + default: + ; // do nothing... COMING SOON: decode at least latin1 + } + continue; + + case STATE_ADDRESS: + + switch( *c ) { + case '"': + state = STATE_QUOTED_ADDRESS; + case '>': + case '\n': + // FIXME: Shouldn't it break here? + // Since the address is finished? + continue; + case '@': + atChar = &addressName[ strlen( addressName ) ]; + *atChar = *c; + continue; + default: + addressName[ strlen( addressName ) ] = *c; + } + continue; + + case STATE_QUOTED_ADDRESS: + + switch( *c ) { + case '"': + state = STATE_ADDRESS; + continue; + case '\\': + addressName[ strlen( addressName ) ] = *(++c); + continue; + default: + addressName[ strlen( addressName ) ] = *c; + } + continue; + case STATE_COMMENT: + switch( *c ) { + case ')': + state = STATE_FULLNAME; + continue; + default: + comment[ strlen( comment ) ] = *c; + continue; + } + continue; } + } - if (*comment) { - //WARNING("Comment seen: %s\nIn: %s\nFullname: %s\nAddress: %s\n", comment, buf, fullName, addressName); - // Comment seen: if there's an address, append to - // fullname. If no address, copy fullname to address - // and comment to fullname. - if (*addressName) { - strcat(fullName, "("); - strcat(fullName, comment); - strcat(fullName, ")"); - } else { - strcpy(addressName, fullName); - strcpy(fullName, comment); - } - } - - //WARNING("Fullname: %s\nAddress: %s\n", fullName, addressName); - - // what name should be tickered - if( config.tickerMode == TICKER_FAMILYNAME && fullName[0] != '\0' && !fullNameEncoded ) { - free( addressName ); - return fullName; + if (*comment) { + //WARNING("Comment seen: %s\nIn: %s\nFullname: %s\nAddress: %s\n", comment, buf, fullName, addressName); + // Comment seen: if there's an address, append to + // fullname. If no address, copy fullname to address + // and comment to fullname. + if (*addressName) { + strcat(fullName, "("); + strcat(fullName, comment); + strcat(fullName, ")"); } else { - if( state == STATE_FULLNAME ) { - strcpy( addressName, fullName ); - if( saveAtCharPos != -1 ) - atChar = &addressName[saveAtCharPos]; - } - if( config.tickerMode == TICKER_NICKNAME ) { - if( atChar != NULL ) - *atChar = '\0'; - } - free( fullName ); - return addressName; + strcpy(addressName, fullName); + strcpy(fullName, comment); } + } + + //WARNING("Fullname: %s\nAddress: %s\n", fullName, addressName); + + // what name should be tickered + if( config.tickerMode == TICKER_FAMILYNAME && fullName[0] != '\0' && !fullNameEncoded ) { + free( addressName ); + return fullName; + } else { + if( state == STATE_FULLNAME ) { + strcpy( addressName, fullName ); + if( saveAtCharPos != -1 ) + atChar = &addressName[saveAtCharPos]; + } + if( config.tickerMode == TICKER_NICKNAME ) { + if( atChar != NULL ) + *atChar = '\0'; + } + free( fullName ); + return addressName; + } } bool SkipSender( char *address ) { - char **skipName; - int len = strlen( address ); + char **skipName; + int len = strlen( address ); - // remove trailing '\n' got from fgets - if( address[len-1] == '\n' ) - address[len-1] = '\0'; + // remove trailing '\n' got from fgets + if( address[len-1] == '\n' ) + address[len-1] = '\0'; - for( skipName = config.skipNames; - skipName != NULL && *skipName != NULL; skipName++ ) - { - TRACE( "comparing \"%s\" and \"%s\"\n", *skipName, address ); + for( skipName = config.skipNames; + skipName != NULL && *skipName != NULL; skipName++ ) + { + TRACE( "comparing \"%s\" and \"%s\"\n", *skipName, address ); - // call libc-fnmatch (wildcard-match :-) ! - if( !fnmatch( *skipName, address, 0 )) { - TRACE( "skipping sender \"%s\"\n", *skipName ); - return true; - } + // call libc-fnmatch (wildcard-match :-) ! + if( !fnmatch( *skipName, address, 0 )) { + TRACE( "skipping sender \"%s\"\n", *skipName ); + return true; } + } - return false; + return false; } void InsertName( char *name, unsigned long checksum, flag_t flag ) @@ -1084,7 +1084,7 @@ void InsertName( char *name, unsigned long checksum, flag_t flag ) item->name = name; /*strdup( name );*/ item->checksum = checksum; item->flag = flag; - item->visited = true; + item->visited = true; item->next = names; names = item; @@ -1094,9 +1094,9 @@ void InsertName( char *name, unsigned long checksum, flag_t flag ) void RemoveLastName() { if( names != NULL ) { - name_t *name = names; - names = names->next; - free( name ); + name_t *name = names; + names = names->next; + free( name ); } } @@ -1105,10 +1105,10 @@ void ClearAllNames() name_t *name, *nextName; for( name = names; name != NULL; name = nextName ) { - nextName = name->next; + nextName = name->next; - free( name->name ); - free( name ); + free( name->name ); + free( name ); } names = NULL; @@ -1122,45 +1122,45 @@ void SetMailFlags( flag_t flag ) name_t *name; for( name = names; name != NULL; name = name->next ) - name->flag |= flag; + name->flag |= flag; } void DrawTickerX11Font() { - // 49x21+7+20 out-drawable size + // 49x21+7+20 out-drawable size - static int insertAt; + static int insertAt; - if( curTickerName == NULL || namesChanged ) - { - for( curTickerName = names; - curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ ); - curTickerName = curTickerName->next ); + if( curTickerName == NULL || namesChanged ) + { + for( curTickerName = names; + curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ ); + curTickerName = curTickerName->next ); - if( curTickerName == NULL ) - return; + if( curTickerName == NULL ) + return; - namesChanged = false; - insertAt = 54; + namesChanged = false; + insertAt = 54; } - XDrawString( DADisplay, outPixmap, tickerGC, insertAt, - 41-tickerFS->max_bounds.descent, - curTickerName->name, strlen( curTickerName->name )); + XDrawString( DADisplay, outPixmap, tickerGC, insertAt, + 41-tickerFS->max_bounds.descent, + curTickerName->name, strlen( curTickerName->name )); - --insertAt; + --insertAt; - if( insertAt < -XTextWidth( tickerFS, curTickerName->name, - strlen( curTickerName->name )) + 6 ) - { - do { - curTickerName = curTickerName->next; - } while( curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ )); + if( insertAt < -XTextWidth( tickerFS, curTickerName->name, + strlen( curTickerName->name )) + 6 ) + { + do { + curTickerName = curTickerName->next; + } while( curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ )); - if( curTickerName != NULL ) { - insertAt = 54; - } + if( curTickerName != NULL ) { + insertAt = 54; } + } } void DrawTickerBuildinFont() @@ -1180,64 +1180,64 @@ void DrawTickerBuildinFont() if( curTickerName == NULL || namesChanged ) { - for( curTickerName = names; - curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ ); - curTickerName = curTickerName->next ); + for( curTickerName = names; + curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ ); + curTickerName = curTickerName->next ); - if( curTickerName == NULL ) - return; + if( curTickerName == NULL ) + return; - insertAt = 57; - takeItFrom = 0; - namesChanged = false; + insertAt = 57; + takeItFrom = 0; + namesChanged = false; } leftSpace = takeItFrom % 14; for( currentChar = (unsigned char *)&curTickerName->name[takeItFrom/14], - drawTo = insertAt; *currentChar != '\0'; ++currentChar ) + drawTo = insertAt; *currentChar != '\0'; ++currentChar ) { - int outChar = (*currentChar < 32 || *currentChar >= 128) ? '?' : - *currentChar; - int charWidth = 57-drawTo >= 14 ? 14 - leftSpace : 57-drawTo; + int outChar = (*currentChar < 32 || *currentChar >= 128) ? '?' : + *currentChar; + int charWidth = 57-drawTo >= 14 ? 14 - leftSpace : 57-drawTo; - XCopyArea( DADisplay, charsPixmap, outPixmap, DAGC, - (outChar-32)*14+leftSpace, 0, charWidth, 21, drawTo, 20 ); + XCopyArea( DADisplay, charsPixmap, outPixmap, DAGC, + (outChar-32)*14+leftSpace, 0, charWidth, 21, drawTo, 20 ); - leftSpace = 0; - drawTo += charWidth; + leftSpace = 0; + drawTo += charWidth; - if( drawTo > 57 ) - break; + if( drawTo > 57 ) + break; } if( --insertAt < 7 ) { - insertAt = 7; - takeItFrom++; + insertAt = 7; + takeItFrom++; - if( takeItFrom/14 >= strlen( curTickerName->name )) { + if( takeItFrom/14 >= strlen( curTickerName->name )) { - do { - curTickerName = curTickerName->next; - } while( curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ )); + do { + curTickerName = curTickerName->next; + } while( curTickerName != NULL && config.newMailsOnly && ( curTickerName->flag & FLAG_READ )); - if( curTickerName != NULL ) { - takeItFrom = 0; - insertAt = 57; - } - } + if( curTickerName != NULL ) { + takeItFrom = 0; + insertAt = 57; + } + } } } void ButtonPressed( int button, int state, int x, int y ) { if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) { - buttonPressed = true; - forceRedraw = true; + buttonPressed = true; + forceRedraw = true; } else - // reread the config file - readConfigFile = true; + // reread the config file + readConfigFile = true; } void ButtonReleased( int button, int state, int x, int y ) @@ -1246,10 +1246,10 @@ void ButtonReleased( int button, int state, int x, int y ) forceRedraw = true; if( x >= 35 && x <= 59 && y >= 47 && y <= 59 ) { - int ret = system( config.runCmd ); + int ret = system( config.runCmd ); - if( ret == 127 || ret == -1 ) - WARNING( "execution of command \"%s\" failed.\n", config.runCmd ); + if( ret == 127 || ret == -1 ) + WARNING( "execution of command \"%s\" failed.\n", config.runCmd ); } } @@ -1258,13 +1258,13 @@ void GetHexColorString( const char *colorName, char *xpmLine ) XColor color; if( XParseColor( DADisplay, - DefaultColormap( DADisplay, DefaultScreen( DADisplay )), - colorName, &color )) + DefaultColormap( DADisplay, DefaultScreen( DADisplay )), + colorName, &color )) { - sprintf( xpmLine, "%02X%02X%02X", color.red>>8, color.green>>8, - color.blue>>8 ); + sprintf( xpmLine, "%02X%02X%02X", color.red>>8, color.green>>8, + color.blue>>8 ); } else - WARNING( "unknown colorname: \"%s\"\n", colorName ); + WARNING( "unknown colorname: \"%s\"\n", colorName ); } char *XpmColorLine( const char *colorName, char *colorLine, bool disposeLine ) @@ -1273,16 +1273,16 @@ char *XpmColorLine( const char *colorName, char *colorLine, bool disposeLine ) char *from = strrchr( newLine, '#' ); if( from == NULL && !strcasecmp( &colorLine[ strlen( colorLine ) - 4 ], "none" )) { - // if no # found, it should be a None-color line - free( newLine ); - newLine = malloc( 12 ); - strcpy( newLine, " \tc #" ); - newLine[11] = '\0'; - from = newLine + 4; + // if no # found, it should be a None-color line + free( newLine ); + newLine = malloc( 12 ); + strcpy( newLine, " \tc #" ); + newLine[11] = '\0'; + from = newLine + 4; } if( disposeLine ) - free( colorLine ); + free( colorLine ); GetHexColorString( colorName, from+1 ); @@ -1291,24 +1291,24 @@ char *XpmColorLine( const char *colorName, char *colorLine, bool disposeLine ) void UpdateConfiguration() { - struct stat fileStat; + struct stat fileStat; TRACE( "reading configuration file...\n" ); ReadConfigFile( true ); - // if no path/name to an mbox or maildir inbox directory was given, - // use the environment + // if no path/name to an mbox or maildir inbox directory was given, + // use the environment if( config.mailBox == NULL ) - config.mailBox = getenv( "MAIL" ); + config.mailBox = getenv( "MAIL" ); - // mbox or maildir ? - if( config.mailBox != NULL && stat( config.mailBox, &fileStat ) == 0 ) - isMaildir = S_ISDIR( fileStat.st_mode ) != 0; - else - isMaildir = false; + // mbox or maildir ? + if( config.mailBox != NULL && stat( config.mailBox, &fileStat ) == 0 ) + isMaildir = S_ISDIR( fileStat.st_mode ) != 0; + else + isMaildir = false; - TRACE( "mailbox is of type %s\n", isMaildir ? "maildir" : "mbox" ); + TRACE( "mailbox is of type %s\n", isMaildir ? "maildir" : "mbox" ); PreparePixmaps( true ); @@ -1317,46 +1317,46 @@ void UpdateConfiguration() void CleanupNames() { - name_t *name, *last = NULL, *nextName; + name_t *name, *last = NULL, *nextName; - numMails = 0; + numMails = 0; - for( name = names; name != NULL; name = nextName ) - { - nextName = name->next; + for( name = names; name != NULL; name = nextName ) + { + nextName = name->next; - if( !name->visited ) { - if( last == NULL ) - names = name->next; - else - last->next = name->next; + if( !name->visited ) { + if( last == NULL ) + names = name->next; + else + last->next = name->next; - free( name ); - } else { - last = name; + free( name ); + } else { + last = name; - if( !config.newMailsOnly || (name->flag & FLAG_READ) == 0 ) - ++numMails; - } + if( !config.newMailsOnly || (name->flag & FLAG_READ) == 0 ) + ++numMails; } + } } bool HasTickerWork() { - name_t *nextTickerName; + name_t *nextTickerName; - if( names == NULL ) - return false; + if( names == NULL ) + return false; - if( curTickerName == NULL || namesChanged ) { + if( curTickerName == NULL || namesChanged ) { - for( nextTickerName = names; - nextTickerName != NULL && ( config.newMailsOnly && ( nextTickerName->flag & FLAG_READ )); - nextTickerName = nextTickerName->next ); + for( nextTickerName = names; + nextTickerName != NULL && ( config.newMailsOnly && ( nextTickerName->flag & FLAG_READ )); + nextTickerName = nextTickerName->next ); - if( nextTickerName == NULL ) - return false; - } + if( nextTickerName == NULL ) + return false; + } - return true; + return true; }