build: add the SIBO SDK
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
@echo off
|
||||
call checkvid
|
||||
if exist %1.pr goto custom
|
||||
tsc %1.c /fpunnamed /%jpivid%
|
||||
goto end
|
||||
:custom
|
||||
tsc %1.c /fp%1 /%jpivid%
|
||||
:end
|
||||
@@ -0,0 +1,2 @@
|
||||
@if not "%jpivid%"=="v2" set jpivid=v0
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
days.pic
|
||||
days.rsc
|
||||
days.shd
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
Days.ANN
|
||||
\ANN\
|
||||
3
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
dump.pic
|
||||
dump.rsc
|
||||
dump.shd
|
||||
@@ -0,0 +1,660 @@
|
||||
/*
|
||||
DUMP.C
|
||||
|
||||
Written by DavidW
|
||||
Started on 27/11/91
|
||||
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_file.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
GLREF_D UWORD DatLocked;
|
||||
GLREF_D TEXT *DatUsedPathNamePtr;
|
||||
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"oOpen",
|
||||
"wWrite",
|
||||
"fFind text",
|
||||
"bFind bytes",
|
||||
"aFind again",
|
||||
"gGoto",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define FILE_ITEMS 2
|
||||
#define FIND_ITEMS 3
|
||||
#define SPECIAL_ITEMS 2
|
||||
|
||||
#define ITEMS_BEFORE_FILE 0
|
||||
#define ITEMS_BEFORE_FIND FILE_ITEMS
|
||||
#define ITEMS_BEFORE_SPECIAL (ITEMS_BEFORE_FIND+FIND_ITEMS)
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"File",FILE_ITEMS,
|
||||
"Find",FIND_ITEMS,
|
||||
"Special",SPECIAL_ITEMS,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D TEXT filename[P_FNAMESIZE+2];
|
||||
LOCAL_D VOID *fcb;
|
||||
|
||||
LOCAL_D LONG lpos;
|
||||
LOCAL_D LONG last;
|
||||
|
||||
LOCAL_D UWORD DisplayPending;
|
||||
|
||||
LOCAL_D VOID *wfcb;
|
||||
|
||||
LOCAL_D TEXT findt[14]={0};
|
||||
LOCAL_D UWORD caset=1;
|
||||
LOCAL_D TEXT findb[14]={0};
|
||||
LOCAL_D TEXT *pfind;
|
||||
LOCAL_D UWORD casef;
|
||||
LOCAL_D LONG fpos=(-1);
|
||||
|
||||
|
||||
LOCAL_C VOID Check(INT val)
|
||||
{
|
||||
TEXT buf[64];
|
||||
|
||||
if (val<0)
|
||||
{
|
||||
wCancelBusyMsg();
|
||||
uForceToFront();
|
||||
DatLocked=TRUE;
|
||||
p_errs(&buf[0],val);
|
||||
wsAlertW(WS_ALERT_CLIENT,&buf[0],"Terminating application",0);
|
||||
p_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID DoSeek(INT sense,LONG *ppos)
|
||||
{
|
||||
Check(p_seek(fcb,sense,ppos));
|
||||
}
|
||||
|
||||
LOCAL_C INT WriteLine(INT ignore,TEXT *pb)
|
||||
{
|
||||
return(p_write(wfcb,pb,38));
|
||||
}
|
||||
|
||||
LOCAL_C INT PrintLine(INT lineno,TEXT *pb)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=6;
|
||||
box.tl.y=4+9*lineno;
|
||||
box.br.x=234;
|
||||
box.br.y=box.tl.y+9;
|
||||
gPrintBoxText(&box,8,G_TEXT_ALIGN_LEFT,0,pb,38);
|
||||
return(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID Output(INT len,INT nlines,INT DoLine(INT,TEXT *))
|
||||
{
|
||||
TEXT inbuf[64];
|
||||
TEXT outbuf[38];
|
||||
INT i;
|
||||
LONG loclpos;
|
||||
INT linelen;
|
||||
TEXT *pin;
|
||||
TEXT *pout1;
|
||||
TEXT *pout2;
|
||||
INT val;
|
||||
|
||||
Check(p_read(fcb,&inbuf[0],len));
|
||||
pin=(&inbuf[0]);
|
||||
loclpos=lpos;
|
||||
for (i=0; i<nlines; i++)
|
||||
{
|
||||
p_atos(&outbuf[0],"%05lx",loclpos);
|
||||
loclpos+=8;
|
||||
linelen=(len<8? len: 8);
|
||||
len-=linelen;
|
||||
pout1=(&outbuf[5]);
|
||||
pout2=(&outbuf[30]);
|
||||
p_bfil(pout1,33,32);
|
||||
while (linelen--)
|
||||
{
|
||||
val=(*pin++);
|
||||
p_atos(pout1," %02x",val);
|
||||
pout1+=3;
|
||||
*pout2++=(val<32? 8: val);
|
||||
}
|
||||
*pout1=32;
|
||||
if (DoLine(i,&outbuf[0]))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID Display(VOID)
|
||||
{
|
||||
LONG ldiff;
|
||||
|
||||
DoSeek(P_FABS,&lpos);
|
||||
ldiff=last-lpos;
|
||||
Output((ldiff<64? (INT)ldiff: 64),8,PrintLine);
|
||||
DisplayPending=FALSE;
|
||||
}
|
||||
|
||||
LOCAL_C VOID ResetDisplay(VOID)
|
||||
{
|
||||
last=0;
|
||||
DoSeek(P_FEND,&last);
|
||||
lpos=0;
|
||||
Display();
|
||||
}
|
||||
|
||||
LOCAL_C INT TryOpenFile(TEXT *pb,VOID **newfcb)
|
||||
{
|
||||
return(uErrorValue(p_open(newfcb,pb,P_FOPEN|P_FRANDOM)));
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeOverTo(TEXT *newname,VOID *newfcb)
|
||||
{
|
||||
p_close(fcb);
|
||||
fcb=newfcb;
|
||||
p_scpy(&filename[0],newname);
|
||||
hSetUpStatusNames(&filename[0]);
|
||||
wsUpdate(WS_UPDATE_NAME);
|
||||
ResetDisplay();
|
||||
}
|
||||
|
||||
LOCAL_C VOID SetupFilename(TEXT *pb)
|
||||
{
|
||||
p_bcpy(pb+1,DatUsedPathNamePtr,*pb=p_slen(DatUsedPathNamePtr));
|
||||
}
|
||||
|
||||
LOCAL_C VOID OpenFile(VOID)
|
||||
{
|
||||
H_DI_FSEL open;
|
||||
TEXT openbuf[P_FNAMESIZE+2];
|
||||
VOID *newfcb;
|
||||
|
||||
SetupFilename(&openbuf[0]);
|
||||
do
|
||||
{
|
||||
if (uOpenDialog("Dump"))
|
||||
return;
|
||||
open.flags=H_FILE_PICK_SELECTOR;
|
||||
open.fname=(&openbuf[0]);
|
||||
if (uAddDialogItem(H_DIALOG_FSEL,"File:",&open))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
openbuf[1+openbuf[0]]=0;
|
||||
} while (TryOpenFile(&openbuf[1],&newfcb));
|
||||
ChangeOverTo(&openbuf[1],newfcb);
|
||||
}
|
||||
|
||||
LOCAL_C VOID WriteFile(VOID)
|
||||
{
|
||||
H_DI_FSEL write;
|
||||
TEXT writebuf[P_FNAMESIZE+2];
|
||||
LONG beg;
|
||||
LONG end;
|
||||
LONG diff;
|
||||
H_DI_NUMBER numbeg;
|
||||
H_DI_NUMBER numend;
|
||||
INT len;
|
||||
INT stop;
|
||||
|
||||
if (uErrorValue(p_fparse(".dmp",DatUsedPathNamePtr,&writebuf[1],NULL)))
|
||||
return;
|
||||
writebuf[0]=p_slen(&writebuf[1]);
|
||||
write.fname=(&writebuf[0]);
|
||||
write.flags=H_FILE_NEW_EDITOR;
|
||||
beg=0;
|
||||
end=last;
|
||||
numbeg.value=(&beg);
|
||||
numbeg.low=0;
|
||||
numbeg.high=last;
|
||||
numend.value=(&end);
|
||||
numend.low=0;
|
||||
numend.high=last;
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Write dump to file"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_FSEL,"File:",&write))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"From offset",&numbeg))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"To offset",&numend))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
diff=end-beg;
|
||||
if (diff<=0)
|
||||
{
|
||||
wInfoMsg("`To' offset must exceed `From' offset");
|
||||
continue;
|
||||
}
|
||||
writebuf[1+writebuf[0]]=0;
|
||||
if (!uErrorValue(p_open(&wfcb,
|
||||
&writebuf[1],P_FTEXT|P_FREPLACE|P_FUPDATE)))
|
||||
break;
|
||||
}
|
||||
DoSeek(P_FABS,&beg);
|
||||
stop=FALSE;
|
||||
FOREVER
|
||||
{
|
||||
if (diff>64)
|
||||
len=64;
|
||||
else
|
||||
{
|
||||
len=(INT)diff;
|
||||
stop=TRUE;
|
||||
}
|
||||
Output(len,len/8,WriteLine);
|
||||
if (stop)
|
||||
break;
|
||||
diff-=64;
|
||||
}
|
||||
p_close(wfcb);
|
||||
wInfoMsg("Dump written to file");
|
||||
}
|
||||
|
||||
LOCAL_C VOID GotoLpos(VOID)
|
||||
{
|
||||
H_DI_NUMBER num;
|
||||
|
||||
if (last<=64)
|
||||
{
|
||||
wInfoMsg("Whole file is already visible");
|
||||
return;
|
||||
}
|
||||
if (uOpenDialog(NULL))
|
||||
return;
|
||||
num.value=(&lpos);
|
||||
num.low=0;
|
||||
num.high=last-64;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Goto",&num))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
Display();
|
||||
}
|
||||
|
||||
LOCAL_C VOID HighlightBlock(INT x,INT y)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.y=4+9*y;
|
||||
box.br.y=box.tl.y+9;
|
||||
if (&findb[0]==pfind)
|
||||
{
|
||||
box.tl.x=41+18*x;
|
||||
box.br.x=box.tl.x+13;
|
||||
}
|
||||
else
|
||||
{
|
||||
box.tl.x=185+6*x;
|
||||
box.br.x=box.tl.x+7;
|
||||
}
|
||||
gClrRect(&box,G_TRMODE_INV);
|
||||
wFlush();
|
||||
p_sleep(10);
|
||||
gClrRect(&box,G_TRMODE_INV);
|
||||
}
|
||||
|
||||
LOCAL_C VOID HighlightFpos(VOID)
|
||||
{
|
||||
INT offset;
|
||||
|
||||
if (fpos<lpos)
|
||||
lpos=fpos;
|
||||
else if (fpos>lpos+63)
|
||||
{
|
||||
lpos=fpos;
|
||||
if (lpos>last-64)
|
||||
lpos=last-64;
|
||||
}
|
||||
Display();
|
||||
offset=(INT)(fpos-lpos);
|
||||
HighlightBlock(offset%8,offset/8);
|
||||
}
|
||||
|
||||
LOCAL_C INT DoSearch(LONG *ptot)
|
||||
{
|
||||
TEXT buf[256];
|
||||
INT toread;
|
||||
TEXT *pb;
|
||||
INT j;
|
||||
INT offset;
|
||||
INT len;
|
||||
|
||||
DoSeek(P_FABS,ptot);
|
||||
toread=256;
|
||||
pb=(&buf[0]);
|
||||
offset=0;
|
||||
wSetBusyMsg("Searching",W_CORNER_BOTTOM_LEFT|2);
|
||||
FOREVER
|
||||
{
|
||||
len=p_read(fcb,pb,toread);
|
||||
if (len==E_FILE_EOF)
|
||||
break;
|
||||
Check(len);
|
||||
if (casef==2)
|
||||
j=p_bsub(&buf[0],len+offset,pfind+1,*pfind);
|
||||
else
|
||||
j=p_bsubi(&buf[0],len+offset,pfind+1,*pfind);
|
||||
if (j>=0)
|
||||
{
|
||||
fpos=(*ptot)+j;
|
||||
wCancelBusyMsg();
|
||||
HighlightFpos();
|
||||
return(0);
|
||||
}
|
||||
if (len<toread)
|
||||
break;
|
||||
*ptot+=toread+offset-12;
|
||||
pb=(TEXT *)p_bcpy(&buf[0],&buf[256-12],12);
|
||||
offset=12;
|
||||
toread=256-12;
|
||||
}
|
||||
wCancelBusyMsg();
|
||||
return(-1);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SearchAll(VOID)
|
||||
{
|
||||
LONG tot;
|
||||
|
||||
tot=0;
|
||||
if (DoSearch(&tot))
|
||||
{
|
||||
wInfoMsg("Not found");
|
||||
fpos=(-1);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID FindText(VOID)
|
||||
{
|
||||
H_DI_EDIT ed;
|
||||
|
||||
if (uOpenDialog("Find"))
|
||||
return;
|
||||
ed.str=(&findt[0]);
|
||||
ed.len=12;
|
||||
if (uAddDialogItem(H_DIALOG_EDIT,"Text",&ed))
|
||||
return;
|
||||
if (uAddChoiceList("Case sensitive",&caset,"No","Yes",NULL))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
pfind=(&findt[0]);
|
||||
casef=caset;
|
||||
SearchAll();
|
||||
}
|
||||
|
||||
LOCAL_C VOID LoadBytes(TEXT *pout)
|
||||
{
|
||||
INT len;
|
||||
TEXT *pin;
|
||||
|
||||
len=findb[0];
|
||||
*pout++=len*2;
|
||||
pin=(&findb[1]);
|
||||
while (len--)
|
||||
{
|
||||
p_atos(pout,"%02x",*pin++);
|
||||
pout+=2;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C INT RecoverBytes(TEXT *pin)
|
||||
{
|
||||
TEXT buf[30];
|
||||
INT len;
|
||||
TEXT *pout;
|
||||
TEXT *newpin;
|
||||
UBYTE tmp;
|
||||
|
||||
if (p_bloc(pin+1,*pin,32)>=0)
|
||||
{
|
||||
wInfoMsg("Don't type any spaces");
|
||||
return(-1);
|
||||
}
|
||||
if (*pin&1)
|
||||
{
|
||||
wInfoMsg("Type bytes as two characters each");
|
||||
return(-1);
|
||||
}
|
||||
len=buf[0]=(*pin++)/2;
|
||||
pout=(&buf[1]);
|
||||
while (len--)
|
||||
{
|
||||
newpin=pin+2;
|
||||
tmp=(*newpin);
|
||||
*newpin=0;
|
||||
if (p_stog(&pin,(UWORD *)pout,16) || pin!=newpin)
|
||||
{
|
||||
p_atos(&buf[0],"Conversion failure at %s",newpin-2);
|
||||
wInfoMsg(&buf[0]);
|
||||
*newpin=tmp;
|
||||
return(-1);
|
||||
}
|
||||
*newpin=tmp;
|
||||
pout++;
|
||||
}
|
||||
p_bcpy(&findb[0],&buf[0],buf[0]+1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID FindBytes(VOID)
|
||||
{
|
||||
TEXT bytes[26];
|
||||
H_DI_EDIT ed;
|
||||
|
||||
LoadBytes(&bytes[0]);
|
||||
ed.str=(&bytes[0]);
|
||||
ed.len=24;
|
||||
do
|
||||
{
|
||||
if (uOpenDialog("Find"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_EDIT,"Bytes",&ed))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
} while (RecoverBytes(&bytes[0]));
|
||||
pfind=(&findb[0]);
|
||||
casef=2;
|
||||
SearchAll();
|
||||
}
|
||||
|
||||
LOCAL_C VOID FindAgain(VOID)
|
||||
{
|
||||
LONG tot;
|
||||
|
||||
if (fpos<0)
|
||||
{
|
||||
wInfoMsg("Nothing to find again");
|
||||
return;
|
||||
}
|
||||
tot=fpos+1;
|
||||
if (tot==last || DoSearch(&tot))
|
||||
wInfoMsg("No more found");
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case ITEMS_BEFORE_FILE:
|
||||
OpenFile();
|
||||
break;
|
||||
case ITEMS_BEFORE_FILE+1:
|
||||
WriteFile();
|
||||
break;
|
||||
case ITEMS_BEFORE_FIND:
|
||||
FindText();
|
||||
break;
|
||||
case ITEMS_BEFORE_FIND+1:
|
||||
FindBytes();
|
||||
break;
|
||||
case ITEMS_BEFORE_FIND+2:
|
||||
FindAgain();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL:
|
||||
GotoLpos();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+1:
|
||||
p_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID MoveToTop(VOID)
|
||||
{
|
||||
lpos=0;
|
||||
DisplayPending=TRUE;
|
||||
}
|
||||
|
||||
LOCAL_C VOID CheckAndDisplay(VOID)
|
||||
{
|
||||
if (lpos<0)
|
||||
lpos=0;
|
||||
DisplayPending=TRUE;
|
||||
}
|
||||
|
||||
LOCAL_C VOID MoveToBottom(VOID)
|
||||
{
|
||||
lpos=last-64;
|
||||
CheckAndDisplay();
|
||||
}
|
||||
|
||||
LOCAL_C VOID MoveBy(INT delta)
|
||||
{
|
||||
lpos+=delta;
|
||||
if (lpos>last-64)
|
||||
lpos=last-64;
|
||||
CheckAndDisplay();
|
||||
}
|
||||
|
||||
LOCAL_C VOID EnsureDisplay(VOID)
|
||||
{
|
||||
if (DisplayPending)
|
||||
Display();
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{
|
||||
keycode=uLocateCommand(keycode);
|
||||
if (keycode>=0)
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_EVENT_KEY)
|
||||
{
|
||||
if (key.keycode==CONS_EVENT_COMMAND)
|
||||
p_exit(0);
|
||||
}
|
||||
else if (key.keycode&W_SPECIAL_KEY)
|
||||
{
|
||||
EnsureDisplay();
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (key.keycode)
|
||||
{
|
||||
case W_KEY_MENU:
|
||||
if (!(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
EnsureDisplay();
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
break;
|
||||
case W_KEY_LEFT:
|
||||
MoveBy(-1);
|
||||
break;
|
||||
case W_KEY_RIGHT:
|
||||
MoveBy(1);
|
||||
break;
|
||||
case W_KEY_UP:
|
||||
if (key.modifiers&W_CTRL_MODIFIER)
|
||||
MoveToTop();
|
||||
else
|
||||
MoveBy(-8);
|
||||
break;
|
||||
case W_KEY_DOWN:
|
||||
if (key.modifiers&W_CTRL_MODIFIER)
|
||||
MoveToBottom();
|
||||
else
|
||||
MoveBy(8);
|
||||
break;
|
||||
case W_KEY_HOME:
|
||||
MoveBy(-4);
|
||||
break;
|
||||
case W_KEY_END:
|
||||
MoveBy(4);
|
||||
break;
|
||||
case W_KEY_PAGE_UP:
|
||||
if (key.modifiers&W_CTRL_MODIFIER)
|
||||
MoveToTop();
|
||||
else
|
||||
MoveBy(-56);
|
||||
break;
|
||||
case W_KEY_PAGE_DOWN:
|
||||
if (key.modifiers&W_CTRL_MODIFIER)
|
||||
MoveToBottom();
|
||||
else
|
||||
MoveBy(56);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (DisplayPending && !uKeyPressOutstanding())
|
||||
Display();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
G_GC gc;
|
||||
|
||||
gc.style=G_STY_MONO;
|
||||
hgc=gCreateGC(uFindMainWid(),G_GC_MASK_STYLE,&gc);
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
hCrackCommandLine();
|
||||
if (TryOpenFile(DatUsedPathNamePtr,&fcb))
|
||||
p_exit(0);
|
||||
ResetDisplay();
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Dump.DMP
|
||||
\DMP\
|
||||
8004
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
iconed.pic
|
||||
iconed.rsc
|
||||
iconed.shd
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
Iconed.PIC
|
||||
\PIC\
|
||||
3
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
joker.pic
|
||||
joker.rsc
|
||||
joker.shd
|
||||
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
JOKER.C
|
||||
|
||||
Written by DavidW
|
||||
Started on 15/11/91
|
||||
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_file.h>
|
||||
#include <epoc.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"oOverwrite",
|
||||
"dDouble free",
|
||||
"fFaulty free",
|
||||
"wWind up stack",
|
||||
"bBusy",
|
||||
"sSlow exit",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define CORRUPT_ITEMS 3
|
||||
#define SPECIAL_ITEMS 4
|
||||
|
||||
#define ITEMS_BEFORE_CORRUPT 0
|
||||
#define ITEMS_BEFORE_SPECIAL CORRUPT_ITEMS
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Corrupt heap",CORRUPT_ITEMS,
|
||||
"Special",SPECIAL_ITEMS,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
LOCAL_D LONG delay=50l;
|
||||
|
||||
|
||||
LOCAL_C VOID DoSleep(VOID)
|
||||
{
|
||||
TEXT buf[30];
|
||||
|
||||
p_atos(&buf[0],"Waiting %ld/10 secs",delay);
|
||||
wSetBusyMsg(&buf[0],W_CORNER_BOTTOM_LEFT);
|
||||
p_sleep(delay);
|
||||
wCancelBusyMsg();
|
||||
}
|
||||
|
||||
LOCAL_C INT AddInDelayItem(VOID)
|
||||
{
|
||||
H_DI_NUMBER num;
|
||||
|
||||
num.value=(&delay);
|
||||
num.low=0;
|
||||
num.high=1000;
|
||||
return(uAddDialogItem(H_DIALOG_NUMBER,"Delay (10ths of secs)",&num));
|
||||
}
|
||||
|
||||
LOCAL_C INT AddNumberEditor(TEXT *prompt,LONG *pnum,INT low,INT high)
|
||||
{
|
||||
H_DI_NUMBER num;
|
||||
|
||||
num.value=pnum;
|
||||
num.low=low;
|
||||
num.high=high;
|
||||
return(uAddDialogItem(H_DIALOG_NUMBER,prompt,&num));
|
||||
}
|
||||
|
||||
LOCAL_C VOID OverwriteAllocCell(VOID)
|
||||
{
|
||||
LONG cellen;
|
||||
LONG overwlen;
|
||||
UBYTE *cell;
|
||||
|
||||
if (uOpenDialog("Overwrite alloc cell"))
|
||||
return;
|
||||
cellen=0x100;
|
||||
if (AddNumberEditor("Length of cell to alloc",&cellen,4,0x1000))
|
||||
return;
|
||||
overwlen=4;
|
||||
if (AddNumberEditor("Length of overwrite",&overwlen,1,0x100))
|
||||
return;
|
||||
if (AddInDelayItem())
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
cell=p_alloc((UWORD)cellen);
|
||||
if (!cell)
|
||||
{
|
||||
wInfoMsg("Cell too large to alloc");
|
||||
return;
|
||||
}
|
||||
DoSleep();
|
||||
p_bfil(cell,(UWORD)(cellen+overwlen),0xee);
|
||||
}
|
||||
|
||||
LOCAL_C VOID FreeCellTwice(VOID)
|
||||
{
|
||||
LONG cellen;
|
||||
UBYTE *cell;
|
||||
|
||||
if (uOpenDialog("Free cell twice"))
|
||||
return;
|
||||
cellen=0x100;
|
||||
if (AddNumberEditor("Length of cell to free twice",&cellen,4,0x1000))
|
||||
return;
|
||||
if (AddInDelayItem())
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
cell=p_alloc((UWORD)cellen);
|
||||
if (!cell)
|
||||
{
|
||||
wInfoMsg("Cell too large to alloc");
|
||||
return;
|
||||
}
|
||||
p_free(cell);
|
||||
DoSleep();
|
||||
p_free(cell);
|
||||
}
|
||||
|
||||
LOCAL_C VOID FreeWrongCell(VOID)
|
||||
{
|
||||
LONG cellen;
|
||||
UBYTE *cell;
|
||||
|
||||
if (uOpenDialog("Free wrong cell"))
|
||||
return;
|
||||
cellen=0x100;
|
||||
if (AddNumberEditor("Length of correct cell",&cellen,4,0x1000))
|
||||
return;
|
||||
if (AddInDelayItem())
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
cell=p_alloc((UWORD)cellen);
|
||||
if (!cell)
|
||||
{
|
||||
wInfoMsg("Cell too large to alloc");
|
||||
return;
|
||||
}
|
||||
DoSleep();
|
||||
p_free(cell+1);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID);
|
||||
|
||||
LOCAL_C VOID DoWindupStack(VOID)
|
||||
{
|
||||
UBYTE junk[256];
|
||||
|
||||
p_bfil(&junk[0],256,0);
|
||||
MainLoop();
|
||||
}
|
||||
|
||||
LOCAL_C VOID WindupStack(VOID)
|
||||
{
|
||||
if (uOpenDialog("Wind up stack"))
|
||||
return;
|
||||
if (AddInDelayItem())
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
DoSleep();
|
||||
DoWindupStack();
|
||||
}
|
||||
|
||||
#define Y_BUSY_LOW 10
|
||||
#define Y_BUSY_HIGH 78
|
||||
#define X_BUSY 83
|
||||
#define BUSY_SCALE 1000
|
||||
|
||||
LOCAL_C VOID DoPrint(UINT y)
|
||||
{
|
||||
gPrintText(X_BUSY,y,"Busy",4);
|
||||
wFlush();
|
||||
}
|
||||
|
||||
LOCAL_C VOID GoBusy(VOID)
|
||||
{
|
||||
LONG nloops;
|
||||
UWORD y;
|
||||
UWORD lasty;
|
||||
ULONG j;
|
||||
|
||||
if (uOpenDialog("Go busy"))
|
||||
return;
|
||||
nloops=3;
|
||||
if (AddNumberEditor("Number of loops of activity",&nloops,1,10))
|
||||
return;
|
||||
if (AddInDelayItem())
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
DoSleep();
|
||||
while (nloops--)
|
||||
{
|
||||
lasty=Y_BUSY_LOW;
|
||||
DoPrint(lasty);
|
||||
j=Y_BUSY_LOW*BUSY_SCALE;
|
||||
FOREVER
|
||||
{
|
||||
j++;
|
||||
y=(UWORD)(j/BUSY_SCALE);
|
||||
if (y!=lasty)
|
||||
{
|
||||
DoPrint(lasty);
|
||||
if (y>Y_BUSY_HIGH)
|
||||
break;
|
||||
lasty=y;
|
||||
DoPrint(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID SlowExit(VOID)
|
||||
{
|
||||
if (uOpenDialog("Slow exit"))
|
||||
return;
|
||||
if (AddInDelayItem())
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
DoSleep();
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case ITEMS_BEFORE_CORRUPT:
|
||||
OverwriteAllocCell();
|
||||
break;
|
||||
case ITEMS_BEFORE_CORRUPT+1:
|
||||
FreeCellTwice();
|
||||
break;
|
||||
case ITEMS_BEFORE_CORRUPT+2:
|
||||
FreeWrongCell();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL:
|
||||
WindupStack();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+1:
|
||||
GoBusy();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+2:
|
||||
SlowExit();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+3:
|
||||
p_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{
|
||||
keycode=uLocateCommand(keycode);
|
||||
if (keycode>=0)
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C VOID GoToSystemScreen(VOID)
|
||||
{
|
||||
wClientPosition(0,p_pidfind("SYS$SHLL.*"));
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_SPECIAL_KEY)
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
else if (key.keycode==26)
|
||||
GoToSystemScreen();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
G_GC gc;
|
||||
INT hgc;
|
||||
|
||||
gc.textmode=G_TRMODE_INV;
|
||||
hgc=gCreateGC(MainWid,G_GC_MASK_TEXTMODE,&gc);
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
MainWid=uFindMainWid();
|
||||
CreateGC();
|
||||
ReduceScreenSize();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
wCaptureKey(26,W_CTRL_MODIFIER,W_CTRL_MODIFIER);
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Joker
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
@echo off
|
||||
call checkvid
|
||||
if exist %1.pr goto custom
|
||||
tsc /m unnamed.pr /smain=%1 /%jpivid%
|
||||
goto end
|
||||
:custom
|
||||
tsc /m %1.pr /smain=%1 /%jpivid%
|
||||
:end
|
||||
@@ -0,0 +1,3 @@
|
||||
notes.pic
|
||||
notes.rsc
|
||||
notes.shd
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
Notes
|
||||
|
||||
4000
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
QU1.C
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
WMSG_KEY key;
|
||||
|
||||
uCommonInit();
|
||||
wSetBusyMsg("Hello world",W_CORNER_BOTTOM_LEFT);
|
||||
uGetKey(&key);
|
||||
uGetKey(&key);
|
||||
p_exit(0);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
QU2.C
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(uFindMainWid());
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
WMSG_KEY key;
|
||||
|
||||
uCommonInit();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wSetBusyMsg("Hello world",W_CORNER_BOTTOM_LEFT);
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode==(W_SPECIAL_KEY|'x'))
|
||||
p_exit(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
QU3.C
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"iInches/Centimetres",
|
||||
"mMiles/Kilometres",
|
||||
"lPounds/Kilogrammes",
|
||||
"pPints/Litres",
|
||||
"fFahrenheit/Centigrade",
|
||||
"dDay of week",
|
||||
"cCombinations",
|
||||
"tTime difference",
|
||||
"hHoroscope",
|
||||
"nNow",
|
||||
"wPassword",
|
||||
"eEncrypt",
|
||||
"uDecrypt",
|
||||
"sSignificance",
|
||||
"zFile size",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Conversions",5,
|
||||
"Calendar",5,
|
||||
"Secret",3,
|
||||
"Special",3,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT keycode)
|
||||
{
|
||||
INT index;
|
||||
TEXT buf[40];
|
||||
|
||||
switch (keycode)
|
||||
{
|
||||
case 'x':
|
||||
p_exit(0);
|
||||
default:
|
||||
index=uLocateCommand(keycode);
|
||||
if (index>=0)
|
||||
{
|
||||
p_atos(&buf[0],"You chose `%s'",cmds[index]+1);
|
||||
wInfoMsg(&buf[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_SPECIAL_KEY)
|
||||
ManageCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
ManageCommand(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(MainWid);
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
MainWid=uFindMainWid();
|
||||
ReduceScreenSize();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
wInfoMsg("Hello world");
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
query.pic
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
QU4.C
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_date.h>
|
||||
#include <p_file.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"iInches/Centimetres",
|
||||
"mMiles/Kilometres",
|
||||
"lPounds/Kilogrammes",
|
||||
"pPints/Litres",
|
||||
"fFahrenheit/Centigrade",
|
||||
"dDay of week",
|
||||
"cCombinations",
|
||||
"tTime difference",
|
||||
"hHoroscope",
|
||||
"nNow",
|
||||
"wPassword",
|
||||
"eEncrypt",
|
||||
"uDecrypt",
|
||||
"sSignificance",
|
||||
"zFile size",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Conversions",5,
|
||||
"Calendar",5,
|
||||
"Secret",3,
|
||||
"Special",3,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
LOCAL_D VOID *ttH;
|
||||
LOCAL_D UWORD ttMonth=1;
|
||||
LOCAL_D UWORD ttSuffix=1;
|
||||
LOCAL_D UWORD ttDay=1;
|
||||
LOCAL_D UWORD ttCentury=2;
|
||||
LOCAL_D UWORD ttSeconds=2;
|
||||
|
||||
|
||||
LOCAL_C INT AddNoYesChoiceList(TEXT *pmt,UWORD *pval)
|
||||
{
|
||||
return(uAddChoiceList(pmt,pval,"No","Yes",NULL));
|
||||
}
|
||||
|
||||
LOCAL_C VOID TimeNow(VOID)
|
||||
{
|
||||
INT values;
|
||||
H_DI_TEXT txt;
|
||||
TEXT buf[48];
|
||||
|
||||
txt.str=(&buf[0]);
|
||||
do
|
||||
{
|
||||
if (uOpenDialog(NULL))
|
||||
return;
|
||||
uZTStoBCS(&buf[0],"Time is now");
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE;
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,NULL,&txt))
|
||||
return;
|
||||
values=0;
|
||||
if (ttMonth==2)
|
||||
values=H_TIME_FORMAT_MONTH_NAME;
|
||||
if (ttDay==2)
|
||||
values|=H_TIME_FORMAT_DAY_NAME;
|
||||
if (ttSuffix==2)
|
||||
values|=H_TIME_FORMAT_SUFFIX;
|
||||
if (ttCentury==1)
|
||||
values|=H_TIME_FORMAT_NO_CENTURY;
|
||||
if (ttSeconds==1)
|
||||
values|=H_TIME_FORMAT_NO_SECONDS;
|
||||
hTTSetFormat(ttH,values);
|
||||
hTTSetTime(ttH,H_TIME_SET_NOW,NULL);
|
||||
buf[0]=hTTSenseString(ttH,H_TIME_SENSE_BOTH,&buf[1]);
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE|H_DTEXT_UNDERLINE;
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,NULL,&txt))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Give month name",&ttMonth))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Give day name",&ttDay))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Use date suffix",&ttSuffix))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Show century",&ttCentury))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Show seconds",&ttSeconds))
|
||||
return;
|
||||
} while (uRunDialog()>0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SetUpDiDate(H_DI_DATE *pdate,P_DAYSEC *pds)
|
||||
{
|
||||
ULONG sdate;
|
||||
|
||||
sdate=p_date();
|
||||
p_sttods(&sdate,pds);
|
||||
pdate->value=(&pds->day);
|
||||
pdate->low=0;
|
||||
pdate->high=H_LAST_DAY;
|
||||
}
|
||||
|
||||
LOCAL_C VOID DayOfWeek(VOID)
|
||||
{
|
||||
P_DAYSEC ds;
|
||||
H_DI_DATE date;
|
||||
TEXT buf[40];
|
||||
H_DI_TEXT txt;
|
||||
|
||||
SetUpDiDate(&date,&ds);
|
||||
do
|
||||
{
|
||||
p_nmday(&buf[1],p_wkday(ds.day));
|
||||
buf[0]=p_slen(&buf[1]);
|
||||
txt.str=(&buf[0]);
|
||||
txt.type=H_DTEXT_ALIGN_LEFT;
|
||||
if (uOpenDialog("Find day of week"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_DATE,"Date",&date))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,"Day of week",&txt))
|
||||
return;
|
||||
} while (uRunDialog()>0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID FileSize(VOID)
|
||||
{
|
||||
TEXT fname[P_FNAMESIZE+2];
|
||||
H_DI_FSEL fsel;
|
||||
P_INFO info;
|
||||
TEXT buf[30];
|
||||
|
||||
fname[0]=0;
|
||||
fsel.fname=(&fname[0]);
|
||||
fsel.flags=H_FILE_PICK_SELECTOR;
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Find file size"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_FSEL,"File:",&fsel))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
fname[1+fname[0]]=0;
|
||||
if (!uErrorValue(p_finfo(&fname[1],&info)))
|
||||
{
|
||||
p_atos(&buf[0],"File size is %lu bytes",info.size);
|
||||
wInfoMsg(&buf[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT keycode)
|
||||
{
|
||||
INT index;
|
||||
TEXT buf[40];
|
||||
|
||||
switch (keycode)
|
||||
{
|
||||
case 'd':
|
||||
DayOfWeek();
|
||||
break;
|
||||
case 'n':
|
||||
TimeNow();
|
||||
break;
|
||||
case 'z':
|
||||
FileSize();
|
||||
break;
|
||||
case 'x':
|
||||
p_exit(0);
|
||||
default:
|
||||
index=uLocateCommand(keycode);
|
||||
if (index>=0)
|
||||
{
|
||||
p_atos(&buf[0],"You chose `%s'",cmds[index]+1);
|
||||
wInfoMsg(&buf[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_SPECIAL_KEY)
|
||||
ManageCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
ManageCommand(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(MainWid);
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
MainWid=uFindMainWid();
|
||||
ReduceScreenSize();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
ttH=hTTOpen();
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
query.pic
|
||||
query.rsc
|
||||
query.shd
|
||||
@@ -0,0 +1,796 @@
|
||||
/*
|
||||
QUERY.C
|
||||
|
||||
Written by DavidW
|
||||
Started on 28/11/91
|
||||
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_math.h>
|
||||
#include <p_date.h>
|
||||
#include <p_crypt.h>
|
||||
#include <p_file.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"iInches/Centimetres",
|
||||
"mMiles/Kilometres",
|
||||
"lPounds/Kilogrammes",
|
||||
"pPints/Litres",
|
||||
"fFahrenheit/Centigrade",
|
||||
"dDay of week",
|
||||
"cCombinations",
|
||||
"tTime difference",
|
||||
"hHoroscope",
|
||||
"nNow",
|
||||
"wPassword",
|
||||
"eEncrypt",
|
||||
"uDecrypt",
|
||||
"sSignificance",
|
||||
"zFile size",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define CONVERT_ITEMS 5
|
||||
#define CALENDAR_ITEMS 5
|
||||
#define SECRET_ITEMS 3
|
||||
#define SPECIAL_ITEMS 3
|
||||
|
||||
#define ITEMS_BEFORE_CONVERT 0
|
||||
#define ITEMS_BEFORE_CALENDAR CONVERT_ITEMS
|
||||
#define ITEMS_BEFORE_SECRET (ITEMS_BEFORE_CALENDAR+CALENDAR_ITEMS)
|
||||
#define ITEMS_BEFORE_SPECIAL (ITEMS_BEFORE_SECRET+SECRET_ITEMS)
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Conversions",CONVERT_ITEMS,
|
||||
"Calendar",CALENDAR_ITEMS,
|
||||
"Secret",SECRET_ITEMS,
|
||||
"Special",SPECIAL_ITEMS,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
LOCAL_D WORD ndp=2;
|
||||
LOCAL_D DOUBLE small;
|
||||
LOCAL_D DOUBLE vsmall;
|
||||
|
||||
LOCAL_D TEXT pass[10];
|
||||
|
||||
LOCAL_D VOID *ttH;
|
||||
LOCAL_D UWORD ttMonth=1;
|
||||
LOCAL_D UWORD ttSuffix=1;
|
||||
LOCAL_D UWORD ttDay=1;
|
||||
LOCAL_D UWORD ttCentury=2;
|
||||
LOCAL_D UWORD ttSeconds=2;
|
||||
|
||||
|
||||
LOCAL_C VOID CalcSmall(VOID)
|
||||
{
|
||||
DOUBLE dndp;
|
||||
DOUBLE ten;
|
||||
|
||||
dndp=(-ndp);
|
||||
ten=10;
|
||||
p_pow(&small,&ten,&dndp);
|
||||
vsmall=small/2;
|
||||
}
|
||||
|
||||
LOCAL_C VOID Clip(DOUBLE *pval)
|
||||
{
|
||||
DOUBLE remain;
|
||||
|
||||
if (*pval>=0)
|
||||
(*pval)+=vsmall;
|
||||
else
|
||||
(*pval)-=vsmall;
|
||||
p_mod(&remain,pval,&small);
|
||||
(*pval)-=remain;
|
||||
}
|
||||
|
||||
LOCAL_C VOID Temperatures(VOID)
|
||||
{
|
||||
DOUBLE fahr;
|
||||
DOUBLE cent;
|
||||
H_DI_FLOAT ffahr;
|
||||
H_DI_FLOAT fcent;
|
||||
INT index;
|
||||
|
||||
fahr=32;
|
||||
cent=0;
|
||||
ffahr.value=(&fahr);
|
||||
ffahr.low=(-17968);
|
||||
ffahr.high=18032;
|
||||
fcent.value=(¢);
|
||||
fcent.low=(-10000);
|
||||
fcent.high=10000;
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Convert temperature"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_FLOAT,"Fahrenheit",&ffahr))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_FLOAT,"Centigrade",&fcent))
|
||||
return;
|
||||
index=uRunDialog();
|
||||
if (index<=0)
|
||||
break;
|
||||
if (index==2)
|
||||
{
|
||||
cent=(fahr-32)*5/9;
|
||||
Clip(¢);
|
||||
}
|
||||
else
|
||||
{
|
||||
fahr=32+cent*9/5;
|
||||
Clip(&fahr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID Convert(TEXT *pmt1,TEXT *pmt2,INT high1,INT high2)
|
||||
{
|
||||
DOUBLE val1;
|
||||
DOUBLE val2;
|
||||
H_DI_FLOAT fled1;
|
||||
H_DI_FLOAT fled2;
|
||||
INT index;
|
||||
DOUBLE ratio;
|
||||
|
||||
val1=0;
|
||||
val2=0;
|
||||
fled1.value=(&val1);
|
||||
fled1.low=0;
|
||||
fled1.high=high1;
|
||||
fled2.value=(&val2);
|
||||
fled2.low=0;
|
||||
fled2.high=high2;
|
||||
ratio=fled2.high/fled1.high;
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Convert"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_FLOAT,pmt1,&fled1))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_FLOAT,pmt2,&fled2))
|
||||
return;
|
||||
index=uRunDialog();
|
||||
if (index<=0)
|
||||
break;
|
||||
if (index==2)
|
||||
{
|
||||
val2=val1*ratio;
|
||||
Clip(&val2);
|
||||
}
|
||||
else
|
||||
{
|
||||
val1=val2/ratio;
|
||||
Clip(&val1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID InchAndCm(VOID)
|
||||
{
|
||||
Convert("Inches","Centimetres",10000,25400);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MileAndKm(VOID)
|
||||
{
|
||||
Convert("Miles","Kilometres",20000,32187);
|
||||
}
|
||||
|
||||
LOCAL_C VOID PoundAndKg(VOID)
|
||||
{
|
||||
Convert("Pounds","Kilograms",31938,14500);
|
||||
}
|
||||
|
||||
LOCAL_C VOID PintAndL(VOID)
|
||||
{
|
||||
Convert("Pints","Litres",28156,16000);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeNdp(VOID)
|
||||
{
|
||||
LONG lndp;
|
||||
H_DI_NUMBER num;
|
||||
|
||||
if (uOpenDialog("Level of significance"))
|
||||
return;
|
||||
lndp=ndp;
|
||||
num.value=(&lndp);
|
||||
num.low=0;
|
||||
num.high=4;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Decimal places",&num))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
ndp=(WORD)lndp;
|
||||
CalcSmall();
|
||||
}
|
||||
|
||||
LOCAL_C VOID SetUpDiDate(H_DI_DATE *pdate,P_DAYSEC *pds)
|
||||
{
|
||||
ULONG sdate;
|
||||
|
||||
sdate=p_date();
|
||||
p_sttods(&sdate,pds);
|
||||
pdate->value=(&pds->day);
|
||||
pdate->low=0;
|
||||
pdate->high=H_LAST_DAY;
|
||||
}
|
||||
|
||||
LOCAL_C VOID DayOfWeek(VOID)
|
||||
{
|
||||
P_DAYSEC ds;
|
||||
H_DI_DATE date;
|
||||
TEXT buf[40];
|
||||
H_DI_TEXT txt;
|
||||
|
||||
SetUpDiDate(&date,&ds);
|
||||
do
|
||||
{
|
||||
p_nmday(&buf[1],p_wkday(ds.day));
|
||||
buf[0]=p_slen(&buf[1]);
|
||||
txt.str=(&buf[0]);
|
||||
txt.type=H_DTEXT_ALIGN_LEFT;
|
||||
if (uOpenDialog("Find day of week"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_DATE,"Date",&date))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,"Day of week",&txt))
|
||||
return;
|
||||
} while (uRunDialog()>0);
|
||||
}
|
||||
|
||||
LOCAL_D TEXT *orient[]=
|
||||
{
|
||||
"Rat","Cow","Tiger","Rabbit","Dragon","Snake",
|
||||
"Horse","Sheep","Monkey","Rooster","Dog","Pig"
|
||||
};
|
||||
|
||||
LOCAL_D TEXT *western[]=
|
||||
{
|
||||
"Capricorn","Aquarius","Pisces","Aries","Taurus","Gemini",
|
||||
"Cancer","Leo","Virgo","Libra","Scorpio","Sagittarius"
|
||||
};
|
||||
|
||||
LOCAL_C INT Zodiac(P_DATE *pdt)
|
||||
{
|
||||
INT ret;
|
||||
LOCAL_D changeover[12]={19,18,19,19,20,20,22,22,22,22,21,20};
|
||||
|
||||
ret=pdt->month;
|
||||
if (pdt->day>changeover[ret])
|
||||
{
|
||||
if (ret++==11)
|
||||
ret=0;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
LOCAL_C VOID Horoscope(VOID)
|
||||
{
|
||||
P_DAYSEC ds;
|
||||
H_DI_DATE date;
|
||||
P_DATE dt;
|
||||
INT key;
|
||||
TEXT buf[40];
|
||||
|
||||
SetUpDiDate(&date,&ds);
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Horoscope"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_DATE,"Date of birth",&date))
|
||||
return;
|
||||
if (uAddButtonList("Stop",W_KEY_ESCAPE,
|
||||
"Western",'w',"Oriental",'o',NULL))
|
||||
return;
|
||||
key=uRunDialog();
|
||||
if (key<=0)
|
||||
return;
|
||||
p_dstodt(&ds,&dt);
|
||||
if (key=='o')
|
||||
p_atos(&buf[0],"Oriental horoscope is %s",orient[dt.year%12]);
|
||||
else
|
||||
p_atos(&buf[0],"Western horoscope is %s",western[Zodiac(&dt)]);
|
||||
wInfoMsg(&buf[0]);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C INT AddListOfDays(UWORD *pdiw)
|
||||
{
|
||||
H_DI_CHOICE ch;
|
||||
TEXT nam[32];
|
||||
INT i;
|
||||
|
||||
if (uBeginDCL(&ch))
|
||||
return(-1);
|
||||
for (i=0; i<7; i++)
|
||||
{
|
||||
p_nmday(&nam[0],i);
|
||||
if (uGrowDCL(&ch,&nam[0]))
|
||||
return(-1);
|
||||
}
|
||||
return(uAddDCL("Day in week",pdiw,&ch));
|
||||
}
|
||||
|
||||
LOCAL_C VOID Combinations(VOID)
|
||||
{
|
||||
P_DAYSEC ds;
|
||||
H_DI_DATE date;
|
||||
P_DATE dt;
|
||||
INT key;
|
||||
UWORD diw;
|
||||
LONG dim;
|
||||
H_DI_NUMBER num;
|
||||
INT diff;
|
||||
ULONG reset;
|
||||
INT inc;
|
||||
|
||||
SetUpDiDate(&date,&ds);
|
||||
p_dstodt(&ds,&dt);
|
||||
diw=p_wkday(ds.day)+1;
|
||||
dim=dt.day+1;
|
||||
num.value=(&dim);
|
||||
num.low=1;
|
||||
num.high=31;
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Find date combinations"))
|
||||
return;
|
||||
if (AddListOfDays(&diw))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Day in month",&num))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_DATE,"Found date",&date))
|
||||
return;
|
||||
if (uAddButtonList("Stop",W_KEY_ESCAPE,"Backwards",W_KEY_MENU,
|
||||
"Forwards",W_KEY_RETURN,0))
|
||||
return;
|
||||
key=uRunDialog();
|
||||
if (key<=0)
|
||||
return;
|
||||
reset=ds.day;
|
||||
diff=diw-p_wkday(ds.day)-1;
|
||||
if (key==W_KEY_RETURN)
|
||||
{
|
||||
if (diff<=0)
|
||||
diff+=7;
|
||||
inc=7;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (diff>=0)
|
||||
diff-=7;
|
||||
inc=(-7);
|
||||
}
|
||||
ds.day+=diff;
|
||||
dim-=1;
|
||||
FOREVER
|
||||
{
|
||||
if (ds.day>H_LAST_DAY)
|
||||
{
|
||||
wInfoMsg("No further matches");
|
||||
ds.day=reset;
|
||||
break;
|
||||
}
|
||||
p_dstodt(&ds,&dt);
|
||||
if (dt.day==dim)
|
||||
break;
|
||||
ds.day+=inc;
|
||||
}
|
||||
dim+=1;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID SetUpTime(H_DI_TIME *ptime,P_DAYSEC *pds)
|
||||
{
|
||||
ptime->value=(&pds->sec);
|
||||
ptime->low=0;
|
||||
ptime->high=P_NSECDAY-1;
|
||||
ptime->type=H_DTIME_SHOW_SECONDS;
|
||||
}
|
||||
|
||||
LOCAL_C VOID TimeDifference(VOID)
|
||||
{
|
||||
P_DAYSEC ds1;
|
||||
H_DI_DATE date1;
|
||||
H_DI_TIME time1;
|
||||
P_DAYSEC ds2;
|
||||
H_DI_DATE date2;
|
||||
H_DI_TIME time2;
|
||||
LONG diff;
|
||||
TEXT buf[40];
|
||||
|
||||
SetUpDiDate(&date1,&ds1);
|
||||
SetUpDiDate(&date2,&ds2);
|
||||
SetUpTime(&time1,&ds1);
|
||||
SetUpTime(&time2,&ds2);
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Time difference"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_DATE,"From",&date1))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_TIME,"",&time1))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_DATE,"To",&date2))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_TIME,"",&time2))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
diff=ds2.day-ds1.day;
|
||||
if (diff<0 || !diff && ds2.sec<ds1.sec)
|
||||
{
|
||||
wInfoMsg("`To' date is before `From' date!");
|
||||
continue;
|
||||
}
|
||||
if (diff>0x7fffffffl/P_NSECDAY)
|
||||
{
|
||||
wInfoMsg("Dates are too far apart");
|
||||
continue;
|
||||
}
|
||||
p_atos(&buf[0],"Dates are %ld seconds apart",
|
||||
diff*P_NSECDAY+ds2.sec-ds1.sec);
|
||||
wInfoMsg(&buf[0]);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C INT AddNoYesChoiceList(TEXT *pmt,UWORD *pval)
|
||||
{
|
||||
return(uAddChoiceList(pmt,pval,"No","Yes",NULL));
|
||||
}
|
||||
|
||||
LOCAL_C VOID TimeNow(VOID)
|
||||
{
|
||||
INT values;
|
||||
H_DI_TEXT txt;
|
||||
TEXT buf[48];
|
||||
|
||||
txt.str=(&buf[0]);
|
||||
do
|
||||
{
|
||||
if (uOpenDialog(NULL))
|
||||
return;
|
||||
uZTStoBCS(&buf[0],"Time is now");
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE;
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,NULL,&txt))
|
||||
return;
|
||||
values=0;
|
||||
if (ttMonth==2)
|
||||
values=H_TIME_FORMAT_MONTH_NAME;
|
||||
if (ttDay==2)
|
||||
values|=H_TIME_FORMAT_DAY_NAME;
|
||||
if (ttSuffix==2)
|
||||
values|=H_TIME_FORMAT_SUFFIX;
|
||||
if (ttCentury==1)
|
||||
values|=H_TIME_FORMAT_NO_CENTURY;
|
||||
if (ttSeconds==1)
|
||||
values|=H_TIME_FORMAT_NO_SECONDS;
|
||||
hTTSetFormat(ttH,values);
|
||||
hTTSetTime(ttH,H_TIME_SET_NOW,NULL);
|
||||
buf[0]=hTTSenseString(ttH,H_TIME_SENSE_BOTH,&buf[1]);
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE|H_DTEXT_UNDERLINE;
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,NULL,&txt))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Give month name",&ttMonth))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Give day name",&ttDay))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Use date suffix",&ttSuffix))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Show century",&ttCentury))
|
||||
return;
|
||||
if (AddNoYesChoiceList("Show seconds",&ttSeconds))
|
||||
return;
|
||||
} while (uRunDialog()>0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID EnterPassword(VOID)
|
||||
{
|
||||
TEXT pass1[10];
|
||||
TEXT pass2[10];
|
||||
H_DI_XINPUT x1;
|
||||
H_DI_XINPUT x2;
|
||||
|
||||
x1.str=(&pass1[0]);
|
||||
x2.str=(&pass2[0]);
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog(NULL))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_XINPUT,"Define password",&x1))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_XINPUT,"Confirm password",&x2))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
if (p_bcmpi(&pass1[1],pass1[0],&pass2[1],pass2[0]))
|
||||
{
|
||||
wInfoMsg("Password not confirmed");
|
||||
continue;
|
||||
}
|
||||
if (pass1[0])
|
||||
break;
|
||||
wInfoMsg("Please supply password");
|
||||
}
|
||||
p_bfil(&pass[0],10,0);
|
||||
p_bcpy(&pass[0],&pass1[0],pass1[0]+1);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MakeReadable(TEXT *out,TEXT *in)
|
||||
{
|
||||
INT len;
|
||||
INT i;
|
||||
INT val;
|
||||
|
||||
i=32;
|
||||
len=(*in++);
|
||||
*out++=len*2;
|
||||
while (len--)
|
||||
{
|
||||
val=(*in++);
|
||||
*out++=i+(val&0xf);
|
||||
i+=16;
|
||||
*out++=i+(val>>4);
|
||||
if (i==112)
|
||||
i=32;
|
||||
else
|
||||
i+=16;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID MakeUnreadable(TEXT *out,TEXT *in)
|
||||
{
|
||||
INT len;
|
||||
INT i;
|
||||
INT val;
|
||||
|
||||
i=32;
|
||||
len=(*in++)/2;
|
||||
*out++=len;
|
||||
while (len--)
|
||||
{
|
||||
val=(*in++)-i;
|
||||
i+=16;
|
||||
val+=((*in++)-i)<<4;
|
||||
*out++=val;
|
||||
if (i==112)
|
||||
i=32;
|
||||
else
|
||||
i+=16;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID Report(TEXT *title,TEXT *mess)
|
||||
{
|
||||
H_DI_TEXT txt;
|
||||
|
||||
if (uOpenDialog(title))
|
||||
return;
|
||||
txt.str=mess;
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE;
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,NULL,&txt))
|
||||
return;
|
||||
uRunDialog();
|
||||
}
|
||||
|
||||
LOCAL_C VOID EncryptMessage(VOID)
|
||||
{
|
||||
P_MASK mask;
|
||||
H_DI_EDIT ed;
|
||||
TEXT in[20];
|
||||
TEXT out[38];
|
||||
|
||||
if (!pass[0])
|
||||
{
|
||||
wInfoMsg("Can't encrypt with no password set");
|
||||
return;
|
||||
}
|
||||
p_setmask((VOID **)&mask,&pass[1]); /** bug in prototype **/
|
||||
if (uOpenDialog("Encrypt message"))
|
||||
return;
|
||||
ed.str=(&in[0]);
|
||||
ed.len=18;
|
||||
in[0]=0;
|
||||
if (uAddDialogItem(H_DIALOG_EDIT,"Message",&ed))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
p_encrypt(&mask,&in[1],in[0]);
|
||||
MakeReadable(&out[0],&in[0]);
|
||||
Report("Encrypted message",&out[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DecryptMessage(VOID)
|
||||
{
|
||||
P_MASK mask;
|
||||
H_DI_SEDIT sed;
|
||||
TEXT in[38];
|
||||
TEXT out[20];
|
||||
|
||||
if (!pass[0])
|
||||
{
|
||||
wInfoMsg("Can't decrypt with no password set");
|
||||
return;
|
||||
}
|
||||
p_setmask((VOID **)&mask,&pass[1]);
|
||||
if (uOpenDialog("Decrypt message"))
|
||||
return;
|
||||
sed.str=(&in[0]);
|
||||
sed.len=36;
|
||||
sed.width=16;
|
||||
in[0]=0;
|
||||
if (uAddDialogItem(H_DIALOG_SEDIT,"Message",&sed))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
MakeUnreadable(&out[0],&in[0]);
|
||||
p_decrypt(&mask,&out[1],out[0]);
|
||||
Report("Decrypted message",&out[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID FileSize(VOID)
|
||||
{
|
||||
TEXT fname[P_FNAMESIZE+2];
|
||||
H_DI_FSEL fsel;
|
||||
P_INFO info;
|
||||
TEXT buf[30];
|
||||
|
||||
fname[0]=0;
|
||||
fsel.fname=(&fname[0]);
|
||||
fsel.flags=H_FILE_PICK_SELECTOR;
|
||||
FOREVER
|
||||
{
|
||||
if (uOpenDialog("Find file size"))
|
||||
return;
|
||||
if (uAddDialogItem(H_DIALOG_FSEL,"File:",&fsel))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
fname[1+fname[0]]=0;
|
||||
if (!uErrorValue(p_finfo(&fname[1],&info)))
|
||||
{
|
||||
p_atos(&buf[0],"File size is %lu bytes",info.size);
|
||||
wInfoMsg(&buf[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case ITEMS_BEFORE_CONVERT:
|
||||
InchAndCm();
|
||||
break;
|
||||
case ITEMS_BEFORE_CONVERT+1:
|
||||
MileAndKm();
|
||||
break;
|
||||
case ITEMS_BEFORE_CONVERT+2:
|
||||
PoundAndKg();
|
||||
break;
|
||||
case ITEMS_BEFORE_CONVERT+3:
|
||||
PintAndL();
|
||||
break;
|
||||
case ITEMS_BEFORE_CONVERT+4:
|
||||
Temperatures();
|
||||
break;
|
||||
case ITEMS_BEFORE_CALENDAR:
|
||||
DayOfWeek();
|
||||
break;
|
||||
case ITEMS_BEFORE_CALENDAR+1:
|
||||
Combinations();
|
||||
break;
|
||||
case ITEMS_BEFORE_CALENDAR+2:
|
||||
TimeDifference();
|
||||
break;
|
||||
case ITEMS_BEFORE_CALENDAR+3:
|
||||
Horoscope();
|
||||
break;
|
||||
case ITEMS_BEFORE_CALENDAR+4:
|
||||
TimeNow();
|
||||
break;
|
||||
case ITEMS_BEFORE_SECRET:
|
||||
EnterPassword();
|
||||
break;
|
||||
case ITEMS_BEFORE_SECRET+1:
|
||||
EncryptMessage();
|
||||
break;
|
||||
case ITEMS_BEFORE_SECRET+2:
|
||||
DecryptMessage();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL:
|
||||
ChangeNdp();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+1:
|
||||
FileSize();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+2:
|
||||
p_exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{
|
||||
keycode=uLocateCommand(keycode);
|
||||
if (keycode>=0)
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_EVENT_KEY)
|
||||
{
|
||||
if (key.keycode==CONS_EVENT_COMMAND)
|
||||
p_exit(0);
|
||||
}
|
||||
else if (key.keycode&W_SPECIAL_KEY)
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(MainWid);
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
hCrackCommandLine();
|
||||
MainWid=uFindMainWid();
|
||||
ReduceScreenSize();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
CalcSmall();
|
||||
ttH=hTTOpen();
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Query
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
remind.pic
|
||||
remind.rsc
|
||||
remind.shd
|
||||
@@ -0,0 +1,875 @@
|
||||
/*
|
||||
REMIND.C
|
||||
|
||||
Written by DavidW
|
||||
Started on 6/12/91
|
||||
Resource file version 1/11/92
|
||||
*/
|
||||
|
||||
#include <p_std.h> /* basic Psion header file */
|
||||
#include <p_object.h> /* defines object oriented functions */
|
||||
#include <p_gen.h> /* defines E_GEN_ error values, etc */
|
||||
#include <p_file.h> /* defines E_FILE_ error values, etc */
|
||||
#include <p_date.h> /* defines date and time functions */
|
||||
#include <rscfile.xg> /* defines C_RSCFILE and related constants */
|
||||
#include <wlib.h> /* defines all Window Server library functions */
|
||||
#include <hwif.h> /* defines all Hwif Library functions */
|
||||
#include "remind.rh" /* definitions common to remind.rss & remind.c */
|
||||
#include "remind.rsg" /* GENERATED resource file header */
|
||||
|
||||
GLREF_D VOID *DatCommandPtr; /* where run from */
|
||||
|
||||
GLDEF_D TEXT ** _cmds; /* for menu commands */
|
||||
GLDEF_D H_MENU_DATA * _mdata; /* for menu titles */
|
||||
|
||||
LOCAL_C VOID *rcb; /* resource file object handle */
|
||||
LOCAL_D UINT MainWid; /* ID of main window */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ULONG sdate; /* date when reminder due */
|
||||
UBYTE ref; /* TRUE iff this is the reminder queued to ALM: */
|
||||
UBYTE tlen; /* length of text message */
|
||||
TEXT *pb; /* the text message itself (another alloc cell) */
|
||||
} ENTRY; /* represents one reminder */
|
||||
|
||||
LOCAL_D ENTRY table[500]; /* handle up to 500 reminders */
|
||||
LOCAL_D UWORD nent=0; /* number of entries */
|
||||
LOCAL_D INT cent=0; /* entry at cursor */
|
||||
LOCAL_D INT tent=0; /* entry at top of screen */
|
||||
|
||||
LOCAL_D ENTRY clipent; /* entry in clipboard */
|
||||
|
||||
LOCAL_D UWORD show_statwin=FALSE; /* is Status Window showing */
|
||||
LOCAL_D UWORD ScreenWidth; /* width of remaining screen */
|
||||
|
||||
LOCAL_D UWORD lastbflags=W_BORD_CORNER_4; /* which kind of Border flags */
|
||||
|
||||
LOCAL_D VOID *ttH; /* handle of Time Text object */
|
||||
|
||||
LOCAL_D VOID *aH; /* handle of channel to ALM: alarm device */
|
||||
LOCAL_D WORD almstat; /* status word for ALM: services */
|
||||
LOCAL_D WORD almactive; /* active word for ALM: services */
|
||||
|
||||
LOCAL_D UWORD PrintRec; /* which entry is being printed */
|
||||
LOCAL_D UWORD PrintState; /* which part of entry is being printed */
|
||||
LOCAL_D TEXT PrintBuf[48]; /* holds text about to be printed */
|
||||
|
||||
|
||||
LOCAL_C VOID LoadStr(INT rid,TEXT *pb)
|
||||
{ /* load resource into given buffer (assumed long enough) */
|
||||
while (p_entersend4(rcb,O_RS_READ_BUF,rid,pb)<0)
|
||||
hRequestReplacePack(rcb,DatCommandPtr);
|
||||
}
|
||||
|
||||
LOCAL_C TEXT *str(INT rid)
|
||||
{ /* load specified resource into scratch buffer and return address */
|
||||
LOCAL_D TEXT scratch[50]; /* static "scratch" buffer */
|
||||
|
||||
LoadStr(rid,&scratch[0]);
|
||||
return(&scratch[0]);
|
||||
}
|
||||
|
||||
LOCAL_C INT cmp(INT r,VOID *pent)
|
||||
{ /* comparison function used in binary searching */
|
||||
return(table[r].sdate>(*(ULONG *)pent)? -1: 1);
|
||||
}
|
||||
|
||||
LOCAL_C INT LocateEntry(ULONG *psdate)
|
||||
{ /* find entry at (or nearest after) given date */
|
||||
INT dir; /* direction to nearest hit (as given by p_bsrch) */
|
||||
INT ret; /* nearest hit (as given by p_bsrch) */
|
||||
|
||||
dir=p_bsrch(nent,cmp,&ret,psdate);
|
||||
if (dir>0)
|
||||
ret++;
|
||||
return(ret);
|
||||
}
|
||||
|
||||
LOCAL_C ENTRY *LocateRef(VOID)
|
||||
{ /* find the entry that was queued to ALM: */
|
||||
ENTRY *pent;
|
||||
|
||||
pent=(&table[0]);
|
||||
while (!pent->ref)
|
||||
pent++;
|
||||
return(pent);
|
||||
}
|
||||
|
||||
LOCAL_C VOID RequeueAlarm(VOID)
|
||||
{ /* recalculate the next alarm due, and queue it (if any) */
|
||||
ULONG sdate; /* current time and date */
|
||||
INT entno; /* no of entry to queue */
|
||||
ENTRY *pent; /* entry to queue */
|
||||
ULONG times[2]; /* needed for service to ALM: */
|
||||
TEXT buf[66]; /* needed for service to ALM: */
|
||||
|
||||
if (almactive)
|
||||
{ /* cancel any alarm currently queued */
|
||||
p_iow2(aH,P_FCANCEL);
|
||||
p_waitstat(&almstat);
|
||||
almactive=FALSE;
|
||||
LocateRef()->ref=FALSE;
|
||||
}
|
||||
if (!nent)
|
||||
return; /* no entries hence none to queue */
|
||||
sdate=p_date();
|
||||
entno=LocateEntry(&sdate);
|
||||
if (entno>=nent)
|
||||
return; /* no entries with dates in the future */
|
||||
pent=(&table[entno]);
|
||||
*p_bcpy(&buf[0],pent->pb,pent->tlen)=0; /* copy the text */
|
||||
pent->ref=TRUE; /* mark this entry as the one queued */
|
||||
times[0]=pent->sdate; /* fill in the time the alarm is due */
|
||||
times[1]=pent->sdate; /* and the time to DISPLAY */
|
||||
p_ioc5(aH,P_FWRITE,&almstat,×,&buf);
|
||||
almactive=TRUE; /* set active word TRUE */
|
||||
}
|
||||
|
||||
LOCAL_C VOID UpdateTimeFormat(VOID)
|
||||
{ /* Update time-text object's record of time format */
|
||||
hTTSetFormat(ttH,H_TIME_FORMAT_NO_SECONDS|H_TIME_FORMAT_SUFFIX|
|
||||
H_TIME_FORMAT_DAY_NAME|H_TIME_FORMAT_MONTH_NAME);
|
||||
}
|
||||
|
||||
LOCAL_C INT SdateToBuf(TEXT *pb,ULONG *psdate)
|
||||
{ /* convert time and date to text, as per system preferences */
|
||||
hTTSetTime(ttH,H_TIME_SET_SDATE,psdate);
|
||||
return(hTTSenseString(ttH,H_TIME_SENSE_BOTH,pb));
|
||||
}
|
||||
|
||||
LOCAL_C VOID SetGmode(INT gmode)
|
||||
{ /* set Gmode of current graphics context */
|
||||
G_GC gc;
|
||||
|
||||
gc.gmode=gmode;
|
||||
gSetGC(0,G_GC_MASK_GMODE,&gc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SetBold(INT flag)
|
||||
{ /* prepare to print in bold (if flag TRUE) or non-bold */
|
||||
G_GC gc;
|
||||
|
||||
gc.font=WS_FONT_BASE+flag;
|
||||
gSetGC(0,G_GC_MASK_FONT,&gc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID GetCursorBox(INT i,P_RECT *pbox)
|
||||
{ /* where should the cursor be drawn */
|
||||
pbox->tl.x=4;
|
||||
pbox->br.x=10;
|
||||
pbox->tl.y=4+i*18;
|
||||
pbox->br.y=pbox->tl.y+9;
|
||||
}
|
||||
|
||||
LOCAL_C VOID DrawCursor(INT i)
|
||||
{ /* draw the cursor (character octal 34) */
|
||||
P_RECT box;
|
||||
|
||||
GetCursorBox(i,&box);
|
||||
gPrintBoxText(&box,8,G_TEXT_ALIGN_LEFT,0,"\034",1);
|
||||
}
|
||||
|
||||
LOCAL_C VOID EraseCursor(INT i)
|
||||
{ /* remove the cursor (from the specified row) */
|
||||
P_RECT box;
|
||||
|
||||
GetCursorBox(i,&box);
|
||||
gClrRect(&box,G_TRMODE_CLR); /* clear all pixels in the rectangle */
|
||||
}
|
||||
|
||||
LOCAL_C VOID LineToScreen(INT y,INT xoff,TEXT *pb,INT tlen)
|
||||
{ /* print the given line of text on the screen */
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=4;
|
||||
box.tl.y=4+y*9;
|
||||
box.br.x=ScreenWidth-4;
|
||||
box.br.y=box.tl.y+9;
|
||||
gPrintBoxText(&box,8,G_TEXT_ALIGN_LEFT,xoff,pb,tlen);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ClearLine(INT y)
|
||||
{ /* clear all text from the given line */
|
||||
LineToScreen(y,0,NULL,0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DrawLine(INT i)
|
||||
{ /* draw the two lines of text for the specified entry */
|
||||
INT len;
|
||||
INT entno;
|
||||
ENTRY *pent;
|
||||
TEXT buf[48];
|
||||
|
||||
entno=i+tent; /* offset by no. of first on-screen entry */
|
||||
if (entno>=nent)
|
||||
{ /* no entry for this position - hence clear */
|
||||
ClearLine(i*2);
|
||||
ClearLine(i*2+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
pent=(&table[entno]);
|
||||
SetBold(TRUE); /* draw the date and time in bold */
|
||||
len=SdateToBuf(&buf[0],&pent->sdate);
|
||||
LineToScreen(i*2,10,&buf[0],len);
|
||||
SetBold(FALSE); /* draw the text (and any cursor) in non-bold */
|
||||
if (entno==cent)
|
||||
DrawCursor(i);
|
||||
LineToScreen(i*2+1,22,pent->pb,pent->tlen);
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID Display(VOID)
|
||||
{ /* draw all four entry slots on the screen */
|
||||
INT i;
|
||||
|
||||
if (!nent)
|
||||
{ /* no entries set - so display text to this effect */
|
||||
SetBold(TRUE);
|
||||
LineToScreen(0,10,str(STR_NO_REMINDERS_SET),16);
|
||||
ClearLine(1); /* clear the line under the message */
|
||||
return;
|
||||
}
|
||||
for (i=0; i<4; i++)
|
||||
DrawLine(i);
|
||||
}
|
||||
|
||||
LOCAL_C INT ResizeWidth(UWORD width)
|
||||
{ /* try to change the width of the main display region */
|
||||
INT ret;
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=width;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
ret=uErrorValue(wCheckPoint()); /* check whether successful */
|
||||
if (!ret)
|
||||
ScreenWidth=width; /* only record new value if successful */
|
||||
return(ret);
|
||||
}
|
||||
|
||||
LOCAL_C INT ToggleStatusWindow(VOID)
|
||||
{ /* attempt to toggle the visibility of the status window */
|
||||
if (show_statwin)
|
||||
{ /* status window is currently showing */
|
||||
if (ResizeWidth(240))
|
||||
return(-1);
|
||||
wsDisable(); /* remove status window */
|
||||
}
|
||||
else
|
||||
{ /* status window not currently showing */
|
||||
if (ResizeWidth(189))
|
||||
return(-1);
|
||||
wsEnable(); /* display status window */
|
||||
}
|
||||
show_statwin^=TRUE;
|
||||
gBorder(lastbflags); /* redraw the border */
|
||||
Display(); /* redraw the main display */
|
||||
return(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID EnsureGoodTent(VOID)
|
||||
{ /* find good value for tent - top entry on screen */
|
||||
if (nent<5)
|
||||
tent=0; /* show ALL entries if less than five in total */
|
||||
else if (tent<cent-3)
|
||||
tent=cent-3; /* cursor was off bottom of screen */
|
||||
else if (tent>cent)
|
||||
tent=cent; /* cursor was off top of screen */
|
||||
}
|
||||
|
||||
LOCAL_C VOID AppendEntry(ENTRY *pent)
|
||||
{ /* add the given entry */
|
||||
INT tomove;
|
||||
|
||||
if (!nent)
|
||||
cent=0;
|
||||
else
|
||||
{ /* find where to insert the entry */
|
||||
cent=LocateEntry(&pent->sdate); /* uses binary search */
|
||||
tomove=nent-cent; /* how many entries to "move along */
|
||||
p_bcpy(&table[cent+1],&table[cent],tomove*sizeof(ENTRY));
|
||||
}
|
||||
nent++; /* increment count of number of entries */
|
||||
table[cent]=(*pent); /* copy the entry details into the table */
|
||||
EnsureGoodTent(); /* check whether need to scroll */
|
||||
Display(); /* redraw the main display */
|
||||
RequeueAlarm(); /* ensure correct alarm is queued */
|
||||
}
|
||||
|
||||
LOCAL_C VOID DoDeleteEntry(VOID)
|
||||
{ /* delete the current entry */
|
||||
INT tomove; /* how many records to "move back" */
|
||||
|
||||
p_free(table[cent].pb); /* free alloc cell holding the text */
|
||||
nent--; /* decrement total count of entries */
|
||||
tomove=nent-cent; /* now fill up the gap in the table */
|
||||
p_bcpy(&table[cent],&table[cent+1],tomove*sizeof(ENTRY));
|
||||
}
|
||||
|
||||
LOCAL_C VOID CleanEntry(ENTRY *pent)
|
||||
{ /* prepare a blank entry */
|
||||
p_bfil(pent,sizeof(ENTRY),0);
|
||||
pent->sdate=p_date()+3600; /* seed to one hour in the future */
|
||||
}
|
||||
|
||||
LOCAL_C INT EditEntry(ENTRY *pent)
|
||||
{ /* allow the user to edit an entry */
|
||||
P_DAYSEC ds;
|
||||
H_DI_DATE date;
|
||||
H_DI_TIME time;
|
||||
TEXT buf[66];
|
||||
H_DI_SEDIT sed;
|
||||
|
||||
if (uOpenDialog(str(STR_REMINDER))) /* title line of dialog */
|
||||
return(-1);
|
||||
p_bcpy(&buf[1],pent->pb,buf[0]=pent->tlen);
|
||||
sed.str=(&buf[0]); /* prepare to edit the text of the reminder */
|
||||
sed.len=64; /* maximum allowed length */
|
||||
sed.width=25; /* width of "viewing" region */
|
||||
if (uAddDialogItem(H_DIALOG_SEDIT,str(STR_MESSAGE),&sed))
|
||||
return(-1);
|
||||
p_sttods(&pent->sdate,&ds); /* crack into "time" and "date" */
|
||||
time.value=(&ds.sec); /* prepare to edit the time of the reminder */
|
||||
time.low=0;
|
||||
time.high=P_NSECDAY-1;
|
||||
time.type=0;
|
||||
if (uAddDialogItem(H_DIALOG_TIME,str(STR_TIME),&time))
|
||||
return(-1);
|
||||
date.value=(&ds.day); /* prepare to edit the date of the reminder */
|
||||
date.low=H_FIRST_SYS_DAY;
|
||||
date.high=H_LAST_SYS_DAY;
|
||||
if (uAddDialogItem(H_DIALOG_DATE,str(STR_DATE),&date))
|
||||
return(-1);
|
||||
if (uRunDialog()<=0)
|
||||
return(-1); /* user cancelled (or insufficient memory) */
|
||||
p_dstost(&ds,&pent->sdate); /* reconstitute system time */
|
||||
pent->pb=p_realloc(pent->pb,buf[0]); /* check text alloc cell length */
|
||||
if (!pent->pb)
|
||||
{ /* no memory left to grow the text alloc cell */
|
||||
uErrorValue(E_GEN_NOMEMORY);
|
||||
return(-1);
|
||||
}
|
||||
pent->tlen=buf[0];
|
||||
p_bcpy(pent->pb,&buf[1],buf[0]);
|
||||
return(0); /* signal successful edit */
|
||||
}
|
||||
|
||||
LOCAL_C VOID AddEntry(VOID)
|
||||
{ /* the user wants to add an entry */
|
||||
ENTRY ent;
|
||||
|
||||
CleanEntry(&ent); /* prepare a "clean" initial starting point */
|
||||
if (EditEntry(&ent)) /* allow the user to edit it */
|
||||
return;
|
||||
AppendEntry(&ent); /* insert the entry */
|
||||
}
|
||||
|
||||
LOCAL_C VOID InfoMsg(INT rid)
|
||||
{ /* present info message with text with given resource id */
|
||||
wInfoMsg(str(rid));
|
||||
}
|
||||
|
||||
LOCAL_C VOID UpdateEntry(VOID)
|
||||
{ /* the user wants to update the current entry */
|
||||
ENTRY *pent;
|
||||
ENTRY ent;
|
||||
|
||||
if (!nent)
|
||||
{ /* no current entry to update */
|
||||
InfoMsg(STR_NO_ENTRY_UPDATE);
|
||||
return;
|
||||
}
|
||||
pent=(&table[cent]); /* find the current entry */
|
||||
if (EditEntry(pent)) /* allow the user to edit it */
|
||||
return;
|
||||
ent=(*pent);
|
||||
pent->pb=0;
|
||||
DoDeleteEntry(); /* delete the existing entry... */
|
||||
AppendEntry(&ent); /* ... and re-insert it with the new contents */
|
||||
}
|
||||
|
||||
LOCAL_C VOID DeleteEntry(VOID)
|
||||
{ /* the user wants to delete the current entry */
|
||||
TEXT ny[4]; /* for the characters 'n' then 'y' */
|
||||
TEXT yes[10]; /* for the string "yes" */
|
||||
TEXT no[10]; /* for the string "no" */
|
||||
|
||||
if (!nent)
|
||||
{ /* no entry to delete */
|
||||
InfoMsg(STR_NO_ENTRY_DELETE);
|
||||
return;
|
||||
}
|
||||
if (uOpenDialog(str(STR_DELETE_REMINDER))) /* title of dialog */
|
||||
return;
|
||||
LoadStr(STR_NY,&ny[0]); /* find the text for the existing language */
|
||||
LoadStr(STR_NO,&no[0]);
|
||||
LoadStr(STR_YES,&yes[0]);
|
||||
if (uAddButtonList(&no[0],-ny[0],&yes[0],ny[1],NULL)) /* no-yes buttons */
|
||||
return;
|
||||
if (uRunDialog()!=ny[1]) /* check if user pressed 'y' button */
|
||||
return;
|
||||
DoDeleteEntry(); /* delete the entry */
|
||||
if (cent==nent && nent) /* change the cursor position */
|
||||
cent=nent-1;
|
||||
EnsureGoodTent(); /* check whether need to scroll display */
|
||||
Display(); /* redraw main display area */
|
||||
RequeueAlarm(); /* recalculate which alarm to queue */
|
||||
}
|
||||
|
||||
LOCAL_C INT TakeCopy(ENTRY *targ,ENTRY *src)
|
||||
{ /* copy specified entry */
|
||||
targ->pb=p_alloc(src->tlen); /* prepare an alloc cell for the text */
|
||||
if (!targ->pb)
|
||||
{
|
||||
uErrorValue(E_GEN_NOMEMORY);
|
||||
return(-1);
|
||||
}
|
||||
p_bcpy(targ->pb,src->pb,src->tlen); /* copy the text */
|
||||
p_bcpy(targ,src,sizeof(ENTRY)-sizeof(TEXT *)); /* copy everything else */
|
||||
return(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CopyEntry(VOID)
|
||||
{ /* the user wants to copy the current entry */
|
||||
ENTRY new;
|
||||
|
||||
if (!nent)
|
||||
{ /* no current entry to copy */
|
||||
InfoMsg(STR_NO_ENTRY_COPY);
|
||||
return;
|
||||
}
|
||||
if (TakeCopy(&new,&table[cent]))
|
||||
return; /* no memory to make copy */
|
||||
p_free(clipent.pb); /* free any existing clipboard text */
|
||||
clipent=new;
|
||||
InfoMsg(STR_REMINDER_COPIED); /* signal success to user */
|
||||
}
|
||||
|
||||
LOCAL_C VOID InsertEntry(VOID)
|
||||
{ /* the user wants to insert the clipboard contents */
|
||||
ENTRY new;
|
||||
|
||||
if (!clipent.pb)
|
||||
{ /* the clipboard contents are empty */
|
||||
InfoMsg(STR_NO_ENTRY_INSERT);
|
||||
return;
|
||||
}
|
||||
if (TakeCopy(&new,&clipent))
|
||||
return; /* no memory for new entry */
|
||||
AppendEntry(&new); /* insert the entry */
|
||||
}
|
||||
|
||||
LOCAL_C VOID ExitIfConfirmed(VOID)
|
||||
{ /* the user wants to exit - request confirmation */
|
||||
H_DI_TEXT txt;
|
||||
TEXT cancel[10]; /* for the text "cancel" */
|
||||
TEXT exit[10]; /* for the text "exit" */
|
||||
|
||||
if (nent)
|
||||
{ /* only need confirmation if there are entries */
|
||||
if (uOpenDialog(str(STR_WARNING))) /* dialog title */
|
||||
return;
|
||||
txt.str=str(LSTR_DELETE_ALL); /* lbc text from resource file */
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE; /* centre alignment */
|
||||
if (uAddDialogItem(H_DIALOG_TEXT,0,&txt))
|
||||
return;
|
||||
LoadStr(STR_CANCEL,&cancel[0]); /* load correct language text */
|
||||
LoadStr(STR_EXIT,&exit[0]);
|
||||
if (uAddButtonList(&cancel[0],W_KEY_ESCAPE,
|
||||
&exit[0],W_KEY_RETURN,NULL))
|
||||
return;
|
||||
if (uRunDialog()!=W_KEY_RETURN)
|
||||
return; /* the user failed to confirm */
|
||||
}
|
||||
p_exit(0); /* exit cleanly */
|
||||
}
|
||||
|
||||
LOCAL_C INT PrintLine(H_PRINT *pr)
|
||||
{ /* print next line of data */
|
||||
ENTRY *pent;
|
||||
|
||||
pent=(&table[PrintRec]); /* which entry to print */
|
||||
switch (PrintState++)
|
||||
{
|
||||
case 0: /* need to print the date and time */
|
||||
pr->blen=SdateToBuf(&PrintBuf[0],&pent->sdate);
|
||||
pr->buf=(&PrintBuf[0]);
|
||||
pr->style|=H_PRINT_STY_BOLD; /* print date and time in bold */
|
||||
break;
|
||||
case 1: /* need to print the text */
|
||||
pr->buf=pent->pb;
|
||||
pr->blen=pent->tlen;
|
||||
break;
|
||||
case 2: /* gap between entries */
|
||||
pr->blen=0;
|
||||
PrintState=0;
|
||||
PrintRec++;
|
||||
return(PrintRec!=nent); /* return FALSE if no more to print */
|
||||
}
|
||||
pr->flags|=H_PRINT_KEEP;/* keep different parts of entry on same page */
|
||||
return(TRUE); /* return TRUE since printing not yet finished */
|
||||
}
|
||||
|
||||
LOCAL_C VOID PrintAll(VOID)
|
||||
{ /* the user wants to print the reminders */
|
||||
if (!nent)
|
||||
{ /* no entries to print */
|
||||
InfoMsg(STR_NOTHING_PRINT);
|
||||
return;
|
||||
}
|
||||
PrintRec=0; /* initialise print state variables */
|
||||
PrintState=0;
|
||||
hPrint(PrintLine); /* specify call-back function */
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{ /* switch on command index to appropriate function */
|
||||
switch (index)
|
||||
{
|
||||
case ITEMS_BEFORE_EDIT:
|
||||
InsertEntry();
|
||||
break;
|
||||
case ITEMS_BEFORE_EDIT+1:
|
||||
CopyEntry();
|
||||
break;
|
||||
case ITEMS_BEFORE_EDIT+2:
|
||||
UpdateEntry();
|
||||
break;
|
||||
case ITEMS_BEFORE_EDIT+3:
|
||||
AddEntry();
|
||||
break;
|
||||
case ITEMS_BEFORE_EDIT+4:
|
||||
DeleteEntry();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL:
|
||||
PrintAll();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+1:
|
||||
hPrintSetupDialog();
|
||||
break;
|
||||
case ITEMS_BEFORE_SPECIAL+2:
|
||||
ExitIfConfirmed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{ /* try to find command to execute matching accelerator passed */
|
||||
keycode=uLocateCommand(keycode); /* look up accelerator table */
|
||||
if (keycode>=0) /* found - keycode converted to index */
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DoScroll(INT dely)
|
||||
{ /* scroll the display vertically by given amount */
|
||||
P_POINT offset; /* offset to scroll */
|
||||
P_RECT src; /* source region for scroll */
|
||||
|
||||
offset.x=0;
|
||||
offset.y=dely*18; /* each entry is two lines each 9 pixels high */
|
||||
src.tl.x=4;
|
||||
src.br.x=ScreenWidth-4;
|
||||
if (dely>0)
|
||||
{ /* scrolling down - so exclude bottom from source */
|
||||
src.tl.y=4;
|
||||
src.br.y=4+(4-dely)*18;
|
||||
}
|
||||
else
|
||||
{ /* scrolling up - so exclude top from source */
|
||||
src.tl.y=4-dely*18;
|
||||
src.br.y=4+4*18;
|
||||
}
|
||||
wScrollRect(MainWid,&src,&offset);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MakeHighlight(INT newcent)
|
||||
{ /* change the cursor position as specified, with smooth scrolling */
|
||||
INT toscroll; /* amount of scroll needed (if any) */
|
||||
|
||||
if (!nent)
|
||||
return; /* no entries - hence nothing to do */
|
||||
if (newcent==cent)
|
||||
return; /* cursor already at specified position */
|
||||
EraseCursor(cent-tent); /* remove existing cursor */
|
||||
toscroll=tent-newcent;
|
||||
if (toscroll>0)
|
||||
{ /* new cursor position off top of screen */
|
||||
tent-=toscroll; /* adjust record of entry at top of screen */
|
||||
if (toscroll<4)
|
||||
DoScroll(toscroll); /* only actually scroll if less than 4 */
|
||||
else
|
||||
toscroll=4; /* toscroll now holds number of lines to redraw */
|
||||
while (toscroll)
|
||||
DrawLine(--toscroll); /* redraw lines not scrolled */
|
||||
}
|
||||
else
|
||||
{
|
||||
toscroll=-3-toscroll;
|
||||
if (toscroll>0)
|
||||
{ /* new cursor position off bottom of screen */
|
||||
tent+=toscroll; /* adjust record of entry at top of screen */
|
||||
if (toscroll<4)
|
||||
DoScroll(-toscroll);
|
||||
else
|
||||
toscroll=4;
|
||||
while (toscroll)
|
||||
DrawLine(4-toscroll--); /* redraw lines not scrolled */
|
||||
}
|
||||
}
|
||||
cent=newcent;
|
||||
DrawCursor(cent-tent); /* draw the cursor back in */
|
||||
}
|
||||
|
||||
LOCAL_C VOID ScrollPageBy(INT delta)
|
||||
{ /* implementation of PgUp / PgDn */
|
||||
if (!nent)
|
||||
return; /* no entries to display */
|
||||
if (delta<(-3))
|
||||
delta=(-3); /* scroll at most three records */
|
||||
else if (delta>3)
|
||||
delta=3;
|
||||
tent+=delta;
|
||||
cent+=delta;
|
||||
Display();
|
||||
}
|
||||
|
||||
LOCAL_C VOID HandleAlarmEvent(VOID)
|
||||
{ /* an alarm has expired (or time has been put back) */
|
||||
ENTRY *pent; /* the alarm that was queued */
|
||||
INT expired; /* whether alarm really did expire */
|
||||
|
||||
pent=LocateRef();
|
||||
expired=(pent->sdate<=p_date()); /* find if alarm time has elapsed */
|
||||
almactive=FALSE;
|
||||
pent->ref=FALSE;
|
||||
RequeueAlarm(); /* find which is next alarm to queue */
|
||||
if (expired)
|
||||
{
|
||||
uForceToFront(); /* come into foreground */
|
||||
MakeHighlight(pent-(&table[0])); /* highlight the elapsed alarm */
|
||||
UpdateEntry(); /* allow user to edit the reminder */
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID CheckBorderArrows(VOID)
|
||||
{ /* see if border needs redisplaying (on account of "scroll arrows") */
|
||||
INT bflags; /* the flags that ought to be displayed */
|
||||
|
||||
if (!nent)
|
||||
return; /* no entries */
|
||||
if (tent) /* check if more entries off screen top */
|
||||
bflags=W_BORD_CORNER_4|W_BORD_TOP_ON;
|
||||
else
|
||||
bflags=W_BORD_CORNER_4|W_BORD_TOP_OFF;
|
||||
if (tent+4<nent) /* check if more entries off screen bottom */
|
||||
bflags|=W_BORD_BOT_ON;
|
||||
else
|
||||
bflags|=W_BORD_BOT_OFF;
|
||||
if (bflags!=lastbflags) /* check if border needs to be redrawn */
|
||||
gBorder(lastbflags=bflags);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{ /* central event processing loop */
|
||||
INT ret;
|
||||
WMSG_KEY key; /* to receive keypress */
|
||||
WORD keystat; /* status word for keypress */
|
||||
WORD keyactive; /* active word for keypress */
|
||||
|
||||
keyactive=FALSE; /* no keyboard read queued */
|
||||
FOREVER
|
||||
{
|
||||
CheckBorderArrows(); /* update border arrow display if changed */
|
||||
if (keyactive)
|
||||
wFlush(); /* flush Window Server function buffer */
|
||||
else
|
||||
{ /* queue a read for another keypress */
|
||||
uGetKeyA(&keystat,&key);
|
||||
keyactive=TRUE;
|
||||
}
|
||||
p_iowait(); /* wait for event */
|
||||
if (keystat==E_FILE_PENDING)
|
||||
{ /* alarm event must have occurred */
|
||||
HandleAlarmEvent();
|
||||
continue;
|
||||
}
|
||||
keyactive=FALSE; /* keypress must have been received */
|
||||
if (key.keycode&W_EVENT_KEY)
|
||||
{
|
||||
if (key.keycode==CONS_EVENT_FOREGROUND)
|
||||
{ /* check whether system time format changed */
|
||||
UpdateTimeFormat();
|
||||
Display();
|
||||
}
|
||||
}
|
||||
else if (key.keycode&W_SPECIAL_KEY) /* Psion key pressed */
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else
|
||||
{
|
||||
switch (key.keycode)
|
||||
{
|
||||
case W_KEY_MENU:
|
||||
if (key.modifiers&W_CTRL_MODIFIER)
|
||||
{ /* toggle status window visibility */
|
||||
SetGmode(G_TRMODE_CLR);
|
||||
gBorder(lastbflags&~(W_BORD_TOP_OFF|W_BORD_BOT_OFF));
|
||||
SetGmode(G_TRMODE_SET);
|
||||
ToggleStatusWindow();
|
||||
}
|
||||
else
|
||||
{ /* display menu bar */
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
break;
|
||||
case W_KEY_DELETE_LEFT:
|
||||
DeleteEntry(); /* user wants to delete entry */
|
||||
break;
|
||||
case W_KEY_RETURN:
|
||||
if (!nent || key.modifiers&W_SHIFT_MODIFIER)
|
||||
AddEntry(); /* user wants to add entry */
|
||||
else
|
||||
UpdateEntry(); /* user wants to update entry */
|
||||
break;
|
||||
case W_KEY_UP:
|
||||
if (cent)
|
||||
MakeHighlight(cent-1);
|
||||
break;
|
||||
case W_KEY_DOWN:
|
||||
if (cent<nent-1)
|
||||
MakeHighlight(cent+1);
|
||||
break;
|
||||
case W_KEY_PAGE_UP:
|
||||
if (key.modifiers&W_CTRL_MODIFIER)
|
||||
MakeHighlight(0);
|
||||
else if (!tent)
|
||||
MakeHighlight(0);
|
||||
else
|
||||
ScrollPageBy(-tent);
|
||||
break;
|
||||
case W_KEY_PAGE_DOWN:
|
||||
if (key.modifiers&W_CTRL_MODIFIER)
|
||||
MakeHighlight(nent-1);
|
||||
else if (tent+4>=nent)
|
||||
MakeHighlight(nent-1);
|
||||
else
|
||||
ScrollPageBy(nent-tent-4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{ /* attempt to create default graphics context on main window */
|
||||
INT hgc; /* graphics context handle (if successful) */
|
||||
|
||||
hgc=gCreateGC0(MainWid);
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID *InitRcb(VOID)
|
||||
{ /* create and initialise resource file object */
|
||||
INT ret;
|
||||
VOID *rcb; /* resource file object handle */
|
||||
|
||||
rcb=p_new(1,C_RSCFILE);
|
||||
ret=p_entersend3(rcb,O_RS_INIT,DatCommandPtr); /* pass file name */
|
||||
if (ret<0) /* no resource file found */
|
||||
p_exit(ret); /* fatal (programmer) error */
|
||||
return(rcb);
|
||||
}
|
||||
|
||||
LOCAL_C H_MENU_DATA *LoadMenuTitles(VOID *rcb,INT rid)
|
||||
{ /* load menu titles from specified resource file */
|
||||
H_MENU_DATA *pmdata,*pi; /* for created alloc cell */
|
||||
TEXT *titles; /* for loaded alloc cell */
|
||||
WORD count; /* how many menus */
|
||||
INT ret;
|
||||
|
||||
ret=p_entersend4(rcb,O_RS_READ,rid,&titles);
|
||||
if (ret<0)
|
||||
return(NULL); /* couldn't access resource file */
|
||||
count=(*(WORD *)titles); /* first WORD gives count of menus */
|
||||
pmdata=p_alloc((count+1)*sizeof(H_MENU_DATA));
|
||||
if (!pmdata)
|
||||
{ /* no memory to alloc H_MENU_DATA array */
|
||||
p_free(titles); /* clean up partially constructed data */
|
||||
return(NULL);
|
||||
}
|
||||
pi=pmdata; /* prepare to walk through H_MENU_DATA array */
|
||||
titles+=2; /* skip over leading WORD count */
|
||||
while (count--) /* for each menu */
|
||||
{
|
||||
pi->title=titles; /* store pointer to title text */
|
||||
titles+=p_slen(titles)+1; /* skip the text and terminating zero */
|
||||
pi->nlines=(*titles++); /* store the number of lines */
|
||||
pi++; /* increment to next H_MENU_DATA element */
|
||||
}
|
||||
pi->title=0; /* place NULL at end of array */
|
||||
return(pmdata); /* return pointer to created struct */
|
||||
}
|
||||
|
||||
LOCAL_C TEXT **LoadMenuCommands(VOID *rcb,INT rid)
|
||||
{ /* load menu commands from specified resource file */
|
||||
TEXT **pcmds,**pi; /* for created alloc cell */
|
||||
TEXT *cmds; /* for loaded alloc cell */
|
||||
WORD count; /* how many commands */
|
||||
INT ret;
|
||||
|
||||
ret=p_entersend4(rcb,O_RS_READ,rid,&cmds);
|
||||
if (ret<0)
|
||||
return(NULL); /* couldn't access resource file */
|
||||
count=(*(WORD *)cmds); /* first WORD gives count of commands */
|
||||
pcmds=p_alloc((count+1)*sizeof(TEXT *));
|
||||
if (!pcmds)
|
||||
{ /* no memory to allow TEXT * array */
|
||||
p_free(cmds); /* clean up partially constructed data */
|
||||
return(NULL);
|
||||
}
|
||||
pi=pcmds; /* prepare to walk through TEXT * array */
|
||||
cmds+=2; /* skip over leading WORD count */
|
||||
while (count--) /* for each menu command */
|
||||
{
|
||||
*pi++=cmds; /* store pointer to command details */
|
||||
cmds+=p_slen(cmds)+1; /* skip the text and terminating zero */
|
||||
}
|
||||
*pi=0; /* place NULL at end of array */
|
||||
return(pcmds); /* return pointer to created struct */
|
||||
}
|
||||
|
||||
LOCAL_C VOID LoadMenus(VOID)
|
||||
{ /* load all menu data */
|
||||
rcb=InitRcb(); /* create and initialise resource file object */
|
||||
_cmds=LoadMenuCommands(rcb,REMIND_CMDS); /* load commands */
|
||||
_mdata=LoadMenuTitles(rcb,REMIND_MENUS); /* load menu titles */
|
||||
if (!_cmds || !_mdata) /* test if either load failed */
|
||||
p_exit(E_GEN_START); /* report fatal initialisation error */
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{ /* application initialisation specific to Remind */
|
||||
uEscape(FALSE); /* disable Psion-Esc */
|
||||
LoadMenus(); /* load all menu data */
|
||||
MainWid=uFindMainWid(); /* find id of main display window */
|
||||
CreateGC(); /* create default graphics context */
|
||||
p_open(&aH,"ALM:",-1); /* open channel to ALM: device */
|
||||
ttH=hTTOpen(); /* open channel to time-text object */
|
||||
hTTSetAbbreviations(ttH,3,3); /* set abbreviations to use */
|
||||
UpdateTimeFormat(); /* check current system time format */
|
||||
hCrackCommandLine(); /* crack incoming command line */
|
||||
if (ToggleStatusWindow()) /* attempt to display status window */
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{ /* the main() for all Hwif programs */
|
||||
uCommonInit(); /* initialisation common to all Hwif programs */
|
||||
SpecificInit(); /* initialisation specific to Remind */
|
||||
MainLoop(); /* the central event processing loop */
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Remind
|
||||
|
||||
4000
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
#system epoc img
|
||||
#set epocinit=iplib
|
||||
#model small jpi
|
||||
|
||||
#run "rs remind" no_window no_abort
|
||||
#compile remind.c
|
||||
#pragma link(hwif.lib)
|
||||
#link remind
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
Constants shared between remind.rss and remind.c
|
||||
*/
|
||||
|
||||
#define EDIT_ITEMS 5
|
||||
#define SPECIAL_ITEMS 3
|
||||
|
||||
#define ITEMS_BEFORE_EDIT 0
|
||||
#define ITEMS_BEFORE_SPECIAL EDIT_ITEMS
|
||||
@@ -0,0 +1,66 @@
|
||||
#include "remind.rh"
|
||||
|
||||
STRUCT STRING
|
||||
{
|
||||
TEXT str;
|
||||
}
|
||||
|
||||
STRUCT LSTRING
|
||||
{
|
||||
LTEXT lstr;
|
||||
}
|
||||
|
||||
STRUCT MENU_TITLE
|
||||
{
|
||||
TEXT str;
|
||||
BYTE ncommands;
|
||||
}
|
||||
|
||||
STRUCT STRING_ARRAY
|
||||
{
|
||||
STRUCT strlst[];
|
||||
}
|
||||
|
||||
RESOURCE STRING_ARRAY remind_cmds
|
||||
{
|
||||
strlst=
|
||||
{
|
||||
STRING {str="iInsert";},
|
||||
STRING {str="cCopy";},
|
||||
STRING {str="uUpdate";},
|
||||
STRING {str="aAdd";},
|
||||
STRING {str="dDelete";},
|
||||
STRING {str="pPrint";},
|
||||
STRING {str="yPrint setup";},
|
||||
STRING {str="xExit";}
|
||||
};
|
||||
}
|
||||
|
||||
RESOURCE STRING_ARRAY remind_menus
|
||||
{
|
||||
strlst=
|
||||
{
|
||||
MENU_TITLE {str="Edit"; ncommands=EDIT_ITEMS;},
|
||||
MENU_TITLE {str="Special"; ncommands=SPECIAL_ITEMS;}
|
||||
};
|
||||
}
|
||||
|
||||
RESOURCE STRING str_no_reminders_set {str="No reminders set";}
|
||||
RESOURCE STRING str_reminder {str="Reminder";}
|
||||
RESOURCE STRING str_message {str="Message";}
|
||||
RESOURCE STRING str_time {str="Time";}
|
||||
RESOURCE STRING str_date {str="Date";}
|
||||
RESOURCE STRING str_no_entry_update {str="No entry to update";}
|
||||
RESOURCE STRING str_no_entry_delete {str="No entry to delete";}
|
||||
RESOURCE STRING str_no_entry_copy {str="No entry to copy";}
|
||||
RESOURCE STRING str_no_entry_insert {str="No entry to insert";}
|
||||
RESOURCE STRING str_reminder_copied {str="Reminder copied";}
|
||||
RESOURCE STRING str_nothing_print {str="Nothing to print";}
|
||||
RESOURCE STRING str_delete_reminder {str="Delete this reminder";}
|
||||
RESOURCE STRING str_warning {str="Warning";}
|
||||
RESOURCE LSTRING lstr_delete_all {lstr="Exiting will delete all reminders";}
|
||||
RESOURCE STRING str_ny {str="ny";}
|
||||
RESOURCE STRING str_no {str="No";}
|
||||
RESOURCE STRING str_yes {str="Yes";}
|
||||
RESOURCE STRING str_cancel {str="Cancel";}
|
||||
RESOURCE STRING str_exit {str="Exit";}
|
||||
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
@echo off
|
||||
rcomp.exe -S%1 -O%1 -I\sibosdk\include\ -G\sibosdk\include\%1
|
||||
@@ -0,0 +1,3 @@
|
||||
spy.pic
|
||||
spy.rsc
|
||||
spy.shd
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
Spy
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
#system epoc img
|
||||
#set epocinit=iplib
|
||||
#model small jpi
|
||||
#compile spy
|
||||
#compile spybw
|
||||
#compile wsreport
|
||||
#pragma link(hwif.lib)
|
||||
#link spy
|
||||
Binary file not shown.
@@ -0,0 +1,293 @@
|
||||
/*
|
||||
SPYBW.C
|
||||
|
||||
Written by SteveT
|
||||
Started on 20/7/92
|
||||
|
||||
Part of Spy to monitor CPU band width usage.
|
||||
*/
|
||||
|
||||
#include <plib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
#define DLG_WIDTH 190
|
||||
#define DLG_HEIGHT 49
|
||||
#define DLG_LINE 13
|
||||
#define STACK_SIZE 500
|
||||
|
||||
GLREF_D TEXT *DatCommandPtr;
|
||||
GLREF_D VOID *winHandle;
|
||||
GLREF_D TEXT *DatProcessNamePtr;
|
||||
|
||||
LOCAL_D UINT TaskCount;
|
||||
|
||||
LOCAL_D INT Debug=FALSE;
|
||||
LOCAL_D UINT oldPri;
|
||||
LOCAL_D INT winId;
|
||||
LOCAL_D HANDLE bwPid;
|
||||
LOCAL_D HANDLE spyPid;
|
||||
LOCAL_D VOID *TimCB;
|
||||
LOCAL_D ULONG bwTotal;
|
||||
LOCAL_D UINT bwCount;
|
||||
LOCAL_D ULONG bwCabTotal;
|
||||
LOCAL_D UINT bwCabCount;
|
||||
LOCAL_D UINT bwCabBase;
|
||||
LOCAL_D ULONG bwCabDisplayTotal;
|
||||
LOCAL_D UINT bwCabDisplayCount;
|
||||
LOCAL_D UINT bwCabDisplayBase;
|
||||
LOCAL_D UWORD LastCount;
|
||||
LOCAL_D UWORD SampleCount;
|
||||
|
||||
LOCAL_D UBYTE TaskStack[STACK_SIZE];
|
||||
|
||||
/***********************************************************/
|
||||
/* This section of code is used by the task to measure the */
|
||||
/* available band width. */
|
||||
/***********************************************************/
|
||||
|
||||
LOCAL_C VOID MonitorLoop(VOID)
|
||||
{
|
||||
UINT i;
|
||||
|
||||
p_unmarka();
|
||||
FOREVER
|
||||
{
|
||||
for(i=0;i<500;i++);
|
||||
TaskCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************/
|
||||
/* Main body of code */
|
||||
/*********************/
|
||||
|
||||
LOCAL_C VOID DebugInfo(VOID)
|
||||
{
|
||||
TEXT buf[80];
|
||||
|
||||
p_atos(&buf[0],"%u/%u",LastCount,SampleCount);
|
||||
wInfoMsg(&buf[0]);
|
||||
}
|
||||
|
||||
GLDEF_C VOID DisableReads(UINT flag)
|
||||
{
|
||||
UINT tmp;
|
||||
|
||||
tmp=P_SCR_DISABLE_READS;
|
||||
p_iow(winHandle,P_FSET,&tmp,&flag);
|
||||
}
|
||||
|
||||
LOCAL_C INT CreateDialog(VOID)
|
||||
{
|
||||
W_WINDATA windata;
|
||||
INT w_id;
|
||||
|
||||
windata.extent.width=DLG_WIDTH;
|
||||
windata.extent.height=DLG_HEIGHT;
|
||||
windata.extent.tl.x=(240-DLG_WIDTH)>>1;
|
||||
windata.extent.tl.y=(80-DLG_HEIGHT)>>1;
|
||||
w_id=wCreateWindow(0,W_WIN_EXTENT,&windata,1);
|
||||
wInitialiseWindowTree(w_id);
|
||||
return(w_id);
|
||||
}
|
||||
|
||||
LOCAL_C VOID pTxt(UINT line,TEXT *txt,ULONG *pTotal,INT count,INT count2)
|
||||
{
|
||||
P_RECT rect;
|
||||
TEXT buf[20];
|
||||
ULONG Percentage,lCount;
|
||||
|
||||
rect.tl.x=4;
|
||||
rect.br.x=96;
|
||||
rect.tl.y=DLG_LINE+3+line*10;
|
||||
rect.br.y=rect.tl.y+8;
|
||||
gPrintBoxText(&rect,7,G_TEXT_ALIGN_LEFT,0,txt,p_slen(txt));
|
||||
buf[0]=0;
|
||||
if (bwCount>0 && count!=0)
|
||||
{
|
||||
lCount=(ULONG)(count==-1?1:count);
|
||||
Percentage=(*pTotal)*100l;
|
||||
Percentage/=lCount;
|
||||
Percentage/=(ULONG)SampleCount;
|
||||
if (count!=0)
|
||||
{
|
||||
if (count2>=0)
|
||||
p_atos(&buf[0],"%U%% [%u-%u]",Percentage,count2,count+count2);
|
||||
else
|
||||
p_atos(&buf[0],count>0?"%U%% [%u]":"%U%%",Percentage,count);
|
||||
}
|
||||
}
|
||||
rect.tl.x=rect.br.x;
|
||||
rect.br.x=DLG_WIDTH-6;
|
||||
gPrintBoxText(&rect,7,G_TEXT_ALIGN_LEFT,0,&buf[0],p_slen(&buf[0]));
|
||||
}
|
||||
|
||||
LOCAL_C VOID redrawWin(UINT update)
|
||||
{
|
||||
P_RECT rect;
|
||||
ULONG tmp;
|
||||
|
||||
if (update)
|
||||
gCreateTempGC0(winId);
|
||||
else
|
||||
{
|
||||
wBeginRedrawWinGC0(winId);
|
||||
gBorder(W_BORD_CORNER_4|W_BORD_SHADOW_D|W_BORD_SHADOW_ON);
|
||||
rect.tl.x=4;
|
||||
rect.br.x=DLG_WIDTH-6;
|
||||
rect.tl.y=3;
|
||||
rect.br.y=11;
|
||||
gPrintBoxText(&rect,7,G_TEXT_ALIGN_CENTRE,0,"Available CPU band width",24);
|
||||
gDrawLine(1,DLG_LINE,DLG_WIDTH-2,DLG_LINE);
|
||||
}
|
||||
pTxt(0,"Average",&bwTotal,bwCount,-1);
|
||||
tmp=LastCount;
|
||||
pTxt(1,"Last",&tmp,-1,-1);
|
||||
pTxt(2,"<Cntrl>\002B",&bwCabDisplayTotal,bwCabDisplayCount,bwCabDisplayBase);
|
||||
if (update)
|
||||
gFreeTempGC();
|
||||
else
|
||||
wEndRedraw();
|
||||
}
|
||||
|
||||
LOCAL_C VOID GetCount(UWORD *pCount)
|
||||
{
|
||||
LONG time;
|
||||
WORD tstat;
|
||||
|
||||
p_presume(bwPid);
|
||||
time=10l;
|
||||
TaskCount=0;
|
||||
p_ioc(TimCB,P_FREAD,&tstat,&time);
|
||||
p_waitstat(&tstat);
|
||||
*pCount=TaskCount;
|
||||
if (TaskCount>SampleCount)
|
||||
SampleCount=TaskCount;
|
||||
p_psuspend(bwPid);
|
||||
p_allowoff();
|
||||
}
|
||||
|
||||
LOCAL_C VOID InitBW(VOID)
|
||||
{
|
||||
UWORD oldSample,Count2;
|
||||
INT i;
|
||||
|
||||
f_leave(bwPid=p_ptask("SYS$SPY",E_MAX_PRIORITY-1,MonitorLoop,&TaskStack[STACK_SIZE-1]));
|
||||
f_open(&TimCB,"TIM:",-1);
|
||||
spyPid=p_getpid();
|
||||
oldPri=p_getpri(spyPid);
|
||||
p_setpri(spyPid,E_MAX_PRIORITY);
|
||||
if (SampleCount==0)
|
||||
for(i=0;i<5;i++)
|
||||
{ /* If no matching samples in 5 then just take the best so far */
|
||||
oldSample=SampleCount;
|
||||
GetCount(&Count2);
|
||||
if (Count2==oldSample || (Count2+1)==oldSample || Count2==(oldSample+1))
|
||||
break; /* Two matching samples, must be good! */
|
||||
}
|
||||
p_setpri(bwPid,E_MIN_PRIORITY);
|
||||
p_setpri(spyPid,E_PRIORITY_WSERV-1);
|
||||
}
|
||||
|
||||
#ifdef JPIC
|
||||
#pragma save,ENTER_CALL
|
||||
#endif
|
||||
LOCAL_C INT xMonitorBandWidth(VOID)
|
||||
{
|
||||
WS_EV event;
|
||||
|
||||
bwCabDisplayCount=bwCabCount=bwCount=bwCabDisplayBase=bwCabBase=LastCount=0;
|
||||
bwCabDisplayTotal=bwCabTotal=bwTotal=0;
|
||||
DisableReads(TRUE);
|
||||
winId=CreateDialog();
|
||||
redrawWin(FALSE);
|
||||
wFlush();
|
||||
InitBW();
|
||||
wGetEvent(&event);
|
||||
FOREVER
|
||||
{
|
||||
p_ioyield();
|
||||
if (event.type!=E_FILE_PENDING)
|
||||
{
|
||||
p_iowait();
|
||||
if (event.type==WM_KEY)
|
||||
{
|
||||
if (event.p.key.keycode==27)
|
||||
break;
|
||||
if (event.p.key.keycode==(W_SPECIAL_KEY|'p'))
|
||||
wClientPosition(0,0);
|
||||
else if (event.p.key.keycode==(W_SPECIAL_KEY|'b'))
|
||||
{
|
||||
p_sound(-5,320);
|
||||
bwCabDisplayTotal=bwCabTotal;
|
||||
bwCabDisplayCount=bwCabCount;
|
||||
bwCabDisplayBase=bwCabBase;
|
||||
bwCabTotal=0;
|
||||
bwCabCount=0;
|
||||
bwCabBase=bwCount;
|
||||
redrawWin(TRUE);
|
||||
}
|
||||
else if (event.p.key.keycode=='d')
|
||||
Debug=!Debug;
|
||||
}
|
||||
else switch (event.type)
|
||||
{
|
||||
case WM_REDRAW:
|
||||
if (event.handle!=1)
|
||||
wInfoMsg("Redraw to unknown window!");
|
||||
else
|
||||
redrawWin(FALSE);
|
||||
break;
|
||||
case WM_FOREGROUND:
|
||||
case WM_BACKGROUND:
|
||||
p_setpri(spyPid,E_PRIORITY_WSERV-1);
|
||||
break;
|
||||
}
|
||||
wGetEvent(&event);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetCount(&LastCount);
|
||||
if (Debug)
|
||||
DebugInfo();
|
||||
bwTotal+=LastCount;
|
||||
if (bwCount++==9999)
|
||||
bwCount=1;
|
||||
bwCabTotal+=LastCount;
|
||||
bwCabCount++;
|
||||
redrawWin(TRUE);
|
||||
wFlush();
|
||||
}
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#ifdef JPIC
|
||||
#pragma restore
|
||||
#endif
|
||||
|
||||
GLDEF_C VOID MonitorBandWidth(VOID)
|
||||
{
|
||||
INT err;
|
||||
TEXT *name;
|
||||
|
||||
name=DatProcessNamePtr;
|
||||
bwPid=spyPid=0;
|
||||
DatProcessNamePtr=0;
|
||||
if (wCaptureKey(W_SPECIAL_KEY|'b',W_PSION_MODIFIER|W_CTRL_MODIFIER,W_PSION_MODIFIER|W_CTRL_MODIFIER)<0)
|
||||
wInfoMsg("'b' key capture failed");
|
||||
wDisableLeaves(FALSE);
|
||||
err=p_enter1(xMonitorBandWidth);
|
||||
wDisableLeaves(TRUE);
|
||||
p_close(TimCB);
|
||||
wCancelCaptureKey(W_SPECIAL_KEY|'b',W_PSION_MODIFIER|W_CTRL_MODIFIER,W_PSION_MODIFIER|W_CTRL_MODIFIER);
|
||||
if (bwPid>0)
|
||||
p_pkill(bwPid,0);
|
||||
wCloseWindowTree(winId);
|
||||
DisableReads(FALSE);
|
||||
if (spyPid>0)
|
||||
p_setpri(spyPid,oldPri);
|
||||
if (err<0)
|
||||
p_notifyerr(err,"Band width monitor failed",NULL,NULL,NULL);
|
||||
DatProcessNamePtr=name;
|
||||
wDisableLeaves(FALSE);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
tables.pic
|
||||
tables.rsc
|
||||
tables.shd
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
TA1.C
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_sys.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"rReset score",
|
||||
"lLimits",
|
||||
"mMode",
|
||||
"tTiming",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define TABLES_ITEMS 5
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Tables",TABLES_ITEMS,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UWORD TableEnd;
|
||||
UWORD MaxTable;
|
||||
UWORD Tested;
|
||||
UWORD Correct;
|
||||
UWORD Timing;
|
||||
UWORD Mode;
|
||||
} TSTATE;
|
||||
|
||||
LOCAL_D TSTATE state={12,12,0,0,5,1};
|
||||
|
||||
LOCAL_D TEXT *EnvName="TABLES";
|
||||
#define ENV_NAME_LEN 6
|
||||
|
||||
|
||||
LOCAL_C VOID ResetScore(VOID)
|
||||
{
|
||||
if (!state.Tested)
|
||||
{
|
||||
wInfoMsg("No score to reset");
|
||||
return;
|
||||
}
|
||||
if (uOpenDialog("Reset score to zero"))
|
||||
return;
|
||||
if (uAddButtonList("No",-'n',"Yes",'y',NULL))
|
||||
return;
|
||||
if (uRunDialog()=='y')
|
||||
{
|
||||
state.Tested=0;
|
||||
state.Correct=0;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeLimits(VOID)
|
||||
{
|
||||
LONG lTableEnd;
|
||||
LONG lMaxTable;
|
||||
H_DI_NUMBER end;
|
||||
H_DI_NUMBER last;
|
||||
|
||||
lTableEnd=state.TableEnd;
|
||||
lMaxTable=state.MaxTable;
|
||||
if (uOpenDialog("Limits for testing"))
|
||||
return;
|
||||
end.value=(&lTableEnd);
|
||||
end.low=10;
|
||||
end.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Tables end at",&end))
|
||||
return;
|
||||
last.value=(&lMaxTable);
|
||||
last.low=2;
|
||||
last.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Highest table",&last))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.TableEnd=lTableEnd;
|
||||
state.MaxTable=lMaxTable;
|
||||
if (state.Mode>state.MaxTable)
|
||||
state.Mode=state.MaxTable;
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeTiming(VOID)
|
||||
{
|
||||
LONG lTiming;
|
||||
H_DI_NUMBER tim;
|
||||
|
||||
lTiming=state.Timing;
|
||||
if (uOpenDialog("Timing"))
|
||||
return;
|
||||
tim.value=(&lTiming);
|
||||
tim.low=1;
|
||||
tim.high=20;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Number of seconds allowed",&tim))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.Timing=lTiming;
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeMode(VOID)
|
||||
{
|
||||
H_DI_CHOICE ch;
|
||||
INT j;
|
||||
TEXT buf[20];
|
||||
|
||||
if (uOpenDialog("Mode"))
|
||||
return;
|
||||
if (uBeginDCL(&ch))
|
||||
return;
|
||||
if (uGrowDCL(&ch,"All tables"))
|
||||
return;
|
||||
for (j=2; j<=state.MaxTable; j++)
|
||||
{
|
||||
p_atos(&buf[0],"%d times table",j);
|
||||
if (uGrowDCL(&ch,&buf[0]))
|
||||
return;
|
||||
}
|
||||
if (uAddDCL("Test which tables",&state.Mode,&ch))
|
||||
return;
|
||||
uRunDialog();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ExitApplication(VOID)
|
||||
{
|
||||
uErrorValue(p_setenviron(EnvName,ENV_NAME_LEN,&state,sizeof(TSTATE)));
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
ResetScore();
|
||||
break;
|
||||
case 1:
|
||||
ChangeLimits();
|
||||
break;
|
||||
case 2:
|
||||
ChangeMode();
|
||||
break;
|
||||
case 3:
|
||||
ChangeTiming();
|
||||
break;
|
||||
case 4:
|
||||
ExitApplication();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{
|
||||
keycode=uLocateCommand(keycode);
|
||||
if (keycode>=0)
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_EVENT_KEY)
|
||||
{
|
||||
if (key.keycode==CONS_EVENT_COMMAND)
|
||||
ExitApplication();
|
||||
}
|
||||
else if (key.keycode&W_SPECIAL_KEY)
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReadState(VOID)
|
||||
{
|
||||
INT len;
|
||||
UBYTE buf[P_ENVMAX];
|
||||
|
||||
len=p_getenviron(EnvName,ENV_NAME_LEN,&buf[0]);
|
||||
if (len<0 || len!=sizeof(TSTATE))
|
||||
return;
|
||||
p_bcpy(&state,&buf[0],sizeof(TSTATE));
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(uFindMainWid());
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
hCrackCommandLine();
|
||||
MainWid=uFindMainWid();
|
||||
ReduceScreenSize();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
ReadState();
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
tables.pic
|
||||
tables.rsc
|
||||
tables.shd
|
||||
@@ -0,0 +1,340 @@
|
||||
/*
|
||||
TA2.C
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_sys.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"rReset score",
|
||||
"lLimits",
|
||||
"mMode",
|
||||
"tTiming",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define TABLES_ITEMS 5
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Tables",TABLES_ITEMS,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UWORD TableEnd;
|
||||
UWORD MaxTable;
|
||||
UWORD Tested;
|
||||
UWORD Correct;
|
||||
UWORD Timing;
|
||||
UWORD Mode;
|
||||
} TSTATE;
|
||||
|
||||
LOCAL_D TSTATE state={12,12,0,0,5,1};
|
||||
|
||||
LOCAL_D TEXT *EnvName="TABLES";
|
||||
#define ENV_NAME_LEN 6
|
||||
|
||||
|
||||
LOCAL_C VOID DrawLine(INT j,TEXT *pb)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=4;
|
||||
box.br.x=189-4;
|
||||
box.tl.y=4+9*j;
|
||||
box.br.y=box.tl.y+9;
|
||||
gPrintBoxText(&box,8,G_TEXT_ALIGN_CENTRE,0,pb,p_slen(pb));
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayScores(VOID)
|
||||
{
|
||||
TEXT buf[40];
|
||||
|
||||
p_atos(&buf[0],"Score: %u correct out of %u",state.Correct,state.Tested);
|
||||
DrawLine(0,&buf[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayMode(VOID)
|
||||
{
|
||||
TEXT *pb;
|
||||
TEXT buf[40];
|
||||
|
||||
if (state.Mode==1)
|
||||
pb="Testing all tables";
|
||||
else
|
||||
{
|
||||
p_atos(&buf[0],"Testing %d times table",state.Mode);
|
||||
pb=(&buf[0]);
|
||||
}
|
||||
DrawLine(1,pb);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayLimits(VOID)
|
||||
{
|
||||
TEXT buf[40];
|
||||
|
||||
p_atos(&buf[0],"(up to %d times %d)",
|
||||
(state.Mode==1? state.MaxTable: state.Mode),state.TableEnd);
|
||||
DrawLine(2,&buf[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DrawButton(INT state)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=34+36;
|
||||
box.br.x=34+36+38;
|
||||
box.tl.y=47;
|
||||
box.br.y=47+14;
|
||||
wDrawButton(&box,"Enter",state);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayPressButton(VOID)
|
||||
{
|
||||
gPrintText(34,56,"Press",5);
|
||||
DrawButton(FALSE);
|
||||
gPrintText(34+36+38+6,56,"to test",7);
|
||||
}
|
||||
|
||||
LOCAL_C VOID Display(VOID)
|
||||
{
|
||||
DisplayScores();
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
DisplayPressButton();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ResetScore(VOID)
|
||||
{
|
||||
if (!state.Tested)
|
||||
{
|
||||
wInfoMsg("No score to reset");
|
||||
return;
|
||||
}
|
||||
if (uOpenDialog("Reset score to zero"))
|
||||
return;
|
||||
if (uAddButtonList("No",-'n',"Yes",'y',NULL))
|
||||
return;
|
||||
if (uRunDialog()=='y')
|
||||
{
|
||||
state.Tested=0;
|
||||
state.Correct=0;
|
||||
DisplayScores();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeLimits(VOID)
|
||||
{
|
||||
LONG lTableEnd;
|
||||
LONG lMaxTable;
|
||||
H_DI_NUMBER end;
|
||||
H_DI_NUMBER last;
|
||||
|
||||
lTableEnd=state.TableEnd;
|
||||
lMaxTable=state.MaxTable;
|
||||
if (uOpenDialog("Limits for testing"))
|
||||
return;
|
||||
end.value=(&lTableEnd);
|
||||
end.low=10;
|
||||
end.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Tables end at",&end))
|
||||
return;
|
||||
last.value=(&lMaxTable);
|
||||
last.low=2;
|
||||
last.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Highest table",&last))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.TableEnd=lTableEnd;
|
||||
state.MaxTable=lMaxTable;
|
||||
if (state.Mode>state.MaxTable)
|
||||
state.Mode=state.MaxTable;
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeTiming(VOID)
|
||||
{
|
||||
LONG lTiming;
|
||||
H_DI_NUMBER tim;
|
||||
|
||||
lTiming=state.Timing;
|
||||
if (uOpenDialog("Timing"))
|
||||
return;
|
||||
tim.value=(&lTiming);
|
||||
tim.low=1;
|
||||
tim.high=20;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Number of seconds allowed",&tim))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.Timing=lTiming;
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeMode(VOID)
|
||||
{
|
||||
H_DI_CHOICE ch;
|
||||
INT j;
|
||||
TEXT buf[20];
|
||||
|
||||
if (uOpenDialog("Mode"))
|
||||
return;
|
||||
if (uBeginDCL(&ch))
|
||||
return;
|
||||
if (uGrowDCL(&ch,"All tables"))
|
||||
return;
|
||||
for (j=2; j<=state.MaxTable; j++)
|
||||
{
|
||||
p_atos(&buf[0],"%d times table",j);
|
||||
if (uGrowDCL(&ch,&buf[0]))
|
||||
return;
|
||||
}
|
||||
if (uAddDCL("Test which tables",&state.Mode,&ch))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ExitApplication(VOID)
|
||||
{
|
||||
uErrorValue(p_setenviron(EnvName,ENV_NAME_LEN,&state,sizeof(TSTATE)));
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
ResetScore();
|
||||
break;
|
||||
case 1:
|
||||
ChangeLimits();
|
||||
break;
|
||||
case 2:
|
||||
ChangeMode();
|
||||
break;
|
||||
case 3:
|
||||
ChangeTiming();
|
||||
break;
|
||||
case 4:
|
||||
ExitApplication();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{
|
||||
keycode=uLocateCommand(keycode);
|
||||
if (keycode>=0)
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C VOID MakeButtonDance(VOID)
|
||||
{
|
||||
DrawButton(TRUE);
|
||||
wFlush();
|
||||
p_sleep(2);
|
||||
DrawButton(FALSE);
|
||||
wFlush();
|
||||
p_sleep(2);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DoTest(VOID)
|
||||
{
|
||||
MakeButtonDance();
|
||||
state.Tested++;
|
||||
state.Correct++;
|
||||
DisplayScores();
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_EVENT_KEY)
|
||||
{
|
||||
if (key.keycode==CONS_EVENT_COMMAND)
|
||||
ExitApplication();
|
||||
}
|
||||
else if (key.keycode&W_SPECIAL_KEY)
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
else if (key.keycode==W_KEY_RETURN)
|
||||
DoTest();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReadState(VOID)
|
||||
{
|
||||
INT len;
|
||||
UBYTE buf[P_ENVMAX];
|
||||
|
||||
len=p_getenviron(EnvName,ENV_NAME_LEN,&buf[0]);
|
||||
if (len<0 || len!=sizeof(TSTATE))
|
||||
return;
|
||||
p_bcpy(&state,&buf[0],sizeof(TSTATE));
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(uFindMainWid());
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
hCrackCommandLine();
|
||||
MainWid=uFindMainWid();
|
||||
ReduceScreenSize();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
ReadState();
|
||||
Display();
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
tables.pic
|
||||
tables.rsc
|
||||
tables.shd
|
||||
@@ -0,0 +1,517 @@
|
||||
/*
|
||||
TA3.C
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_sys.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
|
||||
GLREF_D UWORD DatLocked;
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"rReset score",
|
||||
"lLimits",
|
||||
"mMode",
|
||||
"tTiming",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define TABLES_ITEMS 5
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Tables",TABLES_ITEMS,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UWORD TableEnd;
|
||||
UWORD MaxTable;
|
||||
UWORD Tested;
|
||||
UWORD Correct;
|
||||
UWORD Timing;
|
||||
UWORD Mode;
|
||||
} TSTATE;
|
||||
|
||||
LOCAL_D TSTATE state={12,12,0,0,5,1};
|
||||
|
||||
LOCAL_D TEXT *EnvName="TABLES";
|
||||
#define ENV_NAME_LEN 6
|
||||
|
||||
LOCAL_D ULONG seed;
|
||||
|
||||
|
||||
LOCAL_C VOID DrawLine(INT j,TEXT *pb)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=4;
|
||||
box.br.x=189-4;
|
||||
box.tl.y=4+9*j;
|
||||
box.br.y=box.tl.y+9;
|
||||
gPrintBoxText(&box,8,G_TEXT_ALIGN_CENTRE,0,pb,p_slen(pb));
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayScores(VOID)
|
||||
{
|
||||
TEXT buf[40];
|
||||
|
||||
p_atos(&buf[0],"Score: %u correct out of %u",state.Correct,state.Tested);
|
||||
DrawLine(0,&buf[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayMode(VOID)
|
||||
{
|
||||
TEXT *pb;
|
||||
TEXT buf[40];
|
||||
|
||||
if (state.Mode==1)
|
||||
pb="Testing all tables";
|
||||
else
|
||||
{
|
||||
p_atos(&buf[0],"Testing %d times table",state.Mode);
|
||||
pb=(&buf[0]);
|
||||
}
|
||||
DrawLine(1,pb);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayLimits(VOID)
|
||||
{
|
||||
TEXT buf[40];
|
||||
|
||||
p_atos(&buf[0],"(up to %d times %d)",
|
||||
(state.Mode==1? state.MaxTable: state.Mode),state.TableEnd);
|
||||
DrawLine(2,&buf[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DrawButton(INT state)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=34+36;
|
||||
box.br.x=34+36+38;
|
||||
box.tl.y=47;
|
||||
box.br.y=47+14;
|
||||
wDrawButton(&box,"Enter",state);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayPressButton(VOID)
|
||||
{
|
||||
gPrintText(34,56,"Press",5);
|
||||
DrawButton(FALSE);
|
||||
gPrintText(34+36+38+6,56,"to test",7);
|
||||
}
|
||||
|
||||
LOCAL_C VOID Display(VOID)
|
||||
{
|
||||
DisplayScores();
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
DisplayPressButton();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ResetScore(VOID)
|
||||
{
|
||||
if (!state.Tested)
|
||||
{
|
||||
wInfoMsg("No score to reset");
|
||||
return;
|
||||
}
|
||||
if (uOpenDialog("Reset score to zero"))
|
||||
return;
|
||||
if (uAddButtonList("No",-'n',"Yes",'y',NULL))
|
||||
return;
|
||||
if (uRunDialog()=='y')
|
||||
{
|
||||
state.Tested=0;
|
||||
state.Correct=0;
|
||||
DisplayScores();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeLimits(VOID)
|
||||
{
|
||||
LONG lTableEnd;
|
||||
LONG lMaxTable;
|
||||
H_DI_NUMBER end;
|
||||
H_DI_NUMBER last;
|
||||
|
||||
lTableEnd=state.TableEnd;
|
||||
lMaxTable=state.MaxTable;
|
||||
if (uOpenDialog("Limits for testing"))
|
||||
return;
|
||||
end.value=(&lTableEnd);
|
||||
end.low=10;
|
||||
end.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Tables end at",&end))
|
||||
return;
|
||||
last.value=(&lMaxTable);
|
||||
last.low=2;
|
||||
last.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Highest table",&last))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.TableEnd=lTableEnd;
|
||||
state.MaxTable=lMaxTable;
|
||||
if (state.Mode>state.MaxTable)
|
||||
state.Mode=state.MaxTable;
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeTiming(VOID)
|
||||
{
|
||||
LONG lTiming;
|
||||
H_DI_NUMBER tim;
|
||||
|
||||
lTiming=state.Timing;
|
||||
if (uOpenDialog("Timing"))
|
||||
return;
|
||||
tim.value=(&lTiming);
|
||||
tim.low=1;
|
||||
tim.high=20;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Number of seconds allowed",&tim))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.Timing=lTiming;
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeMode(VOID)
|
||||
{
|
||||
H_DI_CHOICE ch;
|
||||
INT j;
|
||||
TEXT buf[20];
|
||||
|
||||
if (uOpenDialog("Mode"))
|
||||
return;
|
||||
if (uBeginDCL(&ch))
|
||||
return;
|
||||
if (uGrowDCL(&ch,"All tables"))
|
||||
return;
|
||||
for (j=2; j<=state.MaxTable; j++)
|
||||
{
|
||||
p_atos(&buf[0],"%d times table",j);
|
||||
if (uGrowDCL(&ch,&buf[0]))
|
||||
return;
|
||||
}
|
||||
if (uAddDCL("Test which tables",&state.Mode,&ch))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ExitApplication(VOID)
|
||||
{
|
||||
uErrorValue(p_setenviron(EnvName,ENV_NAME_LEN,&state,sizeof(TSTATE)));
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
ResetScore();
|
||||
break;
|
||||
case 1:
|
||||
ChangeLimits();
|
||||
break;
|
||||
case 2:
|
||||
ChangeMode();
|
||||
break;
|
||||
case 3:
|
||||
ChangeTiming();
|
||||
break;
|
||||
case 4:
|
||||
ExitApplication();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{
|
||||
keycode=uLocateCommand(keycode);
|
||||
if (keycode>=0)
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C INT FindRandom(INT low,INT high)
|
||||
{
|
||||
INT range;
|
||||
|
||||
range=high-low+1;
|
||||
return(low+(INT)(p_randl(&seed)%range));
|
||||
}
|
||||
|
||||
LOCAL_C VOID FindFactors(WORD *pa,WORD *pb)
|
||||
{
|
||||
*pa=(state.Mode==1? FindRandom(2,state.MaxTable): state.Mode);
|
||||
*pb=FindRandom(2,state.TableEnd);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SwitchStyle(INT style)
|
||||
{
|
||||
G_GC gc;
|
||||
|
||||
gc.style=style;
|
||||
gSetGC(0,G_GC_MASK_STYLE,&gc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID *CreateEditor(VOID)
|
||||
{
|
||||
H_EDIT_BOX heb;
|
||||
|
||||
heb.maxchars=4;
|
||||
heb.vulen=30;
|
||||
heb.pos.x=113;
|
||||
heb.pos.y=45;
|
||||
heb.win=MainWid;
|
||||
heb.font=WS_FONT_BASE;
|
||||
heb.style=G_STY_DOUBLE;
|
||||
return(hEBOpen(H_EDIT_BOX_FONT,&heb));
|
||||
}
|
||||
|
||||
LOCAL_C VOID ClearBottomArea(VOID)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=4;
|
||||
box.br.x=189-4;
|
||||
box.tl.y=4+3*9;
|
||||
box.br.y=80-4;
|
||||
gClrRect(&box,G_TRMODE_CLR);
|
||||
}
|
||||
|
||||
LOCAL_C VOID Beep(VOID)
|
||||
{
|
||||
p_sound(-5,320);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SelectAll(VOID *ebH)
|
||||
{
|
||||
hEBSetSelect(ebH,0,p_slen(hEBSenseText(ebH)));
|
||||
}
|
||||
|
||||
LOCAL_C INT SenseNumberTyped(VOID *ebH)
|
||||
{
|
||||
TEXT *pb;
|
||||
WORD num;
|
||||
|
||||
pb=hEBSenseText(ebH);
|
||||
p_stoi(&pb,&num);
|
||||
return(num);
|
||||
}
|
||||
|
||||
LOCAL_C INT AddTextItem(TEXT *pmt,TEXT *pbod)
|
||||
{
|
||||
H_DI_TEXT txt;
|
||||
TEXT buf[20];
|
||||
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE;
|
||||
uZTStoBCS(txt.str=(&buf[0]),pbod);
|
||||
return(uAddDialogItem(H_DIALOG_TEXT,pmt,&txt));
|
||||
}
|
||||
|
||||
LOCAL_C INT Complain(INT a,INT b,INT c)
|
||||
{
|
||||
TEXT buf[20];
|
||||
|
||||
if (uOpenDialog("Incorrect"))
|
||||
return(-1);
|
||||
p_atos(&buf[0],"%d \236 %d",a,b);
|
||||
if (AddTextItem("The question",&buf[0]))
|
||||
return(-1);
|
||||
buf[p_itob(&buf[0],c)]=0;
|
||||
if (AddTextItem("Your answer",&buf[0]))
|
||||
return(-1);
|
||||
if (uAddButtonList("Help",W_KEY_ESCAPE,"Retry",W_KEY_RETURN,NULL))
|
||||
return(-1);
|
||||
if (uRunDialog()==W_KEY_RETURN)
|
||||
return(0);
|
||||
p_atos(&buf[0],"%d \236 %d = %d",a,b,a*b);
|
||||
if (uOpenDialog(&buf[0]))
|
||||
return(-1);
|
||||
if (uAddButtonList("Continue",W_KEY_RETURN,NULL))
|
||||
return(-1);
|
||||
uRunDialog();
|
||||
return(-1);
|
||||
}
|
||||
|
||||
LOCAL_C INT BadKey(INT k)
|
||||
{
|
||||
return(k<256 && p_isprint(k) && !p_isdigit(k));
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayQuestion(VOID)
|
||||
{
|
||||
TEXT buf[30];
|
||||
WMSG_KEY key;
|
||||
P_RECT box;
|
||||
VOID *ebH;
|
||||
WORD a;
|
||||
WORD b;
|
||||
WORD c;
|
||||
WORD ans;
|
||||
|
||||
ebH=CreateEditor();
|
||||
if (!ebH)
|
||||
return;
|
||||
ClearBottomArea();
|
||||
hEBEmphasise(ebH,TRUE);
|
||||
FindFactors(&a,&b);
|
||||
ans=a*b;
|
||||
p_atos(&buf[0],"%d \236 %d = ",a,b);
|
||||
box.tl.x=53;
|
||||
box.br.x=113;
|
||||
box.tl.y=45;
|
||||
box.br.y=45+17;
|
||||
SwitchStyle(G_STY_DOUBLE);
|
||||
gPrintBoxText(&box,15,G_TEXT_ALIGN_RIGHT,0,&buf[0],p_slen(&buf[0]));
|
||||
SwitchStyle(G_STY_NORMAL);
|
||||
DatLocked=TRUE;
|
||||
state.Tested++;
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (BadKey(key.keycode))
|
||||
Beep();
|
||||
else if (key.keycode!=W_KEY_RETURN)
|
||||
hEBHandleKey(ebH,key.keycode,key.modifiers);
|
||||
else
|
||||
{
|
||||
c=SenseNumberTyped(ebH);
|
||||
if (c==ans)
|
||||
{
|
||||
state.Correct++;
|
||||
break;
|
||||
}
|
||||
Beep();
|
||||
hEBEmphasise(ebH,FALSE);
|
||||
if (Complain(a,b,c))
|
||||
break;
|
||||
DisplayScores();
|
||||
state.Tested++;
|
||||
hEBEmphasise(ebH,TRUE);
|
||||
SelectAll(ebH);
|
||||
}
|
||||
}
|
||||
DatLocked=FALSE;
|
||||
hEBClose(ebH);
|
||||
ClearBottomArea();
|
||||
DisplayPressButton();
|
||||
}
|
||||
|
||||
LOCAL_C VOID MakeButtonDance(VOID)
|
||||
{
|
||||
DrawButton(TRUE);
|
||||
wFlush();
|
||||
p_sleep(2);
|
||||
DrawButton(FALSE);
|
||||
wFlush();
|
||||
p_sleep(2);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DoTest(VOID)
|
||||
{
|
||||
MakeButtonDance();
|
||||
DisplayQuestion();
|
||||
DisplayScores();
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_EVENT_KEY)
|
||||
{
|
||||
if (key.keycode==CONS_EVENT_COMMAND)
|
||||
ExitApplication();
|
||||
}
|
||||
else if (key.keycode&W_SPECIAL_KEY)
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
else if (key.keycode==W_KEY_RETURN)
|
||||
DoTest();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReadState(VOID)
|
||||
{
|
||||
INT len;
|
||||
UBYTE buf[P_ENVMAX];
|
||||
|
||||
len=p_getenviron(EnvName,ENV_NAME_LEN,&buf[0]);
|
||||
if (len<0 || len!=sizeof(TSTATE))
|
||||
return;
|
||||
p_bcpy(&state,&buf[0],sizeof(TSTATE));
|
||||
}
|
||||
|
||||
LOCAL_C VOID InitSeed(VOID)
|
||||
{
|
||||
seed=p_date();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(uFindMainWid());
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
uEscape(FALSE);
|
||||
hCrackCommandLine();
|
||||
MainWid=uFindMainWid();
|
||||
ReduceScreenSize();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
ReadState();
|
||||
Display();
|
||||
InitSeed();
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
tables.pic
|
||||
tables.rsc
|
||||
tables.shd
|
||||
@@ -0,0 +1,626 @@
|
||||
/*
|
||||
|
||||
TABLES.C
|
||||
|
||||
Written by DavidW
|
||||
Started on 21/1/92
|
||||
|
||||
*/
|
||||
|
||||
#include <p_std.h>
|
||||
#include <p_sys.h>
|
||||
#include <p_file.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
|
||||
GLREF_D UWORD DatLocked;
|
||||
|
||||
LOCAL_D TEXT *cmds[]=
|
||||
{
|
||||
"rReset score",
|
||||
"lLimits",
|
||||
"mMode",
|
||||
"tTiming",
|
||||
"xExit",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define TABLES_ITEMS 5
|
||||
|
||||
LOCAL_D H_MENU_DATA mdata[]=
|
||||
{
|
||||
"Tables",TABLES_ITEMS,
|
||||
NULL
|
||||
};
|
||||
|
||||
GLDEF_D TEXT ** _cmds=(&cmds[0]);
|
||||
GLDEF_D H_MENU_DATA * _mdata=(&mdata[0]);
|
||||
|
||||
|
||||
LOCAL_D UINT MainWid;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UWORD TableEnd;
|
||||
UWORD MaxTable;
|
||||
UWORD Tested;
|
||||
UWORD Correct;
|
||||
UWORD Timing;
|
||||
UWORD Mode;
|
||||
} TSTATE;
|
||||
|
||||
LOCAL_D TSTATE state={12,12,0,0,5,1};
|
||||
|
||||
LOCAL_D TEXT *EnvName="TABLES";
|
||||
#define ENV_NAME_LEN 6
|
||||
|
||||
LOCAL_D ULONG seed;
|
||||
|
||||
LOCAL_D VOID *timH;
|
||||
LOCAL_D WORD timactive;
|
||||
LOCAL_D WORD timstat;
|
||||
LOCAL_D ULONG timint;
|
||||
LOCAL_D WORD timcount;
|
||||
LOCAL_D WORD timtotcnt;
|
||||
|
||||
|
||||
LOCAL_C VOID DrawLine(INT j,TEXT *pb)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=4;
|
||||
box.br.x=189-4;
|
||||
box.tl.y=4+9*j;
|
||||
box.br.y=box.tl.y+9;
|
||||
gPrintBoxText(&box,8,G_TEXT_ALIGN_CENTRE,0,pb,p_slen(pb));
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayScores(VOID)
|
||||
{
|
||||
TEXT buf[40];
|
||||
|
||||
p_atos(&buf[0],"Score: %u correct out of %u",state.Correct,state.Tested);
|
||||
DrawLine(0,&buf[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayMode(VOID)
|
||||
{
|
||||
TEXT *pb;
|
||||
TEXT buf[40];
|
||||
|
||||
if (state.Mode==1)
|
||||
pb="Testing all tables";
|
||||
else
|
||||
{
|
||||
p_atos(&buf[0],"Testing %d times table",state.Mode);
|
||||
pb=(&buf[0]);
|
||||
}
|
||||
DrawLine(1,pb);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayLimits(VOID)
|
||||
{
|
||||
TEXT buf[40];
|
||||
|
||||
p_atos(&buf[0],"(up to %d times %d)",
|
||||
(state.Mode==1? state.MaxTable: state.Mode),state.TableEnd);
|
||||
DrawLine(2,&buf[0]);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DrawButton(INT state)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=34+36;
|
||||
box.br.x=34+36+38;
|
||||
box.tl.y=47;
|
||||
box.br.y=47+14;
|
||||
wDrawButton(&box,"Enter",state);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayPressButton(VOID)
|
||||
{
|
||||
gPrintText(34,56,"Press",5);
|
||||
DrawButton(FALSE);
|
||||
gPrintText(34+36+38+6,56,"to test",7);
|
||||
}
|
||||
|
||||
LOCAL_C VOID Display(VOID)
|
||||
{
|
||||
DisplayScores();
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
DisplayPressButton();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ResetScore(VOID)
|
||||
{
|
||||
if (!state.Tested)
|
||||
{
|
||||
wInfoMsg("No score to reset");
|
||||
return;
|
||||
}
|
||||
if (uOpenDialog("Reset score to zero"))
|
||||
return;
|
||||
if (uAddButtonList("No",-'n',"Yes",'y',NULL))
|
||||
return;
|
||||
if (uRunDialog()=='y')
|
||||
{
|
||||
state.Tested=0;
|
||||
state.Correct=0;
|
||||
DisplayScores();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeLimits(VOID)
|
||||
{
|
||||
LONG lTableEnd;
|
||||
LONG lMaxTable;
|
||||
H_DI_NUMBER end;
|
||||
H_DI_NUMBER last;
|
||||
|
||||
lTableEnd=state.TableEnd;
|
||||
lMaxTable=state.MaxTable;
|
||||
if (uOpenDialog("Limits for testing"))
|
||||
return;
|
||||
end.value=(&lTableEnd);
|
||||
end.low=10;
|
||||
end.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Tables end at",&end))
|
||||
return;
|
||||
last.value=(&lMaxTable);
|
||||
last.low=2;
|
||||
last.high=99;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Highest table",&last))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.TableEnd=lTableEnd;
|
||||
state.MaxTable=lMaxTable;
|
||||
if (state.Mode>state.MaxTable)
|
||||
state.Mode=state.MaxTable;
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeTiming(VOID)
|
||||
{
|
||||
LONG lTiming;
|
||||
H_DI_NUMBER tim;
|
||||
|
||||
lTiming=state.Timing;
|
||||
if (uOpenDialog("Timing"))
|
||||
return;
|
||||
tim.value=(&lTiming);
|
||||
tim.low=1;
|
||||
tim.high=20;
|
||||
if (uAddDialogItem(H_DIALOG_NUMBER,"Number of seconds allowed",&tim))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
state.Timing=lTiming;
|
||||
}
|
||||
|
||||
LOCAL_C VOID ChangeMode(VOID)
|
||||
{
|
||||
H_DI_CHOICE ch;
|
||||
INT j;
|
||||
TEXT buf[20];
|
||||
|
||||
if (uOpenDialog("Mode"))
|
||||
return;
|
||||
if (uBeginDCL(&ch))
|
||||
return;
|
||||
if (uGrowDCL(&ch,"All tables"))
|
||||
return;
|
||||
for (j=2; j<=state.MaxTable; j++)
|
||||
{
|
||||
p_atos(&buf[0],"%d times table",j);
|
||||
if (uGrowDCL(&ch,&buf[0]))
|
||||
return;
|
||||
}
|
||||
if (uAddDCL("Test which tables",&state.Mode,&ch))
|
||||
return;
|
||||
if (uRunDialog()<=0)
|
||||
return;
|
||||
DisplayMode();
|
||||
DisplayLimits();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ExitApplication(VOID)
|
||||
{
|
||||
uErrorValue(p_setenviron(EnvName,ENV_NAME_LEN,&state,sizeof(TSTATE)));
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ManageCommand(INT index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
ResetScore();
|
||||
break;
|
||||
case 1:
|
||||
ChangeLimits();
|
||||
break;
|
||||
case 2:
|
||||
ChangeMode();
|
||||
break;
|
||||
case 3:
|
||||
ChangeTiming();
|
||||
break;
|
||||
case 4:
|
||||
ExitApplication();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID TryExecuteCommand(INT keycode)
|
||||
{
|
||||
keycode=uLocateCommand(keycode);
|
||||
if (keycode>=0)
|
||||
ManageCommand(keycode);
|
||||
}
|
||||
|
||||
LOCAL_C INT FindRandom(INT low,INT high)
|
||||
{
|
||||
INT range;
|
||||
|
||||
range=high-low+1;
|
||||
return(low+(INT)(p_randl(&seed)%range));
|
||||
}
|
||||
|
||||
LOCAL_C VOID FindFactors(WORD *pa,WORD *pb)
|
||||
{
|
||||
*pa=(state.Mode==1? FindRandom(2,state.MaxTable): state.Mode);
|
||||
*pb=FindRandom(2,state.TableEnd);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SwitchStyle(INT style)
|
||||
{
|
||||
G_GC gc;
|
||||
|
||||
gc.style=style;
|
||||
gSetGC(0,G_GC_MASK_STYLE,&gc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID *CreateEditor(VOID)
|
||||
{
|
||||
H_EDIT_BOX heb;
|
||||
|
||||
heb.maxchars=4;
|
||||
heb.vulen=30;
|
||||
heb.pos.x=113;
|
||||
heb.pos.y=38;
|
||||
heb.win=MainWid;
|
||||
heb.font=WS_FONT_BASE;
|
||||
heb.style=G_STY_DOUBLE;
|
||||
return(hEBOpen(H_EDIT_BOX_FONT,&heb));
|
||||
}
|
||||
|
||||
LOCAL_C VOID ClearBottomArea(VOID)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
box.tl.x=4;
|
||||
box.br.x=189-4;
|
||||
box.tl.y=4+3*9;
|
||||
box.br.y=80-4;
|
||||
gClrRect(&box,G_TRMODE_CLR);
|
||||
}
|
||||
|
||||
LOCAL_C VOID Beep(VOID)
|
||||
{
|
||||
p_sound(-5,320);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SelectAll(VOID *ebH)
|
||||
{
|
||||
hEBSetSelect(ebH,0,p_slen(hEBSenseText(ebH)));
|
||||
}
|
||||
|
||||
LOCAL_C INT SenseNumberTyped(VOID *ebH)
|
||||
{
|
||||
TEXT *pb;
|
||||
WORD num;
|
||||
|
||||
pb=hEBSenseText(ebH);
|
||||
if (!*pb)
|
||||
return(0);
|
||||
p_stoi(&pb,&num);
|
||||
return(num);
|
||||
}
|
||||
|
||||
LOCAL_C INT AddTextItem(TEXT *pmt,TEXT *pbod)
|
||||
{
|
||||
H_DI_TEXT txt;
|
||||
TEXT buf[20];
|
||||
|
||||
txt.type=H_DTEXT_ALIGN_CENTRE;
|
||||
uZTStoBCS(txt.str=(&buf[0]),pbod);
|
||||
return(uAddDialogItem(H_DIALOG_TEXT,pmt,&txt));
|
||||
}
|
||||
|
||||
LOCAL_C INT Complain(INT a,INT b,INT c)
|
||||
{
|
||||
TEXT buf[20];
|
||||
|
||||
if (uOpenDialog("Incorrect"))
|
||||
return(-1);
|
||||
p_atos(&buf[0],"%d \236 %d",a,b);
|
||||
if (AddTextItem("The question",&buf[0]))
|
||||
return(-1);
|
||||
buf[p_itob(&buf[0],c)]=0;
|
||||
if (AddTextItem("Your answer",&buf[0]))
|
||||
return(-1);
|
||||
if (uAddButtonList("Help",W_KEY_ESCAPE,"Retry",W_KEY_RETURN,NULL))
|
||||
return(-1);
|
||||
if (uRunDialog()==W_KEY_RETURN)
|
||||
return(0);
|
||||
p_atos(&buf[0],"%d \236 %d = %d",a,b,a*b);
|
||||
if (uOpenDialog(&buf[0]))
|
||||
return(-1);
|
||||
if (uAddButtonList("Continue",W_KEY_RETURN,NULL))
|
||||
return(-1);
|
||||
uRunDialog();
|
||||
return(-1);
|
||||
}
|
||||
|
||||
LOCAL_C INT BadKey(INT k)
|
||||
{
|
||||
return(k<256 && p_isprint(k) && !p_isdigit(k));
|
||||
}
|
||||
|
||||
LOCAL_C VOID CancelTimer(VOID)
|
||||
{
|
||||
if (timactive)
|
||||
{
|
||||
p_iow2(timH,P_FCANCEL);
|
||||
p_waitstat(&timstat);
|
||||
}
|
||||
timactive=FALSE;
|
||||
}
|
||||
|
||||
LOCAL_C VOID QueueTimer(VOID)
|
||||
{
|
||||
CancelTimer();
|
||||
p_ioa4(timH,P_FRELATIVE,&timstat,&timint);
|
||||
timactive=TRUE;
|
||||
}
|
||||
|
||||
LOCAL_C VOID InitialiseTimer(VOID)
|
||||
{
|
||||
if (state.Timing<=4)
|
||||
{
|
||||
timint=5;
|
||||
timcount=2*state.Timing;
|
||||
}
|
||||
else
|
||||
{
|
||||
timint=10;
|
||||
timcount=state.Timing;
|
||||
}
|
||||
timtotcnt=timcount;
|
||||
QueueTimer();
|
||||
}
|
||||
|
||||
LOCAL_C VOID GetBarChartRect(P_RECT *pbox)
|
||||
{
|
||||
pbox->tl.x=9;
|
||||
pbox->br.x=180;
|
||||
pbox->tl.y=62;
|
||||
pbox->br.y=68;
|
||||
}
|
||||
|
||||
LOCAL_C VOID IncrementBarChart(VOID)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
timcount--;
|
||||
GetBarChartRect(&box);
|
||||
box.br.x=9+171*(timtotcnt-timcount)/timtotcnt;
|
||||
gFillPattern(&box,WS_BITMAP_GREY,G_TRMODE_REPL);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ClearBarChart(VOID)
|
||||
{
|
||||
P_RECT box;
|
||||
|
||||
GetBarChartRect(&box);
|
||||
gClrRect(&box,G_TRMODE_CLR);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DisplayQuestion(VOID)
|
||||
{
|
||||
TEXT buf[30];
|
||||
WMSG_KEY key;
|
||||
WORD keyactive;
|
||||
WORD keystat;
|
||||
P_RECT box;
|
||||
VOID *ebH;
|
||||
WORD a;
|
||||
WORD b;
|
||||
WORD c;
|
||||
WORD ans;
|
||||
|
||||
ebH=CreateEditor();
|
||||
if (!ebH)
|
||||
return;
|
||||
ClearBottomArea();
|
||||
hEBEmphasise(ebH,TRUE);
|
||||
FindFactors(&a,&b);
|
||||
ans=a*b;
|
||||
p_atos(&buf[0],"%d \236 %d = ",a,b);
|
||||
box.tl.x=53;
|
||||
box.br.x=113;
|
||||
box.tl.y=38;
|
||||
box.br.y=38+17;
|
||||
SwitchStyle(G_STY_DOUBLE);
|
||||
gPrintBoxText(&box,15,G_TEXT_ALIGN_RIGHT,0,&buf[0],p_slen(&buf[0]));
|
||||
SwitchStyle(G_STY_NORMAL);
|
||||
box.tl.x=8;
|
||||
box.br.x=189-8;
|
||||
box.tl.y=61;
|
||||
box.br.y=61+8;
|
||||
gBorderRect(&box,W_BORD_CORNER_1);
|
||||
DatLocked=TRUE;
|
||||
state.Tested++;
|
||||
keyactive=FALSE;
|
||||
InitialiseTimer();
|
||||
FOREVER
|
||||
{
|
||||
if (keyactive)
|
||||
wFlush();
|
||||
else
|
||||
{
|
||||
uGetKeyA(&keystat,&key);
|
||||
keyactive=TRUE;
|
||||
}
|
||||
p_iowait();
|
||||
if (keystat==E_FILE_PENDING)
|
||||
{
|
||||
timactive=FALSE;
|
||||
IncrementBarChart();
|
||||
if (!timcount)
|
||||
{
|
||||
wFlush();
|
||||
p_sleep(2);
|
||||
goto CheckAnswer;
|
||||
}
|
||||
QueueTimer();
|
||||
continue;
|
||||
}
|
||||
keyactive=FALSE;
|
||||
if (BadKey(key.keycode))
|
||||
Beep();
|
||||
else if (key.keycode!=W_KEY_RETURN)
|
||||
hEBHandleKey(ebH,key.keycode,key.modifiers);
|
||||
else
|
||||
{
|
||||
CheckAnswer:
|
||||
c=SenseNumberTyped(ebH);
|
||||
if (c==ans)
|
||||
{
|
||||
state.Correct++;
|
||||
break;
|
||||
}
|
||||
Beep();
|
||||
hEBEmphasise(ebH,FALSE);
|
||||
if (Complain(a,b,c))
|
||||
break;
|
||||
DisplayScores();
|
||||
state.Tested++;
|
||||
hEBEmphasise(ebH,TRUE);
|
||||
SelectAll(ebH);
|
||||
ClearBarChart();
|
||||
InitialiseTimer();
|
||||
}
|
||||
}
|
||||
DatLocked=FALSE;
|
||||
hEBClose(ebH);
|
||||
ClearBottomArea();
|
||||
DisplayPressButton();
|
||||
CancelTimer();
|
||||
}
|
||||
|
||||
LOCAL_C VOID MakeButtonDance(VOID)
|
||||
{
|
||||
DrawButton(TRUE);
|
||||
wFlush();
|
||||
p_sleep(2);
|
||||
DrawButton(FALSE);
|
||||
wFlush();
|
||||
p_sleep(2);
|
||||
}
|
||||
|
||||
LOCAL_C VOID DoTest(VOID)
|
||||
{
|
||||
MakeButtonDance();
|
||||
DisplayQuestion();
|
||||
DisplayScores();
|
||||
}
|
||||
|
||||
LOCAL_C VOID MainLoop(VOID)
|
||||
{
|
||||
INT ret;
|
||||
WMSG_KEY key;
|
||||
|
||||
FOREVER
|
||||
{
|
||||
uGetKey(&key);
|
||||
if (key.keycode&W_EVENT_KEY)
|
||||
{
|
||||
if (key.keycode==CONS_EVENT_COMMAND)
|
||||
ExitApplication();
|
||||
}
|
||||
else if (key.keycode&W_SPECIAL_KEY)
|
||||
TryExecuteCommand(key.keycode&(~W_SPECIAL_KEY));
|
||||
else if (key.keycode==W_KEY_MENU && !(key.modifiers&W_CTRL_MODIFIER))
|
||||
{
|
||||
ret=uPresentMenus();
|
||||
if (ret>0)
|
||||
TryExecuteCommand(ret);
|
||||
}
|
||||
else if (key.keycode==W_KEY_RETURN)
|
||||
DoTest();
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReadState(VOID)
|
||||
{
|
||||
INT len;
|
||||
UBYTE buf[P_ENVMAX];
|
||||
|
||||
len=p_getenviron(EnvName,ENV_NAME_LEN,&buf[0]);
|
||||
if (len<0 || len!=sizeof(TSTATE))
|
||||
return;
|
||||
p_bcpy(&state,&buf[0],sizeof(TSTATE));
|
||||
}
|
||||
|
||||
LOCAL_C VOID InitSeed(VOID)
|
||||
{
|
||||
seed=p_date();
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReduceScreenSize(VOID)
|
||||
{
|
||||
W_WINDATA wd;
|
||||
|
||||
wd.extent.tl.x=wd.extent.tl.y=0;
|
||||
wd.extent.width=189;
|
||||
wd.extent.height=80;
|
||||
wSetWindow(MainWid,W_WIN_EXTENT,&wd);
|
||||
if (uErrorValue(wCheckPoint()))
|
||||
p_exit(0);
|
||||
}
|
||||
|
||||
LOCAL_C VOID CreateGC(VOID)
|
||||
{
|
||||
INT hgc;
|
||||
|
||||
hgc=gCreateGC0(uFindMainWid());
|
||||
if (hgc<0)
|
||||
p_exit(hgc);
|
||||
}
|
||||
|
||||
LOCAL_C VOID SpecificInit(VOID)
|
||||
{
|
||||
uEscape(FALSE);
|
||||
hCrackCommandLine();
|
||||
MainWid=uFindMainWid();
|
||||
ReduceScreenSize();
|
||||
CreateGC();
|
||||
gBorder(W_BORD_CORNER_4);
|
||||
wsEnable();
|
||||
ReadState();
|
||||
Display();
|
||||
InitSeed();
|
||||
p_open(&timH,"TIM:",-1);
|
||||
}
|
||||
|
||||
GLDEF_C VOID main(VOID)
|
||||
{
|
||||
uCommonInit();
|
||||
SpecificInit();
|
||||
MainLoop();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Tables
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
tele.pic
|
||||
tele.rsc
|
||||
tele.shd
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
Tele.TEL
|
||||
\TEL\
|
||||
3
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
#system epoc img
|
||||
#set epocinit=iplib
|
||||
#model small jpi
|
||||
#compile %main
|
||||
#pragma link(hwif.lib)
|
||||
#link %main
|
||||
@@ -0,0 +1,22 @@
|
||||
@echo off
|
||||
goto X%1X
|
||||
:Xv0X
|
||||
:XoffX
|
||||
set jpivid=v0
|
||||
echo VID is now OFF
|
||||
goto :end
|
||||
:Xv2X
|
||||
:XonX
|
||||
set jpivid=v2
|
||||
echo VID is now ON
|
||||
goto :end
|
||||
:XX
|
||||
call checkvid
|
||||
goto %jpivid%
|
||||
:v0
|
||||
echo VID is OFF
|
||||
goto end
|
||||
:v2
|
||||
echo VID is ON
|
||||
:end
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
/* Module WSREPORT.C
|
||||
Written by Steve Mar 1992
|
||||
|
||||
Write a log of one or all the applications window server resources.
|
||||
*/
|
||||
#include <plib.h>
|
||||
#include <wlib.h>
|
||||
#include <hwif.h>
|
||||
|
||||
GLREF_D VOID *DatApp1;
|
||||
GLREF_D WSERV_SPEC *wserv_channel;
|
||||
|
||||
#define MAX_OBJ 256
|
||||
#define G_SEG_SEL_MAX_ROM 63
|
||||
|
||||
typedef struct
|
||||
{
|
||||
G_FONT_INFO info;
|
||||
UBYTE *addr;
|
||||
P_RECT area;
|
||||
UWORD bytewid;
|
||||
UWORD segment;
|
||||
UWORD work_spc_size;
|
||||
UWORD work_spc_wid;
|
||||
UBYTE *width_table;
|
||||
} G_FONT;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UWORD seg;
|
||||
UBYTE *addr;
|
||||
UWORD bytewid;
|
||||
} BM_DATA;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UBYTE flags;
|
||||
UBYTE filler;
|
||||
BM_DATA bm_data;
|
||||
VOID *region;
|
||||
P_POINT size;
|
||||
TEXT name[14];
|
||||
} BITMAP;
|
||||
|
||||
typedef union
|
||||
{
|
||||
G_FONT *font;
|
||||
BITMAP *bit;
|
||||
} IFOB;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UBYTE type;
|
||||
UBYTE usage;
|
||||
IFOB addr;
|
||||
UINT self_index;
|
||||
} SHARED_HEADER;
|
||||
|
||||
typedef struct s_shared_data /* Bitmap and font header structure */
|
||||
{
|
||||
SHARED_HEADER head;
|
||||
UWORD checksum;
|
||||
struct s_shared_data *next;
|
||||
struct s_shared_data **prev;
|
||||
} S_SHARED_DATA;
|
||||
|
||||
typedef struct s_window
|
||||
{
|
||||
UBYTE type;
|
||||
UBYTE status;
|
||||
UWORD flags;
|
||||
P_POINT origin;
|
||||
P_RECT abs;
|
||||
P_RECT rel;
|
||||
struct s_window *parent;
|
||||
struct s_window *child;
|
||||
struct s_window *sibling;
|
||||
VOID *region;
|
||||
VOID *area;
|
||||
UWORD self_index;
|
||||
} S_WINDOW;
|
||||
|
||||
typedef struct s_gcb
|
||||
{
|
||||
UBYTE type;
|
||||
UBYTE style;
|
||||
BM_DATA bm_data;
|
||||
UBYTE gmode;
|
||||
UBYTE textmode;
|
||||
P_POINT origin;
|
||||
VOID *region;
|
||||
UWORD draws_to;
|
||||
G_FONT *font;
|
||||
BM_DATA extra_bm_data;
|
||||
P_RECT extra_rect;
|
||||
} S_GCB;
|
||||
|
||||
typedef union
|
||||
{
|
||||
S_WINDOW win;
|
||||
S_GCB gcb;
|
||||
S_SHARED_DATA shared;
|
||||
} OBJECT;
|
||||
|
||||
#define MAX_DEV_EVENTS 8
|
||||
#define DEQ_ENTRY_SIZE 16
|
||||
typedef struct
|
||||
{
|
||||
UWORD ready;
|
||||
UBYTE front;
|
||||
UBYTE n_entries;
|
||||
UBYTE buffer[DEQ_ENTRY_SIZE][MAX_DEV_EVENTS];
|
||||
} S_DEQ;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UBYTE *read_addr;
|
||||
UWORD flags;
|
||||
UBYTE *gcb;
|
||||
UWORD os_id;
|
||||
UBYTE SelfIndex;
|
||||
BYTE error;
|
||||
VOID *clock;
|
||||
S_WINDOW *capture;
|
||||
VOID *redrawq;
|
||||
VOID *invalid_area;
|
||||
S_WINDOW *redraw_win;
|
||||
VOID *redraw_region;
|
||||
S_WINDOW *cursor_win;
|
||||
W_CURSOR cursor;
|
||||
UWORD root_handle;
|
||||
S_GCB *tempgcb;
|
||||
S_WINDOW *front_window;
|
||||
VOID *alert;
|
||||
TEXT busy_txt[W_BUSY_MSG_MAX_LEN+1];
|
||||
UBYTE busy_corner;
|
||||
VOID *bit_list;
|
||||
S_GCB *static_gcb;
|
||||
UBYTE *ipcbuf;
|
||||
WORD death_stat;
|
||||
UBYTE *cmd_buf;
|
||||
UWORD open_mode;
|
||||
ULONG open_addr;
|
||||
S_DEQ deq;
|
||||
UINT status[2];
|
||||
UWORD tab_size;
|
||||
OBJECT *obj_tab[MAX_OBJ];
|
||||
} WS_CCB;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WORD WservStaticInitGcb;
|
||||
WORD WservStaticFontTable;
|
||||
WORD WservStaticClients[WS_MAX_CLIENTS];
|
||||
WORD WservStaticRomSegments[G_SEG_SEL_MAX_ROM];
|
||||
WORD WservStaticFontTabSize;
|
||||
WORD WservStaticBitmapTab;
|
||||
WORD WservStaticBitmapTabSize;
|
||||
WORD WservStaticIconTab;
|
||||
WORD WservStaticIconTabSize;
|
||||
} WSERV_STATICS;
|
||||
|
||||
GLREF_D P_DEVICE p_file;
|
||||
LOCAL_D VOID *FileCB=NULL;
|
||||
LOCAL_D WSERV_STATICS *wsDatApp;
|
||||
LOCAL_D WS_CCB *ClientCCBs[WS_MAX_CLIENTS];
|
||||
LOCAL_D WS_CCB ccb;
|
||||
|
||||
LOCAL_C VOID wsRead(VOID *to,VOID *from,UINT len)
|
||||
{
|
||||
p_pcpyfr(wserv_channel->link.local.wserv_pid,from,to,len);
|
||||
}
|
||||
|
||||
LOCAL_C VOID fWrite(TEXT *str,...)
|
||||
{
|
||||
INT len;
|
||||
TEXT buf[128];
|
||||
|
||||
len=p_atob(&buf[0],str,&str+1);
|
||||
f_write(FileCB,&buf[0],len);
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReportWindow(S_WINDOW *pWin,UINT inset)
|
||||
{
|
||||
S_WINDOW *pNext,win;
|
||||
static TEXT *back[4]={"None","Clr","Set","Bit"};
|
||||
|
||||
for(pNext=pWin;pNext;)
|
||||
{
|
||||
wsRead(&win,pNext,sizeof(S_WINDOW));
|
||||
if (win.self_index>ccb.tab_size ||
|
||||
&ccb.obj_tab[win.self_index]->win!=pNext)
|
||||
break;
|
||||
fWrite("%- *fWindow(%d) %s%sisible %s,{{%d,%d},%d,%d}",inset,
|
||||
win.self_index,
|
||||
win.status&W_UNINITIALISED?"Uninitialised ":"",
|
||||
win.status&W_SET_INVISIBLE?"Inv":"V",
|
||||
back[win.status&3],
|
||||
win.rel.tl.x,win.rel.tl.y,
|
||||
win.rel.br.x-win.rel.tl.x,
|
||||
win.rel.br.y-win.rel.tl.y);
|
||||
ReportWindow(win.child,inset+1);
|
||||
pNext=win.sibling;
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL_C VOID ReportClient(VOID *client)
|
||||
{
|
||||
UINT j;
|
||||
OBJECT object;
|
||||
BITMAP bitmap;
|
||||
G_FONT font;
|
||||
TEXT name[34];
|
||||
|
||||
wsRead(&ccb,client,sizeof(ccb));
|
||||
f_leave(p_pname(ccb.os_id,&name[0]));
|
||||
fWrite(&name[0]);
|
||||
fWrite("--------------");
|
||||
fWrite("Client slot %d",ccb.SelfIndex);
|
||||
fWrite(ccb.read_addr?"Read outstanding":"No read outstanding");
|
||||
fWrite("Flags 0x%x",ccb.flags);
|
||||
if (ccb.error)
|
||||
fWrite("Pending error %d",ccb.error);
|
||||
fWrite(ccb.redrawq ? "Redraws-pending":"No Redraws-pending");
|
||||
fWrite("PID=0x%x",ccb.os_id);
|
||||
fWrite("");
|
||||
ReportWindow(ccb.front_window,0);
|
||||
for(j=2;j<ccb.tab_size;j++)
|
||||
{
|
||||
wsRead(&object,ccb.obj_tab[j],sizeof(OBJECT));
|
||||
switch(object.win.type)
|
||||
{
|
||||
case 0x2:
|
||||
fWrite("GC(%d) draws to %d",j,object.gcb.draws_to);
|
||||
case 0x1:
|
||||
break;
|
||||
case 0x4:
|
||||
wsRead(&bitmap,object.shared.head.addr.bit,sizeof(bitmap));
|
||||
fWrite("Bitmap(%d) {%d,%d}",j,
|
||||
bitmap.size.x,
|
||||
bitmap.size.y);
|
||||
break;
|
||||
case 0x8:
|
||||
wsRead(&font,object.shared.head.addr.font,sizeof(font));
|
||||
p_bcpy(&name[0],&font.info.name[0],32);
|
||||
name[32]=0;
|
||||
fWrite("Font(%d) \"%s\",{low=%d,hi=%d,hgt=%d}",j,&name[0],
|
||||
font.info.low_ch,font.info.high_ch,
|
||||
font.info.height);
|
||||
break;
|
||||
case 0x10:
|
||||
fWrite("MouseIcon(%d)",j);
|
||||
break;
|
||||
case 0x20:
|
||||
fWrite("Clock(%d)",j);
|
||||
break;
|
||||
case 0x40:
|
||||
fWrite("Winbit(%d)",j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma save,ENTER_CALL
|
||||
LOCAL_C INT report(TEXT *fName,UINT index)
|
||||
{
|
||||
UINT i;
|
||||
INT pri,pid;
|
||||
|
||||
hEnsurePath(fName);
|
||||
f_open(&FileCB,fName,P_FTEXT|P_FUPDATE|P_FREPLACE);
|
||||
pid=p_getpid();
|
||||
pri=p_getpri(pid);
|
||||
p_setpri(pid,E_PRIORITY_WSERV+1);
|
||||
p_sound(-5,320);
|
||||
if (index)
|
||||
ReportClient(ClientCCBs[index]);
|
||||
else for(i=1;i<WS_MAX_CLIENTS;i++)
|
||||
{
|
||||
if (ClientCCBs[i]==0)
|
||||
fWrite("Client slot %d :- empty",i);
|
||||
else
|
||||
ReportClient(ClientCCBs[i]);
|
||||
fWrite("");
|
||||
}
|
||||
p_setpri(pid,pri);
|
||||
return(0);
|
||||
}
|
||||
#pragma restore
|
||||
|
||||
GLDEF_C VOID wsReport(HANDLE pid)
|
||||
/* Log one or all the window server clients resources.
|
||||
If pid==0 Log all clients resources.
|
||||
If pid==-1 Log the foreground clients resources.
|
||||
Else log the client with process id PID's resources.
|
||||
*/
|
||||
{
|
||||
H_DI_FSEL fsel;
|
||||
static TEXT fName[128]="\030LOC::M:\\OPL\\WSREPORT.LIS";
|
||||
UINT index,nodlg;
|
||||
UWORD buf[25];
|
||||
|
||||
wsRead(&wsDatApp,&DatApp1,2);
|
||||
wsRead(&ClientCCBs[0],&wsDatApp->WservStaticClients[0],
|
||||
sizeof(ClientCCBs));
|
||||
index=nodlg=0;
|
||||
if (pid==-1) /* Log the foreground clients resources */
|
||||
{
|
||||
wGetProcessList(&buf[0]);
|
||||
pid=buf[0];
|
||||
nodlg=TRUE; /* Log to the last file name used with no query */
|
||||
}
|
||||
if (pid) /* Find the client index of the process to log */
|
||||
FOREVER
|
||||
{
|
||||
index++;
|
||||
if (index==WS_MAX_CLIENTS)
|
||||
{
|
||||
wInfoMsg("Not a window server client");
|
||||
return;
|
||||
}
|
||||
if (ClientCCBs[index])
|
||||
{
|
||||
wsRead(&ccb,ClientCCBs[index],sizeof(ccb));
|
||||
if (ccb.os_id==pid)
|
||||
break;
|
||||
}
|
||||
}
|
||||
fsel.fname= &fName[0];
|
||||
fsel.flags=H_FILE_SET_DEFEXT|H_FILE_NEW_EDITOR;
|
||||
if (nodlg==TRUE ||
|
||||
(uOpenDialog("Select file to write report to")>=0 &&
|
||||
uAddDialogItem(H_DIALOG_FSEL,"File",&fsel)>=0 &&
|
||||
uRunDialog()>0))
|
||||
{
|
||||
wsRead(&wsDatApp,&DatApp1,2);
|
||||
fName[fName[0]+1]=0;
|
||||
uErrorValue(p_enter3(report,&fName[1],index));
|
||||
p_close(FileCB);
|
||||
FileCB=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user