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

  1. /*
  2.     fnsdoubl.c         5/2/87
  3.  
  4.     % sdouble_funcs
  5.  
  6.     Double editing functions.
  7.     The field variable should be a double *.
  8.     The record length should be greater than 12.
  9.     These funcs edit doubles 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.      4/06/88 jmd     added call to sed_DoSpecial
  18.      5/12/88 jmd    added calls to sed_GetScratchPad()
  19.      9/15/88 jmd     removed vid_Cursor calls
  20.      9/17/88 jmd     added std_ funcs
  21.     10/06/88 jmd    added snum_fenter, now uses %f and %g
  22.     10/09/88 jmd     added SED_ABORT support
  23.     10/14/88 jdc    added var_size element to field_funcs_struct
  24.  
  25.      6/01/89 gam    added ocountry stuff
  26.      6/07/89 jmd    added test for mouse code (later removed)
  27. */
  28.  
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include <string.h>
  32.  
  33. #include "cscape.h"
  34. #include "fnfunc.h"            /* for field functions */
  35. #include "strdecl.h"        /* for C-scape string functions */
  36.  
  37. #include "scancode.h"
  38.  
  39. boolean sdouble_filter(_arg1(int));
  40.  
  41. OGLOBAL field_funcs_struct sdouble_funcs = {
  42.     stdBigCur_fenter,
  43.     sdouble_fexit,
  44.     sdouble_fkey,
  45.     sdouble_senter,
  46.     sdouble_sexit,
  47.     sizeof(double)
  48. };
  49.  
  50. boolean sdouble_fexit(sed)
  51.     sed_type sed;
  52. {
  53.     double val;
  54.  
  55.     if (sed_GetBaton(sed) != SED_ABORT) {
  56.         sscanf(sed_GetScratchPad(sed), "%lg", &val);
  57.         strtrans(sed_GetScratchPad(sed), ocountry.dec_char, '.');
  58.  
  59.         /* call standard numeric validation routine (fnstdval.c) */
  60.         if (!std_NumValid(sed, (double) val)) {
  61.             return(FALSE);
  62.         }
  63.     }
  64.  
  65.     return(std_fexit(sed));
  66. }
  67.  
  68. void sdouble_fkey(sed)
  69.     sed_type sed;
  70. /*
  71.     Hands its work to StrCommon_fkey (fnstrcom.c)
  72.     Passes a filter function (below) to decide which
  73.     characters can be typed in.
  74. */
  75. {
  76.     StrCommon_fkey(sed, sdouble_filter);
  77. }
  78.  
  79. boolean sdouble_filter(key)
  80.     int key;
  81. /*
  82.     Filter function for sdouble_funcs
  83.     for use with StrCommon_fkey
  84. */
  85. {
  86.     return(isdigit(key) || key == '-' || key == ocountry.dec_char);
  87. }
  88.  
  89. void sdouble_senter(sed, fieldno)
  90.     sed_type sed;
  91.     int fieldno;
  92. /*
  93.     Convert the native double into the record string.
  94. */
  95. {
  96.     sprintf(sed_GetScratchPad(sed), "%lg", *((double *) sed_GetVar(sed, fieldno)));
  97.     strtrans(sed_GetScratchPad(sed), '.', ocountry.dec_char);
  98.     strleft(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
  99.     strclip(sed_GetScratchPad(sed));
  100.     sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
  101.  
  102.     std_senter(sed, fieldno);
  103. }
  104.  
  105. void sdouble_sexit(sed, fieldno)
  106.     sed_type sed;
  107.     int fieldno;
  108. /*
  109.     Convert the record string back into the native double.
  110.     Remove commas from string first.
  111. */
  112. {
  113.     if (sed_GetBaton(sed) != SED_ABORT) {
  114.         strcpy(sed_GetScratchPad(sed), sed_GetRecord(sed, fieldno));
  115.         strnocomma(sed_GetScratchPad(sed));
  116.         strtrans(sed_GetScratchPad(sed), ocountry.dec_char, '.');
  117.         sscanf(sed_GetScratchPad(sed), "%lg", (double *) sed_GetVar(sed, fieldno));
  118.     }
  119. }
  120.  
  121.  
  122.  
  123.