home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 1.ddi / FUNCS.EXE / CSCAPE / SOURCE / FNSFLOAT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-07  |  2.4 KB  |  102 lines

  1. /*
  2.     fnsfloat.c         5/2/87
  3.  
  4.     % sfloat_funcs
  5.  
  6.     Float editing functions.
  7.     The field variable should be a float *.
  8.     The record length should be greater than 7.
  9.     These funcs edit floats in a string_like fashion.
  10.  
  11.     C-scape 3.1
  12.     Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
  13.     ALL RIGHTS RESERVED.
  14.  
  15.     Revision History:
  16.     -----------------
  17.      5/12/88 jmd    added calls to sed_GetScratchPad()
  18.      9/15/88 jmd     removed vid_Cursor calls
  19.      9/17/88 jmd     added std_ funcs
  20.     10/06/88 jmd    added snum_fenter, added validation, use %g now
  21.     10/09/88 jmd     added SED_ABORT support
  22.     10/14/88 jdc    added var_size element to field_funcs_struct
  23.     12/16/88 jmd    added vsfloat_fexit
  24.  
  25.      6/03/89 jmd    added strclip to senter func
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <ctype.h>
  30. #include <string.h>
  31.  
  32. #include "cscape.h"
  33. #include "fnfunc.h"            /* for field functions */
  34. #include "strdecl.h"        /* for C-scape string functions */
  35. #include "scancode.h"
  36.  
  37. OGLOBAL field_funcs_struct sfloat_funcs = {
  38.     stdBigCur_fenter,
  39.     sfloat_fexit,
  40.     sdouble_fkey,
  41.     sfloat_senter,
  42.     sfloat_sexit,
  43.     sizeof(float)
  44. };
  45.  
  46. boolean sfloat_fexit(sed)
  47.     sed_type sed;
  48. {
  49.     float val;
  50.  
  51.     if (sed_GetBaton(sed) != SED_ABORT) {
  52.         sscanf(sed_GetCurrRecord(sed), "%g", &val);
  53.         if ( !valid_Float(val, (char *) sed_GetCurrFieldData(sed, 1)) ) {
  54.             tone();
  55.             sed_BorderPrompt(sed, fnnum_errmsg);
  56.             /* wait for a keystroke */
  57.             while (!kb_Check())
  58.                 ;
  59.             sed_BorderPrompt(sed, sed_GetCurrFieldData(sed, 0));
  60.             return(FALSE);
  61.         }
  62.  
  63.         sed_DoFieldSexit(sed, sed_GetFieldNo(sed));
  64.         sed_DoFieldSenter(sed, sed_GetFieldNo(sed));
  65.         sed_UpdateCurrField(sed);
  66.     }
  67.  
  68.     return(std_fexit(sed));
  69. }
  70.  
  71. void sfloat_senter(sed, fieldno)
  72.     sed_type sed;
  73.     int fieldno;
  74. /*
  75.     Convert the native float into the record string.
  76. */
  77. {
  78.     sprintf(sed_GetScratchPad(sed), "%g", *((float *) sed_GetVar(sed, fieldno)));
  79.     strleft(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
  80.     strclip(sed_GetScratchPad(sed));
  81.     sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
  82.  
  83.     std_senter(sed, fieldno);
  84. }
  85.  
  86. void sfloat_sexit(sed, fieldno)
  87.     sed_type sed;
  88.     int fieldno;
  89. /*
  90.     Convert the record string back into the native float.
  91.     Remove commas from string first.
  92. */
  93. {
  94.     if (sed_GetBaton(sed) != SED_ABORT) {
  95.         strcpy(sed_GetScratchPad(sed), sed_GetRecord(sed, fieldno));
  96.         strnocomma(sed_GetScratchPad(sed));
  97.         sscanf(sed_GetScratchPad(sed), "%g", (float *) sed_GetVar(sed, fieldno));
  98.     }
  99. }
  100.  
  101.  
  102.