home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
FUNCS
/
FNINT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-11
|
2KB
|
97 lines
/*
fnint.c 11/20/86
% int_funcs
Integer editing functions.
The field variable should be a int *.
C-scape 3.2
Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
5/12/88 jmd added calls to sed_GetScratchPad()
9/17/88 jmd added global error msg strings for easy changing
9/17/88 jmd added std_ funcs
10/09/88 jmd added SED_ABORT support
10/14/88 jdc added var_size element to field_funcs_struct
3/14/90 jmd moved formatting before validation
3/28/90 jmd ansi-fied
4/12/90 pmcm added valid_Range check for over/underflow in fexit
4/13/90 jmd added olimits.h
9/11/90 pmcm changed sed_SetMouseCode to kb_Stuff
*/
#include <stdio.h>
#include <ctype.h>
#include "cscape.h"
#include "fnfunc.h" /* for field functions */
#include "strdecl.h" /* for C-scape string functions */
#include "scancode.h"
#include "olimits.h"
OGLOBAL field_funcs_struct int_funcs = {
num_fenter,
int_fexit,
num_fkey,
int_senter,
int_sexit,
sizeof(int)
};
boolean int_fexit(sed_type sed)
/*
Validates an integer using the string in field data 1.
*/
{
int val;
if (sed_GetBaton(sed) != SED_ABORT) {
if (!valid_Range(sed, (long)INT_MIN, (long)INT_MAX)) {
kb_Stuff(KEY_INVALID);
return(FALSE);
}
/* format the field's record */
std_format(sed);
sscanf(sed_GetCurrRecord(sed), "%d", &val);
/* call standard numeric validation routine (fnstdval.c) */
if (!std_NumValid(sed, (double) val)) {
return(FALSE);
}
}
return(std_fexit(sed));
}
void int_senter(sed_type sed, int fieldno)
/*
Convert native type to string for record.
*/
{
sprintf(sed_GetScratchPad(sed), "%d", *((int *) sed_GetVar(sed, fieldno)));
strright(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
std_senter(sed, fieldno);
}
void int_sexit(sed_type sed, int fieldno)
/*
Converts record back to native type.
*/
{
if (sed_GetBaton(sed) != SED_ABORT) {
sscanf(sed_GetRecord(sed, fieldno), "%d", (int *) sed_GetVar(sed, fieldno));
}
}