v03i070: xgraph -- graph points and functions, Part01/06
Dan Heller
argv at island.uu.net
Tue Apr 11 10:42:08 AEST 1989
Submitted-by: David Harrison <davidh at ic.berkeley.edu>
Posting-number: Volume 3, Issue 70
Archive-name: xgraph/part01
[ I compiled this on a sun3/60 running 3.5 and a sun4/280 running 4.0 with
no problems. I ran in on my 3/60 and the program came up on my color
frame buffer regardless of which screen I attempted to display it. The
program looks for the color visual, so I don't know what it'll do if it
can't find it or has to display on monochrome. There is *no* Imakefile
so flames>/dev/null please.. The following 6 shar files create their own
directories including the top-level xgraph-11 directory. The program's
output is rather impressive -- it uses only libX11.a (no widgets as it
is based on an X10 version of the same program). --argv ]
#!/bin/sh
# to extract, remove the header and type "sh filename"
if `test ! -d ./xgraph-11`
then
mkdir ./xgraph-11
echo "mkdir ./xgraph-11"
fi
if `test ! -d ./xgraph-11/ux11`
then
mkdir ./xgraph-11/ux11
echo "mkdir ./xgraph-11/ux11"
fi
if `test ! -s ./xgraph-11/ux11/ux11_open.c`
then
echo "writing ./xgraph-11/ux11/ux11_open.c"
cat > ./xgraph-11/ux11/ux11_open.c << '\End\Of\Shar\'
/*
* X11 Utility functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
Display *ux11_open_display(argc, argv)
int argc;
char *argv[];
/* Looks for -display option */
{
Display *disp;
char *disp_name;
disp = XOpenDisplay(disp_name = ux11_get_value(argc, argv, "-display", ""));
if (!disp) {
fprintf(stderr, "%s: cannot open display `%s'\n", argv[0], disp_name);
abort();
}
return disp;
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11_open.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11f_gcvals.c`
then
echo "writing ./xgraph-11/ux11/ux11f_gcvals.c"
cat > ./xgraph-11/ux11/ux11f_gcvals.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
VARARGS(ux11_fill_gcvals, unsigned long, (XGCValues *gcvals, ...))
/*
* ux11_fill_gcvals(gcvals, name, value, ... , UX11_END);
* XGCValues *gcvals;
* Sets the values of an XGCValues structure using variable
* argument lists. The returned value is the the value_mask
* indicating what field is set. The fields available
* are those described for the value mask (e.g. GCFunction, etc).
*/
{
va_list ap;
unsigned long value_mask = 0;
unsigned long field;
#ifdef __STDC__
va_start(ap, gcvals);
#else
XGCValues *gcvals;
va_start(ap);
gcvals = va_arg(ap, XGCValues *);
#endif
while ((field = va_arg(ap, unsigned long)) != UX11_END) {
if (field == GCFunction) {
gcvals->function = va_arg(ap, int);
value_mask |= GCFunction;
} else if (field == GCPlaneMask) {
gcvals->plane_mask = va_arg(ap, unsigned long);
value_mask |= GCPlaneMask;
} else if (field == GCForeground) {
gcvals->foreground = va_arg(ap, unsigned long);
value_mask |= GCForeground;
} else if (field == GCBackground) {
gcvals->background = va_arg(ap, unsigned long);
value_mask |= GCBackground;
} else if (field == GCLineWidth) {
gcvals->line_width = va_arg(ap, int);
value_mask |= GCLineWidth;
} else if (field == GCLineStyle) {
gcvals->line_style = va_arg(ap, int);
value_mask |= GCLineStyle;
} else if (field == GCCapStyle) {
gcvals->cap_style = va_arg(ap, int);
value_mask |= GCCapStyle;
} else if (field == GCJoinStyle) {
gcvals->join_style = va_arg(ap, int);
value_mask |= GCJoinStyle;
} else if (field == GCFillStyle) {
gcvals->fill_style = va_arg(ap, int);
value_mask |= GCFillStyle;
} else if (field == GCFillRule) {
gcvals->fill_rule = va_arg(ap, int);
value_mask |= GCFillRule;
} else if (field == GCTile) {
gcvals->tile = va_arg(ap, Pixmap);
value_mask |= GCTile;
} else if (field == GCStipple) {
gcvals->stipple = va_arg(ap, Pixmap);
value_mask |= GCStipple;
} else if (field == GCTileStipXOrigin) {
gcvals->ts_x_origin = va_arg(ap, int);
value_mask |= GCTileStipXOrigin;
} else if (field == GCTileStipYOrigin) {
gcvals->ts_y_origin = va_arg(ap, int);
value_mask |= GCTileStipYOrigin;
} else if (field == GCFont) {
gcvals->font = va_arg(ap, Font);
value_mask |= GCFont;
} else if (field == GCSubwindowMode) {
gcvals->subwindow_mode = va_arg(ap, int);
value_mask |= GCSubwindowMode;
} else if (field == GCGraphicsExposures) {
gcvals->graphics_exposures = va_arg(ap, Bool);
value_mask |= GCGraphicsExposures;
} else if (field == GCClipXOrigin) {
gcvals->clip_x_origin = va_arg(ap, int);
value_mask |= GCClipXOrigin;
} else if (field == GCClipYOrigin) {
gcvals->clip_y_origin = va_arg(ap, int);
value_mask |= GCClipYOrigin;
} else if (field == GCClipMask) {
gcvals->clip_mask = va_arg(ap, Pixmap);
value_mask |= GCClipMask;
} else if (field == GCDashOffset) {
gcvals->dash_offset = va_arg(ap, int);
value_mask |= GCDashOffset;
} else if (field == GCDashList) {
gcvals->dashes = va_arg(ap, char);
value_mask |= GCDashList;
} else if (field == GCArcMode) {
gcvals->arc_mode = va_arg(ap, int);
value_mask |= GCArcMode;
} else {
/* Error */
fprintf(stderr, "unknown field to ux11_fill_gcvals: %x\n", field);
abort();
}
}
va_end(ap);
return value_mask;
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11f_gcvals.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11f_hints.c`
then
echo "writing ./xgraph-11/ux11/ux11f_hints.c"
cat > ./xgraph-11/ux11/ux11f_hints.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
VARARGS(ux11_fill_hints, unsigned long, (XWMHints *hints, ...))
/*
* ux11_fill_gcvals(hints, name, value, ... , UX11_END);
* XWMHints *hints;
* Sets the values of an XWMHints structure using variable
* argument lists. The returned value is the the value_mask
* indicating what field is set. The fields available
* are those described for the value mask (e.g. InputHint, etc).
*/
{
va_list ap;
unsigned long value_mask = 0;
unsigned long field;
XPoint *pnt;
#ifdef __STDC__
va_start(ap, hints);
#else
XWMHints *hints;
va_start(ap);
hints = va_arg(ap, XWMHints *);
#endif
while ((field = va_arg(ap, unsigned long)) != UX11_END) {
if (field == InputHint) {
hints->input = va_arg(ap, int);
value_mask |= InputHint;
} else if (field == StateHint) {
hints->initial_state = va_arg(ap, int);
value_mask |= StateHint;
} else if (field == IconPixmapHint) {
hints->icon_pixmap = va_arg(ap, Pixmap);
value_mask |= IconPixmapHint;
} else if (field == IconWindowHint) {
hints->icon_window = va_arg(ap, Window);
value_mask |= IconWindowHint;
} else if (field == IconPositionHint) {
pnt = va_arg(ap, XPoint *);
hints->icon_x = pnt->x;
hints->icon_y = pnt->y;
value_mask |= IconPositionHint;
} else if (field == IconMaskHint) {
hints->icon_mask = va_arg(ap, Pixmap);
value_mask |= IconMaskHint;
} else if (field == WindowGroupHint) {
hints->window_group = va_arg(ap, XID);
value_mask |= WindowGroupHint;
} else {
/* Default action */
fprintf(stderr, "unknown field to ux11_fill_hints: %x\n", field);
abort();
}
}
va_end(ap);
return value_mask;
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11f_hints.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11f_image.c`
then
echo "writing ./xgraph-11/ux11/ux11f_image.c"
cat > ./xgraph-11/ux11/ux11f_image.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
VARARGS(ux11_fill_image, void, (XImage *image, ...))
/*
* ux11_fill_image(image, name, value, ..., UX11_END)
* May be implemented at a later date.
*/
{
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11f_image.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11f_size.c`
then
echo "writing ./xgraph-11/ux11/ux11f_size.c"
cat > ./xgraph-11/ux11/ux11f_size.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
VARARGS(ux11_fill_size, unsigned long, (XSizeHints *hints, ...))
/*
* ux11_fill_size(hints, name, value, ... , UX11_END);
* XSizeHints *hints;
* Sets the values of an XSizeHints structure using variable
* argument lists. The returned value is the the value_mask
* indicating what field is set. The fields available
* are those described for the value mask (e.g. USPosition, etc).
* Needs to be reworked substantially.
*/
{
va_list ap;
unsigned long value_mask = 0;
unsigned long field;
XPoint *pnt;
#ifdef __STDC__
va_start(ap, hints);
#else
XWMHints *hints;
va_start(ap);
gcvals = va_arg(ap, XWMHints *);
#endif
while ((field = va_arg(ap, unsigned long)) != UX11_END) {
if (field == USPosition) {
pnt = va_arg(ap, XPoint *);
hints->x = pnt->x;
hints->y = pnt->y;
value_mask |= USPosition;
} else if (field == USSize) {
pnt = va_arg(ap, XPoint *);
hints->width = pnt->x;
hints->height = pnt->y;
value_mask |= USSize;
} else if (field == PPosition) {
pnt = va_arg(ap, XPoint *);
hints->x = pnt->x;
hints->y = pnt->y;
value_mask |= PPosition;
} else if (field == PSize) {
pnt = va_arg(ap, XPoint *);
hints->width = pnt->x;
hints->height = pnt->y;
value_mask |= PSize;
} else if (field == PMinSize) {
pnt = va_arg(ap, XPoint *);
hints->min_width = pnt->x;
hints->min_height = pnt->y;
value_mask |= PMinSize;
} else if (field == PMaxSize) {
pnt = va_arg(ap, XPoint *);
hints->max_width = pnt->x;
hints->max_height = pnt->y;
value_mask |= PMaxSize;
} else if (field == PResizeInc) {
pnt = va_arg(ap, XPoint *);
hints->width_inc = pnt->x;
hints->height_inc = pnt->y;
value_mask |= PResizeInc;
} else if (field == PAspect) {
value_mask |= PAspect;
} else {
/* Default action */
}
if (field == InputHint) {
hints->input = va_arg(ap, int);
value_mask |= InputHint;
} else if (field == StateHint) {
hints->initial_state = va_arg(ap, int);
value_mask |= StateHint;
} else if (field == IconPixmapHint) {
hints->icon_pixmap = va_arg(ap, Pixmap);
value_mask |= IconPixmapHint;
} else if (field == IconWindowHint) {
hints->icon_window = va_arg(ap, Window);
value_mask |= IconWindowHint;
} else if (field == IconPositionHint) {
pnt = va_arg(ap, XPoint *);
hints->icon_x = pnt->x;
hints->icon_y = pnt->y;
value_mask |= IconPositionHint;
} else if (field == IconMaskHint) {
hints->icon_mask = va_arg(ap, Pixmap);
value_mask |= IconMaskHint;
} else if (field == WindowGroupHint) {
hints->window_group = va_arg(ap, XId);
value_mask |= WindowGroupHint;
} else {
/* Default action */
fprintf(stderr, "unknown field to ux11_fill_hints: %x\n", field);
abort();
}
}
va_end(ap);
return value_mask;
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11f_size.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11f_watter.c`
then
echo "writing ./xgraph-11/ux11/ux11f_watter.c"
cat > ./xgraph-11/ux11/ux11f_watter.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
VARARGS(ux11_fill_wattr, unsigned long, (XSetWindowAttributes *wattr, ... ))
/*
* ux11_fill_wattr(wattr, name, value, ... , UX11_END);
* XSetWindowAttributes *wattr;
* Sets items in a fresh window attribute structure using
* variable argument lists. The settable fields are given
* by the value mask (e.g. CWBackPixmap, etc). The return
* value is the valuemask of those fields set in the structure.
*/
{
va_list ap;
unsigned long value_mask = 0;
unsigned long field;
#ifdef __STDC__
va_start(ap, wattr);
#else
XSetWindowAttributes *wattr;
va_start(ap);
wattr = va_arg(ap, XSetWindowAttributes *);
#endif
while ((field = va_arg(ap, unsigned long)) != UX11_END) {
if (field == CWBackPixmap) {
wattr->background_pixmap = va_arg(ap, Pixmap);
value_mask |= CWBackPixmap;
} else if (field == CWBackPixel) {
wattr->background_pixel = va_arg(ap, unsigned long);
value_mask |= CWBackPixel;
} else if (field == CWBorderPixmap) {
wattr->border_pixel = va_arg(ap, Pixmap);
value_mask |= CWBorderPixmap;
} else if (field == CWBorderPixel) {
wattr->border_pixel = va_arg(ap, unsigned long);
value_mask |= CWBorderPixel;
} else if (field == CWBitGravity) {
wattr->bit_gravity = va_arg(ap, int);
value_mask |= CWBitGravity;
} else if (field == CWWinGravity) {
wattr->win_gravity = va_arg(ap, int);
value_mask |= CWWinGravity;
} else if (field == CWBackingStore) {
wattr->backing_store = va_arg(ap, int);
value_mask |= CWBackingStore;
} else if (field == CWBackingPlanes) {
wattr->backing_planes = va_arg(ap, unsigned long);
value_mask |= CWBackingPlanes;
} else if (field == CWBackingPixel) {
wattr->backing_pixel = va_arg(ap, unsigned long);
value_mask |= CWBackingPixel;
} else if (field == CWOverrideRedirect) {
wattr->override_redirect = va_arg(ap, Bool);
value_mask |= CWOverrideRedirect;
} else if (field == CWSaveUnder) {
wattr->save_under = va_arg(ap, Bool);
value_mask |= CWSaveUnder;
} else if (field == CWEventMask) {
wattr->event_mask = va_arg(ap, long);
value_mask |= CWEventMask;
} else if (field == CWDontPropagate) {
wattr->do_not_propagate_mask = va_arg(ap, long);
value_mask |= CWDontPropagate;
} else if (field == CWColormap) {
wattr->colormap = va_arg(ap, Colormap);
value_mask |= CWColormap;
} else if (field == CWCursor) {
wattr->cursor = va_arg(ap, Cursor);
value_mask |= CWCursor;
} else {
/* Error - not real graceful here */
fprintf(stderr, "unknown field to ux11_fill_wattr: %x\n", field);
abort();
}
}
va_end(ap);
return value_mask;
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11f_watter.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11f_xa.c`
then
echo "writing ./xgraph-11/ux11/ux11f_xa.c"
cat > ./xgraph-11/ux11/ux11f_xa.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
VARARGS(ux11_fill_xa, int, (Arg *arg_list, int size, ...))
/*
* int ux11_fill_xa(arg_list, size, name, value, ... , UX11_END)
* Arg *arg_list;
* int size;
* String name;
* XtArgVal value;
* Sets the components of a X toolkit argument list. The argument list
* is passed in as `arg_list'. Its size should be passed in as `size'.
* The routine returns the number of arguments set if successful, zero
* if not successful (e.g. not enough slots).
*/
{
va_list ap;
String field;
int len;
#ifdef __STDC__
va_start(ap, size);
#else
Arg *arg_list;
int size;
va_start(ap);
arg_list = va_arg(ap, Arg *);
size = va_arg(ap, int);
#endif
len = 0;
while ((field = va_arg(ap, String)) != (String) UX11_END) {
if (len >= size) {
/* Not enough slots */
}
arg_list[len].name = field;
arg_list[len].value = va_arg(ap, XtArgVal);
len++;
}
return len;
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11f_xa.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11g_value.c`
then
echo "writing ./xgraph-11/ux11/ux11g_value.c"
cat > ./xgraph-11/ux11/ux11g_value.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
char *ux11_get_value(argc, argv, value, def)
int argc;
char *argv[];
char *value;
char *def;
/*
* Reads through all arguments looking for `value' (which is
* usually a name preceeded by a - sign) and returns the
* value found. If no value is found, def is returned.
*/
{
int idx;
char *ret_value = def;
for (idx = 1; idx < argc-1; idx++) {
if (strcmp(argv[idx], value) == 0) {
ret_value = argv[idx+1];
break;
}
}
return ret_value;
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11g_value.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11n_font.c`
then
echo "writing ./xgraph-11/ux11/ux11n_font.c"
cat > ./xgraph-11/ux11/ux11n_font.c << '\End\Of\Shar\'
/*
* UX11 Utiltity Functions
*/
#include <stdio.h>
#include <strings.h>
#include "ux11.h"
#include "ux11_internal.h"
#include <X11/Xatom.h>
#define MAX_FONTS 100
int ux11_find_font(disp, scrn_num, pat, good_func, data_p, rtn_font, rtn_name)
Display *disp; /* What display to examine */
int scrn_num; /* Screen number */
char *pat; /* Font pattern */
long (*good_func)(); /* Desirablity function */
VOID_P data_p; /* Data to function */
XFontStruct **rtn_font; /* Returned font */
char **rtn_name; /* Font name (returned) */
/*
* Locates an appropriate font. Uses `good_func' to evaluate
* the list of fonts from the server. `good_func' has the
* following form:
* long good_func(disp, scrn_num, font, data)
* Display *disp;
* int scrn_num;
* XFontStruct *font;
* VOID_P data;
* This should return the desirability of the font (larger values
* mean better visuals). The `data' parameter is passed to
* the function unchanged. Returns a non-zero status if successful.
*/
{
int font_count, i;
long max_eval, eval;
char **font_list;
XFontStruct *font_data, *chosen_data;
font_list = XListFonts(disp, pat, MAX_FONTS, &font_count);
if (font_count <= 0) return 0;
font_data = XLoadQueryFont(disp, font_list[0]);
max_eval = (*good_func)(disp, scrn_num, font_data, data_p);
*rtn_name = font_list[0];
*rtn_font = font_data;
for (i = 1; i < font_count; i++) {
font_data = XLoadQueryFont(disp, font_list[i]);
if (font_data) {
if ((eval = (*good_func)(disp, scrn_num, font_data, data_p)) > max_eval) {
max_eval = eval;
*rtn_name = font_list[i];
XFreeFont(disp, *rtn_font);
*rtn_font = font_data;
} else {
XFreeFont(disp, font_data);
}
}
}
*rtn_name = strcpy(malloc((unsigned) (strlen(*rtn_name)+1)), *rtn_name);
XFreeFontNames(font_list);
return 1;
}
typedef struct font_size_defn {
long micrometers; /* Size in micrometers (10e-6 meters) */
} font_size;
#define MAX_VALUE 23400L
#define ABS(val) ((val) < 0 ? (-(val)) : (val))
static long ux11_size_eval(disp, scrn_num, font, data)
Display *disp; /* Display */
int scrn_num; /* Screen number */
XFontStruct *font; /* Font to examine */
VOID_P data; /* Data to function */
/*
* This routine examines the font `font' and returns an evaluation
* of it based on size. The size is passed in as `data'. If it
* is close between fonts, whether one is proportionally spaced
* counts for a few more points.
*/
{
font_size *desired_size = (font_size *) data;
double um_per_pixel;
long height;
um_per_pixel = ((double) (DisplayHeightMM(disp, scrn_num) * 1000)) /
((double) DisplayHeight(disp, scrn_num));
height = (int) ((((double)
(font->max_bounds.ascent + font->max_bounds.descent))
* um_per_pixel) + 0.5);
return (MAX_VALUE - ABS(height - desired_size->micrometers)) +
(font->per_char ? 300 : 0);
}
int ux11_size_font(disp, scrn_num, size, rtn_font, rtn_name)
Display *disp; /* What display to examine */
int scrn_num; /* Screen number */
long size; /* Font size (micrometers) */
XFontStruct **rtn_font; /* Returned font */
char **rtn_name; /* Returned name */
/*
* Finds the closest font supported on the indicated screen of
* the supplied display whose size is `size' measured in micrometers.
* The font is returned in `rtn_font' and its name is returned
* in `rtn_name'. The routine returns a non-zero status if
* successful. Only normal roman style fonts are examined.
*/
{
font_size data;
data.micrometers = size;
return ux11_find_font(disp, scrn_num,
"*-medium-r-normal-*", ux11_size_eval, (VOID_P) &data,
rtn_font, rtn_name);
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11n_font.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11n_visual.c`
then
echo "writing ./xgraph-11/ux11/ux11n_visual.c"
cat > ./xgraph-11/ux11/ux11n_visual.c << '\End\Of\Shar\'
/*
* UX11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
static XVisualInfo *get_all_visuals();
int ux11_find_visual(disp, good_func, rtn_vis)
Display *disp; /* What display to examine */
int (*good_func)(); /* Desirability function */
XVisualInfo *rtn_vis; /* VisualInfo to fill in */
/*
* Locates an appropriate color visual. Uses `good_func' to evaluate
* all visuals. The function has the following form:
* int good_func(vis)
* XVisualInfo *vis;
* Should return the desirability of the visual (larger values
* mean better visuals). Returns a non-zero status if successful.
*/
{
XVisualInfo *vlist;
int num_vis, idx, max_cost, cost;
XVisualInfo *chosen;
vlist = get_all_visuals(disp, &num_vis);
if (!vlist) return 0;
max_cost = (*good_func)(&(vlist[0]));
chosen = vlist;
for (idx = 1; idx < num_vis; idx++) {
if ((cost = (*good_func)(&(vlist[idx]))) > max_cost) {
max_cost = cost;
chosen = &(vlist[idx]);
}
}
*rtn_vis = *chosen;
XFree(vlist);
return 1;
}
static XVisualInfo *get_all_visuals(disp, num)
Display *disp;
int *num;
/*
* Gets the visual list for for the specified display. Number
* of items returned in `num'.
*/
{
return XGetVisualInfo(disp, VisualNoMask, (XVisualInfo *) 0, num);
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11n_visual.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11s_vismap.c`
then
echo "writing ./xgraph-11/ux11/ux11s_vismap.c"
cat > ./xgraph-11/ux11/ux11s_vismap.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
#define UX11_MIN_DEPTH 4
int ux11_std_vismap(disp, rtn_vis, rtn_cmap, rtn_scrn, rtn_depth)
Display *disp; /* Display to examine */
Visual **rtn_vis; /* Returned visual */
Colormap *rtn_cmap; /* Returned colormap */
int *rtn_scrn; /* Returned screen */
int *rtn_depth; /* Returned depth */
/*
* This routine tries to find a visual/colormap pair that
* supports color for `disp'. The following steps are
* used to determine this pair:
* 1. The default depth of the default screen is examined.
* If it is more than four, the default visual and
* colormap for the display is returned.
* 2. ux11_find_visual is used to see if there is a good
* alternate visual available (better than the default).
* If so, a new colormap is made for the visual
* and it is returned. If no good alternative is
* found, the routine returns the default visual/colormap.
* The routine returns zero if unsuccessful. It returns UX11_DEFAULT
* if the default is returned, and UX11_ALTERNATE if a non-defualt
* visual/colormap is returned.
*/
{
int def_depth;
XVisualInfo info;
def_depth = DefaultDepth(disp, DefaultScreen(disp));
if (def_depth > UX11_MIN_DEPTH) {
/* Plenty and sufficient default resources */
*rtn_vis = DefaultVisual(disp, DefaultScreen(disp));
*rtn_cmap = DefaultColormap(disp, DefaultScreen(disp));
*rtn_scrn = DefaultScreen(disp);
*rtn_depth = DefaultDepth(disp, DefaultScreen(disp));
return UX11_DEFAULT;
} else {
/* Try to find another suitable visual */
if (ux11_find_visual(disp, ux11_color_vis, &info)) {
/* Is it bettern -- this could be a better test */
if (info.depth > UX11_MIN_DEPTH) {
*rtn_vis = info.visual;
*rtn_scrn = info.screen;
*rtn_depth = info.depth;
/* New colormap required */
*rtn_cmap = XCreateColormap(disp,
RootWindow(disp, info.screen),
info.visual, AllocNone);
if (*rtn_cmap) {
return UX11_ALTERNATE;
} else {
return 0;
}
} else {
/* Back to the default */
*rtn_vis = DefaultVisual(disp, DefaultScreen(disp));
*rtn_cmap = DefaultColormap(disp, DefaultScreen(disp));
*rtn_scrn = DefaultScreen(disp);
*rtn_depth = DefaultDepth(disp, DefaultScreen(disp));
return UX11_DEFAULT;
}
} else {
return 0;
}
}
}
int ux11_color_vis(vis)
XVisualInfo *vis; /* Visual to examine */
/*
* Returns a desirability index for the passed visual.
* This functions preference list is:
* PsuedoColor
* DirectColor
* StaticColor
* TrueColor
* GrayScale
* StaticGray
*/
{
switch (vis->class) {
case PseudoColor:
return vis->colormap_size * 100;
break;
case DirectColor:
return vis->depth * 1000;
break;
case StaticColor:
return vis->colormap_size * 50;
break;
case TrueColor:
return vis->depth * 500;
break;
case GrayScale:
return vis->colormap_size * 25;
break;
case StaticGray:
return vis->depth * 250;
break;
default:
fprintf(stderr, "Unknown visual type: %d\n", vis->class);
abort();
}
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11s_vismap.c"
fi
if `test ! -s ./xgraph-11/ux11/ux11w_props.c`
then
echo "writing ./xgraph-11/ux11/ux11w_props.c"
cat > ./xgraph-11/ux11/ux11w_props.c << '\End\Of\Shar\'
/*
* X11 Utility Functions
*/
#include <stdio.h>
#include "ux11.h"
#include "ux11_internal.h"
VARARGS(ux11_win_props, void, (Window win, ...))
/*
* ux11_win_propts(win, name, value, ... , UX11_END)
* Window win;
* Sets or replaces standard window property values for
* the window `win'. The property names are defined
* in ux11.h. May be implemented later.
*/
{
}
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/ux11/ux11w_props.c"
fi
if `test ! -d ./xgraph-11/xtb`
then
mkdir ./xgraph-11/xtb
echo "mkdir ./xgraph-11/xtb"
fi
if `test ! -s ./xgraph-11/xtb/Makefile`
then
echo "writing ./xgraph-11/xtb/Makefile"
cat > ./xgraph-11/xtb/Makefile << '\End\Of\Shar\'
#
# Makefile for xtb Toolkit library
#
CLEVEL = -g
CFLAGS = $(CLEVEL)
CC = cc
TARGET = libxtb.a
SOURCES = xtb.c
OBJECTS = xtb.o
TAGFILE = TAGS
#---------
.c.o:
$(CC) $(CFLAGS) -c $*.c
ar r $(TARGET) $*.o
$(TARGET): $(OBJECTS)
ranlib $(TARGET)
$(TAGFILE): $(SOURCES)
ctags -eut $(SOURCES)
clean:
rm -rf $(TARGET) $(OBJECTS)
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/xtb/Makefile"
fi
if `test ! -s ./xgraph-11/xtb/xtb.h`
then
echo "writing ./xgraph-11/xtb/xtb.h"
cat > ./xgraph-11/xtb/xtb.h << '\End\Of\Shar\'
/*
* xtb - a mini-toolbox for X11
*
* David Harrison
* University of California, Berkeley
* 1988
*/
#ifndef _XTB_
#define _XTB_
#include "../copyright.h"
/* Handler function return codes */
typedef enum xtb_hret_defn { XTB_NOTDEF, XTB_HANDLED, XTB_STOP } xtb_hret;
/* If you have an ANSI compiler, some checking will be done */
#ifdef __STDC__
#define DECLARE(func, rtn, args) extern rtn func args
typedef void *xtb_data;
#else
#define DECLARE(func, rtn, args) extern rtn func ()
typedef char *xtb_data;
#endif
/* Basic return value */
typedef struct xtb_frame_defn {
Window win;
int x_loc, y_loc;
unsigned int width, height;
} xtb_frame;
DECLARE(xtb_init, void, (Display *disp, int scrn,
unsigned long foreground,
unsigned long background,
XFontStruct *font));
/* Initializes mini-toolbox */
/*
* Basic event handling
*/
DECLARE(xtb_register, void, (Window win,
xtb_hret (*func)(XEvent *evt, xtb_data info),
xtb_data info));
/* Registers call-back function */
DECLARE(xtb_lookup, xtb_data, (Window win));
/* Returns data associated with window */
DECLARE(xtb_dispatch, xtb_hret, (XEvent *evt));
/* Dispatches events for mini-toolbox */
DECLARE(xtb_unregister, int, (Window win, xtb_data *info));
/* Unregisters a call-back function */
/*
* Command button frame
*/
DECLARE(xtb_bt_new, void, (Window win, char *text,
xtb_hret (*func)(Window win, int state,
xtb_data val),
xtb_data val,
xtb_frame *frame));
/* Creates new button */
DECLARE(xtb_bt_get, int, (Window win, xtb_data *stuff));
/* Returns state of button */
DECLARE(xtb_bt_set, int, (Window win, int val, xtb_data stuff));
/* Sets state of button */
DECLARE(xtb_bt_del, void, (Window win, xtb_data *info));
/* Deletes a button */
/*
* Button row frame - built on top of buttons
*/
DECLARE(xtb_br_new, void, (Window win, int cnt, char *lbls[], int init,
xtb_hret (*func)(Window win, int prev,
int this, xtb_data val),
xtb_data val,
xtb_frame *frame));
/* Creates a new button row frame */
DECLARE(xtb_br_get, int, (Window win));
/* Returns currently selected button */
DECLARE(xtb_br_del, void, (Window win));
/* Deletes a button row */
/*
* Text output (label) frames
*/
DECLARE(xtb_to_new, void, (Window win, char *text,
XFontStruct *ft, xtb_frame *frame));
/* Create new text output frame */
DECLARE(xtb_to_del, void, (Window win));
/*
* Text input (editable text) frames
*/
#define MAXCHBUF 1024
DECLARE(xtb_ti_new, void, (Window win, char *text, int maxchar,
xtb_hret (*func)(Window win, int ch,
char *textcopy, xtb_data *val),
xtb_data val, xtb_frame *frame));
/* Creates a new text input frame */
DECLARE(xtb_ti_get, void, (Window win, char text[MAXCHBUF], xtb_data *val));
/* Returns state of text input frame */
DECLARE(xtb_ti_set, int, (Window win, char *text, xtb_data val));
/* Sets the state of text input frame */
DECLARE(xtb_ti_ins, int, (Window win, int ch));
/* Inserts character onto end of text input frame */
DECLARE(xtb_ti_dch, int, (Window win));
/* Deletes character from end of text input frame */
DECLARE(xtb_ti_del, void, (Window win, xtb_data *info));
/* Deletes an text input frame */
/*
* Block frame
*/
DECLARE(xtb_bk_new, void, (Window win, unsigned width, unsigned height,
xtb_frame *frame));
/* Makes a new block frame */
DECLARE(xtb_bk_del, void, (Window win));
/* Deletes a block frame */
/*
* Formatting support
*/
#define MAX_BRANCH 50
typedef enum xtb_fmt_types_defn { W_TYPE, A_TYPE } xtb_fmt_types;
typedef enum xtb_fmt_dir_defn { HORIZONTAL, VERTICAL } xtb_fmt_dir;
typedef enum xtb_just_defn {
XTB_CENTER=0, XTB_LEFT, XTB_RIGHT, XTB_TOP, XTB_BOTTOM
} xtb_just;
typedef struct xtb_fmt_widget_defn {
xtb_fmt_types type; /* W_TYPE */
xtb_frame *w;
} xtb_fmt_widget;
typedef struct xtb_fmt_align_defn {
xtb_fmt_types type; /* A_TYPE */
xtb_fmt_dir dir; /* HORIZONTAL or VERTICAL */
int padding; /* Outside padding */
int interspace; /* Internal padding */
xtb_just just; /* Justification */
int ni; /* Number of items */
union xtb_fmt_defn *items[MAX_BRANCH]; /* Branches themselves */
} xtb_fmt_align;
typedef union xtb_fmt_defn {
xtb_fmt_types type; /* W_TYPE or A_TYPE */
xtb_fmt_widget wid;
xtb_fmt_align align;
} xtb_fmt;
#define NE 0
DECLARE(xtb_w, xtb_fmt *, (xtb_frame *w));
/* Returns formatting structure for frame */
DECLARE(xtb_hort, xtb_fmt *, (xtb_just just, int padding, int interspace, ...));
/* Varargs routine for horizontal formatting */
DECLARE(xtb_vert, xtb_fmt *, (xtb_just just, int padding, int interspace, ...));
/* Varargs routine for vertical formatting */
DECLARE(xtb_fmt_do, xtb_fmt *, (xtb_fmt *def, unsigned *w, unsigned *h));
/* Carries out formatting */
DECLARE(xtb_mv_frames, void, (int nf, xtb_frame frames[]));
/* Actually moves widgets */
DECLARE(xtb_fmt_free, void, (xtb_fmt *def));
/* Frees resources claimed by xtb_w, xtb_hort, and xtb_vert */
#endif /* _XTB_ */
\End\Of\Shar\
else
echo "will not over write ./xgraph-11/xtb/xtb.h"
fi
echo "Finished archive 1 of 6"
More information about the Comp.sources.x
mailing list