home *** CD-ROM | disk | FTP | other *** search
- /*
- fnticker.c 2/3/87
-
- % ticker_funcs
-
- Ticker tape field functions.
- i.e. field variable is longer than record.
-
- NOTE: This routine is OBSOLETE. There is no reason to use
- ticker_funcs as C-scape now allows ANY field to be wider
- than its displayed width by using menu_Printf's Field width option.
-
- ALSO, the field var_size is incorrect, this func won't work in sleds.
-
- the variable is interpreted as follows:
- byte 0,1: length to the string
- byte 2,3: offset within the string
- byte 4..n the string.
-
- The various 'tick_' macros (in CSCAPE.H) are used to
- construct the tick_ variable
-
- The length of the tick_ array should be at least
- 2*sizeof(int) + 1 + the length of the string.
-
- NOTE: the length and offset are INTEGERS not unsigned
- as indicated in the manual. It is ok for the field
- to contain non-writeable positions.
-
- C-scape 3.2
- Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 11/15/87 jmd changed memcpy to memmove
- 4/06/88 jmd added call to sed_DoSpecial
- 7/23/88 jmd added oakland.h
- 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
- 12/08/90 pmcm changed std_fenter to stdNoCur_fenter
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- #include "cscape.h"
- #include "fnfunc.h" /* for field functions */
- #include "strdecl.h" /* for C-scape string functions */
- #include "scancode.h"
-
- #include "oakpriv.h" /* for memmove() macro */
-
- OSTATIC void tick_adjust(sed_type sed, char *tick, int delta);
- OSTATIC void tick_PushRight(sed_type sed, char *tick, char c);
- OSTATIC void tick_PullRight(sed_type sed, char *tick);
-
- OGLOBAL field_funcs_struct ticker_funcs = {
- stdNoCur_fenter,
- string_fexit,
- ticker_fkey,
- ticker_senter,
- FNULL,
- 0
- };
-
- void ticker_fkey(sed_type sed)
- {
- int scancode;
- char *tick;
-
- tick = (char *) sed_GetCurrVar(sed);
-
- 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 RIGHT:
- if (!sed_IsEnd(sed)) {
- sed_IncChar(sed);
- }
- else {
- tick_adjust(sed, tick, 1);
- }
- break;
- case LEFT:
- if (!sed_IsHome(sed)) {
- sed_DecChar(sed);
- }
- else {
- tick_adjust(sed, tick, -1);
- }
- break;
-
- case HOME:
- sed_GoHome(sed);
- tick_adjust(sed, tick, -(tick_GetLen(tick)));
- break;
- case END:
- sed_GoEnd(sed);
- tick_adjust(sed, tick, tick_GetLen(tick));
- break;
- case INS:
- if (kb_Insert()) {
- sed_SetCursorType(sed, CURSOR_HALF);
- }
- else {
- sed_SetCursorType(sed, CURSOR_NORMAL);
- }
- break;
- case BACKSPACE:
- if (!sed_IsHome(sed)) {
- sed_DecChar(sed);
- tick_PullRight(sed, tick);
- }
- else if (tick_GetOffset(tick) != 0) {
- tick_adjust(sed, tick, -1);
- tick_PullRight(sed, tick);
- }
- break;
- case DEL:
- tick_PullRight(sed, tick);
- break;
-
- default:
- if (isprint(ascii(scancode))) {
- if (kb_Insert()) {
- tick_PushRight(sed, tick, (char) ascii(scancode));
- }
- else {
- sed_Overwrite(sed, ascii(scancode));
- }
- if (!sed_IsEnd(sed)) {
- tick_adjust(sed, tick, 0); /* copy changes into var */
- sed_IncChar(sed);
- }
- else {
- tick_adjust(sed, tick, 1);
- }
- }
- break;
- }
- }
-
- void ticker_senter(sed_type sed, int fieldno)
- /*
- Copy the native ticker into the record string.
- */
- {
- char *tick;
-
- tick = (char *) sed_GetVar(sed, fieldno);
-
- /* pad the tick string */
- strpad(tick_GetString(tick), tick_GetLen(tick));
-
- sed_SetRecord(sed, tick_GetString(tick) + tick_GetOffset(tick), fieldno);
- }
-
- static void tick_adjust(sed_type sed, char *tick, int delta)
- /*
- Adjust the tick to a new offset;
- */
- {
- char *p, *q;
-
- /* check boundaries */
- if (tick_GetOffset(tick) + delta < 0) {
- delta = -(tick_GetOffset(tick));
- }
-
- if (tick_GetOffset(tick) + delta + sed_GetCurrRecordLen(sed) > tick_GetLen(tick)) {
- delta = tick_GetLen(tick) - (tick_GetOffset(tick) + sed_GetCurrRecordLen(sed));
- }
-
- /* copy record into variable */
- p = tick_GetString(tick) + tick_GetOffset(tick);
- q = sed_GetCurrRecord(sed);
- while(*q) {
- *p++ = *q++;
- }
-
- if (delta == 0) {
- return;
- }
-
- /* set new_offset */
- tick_SetOffset(tick, tick_GetOffset(tick) + delta);
- sed_RepaintField(sed, sed_GetFieldNo(sed));
- }
-
- static void tick_PushRight(sed_type sed, char *tick, char c)
- /*
- inserts c at the current position, pushes the
- characters to the right:
- */
- {
- char *p;
- int cnt, off;
-
- /* move over the other stuff */
-
- off = tick_GetOffset(tick) + sed_GetRecordPos(sed);
- cnt = tick_GetLen(tick) - off;
- p = tick_GetString(tick) + off;
-
- memmove(p + 1, p, cnt);
- p[cnt] = '\0';
-
- *p = c;
-
- sed_RepaintField(sed, sed_GetFieldNo(sed));
- }
-
- static void tick_PullRight(sed_type sed, char *tick)
- /*
- deletes character at the current position, pull the
- characters from the right:
- Put a space at the end.
- */
- {
- char *p;
- int cnt, off;
-
- /* move over the other stuff */
-
- off = tick_GetOffset(tick) + sed_GetRecordPos(sed);
- cnt = tick_GetLen(tick) - off;
- p = tick_GetString(tick) + off;
-
- memmove(p, p + 1, cnt);
- p[cnt - 1] = ' ';
-
- sed_RepaintField(sed, sed_GetFieldNo(sed));
- }
-