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

  1. /*
  2.      fnticker.c  2/3/87
  3.  
  4.     % ticker_funcs
  5.  
  6.     Ticker tape field functions.
  7.     i.e.  field variable is longer than record.
  8.  
  9.     NOTE:  This routine is OBSOLETE.  There is no reason to use
  10.     ticker_funcs as C-scape now allows ANY field to be wider
  11.     than its displayed width by using menu_Printf's Field width option.
  12.  
  13.     ALSO, the field var_size is incorrect, this func won't work in sleds.    
  14.  
  15.     the variable is interpreted as follows:
  16.     byte 0,1:     length to the string
  17.     byte 2,3:     offset within the string
  18.     byte 4..n    the string.
  19.  
  20.     The various 'tick_' macros (in CSCAPE.H) are used to
  21.     construct the tick_ variable
  22.  
  23.     The length of the tick_ array should be at least
  24.     2*sizeof(int) + 1 + the length of the string.
  25.  
  26.     NOTE: the length and offset are INTEGERS not unsigned
  27.           as indicated in the manual.  It is ok for the field
  28.           to contain non-writeable positions.
  29.  
  30.     C-scape 3.1
  31.     Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
  32.     ALL RIGHTS RESERVED.
  33.  
  34.     Revision History:
  35.     -----------------
  36.     11/15/87 jmd    changed memcpy to memmove
  37.      4/06/88 jmd     added call to sed_DoSpecial
  38.      7/23/88 jmd    added oakland.h
  39.      9/15/88 jmd     removed vid_Cursor calls
  40.      9/17/88 jmd     added std_ funcs
  41.     10/14/88 jdc    added var_size element to field_funcs_struct
  42.  
  43.      6/07/89 jmd    added test for mouse code (later removed)
  44. */
  45.  
  46. #include <stdio.h>
  47. #include <ctype.h>
  48. #include <string.h>
  49.  
  50. #include "cscape.h"
  51. #include "fnfunc.h"            /* for field functions */
  52. #include "strdecl.h"        /* for C-scape string functions */
  53. #include "scancode.h"
  54.  
  55. #include "oakpriv.h"        /* for memmove() macro */
  56.  
  57. void tick_adjust(_arg3(sed_type, char *, int));
  58. void tick_PullRight(_arg2(sed_type, char *));
  59. void tick_PushRight(_arg3(sed_type, char *, char));
  60.  
  61. OGLOBAL field_funcs_struct ticker_funcs = {
  62.     std_fenter,
  63.     string_fexit,
  64.     ticker_fkey,
  65.     ticker_senter,
  66.     FNULL,
  67.     0
  68. };
  69.  
  70. void ticker_fkey(sed)
  71.     sed_type sed;
  72. {
  73.     int     scancode;
  74.     char     *tick;
  75.  
  76.     tick = (char *) sed_GetCurrVar(sed);
  77.  
  78.     scancode = kb_Read();
  79.  
  80.     if (sed_DoSpecial(sed, scancode))
  81.         return;
  82.     if (special_key(sed, scancode))
  83.         return;
  84.     if (inter_field(sed, scancode))
  85.         return;
  86.     if (inter_page(sed, scancode))
  87.         return;
  88.  
  89.     switch(scancode) {
  90.     case RIGHT:
  91.         if (!sed_IsEnd(sed)) {
  92.             sed_IncChar(sed);
  93.         }
  94.         else {
  95.             tick_adjust(sed, tick, 1);
  96.         }
  97.         break;
  98.     case LEFT:
  99.         if (!sed_IsHome(sed)) {
  100.             sed_DecChar(sed);
  101.         }
  102.         else {
  103.             tick_adjust(sed, tick, -1);
  104.         }
  105.         break;
  106.  
  107.     case HOME:
  108.         sed_GoHome(sed);
  109.         tick_adjust(sed, tick, -(tick_GetLen(tick)));
  110.         break;
  111.     case END:
  112.         sed_GoEnd(sed);
  113.         tick_adjust(sed, tick, tick_GetLen(tick));
  114.         break;
  115.     case INS:
  116.         if (kb_Insert()) {
  117.             sed_SetCursorType(sed, CURSOR_HALF);
  118.         }
  119.         else {
  120.             sed_SetCursorType(sed, CURSOR_NORMAL);
  121.         }
  122.         break;
  123.     case BACKSPACE:
  124.         if (!sed_IsHome(sed)) {
  125.             sed_DecChar(sed);
  126.             tick_PullRight(sed, tick);
  127.         }
  128.         else if (tick_GetOffset(tick) != 0) {
  129.             tick_adjust(sed, tick, -1);
  130.             tick_PullRight(sed, tick);
  131.         }
  132.         break;
  133.     case DEL:
  134.         tick_PullRight(sed, tick);
  135.         break;
  136.  
  137.     default:
  138.         if (isprint(ascii(scancode))) {
  139.             if (kb_Insert()) {
  140.                 tick_PushRight(sed, tick, (char) ascii(scancode));
  141.             }
  142.             else {
  143.                 sed_Overwrite(sed, ascii(scancode));
  144.             }
  145.             if (!sed_IsEnd(sed)) {
  146.                 tick_adjust(sed, tick, 0);    /* copy changes into var */
  147.                 sed_IncChar(sed);
  148.             }
  149.             else {
  150.                 tick_adjust(sed, tick, 1);
  151.             }
  152.         }
  153.         break;
  154.     }
  155. }
  156.  
  157. void ticker_senter(sed, fieldno)
  158.     sed_type sed;
  159.     int fieldno;
  160. /*
  161.     Copy the native ticker into the record string.
  162. */
  163. {
  164.     char *tick;
  165.  
  166.     tick = (char *) sed_GetVar(sed, fieldno);
  167.  
  168.     /* pad the tick string */
  169.     strpad(tick_GetString(tick), tick_GetLen(tick));
  170.  
  171.     sed_SetRecord(sed, tick_GetString(tick) + tick_GetOffset(tick), fieldno);
  172. }
  173.  
  174. void tick_adjust(sed, tick, delta)
  175.     sed_type sed;
  176.     char      *tick;
  177.     int delta;
  178. /*
  179.     Adjust the tick to a new offset;
  180. */
  181. {
  182.     char *p, *q;
  183.  
  184.     /* check boundaries */
  185.     if (tick_GetOffset(tick) + delta < 0) {
  186.         delta = -(tick_GetOffset(tick));
  187.     }
  188.  
  189.     if (tick_GetOffset(tick) + delta + sed_GetCurrRecordLen(sed) > tick_GetLen(tick)) {
  190.         delta = tick_GetLen(tick) - (tick_GetOffset(tick) + sed_GetCurrRecordLen(sed));
  191.     }
  192.  
  193.     /* copy record into variable */
  194.     p = tick_GetString(tick) + tick_GetOffset(tick);
  195.     q = sed_GetCurrRecord(sed);
  196.     while(*q) {
  197.         *p++ = *q++;
  198.     }
  199.  
  200.     if (delta == 0) {
  201.         return;
  202.     }
  203.  
  204.     /* set new_offset */
  205.     tick_SetOffset(tick, tick_GetOffset(tick) + delta);
  206.      sed_RepaintField(sed, sed_GetFieldNo(sed));
  207. }
  208.  
  209. void tick_PushRight(sed, tick, c)
  210.     sed_type sed;
  211.     char      *tick;
  212.     char    c;
  213. /*
  214.     inserts c at the current position, pushes the
  215.             characters to the right:
  216. */
  217. {
  218.     char *p;
  219.     int cnt, off;
  220.  
  221.     /* move over the other stuff */
  222.  
  223.     off = tick_GetOffset(tick) + sed_GetRecordPos(sed);
  224.     cnt = tick_GetLen(tick) - off;
  225.     p = tick_GetString(tick) + off;
  226.  
  227.     memmove(p + 1, p, cnt);
  228.     p[cnt] = '\0';
  229.  
  230.     *p = c;
  231.  
  232.      sed_RepaintField(sed, sed_GetFieldNo(sed));
  233. }
  234.  
  235. void tick_PullRight(sed, tick)
  236.     sed_type sed;
  237.     char      *tick;
  238. /*
  239.     deletes character at the current position, pull the
  240.             characters from the right:
  241.     Put a space at the end.
  242. */
  243. {
  244.     char *p;
  245.     int cnt, off;
  246.  
  247.     /* move over the other stuff */
  248.  
  249.     off = tick_GetOffset(tick) + sed_GetRecordPos(sed);
  250.     cnt = tick_GetLen(tick) - off;
  251.     p = tick_GetString(tick) + off;
  252.  
  253.     memmove(p, p + 1, cnt);
  254.     p[cnt - 1] = ' ';
  255.  
  256.      sed_RepaintField(sed, sed_GetFieldNo(sed));
  257. }
  258.