home *** CD-ROM | disk | FTP | other *** search
- /* x4edit.c (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved. */
-
- #include "d4base.h"
- #include "w4.h"
- #include "g4char.h"
-
- #include <string.h>
-
- extern INDEX *v4index ;
- extern BASE *v4base ;
-
- static int edit(void), help(void), record_go(void), seek_record(void) ;
- static int do_command( unsigned int), setup(void), write_rec(void) ;
-
- /* Edit the Current Database */
-
- x4edit()
- {
- int rc, last_window, w_ref ;
-
- if ( d4select(-1) < 0 ) /* Make Sure a Database is Open */
- {
- w4display( " Edit is not Possible: ",
- "No database has been opened.",
- "Press any key to continue.", (char *) 0 ) ;
- return -1 ;
- }
-
- last_window = w4select(-1) ;
-
- w_ref = w4define( 0,0, 24,79 ) ;
- w4popup() ;
- w4activate( w_ref ) ;
-
- rc = edit() ;
-
- w4deactivate( w_ref ) ;
- w4close( w_ref ) ;
- w4select( last_window ) ;
-
- return rc ;
- }
-
-
- static int edit()
- {
- int command_char, i_ref, rc ;
-
- if ( d4recno() == 0 )
- if ( x4top() < 0 ) return -1 ;
-
- if ( setup() < 0) return -1 ; /* Setup the Initial Gets */
-
- for ( ;; ) /* Loop Forever */
- {
- rc = 0 ;
-
- /* Display Status Information on Line 0 */
-
- w4( 0,0, "Record:" ) ;
- w4long( 0,7, d4recno(), 6) ;
-
- if ( d4deleted() )
- w4( 0,15, "DELETED" ) ;
- else
- w4( 0,15, " " ) ;
-
- w4out( " Database: " ) ;
- w4out( d4ptr()->name ) ;
-
- i_ref = i4seek_ref() ;
- if ( i_ref >= 0 )
- {
- if ( w4col() < 60 )
- {
- w4out( " Index File: " ) ;
- w4out( v4index[i_ref].name ) ;
- }
- }
-
- /* Unlock the Database */
- if ( d4unlock(-1L ) < 0 ) return -1 ;
-
- /* Get the Record Information */
- command_char = g4read() ;
- if ( command_char == 0 )
- command_char = ESC ;
-
- /* Process the Return Character */
-
- if ( command_char == F1 )
- command_char = help() ;
- else
- {
- rc = do_command( command_char ) ; /* It Could be a Command */
- if ( rc != 0 ) return rc ;
- }
- }
- }
-
-
- static int write_rec()
- {
- if ( d4recno() > 0L )
- {
- if ( d4write( d4recno() ) < 0 ) return -1 ;
- if ( d4unlock(-1L) < 0 ) return -1 ;
- }
- return 0 ;
- }
-
-
- static int do_command( command_char )
- unsigned int command_char ;
- {
- long rec ;
- int rc ;
-
- switch( command_char )
- {
- case ALT_A: /* Add Blank Record */
- if ( write_rec() < 0 ) return -1 ;
- memset( d4ptr()->buffer, (int) ' ', d4ptr()->buffer_len ) ;
- if ( d4write( 0L ) < 0 ) return -1 ; /* Append Blank Record */
- break ;
-
- case ALT_B:
- if ( write_rec() < 0 ) return -1 ;
- if ( x4bottom() < 0 ) return -1 ;
- break ;
-
- case ALT_D: /* Delete */
- if ( write_rec() < 0 ) return -1 ;
- if ( d4recno() > 0L )
- if ( d4delete(d4recno()) < 0 ) return -1 ;
- break ;
-
- case ALT_I: /* Insert Record */
- if ( write_rec() < 0 ) return -1 ;
- memset( d4ptr()->buffer, (int) ' ', d4ptr()->buffer_len ) ;
- if ( x4insert( d4recno() ) < 0 ) return -1 ;
- break ;
-
- case ALT_R: /* Go to Entered Record */
- if ( write_rec() < 0 ) return -1 ;
- if ( record_go() < 0 ) return -1 ;
- break ;
-
- case ALT_S:
- if ( write_rec() < 0 ) return -1 ;
- if ( seek_record() < 0 ) return -1 ;
- break ;
-
- case ALT_T: /* Top Record */
- if ( write_rec() < 0 ) return -1 ;
- if ( x4top() < 0 ) return -1 ;
- break ;
-
- case ALT_U: /* Undo the Record Deletion */
- if ( write_rec() < 0 ) return -1 ;
- if ( d4recno() > 0L )
- if ( d4recall( d4recno() ) < 0 ) return -1 ;
- break ;
-
- case PGUP: /* Previous Record */
- if ( write_rec() < 0 ) return -1 ;
- if ( x4skip(-1L) < 0 ) return -1 ;
- break ;
-
- case PGDN: /* Next Record */
- if ( write_rec() < 0 ) return -1 ;
-
- rec = d4recno() ;
- if ( (rc = x4skip(1L)) < 0 ) return -1 ;
- if ( rc == 3 )
- if ( rec > 0 )
- if ( x4go(rec) < 0 ) return -1 ;
- break ;
-
- case CTRL_W: /* Write the Current Record */
- if ( d4write( d4recno() ) < 0 ) return -1 ;
- return CTRL_W ;
-
- case ESC: /* Exit */
- g4release(1) ;
- return ESC ;
- }
- return 0 ;
- }
-
-
- static int setup()
- {
- int i,r,c ;
- long field_ref ;
-
- w4clear( 0 ) ; /* Clear the Screen */
-
- w4( 24,0, "Press <F1> for Help" ) ;
-
- g4release(1) ;
-
- /* For each Field */
- for ( i=1, r=2, c=5; i<= f4num_fields(); i++ )
- {
- field_ref = f4j_ref(i) ;
- if ( f4type(field_ref) == 'M' ) continue ;
-
- if ( r == 23 )
- {
- if ( c == 5 )
- {
- r = 2 ;
- c = 45 ;
- }
- else
- break ;
- }
-
- w4( r,c, f4name(field_ref) ) ; /* Say the Field Name */
- g4field( r,c+12, field_ref ) ; /* Schedule a Get */
- if ( f4type(field_ref) == 'C' )
- g4width( 0,18) ; /* Max. Width of 18 */
-
- r++ ;
- }
-
- g4release(0) ; /* Do not Release the Gets after a read */
-
- return 0 ;
- }
-
-
- static int help() /* Display Help Information */
- {
- int r,c, rc ;
-
- w4clear( 0 ) ;
-
- w4centre( 1, "Edit Help Screen" ) ;
-
- r = 4 ;
- c = 25 ;
-
- w4( r++,c-3, "Enter Command: " ) ;
- w4cursor( w4row(), w4col() ) ;
-
- w4( ++r, c, "<Alt A> - Add Record" ) ;
- w4( ++r, c, "<Alt B> - Bottom Record" ) ;
- w4( ++r, c, "<Alt D> - Delete Recrord" ) ;
- w4( ++r, c, "<Alt I> - Insert Record" ) ;
- w4( ++r, c, "<Alt R> - Record Number" ) ;
- w4( ++r, c, "<Alt S> - Seek Record" ) ;
- w4( ++r, c, "<Alt T> - Top Record" ) ;
- w4( ++r, c, "<Alt U> - Undo Delete Record" ) ;
- w4( ++r, c, "<PgUp> - Previous Record" ) ;
- w4( ++r, c, "<PgDn> - Next Record" ) ;
- w4( ++r, c, "<Ctrl W> - Write Record and Exit" ) ;
- w4( ++r, c, "<Esc> - Exit" ) ;
- ++r ;
- w4( ++r, c-3, "Press any key to continue ..." ) ;
- ++r ;
-
- rc = g4char() ;
-
- g4release(1) ;
- if ( setup() < 0 ) return -1 ;
-
- return rc ;
- }
-
-
- static int record_go()
- {
- long rec ;
- int rc, w_ref ;
-
- rec = d4recno() ;
-
- w_ref = w4define( 9,27,14,52 ) ;
- w4popup() ;
- w4title( 0,-1, " Record Number Command ", F_WHITE ) ;
- w4activate( w_ref ) ;
-
- w4( 1,2, "Records in Database:" ) ;
- w4long( w4row(),w4col(), d4reccount(), 6 ) ;
-
- w4( 2,2, "Enter Record Number: " ) ;
- g4long( w4row(), w4col(), &rec ) ;
- rc = g4read() ; /* Read the Record */
-
- w4deactivate( w_ref ) ;
- w4close( w_ref ) ;
-
- if ( rc != ESC && rec > 0 && rec <= d4reccount() )
- if ( x4go(rec) < 0) return -1 ; /* Go to the Record */
-
- return 0 ;
- }
-
-
- static int seek_record()
- {
- int index_ref, rc, w_ref ;
- long rec ;
- char seek_data[101] ;
-
- index_ref = i4seek_ref() ;
-
- if ( index_ref < 0 )
- {
- w4display( " Operator Error: ",
- "The Database does not have an Index File.",
- "",
- "Press any key to continue.", (char *) 0 ) ;
- return 1 ;
- }
-
- w_ref = w4define( 10,25,14,54 ) ;
- w4popup() ;
- w4title( 0,-1, " Enter the Seek Information: ", F_WHITE ) ;
- w4activate( w_ref ) ;
-
- memset( seek_data, 0, (size_t) sizeof(seek_data) ) ;
- g4release(1) ;
- g4( 1,3, seek_data ) ;
- g4width( 24, 100 ) ;
- rc = g4read() ;
-
- w4deactivate( w_ref ) ;
- w4close( w_ref ) ;
-
- if ( rc != ESC )
- {
- rec = d4recno() ;
- if ( (rc = x4seek(seek_data))< 0) return -1 ;
-
- if ( rc == 3 )
- {
- c4trim_n( seek_data, (int) sizeof(seek_data) ) ;
- w4display( " Seek Data not Found: ", seek_data, (char *) 0 ) ;
- if ( x4go(rec) < 0 ) return -1 ;
- }
- }
-
- return 0 ;
- }