wmauda: Fix installation dir
[dockapps.git] / wmnotify-1.0.0 / src / options.c
blobd56f2ba13d7b6e65fc3b7a3ae58305cb39805be1
1 /*
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.
21 #if HAVE_CONFIG_H
22 # include "config.h"
23 #endif
25 #include <unistd.h>
26 #include <stdio.h>
27 #include <stdlib.h>
29 #if STDC_HEADERS
30 # include <string.h>
31 #elif HAVE_STRINGS_H
32 # include <strings.h>
33 #endif
35 #include "common.h"
36 #include "wmnotify.h"
37 #include "options.h"
40 /*******************************************************************************
41 * Display the help message and exit
42 ******************************************************************************/
43 static void
44 DisplayUsage( void )
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");
54 printf( "\n" );
58 /*******************************************************************************
59 * Display version information and exit
60 ******************************************************************************/
61 static void
62 DisplayVersion( void )
64 printf( "\n" );
65 printf( " %s, version %s\n", PACKAGE, VERSION );
66 printf( " Written by Hugo Villeneuve\n\n" );
70 static void
71 InvalidOption( const char *message, /*@null@*/ const char *string )
73 if( string == NULL ) {
74 fprintf(stderr, "%s: %s\n", PACKAGE, message );
76 else {
77 fprintf(stderr, "%s: %s %s\n", PACKAGE, message, string );
80 fprintf(stderr, "Try `%s -h' for more information.\n", PACKAGE );
82 exit( EXIT_FAILURE );
86 /*******************************************************************************
87 * Initializes the different options passed as arguments on the command line.
88 ******************************************************************************/
89 void
90 ParseCommandLineOptions( int argc, char *argv[] )
92 int i;
93 char *token;
94 bool config_file_on = false;
95 bool display_on = false;
96 bool geometry_on = false;
98 /* Default values. */
99 wmnotify_infos.debug = false;
101 for( i = 1; i < argc; i++ ) {
102 token = argv[i];
103 switch( token[0] ) {
104 case '-':
105 /* Processing options names */
106 switch( token[1] ) {
107 case 'c':
108 if( strlen( &token[1] ) == 1 ) {
109 config_file_on = true;
111 else {
112 InvalidOption( "invalid option", token );
114 break;
115 case 'd':
116 if( STREQ( "display", &token[1] ) ) {
117 display_on = true;
119 else if( strlen( &token[1] ) == 1 ) {
120 wmnotify_infos.debug = true;
122 break;
123 case 'g':
124 if( STREQ( "geometry", &token[1] ) ) {
125 geometry_on = true;
127 else {
128 InvalidOption( "invalid option", token );
130 break;
131 case 'h':
132 if( strlen( &token[1] ) == 1 ) {
133 DisplayUsage();
134 exit( EXIT_SUCCESS );
136 InvalidOption( "invalid option", token );
137 break;
138 case 'v' :
139 if( STREQ( "version", &token[1] ) ) {
140 DisplayVersion();
141 exit( EXIT_SUCCESS );
143 else {
144 InvalidOption( "invalid option", token );
146 break;
147 default:
148 InvalidOption( "invalid option", token );
149 break;
150 } /* end switch( token[1] ) */
151 break;
152 default:
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 ) {
160 display_on = false;
161 wmnotify_infos.display_arg = token;
163 else if( geometry_on != false ) {
164 geometry_on = false;
165 wmnotify_infos.geometry_arg = token;
167 else {
168 InvalidOption( "invalid option", token );
170 break;
171 } /* end switch( token[0] ) */
172 } /* end for */
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 );