home *** CD-ROM | disk | FTP | other *** search
-
- /* d4simple.c (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved.
-
- This is the example from routine 'n4pull_down' in the manual.
- */
-
- #include "d4base.h"
- #include "w4.h"
- #include "g4char.h"
-
- static FIELD fields[] =
- {
- { "COMMENT", 'C', 40, 0, 0 },
- { "A_VALUE", 'N', 8, 2, 0 },
- { "B_VALUE", 'N', 8, 2, 0 },
- { "SUM", 'N', 8, 2, 0 },
- } ;
-
- /* It is good idea to declare field reference numbers globally. */
- long a_value, b_value, sum ;
-
- /* Declare some action routines. */
- static int edit_database(int) ;
- static int list_database(int) ;
- static int compute_sums(int) ;
-
- main()
- {
- int w_ref ;
- char match_data[14] ;
-
- d4init() ;
- w4clear( -1 ) ;
- w4popup() ; /* Make the default window a popup window. */
-
- /* Create the database if it does not yet exist. */
- if ( u4file_first( "SIMPLE.DBF", match_data ) == 0 )
- d4use( "SIMPLE" ) ;
- else
- d4create( "SIMPLE", 4, fields, 1 ) ;
-
- /* Assign the field reference numbers. */
- a_value = f4ref( "A_VALUE" ) ;
- b_value = f4ref( "B_VALUE" ) ;
- sum = f4ref( "SUM" ) ;
-
- /* Define the menu window. */
- w_ref = w4define( -1,-1,-1,-1 ) ;
- w4title( 0,-1, " Select Choice ", B_WHITE ) ;
-
- /* Specify the menu items. */
- n4skip_over( n4(""), 1 ) ;
- n4( "Edit Database" ) ; n4action( edit_database ) ;
- n4( "List Database" ) ; n4action( list_database ) ;
- n4( "Compute Sums" ) ; n4action( compute_sums ) ;
- n4skip_over( n4(""), 1 ) ;
-
- /* Calculate the window dimensions */
- n4calc( w_ref, 9,31 ) ;
-
- /* Override the border specified by 'n4calc' */
- w4border( DOUBLE_TOP, F_WHITE ) ;
-
- w4cursor( -1,-1 ) ;
-
- /* Activate the menu */
- n4activate( w_ref ) ;
-
- d4close_all() ;
- w4exit(0) ;
- }
-
- static int edit_database( int junk_parm )
- {
- int rc, w_ref ;
-
- w_ref = w4define( 5,10, 16,62 ) ;
- w4title( 0,-1, " Data Entry ", F_WHITE ) ;
- w4popup() ;
- w4border( DOUBLE, F_WHITE ) ;
- w4activate( w_ref ) ;
-
- d4top() ;
-
- w4( 1,1, "Comment: " ) ; g4field( w4row(),w4col(), f4ref("COMMENT")) ;
- w4( 3,1, "A Value: " ) ; g4field( w4row(),w4col(), f4ref("A_VALUE")) ;
- w4( 5,1, "B Value: " ) ; g4field( w4row(),w4col(), f4ref("B_VALUE")) ;
- w4( 7,1, "<Esc> or <Ctrl W> Writes and Exits, <Alt A> Adds" ) ;
- w4( 8,1, "<PgUp> Previous, <PgDn> Next" ) ;
-
- g4release( 0 ) ;
-
- for (;;)
- {
- rc = g4read() ;
-
- if ( d4recno() <= d4reccount() )
- d4write(d4recno()) ;
- else
- d4append() ;
-
- if ( rc < (int) ' ' ) break ;
-
- switch( rc )
- {
- case ALT_A:
- d4append_blank() ;
- break ;
-
- case PGUP:
- d4skip(-1L) ;
- break ;
-
- case PGDN:
- d4skip(1L) ;
- break ;
- }
- }
-
- g4release( 1 ) ;
-
- w4deactivate( w_ref ) ;
- w4close( w_ref ) ;
-
- return 0 ;
- }
-
- extern int v4default_window ;
-
- static int list_database( int junk_parm )
- {
- /* List to the default window which contains the entire screen. */
- w4activate( v4default_window ) ;
- x4list() ;
- g4char() ;
- w4deactivate( v4default_window ) ;
- w4cursor( -1,-1 ) ;
-
- return 0 ;
- }
-
- static int compute_sums( int junk_parm )
- {
- int rc ;
- double result ;
-
- for ( rc = d4top(); rc != 3; rc = d4skip(1L) )
- {
- result = f4value(a_value) + f4value(b_value) ;
- f4replace( sum, &result ) ;
- d4write( d4recno() ) ;
- }
-
- w4display( " Message ", "Sum Computed", "", "Press a key", (char *) 0 ) ;
-
- return 0 ;
- }
-