home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
FUNCS
/
FNLONG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-11
|
3KB
|
104 lines
/*
fnlong.c 10/30/86
% long_funcs
Long editing functions.
Variable should be a long*.
C-scape 3.2
Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
10/01/87 jmd added casting
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
1/22/90 pmcm stripped comma's for sscanf in _fexit and _sexit
2/03/90 jmd added #include
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 <string.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 long_funcs = {
num_fenter,
long_fexit,
num_fkey,
long_senter,
long_sexit,
sizeof(long)
};
boolean long_fexit(sed_type sed)
/*
Validates a long using the string in field data 1.
*/
{
long val;
if (sed_GetBaton(sed) != SED_ABORT) {
/* test for overflow/underflow */
if (!valid_Range(sed, (long)LONG_MIN, (long)LONG_MAX)) {
kb_Stuff(KEY_INVALID);
return(FALSE);
}
/* format the field's record */
std_format(sed);
/* strip commas for sscanf */
strcpy(sed_GetScratchPad(sed), sed_GetCurrRecord(sed));
sscanf(strnocomma(sed_GetScratchPad(sed)), "%ld", &val);
/* call standard numeric validation routine (fnstdval.c) */
if (!std_NumValid(sed, (double) val)) {
return(FALSE);
}
}
return(std_fexit(sed));
}
void long_senter(sed_type sed, int fieldno)
/*
Convert native type to string for record.
*/
{
sprintf(sed_GetScratchPad(sed), "%ld", *((long *) sed_GetVar(sed, fieldno)));
strright(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
std_senter(sed, fieldno);
}
void long_sexit(sed_type sed, int fieldno)
/*
Converts record back to native type.
*/
{
if (sed_GetBaton(sed) != SED_ABORT) {
strcpy(sed_GetScratchPad(sed), sed_GetRecord(sed, fieldno));
sscanf(strnocomma(sed_GetScratchPad(sed)), "%ld", (long *) sed_GetVar(sed, fieldno));
}
}