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

  1. /*
  2.     fnsint.c  5/2/87
  3.  
  4.     % sint_funcs
  5.  
  6.     Integer editing functions.
  7.     These funcs edit ints in a string_like fashion.
  8.     The field variable should be a int *.
  9.  
  10.     C-scape 3.1
  11.     Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
  12.     ALL RIGHTS RESERVED.
  13.  
  14.     Revision History:
  15.     -----------------
  16.      4/06/88 jmd     added call to sed_DoSpecial
  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 global error msg strings for easy changing
  20.      9/17/88 jmd     added std_ funcs
  21.     10/06/88 jmd    added stdBigCur_fenter
  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/03/89 jmd    added strclip to senter func
  26.      6/07/89 jmd    added test for mouse code (later removed)
  27.      8/07/89 jmd    now uses int fexit
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <ctype.h>
  32. #include <string.h>
  33.  
  34. #include "cscape.h"
  35. #include "ostdlib.h"        /* for atoi() */
  36.  
  37. #include "fnfunc.h"            /* for field functions */
  38. #include "strdecl.h"        /* for C-scape string functions */
  39. #include "scancode.h"
  40.  
  41. boolean sint_filter(_arg1(int));
  42.  
  43. OGLOBAL field_funcs_struct sint_funcs = {
  44.     stdBigCur_fenter,
  45.     int_fexit,
  46.     sint_fkey,
  47.     sint_senter,
  48.     sint_sexit,
  49.     sizeof(int)
  50. };
  51.  
  52. void sint_fkey(sed)
  53.     sed_type sed;
  54. /*
  55.     Hands its work to StrCommon_fkey (fnstrcom.c)
  56.     Passes a filter function (below) to decide which
  57.     characters can be typed in.
  58. */
  59. {
  60.     StrCommon_fkey(sed, sint_filter);
  61. }
  62.  
  63. boolean sint_filter(key)
  64.     int key;
  65. /*
  66.     Filter function for sint_funcs
  67.     for use with StrCommon_fkey
  68. */
  69. {
  70.     return(isdigit(key) || key == '-');
  71. }
  72.  
  73. void sint_senter(sed, fieldno)
  74.     sed_type sed;
  75.     int fieldno;
  76. /*
  77.     Convert the native int into the record string.
  78. */
  79. {
  80.     sprintf(sed_GetScratchPad(sed), "%d", *((int *) sed_GetVar(sed, fieldno)));
  81.     strleft(sed_GetScratchPad(sed), sed_GetRecordLen(sed, fieldno));
  82.     strclip(sed_GetScratchPad(sed));
  83.     sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
  84.  
  85.     std_senter(sed, fieldno);
  86. }
  87.  
  88. void sint_sexit(sed, fieldno)
  89.     sed_type sed;
  90.     int fieldno;
  91. /*
  92.     Convert the record string back into the native int.
  93.     Remove commas from string first.
  94. */
  95. {
  96.     if (sed_GetBaton(sed) != SED_ABORT) {
  97.         strcpy(sed_GetScratchPad(sed), sed_GetRecord(sed, fieldno));
  98.         strnocomma(sed_GetScratchPad(sed));
  99.         *((int *) sed_GetVar(sed, fieldno)) = atoi(sed_GetScratchPad(sed));
  100.     }
  101. }
  102.  
  103.