home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
FUNCS
/
FNPNUM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-07-26
|
2KB
|
116 lines
/*
fnpnum.c 10/10/87
% pint_funcs, plong_funcs
Misc. routines used by positive numeric field functions.
The positive numeric functions do not allow the entry of
negative numbers.
pnum_fkey()
C-scape 3.2
Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
4/06/88 jmd added call to sed_DoSpecial
9/24/88 jmd clears after first key pressed
10/09/88 jmd added SED_ABORT support
10/14/88 jdc added var_size element to field_funcs_struct
6/07/89 jmd added test for mouse code (later removed)
1/31/90 jmd don't reset baton on MOU_CLICK
3/28/90 jmd ansi-fied
7/26/90 jdc fixed for use with only one writeable position
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "cscape.h"
#include "fnfunc.h" /* for field functions */
#include "scancode.h"
/* positive integer funcs */
OGLOBAL field_funcs_struct pint_funcs = {
num_fenter,
int_fexit,
pnum_fkey,
int_senter,
int_sexit,
sizeof(int)
};
/* positive long funcs */
OGLOBAL field_funcs_struct plong_funcs = {
num_fenter,
long_fexit,
pnum_fkey,
long_senter,
long_sexit,
sizeof(long)
};
void pnum_fkey(sed_type sed)
/*
Generic fkey function for positive numeric fields.
Supports right to left calculator style entry.
The Space Bar key clears the field to 0.
*/
{
int scancode, key;
scancode = kb_Read();
if (sed_DoSpecial(sed, scancode))
return;
if (special_key(sed, scancode))
return;
if (inter_field(sed, scancode))
return;
if (inter_page(sed, scancode))
return;
switch(scancode) {
case BACKSPACE:
sed_PullLeft(sed);
if (digit_count(sed_GetCurrRecord(sed)) == 0) {
sed_Overwrite(sed, '0');
}
break;
default:
/* overwrite leading zeroes */
key = ascii(scancode);
if (isdigit(key)) {
if (sed_GetBaton(sed) == SED_FIRST) {
/* Clear field if first key pressed is a digit */
clear_field(sed);
}
if (sed_GetCurrChar(sed) == '0'
&& digit_count(sed_GetCurrRecord(sed)) == 1) {
sed_Overwrite(sed, key);
}
else if (sed_GetChar(sed, 0) == ' ') {
sed_PushLeft(sed, key);
}
}
/* Clear the field if ' ' is pressed */
else if (key == ' ') {
clear_field(sed);
}
break;
}
/* reset baton */
if (scancode != MOU_CLICK) {
sed_SetBaton(sed, -1);
}
}