dslinux/user/pixil/apps/nanox/keyboard Makefile bmptools.c bmptools.h buildmap.c cli.c cli.h filetools.c filetools.h header.h keymap.c keymap.h nxkeyboard.c srvconn.c
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:42:54 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/apps/nanox/keyboard
In directory antilope:/tmp/cvs-serv22795/user/pixil/apps/nanox/keyboard
Added Files:
Makefile bmptools.c bmptools.h buildmap.c cli.c cli.h
filetools.c filetools.h header.h keymap.c keymap.h
nxkeyboard.c srvconn.c
Log Message:
Pixil: add some forgotten files
--- NEW FILE: buildmap.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/*
**
** Imported "Include" Files
**
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "bmptools.h"
/*
**
** Local Constant Definitions
**
*/
#define HEADERSTR1 "************************************************************************\n"
#define HEADERSTR2 "* nxkeyboard map file automatically generated by 'buildmap' *\n"
#define HEADERSTR3 "* *\n"
/*
**
** Local Enumeration Definitions
**
*/
/*
**
** Local Structure Definitions
**
*/
typedef struct
{
int x;
int y;
}
Point;
typedef struct
{
Point upperleft;
Point lowerright;
}
Rect;
/*
**
** Local Variable Declarations
**
*/
char *(header[]) =
{
NULL};
/*
**
** The following function will recover the pixel value for the specified
** x,y position.
**
** If the pixel is black, '0' is returned. If the pixel is white, '1' is
** returned. If an error occurs, a negative value is returned.
**
*/
static int
getPixel(BmpHandle * handle, int xpos, int ypos)
{
BmpColor color;
int result;
// recover the pixel
result = bmpGetPixel(handle, xpos, ypos, &color);
if (result)
return (-1);
// printf("%d,%d: %d,%d,%d\n",xpos,ypos,color.red,color.green,color.blue);
// check for black pixel
if ((color.red == 255) && (color.green == 255) && (color.blue == 255))
return (1);
// chcek for black pixel
if ((color.red == 0) && (color.green == 0) && (color.blue == 0))
return (0);
// unknown pixel
return (-2);
}
/*
**
** The following function will parse the entire image, looking for the next
** white pixel. The function will parse all scan lines in the image.
**
** If successful, '0' is returned and the pixel position is saved at "result".
** If the end of the image is found, '1' is returned. If an error occurs, a
** negative value is returned.
**
*/
static int
findWhitePixel(BmpHandle * handle, int xpos, int ypos, Point * result)
{
int res;
// locate the next black pixel
while (1) {
res = getPixel(handle, xpos, ypos);
if (res < 0)
return (res);
if (res == 0)
break;
if (++xpos >= handle->info.width) {
xpos = 0;
if (++ypos >= handle->info.height)
return (1);
}
}
// locate the next white pixel
while (1) {
res = getPixel(handle, xpos, ypos);
if (res < 0)
return (res);
if (res == 1)
break;
if (++xpos >= handle->info.width) {
xpos = 0;
if (++ypos >= handle->info.height)
return (1);
}
}
// save result
result->x = xpos;
result->y = ypos;
// exit with no errors
return (0);
}
/*
**
** The following function will parse the image, looking for the next white
** pixel on this row. The function will only parse the width of the image.
**
** If successful, '0' is returned and the pixel position is saved at "result".
** If the end of the row is found, '1' is returned. If an error occurs, a
** negative value is returned.
**
*/
static int
findNextWhitePixel(BmpHandle * handle, int xpos, int ypos, Point * result)
{
int res;
// find the next black pixel
while (1) {
res = getPixel(handle, xpos, ypos);
if (res < 0)
return (res);
if (res == 0)
break;
if (++xpos >= handle->info.width)
return (1);
}
// find the next white pixel
while (1) {
res = getPixel(handle, xpos, ypos);
if (res < 0)
return (res);
if (res == 1)
break;
if (++xpos >= handle->info.width)
return (1);
}
// save result
result->x = xpos;
result->y = ypos;
// exit with no errors
return (0);
}
/*
**
** The following function will recover a rectangle that specifies the area
** covered by a key.
**
** If successful, '0' is returned and the key area is stored at "result".
** If an error occurrs, a negative value is returned.
**
*/
static int
findCorners(BmpHandle * handle, int xpos, int ypos, Rect * result)
{
int res;
// make sure the pixel is white
res = getPixel(handle, xpos, ypos);
if (res < 0)
return (res);
if (res != 1)
return (-100);
// make sure the pixel is on a left edge
while (1) {
res = getPixel(handle, xpos - 1, ypos);
if (res < 0)
return (res);
if (res == 0)
break;
--xpos;
}
// make sure the pixel is on a top edge
while (1) {
res = getPixel(handle, xpos, ypos - 1);
if (res < 0)
return (res);
if (res == 0)
break;
--ypos;
}
// save the top and left edges
result->upperleft.x = xpos;
result->upperleft.y = ypos;
// find the right edge
while (1) {
res = getPixel(handle, xpos + 1, ypos);
if (res < 0)
return (res);
if (res == 0)
break;
++xpos;
}
// find the bottom edge
while (1) {
res = getPixel(handle, xpos, ypos + 1);
if (res < 0)
return (res);
if (res == 0)
break;
++ypos;
}
// save the right and bottom edges
result->lowerright.x = xpos;
result->lowerright.y = ypos;
// exit with no errors
return (0);
}
/*
**
**
**
*/
static int
stripExtension(char *str, char *result)
{
int index;
// create a copy of the string
strcpy(result, str);
// remove the extension
index = strlen(result) - 1;
while (index >= 0) {
if (*(result + index) == '.')
break;
--index;
}
// modify result
if (index < 0)
*result = 0x00;
else
*(result + index + 1) = 0x00;
// exit with no errors
return (0);
}
/*
**
**
**
*/
int
main(int argc, char *argv[])
{
FILE *fp;
BmpColor pixel;
BmpHandle *handle;
Point point;
Rect rect;
char buf1[1024], buf2[1024];
int count, keycnt, result, rowcnt, tkeys, trows, xref, yref;
time_t tval;
// open and load the BMP image
handle = bmpLoadImage(argv[1]);
if (handle == NULL) {
printf("Unable to open \"%s\"...\n", argv[1]);
return (-1);
}
// display image information
printf("\nProcessing %s:\n", argv[1]);
if (handle->info.bits_per_pixel == 1)
printf(" %d x %d monochrome image\n",
handle->info.width, handle->info.height);
else if (handle->info.bits_per_pixel == 4)
printf(" %d x %d 16 color image\n",
handle->info.width, handle->info.height);
else if (handle->info.bits_per_pixel == 8)
printf(" %d x %d 256 color image\n",
handle->info.width, handle->info.height);
else if (handle->info.bits_per_pixel == 16)
printf(" %d x %d 65536 color image\n",
handle->info.width, handle->info.height);
else if (handle->info.bits_per_pixel == 24)
printf(" %d x %d 16777216 color image\n",
handle->info.width, handle->info.height);
// display the palette information
count = 0;
while (1) {
if (bmpGetPaletteEntry(handle, count, &pixel) != 0)
break;
printf(" Palette%d: R:%3d G:%3d B:%3d\n",
count++, pixel.red, pixel.green, pixel.blue);
}
// create the map file
stripExtension(argv[1], buf1);
strcat(buf1, "map");
if ((fp = fopen(buf1, "w")) == NULL) {
printf("Unable to open \"%s\"\n", buf1);
bmpCloseImage(handle);
return (-2);
}
// write out the map file header
fprintf(fp, HEADERSTR1);
fprintf(fp, HEADERSTR2);
strcpy(buf2, HEADERSTR3);
strncpy(buf2 + 2, "Image File:", 11);
strcpy(buf1, argv[1]);
count = 0;
while (buf1[count])
buf2[count + 14] = buf1[count++];
fprintf(fp, buf2);
strcpy(buf2, HEADERSTR3);
strncpy(buf2 + 2, "Date:", 5);
tval = time(NULL);
strcpy(buf1, ctime(&tval));
buf1[strlen(buf1) - 1] = 0x00;
count = 0;
while (buf1[count])
buf2[count + 14] = buf1[count++];
fprintf(fp, buf2);
fprintf(fp, HEADERSTR1);
fprintf(fp, "\n");
// write out the map file parameters
fprintf(fp, "******************\n");
fprintf(fp, "* Map Parameters *\n");
fprintf(fp, "******************\n");
fprintf(fp,
"parms: #,#,#,#,#,%d,%d |ID,high1,high2,high3,high4,width,height\n",
handle->info.width, handle->info.height);
// process all key areas found in the bitmap
keycnt = rowcnt = 1;
trows = tkeys = 0;
xref = yref = 0;
while (1) {
result = findWhitePixel(handle, xref, yref, &point);
if (result == 1)
break;
if (result) {
printf
("Unable to find a white pixel using %d,%d as a reference\n",
xref, yref);
fclose(fp);
bmpCloseImage(handle);
return (-2);
}
++trows;
fprintf(fp, "\n");
fprintf(fp, "******************\n");
fprintf(fp, "* Row %2d Keymaps *\n", rowcnt);
fprintf(fp, "******************\n");
while (1) {
result = findCorners(handle, point.x, point.y, &rect);
if (result) {
printf("Unable to find corners using %d,%d as a reference.\n",
point.x, point.y);
fclose(fp);
bmpCloseImage(handle);
return (-3);
}
++tkeys;
fprintf(fp, "keymap: #,%d,%d,%d,%d |Row%dKey%d\n",
rect.upperleft.x,
rect.upperleft.y,
rect.lowerright.x, rect.lowerright.y, rowcnt, keycnt++);
fflush(fp);
result = findNextWhitePixel(handle, point.x, point.y, &point);
if (result < 0) {
printf
("Unable to find next white pixel using %d,%d as a reference\n.",
point.x, point.y);
fclose(fp);
bmpCloseImage(handle);
return (-4);
}
if (result == 1) {
keycnt = 1;
++rowcnt;
xref = 0;
yref = rect.lowerright.y + 1;
break;
}
}
}
// add multikey header
fprintf(fp, "\n***********************\n");
fprintf(fp, "* Multikey Extensions *\n");
fprintf(fp, "***********************\n");
// display final totals
printf(" Located %d keyrows, generated %d keymaps\n", trows, tkeys);
printf(" Complete!\n\n");
// do housekeeping
fclose(fp);
bmpCloseImage(handle);
// exit with no errors
return (0);
}
--- NEW FILE: header.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/***********************************************************************
* *
* COPYRIGHT (c) 2000 Century Software All Rights Reserved *
* *
* This software is the property of Century Software and shall not be *
* reproduced or copied in whole or used in whole or in part as the *
* basis for the manufacture or sale of items, nor shall such copy be *
* sold or constitute part of a sale without written permission. *
* *
* RESTRICTED RIGHTS LEGEND *
* *
* Use, duplication, or disclosure by the government is subject to *
* restriction as set forth in paragraph (b)(3)(b) of the Rights in *
* Technical Data and Computer Software clause in DAR 7-104.9(a). *
* *
* CENTURY SOFTWARE *
* 5284 SOUTH 320 WEST - SUITE C-134 *
* MURRAY, UTAH 84107 *
* *
************************************************************************
* *
* FILENAME: *
* *
***********************************************************************/
#ifndef
#define
/*
**
** Imported "Include" Files
**
*/
/*
**
** Global Constant Definitions
**
*/
/*
**
** Global Enumeration Definitions
**
*/
/*
**
** Global Structure Definitions
**
*/
/*
**
** Global Variable Declarations
**
*/
/*
**
** NAME:
**
** USAGE:
**
** DESCR:
**
** PARMS:
**
** RETRN:
**
** NOTES:
**
*/
#endif /* */
--- NEW FILE: srvconn.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/* Copyright (C) 2000 by VTech Informations LTD.
* Vladimir Cotfas <vladimircotfas at vtech.ca> Aug 31, 2000
*/
#include <unistd.h>
#include <fcntl.h>
#include "nano-X.h"
#define KBDPIPE 0 /* =1 to use named pipe for soft kbd */
#if KBDPIPE
static char KBD_NAMED_PIPE[] = "/tmp/.nano-X-softkbd";
static int kbd_fd = -1;
int
KbdOpen(void)
{
if (kbd_fd != -1)
close(kbd_fd);
if ((kbd_fd = open(KBD_NAMED_PIPE, O_WRONLY)) < 0)
return -1;
return kbd_fd;
}
void
KbdClose(void)
{
if (kbd_fd >= 0) {
close(kbd_fd);
kbd_fd = -1;
}
}
int
KbdWrite(int c)
{
char cc = c & 0xff;
return write(kbd_fd, &cc, 1);
}
#else /* !KBDPIPE */
int
KbdOpen(void)
{
return 0;
}
void
KbdClose(void)
{
}
int
KbdWrite(int c)
{
GR_WINDOW_ID win = GrGetFocus();
/* FIXME: modifiers are incorrect */
GrInjectKeyboardEvent(win, c, 0, 0, 1);
GrInjectKeyboardEvent(win, c, 0, 0, 0);
return 1;
}
#endif /* KBDPIPE */
--- NEW FILE: Makefile ---
#nanox/keyboard/Makefile
# Note: We only install for one keyboard to cut down
# on space usage. It is unfortunately that we have to
# use .bmp files, but thats the way the cookie crumbles
KEYMAP_PREFIX=com
TARGET=nxkeyboard
OBJS=cli.o filetools.o keymap.o nxkeyboard.o srvconn.o
INSTALL_EXTRAS=inst-keymaps
LIBS+=-lwm -lnano-X
ifeq ($(CONFIG_COLOSSEUM),y)
LIBS+=-lipc
endif
include $(BASE_DIR)/Rules.make
inst-keymaps:
mkdir -p $(INSTALL_DIR)/share/keymaps
cp -af keymaps/$(KEYMAP_PREFIX)* $(INSTALL_DIR)/share/keymaps
--- NEW FILE: nxkeyboard.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/*
**
** Imported "Include" Files
**
*/
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "cli.h"
#include "filetools.h"
#include "keymap.h"
#include <nano-X.h>
#include <wm/nxlib.h>
/*
**
** External Declarations
**
*/
extern int KbdOpen(void);
extern int KbdWrite(int);
/*
**
** Local Constant Definitions
**
*/
#define FLASH_DELAY 100000
#define MAX_KEYMAPS 32
/*
**
** Local Enumeration Definitions
**
*/
/*
**
** Local Structure Definitions
**
*/
/*
**
** Local Variable Declarations
**
*/
static nxARGS nxargs[] = {
{nxtypeTITLE | nxSTR, "-title", "Popup Keyboard"},
{nxtypeGEOMETRY | nxINT, "-geom", "32x32+0-0"},
{nxtypeBACKGROUND | nxINT, "-background", (char *) GR_COLOR_WINDOW},
{nxtypeSTYLE | nxINT, "-style", (char *) (GR_WM_PROPS_NOFOCUS |
GR_WM_PROPS_NOAUTOMOVE |
GR_WM_PROPS_APPFRAME)},
{0, NULL, NULL}
};
static GR_GC_ID gc;
static GR_WINDOW_ID w;
static KeymapHandle *keymaps[MAX_KEYMAPS];
static GR_IMAGE_ID images[MAX_KEYMAPS];
static GR_PIXELVAL *pixels;
static int current_map;
static int old_map;
static int extra_width, extra_height;
static char cpGeom[32 + 1];
/*
**
** This function will invert the image of the specified area.
**
*/
static int
invertArea(int ulx, int uly, int lrx, int lry)
{
int count, height, size, width;
// read the affected area
width = (lrx - ulx) + 1;
height = (lry - uly) + 1;
GrReadArea(w, ulx, uly, width, height, pixels);
// invert the pixels
size = width * height;
count = 0;
do {
if (pixels[count] == 0)
pixels[count] = 0xffffff;
else
pixels[count] = 0x000000;
} while (++count < size);
// write out the affected area
GrArea(w, gc, ulx, uly, width, height, pixels, 0);
// exit with no errors
return (0);
}
/*
**
** This function will invert the image of the specified key.
**
*/
static int
invertKey(int keynum)
{
KeymapEntry *kentry;
kentry = keymaps[current_map]->keys + keynum;
invertArea(kentry->ulx, kentry->uly, kentry->lrx, kentry->lry);
return (0);
}
/*
**
**
**
*/
static int
updateWindow(void)
{
GR_WINDOW_INFO pinfo, winfo;
GrGetWindowInfo(w, &winfo);
if (winfo.parent != GR_ROOT_WINDOW_ID) {
if (extra_width == -1) {
GrGetWindowInfo(winfo.parent, &pinfo);
extra_width = pinfo.width - winfo.width;
extra_height = pinfo.height - winfo.height;
}
if ((winfo.width != keymaps[current_map]->width) ||
(winfo.height != keymaps[current_map]->height)) {
GrResizeWindow(winfo.parent,
keymaps[current_map]->width + extra_width,
keymaps[current_map]->height + extra_height);
GrFlush();
}
}
GrDrawImageToFit(w, gc, 0, 0, -1, -1, images[current_map]);
if (keymaps[current_map]->highlight1 != -1)
invertKey(keymaps[current_map]->highlight1);
if (keymaps[current_map]->highlight2 != -1)
invertKey(keymaps[current_map]->highlight2);
if (keymaps[current_map]->highlight3 != -1)
invertKey(keymaps[current_map]->highlight3);
if (keymaps[current_map]->highlight4 != -1)
invertKey(keymaps[current_map]->highlight4);
return (0);
}
/*
**
**
**
*/
static int
mouseClick(int xpos, int ypos)
{
ExtEntry *eentry;
KeymapEntry *kentry;
int count, index, loop, maxkeys;
maxkeys = keymaps[current_map]->maxkeys;
// check for a keyclick
count = 0;
do {
// recover a pointer to this keymap entry
kentry = keymaps[current_map]->keys + count;
// skip disabled keymap entries
if (kentry->keycode == -1)
continue;
// check for pointer/key intersection
if ((xpos >= kentry->ulx) &&
(xpos <= kentry->lrx) &&
(ypos >= kentry->uly) && (ypos <= kentry->lry)) {
// flash the key
invertArea(kentry->ulx, kentry->uly, kentry->lrx, kentry->lry);
GrFlush();
usleep(FLASH_DELAY);
invertArea(kentry->ulx, kentry->uly, kentry->lrx, kentry->lry);
GrFlush();
// standard keypress
if (kentry->keycode >= 0) {
// scan extensions for keycode match
if (keymaps[current_map]->maxexts > 0) {
loop = 0;
do {
eentry = keymaps[current_map]->exts + loop;
if (kentry->keycode == eentry->keycode) {
index = 0;
while (eentry->str[index])
KbdWrite(eentry->str[index++]);
return (0);
}
} while (++loop < keymaps[current_map]->maxexts);
}
KbdWrite(kentry->keycode);
if (old_map != -1) {
current_map = old_map;
old_map = -1;
updateWindow();
}
return (0);
}
// temporary keymap change
else if ((kentry->keycode <= -2) && (kentry->keycode >= -9)) {
loop = 0;
do {
if (keymaps[loop] != NULL) {
if (keymaps[loop]->mapid == kentry->keycode) {
old_map = current_map;
current_map = loop;
updateWindow();
}
}
} while (++loop < MAX_KEYMAPS);
}
// permanent keymap change
else {
loop = 0;
do {
if (keymaps[loop] != NULL) {
if (keymaps[loop]->mapid == kentry->keycode) {
current_map = loop;
old_map = -1;
updateWindow();
}
}
} while (++loop < MAX_KEYMAPS);
}
}
} while (++count < maxkeys);
return (0);
}
/*
**
**
**
*/
int
main(int argc, char *argv[])
{
DIR *dir;
GR_EVENT event;
KeymapEntry *kentry;
char buf[256], file[256];
int count, keysize, loop, mapid, mapindex, parms, size;
struct dirent *dentry;
// check for usage
if (argc == 1) {
printf("\nnxkeyboard usage:\n");
printf(" nxkeyboard -d /path/to/keymap/dir -m mapset\n\n");
exit(1);
}
// open graphics
if (GrOpen() < 0) {
fprintf(stderr, "nxkeyboard: cannot open graphics\n");
exit(1);
}
// open access to the keyboard
if (KbdOpen() < 0) {
fprintf(stderr, "nxkeyboard: cannot open kbd named pipe.\n");
exit(1);
}
// recover the command line parameters
parms = parseCommandLine(argc, argv);
if (parms != 2) {
fprintf(stderr, "nxkeyboard: incorrect command line parameters.\n");
exit(1);
}
// clear keymap list
count = 0;
do {
keymaps[count] = NULL;
images[count] = 0;
} while (++count < MAX_KEYMAPS);
// open the specified keymap directory
printf("opening directory %s\n", gMapDir);
dir = opendir(gMapDir);
if (dir == NULL) {
fprintf(stderr, "nxkeyboard: unable to load keymaps.\n");
exit(1);
}
// load keymaps
count = 0;
while (1) {
// recover the next directory entry
dentry = readdir(dir);
if (dentry == NULL)
break;
// skip current, parent, and sub directories
if (strcmp(dentry->d_name, ".") == 0)
continue;
if (strcmp(dentry->d_name, "..") == 0)
continue;
// see if this entry matches
strcpy(file, dentry->d_name);
if (strncmp(file, gMapID, strlen(gMapID)) != 0)
continue;
if (strstr(file, ".map") != 0)
continue;
// match found - create keymap filename
*(strstr(file, ".")) = 0x00;
sprintf(buf, "%s/%s.map", gMapDir, file);
keymaps[count] = keymapLoadMap(buf);
if (keymaps[count] == NULL)
continue;
// create imagemap filename
sprintf(buf, "%s/%s.bmp", gMapDir, file);
images[count] = GrLoadImageFromFile(buf, 0);
++count;
}
closedir(dir);
// scan all keymaps - find starting keymap and largest keysize
mapid = -1000000;
mapindex = -1;
keysize = 0;
count = 0;
do {
if (keymaps[count] != NULL) {
if ((keymaps[count]->mapid <= -10)
&& (keymaps[count]->mapid > mapid)) {
mapid = keymaps[count]->mapid;
mapindex = count;
}
loop = 0;
do {
kentry = keymaps[count]->keys + loop;
size =
((kentry->lrx - kentry->ulx) +
1) * ((kentry->lry - kentry->uly) + 1);
if (size > keysize)
keysize = size;
} while (++loop < keymaps[count]->maxkeys);
}
} while (++count < MAX_KEYMAPS);
// check for no maps
if (mapindex < 0) {
fprintf(stderr, "nxkeyboard: no maps or images.\n");
return (0);
}
// allocate memory from the system
pixels = (GR_PIXELVAL *) malloc(keysize * sizeof(GR_PIXELVAL));
if (pixels == NULL) {
fprintf(stderr, "nxkeyboard: not enough memory\n");
return (0);
}
// set defaults
current_map = mapindex;
old_map = -1;
extra_width = extra_height = -1;
/* Set up the geometry to force flush with bottom left corner */
sprintf(cpGeom, "%dX%d+0-0", keymaps[current_map]->width,
keymaps[current_map]->height);
{
int ii = 0;
while (nxargs[ii].type != 0) {
if (nxargs[ii].type & nxtypeGEOMETRY) {
nxargs[ii].defvalue = cpGeom;
break;
} /* end of if */
ii++;
} /* end of while */
} /* end of memory lifetime (ii) */
w = nxCreateAppWindow(&argc, &argv, nxargs);
// enable specific window events
GrSelectEvents(w,
GR_EVENT_MASK_CLOSE_REQ |
GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN);
// display the window
GrMapWindow(w);
GrResizeWindow(w, keymaps[current_map]->width,
keymaps[current_map]->height);
GrFlush();
gc = GrNewGC();
// event loop
while (1) {
GrGetNextEvent(&event);
switch (event.type) {
// close the application
case GR_EVENT_TYPE_CLOSE_REQ:
count = 0;
do {
if (keymaps[count] != NULL)
keymapDeleteMap(keymaps[count]);
if (images[count] != 0)
GrFreeImage(images[count]);
} while (++count < MAX_KEYMAPS);
GrClose();
exit(0);
break;
// redraw the window
case GR_EVENT_TYPE_EXPOSURE:
updateWindow();
break;
// mouse click
case GR_EVENT_TYPE_BUTTON_DOWN:
mouseClick(event.button.x, event.button.y);
break;
}
}
}
--- NEW FILE: cli.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/*
**
** Imported "Include" Files
**
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
**
** Global Variable Declarations
**
*/
char gMapID[256];
char gMapDir[256];
/*
**
** Local Constant Definitions
**
*/
/*
**
** Local Enumeration Definitions
**
*/
/*
**
** Local Structure Definitions
**
*/
typedef struct
{
char *parm_flag; // parameter keyword
void *parm_result; // where to place parameter value
int parm_type; // 0=integer | 1=string | 2=bool
}
ParmEntry;
/*
**
** Local Variable Declarations
**
*/
ParmEntry parm_list[] = {
{"-m", gMapID, 1},
{"-d", gMapDir, 1},
{NULL, NULL, 0}
};
/*
**
** This function will parse the list of command line arguments
** and recover their associated information.
**
** The "argc" parameter specifies the number of arguments found in
** the argv list. The "argv" parameter is a pointer to the array
** of command line arguments.
**
** If successful, the number of command line arguments parsed is
** is returned. If an error occurs during function , a negative
** value is returned.
**
*/
int
parseCommandLine(int argc, char **argv)
{
int count, len = 0, loop, total;
char *arg;
// initialize any bools and strings in the list
loop = 0;
while (1) {
if (parm_list[loop].parm_flag == NULL)
break;
if (parm_list[loop].parm_type == 1)
*((char *) parm_list[loop].parm_result) = 0x00;
if (parm_list[loop].parm_type == 2)
*((int *) parm_list[loop].parm_result) = 0;
++loop;
}
// check for empty list
if (argc <= 1)
return (0);
// locate and process all command line flags
total = 0;
count = 1;
do {
// recover and verify the next entry
arg = *(argv + count);
if (*arg != '-')
continue;
// scan list of valid arguments
loop = 0;
while (1) {
if (parm_list[loop].parm_flag == NULL)
break;
len = strlen(parm_list[loop].parm_flag);
if (strncmp(arg, parm_list[loop].parm_flag, len) == 0)
break;
++loop;
}
// check for no match in list
if (parm_list[loop].parm_flag == NULL)
continue;
// handle integer parameter
if (parm_list[loop].parm_type == 0) {
if (strlen(arg) == len) {
if (++count >= argc)
continue;
*((int *) parm_list[loop].parm_result) =
atoi(*(argv + count));
} else
*((int *) parm_list[loop].parm_result) = atoi(arg + len);
}
// handle string parameter
else if (parm_list[loop].parm_type == 1) {
if (strlen(arg) == len) {
if (++count >= argc)
continue;
strcpy((char *) parm_list[loop].parm_result, *(argv + count));
} else
strcpy((char *) parm_list[loop].parm_result, arg + len);
}
// handle boolean parameter
else if (parm_list[loop].parm_type == 2)
*((int *) parm_list[loop].parm_result) = 1;
// bump the keyword counter
++total;
} while (++count < argc);
// exit with no errors
return (total);
}
--- NEW FILE: keymap.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef KEYMAP_H
#define KEYMAP_H
/*
**
** Imported "Include" Files
**
*/
/*
**
** Global Constant Definitions
**
*/
#define MAXEXTLEN 16
/*
**
** Global Enumeration Definitions
**
*/
/*
**
** Global Structure Definitions
**
*/
typedef struct
{
int ulx;
int uly;
int lrx;
int lry;
int keycode;
}
KeymapEntry;
typedef struct
{
int keycode;
char str[MAXEXTLEN];
}
ExtEntry;
typedef struct
{
int mapid;
int highlight1;
int highlight2;
int highlight3;
int highlight4;
int width;
int height;
KeymapEntry *keys;
unsigned short maxkeys;
ExtEntry *exts;
unsigned short maxexts;
}
KeymapHandle;
/*
**
** Global Variable Declarations
**
*/
/*
**
** NAME: keymapLoadMap()
**
** USAGE: KeymapHandle *keymapLoadMap(char *file);
**
** DESCR: This function will load the specified keymap.
**
** PARMS: The "file" parameter is a pointer to the buffer that contains the
** path and filename.
**
** RETRN: If successful, a pointer to a KeymapHandle is returned. If an error
** occurs during function exeuction, NULL is returned.
**
*/
KeymapHandle *keymapLoadMap(char *);
/*
**
** NAME: keymapDeleteMap()
**
** USAGE: int keymapDeleteMap(KeymapHandle *handle);
**
** DESCR: This function will delete a KeymapHandle that was previously
** created by a successful call to "keymapLoadHandle()".
**
** PARMS: The "handle" parameter is a pointer to a KeymapHandle.
**
** RETRN: If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int keymapDeleteMap(KeymapHandle *);
#endif /* KEYMAP_H */
--- NEW FILE: bmptools.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/*
**
** Imported "Include" Files
**
*/
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include "bmptools.h"
/*
**
** Local Constant Definitions
**
*/
/*
**
** Local Enumeration Definitions
**
*/
/*
**
** Local Structure Definitions
**
*/
/*
**
** Local Variable Declarations
**
*/
static unsigned char bitmask[] = {
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};
/*
**
**
**
*/
static int
readByte(FILE * fp, unsigned char *result)
{
if (fread(result, 1, 1, fp) != 1)
return (-1);
return (0);
}
/*
**
**
**
*/
static int
readWord(FILE * fp, unsigned short *result)
{
unsigned char b1, b2;
if (fread(&b1, 1, 1, fp) != 1)
return (-1);
if (fread(&b2, 1, 1, fp) != 1)
return (-1);
*result = (((unsigned short) b2) << 8) + b1;
return (0);
}
/*
**
**
**
*/
static int
readLong(FILE * fp, unsigned int *result)
{
unsigned char b1, b2, b3, b4;
if (fread(&b1, 1, 1, fp) != 1)
return (-1);
if (fread(&b2, 1, 1, fp) != 1)
return (-1);
if (fread(&b3, 1, 1, fp) != 1)
return (-1);
if (fread(&b4, 1, 1, fp) != 1)
return (-1);
*result = (((unsigned int) b4) << 24) +
(((unsigned int) b3) << 16) + (((unsigned int) b2) << 8) + b1;
return (0);
}
/*
**
**
**
*/
static void
getMonochromePixel(BmpHandle * handle,
unsigned int xpos, unsigned short ypos, BmpColor * result)
{
BmpPaletteEntry pentry;
int res, sw;
unsigned char bit, byte, ref;
// calculate the scanline width - adjust for pixel padding
sw = handle->info.padded_width / 8;
// adjust the ypos (origin is lower-left corner for BMP images)
ypos = (handle->info.height - 1) - ypos;
// recover the pixel
ref = xpos / 8;
byte = *(handle->image + ((ypos * sw) + ref));
bit = xpos - (ref * 8);
// recover the pixel value
res = byte & bitmask[bit];
if (res)
pentry = *(handle->palette + 1);
else
pentry = *(handle->palette + 0);
// save result and exit
result->red = pentry.red;
result->green = pentry.green;
result->blue = pentry.blue;
}
/*
**
** This function will load the specfied image into memory.
**
** The "path" parameter is a pointer to the buffer that contains
** the files path and filename.
**
** If successful, a handle to the loaded image is returned. If an
** error occurs during function execution, NULL is returned.
**
*/
BmpHandle *
bmpLoadImage(char *path)
{
FILE *fp;
BmpHandle *handle;
unsigned int count, result, size;
// open the file
if ((fp = fopen(path, "r")) == NULL)
return (NULL);
// allocate memory from the system
handle = (BmpHandle *) malloc(sizeof(BmpHandle));
if (handle == NULL) {
fclose(fp);
return (NULL);
}
// read the BmpHeader structure
result = readByte(fp, &handle->header.signature[0]);
result += readByte(fp, &handle->header.signature[1]);
result += readLong(fp, &handle->header.filesize);
result += readLong(fp, &handle->header.reserved);
result += readLong(fp, &handle->header.raster_offset);
if (result != 0) {
free(handle);
fclose(fp);
return (NULL);
}
// make sure this is a valid BMP file
if (strcmp(handle->header.signature, "BM") != 0) {
free(handle);
fclose(fp);
return (NULL);
}
// read the BmpInfo structure
result = readLong(fp, &handle->info.size);
result += readLong(fp, &handle->info.width);
result += readLong(fp, &handle->info.height);
result += readWord(fp, &handle->info.planes);
result += readWord(fp, &handle->info.bits_per_pixel);
result += readLong(fp, &handle->info.compression);
result += readLong(fp, &handle->info.image_size);
result += readLong(fp, &handle->info.hres);
result += readLong(fp, &handle->info.vres);
result += readLong(fp, &handle->info.colors_used);
result += readLong(fp, &handle->info.colors_important);
if (result != 0) {
free(handle);
fclose(fp);
return (NULL);
}
// calculate the padded width
result = handle->info.width / 32;
if ((result * 32) == handle->info.width)
handle->info.padded_width = result * 32;
else
handle->info.padded_width = (result + 1) * 32;
// read the color palette
if (handle->info.bits_per_pixel <= 8) {
// determine number of palette entries
if (handle->info.bits_per_pixel == 1)
size = 2;
else if (handle->info.bits_per_pixel == 4)
size = 16;
else if (handle->info.bits_per_pixel == 8)
size = 256;
else {
free(handle);
fclose(fp);
return (NULL);
}
// allocate memory from the system
handle->palette =
(BmpPaletteEntry *) malloc(size * sizeof(BmpPaletteEntry));
if (handle->palette == NULL) {
free(handle);
fclose(fp);
return (NULL);
}
// load the palette
count = 0;
do {
readByte(fp, &((handle->palette + count)->red));
readByte(fp, &((handle->palette + count)->green));
readByte(fp, &((handle->palette + count)->blue));
readByte(fp, &((handle->palette + count)->reserved));
} while (++count < size);
} else
handle->palette = NULL;
// determine the size of the image
if (handle->info.bits_per_pixel == 1)
size = (handle->info.padded_width * handle->info.height) / 8;
else if (handle->info.bits_per_pixel == 4)
size = (handle->info.width * handle->info.height) / 2;
else if (handle->info.bits_per_pixel == 8)
size = handle->info.width * handle->info.height;
else if (handle->info.bits_per_pixel == 16)
size = handle->info.width * handle->info.height * 2;
else if (handle->info.bits_per_pixel == 24)
size = handle->info.width * handle->info.height * 3;
else {
if (handle->palette)
free(handle->palette);
free(handle);
fclose(fp);
return (NULL);
}
// allocate memory from the system
handle->image = (unsigned char *) malloc(size);
if (handle->image == NULL) {
if (handle->palette)
free(handle->palette);
free(handle);
fclose(fp);
return (NULL);
}
// read the image
if (fread(handle->image, 1, size, fp) != size) {
if (handle->palette)
free(handle->palette);
free(handle->image);
free(handle);
fclose(fp);
return (NULL);
}
// return result and exit with no errors
return (handle);
}
/*
**
** This function will close the specified BMP image handle and free
** all associated memory.
**
** The "handle" parameter specifies an image loaded into memory
** using the "bmpLoadImage()" function.
**
** If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int
bmpCloseImage(BmpHandle * handle)
{
free(handle->image);
if (handle->palette)
free(handle->palette);
free(handle);
return (0);
}
/*
**
** This function will recover the specified palette entry.
**
** The "handle" parameter specifies an image loaded into memory
** using the "bmpLoadImage()" function. The "entry" parameter
** specifies which palette entry to recover. The "result" parameter
** is a pointer to the location where the palette entry color is
** stored.
**
** If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int
bmpGetPaletteEntry(BmpHandle * handle, int entry, BmpColor * result)
{
int size;
// recover the palette size
if (handle->info.bits_per_pixel == 1)
size = 2;
else if (handle->info.bits_per_pixel == 4)
size = 16;
else if (handle->info.bits_per_pixel == 8)
size = 256;
else
return (-1);
// make sure the palette entry is legal
if (entry >= size)
return (-2);
// recover the result
result->red = (handle->palette + entry)->red;
result->green = (handle->palette + entry)->green;
result->blue = (handle->palette + entry)->blue;
// exit with no errors
return (0);
}
/*
**
** This function will recover the pixel value at the specified
** location.
**
** The "handle" parameter specifies an image loaded into memory
** using the "bmpLoadImage()" function. The "xpos" and "ypos"
** parameters specify the pixel position in the image. These
** values are referenced from the upper-left corner of the image.
** The "result" parameter is a pointer to the location where the
** color will be stored.
**
** If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int
bmpGetPixel(BmpHandle * handle, int xpos, int ypos, BmpColor * result)
{
// verify the pixel position
if ((xpos < 0) ||
(xpos >= handle->info.width) ||
(ypos < 0) || (ypos >= handle->info.height))
return (-1);
// monochrome (two-color) palette image
if (handle->info.bits_per_pixel == 1)
getMonochromePixel(handle, xpos, ypos, result);
// 16 color palette image
else if (handle->info.bits_per_pixel == 4)
return (-2);
// 256 color palette image
else if (handle->info.bits_per_pixel == 8)
return (-3);
// 65,536 color image
else if (handle->info.bits_per_pixel == 16)
return (-4);
// 16,777,216 color image
else if (handle->info.bits_per_pixel == 24)
return (-5);
// unknown image format
else
return (-6);
// exit with no errors
return (0);
}
--- NEW FILE: filetools.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef FILETOOLS_H
#define FILETOOLS_H
/*
**
** Imported "Include" Files
**
*/
/*
**
** Global Constant Definitions
**
*/
/*
**
** Global Enumeration Definitions
**
*/
/*
**
** Global Structure Definitions
**
*/
/*
**
** Global Variable Declarations
**
*/
/*
**
** NAME: splitPath()
**
** USAGE: int splitPath(char *path, char *dir, char *file, char *ext);
**
** DESCR: This function will split the specified path into its directory,
** filename, and extension components.
**
** PARMS: The "path" paramter is a pointer to a buffer that contains the
** path to be split. The "dir" parameter is a pointer to a buffer
** that will hold the directory result. The "file" parameter is
** a pointer to a buffer that will hold the filename result. The
** "ext" parameter is a pointer to a buffer that will hold the
** file extension result.
**
** RETRN: If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int splitPath(char *, char *, char *, char *);
#endif /* FILETOOLS_H */
--- NEW FILE: keymap.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/*
**
** Imported "Include" Files
**
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "keymap.h"
/*
**
** Local Constant Definitions
**
*/
/*
**
** Local Enumeration Definitions
**
*/
/*
**
** Local Structure Definitions
**
*/
typedef struct
{
char oldchr;
unsigned char newchr;
}
EscapeCodeEntry;
/*
**
** Local Variable Declarations
**
*/
EscapeCodeEntry esc_list[] = {
{'[', 27}, // escape
{'b', 8}, // backspace
{'f', 12}, // formfeed
{'n', 10}, // newline
{'r', 13}, // carriage return
{'t', 9}, // horizontal tab
{'v', 11}, // vertical tab
{92, 92}, // backslash
{0, 0}
};
/*
**
**
**
*/
static void
processEscapeCodes(char *src, char *dst)
{
int count, index, loop;
count = index = 0;
while (1) {
// check for end of source
if (*(src + count) == 0x00)
break;
// check for a full destination buffer
if (index >= (MAXEXTLEN - 1))
break;
// handle escape sequence
if (*(src + count) == 92) {
loop = 0;
while (1) {
if (esc_list[loop].oldchr == 0) {
++count;
break;
}
if (esc_list[loop].oldchr == *(src + count + 1)) {
*(dst + index++) = esc_list[loop].newchr;
count += 2;
break;
}
++loop;
}
}
// handle regular character
else
*(dst + index++) = *(src + count++);
}
// terminate destination and exit
*(dst + index) = 0x00;
}
/*
**
** This function will load the specified keymap.
**
** The "file" parameter is a pointer to the buffer that contains the
** path and filename.
**
** If successful, a pointer to a KeymapHandle is returned. If an error
** occurs during function exeuction, NULL is returned.
**
*/
KeymapHandle *
keymapLoadMap(char *file)
{
FILE *fp;
ExtEntry *eentry;
KeymapEntry *kentry;
KeymapHandle *handle;
char buf[256], ext[256];
// open the mapfile
if ((fp = fopen(file, "r")) == NULL)
return (NULL);
// allocate memory from the system
handle = (KeymapHandle *) malloc(sizeof(KeymapHandle));
if (handle == NULL) {
fclose(fp);
return (NULL);
}
handle->keys = NULL;
handle->maxkeys = 0;
handle->exts = NULL;
handle->maxexts = 0;
// load the keymap file
while (1) {
// read the next line from the file and strip the return
if (fgets(buf, 256, fp) == NULL)
break;
buf[strlen(buf) - 1] = 0x00;
// check for empty or comment lines
if (buf[0] == 0x00)
continue;
if (buf[0] == '*')
continue;
// handle parameter entry
if (strncmp(buf, "parms:", 6) == 0) {
sscanf(buf + 6,
"%d,%d,%d,%d,%d,%d,%d",
&handle->mapid,
&handle->highlight1,
&handle->highlight2,
&handle->highlight3,
&handle->highlight4, &handle->width, &handle->height);
}
// handle keymap entry
else if (strncmp(buf, "keymap:", 7) == 0) {
if (handle->keys == NULL) {
handle->keys = (KeymapEntry *) malloc(sizeof(KeymapEntry));
handle->maxkeys = 0;
} else {
handle->keys =
(KeymapEntry *) realloc(handle->keys,
(handle->maxkeys +
1) * sizeof(KeymapEntry));
}
if (handle->keys == NULL) {
free(handle);
fclose(fp);
return (NULL);
}
// add the keymap to the list
kentry = handle->keys + handle->maxkeys;
sscanf(buf + 7,
"%d,%d,%d,%d,%d",
&kentry->keycode,
&kentry->ulx, &kentry->uly, &kentry->lrx, &kentry->lry);
handle->maxkeys += 1;
}
// handle multichar entry
else if (strncmp(buf, "multi:", 6) == 0) {
if (handle->exts == NULL) {
handle->exts = (ExtEntry *) malloc(sizeof(ExtEntry));
handle->maxexts = 0;
} else {
handle->exts =
(ExtEntry *) realloc(handle->exts,
(handle->maxexts +
1) * sizeof(ExtEntry));
}
if (handle->exts == NULL) {
free(handle);
fclose(fp);
return (NULL);
}
// add the extension to the list
eentry = handle->exts + handle->maxexts;
eentry->str[0] = 0x00;
sscanf(buf + 6, "%d", &eentry->keycode);
strcpy(ext, strstr(buf, ",") + 1);
processEscapeCodes(ext, eentry->str);
handle->maxexts += 1;
}
}
// do houskeeping
fclose(fp);
// return result and exit with no errors
return (handle);
}
/*
**
** This function will delete a KeymapHandle that was previously
** created by a successful call to "keymapLoadHandle()".
**
** The "handle" parameter is a pointer to a KeymapHandle.
**
** If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int
keymapDeleteMap(KeymapHandle * handle)
{
if (handle->keys)
free(handle->keys);
if (handle->exts)
free(handle->exts);
free(handle);
return (0);
}
--- NEW FILE: cli.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef CLI_H
#define CLI_H
/*
**
** Imported "Include" Files
**
*/
/*
**
** Global Constant Definitions
**
*/
/*
**
** Global Enumeration Definitions
**
*/
/*
**
** Global Structure Definitions
**
*/
/*
**
** Global Variable Declarations
**
*/
extern char gMapID[];
extern char gMapDir[];
/*
**
** NAME: parseCommandLine()
**
** USAGE: int parseCommandLine(int argc, char **argv)
**
** DESCR: This function will parse the list of command line arguments
** and recover their associated information.
**
** PARMS: The "argc" parameter specifies the number of arguments found in
** the argv list. The "argv" parameter is a pointer to the array
** of command line arguments.
**
** RETRN: If successful, the number of command line arguments parsed is
** is returned. If an error occurs during function , a negative
** value is returned.
**
*/
int parseCommandLine(int, char **);
#endif /* CLI_H */
--- NEW FILE: filetools.c ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
/*
**
** Imported "Include" Files
**
*/
#include <stdio.h>
#include <string.h>
/*
**
** Local Constant Definitions
**
*/
/*
**
** Local Enumeration Definitions
**
*/
/*
**
** Local Structure Definitions
**
*/
/*
**
** Local Variable Declarations
**
*/
/*
**
** This function will split the specified path into its directory,
** filename, and extension components.
**
** The "path" paramter is a pointer to a buffer that contains the
** path to be split. The "dir" parameter is a pointer to a buffer
** that will hold the directory result. The "file" parameter is
** a pointer to a buffer that will hold the filename result. The
** "ext" parameter is a pointer to a buffer that will hold the
** file extension result.
**
** If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int
splitPath(char *path, char *dir, char *file, char *ext)
{
char buf[1024];
int count, index;
// clear all result buffers
*dir = *file = *ext = 0x00;
// check for null or empty path
if (path == NULL)
return (0);
if (*path == 0x00)
return (0);
// recover the length of the path
strcpy(buf, path);
index = strlen(buf) - 1;
// locate the end of the directory
count = index;
while (1) {
if (count < 0)
break;
if (buf[count] == '/')
break;
--count;
}
if (count >= 0) {
strcpy(dir, buf);
*(dir + ++count) = 0x00;
} else
count = 0;
// check for directory only
if (buf[count] == 0x00)
return (0);
// locate the extension
while (1) {
if (index < count)
break;
if (buf[index] == '.')
break;
--index;
}
// filename with no '.' at all
if (index < count)
strcpy(file, buf + count);
// filename with '.' at beginning
else if (index == count)
strcpy(file, buf + count);
// filename with extension
else {
strcpy(ext, buf + index + 1);
buf[index] = 0x00;
strcpy(file, buf + count);
}
// exit with no errors
return (0);
}
--- NEW FILE: bmptools.h ---
/*
* Copyright (c) 2003 Century Software, Inc. All Rights Reserved.
*
* This file is part of the PIXIL Operating Environment
*
* The use, copying and distribution of this file is governed by one
* of two licenses, the PIXIL Commercial License, or the GNU General
* Public License, version 2.
*
* Licensees holding a valid PIXIL Commercial License may use this file
* in accordance with the PIXIL Commercial License Agreement provided
* with the Software. Others are governed under the terms of the GNU
* General Public License version 2.
*
* This file may be distributed and/or modified under the terms of the
* GNU General Public License version 2 as published by the Free
* Software Foundation and appearing in the file LICENSE.GPL included
* in the packaging of this file.
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
* THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE.
*
* RESTRICTED RIGHTS LEGEND
*
* Use, duplication, or disclosure by the government is subject to
* restriction as set forth in paragraph (b)(3)(b) of the Rights in
* Technical Data and Computer Software clause in DAR 7-104.9(a).
*
* See http://www.pixil.org/gpl/ for GPL licensing
* information.
*
* See http://www.pixil.org/license.html or
* email cetsales at centurysoftware.com for information about the PIXIL
* Commercial License Agreement, or if any conditions of this licensing
* are not clear to you.
*/
#ifndef BMPTOOLS_H
#define BMPTOOLS_H
/*
**
** Imported "Include" Files
**
*/
/*
**
** Global Constant Definitions
**
*/
/*
**
** Global Enumeration Definitions
**
*/
/*
**
** Global Structure Definitions
**
*/
typedef struct
{
char signature[2];
unsigned int filesize;
unsigned int reserved;
unsigned int raster_offset;
}
BmpHeader;
typedef struct
{
unsigned int size;
unsigned int width;
unsigned int padded_width;
unsigned int height;
unsigned short planes;
unsigned short bits_per_pixel;
unsigned int compression;
unsigned int image_size;
unsigned int hres;
unsigned int vres;
unsigned int colors_used;
unsigned int colors_important;
}
BmpInfo;
typedef struct
{
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char reserved;
}
BmpPaletteEntry;
typedef struct
{
BmpHeader header;
BmpInfo info;
BmpPaletteEntry *palette;
unsigned char *image;
}
BmpHandle;
typedef struct
{
unsigned char red;
unsigned char green;
unsigned char blue;
}
BmpColor;
/*
**
** Global Variable Declarations
**
*/
/*
**
** NAME: bmpLoadImage()
**
** USAGE: BmpHandle *bmpLoadImage(char *path);
**
** DESCR: This function will load the specfied image into memory.
**
** PARMS: The "path" parameter is a pointer to the buffer that contains
** the files path and filename.
**
** RETRN: If successful, a handle to the loaded image is returned. If an
** error occurs during function execution, NULL is returned.
**
*/
BmpHandle *bmpLoadImage(char *);
/*
**
** NAME: bmpCloseImage()
**
** USAGE: int bmpCloseImage(BmpHandle *handle);
**
** DECSR: This function will close the specified BMP image handle and free
** all associated memory.
**
** PARMS: The "handle" parameter specifies an image loaded into memory
** using the "bmpLoadImage()" function.
**
** RETRN: If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int bmpCloseImage(BmpHandle *);
/*
**
** NAME: bmpGetPaletteEntry()
**
** USAGE: int bmpGetPaletteEntry(BmpHandle *handle,
** int entry,
** BmpColor *result);
**
** DESCR: This function will recover the specified palette entry.
**
** PARMS: The "handle" parameter specifies an image loaded into memory
** using the "bmpLoadImage()" function. The "entry" parameter
** specifies which palette entry to recover. The "result" parameter
** is a pointer to the location where the palette entry color is
** stored.
**
** RETRN: If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int bmpGetPaletteEntry(BmpHandle *, int, BmpColor *);
/*
**
** NAME: bmpGetPixel()
**
** USAGE: int bmpGetPixel(BmpHandle *handle,
** int xpos,
** int ypos,
** BmpColor *result);
**
** DESCR: This function will recover the pixel value at the specified
** location.
**
** PARMS: The "handle" parameter specifies an image loaded into memory
** using the "bmpLoadImage()" function. The "xpos" and "ypos"
** parameters specify the pixel position in the image. These
** values are referenced from the upper-left corner of the image.
** The "result" parameter is a pointer to the location where the
** color will be stored.
**
** RETRN: If successful, '0' is returned. If an error occurs during function
** execution, a non-zero value is returned that describes the error.
**
*/
int bmpGetPixel(BmpHandle *, int, int, BmpColor *);
#endif /* BMPTOOLS_H */
More information about the dslinux-commit
mailing list