home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Elysian Archive
/
AmigaElysianArchive.iso
/
wp_dtp
/
tpp400en.lha
/
tpp
/
pd
/
MSClock23.lzh
/
MSClock
/
source
/
MSClock.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-05
|
16KB
|
395 lines
/*
* MSClock.c © by Martin Steppler
*
* Yet another clock utility for use with L:MSClock-Handler
*
* last change: 05.08.91
*/
// defines
#define WriteStdOut(str) Write(StdOut, str, (LONG)strlen(str))
#define LOGNAME "S:MSClock.log"
#define PROCNAME "MSClock2.3"
// prototypes
VOID main(int, char **);
int GetOverscan(VOID);
UWORD htoin(register char *str);
// globals
struct IntuitionBase *IntuitionBase;
struct TheClock *TheClock;
struct TextFont *Font;
// here we go ...
void
main(argc, argv)
int argc;
char *argv[];
{
register struct Process *ThatsMe = (struct Process *)FindTask(NULL);
LONG DefFlag = 39; // display time, date, online time and mem
SHORT i, quit=0, help=0, log=0;
// we spent in 360 seconds 23 pfennings
// in the interval during which charges are low we spent 23 pfennigs in 720 secs
SHORT interval=360, unit=23, cinterval = 720;
// low charges interval from 18h to 8h
SHORT LCStart = 18, LCEnd = 8;
// default hotkeys: RIGHT ALT + DEL, RIGHT ALT + HELP, RIGHT (ALT+SHIFT) + DEL
UWORD DCode = 0x0046, DQualif = 0x0020, SCode = 0x005F, SQualif = 0x0020,
JCode = 0x0041, JQualif = 0x0020;
// default viewmode: view all
BYTE v=0, GadWidth;
BPTR StdOut = (BPTR)Open((UBYTE *)"*", MODE_OLDFILE);
LONG flag = 0;
// open libraries
// check for OS2.0 / VERSION 36 or higher
if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library", 36))) {
if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary((UBYTE *)"intuition.library",0))) {
goto abort;
}
else GadWidth = FRONTBACKGAD_WIDTH;
}
else GadWidth = FBGAD_WIDTH_NEW_OS;
// Is the TheClock structure anywhere?
if(TheClock = (struct TheClock *)FindPort((UBYTE *)PORTNAME)) DefFlag = TheClock->Flags;
for (i = 1; i < argc; i++) {
if(!strcmp(argv[i], "quit") || !strcmp(argv[i], "-q")) {
quit = 1;
break;
}
else if(!strcmp(argv[i], "-t")) { DefFlag = (DefFlag & TIME_FLAG) ? (DefFlag & (SUM_FLAG - TIME_FLAG)) :(DefFlag | TIME_FLAG); }
else if(!strcmp(argv[i], "-d")) { DefFlag = (DefFlag & DATE_FLAG) ? (DefFlag & (SUM_FLAG - DATE_FLAG)) :(DefFlag | DATE_FLAG); }
else if(!strcmp(argv[i], "-m")) { DefFlag = (DefFlag & MEMORY_FLAG) ? (DefFlag & (SUM_FLAG - MEMORY_FLAG)) :(DefFlag | MEMORY_FLAG); }
else if(!strcmp(argv[i], "-e")) { DefFlag = (DefFlag & ENGLISH_FLAG) ? (DefFlag & (SUM_FLAG - ENGLISH_FLAG)) :(DefFlag | ENGLISH_FLAG); }
else if(!strcmp(argv[i], "-r")) { DefFlag = (DefFlag & REVERSE_FLAG) ? (DefFlag & (SUM_FLAG - REVERSE_FLAG)) :(DefFlag | REVERSE_FLAG); }
else if(!strcmp(argv[i], "-o")) { DefFlag = (DefFlag & ONLINE_FLAG) ? (DefFlag & (SUM_FLAG - ONLINE_FLAG)) :(DefFlag | ONLINE_FLAG); }
else if(!strcmp(argv[i], "-h")) { DefFlag = (DefFlag & HOLIDAY_FLAG) ? (DefFlag & (SUM_FLAG - HOLIDAY_FLAG)) :(DefFlag | HOLIDAY_FLAG); }
else if(!strcmp(argv[i], "-s")) { DefFlag = (DefFlag & START_STOP_FLAG) ? (DefFlag & (SUM_FLAG - START_STOP_FLAG)) :(DefFlag | START_STOP_FLAG); }
else if(!strcmp(argv[i], "-nl")) { DefFlag = (DefFlag & NO_LOGFILE_FLAG) ? (DefFlag & (SUM_FLAG - NO_LOGFILE_FLAG)) :(DefFlag | NO_LOGFILE_FLAG); }
else if(!strcmp(argv[i], "-ns")) { DefFlag = (DefFlag & NO_SECONDS_FLAG) ? (DefFlag & (SUM_FLAG - NO_SECONDS_FLAG)) :(DefFlag | NO_SECONDS_FLAG); }
else if(!strcmp(argv[i], "-aj")) { DefFlag = (DefFlag & AUTO_JUMP_FLAG) ? (DefFlag & (SUM_FLAG - AUTO_JUMP_FLAG)) :(DefFlag | AUTO_JUMP_FLAG); }
else if(!strcmp(argv[i], "-u")) {
if(i+1 < argc) {
unit = atoi(argv[++i]);
if(unit>=1 || unit<=99) flag |= 1;
else unit = 23;
}
else help = 1;
}
// interval
else if(!strcmp(argv[i], "-i")) {
if(i+1 < argc) {
interval = atoi(argv[++i]);
if(interval>=1 && interval <=1000) flag |= 2;
else interval = 360;
}
else help = 1;
}
// low charges interval
else if(!strcmp(argv[i], "-c")) {
if(i+1 < argc) {
cinterval = atoi(argv[++i]);
if(cinterval>=1 && cinterval <=1000) flag |= 4;
else cinterval = 720;
}
else help = 1;
}
// view mode
else if(!strcmp(argv[i], "-v")) {
if(i+1 < argc) {
v = atoi(argv[++i]);
if(v<0 || v >3) v=0;
else flag |= 512;
}
else help = 1;
}
// change display code
else if(!strcmp(argv[i], "-dc")) {
if(i+1 < argc) {
DCode = htoin(argv[++i]);
if(DCode <=255) flag |= 8;
else DCode = 0x0046;
}
else help = 1;
}
// change display qualifier
else if(!strcmp(argv[i], "-dq")) {
if(i+1 < argc) {
DQualif = htoin(argv[++i]);
if(DQualif <=255) flag |= 16;
else DQualif = 0x0020;
}
else help = 1;
}
// start/stop counter code
else if(!strcmp(argv[i], "-sc")) {
if(i+1 < argc) {
SCode = htoin(argv[++i]);
if(SCode<=255) flag |= 32;
else SCode = 0x005F;
}
else help = 1;
}
// start/stop counter qualifier
else if(!strcmp(argv[i], "-sq")) {
if(i+1 < argc) {
SQualif = htoin(argv[++i]);
if(SQualif<=255) flag |= 64;
else SQualif=0x0020;
}
else help = 1;
}
// start of low charges interval
else if(!strcmp(argv[i], "-cs")) {
if(i+1 < argc) {
LCStart = atoi(argv[++i]);
if(LCStart>=0 && LCStart <=24) flag |= 128;
else LCStart = 18;
}
else help = 1;
}
// end of low charges interval
else if(!strcmp(argv[i], "-ce")) {
if(i+1 < argc) {
LCEnd = atoi(argv[++i]);
if(LCEnd>=0 && LCEnd <=24) LCEnd |= 256;
else LCEnd=8;
}
else help = 1;
}
// jump to next screen code
else if(!strcmp(argv[i], "-jc")) {
if(i+1 < argc) {
JCode = htoin(argv[++i]);
if(JCode<=255) flag |= 1024;
else JCode = 0x0046;
}
else help = 1;
}
// jump to next screen qualifier
else if(!strcmp(argv[i], "-jq")) {
if(i+1 < argc) {
JQualif = htoin(argv[++i]);
if(JQualif<=255) flag |= 2048;
else JQualif=0x0022;
}
else help = 1;
}
// change name of logfile
else if(!strcmp(argv[i], "-l")) {
if(++i < argc) log=i;
else help = 1;
}
else { help = 1; break; }
}
if(help && StdOut) {
WriteStdOut("\33[33mMSClock V2.3\33[31m © 05.08.91 by Martin Steppler\n");
WriteStdOut("USAGE: MSClock {<flag> [<value>]}\n");
WriteStdOut(" -t Time off/on default: on\n");
WriteStdOut(" -d Date off/on default: on\n");
WriteStdOut(" -m Memory off/on default: on\n");
WriteStdOut(" -e English weekdays on/off default: German on\n");
WriteStdOut(" -r Reverse date display on/off default: off\n");
WriteStdOut(" -o Online time off/on default: on\n");
WriteStdOut(" -s Start/stop counter default: off\n");
WriteStdOut(" -h Holiday on/off default: off\n");
WriteStdOut(" -u 1-99 Unit spent in one interval default: 23\n");
WriteStdOut(" -i 1-1000 Interval in seconds default: 360\n");
WriteStdOut(" -c 1-1000 interval in seconds during default: 720\n");
WriteStdOut(" which Charges are low\n");
WriteStdOut(" -cs 0-24 low Charges Start (0-24 h) default: 18 h\n");
WriteStdOut(" -ce 0-24 low Charges End (0-24 h) default: 8 h\n");
WriteStdOut(" -dq Qual Display Qualifier default: 20 (RIGHT ALT)\n");
WriteStdOut(" -dc Code Display Code default: 46 (DEL)\n");
WriteStdOut(" -sq Qual Start/stop counter Qualifier default: 20 (RIGHT ALT)\n");
WriteStdOut(" -sc Code Start/stop counter Code default: 5F (HELP)\n");
WriteStdOut(" -jq Qual Jump to active screen Qual. default: 20 (RIGHT ALT)\n");
WriteStdOut(" -jc Code Jump to active screen Code default: 41 (BS)\n");
WriteStdOut(" -aj Auto-Jump to active screen default: off\n");
WriteStdOut(" -l T:MyLog use MyLog as logfile default: S:MSClock.log\n");
WriteStdOut(" -nl do Not use any Logfile default: off\n");
WriteStdOut(" -ns do Not display Seconds default: off\n");
WriteStdOut(" -v 0-3 Viewmodes 0-3 all/t+d/m/o default: 0\n");
WriteStdOut(" -q Quit MSClock\n");
}
else if(!TheClock && !quit) {
// No, then Create Process
if(TheClock = (struct TheClock *)AllocMem(sizeof(struct TheClock),MEMF_PUBLIC | MEMF_CLEAR)) {
// Dummy MessagePort.
TheClock -> Port . mp_Flags = PA_IGNORE;
TheClock -> Port . mp_Node . ln_Pri = 0;
TheClock -> Port . mp_Node . ln_Type= NT_MSGPORT;
TheClock -> Port . mp_Node . ln_Name= AllocMem(sizeof(PORTNAME),MEMF_PUBLIC);
// initialize TheClock structure
TheClock -> Child = NULL;
TheClock -> Father = (struct Task *)ThatsMe;
TheClock -> SegSize = sizeof(struct TheClock);
TheClock -> LastSecs = 100;
TheClock -> OverScan = GetOverscan();
TheClock -> Online = FALSE;
TheClock -> Flags = DefFlag;
TheClock -> FlagsBackup = DefFlag;
TheClock -> Unit = unit;
TheClock -> Interval = interval;
TheClock -> CInterval = cinterval;
TheClock -> HotKeyCode = DCode;
TheClock -> HotKeyQualif = DQualif;
TheClock -> StartStopCode = SCode;
TheClock -> StartStopQualif = SQualif;
TheClock -> JumpCode = JCode;
TheClock -> JumpQualif = JQualif;
TheClock -> LowChargesStart = LCStart;
TheClock -> LowChargesEnd = LCEnd;
TheClock -> Viewmodes = v;
TheClock -> ModesBackup = v;
TheClock -> FBGadWidth = GadWidth;
TheClock -> Font = Font;
if(log) strcpy(TheClock->Logfile, argv[log]);
else strcpy(TheClock->Logfile, LOGNAME);
// Init port.
strcpy(TheClock -> Port . mp_Node . ln_Name,PORTNAME);
NewList(&TheClock -> Port . mp_MsgList);
// Load the handler code.
if(!(TheClock -> Segment = LoadSeg((UBYTE *)"MSClock-Handler")))
TheClock -> Segment = LoadSeg((UBYTE *)"L:MSClock-Handler");
if(!TheClock -> Segment)
{
FreeMem(TheClock -> Port . mp_Node . ln_Name,sizeof(PORTNAME));
FreeMem(TheClock,TheClock -> SegSize);
if(StdOut) WriteStdOut("Installation of \33[33mMartin Steppler's Clock V2.3\33[31m failed. Don't panic!!!\n");
}
else
{
// Install the port and start the handler.
AddPort(&TheClock -> Port);
CreateProc((UBYTE *)PROCNAME, 5,TheClock -> Segment,4096);
// Wait for child task to ring back...
Wait(CHILD_READY);
if(!TheClock -> Child) // failed
{
RemPort(&TheClock -> Port);
FreeMem(TheClock -> Port . mp_Node . ln_Name,sizeof(PORTNAME));
if(TheClock -> Segment) UnLoadSeg(TheClock -> Segment);
FreeMem(TheClock,TheClock -> SegSize);
if(StdOut) WriteStdOut("Installation of \33[33mMartin Steppler's Clock V2.3\33[31m failed. Don't panic!\n");
}
else // Yeah, it works
if(StdOut) WriteStdOut("It is my pleasure to install \33[33mMartin Steppler's Clock V2.3\33[31m for you!\n");
}
}
}
else if(TheClock && quit) {
TheClock -> Father = (struct Task *)ThatsMe;
Signal(TheClock -> Child,SIG_CLOSE);
Wait(CHILD_READY);
// Remove port and associated data.
RemPort(&TheClock -> Port);
FreeMem(TheClock -> Port . mp_Node . ln_Name,sizeof(PORTNAME));
if(TheClock -> Segment) UnLoadSeg(TheClock -> Segment);
FreeMem(TheClock,TheClock -> SegSize);
if(StdOut) {
WriteStdOut("It is my satisfaction to close \33[33mMartin Steppler's Clock V2.3\33[31m again\n");
WriteStdOut("with the knowledge of a job well done!\n");
}
}
else if(TheClock) {
// store changes and signal child
TheClock->FlagsBackup = DefFlag;
TheClock->OverScan = GetOverscan();
TheClock->ModesBackup = TheClock->Viewmodes;
if(flag & 1) TheClock -> Unit = unit;
if(flag & 2) TheClock -> Interval = interval;
if(flag & 4) TheClock -> CInterval = cinterval;
if(flag & 8) TheClock -> HotKeyCode = DCode;
if(flag & 16) TheClock -> HotKeyQualif = DQualif;
if(flag & 32) TheClock -> StartStopCode = SCode;
if(flag & 64) TheClock -> StartStopQualif = SQualif;
if(flag & 128) TheClock -> LowChargesStart = LCStart;
if(flag & 256) TheClock -> LowChargesEnd = LCEnd;
if(flag & 512) TheClock -> ModesBackup = v;
if(flag & 1024) TheClock -> JumpCode = JCode;
if(flag & 2048) TheClock -> JumpQualif = JQualif;
if(log) strcpy(TheClock->Logfile, argv[log]);
TheClock -> Father = (struct Task *)ThatsMe;
Signal(TheClock -> Child, SIG_CHANGE);
Wait(CHILD_READY);
if(StdOut) {
WriteStdOut("It is my satisfaction to change \33[33mMartin Steppler's Clock V2.3\33[31m for you\n");
WriteStdOut("with the knowledge of a job well done!\n");
}
}
abort:
if(StdOut) Close(StdOut);
if(IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
}
GetOverscan(void)
{
register struct Screen *WBench;
register ULONG IntuiLock;
// Start with the first one.
IntuiLock = LockIBase(0L);
WBench = IntuitionBase -> FirstScreen;
UnlockIBase(IntuiLock);
// Scan the list...
do
{
// The type we want?
if((WBench -> Flags & SCREENTYPE) == WBENCHSCREEN) {
Font = WBench -> RastPort . Font;
return(WBench -> Width);
}
}
while(WBench = WBench -> NextScreen);
// Failed!
return(640);
}
// HEX --> UWORD
UWORD
htoin(register char *str)
{
REGISTER UWORD val = 0;
REGISTER char c;
while (c = *str) {
val <<= 4;
val |= (c & 15) + (isdigit(c) ? 0 : 9);
str++;
}
return(val);
}