home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / SOURCE / G4.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-22  |  21.4 KB  |  944 lines

  1. /* g4.c    (c)Copyright Sequiter Software Inc., 1987-1990.  All rights reserved.
  2.  
  3.    GET Routines
  4. */
  5.  
  6. #include "w4.h"
  7. #include "d4all.h"
  8. #include "g4char.h"
  9. #include "p4misc.h"
  10.  
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <ctype.h>
  14.  
  15. #ifndef UNIX
  16. #include <io.h>
  17. #include <dos.h>
  18. #endif
  19.  
  20. #ifdef LANGUAGE
  21.    #define YES_CHAR    'J'
  22.    #define YES_CHAR_LC 'j'
  23. #else
  24.    #define YES_CHAR    'Y'
  25.    #define YES_CHAR_LC 'y'
  26. #endif
  27.  
  28. extern    CB_WINDOW *v4window_ptr ;
  29. extern  int     v4cur_window ;
  30.  
  31. extern  GET   *v4get ;
  32. static    int   insert =    0 ;
  33. static  long  prev_attribute = 7 ;
  34.  
  35. static void  g4check_get( GET * ) ;
  36. static int   g4from_data( GET *, char * ) ;
  37. static void  g4display_get( GET * ) ;
  38. static int   g4fill_data( GET *, char *, char * ) ;
  39. static int   g4right_pos( int, int, char * ) ;
  40. static int   g4num_pos( int, int, char * ) ;
  41.  
  42.  
  43. /* Allocates some get memory */
  44.  
  45. GET *  g4alloc( int row, int col, void *data_ptr, char type )
  46. {
  47.    GET *  get_ptr ;
  48.  
  49.    if (v4get == (GET *) 0)  
  50.       if ( h4create( (char **) &v4get, 20, sizeof(GET), 10) < 0)  return( (GET *) 0 ) ;
  51.  
  52.    v4window_ptr->last_get =  h4get( (char **) &v4get, v4window_ptr->last_get ) ;
  53.    if ( v4window_ptr->last_get < 0 )  return( (GET *) 0 ) ;
  54.  
  55.    if ( v4window_ptr->first_get < 0 )
  56.       v4window_ptr->first_get =  v4window_ptr->last_get ;
  57.  
  58.    get_ptr =  v4get+  v4window_ptr->last_get ;
  59.    get_ptr->window_ref =  v4cur_window ;
  60.    get_ptr->num_decimals =  -1 ;   /* Not Yet Set Flag */
  61.    get_ptr->attribute =  v4window_ptr->get_attribute ;
  62.    memcpy( get_ptr->delimiter, v4window_ptr->get_delimiter,
  63.        sizeof(get_ptr->delimiter) ) ;
  64.  
  65.    get_ptr->row  =  row ;
  66.    get_ptr->col  =  col ;
  67.    get_ptr->type =  type ;
  68.    get_ptr->data =  data_ptr ;
  69.  
  70.    return( get_ptr ) ;
  71. }
  72.  
  73.  
  74. void  g4( int row, int col, char *buffer )
  75. {
  76.    g4alloc( row, col, (void *) buffer, 'C' ) ;
  77. }
  78.  
  79.  
  80. long  g4attribute( long attribute )
  81. {
  82.    v4window_ptr->get_attribute =  attribute ;
  83.    return ( v4window_ptr->get_attribute ) ;
  84. }
  85.  
  86.  
  87. void  g4call( GET_ROUTINE *routine, int call_data )
  88. {
  89.    v4get[ v4window_ptr->last_get].call =  routine ;
  90.    v4get[ v4window_ptr->last_get].call_data =  call_data ;
  91. }
  92.  
  93.  
  94. void  g4date( int row, int column, char *date_ptr )
  95. {
  96.    g4alloc( row, column, date_ptr, 'D' ) ;
  97. }
  98.  
  99.  
  100. void  g4delimiter( char *delimiter )
  101. {
  102.    memcpy( v4window_ptr->get_delimiter, delimiter, 2 ) ;
  103. }
  104.  
  105.  
  106. void  g4double( int row, int column, double *double_ptr )
  107. {
  108.    g4alloc( row, column, (void *) double_ptr, 'd' ) ;
  109. }
  110.  
  111.  
  112. void  g4int( int row, int column, int *int_ptr )
  113. {
  114.    g4alloc( row, column, int_ptr, 'i' ) ;
  115. }
  116.  
  117.  
  118. void  g4logical( int row, int column, int *logical_ptr )
  119. {
  120.    g4alloc( row, column, (void *) logical_ptr, 'L' ) ;
  121. }
  122.  
  123. void  g4long( int row, int column, long *long_ptr )
  124. {
  125.    g4alloc( row, column, (void *) long_ptr, 'l' ) ;
  126. }
  127.  
  128.  
  129. void  g4message( char *message )
  130. {
  131.    if ( v4window_ptr->last_get < 0 )  return ;
  132.    v4get[ v4window_ptr->last_get].message =  message ;
  133. }
  134.  
  135.  
  136. void  g4numeric( int row, int column, char *num_ptr )
  137. {
  138.    g4alloc( row, column, num_ptr, 'N' ) ;
  139. }
  140.  
  141.  
  142. void  g4picture( char *picture )
  143. {
  144.    if ( v4window_ptr->last_get < 0 )  return ;
  145.    v4get[ v4window_ptr->last_get].picture  =    picture ;
  146. }
  147.  
  148.  
  149. void  g4upper()
  150. {
  151.    v4get[ v4window_ptr->last_get].upper_convert =  1 ;
  152. }
  153.  
  154.  
  155. #ifdef KR
  156.    void  g4valid( routine )
  157.    int (*routine)() ;
  158. #else
  159.    void  g4valid( int (*routine)(GET *) )
  160. #endif
  161. {
  162.    if ( v4window_ptr->last_get < 0 )  return ;
  163.    v4get[ v4window_ptr->last_get].valid  =  routine ;
  164. }
  165.  
  166.  
  167. void  g4width( int width_data, int width_scr )
  168. {
  169.    GET *get_ptr ;
  170.    if ( v4window_ptr->last_get < 0 ) return ;
  171.  
  172.    get_ptr =  v4get+ v4window_ptr->last_get ;
  173.  
  174.    if ( width_data > 0 )
  175.       get_ptr->width_data =   width_data ;
  176.    if ( width_scr > 0 )
  177.       v4get[ v4window_ptr->last_get].width_scr =   width_scr ;
  178. }
  179.  
  180.  
  181. static void  g4check_get( GET *get_ptr )
  182. {
  183.    int      picture_len, i ;
  184.    char  *ptr ;
  185.  
  186.    if ( get_ptr->picture == (char *) 0)
  187.       picture_len =  0 ;
  188.    else
  189.    {
  190.       picture_len =  (int) strlen( get_ptr->picture) ;
  191.    }
  192.  
  193.    switch( get_ptr->type )
  194.    {
  195.       case 'C':
  196.       case 'N':
  197.       case 'D':
  198.      if ( get_ptr->width_data <= 0)
  199.         get_ptr->width_data =  picture_len ;
  200.      if ( get_ptr->width_data <= 0)
  201.      {
  202.         if ( get_ptr->type == 'D' )
  203.            get_ptr->width_data =  (int) strlen(v4default_date) ; 
  204.         else
  205.            get_ptr->width_data =  (int) strlen( (char *) get_ptr->data ) ;
  206.      }
  207.      if ( get_ptr->width_data <= 0 )
  208.         get_ptr->width_data =  1 ;
  209.      if ( get_ptr->width_scr <= 0 || get_ptr->width_scr > get_ptr->width_data)
  210.         get_ptr->width_scr =  get_ptr->width_data ;
  211.  
  212.      if ( get_ptr->type == 'N' )
  213.      {
  214.         if ( picture_len > 0 )
  215.            ptr =  get_ptr->picture ;
  216.         else
  217.            ptr =  (char *) get_ptr->data ;
  218.  
  219.         for ( i=1; i<= get_ptr->width_data && *ptr != '\000'; i++, ptr++ )
  220.            if ( *ptr == '.' )
  221.            {
  222.           get_ptr->num_decimals =  get_ptr->width_data - i ;
  223.           break ;
  224.            }
  225.  
  226.         if ( get_ptr->num_decimals < 0 )  get_ptr->num_decimals = 0 ;
  227.      }
  228.      break ;
  229.  
  230.       case 'L':
  231.      get_ptr->width_data =    get_ptr->width_scr =  1 ;
  232.      break ;
  233.  
  234.       case 'l':
  235.       case 'i':
  236.      if ( get_ptr->width_scr <= 0)
  237.      {
  238.         if ( picture_len > 0 )
  239.            get_ptr->width_scr =  picture_len ;
  240.         else
  241.         {
  242.            if ( get_ptr->type == 'l' )
  243.           get_ptr->width_scr =  8 ;
  244.            else
  245.           get_ptr->width_scr =  4 ;
  246.         }
  247.      }
  248.      get_ptr->width_data =    get_ptr->width_scr ;
  249.      break ;
  250.  
  251.       case 'd':
  252.      if ( picture_len > 0 )
  253.      {
  254.         ptr =  strchr( get_ptr->picture, '.' ) ;
  255.         if ( ptr == (char *) 0)
  256.            get_ptr->num_decimals =    0 ;
  257.         else
  258.            get_ptr->num_decimals =
  259.              picture_len - (int) (ptr-get_ptr->picture) -1;
  260.  
  261.         get_ptr->width_scr =  picture_len ;
  262.      }
  263.      else
  264.      {
  265.         if ( get_ptr->width_scr <= 0)  get_ptr->width_scr =  8 ;
  266.         if ( get_ptr->num_decimals < 0)
  267.            get_ptr->num_decimals =    2 ;
  268.         if ( get_ptr->num_decimals >= get_ptr->width_scr)
  269.            get_ptr->num_decimals = 0 ;
  270.      }
  271.  
  272.      get_ptr->width_data =    get_ptr->width_scr ;
  273.      break ;
  274.    }
  275. }
  276.  
  277.  
  278. #define  PICTURE_CHRS  "!9#ALNYXCMD"
  279.  
  280. static int  g4from_data( GET *get_ptr, char *chr_buf )
  281. {
  282.    char *ptr, pict_char ;
  283.    int    i, len ;
  284.  
  285.    if ( get_ptr->type == 'd' )
  286.    {
  287.       ptr = c4dtoa( * ((double *) get_ptr->data), get_ptr->width_scr,
  288.                   get_ptr->num_decimals);
  289.       memcpy( chr_buf, ptr, (size_t) get_ptr->width_scr ) ;
  290.       return( get_ptr->width_scr ) ;
  291.    }
  292.  
  293.    if ( get_ptr->type == 'l' )
  294.    {
  295.       c4ltoa( * ((long *) get_ptr->data), chr_buf, get_ptr->width_scr ) ;
  296.       return( get_ptr->width_scr ) ;
  297.    }
  298.  
  299.    if ( get_ptr->type == 'i' )
  300.    {
  301.       c4ltoa((long) (* ((int *)get_ptr->data)), chr_buf, get_ptr->width_scr) ;
  302.       return( get_ptr->width_scr ) ;
  303.    }
  304.  
  305.    if ( get_ptr->type == 'D' )
  306.    {
  307.       if ( get_ptr->picture == (char *) 0 )
  308.       {
  309.      ptr =    c4dt_format( (char *) get_ptr->data, v4default_date ) ;
  310.      len =  (int) strlen(v4default_date ) ;
  311.       }
  312.       else
  313.       {
  314.      ptr =    c4dt_format( (char *) get_ptr->data, get_ptr->picture ) ;
  315.      len =  (int) strlen( get_ptr->picture ) ;
  316.       }
  317.  
  318.       memcpy( chr_buf, ptr, (size_t) len ) ;
  319.       return( len ) ;
  320.    }
  321.  
  322.    if ( get_ptr->type == 'L' )
  323.    {
  324.       if ( get_ptr->picture == (char *) 0 )
  325.      pict_char =  'L' ;
  326.       else
  327.      pict_char =  get_ptr->picture[0] ;
  328.  
  329.       if ( * ((int *) get_ptr->data) )
  330.       {
  331.      if ( pict_char == 'L' )
  332.         chr_buf[0] = 'T' ;
  333.      else
  334.         chr_buf[0] = YES_CHAR ;
  335.       }
  336.       else
  337.       {
  338.      if ( pict_char == 'L' )
  339.         chr_buf[0] =  'F' ;
  340.      else
  341.         chr_buf[0] =  'N' ;
  342.       }
  343.       return 1 ;
  344.    }
  345.  
  346.    if ( get_ptr->type == 'N' && get_ptr->num_decimals > 0 )
  347.    {
  348.       ( (char *)get_ptr->data )
  349.      [ get_ptr->width_data - get_ptr->num_decimals - 1] = '.' ;
  350.    }
  351.  
  352.    memcpy( chr_buf, get_ptr->data, (size_t) get_ptr->width_data ) ;
  353.  
  354.    ptr =  get_ptr->picture ;
  355.    if ( ptr != (char *) 0)
  356.       for ( i= 0; *ptr != '\000'; i++, ptr++ )
  357.       {
  358.      if ( strchr( PICTURE_CHRS, *ptr) == (char *) 0 )
  359.         chr_buf[i] =  get_ptr->picture[i] ;
  360.          #ifdef LANGUAGE
  361.             if ( *ptr == 'Y' || *ptr == 'L' )
  362.             {
  363.                if ( chr_buf[i] == 'Y' )
  364.                   chr_buf[i] = YES_CHAR ;
  365.                if ( chr_buf[i] == 'y' )
  366.                   chr_buf[i] = YES_CHAR_LC ;
  367.             }
  368.          #endif
  369.       }
  370.  
  371.    return( get_ptr->width_data ) ;
  372. }
  373.  
  374.  
  375. static void  g4display_get( GET *get_ptr )
  376. {
  377.    char  buf[MAX_GET_WIDTH] ;
  378.  
  379.    g4from_data( get_ptr, buf ) ;
  380.  
  381.    if ( get_ptr->delimiter[0] != '\000' )
  382.    {
  383.       w4attribute( prev_attribute ) ;
  384.       w4num( get_ptr->row, get_ptr->col-1, get_ptr->delimiter, 1 ) ;
  385.    }
  386.  
  387.    w4attribute( get_ptr->attribute ) ;
  388.    w4num( get_ptr->row, get_ptr->col, buf, get_ptr->width_scr ) ;
  389.  
  390.    if ( get_ptr->delimiter[1] != '\000' )
  391.    {
  392.       w4attribute( prev_attribute ) ;
  393.       w4num( get_ptr->row, get_ptr->col+get_ptr->width_scr,
  394.          get_ptr->delimiter+1, 1 ) ;
  395.    }
  396. }
  397.  
  398.  
  399. void  g4display()
  400. {
  401.    GET     *get_ptr  ;
  402.    int      on_get   ;
  403.  
  404.    prev_attribute =  v4window_ptr->attribute ;
  405.  
  406.    on_get =  v4window_ptr->last_get ;
  407.  
  408.    while ( on_get >= 0 )
  409.    {
  410.       get_ptr =  v4get+ on_get ;
  411.  
  412.       g4check_get( get_ptr ) ;
  413.       g4display_get( get_ptr ) ;
  414.  
  415.       on_get =    get_ptr->prev ;
  416.    }
  417.  
  418.    v4window_ptr->attribute =  prev_attribute ;
  419. }
  420.  
  421.  
  422. static g4fill_data( GET *get_ptr, char *buffer, char *picture )
  423. {
  424.    /* Transfer Back to    get_ptr->data */
  425.    switch ( get_ptr->type )
  426.    {
  427.       case 'd':
  428.      *((double *)get_ptr->data) =
  429.              c4atod( buffer, get_ptr->width_scr ) ;
  430.      break ;
  431.  
  432.       case 'N':
  433.      memcpy( get_ptr->data,
  434.          c4dtoa( c4atod(buffer, get_ptr->width_data),
  435.              get_ptr->width_data, get_ptr->num_decimals),
  436.          (size_t) get_ptr->width_data ) ;
  437.      break ;
  438.  
  439.       case 'i':
  440.      *((int *)get_ptr->data) =
  441.          (int) c4atoi( (char *) buffer, get_ptr->width_scr ) ;
  442.      break ;
  443.  
  444.       case 'l':
  445.      buffer[get_ptr->width_scr] =  '\000' ;
  446.      *((long *)get_ptr->data) =  (long) atol( (char *) buffer ) ;
  447.      break ;
  448.  
  449.       case 'D':
  450.      memcpy( get_ptr->data, c4dt_unformat((char *) buffer, picture), 8) ;
  451.      break;
  452.  
  453.       case 'L':
  454.      if ( buffer[0] == (int) YES_CHAR  ||  buffer[0] == (int) 'T' ||
  455.           buffer[0] == (int) 't' || buffer[0] == (int) YES_CHAR_LC )
  456.         *((int *)get_ptr->data) =  1 ;
  457.      else
  458.         *((int *)get_ptr->data) =  0 ;
  459.      break ;
  460.  
  461.       default:
  462.      memcpy( get_ptr->data, buffer, (size_t) get_ptr->width_data ) ;
  463.          #ifdef LANGUAGE
  464.             if ( picture != 0 )
  465.             {
  466.                int i ;
  467.                for ( i = 0; picture[i] != 0 ; i++ )
  468.           if ( get_ptr->picture[i] == 'Y' || get_ptr->picture[i] == 'L' )
  469.                      if ( buffer[i] == YES_CHAR )
  470.                      {
  471.                         char *temp_ptr ;
  472.                         temp_ptr =  (char *) get_ptr->data ;
  473.                         temp_ptr[i] =  'Y' ;
  474.                      }
  475.             }
  476.          #endif
  477.      break ;
  478.    }
  479.  
  480.    return 0 ;
  481. }
  482.  
  483.  
  484. static    g4right_pos( int buffer_pos, int width_data, char *picture )
  485. {
  486.    buffer_pos++ ;
  487.  
  488.    while ( buffer_pos < width_data )
  489.       if ( strchr(PICTURE_CHRS,picture[buffer_pos]) == 0)
  490.      buffer_pos++ ;
  491.       else
  492.      break ;
  493.  
  494.    if ( buffer_pos == width_data)
  495.    {
  496.       buffer_pos-- ;
  497.       while (buffer_pos > 0 &&
  498.        strchr(PICTURE_CHRS,picture[buffer_pos]) == 0) buffer_pos-- ;
  499.    }
  500.  
  501.    return  buffer_pos ;
  502. }
  503.  
  504.  
  505. /* Counts the Number of Positions to the Next Picture Data Character */
  506.  
  507. static    g4num_pos( int buffer_pos, int width_data, char *picture )
  508. {
  509.    int    on_pos ;
  510.  
  511.    on_pos =  buffer_pos ;
  512.  
  513.    while ( on_pos < width_data )
  514.       if ( strchr(PICTURE_CHRS,picture[on_pos]) == 0)
  515.      break ;
  516.       else
  517.      on_pos++ ;
  518.  
  519.    return ( on_pos - buffer_pos ) ;
  520. }
  521.  
  522.  
  523. static int  bell_flag =  0 ;
  524.  
  525. int  g4bell_set( int set_flag )
  526. {
  527.    if ( set_flag >= 0 )   bell_flag =  set_flag ;
  528.  
  529.    return ( bell_flag ) ;
  530. }
  531.  
  532.  
  533. void  g4bell()
  534. {
  535.    if ( bell_flag )  write( 1, "\7", 1 ) ;
  536. }
  537.  
  538.  
  539. g4read()
  540. {
  541.    int      get_on, get_new, first, buffer_pos, buffer_off, buffer_width ;
  542.    int      cur_pos, num, ok, i ;
  543.    int    rc ;
  544.    GET     *get_ptr ;
  545.    char   chr ;
  546.    char   buffer[MAX_GET_WIDTH], picture[MAX_GET_WIDTH] ;
  547.  
  548.    g4display() ;
  549.    prev_attribute =  v4window_ptr->attribute ;
  550.  
  551.    first  =  1 ;
  552.    get_on =  v4window_ptr->first_get ;
  553.    if ( get_on < 0 )  return 0 ;
  554.  
  555.    for (;;)
  556.    {
  557.       if ( first )  /* First time for this 'get' */
  558.       {
  559.      first =  0 ;
  560.      buffer_pos =  buffer_off =  0 ;
  561.  
  562.      get_ptr =  v4get +  get_on ;
  563.      g4message_do( get_ptr->message ) ;
  564.  
  565.      /* Buffer is filled and the width is returned by 'g4from_data' */
  566.      buffer_width =  g4from_data( get_ptr, buffer ) ;
  567.      buffer[buffer_width] =  '\000' ;
  568.  
  569.      memset( picture, 0, (size_t) sizeof(picture) ) ;
  570.      if ( get_ptr->picture != (char *) 0 )
  571.         strncpy( picture, get_ptr->picture, sizeof(picture) ) ;
  572.      else
  573.      {
  574.         switch( get_ptr->type )
  575.         {
  576.            case 'D':
  577.           strcpy( picture, v4default_date ) ;
  578.           break ;
  579.  
  580.            case 'N':
  581.            case 'd':
  582.            case 'i':
  583.           memset( picture, (int) '#', (size_t) get_ptr->width_scr ) ;
  584.           if ( get_ptr->num_decimals > 0)
  585.           {
  586.              i =  get_ptr->width_scr - get_ptr->num_decimals - 1 ;
  587.              buffer[i] =  picture[i] =    '.' ;
  588.           }
  589.           break ;
  590.  
  591.            case 'L':
  592.           picture[0] = 'L' ;
  593.           picture[1] = '\000' ;
  594.           break ;
  595.         }
  596.      }
  597.       }
  598.  
  599.       w4attribute( get_ptr->attribute ) ;
  600.  
  601.       if ( buffer_pos >= buffer_width )
  602.       {
  603.      rc =  RETURN ;
  604.      w4num( get_ptr->row, get_ptr->col, buffer, get_ptr->width_scr ) ;
  605.       }
  606.       else
  607.       {
  608.      rc =  0 ;
  609.  
  610.      if ( strchr( PICTURE_CHRS, picture[buffer_pos] ) == (char *) 0  &&
  611.           (int) picture[buffer_pos] >= 0x20  &&  
  612.               (int) picture[buffer_pos] <= 0xFF)
  613.      {
  614.         buffer[buffer_pos] =  picture[buffer_pos] ;
  615.         buffer_pos++ ;
  616.         continue ;
  617.      }
  618.  
  619.      if ( buffer_off <= buffer_pos - get_ptr->width_scr )
  620.           buffer_off =  1+ buffer_pos - get_ptr->width_scr ;
  621.      if ( buffer_pos < buffer_off )  buffer_off =  buffer_pos ;
  622.      w4num(get_ptr->row,get_ptr->col,buffer+buffer_off,get_ptr->width_scr);
  623.      w4cursor( get_ptr->row, get_ptr->col+ buffer_pos - buffer_off ) ;
  624.  
  625.      if ( ! u4ptr_equal( (void *) get_ptr->call, (void *) 0) )
  626.      {
  627.         buffer[buffer_width] = '\000' ;
  628.         rc = (*get_ptr->call)( get_ptr, buffer, get_ptr->call_data);
  629.             get_ptr =  v4get + get_on ;
  630.         if ( rc == -1 )  continue ;
  631.      }
  632.      if ( rc == 0 )
  633.         rc =  g4char() ;
  634.      if ( (get_ptr->upper_convert ||  picture[buffer_pos] == '!')  &&  rc >= 0x20  &&  rc <= 0xFF )
  635.         rc =  u4toupper( rc ) ;
  636.       }
  637.  
  638.       switch ( rc )
  639.       {
  640.      case INS:
  641.      case CTRL_V:
  642.         insert =  ! insert ;
  643.         if ( insert )
  644.            w4cursor_size( 4, 7 ) ;
  645.         else
  646.            w4cursor_size( 6, 7 ) ;
  647.         continue ;
  648.  
  649.      case BACK_SPACE:
  650.      case LEFT:
  651.      case CTRL_S:
  652.         cur_pos =  buffer_pos - 1 ;
  653.  
  654.         while (cur_pos >= 0)
  655.            if ( strchr(PICTURE_CHRS,picture[cur_pos]) == 0 )
  656.           cur_pos-- ;
  657.            else
  658.           break ;
  659.  
  660.         if ( cur_pos < 0 )    continue ;
  661.  
  662.         buffer_pos =  cur_pos ;
  663.         if ( rc == LEFT || rc == CTRL_S )  continue ;
  664.  
  665.         /* BACK_SPACE is a LEFT and a DEL */
  666.  
  667.      case DEL:
  668.      case CTRL_G:
  669.  
  670.         num =  g4num_pos( buffer_pos, get_ptr->width_data, picture) ;
  671.         if ( num == 0 )  continue ;
  672.         memcpy( buffer+ buffer_pos, buffer + buffer_pos+1, (size_t) num ) ;
  673.         buffer[buffer_pos+num-1] = ' ' ;
  674.         continue ;
  675.  
  676.      case CTRL_Y:
  677.         cur_pos =  buffer_pos ;
  678.         memset( buffer + buffer_pos, (int) ' ',
  679.          (size_t) g4num_pos( buffer_pos, get_ptr->width_data, picture));
  680.         continue ;
  681.  
  682.      case RIGHT:
  683.      case CTRL_D:
  684.         buffer_pos =
  685.          g4right_pos( buffer_pos, get_ptr->width_data, picture);
  686.         continue ;
  687.  
  688.      case HOME:
  689.      case CTRL_A:
  690.         buffer_pos = 0;
  691.         continue;
  692.  
  693.      case END:
  694.      case CTRL_F:
  695.         buffer_pos =  get_ptr->width_data - 1;
  696.         while ( buffer_pos >= 0 )
  697.            if (buffer[buffer_pos] == ' ' || buffer[buffer_pos] == '\000')
  698.           buffer_pos-- ;
  699.            else
  700.           break ;
  701.  
  702.         buffer_pos =
  703.          g4right_pos( buffer_pos, get_ptr->width_data, picture);
  704.         continue ;
  705.       }
  706.  
  707.       if ( rc < 0x20 || rc > 0xFF )
  708.       {
  709.      switch( rc )
  710.      {
  711.         case CTRL_HOME:
  712.            first =    1 ;
  713.            get_new =  v4window_ptr->first_get ;
  714.            g4bell() ;
  715.            break ;
  716.  
  717.         case CTRL_END:
  718.            first =    1 ;
  719.            get_new =  v4window_ptr->last_get ;
  720.            g4bell() ;
  721.            break ;
  722.  
  723.         case UP:
  724.         case SHIFT_TAB:
  725.         case CTRL_Z:
  726.            first =    1 ;
  727.                get_new =  get_on ;
  728.            if ( get_ptr->prev >= 0 )   get_new =  get_ptr->prev ;
  729.            g4bell() ;
  730.            break ;
  731.  
  732.         case DOWN:
  733.         case RETURN:
  734.         case TAB:
  735.         case CTRL_B:
  736.            first =    1 ;
  737.            buffer_pos =  0 ;
  738.            get_new =  get_ptr->next ;
  739.            g4bell() ;
  740.            break ;
  741.  
  742.         /* Also Return if a Function Key was Pressed */
  743.         default:
  744.            if (rc == CTRL_W  ||  rc == CTRL_Q  ||
  745.                    rc == ESC || rc > 0xFF || rc < 0 )
  746.            {
  747.           get_new =  first =  -1 ;
  748.           g4bell() ;
  749.            }
  750.            break ;
  751.      }
  752.  
  753.      w4attribute( prev_attribute ) ;
  754.  
  755.      if ( first )
  756.      {
  757.         g4fill_data( get_ptr, buffer, picture ) ;
  758.  
  759.         if ( ! u4ptr_equal( (void *) get_ptr->valid, (void *) 0)  &&
  760.          rc != ESC && rc != CTRL_Q )
  761.             {
  762.            if ( (*get_ptr->valid)( get_ptr ) )
  763.            {
  764.           get_ptr =  v4get + get_on ;
  765.           first = 0 ;  /* Not Valid */
  766.           continue ;
  767.            }
  768.                get_ptr =  v4get + get_on ;
  769.         }
  770.  
  771.         if ( get_ptr->type == 'D' && rc != ESC && rc != CTRL_Q )
  772.         {
  773.            double  temp_data ;
  774.            int     date_rc ;
  775.  
  776.            /* Date Check */
  777.            date_rc =  c4dt_julian( (char *) get_ptr->data, &temp_data ) ;
  778.            if ( date_rc == -1 )
  779.            {
  780.           first = 0 ;
  781.           get_ptr =  v4get + get_on ;
  782.           buffer[buffer_width] =  '\000' ;
  783.           w4display( " Illegal Date: ", buffer, (char *) 0) ;
  784.           continue ;
  785.            }
  786.         }
  787.  
  788.         get_on =  get_new ;
  789.  
  790.         g4display_get( get_ptr ) ;
  791.      }
  792.  
  793.      if ( get_on < 0 )
  794.      {
  795.         if ( v4window_ptr->release )   g4release(1) ;
  796.  
  797.         w4attribute( prev_attribute ) ;
  798.         g4message_do( "" ) ;
  799.         w4cursor( -1,-1 ) ;
  800.         return rc ;
  801.      }
  802.  
  803.      continue ;
  804.       }
  805.  
  806.       /* Check the Picture Template */
  807.  
  808.       if ( picture[buffer_pos] != '\000' )
  809.       {
  810.      ok  =    0 ;
  811.      chr =    (char) rc ;
  812.  
  813.      switch( picture[buffer_pos] )
  814.      {
  815.         case '9':
  816.         case '#':
  817.            if ( chr >= '0' && chr <= '9' )  ok = 1 ;
  818.            if ( (chr == '+' || chr == '-' || chr == ' ')    &&
  819.                    picture[buffer_pos] == '#')
  820.           ok =    1 ;
  821.  
  822.            if ( chr == '.'  &&  get_ptr->num_decimals > 0 )
  823.            {
  824.           int  num_shift ;
  825.  
  826.           num_shift =  get_ptr->width_scr - get_ptr->num_decimals -
  827.                    buffer_pos - 1 ;
  828.  
  829.           if ( --buffer_pos < 0 )  buffer_pos = 0 ;
  830.  
  831.           if ( num_shift > 0  &&  buffer[buffer_pos] != ' ' )
  832.           {
  833.              memmove( buffer+ num_shift, buffer,
  834.                   (size_t) (get_ptr->width_scr - num_shift) ) ;
  835.              memset( buffer, (int) ' ', (size_t) num_shift ) ;
  836.           }
  837.  
  838.           buffer_pos = get_ptr->width_scr - get_ptr->num_decimals-1;
  839.           memset( buffer+ buffer_pos+1, (int) '0',
  840.               (size_t) get_ptr->num_decimals);
  841.           ok = 1 ;
  842.            }
  843.            break ;
  844.  
  845.         case 'A':
  846.            if ( chr >= 'A' && chr <= 'Z'  ||
  847.             chr >= 'a' && chr <= 'z' )     ok =  1 ;
  848.            break ;
  849.  
  850.         case 'L':
  851.            rc =  (char) u4toupper( rc ) ;
  852.            if ( rc == YES_CHAR || rc == 'N' || rc == 'T' || rc == 'F' )
  853.           ok = 1;
  854.            break ;
  855.  
  856.         case 'N':
  857.            if ( chr >= 'A' && chr <= 'Z'  ||
  858.             chr >= 'a' && chr <= 'z'  ||
  859.             chr >= '0' && chr <= '9'  )     ok =  1 ;
  860.            break ;
  861.  
  862.         case 'Y':
  863.            if ( get_ptr->type == 'D' )  /* Date Type: 'Y' for year */
  864.            {
  865.           if ( chr >= '0'  &&  chr <= '9' || chr == ' ' )  ok =  1 ;
  866.            }
  867.            else
  868.            {
  869.           rc =  (char) u4toupper( rc ) ;
  870.           if ( rc == YES_CHAR ||  rc == 'N' )  ok =  1 ;
  871.            }
  872.            break ;
  873.  
  874.         case 'X':
  875.         case '!':
  876.            ok =  1 ;
  877.            break ;
  878.  
  879.         case 'C':
  880.         case 'D':
  881.            if ( get_ptr->type == 'D' &&
  882.             (chr >= '0'  &&  chr <= '9' ||  chr == ' ')  )
  883.           ok =    1 ;
  884.            break ;
  885.  
  886.         case 'M':
  887.            if ( get_ptr->type == 'D' )
  888.            {
  889.           if ( chr == ' ' )
  890.           {
  891.              ok = 1 ;
  892.              break ;
  893.           }
  894.  
  895.           for ( num= i=0; picture[i] != '\000'; i++ )
  896.              if ( picture[i] == 'M' ) num++ ;
  897.  
  898.           if ( num > 2 )
  899.           {
  900.              if ( chr >= 'A' && chr <= 'Z'  ||
  901.               chr >= 'a' && chr <= 'z')  ok =  1 ;
  902.           } else
  903.           {
  904.              if ( chr >= '0' && chr <= '9')  ok =  1 ;
  905.           }
  906.            }
  907.            break ;
  908.      }
  909.       }
  910.       else
  911.      ok =  1 ;
  912.  
  913.       if ( ok )
  914.       {
  915.      if ( insert )
  916.      {
  917.         /* Insert the Character */
  918.         num =  g4num_pos( buffer_pos, get_ptr->width_data, picture) ;
  919.         if ( num > 1 )
  920.            memmove( buffer+buffer_pos+1, buffer+buffer_pos, (size_t) num-1) ;
  921.      }
  922.  
  923.      buffer[buffer_pos++] =  (char) rc ;
  924.       }
  925.       else
  926.      write( 1, "\7", 1 ) ;  /* Sound the Bell */
  927.    }
  928. }
  929.  
  930.  
  931. g4release( int do_release )
  932. {
  933.    v4window_ptr->release =  do_release ;
  934.  
  935.    if ( do_release )
  936.    {
  937.       h4free_chain( (char **) &v4get, v4window_ptr->last_get ) ;
  938.       v4window_ptr->last_get  =  -1 ;
  939.       v4window_ptr->first_get =  -1 ;
  940.    }
  941.  
  942.    return 0 ;
  943. }
  944.