home *** CD-ROM | disk | FTP | other *** search
- /*
- 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.1
- 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)
- */
-
- #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"
-
- boolean sdouble_filter(_arg1(int));
-
- OGLOBAL field_funcs_struct sdouble_funcs = {
- stdBigCur_fenter,
- sdouble_fexit,
- sdouble_fkey,
- sdouble_senter,
- sdouble_sexit,
- sizeof(double)
- };
-
- boolean sdouble_fexit(sed)
- sed_type sed;
- {
- double val;
-
- if (sed_GetBaton(sed) != SED_ABORT) {
- sscanf(sed_GetScratchPad(sed), "%lg", &val);
- strtrans(sed_GetScratchPad(sed), ocountry.dec_char, '.');
-
- /* call standard numeric validation routine (fnstdval.c) */
- if (!std_NumValid(sed, (double) val)) {
- return(FALSE);
- }
- }
-
- return(std_fexit(sed));
- }
-
- void sdouble_fkey(sed)
- 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);
- }
-
- boolean sdouble_filter(key)
- int key;
- /*
- Filter function for sdouble_funcs
- for use with StrCommon_fkey
- */
- {
- return(isdigit(key) || key == '-' || key == ocountry.dec_char);
- }
-
- void sdouble_senter(sed, fieldno)
- 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, fieldno)
- 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, '.');
- sscanf(sed_GetScratchPad(sed), "%lg", (double *) sed_GetVar(sed, fieldno));
- }
- }
-
-
-
-