wmmixer: 1.9
[dockapps.git] / wmmisc / src / dockapp_main.c
blobfccc677938c80a6adb4255e8ba8a264525aff1f5
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 <getopt.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <bits/getopt_core.h>
26 #include <signal.h>
28 #ifdef USE_MTRACE
29 #include <mcheck.h>
30 #endif /* USE_MTRACE */
32 #include <libdockapp/wmgeneral.h>
34 #include "wmmisc-master.xpm"
35 #include "dockapp_main.h"
36 #include "dockapp_draw.h"
38 void
39 dockapp_show_help( const char* wm_name )
41 printf( "Usage: %s [OPTION]...\n", wm_name );
42 printf( "This is a simple WindowMaker 'DockApp' that will monitor the following:\n" );
43 printf( "Number of users logged in, total processes, total number of processes running,\n" );
44 printf( "the system's fork count and load average.\n\n" );
45 printf( " -h display this help and exit\n" );
46 printf( " -v output version information and exit\n" );
47 printf( " -display DISPLAY set display\n");
48 printf( " -geometry +x+y set position\n\n");
49 printf( "Report bugs to <" PACKAGE_BUGREPORT ">.\n" );
52 void
53 dockapp_show_version( void )
55 printf( "%s\n", PACKAGE_STRING);
56 printf( "Written by %s <%s>\n\n", DOCKAPP_AUTHOR, DOCKAPP_AUTHOR_EMAIL );
57 printf( "Copyright (C) 2003-2006 %s\n", DOCKAPP_AUTHOR );
58 printf( "This is free software; see the source for copying conditions. There is NO\n" );
59 printf( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" );
62 void
63 dockapp_exit( int signal_received )
65 #ifdef USE_MTRACE
66 muntrace();
67 #endif /* USE_MTRACE */
69 #ifdef DEBUG
70 fprintf( stderr,
71 "%s: Exiting cleanly with signal %d\n",
72 DOCKAPP_NAME,
73 signal_received );
74 #endif /* DEBUG */
76 exit( 0 );
79 void
80 dockapp_crash( int signal_received )
82 fprintf( stderr,
83 "%s: got signal %d -- bailing out!\n",
84 DOCKAPP_NAME,
85 signal_received );
86 fprintf( stderr,
87 "It appears that %s has encountered an error.\n",
88 DOCKAPP_NAME );
89 fprintf( stderr,
90 "If this continues to happen, please run '%s core' from a debugger,\n",
91 DOCKAPP_NAME );
92 fprintf( stderr,
93 "such as gdb, and report the output to <%s>.\n",
94 PACKAGE_BUGREPORT );
96 abort();
99 int
100 main( int argc, char** argv )
102 int opt = 0;
103 const struct option longopts[] = {
104 {"display", required_argument, NULL, 0},
105 {"geometry", required_argument, NULL, 0},
106 {0, 0, 0, 0}
109 #ifdef USE_MTRACE
110 mtrace();
111 #endif /* USE_MTRACE */
113 signal( SIGINT, dockapp_exit );
114 signal( SIGSEGV, dockapp_crash );
116 opt = getopt_long_only( argc, argv, "hv", longopts, NULL);
118 while ( -1 != opt )
120 switch ( opt )
122 case 'h':
124 dockapp_show_help( argv[0] );
125 exit( 1 );
126 /* Never reached. */
129 case 'v':
131 dockapp_show_version();
132 exit( 1 );
133 /* Never reached. */
137 opt = getopt_long_only( argc, argv, "hv", longopts, NULL);
140 createXBMfromXPM( wmmisc_mask_bits,
141 wmmisc_master_xpm,
142 wmmisc_mask_width,
143 wmmisc_mask_height );
145 openXwindow( argc,
146 argv,
147 wmmisc_master_xpm,
148 wmmisc_mask_bits,
149 wmmisc_mask_width,
150 wmmisc_mask_height );
152 RedrawWindow();
154 dockapp_draw_small_str( "USERS", 4, 4 );
155 dockapp_draw_small_str( "PROCS", 4, 11 );
156 dockapp_draw_small_str( "ACTIVE", 4, 18 );
158 dockapp_draw_small_str( "UP", 4, 28 );
159 dockapp_draw_small_str( "DAYS", 4, 37 );
160 dockapp_draw_small_str( "WEEKS", 4, 44 );
162 dockapp_draw_small_str( "LOAD", 4, 53 );
166 dockapp_draw_data();
167 usleep( 250000L );
168 } while( 1 );
170 return 0;