Subject: xtbload ver0.1

From: Takeshi Houjyou <[email-masked]>
Date: Thu, 14 Jan 93 17:46:27 +0900

Hi,

  This is toy program about Informix Online monitor on X. I'd like 
to know Online up or down to easy, so I bit modified xload.c on
MIT X11R5. I use on SunOS 4.1.1 and Sequent/ptx with Online 4.1.

  Any commant/suggtion will welcom. Sorry, no manual page.
But same of xload.

                thanks everything.       Takeshi Hojo ([email-masked])
#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  Imakefile
#	  XTbLoad.ad
#	  xtbload.bit
#	  xtbload.c
#
sed 's/^X//' << 'SHAR_EOF' > Imakefile &&
X        DEPLIBS = XawClientDepLibs
XLOCAL_LIBRARIES = XawClientLibs
X           SRCS = xtbload.c 
X           OBJS = xtbload.o 
X OSMAJORVERSION = OSMajorVersion
X OSMINORVERSION = OSMinorVersion
X      DEFINES = -DOSMAJORVERSION=$(OSMAJORVERSION) -DOSMINORVERSION=$(OSMINORVERSION) 
X
XAllTarget(xtbload)
XNormalProgramTarget(xtbload,$(OBJS),$(DEPLIBS),$(LOCAL_LIBRARIES), /**/)
XInstallProgramWithFlags(xtbload, $(BINDIR), $(INSTKMEMFLAGS))
X
XInstallAppDefaults(XTbLoad)
X
XDependTarget()
SHAR_EOF
chmod 0662 Imakefile || echo "restore of Imakefile fails"
sed 's/^X//' << 'SHAR_EOF' > XTbLoad.ad &&
XXTbLoad.input:				false
XXTbLoad*Label*Justify:			left
XXTbLoad*JumpScroll:			1
XXTbLoad*internalBorderWidth:		0
XXTbLoad*showGrip:				FALSE
X
SHAR_EOF
chmod 0662 XTbLoad.ad || echo "restore of XTbLoad.ad fails"
sed 's/^X//' << 'SHAR_EOF' > xtbload.bit &&
X#define xtbload_width 32
X#define xtbload_height 32
X#define xtbload_x_hot 15
X#define xtbload_y_hot 16
Xstatic char xtbload_bits[] = {
X   0x00, 0x00, 0xc0, 0x03, 0x1e, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xf8, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xfc, 0x03, 0x00, 0x00, 0xfe, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0xff, 0x03, 0x00, 0xc0, 0xff, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x00, 0xe0, 0xff, 0x03, 0x00, 0xf0, 0xff, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0xff, 0x03, 0x00, 0xf8, 0xff, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0xff, 0x03, 0x00, 0xfc, 0xff, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x00, 0xfe, 0xff, 0x03, 0x00, 0xfe, 0xff, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0x03, 0x00, 0xff, 0xff, 0x03,
X   0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0x03, 0xc0, 0xff, 0xff, 0x03,
X   0xcf, 0xaf, 0xff, 0xff, 0xb0, 0xee, 0x8e, 0x03, 0xb7, 0xa8, 0x88, 0x03,
X   0xb7, 0xaa, 0xea, 0xff, 0xcf, 0xaa, 0x8a, 0x03};
SHAR_EOF
chmod 0662 xtbload.bit || echo "restore of xtbload.bit fails"
sed 's/^X//' << 'SHAR_EOF' > xtbload.c &&
X#ifndef lint
Xstatic char rcsid[] = "$XConsortium: xload.c,v 1.26 89/12/11 15:53:27 kit Exp $";
X#endif /* lint */
X
X#include <stdio.h> 
X#include <sys/types.h>
X#include <sys/time.h>
X#include <X11/Intrinsic.h>
X#include <X11/Xatom.h>
X#include <X11/StringDefs.h>
X#include <X11/Shell.h>
X
X#include <X11/Xaw/Cardinals.h>
X#include <X11/Xaw/Label.h>
X#include <X11/Xaw/Paned.h>
X#include <X11/Xaw/StripChart.h>
X#include <X11/Xmu/SysUtil.h>
X
X#include "xtbload.bit"
X
Xchar *ProgramName;
X
Xvoid GetLoadPoint();
Xstatic void quit();
X
X/*
X* Definition of the Application resources structure.
X*/
X
Xtypedef struct _XLoadResources {
XBoolean show_label;
X} XLoadResources;
X
Xchar tbconfig[64], * label;
Xchar tbstat[80];
XWidget toplevel, load, pane, label_wid, load_parent;
XArg args[1];
XXLoadResources resources;
Xint bef = 0;
Xtime_t beft = 0;
Xint laststatus;
X
X#define ONLDOWN -1
X#define ONLUP   0
X#define ONLUNKN -2
X
X/*
X* Command line options table.  Only resources are entered here...there is a
X* pass over the remaining options after XtParseCommand is let loose. 
X*/
X
Xstatic XrmOptionDescRec options[] = {
X{"-scale",	"*load.minScale",	XrmoptionSepArg,	   NULL},
X{"-update",	"*load.update",		XrmoptionSepArg,	   NULL},
X{"-hl",		"*load.highlight",	XrmoptionSepArg,	   NULL},
X{"-highlight",	"*load.highlight",	XrmoptionSepArg,	   NULL},
X{"-label",	"*label.label",		XrmoptionSepArg,	   NULL},
X{"-nolabel",	"*showLabel",	        XrmoptionNoArg,          "False"},
X{"-jumpscroll",	"*load.jumpScroll",	XrmoptionSepArg,	   NULL},
X};
X
X/*
X* The structure containing the resource information for the
X* Xload application resources.
X*/
X
X#define Offset(field) (XtOffset(XLoadResources *, field))
X
Xstatic XtResource my_resources[] = {
X{"showLabel", XtCBoolean, XtRBoolean, sizeof(Boolean),
XOffset(show_label), XtRImmediate, (caddr_t) TRUE},
X};
X
X#undef Offset
X
Xstatic XtActionsRec xload_actions[] = {
X{ "quit",	quit },
X};
Xstatic Atom wm_delete_window;
X
X
X/*
X* Exit with message describing command line format.
X*/
X
Xvoid usage()
X{
Xfprintf (stderr, "usage:  %s [-options ...]\n\n", ProgramName);
Xfprintf (stderr, "where options include:\n");
Xfprintf (stderr,
X"    -display dpy            X server on which to display\n");
Xfprintf (stderr,
X"    -geometry geom          size and location of window\n");
Xfprintf (stderr, 
X"    -fn font                font to use in label\n");
Xfprintf (stderr, 
X"    -scale number           minimum number of scale lines\n");
Xfprintf (stderr, 
X"    -update seconds         interval between updates\n");
Xfprintf (stderr,
X"    -label string           annotation text\n");
Xfprintf (stderr, 
X"    -bg color               background color\n");
Xfprintf (stderr, 
X"    -fg color               graph color\n");
Xfprintf (stderr, 
X"    -hl color               scale and text color\n");
Xfprintf (stderr, 
X"    -nolabel                removes the label from above the chart.\n");
Xfprintf (stderr, 
X"    -jumpscroll value       number of pixels to scroll on overflow\n");
Xfprintf (stderr, "\n");
Xexit(1);
X}
X
Xvoid main(argc, argv)
Xint argc;
Xchar **argv;
X{
XPixmap icon_pixmap = None;
X
XProgramName = argv[0];
Xtoplevel = XtInitialize(NULL, "XTbLoad", 
X		    options, XtNumber(options), &argc, argv);
X
XXtGetApplicationResources( toplevel, (caddr_t) &resources, 
X		      my_resources, XtNumber(my_resources),
X		      NULL, (Cardinal) 0);
Xif (argc != 1) usage();
X
X/*
X* This is a hack so that f.delete will do something useful in this
X* single-window application.
X*/
XXtAppAddActions (XtWidgetToApplicationContext(toplevel),
X	     xload_actions, XtNumber(xload_actions));
XXtOverrideTranslations(toplevel,
X	    XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
X
XXtSetArg (args[0], XtNiconPixmap, &icon_pixmap);
XXtGetValues(toplevel, args, ONE);
Xif (icon_pixmap == None) {
XXtSetArg(args[0], XtNiconPixmap, 
X	 XCreateBitmapFromData(XtDisplay(toplevel),
X			       XtScreen(toplevel)->root,
X			       xtbload_bits, xtbload_width, xtbload_height));
XXtSetValues (toplevel, args, ONE);
X}
X
Xif (resources.show_label) {
Xpane = XtCreateManagedWidget ("paned", panedWidgetClass,
X			    toplevel, NULL, ZERO);
Xlabel_wid = XtCreateManagedWidget ("label", labelWidgetClass,
X				 pane, NULL, ZERO);
X
XXtSetArg (args[0], XtNlabel, &label);
X
Xload_parent = pane;
X}
Xelse
Xload_parent = toplevel;
X
Xload = XtCreateManagedWidget ("load", stripChartWidgetClass,
X			  load_parent, NULL, ZERO);    
X
XXtAddCallback(load, XtNgetValue, GetLoadPoint, NULL);
X
X    XtRealizeWidget (toplevel);
X    wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
X                                    False);
X    (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
X                            &wm_delete_window, 1);
X    xtbloadinit();
X    XtMainLoop();
X}
X
X
Xstatic void quit (w, event, params, num_params)
X    Widget w;
X    XEvent *event;
X    String *params;
X    Cardinal *num_params;
X{
X    if (event->type == ClientMessage &&
X        event->xclient.data.l[0] != wm_delete_window) {
X        XBell (XtDisplay(w), 0);
X        return;
X    }
X    XCloseDisplay (XtDisplay(w));
X    exit (0);
X}
X
Xvoid
XGetLoadPoint( w, closure, call_data )
X     Widget	w;		/* unused */
X     caddr_t	closure;	/* unused */
X     caddr_t	call_data;	/* pointer to (double) return value */
X{
X  	double *loadavg = (double *)call_data;
X	time_t now;
X	char line[BUFSIZ];
X	int commit,dum;
X	FILE *tbs;
X
X	if ( (tbs = popen(tbstat, "r")) == NULL ) {
X	    fprintf(stderr, "tbstat not found\n");
X	    exit(-1);
X	}
X
X	fgets(line, BUFSIZ, tbs); /* skip 1'st line */
X
X	if ( fgets(line, BUFSIZ, tbs) == NULL ) { /* not online up */
X	  if (resources.show_label && laststatus != ONLDOWN) {
X	    XtSetArg (args[0], XtNlabel, "DOWN");
X	    XtSetValues (label_wid, args, ONE);
X	    *loadavg = 0;
X	    laststatus = ONLDOWN;
X	    return;
X	  }
X	} else { /* up */
X	  if (resources.show_label && laststatus != ONLUP) {
X	    XtSetArg (args[0], XtNlabel, tbconfig);
X	    XtSetValues (label_wid, args, ONE);
X	    laststatus = ONLUP;
X	  }
X	}
X
X	fgets(line, BUFSIZ, tbs);fgets(line, BUFSIZ, tbs);
X	fgets(line, BUFSIZ, tbs);fgets(line, BUFSIZ, tbs);
X	fgets(line, BUFSIZ, tbs);fgets(line, BUFSIZ, tbs);
X
X	fscanf(tbs, "%d %d %d %d %d %d %d %d", &dum, &dum, &dum,
X	       &dum, &dum, &dum, &dum, &commit);
X	pclose(tbs);
X	time(&now);
X	*loadavg = (commit - bef) / (float)(now - beft); 
X	if ( *loadavg < 0.0 || bef == 0) {
X	   *loadavg = 0;
X	}
X	bef = commit;
X	beft = now;
X	return;
X}
X
Xxtbloadinit()
X{
X  if ( getenv("TBCONFIG") == NULL ) {
X    strcpy(tbconfig, "tbconfig");
X  } else {
X    strcpy(tbconfig, getenv("TBCONFIG"));
X  }
X
X  if ( getenv("INFORMIXDIR") == NULL ) {
X    strcpy(tbstat, "/usr/informix/");
X  } else {
X    strcpy(tbstat, getenv("INFORMIXDIR"));
X  }
X  strcat(tbstat, "/bin/tbstat -p");
X  
X  laststatus = ONLUNKN;
X}
SHAR_EOF
chmod 0662 xtbload.c || echo "restore of xtbload.c fails"
exit 0