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

  1.  
  2. /*  Screen I/O Example Program   w4example.c
  3.     (c)Copyright Sequiter Software Inc., 1987, 1988, 1989.  All rights reserved.
  4. */
  5.  
  6. #include  "d4all.h"  /* For Conversion Routine Prototype */
  7. #include  "w4.h"
  8. #include  "g4char.h"
  9.  
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <stdlib.h>
  13. #include <time.h>
  14.  
  15. #ifdef TURBO
  16.    unsigned int  _stklen =  10000 ;
  17. #endif
  18.  
  19. static  int  a_pulldown(int) ;
  20. static int   b_pulldown(int) ;
  21. static int   lotus_example(int) ;
  22. static int   menu_entry(int) ;
  23. static int   double_example(int) ;
  24. static int   date_example(int) ;
  25. static int   valid_example(int) ;
  26. static int   delimiter_example(int) ;
  27. static int   handle_example(int) ;
  28. static int   position_window(int) ;
  29. static int   search_example(int) ;
  30. static int   color_menu(int) ;
  31. static int   skipping(int) ;
  32. static int   row_column(int) ;
  33. static int   random_menu(int) ;
  34. static int   get_entry_help(int) ;
  35. static int   lotus_help(int) ;
  36. static int   search_help(int) ;
  37. static int   display_item(int) ;
  38. static int   select_file(char *) ;
  39. static int   skipping_help(int) ;
  40. static int   row_column_display(int) ;
  41.  
  42. static int  is_date_valid( GET * ) ;
  43. static int   plus_or_minus( GET *) ;
  44. static int   before_t( GET *) ;
  45. static int   n_valid( GET *) ;
  46. static int   minus_four( GET *)  ;
  47.  
  48. extern int  v4default_window ;
  49. extern MENU *v4menu ;
  50.  
  51.  
  52. main()
  53. {
  54.    int  main_menu, w_ref, w_get_example ;
  55.  
  56.    w_ref =  w4define( 5,10, 19,68 ) ;
  57.    w4clear( -1 ) ;
  58.    w4cursor( -1,-1 ) ;
  59.    w4activate( w_ref ) ;
  60.  
  61.    w4centre( 1, "Code Base" ) ;
  62.    w4centre( 3, "Window, Menu and Data Entry Examples" ) ;
  63.    w4centre( 5, "(c)Copyright Sequiter Software Inc., 1987, 1988, 1989" ) ;
  64.    w4centre( 9, "Source to this example is in file \'w4example.c\'" ) ;
  65.    w4centre( 11,"Press a key to continue" ) ;
  66.  
  67.    g4char() ;
  68.  
  69.    /* Main Menu Definition */
  70.    main_menu   =  w4define( -1,-1,-1,-1 ) ;
  71.    w4title( 0,-1, " Main Menu ", F_WHITE | F_INTENSE ) ;
  72.  
  73.    n4skip_over( n4( "" ), 1 ) ;
  74.    n4( "Pulldown Menu - Type A" ) ;  n4action( a_pulldown) ;
  75.                      n4key( 'P', 0,0 ) ;
  76.    n4( "Pulldown Menu - Type B" ) ;  n4action( b_pulldown) ;
  77.                      n4key( 'P', 0,0 ) ;
  78.    n4( "Lotus-style Menu" ) ;         n4action( lotus_example) ;
  79.                      n4key( 'L', 0,0 ) ;
  80.    n4( "Get Examples" ) ;         n4action( n4sub_menu );
  81.                      n4ptr_save( &w_get_example ) ;
  82.                      n4key( 'G', 0,0 ) ;
  83.    n4( "File Name Search" ) ;         n4action( search_example) ;
  84.                      n4key( 'F', 0,0 ) ;
  85.    #ifndef UNIX
  86.       n4( "Color Menu" ) ;         n4action( color_menu) ;
  87.                      n4key( 'C', 0,0 ) ;
  88.    #endif
  89.    n4( "Menu Item Skipping" ) ;      n4action( skipping) ;
  90.                      n4key( 'M', 0,0 ) ;
  91.    n4( "Columns and Rows" ) ;         n4action( row_column ) ;
  92.                      n4key( 'C', 0,0 ) ;
  93.    n4( "Random Menu" ) ;         n4action( random_menu ) ;
  94.                      n4key( 'R', 0,0 ) ;
  95.    n4skip_over( n4( "" ), 1 ) ;
  96.    n4( "Exit" ) ;             n4parm( -1 ) ;
  97.                      n4key( 'E', 0,0 ) ;
  98.    n4skip_over( n4( "" ), 1 ) ;
  99.  
  100.  
  101.    w_get_example =  w4define(-1,-1,-1,-1) ;
  102.  
  103.    n4( "F1 - Data Entry with Menus" ) ;   n4action( menu_entry) ;
  104.                       n4key( F1, 1, -1 ) ;
  105.    n4( "F2 - Numeric Entry" ) ;             n4action( double_example) ;
  106.                       n4key( F2, 1, -1 ) ;
  107.    n4( "F3 - Date Entry" ) ;                n4action( date_example) ;
  108.                       n4key( F3, 1, -1 ) ;
  109.    n4( "F4 - Data Validation" ) ;      n4action( valid_example) ;
  110.                       n4key( F4, 1, -1 ) ;
  111.    n4( "F5 - Delimiters and Attributes"); n4action( delimiter_example) ;
  112.                       n4key( F5, 1, -1 ) ;
  113.    n4( "F6 - Printer/Handle Example" ) ;  n4action( handle_example) ;
  114.                       n4key( F6, 1, -1 ) ;
  115.  
  116.    n4calc( main_menu, 4,1 ) ;
  117.  
  118.    w4select( main_menu ) ;
  119.    w4border( DOUBLE_TOP, F_WHITE ) ;
  120.  
  121.    n4activate( main_menu ) ;
  122.  
  123.    w4exit(0) ;
  124. }
  125.  
  126. static int  get_entry_help( int junk_parm )
  127. {
  128.    int  w_ref, c ;
  129.  
  130.    w4cursor( -1,-1 ) ;
  131.  
  132.    w_ref =  w4define( 7,13 ,19,67 ) ;
  133.    w4title( 0,-1, " Using Menus with Entry Areas ", F_WHITE | F_INTENSE ) ;
  134.    w4border( DOUBLE, F_WHITE ) ;
  135.    w4popup() ;
  136.  
  137.    w4activate( w_ref ) ;
  138.  
  139.    c =  2 ;
  140.    w4( 1,c,           "It is possible to move between entry areas, even" ) ;
  141.    w4( w4row()+1,c, "when using menus, using the following commands:" ) ;
  142.  
  143.    w4( w4row()+2,c, "<Ctrl Home> -  Move to the top entry area." ) ;
  144.    w4( w4row()+1,c, "<Ctrl End>  -  Move to the bottom entry area." ) ;
  145.    w4( w4row()+1,c, "<Tab>       -  Move to the next entry area." ) ;
  146.    w4( w4row()+1,c, "<Shift Tab> -  Move to the previous entry area." ) ;
  147.  
  148.    w4( w4row()+2,c, "Under Unix use <Ctrl Z> if there is no" ) ;
  149.    w4( w4row()+1,c, "<Shift Tab> key." ) ;
  150.    g4char() ;
  151.  
  152.    w4deactivate( w_ref ) ;
  153.    w4close( w_ref ) ;
  154.  
  155.    return 0 ;
  156. }
  157.  
  158.  
  159. static int  menu_entry(int junk_parm)
  160. {
  161.    char  name_data[21], subject_data[11], date_data[10] ;
  162.    int   grade_data, name_window, subject_window, grade_window, entry_window ;
  163.    int   save_row ;
  164.  
  165.    /* Initialize the Data */
  166.    memset( name_data,   (int) ' ', sizeof(name_data) ) ;
  167.    name_data[20] = '\0' ;
  168.    memset( subject_data,(int) ' ', sizeof(subject_data) ) ;
  169.    subject_data[10] = '\0' ;
  170.    memset( date_data,   (int) ' ', sizeof(date_data) ) ;
  171.    date_data[8] = '\0' ;
  172.    grade_data =  0 ;
  173.  
  174.    /* Define the Windows for the Menu Data Entry */
  175.    name_window =  w4define(-1,-1,-1,-1) ;
  176.  
  177.    n4( "Menu Entry Help" ) ;
  178.    n4action( get_entry_help ) ;
  179.    n4skip_over( n4(""), 1 ) ;
  180.  
  181.    n4( "Alice Wonder" ) ;
  182.    n4( "Fred Calvert" ) ;
  183.    n4( "Jim Roberts" ) ;
  184.    n4( "John Short" ) ;
  185.    n4( "Lucy Williams" ) ;
  186.    n4( "Tony Smith" ) ;
  187.  
  188.    subject_window =  w4define(-1,-1,-1,-1) ;
  189.  
  190.    n4( "Menu Entry Help" ) ;
  191.    n4action( get_entry_help ) ;
  192.    n4skip_over( n4(""), 1 ) ;
  193.  
  194.    n4( "Biology  " ) ;
  195.    n4( "Chemistry" ) ;
  196.    n4( "English  " ) ;
  197.    n4( "History  " ) ;
  198.    n4( "Math     " ) ;
  199.    n4( "Physics  " ) ;
  200.  
  201.    grade_window =  w4define(-1,-1,-1,-1) ;
  202.  
  203.    n4( "Menu Entry Help" ) ;
  204.    n4action( get_entry_help ) ;
  205.    n4skip_over( n4(""), 1 ) ;
  206.  
  207.    n4( " 85  (A)" ) ;  n4key( 'A', 1, 6 ) ;
  208.    n4( " 75  (B)" ) ;  n4key( 'B', 1, 6 ) ;
  209.    n4( " 65  (C)" ) ;  n4key( 'C', 1, 6 ) ;
  210.    n4( " 55  (D)" ) ;  n4key( 'D', 1, 6 ) ;
  211.    n4( " 45  (F)" ) ;  n4key( 'F', 1, 6 ) ;
  212.  
  213.    /* Specify the GET Screen */
  214.    entry_window =  w4define( 5,10, 21,70 ) ;
  215.    w4border( SINGLE, F_WHITE ) ;
  216.    w4popup() ;
  217.  
  218.    w4activate( entry_window ) ;
  219.  
  220.    w4centre( 2, "Example Entry Screen Using Menus" ) ;
  221.  
  222.    #define  C1   4
  223.    #define  C2  13
  224.    #define  C3  36
  225.  
  226.    w4( 5,C1, "Name" ) ;
  227.    w4( w4row(),C3, "(May use menu)" ) ;
  228.    g4( w4row(),C2, name_data ) ;
  229.    g4call( g4menu_help, name_window ) ;
  230.    g4message( "Press F1 for Entry Possibilities" ) ;
  231.  
  232.    w4( w4row()+2,C1, "Subject" ) ;
  233.    w4( w4row(),C3, "(Must use menu)" ) ;
  234.    g4( w4row(),C2, subject_data ) ;
  235.    g4call( g4menu, subject_window ) ;
  236.  
  237.    w4( w4row()+2,C1, "Grade" ) ;
  238.    w4( w4row(),C3, "(May use menu)" ) ;
  239.    g4int( w4row(),C2, &grade_data ) ;
  240.    g4picture( "999" ) ;
  241.    g4call( g4menu_help, grade_window ) ;
  242.    g4message( "Press F1 for Entry Possibilities" ) ;
  243.  
  244.    w4( w4row()+2,C1, "Date" ) ;
  245.    w4( w4row(),C3, "(No menu available)") ;
  246.    g4date( w4row(),C2, date_data ) ;
  247.    g4picture( "MMM DD/CCYY" ) ;
  248.    g4message( "The format is MMM DD/CCYY;  Example: Mar 30/1989" ) ;
  249.    save_row =  w4row() ;
  250.  
  251.    n4get_calc( entry_window ) ;
  252.    g4read() ;
  253.  
  254.    w4( save_row+2,C2, "Press any key to continue" ) ;
  255.    g4char() ;
  256.  
  257.    w4deactivate( entry_window ) ;
  258.    w4close( entry_window ) ;
  259.    w4close( name_window ) ;
  260.    w4close( subject_window ) ;
  261.    w4close( grade_window ) ;
  262.  
  263.    w4cursor( -1,-1 ) ;
  264.  
  265.    return 0 ;
  266. }
  267.  
  268.  
  269. static int  double_example(int junk_parm)
  270. {
  271.    double  d1, d2, d4 ;
  272.    char    n1[10], n2[10], n3[10], n4[10] ;
  273.  
  274.    int     r, save_r, c1, c2, c4, w_ref ;
  275.  
  276.    w_ref =  w4define( 0,0,23,79 ) ;
  277.    w4popup() ;
  278.    w4border( DOUBLE, B_WHITE ) ;
  279.    w4activate( w_ref ) ;
  280.  
  281.    r = 4 ;  c1 = 20 ;  c2 = 34 ;  c4 = 50 ;
  282.    d1 = 1234.0 ;  d2 = -4.2 ;  d4 = 0.0 ;
  283.  
  284.    w4attribute( F_WHITE | F_INTENSE ) ;
  285.    w4centre( r++, "Double/Numeric Examples" ) ;
  286.    w4attribute( F_WHITE ) ;
  287.    ++r ;
  288.  
  289.    w4( ++r,c1, "Picture" ) ;  w4( r,c2, "Data" ) ;  w4( r,c4, "Results" ) ;
  290.  
  291.    save_r =  ++r ;
  292.  
  293.    w4( ++r, c1, "Default" ) ;
  294.    g4double( r, c2, &d4 ) ;
  295.    g4message(  "2 Decimals, 8 Width" ) ;
  296.  
  297.    w4( ++r, c1, "9999" ) ;
  298.    g4double( r, c2, &d1 ) ;
  299.    g4picture( "9999" ) ;
  300.    g4message( "All Digits" ) ;
  301.  
  302.    w4( ++r, c1, "####.#" ) ;
  303.    g4double( r, c2, &d2 ) ;
  304.    g4picture( "####.#" ) ;
  305.    g4message( "One Decimal" ) ;
  306.  
  307.    w4( ++r, c1, "Default" ) ;
  308.    strcpy( n1, " -34.678" ) ;
  309.    g4numeric( r, c2, n1 ) ;
  310.    g4message( "Numeric Example" ) ;
  311.  
  312.    w4( ++r, c1, "####" ) ;
  313.    strcpy( n2, "8431" ) ;
  314.    g4numeric( r, c2, n2 ) ;
  315.    g4picture( "####" ) ;
  316.  
  317.    w4( ++r, c1, "9.9999" ) ;
  318.    strcpy( n3, "      " ) ;
  319.    g4numeric( r, c2, n3 ) ;
  320.    g4picture( "9.9999" ) ;
  321.    g4message( "Initially Blank" ) ;
  322.  
  323.    w4( ++r, c1, "999.99" ) ;
  324.    strcpy( n4, "  1.23" ) ;
  325.    g4numeric( r, c2, n4 ) ;
  326.    g4picture( "999.99" ) ;
  327.  
  328.    g4read() ;
  329.  
  330.    r =  save_r ;
  331.  
  332.    w4double( ++r, c4, d4, 8, 2 ) ;
  333.    w4double( ++r, c4, d1, 4, 0 ) ;
  334.    w4double( ++r, c4, d2, 6, 1 ) ;
  335.    w4( ++r, c4, n1 ) ;
  336.    w4( ++r, c4, n2 ) ;
  337.    w4( ++r, c4, n3 ) ;
  338.    w4( ++r, c4, n4 ) ;
  339.    ++r ;
  340.    w4( ++r, c1, "Press any key to continue ..." ) ;
  341.    w4cursor( -1,-1 ) ;
  342.    g4char() ;
  343.  
  344.    w4deactivate( w_ref ) ;
  345.    w4close( w_ref ) ;
  346.  
  347.    return 0 ;
  348. }
  349.  
  350.  
  351. static int  date_example(int junk_parm)
  352. {
  353.    int r, save_r, i_data, c1, c2, c4, i, w_ref ;
  354.    char  date_data[6][8] ;
  355.  
  356.    w_ref =  w4define( 0,0, 23,79 ) ;
  357.    w4popup() ;
  358.    w4border( PANEL, F_WHITE ) ;
  359.    w4activate( w_ref ) ;
  360.  
  361.    memcpy( date_data[0], "19890228", 8 ) ;
  362.    memcpy( date_data[1], "19881030", 8 ) ;
  363.    memcpy( date_data[2], "19420622", 8 ) ;
  364.    memcpy( date_data[3], "        ", 8 ) ;
  365.    memcpy( date_data[4], "19670701", 8 ) ;
  366.  
  367.    r = 4 ;  i_data = 0 ;  c1 = 20 ;  c2 = 34 ;  c4 = 50 ;
  368.  
  369.    w4attribute( F_WHITE | F_INTENSE ) ;
  370.    w4centre( r++, "Date Entry Examples" ) ;
  371.    w4attribute( F_WHITE ) ;
  372.    ++r ;
  373.  
  374.    w4( ++r, c1, "Picture" ) ;  w4( r, c2, "Data" ) ;  w4( r, c4, "Results") ;
  375.  
  376.    save_r =  ++r ;
  377.  
  378.    w4( ++r, c1, DEFAULT_DATE ) ;
  379.    g4date(  r, c2, date_data[i_data++] ) ;
  380.    g4message( "This is the default date picture." ) ;
  381.  
  382.    w4( ++r, c1, "CCYY.MM.DD" ) ;
  383.    g4date(  r, c2, date_data[i_data++] ) ;
  384.    g4picture( "CCYY.MM.DD" ) ;
  385.  
  386.    w4( ++r, c1, "MM/DD/YY" ) ;
  387.    g4date(  r, c2, date_data[i_data++] ) ;
  388.    g4picture( "MM/DD/YY" ) ;
  389.  
  390.    w4( ++r, c1, "MMM DD/CCYY" ) ;
  391.    g4date(  r, c2, date_data[i_data++] ) ;
  392.    g4picture( "MMM DD/CCYY" ) ;
  393.    g4message( "A possible entry is \'Jan 01/1989\'" ) ;
  394.  
  395.    w4( ++r, c1, "DD/MMM" ) ;
  396.    g4date(  r, c2, date_data[i_data++] ) ;
  397.    g4picture( "DD/MMM" ) ;
  398.  
  399.    g4read() ;
  400.  
  401.    for ( i= 0; i< i_data; i++ )
  402.       w4num( save_r+i+1, c4, date_data[i], 8 ) ;
  403.  
  404.    ++r ;
  405.    w4( ++r, c1, "Press any key to continue ..." ) ;
  406.    w4cursor( -1,-1 ) ;
  407.    g4char() ;
  408.  
  409.    w4deactivate( w_ref ) ;
  410.    w4close( w_ref ) ;
  411.  
  412.    return 0 ;
  413. }
  414.  
  415.  
  416. static int  delimiter_example(int junk_parm)
  417. {
  418.    char    data1[10], data2[10], data3[8], data4[10] ;
  419.    int     r, save_r, c1, c2, c4, l1, l2, w_ref ;
  420.  
  421.    w_ref =  w4define( 0,0, 23,79 ) ;
  422.    w4popup() ;
  423.    w4border( SINGLE, F_GREEN ) ;
  424.    w4activate( w_ref ) ;
  425.  
  426.    r = 4 ;  c1 = 14;  c2 = 36 ;  c4 = 52 ;
  427.  
  428.    w4attribute( F_WHITE | F_INTENSE ) ;
  429.    w4centre( r++, "Color/Screen/Delimiter Examples" ) ;
  430.    w4attribute( F_BLUE | F_GREEN ) ;
  431.    ++r ;
  432.  
  433.    w4( ++r,c1, "Description" ) ;  w4( r,c2, "Data") ;  w4( r,c4, "Results" ) ;
  434.  
  435.    save_r =  ++r ;
  436.  
  437.    w4( ++r,c1, "Small Screen Width" ) ;
  438.    g4delimiter( "[]" ) ;
  439.    g4attribute( F_RED | F_BLUE ) ;
  440.    strcpy( data1, "abcdefgh" ) ;
  441.    g4( r, c2, data1 ) ;
  442.    g4width( 6, 4 ) ;
  443.    g4message( "The data width is 6 and the screen width is 4" ) ;
  444.  
  445.    w4( ++r,c1, "Phone" ) ;
  446.    g4delimiter( "!!" ) ;
  447.    g4attribute( F_WHITE | F_INTENSE | B_WHITE | B_BLINK ) ;
  448.    strcpy( data2, "444444444" ) ;
  449.    g4( r, c2, data2 ) ;
  450.    g4picture( "999-9999" ) ;
  451.    g4message( "North American Phone Number" ) ;
  452.  
  453.    w4( ++r,c1, "Postal Code" ) ;
  454.    strcpy( data3, "T6E 0T8" ) ;
  455.    g4delimiter( "  " ) ;
  456.    g4attribute( F_RED | F_GREEN ) ;
  457.    g4( r,c2, data3 ) ;
  458.    g4picture( "!9! 9!9" ) ;
  459.    g4message( "Canadian Postal Code (Picture: \"!9! 9!9\" )" ) ;
  460.  
  461.    w4( ++r,c1, "Variety" ) ;
  462.    strcpy( data4, "a1 jT8kN" ) ;
  463.    g4( r,c2, data4 ) ;
  464.    g4picture( "!9#ALNXY" ) ;
  465.    g4message( "Read with a variety of picture characters: \'!9#ALNXY\'") ;
  466.  
  467.    /* Logical Reads */
  468.    l1 = 0 ;  l2 = 1 ;
  469.    g4delimiter( "##" ) ;
  470.  
  471.    w4( ++r,c1, "Logical One" ) ;
  472.    g4logical( r,c2, &l1 ) ;
  473.    g4picture( "L" ) ;
  474.    g4message( "Logical Read using \'g4logical\' with Picture \"L\"" ) ;
  475.  
  476.    w4( ++r,c1, "Logical Two" ) ;
  477.    g4logical( r,c2, &l2 ) ;
  478.    g4picture( "Y" ) ;
  479.    g4message( "Logical Read using \'g4logical\' with Picture \"Y\"" ) ;
  480.  
  481.    g4read() ;
  482.  
  483.    w4attribute( F_WHITE ) ;    /* Back to the defaults */
  484.    g4attribute( B_WHITE ) ;
  485.    g4delimiter( "\x00\x00" ) ;
  486.  
  487.    r =  save_r ;
  488.  
  489.    w4num( ++r, c4, data1, 6 ) ;
  490.    w4num( ++r, c4, data2, 8 ) ;
  491.    w4num( ++r, c4, data3, 7 ) ;
  492.    w4num( ++r, c4, data4, 7 ) ;
  493.    w4int( ++r, c4, l1, 1 ) ;
  494.    w4int( ++r, c4, l2, 1 ) ;
  495.  
  496.    ++r ;
  497.    w4( ++r, c1, "Press any key to continue ..." ) ;
  498.    w4cursor( -1,-1 ) ;
  499.    g4char() ;
  500.  
  501.    w4deactivate( w_ref ) ;
  502.    w4close( w_ref ) ;
  503.  
  504.    return 0 ;
  505. }
  506.  
  507.  
  508. static int  is_date_valid( GET *get_ptr )
  509. {
  510.    if ( memcmp( (char *) get_ptr->data+ 2, "80", 2 ) >= 0 )
  511.    {
  512.       w4display( " Date Entry Error ", "The Date Must be Before 1980", (char *) 0) ;
  513.       return -1 ;
  514.    }
  515.    return 0 ;
  516. }
  517.  
  518.  
  519. static int  minus_four( GET *get_ptr )
  520. {
  521.    if ( * ((int *)get_ptr->data)  < -4 )   return 0 ;
  522.    w4display( " Entry Error ", "Must be Less Than -4", (char *) 0 ) ;
  523.    return -1 ;
  524. }
  525.  
  526.  
  527. static int  plus_or_minus( GET *get_ptr )
  528. {
  529.    switch( get_ptr->type )
  530.    {
  531.       case 'l':
  532.      if ( *((long *)get_ptr->data) >  1  ||
  533.           *((long *)get_ptr->data) < -1 )   return 0 ;
  534.      break ;
  535.  
  536.       case 'd':
  537.      if ( *((double *)get_ptr->data) > 1.0 ||
  538.           *((double *)get_ptr->data) <-1.0 )   return 0 ;
  539.      break ;
  540.    }
  541.    w4display( " Entry Error ", "Not less than -1 or greater than 1", (char *) 0 ) ;
  542.    return -1 ;
  543. }
  544.  
  545.  
  546. static int  before_t( GET *get_ptr )
  547. {
  548.    if ( *((char *)get_ptr->data) <= 'S' )  return 0 ;
  549.    w4display( " Illegal Letter ", "Must start with a letter before \'T\'", (char *) 0 ) ;
  550.    return -1 ;
  551. }
  552.  
  553.  
  554. static int  n_valid( GET *get_ptr )
  555. {
  556.    if ( c4atod( (char *) get_ptr->data, get_ptr->width_data) < -18.5 )  return 0 ;
  557.    w4display( " Illegal Number ", "Must be less than -18.5", (char *) 0 ) ;
  558.    return -1 ;
  559. }
  560.  
  561.  
  562. static int  valid_example(int junk_parm)
  563. {
  564.    int    i_data, r, save_r, c1, c2, c4, w_ref ;
  565.    long   l_data ;
  566.    double d_data ;
  567.    char   dt_data[10], c_data[10], n_data[10] ;
  568.  
  569.    w_ref =  w4define( 0,0, 23,79 ) ;
  570.    w4popup() ;
  571.    w4border( PANEL, F_WHITE ) ;
  572.    w4activate( w_ref ) ;
  573.  
  574.    c1 = 20 ;  c2 = 34 ;  c4 = 50 ;
  575.    r  =  4 ;
  576.  
  577.    i_data =  -4 ;
  578.    l_data =   2 ;
  579.    d_data =  -2.0 ;
  580.  
  581.    strcpy( n_data, " -19.234" ) ;
  582.    strcpy( c_data,  "TEST DATA" ) ;
  583.    strcpy( dt_data, "19790101" ) ;
  584.  
  585.    w4attribute( F_WHITE | F_INTENSE ) ;
  586.    w4centre( r++, "User Defined Validation Examples" ) ;
  587.    w4attribute( F_WHITE ) ;
  588.    ++r ;
  589.  
  590.    w4( ++r,c1, "Picture" ) ;  w4( r,c2, "Data" ) ;  w4( r,c4, "Results") ;
  591.  
  592.    save_r =  ++r ;
  593.  
  594.    w4( ++r,c1, "Date:" ) ;
  595.    g4date(  r,c2, dt_data ) ;
  596.    g4valid( is_date_valid ) ;
  597.    g4message( "The date must be before 1980" ) ;
  598.  
  599.    w4(  ++r, c1, "Integer:" ) ;
  600.    g4int( r, c2, &i_data ) ;
  601.    g4valid( minus_four ) ;
  602.    g4message( "This integer must be less than -4" ) ;
  603.  
  604.    w4(  ++r, c1, "Long:" ) ;
  605.    g4long(r, c2, &l_data ) ;
  606.    g4valid( plus_or_minus ) ;
  607.    g4message( "This long must be less than -1 or greater than 1" ) ;
  608.  
  609.    w4(  ++r, c1, "Double:" ) ;
  610.    g4double(r, c2, &d_data ) ;
  611.    g4valid( plus_or_minus ) ;
  612.    g4message( "This double must be less than -1 or greater than 1") ;
  613.  
  614.    w4(  ++r, c1, "Character:" ) ;
  615.    g4(    r, c2, c_data ) ;
  616.    g4upper() ;
  617.    g4valid( before_t ) ;
  618.    g4message( "The first character must be less than \'T\'" ) ;
  619.  
  620.    w4(  ++r, c1, "Numeric:" ) ;
  621.    g4numeric(r, c2, n_data ) ;
  622.    g4valid( n_valid ) ;
  623.    g4message( "This numeric character string must be less than -18.5" ) ;
  624.  
  625.    g4read() ;
  626.  
  627.    r = save_r ;
  628.  
  629.    w4( ++r, c4, dt_data ) ;
  630.    w4int( ++r, c4, i_data, 4 ) ;
  631.    w4long( ++r, c4, l_data, 8 ) ;
  632.    w4double( ++r, c4, d_data, 8,2 ) ;
  633.    w4( ++r, c4, c_data ) ;
  634.    w4( ++r, c4, n_data ) ;
  635.  
  636.    ++r ;
  637.    w4( ++r, c1, "Press any key to continue ...") ;
  638.    w4cursor( -1,-1 ) ;
  639.    g4char() ;
  640.  
  641.    w4deactivate( w_ref ) ;
  642.    w4close( w_ref ) ;
  643.  
  644.    return 0 ;
  645. }
  646.  
  647.  
  648. static int  handle_example( int junk_parm )
  649. {
  650.    int r, choice, w_ref ;
  651.  
  652.    #ifndef UNIX
  653.       char  save_screen[4000] ;
  654.  
  655.       /* Save the complete screen as writing to the screen with handles
  656.      destroys it. */
  657.       w4read( 0,0, save_screen, sizeof(save_screen) ) ;
  658.    #endif
  659.  
  660.    w_ref =  w4define( 0,0,0,60 ) ;   /* The Window Width is Important */
  661.    w4handle( 1 ) ;
  662.    w4cursor( 24,0 ) ;       /* Move the cursor to the end of the screen */
  663.  
  664.    r = 0 ;
  665.    ++r ;
  666.  
  667.    w4( ++r,0, "  This output is going to handle \'1\'.  Observe that" ) ;
  668.    w4( ++r,0, "output to a handle is completely different than direct" ) ;
  669.    w4( ++r,0, "screen output." ) ;
  670.    ++r ;
  671.    w4( ++r,0, "Press a key to continue ..." ) ;
  672.  
  673.    g4char() ;
  674.  
  675.    r += 3 ;
  676.    w4( ++r,0, "Notice that output is quite a bit slower." ) ;
  677.  
  678.    r += 2 ;
  679.    w4( ++r, 10, "Selections: " ) ;
  680.    ++r ;
  681.    w4( ++r, 13, "S - Screen Output" ) ;
  682.    w4( ++r, 13, "P - Printer Output" ) ;
  683.  
  684.    ++r ;
  685.    w4( ++r, 10, "Press key according to selection ... " ) ;
  686.  
  687.    choice =  toupper( g4char() ) ;
  688.  
  689.    if ( choice == (int) 'P' )
  690.    {
  691.       r = 0 ;
  692.       w4handle( 4 ) ;
  693.       w4centre( r, "PRINTER OUTPUT" ) ;
  694.    }
  695.    else
  696.    {
  697.       w4handle( 1 ) ;
  698.       r += 5 ;
  699.       w4centre( r, "SCREEN OUTPUT" ) ;
  700.    }
  701.  
  702.    ++r ;
  703.    w4( ++r,0, "Now some other output routines will be executed:" ) ;
  704.    ++r ;
  705.    w4( ++r,0, "w4int -   " ) ;
  706.    w4int( r, w4col(), 4, 8 ) ;
  707.  
  708.    w4( ++r,0, "w4long -  " ) ;
  709.    w4long(r, w4col(), -10L, 8 ) ;
  710.    w4(++r,0, "w4double -  " ) ;
  711.    w4double( r, w4col(), 4.4, 8, 2 ) ;
  712.  
  713.    if ( choice == (int) 'P' )  w4eject() ;
  714.  
  715.    w4handle( 1 ) ;
  716.    r =  w4row()+1 ;
  717.    w4( ++r,0, "Press a key to restore the saved screen" ) ;
  718.    w4( ++r,0, "and to return to the main menu" ) ;
  719.    g4char() ;
  720.  
  721.    w4close( w_ref ) ;
  722.  
  723.    #ifdef UNIX
  724.       /* Force a Complete Screen Redraw */
  725.       w_ref =  w4define( 0,0, 24,79 ) ;
  726.       w4activate( w_ref ) ;
  727.       w4deactivate( w_ref ) ;
  728.       w4close( w_ref ) ;
  729.    #else
  730.       /* Restore the screen */
  731.       w4write( 0,0, save_screen, sizeof(save_screen) ) ;
  732.       w4cursor( -1,-1 ) ;
  733.    #endif
  734.  
  735.    return 0 ;
  736. }
  737.  
  738. static int  start_row = 10,  start_col = 20,  end_row = 14, end_col = 59 ;
  739.  
  740. static int  position_window( int command )
  741. {
  742.    int  pop_window, rc ;
  743.  
  744.    switch ( command )
  745.    {
  746.       case 0:   /* Move Up */
  747.      start_row-- ;
  748.      if ( start_row >= 0 )  end_row-- ;
  749.      break ;
  750.  
  751.       case 1:   /* Move Down */
  752.      end_row++ ;
  753.      if ( end_row <= 23 )  start_row++ ;
  754.      break ;
  755.  
  756.       case 2:   /* Move Right */
  757.      end_col++ ;
  758.      if ( end_col <= 79 )  start_col++ ;
  759.      break ;
  760.  
  761.       case 3:   /* Move Left */
  762.      start_col-- ;
  763.      if ( start_col >= 0 )  end_col-- ;
  764.      break ;
  765.  
  766.       case 4:  /* Size Up */
  767.      start_row-- ;
  768.      break ;
  769.  
  770.       case 5:  /* Size Down */
  771.      if ( start_row < end_row )  start_row++ ;
  772.      break ;
  773.  
  774.       case 6:  /* Size Right */
  775.      end_col++ ;
  776.      break ;
  777.  
  778.       case 7:  /* Size Left */
  779.      if ( start_col < end_col )  end_col-- ;
  780.      break ;
  781.    }
  782.  
  783.    if ( start_row < 0 )  start_row =  0 ;
  784.    if ( end_row > 23 )   end_row   = 23 ;
  785.    if ( start_col < 0 )  start_col =  0 ;
  786.    if ( end_col > 79 )   end_col   = 79 ;
  787.  
  788.    pop_window =  w4define( start_row, start_col, end_row, end_col ) ;
  789.    w4attribute( F_INTENSE | F_BLUE | F_GREEN ) ;
  790.    w4popup() ;
  791.    w4border( PANEL, F_GREEN ) ;
  792.    w4activate( pop_window ) ;
  793.  
  794.    if ( w4height(-1) > 0  &&  w4width(-1) > 0 )
  795.       w4centre( (end_row-start_row-2)/2, "Enter a menu command character.") ;
  796.    rc =  g4char() ;
  797.  
  798.    w4deactivate( pop_window ) ;
  799.    w4close( pop_window ) ;
  800.  
  801.    return( rc ) ;
  802. }
  803.  
  804. static int  a_pulldown(int junk_parm)
  805. {
  806.    int  mov , size, pop_menu ;
  807.  
  808.    n4key_special( ESC, CTRL_C, 0x100, 0x7FFF ) ;
  809.  
  810.    pop_menu =  w4define( -1,-1,-1,-1 ) ;
  811.    n4( "Move <Alt M>"); 
  812.    n4reaction( n4sub_menu);       
  813.    n4ptr_save( &mov) ; 
  814.    n4key( ALT_M,0,10);
  815.  
  816.    n4( "Size <Alt S>"); 
  817.    n4reaction( n4sub_menu);
  818.    n4ptr_save( &size) ;
  819.    n4key( ALT_S,0,10);
  820.  
  821.    n4( "Exit <Alt X>"); 
  822.    n4parm( ALT_X);
  823.    n4key( ALT_X,1,10);
  824.  
  825.    mov  =  w4define( -1,-1,-1,-1 ) ;
  826.    n4( "Up" ) ;    n4reaction( position_window);   n4parm(0) ;
  827.    n4( "Down" ) ;  n4reaction( position_window);   n4parm(1) ;
  828.    n4( "Right" ) ; n4reaction( position_window);   n4parm(2) ;
  829.    n4( "Left" ) ;  n4reaction( position_window);   n4parm(3) ;
  830.  
  831.    size =  w4define( -1,-1,-1,-1 ) ;
  832.    n4( "Up" ) ;    n4reaction( position_window);   n4parm(4) ;
  833.    n4( "Down" ) ;  n4reaction( position_window);   n4parm(5) ;
  834.    n4( "Right" ) ; n4reaction( position_window);   n4parm(6) ;
  835.    n4( "Left" ) ;  n4reaction( position_window);   n4parm(7) ;
  836.  
  837.    n4pulldown( pop_menu ) ;
  838.  
  839.    n4activate( pop_menu ) ;
  840.  
  841.    w4close( mov  ) ;
  842.    w4close( size ) ;
  843.    w4close( pop_menu ) ;
  844.  
  845.    return( 0 ) ;
  846. }
  847.  
  848. static int  b_pulldown(int junk_parm)
  849. {
  850.    int  mov , size, pop_menu ;
  851.  
  852.    n4key_special( ESC, CTRL_C, 0, 0 ) ;
  853.  
  854.    pop_menu =  w4define( 0,0, 0,79 ) ;
  855.    w4popup() ;  n4horizontal() ;
  856.    n4item_width( 8 ) ;
  857.    n4( "Move" ); n4action( n4sub_menu) ;
  858.    n4ptr_save( &mov ) ;
  859.    n4key(0,0,-1);
  860.  
  861.    n4( "Size" );
  862.    n4action( n4sub_menu) ;
  863.    n4ptr_save( &size ) ;
  864.    n4key(0,0,-1);
  865.  
  866.    n4( "Exit" ) ;
  867.    n4parm( ALT_X ) ;
  868.    n4key(0,0,-1);
  869.  
  870.    mov  =  w4define( 1,0, 6,8 ) ;
  871.    w4popup() ;     w4border( SINGLE, F_WHITE ) ;   n4arrow_exit() ;
  872.  
  873.    n4( "Up" ) ;
  874.    n4action( position_window ) ;
  875.    n4parm(0) ;
  876.    n4key( 0,0, -1 ) ;
  877.  
  878.    n4( "Down" ) ;
  879.    n4action( position_window ) ;
  880.    n4parm( 1 ) ;
  881.    n4key( 0,0, -1 ) ;
  882.  
  883.    n4( "Right" ) ;
  884.    n4action( position_window ) ;
  885.    n4parm( 2 ) ;
  886.    n4key( 0,0, -1 ) ;
  887.  
  888.    n4( "Left" ) ;
  889.    n4action( position_window ) ;
  890.    n4parm( 3 ) ;
  891.    n4key( 0,0, -1 ) ;
  892.  
  893.    size =  w4define( 1,8, 6,16 ) ;
  894.    w4popup() ;     w4border( SINGLE, F_WHITE ) ;    n4arrow_exit() ;
  895.  
  896.    n4( "Up" ) ;
  897.    n4action( position_window ) ;
  898.    n4parm( 4 ) ;
  899.    n4key( 0,0, -1 ) ;
  900.  
  901.    n4( "Down" ) ;
  902.    n4action( position_window ) ;
  903.    n4parm( 5 ) ;
  904.    n4key( 0,0, -1 ) ;
  905.  
  906.    n4( "Right" ) ;
  907.    n4action( position_window ) ;
  908.    n4parm( 6 ) ;
  909.    n4key( 0,0, -1 ) ;
  910.  
  911.    n4( "Left" ) ;
  912.    n4action( position_window ) ;
  913.    n4parm( 7 ) ;
  914.    n4key( 0,0, -1 ) ;
  915.  
  916.    n4pulldown( pop_menu ) ;
  917.  
  918.    n4activate( pop_menu ) ;
  919.  
  920.    w4close( mov  ) ;
  921.    w4close( size ) ;
  922.    w4close( pop_menu ) ;
  923.  
  924.    return( 0 ) ;
  925. }
  926.  
  927.  
  928. static int   language_display( int ) ;
  929.  
  930. static int   language_display( int item_ref )
  931. {
  932.    char  buffer[80] ;
  933.    char *ptr ;
  934.    int i ;
  935.  
  936.    ptr =  (char *) n4ptr_get(item_ref) ;
  937.    i   =  n4int_get(item_ref) ;
  938.  
  939.    memset( buffer, (int) 0, sizeof(buffer) ) ;
  940.    strcpy( buffer, ptr ) ;
  941.    c4ltoa( (long) i, buffer+strlen(buffer), 2 ) ;
  942.  
  943.    return( w4display( "", buffer, (char *) 0 )   ) ;
  944. }
  945.  
  946.  
  947. static int  lotus_help( int junk_parm )
  948. {
  949.    int  w_ref, r, c ;
  950.  
  951.    w_ref =  w4define( 3,10, 21,69 ) ;
  952.    w4popup() ;
  953.    w4border( DOUBLE, B_GREEN ) ;
  954.  
  955.    w4title( 0, -1, " Lotus-style Menu Help Window ", F_WHITE | F_INTENSE ) ;
  956.  
  957.    w4activate( w_ref ) ;
  958.  
  959.    r = 1 ; c = 4 ;
  960.    w4( ++r,c,  "The Lotus-style Menus have an user interface which" ) ;
  961.    w4( ++r,c,  "operates the same manner as Lotus 123 Menus.  You" ) ;
  962.    w4( ++r,c,  "have the following options:" ) ;
  963.    ++r ;
  964.    w4( ++r,c,  "   1.  Arrow left or right and then press <Enter>." ) ;
  965.    ++r ;
  966.    w4( ++r,c,  "   2.  Press the highlighted key." ) ;
  967.    ++r ;
  968.    w4( ++r,c,  "   3.  <Esc> moves up one menu." ) ;
  969.    ++r ;
  970.    w4( ++r,c,  "   4.  '/' moves to the top menu." ) ;
  971.    ++r ;
  972.    w4( ++r,c,  "Press any key to continue ..." ) ;
  973.  
  974.    g4char() ;
  975.  
  976.    w4deactivate( w_ref ) ;
  977.    w4close( w_ref ) ;
  978.  
  979.    return 0 ;
  980. }
  981.  
  982. extern int  v4menu_row, v4menu_col ;
  983.  
  984. /* Implements Some Lotus Style Menuing */
  985. static int  lotus_example(int junk_parm)
  986. {
  987.    int  language, french, english, german ;
  988.    #define  RETURN_CODE  -2
  989.  
  990.    language =  w4define( -1,-1,-1,-1 ) ;
  991.    n4( "French" );  n4message( "Un, Deux, Trois, Quatre, Cinq, Six" ) ;
  992.             n4action( n4sub_menu ) ;
  993.                     n4ptr_save( &french ) ;
  994.    n4( "English" ); n4message( "One, Two, Three, Four" ) ;
  995.             n4action( n4sub_menu) ;
  996.                     n4ptr_save( &english ) ;
  997.    n4( "German" );  n4message( "Eins, Zwei, Drei, Fier, Fuenf" ) ;
  998.             n4action( n4sub_menu ) ;
  999.                     n4ptr_save( &german ) ;
  1000.    n4( "Help") ;    n4message( "Lotus-style Menu Help" ) ;
  1001.             n4action( lotus_help ) ;
  1002.    n4( "Return" );  n4message( "Return from the Lotus menu example." ) ;
  1003.             n4parm( RETURN_CODE ) ;
  1004.  
  1005.    french   =  w4define( -1,-1,-1,-1 ) ;
  1006.    n4( "Un");      n4message( "Le nombre est un.") ;
  1007.            n4action( language_display ) ;
  1008.                    n4ptr_save( "Le nombre est" ) ;
  1009.                    n4int_save( 1 ) ;
  1010.    n4( "Deux");    n4message( "Le nombre est deux." ) ;
  1011.            n4action( language_display ) ;
  1012.                    n4ptr_save( "Le nombre est" ) ;
  1013.                    n4int_save( 2 ) ;
  1014.    n4( "Trois");   n4message( "Le nombre est trois." ) ;
  1015.            n4action( language_display ) ;
  1016.                    n4ptr_save( "Le nombre est" ) ;
  1017.                    n4int_save( 3 ) ;
  1018.    n4( "Quatre");  n4message( "Le nombre est quatre." ) ;
  1019.            n4action( language_display ) ;
  1020.                    n4ptr_save( "Le nombre est" ) ;
  1021.                    n4int_save( 4 ) ;
  1022.    n4( "Cinq");    n4message( "Le nombre est cinq." ) ;
  1023.            n4action( language_display ) ;
  1024.                    n4ptr_save( "Le nombre est" ) ;
  1025.                    n4int_save( 5 ) ;
  1026.    n4( "Six");     n4message( "Le nombre est six." ) ;
  1027.            n4action( language_display ) ;
  1028.                    n4ptr_save( "Le nombre est" ) ;
  1029.                    n4int_save( 6 ) ;
  1030.    n4( "Help") ;   n4message( "Lotus-style Menu Help" ) ;
  1031.            n4action( lotus_help) ;
  1032.  
  1033.    english  =  w4define( -1,-1,-1,-1 ) ;
  1034.    n4( "One");     n4message( "You are on number one." ) ;
  1035.            n4action( language_display ) ;
  1036.                    n4ptr_save( "The number is" ) ;
  1037.                    n4int_save( 1 ) ;
  1038.    n4( "Two");     n4message( "You are on number two." ) ;
  1039.            n4action( language_display ) ;
  1040.                    n4ptr_save( "The number is" ) ;
  1041.                    n4int_save( 2 ) ;
  1042.    n4( "Three");   n4message( "You are on number three." ) ;
  1043.            n4action( language_display ) ;
  1044.                    n4ptr_save( "The number is" ) ;
  1045.                    n4int_save( 3 ) ;
  1046.    n4( "Four");    n4message( "You are on number four." ) ;
  1047.            n4action( language_display ) ;
  1048.                    n4ptr_save( "The number is" ) ;
  1049.                    n4int_save( 4 ) ;
  1050.    n4( "Help");    n4message( "Lotus-style Menu Help" ) ;
  1051.            n4action( lotus_help ) ;
  1052.  
  1053.    german   =  w4define( -1,-1,-1,-1 ) ;
  1054.    n4( "Eins");    n4message( "Sie sind auf Nummer einz" ) ;
  1055.            n4action( language_display ) ;
  1056.                    n4ptr_save( "Sie sind auf Nummer" ) ;
  1057.                    n4int_save( 1 ) ;
  1058.    n4( "Zwei");    n4message( "Sie sind auf Nummer zwei" ) ;
  1059.            n4action( language_display ) ;
  1060.                    n4ptr_save( "Sie sind auf Nummer" ) ;
  1061.                    n4int_save( 2 ) ;
  1062.    n4( "Drei");    n4message( "Sie sind auf Nummer drei" ) ;
  1063.            n4action( language_display ) ;
  1064.                    n4ptr_save( "Sie sind auf Nummer" ) ;
  1065.                    n4int_save( 3 ) ;
  1066.    n4( "Fier");    n4message( "Sie sind auf Nummer fier" ) ;
  1067.            n4action( language_display ) ;
  1068.                    n4ptr_save( "Sie sind auf Nummer" ) ;
  1069.                    n4int_save( 4 ) ;
  1070.    n4( "Fuenf");   n4message( "Sie sind auf Nummer fuenf" ) ;
  1071.            n4action( language_display ) ;
  1072.                    n4ptr_save( "Sie sind auf Nummer" ) ;
  1073.                    n4int_save( 5 ) ;
  1074.    n4( "Help") ;   n4message( "Lotus-style Menu Help" ) ;
  1075.            n4action( lotus_help ) ;
  1076.  
  1077.    n4lotus( language ) ;
  1078.  
  1079.    while( n4activate( language ) != RETURN_CODE )  ;
  1080.  
  1081.    w4close( language ) ;
  1082.    w4close( french ) ;
  1083.    w4close( english ) ;
  1084.    w4close( german ) ;
  1085.  
  1086.    v4menu_row = 24 ;
  1087.    v4menu_col =  0 ;
  1088.  
  1089.    return 0 ;
  1090. }
  1091.  
  1092.  
  1093. /* File Searching Example */
  1094.  
  1095. static int  search_help( int junk_parm )
  1096. {
  1097.     w4display( " Search Help ",
  1098.        "   In this search example, you are able to type a",
  1099.        "file name.  The menu highlighting bar is automatically",
  1100.        "positioned to the menu entry corresponding to the",
  1101.        "letters typed.",
  1102.        "",
  1103.        "   If you type the wrong character, <Back Space> will",
  1104.        "reverse the character entry.",
  1105.        "",
  1106.        "   To select a different set of files, select the search",
  1107.        "pattern menu option.",
  1108.        (char *) 0 ) ;
  1109.  
  1110.     return 0 ;
  1111. }
  1112.  
  1113. static int  display_item( int item_ref )
  1114. {
  1115.    w4display( " Selected File: ", v4menu[item_ref].item_ptr, (char *) 0 ) ;
  1116.    return 0 ;
  1117. }
  1118.  
  1119. static int  select_file( char *pattern )
  1120. {
  1121.    int   w_ref, n_data, i, rc ;
  1122.    char  count_data[14], *data ;
  1123.  
  1124.    for( rc =  u4file_first(pattern,count_data), n_data= 0; rc == 0; n_data +=14)
  1125.     rc =  u4file_next( count_data ) ;
  1126.  
  1127.    if ( n_data == 0 )
  1128.    {
  1129.       w4display( " No Files for Pattern ", pattern, (char *) 0 ) ;
  1130.       return 0 ;
  1131.    }
  1132.  
  1133.    w_ref =  w4define( -1,-1,-1,-1 ) ;
  1134.  
  1135.    n4skip_over( n4(""), 1 ) ;
  1136.  
  1137.    n4( "Help" ) ;
  1138.    n4action( search_help ) ;
  1139.  
  1140.    n4skip_over( n4(""), 1 ) ;
  1141.    n4skip_over( n4( "Search" ), 1 ) ;
  1142.    n4skip_over( n4( "Pattern:" ), 1 ) ;
  1143.    n4( pattern ) ;
  1144.    n4parm( -2 ) ;
  1145.  
  1146.    n4skip_over( n4(""), 1 ) ;
  1147.  
  1148.    /* Allocate Enough File Memory */
  1149.    data =  (char *) h4alloc( n_data ) ;
  1150.  
  1151.    rc =  u4file_first(pattern, data ) ;
  1152.    n4( data ) ;  
  1153.    n4action( display_item ) ;
  1154.  
  1155.    for ( i= 14; i< n_data ; i+= 14 )
  1156.    {
  1157.       if ( u4file_next( data+i )  != 0 )  break ;
  1158.       n4( data+i ) ;
  1159.       n4action(  display_item ) ;
  1160.    }
  1161.  
  1162.    n4calc( w_ref, 2,79 ) ; /* Put in upper right hand corner */
  1163.    n4key_set( 2,1 ) ;      /* ** Searching On ** */
  1164.    w4border( DOUBLE, F_WHITE ) ;
  1165.    w4title( 0,-1, " File Search ", F_WHITE ) ;
  1166.    rc =  n4activate( w_ref ) ;
  1167.    w4close( w_ref ) ;
  1168.    h4free_memory( data ) ;
  1169.  
  1170.    return  rc ;
  1171. }
  1172.  
  1173.  
  1174. static int  search_example( int junk_parm )
  1175. {
  1176.    char pattern[14] ;
  1177.    int  rc, w_ref, len ;
  1178.  
  1179.    strcpy( pattern, "*.*" ) ;
  1180.  
  1181.    for( rc = select_file(pattern);  rc == -2; rc = select_file(pattern) )
  1182.    {
  1183.      /* Change Pattern Selected */
  1184.       w_ref =  w4define( 5,50, 9, 79 ) ;
  1185.       w4popup() ;
  1186.       w4border( DOUBLE, F_WHITE ) ;
  1187.       w4activate( w_ref ) ;
  1188.  
  1189.       w4( 1,3, "Pattern:  " ) ;
  1190.       len =  (int) strlen(pattern) ;
  1191.       memset( pattern+len, (int) ' ', 12-len ) ;
  1192.       pattern[12] =  '\0' ;
  1193.       g4( w4row(),w4col(), pattern ) ;
  1194.       g4message( "Enter a new file pattern" ) ;
  1195.       g4upper() ;
  1196.  
  1197.       g4read() ;
  1198.       w4deactivate( w_ref ) ;
  1199.       w4close( w_ref ) ;
  1200.    }
  1201.    return 0 ;
  1202. }
  1203.  
  1204. #ifndef UNIX
  1205. /* Color Example */
  1206.  
  1207. typedef struct  color_data_st
  1208. {
  1209.    char  text[19] ;
  1210.    char  status[4] ;
  1211.    long  attribute ;
  1212.    int   item_ref ;
  1213.    int   mask ;
  1214. }  COLOR_DATA ;
  1215.  
  1216. static COLOR_DATA  color_data[] =
  1217. {
  1218.    { "Foreground Blue:  ", "",  F_WHITE, 0, 0x01 },
  1219.    { "Foreground Green: ", "",  F_WHITE, 0, 0x02 },
  1220.    { "Foreground Red:   ", "",  F_WHITE, 0, 0x04 },
  1221.    { "Intensity:        ", "",  F_WHITE, 0, 0x08 },
  1222.    { "Background Blue:  ", "",  F_WHITE, 0, 0x10 },
  1223.    { "Background Green: ", "",  F_WHITE, 0, 0x20 },
  1224.    { "Background Red:   ", "",  F_WHITE, 0, 0x40 },
  1225.    { "Blinking:         ", "",  F_WHITE, 0, 0x80 },
  1226. } ;
  1227.  
  1228. typedef struct att_choice_st
  1229. {
  1230.    char text[20] ;
  1231.    long attribute ;
  1232. }  ATT_CHOICE ;
  1233.  
  1234. static ATT_CHOICE  att_choices[] =
  1235. {
  1236.    { "Window Attribute", 0x70L },
  1237.    { "Title Attribute",  0x0FL },
  1238.    { "Border Attribute", 0x0FL },
  1239. } ;
  1240.  
  1241. static  char  choice_data[20] ;
  1242. static  long *attribute_ptr ;
  1243. static  int   explain_color(int) ;
  1244. static  int   change_bits(int) ;
  1245. static  int   change_choice(int) ;
  1246. static  void  init_all_bits(void) ;
  1247.  
  1248. static int  explain_color(int junk_parm)
  1249. {
  1250.    int  rc, w_ref, r,c ;
  1251.  
  1252.    w_ref =  w4define(  2,30, 22,79 ) ;
  1253.    w4attribute( att_choices[0].attribute ) ;
  1254.    w4title( 0,-1, " Color Window ", att_choices[1].attribute ) ;
  1255.    w4border( PANEL, att_choices[2].attribute ) ;
  1256.    w4popup() ;
  1257.    w4activate( w_ref ) ;
  1258.  
  1259.    r=0 ;  c=2 ;
  1260.  
  1261.    w4( ++r,c, "  You may select a menu option to toggle its" ) ;
  1262.    w4( ++r,c, "setting.  For example, \'Foreground Blue\'" ) ;
  1263.    w4( ++r,c, "can be ON or OFF.  As each of these eight" ) ;
  1264.    w4( ++r,c, "menu options in the Color Menu corresponds");
  1265.    w4( ++r,c, "to a bit in an attribute byte, you are" ) ;
  1266.    w4( ++r,c, "flipping the bits in the attribute bytes" ) ;
  1267.    w4( ++r,c, "being displayed.  This lets you observe" ) ;
  1268.    w4( ++r,c, "all of the color possibilities." ) ;
  1269.    ++r ;
  1270.    w4( ++r,c, "  You may also change the color of this" ) ;
  1271.    w4( ++r,c, "windows title or border by selecting the" ) ;
  1272.    w4( ++r,c, "\'Choice\' option." ) ;
  1273.    ++r ;
  1274.    w4( ++r,c, "  Note that Code Base can also be programmed" ) ;
  1275.    w4( ++r,c, "to set the color attribute of individual menu" ) ;
  1276.    w4( ++r,c, "items or the color attribute of the currently" ) ;
  1277.    w4( ++r,c, "selected menu item." ) ;
  1278.  
  1279.    rc =  g4char() ;
  1280.    w4deactivate( w_ref ) ;
  1281.    w4close( w_ref ) ;
  1282.  
  1283.    return rc ;
  1284. }
  1285.  
  1286. static int  change_bits_ptr( COLOR_DATA * ) ;
  1287.  
  1288. static int  change_bits( int item_ref )
  1289. {
  1290.    return( change_bits_ptr( (COLOR_DATA *) n4ptr_get(item_ref)) ) ;
  1291. }
  1292.  
  1293. static int  change_bits_ptr( COLOR_DATA *data_ptr )
  1294. {
  1295.    *attribute_ptr ^=  data_ptr->mask ;
  1296.  
  1297.    if ( *attribute_ptr & data_ptr->mask )
  1298.    {
  1299.       strcpy( data_ptr->status, "ON " ) ;
  1300.       n4attribute_item( data_ptr->item_ref, data_ptr->attribute | F_INTENSE) ;
  1301.    }
  1302.    else
  1303.    {
  1304.       strcpy( data_ptr->status, "OFF" ) ;
  1305.       n4attribute_item( data_ptr->item_ref, data_ptr->attribute ) ;
  1306.    }
  1307.  
  1308.    return 0 ;
  1309. }
  1310.  
  1311. static void  init_all_bits()
  1312. {
  1313.    int i ;
  1314.    *attribute_ptr ^=  0xFF ;
  1315.    for ( i=0; i< 8; i++ )
  1316.       change_bits_ptr( color_data+i ) ;
  1317. }
  1318.  
  1319. static int  change_choice( int item_ref )
  1320. {
  1321.    ATT_CHOICE *choice_ptr ;
  1322.    choice_ptr =  (ATT_CHOICE *) n4ptr_get( item_ref ) ;
  1323.  
  1324.    attribute_ptr =  &choice_ptr->attribute ;
  1325.    memcpy( choice_data, choice_ptr->text, (int) sizeof(choice_data) ) ;
  1326.    return -2 ;  /* Return from 'n4activate' with this -2 code */
  1327. }
  1328.  
  1329. static int  color_menu( int junk_parm )
  1330. {
  1331.    int  w_ref, choice_ref, i, i_ref ;
  1332.  
  1333.    n4key_special( ESC, CTRL_C, 0,0 ) ;
  1334.  
  1335.    w_ref =  w4define( -1,-1,-1,-1 ) ;
  1336.    w4border( SINGLE, F_WHITE ) ;
  1337.    w4title( 0,-1, " Color Menu ", B_WHITE ) ;
  1338.  
  1339.    n4skip_over( n4( "Currently Changing:"), 1 ) ;
  1340.  
  1341.    n4( choice_data ) ;
  1342.    n4key( 0,0,-1 ) ;
  1343.    n4reaction( explain_color ) ;
  1344.    n4action( n4sub_menu ) ;
  1345.    n4ptr_save( &choice_ref ) ;
  1346.  
  1347.    n4skip_over( n4(""), 1 ) ;
  1348.  
  1349.    for ( i=0; i< 8; i++ )
  1350.    {
  1351.       color_data[i].item_ref =  n4( color_data[i].text ) ;
  1352.       n4reaction( explain_color ) ;
  1353.       n4action( change_bits ) ;
  1354.       n4ptr_save( color_data+i ) ;
  1355.       n4key( 0,0, -1 ) ;
  1356.    }
  1357.  
  1358.  
  1359.    choice_ref =  w4define( -1,-1,-1,-1 ) ;
  1360.    w4border( SINGLE, F_WHITE ) ;
  1361.    for ( i=2; i >= 0; i-- )
  1362.    {
  1363.       i_ref =  n4( att_choices[i].text ) ;
  1364.       n4action( change_choice ) ;
  1365.       n4ptr_save( att_choices+i ) ;
  1366.    }
  1367.  
  1368.    change_choice( i_ref ) ;
  1369.    init_all_bits() ;
  1370.    n4calc( w_ref, 12,2 ) ;
  1371.  
  1372.    while( n4activate(w_ref) == -2 )    init_all_bits() ;
  1373.  
  1374.    w4close( w_ref ) ;
  1375.    w4close( choice_ref ) ;
  1376.  
  1377.    return 0 ;
  1378. }
  1379. #endif
  1380.  
  1381.  
  1382. /* Skipping Example */
  1383.  
  1384. static  int  main_window_ref, on_window_ref ;
  1385.  
  1386. typedef struct count_data_st
  1387. {
  1388.    char  ptr[10] ;
  1389.    int   main_item_ref, on_item_ref ;
  1390. }  COUNT_DATA ;
  1391.  
  1392. COUNT_DATA  count_data[] =
  1393. {
  1394.    {"One"},
  1395.    {"Two"},
  1396.    {"Three"},
  1397.    {"Four"},
  1398. } ;
  1399.  
  1400. static int  change_status( int ) ;
  1401.  
  1402. static int  change_status( int item_ref )
  1403. {
  1404.    COUNT_DATA  *count_ptr ;
  1405.    int  main_on_flag ;
  1406.  
  1407.    count_ptr    =  (COUNT_DATA *) n4ptr_get( item_ref ) ;
  1408.    main_on_flag =  n4int_get( item_ref ) ;
  1409.  
  1410.    n4skip_over( count_ptr->main_item_ref, ! main_on_flag ) ;
  1411.  
  1412.    if ( main_on_flag )
  1413.    {
  1414.       n4attribute_item( count_ptr->main_item_ref, F_WHITE | F_INTENSE ) ;
  1415.       n4attribute_item( count_ptr->on_item_ref, F_WHITE ) ;
  1416.       n4refresh( main_window_ref ) ;
  1417.    }
  1418.    else
  1419.    {
  1420.       n4attribute_item( count_ptr->main_item_ref, F_WHITE ) ;
  1421.       n4attribute_item( count_ptr->on_item_ref, F_WHITE | F_INTENSE ) ;
  1422.    }
  1423.  
  1424.    return DOWN ;
  1425. }
  1426.  
  1427.  
  1428. static int  skipping_help( int junk_parm )
  1429. {
  1430.    w4display( " Help for Menu Item Skipping ",
  1431.  
  1432.           "   This example illustrates how individual menu items",
  1433.           "can interactively be turned on and off.  When a menu item",
  1434.           "is turned off, it can no longer be chosen.  This is",
  1435.           "useful when a menu item is temporarily not needed.",
  1436.           "",
  1437.           "   Menu items \'One\', \'Two\', \'Three\' and \'Four\' can",
  1438.           "all be temporarily turned off by selecting them.  To turn",
  1439.           "one of these menu items back on, choose option \'Turn On\'.",
  1440.           (char *) 0 )  ;
  1441.    return 0 ;
  1442. }
  1443.  
  1444. static int  skipping( int junk_parm )
  1445. {
  1446.    int  i, item_ref ;
  1447.  
  1448.    main_window_ref =  w4define( -1,-1,-1,-1 ) ;
  1449.    w4border( DOUBLE, F_WHITE ) ;
  1450.    w4popup() ;
  1451.    n4key_set( 0,0 ) ;
  1452.  
  1453.    item_ref =  n4( "Help" ) ;
  1454.    n4attribute_item( item_ref, F_WHITE | F_INTENSE ) ;
  1455.    n4action( skipping_help ) ;
  1456.  
  1457.    n4skip_over( n4( "" ), 1 ) ;
  1458.  
  1459.    item_ref =  n4( "Turn On") ;
  1460.    n4attribute_item( item_ref, F_WHITE | F_INTENSE ) ;
  1461.    n4action( n4sub_menu ) ;
  1462.    n4ptr_save( &on_window_ref ) ;
  1463.    n4skip_over( n4( "" ), 1) ;
  1464.  
  1465.    for ( i=0; i<4; i++ )
  1466.    {
  1467.       count_data[i].main_item_ref =  n4( count_data[i].ptr ) ;
  1468.       n4action( change_status ) ;
  1469.       n4ptr_save( count_data+i ) ;
  1470.       n4int_save( 0 ) ;
  1471.       n4attribute_item( count_data[i].main_item_ref, F_WHITE | F_INTENSE ) ;
  1472.    }
  1473.  
  1474.    on_window_ref =  w4define( -1,-1,-1,-1 ) ;
  1475.    w4border( DOUBLE, F_WHITE ) ;
  1476.    w4popup() ;
  1477.    n4key_set( 0,0 ) ;
  1478.  
  1479.    for ( i=0; i<4; i++ )
  1480.    {
  1481.       count_data[i].on_item_ref =  n4( count_data[i].ptr ) ;
  1482.       n4action( change_status ) ;
  1483.       n4ptr_save( count_data+i ) ;
  1484.       n4int_save( 1 ) ;
  1485.    }
  1486.  
  1487.    n4calc( main_window_ref, 13,2 ) ;
  1488.  
  1489.    n4activate( main_window_ref ) ;
  1490.  
  1491.    w4close(main_window_ref) ;
  1492.    w4close(on_window_ref) ;
  1493.  
  1494.    return 0 ;
  1495. }
  1496.  
  1497.  
  1498. static int  row_column_display( int item_ref )
  1499. {
  1500.    int  w_ref, rc ;
  1501.    int  r,c ;
  1502.  
  1503.    c =  n4int_get(item_ref) & 7 ;
  1504.    r =  n4int_get(item_ref) / 8 ;
  1505.  
  1506.    w_ref =  w4define( r*10, c*34, r*10+4, c*34+10 ) ;
  1507.    w4popup() ;
  1508.    w4border( PANEL, F_BLUE ) ;
  1509.  
  1510.    w4activate( w_ref ) ;
  1511.    w4( 1,2, n4item_text( item_ref ) ) ;
  1512.  
  1513.    rc =  g4char() ;
  1514.    w4deactivate( w_ref ) ;
  1515.    w4close( w_ref ) ;
  1516.  
  1517.    return rc ;
  1518. }
  1519.  
  1520. static int  row_column( int junk_parm )
  1521. {
  1522.    int  w_ref ;
  1523.  
  1524.    w_ref =  w4define(10,28,14,54) ;
  1525.    w4popup() ;
  1526.    w4border( DOUBLE, F_WHITE ) ;
  1527.    w4title( 0,-1, " Row/Column Menu ", B_WHITE ) ;
  1528.  
  1529.    n4( "One" ) ;   n4action( row_column_display ) ; n4int_save(0) ;
  1530.    n4( "Two" ) ;   n4action( row_column_display ) ; n4int_save(1) ;
  1531.    n4( "Three" ) ; n4action( row_column_display ) ; n4int_save(2) ;
  1532.    n4( "Four" ) ;  n4action( row_column_display ) ; n4int_save(8) ;
  1533.    n4( "Five" ) ;  n4action( row_column_display ) ; n4int_save(9) ;
  1534.    n4( "Six" ) ;   n4action( row_column_display ) ; n4int_save(10) ;
  1535.    n4( "Seven" ) ; n4action( row_column_display ) ; n4int_save(16) ;
  1536.    n4( "Eight" ) ; n4action( row_column_display ) ; n4int_save(17) ;
  1537.    n4( "Nine" ) ;  n4action( row_column_display ) ; n4int_save(18) ;
  1538.  
  1539.    n4item_width( 7 ) ;
  1540.    n4horizontal() ;
  1541.  
  1542.    n4activate( w_ref ) ;
  1543.    w4close( w_ref ) ;
  1544.  
  1545.    return 0 ;
  1546. }
  1547.  
  1548.  
  1549. static  char  random_data[9][6] =
  1550. {
  1551.    "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
  1552. } ;
  1553.  
  1554.  
  1555.  
  1556. static int  random_menu( int junk_parm )
  1557. {
  1558.    int     w_ref, num_items, i, r,c ;
  1559.    time_t  t ;
  1560.  
  1561.    srand( (unsigned int) time(&t) ) ;
  1562.  
  1563.    #define  START_ROW    5
  1564.    #define  START_COL   30
  1565.    #define  END_ROW     20
  1566.    #define  END_COL     60
  1567.  
  1568.    w_ref =  w4define( START_ROW, START_COL, END_ROW, END_COL ) ;
  1569.    w4popup() ;
  1570.    w4border( DOUBLE, F_GREEN ) ;
  1571.    w4title( 0,-1, " Random Menu ", B_WHITE ) ;
  1572.  
  1573.    num_items =  rand() % 7 + 3 ;  /* 3 to 9 */
  1574.  
  1575.    for ( i=0; i< num_items; i++ )
  1576.    {
  1577.       r = rand() % ( END_ROW-START_ROW-1 ) ;
  1578.       c = rand() % ( END_COL-START_COL-1 ) ;
  1579.  
  1580.       n4item( r,c, random_data[i] ) ;
  1581.       n4action( row_column_display ) ;
  1582.       n4int_save(9) ;
  1583.    }
  1584.  
  1585.    n4activate( w_ref ) ;
  1586.    w4close( w_ref ) ;
  1587.  
  1588.    return 0 ;   
  1589. }
  1590.