home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
FNTOGINT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-31
|
5KB
|
205 lines
/*
fntogint.c
% togint_funcs, like toggle_funcs except the variable is an int
A field has multiple choices.
The Space bar changes the selection.
First letter searching.
The Variable is the number of the selected choice.
The choices are contained in the field's second data pointer in
the form "choice 1, choice 2, choice 3" (commas delimit).
The cursor is turned off.
Also toggles choice when clicked with a mouse.
(if mouse handler is attached to sed)
C-scape 3.2
Copyright (c) 1989 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
11/04/89 jdc changed toupper & tolower to otoupper & otolower
3/28/90 jmd ansi-fied
6/01/90 jmd changed index to indeks to avoid DG conflict
6/05/90 jmd changed the rest of index to indeks to avoid DG conflict
10/31/90 ted changed 'key' from char to int to avoid int/char compiler warning.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "cscape.h"
#include "fnfunc.h" /* for field functions */
#include "scancode.h"
#include "oakpriv.h" /* for memmove() macro */
OGLOBAL field_funcs_struct togint_funcs = {
stdNoCur_fenter,
std_fexit,
togint_fkey,
togint_senter,
togint_sexit,
sizeof(int)
};
#define DELIMITER ','
#define TOGINT_CHOICE_COUNT 100
OSTATIC char *togint_GetChoice(char *list, char *string, int indeks, int slen);
void togint_fkey(sed_type sed)
/*
Cycle through list of changes when the SPACE bar is pressed.
(or when mouse is clicked on the field)
*/
{
int scancode, i, fieldno, key;
char *list, choice;
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;
/* reset baton */
sed_SetBaton(sed, -1);
if ((list = (char *) sed_GetFieldData(sed, sed_GetFieldNo(sed), 1)) == NULL) {
return;
}
fieldno = sed_GetFieldNo(sed);
/* toggle on mouse click or spacebar */
if (scancode == MOU_CLICK || (ascii(scancode)) == ' ') {
for (i = 0; i < TOGINT_CHOICE_COUNT; i++) {
if (strncmp(togint_GetChoice(list, sed_GetScratchPad(sed),
i, sed_GetRecordLen(sed, fieldno)),
sed_GetCurrRecord(sed),
sed_GetRecordLen(sed, fieldno)) == 0) {
togint_GetChoice(list, sed_GetScratchPad(sed), i + 1,
sed_GetRecordLen(sed, fieldno));
sed_SetCurrRecord(sed, sed_GetScratchPad(sed));
sed_UpdateCurrField(sed);
break;
}
}
}
/* do first letter search */
else {
key = otolower(ascii(scancode));
for (i = 0; i < TOGINT_CHOICE_COUNT; i++) {
choice = otolower(*togint_GetChoice(list, sed_GetScratchPad(sed),
i, sed_GetRecordLen(sed, fieldno)));
if (choice == (char) key) {
sed_SetCurrRecord(sed, sed_GetScratchPad(sed));
sed_UpdateCurrField(sed);
break;
}
}
}
}
static char *togint_GetChoice(char *list, char *string, int indeks, int slen)
/*
Copies the next choice from the list into string.
Returns string.
List is of the form:
"choice 1,choice 2,choice 3" (commas delimit).
*/
{
int start_off, off, word_off;
int len, len1, count;
/* skip leading DELIMITERS */
for (start_off = 0; list[start_off] == DELIMITER; start_off++) {
;
}
for (word_off = off = start_off, count = 0, len1 = -1;; off++) {
if (list[off] == DELIMITER || list[off] == '\0') {
if ((len = off - word_off) > slen) {
len = slen;
}
if (len1 == -1) {
len1 = len;
}
if (count == indeks) {
memmove(string, list + word_off, len);
string[len] = '\0';
return(string);
}
if (list[off] == '\0') {
memmove(string, list + start_off, len1);
string[len1] = '\0';
return(string);
}
count++;
word_off = off + 1;
}
}
}
void togint_senter(sed_type sed, int fieldno)
/*
This function goes from the native int to the record string.
*/
{
char *list;
if ((list = (char *) sed_GetFieldData(sed, fieldno, 1)) == NULL) {
return;
}
togint_GetChoice(list, sed_GetScratchPad(sed),
*(int *)sed_GetVar(sed, fieldno), sed_GetRecordLen(sed, fieldno));
sed_SetRecord(sed, sed_GetScratchPad(sed), fieldno);
std_senter(sed, fieldno);
}
void togint_sexit(sed_type sed, int fieldno)
/*
Converts the record string into a int.
*/
{
int i;
char *list;
if (sed_GetBaton(sed) != SED_ABORT) {
if ((list = (char *) sed_GetFieldData(sed, fieldno, 1)) == NULL) {
return;
}
for (i = 0; i < TOGINT_CHOICE_COUNT; i++) {
if (strncmp(togint_GetChoice(list, sed_GetScratchPad(sed),
i, sed_GetRecordLen(sed, fieldno)), sed_GetRecord(sed, fieldno),
sed_GetRecordLen(sed, fieldno)) == 0) {
*(int *)sed_GetVar(sed, fieldno) = i;
return;
}
}
*(int *)sed_GetVar(sed, fieldno) = 0;
}
}