home *** CD-ROM | disk | FTP | other *** search
-
- /* d4learn.c,
- (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Tests "Code Base" routines.
- */
-
- #include "d4all.h"
- #include "w4.h"
- #include "g4char.h"
- #include "p4misc.h"
-
- #include <stdlib.h>
- #include <string.h>
-
- #define C_LEFT 7
- #define C_MIDDLE 22
- #define C_RIGHT 37
-
- #define INT 0
- #define LONG 1
- #define CHAR 2
- #define CHAR_PTR 3
- #define DOUB 4
- #define DATE 5
- #define VOID 6
- #define MSG 7
-
- #define S_GET_LEN 81
-
- static char p_buffer[5][S_GET_LEN] ;
- static int p_on = 0 ;
- static int result_ref, entry_ref ;
-
- static int rc_type = INT ;
- static int rc ;
- static long l_rc ;
- static char c_rc, *s_rc, *s_msg, buffer[MAX_KEY_SIZE+1],
- extra_buffer[MAX_KEY_SIZE+1] ;
- static double d_rc ;
- static char *extra_result = (char *) 0 ;
-
- extern int v4cur_base, v4default_window ;
- extern CB_WINDOW *v4window_ptr ;
- extern CB_WINDOW *v4window ;
- extern MENU *v4menu ;
- extern BASE *v4base ;
- extern INDEX *v4index ;
- extern BLOCK *v4block ;
-
- #ifdef TURBO
- extern unsigned _stklen = 10000 ;
- #endif
-
- static int c4conv(int) ;
- static int m4memo(int) ;
- static int e4expr(int) ;
- static int i4ind(int) ;
- static int f4field(int) ;
- static int d4data(int) ;
- static int x4ext(int) ;
- static int index_help(int) ;
- static int field_help(int) ;
- static int filter_set(void), filter_evaluate(void),
- help(int), display_results(void),
- p_reset(void), field_name_parm(void) ;
- static void activate_entry_window( int ) ;
- static char *s_get( int ) ;
- static long l_get( int ) ;
- static int i_get( int ) ;
- static double d_get( int ) ;
- static char *parm( char *) ;
- static char *parm_default( char *, char *, int ) ;
- static void c4key( char *, char *, int ) ;
-
-
- char title_buf[80] ;
-
- main()
- {
- int i_ref, main_menu, conv, data, index, field, expr, ext, memo, pos ;
-
- /* Call 'd4init_memory' and 'w4init' to specify the exact amount of memory
- needed. Note that a call to 'd4init()' would work instead. However,
- initializing in this manner saves some memory and reduces fragmentation. */
-
- w4init( 15,6,135 ) ;
- d4initialize( 2,2,10,1500,0xFC00L ) ; /* Initialize Code Base */
-
- w4popup() ; /* Make the Error Window a Popup Window */
- w4clear( -1 ) ;
- w4cursor( -1,-1 ) ;
-
- entry_ref = w4define( 0,0, 9,79 ) ;
- w4title( 0,-1, title_buf, B_WHITE ) ;
- w4border( DOUBLE, F_WHITE ) ;
- w4popup() ;
-
- result_ref = w4define( 9,0, 24,79 ) ;
- w4border( DOUBLE, F_WHITE ) ;
- w4title( 0,-1, " Return Code and Status Information ", B_WHITE ) ;
- w4popup() ;
-
- main_menu = w4define( -1,-1,-1,-1 ) ;
- #ifdef UNIX
- pos = -1 ;
- #else
- n4key_special( 0,0, ALT_Q, ALT_M ) ;
- pos = 0 ;
- #endif
-
- n4( "Conv." );
- n4key( ALT_C, 0, pos);
- n4reaction( n4sub_menu ) ;
- n4ptr_save( &conv ) ;
-
- n4start_item( n4( "Database" ) ) ;
- n4key( ALT_D, 0, pos);
- n4reaction( n4sub_menu ) ;
- n4ptr_save( &data ) ;
-
- n4( "Expression" );
- n4key( ALT_E, 0, pos);
- n4reaction( n4sub_menu ) ;
- n4ptr_save( &expr ) ;
-
- n4( "Field" );
- n4key( ALT_F, 0, pos);
- n4reaction( n4sub_menu ) ;
- n4ptr_save( &field ) ;
-
- n4( "Index" );
- n4key( ALT_I, 0, pos);
- n4reaction( n4sub_menu ) ;
- n4ptr_save( &index ) ;
-
- n4( "Memo" );
- n4key( ALT_M, 0, pos);
- n4reaction( n4sub_menu ) ;
- n4ptr_save( &memo ) ;
-
- n4( "Extended" );
- #ifdef UNIX
- n4key( ALT_X, 0,pos);
- #else
- n4key( ALT_X, 0, 1);
- #endif
- n4reaction( n4sub_menu ) ;
- n4ptr_save( &ext ) ;
-
- n4( "Help" );
- n4key( ALT_H, 0, pos);
- n4action( help ) ;
-
- n4( "Quit" );
- n4key( ALT_Q, 0, pos);
- n4parm( -1 ) ;
-
-
- conv = w4define( -1,-1,-1,-1 ) ;
- n4( "c4atod( char_string, len_string )" ) ;
- n4key( (int) 'a', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'a') ;
- n4( "c4atoi( char_string, len_string )" ) ;
- n4key( (int) 'a', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'a' + 0x100) ;
- n4( "c4atol( char_string, len_string )" ) ;
- n4key( (int) 'a', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'a' + 0x200) ;
- n4( "c4dt_julian( str_date, julian_date )" ) ;
- n4key( (int) 'a', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'd') ;
- n4( "c4dtoa( double_value, len, dec )" ) ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'd' + 0x100) ;
- n4( "c4dt_format( str_date, picture )" ) ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'd' + 0x200) ;
- n4( "c4dt_str( str_date, julian_date )" ) ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'd' + 0x300) ;
- n4( "c4dt_unformat( date_data, picture )" ) ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'd' + 0x400) ;
- n4( "c4encode( to, from, t_to, t_from )" ) ;
- n4key( (int) 'e', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'e') ;
- n4( "c4ltoa( long_value, ptr, len )" ) ;
- n4key( (int) 'l', 0, 2 ) ;
- n4action( c4conv ) ;
- n4int_save( (int) 'l') ;
-
- data = w4define( -1,-1,-1,-1 ) ;
- n4( "d4append()" ) ;
- n4key( (int) 'a', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'a') ;
- n4( "d4append_blank()" ) ;
- n4key( (int) 'a', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'a' + 0x100) ;
- n4( "d4bof()" ) ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'b') ;
- n4( "d4bottom()" ) ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'b'+ 0x100) ;
- n4( "d4buf_init( start_try, end_try, ch_try )" ) ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'b'+ 0x200) ;
- n4( "d4buf_total( num_records, max_buffers, may_lend )" ) ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'b'+ 0x300) ;
- n4( "d4buf_unit( num_records )" ) ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'b'+ 0x400) ;
- n4( "d4close()" ) ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'c') ;
- n4( "d4create( name, ... )" ) ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'c' + 0x100) ;
- n4( "d4delete( rec_num )") ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'd') ;
- n4( "d4deleted()") ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'd' + 0x100) ;
- n4( "d4eof()") ;
- n4key( (int) 'e', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'e') ;
- n4( "d4go( rec_num )") ;
- n4key( (int) 'g', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'g') ;
- n4( "d4lock( lock_code, wait )") ;
- n4key( (int) 'l', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'l') ;
- n4( "d4pack()") ;
- n4key( (int) 'p', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'p') ;
- n4( "d4recall(rec_num)") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'r') ;
- n4( "d4reccount()") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'r'+ 0x100) ;
- n4( "d4recno()") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'r'+ 0x200) ;
- n4( "d4ref( name )") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'r'+ 0x300) ;
- n4( "d4seek_double( doub_value )" ) ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 's') ;
- n4( "d4seek_str( search_string )" ) ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 's' + 0x100) ;
- n4( "d4select( base_ref )" ) ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 's' + 0x200) ;
- n4( "d4skip( num_records )" ) ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 's' + 0x300) ;
- n4( "d4unlock( lock_code )" ) ;
- n4key( (int) 'u', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'u') ;
- i_ref = n4( "d4use( name )" ) ;
- n4start_item( i_ref ) ;
- n4key( (int) 'u', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'u' + 0x100) ;
- n4( "d4top()") ;
- n4key( (int) 't', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 't') ;
- n4( "d4write( rec_num )") ;
- n4key( (int) 'w', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'w') ;
- n4( "d4zap( start_rec, end_rec )") ;
- n4key( (int) 'z', 0, 2 ) ;
- n4action( d4data ) ;
- n4int_save( (int) 'z') ;
-
- expr = w4define( -1,-1,-1,-1 ) ;
- n4( "e4eval( expression )" ) ;
- n4key( (int) 'e', 0, 2 ) ;
- n4action( e4expr ) ;
- n4int_save( (int) 'e') ;
- n4( "e4type()" ) ;
- n4key( (int) 't', 0, 2 ) ;
- n4action( e4expr ) ;
- n4int_save( (int) 't') ;
-
- field = w4define( -1,-1,-1,-1 ) ;
- n4( "Field Ref. Number Help" ) ;
- n4key( 'h', 0, 18 ) ;
- n4action( field_help ) ;
- n4skip_over( n4(""), 1 ) ;
- n4( "f4char( field_ref )" ) ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'c') ;
- n4( "f4decimals( field_ref )" ) ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'd') ;
- n4( "f4double( field_ref )" ) ;
- n4key( (int) 'd', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'd'+0x100) ;
- n4( "f4int( field_ref )" ) ;
- n4key( (int) 'i', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'i') ;
- n4( "f4j_ref( j_field )" ) ;
- n4key( (int) 'j', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'j') ;
- n4( "f4long( field_ref )" ) ;
- n4key( (int) 'l', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'l') ;
- n4( "f4name( field_ref )" ) ;
- n4key( (int) 'n', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'n') ;
- n4( "f4ncpy( field_ref, mem_ptr, n )" ) ;
- n4key( (int) 'n', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'n' + 0x100) ;
- n4( "f4num_fields( field_ref )" ) ;
- n4key( (int) 'n', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'n' + 0x200) ;
- n4( "f4ptr( field_ref )" ) ;
- n4key( (int) 'p', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'p') ;
- n4( "f4record()" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r') ;
- n4( "f4record_width()" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r' + 0x100) ;
- n4( "f4ref( field_name )" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r' + 0x200) ;
- n4( "f4r_char( field_ref, chr )" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r' + 0x300) ;
- n4( "f4r_double( field_ref, double_value )" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r' + 0x400) ;
- n4( "f4r_int( field_ref, int_value )" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r' + 0x500) ;
- n4( "f4r_long( field_ref, long_value )" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r' + 0x600) ;
- n4( "f4r_str( field_ref, ptr )" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'r' + 0x700) ;
- n4( "f4str( field_ref )" ) ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 's') ;
- n4( "f4true( field_ref )" ) ;
- n4key( (int) 't', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 't') ;
- n4( "f4type( field_ref )" ) ;
- n4key( (int) 't', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 't' + 0x100) ;
- n4( "f4value( field_ref )" ) ;
- n4key( (int) 'v', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'v') ;
- n4( "f4width( field_ref )" ) ;
- n4key( (int) 'w', 0, 2 ) ;
- n4action( f4field ) ;
- n4int_save( (int) 'w') ;
-
- index = w4define( -1,-1,-1,-1 ) ;
- n4( "Index File Reference Number Help" ) ;
- n4key( (int) 'h', 0, 28) ;
- n4action( index_help ) ;
- n4skip_over( n4(""), 1 ) ;
- n4( "i4add( index_ref, key_ptr, rec_num )") ;
- n4key( (int) 'a', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'a') ;
- n4( "i4bottom( index_ref )") ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'b') ;
- n4( "i4check( index_ref )") ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'c') ;
- n4( "i4close( index_ref )") ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'c' + 0x100) ;
- n4( "i4eval( index_ref )") ;
- n4key( (int) 'e', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'e') ;
- n4( "i4go( index_ref, key_ptr, rec_num )") ;
- n4key( (int) 'g', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'g') ;
- n4( "i4index( name, expression, unique, safety )" ) ;
- n4key( (int) 'i', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'i') ;
- n4( "i4lock( index_ref, wait )") ;
- n4key( (int) 'l', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'l') ;
- n4( "i4open( name )") ;
- n4key( (int) 'o', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'o') ;
- n4( "i4ref( name )") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'r') ;
- n4( "i4reindex( index_ref )") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'r' + 0x100) ;
- n4( "i4remove( index_ref, key_ptr, rec_num )") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'r' + 0x200) ;
- n4( "i4seek( index_ref, key_ptr )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 's') ;
- n4( "i4seek_ref()") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 's' + 0x100) ;
- n4( "i4select( index_ref )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 's' + 0x200) ;
- n4( "i4skip( index_ref, n )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 's' + 0x300) ;
- n4( "i4top( index_ref )") ;
- n4key( (int) 't', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 't') ;
- n4( "i4type( index_ref )") ;
- n4key( (int) 't', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 't' + 0x100) ;
- n4( "i4unlock( index_ref )") ;
- n4key( (int) 'u', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'u') ;
- n4( "i4unselect()") ;
- n4key( (int) 'u', 0, 2 ) ;
- n4action( i4ind ) ;
- n4int_save( (int) 'u' + 0x100) ;
-
- memo = w4define( -1,-1,-1,-1 ) ;
- n4( "m4check( field_ref )" ) ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'c') ;
- n4( "m4convert( memo_file_name )" ) ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'c' + 0x100) ;
- #ifndef UNIX
- n4( "m4edit( field_ref, rec_num, editor, size )" ) ;
- n4key( (int) 'e', 0, 2 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'e') ;
- #endif
- n4( "m4exist( field_ref )") ;
- n4key( (int) 'e', 0, 2 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'e' + 0x100) ;
- n4( "m4read( field_ref, rec_num, str, str_len )") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'r') ;
- n4( "m4renamed( memo_file_name )" ) ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'r' + 0x100) ;
- n4( "m4write( field_ref, rec_num, str, str_len )") ;
- n4key( (int) 'w', 0, 2 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'w') ;
-
- n4skip_over( n4( "-------------------------------------------" ), 1 ) ;
-
- #ifndef UNIX
- n4( "m3edit( field_ref, rec_num, editor, size )") ;
- n4key( (int) '3', 0, 1 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'e'+ 0x1000) ;
- #endif
- n4( "m3exist( field_ref )") ;
- n4key( (int) '3', 0, 1 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'e' + 0x1100) ;
- n4( "m3read( field_ref, rec_num, str, str_len )") ;
- n4key( (int) '3', 0, 1 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'r' + 0x1000) ;
- n4( "m3write( field_ref, rec_num, str, str_len )") ;
- n4key( (int) '3', 0, 1 ) ;
- n4action( m4memo ) ;
- n4int_save( (int) 'w' + 0x1000) ;
-
- ext = w4define( -1,-1,-1,-1 ) ;
- n4( "x4blank()") ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'b') ;
- n4( "x4bottom()") ;
- n4key( (int) 'b', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'b' + 0x100) ;
- n4( "x4copy( new_base, start_rec, safety )") ;
- n4key( (int) 'c', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'c' ) ;
- n4( "x4filter( (*filter_routine)()") ;
- n4key( (int) 'f', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'f') ;
- n4( "x4go( record_number )") ;
- n4key( (int) 'g', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'g') ;
- n4( "x4insert( record_number )") ;
- n4key( (int) 'i', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'i') ;
- n4( "x4list()") ;
- n4key( (int) 'l', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'l') ;
- n4( "x4pack( safety )") ;
- n4key( (int) 'p', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'p' ) ;
- n4( "x4relate( expr, base_ref, index_ref, miss_code )") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'r') ;
- n4( "x4relate_reset()") ;
- n4key( (int) 'r', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 'r' + 0x100) ;
- n4( "x4seek_double( double_value )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 's') ;
- n4( "x4seek_str( search_string )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 's' + 0x100) ;
- n4( "x4skip( num_records )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 's' + 0x200) ;
- n4( "x4sort( file_name, expr, start_rec, safety )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 's' + 0x300) ;
- n4( "x4sum( field_ref )") ;
- n4key( (int) 's', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 's' + 0x400) ;
- n4( "x4top()" ) ;
- n4key( (int) 't', 0, 2 ) ;
- n4action( x4ext ) ;
- n4int_save( (int) 't') ;
-
- n4pulldown( main_menu ) ;
- n4activate( main_menu ) ;
-
- w4exit(0) ;
- }
-
- static int help( int junk_parm )
- {
- w4display( " HELP ",
- " Use \'d4learn\' to test the use of Code Base 4 routines.",
- "The pulldown menu system is used to select the routine. Once",
- "the routine is selected, \'d4learn\' prompts for the parameters,",
- "executes the routine, and then displays the results.",
- "",
- " The <Alt> keys are used to select between options on the",
- "top menu bar. For example, to move to the database Routines,",
- "press <Alt D>. In addition, <Alt X> is used for the extended",
- "routines.",
- "",
- " Note that not all of the sub-menu items fit on the screen.",
- "Consequently, menu scrolling is used to select routines such",
- "as \'f4width\'.",
- (char *) 0 ) ;
- return 0 ;
- }
-
- static int p_reset()
- {
- p_on = 0 ;
- rc_type = INT ;
- w4position( 0,0 ) ;
- return( 0 ) ;
- }
-
- static char * parm( char *message )
- {
- return( parm_default( message, (char *) 0, 0) ) ;
- }
-
- static char * parm_default( char *message, char *def, int def_len )
- {
- int m_len, pos ;
-
- if ( p_on > 4 ) p_on = 4 ;
- m_len = (int) strlen(message) ;
-
- if ( w4row() >= v4window_ptr->height-1 || w4row() == 0 )
- w4clear(0) ;
-
- w4( w4row()+1, C_LEFT, message ) ;
- memset( p_buffer[p_on], (int) ' ', sizeof(p_buffer[0]) ) ;
-
- if ( def != (char *) 0 )
- {
- if ( def_len > sizeof(p_buffer[0]) )
- memcpy( p_buffer[p_on], def, sizeof(p_buffer[0]) ) ;
- else
- memcpy( p_buffer[p_on], def, def_len ) ;
- }
- p_buffer[p_on][sizeof(p_buffer[0])-1] = '\0' ;
-
- if ( m_len > 40 )
- {
- w4position( w4row()+1,0 ) ;
- g4( w4row(), C_LEFT, p_buffer[p_on] ) ;
- g4width( 80, 55 ) ;
- }
- else
- {
- pos = 15 ;
- if ( m_len > 13 ) pos = m_len + 2 ;
- g4( w4row(), C_LEFT+pos, p_buffer[p_on] ) ;
- g4width( 79, 40-pos+15 ) ;
- }
-
- return( p_buffer[p_on++] ) ;
- }
-
- static char * s_get(int i)
- {
- if ( p_on >= 0 )
- {
- p_on = -1 ;
- g4read() ;
- }
- return( p_buffer[i] ) ;
- }
-
- static int i_get(int i)
- {
- return( atoi(s_get(i)) ) ;
- }
-
- static long l_get(int i)
- {
- return( atol(s_get(i)) ) ;
- }
-
- static double d_get(int i)
- {
- return( strtod( s_get(i), (char **) 0) ) ;
- }
-
- static int chk_fld( GET *) ;
- static int chk_fld( GET *get_ptr )
- {
- if ( memcmp( get_ptr->data, " ", 1 ) == 0 )
- return -1 ;
- else
- return 0 ;
- }
-
- static int field_name_parm()
- {
- int w_ref, get_ref ;
- int i ;
-
- get_ref = w4select(-1) ;
-
- w_ref = w4define( -1,-1,-1,-1 ) ;
-
- for ( i=1; i <= f4num_fields(); i++ )
- n4( f4name(f4j_ref(i)) ) ;
-
- w4select( get_ref ) ;
-
- parm( "Field Name" ) ;
- g4call( g4menu, w_ref ) ;
- g4valid( chk_fld ) ;
- n4get_calc( get_ref ) ;
-
- return( w_ref ) ;
- }
-
-
- static void file_name_parm( char * ) ;
- static void file_name_free( void ) ;
- static char *file_menu_data = (char *) 0 ;
- static int file_w_ref = -1 ;
-
- static void file_name_free()
- {
- if ( file_menu_data != (char *) 0) h4free_memory( file_menu_data ) ;
- file_menu_data = (char *) 0 ;
-
- if ( file_w_ref >= 0 ) w4close( file_w_ref ) ;
- file_w_ref = -1 ;
- }
-
- static void file_name_parm( char *pattern )
- {
- int n_data, i, rc, get_ref ;
- char count_data[14] ;
-
- get_ref = w4select( -1 ) ;
-
- for( rc = u4file_first(pattern,count_data), n_data= 0; rc == 0; n_data +=14)
- rc = u4file_next( count_data ) ;
-
- if ( n_data == 0 )
- {
- #ifndef UNIX
- w4display( " Informative Message: ",
- "There are no files for wildcard pattern",
- pattern, "in the current directory.",
- "",
- "Press a key.",
- (char *) 0 ) ;
- #endif
- parm( "File Name" ) ;
- return ;
- }
-
- file_w_ref = w4define( -1,-1,-1,-1 ) ;
-
- /* Allocate Enough File Memory */
- file_menu_data = (char *) h4alloc( n_data ) ;
-
- rc = u4file_first(pattern, file_menu_data ) ;
- n4( file_menu_data ) ;
- n4key( (int) file_menu_data[0], 0, 0 ) ;
-
- for ( i= 14; i< n_data ; i+= 14 )
- {
- if ( u4file_next( file_menu_data+i ) != 0 ) break ;
- n4( file_menu_data+i ) ;
- n4key( (int) file_menu_data[i], 0, 0 ) ;
- }
-
- w4select( get_ref ) ;
- parm( "File Name, Press <F1> for a menu of choices." ) ;
-
- g4call( g4menu_help, file_w_ref ) ;
- n4get_calc( get_ref ) ;
- }
-
-
- static int display_results()
- {
- int cur_index, cur_base ;
- char buf[40] ;
-
- cur_index = i4seek_ref() ;
- cur_base = d4select(-1) ;
-
- w4activate( result_ref ) ;
-
- /* Print out Database Information */
- w4( 1, C_LEFT, "Selected Database: " ) ;
- if ( cur_base < 0)
- w4out( "NONE" ) ;
- else
- {
- w4out( v4base[cur_base].name ) ;
- w4long( w4row(), w4col(), (long) f4num_fields(), 6) ;
- w4out( " Fields" ) ;
- w4out( " Record Num:" ) ;
- w4long( w4row(), w4col(), d4recno(), 6 ) ;
- w4position( w4row()+1,C_LEFT ) ;
- if ( d4locked(-1L) )
- w4out( "The Database is Locked." ) ;
- if ( v4base[cur_base].rec_lock >0 )
- {
- w4out( "Record Locked:" ) ;
- w4long( w4row(), w4col(), (long) v4base[cur_base].rec_lock, 6 ) ;
- }
- if ( d4locked(0L) && ! d4locked(-1L) )
- w4out( " The Record Count Bytes are Locked" ) ;
- if ( C_LEFT != w4col() ) w4position( w4row()+1,C_LEFT) ;
-
- w4( w4row()+1, C_LEFT, "Database Buffer: " ) ;
- if ( f4record_width() < 130 )
- w4out( (char *) f4record() ) ;
- else
- w4num( w4row(),w4col(), (char *) f4record(), 130 ) ;
- }
-
-
- /* Print out Index File Information */
- if ( cur_index >= 0)
- {
- KEY *key_ptr ;
- char *ptr ;
-
- if ( v4base[cur_base].current_index >= 0)
- w4( w4row()+2, C_LEFT, "Selected Index File: " ) ;
- else
- w4( w4row()+2, C_LEFT, "Default Index File: " ) ;
- w4out( v4index[cur_index].name ) ;
- if ( v4index[cur_index].lock )
- w4out( " Locked" ) ;
- w4( w4row()+1, C_LEFT, "Key Expression: " ) ;
- strncpy( buffer, v4index[cur_index].expression, sizeof(buffer) ) ;
- c4trim_n( buffer, w4width(-1)-w4col() ) ;
- w4out( buffer ) ;
- if ( v4base[cur_base].rec_num > 0 )
- {
- w4( w4row()+1, C_LEFT, "Evaluated Index Expression: " ) ;
- ptr = i4eval( cur_index ) ;
- c4key( ptr, ptr, (int) i4type(cur_index) ) ;
- w4out( ptr ) ;
- }
-
- key_ptr = i4key(cur_index) ;
- if ( key_ptr != (KEY *) 0 &&
- v4block[v4index[cur_index].block_ref].key_on
- < v4block[v4index[cur_index].block_ref].num_keys)
- {
- w4( w4row()+1, C_LEFT, "Current Key Value: " ) ;
- memcpy( buffer, key_ptr->value, v4index[cur_index].key_len ) ;
- buffer[ v4index[cur_index].key_len ] = '\0' ;
- c4key( buffer, buffer, (int) i4type(cur_index) ) ;
- w4out( buffer ) ;
- w4( w4row()+1, C_LEFT, "Index Key's Record No:" ) ;
- w4long( w4row(), w4col(), key_ptr->rec_num, 10 ) ;
- }
- }
-
- /* Print out RC information */
- w4position( w4row()+2, 0 ) ;
- switch( rc_type )
- {
- int len ;
-
- case INT:
- w4( w4row(), C_LEFT, "(int) Function Return:") ;
- c4ltoa( (long) rc, buf, 6 ) ;
- buf[6] = '\0' ;
- w4out( buf ) ;
- break ;
-
- case LONG:
- w4( w4row(), C_LEFT, "(long) Function Return:") ;
- c4ltoa( l_rc, buf, 10 ) ;
- buf[10] = '\0' ;
- w4out( buf ) ;
- break ;
-
- case CHAR:
- w4( w4row(), C_LEFT, "(char) Function Return: ") ;
- buffer[0] = c_rc ;
- buffer[1] = '\0' ;
- w4out( buffer ) ;
- break ;
-
- case DOUB:
- w4( w4row(), C_LEFT, "(double) Function Return: ") ;
- s_rc = c4dtoa( d_rc, 34, 16 ) ;
- len = (int) strlen( s_rc ) ;
- while ( s_rc[--len] == '0' ) if ( len >= 0 ) s_rc[len] = '\0' ;
- while ( *s_rc == ' ' ) s_rc++ ;
- w4out( s_rc ) ;
- break ;
-
- case DATE:
- case CHAR_PTR:
- case MSG:
- if (rc_type == DATE)
- w4( w4row(), C_LEFT, "(DATE) Function Return: ") ;
- if (rc_type == CHAR_PTR)
- w4( w4row(), C_LEFT, "(char *) Function Return: ") ;
- if (rc_type == MSG)
- w4( w4row(), C_LEFT, s_msg ) ;
-
- if ( s_rc == (char *) 0)
- w4out( "NULL POINTER") ;
- else
- {
- strncpy( buffer, s_rc, sizeof(buffer) ) ;
- buffer[sizeof(buffer)-1] = '\0' ;
- w4out( buffer ) ;
- }
- break ;
-
- case VOID:
- w4( w4row(),C_LEFT, "Void Return" ) ;
- break ;
- }
-
- /* Display any Extra Information */
- if ( extra_result != (char *) 0 )
- {
- w4( w4row()+1,C_LEFT, extra_result ) ;
- extra_result = (char *) 0 ;
- }
-
- rc = g4char() ;
-
- w4deactivate( result_ref ) ;
-
- return( rc ) ;
- }
-
- static void activate_entry_window( int item_ref )
- {
- strcpy( title_buf, "PARAMETER ENTRY: " ) ;
- strcat( title_buf, v4menu[item_ref].item_ptr ) ;
- w4activate( entry_ref ) ;
- w4position( 0,0 ) ;
- }
-
- static int c4conv( int item_ref )
- {
- int i, r ;
- double d ;
- int option_code ;
-
- option_code = n4int_get( item_ref ) ;
-
- activate_entry_window( item_ref ) ;
-
- switch( option_code )
- {
- case (int) 'a':
- parm( "char_string" ) ;
- parm( "len_string" ) ;
- i = i_get(1) ;
- if ( i > 70 ) i = 70 ;
- d_rc = c4atod( s_get(0), i ) ;
- rc_type = DOUB ;
- break ;
-
- case (int) 'a'+ 0x100:
- parm( "char_string" ) ;
- parm( "len_string" ) ;
- i = i_get(1) ;
- if ( i > 70 ) i = 70 ;
- rc = c4atoi( s_get(0), i ) ;
- break ;
-
- case (int) 'a'+ 0x200:
- parm( "char_string" ) ;
- parm( "len_string" ) ;
- i = i_get(1) ;
- if ( i > 70 ) i = 70 ;
- l_rc = c4atol( s_get(0), i ) ;
- rc_type = LONG ;
- break ;
-
- case (int) 'd':
- parm( "String Date" ) ;
- rc = c4dt_julian( s_get(0), &d ) ;
- if ( rc != -1 )
- {
- extra_result = extra_buffer ;
- strcpy( extra_result, "Julian Date Result:" ) ;
- strcat( extra_result, c4dtoa(d,10,0) ) ;
- }
- break ;
-
- case (int) 'd'+0x100:
- parm( "double_value" ) ;
- parm( "len_string" ) ;
- parm( "dec" ) ;
- i = i_get(1) ;
- if ( i > 70 ) i = 70 ;
- s_rc = c4dtoa( d_get(0), i, i_get(2) ) ;
- s_rc[i] = '\0' ;
- rc_type = CHAR_PTR ;
- break ;
-
- case (int) 'd'+ 0x200:
- parm("String Date (Ex. 19880430)") ;
- parm("Picture (Ex. CCYY.MM.DD)") ;
- s_rc = c4dt_format( s_get(0), s_get(1) ) ;
- rc_type = CHAR_PTR ;
- break ;
-
- case (int) 'd'+ 0x300:
- parm( "Julian Double" ) ;
-
- memset( extra_buffer, 0, sizeof(extra_buffer) ) ;
- strcpy( extra_buffer, "String Date Result:" ) ;
-
- d = d_get(0) ;
- c4dt_str( extra_buffer+(int) strlen(extra_buffer), &d ) ;
- extra_result = extra_buffer ;
- rc_type = VOID ;
- break ;
-
- case (int) 'd'+ 0x400:
- parm("date_data") ;
- parm("picture") ;
- s_rc = c4dt_unformat( s_get(0), s_get(1) ) ;
- rc_type = CHAR_PTR ;
- break ;
-
- case 'e':
- parm("from") ;
- parm("t_to") ;
- parm("t_from") ;
- c4encode( extra_buffer, s_get(0), s_get(1), s_get(2) ) ;
- s_rc = extra_buffer ;
- rc_type = CHAR_PTR ;
- break ;
-
- case 'l':
- parm( "long_value" ) ;
- parm( "len_string" ) ;
- i = i_get(1) ;
- if ( i > 70 ) i = 70 ;
- s_rc = c4ltoa( l_get(0), extra_buffer, i ) ;
- s_rc[i] = '\0' ;
- rc_type = CHAR_PTR ;
- break ;
-
- default:
- return( -1 ) ;
- }
-
- r = display_results() ;
-
- w4deactivate( entry_ref ) ;
- p_reset() ;
-
- return( r ) ;
- }
-
-
- static int d4data( int item_ref )
- {
- int i, r ;
- int option_code ;
-
- option_code = n4int_get( item_ref ) ;
-
- if ( d4select(-1)< 0 && option_code != (int) 'u'+0x100 &&
- option_code != (int) 'c'+0x100 )
- {
- w4display( "First use or create a database.", (char *) 0 ) ;
- return 0 ;
- }
-
- v4window[ v4menu[item_ref].window_ref].start_item = -1 ;
- activate_entry_window( item_ref ) ;
-
- switch( option_code )
- {
- case (int) 'a':
- parm_default( "Enter Record to Append - <Enter> for Current Buffer",
- (char *) f4record(), f4record_width() ) ;
-
- i = (int) strlen( s_get(0) ) ;
- if ( i > 0 )
- {
- if ( i >= f4record_width() )
- i = f4record_width()-1 ;
- memcpy( f4record(), s_get(0), i ) ;
- }
- rc = d4append() ;
- break ;
-
- case (int) 'a'+0x100:
- rc = d4append_blank() ;
- break ;
-
- case (int) 'b':
- rc = d4bof() ;
- break ;
-
- case (int) 'b'+ 0x100:
- rc = d4bottom() ;
- break ;
-
- case (int) 'b'+ 0x200:
- parm( "Start Allocation to Try" ) ;
- parm( "Last Allocation to Try" ) ;
- parm( "Amount to Change" ) ;
- l_rc = d4buf_init( l_get(0), l_get(1), l_get(2) ) ;
- rc_type = LONG ;
- break ;
-
- case (int) 'b'+ 0x300:
- parm( "Number of Records" ) ;
- parm( "Maximum Buffers" ) ;
- parm( "May Lend (1/0)" ) ;
- rc = d4buf_total( l_get(0), i_get(1), i_get(2) ) ;
- break ;
-
- case (int) 'b'+ 0x400:
- parm( "Number of Records" ) ;
- rc = d4buf_unit( l_get(0) ) ;
- break ;
-
- case (int) 'c':
- rc = d4close() ;
- break ;
-
- case (int) 'c'+ 0x100:
- {
- int num_fields, safety, i_field ;
- FIELD *field_ptr, *field_on ;
- char file_name[82] ;
-
- parm("File Name" ) ;
- parm("Number of Fields" ) ;
- parm("Safety" ) ;
-
- memcpy( file_name, s_get(0), sizeof(file_name) ) ;
- num_fields = i_get(1) ;
- if ( num_fields <= 0 ) num_fields = 1 ;
-
- safety = i_get(2) ;
- field_ptr = (FIELD *) h4alloc( sizeof(FIELD)*num_fields ) ;
-
- field_on = field_ptr ;
- for ( i_field = 0; i_field < num_fields; i_field++ )
- {
- p_reset() ;
-
- parm( "Field Name" ) ;
- parm( "Field Type" ) ;
- parm( "Field Width" ) ;
- parm( "Field Decimals" ) ;
-
- memcpy( field_on->name, s_get(0), sizeof(field_on->name) ) ;
- memcpy( &field_on->type, s_get(1), 1 ) ;
- field_on->width = i_get(2) ;
- field_on->decimals = i_get(3) ;
- field_on++ ;
- }
-
- rc = d4create( file_name, num_fields, field_ptr, safety ) ;
- h4free_memory( (char *) field_ptr ) ;
-
- break ;
- }
-
- case (int) 'd':
- parm("Record Number" ) ;
- rc = d4delete( l_get(0) ) ;
- break ;
-
- case (int) 'd'+ 0x100:
- rc = d4deleted() ;
- break ;
-
- case (int) 'e':
- rc = d4eof() ;
- break ;
-
- case (int) 'g':
- parm("Record Number" ) ;
- rc = d4go( l_get(0) ) ;
- break ;
-
- case (int) 'l':
- parm( "Lock Code" ) ;
- parm( "Wait" ) ;
- rc = d4lock( l_get(0), i_get(1) ) ;
- break ;
-
- case (int) 'p':
- rc = d4pack() ;
- break ;
-
- case (int) 'r':
- parm( "Record Number" ) ;
- rc = d4recall( l_get(0) ) ;
- break ;
-
- case (int) 'r'+ 0x100:
- l_rc = d4reccount() ;
- rc_type = LONG ;
- break ;
-
- case (int) 'r'+ 0x200:
- l_rc = d4recno() ;
- rc_type = LONG ;
- break ;
-
- case (int) 'r'+ 0x300:
- parm( "Database Name" ) ;
- rc = d4ref( s_get(0) ) ;
- break ;
-
- case (int) 's':
- parm( "Search Value (Numeric Value)") ;
- rc = d4seek_double( d_get(0) ) ;
- break ;
-
- case (int) 's'+ 0x100:
- parm( "Search Value") ;
- c4trim_n( s_get(0), S_GET_LEN ) ;
- rc = d4seek_str( s_get(0) ) ;
- break ;
-
- case (int) 's'+ 0x200:
- parm("Database Reference Number") ;
- rc = d4select( i_get(0) ) ;
- break ;
-
- case (int) 's'+ 0x300:
- parm("Number of Records") ;
- rc = d4skip( l_get(0) ) ;
- break ;
-
- case (int) 't':
- rc = d4top() ;
- break ;
-
- case (int) 'u':
- parm("Lock Code") ;
- rc = d4unlock( l_get(0) ) ;
- break ;
-
- case (int) 'u'+ 0x100:
- file_name_parm( "*.DBF" ) ;
- c4trim_n( s_get(0), (int) sizeof(p_buffer[0]) ) ;
-
- rc = d4use( s_get(0) ) ;
- file_name_free() ;
- break ;
-
- case (int) 'w':
- parm_default( "Enter Record to Write - <Enter> for Current Buffer",
- (char *) f4record(), f4record_width() ) ;
- parm( "Record Number") ;
-
- i = (int) strlen( s_get(0) ) ;
- if ( i > 0 )
- {
- if ( i >= f4record_width() )
- i = f4record_width()-1 ;
- memcpy( f4record(), s_get(0), i ) ;
- }
- rc = d4write( l_get(1) ) ;
- break ;
-
- case (int) 'z':
- parm( "Starting Record" ) ;
- parm("Ending Record") ;
- rc = d4zap( l_get(0), l_get(1) ) ;
- break ;
-
- default:
- return( -1 ) ;
-
- }
-
- r = display_results() ;
-
- w4deactivate( entry_ref ) ;
- p_reset() ;
-
- return( r ) ;
- }
-
-
- static int field_help( int junk_parm )
- {
- w4display( " Field Reference Number Help ",
- " The \'field_ref\' uniquely specifies a field and",
- "is obtained by a call to \'f4j_ref\' or \'f4ref\'.",
- "However, to make things simpler while using \'d4learn\',",
- "you will select from a menu of field names.",
- "",
- " Normally, \'f4ref\' would be called once, after the",
- "corresponding database is opened, for each field to be",
- "used. Assign the field reference number returned by",
- "\'f4ref\' to globally declared long integer varaibles.",
- "Note that it does not matter which database is selected",
- "when using field routines with field reference numbers.",
- "This is because the two high order bytes, of a field",
- "reference number, contain the database reference number!",
- (char *) 0 ) ;
- return 0 ;
- }
-
-
- static int f4field( int item_ref )
- {
- int menu_ref, r, n, is_done ;
- int option_code ;
-
- option_code = n4int_get( item_ref ) ;
-
- if ( d4select(-1) < 0 )
- {
- w4display( " User Error: ",
- "Do not use the field routines",
- "when no database is being used.",
- (char *) 0 ) ;
- return 0 ;
- }
-
- activate_entry_window( item_ref ) ;
- rc = menu_ref = -1 ;
- is_done = 1 ;
-
- switch( option_code )
- {
- case (int) 'j':
- parm( "Field Number" ) ;
- l_rc = f4j_ref( i_get(0) ) ;
- rc_type = LONG ;
- break ;
-
- case (int) 'n'+ 0x100:
- menu_ref = field_name_parm() ;
- parm( "num_bytes" ) ;
- n = i_get(1) ;
-
- strcpy( extra_buffer, "\'mem_ptr\' result: " ) ;
- r = (int) strlen(extra_buffer) ;
- if ( n >= (int) sizeof(extra_buffer)-r)
- n = (int) sizeof(extra_buffer) -1 -r ;
-
- if ( (l_rc = f4ref(s_get(0))) >= 0L)
- {
- rc = f4ncpy( f4ref(s_get(0)), extra_buffer+r, n ) ;
- extra_result = extra_buffer ;
- }
- break ;
-
- case (int) 'n'+ 0x200:
- rc = f4num_fields() ;
- break ;
-
- case (int) 'r':
- s_rc = (char *) f4record() ;
- rc_type = CHAR_PTR ;
- break ;
-
- case (int) 'r'+ 0x100:
- rc = f4record_width() ;
- break ;
-
- case (int) 'r'+ 0x300:
- rc_type = VOID ;
- menu_ref= field_name_parm() ;
- parm( "Single Character" ) ;
- if ( (l_rc = f4ref( s_get(0))) >= 0L )
- f4r_char( l_rc, *s_get(1) ) ;
- break ;
-
- case (int) 'r'+ 0x400:
- rc_type = VOID ;
- menu_ref= field_name_parm() ;
- parm( "Double Value" ) ;
- if ( (l_rc = f4ref( s_get(0))) >= 0L )
- f4r_double( l_rc, d_get(1) ) ;
- break ;
-
- case (int) 'r'+ 0x500:
- rc_type = VOID ;
- menu_ref= field_name_parm() ;
- parm( "Integer Value" ) ;
- if ( (l_rc = f4ref( s_get(0))) >= 0L )
- f4r_int( l_rc, i_get(1) ) ;
- break ;
-
- case (int) 'r'+ 0x600:
- rc_type = VOID ;
- menu_ref= field_name_parm() ;
- parm( "Long Value" ) ;
- if ( (l_rc = f4ref( s_get(0))) >= 0L )
- f4r_long( l_rc, l_get(1) ) ;
- break ;
-
- case (int) 'r'+ 0x700:
- rc_type = VOID ;
- menu_ref= field_name_parm() ;
- parm( "Character String" ) ;
- if ( (l_rc = f4ref( s_get(0))) >= 0L )
- f4r_str( l_rc, s_get(1) ) ;
- break ;
-
- default:
- is_done = 0 ;
- }
-
- if ( ! is_done )
- {
- menu_ref = field_name_parm() ;
- if ( (l_rc = f4ref(s_get(0))) >= 0L )
- {
- switch (option_code)
- {
- case (int) 'c':
- rc = f4char( l_rc ) ;
- break ;
-
- case (int) 'd':
- rc = f4decimals( l_rc ) ;
- break ;
-
- case (int) 'd'+0x100:
- d_rc = f4double( l_rc ) ;
- rc_type = DOUB ;
- break ;
-
- case (int) 'i':
- rc = f4int( l_rc ) ;
- break ;
-
- case (int) 'l':
- l_rc = f4long( l_rc ) ;
- rc_type = LONG ;
- break ;
-
- case (int) 'n':
- s_rc = f4name( l_rc ) ;
- rc_type = CHAR_PTR ;
- break ;
-
- case (int) 'p':
- s_rc = f4ptr( l_rc ) ;
- rc_type = CHAR_PTR ;
- break ;
-
- case (int) 'r'+ 0x200:
- rc_type = LONG ;
- break ;
-
- case (int) 's':
- s_rc = f4str( l_rc ) ;
- rc_type = CHAR_PTR ;
- break ;
-
- case (int) 't':
- rc = f4true( l_rc ) ;
- break ;
-
- case (int) 't'+ 0x100:
- c_rc = f4type( l_rc ) ;
- rc_type = CHAR ;
- break ;
-
- case (int) 'v':
- d_rc = f4value( l_rc ) ;
- rc_type = DOUB ;
- break ;
-
- case (int) 'w':
- rc = f4width( l_rc ) ;
- break ;
-
- default:
- return( -1 ) ;
- }
- }
- }
-
-
- r = display_results() ;
-
- if ( menu_ref >= 0 )
- w4close( menu_ref ) ;
-
- w4deactivate( entry_ref ) ;
- p_reset() ;
-
- return( r ) ;
- }
-
-
- static int index_help( int junk_parm )
- {
- w4display( " Index File Reference Number Help ",
- " d4learn automatically supplies the index file",
- "reference number parameter for any index file routine",
- "which requires one. The index file reference number",
- "for the currently selected index file is used. If",
- "no index file is currently selected, the index file",
- "reference number for the last opened index file is",
- "used instead.", (char *) 0 ) ;
- return 0 ;
- }
-
-
- static int i4ind( int item_ref )
- {
- int cur_index, i, r ;
- char *s ;
- int option_code ;
-
- option_code = n4int_get( item_ref ) ;
-
- if ( d4select(-1) < 0 )
- {
- w4display( " User Error: ",
- "Open a database before executing an index file routine.",
- "",
- "Press any key to continue.",
- (char *) 0 ) ;
- return 0 ;
- }
-
- cur_index = i4seek_ref() ;
- if ( cur_index < 0 )
- {
- /* i4open, i4index, i4ref, i4select, i4unselect */
- if ( option_code != 'o' && option_code != 'i' &&
- option_code != 'r' && option_code != 's'+0x200 &&
- option_code != 'u'+0x100 )
- {
- w4display( " User Error: ",
- "d4learn will not execute this routine until an index",
- "file is opened or created for the selected database.",
- (char *) 0 ) ;
- return 0 ;
- }
- }
-
- activate_entry_window( item_ref ) ;
-
- switch (option_code)
- {
- case (int) 'a':
- parm("key_ptr") ;
- parm("record number") ;
- rc = i4add( cur_index, s_get(0), l_get(1) ) ;
- break ;
-
- case (int) 'b':
- rc = i4bottom( cur_index ) ;
- break ;
-
- case (int) 'c':
- l_rc = i4check( cur_index ) ;
- rc_type = LONG ;
- break ;
-
- case (int) 'c'+ 0x100:
- rc = i4close( cur_index ) ;
- cur_index = -1 ;
- break ;
-
- case (int) 'e':
- s_rc = i4eval( cur_index ) ;
- if ( e4type() == 'N' || e4type() == 'F' || e4type() == 'D' )
- {
- s = c4dtoa( (double) (*s_rc), 30, 12 ) ;
- i = (int) strlen(s) ;
- while ( s[--i] == '0' ) s[i] = '\0' ;
- if ( s[i] == '.' ) s[i] = '\0' ;
- strcpy( s_rc, s ) ;
- }
- rc_type = CHAR_PTR ;
- break ;
-
- case (int) 'g':
- parm("key_ptr") ;
- parm("record number" ) ;
- rc = i4go( cur_index, s_get(0), l_get(1) ) ;
- break ;
-
- case (int) 'i':
- parm( "file name") ;
- parm( "expression") ;
- parm( "unique (0,1)") ;
- parm( "safety (0,1)") ;
- rc = i4index( s_get(0), s_get(1), i_get(2), i_get(3) ) ;
- break ;
-
- case (int) 'l':
- parm( "Wait" ) ;
- rc = i4lock( cur_index, i_get(0) ) ;
- break ;
-
- case (int) 'o':
- #ifdef CLIPPER
- file_name_parm( "*.NTX" ) ;
- #else
- file_name_parm( "*.NDX" ) ;
- #endif
- c4trim_n( s_get(0), (int) sizeof(p_buffer[0]) ) ;
-
- rc = i4open( s_get(0) ) ;
- file_name_free() ;
-
- if ( v4base[v4cur_base].current_index >= 0)
- cur_index = v4base[v4cur_base].current_index ;
- break ;
-
- case (int) 'r':
- parm( "file name" ) ;
- rc = i4ref( s_get(0) ) ;
- break ;
-
- case (int) 'r'+ 0x100:
- parm("Index Ref. No.") ;
- rc = i4reindex( i_get(0) ) ;
- break ;
-
- case (int) 'r'+ 0x200:
- parm("key_ptr") ;
- parm("rec_num") ;
- rc = i4remove( cur_index, s_get(0), l_get(1) ) ;
- break ;
-
- case (int) 's':
- parm("key_ptr") ;
- rc = i4seek( cur_index, s_get(0) ) ;
- break ;
-
- case (int) 's'+ 0x100:
- rc = i4seek_ref() ;
- break ;
-
- case (int) 's'+ 0x200:
- parm( "index_ref" ) ;
- rc = i4select( i_get(0) ) ;
- if ( v4base[v4cur_base].current_index >= 0)
- cur_index = v4base[v4cur_base].current_index ;
- break ;
-
- case (int) 's'+ 0x300:
- parm("n") ;
- l_rc = i4skip( cur_index, l_get(0) ) ;
- rc_type = LONG ;
- break ;
-
- case (int) 't':
- rc = i4top( cur_index ) ;
- break ;
-
- case (int) 't'+ 0x100:
- c_rc = i4type( cur_index ) ;
- rc_type = CHAR ;
- break ;
-
- case (int) 'u':
- rc = i4unlock( cur_index ) ;
- break ;
-
- case (int) 'u'+ 0x100:
- i4unselect() ;
- rc = 0 ;
- break ;
-
- default:
- return( -1 ) ;
- }
-
- r = display_results() ;
-
- w4deactivate( entry_ref ) ;
- p_reset() ;
-
- return( r ) ;
- }
-
-
- static int e4expr( int item_ref )
- {
- int r ;
- int option_code ;
-
- option_code = n4int_get( item_ref ) ;
- activate_entry_window( item_ref ) ;
-
- switch( option_code )
- {
- case (int) 'e':
- rc_type = CHAR_PTR ;
-
- parm( "expression" ) ;
- s_rc = (char *) e4eval( s_get(0) ) ;
- if ( e4type() == 'N' || e4type() == 'F' )
- {
- d_rc = *((double *)s_rc) ;
- rc_type = DOUB ;
- }
- if (e4type() == 'L')
- {
- rc = *((int *)s_rc) ;
- rc_type = INT;
- }
- if (e4type() == 'D' )
- rc_type = DATE ;
-
- break ;
-
- case (int) 't':
- c_rc = e4type() ;
- rc_type = CHAR ;
- break ;
-
- default:
- return( -1 ) ;
- }
-
- r = display_results() ;
-
- w4deactivate( entry_ref ) ;
- p_reset() ;
-
- return( r ) ;
- }
-
-
- char memo_buf[82] ;
-
- static int m4memo( int item_ref )
- {
- int j, r, n_fields ;
- long field_ref ;
- char file_name[90], *screen ;
-
- int option_code = n4int_get( item_ref ) ;
-
- memset( memo_buf, 0, (size_t) sizeof(memo_buf) ) ;
-
- if (option_code != ('c'+0x100) && option_code != ('r'+0x100) )
- {
- if ( d4select(-1) >= 0 )
- n_fields = f4num_fields() ;
- else
- n_fields = 0 ;
-
- for ( j=1; j<= n_fields; j++ )
- {
- field_ref = f4j_ref(j) ;
- if ( f4type(field_ref) == 'M') break ;
- }
-
- if ( j > n_fields )
- {
- w4display( "", "There are no Memo Fields in the Database.",
- "",
- "Press a Key",
- (char *) 0 ) ;
- return 0 ;
- }
-
- activate_entry_window( item_ref ) ;
-
- w4( w4row()+1, C_MIDDLE, "Using Memo Field: ") ;
- w4out( f4name(field_ref) ) ;
- }
- else
- activate_entry_window( item_ref ) ;
-
- w4position( w4row()+1, 0 ) ;
-
- switch( option_code )
- {
- case (int) 'c':
- {
- char buf[5][6] ;
- long *data ;
-
- data = m4check( field_ref ) ;
- rc_type = -1 ; /* Display Nothing */
-
- if ( data != (long *) 0 )
- {
- for ( j=0; j< 5; j++ )
- {
- c4ltoa( data[j], buf[j], 5 ) ;
- buf[j][5] = '\0' ;
- }
- w4display( " m4check Results ",
- "No. of Entries in Free Chain:",
- buf[0],
- "",
- "No. of Blocks in Free Chain:",
- buf[1],
- "",
- "No. of Adjacent Entries in Free Chain:",
- buf[2],
- "",
- "No. of Lost Blocks:",
- buf[3],
- "",
- "No. of Blocks Used:",
- buf[4],
- (char *) 0 ) ;
- }
- break ;
- }
-
- case (int) 'c' + 0x100:
- parm( "memo_file_name" ) ;
- u4name_full( file_name, s_get(0), ".DBT" ) ;
- rc = w4display( " Memo File Conversion ",
- "Are you sure the file",
- file_name,
- "is a dBASE III (III PLUS) memo file to be",
- "converted to a dBASE IV memo file ? (Y/N)",
- (char *) 0 ) ;
- if ( rc == (int) 'y' || rc == (int) 'Y' )
- rc = m4convert( s_get(0) ) ;
- else
- {
- s_msg = "\'m4convert\' was not executed." ;
- s_rc = "" ;
- rc_type = MSG ;
- }
- break ;
-
- #ifndef UNIX
- case (int) 'e':
- screen = h4alloc( 4000 ) ;
- parm( "rec_num" ) ;
- parm( "editor_name" ) ;
- parm( "max_size") ;
- l_get(0) ;
- w4read( 0,0, screen, 4000 ) ;
- rc = m4edit( field_ref, l_get(0), s_get(1), i_get(2) ) ;
- w4write( 0,0, screen, 4000 ) ;
- h4free_memory( screen ) ;
- w4cursor(-1,-1) ;
- break ;
- #endif
-
- case (int) 'e' + 0x100:
- rc = m4exist( field_ref ) ;
- break ;
-
- case (int) 'r':
- parm( "rec_num" ) ;
- rc = m4read( field_ref, l_get(0), memo_buf, (int) sizeof(memo_buf) ) ;
- if ( rc > 0 )
- {
- s_rc = memo_buf ;
- rc_type = MSG ;
- s_msg = "Parameter \'str\': " ;
- }
- break ;
-
- case (int) 'r'+ 0x100:
- parm( "memo_file_name" ) ;
- u4name_full( file_name, s_get(0), ".DBT" ) ;
- rc = w4display( " Memo File Renaming ",
- "Are you sure the file",
- file_name,
- "is a dBASE IV memo file which has",
- "been renamed using DOS ? (Y/N)",
- (char *) 0 ) ;
- if ( rc == (int) 'y' || rc == (int) 'Y' )
- rc = m4renamed( s_get(0) ) ;
- else
- {
- s_msg = "\'m4renamed\' was not executed." ;
- s_rc = "" ;
- rc_type = MSG ;
- }
- break ;
-
- case (int) 'w':
- parm( "rec_num" ) ;
- parm( "str" ) ;
- rc = m4write( field_ref, l_get(0), s_get(1), (int) strlen(s_get(1)) ) ;
- break ;
-
- #ifndef UNIX
- case (int) 'e'+ 0x1000:
- screen = h4alloc( 4000 ) ;
- parm( "rec_num" ) ;
- parm( "editor_name" ) ;
- parm( "max_size") ;
- l_get(0) ;
- w4read( 0,0, screen, 4000 ) ;
- rc = m3edit( field_ref, l_get(0), s_get(1), i_get(2) ) ;
- w4write( 0,0, screen, 4000 ) ;
- h4free_memory( screen ) ;
- w4cursor(-1,-1) ;
- break ;
- #endif
-
- case (int) 'e'+ 0x1100:
- rc = m3exist( field_ref ) ;
- break ;
-
- case (int) 'r'+ 0x1000:
- parm( "rec_num" ) ;
- rc = m3read( field_ref, l_get(0), memo_buf, (int) sizeof(memo_buf) ) ;
- if ( rc > 0 )
- {
- s_rc = memo_buf ;
- rc_type = MSG ;
- s_msg = "Parameter \'str\': " ;
- }
- break ;
-
- case (int) 'w'+ 0x1000:
- parm( "rec_num" ) ;
- parm( "str" ) ;
- rc = m3write( field_ref, l_get(0), s_get(1), (int) strlen(s_get(1)) ) ;
- break ;
-
- default:
- return( -1 ) ;
- }
-
- r = display_results() ;
-
- w4deactivate( entry_ref ) ;
- p_reset() ;
-
- return( r ) ;
- }
-
-
- static char *compile_ptr = (char *) 0 ;
- static int compile_base = -1 ;
-
- static char expr[100] ;
-
- static int filter_evaluate()
- {
- int *i_ptr ;
-
- i_ptr = (int *) e4exec( compile_ptr ) ;
- return( *i_ptr ) ;
- }
-
- static int filter_set()
- {
- int *result_ptr ;
-
- w4( w4row()+1,C_LEFT, "Enter a Logical dBASE Expression for Records to Filter") ;
-
- if ( d4select(-1) != compile_base || compile_base < 0 )
- {
- memset( expr, 0, (size_t) sizeof(expr) ) ;
- compile_base = d4select(-1) ;
- }
-
- x4filter_reset() ;
- if ( compile_ptr != (char *) 0 )
- {
- h4free_memory( compile_ptr ) ;
- compile_ptr = (char *) 0 ;
- }
-
- g4release(1) ;
- g4( w4row()+1,C_LEFT, expr ) ;
- g4width( 54, 100 ) ;
- if ( g4read() == ESC ) return 0 ;
-
- c4trim_n( expr, (int) sizeof(expr) ) ;
- if ( strlen(expr) == 0 ) return 0 ;
-
- if ( e4parse( expr, &compile_ptr ) < 0 ) return -1 ;
- result_ptr = (int *) e4exec( compile_ptr ) ;
- if ( result_ptr == (int *) 0 ) return( -1 ) ;
-
- if ( e4type() != 'L' )
- {
- w4display( " User Error: ",
- "Do not enter a Logical Expression",
- "Press a key ...",
- (char *) 0 ) ;
- return -1 ;
- }
-
- x4filter( filter_evaluate ) ;
-
- return 0 ;
- }
-
- static int x4ext( int item_ref )
- {
- int menu_ref, r ;
- int option_code ;
-
- option_code = n4int_get( item_ref ) ;
-
- if ( d4select(-1)< 0 )
- {
- w4display( "First use or create a database.", (char *) 0 ) ;
- return 0 ;
- }
-
- activate_entry_window( item_ref ) ;
-
- switch( option_code )
- {
- case (int) 'b':
- rc = x4blank() ;
- break ;
-
- case (int) 'b'+ 0x100:
- rc = x4bottom() ;
- break ;
-
- case (int) 'c':
- parm("New Database") ;
- parm("Starting Record") ;
- parm("Safety") ;
- rc = x4copy( s_get(0), l_get(1), i_get(2) ) ;
- break ;
-
- case (int) 'f':
- filter_set() ;
- rc_type = VOID ;
- break ;
-
- case (int) 'g':
- parm( "Record Number") ;
- rc = x4go( l_get(0) ) ;
- break ;
-
- case (int) 'i':
- parm( "Record Number" ) ;
- rc = x4insert( l_get(0) ) ;
- break ;
-
- case (int) 'l':
- w4activate( v4default_window ) ;
- rc = x4list() ;
- g4char() ;
- w4deactivate( v4default_window ) ;
- w4cursor(-1,-1) ;
- break ;
-
- case (int) 'p':
- parm("Safety") ;
- rc = x4pack( i_get(0) ) ;
- break ;
-
- case (int) 'r':
- parm("Expression") ;
- parm("Database Reference Number") ;
- parm("Index File Reference Number") ;
- parm("Miss Code") ;
- rc = x4relate( s_get(0), i_get(1), i_get(2), l_get(3) ) ;
- break ;
-
- case (int) 'r'+ 0x100:
- x4relate_reset() ;
- rc_type = VOID ;
- break ;
-
- case (int) 's':
- parm("Double Value") ;
- rc = x4seek_double( d_get(0) ) ;
- break ;
-
- case (int) 's'+ 0x100:
- parm("Search String") ;
- rc = x4seek_str( s_get(0) ) ;
- break ;
-
- case (int) 's'+ 0x200:
- parm("Number of Records") ;
- rc = x4skip( l_get(0) ) ;
- break ;
-
- case (int) 's'+ 0x300:
- parm("New Database Name") ;
- parm("Sort Expression") ;
- parm("Starting Record") ;
- parm("Safety") ;
- rc = x4sort( s_get(0), s_get(1), l_get(2), i_get(3) ) ;
- break ;
-
- case (int) 's'+ 0x400:
- menu_ref = field_name_parm() ;
- d_rc = x4sum( f4ref(s_get(0)) ) ;
- w4close(menu_ref) ;
- rc_type = DOUB ;
- break ;
-
- case (int) 't':
- rc = x4top() ;
- break ;
-
- default:
- return( -1 ) ;
- }
-
- r = display_results() ;
-
- w4deactivate( entry_ref ) ;
- p_reset() ;
-
- return( r ) ;
- }
-
-
-
- /* c4key
-
- Usage void c4key( char * in_key, char * out_str, int key_type )
-
- Description Routine 'c4key' converts the key value returned by 'i4eval' into
- printable character format.
-
- Parameters Name Use
-
- in_key A pointer to the index file key.
-
- out_str A pointer to a buffer where the result should be
- returned. Make sure 'out_str' points to 64 (or more)
- bytes of memory.
-
- key_type The type of the index file. This value may is
- returned by routine 'i4type()'.
-
- */
-
- static void c4key( char *in_key, char *out_str, int type_key )
- {
- #ifdef CLIPPER
- int negative ;
- char *ptr ;
-
- strncpy( out_str, in_key, 64 ) ;
- out_str[63] = '\0' ;
-
- if ( type_key == (int) 'N' || type_key == (int) 'F' )
- {
- ptr = out_str ;
- negative = 0 ;
-
- if ( *ptr < '0' )
- {
- negative = 1 ;
- while (*ptr != '\0' )
- {
- *ptr = (char) 0x5c - *ptr ;
- ptr++ ;
- }
- ptr = out_str ;
- }
-
- while (*ptr == '0') *ptr++ = ' ' ;
- ptr-- ;
- if (ptr[1] == '\0' || ptr[1] == '.' )
- {
- if ( ptr >= out_str ) *ptr = '0' ;
- }
- if ( negative )
- {
- ptr-- ;
- if ( ptr >= out_str ) *ptr = '-' ;
- }
- }
- #else
- char *ptr ;
- int len ;
-
- if ( in_key == (char *) 0 || out_str == (char *) 0 ) return ;
-
- if ( type_key == (int) 'C' ) strncpy( out_str, in_key, 64 ) ;
- if ( type_key == (int) 'D' )
- {
- c4dt_str( out_str, (double *) in_key ) ;
- out_str[8] = '\0' ;
- }
-
- if ( type_key == (int) 'N' || type_key == (int) 'F' )
- {
- ptr = c4dtoa( *((double *)in_key), 34, 16 ) ;
- len = (int) strlen( ptr ) ;
- while ( ptr[--len] == '0' ) if (len>=0) ptr[len] = '\0' ;
- while ( *ptr == ' ' ) ptr++ ;
- strcpy( out_str, ptr ) ;
- }
- #endif
-
- return ;
- }
-