home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
200-299
/
ff254.lzh
/
Etale
/
numget.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-10-19
|
2KB
|
91 lines
/* numget.c -- (part of efr) Copyright © 1989 by William F. Hammond */
/* -- get user's number from custom window, providing on */
/* the spot rejection of invalid input */
#ifndef TDM_H
#include "tdm.h"
#endif
/*********************************************************************/
LONG numget(gstr)
UBYTE *gstr;
{
struct IntuiMessage *msg;
LONG lskip; /* that which is returned */
UBYTE signflag, zeroflag;
UBYTE chx, holdskip[HSL + 1];
ULONG flags;
LONG firstx, lastx;
int gsl;
SHORT jdir, kdir;
zeroflag = NULB;
gsl = strlen(gstr);
savestyle = SetSoftStyle(rp, (ULONG)FS_NORMAL, enable);
SetDrMd(rp,(LONG)(JAM2));
Move(rp, 0L, (LONG)maxrowpix);
ClearScreen(rp);
Text(rp, gstr, (LONG)gsl);
jdir = 0;
firstx = (LONG)rp->cp_x;
lastx = (LONG)rp->cp_x;
flags = VANILLAKEY;
holdskip[0] = '1'; /* 1 is the default return */
signflag = NULB;
while(1)
{
Wait(1L << mw->UserPort->mp_SigBit);
while(msg = (struct IntuiMessage *)GetMsg(mw->UserPort))
{
if(msg->Class == VANILLAKEY) chx = (UBYTE)msg->Code;
ReplyMsg(msg);
}
if ( (chx == 0x0a) || (chx == 0x0d) )break;
else if (jdir >= HSL)
{
zeroflag = ONEB;
break;
}
else if (chx == 0x08)
{
Move(rp, firstx, (LONG)maxrowpix);
ClearScreen(rp);
if (jdir > 0) jdir --;
for (kdir = 0; kdir < jdir; kdir ++)
{
Text(rp, &holdskip[kdir], 1L);
}
lastx = (LONG)rp->cp_x;
}
else if( (chx == '-') && (jdir == 0) )
{
signflag = ONEB;
Text(rp, &chx, 1L);
lastx = (LONG)rp->cp_x;
}
else if( (chx < '0') || (chx > '9') )
{
DisplayBeep(mw->WScreen);
Move(rp, lastx, (LONG)maxrowpix);
ClearScreen(rp);
}
else
{
holdskip[jdir] = chx;
jdir ++;
Text(rp, &chx, 1L);
lastx = (LONG)rp->cp_x;
}
}
lskip = 0L;
kdir = 0;
if(zeroflag) jdir = 0;
while(kdir < jdir)
{
lskip = 10L * lskip + (LONG)(holdskip[kdir] - '0');
kdir ++;
}
if(signflag) lskip = -lskip;
/*if(lskip == 0L) lskip = numget(gstr);*/
Move(rp, 0L, (LONG)maxrowpix);
ClearScreen(rp);
return lskip;
}