2015-01-10 16:59:41 +00:00
|
|
|
/****************************************************************
|
|
|
|
* File: wmcalc.c
|
|
|
|
* Version: 0.3
|
|
|
|
* Date: January 17, 2001
|
|
|
|
* Author: Edward H. Flora <ehflora@access1.net>
|
|
|
|
*
|
2015-01-10 16:59:48 +00:00
|
|
|
* This file is a part of the wmcalc application. As such, this
|
|
|
|
* file is licensed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license may be found in the file COPYING that should
|
|
|
|
* have been distributed with this file. If not, please refer to
|
2015-01-10 16:59:41 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html for details.
|
|
|
|
*
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
This file contains the main program code for the wmcalc
|
2015-01-10 16:59:48 +00:00
|
|
|
application. Wmcalc is a dockapp designed for the WindowMaker or
|
2015-01-10 16:59:41 +00:00
|
|
|
Afterstep window managers (although it should run well in most
|
|
|
|
others.) wmcalc is a four-function (and more) calculator that
|
|
|
|
has a small enough footprint that you may leave it open on your
|
|
|
|
desktop at all times, for convenient use.
|
2015-01-10 16:59:48 +00:00
|
|
|
|
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
01/17/01 Updated to use XLookupString
|
|
|
|
12/10/00 Revised includes, extracting X libs to wmcalc_x.h
|
|
|
|
11/09/00 Added "locked" memory capabilities
|
2015-01-10 16:59:48 +00:00
|
|
|
11/08/00 Added Code to Support Keyboard / focus
|
2015-01-10 16:59:41 +00:00
|
|
|
10/29/00 Implemented memory use, configuration files, and a
|
|
|
|
quickstart button for a larger calculator. Also
|
|
|
|
abstracted some of the macros, global vars, function
|
|
|
|
prototypes, etc out to independent header files, to
|
|
|
|
eliminate some dependency issues between source files.
|
|
|
|
02/10/00 Added keyboard event code, without success
|
|
|
|
12/21/99 Original product release, version 0.1
|
|
|
|
11/26/99 Original file creation
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "wmcalc_x.h"
|
2015-01-10 16:59:44 +00:00
|
|
|
#include <X11/XKBlib.h>
|
2015-01-10 16:59:41 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "wmcalc_c.h"
|
|
|
|
#include "wmcalc_err.h"
|
|
|
|
#include "wmcalc_t.h"
|
|
|
|
#include "wmcalc_g.h"
|
|
|
|
#include "wmcalc_f.h"
|
|
|
|
|
2015-01-10 16:59:54 +00:00
|
|
|
#include "backdrop.xpm" /* background graphic */
|
|
|
|
#include "calcbuttons.xpm" /* graphic of buttons */
|
|
|
|
#include "charmap.xpm" /* pixmap of characters */
|
2015-01-10 16:59:41 +00:00
|
|
|
#include "mask.xbm"
|
|
|
|
|
|
|
|
/* Global Variables */
|
|
|
|
/* Ok, so I didn't get them all extracted. Should look into this
|
|
|
|
further */
|
|
|
|
int N = 1; /* Button number pressed to goto app # */
|
|
|
|
int border = 0;
|
|
|
|
int Verbose = 0; /* Debug flag */
|
|
|
|
int mmouse = 1; /* flag to enable middle mouse (hold
|
|
|
|
over from wmbutton */
|
|
|
|
int button_pressed = -1; /* button to be drawn pressed */
|
|
|
|
char PlusMinusFlag = '+'; /* flag for sign of number in display */
|
|
|
|
char OpFlag = ' '; /* Operation requested */
|
|
|
|
int ExpFlag = 0; /* Flag if in scientific notation */
|
|
|
|
int DecFlag = 0; /* Flag if a decimal is in display */
|
|
|
|
int ImgFlag = 0; /* Flag if a number is imaginary */
|
2015-01-10 16:59:48 +00:00
|
|
|
int StrCnt = 0;
|
2015-01-10 16:59:41 +00:00
|
|
|
double RegisterA = 0.0; /* Main working register, displayed */
|
|
|
|
double RegisterB = 0.0; /* Second register to add to, etc */
|
|
|
|
char DispString[DISPSIZE+1]; /* Pointer to string of display */
|
|
|
|
ButtonArea button_region[NUM_BUTTONS]; /* Array of buttons */
|
|
|
|
|
|
|
|
char *app_name = "wmcalc"; /* Name of app, for window management */
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: main
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
This is the main Program control function for wmcalc. It
|
|
|
|
contains all the X11 windows function calls, as well as other
|
|
|
|
general operations.
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
01/17/01 Updated to use XLookupString to get KeySym
|
|
|
|
11/09/00 Added Events for focus and keyboard work.
|
|
|
|
11/01/00 File Header Added
|
|
|
|
21/09/01 Added global configfile by Gordon Fraser
|
|
|
|
****************************************************************/
|
|
|
|
int main( int argc, char **argv ) {
|
|
|
|
XEvent report;
|
2015-01-10 16:59:48 +00:00
|
|
|
XGCValues xgcValues;
|
2015-01-10 16:59:41 +00:00
|
|
|
XTextProperty app_name_atom;
|
|
|
|
int err_code = OKAY;
|
|
|
|
int dummy = 0;
|
|
|
|
int i;
|
|
|
|
char Geometry_str[64] = "64x64+0+0";
|
|
|
|
char Display_str[64] = "";
|
|
|
|
int KeywithMask = NO_BUTTON;
|
|
|
|
KeySym ksym;
|
|
|
|
XComposeStatus compose;
|
|
|
|
char buffer[20];
|
|
|
|
int bufsize = 20;
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
|
2015-01-10 16:59:54 +00:00
|
|
|
strcpy(configfile, getenv("HOME")); /* Added to wmbutton by Casey Harkin, 3/6/99 */
|
|
|
|
strcat(configfile, CONFFILENAME); /* Fixed Bug - didn't look in home directory */
|
|
|
|
/* but startup directory */
|
|
|
|
strcat(tempfile, CONFTEMPFILE); /* Setup name for temp file */
|
2015-01-10 16:59:41 +00:00
|
|
|
|
|
|
|
/* Clear the Calculator Display */
|
2015-01-10 16:59:46 +00:00
|
|
|
for(i=0; i<DISPSIZE; i++) DispString[i] = ' ';
|
|
|
|
DispString[DISPSIZE] = '\0';
|
2015-01-10 16:59:41 +00:00
|
|
|
|
2015-01-10 16:59:48 +00:00
|
|
|
/* Parse Command Line Arguments */
|
2015-01-10 16:59:41 +00:00
|
|
|
for ( i=1; i < argc; i++ ) {
|
|
|
|
if ( *argv[i] == '-' ) {
|
|
|
|
switch ( *(argv[i]+1) ) {
|
2015-01-10 16:59:54 +00:00
|
|
|
case 'v': /* Turn on Verbose (debugging) Mode */
|
2015-01-10 16:59:41 +00:00
|
|
|
Verbose = 1;
|
|
|
|
break;
|
2015-01-10 16:59:54 +00:00
|
|
|
case 'g': /* Set Geometry Options */
|
2015-01-10 16:59:41 +00:00
|
|
|
if ( ++i >= argc ) show_usage();
|
|
|
|
sscanf(argv[i], "%s", Geometry_str);
|
|
|
|
if ( Verbose ) printf("Geometry is: %s\n", Geometry_str);
|
|
|
|
break;
|
2015-01-10 16:59:54 +00:00
|
|
|
case 'd': /* Set display */
|
2015-01-10 16:59:41 +00:00
|
|
|
if ( ++i >= argc ) show_usage();
|
|
|
|
sscanf(argv[i], "%s", Display_str);
|
|
|
|
if ( Verbose ) printf("Display is: %s\n", Display_str);
|
|
|
|
break;
|
2015-01-10 16:59:54 +00:00
|
|
|
case 'h': /* Show Help Message */
|
2015-01-10 16:59:41 +00:00
|
|
|
show_usage();
|
|
|
|
break;
|
2015-01-10 16:59:54 +00:00
|
|
|
case 'f': /* use config file <filename> */
|
2015-01-10 16:59:41 +00:00
|
|
|
if ( ++i >= argc ) show_usage();
|
|
|
|
sscanf(argv[i], "%s", configfile);
|
|
|
|
if ( Verbose ) printf("Using Config File: %s\n", configfile);
|
|
|
|
break;
|
2015-01-10 16:59:54 +00:00
|
|
|
default: /* other, unknown, parameters */
|
2015-01-10 16:59:41 +00:00
|
|
|
show_usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} /* End of loop to process command line options */
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
/* Open display on requested X server */
|
|
|
|
if ( (display = XOpenDisplay(Display_str)) == NULL ) {
|
|
|
|
error_handler(ERR_X_DISPLAY, Display_str);
|
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
screen = DefaultScreen(display);
|
|
|
|
rootwin = RootWindow(display,screen);
|
|
|
|
depth = DefaultDepth(display, screen);
|
2015-01-10 16:59:48 +00:00
|
|
|
|
|
|
|
bg_pixel = WhitePixel(display, screen );
|
|
|
|
fg_pixel = BlackPixel(display, screen );
|
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
xsizehints.flags = USSize | USPosition;
|
|
|
|
xsizehints.width = APP_WIDTH;
|
|
|
|
xsizehints.height = APP_HEIGHT;
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
/* Parse Geometry string and fill in sizehints fields */
|
2015-01-10 16:59:48 +00:00
|
|
|
XWMGeometry(display, screen,
|
|
|
|
Geometry_str,
|
|
|
|
NULL,
|
|
|
|
border,
|
2015-01-10 16:59:41 +00:00
|
|
|
&xsizehints,
|
2015-01-10 16:59:48 +00:00
|
|
|
&xsizehints.x,
|
2015-01-10 16:59:41 +00:00
|
|
|
&xsizehints.y,
|
|
|
|
&xsizehints.width,
|
2015-01-10 16:59:48 +00:00
|
|
|
&xsizehints.height,
|
2015-01-10 16:59:41 +00:00
|
|
|
&dummy);
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
if ( (win = XCreateSimpleWindow(display,
|
|
|
|
rootwin,
|
|
|
|
xsizehints.x,
|
|
|
|
xsizehints.y,
|
|
|
|
xsizehints.width,
|
|
|
|
xsizehints.height,
|
|
|
|
border,
|
|
|
|
fg_pixel, bg_pixel) ) == 0 ) {
|
|
|
|
error_handler(ERR_X_CREATE_WINDOW, NULL);
|
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
if ( (iconwin = XCreateSimpleWindow(display,
|
|
|
|
win,
|
|
|
|
xsizehints.x,
|
|
|
|
xsizehints.y,
|
|
|
|
xsizehints.width,
|
|
|
|
xsizehints.height,
|
|
|
|
border,
|
|
|
|
fg_pixel, bg_pixel) ) == 0 ) {
|
|
|
|
error_handler(ERR_X_CREATE_WINDOW, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up shaped windows */
|
|
|
|
/*Gives the appicon a border so you can grab and move it. */
|
|
|
|
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( ( pixmask = XCreateBitmapFromData(display,
|
2015-01-10 16:59:41 +00:00
|
|
|
win,
|
2015-01-10 16:59:53 +00:00
|
|
|
(char *)mask_bits,
|
2015-01-10 16:59:41 +00:00
|
|
|
mask_width,
|
|
|
|
mask_height) ) == 0 ) {
|
|
|
|
error_handler(ERR_X_CREATE_BITMAP, NULL);
|
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
XShapeCombineMask(display, win, ShapeBounding, 0, 0, pixmask, ShapeSet );
|
|
|
|
XShapeCombineMask(display, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
|
|
|
|
|
|
|
|
/* Convert in pixmaps from .xpm includes. */
|
|
|
|
getPixmaps();
|
|
|
|
|
|
|
|
/* Interclient Communication stuff */
|
|
|
|
/* Appicons don't work with out this stuff */
|
|
|
|
xwmhints = XAllocWMHints();
|
2015-01-10 16:59:48 +00:00
|
|
|
xwmhints->flags = WindowGroupHint | IconWindowHint | StateHint;
|
2015-01-10 16:59:41 +00:00
|
|
|
xwmhints->icon_window = iconwin;
|
|
|
|
xwmhints->window_group = win;
|
2015-01-10 16:59:48 +00:00
|
|
|
xwmhints->initial_state = WithdrawnState;
|
2015-01-10 16:59:41 +00:00
|
|
|
XSetWMHints( display, win, xwmhints );
|
|
|
|
|
|
|
|
xclasshint.res_name = app_name;
|
|
|
|
xclasshint.res_class = app_name;
|
|
|
|
XSetClassHint( display, win, &xclasshint );
|
|
|
|
|
|
|
|
XSetWMNormalHints( display, win, &xsizehints );
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
/* Tell window manager what the title bar name is. We never see */
|
|
|
|
/* this anyways in the WithdrawnState */
|
|
|
|
if ( XStringListToTextProperty(&app_name, 1, &app_name_atom) == 0 ) {
|
|
|
|
error_handler(ERR_SETUP_WINDOW_NAME, app_name);
|
|
|
|
}
|
|
|
|
XSetWMName( display, win, &app_name_atom );
|
2015-01-10 16:59:48 +00:00
|
|
|
|
|
|
|
/* Create Graphic Context */
|
2015-01-10 16:59:41 +00:00
|
|
|
if (( gc = XCreateGC(display, win,(GCForeground | GCBackground), &xgcValues))
|
|
|
|
== NULL ) {
|
|
|
|
error_handler(ERR_CREATE_GC, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XEvent Masks. We want both windows to process X events */
|
|
|
|
XSelectInput(display, win,
|
2015-01-10 16:59:48 +00:00
|
|
|
ExposureMask |
|
|
|
|
ButtonPressMask |
|
2015-01-10 16:59:41 +00:00
|
|
|
ButtonReleaseMask | /* added ButtonReleaseMask *charkins*/
|
|
|
|
PointerMotionMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
LeaveWindowMask |
|
|
|
|
KeyPressMask | /* Try this to get keyboard working */
|
|
|
|
StructureNotifyMask |
|
2015-01-10 16:59:48 +00:00
|
|
|
EnterWindowMask );
|
2015-01-10 16:59:41 +00:00
|
|
|
XSelectInput(display, iconwin,
|
2015-01-10 16:59:48 +00:00
|
|
|
ExposureMask |
|
|
|
|
ButtonPressMask |
|
2015-01-10 16:59:41 +00:00
|
|
|
ButtonReleaseMask | /* added ButtonReleaseMask *charkins*/
|
|
|
|
PointerMotionMask |
|
|
|
|
FocusChangeMask |
|
|
|
|
LeaveWindowMask |
|
|
|
|
KeyPressMask | /* Try this to get keyboard working */
|
|
|
|
StructureNotifyMask |
|
|
|
|
EnterWindowMask );
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
/* Store the 'state' of the application for restarting */
|
2015-01-10 16:59:48 +00:00
|
|
|
XSetCommand( display, win, argv, argc );
|
2015-01-10 16:59:41 +00:00
|
|
|
|
|
|
|
/* Window won't ever show up until it is mapped.. then drawn after a */
|
|
|
|
/* ConfigureNotify */
|
|
|
|
XMapWindow( display, win );
|
|
|
|
|
|
|
|
/* Read Configuration File */
|
|
|
|
err_code = read_config();
|
|
|
|
if (err_code) {
|
|
|
|
error_handler(err_code, configfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* X Event Loop */
|
|
|
|
while (1) {
|
|
|
|
XNextEvent(display, &report );
|
|
|
|
switch (report.type) {
|
|
|
|
case Expose:
|
2015-01-10 16:59:48 +00:00
|
|
|
if (report.xexpose.count != 0) {
|
2015-01-10 16:59:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose ) printf("Event: Expose\n");
|
2015-01-10 16:59:41 +00:00
|
|
|
redraw();
|
2015-01-10 16:59:48 +00:00
|
|
|
break;
|
2015-01-10 16:59:41 +00:00
|
|
|
case ConfigureNotify:
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose ) printf("Event: ConfigureNotify\n");
|
2015-01-10 16:59:54 +00:00
|
|
|
/* redraw(); */
|
2015-01-10 16:59:41 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyPress:
|
2015-01-10 16:59:48 +00:00
|
|
|
if (Verbose) printf("Event: Key state: 0x%x Key: 0x%x\n",
|
2015-01-10 16:59:41 +00:00
|
|
|
report.xkey.state, report.xkey.keycode);
|
|
|
|
|
2015-01-10 16:59:54 +00:00
|
|
|
/* ksym = XLookupKeysym(&(report.xkey), report.xkey.state); */
|
2015-01-10 16:59:48 +00:00
|
|
|
/* KeywithMask - this allows Left, middle, and right button functions
|
2015-01-10 16:59:41 +00:00
|
|
|
to be implemented via keyboard */
|
2015-01-10 16:59:45 +00:00
|
|
|
XLookupString(&(report.xkey), buffer, bufsize, &ksym, &compose);
|
2015-01-10 16:59:41 +00:00
|
|
|
if (Verbose) printf("Keysym is: 0x%x\n", (int) ksym);
|
|
|
|
KeywithMask = whichKey(ksym);
|
|
|
|
ExecFunc( KeywithMask );
|
|
|
|
redraw();
|
|
|
|
break;
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
case ButtonPress: /* draw button pressed, don't launch *charkins*/
|
|
|
|
switch (report.xbutton.button) {
|
|
|
|
case Button1:
|
|
|
|
N = whichButton(report.xbutton.x, report.xbutton.y );
|
|
|
|
if ( (N >= 0) && (N <= NUM_BUTTONS) ) {
|
|
|
|
button_pressed = N + LMASK;
|
2015-01-10 16:59:54 +00:00
|
|
|
/* redraw(); */
|
2015-01-10 16:59:41 +00:00
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose )
|
|
|
|
printf("Button 1:x=%d y=%d N=%d\n",
|
|
|
|
report.xbutton.x, report.xbutton.y, N+LMASK);
|
2015-01-10 16:59:41 +00:00
|
|
|
break;
|
|
|
|
case Button2:
|
|
|
|
if (mmouse) {
|
|
|
|
N = whichButton(report.xbutton.x, report.xbutton.y );
|
|
|
|
if ( (N >= 0) && (N <= NUM_BUTTONS) ) {
|
|
|
|
button_pressed = N + MMASK;
|
2015-01-10 16:59:54 +00:00
|
|
|
/* redraw(); */
|
2015-01-10 16:59:41 +00:00
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose )
|
|
|
|
printf("Button 2:x=%d y=%d N=%d\n",
|
2015-01-10 16:59:41 +00:00
|
|
|
report.xbutton.x, report.xbutton.y, N+MMASK);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Button3:
|
|
|
|
N = whichButton(report.xbutton.x, report.xbutton.y );
|
|
|
|
if ( (N >= 0) && (N <= NUM_BUTTONS) ) {
|
|
|
|
button_pressed = N + RMASK;
|
2015-01-10 16:59:54 +00:00
|
|
|
/* redraw(); */
|
2015-01-10 16:59:41 +00:00
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose )
|
|
|
|
printf("Button 3:x=%d y=%d N=%d\n",
|
2015-01-10 16:59:41 +00:00
|
|
|
report.xbutton.x, report.xbutton.y, N+RMASK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ButtonRelease: /* If still over button, it was a real button press */
|
|
|
|
switch (report.xbutton.button) {
|
|
|
|
case Button1:
|
|
|
|
N = whichButton(report.xbutton.x, report.xbutton.y );
|
|
|
|
if ( (N >= 0) && (N <= NUM_BUTTONS) && (N == button_pressed - LMASK))
|
|
|
|
ExecFunc(N + LMASK);
|
|
|
|
button_pressed=-1;
|
|
|
|
redraw();
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose )
|
|
|
|
printf("Button 1:x=%d y=%d N=%d\n",
|
|
|
|
report.xbutton.x, report.xbutton.y, N+LMASK);
|
2015-01-10 16:59:41 +00:00
|
|
|
break;
|
|
|
|
case Button2:
|
|
|
|
if (mmouse) {
|
|
|
|
N = whichButton(report.xbutton.x, report.xbutton.y );
|
|
|
|
if ( (N >= 0) && (N <= NUM_BUTTONS) && (N == button_pressed - MMASK))
|
|
|
|
ExecFunc( N + MMASK);
|
|
|
|
button_pressed=-1;
|
|
|
|
redraw();
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose )
|
|
|
|
printf("Button 2:x=%d y=%d N=%d\n",
|
2015-01-10 16:59:41 +00:00
|
|
|
report.xbutton.x, report.xbutton.y, N+MMASK);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Button3:
|
|
|
|
N = whichButton(report.xbutton.x, report.xbutton.y );
|
|
|
|
if ( (N >= 0) && (N <= NUM_BUTTONS) && (N == button_pressed - RMASK))
|
|
|
|
ExecFunc( N + RMASK);
|
|
|
|
button_pressed=-1;
|
|
|
|
redraw();
|
2015-01-10 16:59:48 +00:00
|
|
|
if ( Verbose )
|
|
|
|
printf("Button 3:x=%d y=%d N=%d\n",
|
2015-01-10 16:59:41 +00:00
|
|
|
report.xbutton.x, report.xbutton.y, N+RMASK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DestroyNotify:
|
|
|
|
if ( Verbose ) printf("Requested Program Quit.\n");
|
|
|
|
XFreeGC(display, gc);
|
|
|
|
XDestroyWindow(display,win);
|
|
|
|
XDestroyWindow(display,iconwin);
|
|
|
|
XCloseDisplay(display);
|
|
|
|
exit(OKAY);
|
|
|
|
break;
|
2015-01-10 16:59:48 +00:00
|
|
|
case EnterNotify:
|
|
|
|
case LeaveNotify:
|
2015-01-10 16:59:41 +00:00
|
|
|
XSetInputFocus(display, PointerRoot, RevertToParent, CurrentTime);
|
|
|
|
if (Verbose) printf("Focus Change\n");
|
2015-01-10 16:59:48 +00:00
|
|
|
break;
|
2015-01-10 16:59:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (OKAY);
|
|
|
|
} /***** End of main program ***********************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: redraw
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
2015-01-10 16:59:48 +00:00
|
|
|
This function maintains the appearance of the application
|
2015-01-10 16:59:41 +00:00
|
|
|
by copying the "visible" pixmap to the two windows (the withdrawn
|
2015-01-10 16:59:48 +00:00
|
|
|
main window, and the icon window which is the main windows's icon
|
2015-01-10 16:59:41 +00:00
|
|
|
image).
|
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/1/00 Function Header updated
|
|
|
|
****************************************************************/
|
|
|
|
void redraw() {
|
|
|
|
|
|
|
|
XCopyArea(display, template.pixmap, visible.pixmap, gc, 0, 0,
|
2015-01-10 16:59:48 +00:00
|
|
|
template.attributes.width, template.attributes.height, 0, 0 );
|
2015-01-10 16:59:41 +00:00
|
|
|
|
|
|
|
defineButtonRegions();
|
|
|
|
|
|
|
|
/* Copy button to icon */
|
2015-01-10 16:59:48 +00:00
|
|
|
XCopyArea(display, buttons.pixmap, visible.pixmap, gc,
|
2015-01-10 16:59:41 +00:00
|
|
|
1, 1, 53, 40, 6, 20);
|
|
|
|
|
2015-01-10 16:59:48 +00:00
|
|
|
flush_expose( win );
|
2015-01-10 16:59:41 +00:00
|
|
|
XCopyArea(display, visible.pixmap, win, gc, 0, 0,
|
2015-01-10 16:59:48 +00:00
|
|
|
visible.attributes.width, visible.attributes.height, 0, 0 );
|
|
|
|
flush_expose( iconwin );
|
2015-01-10 16:59:41 +00:00
|
|
|
XCopyArea(display, visible.pixmap, iconwin, gc, 0, 0,
|
|
|
|
visible.attributes.width, visible.attributes.height, 0, 0 );
|
2015-01-10 16:59:54 +00:00
|
|
|
/* if ( Verbose ) printf("In Redraw()\n"); */
|
2015-01-10 16:59:41 +00:00
|
|
|
displaystr();
|
|
|
|
} /***** End of function redraw() ********************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: whichButton
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
Return the button at the x,y coordinates. The button need not
|
|
|
|
be visible ( drawn ). Return -1 if no button match.
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
Change History:
|
|
|
|
Date Modification
|
2015-01-10 16:59:48 +00:00
|
|
|
11/1/00 Function Header Updated
|
2015-01-10 16:59:41 +00:00
|
|
|
****************************************************************/
|
|
|
|
int whichButton( int x, int y ) {
|
|
|
|
int index;
|
|
|
|
|
|
|
|
for ( index=0; index < NUM_BUTTONS; index++ ) {
|
|
|
|
if ( (x >= button_region[index].x) && (x <= button_region[index].i) &&
|
|
|
|
(y >= button_region[index].y) && (y <= button_region[index].j) ) {
|
|
|
|
return(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(NO_BUTTON);
|
|
|
|
} /***** End of function whichButton() **************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: whichKey
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
This function decodes the keycode passed in and converts this to
|
|
|
|
a function number to execute. This is not simply the Button number,
|
|
|
|
but also contains the LMASK, MMASK, or RMASK to pass into ExecFunc to
|
|
|
|
handle expanded functions.
|
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
01/17/01 Updated to take a KeySym, rather than a KeyCode
|
2015-01-10 16:59:48 +00:00
|
|
|
11/09/00 Original Function creation
|
2015-01-10 16:59:41 +00:00
|
|
|
****************************************************************/
|
|
|
|
int whichKey (KeySym keysym) {
|
|
|
|
extern int Verbose;
|
|
|
|
int func = NO_BUTTON;
|
|
|
|
|
|
|
|
if (Verbose) printf("KeySym 0x%x received, decoding...\n", (int) keysym);
|
|
|
|
|
|
|
|
switch(keysym) {
|
|
|
|
case XK_Escape:
|
|
|
|
case XK_space:
|
|
|
|
case XK_KP_Space:
|
|
|
|
func = LMASK + 0;
|
|
|
|
break;
|
|
|
|
case XK_Delete:
|
|
|
|
func = MMASK + 0;
|
|
|
|
break;
|
|
|
|
case XK_BackSpace:
|
|
|
|
func = RMASK + 0;
|
|
|
|
break;
|
|
|
|
case XK_Return:
|
|
|
|
case XK_KP_Equal:
|
|
|
|
case XK_KP_Enter:
|
|
|
|
case XK_equal:
|
|
|
|
func = LMASK + 19;
|
|
|
|
break;
|
|
|
|
case XK_KP_0:
|
|
|
|
case XK_0:
|
|
|
|
func = LMASK + 17;
|
|
|
|
break;
|
|
|
|
case XK_KP_1:
|
|
|
|
case XK_1:
|
|
|
|
func = LMASK + 12;
|
|
|
|
break;
|
|
|
|
case XK_KP_2:
|
|
|
|
case XK_2:
|
|
|
|
func = LMASK + 13;
|
|
|
|
break;
|
|
|
|
case XK_KP_3:
|
|
|
|
case XK_3:
|
|
|
|
func = LMASK + 14;
|
|
|
|
break;
|
|
|
|
case XK_KP_4:
|
|
|
|
case XK_4:
|
|
|
|
func = LMASK + 7;
|
|
|
|
break;
|
|
|
|
case XK_KP_5:
|
|
|
|
case XK_5:
|
|
|
|
func = LMASK + 8;
|
|
|
|
break;
|
|
|
|
case XK_KP_6:
|
|
|
|
case XK_6:
|
|
|
|
func = LMASK + 9;
|
|
|
|
break;
|
|
|
|
case XK_KP_7:
|
|
|
|
case XK_7:
|
|
|
|
func = LMASK + 2;
|
|
|
|
break;
|
|
|
|
case XK_KP_8:
|
|
|
|
case XK_8:
|
|
|
|
func = LMASK + 3;
|
|
|
|
break;
|
|
|
|
case XK_KP_9:
|
|
|
|
case XK_9:
|
|
|
|
func = LMASK + 4;
|
|
|
|
break;
|
|
|
|
case XK_KP_Decimal:
|
|
|
|
case XK_period:
|
|
|
|
func = LMASK + 18;
|
|
|
|
break;
|
|
|
|
case XK_KP_Divide:
|
|
|
|
case XK_slash:
|
|
|
|
func = LMASK + 5;
|
|
|
|
break;
|
|
|
|
case XK_KP_Subtract:
|
|
|
|
case XK_minus:
|
|
|
|
func = LMASK + 15;
|
|
|
|
break;
|
|
|
|
case XK_KP_Multiply:
|
|
|
|
case XK_asterisk:
|
|
|
|
func = LMASK + 10;
|
|
|
|
break;
|
|
|
|
case XK_KP_Add:
|
|
|
|
case XK_plus:
|
|
|
|
func = LMASK + 20;
|
|
|
|
break;
|
|
|
|
case XK_R:
|
|
|
|
case XK_r:
|
|
|
|
func = LMASK + 1;
|
|
|
|
break;
|
|
|
|
case XK_asciicircum:
|
|
|
|
func = LMASK + 6;
|
|
|
|
break;
|
|
|
|
case XK_C:
|
|
|
|
case XK_c:
|
|
|
|
func = LMASK + 11;
|
|
|
|
break;
|
|
|
|
case XK_N:
|
|
|
|
case XK_n:
|
|
|
|
func = LMASK + 16;
|
|
|
|
break;
|
|
|
|
case XK_F1:
|
|
|
|
func = MMASK + 12;
|
|
|
|
break;
|
|
|
|
case XK_F2:
|
|
|
|
func = MMASK + 13;
|
|
|
|
break;
|
|
|
|
case XK_F3:
|
|
|
|
func = MMASK + 14;
|
|
|
|
break;
|
|
|
|
case XK_F4:
|
|
|
|
func = MMASK + 7;
|
|
|
|
break;
|
|
|
|
case XK_F5:
|
|
|
|
func = MMASK + 8;
|
|
|
|
break;
|
|
|
|
case XK_F6:
|
|
|
|
func = MMASK + 9;
|
|
|
|
break;
|
|
|
|
case XK_F7:
|
|
|
|
func = MMASK + 2;
|
|
|
|
break;
|
|
|
|
case XK_F8:
|
|
|
|
func = MMASK + 3;
|
|
|
|
break;
|
|
|
|
case XK_F9:
|
|
|
|
func = MMASK + 4;
|
|
|
|
break;
|
|
|
|
case XK_F10:
|
|
|
|
func = MMASK + 17;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (Verbose) printf("Unknown Keysym, ignoring.\n");
|
|
|
|
func = NO_BUTTON;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return(func);
|
|
|
|
} /***** End of function whichKey() ****************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: getPixmaps
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
Load XPM data into X Pixmaps.
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
* Pixmap 'template' contains the untouched window backdrop image.
|
|
|
|
* Pixmap 'visible' is the template pixmap with buttons drawn on it.
|
|
|
|
-- what is seen by the user.
|
|
|
|
* Pixmap 'buttons' holds the images for individual buttons that are
|
|
|
|
later copied onto Pixmap visible.
|
|
|
|
* Pixmap 'charmap' holds the character map for the characters in
|
|
|
|
the display.
|
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/1/00 Function Header Updated
|
|
|
|
****************************************************************/
|
|
|
|
void getPixmaps() {
|
|
|
|
template.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
|
|
|
|
visible.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
|
|
|
|
buttons.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
|
|
|
|
charmap.attributes.valuemask |= (XpmReturnPixels | XpmReturnExtensions);
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
/* Template Pixmap. Never Drawn To. */
|
|
|
|
if ( XpmCreatePixmapFromData( display, rootwin, backdrop_xpm,
|
2015-01-10 16:59:48 +00:00
|
|
|
&template.pixmap, &template.mask,
|
2015-01-10 16:59:41 +00:00
|
|
|
&template.attributes) != XpmSuccess ) {
|
|
|
|
error_handler(ERR_CREATE_PIXMAP, "template");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Visible Pixmap. Copied from template Pixmap and then drawn to. */
|
|
|
|
if ( XpmCreatePixmapFromData( display, rootwin, backdrop_xpm,
|
2015-01-10 16:59:48 +00:00
|
|
|
&visible.pixmap, &visible.mask,
|
2015-01-10 16:59:41 +00:00
|
|
|
&visible.attributes) != XpmSuccess ) {
|
|
|
|
error_handler(ERR_CREATE_PIXMAP, "visible");
|
|
|
|
}
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
/* Button Pixmap. */
|
|
|
|
if ( XpmCreatePixmapFromData( display, rootwin, calcbuttons_xpm,
|
2015-01-10 16:59:48 +00:00
|
|
|
&buttons.pixmap, &buttons.mask,
|
2015-01-10 16:59:41 +00:00
|
|
|
&buttons.attributes) != XpmSuccess ) {
|
|
|
|
error_handler(ERR_CREATE_PIXMAP, "buttons");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Character Map Pixmap. */
|
|
|
|
if ( XpmCreatePixmapFromData( display, rootwin, charmap_xpm,
|
2015-01-10 16:59:48 +00:00
|
|
|
&charmap.pixmap, &charmap.mask,
|
2015-01-10 16:59:41 +00:00
|
|
|
&charmap.attributes) != XpmSuccess ) {
|
|
|
|
error_handler(ERR_CREATE_PIXMAP, "charmap");
|
|
|
|
}
|
|
|
|
} /***** End of function getPixmaps() *****************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: flush_expose
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
2015-01-10 16:59:48 +00:00
|
|
|
This function is a hold-over from previous programs (wmcp).
|
2015-01-10 16:59:41 +00:00
|
|
|
The use of this function is not well understood.
|
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/1/00 Function header updated.
|
|
|
|
****************************************************************/
|
|
|
|
int flush_expose(Window w) {
|
|
|
|
XEvent dummy;
|
|
|
|
int i=0;
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
while (XCheckTypedWindowEvent(display, w, Expose, &dummy)) i++;
|
|
|
|
return(i);
|
|
|
|
} /***** End of function flush_expose() *************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: defineButtonRegion
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
This function defines the start and end x and y coordinates for
|
2015-01-10 16:59:48 +00:00
|
|
|
the various buttons used in wmcalc.
|
2015-01-10 16:59:41 +00:00
|
|
|
|
2015-01-10 16:59:48 +00:00
|
|
|
There should be a better way to do this, as right now, changing
|
|
|
|
the pixmap calcbuttons.xpm may require the modification of these
|
2015-01-10 16:59:41 +00:00
|
|
|
magic numbers.
|
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/1/00 Function header updated
|
|
|
|
****************************************************************/
|
|
|
|
void defineButtonRegions(void) {
|
|
|
|
int ndx = 0; /* button index */
|
|
|
|
|
2015-01-10 16:59:54 +00:00
|
|
|
button_region[0].x = 1; /* Define display region button */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[0].i = 62;
|
|
|
|
button_region[0].y = 6;
|
|
|
|
button_region[0].j = 17;
|
|
|
|
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 1; ndx <= 5; ndx++) { /* Define y coord's for top row */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].y = 20;
|
|
|
|
button_region[ndx].j = 29;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 6; ndx <= 10; ndx++) { /* Define y coord's for 2nd row */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].y = 30;
|
|
|
|
button_region[ndx].j = 39;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 11; ndx <= 15; ndx++) { /* Define y coord's for 3rd row */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].y = 40;
|
|
|
|
button_region[ndx].j = 49;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 16; ndx <= 20; ndx++) { /* Define y coord's for bottom row */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].y = 50;
|
|
|
|
button_region[ndx].j = 59;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 1; ndx <= 16; ndx+=5) { /* Define x coord's for Left column */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].x = 5;
|
|
|
|
button_region[ndx].i = 16;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 2; ndx <= 17; ndx+=5) { /* Define x coord's for 2nd Left column */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].x = 17;
|
|
|
|
button_region[ndx].i = 26;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 3; ndx <= 18; ndx+=5) { /* Define x coord's for middle column */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].x = 27;
|
|
|
|
button_region[ndx].i = 36;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 4; ndx <= 19; ndx+=5) { /* Define x coord's for 2nd right column */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].x = 37;
|
|
|
|
button_region[ndx].i = 46;
|
|
|
|
}
|
2015-01-10 16:59:54 +00:00
|
|
|
for (ndx = 5; ndx <= 20; ndx+=5) { /* Define x coord's for 2nd right column */
|
2015-01-10 16:59:41 +00:00
|
|
|
button_region[ndx].x = 47;
|
|
|
|
button_region[ndx].i = 57;
|
|
|
|
}
|
|
|
|
} /***** End of function defineButtonRgions() *************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: displaychar
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
This function displays individual characters to the "display".
|
2015-01-10 16:59:48 +00:00
|
|
|
This function should only be called from displaystr().
|
2015-01-10 16:59:41 +00:00
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/09/00 Added "Locked" character and capabilities
|
|
|
|
11/01/00 Function header updated
|
|
|
|
10/30/00 Updated to include the memory indicators as well.
|
|
|
|
****************************************************************/
|
|
|
|
void displaychar(char ch, int location) {
|
|
|
|
ButtonArea dispchar;
|
|
|
|
int locatx, locaty;
|
|
|
|
|
|
|
|
dispchar = getboundaries(ch); /* Get the region of the charmap
|
|
|
|
containing the character to
|
|
|
|
display */
|
|
|
|
|
2015-01-10 16:59:48 +00:00
|
|
|
locaty = 6;
|
2015-01-10 16:59:41 +00:00
|
|
|
locatx = 2 + location * 6;
|
|
|
|
|
|
|
|
/* If the character is a memory display character, use the memory
|
|
|
|
location display region. Valid Characters are:
|
|
|
|
'_' - No data in Memory Location
|
|
|
|
'=' - Value in Memory Location, Not Locked
|
2015-01-10 16:59:48 +00:00
|
|
|
'#' - Constant in Memory Location, Locked
|
2015-01-10 16:59:41 +00:00
|
|
|
*/
|
2015-01-10 16:59:48 +00:00
|
|
|
if ((ch == '=') || (ch == '_') || ch == '#') {
|
|
|
|
locaty = 15;
|
2015-01-10 16:59:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 16:59:48 +00:00
|
|
|
XCopyArea(display, charmap.pixmap, win, gc,
|
|
|
|
dispchar.x, dispchar.y,
|
|
|
|
dispchar.i-dispchar.x, dispchar.j-dispchar.y,
|
2015-01-10 16:59:41 +00:00
|
|
|
locatx, locaty);
|
2015-01-10 16:59:48 +00:00
|
|
|
XCopyArea(display, charmap.pixmap, iconwin, gc,
|
|
|
|
dispchar.x, dispchar.y,
|
|
|
|
dispchar.i-dispchar.x, dispchar.j-dispchar.y,
|
2015-01-10 16:59:41 +00:00
|
|
|
locatx, locaty);
|
|
|
|
|
|
|
|
} /***** End of Function displaychar() **************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: displaystr
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
2015-01-10 16:59:48 +00:00
|
|
|
|
2015-01-10 16:59:41 +00:00
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/09/00 Added Capabilities for "Locked" memories
|
|
|
|
11/01/00 Function header updated
|
|
|
|
10/30/00 Added memory location indicators
|
|
|
|
****************************************************************/
|
|
|
|
void displaystr(void) {
|
|
|
|
extern char DispString[];
|
|
|
|
extern int MemLock[];
|
|
|
|
extern double MemArray[];
|
|
|
|
extern int Verbose;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (Verbose) printf("Displaystr %s\n", DispString);
|
|
|
|
|
|
|
|
/* Update the alphanumeric display */
|
|
|
|
for (i = 0; i < DISPSIZE; i++)
|
|
|
|
displaychar(DispString[i], i);
|
|
|
|
|
|
|
|
/* Update the memory location indicators */
|
|
|
|
for (i = 0; i < NUM_MEM_CELLS; i++) {
|
|
|
|
if (MemArray[i] == 0.0)
|
|
|
|
displaychar('_', i); /* Value NOT stored here */
|
2015-01-10 16:59:48 +00:00
|
|
|
else if (MemLock[i] == 0)
|
2015-01-10 16:59:41 +00:00
|
|
|
displaychar('=', i); /* Value IS stored here */
|
|
|
|
else
|
|
|
|
displaychar('#', i); /* Constant IS stored here */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} /***** End of function displaystr() ***************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: show_usage
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
2015-01-10 16:59:48 +00:00
|
|
|
This function prints a brief usage message to stdout,
|
2015-01-10 16:59:41 +00:00
|
|
|
and exits.
|
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/01/00 Function header updated
|
|
|
|
****************************************************************/
|
|
|
|
void show_usage(void) {
|
|
|
|
|
|
|
|
printf("\n");
|
2018-09-10 23:53:30 +00:00
|
|
|
printf(" %s %s\n",app_name, PACKAGE_VERSION);
|
2015-01-10 16:59:41 +00:00
|
|
|
printf("\n");
|
|
|
|
printf("usage: %s [-g geometry] [-d display] [-f <filename>] [-v] [-h] \n",
|
|
|
|
app_name);
|
|
|
|
printf("\n");
|
|
|
|
printf("-g <geometry> Window Geometry - ie: 64x64+10+10\n");
|
2015-01-10 16:59:48 +00:00
|
|
|
printf("-d <display> Display - ie: 127.0.0.1:0.0\n");
|
2015-01-10 16:59:41 +00:00
|
|
|
printf("-f <filename> Name of Config file - ie: /home/user/.wmcalc\n");
|
|
|
|
printf("-v Verbose Mode. \n");
|
|
|
|
printf("-h Help. This message.\n");
|
|
|
|
printf("\n");
|
|
|
|
exit(OKAY);
|
|
|
|
} /***** End of function show_usage() ***************************/
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Function: error_handler
|
|
|
|
****************************************************************
|
|
|
|
Description:
|
|
|
|
This function will handle all fatal error conditions that exist.
|
|
|
|
Error condition codes are kept in wmcalc_err.h
|
|
|
|
|
|
|
|
Change History:
|
|
|
|
Date Modification
|
|
|
|
11/1/00 Function created
|
|
|
|
****************************************************************/
|
|
|
|
void error_handler (int err_code, char *err_string) {
|
|
|
|
extern char tempfile[];
|
|
|
|
|
|
|
|
if (err_code == OKAY) {
|
2015-01-10 16:59:48 +00:00
|
|
|
/* This case should never happen.
|
|
|
|
If it does, somebody screwed up (probably me),
|
2015-01-10 16:59:41 +00:00
|
|
|
but don't kill the program!! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "Error Code %d: ", err_code);
|
|
|
|
switch (err_code) {
|
|
|
|
case ERR_FILE_NOT_FOUND:
|
|
|
|
fprintf(stderr, "Could not open file %s\n",configfile);
|
|
|
|
break;
|
|
|
|
case ERR_TMP_FILE_FAILED:
|
|
|
|
fprintf(stderr, "Could not open temporary file %s\n", tempfile);
|
2015-01-10 16:59:48 +00:00
|
|
|
break;
|
|
|
|
case ERR_X_CREATE_WINDOW:
|
|
|
|
fprintf(stderr, "Could not create simple window\n");
|
2015-01-10 16:59:41 +00:00
|
|
|
break;
|
|
|
|
case ERR_X_CREATE_BITMAP:
|
|
|
|
fprintf(stderr, "Could not create bitmap from data\n");
|
|
|
|
break;
|
|
|
|
case ERR_SETUP_WINDOW_NAME:
|
|
|
|
fprintf(stderr, "Could not setup window name %s\n", err_string);
|
|
|
|
break;
|
|
|
|
case ERR_CREATE_GC:
|
|
|
|
fprintf(stderr, "XCreateGC\n");
|
|
|
|
break;
|
|
|
|
case ERR_X_DISPLAY:
|
|
|
|
fprintf(stderr, "Could not open display on %s\n", err_string);
|
|
|
|
break;
|
|
|
|
case ERR_CREATE_PIXMAP:
|
|
|
|
fprintf(stderr, "Can't Create %s Pixmap\n", err_string);
|
|
|
|
break;
|
|
|
|
/* case : */
|
|
|
|
/* break; */
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unknown Error\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(err_code);
|
|
|
|
} /***** End of Function error_handler **************************/
|