home *** CD-ROM | disk | FTP | other *** search
- /*
- fnsfloat.c 5/2/87
-
- % sfloat_funcs
-
- Float editing functions.
- The field variable should be a float *.
- The record length should be greater than 7.
- These funcs edit floats in a string_like fashion.
-
- 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/15/88 jmd removed vid_Cursor calls
- 9/17/88 jmd added std_ funcs
- 10/06/88 jmd added snum_fenter, added validation, use %g now
- 10/09/88 jmd added SED_ABORT support
- 10/14/88 jdc added var_size element to field_funcs_struct
- 12/16/88 jmd added vsfloat_fexit
-
- 6/03/89 jmd added strclip to senter func
-
- 1/25/90 jmd converted kb_Check to kb_CheckWait
- 3/14/90 jmd moved formatting before validation
- 3/14/90 pmcm sdouble_fexit now uses local double for validation, not float
- 3/16/90 jmd added support for KEY_INVALID in fexit
- 3/28/90 jmd ansi-fied
- 9/07/90 jmd ifdef'd out code that call sexit/senter
- 9/11/90 pmcm changed sed_SetMouseCode to kb_Stuff
- 10/06/90 pmcm changed sscanf %lg to %le in sfloat_fexit for VAX C
- 10/06/90 pmcm changed sscanf %g to %f in sfloat_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"
-
- OGLOBAL field_funcs_struct sfloat_funcs = {
- stdBigCur_fenter,
- sfloat_fexit,
- sdouble_fkey,
- sfloat_senter,
- sfloat_sexit,
- sizeof(float)
- };
-
- boolean sfloat_fexit(sed_type sed)
- {
- double val;
-
- if (sed_GetBaton(sed) != SED_ABORT) {
- /* format the field's record */
- std_format(sed);
-
- #ifdef OAK_VMS
- /* Note: VMS does not support %g in sscanf */
- sscanf(sed_GetCurrRecord(sed), "%le", &val);
- #else
- sscanf(sed_GetCurrRecord(sed), "%lg", &val);
- #endif
-
- if ( !valid_Double(val, (char *) sed_GetCurrFieldData(sed, 1)) ) {
-
- /* Invalid entry: notify fkey function via mouse code */
- kb_Stuff(KEY_INVALID);
- return(FALSE);
- }
-
- #ifdef DOSEXIT
- sed_DoFieldSexit(sed, sed_GetFieldNo(sed));
- sed_DoFieldSenter(sed, sed_GetFieldNo(sed));
- sed_UpdateCurrField(sed);
- #endif
- }
-
- return(std_fexit(sed));
- }
-
- void sfloat_senter(sed_type sed, int fieldno)
- /*
- Convert the native float into the record string.
- */
- {
- sprintf(sed_GetScratchPad(sed), "%g", *((float *) sed_GetVar(sed, fieldno)));
- strleft(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
- strclip(sed_GetScratchPad(sed));
- sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
-
- std_senter(sed, fieldno);
- }
-
- void sfloat_sexit(sed_type sed, int fieldno)
- /*
- Convert the record string back into the native float.
- Remove commas from string first.
- */
- {
- if (sed_GetBaton(sed) != SED_ABORT) {
- strcpy(sed_GetScratchPad(sed), sed_GetRecord(sed, fieldno));
- strnocomma(sed_GetScratchPad(sed));
-
- #ifdef OAK_VMS
- /* Note: VMS does not support %g in sscanf */
- sscanf(sed_GetScratchPad(sed), "%f", (float *) sed_GetVar(sed, fieldno));
- #else
- sscanf(sed_GetScratchPad(sed), "%g", (float *) sed_GetVar(sed, fieldno));
- #endif
-
- }
- }
-
-
-