dslinux/user/pixil/apps/fltk/sysconfig/clock/old Makefile addcity.c astro.c citylist.out gray_grid_240.c hashdb_api.c hashdb_api.h hashdb_low.c nxsunclock.cxx nxsunclock.h scfxn.c scfxn.h
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:24:34 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/apps/fltk/sysconfig/clock/old
In directory antilope:/tmp/cvs-serv11916/apps/fltk/sysconfig/clock/old
Added Files:
Makefile addcity.c astro.c citylist.out gray_grid_240.c
hashdb_api.c hashdb_api.h hashdb_low.c nxsunclock.cxx
nxsunclock.h scfxn.c scfxn.h
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: scfxn.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 SCFXN_INCLUDED
#define SCFXN_INCLUDED 1
#ifdef __cplusplus
extern "C"
{
#endif
/* System header files */
/* Local header files */
/* Typedefs, macro, enum/struct/union definitions */
typedef struct
{
unsigned char red, // Red value
green, // Green value
blue; // Blue value
}
rgbTriplet;
#define RGB2PIXEL565(r,g,b) \
((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | (((b) & 0xf8) >> 3))
#define RGB2PIXEL888(r,g,b) \
(((r) << 16) | ((g) << 8) | (b))
#define PI 3.14159265358979323846
#define EPSILON 1E-6
#define abs(x) ((x) < 0 ? (-(x)) : x) /* Absolute value */
#define sgn(x) (((x) < 0) ? -1 : ((x) > 0 ? 1 : 0)) /* Extract sign */
#define dtr(x) ((x) * (PI / 180.0)) /* Degree->Radian */
#define rtd(x) ((x) / (PI / 180.0)) /* Radian->Degree */
#define fixangle(a) ((a) - 360.0 * (floor((a) / 360.0))) /* Fix angle */
/* Function prototypes */
void nxsunimage(unsigned char *srcpix, unsigned char *dstpix, int width,
int height, int depth);
void read_pixel(unsigned char *data, int x, int y, int bpp, int xsize,
rgbTriplet * pixel);
void darken_pixel(rgbTriplet * pixel, double val);
void write_pixel(unsigned char *data, int x, int y, int bpp, int xsize,
rgbTriplet * pixel);
/* functions in astro.c */
long jdate(struct tm *t);
double jtime(struct tm *t);
double kepler(double m, double ecc);
void sunpos(double jd, int apparent, double *ra, double *dec, double *rv,
double *slong);
double gmst(double jd);
#ifdef __cplusplus
}
#endif
#endif // SCFXN_INCLUDED
--- NEW FILE: hashdb_api.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 HASHDB_API_INCLUDED
#define HASHDB_API_INCLUDED 1
/* Protect against C++ name mangling */
#ifdef __cplusplus
extern "C"
{
#endif
/* System header files */
#include <fcntl.h>
#include <sys/types.h>
/* Local header files */
/* Typedef, macros, enum/struct/union definitions */
/* Macros for datakey, block number, data offset handling */
#define MAKE_DATA_KEY(b,o) ( (o) | (b << 16))
#define GET_DATA_BLOCK(k) ( (k >> 16) )
#define GET_DATA_OFFSET(k) ( (k & 0x0000FFFF) )
#define HASH_MAGIC 0x2324 /* Pulled this out of my arse */
#define HASH_BLK_SIZE 4096
#define HASH_ROOT_NODE 0
/* Modes for h_getrecord() */
#define HDB_KEY_HASH 0
#define HDB_KEY_DATA 1
typedef unsigned long data_key_t;
typedef unsigned short hash_key_t;
typedef unsigned long hdb_key_t;
//typedef data_key_t unsigned long;
//typedef hash_key_t unsigned short;
//typedef key_t unsigned long;
typedef struct h_info_hdr
{
unsigned short magic, /* Magic number */
blksz, /* Max block number */
nblk; /* Number of blocks */
char pad[2]; /* Padded to 4byte alignment */
}
h_info_hdr;
#define HDB_INFHDR_SZ (sizeof(h_info_hdr))
typedef struct h_idx_hdr
{
unsigned short idx_size, /* size of the index */
idx_max_val; /* Max hash index */
}
h_idx_hdr;
#define HDB_IDXHDR_SZ (sizeof(h_idx_hdr))
typedef struct h_idx_rec
{
data_key_t head; /* data key for the head of the list */
data_key_t tail; /* Data key for the tail of the list */
}
h_idx_rec;
#define HDB_IDXREC_SZ (sizeof(h_idx_rec))
typedef struct h_blk_hdr
{
unsigned short id, /* Block id */
free, /* Space free */
parent, /* Parent block */
peer; /* peer block */
}
h_blk_hdr;
#define HDB_BLKHDR_SZ (sizeof(h_blk_hdr))
typedef struct h_data_rec
{
char city_name[20 + 1], /* City name */
reg[2 + 1], /* Region */
zinfo[2 + 5 + 1]; /* Timezone (2Reg/5city) */
signed short lat, /* Latitude */
lon; /* Longitude */
data_key_t next; /* idx to the next record */
}
h_data_rec;
#define HDB_DTAREC_SZ (sizeof(h_data_rec))
typedef struct
{
int blkno; /* Block number */
caddr_t *addr; /* Address */
}
h_blk_map_t;
#define HDB_MAPREC_SZ (sizeof(h_blk_map_t))
typedef struct
{
int fd, /* File descriptor for the database file */
fsize, /* database file size */
nblk, /* Number of blocks */
blksz, /* Size of blocks */
mapcnt, /* Number of blocks mapped */
mapsz, /* size of the dynamic array */
idxsz, /* Number of entries in the index */
mode; /* File access mode */
h_idx_rec *idx_tbl; /* Ptr to the index table */
h_blk_map_t *blk_ar; /* Mapped block array */
}
hashdb_t;
#define HDB_DBHND_SZ (sizeof(hashdb_t))
int h_addrec(hashdb_t * dbd, hash_key_t key, h_data_rec * rec);
void h_closedb(hashdb_t * dbd);
int h_getrecord(int mode, hashdb_t * dbd, hdb_key_t key,
h_data_rec * rec);
int h_init_new_db(char *name, int blocksize, int mxhashidx);
int h_init_new_blk(hashdb_t * dbd, int bl_no);
int h_map_block(hashdb_t * dbd, int blkno);
hashdb_t *h_opendb(char *name, int perms);
#ifdef __cplusplus
}
#endif
#endif /* HASHDB_API_INCLUDED */
--- NEW FILE: scfxn.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.
*/
// System header files
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
#include <unistd.h>
// Local header files
#define MWINCLUDECOLORS
#include <nano-X.h>
#include "scfxn.h"
// Typedef, macros, enum/struct/union defintions
// Global variables
// Local variables
// Static function prototypes
//------------------------------------------------------------------------------
//
// Static function definitions
//
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
// Extern function definitions
//
//------------------------------------------------------------------------------
/*******************************************************************************\
**
** Function: void darken_pixel()
** Desc: Darkens the cooresponding pixel value
** Accepts: rgbTriplet *pix = Ptr to the pixel values
** double adj = value adjustment multiplier
** Returns: Nothing (void)
**
\*******************************************************************************/
void
darken_pixel(rgbTriplet * pix, double adj)
{
pix->red = (int) (((double) pix->red) * adj);
pix->green = (int) (((double) pix->green) * adj);
pix->blue = (int) (((double) pix->blue) * adj);
return;
} // end of darken_pixel(rgbTriplet *, double)
/*******************************************************************************\
**
** Function: void nxsunimage()
** Desc: Generates the sunimage using native Microwindow's calls.
** Accepts: unsigned char *srcpix = Source image
** unsigned char *dstpix = Destination image
** int w = Width of the image
** int h = height of the image
** int d = Depth of the image
** Returns: Nothing (void)
**
\*******************************************************************************/
void
nxsunimage(unsigned char *srcpix, unsigned char *dstpix, int w, int h, int d)
{
double cd, *daywave, fnoon, f1, f2, f3, gmttm, jultm, quot, sd, sdec, shft, sra, srv, slong; // Sun longitude
int i, // Loop iterator
j, // 2nd loop iterator
north, // North value
south, // South value
tr1; // ????
rgbTriplet pix; // Current pixel
time_t now = time(NULL); // Current time
struct tm *utctm; // UTC time structure
// Allocate memory for the day/night wave line
daywave = (double *) malloc(w * sizeof(double));
utctm = gmtime(&now);
jultm = jtime(utctm);
sunpos(jultm, 0, &sra, &sdec, &srv, &slong);
gmttm = gmst(jultm);
slong = fixangle(180.0 + (sra - (gmttm * 15)));
fnoon = slong * (w / 360.0);
slong -= 180;
if ((quot = dtr(sdec)) > 0)
south = 0;
else
south = -1;
north = -1 - south;
cd = cos(quot);
sd = sin(quot);
quot = (2.0 * M_PI) / (double) w;
shft = 0.5 * (h + 1);
f1 = M_PI / ((double) h);
f2 = ((double) h) / M_PI;
f3 = 1E-8 * f2;
for (i = 0; i < w; i++) {
double val = (double) i;
daywave[i] = cos(quot * (val - fnoon));
} // end of for
// Start manipulating the image
for (i = 0; i < w; i++) {
if (fabs(sd) > f3)
tr1 = (int) (shft + f2 * atan(daywave[i] * (cd / sd)));
else
tr1 = 0;
if (tr1 < 0)
tr1 = 0;
// Figure where to darken....
if (south == -1) {
// Draw below the line
for (j = 0; j <= tr1; j++) {
read_pixel(srcpix, i, j, d, w, &pix);
darken_pixel(&pix, 0.5);
write_pixel(dstpix, i, j, d, w, &pix);
} // end of for
} // end of if
else {
// Draw above the line
for (j = tr1; j < h; j++) {
read_pixel(srcpix, i, j, d, w, &pix);
darken_pixel(&pix, 0.5);
write_pixel(dstpix, i, j, d, w, &pix);
} // end of for
} // end of else
} // end of for
free(daywave);
return;
} // end of nxsunimage(unsigned char *, unsigned char *, int, int, int)
/*******************************************************************************\
**
** Function: void read_pixel()
** Desc: Reads the current pixel (determined by i,j) from the array
** and stores it into the rgbTriplet
** Accepts: unsigned char *src = Image array source
** int x = x location of current pixel
** int y = y location of current pixel
** int d = depth (img depth)
** int xsize = img width
** rgbTriplet *pix = Store the data
** Returns: Nothing (void)
**
\*******************************************************************************/
void
read_pixel(unsigned char *src, int x, int y, int d, int xsize,
rgbTriplet * pix)
{
unsigned short wv; // word pixel value (for 16 bpp images)
unsigned long lv; // long pixel value (for 24/32 bpp images)
switch (d) {
case 2:
// 16 bpp images
wv = *((unsigned short *) src + (y * (xsize * 2)) + (x * 2));
pix->red = (wv & 0xF800) >> 11; // Red pixel component
pix->green = (wv & 0x07E0) >> 5; // Blue pixel component
pix->blue = (wv & 0x001F); // Green pixel component
break;
case 3:
// 24 bpp images
lv = *(((unsigned long *) src) + (y * xsize) + x);
pix->red = (lv & 0xFF000000) >> 24; // Red pixel component
pix->green = (lv & 0xFF0000) >> 16; // Blue pixel component
pix->blue = (lv & 0xFF00) >> 8; // Green pixel component
break;
case 4:
// 32 bpp images
lv = *((((unsigned long *) src) + (y * xsize) + x));
pix->red = (lv & 0xFF0000) >> 16; // Red pixel component
pix->green = (lv & 0xFF00) >> 8; // Blue pixel component
pix->blue = (lv & 0xFF); // Green pixel component
break;
} // end of switch
return;
} // end of read_pixel(unsigned char *, int, int, int, int, rgbTriplet *)
/*******************************************************************************\
**
** Function: void write_pixel()
** Desc: Writes the current pixel value to the destination image array
** Accepts: unsigned char *dst = Destination image array
** int x = x pixel coordinate
** int y = y pixel coordiante
** int d = Depth value
** int xsize = image width
** rgbTriplet *pix = Ptr to the pixel structure
** Returns: Nothing (void)
**
\*******************************************************************************/
void
write_pixel(unsigned char *dst, int x, int y, int d, int xsize,
rgbTriplet * pix)
{
unsigned short wv; // Word pixel value
unsigned long lv; // Long pixel value
unsigned long offset = 0;
switch (d) {
case 2:
// 16 bpp image
wv = RGB2PIXEL565(pix->red, pix->green, pix->blue);
offset = (y * (xsize * 2)) + (x * 2);
*((unsigned short *) (dst + offset)) = wv;
break;
case 3:
// 24 bpp image
lv = RGB2PIXEL888(pix->red, pix->green, pix->blue);
offset = (y * (xsize * 3)) + (x * 3);
*((unsigned long *) (dst + offset)) = lv;
break;
case 4:
// 32 bpp image
lv = (pix->red << 16) | (pix->green << 8) | pix->blue;
offset = (y * (xsize * 4)) + (x * 4);
*((unsigned long *) (dst + offset)) = lv;
break;
} // end of switch
return;
} // end of write_pixel(unsigned char *, int, int, int, int, rgbTriplet *)
--- NEW FILE: hashdb_low.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.
*/
/* System header files */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* Local header files */
#include "hashdb_api.h"
/* Typedef, macros, enum/struct/union definitions */
/* Global scope variables */
/* Local scope variables */
/* Static function prototypes */
static int h_get_free_blk(hashdb_t * dbd, size_t dsize);
static int h_makeroot_blk(hashdb_t * dbd);
/*******************************************************************************\
**
** Function: int h_addrec()
** Desc: Adds a record into the database at the next free location in
** the block, or forces a new block to be created
** Accepts: hashdb_t *dbd = Ptr to the database handle
** hash_key_t key = Hash key (index into the hash table)
** h_data_rec *hrec = Ptr to the record to store
** Returns: int; 0 on success, -1 on error
** Note: This isn't included into the "api" file, because for the
** "super quick" hash db normal operation is only search, not add
**
\*******************************************************************************/
int
h_addrec(hashdb_t * dbd, hash_key_t key, h_data_rec * hrec)
{
char *blkbuf, /* Block buf */
*cptr; /* Generic pointer */
int blkidx, /* Index of the block */
nrec_key, /* New record key */
offset; /* Offset for the record */
h_blk_hdr *bhdr; /* ptr a block header */
h_data_rec *tailrec; /* tail record */
/* Get to a block with space */
blkidx = h_get_free_blk(dbd, HDB_DTAREC_SZ);
if (blkidx == -1)
return (-1);
/* Get the offset for the new record */
blkbuf = (char *) dbd->blk_ar[blkidx].addr;
if (dbd->blk_ar[blkidx].blkno == HASH_ROOT_NODE)
bhdr = (h_blk_hdr *) (blkbuf + HDB_INFHDR_SZ);
else
bhdr = (h_blk_hdr *) (blkbuf);
offset = dbd->blksz - bhdr->free;
cptr = blkbuf + offset;
nrec_key = MAKE_DATA_KEY(dbd->blk_ar[blkidx].blkno, offset);
hrec->next = 0;
memcpy(cptr, hrec, HDB_DTAREC_SZ);
bhdr->free -= HDB_DTAREC_SZ;
/* Handle first add case (or only 1 item) */
if (dbd->idx_tbl[key].head == dbd->idx_tbl[key].tail
&& dbd->idx_tbl[key].head == 0) {
dbd->idx_tbl[key].head = dbd->idx_tbl[key].tail = nrec_key;
} /* end of if */
else {
h_get_rec(dbd, dbd->idx_tbl[key].tail, &tailrec);
tailrec->next = nrec_key;
dbd->idx_tbl[key].tail = nrec_key;
} /* end of else */
return 0;
} /* end of h_addrec() */
/*******************************************************************************\
**
** Function: int h_get_free_blk()
** Desc: Searches through the file block at a time, looking for the first
** block with enough free space to hold a record of size, and maps
** that block
** Accepts: hashdb_t *dbd = Ptr to the hash db handle
** size_t size = Size value
** Returns: int; -1 on error, >= 0 indicating the mapped index for the block
**
\*******************************************************************************/
static int
h_get_free_blk(hashdb_t * dbd, size_t size)
{
char *buf[HDB_BLKHDR_SZ]; /* Buffer */
int i, /* Loop iterator */
offset; /* Offset to skip */
h_blk_hdr *bhdr = 0; /* Ptr to the block header */
/* Start looking */
if (dbd == NULL)
return (-1);
/* Look in the root node first */
for (i = 0; i < dbd->nblk; i++) {
offset = i * dbd->blksz;
if (offset == 0)
offset = HDB_INFHDR_SZ;
lseek(dbd->fd, offset, SEEK_SET);
if (read(dbd->fd, buf, HDB_BLKHDR_SZ) <= 0)
return (-1);
bhdr = (h_blk_hdr *) buf;
if (bhdr->free >= size)
return (h_map_block(dbd, i));
} /* end of for */
/* if here, there were no free blocks, allocate a new one */
return (h_init_new_blk(dbd, bhdr->id));
} /* end of h_get_free_blk() */
/*******************************************************************************\
**
** Function: int h_get_rec
** Desc: Returns a ptr the index table record for the specified key
** Accepts: hashdb_t *dbd = Ptr to the database handle
** data_key_t key = exact key location
** h_data_rec **rec = Ptr to the record
** Returns: int; 0 on success, -1 on error
**
\*******************************************************************************/
int
h_get_rec(hashdb_t * dbd, data_key_t key, h_data_rec ** rec)
{
char *blkbuf; /* Char block buffer */
short blidx, /* block index */
blno, /* Block number */
offset; /* Offset */
/* Validate the parameters */
if (rec == NULL || dbd == NULL) {
errno = EINVAL;
return (-1);
}
/* end of if */
/* Get the record */
blno = GET_DATA_BLOCK(key);
offset = GET_DATA_OFFSET(key);
/* Map this block */
if ((blidx = h_map_block(dbd, blno)) == -1)
return (-1);
blkbuf = (char *) dbd->blk_ar[blidx].addr + offset;
*rec = (h_data_rec *) blkbuf;
return (0);
} /* end of h_get_rec() */
/*******************************************************************************\
**
** Function: int h_init_new_blk()
** Desc: Allocates a new block, and maps it, updating all of the necessary
** block headers, etc
** Accepts: hashdb_t *dbd = Ptr Hash db handle
** int p_idx = parent blocks index
** Returns: int; idx into the mapped array for this block; -1 on error
**
\*******************************************************************************/
int
h_init_new_blk(hashdb_t * dbd, int p_idx)
{
char *newbuf, /* New buffer */
*pbuf; /* Parents buffer */
int rc; /* Return code */
long fpos; /* File position */
h_blk_hdr *parent, /* Ptr to the parents blk header */
*child; /* Ptr to the childs blk header */
/* Grow the file */
fpos = lseek(dbd->fd, 0, SEEK_END);
lseek(dbd->fd, dbd->blksz, SEEK_END);
if (write(dbd->fd, "", 1) == -1) {
lseek(dbd->fd, 0, SEEK_END);
return (-1);
}
/* end of if */
dbd->fsize += dbd->blksz;
dbd->nblk = (dbd->fsize / dbd->blksz) - 1;
if ((rc = h_map_block(dbd, dbd->nblk)) == -1) {
ftruncate(dbd->fd, fpos);
return (-1);
} /* end of if */
dbd->nblk++;
/* Special handling for the root node */
if (p_idx != HASH_ROOT_NODE - 1) {
pbuf = (char *) dbd->blk_ar[p_idx].addr;
newbuf = (char *) dbd->blk_ar[rc].addr;
if (p_idx == HASH_ROOT_NODE)
parent = (h_blk_hdr *) (pbuf + HDB_INFHDR_SZ);
else
parent = (h_blk_hdr *) pbuf;
child = (h_blk_hdr *) newbuf;
child->id = dbd->nblk - 1;
child->free = dbd->blksz - HDB_BLKHDR_SZ;
child->parent = parent->id;
child->peer = -1;
parent->peer = child->id;
}
/* end of if */
return (rc);
} /* end of h_init_new_blk() */
/*******************************************************************************\
**
** Function: int h_init_new_db()
** Desc: Initializes a new database
** Accepts: char *name = File name
** int blocksize = blocksize of each block
** int mxhashidx = Maximum index in the hash table to create
** Returns: int; 0 on success, -1 on error
**
\*******************************************************************************/
int
h_init_new_db(char *name, int blocksize, int mxhashidx)
{
char *buf; /* Dynamic buffer */
int db_fd = -1, /* Database file descriptor */
perm, /* Create permissions */
rc; /* Return code */
long pagesz; /* Page size */
hashdb_t hashrec; /* Hash database handle */
/* Make sure the blocksize is page aligned */
pagesz = sysconf(_SC_PAGESIZE);
if (pagesz == -1) {
/* Blocksize is left alone? */
;
} /* end of if */
else if ((blocksize % pagesz)) {
/* Do something to align the block size */
blocksize = ((blocksize + pagesz) / pagesz * pagesz);
}
/* end of else-if */
/* First, check to make sure that the index record will fit on 1 block!!! */
if ((blocksize - (HDB_INFHDR_SZ + HDB_IDXHDR_SZ + HDB_BLKHDR_SZ)) <
(mxhashidx * HDB_IDXHDR_SZ)) {
/* Not enough space for the index to fit.... */
errno = E2BIG;
return (-1);
}
/* end of if */
buf = (char *) calloc(blocksize, sizeof(char));
if (!buf)
return (-1);
perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
/* open the file, and return an EEXISTS if already exists */
if ((db_fd = open(name, O_RDWR)) > -1) {
/* File already exists....see if it is a database file */
if ((rc = read(db_fd, buf, HDB_INFHDR_SZ)) <= 0) {
/* Error reading from file, unlink it, and then create it */
close(db_fd);
unlink(name);
db_fd = -1;
} /* end of if */
else {
/* Data was read */
h_info_hdr *inf_hdr = (h_info_hdr *) buf; /* Info header of the file */
if (inf_hdr->magic == HASH_MAGIC) {
errno = EEXIST;
close(db_fd);
free(buf);
return (-1);
} /* end of if */
close(db_fd);
unlink(name);
db_fd = -1;
} /* end of else */
} /* end of if */
free(buf);
if (db_fd == -1
&& (db_fd = open(name, O_RDWR | O_CREAT | O_TRUNC, perm)) == -1) {
/* Could not create the file */
return (db_fd);
} // end of if
/* Grow the file to the block size, and initialize the root block */
memset(&hashrec, 0, HDB_DBHND_SZ);
hashrec.fd = db_fd;
hashrec.blksz = blocksize;
hashrec.idxsz = mxhashidx;
hashrec.mode = O_RDWR;
rc = h_makeroot_blk(&hashrec);
close(db_fd);
if (rc == -1)
unlink(name);
return (rc);
} /* End of h_init_new_db() */
/*******************************************************************************\
**
** Function: int h_makeroot_blk()
** Desc: Makes the root block on the newly created file
** Accepts: hashdb_t *dbd = Ptr to the hashed db record
** Returns: int; 0 on success, -1 on error (errno is set)
**
\*******************************************************************************/
static int
h_makeroot_blk(hashdb_t * dbd)
{
char *rootbuf; /* Dynamic buffer for the root */
int bufsz, /* Buffer size */
rc; /* Result code */
h_info_hdr *infh; /* Ptr into info header */
h_blk_hdr *blkh; /* Ptr to the blkh header */
h_idx_hdr *idxh; /* Ptr into the index header */
/* Make the block */
if ((rc = h_init_new_blk(dbd, HASH_ROOT_NODE - 1)) == -1) {
return (-1);
}
/* end of if */
/* Allocate the buffer */
bufsz = HDB_INFHDR_SZ + HDB_BLKHDR_SZ + HDB_IDXHDR_SZ +
(dbd->idxsz * HDB_IDXREC_SZ);
/* Figure out how to write this out (either via map or file io) */
rootbuf = (char *) dbd->blk_ar[rc].addr;
infh = (h_info_hdr *) rootbuf;
blkh = (h_blk_hdr *) (rootbuf + HDB_INFHDR_SZ);
idxh = (h_idx_hdr *) (rootbuf + HDB_INFHDR_SZ + HDB_BLKHDR_SZ);
/* Fill in the info header stuff */
infh->magic = HASH_MAGIC;
infh->blksz = dbd->blksz;
infh->nblk = 0;
/* Fill in the block header stuff */
blkh->id = HASH_ROOT_NODE;
blkh->free = dbd->blksz - bufsz;
blkh->parent = -1;
blkh->peer = 0;
/* Fill in the index header */
idxh->idx_size = dbd->idxsz * HDB_IDXREC_SZ;
idxh->idx_max_val = dbd->idxsz;
munmap(dbd->blk_ar[rc].addr, dbd->blksz);
return (rc);
} /* end of h_makeroot_blk() */
/*******************************************************************************\
**
** Function: int h_map_block()
** Desc: Maps the requested block into memory
** Accepts: hashdb_t *dbd = Ptr to the database handle record
** int blkno = Number of the block to map
** Returns: int; -1 on error, or the index into the array of the mapped
** block
**
\*******************************************************************************/
int
h_map_block(hashdb_t * dbd, int blkno)
{
int i, /* Loop iterator */
mmode = 0, /* Map mode */
rc; /* Result code */
/* Check the sanity of the block */
if ((blkno * dbd->blksz) >= dbd->fsize) {
errno = EINVAL;
return (-1);
}
/* end of if */
/* Check to see if this block is already mapped */
for (i = 0; i < dbd->mapcnt; i++) {
if (dbd->blk_ar[i].blkno == blkno)
return (i);
} /* end of for */
/* Map this */
switch (dbd->mode) {
case O_RDONLY:
mmode = PROT_READ;
break;
case O_WRONLY:
mmode = PROT_WRITE;
break;
case O_RDWR:
mmode = PROT_READ | PROT_WRITE;
break;
} /* end of switch */
if ((dbd->mapcnt + 1) >= dbd->mapsz) {
if (dbd->mapsz == 0) {
if ((dbd->blk_ar =
(h_blk_map_t *) calloc(5, HDB_MAPREC_SZ)) == NULL)
return (-1);
} /* end of if */
else {
/* Need to reallocate */
h_blk_map_t *tmp;
tmp =
(h_blk_map_t *) realloc(dbd->blk_ar,
((dbd->mapsz + 5) * HDB_MAPREC_SZ));
if (!tmp)
return (-1);
dbd->blk_ar = tmp;
} /* end of else */
dbd->mapsz += 5;
}
/* end of if */
/* Seek to this area? */
// lseek(dbd->fd, blkno * dbd->blksz, SEEK_SET);
dbd->blk_ar[dbd->mapcnt].addr =
mmap(0, dbd->blksz, mmode, MAP_SHARED, dbd->fd, dbd->blksz * blkno);
if (dbd->blk_ar[dbd->mapcnt].addr == MAP_FAILED) {
rc = -1;
} // end of if
else {
dbd->blk_ar[dbd->mapcnt].blkno = blkno;
rc = dbd->mapcnt++;
} // end of else
return (rc);
} /* end of h_map_block() */
--- NEW FILE: addcity.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.
*/
/* Feature test switches */
/* System header files */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* Local header files */
#include "hashdb_api.h"
/* Typedef, macros, enum/struct/unions */
typedef struct
{
char iso_id[2 + 1], /* ISO 3166 country id */
long_reg[48]; /* Name */
}
iso_name_t;
/* Global scope variables */
unsigned short g_Debug = 0;
/* Local scope variables */
static char *dbname = "./cityzones.db", *txtfile = "./citylist.out";
static iso_name_t iso_head[240];
static int iso_cnt = 0; /* Number of elements of iso_head in use */
/* Function prototypes */
void build_iso_list(void);
int iso_find(char *key);
int iso_ins(iso_name_t * isorec);
void get_records(hashdb_t * dbd, char *txtname);
/* main */
int
main(int argc, char **argv)
{
int gopt, /* getopt() value */
initflg = 1, /* Initialize the database */
rc; /* Result code */
hashdb_t *hdbd; /* Hashed db descriptor */
/* Parse the commandline arguments */
while ((gopt = getopt(argc, argv, "cf:t:v")) != -1)
switch (gopt) {
case 'c':
initflg = 1;
break;
case 'f':
if (optarg && !access((char *) optarg, R_OK | W_OK))
dbname = optarg;
break;
case 't':
if (optarg && !(access((char *) optarg, R_OK)))
txtfile = optarg;
break;
case 'v':
g_Debug = 1;
break;
} /* end of while-switch */
/* Initialize the database (if desired) */
if (initflg && h_init_new_db(dbname, HASH_BLK_SIZE, (90 + 90 + 1)) != 0) {
printf("Error in h_init_new_db() for \"%s\", error=%s\n",
dbname, strerror(errno));
exit(EXIT_FAILURE);
}
/* end of if */
/* Open the database */
if ((hdbd = h_opendb(dbname, O_RDWR)) == NULL) {
printf("Error in h_opendb(\"%s\"), error=%s.\n", dbname,
strerror(errno));
exit(EXIT_FAILURE);
}
/* end of if */
build_iso_list();
get_records(hdbd, txtfile);
h_closedb(hdbd);
exit(EXIT_SUCCESS);
} /* end of main() */
/*******************************************************************************\
**
** Function: void build_iso_list()
** Desc: Builds a sorted list of iso 3166 records (sorted by Country name,
** not 2 char id)
** Accepts: Nothing (void)
** Returns: Nothing (void)
**
\*******************************************************************************/
void
build_iso_list(void)
{
char *cp, /* character pointer */
isobuf[255]; /* Iso buffer */
FILE *fiso; /* File stream */
iso_name_t tmpiso; /* Temp iso */
if ((fiso = fopen("/usr/share/zoneinfo/iso3166.tab", "r")) == NULL)
return;
while (fgets(isobuf, sizeof(isobuf), fiso) != NULL) {
int len = strlen(isobuf);
if (isobuf[0] == '#')
continue;
if (isobuf[len - 1] == '\n')
isobuf[--len] = '\0';
if ((cp = strchr(isobuf, 0x09)) == NULL)
continue;
*cp = '\0';
memset(&tmpiso, 0, sizeof(tmpiso));
memcpy(tmpiso.iso_id, isobuf, sizeof(tmpiso.iso_id) - 1);
memcpy(tmpiso.long_reg, cp + 1, sizeof(tmpiso.long_reg) - 1);
iso_ins(&tmpiso);
} /* end of while */
fclose(fiso);
} /* end of build_iso_list() */
/*******************************************************************************\
**
** Function: int iso_find()
** Desc: Finds the given record in the array and returns its index, if
** the record isn't found, it will return the index where it needs
** to be inserted based on the following algorithm:
** w = (w + 1) * -1
** Accepts: char *key = Key to look for
** Returns: int; >= 0 on successful find, < 0 on unable to find
**
\*******************************************************************************/
int
iso_find(char *key)
{
int cmprc = 0, /* RC of the cmp */
found = 0, /* Found flag */
hi, /* High index in bsearch */
lo, /* Lo index in bsearch */
mid = 0; /* Middle idx in bsearch */
hi = iso_cnt - 1;
lo = 0;
while (lo <= hi) {
mid = (hi + lo) / 2;
if ((cmprc = strcmp(key, iso_head[mid].long_reg)) == 0) {
found = mid;
break;
} /* end of if */
else if (cmprc < 0)
hi = mid - 1;
else
lo = mid + 1;
} /* end of while */
if (!found) {
if (cmprc > 0)
mid++;
found = (mid + 1) * -1;
}
/* end of if */
return (found);
} /* end of iso_find() */
/*******************************************************************************\
**
** Function: int iso_ins()
** Desc: Inserts the record into the list (sorted array)
** Accepts: iso_name_t *isorec = Key to look up
** Returns: int; 0 on success, -1 on error
**
\*******************************************************************************/
int
iso_ins(iso_name_t * isorec)
{
int idx, /* Index to insert into */
rc = -1; /* Return code, assume error */
// memcpy(&iso_head[iso_cnt++], isorec, sizeof(iso_name_t));
if ((idx = iso_find(isorec->long_reg)) < 0) {
/* Only add those that aren't in the list */
idx = (idx * -1) - 1;
if (idx >= iso_cnt) {
memcpy(&iso_head[idx], isorec, sizeof(iso_name_t));
} /* end of if */
else {
memmove(&iso_head[idx + 1], &iso_head[idx],
(sizeof(iso_name_t) * (iso_cnt - idx)));
memcpy(&iso_head[idx], isorec, sizeof(iso_name_t));
} /* end of else */
iso_cnt++;
rc = 0;
}
/* end of if */
return (rc);
} /* end of iso_ins() */
/*******************************************************************************\
**
** Function: void get_records()
** Desc: Reads the data from the citylist.out (text file) and formats/encodes
** them into a h_data_rec structure and adds it to the database
** Accepts: hashdb_t *dbd = Database descriptor
** char *txtname = Path name of the textfile
** Returns: Nothing (void)
**
\*******************************************************************************/
void
get_records(hashdb_t * dbd, char *txtname)
{
char *cp, /* generic ptr */
*txtflds[5], /* Text fields */
txtbuf[512]; /* Text file buffer */
int cnt = 0, hashidx, /* hash index */
isoidx, /* iso index */
txtidx, /* Index into txtflds */
txtlen; /* Length of line */
FILE *ftxt; /* text FILE handler */
h_data_rec record; /* Record */
if ((ftxt = fopen(txtname, "r")) == NULL) {
printf("Error opening textfile \"%s\", error=%s\n", txtname,
strerror(errno));
return;
}
/* end of if */
while (fgets(txtbuf, sizeof(txtbuf), ftxt) != NULL) {
txtlen = strlen(txtbuf);
if (txtbuf[txtlen - 1] == '\n')
txtbuf[--txtlen] = '\0';
/* Parse the record */
memset(&record, 0, HDB_DTAREC_SZ);
/* txtflds[0] = city name, [1] = region [2] = lat [3] = lon [4] = timezone */
for (cp = txtflds[0] = txtbuf, txtidx = 0; *cp; cp++) {
/* Once the 5th field has been found, stop! */
if (txtidx == 4)
break;
if (*cp == 0x09) {
*cp = '\0';
txtflds[++txtidx] = (cp + 1);
} /* end of if */
} /* end of for */
/* Build the h_data_rec record */
/* Make the ',' a NUL terminator in cityname (txtflds[0]) */
for (cp = txtflds[0]; *cp; cp++) {
if (*cp == ',') {
*cp = '\0';
break;
} /* end of if */
} /* end of for */
memcpy(record.city_name, txtflds[0], sizeof(record.city_name) - 1);
/* Get the correct ISO3166 2 char id */
if (!memcmp(txtflds[1], "United States", 13)) {
cp = txtflds[0] + strlen(txtflds[0]) + 1;
memcpy(record.reg, cp, 2);
} /* end of if */
else {
if ((isoidx = iso_find(txtflds[1])) >= 0)
memcpy(record.reg, iso_head[isoidx].iso_id, 2);
else
memcpy(record.reg, txtflds[1], sizeof(record.reg) - 1);
} /* end of else */
/* Set the latitude and longitude values */
record.lat = (short) atoi(txtflds[2]);
record.lon = (short) atoi(txtflds[3]);
/* Time zone is stored as a 2 character directory + a 5 character file */
if (txtflds[4][0] == '/')
memmove(&txtflds[4][0], &txtflds[4][1], strlen(txtflds[4]) - 1);
if ((cp = strrchr(txtflds[4], '/')) == NULL) {
continue;
} /* end of if */
sprintf(record.zinfo, "%2.2s%5.5s", txtflds[4], (cp + 1));
/* Hash on the latitude */
hashidx = record.lat / 60;
hashidx += 90;
if (h_addrec(dbd, hashidx, &record) == -1) {
printf("Error in h_addrec(%s,%s,%s), error=%s\n",
record.city_name, record.reg, record.zinfo,
strerror(errno));
continue;
} /* end of if */
cnt++;
} /* end of while */
fclose(ftxt);
return;
} /* end of get_records() */
--- NEW FILE: nxsunclock.cxx ---
/*
* 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.
*
[...1432 lines suppressed...]
tmp =
(h_data_rec *) realloc(city_list,
(city_size +
5) * sizeof(record));
if (tmp == NULL)
return (-1);
city_list = tmp;
} // end of else
city_size += 5;
} // end of if
memcpy(&city_list[cnt], &record, sizeof(h_data_rec));
cnt++;
} /* end of if */
} /* end of while */
} /* end of for */
h_closedb(hdbd);
// Possibly sort the list???
return (cnt);
} // end of void GetCityList(char *, int, int)
--- NEW FILE: hashdb_api.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.
*/
/* Feature test switches */
/* System header files */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/mman.h>
/* Local header files */
#include "hashdb_api.h"
/* Typedef, macros, enum/struct/union definitions */
/* Global scope variables */
/* File scope variables */
/* Static function protoypes */
/*******************************************************************************\
**
** External function definitions
**
\*******************************************************************************/
/*******************************************************************************\
**
** Function: void h_closedb()
** Desc: Closes the database file (and unmaps/unallocates) all memory
** Accepts: hashdb_t *dbd = Ptr to the database descriptor
** Returns: Nothing (void)
**
\*******************************************************************************/
void
h_closedb(hashdb_t * dbd)
{
int i; /* Loop iterator */
if (dbd != NULL) {
/* Unmap all datafiles */
if (dbd->blk_ar != NULL) {
for (i = 0; i < dbd->mapcnt; i++)
munmap(dbd->blk_ar[i].addr, dbd->blksz);
free(dbd->blk_ar);
}
/* end of if */
/* Close the file */
if (dbd->fd > -1)
close(dbd->fd);
free(dbd);
}
/* end of if */
return;
} /* end of h_closedb() */
/*******************************************************************************\
**
** Function: int h_getrecord()
** Desc: Gets the record from the specified location
** Accepts: int mode = Type of key
** HDB_KEY_HASH = hash key (look up in table)
** HDB_KEY_DATA = data key
** hashdb_t *dbd = Ptr to the db handle
** key_t key = Key of record to get
** h_data_rec *rec = Ptr to storage to copy memory to
** Returns: int; 0 on success, -1 on error
**
\*******************************************************************************/
int
h_getrecord(int mode, hashdb_t * dbd, hdb_key_t key, h_data_rec * rec)
{
h_data_rec *lrec; /* local record */
/* Check the parameters */
if (dbd == NULL || rec == NULL) {
errno = EINVAL;
return (-1);
}
/* end of if */
/* Determine the mode */
if (mode == HDB_KEY_HASH) {
if (key >= dbd->idxsz) {
errno = EINVAL;
return (-1);
} /* end of if */
key = dbd->idx_tbl[key].head;
}
/* end of if */
if (key == 0) {
errno = ENODATA;
return (-1);
}
/* end of if */
/* Get the record */
if (h_get_rec(dbd, key, &lrec) == -1) {
/* error, errno should be set */
return (-1);
}
/* end of if */
memcpy(rec, lrec, HDB_DTAREC_SZ);
return (0);
} /* end of h_getrecord() */
/*******************************************************************************\
**
** Function: hashdb_t *h_opendb()
** Desc: Opens the database specified by file and maps the first block
** Accepts: char *name = Name of the file to open
** int mode = Mode to open (using std C mode values (O_RDONLY, etc)
** Returns: hashdb_t *; Ptr to the handle structure, or NULL on error
**
\*******************************************************************************/
hashdb_t *
h_opendb(char *name, int mode)
{
char buf[HDB_INFHDR_SZ + HDB_BLKHDR_SZ + HDB_IDXHDR_SZ], /* buffer to read the file */
*cp;
int fd, /* normal file i/o descriptor */
rc; /* Return code */
struct stat statbuf; /* stat buffer */
h_info_hdr *infh; /* Ptr to the info header */
h_idx_hdr *idxh; /* Ptr to the idx header */
hashdb_t *local; /* database descriptor */
/* Validate parameters */
if (mode == 0)
mode = O_RDONLY;
if (name == NULL || *name == '\0') {
errno = EINVAL;
return (NULL);
}
/* end of if */
/* Open the file */
if ((fd = open(name, mode)) == -1)
return (NULL);
/* Read the necessary headers */
if ((rc =
read(fd, buf, HDB_INFHDR_SZ + HDB_BLKHDR_SZ + HDB_IDXHDR_SZ)) <= 0) {
/* Use default errno */
close(fd);
return (NULL);
}
/* end of if */
infh = (h_info_hdr *) buf;
idxh = (h_idx_hdr *) (buf + HDB_INFHDR_SZ + HDB_BLKHDR_SZ);
if (infh->magic != HASH_MAGIC) {
close(fd);
errno = EINVAL;
return (NULL);
}
/* end of if */
if ((local = (hashdb_t *) calloc(1, sizeof(hashdb_t))) == NULL) {
close(fd);
return (NULL);
}
/* end of if */
/* Fill in the struct */
fstat(fd, &statbuf);
local->fd = fd;
local->fsize = statbuf.st_size;
local->blksz = infh->blksz;
local->nblk = statbuf.st_size / local->blksz;
local->idxsz = idxh->idx_max_val;
local->mode = mode;
if ((rc = h_map_block(local, 0)) == -1) {
close(fd);
free(local);
return (NULL);
}
/* end of if */
/* Get the index table record */
cp = (char *) local->blk_ar[rc].addr + HDB_INFHDR_SZ + HDB_BLKHDR_SZ +
HDB_IDXHDR_SZ;
local->idx_tbl = (h_idx_rec *) cp;
return (local);
} /* end of h_opendb() */
/*******************************************************************************\
**
** Internally Callable (static) functions
**
\*******************************************************************************/
--- NEW FILE: gray_grid_240.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.
*
[...4562 lines suppressed...]
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\223"
"\223\223\230\230\230\222\222\222\233\233\233eee\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\230"
"\230\230aaa\226\226\226\215\215\215\230\230\230\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222\222"
"\222\222\226\226\226\227\227\227\223\223\223ccc\232\232\232\222\222\222\222"
"\222\222\222\222\222\222\222\222\222\222\222",};
--- NEW FILE: Makefile ---
# apps/sysconfig/about/Makefile
TARGET_SO=clock.so
INSTALL_BINDIR=$(INSTALL_DIR)/bin/sysconfig
OBJS=nxclock.o nxsunclock.o scfxn.o astro.o hashdb_api.o hashdb_low.o
INCLUDES=-I../include
include $(BASE_DIR)/Rules.make
--- NEW FILE: citylist.out ---
Denver,CO United States 2384 -6299 /US/Mountain
Salt Lake City,UT United States 2445 -6717 /US/Mountain
Chicago,IL United States 2512 -5258 /US/Central
Indianapolis,IN United States 2386 -5169 /US/Indiana-Starke
New_York,NY United States 2445 -4439 /US/Eastern
Honolulu,HI United States -1278 -9471 /US/Hawaii
Detroit,MI United States 2539 -4982 /US/Michigan
Anchorage,AK United States 3670 -8994 /US/Alaska
Phoenix,AZ United States 2007 -6724 /US/Arizona
Los_Angeles,CA United States 2043 -7094 /US/Pacific
Asmara,Eritrea Eritrea 916 2334 /Africa/Asmera
Cairo,Egypt Egypt 1800 1876 /Africa/Cairo
Kabul,Afghanistan Afghanistan 2074 4153 /Asia/Kabul
Sarajevo,Bosnia Bosnia 2629 1100 /Europe/Sarajevo
Tirane,Albania Albania 2479 1189 /Europe/Tirane
Algiers,Algeria Algeria 2202 193 /Africa/Algiers
Buenos_Aires,Argent. Argentina -2059 -3509 /America/Buenos_Aires
Andorra la Vella,Andoroa Andorra 2550 90 /Europre/Andorra
Luanda,Angola Angola -529 794 /Africa/Johannesburg
Adelaide,Australia Australia -2085 8312 /Australia/Adelaide
Melbourne,Australia Australia -2271 8707 /Australia/Melbourne
Perth,Australia Australia -1909 6970 /Australia/Perth
Vienna,Austria Austria 2893 982 /Europe/Vienna
Al_Manamah,Bahrain Bahrain 1561 3033 /Asia/Bahrain
Dhaka,Bangladesh Bangladesh 1422 5423 /Asia/Dhaka
Brussels,Belgium Belgium 3051 261 /Europe/Brussels
Porto-Novo,Benin Benin 388 157 /Africa/Porto-Novo
La_Paz,Bolivia Bolivia -991 -4090 /America/La_Paz
Gaborone,Botswana Botswana -1479 1554 /Africa/Johannesburg
Sao_Paulo,Brazil Brazil -1413 -2797 /America/Sao_Paulo
Belem,Brazil Brazil -82 -2908 /America/Belem
Manaus,Brazil Brazil -181 -3603 /America/Manaus
Sofia,Bulgaria Bulgaria 2563 1399 /Europe/Sofia
Douala,Cameroon Cameroon 241 583 /Africa/Douala
Amilcar_Cabral,C._Ver Cape Verde 1005 -1377 /Atlantic/Cape_Verde
N'djamina,Chad Chad 728 902 /Africa/Ndjamena
Santiago,Chile Chile -2005 -4239 /America/Santiago
Beijing,China China 2395 6984 /Asia/Shanghai
Shanghai,China China 1873 7287 /Asia/Shanghai
Bogota,Colombia Colombia 277 -4445 /America/Bogota
Bogota,Colombia Colombia 277 -4445 /America/Bogota
San_Jose,Costa_Rica Costa Rica 597 -5044 /America/Costa_Rica
Havana,Cuba Cuba 1387 -4942 /America/Havana
Nicosia,Cyprus Cyprus 2109 1996 /Asia/Nicosia
Prague,Czech_Rep. Czech Republic 3004 865 /Europe/Prague
Copenhagen,Denmark Denmark 3343 747 /Europe/Copenhagen
Santo_Domingo,Dom._Re Dominican Republic 1106 -4180 /America/Santo_Domingo
Guayaquil,Ecuador Ecuador -135 -4792 /America/Guayaquil
Tallinn,Estonia Estonia 3566 1484 /Europe/Tallinn
Addis_Ababa,Ethiopia Ethiopia 540 2323 /Africa/Addis_Ababa
Nandi,Fiji Fiji -1065 10647 /Pacific/Fiji
Helsinki,Finland Finland 3609 1492 /Europe/Helsinki
--- NEW FILE: astro.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.
*/
/*
* Sun clock - astronomical routines.
*/
#include "sunclock.h"
/* JDATE -- Convert internal GMT date and time to Julian day
and fraction. */
long
jdate(t)
struct tm *t;
{
long c, m, y;
y = t->tm_year + 1900;
m = t->tm_mon + 1;
if (m > 2)
m = m - 3;
else {
m = m + 9;
y--;
}
c = y / 100L; /* Compute century */
y -= 100L * c;
return t->tm_mday + (c * 146097L) / 4 + (y * 1461L) / 4 +
(m * 153L + 2) / 5 + 1721119L;
}
/* JTIME -- Convert internal GMT date and time to astronomical
Julian time (i.e. Julian date plus day fraction,
expressed as a double). */
double
jtime(t)
struct tm *t;
{
#ifdef NOTUSED
long val = t->tm_sec + (60L * (t->tm_min + 60L * t->tm_hour));
double ret = (((double) (jdate(t) + val)) - 0.5) / 86400.0;
return (ret);
#endif
return ((jdate(t) - 0.5) +
(((long) t->tm_sec) +
60L * (t->tm_min + 60L * t->tm_hour)) / 86400.0);
}
/* KEPLER -- Solve the equation of Kepler. */
double
kepler(m, ecc)
double m, ecc;
{
double e, delta;
#define EPSILON 1E-6
e = m = dtr(m);
do {
delta = e - ecc * sin(e) - m;
e -= delta / (1 - ecc * cos(e));
} while (abs(delta) > EPSILON);
return e;
}
/* SUNPOS -- Calculate position of the Sun. JD is the Julian date
of the instant for which the position is desired and
APPARENT should be nonzero if the apparent position
(corrected for nutation and aberration) is desired.
The Sun's co-ordinates are returned in RA and DEC,
both specified in degrees (divide RA by 15 to obtain
hours). The radius vector to the Sun in astronomical
units is returned in RV and the Sun's longitude (true
or apparent, as desired) is returned as degrees in
SLONG. */
void
sunpos(jd, apparent, ra, dec, rv, slong)
double jd;
int apparent;
double *ra, *dec, *rv, *slong;
{
double t, t2, t3, l, m, e, ea, v, theta, omega, eps;
/* Time, in Julian centuries of 36525 ephemeris days,
measured from the epoch 1900 January 0.5 ET. */
t = (jd - 2415020.0) / 36525.0;
t2 = t * t;
t3 = t2 * t;
/* Geometric mean longitude of the Sun, referred to the
mean equinox of the date. */
l = fixangle(279.69668 + 36000.76892 * t + 0.0003025 * t2);
/* Sun's mean anomaly. */
m = fixangle(358.47583 + 35999.04975 * t - 0.000150 * t2 -
0.0000033 * t3);
/* Eccentricity of the Earth's orbit. */
e = 0.01675104 - 0.0000418 * t - 0.000000126 * t2;
/* Eccentric anomaly. */
ea = kepler(m, e);
/* True anomaly */
v = fixangle(2 * rtd(atan(sqrt((1 + e) / (1 - e)) * tan(ea / 2))));
/* Sun's true longitude. */
theta = l + v - m;
/* Obliquity of the ecliptic. */
eps = 23.452294 - 0.0130125 * t - 0.00000164 * t2 + 0.000000503 * t3;
/* Corrections for Sun's apparent longitude, if desired. */
if (apparent) {
omega = fixangle(259.18 - 1934.142 * t);
theta = theta - 0.00569 - 0.00479 * sin(dtr(omega));
eps += 0.00256 * cos(dtr(omega));
}
/* Return Sun's longitude and radius vector */
*slong = theta;
*rv = (1.0000002 * (1 - e * e)) / (1 + e * cos(dtr(v)));
/* Determine solar co-ordinates. */
*ra =
fixangle(rtd
(atan2(cos(dtr(eps)) * sin(dtr(theta)), cos(dtr(theta)))));
*dec = rtd(asin(sin(dtr(eps)) * sin(dtr(theta))));
}
/* GMST -- Calculate Greenwich Mean Siderial Time for a given
instant expressed as a Julian date and fraction. */
double
gmst(jd)
double jd;
{
double t, theta0;
/* Time, in Julian centuries of 36525 ephemeris days,
measured from the epoch 1900 January 0.5 ET. */
t = ((floor(jd + 0.5) - 0.5) - 2415020.0) / 36525.0;
theta0 = 6.6460656 + 2400.051262 * t + 0.00002581 * t * t;
t = (jd + 0.5) - (floor(jd + 0.5));
theta0 += (t * 24.0) * 1.002737908;
theta0 = (theta0 - 24.0 * (floor(theta0 / 24.0)));
return theta0;
}
--- NEW FILE: nxsunclock.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 NXSUNCLOCK_INCLUDED
#define NXSUNCLOCK_INCLUDED 1
// System header files
// Local header files
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Clock.H>
#include <FL/Fl_Calendar.H>
#include <FL/Fl_Image.H>
#include <nximage.h>
#include <nxapp.h>
#include <nxbutton.h>
#include <nxmenubutton.h>
#include <nxoutput.h>
#include <nxtminput.h>
#include "sysconf.h"
#include <sysconfig.h>
// Typedefs, macro, enum/struct/union definitions
typedef struct
{
unsigned char red, // Red pixel value
green, // Green pixel value
blue, // Blue pixel value
alpha; // Alpha blend value
}
RGBpixel;
typedef enum
{
tzCTYQUERY = 0, // Query the time at the specified city
tzCTYSET // Sets the current timezone (either home/visiting)
}
tz_ptmode_enum;
typedef enum
{
tzHOME = 0, // Affects the home timezone only
tzVISIT // Affects the Visiting timezone only
}
tz_mode_enum;
typedef struct
{
char name[25 + 1], // City name
reg[2 + 1], // State/Country 2 char value
tz[64]; // Timezone stuff
}
city_rec_t;
typedef struct
{
city_rec_t cities[2]; // Home/Visiting city records
bool home_current; // Flag detailing which is current
unsigned char dirty_flgs; // Flags indicating what has changed and needs
// to be written back out to PAR
}
app_value_t;
// Values for app_value_t.dirty_flgs
#define APP_DFLGS_HOME 0x01 // Home city info has changed
#define APP_DFLGS_VISIT 0x02 // Visit city info has changed
#define APP_DFLGS_CUR 0x04 // Current active city has changed
#define UTILITY_PAR_NAME "worldclock"
//#define UTILITY_NAME "WorldClock"
// Class definition
class nxSunclock
{
public:
// Constructor // destructor
~nxSunclock(); // Class destructor
nxSunclock(int X, int Y, int W, int H, char *appname); // Class constructor
void *GetWindow(void);
private:
// Private data
unsigned char *_sun_array, // Buffer of modified day/night map data
*_map_array; // Buffer of original map data
char *_grImage, // Ptr to the image path
*_zndb; // Ptr to the zone database
tz_ptmode_enum _ePtMode; // Current point mode (query/set)
tz_mode_enum _eCurTzMode; // Current mode (home/visiting)
AppMode_t _appmode; // Current app mode
int _clckedit, // clock edit mode
_winX, // Windows TL X value
_winY; // Windows TL Y value
app_value_t _app_settings; // Application settings
// Fltk widgets/windows
Fl_Group *_timewin; // Window for setting date/time
Fl_Group *_sunwin; // Main window
Fl_Group *_mainw;
Fl_Calendar *_cal; // Calendar widget
// Fl_Check_Button *_dstbtn; // Dst button
Fl_Clock_Output *_tclock; // Time clock
// NxImage *_sunmap; // Sun map image
Fl_Image *_sunmap; // Sun map image
Fl_Button *_sunbutton;
NxButton *_tzbtns[2]; // Home/Visiting timezone buttons
NxTmInput *_timeui; // Widget to set the time
NxMenuButton *_selcity; // "Popup" menu button
// Private methods
void ColosseumLogger(int level, char *str, ...); // Logging function
void GetAppPrefs(void); // Get the application preferences
void MakeWindows(int, int, int, int); // Creates the fltk windows
void MakeSunwin(int w, int h); // Creates the sunclock window
void MakeTimewin(int x, int y, int w, int h); // Creates the time window
void SetAppPrefs(void); // Saves the App prefences
void SetSunclock(); // Creates the sunclock image
void SetTimes(); // Sets the time
public:
// Static Methods
static void adj_tm_cb(Fl_Widget * w, void *d); // Inc/Dec the time unit
static void map_click_cb(Fl_Widget * w, void *d); // Callback for a click on the map
static void save_exit_cb(Fl_Widget * w, void *d); // Save/Exit callback
static void sel_city_cb(Fl_Widget * w, void *d); // Call back for the city selection
static void set_dt_tm_cb(Fl_Widget * w, void *d); // Callback to set the date/time
static void set_tz_cb(Fl_Widget * w, void *d); // Change tz for active zone
static void show_sc_win_cb(Fl_Widget * w, void *d); // Call back to return to sunclock
static void Sunclock_Timeout(void *d); // Callback to update (refresh) the map
static void Timer_Timeout(void *d); // Callback to update the current time
static void Toggle_tz_cb(Fl_Widget * w, void *d); // Callback to make a timezone active
static void upd_tm_cb(Fl_Widget * w, void *d); // Update the clock's time
}; // end of nxSunclock definition
#endif // NXSUNCLOCK_INCLUDED
More information about the dslinux-commit
mailing list