clean code, update to C99 style

This commit is contained in:
bch 2017-02-18 21:11:06 +00:00
parent 5239eb4dfa
commit 4152e1651f

169
xmem.c
View File

@ -1,6 +1,7 @@
/*
* xload - display system load average in a window
* xmem - display memory/swap usage utility for X
*
* Copyright 2017 Christian Barthel <bch@onfire.org>
* Copyright 1989 Massachusetts Institute of Technology
*
* $XConsortium: xload.c,v 1.36 91/05/24 16:57:46 converse Exp $
@ -16,11 +17,9 @@
#include <X11/Xaw/Cardinals.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Paned.h>
#include "MemStripChart.h"
#include <X11/Xaw/StripChart.h>
#include <X11/Xmu/SysUtil.h>
/* #include <X11/Wc/WcCreateP.h> */
#include "MemStripChart.h"
#include "xmem.bit"
@ -146,97 +145,91 @@ void usage(char *progname)
exit(1);
}
int main(argc, argv)
int argc;
char **argv;
int main(int argc, char **argv)
{
XtAppContext app_con;
Widget toplevel, load, pane, label_wid, load_parent;
Arg args[1];
Pixmap icon_pixmap = None;
char *label, host[256];
char *lastslash;
/* For security reasons, we reset our uid/gid after doing the necessary
system initialization and before calling any X routines. */
setgid(getgid()); /* reset gid first while still (maybe) root */
setuid(getuid());
toplevel = XtAppInitialize(&app_con, "XMem", options_mem, XtNumber(options_mem),
&argc, argv, NULL, NULL, (Cardinal) 0);
if (argc != 1) usage(argv[0]);
XtGetApplicationResources( toplevel, (XtPointer) &resources,
my_resources_mem, XtNumber(my_resources_mem),
NULL, (Cardinal) 0);
/*
* This is a hack so that f.delete will do something useful in this
* single-window application.
*/
XtAppAddActions (app_con, xload_actions, XtNumber(xload_actions));
XtOverrideTranslations(toplevel,
XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
XtSetArg (args[0], XtNiconPixmap, &icon_pixmap);
XtGetValues(toplevel, args, ONE);
if (icon_pixmap == None) {
XtSetArg(args[0], XtNiconPixmap,
XCreateBitmapFromData(XtDisplay(toplevel),
XtScreen(toplevel)->root,
(char *)xload_bits,
xload_width, xload_height));
XtSetValues (toplevel, args, ONE);
}
if (resources.show_label) {
pane = XtCreateManagedWidget ("paned", panedWidgetClass,
toplevel, NULL, ZERO);
label_wid = XtCreateManagedWidget ("label", labelWidgetClass,
pane, NULL, ZERO);
XtSetArg (args[0], XtNlabel, &label);
XtGetValues(label_wid, args, ONE);
if ( strcmp("label", label) == 0 ) {
XtAppContext app_con;
Widget toplevel, load, pane, label_wid, load_parent;
Arg args[1];
Pixmap icon_pixmap = None;
char *label, host[256];
char *lastslash;
/* For security reasons, we reset our uid/gid after doing the necessary
system initialization and before calling any X routines. */
setgid(getgid()); /* reset gid first while still (maybe) root */
setuid(getuid());
toplevel = XtAppInitialize(&app_con, "XMem", options_mem, XtNumber(options_mem),
&argc, argv, NULL, NULL, (Cardinal) 0);
if (argc != 1) usage(argv[0]);
XtGetApplicationResources( toplevel, (XtPointer) &resources,
my_resources_mem, XtNumber(my_resources_mem),
NULL, (Cardinal) 0);
/*
* This is a hack so that f.delete will do something useful in this
* single-window application.
*/
XtAppAddActions (app_con, xload_actions, XtNumber(xload_actions));
XtOverrideTranslations(toplevel,
XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
XtSetArg (args[0], XtNiconPixmap, &icon_pixmap);
XtGetValues(toplevel, args, ONE);
if (icon_pixmap == None) {
XtSetArg(args[0], XtNiconPixmap,
XCreateBitmapFromData(XtDisplay(toplevel),
XtScreen(toplevel)->root,
(char *)xload_bits,
xload_width, xload_height));
XtSetValues (toplevel, args, ONE);
}
if (resources.show_label) {
pane = XtCreateManagedWidget ("paned", panedWidgetClass,
toplevel, NULL, ZERO);
label_wid = XtCreateManagedWidget ("label", labelWidgetClass,
pane, NULL, ZERO);
XtSetArg (args[0], XtNlabel, &label);
XtGetValues(label_wid, args, ONE);
if ( strcmp("label", label) == 0 ) {
(void) XmuGetHostname (host, 255);
XtSetArg (args[0], XtNlabel, host);
XtSetValues (label_wid, args, ONE);
}
load_parent = pane;
}
load_parent = pane;
}
else
load_parent = toplevel;
load = XtCreateManagedWidget ("mem", memStripChartWidgetClass,
load_parent, NULL, ZERO);
XtAddCallback(load, XtNgetValue, (void*)GetMemLoadPoint, NULL);
XtRealizeWidget (toplevel);
wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
False);
(void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
&wm_delete_window, 1);
XtAppMainLoop(app_con);
else
load_parent = toplevel;
load = XtCreateManagedWidget ("mem", memStripChartWidgetClass,
load_parent, NULL, ZERO);
XtAddCallback(load, XtNgetValue, (void*)GetMemLoadPoint, NULL);
XtRealizeWidget (toplevel);
wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
False);
(void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
&wm_delete_window, 1);
XtAppMainLoop(app_con);
}
static void quit (w, event, params, num_params)
Widget w;
XEvent *event;
String *params;
Cardinal *num_params;
static void quit (Widget w, XEvent *event, String *params, Cardinal *num_params)
{
if (event->type == ClientMessage &&
event->xclient.data.l[0] != wm_delete_window) {
XBell (XtDisplay(w), 0);
return;
}
XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
exit (0);
if (event->type == ClientMessage &&
event->xclient.data.l[0] != wm_delete_window) {
XBell (XtDisplay(w), 0);
return;
}
XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
exit (0);
}