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

  1. /*
  2.     fnsecure.c         10/24/86
  3.  
  4.     % secure_funcs
  5.  
  6.     Editting functions for fields which do not print
  7.     out to the screen.  (i.e.) passwords.
  8.  
  9.     When a letter is typed in a MASK character is printed to the screen.
  10.     The Record maintains the correct value, however.
  11.  
  12.     Note:    SED_ABORT will NOT affect this routine
  13.  
  14.     The RIGHT and LEFT keys don't do anything.
  15.  
  16.     C-scape 3.1
  17.     Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
  18.     ALL RIGHTS RESERVED.
  19.  
  20.     Revision History:
  21.     -----------------
  22.      4/06/88 jmd     added call to sed_DoSpecial
  23.      5/12/88 jmd    added calls to sed_GetScratchPad()
  24.      6/23/88 jmd     added casting to char * for sed_GetVar
  25.      9/17/88 jmd     added std_ funcs
  26.     10/14/88 jdc    added var_size element to field_funcs_struct
  27.  
  28.      6/07/89 jmd    added test for mouse code (later removed)
  29. */
  30.  
  31. #include <stdio.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34.  
  35. #include "cscape.h"
  36. #include "fnfunc.h"            /* for field functions */
  37. #include "scancode.h"
  38.  
  39. #define    MASK    '*'
  40.  
  41. OGLOBAL field_funcs_struct secure_funcs = {
  42.     std_fenter,
  43.     std_fexit,
  44.     secure_fkey,
  45.     secure_senter,
  46.     FNULL,
  47.     VAR_STRING
  48. };
  49.  
  50. void secure_fkey(sed)
  51.     sed_type sed;
  52. {
  53.     int scancode, key;
  54.  
  55.     scancode = kb_Read();
  56.  
  57.     if (sed_DoSpecial(sed, scancode))
  58.         return;
  59.     if (special_key(sed, scancode))
  60.         return;
  61.     if (inter_field(sed, scancode))
  62.         return;
  63.     if (inter_page(sed, scancode))
  64.         return;
  65.  
  66.     switch(scancode) {
  67.     case BACKSPACE:
  68.         if ( sed_DecChar(sed) ) {
  69.             sed_PullRight(sed);
  70.             ((char *) sed_GetCurrVar(sed))[sed_GetRecordPos(sed)] = '\0';
  71.         }
  72.         break;
  73.     default:
  74.         /*
  75.             Don't allow typing in the last position or else BACKSPACE
  76.             gets weird.
  77.         */
  78.  
  79.         key = ascii(scancode);
  80.         if (isprint(key) &&
  81.           (sed_GetRecordPos(sed) < sed_GetCurrRecordLen(sed) -1) ){
  82.             ((char *) sed_GetCurrVar(sed))[sed_GetRecordPos(sed)] = (char) key;
  83.             ((char *) sed_GetCurrVar(sed))[sed_GetRecordPos(sed)+1] = '\0';
  84.             sed_Overwrite(sed, MASK);
  85.             sed_IncChar(sed);
  86.         }
  87.         break;
  88.     }
  89.  
  90.     /* reset baton */
  91.     sed_SetBaton(sed, -1);
  92. }
  93.  
  94. void secure_senter(sed, fieldno)
  95.     sed_type sed;
  96.     int fieldno;
  97. /*
  98.     Convert native type to string for record.
  99. */
  100. {
  101.     char *p, *s;
  102.  
  103.     /* mask the record */
  104.     s = sed_GetScratchPad(sed);
  105.     strcpy(s, (char *) sed_GetVar(sed, fieldno));
  106.  
  107.     for (p = s + strlen(s) - 1; p >= s; p--) {
  108.         if( *p != ' ') *p = MASK;
  109.     }
  110.  
  111.     sed_SetRecord(sed, s, fieldno);
  112. }
  113.  
  114.  
  115.