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

  1.  
  2. /*  d4simple.c  (c)Copyright Sequiter Software Inc., 1987, 1988, 1989. All rights reserved. 
  3.  
  4.     This is the example from routine 'n4pull_down' in the manual.
  5. */
  6.  
  7. #include "d4base.h"
  8. #include "w4.h"
  9. #include "g4char.h"
  10.  
  11. static FIELD  fields[] =
  12. {
  13.    { "COMMENT", 'C', 40, 0, 0 },
  14.    { "A_VALUE", 'N',  8, 2, 0 },
  15.    { "B_VALUE", 'N',  8, 2, 0 },
  16.    { "SUM",     'N',  8, 2, 0 },
  17. } ;
  18.  
  19. /* It is good idea to declare field reference numbers globally. */
  20. long   a_value, b_value, sum ;
  21.  
  22. /* Declare some action routines. */
  23. static int  edit_database(int) ;
  24. static int  list_database(int) ;
  25. static int  compute_sums(int) ;
  26.  
  27. main()
  28. {
  29.    int  w_ref ;
  30.    char match_data[14] ;
  31.  
  32.    d4init() ;
  33.    w4clear( -1 ) ;
  34.    w4popup() ;  /* Make the default window a popup window. */
  35.  
  36.    /* Create the database if it does not yet exist. */
  37.    if ( u4file_first( "SIMPLE.DBF", match_data ) == 0 )
  38.       d4use( "SIMPLE" ) ;
  39.    else
  40.       d4create( "SIMPLE", 4, fields, 1 ) ;
  41.  
  42.    /* Assign the field reference numbers. */
  43.    a_value =  f4ref( "A_VALUE" ) ;
  44.    b_value =  f4ref( "B_VALUE" ) ;
  45.    sum     =  f4ref( "SUM" ) ;
  46.  
  47.    /* Define the menu window. */
  48.    w_ref =  w4define( -1,-1,-1,-1 ) ;
  49.    w4title( 0,-1, " Select Choice ", B_WHITE ) ;
  50.  
  51.    /* Specify the menu items. */
  52.    n4skip_over( n4(""), 1 ) ;
  53.    n4( "Edit Database" ) ;   n4action( edit_database ) ;
  54.    n4( "List Database" ) ;   n4action( list_database ) ;
  55.    n4( "Compute Sums"  ) ;   n4action( compute_sums  ) ;
  56.    n4skip_over( n4(""), 1 ) ;
  57.  
  58.    /* Calculate the window dimensions */
  59.    n4calc( w_ref, 9,31 ) ;
  60.  
  61.    /* Override the border specified by 'n4calc' */
  62.    w4border( DOUBLE_TOP, F_WHITE ) ;
  63.  
  64.    w4cursor( -1,-1 ) ;
  65.  
  66.    /* Activate the menu */
  67.    n4activate( w_ref ) ;
  68.  
  69.    d4close_all() ;
  70.    w4exit(0) ;
  71. }
  72.  
  73. static int  edit_database( int junk_parm )
  74. {
  75.    int  rc, w_ref ;
  76.  
  77.    w_ref =  w4define( 5,10, 16,62 ) ;
  78.    w4title( 0,-1, " Data Entry ",  F_WHITE ) ;
  79.    w4popup() ;
  80.    w4border( DOUBLE, F_WHITE ) ;
  81.    w4activate( w_ref ) ;
  82.  
  83.    d4top() ;
  84.  
  85.    w4( 1,1, "Comment: " ) ;   g4field( w4row(),w4col(), f4ref("COMMENT")) ;
  86.    w4( 3,1, "A Value: " ) ;   g4field( w4row(),w4col(), f4ref("A_VALUE")) ;
  87.    w4( 5,1, "B Value: " ) ;   g4field( w4row(),w4col(), f4ref("B_VALUE")) ;
  88.    w4( 7,1, "<Esc> or <Ctrl W> Writes and Exits,  <Alt A> Adds" ) ;
  89.    w4( 8,1, "<PgUp> Previous,  <PgDn> Next" ) ;
  90.  
  91.    g4release( 0 ) ;
  92.  
  93.    for (;;)
  94.    {
  95.       rc =  g4read() ;
  96.       
  97.       if ( d4recno() <= d4reccount() )
  98.          d4write(d4recno()) ;
  99.       else
  100.          d4append() ;
  101.  
  102.       if ( rc < (int) ' ' )  break ;
  103.  
  104.       switch( rc )
  105.       {
  106.          case ALT_A:
  107.             d4append_blank() ;
  108.             break ;
  109.  
  110.          case PGUP:
  111.             d4skip(-1L) ;
  112.             break ;
  113.             
  114.          case PGDN:
  115.             d4skip(1L) ;
  116.             break ;
  117.       }
  118.    }
  119.  
  120.    g4release( 1 ) ;
  121.  
  122.    w4deactivate( w_ref ) ;
  123.    w4close( w_ref ) ;
  124.  
  125.    return 0 ;
  126. }
  127.  
  128. extern int  v4default_window ;
  129.  
  130. static int  list_database( int junk_parm )
  131. {
  132.    /* List to the default window which contains the entire screen. */
  133.    w4activate( v4default_window ) ;
  134.    x4list() ;
  135.    g4char() ;
  136.    w4deactivate( v4default_window ) ;
  137.    w4cursor( -1,-1 ) ;
  138.  
  139.    return 0 ;
  140. }
  141.  
  142. static int  compute_sums( int junk_parm )
  143. {
  144.    int     rc ;
  145.    double  result ;
  146.  
  147.    for ( rc = d4top(); rc != 3; rc = d4skip(1L) )
  148.    {
  149.       result =  f4value(a_value) + f4value(b_value) ;
  150.       f4replace( sum, &result ) ;
  151.       d4write( d4recno() ) ;
  152.    }
  153.  
  154.    w4display( " Message ", "Sum Computed", "", "Press a key", (char *) 0 ) ;
  155.  
  156.    return 0 ;
  157. }
  158.