wmmisc: Use autoconf defines for version number and bugreport address.
[dockapps.git] / wmmisc / src / dockapp_main.c
blobfb22631f0d86db31f0197eaa9f36c2c406490ae4
1 /*
2 * wmmisc - WindowMaker Dockapp for monitoring misc. information.
3 * Copyright (C) 2003-2006 Jesse S. (luxorfalls@sbcglobal.net)
5 * wmmisc is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * wmmisc is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with wmmisc; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <bits/getopt_core.h>
25 #include <signal.h>
27 #ifdef USE_MTRACE
28 #include <mcheck.h>
29 #endif /* USE_MTRACE */
31 #include <libdockapp/wmgeneral.h>
33 #include "wmmisc-master.xpm"
34 #include "dockapp_main.h"
35 #include "dockapp_draw.h"
37 void
38 dockapp_show_help( const char* wm_name )
40 printf( "Usage: %s [OPTION]...\n", wm_name );
41 printf( "This is a simple WindowMaker 'DockApp' that will monitor the following:\n" );
42 printf( "Number of users logged in, total processes, total number of processes running,\n" );
43 printf( "the system's fork count and load average.\n\n" );
44 printf( " -h display this help and exit\n" );
45 printf( " -v output version information and exit\n\n" );
46 printf( "Report bugs to <" PACKAGE_BUGREPORT ">.\n" );
49 void
50 dockapp_show_version( void )
52 printf( "%s\n", PACKAGE_STRING);
53 printf( "Written by %s <%s>\n\n", DOCKAPP_AUTHOR, DOCKAPP_AUTHOR_EMAIL );
54 printf( "Copyright (C) 2003-2006 %s\n", DOCKAPP_AUTHOR );
55 printf( "This is free software; see the source for copying conditions. There is NO\n" );
56 printf( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" );
59 void
60 dockapp_exit( int signal_received )
62 #ifdef USE_MTRACE
63 muntrace();
64 #endif /* USE_MTRACE */
66 #ifdef DEBUG
67 fprintf( stderr,
68 "%s: Exiting cleanly with signal %d\n",
69 DOCKAPP_NAME,
70 signal_received );
71 #endif /* DEBUG */
73 exit( 0 );
76 void
77 dockapp_crash( int signal_received )
79 fprintf( stderr,
80 "%s: got signal %d -- bailing out!\n",
81 DOCKAPP_NAME,
82 signal_received );
83 fprintf( stderr,
84 "It appears that %s has encountered an error.\n",
85 DOCKAPP_NAME );
86 fprintf( stderr,
87 "If this continues to happen, please run '%s core' from a debugger,\n",
88 DOCKAPP_NAME );
89 fprintf( stderr,
90 "such as gdb, and report the output to <%s>.\n",
91 PACKAGE_BUGREPORT );
93 abort();
96 int
97 main( int argc, char** argv )
99 int opt = 0;
101 #ifdef USE_MTRACE
102 mtrace();
103 #endif /* USE_MTRACE */
105 signal( SIGINT, dockapp_exit );
106 signal( SIGSEGV, dockapp_crash );
108 opt = getopt( argc, argv, "hv" );
110 while ( -1 != opt )
112 switch ( opt )
114 case 'h':
116 dockapp_show_help( argv[0] );
117 exit( 1 );
118 /* Never reached. */
121 case 'v':
123 dockapp_show_version();
124 exit( 1 );
125 /* Never reached. */
129 opt = getopt( argc, argv, "hv" );
132 createXBMfromXPM( wmmisc_mask_bits,
133 wmmisc_master_xpm,
134 wmmisc_mask_width,
135 wmmisc_mask_height );
137 openXwindow( argc,
138 argv,
139 wmmisc_master_xpm,
140 wmmisc_mask_bits,
141 wmmisc_mask_width,
142 wmmisc_mask_height );
144 RedrawWindow();
146 dockapp_draw_small_str( "USERS", 4, 4 );
147 dockapp_draw_small_str( "PROCS", 4, 11 );
148 dockapp_draw_small_str( "ACTIVE", 4, 18 );
150 dockapp_draw_small_str( "UP", 4, 28 );
151 dockapp_draw_small_str( "DAYS", 4, 37 );
152 dockapp_draw_small_str( "WEEKS", 4, 44 );
154 dockapp_draw_small_str( "LOAD", 4, 53 );
158 dockapp_draw_data();
159 usleep( 250000L );
160 } while( 1 );
162 return 0;