2 * options.c -- functions for processing command-line options and arguments
4 * Copyright (C) 2003 Hugo Villeneuve <hugo@hugovil.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
40 /*******************************************************************************
41 * Display the help message and exit
42 ******************************************************************************/
46 printf( "Usage: %s [OPTIONS]...\n", PACKAGE
);
47 printf( "Email notification for single POP3 or IMAP4 account.\n\n" );
48 printf( " -c <config-file> use alternate configuration file\n" );
49 printf( " -d Display debugging messages.\n" );
50 printf( " -display <host:display> X display name\n" );
51 printf( " -geometry +XPOS+YPOS initial window position\n" );
52 printf( " -h display this help and exit\n" );
53 printf( " -version display version information and exit\n");
58 /*******************************************************************************
59 * Display version information and exit
60 ******************************************************************************/
62 DisplayVersion( void )
65 printf( " %s, version %s\n", PACKAGE
, VERSION
);
66 printf( " Written by Hugo Villeneuve\n\n" );
71 InvalidOption( const char *message
, /*@null@*/ const char *string
)
73 if( string
== NULL
) {
74 fprintf(stderr
, "%s: %s\n", PACKAGE
, message
);
77 fprintf(stderr
, "%s: %s %s\n", PACKAGE
, message
, string
);
80 fprintf(stderr
, "Try `%s -h' for more information.\n", PACKAGE
);
86 /*******************************************************************************
87 * Initializes the different options passed as arguments on the command line.
88 ******************************************************************************/
90 ParseCommandLineOptions( int argc
, char *argv
[] )
94 bool config_file_on
= false;
95 bool display_on
= false;
96 bool geometry_on
= false;
99 wmnotify_infos
.debug
= false;
101 for( i
= 1; i
< argc
; i
++ ) {
105 /* Processing options names */
108 if( strlen( &token
[1] ) == 1 ) {
109 config_file_on
= true;
112 InvalidOption( "invalid option", token
);
116 if( STREQ( "display", &token
[1] ) ) {
119 else if( strlen( &token
[1] ) == 1 ) {
120 wmnotify_infos
.debug
= true;
124 if( STREQ( "geometry", &token
[1] ) ) {
128 InvalidOption( "invalid option", token
);
132 if( strlen( &token
[1] ) == 1 ) {
134 exit( EXIT_SUCCESS
);
136 InvalidOption( "invalid option", token
);
139 if( STREQ( "version", &token
[1] ) ) {
141 exit( EXIT_SUCCESS
);
144 InvalidOption( "invalid option", token
);
148 InvalidOption( "invalid option", token
);
150 } /* end switch( token[1] ) */
153 /* Processing options arguments */
154 if( config_file_on
!= false ) {
155 wmnotify_infos
.optional_config_file
= token
;
156 /*strcpy( config_file_name, token );*/
157 config_file_on
= false;
159 else if( display_on
!= false ) {
161 wmnotify_infos
.display_arg
= token
;
163 else if( geometry_on
!= false ) {
165 wmnotify_infos
.geometry_arg
= token
;
168 InvalidOption( "invalid option", token
);
171 } /* end switch( token[0] ) */
174 if( config_file_on
!= false ) {
175 InvalidOption( "missing configuration file parameter", NULL
);
177 else if( display_on
!= false ) {
178 InvalidOption( "missing display parameter", NULL
);
180 else if( geometry_on
!= false ) {
181 InvalidOption( "missing geometry parameter", NULL
);