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

  1. /*
  2.     fnint.c             11/20/86
  3.  
  4.     % int_funcs
  5.  
  6.     Integer editting functions.
  7.     The field variable should be a int *.
  8.  
  9.     C-scape 3.1
  10.     Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
  11.     ALL RIGHTS RESERVED.
  12.  
  13.     Revision History:
  14.     -----------------
  15.      5/12/88 jmd    added calls to sed_GetScratchPad()
  16.      9/17/88 jmd    added global error msg strings for easy changing
  17.      9/17/88 jmd     added std_ funcs
  18.     10/09/88 jmd     added SED_ABORT support
  19.     10/14/88 jdc    added var_size element to field_funcs_struct
  20. */
  21.  
  22. #include <stdio.h>
  23. #include <ctype.h>
  24.  
  25. #include "cscape.h"
  26. #include "fnfunc.h"            /* for field functions */
  27. #include "strdecl.h"        /* for C-scape string functions */
  28. #include "scancode.h"
  29.  
  30. OGLOBAL field_funcs_struct int_funcs = {
  31.     num_fenter,
  32.     int_fexit,
  33.     num_fkey,
  34.     int_senter,
  35.     int_sexit,
  36.     sizeof(int)
  37. };
  38.  
  39. boolean int_fexit(sed)
  40.     sed_type sed;
  41. /*
  42.     Validates an integer using the string in field data 1.
  43. */
  44. {
  45.     int val;
  46.  
  47.     if (sed_GetBaton(sed) != SED_ABORT) {
  48.  
  49.         sscanf(sed_GetCurrRecord(sed), "%d", &val);
  50.  
  51.         /* call standard numeric validation routine (fnstdval.c) */
  52.         if (!std_NumValid(sed, (double) val)) {
  53.             return(FALSE);
  54.         }
  55.     }
  56.  
  57.     return(std_fexit(sed));
  58. }
  59.  
  60. void int_senter(sed, fieldno)
  61.     sed_type sed;
  62.     int fieldno;
  63. /*
  64.     Convert native type to string for record.
  65. */
  66. {
  67.     sprintf(sed_GetScratchPad(sed), "%d", *((int *) sed_GetVar(sed, fieldno)));
  68.  
  69.     strright(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
  70.     sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
  71.  
  72.     std_senter(sed, fieldno);
  73. }
  74.  
  75. void int_sexit(sed, fieldno)
  76.     sed_type sed;
  77.     int fieldno;
  78. /*
  79.     Converts record back to native type.
  80. */
  81. {
  82.     if (sed_GetBaton(sed) != SED_ABORT) {
  83.         sscanf(sed_GetRecord(sed, fieldno), "%d", (int *) sed_GetVar(sed, fieldno));
  84.     }
  85. }
  86.  
  87.  
  88.