home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / EXAMPLES / D4LEARN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  62.3 KB  |  2,248 lines

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