home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / codebase.zip / CSDEMO.C < prev    next >
Text File  |  1992-09-14  |  42KB  |  1,595 lines

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