home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
FUNCS
/
FNRANGE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-28
|
2KB
|
117 lines
/*
fnrange.c 11/24/86
% range_funcs
Range functions.
Displays a bar graph in the field dependent on the value in
the variable.
Note: SED_ABORT will not affect this function.
The field variable should be a int *.
The int should be between 1 and 10, inclusive.
C-scape 3.2
Copyright (c) 1986, 1987, 1988 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()
9/15/88 jmd removed vid_Cursor calls
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
*/
#include <stdio.h>
#include <ctype.h>
#include "cscape.h"
#include "fnfunc.h" /* for field functions */
#include "strdecl.h" /* for C-scape string functions */
#include "ostdlib.h" /* for int_min */
#include "scancode.h"
#define RANGE_CHAR '*'
OGLOBAL field_funcs_struct range_funcs = {
stdNoCur_fenter,
std_fexit,
range_fkey,
range_senter,
FNULL,
sizeof(int)
};
void range_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 LEFT:
if (*((int *) sed_GetCurrVar(sed)) > 1) {
(*((int *) sed_GetCurrVar(sed)))--;
range_senter(sed, sed_GetFieldNo(sed));
sed_UpdateCurrField(sed);
}
break;
case RIGHT:
if (*((int *) sed_GetCurrVar(sed)) < 10) {
(*((int *) sed_GetCurrVar(sed)))++;
range_senter(sed, sed_GetFieldNo(sed));
sed_UpdateCurrField(sed);
}
break;
default:
key = ascii(scancode);
if (isdigit(key)) {
if (key == '0') {
*((int *) sed_GetCurrVar(sed)) = 10;
}
else {
*((int *) sed_GetCurrVar(sed)) = key - '0';
}
range_senter(sed, sed_GetFieldNo(sed));
sed_UpdateCurrField(sed);
}
break;
}
/* reset baton */
sed_SetBaton(sed, -1);
}
void range_senter(sed_type sed, int fieldno)
/*
Convert native int type to bar graph string for record.
*/
{
int val;
val = int_min( *((int *) sed_GetVar(sed, fieldno)),
sed_GetRecordLen(sed, fieldno));
strfill(sed_GetScratchPad(sed), RANGE_CHAR, val);
sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
}