home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-4.ZIP / HDR_EXMP.ZIP / EXAMPLES.ZIP / D4LEARN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-14  |  53.0 KB  |  1,860 lines

  1.  
  2. /* d4learn.c,
  3.    (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
  4.  
  5.    Tests "Code Base" routines.
  6. */
  7.  
  8. #include "d4base.h"
  9. #include "w4.h"
  10. #include "g4char.h"
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #define   C_LEFT   10
  16. #define   C_MIDDLE 25
  17. #define   C_RIGHT  40
  18.  
  19. #define   INT      0
  20. #define   LONG     1
  21. #define   CHAR     2
  22. #define   CHAR_PTR 3
  23. #define   DOUB     4
  24. #define   DATE     5
  25. #define   VOID     6
  26. #define   MSG      7
  27.  
  28. static char  p_buffer[5][81] ;
  29. static int   p_on = 0 ;
  30. static int   result_ref, entry_ref ;
  31.  
  32. static int     rc_type = INT ;
  33. static int     rc ;
  34. static long    l_rc ;
  35. static char    c_rc, *s_rc, *s_msg, buffer[258], extra_buffer[258] ;
  36. static double  d_rc ;
  37.  
  38. extern char    *itoa(int, char *, int) ;
  39. extern int      v4cur_base, v4default_window ;
  40. extern CB_WINDOW  *v4window_ptr ;
  41. extern CB_WINDOW  *v4window ;
  42. extern MENU    *v4menu ;
  43. extern BASE    *v4base ;
  44. extern INDEX   *v4index ;
  45. extern BLOCK   *v4block ;
  46.  
  47. #ifdef TURBO
  48.    extern  unsigned  _stklen =  10000 ;
  49. #endif
  50.  
  51. typedef  int DO_ROUTINE(int,int) ;
  52. static  DO_ROUTINE  c4conv, x4ext, m4memo, e4expr, i4ind, f4field, d4data ;
  53. static  int   filter_set(void), filter_evaluate(void), index_help(void),
  54.           help(void), field_help(void), display_results(void),
  55.           p_reset(void), field_name_parm(void) ;
  56. static  void   activate_entry_window( int ) ;
  57. static  char  *s_get( int ) ;
  58. static  long   l_get( int ) ;
  59. static  int    i_get( int ) ;
  60. static  double d_get( int ) ;
  61. static  char *parm( char *) ;
  62. static  char *parm_default( char *, char *, int ) ;
  63.  
  64. char  title_buf[80] ;
  65.  
  66. main()
  67. {
  68.    int  i_ref, main_menu, conv, data, index, field, expr, ext, memo, pos ;
  69.  
  70.    /* Call 'd4init_memory' and 'w4init' to specify the exact amount of memory
  71.       needed.  Note that a call to 'd4init()' would work instead.  However, 
  72.       initializing in this manner saves some memory and reduces fragmentation. */
  73.    w4init( 15,6,135 ) ;
  74.    d4init_memory( 2,2,10,1500 ) ;      /* Initialize Code Base */
  75.  
  76.    w4popup() ;     /* Make the Error Window a Popup Window */
  77.    w4clear( -1 ) ;
  78.    w4cursor( -1,-1 ) ;
  79.  
  80.    entry_ref =  w4define( 0,0, 9,79 ) ;
  81.    w4title( 0,-1, title_buf, B_WHITE ) ;
  82.    w4border( DOUBLE, F_WHITE ) ;
  83.    w4popup() ;
  84.  
  85.    result_ref =  w4define( 9,0, 24,79 ) ;
  86.    w4border( DOUBLE, F_WHITE ) ;
  87.    w4title( 0,-1, " Return Code and Status Information ", B_WHITE ) ;
  88.    w4popup() ;
  89.  
  90.    main_menu =  w4define( -1,-1,-1,-1 ) ;
  91.    #ifdef UNIX
  92.       pos =  -1 ;
  93.    #else
  94.       n4key_special( 0,0, ALT_Q, ALT_M ) ;
  95.       pos =   0 ;
  96.    #endif
  97.    n4( "Conv." );      n4key( ALT_C, 0, pos); n4reaction( n4activate, &conv ) ;
  98.    n4start_item( n4( "Database" ) ) ;
  99.                n4key( ALT_D, 0, pos); n4reaction( n4activate, &data ) ;
  100.    n4( "Expression" ); n4key( ALT_E, 0, pos); n4reaction( n4activate, &expr ) ;
  101.    n4( "Field" );      n4key( ALT_F, 0, pos); n4reaction( n4activate, &field ) ;
  102.    n4( "Index" );      n4key( ALT_I, 0, pos); n4reaction( n4activate, &index ) ;
  103.    n4( "Memo" );       n4key( ALT_M, 0, pos); n4reaction( n4activate, &memo ) ;
  104.    #ifdef UNIX
  105.       n4( "Extended" );   n4key( ALT_X, 0,pos); n4reaction( n4activate, &ext ) ;
  106.    #else
  107.       n4( "Extended" );   n4key( ALT_X, 0, 1); n4reaction( n4activate, &ext ) ;
  108.    #endif
  109.    n4( "Help" );       n4key( ALT_H, 0, pos); n4action( help ) ;
  110.    n4( "Quit" );       n4key( ALT_Q, 0, pos); n4action( (ACTION *) 0, -1 ) ;
  111.  
  112.    conv =  w4define( -1,-1,-1,-1 ) ;
  113.    i_ref =  n4( "c4atod( char_string, len_string )" ) ;
  114.         n4key( (int) 'a', 0, 2 ) ;
  115.                 n4action( c4conv, (int) 'a', i_ref ) ;
  116.    i_ref =  n4( "c4atoi( char_string, len_string )" ) ;
  117.         n4key( (int) 'a', 0, 2 ) ;
  118.                 n4action( c4conv, (int) 'a' + 0x100, i_ref ) ;
  119.    i_ref =  n4( "c4atol( char_string, len_string )" ) ;
  120.         n4key( (int) 'a', 0, 2 ) ;
  121.                 n4action( c4conv, (int) 'a' + 0x200, i_ref ) ;
  122.    i_ref =  n4( "c4dtoa( double_value, len, dec )" ) ;
  123.         n4key( (int) 'd', 0, 2 ) ;
  124.                 n4action( c4conv, (int) 'd', i_ref ) ;
  125.    i_ref =  n4( "c4dt_format( dbf_date, picture )" ) ;
  126.         n4key( (int) 'd', 0, 2 ) ;
  127.                 n4action( c4conv, (int) 'd' + 0x100, i_ref ) ;
  128.    i_ref =  n4( "c4dt_unformat( date_data, picture )" ) ;
  129.         n4key( (int) 'd', 0, 2 ) ;
  130.                 n4action( c4conv, (int) 'd' + 0x200, i_ref ) ;
  131.    i_ref =  n4( "c4encode( to, from, t_to, t_from )" ) ;
  132.         n4key( (int) 'e', 0, 2 ) ;
  133.                 n4action( c4conv, (int) 'e', i_ref ) ;
  134.    i_ref =  n4( "c4ltoa( long_value, ptr, len )" ) ;
  135.         n4key( (int) 'l', 0, 2 ) ;
  136.                 n4action( c4conv, (int) 'l', i_ref ) ;
  137.  
  138.    data =  w4define( -1,-1,-1,-1 ) ;
  139.    i_ref =  n4( "d4bottom()" ) ;
  140.                 n4key( (int) 'b', 0, 2 ) ;
  141.                 n4action( d4data, (int) 'b', i_ref ) ;
  142.    i_ref =  n4( "d4close()" ) ;
  143.                 n4key( (int) 'c', 0, 2 ) ;
  144.                 n4action( d4data, (int) 'c', i_ref ) ;
  145.    i_ref =  n4( "d4create( name, ... )" ) ;
  146.                 n4key( (int) 'c', 0, 2 ) ;
  147.                 n4action( d4data, (int) 'c' + 0x100, i_ref ) ;
  148.    i_ref =  n4( "d4delete( rec_num )") ;
  149.                 n4key( (int) 'd', 0, 2 ) ;
  150.                 n4action( d4data, (int) 'd', i_ref ) ;
  151.    i_ref =  n4( "d4deleted()") ;
  152.                 n4key( (int) 'd', 0, 2 ) ;
  153.                 n4action( d4data, (int) 'd' + 0x100, i_ref ) ;
  154.    i_ref =  n4( "d4go( rec_num )") ;
  155.                 n4key( (int) 'g', 0, 2 ) ;
  156.                 n4action( d4data, (int) 'g', i_ref ) ;
  157.    i_ref =  n4( "d4lock( lock_code, wait )") ;
  158.                 n4key( (int) 'l', 0, 2 ) ;
  159.                 n4action( d4data, (int) 'l', i_ref ) ;
  160.    i_ref =  n4( "d4pack()") ;
  161.                 n4key( (int) 'p', 0, 2 ) ;
  162.                 n4action( d4data, (int) 'p', i_ref ) ;
  163.    i_ref =  n4( "d4recall(rec_num)") ;
  164.                 n4key( (int) 'r', 0, 2 ) ;
  165.                 n4action( d4data, (int) 'r', i_ref ) ;
  166.    i_ref =  n4( "d4reccount()") ;
  167.                 n4key( (int) 'r', 0, 2 ) ;
  168.                 n4action( d4data, (int) 'r'+ 0x100, i_ref ) ;
  169.    i_ref =  n4( "d4recno()") ;
  170.                 n4key( (int) 'r', 0, 2 ) ;
  171.                 n4action( d4data, (int) 'r'+ 0x200, i_ref ) ;
  172.    i_ref =  n4( "d4ref( name )") ;
  173.                 n4key( (int) 'r', 0, 2 ) ;
  174.         n4action( d4data, (int) 'r'+ 0x300, i_ref ) ;
  175.    i_ref =  n4( "d4seek( search_string )") ;
  176.                 n4key( (int) 's', 0, 2 ) ;
  177.                 n4action( d4data, (int) 's', i_ref ) ;
  178.    i_ref =  n4( "d4select( base_ref )") ;
  179.                 n4key( (int) 's', 0, 2 ) ;
  180.                 n4action( d4data, (int) 's' + 0x100, i_ref ) ;
  181.    i_ref =  n4( "d4skip( num_records )") ;
  182.                 n4key( (int) 's', 0, 2 ) ;
  183.                 n4action( d4data, (int) 's' + 0x200, i_ref ) ;
  184.    i_ref =  n4( "d4unlock( lock_code )") ;
  185.                 n4key( (int) 'u', 0, 2 ) ;
  186.                 n4action( d4data, (int) 'u', i_ref ) ;
  187.    i_ref =  n4( "d4use( name )") ;
  188.                 n4start_item( i_ref ) ;
  189.                 n4key( (int) 'u', 0, 2 ) ;
  190.                 n4action( d4data, (int) 'u' + 0x100, i_ref ) ;
  191.    i_ref =  n4( "d4top()") ;
  192.                 n4key( (int) 't', 0, 2 ) ;
  193.                 n4action( d4data, (int) 't', i_ref ) ;
  194.    i_ref =  n4( "d4write( rec_num )") ;
  195.                 n4key( (int) 'w', 0, 2 ) ;
  196.                 n4action( d4data, (int) 'w', i_ref ) ;
  197.    i_ref =  n4( "d4zap( start_rec, end_rec )") ;
  198.                 n4key( (int) 'z', 0, 2 ) ;
  199.                 n4action( d4data, (int) 'z', i_ref ) ;
  200.   
  201.    expr =  w4define( -1,-1,-1,-1 ) ;
  202.    i_ref =  n4( "e4eval( expression )" ) ;
  203.                 n4key( (int) 'e', 0, 2 ) ;
  204.                 n4action( e4expr, (int) 'e', i_ref ) ;
  205.    i_ref =  n4( "e4priority( operator_char )" ) ;
  206.                 n4key( (int) 'p', 0, 2 ) ;
  207.                 n4action( e4expr, (int) 'p', i_ref ) ;
  208.    i_ref =  n4( "e4type()" ) ;
  209.                 n4key( (int) 't', 0, 2 ) ;
  210.                 n4action( e4expr, (int) 't', i_ref ) ;
  211.  
  212.    field =  w4define( -1,-1,-1,-1 ) ;
  213.    i_ref =  n4( "Field Ref. Number Help" ) ;
  214.                 n4key( 'h', 0, 15 ) ;
  215.                 n4action( field_help, i_ref ) ;
  216.    n4skip_over( n4(""), 1 ) ;
  217.    i_ref =  n4( "f4decimals( field_ref )" ) ;
  218.                 n4key( (int) 'd', 0, 2 ) ;
  219.                 n4action( f4field, (int) 'd', i_ref ) ;
  220.    i_ref =  n4( "f4j_ref( j_field )" ) ;
  221.                 n4key( (int) 'j', 0, 2 ) ;
  222.                 n4action( f4field, (int) 'j', i_ref ) ;
  223.    i_ref =  n4( "f4name( field_ref )" ) ;
  224.                 n4key( (int) 'n', 0, 2 ) ;
  225.                 n4action( f4field, (int) 'n', i_ref ) ;
  226.    i_ref =  n4( "f4num_fields( )" ) ;
  227.                 n4key( (int) 'n', 0, 2 ) ;
  228.                 n4action( f4field, (int) 'n' + 0x100, i_ref ) ;
  229.    i_ref =  n4( "f4ptr( field_ref )" ) ;
  230.                 n4key( (int) 'p', 0, 2 ) ;
  231.                 n4action( f4field, (int) 'p', i_ref ) ;
  232.    i_ref =  n4( "f4record()" ) ;
  233.                 n4key( (int) 'r', 0, 2 ) ;
  234.                 n4action( f4field, (int) 'r', i_ref ) ;
  235.    i_ref =  n4( "f4record_width()" ) ;
  236.                 n4key( (int) 'r', 0, 2 ) ;
  237.                 n4action( f4field, (int) 'r' + 0x100, i_ref ) ;
  238.    i_ref =  n4( "f4ref( field_name )" ) ;
  239.                 n4key( (int) 'r', 0, 2 ) ;
  240.                 n4action( f4field, (int) 'r' + 0x200, i_ref ) ;
  241.    i_ref =  n4( "f4replace( field_ref, ptr )" ) ;
  242.                 n4key( (int) 'r', 0, 2 ) ;
  243.                 n4action( f4field, (int) 'r' + 0x300, i_ref ) ;
  244.    i_ref =  n4( "f4str( field_ref )" ) ;
  245.                 n4key( (int) 's', 0, 2 ) ;
  246.                 n4action( f4field, (int) 's', i_ref ) ;
  247.    i_ref =  n4( "f4true( field_ref )" ) ;
  248.                 n4key( (int) 't', 0, 2 ) ;
  249.                 n4action( f4field, (int) 't', i_ref ) ;
  250.    i_ref =  n4( "f4type( field_ref )" ) ;
  251.                 n4key( (int) 't', 0, 2 ) ;
  252.                 n4action( f4field, (int) 't' + 0x100, i_ref ) ;
  253.    i_ref =  n4( "f4value( field_ref )" ) ;
  254.                 n4key( (int) 'v', 0, 2 ) ;
  255.                 n4action( f4field, (int) 'v', i_ref ) ;
  256.    i_ref =  n4( "f4width( field_ref )" ) ;
  257.                 n4key( (int) 'w', 0, 2 ) ;
  258.                 n4action( f4field, (int) 'w', i_ref ) ;
  259.  
  260.    index =  w4define( -1,-1,-1,-1 ) ;
  261.    i_ref =  n4( "Index File Reference Number Help" ) ;
  262.                 n4key( (int) 'h', 0, 15) ;
  263.                 n4action( index_help, i_ref ) ;
  264.    n4skip_over( n4(""),1) ;
  265.    i_ref =  n4( "i4add( index_ref, key_ptr, rec_num )") ;
  266.                 n4key( (int) 'a', 0, 2 ) ;
  267.                 n4action( i4ind, (int) 'a', i_ref ) ;
  268.    i_ref =  n4( "i4bottom( index_ref )") ;
  269.                 n4key( (int) 'b', 0, 2 ) ;
  270.                 n4action( i4ind, (int) 'b', i_ref ) ;
  271.    i_ref =  n4( "i4check( index_ref )") ;
  272.                 n4key( (int) 'c', 0, 2 ) ;
  273.                 n4action( i4ind, (int) 'c', i_ref ) ;
  274.    i_ref =  n4( "i4close( index_ref )") ;
  275.                 n4key( (int) 'c', 0, 2 ) ;
  276.                 n4action( i4ind, (int) 'c' + 0x100, i_ref ) ;
  277.    i_ref =  n4( "i4eval( index_ref )") ;
  278.                 n4key( (int) 'e', 0, 2 ) ;
  279.                 n4action( i4ind, (int) 'e', i_ref ) ;
  280.    i_ref =  n4( "i4go( index_ref, key_ptr, rec_num )") ;
  281.                 n4key( (int) 'g', 0, 2 ) ;
  282.                 n4action( i4ind, (int) 'g', i_ref ) ;
  283.    i_ref =  n4( "i4index( name, expression, unique, safety )" ) ;
  284.                 n4key( (int) 'i', 0, 2 ) ;
  285.                 n4action( i4ind, (int) 'i', i_ref ) ;
  286.    i_ref =  n4( "i4lock( index_ref, wait )") ;
  287.                 n4key( (int) 'l', 0, 2 ) ;
  288.                 n4action( i4ind, (int) 'l', i_ref ) ;
  289.    i_ref =  n4( "i4open( name )") ;
  290.                 n4key( (int) 'o', 0, 2 ) ;
  291.                 n4action( i4ind, (int) 'o', i_ref ) ;
  292.    i_ref =  n4( "i4ref( name )") ;
  293.                 n4key( (int) 'r', 0, 2 ) ;
  294.                 n4action( i4ind, (int) 'r', i_ref ) ;
  295.    i_ref =  n4( "i4reindex( index_ref )") ;
  296.                 n4key( (int) 'r', 0, 2 ) ;
  297.                 n4action( i4ind, (int) 'r' + 0x100, i_ref ) ;
  298.    i_ref =  n4( "i4remove( index_ref, key_ptr, rec_num )") ;
  299.                 n4key( (int) 'r', 0, 2 ) ;
  300.                 n4action( i4ind, (int) 'r' + 0x200, i_ref ) ;
  301.    i_ref =  n4( "i4seek( index_ref, key_ptr )") ;
  302.                 n4key( (int) 's', 0, 2 ) ;
  303.                 n4action( i4ind, (int) 's', i_ref ) ;
  304.    i_ref =  n4( "i4seek_ref()") ;
  305.                 n4key( (int) 's', 0, 2 ) ;
  306.                 n4action( i4ind, (int) 's' + 0x100, i_ref ) ;
  307.    i_ref =  n4( "i4select( index_ref )") ;
  308.                 n4key( (int) 's', 0, 2 ) ;
  309.                 n4action( i4ind, (int) 's' + 0x200, i_ref ) ;
  310.    i_ref =  n4( "i4skip( index_ref, n )") ;
  311.                 n4key( (int) 's', 0, 2 ) ;
  312.                 n4action( i4ind, (int) 's' + 0x300, i_ref ) ;
  313.    i_ref =  n4( "i4top( index_ref )") ;
  314.                 n4key( (int) 't', 0, 2 ) ;
  315.                 n4action( i4ind, (int) 't', i_ref ) ;
  316.    i_ref =  n4( "i4type( index_ref )") ;
  317.                 n4key( (int) 't', 0, 2 ) ;
  318.                 n4action( i4ind, (int) 't' + 0x100, i_ref ) ;
  319.    i_ref =  n4( "i4unlock( index_ref )") ;
  320.                 n4key( (int) 'u', 0, 2 ) ;
  321.                 n4action( i4ind, (int) 'u', i_ref ) ;
  322.    i_ref =  n4( "i4unselect()") ;
  323.                 n4key( (int) 'u', 0, 2 ) ;
  324.                 n4action( i4ind, (int) 'u' + 0x100, i_ref ) ;
  325.  
  326.    memo =  w4define( -1,-1,-1,-1 ) ;
  327.    i_ref =  n4( "m4check( field_ref )" ) ;
  328.                 n4key( (int) 'c', 0, 2 ) ;
  329.                 n4action( m4memo, (int) 'c', i_ref ) ;
  330.    i_ref =  n4( "m4convert( memo_file_name )" ) ;
  331.                 n4key( (int) 'c', 0, 2 ) ;
  332.                 n4action( m4memo, (int) 'c' + 0x100, i_ref ) ;
  333.    #ifndef UNIX
  334.    i_ref =  n4( "m4edit( field_ref, rec_num, editor, size )" ) ;
  335.                 n4key( (int) 'e', 0, 2 ) ;
  336.                 n4action( m4memo, (int) 'e', i_ref ) ;
  337.    #endif
  338.    i_ref =  n4( "m4exist( field_ref )") ;
  339.                 n4key( (int) 'e', 0, 2 ) ;
  340.                 n4action( m4memo, (int) 'e' + 0x100, i_ref ) ;
  341.    i_ref =  n4( "m4read( field_ref, rec_num, str, str_len )") ;
  342.                 n4key( (int) 'r', 0, 2 ) ;
  343.                 n4action( m4memo, (int) 'r', i_ref ) ;
  344.    i_ref =  n4( "m4renamed( memo_file_name )" ) ;
  345.                 n4key( (int) 'r', 0, 2 ) ;
  346.                 n4action( m4memo, (int) 'r' + 0x100, i_ref ) ;
  347.    i_ref =  n4( "m4write( field_ref, rec_num, str, str_len )") ;
  348.                 n4key( (int) 'w', 0, 2 ) ;
  349.                 n4action( m4memo, (int) 'w', i_ref ) ;
  350.  
  351.    n4skip_over( n4( "-------------------------------------------" ), 1 ) ;
  352.  
  353.    #ifndef UNIX
  354.    i_ref =  n4( "m3edit( field_ref, rec_num, editor, size )") ;
  355.                 n4key( (int) '3', 0, 1 ) ;
  356.                 n4action( m4memo, (int) 'e'+ 0x1000, i_ref ) ;
  357.    #endif
  358.    i_ref =  n4( "m3exist( field_ref )") ;
  359.                 n4key( (int) '3', 0, 1 ) ;
  360.                 n4action( m4memo, (int) 'e' + 0x1100, i_ref ) ;
  361.    i_ref =  n4( "m3read( field_ref, rec_num, str, str_len )") ;
  362.                 n4key( (int) '3', 0, 1 ) ;
  363.         n4action( m4memo, (int) 'r' + 0x1000, i_ref ) ;
  364.    i_ref =  n4( "m3write( field_ref, rec_num, str, str_len )") ;
  365.                 n4key( (int) '3', 0, 1 ) ;
  366.                 n4action( m4memo, (int) 'w' + 0x1000, i_ref ) ;
  367.  
  368.    ext =  w4define( -1,-1,-1,-1 ) ;
  369.    i_ref =  n4( "x4blank()")  ;
  370.                 n4key( (int) 'b', 0, 2 ) ;
  371.                 n4action( x4ext, (int) 'b', i_ref ) ;
  372.    i_ref =  n4( "x4bottom()") ;
  373.                 n4key( (int) 'b', 0, 2 ) ;
  374.                 n4action( x4ext, (int) 'b' + 0x100, i_ref ) ;
  375.    i_ref =  n4( "x4buffer( start_record, buffer, buffer_length )") ;
  376.                 n4key( (int) 'b', 0, 2 ) ;
  377.                 n4action( x4ext, (int) 'b' + 0x200, i_ref ) ;
  378.    i_ref =  n4( "x4buffer_copy( offset_record, buffer )" ) ;
  379.                 n4key( (int) 'b', 0, 2 ) ;
  380.                 n4action( x4ext, (int) 'b' + 0x300, i_ref ) ;
  381.    i_ref =  n4( "x4edit()") ;
  382.                 n4key( (int) 'e', 0, 2 ) ;
  383.                 n4action( x4ext, (int) 'e', i_ref ) ;
  384.    i_ref =  n4( "x4filter( (*filter_routine)()") ;
  385.                 n4key( (int) 'f', 0, 2 ) ;
  386.                 n4action( x4ext, (int) 'f', i_ref ) ;
  387.    i_ref =  n4( "x4go( record_number )") ;
  388.                 n4key( (int) 'g', 0, 2 ) ;
  389.                 n4action( x4ext, (int) 'g', i_ref ) ;
  390.    i_ref =  n4( "x4insert( record_number )") ;            
  391.                 n4key( (int) 'i', 0, 2 ) ;
  392.                 n4action( x4ext, (int) 'i', i_ref ) ;
  393.    i_ref =  n4( "x4list()") ;
  394.         n4key( (int) 'l', 0, 2 ) ;
  395.                 n4action( x4ext, (int) 'l', i_ref ) ;
  396.    i_ref =  n4( "x4relate( expr, base_ref, index_ref, miss_code )") ;
  397.                 n4key( (int) 'r', 0, 2 ) ;
  398.                 n4action( x4ext, (int) 'r', i_ref ) ;
  399.    i_ref =  n4( "x4relate_reset()") ;
  400.                 n4key( (int) 'r', 0, 2 ) ;
  401.                 n4action( x4ext, (int) 'r' + 0x100, i_ref ) ;
  402.    i_ref =  n4( "x4replace( field_ref, record_number, value )") ;
  403.                 n4key( (int) 'r', 0, 2 ) ;
  404.                 n4action( x4ext, (int) 'r' + 0x200, i_ref ) ;
  405.    i_ref =  n4( "x4seek( search_string )") ;
  406.                 n4key( (int) 's', 0, 2 ) ;
  407.                 n4action( x4ext, (int) 's', i_ref ) ;
  408.    i_ref =  n4( "x4skip( num_records )") ;
  409.                 n4key( (int) 's', 0, 2 ) ;
  410.                 n4action( x4ext, (int) 's' + 0x100, i_ref ) ;
  411.    i_ref =  n4( "x4sum( field_ref )") ;
  412.                 n4key( (int) 's', 0, 2 ) ;
  413.                 n4action( x4ext, (int) 's' + 0x200, i_ref ) ;
  414.    i_ref =  n4( "x4top()" ) ;
  415.                 n4key( (int) 't', 0, 2 ) ;
  416.                 n4action( x4ext, (int) 't', i_ref ) ;
  417.  
  418.    n4pulldown( main_menu ) ;
  419.    n4activate( &main_menu ) ;
  420.  
  421.    w4exit(0) ;
  422. }
  423.  
  424. static int  help()
  425. {
  426.    w4display( " HELP ",
  427.               "   Use \'d4learn\' to test the use of Code Base 4 routines.",
  428.           "The pulldown menu system is used to select the routine.  Once",
  429.           "the routine is selected, \'d4learn\' prompts for the parameters,",
  430.           "executes the routine, and then displays the results.",
  431.           "",
  432.           "   Note that the <Alt> keys are used to select between options",
  433.           "on the top menu bar.  For example, to move to the database",
  434.           "routines, press <Alt D>.  In addition, <Alt X> is used for the",
  435.           "extended routines.",
  436.           (char *) 0 ) ;
  437. }
  438.  
  439. static int  p_reset()
  440. {
  441.    p_on = 0 ;
  442.    rc_type =  INT ;
  443.    w4position( 0,0 ) ;
  444.    return( 0 ) ;
  445. }
  446.  
  447. static char *  parm( message )
  448. char  *message ;
  449. {
  450.    return( parm_default( message, (char *) 0, 0) ) ;
  451. }
  452.  
  453. static char *  parm_default( message, def, def_len ) 
  454. char *message ;
  455. char *def ;
  456. int   def_len ;
  457. {
  458.    int  m_len, pos ;
  459.  
  460.    if ( p_on > 4 )  p_on = 4 ;
  461.    m_len =  strlen(message) ;
  462.  
  463.    if ( w4row() >= v4window_ptr->height-1 || w4row() == 0 )
  464.       w4clear(0) ;
  465.  
  466.    w4( w4row()+1, C_LEFT, message ) ;
  467.    memset( p_buffer[p_on], (int) ' ', sizeof(p_buffer[0]) ) ;
  468.  
  469.    if ( def != (char *) 0 )
  470.    {
  471.       if ( def_len > sizeof(p_buffer[0]) )
  472.          memcpy( p_buffer[p_on], def, sizeof(p_buffer[0]) ) ;
  473.       else
  474.          memcpy( p_buffer[p_on], def, def_len ) ;
  475.    }
  476.    p_buffer[p_on][sizeof(p_buffer[0])-1] = '\0' ;
  477.    
  478.    if ( m_len > 40 )
  479.    {
  480.       w4position( w4row()+1,0 ) ;
  481.       g4( w4row(), C_LEFT, p_buffer[p_on] ) ;
  482.       g4width( 80, 55 ) ;
  483.    }
  484.    else
  485.    {
  486.       pos =  15 ;
  487.       if ( m_len > 13 )  pos =  m_len + 2 ;
  488.       g4( w4row(), C_LEFT+pos, p_buffer[p_on] ) ;
  489.       g4width( 79, 40-pos+15 ) ;
  490.    }
  491.  
  492.    return( p_buffer[p_on++] ) ;
  493. }
  494.  
  495. static char *  s_get(i)
  496. int i ;
  497. {
  498.    if ( p_on >= 0 )
  499.    {
  500.       p_on =  -1 ;
  501.       g4read() ;
  502.    }
  503.    return( p_buffer[i] ) ;
  504. }
  505.  
  506. static int  i_get(i)
  507. int  i ;
  508. {
  509.    return( atoi(s_get(i)) ) ;
  510. }
  511.  
  512. static long  l_get(i)
  513. int  i ;
  514. {
  515.    return( atol(s_get(i)) ) ;
  516. }
  517.  
  518. static double d_get(i)
  519. int  i ;
  520. {
  521.    return( strtod( s_get(i), (char **) 0)  ) ;
  522. }
  523.  
  524.  
  525. static int  field_name_parm()
  526. {
  527.    int  w_ref, get_ref ;
  528.    int  i ;
  529.  
  530.    get_ref =  w4select(-1) ;
  531.  
  532.    w_ref =  w4define( -1,-1,-1,-1 ) ;
  533.  
  534.    for ( i=1; i <= f4num_fields(); i++ )
  535.       n4( f4name(f4j_ref(i)) ) ;
  536.  
  537.    w4select( get_ref ) ;
  538.  
  539.    parm( "Field Name" ) ;
  540.    g4call( g4menu, w_ref ) ;
  541.    n4get_calc( get_ref ) ;
  542.  
  543.    return( w_ref ) ;
  544. }
  545.  
  546.  
  547. static void  file_name_parm( char * ) ;
  548. static void  file_name_free( void ) ;
  549. static char *file_menu_data =  (char *) 0 ;
  550. static int   file_w_ref     =  -1 ;
  551.  
  552. static void  file_name_free()
  553. {
  554.    if ( file_menu_data != (char *) 0)  h4free_memory( file_menu_data ) ;
  555.    file_menu_data = (char *) 0 ;
  556.  
  557.    if ( file_w_ref >= 0 )  w4close( file_w_ref ) ;
  558.    file_w_ref =  -1 ;
  559. }
  560.  
  561. static void  file_name_parm( pattern )
  562. char *pattern ;
  563. {
  564.    int   n_data, i, rc, get_ref ;
  565.    char  count_data[14] ;
  566.  
  567.    get_ref =  w4select( -1 ) ;
  568.  
  569.    for( rc =  u4file_first(pattern,count_data), n_data= 0; rc == 0; n_data +=14)
  570.     rc =  u4file_next( count_data ) ;
  571.  
  572.    if ( n_data == 0 )
  573.    {
  574.       w4display( " Informative Message: ",
  575.                  "There are no files for wildcard pattern",
  576.           pattern, "in the current directory.",
  577.           "",
  578.           "Press a key.",
  579.           (char *) 0 ) ;
  580.  
  581.       parm( "File Name" ) ;
  582.       return ;
  583.    }
  584.  
  585.    file_w_ref =  w4define( -1,-1,-1,-1 ) ;
  586.  
  587.    /* Allocate Enough File Memory */
  588.    file_menu_data =  (char *) h4alloc( n_data ) ;
  589.  
  590.    rc = u4file_first(pattern, file_menu_data ) ;
  591.    n4( file_menu_data ) ;
  592.    n4key( (int) file_menu_data[0], 0, 0 ) ;
  593.  
  594.    for ( i= 14; i< n_data ; i+= 14 )
  595.    {
  596.       if ( u4file_next( file_menu_data+i )  != 0 )  break ;
  597.       n4( file_menu_data+i ) ;
  598.       n4key( (int) file_menu_data[i], 0, 0 ) ;
  599.    }
  600.  
  601.    w4select( get_ref ) ;
  602.    parm( "File Name" ) ;
  603.    g4message( "Press <F1> for a menu of choices" ) ;
  604.  
  605.    g4call( g4menu_help, file_w_ref ) ;
  606.    n4get_calc( get_ref ) ;
  607. }
  608.  
  609.  
  610. static int  display_results()
  611. {
  612.    int  cur_index ;
  613.    char buf[40] ;
  614.  
  615.    cur_index =  i4seek_ref() ;
  616.  
  617.    w4activate( result_ref ) ;
  618.  
  619.    /* Print out Database Information */
  620.    w4( 1, C_LEFT, "Selected Database: " ) ;
  621.    if ( v4cur_base < 0)
  622.       w4out( "NONE" ) ;
  623.    else
  624.    {
  625.       w4out( v4base[v4cur_base].name ) ;
  626.       if ( v4base[v4cur_base].file_lock == 1 )
  627.      w4out( "   Locked" ) ;
  628.       w4( w4row()+1, C_LEFT, "Number of Fields:  " ) ;
  629.       w4long( w4row(), w4col(), (long) f4num_fields(), 10) ;
  630.       w4( w4row()+1, C_LEFT, "Current Record No: " ) ;
  631.       w4long( w4row(), w4col(), d4recno(), 10 ) ;
  632.       if ( v4base[v4cur_base].rec_lock >0 )
  633.       {
  634.          w4( w4row()+1, C_LEFT, "Record Locked:     " ) ;
  635.          w4long( w4row(), w4col(), (long) v4base[v4cur_base].rec_lock, 10) ;
  636.       }
  637.       if ( v4base[v4cur_base].file_lock == 2 )
  638.          w4( w4row()+1, C_LEFT, "The Record Count Bytes are Locked" ) ;
  639.  
  640.       w4( w4row()+1, C_LEFT, "Database Buffer:   " ) ;
  641.       if ( f4record_width() < 130 )
  642.          w4out( f4record() ) ;
  643.       else
  644.      w4num( w4row(),w4col(), f4record(), 130 ) ;
  645.    }
  646.  
  647.  
  648.    /* Print out Index File Information */
  649.    if ( cur_index >= 0)
  650.    {
  651.       KEY  *key_ptr ;
  652.       char *ptr ;
  653.  
  654.       if ( v4base[v4cur_base].current_index >= 0)
  655.          w4( w4row()+2, C_LEFT, "Selected Index File:  " ) ;
  656.       else
  657.          w4( w4row()+2, C_LEFT, "Default Index File:   " ) ;
  658.       w4out( v4index[cur_index].name ) ;
  659.       if ( v4index[cur_index].lock )
  660.      w4out( "   Locked" ) ;
  661.       w4( w4row()+1, C_LEFT, "Key Expression:       " ) ;
  662.       w4out( v4index[cur_index].expression ) ;
  663.       if ( v4base[v4cur_base].rec_num > 0 )
  664.       {
  665.      w4( w4row()+1, C_LEFT, "Evaluated Index Expression: " ) ;
  666.          ptr =  i4eval( cur_index ) ;
  667.          c4key( ptr, ptr, i4type(cur_index) ) ;
  668.          w4out( ptr ) ;
  669.       }
  670.  
  671.       key_ptr =  b4key(cur_index) ;
  672.       if ( key_ptr != (KEY *) 0  &&
  673.            v4block[v4index[cur_index].block_ref].key_on
  674.            < v4block[v4index[cur_index].block_ref].num_keys)
  675.       {
  676.          w4( w4row()+1, C_LEFT, "Current Key Value:    " ) ;
  677.          memcpy( buffer, key_ptr->value, v4index[cur_index].key_len ) ;
  678.          buffer[ v4index[cur_index].key_len ] = '\0' ;
  679.          c4key( buffer, buffer, i4type(cur_index) ) ;
  680.          w4out( buffer ) ;
  681.          w4( w4row()+1, C_LEFT, "Index Key's Record No:" ) ;
  682.          w4long( w4row(), w4col(), key_ptr->rec_num, 10 ) ;
  683.       }
  684.    }
  685.  
  686.    /* Print out  RC  information */
  687.    w4position( w4row()+2, 0 ) ;
  688.    switch( rc_type )
  689.    {
  690.       int  len ;
  691.  
  692.       case INT:
  693.      w4( w4row(), C_LEFT, "(int) Function Return: ") ;
  694.      itoa( rc, buf, 10 ) ;
  695.      w4out( buf ) ;
  696.      w4( w4row(),w4col(), "    In Hex: " ) ;
  697.      itoa( rc, buf, 16 ) ;
  698.      w4out( buf ) ;
  699.          break ;
  700.  
  701.       case LONG:
  702.      w4( w4row(), C_LEFT, "(long) Function Return: ") ;
  703.      ltoa( l_rc, buf, 10 ) ;
  704.      w4out( buf ) ;
  705.      w4( w4row(),w4col(), "    In Hex: " ) ;
  706.      ltoa( l_rc, buf, 16 ) ;
  707.      w4out( buf ) ;
  708.          break ;
  709.  
  710.       case CHAR:
  711.          w4( w4row(), C_LEFT, "(char) Function Return: ") ;
  712.          buffer[0] =  c_rc ;
  713.          buffer[1] =  '\0' ;
  714.          w4out( buffer ) ;
  715.          break ;
  716.  
  717.       case DOUB:
  718.          w4( w4row(), C_LEFT, "(double) Function Return: ") ;
  719.          s_rc =  c4dtoa( d_rc, 34, 16 ) ;
  720.          len  =  strlen( s_rc ) ;
  721.          while ( s_rc[--len] == '0' ) if ( len >= 0 )  s_rc[len] = '\0' ;
  722.          while ( *s_rc == ' ' ) s_rc++ ;
  723.          w4out( s_rc ) ;
  724.          break ;
  725.  
  726.       case DATE:
  727.       case CHAR_PTR:
  728.       case MSG:
  729.          if (rc_type == DATE)
  730.             w4( w4row(), C_LEFT, "(DATE) Function Return: ") ;
  731.      if (rc_type == CHAR_PTR)
  732.         w4( w4row(), C_LEFT, "(char *) Function Return: ") ;
  733.      if (rc_type == MSG)
  734.         w4( w4row(), C_LEFT, s_msg ) ;
  735.  
  736.          if ( s_rc == (char *) 0)
  737.             w4out( "NULL POINTER") ;
  738.          else
  739.          {
  740.             strncpy( buffer, s_rc, sizeof(buffer) ) ;
  741.             buffer[sizeof(buffer)-1] = '\0' ;
  742.         w4out( buffer ) ;
  743.          }
  744.          break ;
  745.  
  746.       case VOID:
  747.          w4( w4row(),C_LEFT, "Void Return" ) ;
  748.      break ;
  749.    }
  750.  
  751.    rc =  g4char() ;
  752.  
  753.    w4deactivate( result_ref ) ;
  754.  
  755.    return( rc ) ;
  756. }
  757.  
  758. static void  activate_entry_window( item_ref )
  759. int  item_ref ;
  760. {
  761.    strcpy( title_buf, "PARAMETER ENTRY: " ) ;
  762.    strcat( title_buf, v4menu[item_ref].item_ptr ) ;
  763.    w4activate( entry_ref ) ;
  764.    w4position( 0,0 ) ;
  765. }
  766.  
  767. static int  c4conv( option_code, item_ref )
  768. int  option_code, item_ref ;
  769. {
  770.    int  i, r ;
  771.  
  772.    activate_entry_window( item_ref ) ;
  773.  
  774.    switch( option_code )
  775.    {
  776.       case (int) 'a':
  777.          parm( "char_string" ) ;
  778.          parm( "len_string" ) ;
  779.          i =  i_get(1) ;
  780.          if ( i > 70 )  i = 70 ;
  781.          d_rc =  c4atod( s_get(0), i ) ;
  782.          rc_type =  DOUB ;
  783.          break ;
  784.  
  785.       case (int) 'a'+ 0x100:
  786.          parm( "char_string" ) ;
  787.          parm( "len_string" ) ;
  788.          i =  i_get(1) ;
  789.          if ( i > 70 )  i = 70 ;
  790.          rc =  c4atoi( s_get(0), i ) ;
  791.          break ;
  792.  
  793.       case (int) 'a'+ 0x200:
  794.          parm( "char_string" ) ;
  795.      parm( "len_string" ) ;
  796.          i =  i_get(1) ;
  797.          if ( i > 70 )  i = 70 ;
  798.          l_rc =  c4atol( s_get(0), i ) ;
  799.          rc_type =  LONG ;
  800.          break ;
  801.  
  802.       case (int) 'd':
  803.          parm( "double_value" ) ;
  804.          parm( "len_string" ) ;
  805.          parm( "dec" ) ;
  806.          i =  i_get(1) ;
  807.          if ( i > 70 )  i =  70 ;
  808.          s_rc =  c4dtoa( d_get(0), i, i_get(2) ) ;
  809.          s_rc[i] = '\0' ;
  810.          rc_type =  CHAR_PTR ;
  811.          break ;
  812.  
  813.       case (int) 'd'+ 0x100:
  814.          parm("dbf_date (Ex. 19880430)") ;
  815.          parm("picture (Ex. CCYY.MM.DD)") ;
  816.          s_rc =  c4dt_format( s_get(0), s_get(1) ) ;
  817.          rc_type =  CHAR_PTR ;
  818.          break ;
  819.  
  820.       case (int) 'd'+ 0x200:
  821.          parm("date_data") ;
  822.          parm("picture") ;
  823.          s_rc =  c4dt_unformat( s_get(0), s_get(1) ) ;
  824.          rc_type =  CHAR_PTR ;
  825.          break ;
  826.  
  827.       case 'e':
  828.          parm("from") ;
  829.          parm("t_to") ;
  830.      parm("t_from") ;
  831.      c4encode( extra_buffer, s_get(0), s_get(1), s_get(2) ) ;
  832.          s_rc    =  extra_buffer ;
  833.          rc_type =  CHAR_PTR ;
  834.          break ;
  835.  
  836.       case 'l':
  837.          parm( "long_value" ) ;
  838.          parm( "len_string" ) ;
  839.          i = i_get(1) ;
  840.          if ( i > 70 )  i =  70 ;
  841.          s_rc =  c4ltoa( l_get(0), extra_buffer, i ) ;
  842.          s_rc[i] = '\0' ;
  843.          rc_type =  CHAR_PTR ;
  844.          break ;
  845.  
  846.       default:
  847.          return( -1 ) ;
  848.    }
  849.  
  850.    r =  display_results() ;
  851.  
  852.    w4deactivate( entry_ref ) ;
  853.    p_reset() ;
  854.  
  855.    return( r ) ;
  856. }
  857.  
  858.  
  859. static int  d4data( option_code, item_ref )
  860. int  option_code, item_ref ;
  861. {
  862.    double d ;
  863.    int    i, r ;
  864.  
  865.    v4window[ v4menu[item_ref].window_ref].start_item =  -1 ;
  866.    activate_entry_window( item_ref ) ;
  867.  
  868.    switch( option_code )
  869.    {
  870.       case (int) 'b':
  871.          rc =  d4bottom() ;
  872.          break ;
  873.  
  874.       case (int) 'c':
  875.          rc =  d4close() ;
  876.          break ;
  877.  
  878.       case (int) 'c'+ 0x100:
  879.          {
  880.             int    num_fields, safety, i_field ;
  881.             FIELD *field_ptr, *field_on ;
  882.             char   file_name[82] ;
  883.  
  884.             parm("File Name" ) ;
  885.             parm("Number of Fields" ) ;
  886.             parm("Safety" ) ;
  887.  
  888.             memcpy( file_name, s_get(0), sizeof(file_name) ) ;
  889.             num_fields =  i_get(1) ;
  890.             if ( num_fields <= 0 )  num_fields = 1 ;
  891.  
  892.             safety     =  i_get(2) ;
  893.             field_ptr  =  (FIELD *) h4alloc( sizeof(FIELD)*num_fields ) ;
  894.  
  895.             field_on   =  field_ptr ;
  896.             for ( i_field = 0;  i_field < num_fields; i_field++ )
  897.             {
  898.            p_reset() ;
  899.  
  900.                parm( "Field Name" ) ;
  901.                parm( "Field Type" ) ;
  902.                parm( "Field Width" ) ;
  903.                parm( "Field Decimals" ) ;
  904.  
  905.                memcpy( field_on->name, s_get(0), sizeof(field_on->name) ) ;
  906.                memcpy( &field_on->type, s_get(1), 1 ) ;
  907.                field_on->width    =  i_get(2) ;
  908.                field_on->decimals =  i_get(3) ;
  909.                field_on++ ;
  910.             }
  911.  
  912.             rc =  d4create( file_name, num_fields, field_ptr, safety ) ;
  913.             h4free_memory( (char *) field_ptr ) ;
  914.  
  915.             break ;
  916.          }
  917.  
  918.       case (int) 'd':
  919.          parm("Record Number" ) ;
  920.          rc =  d4delete( l_get(0) ) ;
  921.          break ;
  922.  
  923.       case (int) 'd'+ 0x100:
  924.          rc =  d4deleted() ;
  925.          break ;
  926.  
  927.       case (int) 'g':
  928.          parm("Record Number" ) ;
  929.          rc =  d4go( l_get(0) ) ;
  930.          break ;
  931.  
  932.       case (int) 'l':
  933.          parm( "Lock Code" ) ;
  934.          parm( "Wait" ) ;
  935.          rc =  d4lock( l_get(0), i_get(1) ) ;
  936.          break ;
  937.  
  938.       case (int) 'p':
  939.          rc =  d4pack() ;
  940.          break ;
  941.  
  942.       case (int) 'r':
  943.          parm( "Record Number" ) ;
  944.          rc =  d4recall( l_get(0) ) ;
  945.          break ;
  946.  
  947.       case (int) 'r'+ 0x100:
  948.          l_rc =  d4reccount() ;
  949.          rc_type =  LONG ;
  950.          break ;
  951.  
  952.       case (int) 'r'+ 0x200:
  953.          l_rc =  d4recno() ;
  954.          rc_type =  LONG ;
  955.          break ;
  956.  
  957.       case (int) 'r'+ 0x300:
  958.          parm( "Database Name" ) ;
  959.          rc =  d4ref( s_get(0) ) ;
  960.          break ;
  961.  
  962.       case (int) 's':
  963.          parm( "Search Value") ;
  964.  
  965.          if ( i4type(i4seek_ref()) == 'N' ||
  966.               i4type(i4seek_ref()) == 'F' )
  967.          {
  968.             d  =  c4atod( s_get(0), strlen(s_get(0)) ) ;
  969.             rc =  d4seek( (char *) &d ) ;
  970.          }
  971.          else
  972.             rc =  d4seek( s_get(0) ) ;
  973.          break ;
  974.  
  975.       case (int) 's'+ 0x100:
  976.      parm("Database Reference Number") ;
  977.      rc =  d4select( i_get(0) ) ;
  978.          break ;
  979.  
  980.       case (int) 's'+ 0x200:
  981.          parm("Number of Records") ;
  982.          rc =  d4skip( l_get(0) ) ;
  983.          break ;
  984.  
  985.       case (int) 't':
  986.          rc =  d4top() ;
  987.          break ;
  988.  
  989.       case (int) 'u':
  990.          parm("Lock Code") ;
  991.          rc =  d4unlock( l_get(0) ) ;
  992.          break ;
  993.  
  994.       case (int) 'u'+ 0x100:
  995.      file_name_parm( "*.DBF" ) ;
  996.      c4trim_n( s_get(0), (int) sizeof(p_buffer[0]) ) ;
  997.  
  998.          rc =  d4use( s_get(0) ) ;
  999.      file_name_free() ;
  1000.          break ;
  1001.  
  1002.       case (int) 'w':
  1003.          parm_default( "Enter Record to Write - <Enter> for Current Buffer",
  1004.                        f4record(), f4record_width() ) ;
  1005.          parm( "Record Number") ;
  1006.  
  1007.          i =  strlen( s_get(0) ) ;
  1008.          if ( i > 0 )
  1009.          {
  1010.             memset( f4record(), (int) ' ', (size_t) f4record_width() ) ;
  1011.             if ( i >= f4record_width() )
  1012.                  i =  f4record_width()-1 ;
  1013.             memcpy( f4record(), s_get(0), i ) ;
  1014.          }
  1015.          rc =  d4write( l_get(1) ) ;
  1016.          break ;
  1017.  
  1018.       case (int) 'z':
  1019.          parm( "Starting Record" ) ;
  1020.          parm("Ending Record") ;
  1021.          rc =  d4zap( l_get(0), l_get(1) ) ;
  1022.          break ;
  1023.  
  1024.       default:
  1025.          return( -1 ) ;
  1026.  
  1027.    }
  1028.  
  1029.    r =  display_results() ;
  1030.  
  1031.    w4deactivate( entry_ref ) ;
  1032.    p_reset() ;
  1033.  
  1034.    return( r ) ;
  1035. }
  1036.  
  1037.  
  1038. static int  field_help()
  1039. {
  1040.    w4display( " Field Reference Number Help ",
  1041.             "   The \'field_ref\' uniquely specifies a field and",
  1042.             "is obtained by a call to \'f4j_ref\' or \'f4ref\'.",
  1043.             "However, to make things simpler while using \'d4learn\',",
  1044.             "you will select from a menu of field names.",  
  1045.             "",
  1046.             "   Normally, \'f4ref\' would be called once, after the",
  1047.             "corresponding database is opened, for each field to be",
  1048.             "used.  Assign the field reference number returned by",
  1049.         "\'f4ref\' to globally declared long integer varaibles.",
  1050.             "Note that it does not matter which database is selected",
  1051.             "when using field routines with field reference numbers.",
  1052.             "This is because the two high order bytes, of a field",
  1053.             "reference number, contain the database reference number!",
  1054.             (char *) 0 ) ;
  1055.    return 0 ;
  1056. }
  1057.  
  1058.  
  1059. static int  f4field( option_code, item_ref )
  1060. int  option_code, item_ref ;
  1061. {
  1062.    int  menu_ref, r ;
  1063.  
  1064.    if ( v4cur_base < 0 )
  1065.    {
  1066.       w4display( " User Error: ",
  1067.          "Do not use the field routines",
  1068.          "when no database is being used.",
  1069.          (char *) 0 ) ;
  1070.       return 0 ;
  1071.    }
  1072.  
  1073.    activate_entry_window( item_ref ) ;
  1074.    menu_ref =  -1 ;
  1075.  
  1076.    switch (option_code)
  1077.    {
  1078.       case (int) 'd':
  1079.          menu_ref =  field_name_parm() ;
  1080.          rc = f4decimals( f4ref(s_get(0)) ) ;
  1081.          break ;
  1082.  
  1083.       case (int) 'j':
  1084.          parm( "Field Number" ) ;
  1085.          l_rc = f4j_ref( i_get(0) ) ;
  1086.          rc_type =  LONG ;
  1087.          break ;
  1088.  
  1089.       case (int) 'n':
  1090.          menu_ref =  field_name_parm() ;
  1091.          s_rc = f4name( f4ref(s_get(0)) ) ;
  1092.          rc_type =  CHAR_PTR ;
  1093.          break ;
  1094.  
  1095.       case (int) 'n'+ 0x100:
  1096.          rc      =  f4num_fields() ;
  1097.          break ;
  1098.  
  1099.       case (int) 'p':
  1100.          menu_ref =  field_name_parm() ;
  1101.          s_rc    =  f4ptr( f4ref(s_get(0)) ) ;
  1102.          rc_type =  CHAR_PTR ;
  1103.          break ;
  1104.  
  1105.       case (int) 'r':
  1106.          s_rc    =  f4record() ;
  1107.          rc_type =  CHAR_PTR ;
  1108.          break ;
  1109.  
  1110.       case (int) 'r'+ 0x100:
  1111.          rc    =  f4record_width() ;
  1112.          break ;
  1113.  
  1114.       case (int) 'r'+ 0x200:
  1115.          menu_ref=  field_name_parm() ;
  1116.          l_rc    =  f4ref( s_get(0) ) ;
  1117.          rc_type =  LONG ;
  1118.          break ;
  1119.  
  1120.       case (int) 'r'+ 0x300:
  1121.          {
  1122.             int    i_val ;
  1123.             double doub_val ;
  1124.             char   ch ;
  1125.             long   f_ref ;
  1126.  
  1127.             menu_ref =  field_name_parm() ;
  1128.             parm( "*ptr value" ) ;
  1129.  
  1130.         f_ref =  f4ref( s_get(0) ) ;
  1131.  
  1132.             switch ( f4type(f_ref) )
  1133.             {
  1134.                case 'N':
  1135.                case 'F':
  1136.                   doub_val =  d_get(1) ;
  1137.                   rc =  f4replace( f_ref, (void *) (&doub_val) ) ;
  1138.                   break ;
  1139.  
  1140.                case 'L':
  1141.                   ch =  *s_get(1) ;
  1142.                   if ( ch == 'Y' || ch == 'y' || ch == 'T' || ch == 't')
  1143.                      i_val = 1 ;
  1144.                   else
  1145.                      i_val = 0 ;
  1146.  
  1147.                   rc =  f4replace( f_ref, (void *) (&i_val) ) ;
  1148.                   break ;
  1149.  
  1150.                default:
  1151.                   rc =  f4replace( f_ref, (void *) s_get(1) ) ;
  1152.                   break ;
  1153.             }
  1154.          }
  1155.          break ;
  1156.  
  1157.       case (int) 's':
  1158.          menu_ref =  field_name_parm() ;
  1159.      s_rc = f4str( f4ref( s_get(0) ) ) ;
  1160.          rc_type =  CHAR_PTR ;
  1161.          break ;
  1162.  
  1163.       case (int) 't':
  1164.          menu_ref =  field_name_parm() ;
  1165.      rc = f4true( f4ref( s_get(0) ) ) ;
  1166.          break ;
  1167.  
  1168.       case (int) 't'+ 0x100:
  1169.          menu_ref =  field_name_parm() ;
  1170.      c_rc = f4type( f4ref( s_get(0) ) ) ;
  1171.          rc_type =  CHAR ;
  1172.          break ;
  1173.  
  1174.       case (int) 'v':
  1175.          menu_ref =  field_name_parm() ;
  1176.      d_rc = f4value( f4ref( s_get(0) ) ) ;
  1177.          rc_type =  DOUB ;
  1178.          break ;
  1179.  
  1180.       case (int) 'w':
  1181.          menu_ref =  field_name_parm() ;
  1182.      rc = f4width( f4ref( s_get(0) ) ) ;
  1183.          break ;
  1184.  
  1185.       default:
  1186.          return( -1 ) ;
  1187.  
  1188.    }
  1189.  
  1190.    r = display_results() ;
  1191.  
  1192.    if ( menu_ref >= 0 )
  1193.       w4close( menu_ref ) ;
  1194.  
  1195.    w4deactivate( entry_ref ) ;
  1196.    p_reset() ;
  1197.  
  1198.    return( r ) ;
  1199. }
  1200.  
  1201.  
  1202. static int  index_help()
  1203. {
  1204.    w4display( " Index File Reference Number Help ",
  1205.             "   d3learn automatically supplies the index file",
  1206.             "reference number parameter for any index file routine",
  1207.             "which requires one.  The index file reference number",
  1208.             "for the currently selected index file is used.  If",
  1209.             "no index file is currently selected, the index file",
  1210.             "reference number for the last opened index file is",
  1211.         "used instead.", (char *) 0 ) ;
  1212.    return 0 ;
  1213. }
  1214.  
  1215.  
  1216. static int  i4ind( option_code, item_ref )
  1217. int  option_code, item_ref ;
  1218. {
  1219.    int   cur_index, i, r ;
  1220.    char *s ;
  1221.  
  1222.    if ( v4cur_base < 0 )
  1223.    {
  1224.       w4display( " User Error: ",
  1225.                  "Open a database before executing an index file routine.",
  1226.                  "",
  1227.                  "Press any key to continue.",
  1228.                  (char *) 0 ) ;
  1229.       return 0 ;
  1230.    }
  1231.  
  1232.    cur_index =  i4seek_ref() ;
  1233.    if ( cur_index < 0 )
  1234.    {
  1235.       /* i4open, i4index, i4ref, i4select, i4unselect */
  1236.       if ( option_code != 'o' &&  option_code != 'i' &&
  1237.            option_code != 'r' &&  option_code != 's'+0x100 &&
  1238.            option_code != 'u'+0x100 )
  1239.       {
  1240.      w4display( " User Error: ",
  1241.                     "d3learn will not execute this routine until an index",
  1242.                     "file is opened or created for the selected database.",
  1243.                     (char *) 0 ) ;
  1244.          return 0 ;
  1245.       }
  1246.    }
  1247.  
  1248.    activate_entry_window( item_ref ) ;
  1249.  
  1250.    switch (option_code)
  1251.    {
  1252.       case (int) 'a':
  1253.      parm("key_ptr") ;
  1254.      parm("record number") ;
  1255.      rc =  i4add( cur_index, s_get(0), l_get(1) ) ;
  1256.          break ;
  1257.  
  1258.       case (int) 'b':
  1259.          rc =  i4bottom( cur_index ) ;
  1260.          break ;
  1261.  
  1262.       case (int) 'c':
  1263.          l_rc =  i4check( cur_index ) ;
  1264.          rc_type =  LONG ;
  1265.          break ;
  1266.  
  1267.       case (int) 'c'+ 0x100:
  1268.          rc =  i4close( cur_index ) ;
  1269.          cur_index = -1 ;
  1270.          break ;
  1271.  
  1272.       case (int) 'e':
  1273.          s_rc =  i4eval( cur_index ) ;
  1274.          if ( e4type() == 'N' ||  e4type() == 'F' || e4type() == 'D' )
  1275.          {
  1276.             s =  c4dtoa( (double) (*s_rc), 30, 12 ) ;
  1277.             i =  strlen(s) ;
  1278.             while ( s[--i] == '0' ) s[i] = '\0' ;
  1279.             if ( s[i] == '.' ) s[i] = '\0' ;
  1280.             strcpy( s_rc, s ) ;
  1281.          }
  1282.          rc_type =  CHAR_PTR ;
  1283.          break ;
  1284.  
  1285.       case (int) 'g':
  1286.      parm("key_ptr") ;
  1287.      parm("record number" ) ;
  1288.      rc =  i4go( cur_index, s_get(0), l_get(1) ) ;
  1289.          break ;
  1290.  
  1291.       case (int) 'i':
  1292.          parm( "file name") ;
  1293.          parm( "expression") ;
  1294.          parm( "unique (0,1)") ;
  1295.          parm( "safety (0,1)") ;
  1296.          rc =  i4index( s_get(0), s_get(1), i_get(2), i_get(3) ) ;
  1297.          break ;
  1298.  
  1299.       case (int) 'l':
  1300.          parm( "Wait" ) ;
  1301.          rc =  i4lock( cur_index, i_get(0) ) ;
  1302.          break ;
  1303.  
  1304.       case (int) 'o':
  1305.          #ifdef CLIPPER
  1306.         file_name_parm( "*.NTX" ) ;
  1307.      #else
  1308.         file_name_parm( "*.NDX" ) ;
  1309.      #endif
  1310.      c4trim_n( s_get(0), (int) sizeof(p_buffer[0]) ) ;
  1311.  
  1312.          rc =  i4open( s_get(0) ) ;
  1313.      file_name_free() ;
  1314.  
  1315.          if ( v4base[v4cur_base].current_index >= 0)
  1316.             cur_index =  v4base[v4cur_base].current_index ;
  1317.          break ;
  1318.  
  1319.       case (int) 'r':
  1320.          parm( "file name" ) ;
  1321.          rc =  i4ref( s_get(0) ) ;
  1322.          break ;
  1323.  
  1324.       case (int) 'r'+ 0x100:
  1325.          parm("Index Ref. No.") ;
  1326.          rc =  i4reindex( i_get(0) ) ;
  1327.          break ;
  1328.  
  1329.       case (int) 'r'+ 0x200:
  1330.          parm("key_ptr") ;
  1331.          parm("rec_num") ;
  1332.          rc =  i4remove( cur_index, s_get(0), l_get(1) ) ;
  1333.          break ;
  1334.  
  1335.       case (int) 's':
  1336.          parm("key_ptr") ;
  1337.          rc =  i4seek( cur_index, s_get(0) ) ;
  1338.          break ;
  1339.  
  1340.       case (int) 's'+ 0x100:
  1341.          rc =  i4seek_ref() ;
  1342.          break ;
  1343.  
  1344.       case (int) 's'+ 0x200:
  1345.          parm( "index_ref" ) ;
  1346.          rc =  i4select( i_get(0) ) ;
  1347.          if ( v4base[v4cur_base].current_index >= 0)
  1348.             cur_index =  v4base[v4cur_base].current_index ;
  1349.          break ;
  1350.  
  1351.       case (int) 's'+ 0x300:
  1352.          parm("n") ;
  1353.          l_rc =  i4skip( cur_index, l_get(0) ) ;
  1354.          rc_type =  LONG ;
  1355.          break ;
  1356.  
  1357.       case (int) 't':
  1358.          rc =  i4top( cur_index ) ;
  1359.          break ;
  1360.  
  1361.       case (int) 't'+ 0x100:
  1362.          c_rc =  i4type( cur_index ) ;
  1363.          rc_type =  CHAR ;
  1364.          break ;
  1365.  
  1366.       case (int) 'u':
  1367.          rc =  i4unlock( cur_index ) ;
  1368.          break ;
  1369.  
  1370.       case (int) 'u'+ 0x100:
  1371.          i4unselect() ;
  1372.          rc = 0 ;
  1373.          break ;
  1374.  
  1375.       default:
  1376.          return( -1 ) ;
  1377.    }
  1378.  
  1379.    r =  display_results() ;
  1380.  
  1381.    w4deactivate( entry_ref ) ;
  1382.    p_reset() ;
  1383.  
  1384.    return( r ) ;
  1385. }
  1386.  
  1387.  
  1388. static int  e4expr( option_code, item_ref )
  1389. int  option_code, item_ref ;
  1390. {
  1391.    int  r ;
  1392.  
  1393.    activate_entry_window( item_ref ) ;
  1394.  
  1395.    switch( option_code )
  1396.    {
  1397.       case (int) 'e':
  1398.          rc_type =  CHAR_PTR ;
  1399.  
  1400.          parm( "expression" ) ;
  1401.          s_rc =  (char *) e4eval( s_get(0) ) ;
  1402.          if ( e4type() == 'N' || e4type() == 'F' )
  1403.          {
  1404.             d_rc =  *((double *)s_rc) ;
  1405.             rc_type =  DOUB ;
  1406.          }
  1407.          if (e4type() == 'L')
  1408.          {
  1409.             rc =  *((int *)s_rc) ;
  1410.             rc_type =  INT;
  1411.          }
  1412.          if (e4type() == 'D' )
  1413.             rc_type =  DATE ;
  1414.  
  1415.          break ;
  1416.  
  1417.       case (int) 'p':
  1418.          parm( "operator character" ) ;
  1419.          rc =  e4priority( *s_get(0) ) ;
  1420.          rc_type =  INT ;
  1421.          break ;
  1422.  
  1423.       case (int) 't':
  1424.          c_rc =  e4type() ;
  1425.          rc_type =  CHAR ;
  1426.          break ;
  1427.  
  1428.       default:
  1429.          return( -1 ) ;
  1430.    }
  1431.  
  1432.    r =  display_results() ;
  1433.  
  1434.    w4deactivate( entry_ref ) ;
  1435.    p_reset() ;
  1436.  
  1437.    return( r ) ;
  1438. }
  1439.  
  1440.  
  1441. char memo_buf[82] ;
  1442.  
  1443. static int  m4memo( option_code, item_ref )
  1444. int  option_code, item_ref ;
  1445. {
  1446.    int   j, r ;
  1447.    long  field_ref ;
  1448.    char  file_name[90], *screen ;
  1449.  
  1450.    memset( memo_buf, 0, (size_t) sizeof(memo_buf) ) ;
  1451.  
  1452.    for ( j=1; j<= f4num_fields(); j++ )
  1453.    {
  1454.       field_ref =  f4j_ref(j) ;
  1455.       if ( f4type(field_ref) == 'M')  break ;
  1456.    }
  1457.  
  1458.    if ( j > f4num_fields() &&
  1459.     option_code != ('c'+0x100) && option_code != ('r'+0x100) )
  1460.    {
  1461.       w4display( "", "There are no Memo Fields in the Database."
  1462.                  "",
  1463.                  "Press a Key",
  1464.          (char *) 0 ) ;
  1465.       return 0 ;
  1466.    }
  1467.  
  1468.    activate_entry_window( item_ref ) ;
  1469.  
  1470.    if ( j <= f4num_fields() )
  1471.    {
  1472.       w4( w4row()+1, C_MIDDLE, "Using Memo Field: ") ;
  1473.       w4out( f4name(field_ref) ) ;
  1474.    }
  1475.  
  1476.    w4position( w4row()+1, 0 ) ;
  1477.  
  1478.    switch( option_code )
  1479.    {
  1480.       case (int) 'c':
  1481.       {
  1482.      char  buf[5][6] ;
  1483.      long  *data ;
  1484.  
  1485.      data =  m4check( field_ref ) ;
  1486.      rc_type =  -1 ; /* Display Nothing */
  1487.  
  1488.      if ( data != (long *) 0 )
  1489.          {
  1490.             for ( j=0; j< 5; j++ )
  1491.             {
  1492.            c4ltoa( data[j], buf[j], 5 ) ;
  1493.            buf[j][5] =  '\0' ;
  1494.             }
  1495.             w4display( " m4check Results ",
  1496.                        "No. of Entries in Free Chain:",
  1497.                        buf[0],
  1498.                        "",
  1499.                        "No. of Blocks in Free Chain:",
  1500.                        buf[1],
  1501.                        "",
  1502.                        "No. of Adjacent Entries in Free Chain:",
  1503.                        buf[2],
  1504.                        "",
  1505.                        "No. of Lost Blocks:",
  1506.                        buf[3],
  1507.                        "",
  1508.                        "No. of Blocks Used:",
  1509.                        buf[4],
  1510.                        (char *) 0 ) ;
  1511.          }
  1512.          break ;
  1513.       }
  1514.  
  1515.       case (int) 'c' + 0x100:
  1516.          parm( "memo_file_name" ) ;
  1517.          u4name_full( file_name, s_get(0), ".DBT" ) ;
  1518.      rc =  w4display( " Memo File Conversion ",
  1519.               "Are you sure the file",
  1520.               file_name,
  1521.               "is a dBASE III (III PLUS) memo file to be",
  1522.               "converted to a dBASE IV memo file ?  (Y/N)",
  1523.               (char *) 0  ) ;
  1524.          if ( rc == (int) 'y' || rc == (int) 'Y' )
  1525.             rc =  m4convert( s_get(0) ) ;
  1526.          else
  1527.          {
  1528.         s_msg   =  "\'m4convert\' was not executed." ;
  1529.         s_rc    =  "" ;
  1530.         rc_type =  MSG ;
  1531.          }
  1532.          break ;
  1533.  
  1534.       #ifndef UNIX
  1535.       case (int) 'e':
  1536.          screen =  h4alloc( 4000 ) ;
  1537.          parm( "rec_num" ) ;
  1538.          parm( "editor_name" ) ;
  1539.      parm( "max_size") ;
  1540.      l_get(0) ;
  1541.          w4read( 0,0, screen, 4000 ) ;
  1542.          rc =  m4edit( field_ref, l_get(0), s_get(1), i_get(2) ) ;
  1543.          w4write( 0,0, screen, 4000 ) ;
  1544.          h4free_memory( screen ) ;
  1545.      w4cursor(-1,-1) ;
  1546.          break ;
  1547.       #endif
  1548.  
  1549.       case (int) 'e' + 0x100:
  1550.          rc =  m4exist( field_ref ) ;
  1551.          break ;
  1552.  
  1553.       case (int) 'r':
  1554.          parm( "rec_num" ) ;
  1555.          rc =  m4read( field_ref, l_get(0), memo_buf, (int) sizeof(memo_buf) ) ;
  1556.          if ( rc > 0 )
  1557.          {
  1558.             s_rc =  memo_buf ;
  1559.         rc_type =  MSG ;
  1560.         s_msg =  "Parameter \'str\': " ;
  1561.          }
  1562.          break ;
  1563.  
  1564.       case (int) 'r'+ 0x100:
  1565.          parm( "memo_file_name" ) ;
  1566.          u4name_full( file_name, s_get(0), ".DBT" ) ;
  1567.      rc =  w4display( " Memo File Renaming ",
  1568.               "Are you sure the file",
  1569.               file_name,
  1570.               "is a dBASE IV memo file which has",
  1571.               "been renamed using DOS ?  (Y/N)",
  1572.               (char *) 0 ) ;
  1573.          if ( rc == (int) 'y' || rc == (int) 'Y' )
  1574.             rc =  m4renamed( s_get(0) ) ;
  1575.          else
  1576.          {
  1577.         s_msg =  "\'m4renamed\' was not executed." ;
  1578.         s_rc  =  "" ;
  1579.         rc_type =  MSG ;
  1580.          }
  1581.          break ;
  1582.  
  1583.       case (int) 'w':
  1584.          parm( "rec_num" ) ;
  1585.          parm( "str" ) ;
  1586.          rc =  m4write( field_ref, l_get(0), s_get(1), strlen(s_get(1)) ) ;
  1587.          break ;
  1588.  
  1589.       #ifndef UNIX
  1590.       case (int) 'e'+ 0x1000:
  1591.          screen =  h4alloc( 4000 ) ;
  1592.          parm( "rec_num" ) ;
  1593.          parm( "editor_name" ) ;
  1594.      parm( "max_size") ;
  1595.      l_get(0) ;
  1596.          w4read( 0,0, screen, 4000 ) ;
  1597.          rc =  m3edit( field_ref, l_get(0), s_get(1), i_get(2) ) ;
  1598.          w4write( 0,0, screen, 4000 ) ;
  1599.          h4free_memory( screen ) ;
  1600.      w4cursor(-1,-1) ;
  1601.          break ;
  1602.       #endif
  1603.  
  1604.       case (int) 'e'+ 0x1100:
  1605.          rc =  m3exist( field_ref ) ;
  1606.          break ;
  1607.  
  1608.       case (int) 'r'+ 0x1000:
  1609.          parm( "rec_num" ) ;
  1610.          rc =  m3read( field_ref, l_get(0), memo_buf, (int) sizeof(memo_buf) ) ;
  1611.          if ( rc > 0 )
  1612.          {
  1613.             s_rc =  memo_buf ;
  1614.         rc_type =  MSG ;
  1615.         s_msg =  "Parameter \'str\': " ;
  1616.          }
  1617.          break ;
  1618.  
  1619.       case (int) 'w'+ 0x1000:
  1620.          parm( "rec_num" ) ;
  1621.          parm( "str" ) ;
  1622.      rc =  m3write( field_ref, l_get(0), s_get(1), strlen(s_get(1)) ) ;
  1623.          break ;
  1624.  
  1625.       default:
  1626.          return( -1 ) ;
  1627.    }
  1628.  
  1629.    r =  display_results() ;
  1630.  
  1631.    w4deactivate( entry_ref ) ;
  1632.    p_reset() ;
  1633.  
  1634.    return( r ) ;
  1635. }
  1636.  
  1637.  
  1638. static char  *compile_ptr  =  (char *) 0 ;
  1639. static int    compile_base =  -1 ;
  1640.  
  1641. static char   expr[100] ;
  1642.  
  1643. static int  filter_evaluate()
  1644. {
  1645.    int  *i_ptr ;
  1646.  
  1647.    i_ptr =  (int *)  e4exec( compile_ptr ) ;
  1648.    return( *i_ptr ) ;
  1649. }
  1650.  
  1651. static int  filter_set()
  1652. {
  1653.    int  *result_ptr ;
  1654.  
  1655.    w4( w4row()+1,C_LEFT, "Enter a Logical dBASE Expression for Records to Filter") ;
  1656.  
  1657.    if ( d4select(-1) != compile_base ||  compile_base < 0 )
  1658.    {
  1659.       memset( expr, 0, (size_t) sizeof(expr) ) ;
  1660.       compile_base =  d4select(-1) ;
  1661.    }
  1662.  
  1663.    x4filter_reset() ;
  1664.    if ( compile_ptr != (char *) 0 )
  1665.    {
  1666.       h4free_memory( compile_ptr ) ;
  1667.       compile_ptr =  (char *) 0 ;
  1668.    }
  1669.  
  1670.    g4release(1) ;
  1671.    g4( w4row()+1,C_LEFT, expr ) ;
  1672.    g4width( 54, 100 ) ;
  1673.    if ( g4read() == ESC )  return 0 ;
  1674.  
  1675.    c4trim_n( expr, (int) sizeof(expr) ) ;
  1676.    if ( strlen(expr) == 0 )  return 0 ;
  1677.  
  1678.    if ( e4parse( expr, &compile_ptr ) < 0 )  return -1 ;
  1679.    result_ptr =  (int *) e4exec( compile_ptr ) ;
  1680.    if ( result_ptr == (int *) 0 )  return( -1 ) ;
  1681.  
  1682.    if ( e4type() != 'L' )
  1683.    {
  1684.       w4display( " User Error: ",
  1685.                  "Do not enter a Logical Expression",
  1686.                  "Press a key ...",
  1687.                  (char *) 0 ) ;
  1688.       return -1 ;
  1689.    }
  1690.  
  1691.    x4filter( filter_evaluate ) ;
  1692.  
  1693.    return 0 ;
  1694. }
  1695.  
  1696. static  char *  x4save_buffer =  (char *) 0 ;
  1697.  
  1698. static int  x4ext( option_code, item_ref )
  1699. int  option_code, item_ref ;
  1700. {
  1701.    long   f_ref ;
  1702.    char   f_type, *s ;
  1703.    int    menu_ref, i, r ;
  1704.    double d ;
  1705.  
  1706.    activate_entry_window( item_ref ) ;
  1707.  
  1708.    switch( option_code )
  1709.    {
  1710.       case (int) 'b':
  1711.          rc =  x4blank() ;
  1712.          break ;
  1713.  
  1714.       case (int) 'b'+ 0x100:
  1715.          rc =  x4bottom() ;
  1716.      break ;
  1717.  
  1718.       case (int) 'b'+ 0x200:
  1719.          parm( "Start Record" ) ;
  1720.          parm( "Buffer Length" ) ;
  1721.  
  1722.          if ( x4save_buffer != (char *) 0 )   h4free_memory( x4save_buffer) ;
  1723.          x4save_buffer =  malloc( (size_t) i_get(1) ) ;
  1724.          if ( x4save_buffer == (char *) 0 )
  1725.          {
  1726.             s_rc =  "d4learn Error:  Out of Memory" ;
  1727.             rc_type =  CHAR_PTR ;
  1728.          }
  1729.          else
  1730.             rc =  x4buffer( l_get(0), x4save_buffer, i_get(1) ) ;
  1731.          break ;
  1732.  
  1733.       case (int) 'b'+ 0x300:
  1734.      parm( "offset_record" ) ;
  1735.          if ( x4save_buffer != (char *) 0 )
  1736.         x4buffer_copy( i_get(0), x4save_buffer ) ;
  1737.      rc_type =  VOID ;
  1738.          break ;
  1739.  
  1740.       case (int) 'e':
  1741.          rc =  x4edit() ;
  1742.          break ;
  1743.  
  1744.       case (int) 'f':
  1745.      filter_set() ;
  1746.      rc_type =  VOID ;
  1747.          break ;
  1748.  
  1749.       case (int) 'g':
  1750.          parm( "Record Number") ;
  1751.          rc =  x4go( l_get(0) ) ;
  1752.          break ;
  1753.  
  1754.       case (int) 'i':
  1755.          parm( "Record Number" ) ;
  1756.          rc =  x4insert( l_get(0) ) ;
  1757.          break ;
  1758.  
  1759.       case (int) 'l':
  1760.      w4activate( v4default_window ) ;
  1761.      rc =  x4list() ;
  1762.      g4char() ;
  1763.      w4deactivate( v4default_window ) ;
  1764.      w4cursor(-1,-1) ;
  1765.          break ;
  1766.  
  1767.       case (int) 'r':
  1768.          parm("Expression") ;
  1769.          parm("Database Reference Number") ;
  1770.          parm("Index File Reference Number") ;
  1771.          parm("Miss Code") ;
  1772.          rc =  x4relate( s_get(0), i_get(1), i_get(2), l_get(3) ) ;
  1773.          break ;
  1774.  
  1775.       case (int) 'r'+ 0x100:
  1776.          x4relate_reset() ;
  1777.          rc_type =  VOID ;
  1778.      break ;
  1779.  
  1780.       case (int) 'r'+ 0x200:
  1781.          menu_ref =  field_name_parm() ;
  1782.      parm( "record_number" ) ;
  1783.          parm( "value" ) ;
  1784.  
  1785.          f_ref =  f4ref(s_get(0)) ;
  1786.          f_type=  f4type(f_ref) ;
  1787.      s =  s_get(2) ;
  1788.  
  1789.          switch (f_type )
  1790.          {
  1791.             case 'N':
  1792.             case 'F':
  1793.                d =  c4atod( s, strlen(s) ) ;
  1794.                rc =  x4replace( f_ref, l_get(1), (void *) (&d) ) ;
  1795.                break ;
  1796.  
  1797.             case 'L':
  1798.                if (*s == 'Y' || *s == 'y' || *s == 'T' || *s == 't')
  1799.                   i = 1 ;
  1800.                else
  1801.                   i = 0 ;
  1802.  
  1803.                rc =  x4replace( f_ref, l_get(1), (void *) (&i) ) ;
  1804.                break ;
  1805.  
  1806.             default:
  1807.                rc =  x4replace( f_ref, l_get(1), (void *) s ) ;
  1808.                break ;
  1809.          }
  1810.          w4close(menu_ref) ;
  1811.          break ;
  1812.  
  1813.       case (int) 's':
  1814.      if ( i4seek_ref() < 0 )
  1815.      {
  1816.         w4display( " User Error: ", "No index file has been opened.", (char *) 0 ) ;
  1817.         rc = 0 ;
  1818.      }
  1819.      else
  1820.      {
  1821.         parm( "Search Value") ;
  1822.         if ( i4type(i4seek_ref()) == 'N' ||
  1823.                  i4type(i4seek_ref()) == 'F' )
  1824.         {
  1825.            d =  c4atod( s_get(0), strlen(s_get(0)) ) ;
  1826.            rc =  x4seek( (char *) &d ) ;
  1827.         }
  1828.         else
  1829.            rc =  x4seek( s_get(0) ) ;
  1830.      }
  1831.          break ;
  1832.  
  1833.       case (int) 's'+ 0x100:
  1834.          parm("Number of Records") ;
  1835.          rc =  x4skip( l_get(0) ) ;
  1836.          break ;
  1837.  
  1838.       case (int) 's'+ 0x200:
  1839.          menu_ref =  field_name_parm() ;
  1840.          d_rc =  x4sum( f4ref(s_get(0)) ) ;
  1841.          w4close(menu_ref) ;
  1842.          rc_type =  DOUB ;
  1843.          break ;
  1844.  
  1845.       case (int) 't':
  1846.          rc =  x4top() ;
  1847.          break ;
  1848.  
  1849.       default:
  1850.          return( -1 ) ;
  1851.    }
  1852.  
  1853.    r =  display_results() ;
  1854.  
  1855.    w4deactivate( entry_ref ) ;
  1856.    p_reset() ;
  1857.  
  1858.    return( r ) ;
  1859. }
  1860.