home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
FNSDOUBL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-06
|
4KB
|
141 lines
/*
fnsdoubl.c 5/2/87
% sdouble_funcs
Double editing functions.
The field variable should be a double *.
The record length should be greater than 12.
These funcs edit doubles in a string_like fashion.
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
5/12/88 jmd added calls to sed_GetScratchPad()
9/15/88 jmd removed vid_Cursor calls
9/17/88 jmd added std_ funcs
10/06/88 jmd added snum_fenter, now uses %f and %g
10/09/88 jmd added SED_ABORT support
10/14/88 jdc added var_size element to field_funcs_struct
6/01/89 gam added ocountry stuff
6/07/89 jmd added test for mouse code (later removed)
10/02/89 gam fixed some of the ocountry stuff
10/17/89 jdc fixed filter (no extended ascii)
3/14/90 jmd moved formatting before validation
3/28/90 jmd ansi-fied
10/06/90 pmcm changed %lg to %le in sdouble_fexit for VAX C
10/06/90 pmcm changed %lg to %le in sdouble_sexit for VAX C
*/
#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"
OSTATIC sfilter_func (sdouble_filter);
OGLOBAL field_funcs_struct sdouble_funcs = {
stdBigCur_fenter,
sdouble_fexit,
sdouble_fkey,
sdouble_senter,
sdouble_sexit,
sizeof(double)
};
boolean sdouble_fexit(sed_type sed)
{
double val;
if (sed_GetBaton(sed) != SED_ABORT) {
/* format the field's record */
std_format(sed);
strcpy(sed_GetScratchPad(sed), sed_GetCurrRecord(sed));
strnocomma(sed_GetScratchPad(sed));
strtrans(sed_GetScratchPad(sed), ocountry.dec_char, '.');
#ifdef OAK_VMS
/* Note: VMS does not support %g in sscanf */
sscanf(sed_GetScratchPad(sed), "%le", &val);
#else
sscanf(sed_GetScratchPad(sed), "%lg", &val);
#endif
/* call standard numeric validation routine (fnstdval.c) */
if (!std_NumValid(sed, (double) val)) {
return(FALSE);
}
}
return(std_fexit(sed));
}
void sdouble_fkey(sed_type sed)
/*
Hands its work to StrCommon_fkey (fnstrcom.c)
Passes a filter function (below) to decide which
characters can be typed in.
*/
{
StrCommon_fkey(sed, sdouble_filter);
}
static boolean sdouble_filter(int key)
/*
Filter function for sdouble_funcs
for use with StrCommon_fkey
*/
{
return(isprint(key) && (isdigit(key) || key == '-' || key == ocountry.dec_char));
}
void sdouble_senter(sed_type sed, int fieldno)
/*
Convert the native double into the record string.
*/
{
sprintf(sed_GetScratchPad(sed), "%lg", *((double *) sed_GetVar(sed, fieldno)));
strtrans(sed_GetScratchPad(sed), '.', ocountry.dec_char);
strleft(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
strclip(sed_GetScratchPad(sed));
sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
std_senter(sed, fieldno);
}
void sdouble_sexit(sed_type sed, int fieldno)
/*
Convert the record string back into the native double.
Remove commas from string first.
*/
{
if (sed_GetBaton(sed) != SED_ABORT) {
strcpy(sed_GetScratchPad(sed), sed_GetRecord(sed, fieldno));
strnocomma(sed_GetScratchPad(sed));
strtrans(sed_GetScratchPad(sed), ocountry.dec_char, '.');
#ifdef OAK_VMS
/* Note: VMS does not support %g in sscanf */
sscanf(sed_GetScratchPad(sed), "%le", (double *) sed_GetVar(sed, fieldno));
#else
sscanf(sed_GetScratchPad(sed), "%lg", (double *) sed_GetVar(sed, fieldno));
#endif
}
}