home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
FUNCS
/
FNSECURE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-26
|
3KB
|
139 lines
/*
fnsecure.c 10/24/86
% secure_funcs
Editting functions for fields which do not print
out to the screen. (i.e.) passwords.
When a letter is typed in a MASK character is printed to the screen;
however, the field's variable maintains the correct value.
SED_ABORT suppresses field formating.
The RIGHT and LEFT keys don't do anything.
C-scape 3.2
Copyright (c) 1986 - 1990 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
4/06/88 jmd added call to sed_DoSpecial
5/12/88 jmd added calls to sed_GetScratchPad()
6/23/88 jmd added casting to char * for sed_GetVar
9/17/88 jmd added std_ funcs
10/14/88 jdc added var_size element to field_funcs_struct
6/07/89 jmd added test for mouse code (later removed)
3/28/90 jmd ansi-fied
6/13/90 jdc replaced backwards pointer math
8/05/90 jdc added secure_fexit for formatting
8/26/90 mla fixed weird backspace case & added del case
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "cscape.h"
#include "fnfunc.h" /* for field functions */
#include "scancode.h"
#define MASK '*'
OGLOBAL field_funcs_struct secure_funcs = {
std_fenter,
secure_fexit,
secure_fkey,
secure_senter,
FNULL,
VAR_STRING
};
void secure_fkey(sed_type sed)
{
int scancode, key;
scancode = kb_Read();
if (sed_DoSpecial(sed, scancode))
return;
if (special_key(sed, scancode))
return;
if (inter_field(sed, scancode))
return;
if (inter_page(sed, scancode))
return;
switch(scancode) {
case DEL:
case BACKSPACE:
if (sed_GetRecordPos(sed) == sed_GetCurrRecordLen(sed) -1
&& sed_GetCurrChar(sed) == MASK) {
sed_PullRight(sed);
((char *) sed_GetCurrVar(sed))[sed_GetRecordPos(sed)] = '\0';
}
else {
if ( sed_DecChar(sed) ) {
sed_PullRight(sed);
((char *) sed_GetCurrVar(sed))[sed_GetRecordPos(sed)] = '\0';
}
}
break;
default:
key = ascii(scancode);
if (isprint(key)){
((char *) sed_GetCurrVar(sed))[sed_GetRecordPos(sed)] = (char) key;
((char *) sed_GetCurrVar(sed))[sed_GetRecordPos(sed)+1] = '\0';
sed_Overwrite(sed, MASK);
sed_IncChar(sed);
}
break;
}
/* reset baton */
sed_SetBaton(sed, -1);
}
void secure_senter(sed_type sed, int fieldno)
/*
Convert native type to string for record.
*/
{
char *s;
int i;
/* mask the record */
s = sed_GetScratchPad(sed);
strcpy(s, (char *) sed_GetVar(sed, fieldno));
for (i = strlen(s) - 1; i >= 0; i--) {
if (s[i] != ' ') {
s[i] = MASK;
}
}
sed_SetRecord(sed, s, fieldno);
}
boolean secure_fexit(sed_type sed)
{
if (sed_GetBaton(sed) != SED_ABORT) {
/* format the field */
strcpy(sed_GetScratchPad(sed), sed_GetCurrRecord(sed));
sed_SetCurrRecord(sed, (char *)sed_GetCurrVar(sed));
if (valid_Format(sed, sed_GetFieldNo(sed), (char *) sed_GetCurrFieldData(sed, 2))) {
strcpy((char *)sed_GetCurrVar(sed), sed_GetCurrRecord(sed));
}
sed_SetCurrRecord(sed, sed_GetScratchPad(sed));
}
return(std_fexit(sed));
}