home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
MM1
/
CMDS
/
sclock.lzh
/
sclock.c
< prev
Wrap
C/C++ Source or Header
|
1992-09-08
|
8KB
|
200 lines
/*
* SClock -- Written (August, 1992) by Blair Leduc
*
* This program displays a clock at the top of the screen. The clock is
* drawn on the screen with its own internal font. This font can be modified
* by patching the program, or by changing the "numbers.h" header file. See
* the header file for more information concerning the font.
*
* This is a quick and dirty way of putting a clock on the top of the
* screen. A path to the screen is opened only long enough to get the screen
* information packet. Be sure to kill the clock _before_ you kill the
* window, or it will continue to modify the screen memory (even if it is no
* longer screen memory). By the way, this is completely invisible to the
* system, as the system has no way of knowing that the program is modifying
* the screen (which causes a problem when the arrow is moved over the clock).
*
*/
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <wind.h>
#include <ctype.h>
#include "numbers.h"
#ifndef TRUE /* make sure TRUE/FALSE is */
# define TRUE 1 /* defined */
# define FALSE 0
#endif
#define TICKS 50 /* amount of time between */
/* time ckecks */
char rnum[11][7][8];
void Help() /* Show user how to use */
{ /* program */
fprintf(stderr,"Syntax: SClock [<opts>] <device> [<opts>]\n");
fprintf(stderr,"Function: Display clock anywhere on the screen.\n");
fprintf(stderr,"Options:\n");
fprintf(stderr," -b=<num> Background colour of clock\n");
fprintf(stderr," -f=<num> Foreground colour of clock\n");
fprintf(stderr," -h Hourly chime\n");
fprintf(stderr," -m Display in military time format\n");
fprintf(stderr," -c=<col> Horizontal position of clock\n");
fprintf(stderr," -l=<line> Vertical position of clock\n");
exit(0);
}
main(argc,argv)
int argc;
char **argv;
{
register int i,j,k;
int path, col=0, line=0, clr=255, back=0;
SCINFO spack;
struct sgtbuf ti, last;
char dev[29], done=FALSE, military=FALSE, chime=FALSE;
char tstr[10], *start;
*dev=(char)NULL;
for(i=1; i<argc; i++) /* Parse command line */
if (argv[i][0]=='-')
{
j=1;
done=FALSE;
while (argv[i][j] && !done)
switch (tolower(argv[i][j++]))
{
case 'c': col=atoi(&argv[i][j+1]);/* Col pos of clock */
done=TRUE;
break;
case 'f': clr=atoi(&argv[i][j+1]);/* FG colour of clk */
done=TRUE;
break;
case 'l': line=atoi(&argv[i][j+1]);/* Line pos of clk */
done=TRUE;
break;
case 'b': back=atoi(&argv[i][j+1]);/* BG colour of clk */
done=TRUE;
break;
case 'm': military=TRUE; /* Put in military time */
break;
case 'h': chime=TRUE;
break;
default: Help(); /* Don't understand opts? */
break;
}
} /* no '-', must be device */
else
{
if (*dev) /* "We already got one!" */
{
fprintf(stderr,"SClock: multiple devices not yet supported.\n");
exit(1);
}
else
strcpy(dev,argv[i]);
}
if (!(*dev))
{
fprintf(stderr,"SClock: Device required!\n");
exit(1);
}
path=open(dev,3); /* Grab scinfo; that's all */
if (path<3)
{
fprintf(stderr,"SClock: Cannot open device!\n");
exit(errno);
}
_gs_scinfo(path,&spack);
close(path); /* Don't need the open path */
if (spack.sd_bitsperpixel==4) /* Convert font to screen */
{ /* format with proper colours */
clr&=0x0F; /* 16-colour screen */
back&=0x0F;
for(i=0; i<11; i++)
for(j=0; j<7; j++)
for(k=0; k<4; k++)
{
if (tnumber[i][j][k<<1]=='X')
rnum[i][j][k]=clr<<4;
else
rnum[i][j][k]=back<<4;
if (tnumber[i][j][(k<<1)+1]=='X')
rnum[i][j][k]|=clr;
else
rnum[i][j][k]|=back;
}
}
else if (spack.sd_bitsperpixel==8) /* 256-colour screen */
{
clr&=0xFF;
back&=0xFF;
for(i=0; i<11; i++)
for(j=0; j<7; j++)
for(k=0; k<8; k++)
rnum[i][j][k]=(tnumber[i][j][k]=='X')?clr:back;
}
else /* something is wrong */
{
fprintf(stderr,"SClock: Unknown screen format.\n");
exit(1);
}
/* top left corner of clock */
start=spack.sd_address+(col*spack.sd_bitsperpixel)+(line*spack.sd_phy_width*8);
while(TRUE) /* Do this forever */
{
getime(&ti); /* Get the time */
/* Has it changed? */
if (memcmp(&ti,&last,sizeof(struct sgtbuf)))
{
if (military) /* Put time in right format */
sprintf(tstr,"%02d:%02d:%02d",ti.t_hour,ti.t_minute,ti.t_second);
else
sprintf(tstr,"%2d:%02d:%02d",((i=(ti.t_hour)?ti.t_hour:12)>12)?i-12:i,
ti.t_minute, ti.t_second);
/* Draw clock on the screen */
drawclock(start,tstr,8,spack.sd_phy_width,spack.sd_bitsperpixel,back);
_strass(&last,&ti,sizeof(struct sgtbuf));
if (ti.t_minute==0 && ti.t_second==0 && chime)
write(1,"\x07",1);
}
tsleep(TICKS); /* Nighty-night */
}
}
/* Draw clock with int. font */
drawclock(ptr,str, size, width, pixel, bclr)
char *ptr, *str;
int size, pixel, bclr;
short width;
{
register int i,j,k;
char *pos;
if (pixel==4) /* Fill both pixels in byte */
bclr|=bclr<<4;
for(i=0; i<7; i++, ptr+=width) /* Each char is 7 pixels high */
{
pos=ptr; /* Start at the left */
for(j=0; j<size; j++) /* One character at a time */
{
for(k=0; k<pixel; k++) /* Loop to draw a character */
{
if (str[j]==NULL) /* At end of the string */
break;
if (str[j]==':') /* Draw colon */
*(pos++)=rnum[10][i][k];
else if (str[j]==' ') /* Draw space */
*(pos++)=bclr;
else /* Draw number */
*(pos++)=rnum[str[j]-48][i][k];
}
}
}
}