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

  1. /*
  2.     fnpnum.c             10/10/87
  3.  
  4.     % pint_funcs
  5.  
  6.     Misc. routines used by positive numeric field functions.
  7.     The positive numeric functions do not allow the entry of
  8.     negative numbers.
  9.  
  10.     pnum_fkey()
  11.  
  12.     C-scape 3.1
  13.     Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
  14.     ALL RIGHTS RESERVED.
  15.  
  16.     Revision History:
  17.     -----------------
  18.      4/06/88 jmd     added call to sed_DoSpecial
  19.      9/24/88 jmd     clears after first key pressed
  20.     10/09/88 jmd     added SED_ABORT support
  21.     10/14/88 jdc    added var_size element to field_funcs_struct
  22.  
  23.      6/07/89 jmd    added test for mouse code (later removed)
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <ctype.h>
  29.  
  30. #include "cscape.h"
  31. #include "fnfunc.h"            /* for field functions */
  32. #include "scancode.h"
  33.  
  34. /* positive integer funcs */
  35. OGLOBAL field_funcs_struct pint_funcs = {
  36.     num_fenter,
  37.     int_fexit,
  38.     pnum_fkey,
  39.     int_senter,
  40.     int_sexit,
  41.     sizeof(int)
  42. };
  43.  
  44. /* positive long funcs */
  45. OGLOBAL field_funcs_struct plong_funcs = {
  46.     num_fenter,
  47.     long_fexit,
  48.     pnum_fkey,
  49.     long_senter,
  50.     long_sexit,
  51.     sizeof(long)
  52. };
  53.  
  54. void pnum_fkey(sed)
  55.     sed_type sed;
  56. /*
  57.     Generic fkey function for positive numeric fields.
  58.     Supports right to left calculator style entry.
  59.     The Space Bar key clears the field to 0.
  60. */
  61. {
  62.     int   scancode, key;
  63.  
  64.     scancode = kb_Read();
  65.  
  66.     if (sed_DoSpecial(sed, scancode))
  67.         return;
  68.     if (special_key(sed, scancode))
  69.         return;
  70.     if (inter_field(sed, scancode))
  71.         return;
  72.     if (inter_page(sed, scancode))
  73.         return;
  74.  
  75.     switch(scancode) {
  76.     case BACKSPACE:
  77.         sed_PullLeft(sed);
  78.         if (digit_count(sed_GetCurrRecord(sed)) == 0) {
  79.             sed_Overwrite(sed, '0');
  80.         }
  81.         break;
  82.     default:
  83.         /* overwrite leading zeroes                        */
  84.         key = ascii(scancode);
  85.         if (isdigit(key)) {
  86.             if (sed_GetBaton(sed) == SED_FIRST) {
  87.                 /* Clear field if first key pressed is a digit */
  88.                 clear_field(sed);
  89.             }
  90.             if (sed_GetChar(sed, 0) == ' '){
  91.                 if (sed_GetCurrChar(sed) == '0' &&
  92.                   digit_count(sed_GetCurrRecord(sed)) == 1) {
  93.                     sed_Overwrite(sed, key);
  94.                 }
  95.                 else {
  96.                     sed_PushLeft(sed, key);
  97.                 }
  98.             }
  99.         }
  100.  
  101.         /* Clear the field if ' ' is pressed */
  102.         else if (key == ' ') {
  103.             clear_field(sed);
  104.         }
  105.  
  106.         break;
  107.     }
  108.  
  109.     /* reset baton */
  110.     sed_SetBaton(sed, -1);
  111. }
  112.