indent -linux -l144 -i4 -ts4 **/*.[ch]
This commit is contained in:
parent
cb310ed1a1
commit
324a28e4ba
|
@ -9,7 +9,6 @@
|
|||
* that your changes will be lost if you ever run `configure' again.
|
||||
*/
|
||||
|
||||
|
||||
/* *************************************************************************
|
||||
CONFIGURING SERVER EXTENSIONS
|
||||
************************************************************************* */
|
||||
|
@ -110,8 +109,6 @@
|
|||
*/
|
||||
/* #undef HAVE_PROC_INTERRUPTS */
|
||||
|
||||
|
||||
|
||||
/* *************************************************************************
|
||||
CONFIGURING GRAPHICS TOOLKITS
|
||||
************************************************************************* */
|
||||
|
@ -184,8 +181,6 @@
|
|||
*/
|
||||
#define ZIPPY_PROGRAM "/packages/libexec/emacs/20.2/sparc-sun-solaris2.6/yow"
|
||||
|
||||
|
||||
|
||||
/* *************************************************************************
|
||||
CONFIGURING PASSWORD AUTHENTICATION
|
||||
************************************************************************* */
|
||||
|
@ -258,13 +253,11 @@
|
|||
*/
|
||||
/* #undef HAVE_VT_LOCKSWITCH */
|
||||
|
||||
|
||||
/* Define this if you the openlog(), syslog(), and closelog() functions.
|
||||
This is used for logging failed login attempts.
|
||||
*/
|
||||
#define HAVE_SYSLOG 1
|
||||
|
||||
|
||||
/* *************************************************************************
|
||||
OTHER C ENVIRONMENT JUNK
|
||||
************************************************************************* */
|
||||
|
|
|
@ -31,323 +31,328 @@
|
|||
#include "resources.h"
|
||||
*/
|
||||
|
||||
extern GC NormalGC;
|
||||
extern GC EraseGC;
|
||||
extern Pixel back_pix, fore_pix;
|
||||
extern int PixmapSize;
|
||||
int CHAR_HEIGHT;
|
||||
extern GC NormalGC;
|
||||
extern GC EraseGC;
|
||||
extern Pixel back_pix, fore_pix;
|
||||
extern int PixmapSize;
|
||||
int CHAR_HEIGHT;
|
||||
|
||||
static void load_images(m_state * state)
|
||||
{
|
||||
|
||||
if (state->xgwa.depth > 1) {
|
||||
|
||||
XpmAttributes xpmattrs;
|
||||
int result;
|
||||
|
||||
xpmattrs.valuemask = 0;
|
||||
xpmattrs.valuemask |= XpmCloseness;
|
||||
xpmattrs.closeness = 40000;
|
||||
xpmattrs.valuemask |= XpmVisual;
|
||||
xpmattrs.visual = state->xgwa.visual;
|
||||
xpmattrs.valuemask |= XpmDepth;
|
||||
xpmattrs.depth = state->xgwa.depth;
|
||||
xpmattrs.valuemask |= XpmColormap;
|
||||
xpmattrs.colormap = state->xgwa.colormap;
|
||||
|
||||
static void load_images (m_state *state) {
|
||||
if (PixmapSize == 1) {
|
||||
|
||||
if (state->xgwa.depth > 1) {
|
||||
CHAR_HEIGHT = 4;
|
||||
result = XpmCreatePixmapFromData(state->dpy, state->window, small, &state->images, 0 /* mask */ ,
|
||||
&xpmattrs);
|
||||
} else if (PixmapSize == 2) {
|
||||
|
||||
XpmAttributes xpmattrs;
|
||||
int result;
|
||||
CHAR_HEIGHT = 6;
|
||||
result = XpmCreatePixmapFromData(state->dpy, state->window, medium, &state->images, 0 /* mask */ ,
|
||||
&xpmattrs);
|
||||
} else {
|
||||
|
||||
xpmattrs.valuemask = 0;
|
||||
xpmattrs.valuemask |= XpmCloseness;
|
||||
xpmattrs.closeness = 40000;
|
||||
xpmattrs.valuemask |= XpmVisual;
|
||||
xpmattrs.visual = state->xgwa.visual;
|
||||
xpmattrs.valuemask |= XpmDepth;
|
||||
xpmattrs.depth = state->xgwa.depth;
|
||||
xpmattrs.valuemask |= XpmColormap;
|
||||
xpmattrs.colormap = state->xgwa.colormap;
|
||||
CHAR_HEIGHT = 8;
|
||||
result = XpmCreatePixmapFromData(state->dpy, state->window, large, &state->images, 0 /* mask */ ,
|
||||
&xpmattrs);
|
||||
}
|
||||
|
||||
if (PixmapSize == 1){
|
||||
if (!state->images || (result != XpmSuccess && result != XpmColorError))
|
||||
state->images = 0;
|
||||
|
||||
CHAR_HEIGHT = 4;
|
||||
result = XpmCreatePixmapFromData (state->dpy, state->window, small,
|
||||
&state->images, 0 /* mask */,
|
||||
&xpmattrs);
|
||||
} else if (PixmapSize == 2){
|
||||
state->image_width = xpmattrs.width;
|
||||
state->image_height = xpmattrs.height;
|
||||
state->nglyphs = state->image_height / CHAR_HEIGHT;
|
||||
|
||||
CHAR_HEIGHT = 6;
|
||||
result = XpmCreatePixmapFromData (state->dpy, state->window, medium,
|
||||
&state->images, 0 /* mask */,
|
||||
&xpmattrs);
|
||||
} else {
|
||||
} else {
|
||||
|
||||
CHAR_HEIGHT = 8;
|
||||
result = XpmCreatePixmapFromData (state->dpy, state->window, large,
|
||||
&state->images, 0 /* mask */,
|
||||
&xpmattrs);
|
||||
}
|
||||
state->image_width = matrix_width;
|
||||
state->image_height = matrix_height;
|
||||
state->nglyphs = state->image_height / CHAR_HEIGHT;
|
||||
|
||||
if (!state->images || (result != XpmSuccess && result != XpmColorError))
|
||||
state->images = 0;
|
||||
|
||||
state->image_width = xpmattrs.width;
|
||||
state->image_height = xpmattrs.height;
|
||||
state->nglyphs = state->image_height / CHAR_HEIGHT;
|
||||
|
||||
} else {
|
||||
|
||||
state->image_width = matrix_width;
|
||||
state->image_height = matrix_height;
|
||||
state->nglyphs = state->image_height / CHAR_HEIGHT;
|
||||
|
||||
state->images = XCreatePixmapFromBitmapData (state->dpy, state->window,
|
||||
(char *) matrix_bits,
|
||||
state->image_width, state->image_height,
|
||||
back_pix, fore_pix, state->xgwa.depth);
|
||||
}
|
||||
state->images = XCreatePixmapFromBitmapData(state->dpy, state->window,
|
||||
(char *)matrix_bits,
|
||||
state->image_width, state->image_height, back_pix, fore_pix, state->xgwa.depth);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_state *init_matrix(Display * dpy, Window window)
|
||||
{
|
||||
|
||||
m_state *init_matrix( Display *dpy, Window window ) {
|
||||
m_state *state = (m_state *) calloc(sizeof(*state), 1);
|
||||
|
||||
m_state *state = (m_state *) calloc (sizeof(*state), 1);
|
||||
state->dpy = dpy;
|
||||
state->window = window;
|
||||
|
||||
XGetWindowAttributes(dpy, window, &state->xgwa);
|
||||
load_images(state);
|
||||
|
||||
state->dpy = dpy;
|
||||
state->window = window;
|
||||
state->draw_gc = NormalGC;
|
||||
state->erase_gc = EraseGC;
|
||||
|
||||
XGetWindowAttributes (dpy, window, &state->xgwa);
|
||||
load_images (state);
|
||||
state->char_width = state->image_width / 2;
|
||||
state->char_height = CHAR_HEIGHT;
|
||||
|
||||
state->draw_gc = NormalGC;
|
||||
state->erase_gc = EraseGC;
|
||||
state->grid_width = state->xgwa.width / state->char_width;
|
||||
state->grid_height = state->xgwa.height / state->char_height;
|
||||
state->grid_width++;
|
||||
state->grid_height++;
|
||||
|
||||
state->char_width = state->image_width / 2;
|
||||
state->char_height = CHAR_HEIGHT;
|
||||
state->cells = (m_cell *) calloc(sizeof(m_cell), state->grid_width * state->grid_height);
|
||||
state->feeders = (m_feeder *) calloc(sizeof(m_feeder), state->grid_width);
|
||||
|
||||
state->grid_width = state->xgwa.width / state->char_width;
|
||||
state->grid_height = state->xgwa.height / state->char_height;
|
||||
state->grid_width++;
|
||||
state->grid_height++;
|
||||
state->density = 40;
|
||||
|
||||
state->cells = (m_cell *)calloc (sizeof(m_cell), state->grid_width * state->grid_height);
|
||||
state->feeders = (m_feeder *)calloc (sizeof(m_feeder), state->grid_width);
|
||||
state->insert_top_p = False;
|
||||
state->insert_bottom_p = True;
|
||||
|
||||
state->density = 40;
|
||||
|
||||
state->insert_top_p = False;
|
||||
state->insert_bottom_p = True;
|
||||
|
||||
|
||||
return state;
|
||||
return state;
|
||||
|
||||
}
|
||||
|
||||
static void insert_glyph(m_state * state, int glyph, int x, int y)
|
||||
{
|
||||
|
||||
static void insert_glyph (m_state *state, int glyph, int x, int y) {
|
||||
Bool bottom_feeder_p = (y >= 0);
|
||||
m_cell *from, *to;
|
||||
|
||||
Bool bottom_feeder_p = (y >= 0);
|
||||
m_cell *from, *to;
|
||||
if (y >= state->grid_height)
|
||||
return;
|
||||
|
||||
if (y >= state->grid_height) return;
|
||||
if (bottom_feeder_p) {
|
||||
|
||||
if (bottom_feeder_p) {
|
||||
to = &state->cells[state->grid_width * y + x];
|
||||
|
||||
to = &state->cells[state->grid_width * y + x];
|
||||
} else {
|
||||
|
||||
} else {
|
||||
for (y = state->grid_height - 1; y > 0; y--) {
|
||||
|
||||
for (y = state->grid_height-1; y > 0; y--) {
|
||||
from = &state->cells[state->grid_width * (y - 1) + x];
|
||||
to = &state->cells[state->grid_width * y + x];
|
||||
*to = *from;
|
||||
to->changed = True;
|
||||
|
||||
from = &state->cells[state->grid_width * (y-1) + x];
|
||||
to = &state->cells[state->grid_width * y + x];
|
||||
*to = *from;
|
||||
to->changed = True;
|
||||
|
||||
}
|
||||
to = &state->cells[x];
|
||||
|
||||
}
|
||||
|
||||
to->glyph = glyph;
|
||||
to->changed = True;
|
||||
|
||||
if (!to->glyph) ;
|
||||
else if (bottom_feeder_p) to->glow = 1 + (random() % 2);
|
||||
else to->glow = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void feed_matrix (m_state *state) {
|
||||
|
||||
int x;
|
||||
|
||||
|
||||
/*
|
||||
* Update according to current feeders.
|
||||
*/
|
||||
for (x = 0; x < state->grid_width; x++) {
|
||||
|
||||
m_feeder *f = &state->feeders[x];
|
||||
|
||||
if (f->throttle) { /* this is a delay tick, synced to frame. */
|
||||
|
||||
f->throttle--;
|
||||
|
||||
} else if (f->remaining > 0) { /* how many items are in the pipe */
|
||||
|
||||
int g = (random() % state->nglyphs) + 1;
|
||||
insert_glyph (state, g, x, f->y);
|
||||
f->remaining--;
|
||||
if (f->y >= 0) f->y++; /* bottom_feeder_p */
|
||||
|
||||
} else { /* if pipe is empty, insert spaces */
|
||||
|
||||
insert_glyph (state, 0, x, f->y);
|
||||
if (f->y >= 0) f->y++; /* bottom_feeder_p */
|
||||
|
||||
}
|
||||
|
||||
if ((random() % 10) == 0) { /* randomly change throttle speed */
|
||||
|
||||
f->throttle = ((random() % 5) + (random() % 5));
|
||||
}
|
||||
to = &state->cells[x];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
to->glyph = glyph;
|
||||
to->changed = True;
|
||||
|
||||
if (!to->glyph) ;
|
||||
else if (bottom_feeder_p)
|
||||
to->glow = 1 + (random() % 2);
|
||||
else
|
||||
to->glow = 0;
|
||||
|
||||
}
|
||||
|
||||
static int densitizer (m_state *state) {
|
||||
static void feed_matrix(m_state * state)
|
||||
{
|
||||
|
||||
/* Horrid kludge that converts percentages (density of screen coverage)
|
||||
to the parameter that actually controls this. I got this mapping
|
||||
empirically, on a 1024x768 screen. Sue me. */
|
||||
if (state->density < 10) return 85;
|
||||
else if (state->density < 15) return 60;
|
||||
else if (state->density < 20) return 45;
|
||||
else if (state->density < 25) return 25;
|
||||
else if (state->density < 30) return 20;
|
||||
else if (state->density < 35) return 15;
|
||||
else if (state->density < 45) return 10;
|
||||
else if (state->density < 50) return 8;
|
||||
else if (state->density < 55) return 7;
|
||||
else if (state->density < 65) return 5;
|
||||
else if (state->density < 80) return 3;
|
||||
else if (state->density < 90) return 2;
|
||||
else return 1;
|
||||
int x;
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void hack_matrix (m_state *state) {
|
||||
|
||||
int x;
|
||||
|
||||
/* Glow some characters. */
|
||||
if (!state->insert_bottom_p) {
|
||||
|
||||
int i = random() % (state->grid_width / 2);
|
||||
while (--i > 0) {
|
||||
|
||||
int x = random() % state->grid_width;
|
||||
int y = random() % state->grid_height;
|
||||
m_cell *cell = &state->cells[state->grid_width * y + x];
|
||||
if (cell->glyph && cell->glow == 0) {
|
||||
|
||||
cell->glow = random() % 10;
|
||||
cell->changed = True;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Change some of the feeders. */
|
||||
for (x = 0; x < state->grid_width; x++) {
|
||||
|
||||
m_feeder *f = &state->feeders[x];
|
||||
Bool bottom_feeder_p;
|
||||
|
||||
if (f->remaining > 0) /* never change if pipe isn't empty */
|
||||
continue;
|
||||
|
||||
if ((random() % densitizer(state)) != 0) /* then change N% of the time */
|
||||
continue;
|
||||
|
||||
f->remaining = 3 + (random() % state->grid_height);
|
||||
f->throttle = ((random() % 5) + (random() % 5));
|
||||
|
||||
if ((random() % 4) != 0)
|
||||
f->remaining = 0;
|
||||
|
||||
if (state->insert_top_p && state->insert_bottom_p)
|
||||
bottom_feeder_p = (random() & 1);
|
||||
else
|
||||
bottom_feeder_p = state->insert_bottom_p;
|
||||
|
||||
if (bottom_feeder_p)
|
||||
f->y = random() % (state->grid_height / 2);
|
||||
else
|
||||
f->y = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw_matrix (m_state *state, int d) {
|
||||
|
||||
int x, y;
|
||||
int count = 0;
|
||||
|
||||
state->density = d;
|
||||
feed_matrix( state );
|
||||
hack_matrix( state );
|
||||
|
||||
for (y = 0; y < state->grid_height; y++) {
|
||||
/*
|
||||
* Update according to current feeders.
|
||||
*/
|
||||
for (x = 0; x < state->grid_width; x++) {
|
||||
|
||||
m_cell *cell = &state->cells[state->grid_width * y + x];
|
||||
m_feeder *f = &state->feeders[x];
|
||||
|
||||
if ( cell->glyph ) count++;
|
||||
if (f->throttle) { /* this is a delay tick, synced to frame. */
|
||||
|
||||
if ( !cell->changed ) continue;
|
||||
f->throttle--;
|
||||
|
||||
if ( cell->glyph == 0 ) {
|
||||
} else if (f->remaining > 0) { /* how many items are in the pipe */
|
||||
|
||||
XFillRectangle( state->dpy, state->window, state->erase_gc,
|
||||
x * state->char_width, y * state->char_height,
|
||||
state->char_width, state->char_height );
|
||||
} else {
|
||||
int g = (random() % state->nglyphs) + 1;
|
||||
insert_glyph(state, g, x, f->y);
|
||||
f->remaining--;
|
||||
if (f->y >= 0)
|
||||
f->y++; /* bottom_feeder_p */
|
||||
|
||||
XCopyArea( state->dpy, state->images, state->window, state->draw_gc,
|
||||
(cell->glow ? state->char_width : 0), (cell->glyph - 1) * state->char_height,
|
||||
state->char_width, state->char_height, x * state->char_width, y * state->char_height );
|
||||
|
||||
}
|
||||
} else { /* if pipe is empty, insert spaces */
|
||||
|
||||
cell->changed = False;
|
||||
insert_glyph(state, 0, x, f->y);
|
||||
if (f->y >= 0)
|
||||
f->y++; /* bottom_feeder_p */
|
||||
|
||||
if (cell->glow > 0) {
|
||||
}
|
||||
|
||||
cell->glow--;
|
||||
cell->changed = True;
|
||||
if ((random() % 10) == 0) { /* randomly change throttle speed */
|
||||
|
||||
}
|
||||
f->throttle = ((random() % 5) + (random() % 5));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int densitizer(m_state * state)
|
||||
{
|
||||
|
||||
/* Horrid kludge that converts percentages (density of screen coverage)
|
||||
to the parameter that actually controls this. I got this mapping
|
||||
empirically, on a 1024x768 screen. Sue me. */
|
||||
if (state->density < 10)
|
||||
return 85;
|
||||
else if (state->density < 15)
|
||||
return 60;
|
||||
else if (state->density < 20)
|
||||
return 45;
|
||||
else if (state->density < 25)
|
||||
return 25;
|
||||
else if (state->density < 30)
|
||||
return 20;
|
||||
else if (state->density < 35)
|
||||
return 15;
|
||||
else if (state->density < 45)
|
||||
return 10;
|
||||
else if (state->density < 50)
|
||||
return 8;
|
||||
else if (state->density < 55)
|
||||
return 7;
|
||||
else if (state->density < 65)
|
||||
return 5;
|
||||
else if (state->density < 80)
|
||||
return 3;
|
||||
else if (state->density < 90)
|
||||
return 2;
|
||||
else
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
static void hack_matrix(m_state * state)
|
||||
{
|
||||
|
||||
int x;
|
||||
|
||||
/* Glow some characters. */
|
||||
if (!state->insert_bottom_p) {
|
||||
|
||||
int i = random() % (state->grid_width / 2);
|
||||
while (--i > 0) {
|
||||
|
||||
int x = random() % state->grid_width;
|
||||
int y = random() % state->grid_height;
|
||||
m_cell *cell = &state->cells[state->grid_width * y + x];
|
||||
if (cell->glyph && cell->glow == 0) {
|
||||
|
||||
cell->glow = random() % 10;
|
||||
cell->changed = True;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Change some of the feeders. */
|
||||
for (x = 0; x < state->grid_width; x++) {
|
||||
|
||||
m_feeder *f = &state->feeders[x];
|
||||
Bool bottom_feeder_p;
|
||||
|
||||
if (f->remaining > 0) /* never change if pipe isn't empty */
|
||||
continue;
|
||||
|
||||
if ((random() % densitizer(state)) != 0) /* then change N% of the time */
|
||||
continue;
|
||||
|
||||
f->remaining = 3 + (random() % state->grid_height);
|
||||
f->throttle = ((random() % 5) + (random() % 5));
|
||||
|
||||
if ((random() % 4) != 0)
|
||||
f->remaining = 0;
|
||||
|
||||
if (state->insert_top_p && state->insert_bottom_p)
|
||||
bottom_feeder_p = (random() & 1);
|
||||
else
|
||||
bottom_feeder_p = state->insert_bottom_p;
|
||||
|
||||
if (bottom_feeder_p)
|
||||
f->y = random() % (state->grid_height / 2);
|
||||
else
|
||||
f->y = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_matrix(m_state * state, int d)
|
||||
{
|
||||
|
||||
int x, y;
|
||||
int count = 0;
|
||||
|
||||
state->density = d;
|
||||
feed_matrix(state);
|
||||
hack_matrix(state);
|
||||
|
||||
for (y = 0; y < state->grid_height; y++) {
|
||||
for (x = 0; x < state->grid_width; x++) {
|
||||
|
||||
m_cell *cell = &state->cells[state->grid_width * y + x];
|
||||
|
||||
if (cell->glyph)
|
||||
count++;
|
||||
|
||||
if (!cell->changed)
|
||||
continue;
|
||||
|
||||
if (cell->glyph == 0) {
|
||||
|
||||
XFillRectangle(state->dpy, state->window, state->erase_gc,
|
||||
x * state->char_width, y * state->char_height, state->char_width, state->char_height);
|
||||
} else {
|
||||
|
||||
XCopyArea(state->dpy, state->images, state->window, state->draw_gc,
|
||||
(cell->glow ? state->char_width : 0), (cell->glyph - 1) * state->char_height,
|
||||
state->char_width, state->char_height, x * state->char_width, y * state->char_height);
|
||||
|
||||
}
|
||||
|
||||
cell->changed = False;
|
||||
|
||||
if (cell->glow > 0) {
|
||||
|
||||
cell->glow--;
|
||||
cell->changed = True;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
static int i = 0;
|
||||
static int ndens = 0;
|
||||
static int tdens = 0;
|
||||
i++;
|
||||
if (i > 50)
|
||||
{
|
||||
int dens = (100.0 *
|
||||
(((double)count) /
|
||||
((double) (state->grid_width * state->grid_height))));
|
||||
tdens += dens;
|
||||
ndens++;
|
||||
printf ("density: %d%% (%d%%)\n", dens, (tdens / ndens));
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
{
|
||||
static int i = 0;
|
||||
static int ndens = 0;
|
||||
static int tdens = 0;
|
||||
i++;
|
||||
if (i > 50) {
|
||||
int dens = (100.0 * (((double)count) / ((double)(state->grid_width * state->grid_height))));
|
||||
tdens += dens;
|
||||
ndens++;
|
||||
printf("density: %d%% (%d%%)\n", dens, (tdens / ndens));
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,34 +6,32 @@
|
|||
#include <X11/Xutil.h>
|
||||
#include <X11/xpm.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
int glyph;
|
||||
int changed;
|
||||
int glow;
|
||||
int glyph;
|
||||
int changed;
|
||||
int glow;
|
||||
} m_cell;
|
||||
|
||||
typedef struct {
|
||||
int remaining;
|
||||
int throttle;
|
||||
int y;
|
||||
int remaining;
|
||||
int throttle;
|
||||
int y;
|
||||
} m_feeder;
|
||||
|
||||
typedef struct {
|
||||
Display *dpy;
|
||||
Window window;
|
||||
XWindowAttributes xgwa;
|
||||
GC draw_gc, erase_gc;
|
||||
int grid_width, grid_height;
|
||||
int char_width, char_height;
|
||||
m_cell *cells;
|
||||
m_feeder *feeders;
|
||||
int insert_top_p, insert_bottom_p;
|
||||
int density;
|
||||
Display *dpy;
|
||||
Window window;
|
||||
XWindowAttributes xgwa;
|
||||
GC draw_gc, erase_gc;
|
||||
int grid_width, grid_height;
|
||||
int char_width, char_height;
|
||||
m_cell *cells;
|
||||
m_feeder *feeders;
|
||||
int insert_top_p, insert_bottom_p;
|
||||
int density;
|
||||
|
||||
Pixmap images;
|
||||
int image_width, image_height;
|
||||
int nglyphs;
|
||||
Pixmap images;
|
||||
int image_width, image_height;
|
||||
int nglyphs;
|
||||
|
||||
} m_state;
|
||||
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
static const char screensaver_id[] =
|
||||
"@(#)xscreensaver 3.17 (15-Jul-99), by Jamie Zawinski (jwz@jwz.org)";
|
||||
static const char screensaver_id[] = "@(#)xscreensaver 3.17 (15-Jul-99), by Jamie Zawinski (jwz@jwz.org)";
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Includes
|
||||
*/
|
||||
|
@ -54,157 +53,155 @@
|
|||
#include "wmMatrix_mask.xbm"
|
||||
#include "matrix.h"
|
||||
|
||||
|
||||
/*
|
||||
* Delay between refreshes (in microseconds)
|
||||
*/
|
||||
#define DELAY 20000UL /* 0.020000 sec */
|
||||
#define DELAY 20000UL /* 0.020000 sec */
|
||||
#define WMMATRIX_VERSION "0.2"
|
||||
|
||||
void ParseCMDLine(int argc, char *argv[]);
|
||||
void ButtonPressEvent(XButtonEvent *);
|
||||
void print_usage();
|
||||
m_state *init_matrix(Display *, Window);
|
||||
void draw_matrix(m_state *, int);
|
||||
|
||||
void ParseCMDLine(int argc, char *argv[]);
|
||||
void ButtonPressEvent(XButtonEvent *);
|
||||
void print_usage();
|
||||
m_state *init_matrix( Display *, Window );
|
||||
void draw_matrix( m_state *, int );
|
||||
|
||||
|
||||
int GotFirstClick1, GotDoubleClick1;
|
||||
int GotFirstClick2, GotDoubleClick2;
|
||||
int GotFirstClick3, GotDoubleClick3;
|
||||
int DblClkDelay;
|
||||
int GotFirstClick1, GotDoubleClick1;
|
||||
int GotFirstClick2, GotDoubleClick2;
|
||||
int GotFirstClick3, GotDoubleClick3;
|
||||
int DblClkDelay;
|
||||
/*int HasExecute;*/
|
||||
/*char* ExecuteCommand = "xmatrixsmall";*/
|
||||
char *progname = "wmMatrix";
|
||||
char *progclass = "WMMatrix";
|
||||
int PixmapSize;
|
||||
char *progname = "wmMatrix";
|
||||
char *progclass = "WMMatrix";
|
||||
int PixmapSize;
|
||||
char *DoubleClickCmd = NULL;
|
||||
char *RDoubleClickCmd = NULL;
|
||||
char* TimeColor = "#ffff00";
|
||||
char* BackgroundColor = "#181818";
|
||||
|
||||
char *TimeColor = "#ffff00";
|
||||
char *BackgroundColor = "#181818";
|
||||
|
||||
/*
|
||||
* main
|
||||
*/
|
||||
int main(int argc, char *argv[]) {
|
||||
XEvent event;
|
||||
m_state *state;
|
||||
|
||||
|
||||
/*
|
||||
* Parse any command line arguments.
|
||||
*/
|
||||
ParseCMDLine(argc, argv);
|
||||
if(DoubleClickCmd==NULL)
|
||||
DoubleClickCmd=strdup("xscreensaver-demo");
|
||||
if(RDoubleClickCmd==NULL)
|
||||
RDoubleClickCmd=strdup("xscreensaver-command -activate");
|
||||
initXwindow(argc, argv);
|
||||
openXwindow(argc, argv, wmMatrix_master, wmMatrix_mask_bits, wmMatrix_mask_width, wmMatrix_mask_height);
|
||||
state = init_matrix( display, iconwin );
|
||||
|
||||
/*
|
||||
* Loop until we die
|
||||
*/
|
||||
while(1) {
|
||||
draw_matrix( state, 40 );
|
||||
|
||||
/*
|
||||
* Double Click Delays
|
||||
* Keep track of click events. If Delay too long, set GotFirstClick's to False.
|
||||
*/
|
||||
/* 25 * 0.02 = .5 sec */
|
||||
if (DblClkDelay > 25) {
|
||||
DblClkDelay = 0;
|
||||
GotFirstClick1 = 0; GotDoubleClick1 = 0;
|
||||
GotFirstClick2 = 0; GotDoubleClick2 = 0;
|
||||
GotFirstClick3 = 0; GotDoubleClick3 = 0;
|
||||
} else {
|
||||
++DblClkDelay;
|
||||
}
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
XEvent event;
|
||||
m_state *state;
|
||||
|
||||
/*
|
||||
* Process any pending X events.
|
||||
* Parse any command line arguments.
|
||||
*/
|
||||
while(XPending(display)){
|
||||
XNextEvent(display, &event);
|
||||
switch(event.type){
|
||||
case Expose:
|
||||
RedrawWindow();
|
||||
break;
|
||||
case ButtonPress:
|
||||
ButtonPressEvent(&event.xbutton);
|
||||
break;
|
||||
case ButtonRelease:
|
||||
break;
|
||||
}
|
||||
}
|
||||
ParseCMDLine(argc, argv);
|
||||
if (DoubleClickCmd == NULL)
|
||||
DoubleClickCmd = strdup("xscreensaver-demo");
|
||||
if (RDoubleClickCmd == NULL)
|
||||
RDoubleClickCmd = strdup("xscreensaver-command -activate");
|
||||
initXwindow(argc, argv);
|
||||
openXwindow(argc, argv, wmMatrix_master, wmMatrix_mask_bits, wmMatrix_mask_width, wmMatrix_mask_height);
|
||||
state = init_matrix(display, iconwin);
|
||||
|
||||
/*
|
||||
* sleep till next update. I cant seem to get usleep or select to work properly
|
||||
* with args smaller than 10000. A kernel tick problem? If I comment out the next line,
|
||||
* the app screams (chews up cpu too). Or if I use DELAY of 0 it also screams.
|
||||
* But a delay of 1 or higher is slow.....
|
||||
*
|
||||
* Loop until we die
|
||||
*/
|
||||
short_uusleep(DELAY);
|
||||
}
|
||||
while (1) {
|
||||
draw_matrix(state, 40);
|
||||
|
||||
/*
|
||||
* Double Click Delays
|
||||
* Keep track of click events. If Delay too long, set GotFirstClick's to False.
|
||||
*/
|
||||
/* 25 * 0.02 = .5 sec */
|
||||
if (DblClkDelay > 25) {
|
||||
DblClkDelay = 0;
|
||||
GotFirstClick1 = 0;
|
||||
GotDoubleClick1 = 0;
|
||||
GotFirstClick2 = 0;
|
||||
GotDoubleClick2 = 0;
|
||||
GotFirstClick3 = 0;
|
||||
GotDoubleClick3 = 0;
|
||||
} else {
|
||||
++DblClkDelay;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process any pending X events.
|
||||
*/
|
||||
while (XPending(display)) {
|
||||
XNextEvent(display, &event);
|
||||
switch (event.type) {
|
||||
case Expose:
|
||||
RedrawWindow();
|
||||
break;
|
||||
case ButtonPress:
|
||||
ButtonPressEvent(&event.xbutton);
|
||||
break;
|
||||
case ButtonRelease:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* sleep till next update. I cant seem to get usleep or select to work properly
|
||||
* with args smaller than 10000. A kernel tick problem? If I comment out the next line,
|
||||
* the app screams (chews up cpu too). Or if I use DELAY of 0 it also screams.
|
||||
* But a delay of 1 or higher is slow.....
|
||||
*
|
||||
*/
|
||||
short_uusleep(DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ParseCMDLine()
|
||||
*/
|
||||
void ParseCMDLine(int argc, char *argv[]) {
|
||||
int i;
|
||||
PixmapSize = 2;
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-display")){
|
||||
++i;
|
||||
} else if (!strcmp(argv[i], "-c")){
|
||||
if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
|
||||
fprintf(stderr, "wmMatrix: No command given\n");
|
||||
print_usage();
|
||||
exit(-1);
|
||||
}
|
||||
if(DoubleClickCmd!=NULL)
|
||||
free(DoubleClickCmd);
|
||||
DoubleClickCmd=strdup(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-cr")){
|
||||
if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
|
||||
fprintf(stderr, "wmMatrix: No command given\n");
|
||||
print_usage();
|
||||
exit(-1);
|
||||
}
|
||||
if(RDoubleClickCmd!=NULL)
|
||||
free(RDoubleClickCmd);
|
||||
RDoubleClickCmd=strdup(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-sml")){
|
||||
PixmapSize = 1;
|
||||
} else if (!strcmp(argv[i], "-med")){
|
||||
PixmapSize = 2;
|
||||
} else if (!strcmp(argv[i], "-lrg")){
|
||||
PixmapSize = 3;
|
||||
} else {
|
||||
print_usage();
|
||||
exit(1);
|
||||
void ParseCMDLine(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
PixmapSize = 2;
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "-display")) {
|
||||
++i;
|
||||
} else if (!strcmp(argv[i], "-c")) {
|
||||
if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) {
|
||||
fprintf(stderr, "wmMatrix: No command given\n");
|
||||
print_usage();
|
||||
exit(-1);
|
||||
}
|
||||
if (DoubleClickCmd != NULL)
|
||||
free(DoubleClickCmd);
|
||||
DoubleClickCmd = strdup(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-cr")) {
|
||||
if ((i + 1 >= argc) || (argv[i + 1][0] == '-')) {
|
||||
fprintf(stderr, "wmMatrix: No command given\n");
|
||||
print_usage();
|
||||
exit(-1);
|
||||
}
|
||||
if (RDoubleClickCmd != NULL)
|
||||
free(RDoubleClickCmd);
|
||||
RDoubleClickCmd = strdup(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-sml")) {
|
||||
PixmapSize = 1;
|
||||
} else if (!strcmp(argv[i], "-med")) {
|
||||
PixmapSize = 2;
|
||||
} else if (!strcmp(argv[i], "-lrg")) {
|
||||
PixmapSize = 3;
|
||||
} else {
|
||||
print_usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print_usage() {
|
||||
printf("\nwmMatrix version: %s\n", WMMATRIX_VERSION);
|
||||
printf("\t-h\t\tDisplay help screen.\n");
|
||||
printf("\t-c cmd\t\tCommand executed on doubleclick.\n");
|
||||
printf("\t-cr cmd\t\tCommand executed on right doubleclick\n");
|
||||
printf("\t-sml\t\tUse small size pixmap.\n");
|
||||
printf("\t-med\t\tUse medium size pixmap.\n");
|
||||
printf("\t-lrg\t\tUse large size pixmap.\n");
|
||||
void print_usage()
|
||||
{
|
||||
printf("\nwmMatrix version: %s\n", WMMATRIX_VERSION);
|
||||
printf("\t-h\t\tDisplay help screen.\n");
|
||||
printf("\t-c cmd\t\tCommand executed on doubleclick.\n");
|
||||
printf("\t-cr cmd\t\tCommand executed on right doubleclick\n");
|
||||
printf("\t-sml\t\tUse small size pixmap.\n");
|
||||
printf("\t-med\t\tUse medium size pixmap.\n");
|
||||
printf("\t-lrg\t\tUse large size pixmap.\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This routine handles button presses.
|
||||
*
|
||||
|
@ -215,46 +212,50 @@ void print_usage() {
|
|||
*
|
||||
*
|
||||
*/
|
||||
void ButtonPressEvent(XButtonEvent *xev){
|
||||
DblClkDelay = 0;
|
||||
if ((xev->button == Button1) && (xev->type == ButtonPress)){
|
||||
if (GotFirstClick1) GotDoubleClick1 = 1;
|
||||
else GotFirstClick1 = 1;
|
||||
} else if ((xev->button == Button2) && (xev->type == ButtonPress)){
|
||||
if (GotFirstClick2) GotDoubleClick2 = 1;
|
||||
else GotFirstClick2 = 1;
|
||||
} else if ((xev->button == Button3) && (xev->type == ButtonPress)){
|
||||
if (GotFirstClick3) GotDoubleClick3 = 1;
|
||||
else GotFirstClick3 = 1;
|
||||
}
|
||||
void ButtonPressEvent(XButtonEvent * xev)
|
||||
{
|
||||
DblClkDelay = 0;
|
||||
if ((xev->button == Button1) && (xev->type == ButtonPress)) {
|
||||
if (GotFirstClick1)
|
||||
GotDoubleClick1 = 1;
|
||||
else
|
||||
GotFirstClick1 = 1;
|
||||
} else if ((xev->button == Button2) && (xev->type == ButtonPress)) {
|
||||
if (GotFirstClick2)
|
||||
GotDoubleClick2 = 1;
|
||||
else
|
||||
GotFirstClick2 = 1;
|
||||
} else if ((xev->button == Button3) && (xev->type == ButtonPress)) {
|
||||
if (GotFirstClick3)
|
||||
GotDoubleClick3 = 1;
|
||||
else
|
||||
GotFirstClick3 = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* We got a double click on Mouse Button1 (i.e. the left one)
|
||||
*/
|
||||
if (GotDoubleClick1) {
|
||||
GotFirstClick1 = 0;
|
||||
GotDoubleClick1 = 0;
|
||||
system(DoubleClickCmd);
|
||||
}
|
||||
|
||||
/*
|
||||
* We got a double click on Mouse Button1 (i.e. the left one)
|
||||
*/
|
||||
if (GotDoubleClick1) {
|
||||
GotFirstClick1 = 0;
|
||||
GotDoubleClick1 = 0;
|
||||
system(DoubleClickCmd);
|
||||
}
|
||||
/*
|
||||
* We got a double click on Mouse Button2 (i.e. the middle one)
|
||||
*/
|
||||
if (GotDoubleClick2) {
|
||||
GotFirstClick2 = 0;
|
||||
GotDoubleClick2 = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* We got a double click on Mouse Button2 (i.e. the middle one)
|
||||
*/
|
||||
if (GotDoubleClick2) {
|
||||
GotFirstClick2 = 0;
|
||||
GotDoubleClick2 = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* We got a double click on Mouse Button3 (i.e. the right one)
|
||||
*/
|
||||
if (GotDoubleClick3) {
|
||||
GotFirstClick3 = 0;
|
||||
GotDoubleClick3 = 0;
|
||||
system(RDoubleClickCmd);
|
||||
}
|
||||
return;
|
||||
/*
|
||||
* We got a double click on Mouse Button3 (i.e. the right one)
|
||||
*/
|
||||
if (GotDoubleClick3) {
|
||||
GotFirstClick3 = 0;
|
||||
GotDoubleClick3 = 0;
|
||||
system(RDoubleClickCmd);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -41,342 +41,297 @@
|
|||
#include <sys/select.h>
|
||||
#include "xutils.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* X11 Variables
|
||||
*/
|
||||
int x_fd;
|
||||
XSizeHints mysizehints;
|
||||
XWMHints mywmhints;
|
||||
Pixel back_pix, fore_pix;
|
||||
char *Geometry = "";
|
||||
GC NormalGC;
|
||||
GC EraseGC;
|
||||
XpmIcon wmgen;
|
||||
Pixmap pixmask;
|
||||
|
||||
int x_fd;
|
||||
XSizeHints mysizehints;
|
||||
XWMHints mywmhints;
|
||||
Pixel back_pix, fore_pix;
|
||||
char *Geometry = "";
|
||||
GC NormalGC;
|
||||
GC EraseGC;
|
||||
XpmIcon wmgen;
|
||||
Pixmap pixmask;
|
||||
|
||||
/*
|
||||
* Colors for wmCalClock
|
||||
*/
|
||||
extern char TimeColor[30];
|
||||
extern char BackgroundColor[30];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern char TimeColor[30];
|
||||
extern char BackgroundColor[30];
|
||||
|
||||
/*
|
||||
* flush_expose
|
||||
*/
|
||||
static int flush_expose(Window w) {
|
||||
static int flush_expose(Window w)
|
||||
{
|
||||
|
||||
XEvent dummy;
|
||||
int i=0;
|
||||
XEvent dummy;
|
||||
int i = 0;
|
||||
|
||||
while (XCheckTypedWindowEvent(display, w, Expose, &dummy))
|
||||
i++;
|
||||
while (XCheckTypedWindowEvent(display, w, Expose, &dummy))
|
||||
i++;
|
||||
|
||||
return i;
|
||||
return i;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* RedrawWindow
|
||||
* RedrawWindowXY
|
||||
*/
|
||||
void RedrawWindow(void) {
|
||||
|
||||
flush_expose(iconwin);
|
||||
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 0,0, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
void RedrawWindow(void)
|
||||
{
|
||||
|
||||
flush_expose(win);
|
||||
XCopyArea(display, wmgen.pixmap, win, NormalGC, 0,0, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
flush_expose(iconwin);
|
||||
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 0, 0, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
|
||||
flush_expose(win);
|
||||
XCopyArea(display, wmgen.pixmap, win, NormalGC, 0, 0, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
void RedrawWindowXY(int x, int y) {
|
||||
|
||||
flush_expose(iconwin);
|
||||
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, x,y, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
void RedrawWindowXY(int x, int y)
|
||||
{
|
||||
|
||||
flush_expose(win);
|
||||
XCopyArea(display, wmgen.pixmap, win, NormalGC, x,y, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
flush_expose(iconwin);
|
||||
XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, x, y, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
|
||||
flush_expose(win);
|
||||
XCopyArea(display, wmgen.pixmap, win, NormalGC, x, y, wmgen.attributes.width, wmgen.attributes.height, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* copyXPMArea
|
||||
* copyXBMArea
|
||||
*/
|
||||
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy) {
|
||||
void copyXPMArea(int x, int y, int sx, int sy, int dx, int dy)
|
||||
{
|
||||
XCopyArea(display, wmgen.pixmap, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
|
||||
}
|
||||
|
||||
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy) {
|
||||
void copyXBMArea(int x, int y, int sx, int sy, int dx, int dy)
|
||||
{
|
||||
|
||||
XCopyArea(display, wmgen.mask, wmgen.pixmap, NormalGC, x, y, sx, sy, dx, dy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* initXwindow
|
||||
*/
|
||||
void initXwindow(int argc, char *argv[]){
|
||||
void initXwindow(int argc, char *argv[])
|
||||
{
|
||||
|
||||
int i;
|
||||
char *display_name = NULL;
|
||||
int i;
|
||||
char *display_name = NULL;
|
||||
|
||||
for (i=1; argv[i]; ++i) {
|
||||
if (!strcmp(argv[i], "-display")) display_name = argv[i+1];
|
||||
}
|
||||
for (i = 1; argv[i]; ++i) {
|
||||
if (!strcmp(argv[i], "-display"))
|
||||
display_name = argv[i + 1];
|
||||
}
|
||||
|
||||
if (!(display = XOpenDisplay(display_name))) {
|
||||
fprintf(stderr, "%s: can't open display %s\n", argv[0], XDisplayName(display_name));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!(display = XOpenDisplay(display_name))) {
|
||||
fprintf(stderr, "%s: can't open display %s\n",
|
||||
argv[0], XDisplayName(display_name));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
screen = DefaultScreen(display);
|
||||
Root = RootWindow(display, screen);
|
||||
DisplayDepth = DefaultDepth(display, screen);
|
||||
x_fd = XConnectionNumber(display);
|
||||
screen = DefaultScreen(display);
|
||||
Root = RootWindow(display, screen);
|
||||
DisplayDepth = DefaultDepth(display, screen);
|
||||
x_fd = XConnectionNumber(display);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* openXwindow
|
||||
*/
|
||||
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits,
|
||||
int pixmask_width, int pixmask_height) {
|
||||
void openXwindow(int argc, char *argv[], char *pixmap_bytes[], char *pixmask_bits, int pixmask_width, int pixmask_height)
|
||||
{
|
||||
|
||||
unsigned int borderwidth = 1;
|
||||
XClassHint classHint;
|
||||
char *wname = argv[0];
|
||||
XTextProperty name;
|
||||
XGCValues gcv;
|
||||
unsigned long gcm;
|
||||
int dummy=0, red, grn, blu;
|
||||
XpmColorSymbol cols[10]={ {"Back", NULL, 0},
|
||||
{"Color1", NULL, 0},
|
||||
{"Color2", NULL, 0},
|
||||
{"Color3", NULL, 0},
|
||||
{"Color4", NULL, 0},
|
||||
{"Color5", NULL, 0},
|
||||
{"Color6", NULL, 0},
|
||||
{"Color7", NULL, 0},
|
||||
{"Color8", NULL, 0},
|
||||
{"Color9", NULL, 0}};
|
||||
unsigned int borderwidth = 1;
|
||||
XClassHint classHint;
|
||||
char *wname = argv[0];
|
||||
XTextProperty name;
|
||||
XGCValues gcv;
|
||||
unsigned long gcm;
|
||||
int dummy = 0, red, grn, blu;
|
||||
XpmColorSymbol cols[10] = { {"Back", NULL, 0},
|
||||
{"Color1", NULL, 0},
|
||||
{"Color2", NULL, 0},
|
||||
{"Color3", NULL, 0},
|
||||
{"Color4", NULL, 0},
|
||||
{"Color5", NULL, 0},
|
||||
{"Color6", NULL, 0},
|
||||
{"Color7", NULL, 0},
|
||||
{"Color8", NULL, 0},
|
||||
{"Color9", NULL, 0}
|
||||
};
|
||||
|
||||
/*
|
||||
* Create Pixmap
|
||||
*/
|
||||
cols[0].pixel = getColor(BackgroundColor, 1.0000, &red, &grn, &blu);
|
||||
cols[1].pixel = getBlendedColor(TimeColor, 0.1522, red, grn, blu);
|
||||
cols[2].pixel = getBlendedColor(TimeColor, 0.2602, red, grn, blu);
|
||||
cols[3].pixel = getBlendedColor(TimeColor, 0.3761, red, grn, blu);
|
||||
cols[4].pixel = getBlendedColor(TimeColor, 0.4841, red, grn, blu);
|
||||
cols[5].pixel = getBlendedColor(TimeColor, 0.5922, red, grn, blu);
|
||||
cols[6].pixel = getBlendedColor(TimeColor, 0.6980, red, grn, blu);
|
||||
cols[7].pixel = getBlendedColor(TimeColor, 0.7961, red, grn, blu);
|
||||
cols[8].pixel = getBlendedColor(TimeColor, 0.8941, red, grn, blu);
|
||||
cols[9].pixel = getBlendedColor(TimeColor, 1.0000, red, grn, blu);
|
||||
|
||||
|
||||
wmgen.attributes.numsymbols = 10;
|
||||
wmgen.attributes.colorsymbols = cols;
|
||||
wmgen.attributes.exactColors = False;
|
||||
wmgen.attributes.closeness = 40000;
|
||||
wmgen.attributes.valuemask = XpmReturnPixels | XpmReturnExtensions | XpmColorSymbols | XpmExactColors | XpmCloseness | XpmSize;
|
||||
if (XpmCreatePixmapFromData(display, Root, pixmap_bytes, &(wmgen.pixmap), &(wmgen.mask), &(wmgen.attributes)) != XpmSuccess) {
|
||||
fprintf(stderr, "Not enough free colorcells.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create Pixmap
|
||||
*/
|
||||
cols[0].pixel = getColor(BackgroundColor, 1.0000, &red, &grn, &blu);
|
||||
cols[1].pixel = getBlendedColor(TimeColor, 0.1522, red, grn, blu);
|
||||
cols[2].pixel = getBlendedColor(TimeColor, 0.2602, red, grn, blu);
|
||||
cols[3].pixel = getBlendedColor(TimeColor, 0.3761, red, grn, blu);
|
||||
cols[4].pixel = getBlendedColor(TimeColor, 0.4841, red, grn, blu);
|
||||
cols[5].pixel = getBlendedColor(TimeColor, 0.5922, red, grn, blu);
|
||||
cols[6].pixel = getBlendedColor(TimeColor, 0.6980, red, grn, blu);
|
||||
cols[7].pixel = getBlendedColor(TimeColor, 0.7961, red, grn, blu);
|
||||
cols[8].pixel = getBlendedColor(TimeColor, 0.8941, red, grn, blu);
|
||||
cols[9].pixel = getBlendedColor(TimeColor, 1.0000, red, grn, blu);
|
||||
/*
|
||||
* Create a window
|
||||
*/
|
||||
mysizehints.flags = USSize | USPosition;
|
||||
mysizehints.x = 0;
|
||||
mysizehints.y = 0;
|
||||
|
||||
wmgen.attributes.numsymbols = 10;
|
||||
wmgen.attributes.colorsymbols = cols;
|
||||
wmgen.attributes.exactColors = False;
|
||||
wmgen.attributes.closeness = 40000;
|
||||
wmgen.attributes.valuemask = XpmReturnPixels | XpmReturnExtensions | XpmColorSymbols
|
||||
| XpmExactColors | XpmCloseness | XpmSize;
|
||||
if (XpmCreatePixmapFromData(display, Root, pixmap_bytes,
|
||||
&(wmgen.pixmap), &(wmgen.mask), &(wmgen.attributes)) != XpmSuccess){
|
||||
fprintf(stderr, "Not enough free colorcells.\n");
|
||||
exit(1);
|
||||
}
|
||||
back_pix = getColor("black", 1.0, &red, &grn, &blu);
|
||||
fore_pix = getColor("white", 1.0, &red, &grn, &blu);
|
||||
|
||||
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
|
||||
&mysizehints.x, &mysizehints.y, &mysizehints.width, &mysizehints.height, &dummy);
|
||||
|
||||
mysizehints.width = 64;
|
||||
mysizehints.height = 64;
|
||||
|
||||
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
|
||||
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
|
||||
|
||||
/*
|
||||
* Create a window
|
||||
*/
|
||||
mysizehints.flags = USSize | USPosition;
|
||||
mysizehints.x = 0;
|
||||
mysizehints.y = 0;
|
||||
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
|
||||
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
|
||||
|
||||
back_pix = getColor("black", 1.0, &red, &grn, &blu);
|
||||
fore_pix = getColor("white", 1.0, &red, &grn, &blu);
|
||||
/*
|
||||
* Activate hints
|
||||
*/
|
||||
XSetWMNormalHints(display, win, &mysizehints);
|
||||
classHint.res_name = wname;
|
||||
classHint.res_class = wname;
|
||||
XSetClassHint(display, win, &classHint);
|
||||
|
||||
XWMGeometry(display, screen, Geometry, NULL, borderwidth, &mysizehints,
|
||||
&mysizehints.x, &mysizehints.y,&mysizehints.width,&mysizehints.height, &dummy);
|
||||
/*
|
||||
* Set up the xevents that you want the relevent windows to inherit
|
||||
* Currently, its seems that setting KeyPress events here has no
|
||||
* effect. I.e. for some you will need to Grab the focus and then return
|
||||
* it after you are done...
|
||||
*/
|
||||
XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask
|
||||
| PointerMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask);
|
||||
XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask
|
||||
| PointerMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask | KeyPressMask | KeyReleaseMask);
|
||||
|
||||
mysizehints.width = 64;
|
||||
mysizehints.height = 64;
|
||||
|
||||
if (XStringListToTextProperty(&wname, 1, &name) == 0) {
|
||||
fprintf(stderr, "%s: can't allocate window name\n", wname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
XSetWMName(display, win, &name);
|
||||
|
||||
win = XCreateSimpleWindow(display, Root, mysizehints.x, mysizehints.y,
|
||||
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
|
||||
|
||||
iconwin = XCreateSimpleWindow(display, win, mysizehints.x, mysizehints.y,
|
||||
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
|
||||
/*
|
||||
* Create Graphics Context (GC) for drawing
|
||||
*/
|
||||
gcm = GCForeground | GCBackground | GCGraphicsExposures;
|
||||
gcv.foreground = fore_pix;
|
||||
gcv.background = back_pix;
|
||||
gcv.graphics_exposures = 0;
|
||||
NormalGC = XCreateGC(display, Root, gcm, &gcv);
|
||||
|
||||
/*
|
||||
* Create Graphics Context (GC) for erasing
|
||||
*/
|
||||
gcm = GCForeground | GCBackground | GCGraphicsExposures;
|
||||
gcv.foreground = back_pix;
|
||||
gcv.background = back_pix;
|
||||
gcv.graphics_exposures = 0;
|
||||
EraseGC = XCreateGC(display, Root, gcm, &gcv);
|
||||
|
||||
pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height);
|
||||
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
|
||||
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
|
||||
|
||||
/*
|
||||
* Activate hints
|
||||
*/
|
||||
XSetWMNormalHints(display, win, &mysizehints);
|
||||
classHint.res_name = wname;
|
||||
classHint.res_class = wname;
|
||||
XSetClassHint(display, win, &classHint);
|
||||
mywmhints.initial_state = WithdrawnState;
|
||||
mywmhints.icon_window = iconwin;
|
||||
mywmhints.icon_x = mysizehints.x;
|
||||
mywmhints.icon_y = mysizehints.y;
|
||||
mywmhints.window_group = win;
|
||||
mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
|
||||
|
||||
XSetWMHints(display, win, &mywmhints);
|
||||
|
||||
|
||||
/*
|
||||
* Set up the xevents that you want the relevent windows to inherit
|
||||
* Currently, its seems that setting KeyPress events here has no
|
||||
* effect. I.e. for some you will need to Grab the focus and then return
|
||||
* it after you are done...
|
||||
*/
|
||||
XSelectInput(display, win, ButtonPressMask | ExposureMask | ButtonReleaseMask
|
||||
| PointerMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask
|
||||
| KeyPressMask | KeyReleaseMask);
|
||||
XSelectInput(display, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask
|
||||
| PointerMotionMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask
|
||||
| KeyPressMask | KeyReleaseMask);
|
||||
|
||||
|
||||
if (XStringListToTextProperty(&wname, 1, &name) == 0) {
|
||||
fprintf(stderr, "%s: can't allocate window name\n", wname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
XSetWMName(display, win, &name);
|
||||
|
||||
/*
|
||||
* Create Graphics Context (GC) for drawing
|
||||
*/
|
||||
gcm = GCForeground | GCBackground | GCGraphicsExposures;
|
||||
gcv.foreground = fore_pix;
|
||||
gcv.background = back_pix;
|
||||
gcv.graphics_exposures = 0;
|
||||
NormalGC = XCreateGC(display, Root, gcm, &gcv);
|
||||
|
||||
/*
|
||||
* Create Graphics Context (GC) for erasing
|
||||
*/
|
||||
gcm = GCForeground | GCBackground | GCGraphicsExposures;
|
||||
gcv.foreground = back_pix;
|
||||
gcv.background = back_pix;
|
||||
gcv.graphics_exposures = 0;
|
||||
EraseGC = XCreateGC(display, Root, gcm, &gcv);
|
||||
|
||||
|
||||
|
||||
pixmask = XCreateBitmapFromData(display, win, pixmask_bits, pixmask_width, pixmask_height);
|
||||
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
|
||||
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
|
||||
|
||||
|
||||
mywmhints.initial_state = WithdrawnState;
|
||||
mywmhints.icon_window = iconwin;
|
||||
mywmhints.icon_x = mysizehints.x;
|
||||
mywmhints.icon_y = mysizehints.y;
|
||||
mywmhints.window_group = win;
|
||||
mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
|
||||
|
||||
|
||||
XSetWMHints(display, win, &mywmhints);
|
||||
|
||||
|
||||
XSetCommand(display, win, argv, argc);
|
||||
XMapWindow(display, win);
|
||||
XSetCommand(display, win, argv, argc);
|
||||
XMapWindow(display, win);
|
||||
|
||||
}
|
||||
|
||||
unsigned long getColor(char *ColorName, float fac, int *red, int *grn, int *blu) {
|
||||
unsigned long getColor(char *ColorName, float fac, int *red, int *grn, int *blu)
|
||||
{
|
||||
|
||||
XColor Color;
|
||||
XWindowAttributes Attributes;
|
||||
XColor Color;
|
||||
XWindowAttributes Attributes;
|
||||
|
||||
XGetWindowAttributes(display, Root, &Attributes);
|
||||
Color.pixel = 0;
|
||||
XGetWindowAttributes(display, Root, &Attributes);
|
||||
Color.pixel = 0;
|
||||
|
||||
XParseColor(display, Attributes.colormap, ColorName, &Color);
|
||||
Color.red = (unsigned short)(fac*(Color.red-24) + 24);
|
||||
Color.blue = (unsigned short)(fac*(Color.blue-24) + 24);
|
||||
Color.green = (unsigned short)(fac*(Color.green-24) + 24);
|
||||
Color.flags = DoRed | DoGreen | DoBlue;
|
||||
XAllocColor(display, Attributes.colormap, &Color);
|
||||
XParseColor(display, Attributes.colormap, ColorName, &Color);
|
||||
Color.red = (unsigned short)(fac * (Color.red - 24) + 24);
|
||||
Color.blue = (unsigned short)(fac * (Color.blue - 24) + 24);
|
||||
Color.green = (unsigned short)(fac * (Color.green - 24) + 24);
|
||||
Color.flags = DoRed | DoGreen | DoBlue;
|
||||
XAllocColor(display, Attributes.colormap, &Color);
|
||||
|
||||
|
||||
*red = Color.red;
|
||||
*grn = Color.green;
|
||||
*blu = Color.blue;
|
||||
return Color.pixel;
|
||||
*red = Color.red;
|
||||
*grn = Color.green;
|
||||
*blu = Color.blue;
|
||||
return Color.pixel;
|
||||
|
||||
}
|
||||
|
||||
unsigned long getBlendedColor(char *ColorName, float fac, int red, int grn, int blu) {
|
||||
unsigned long getBlendedColor(char *ColorName, float fac, int red, int grn, int blu)
|
||||
{
|
||||
|
||||
XColor Color;
|
||||
XWindowAttributes Attributes;
|
||||
XColor Color;
|
||||
XWindowAttributes Attributes;
|
||||
|
||||
XGetWindowAttributes(display, Root, &Attributes);
|
||||
Color.pixel = 0;
|
||||
XGetWindowAttributes(display, Root, &Attributes);
|
||||
Color.pixel = 0;
|
||||
|
||||
XParseColor(display, Attributes.colormap, ColorName, &Color);
|
||||
Color.red = (unsigned short)(fac*(Color.red-red) + red);
|
||||
Color.blue = (unsigned short)(fac*(Color.blue-grn) + grn);
|
||||
Color.green = (unsigned short)(fac*(Color.green-blu) + blu);
|
||||
Color.flags = DoRed | DoGreen | DoBlue;
|
||||
XAllocColor(display, Attributes.colormap, &Color);
|
||||
XParseColor(display, Attributes.colormap, ColorName, &Color);
|
||||
Color.red = (unsigned short)(fac * (Color.red - red) + red);
|
||||
Color.blue = (unsigned short)(fac * (Color.blue - grn) + grn);
|
||||
Color.green = (unsigned short)(fac * (Color.green - blu) + blu);
|
||||
Color.flags = DoRed | DoGreen | DoBlue;
|
||||
XAllocColor(display, Attributes.colormap, &Color);
|
||||
|
||||
return Color.pixel;
|
||||
return Color.pixel;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Here is a faster version of usleep using select()
|
||||
*/
|
||||
void uusleep(unsigned long usecs) {
|
||||
void uusleep(unsigned long usecs)
|
||||
{
|
||||
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = usecs / 1000000UL;
|
||||
tv.tv_usec = usecs % 1000000UL;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(x_fd, &fds);
|
||||
select(x_fd + 1, &fds, NULL, NULL, &tv);
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = usecs / 1000000UL;
|
||||
tv.tv_usec = usecs % 1000000UL;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(x_fd, &fds);
|
||||
select(x_fd + 1, &fds, NULL, NULL, &tv);
|
||||
|
||||
}
|
||||
|
||||
|
@ -385,15 +340,15 @@ void uusleep(unsigned long usecs) {
|
|||
* will be less than 1 second. This allows us to save on a div operation.
|
||||
*
|
||||
*/
|
||||
void short_uusleep(unsigned long usecs) {
|
||||
void short_uusleep(unsigned long usecs)
|
||||
{
|
||||
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = usecs;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(x_fd, &fds);
|
||||
select(x_fd + 1, &fds, NULL, NULL, &tv);
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = usecs;
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(x_fd, &fds);
|
||||
select(x_fd + 1, &fds, NULL, NULL, &tv);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,51 +1,40 @@
|
|||
#ifndef WMGENERAL_H_INCLUDED
|
||||
#define WMGENERAL_H_INCLUDED
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Typedefs
|
||||
*/
|
||||
typedef struct {
|
||||
Pixmap pixmap;
|
||||
Pixmap mask;
|
||||
XpmAttributes attributes;
|
||||
Pixmap pixmap;
|
||||
Pixmap mask;
|
||||
XpmAttributes attributes;
|
||||
} XpmIcon;
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Global variable
|
||||
*/
|
||||
Display *display;
|
||||
Window Root;
|
||||
Window iconwin, win;
|
||||
int screen;
|
||||
int DisplayDepth;
|
||||
|
||||
|
||||
|
||||
|
||||
Display *display;
|
||||
Window Root;
|
||||
Window iconwin, win;
|
||||
int screen;
|
||||
int DisplayDepth;
|
||||
|
||||
/*
|
||||
* Function Prototypes
|
||||
*/
|
||||
void AddMouseRegion(int, int, int, int, int);
|
||||
int CheckMouseRegion(int, int);
|
||||
void openXwindow(int, char **, char **, char *, int, int);
|
||||
void initXwindow(int, char **);
|
||||
void RedrawWindow(void);
|
||||
void RedrawWindowXY(int, int);
|
||||
void copyXPMArea(int, int, int, int, int, int);
|
||||
void copyXBMArea(int, int, int, int, int, int);
|
||||
void setMaskXY(int, int);
|
||||
unsigned long getColor(char *, float, int *, int *, int *);
|
||||
unsigned long getBlendedColor(char *, float, int, int, int);
|
||||
void RedrawWindow(void);
|
||||
void uusleep( unsigned long );
|
||||
void short_uusleep( unsigned long );
|
||||
|
||||
|
||||
void AddMouseRegion(int, int, int, int, int);
|
||||
int CheckMouseRegion(int, int);
|
||||
void openXwindow(int, char **, char **, char *, int, int);
|
||||
void initXwindow(int, char **);
|
||||
void RedrawWindow(void);
|
||||
void RedrawWindowXY(int, int);
|
||||
void copyXPMArea(int, int, int, int, int, int);
|
||||
void copyXBMArea(int, int, int, int, int, int);
|
||||
void setMaskXY(int, int);
|
||||
unsigned long getColor(char *, float, int *, int *, int *);
|
||||
unsigned long getBlendedColor(char *, float, int, int, int);
|
||||
void RedrawWindow(void);
|
||||
void uusleep(unsigned long);
|
||||
void short_uusleep(unsigned long);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,15 +42,13 @@
|
|||
Irix 6.2; Indy r5k; SGI cc version 6; gcc version 2.7.2.1.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h> /* for getpid() */
|
||||
#include <unistd.h> /* for getpid() */
|
||||
#endif
|
||||
#include <sys/time.h> /* for gettimeofday() */
|
||||
#include <sys/time.h> /* for gettimeofday() */
|
||||
|
||||
#include "yarandom.h"
|
||||
|
||||
|
||||
/* The following 'random' numbers are taken from CRC, 18th Edition, page 622.
|
||||
Each array element was taken from the corresponding line in the table,
|
||||
except that a[0] was from line 100. 8s and 9s in the table were simply
|
||||
|
@ -58,55 +56,53 @@
|
|||
*/
|
||||
#define VectorSize 55
|
||||
static unsigned int a[VectorSize] = {
|
||||
035340171546, 010401501101, 022364657325, 024130436022, 002167303062, /* 5 */
|
||||
037570375137, 037210607110, 016272055420, 023011770546, 017143426366, /* 10 */
|
||||
014753657433, 021657231332, 023553406142, 004236526362, 010365611275, /* 14 */
|
||||
007117336710, 011051276551, 002362132524, 001011540233, 012162531646, /* 20 */
|
||||
007056762337, 006631245521, 014164542224, 032633236305, 023342700176, /* 25 */
|
||||
002433062234, 015257225043, 026762051606, 000742573230, 005366042132, /* 30 */
|
||||
012126416411, 000520471171, 000725646277, 020116577576, 025765742604, /* 35 */
|
||||
007633473735, 015674255275, 017555634041, 006503154145, 021576344247, /* 40 */
|
||||
014577627653, 002707523333, 034146376720, 030060227734, 013765414060, /* 45 */
|
||||
036072251540, 007255221037, 024364674123, 006200353166, 010126373326, /* 50 */
|
||||
015664104320, 016401041535, 016215305520, 033115351014, 017411670323 /* 55 */
|
||||
035340171546, 010401501101, 022364657325, 024130436022, 002167303062, /* 5 */
|
||||
037570375137, 037210607110, 016272055420, 023011770546, 017143426366, /* 10 */
|
||||
014753657433, 021657231332, 023553406142, 004236526362, 010365611275, /* 14 */
|
||||
007117336710, 011051276551, 002362132524, 001011540233, 012162531646, /* 20 */
|
||||
007056762337, 006631245521, 014164542224, 032633236305, 023342700176, /* 25 */
|
||||
002433062234, 015257225043, 026762051606, 000742573230, 005366042132, /* 30 */
|
||||
012126416411, 000520471171, 000725646277, 020116577576, 025765742604, /* 35 */
|
||||
007633473735, 015674255275, 017555634041, 006503154145, 021576344247, /* 40 */
|
||||
014577627653, 002707523333, 034146376720, 030060227734, 013765414060, /* 45 */
|
||||
036072251540, 007255221037, 024364674123, 006200353166, 010126373326, /* 50 */
|
||||
015664104320, 016401041535, 016215305520, 033115351014, 017411670323 /* 55 */
|
||||
};
|
||||
|
||||
static int i1, i2;
|
||||
|
||||
unsigned int
|
||||
ya_random (void)
|
||||
unsigned int ya_random(void)
|
||||
{
|
||||
register int ret = a[i1] + a[i2];
|
||||
a[i1] = ret;
|
||||
if (++i1 >= VectorSize) i1 = 0;
|
||||
if (++i2 >= VectorSize) i2 = 0;
|
||||
return ret;
|
||||
register int ret = a[i1] + a[i2];
|
||||
a[i1] = ret;
|
||||
if (++i1 >= VectorSize)
|
||||
i1 = 0;
|
||||
if (++i2 >= VectorSize)
|
||||
i2 = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
ya_rand_init(unsigned int seed)
|
||||
void ya_rand_init(unsigned int seed)
|
||||
{
|
||||
int i;
|
||||
if (seed == 0)
|
||||
{
|
||||
struct timeval tp;
|
||||
int i;
|
||||
if (seed == 0) {
|
||||
struct timeval tp;
|
||||
#ifdef GETTIMEOFDAY_TWO_ARGS
|
||||
struct timezone tzp;
|
||||
gettimeofday(&tp, &tzp);
|
||||
struct timezone tzp;
|
||||
gettimeofday(&tp, &tzp);
|
||||
#else
|
||||
gettimeofday(&tp);
|
||||
gettimeofday(&tp);
|
||||
#endif
|
||||
/* ignore overflow */
|
||||
seed = (999*tp.tv_sec) + (1001*tp.tv_usec) + (1003 * getpid());
|
||||
}
|
||||
/* ignore overflow */
|
||||
seed = (999 * tp.tv_sec) + (1001 * tp.tv_usec) + (1003 * getpid());
|
||||
}
|
||||
|
||||
a[0] += seed;
|
||||
for (i = 1; i < VectorSize; i++)
|
||||
{
|
||||
seed = a[i-1]*1001 + seed*999;
|
||||
a[i] += seed;
|
||||
}
|
||||
a[0] += seed;
|
||||
for (i = 1; i < VectorSize; i++) {
|
||||
seed = a[i - 1] * 1001 + seed * 999;
|
||||
a[i] += seed;
|
||||
}
|
||||
|
||||
i1 = a[0] % VectorSize;
|
||||
i2 = (i1 + 024) % VectorSize;
|
||||
i1 = a[0] % VectorSize;
|
||||
i2 = (i1 + 024) % VectorSize;
|
||||
}
|
||||
|
|
|
@ -22,33 +22,32 @@
|
|||
#undef RAND_MAX
|
||||
|
||||
#ifdef VMS
|
||||
# include "vms-gtod.h"
|
||||
#include "vms-gtod.h"
|
||||
#endif
|
||||
|
||||
#define random() ya_random()
|
||||
#define srandom(i) ya_rand_init(0)
|
||||
#define RAND_MAX 0x7FFFFFFF
|
||||
|
||||
extern unsigned int ya_random (void);
|
||||
extern void ya_rand_init (unsigned int);
|
||||
|
||||
extern unsigned int ya_random(void);
|
||||
extern void ya_rand_init(unsigned int);
|
||||
|
||||
#if defined (__GNUC__) && (__GNUC__ >= 2)
|
||||
/* Implement frand using GCC's statement-expression extension. */
|
||||
|
||||
# define frand(f) \
|
||||
#define frand(f) \
|
||||
({ double tmp = (((double) random()) / \
|
||||
(((double) ((unsigned int)~0)) / ((double) (f)))); \
|
||||
tmp < 0 ? (-tmp) : tmp; })
|
||||
|
||||
#else /* not GCC2 - implement frand using a global variable.*/
|
||||
#else /* not GCC2 - implement frand using a global variable. */
|
||||
|
||||
static double _frand_tmp_;
|
||||
# define frand(f) \
|
||||
#define frand(f) \
|
||||
(_frand_tmp_ = (((double) random()) / \
|
||||
(((double) ((unsigned int)~0)) / ((double) (f)))), \
|
||||
_frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_)
|
||||
|
||||
#endif /* not GCC2 */
|
||||
#endif /* not GCC2 */
|
||||
|
||||
#endif /* __YARANDOM_H__ */
|
||||
#endif /* __YARANDOM_H__ */
|
||||
|
|
Loading…
Reference in a new issue