home *** CD-ROM | disk | FTP | other *** search
/ Games 1995 to 2000 / Games.iso / SexTetris / GETFUNCS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-16  |  44.0 KB  |  1,428 lines

  1. #include "microlib.h"
  2.  
  3. #define    GETFROMBROWSE_KEY        F3
  4.  
  5. extern char iepdrive[3];
  6. extern char ieppath[50];
  7.  
  8. /*****************************************************************************/
  9. /* Function: int gpassword(GET *get_ptr, char *data_buffer, int no_need)          */
  10. /*****************************************************************************/
  11. int gpassword(get_ptr, data_buffer, no_need)
  12. GET *get_ptr;
  13. char *data_buffer;
  14. int no_need;
  15. {
  16.     char *first_password;
  17.     char second_password[7];
  18.     int check_password_wref;
  19.     int first_len;
  20.     int key_val;
  21.     int count;
  22.  
  23.     /* Disable Borland's C warning: "Parameter never used in function..." */
  24.     if(no_need);
  25.  
  26.     key_val = g4char();
  27.  
  28.     /* If a key, which causes g4read to change field, is pressed. */
  29.     /* ==IF EXIT KEY== */
  30.     if(key_val == RETURN || key_val == TAB || key_val == DOWN || key_val == UP \
  31.                 || key_val == SHIFT_TAB) {
  32.         first_password = data_buffer;
  33.         first_len = get_ptr->width_data;
  34.         /* Convert first password entered to uppercase. */
  35.         for(count=0; count<=first_len -1; count ++)
  36.             first_password[count] = gtoupper(first_password[count]);
  37.         /* Open window and ask to retype the password. */
  38.         check_password_wref = w4define(get_ptr->row, get_ptr->col, \
  39.                                             get_ptr->row + 2, get_ptr->col +18);
  40.         w4attribute(custom[MAIN_N]);
  41.         w4title(0, 1, mes[MT+17], custom[MAIN_N]);
  42.         w4border(SINGLE, custom[MAIN_N]);
  43.         w4popup();
  44.         w4memory();
  45.         w4activate( check_password_wref );
  46.  
  47.         memcpy(second_password, space(first_len), first_len);
  48.         g4attribute( 0 );
  49.         g4delimiter("[]");
  50.         g4(0, 3, second_password); g4width(7, 7);
  51.         g4read();
  52.  
  53.         w4deactivate(check_password_wref);
  54.         w4close(check_password_wref);
  55.  
  56.         /* Convert second password to uppercase before comparison. */
  57.         for(count=0; count<=first_len -1; count ++)
  58.             second_password[count] = gtoupper(second_password[count]);
  59.  
  60.         /* If passwords are equal. */
  61.         if( !memcmp( first_password, second_password, first_len)) {
  62.             return(TAB);
  63.             }
  64.         else {
  65.             w4display("", mes[ME+15], mes[MH+16], (char *) 0);
  66.             memcpy(first_password, space(first_len), first_len);
  67.             return(HOME);
  68.             }
  69.         } /* ==IF EXIT KEY== */
  70.     else
  71.         return(key_val);
  72.     }
  73.  
  74. /*****************************************************************************/
  75. /* Function: int vnot_empty(GET *get_ptr)                                     */
  76. /*****************************************************************************/
  77. int vnot_empty(get_ptr )
  78. GET *get_ptr;
  79. {
  80.     char *entry_area;
  81.  
  82.     entry_area = (char *) get_ptr->data;
  83.     /* If empty then NOT Valid. */
  84.     if( !memcmp( entry_area, space(get_ptr->width_data), get_ptr->width_data)) {
  85.         w4display("", mes[ME+14], mes[MH+16], (char *) 0);
  86.         return(-1);
  87.         }
  88.     else
  89.         return(0);
  90.     }
  91. /*****************************************************************************/
  92. /* Function: int gfilename(GET *get_ptr, char *data_buffer, int no_need)          */
  93. /*****************************************************************************/
  94. int gfilename(get_ptr, data_buffer, browser_flag)
  95. GET *get_ptr;
  96. char *data_buffer;
  97. int browser_flag;
  98. {
  99.     int    key_val;
  100.  
  101.     int    src_count;
  102.     int    dest_count;
  103.     int    ext_count;
  104.     int    ext_flag;
  105.     int    error_flag;
  106.  
  107.     char  filename[12];
  108.  
  109.     if(get_ptr);
  110.  
  111.     memset(filename, ' ', 12);
  112.     ext_count = 0;
  113.     ext_flag = FALSE;
  114.     error_flag = FALSE;
  115.  
  116.     key_val = g4char();
  117.     /* If a key, which causes g4read to change field, is pressed, if the value */
  118.     /* entered is found in the data base print the description. Otherwise ring */
  119.     /* the bell and stay to the field.                                         */
  120.     if(key_val == RETURN || key_val == TAB || key_val == DOWN || key_val == UP \
  121.             || key_val == SHIFT_TAB || key_val == F10) {
  122.             dest_count = 0;
  123.             for(src_count = 0; src_count <= 11; src_count ++ ) { /* ==L1== */
  124.                 /* No '.' first letter */
  125.                 if(data_buffer[src_count] == '.' && src_count == 0) {
  126.                     error_flag = TRUE;
  127.                     break;
  128.                     }
  129.                 /* No '.' position > 8 (9th character) */
  130.                 if(data_buffer[src_count] == '.' &&  src_count > 8) {
  131.                     error_flag = TRUE;
  132.                     break;
  133.                     }
  134.                 if(data_buffer[src_count] == '.') {
  135.                     /* No two '.' allowed. */
  136.                     if(memchr(data_buffer, '.', src_count)) {
  137.                         error_flag = TRUE;
  138.                         break;
  139.                         }
  140.                     ext_flag = TRUE;
  141.                     }
  142.                 /* If end of file name. */
  143.                 if(data_buffer[src_count] == ' ') {
  144.                     /* If the last character was a '.' replace with ' ' */
  145.                     if(data_buffer[src_count - 1] == '.')
  146.                         filename[dest_count - 1] = ' ';
  147.                     break;
  148.                     }
  149.                 /* If main name has ended. */
  150.                 if(src_count > 7 && data_buffer[8] != '.') {
  151.                     /* If there is no '.' */
  152.                     if(! memchr(data_buffer, '.', src_count)) {
  153.                         error_flag = TRUE;
  154.                         break;
  155.                         }
  156.                     }
  157.                 /* If extention started. */
  158.                 if(ext_flag == TRUE) {
  159.                     ext_count ++;
  160.                     /* If extention has more than 3 characters + the '.' */
  161.                     if(ext_count > 4) {
  162.                         error_flag = TRUE;
  163.                         break;
  164.                         }
  165.                     }
  166.                 filename[dest_count] = data_buffer[src_count];
  167.                 dest_count ++;
  168.                 }  /* ==L1== */
  169.             if(error_flag) {
  170.                 w4display("", mes[ME+24], (char *) 0);
  171.                 return(-1);
  172.                 }
  173.             for(dest_count = 0; dest_count <= 11; dest_count ++)
  174.                 filename[dest_count] = gtoupper(filename[dest_count]);
  175.             memcpy(data_buffer, filename, 12);
  176.             return(key_val);
  177.             }
  178.  
  179.     else if(key_val == BACK_SPACE || key_val == INS || key_val == DEL ||\
  180.          key_val == HOME || key_val == END || key_val == '.' || key_val == '_' ||\
  181.          key_val == ESC || key_val == LEFT || key_val == RIGHT || key_val == F10 ||\
  182.          key_val == F3 || key_val == F1 ||\
  183.         (key_val >= 48 && key_val <= 57) || \
  184.         (key_val >= 65 && key_val <= 90) || \
  185.         (key_val >= 97 && key_val <= 122)) {
  186.         if(key_val == F3 && browser_flag) {
  187.             cd_doc();
  188.             search_files( data_buffer );
  189.             cd_iep();
  190.             key_val = HOME;
  191.             }
  192.         return(key_val);
  193.         }
  194.     else {
  195.         g4bell_set(1);
  196.         g4bell();
  197.         g4bell_set(0);
  198.         return(-1);
  199.         }
  200.     }
  201.  
  202. /*****************************************************************************/
  203. /* Function: int gper_comp(GET *get_ptr, char *data_buffer, int no_need)          */
  204. /*****************************************************************************/
  205. int gper_comp(get_ptr, data_buffer, no_need)
  206. GET *get_ptr;
  207. char *data_buffer;
  208. int no_need;
  209. {
  210.     int    ret_val;
  211.  
  212.     /* Disable compiler's warrning ("Parameter 'xxx' is never used ..."). */
  213.     if(no_need);
  214.     if(get_ptr);
  215.  
  216.     for(;;) { /* ==L1== */
  217.         ret_val = g4char();
  218.         switch(ret_val) {
  219.             case 'ö':
  220.             case '¡':
  221.             case 'F':
  222.             case 'f':
  223.                 memcpy(data_buffer, "ö", 1);
  224.                 return(TAB);
  225.             case 'N':
  226.             case 'n':
  227.             case 'î':
  228.             case 'ñ':
  229.                 memcpy(data_buffer, "î", 1);
  230.                 return(TAB);
  231.             case ' ':
  232.                 memcpy(data_buffer, " ", 1);
  233.                 return(TAB);
  234.             case F1:
  235.             case F2:
  236.             case F4:
  237.             case F5:
  238.             case F6:
  239.             case F7:
  240.             case F8:
  241.             case F9:
  242.             case F10:
  243.             case UP:
  244.             case DOWN:
  245.             case PGUP:
  246.             case PGDN:
  247.             case TAB:
  248.             case SHIFT_TAB:
  249.             case RETURN:
  250.             case ESC:
  251.             case DEL:
  252.                 return(ret_val);
  253.             }
  254.         } /* ==L1== */
  255.     }
  256.  
  257. /*****************************************************************************/
  258. /* Function: int gcl_status(GET *get_ptr, char *data_buffer, int no_need)          */
  259. /*****************************************************************************/
  260. int gcl_status(get_ptr, data_buffer, no_need)
  261. GET *get_ptr;
  262. char *data_buffer;
  263. int no_need;
  264. {
  265.     int    ret_val;
  266.  
  267.     /* Disable compiler's warrning ("Parameter 'xxx' is never used ..."). */
  268.     if(no_need);
  269.     if(get_ptr);
  270.  
  271.     for(;;) { /* ==L1== */
  272.         ret_val = g4char();
  273.         switch(ret_val) {
  274.             case '+':
  275.                 memcpy(data_buffer, "+", 1);
  276.                 return(TAB);
  277.             case '-':
  278.                 memcpy(data_buffer, "-", 1);
  279.                 return(TAB);
  280.             case '*':
  281.                 memcpy(data_buffer, "*", 1);
  282.                 return(TAB);
  283.             case ' ':
  284.                 memcpy(data_buffer, " ", 1);
  285.                 return(TAB);
  286.             case F1:
  287.             case F2:
  288.             case F4:
  289.             case F5:
  290.             case F6:
  291.             case F7:
  292.             case F8:
  293.             case F9:
  294.             case F10:
  295.             case UP:
  296.             case DOWN:
  297.             case PGUP:
  298.             case PGDN:
  299.             case TAB:
  300.             case SHIFT_TAB:
  301.             case RETURN:
  302.             case ESC:
  303.             case DEL:
  304.                 return(ret_val);
  305.             }
  306.         } /* ==L1== */
  307.     }
  308.  
  309.  
  310. /*****************************************************************************/
  311. /* Function: int gsex(GET *get_ptr, char *data_buffer, int no_need)          */
  312. /*****************************************************************************/
  313. int gsex(get_ptr, data_buffer, no_need)
  314. GET *get_ptr;
  315. char *data_buffer;
  316. int no_need;
  317. {
  318.     int    ret_val;
  319.  
  320.     /* Disable compiler's warrning ("Parameter 'xxx' is never used ..."). */
  321.     if(no_need);
  322.     if(get_ptr);
  323.  
  324.     for(;;) { /* ==L1== */
  325.         ret_val = g4char();
  326.         switch(ret_val) {
  327.             case 'A':
  328.             case 'a':
  329.             case 'Ç':
  330.             case 'ÿ':
  331.                 memcpy(data_buffer, "Ç", 1);
  332.                 return(TAB);
  333.             case 'U':
  334.             case 'u':
  335.             case 'ç':
  336.             case 'ƒ':
  337.                 memcpy(data_buffer, "ç", 1);
  338.                 return(TAB);
  339.             case ' ':
  340.                 memcpy(data_buffer, " ", 1);
  341.                 return(TAB);
  342.             case F1:
  343.             case F2:
  344.             case F3:
  345.             case F4:
  346.             case F5:
  347.             case F6:
  348.             case F7:
  349.             case F8:
  350.             case F9:
  351.             case F10:
  352.             case UP:
  353.             case DOWN:
  354.             case PGUP:
  355.             case PGDN:
  356.             case TAB:
  357.             case SHIFT_TAB:
  358.             case RETURN:
  359.             case ESC:
  360.             case DEL:
  361.                 return(ret_val);
  362.             }
  363.         } /* ==L1== */
  364.     }
  365.  
  366.  
  367. /*****************************************************************************/
  368. /* Function: int gfb_help(GET *get_ptr, char *data_buffer, int file_ref)     */
  369. /* Description: This function is not called directly. It is used as a        */
  370. /*              parameter to g4call(): g4call( gfb_menu, file_ref);          */
  371. /*              Actually gfb_help() calls gfb() if F3 is pressed.            */
  372. /* Parameters: GET *get_ptr        -> The get structure of the field.        */
  373. /*             char *data_buffer   -> The currently entered information.     */
  374. /*             int file_ref        -> The file reference number used for the */
  375. /*                                    menu entries.                          */
  376. /* Returns: A value significant for g4call routine.                          */
  377. /*          >0  input data(as if it was read from the keyboard).             */
  378. /*          =0  Read the next keyboard character as normal input data.       */
  379. /*          -1  Call this call routine again without getting any keyboard    */
  380. /*              data from the user.                                          */
  381. /* Uses: gfb().                                                              */
  382. /*****************************************************************************/
  383. gfb_help( get_ptr, data_buffer, file_ref )
  384. GET *get_ptr;
  385. char *data_buffer;
  386. int file_ref;
  387. {
  388.     D4DATA *dbfile;                /* Database file used for the menu. */
  389.     int code_len;                    /* Length of frequently used fields. */
  390.     int desc_len;
  391.     int key_val ;                    /* Key Pressed. */
  392.     int count;                        /* Counter. */
  393.     int already_openf;            /* Already open file flag. */
  394.     char hs[150];
  395.     char ss[150];
  396.  
  397.     static changed_flag = FALSE;
  398.  
  399.  
  400.     key_val =  g4char() ;
  401.  
  402.     /* If F3 is pressed call gfb(). If gfb() returns Esc call the routine again.*/
  403.     if ( key_val == GETFROMBROWSE_KEY ) {
  404.         /* Get file pointer and set some frequently used variables. */
  405.         dbfile = d4data( &set, dbf[file_ref]);
  406.         if( dbfile == 0 ) {
  407.             dbfile = d4open( &set, files(file_ref));
  408.             already_openf = FALSE; /* I shall close th file later. */
  409.             }
  410.         else
  411.             already_openf = TRUE;
  412.         d4tag_select(dbfile , d4tag_prev(dbfile, d4tag(dbfile,"DESC_T")));
  413.  
  414.         strcpy(hs, helpline_save);
  415.         strcpy(ss, statusline_save);
  416.         helpline(mes[MH+67]);
  417.         statline(mes[MS+33]);
  418.         key_val =  gfb( get_ptr, data_buffer, file_ref ) ;
  419.         helpline(hs);
  420.         statline(ss);
  421.  
  422.         d4tag_select(dbfile , d4tag_prev(dbfile, d4tag(dbfile,"DESC_T")));
  423.         if( already_openf == 0 ) {
  424.             d4close(dbfile);
  425.             }
  426.         if ( key_val == ESC )  key_val = -1 ;
  427.         return( key_val ) ;
  428.         }
  429.  
  430.     /* If a key, which causes g4read to change field, is pressed, if the value */
  431.     /* entered is found in the data base print the description. Otherwise ring */
  432.     /* the bell and stay to the field.                                         */
  433.     else if(key_val == RETURN || key_val == TAB || key_val == DOWN || key_val == UP \
  434.                 || key_val == SHIFT_TAB) {
  435.         /* If the data_buffer is blank...            */
  436.         code_len = get_ptr->width_data;
  437.         if(!memcmp(data_buffer, space(code_len),code_len)) {
  438.             if(! changed_flag)
  439.                 return(key_val);
  440.             }
  441.         changed_flag = FALSE;
  442.         /* Get file pointer and set some frequently used variables. */
  443.         dbfile = d4data( &set, dbf[file_ref]);
  444.         if( dbfile == 0 ) {
  445.             dbfile = d4open( &set, files(file_ref));
  446.             already_openf = FALSE; /* I shall close th file later. */
  447.             }
  448.         else
  449.             already_openf = TRUE;
  450.         d4tag_select(dbfile , d4tag_prev(dbfile, d4tag(dbfile,"DESC_T")));
  451.  
  452.         code_len = get_ptr->width_data;
  453.         desc_len = f4len(d4field(dbfile, "DESC"));
  454.  
  455.         if(!memcmp(data_buffer, space(code_len),code_len)) {
  456.             w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  457.                 space(desc_len), desc_len, custom[MAIN_I]);
  458.             if(already_openf == FALSE)
  459.                 d4close(dbfile);
  460.             return(key_val);
  461.             }
  462.  
  463.         for(count=0; count<= code_len -1; count ++)
  464.             data_buffer[count] = gtoupper(data_buffer[count]);
  465.  
  466.         if( d4seek(dbfile, data_buffer) != 0 ) {
  467.             d4unlock_index(dbfile);
  468.             w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  469.                 space(desc_len), desc_len, custom[MAIN_I]);
  470.             w4display("",mes[ME+4],mes[MH+16], (char *) 0);
  471.             if(already_openf == FALSE)
  472.                 d4close(dbfile);
  473.             return(HOME);
  474.             }
  475.         d4unlock_index(dbfile);
  476.         w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  477.                 f4str(d4field_j(dbfile, 2)), desc_len, custom[MAIN_I]);
  478.         if(already_openf == FALSE)
  479.             d4close(dbfile);
  480.         return(key_val);
  481.         }
  482.     else {
  483.         changed_flag = TRUE;
  484.         return(key_val);
  485.         }
  486.     }
  487.  
  488. /*****************************************************************************/
  489. /* Function: int gfb(GET *get_ptr, char *data_buffer, int file_ref)          */
  490. /* Description: This function is not called directly. It is used as a        */
  491. /*              parameter to g4call(): g4call( gfb, file_ref);               */
  492. /* Parameters: GET *get_ptr        -> The get structure of the field.        */
  493. /*             char *data_buffer   -> The currently entered information.     */
  494. /*             int file_ref        -> The file reference number used for the */
  495. /*                                    menu entries.                          */
  496. /* Returns: A value significant for g4call routine.                          */
  497. /*          >0  input data(as if it was read from the keyboard).             */
  498. /*          =0  Read the next keyboard character as normal input data.       */
  499. /*          -1  Call this call routine again without getting any keyboard    */
  500. /*              data from the user.                                          */
  501. /* Uses: Nothing.                                                            */
  502. /*****************************************************************************/
  503. int gfb(get_ptr, data_buffer, file_ref)
  504. GET *get_ptr;
  505. char *data_buffer;
  506. int file_ref;
  507. {
  508.     D4DATA *dbfile;                /* Database file used for the menu. */
  509.     int browse_wref;            /* Windows References. */
  510.     int append_wref;
  511.     int edit_wref;
  512.     int code_len;                    /* Length of frequently used fields. */
  513.     int desc_len;
  514.     int win_s, win_e;                /* Browse y and y1 coordinates. */
  515.     int maxrow;                        /* maxrow -1 = Maximum number of items in menu. */
  516.     int cur_row;
  517.     int key_val;                    /* Key pressed. */
  518.     int count;
  519.     int update_flag;
  520.     int skp;
  521.     int seek_val;
  522.     int records_found;
  523.     long cur_record;
  524.     int skp_flag;
  525.  
  526.     /* Used in append and edit. */
  527.     F4FIELD *f_code;                /* Code and Description fields ... */
  528.     F4FIELD *f_desc;
  529.  
  530.     char *code;                        /* Code and Description Entry areas. Memory */
  531.     char *desc;                        /* is allocated before use.                 */
  532.     char *sk;                    /* Temporary search key. */
  533.  
  534.     update_flag = FALSE;
  535.     maxrow = 5;
  536.     skp = 0;
  537.     skp_flag = 0;
  538.  
  539.     /* Get file pointer and set some frequently used variables. */
  540.     dbfile = d4data( &set, dbf[file_ref]);
  541.  
  542.     code_len = get_ptr->width_data;
  543.     desc_len = f4len(d4field(dbfile, "DESC"));
  544.     win_s = get_ptr->col + code_len +2;
  545.     win_e = win_s + desc_len + code_len + 2;
  546.  
  547.     records_found = TRUE;
  548.  
  549.  
  550.     /* Allocate space for CODE, DESC entry areas and TMP_KEY . */
  551.     if( (code = calloc(code_len + 1, sizeof(char))) == NULL) {
  552.         w4display(mes[MT], mes[ME+1], (char *) 0);
  553.         w4exit(1);
  554.         }
  555.     if( (desc = calloc(desc_len, sizeof(char))) == NULL) {
  556.         w4display(mes[MT], mes[ME+1], (char *) 0);
  557.         w4exit(1);
  558.         }
  559.     if( (sk = calloc(desc_len + 1, sizeof(char))) == NULL) {
  560.         w4display(mes[MT], mes[ME+1], (char *) 0);
  561.         w4exit(1);
  562.         }
  563.     memcpy(code, space(code_len), code_len);
  564.     memcpy(desc, space(desc_len), desc_len);
  565.     memcpy(sk, space(desc_len), desc_len);
  566.  
  567.     code[code_len] = '\0';                    /* Null terminate for seek operations. */
  568.  
  569.     /* Select Code TAG (the previous tag of DESK_T) and try to find the  */
  570.     /* CODE in the field in order to set the database pointer correctly. */
  571.     d4tag_select(dbfile , d4tag_prev(dbfile, d4tag(dbfile,"DESC_T")));
  572.     for(count=0; count<= code_len -1; count ++)
  573.         data_buffer[count] = gtoupper(data_buffer[count]);
  574.     if( d4seek(dbfile, data_buffer) != 0) {
  575.         d4unlock_index(dbfile);
  576.         /* If not in append mode ...  */
  577. /*
  578.         if( memcmp(data_buffer, space(code_len), code_len))
  579.             w4display("",mes[ME+4],mes[MH+16], (char *) 0);
  580. */
  581.         d4tag_select(dbfile , d4tag(dbfile,"DESC_T"));
  582.         if( d4top(dbfile)) {
  583.             records_found = FALSE;
  584.             }
  585.         else
  586.             records_found = TRUE;
  587.  
  588.         d4unlock_index(dbfile);
  589.         }
  590.     d4unlock_index(dbfile);
  591.  
  592.     /* The records are ordered with Description TAG. */
  593.     d4tag_select(dbfile , d4tag(dbfile,"DESC_T"));
  594.  
  595.     /* Open the browse window.                             */
  596.     browse_wref = w4define(get_ptr->row + 1, win_s,\
  597.                         get_ptr->row + maxrow+3, win_e);
  598.     w4attribute(custom[BROWSER_N]);
  599.     w4border(SINGLE, custom[BROWSER_B]);
  600.     w4title(0, 1, mes[MT+16], custom[BROWSER_B]);
  601.     w4popup();
  602.     w4memory();
  603.     w4activate( browse_wref );
  604.     w4cursor(-1, -1);
  605.  
  606.     gfb_fillwindow(dbfile, desc_len, code_len, maxrow, desc_len);
  607.     cur_row = 0;
  608.  
  609.     for (;;) {                    /* ==L1== */
  610.         key_val = g4char();
  611.  
  612.         if ( key_val == F1 ) {
  613.             help("GET_FROM_BROWSE");
  614.             continue ;
  615.             }
  616.         if ( key_val == F8  && records_found) {
  617.             if(warning(mes[MH+56])) {
  618.                 w4select(browse_wref);
  619.                 d4delete(dbfile);
  620.                 d4flush_all(dbfile);
  621.                 d4unlock_all_data(dbfile);
  622.                 d4unlock_index(dbfile);
  623.                 if (d4top(dbfile)) {
  624.                     records_found = FALSE;
  625.                     }
  626.                 else
  627.                     records_found = TRUE;
  628.  
  629.                 d4unlock_index(dbfile);
  630.                 gfb_fillwindow(dbfile, desc_len, code_len, maxrow, desc_len);
  631.                 cur_row = 0;
  632.                 }
  633.             w4select(browse_wref);
  634.             }
  635.         /* Edit Record to file. */
  636.         if(key_val == F2 && records_found) {
  637.             edit_wref = w4define(get_ptr->row +2, win_s +1,\
  638.                             get_ptr->row + 7, win_e +12);
  639.             w4border(DOUBLE, custom[MAIN_N]);
  640.             w4title(0, 1, mes[MT+15], custom[MAIN_N]);
  641.             w4popup();
  642.             w4memory();
  643.             w4activate( edit_wref );
  644.             w4attribute(custom[MAIN_N]);
  645.             w4clear(0);
  646.             w4(1, 1, "ëα¢áíµ¬  :");
  647.             w4(2, 1, "Å£¿áÜ¿ÿ¡π:");
  648.             g4delimiter("[]");
  649.             g4attribute(custom[MAIN_I]);
  650.             w4num_att(1, 12, f4str(d4field_j(dbfile,1)), code_len, custom[MAIN_I]);
  651.             memcpy(desc,f4str(d4field_j(dbfile,2)), desc_len);
  652.             g4(2, 12, desc); g4width(desc_len,desc_len);
  653.             if(g4read() != ESC) {
  654.                 for(count=0; count<= desc_len -1; count ++)
  655.                     desc[count] = gtoupper(desc[count]);
  656.                 f_desc = d4field_j(dbfile, 2); /* Get field pointer. */
  657.                 f4assign_n(f_desc, desc, desc_len);
  658.                 d4flush_all(dbfile);
  659.                 d4unlock_all_data(dbfile);
  660.                 d4unlock_index(dbfile);
  661.                 update_flag = TRUE;
  662.                 }
  663.             w4deactivate(edit_wref);
  664.             w4close(edit_wref);
  665.             if(update_flag) {
  666.                 update_flag = FALSE;
  667.                 d4seek(dbfile, desc);   /* Seek new description. */
  668.                 gfb_fillwindow(dbfile, desc_len, code_len, maxrow, desc_len);
  669.                 cur_row = 0;
  670.                 }
  671.             }
  672.  
  673.         /* Append Record to file. */
  674.         if(key_val == F5) {
  675.             append_wref = w4define(get_ptr->row +2, win_s +1,\
  676.                                 get_ptr->row + 7, win_e +12);
  677.             w4border(DOUBLE, custom[MAIN_N]);
  678.             w4title(0, 1, mes[MT+14], custom[MAIN_N]);
  679.             w4popup();
  680.             w4memory();
  681.             w4activate( append_wref );
  682.             w4attribute(custom[MAIN_N]);
  683.             w4clear(0);
  684.             w4(1, 1, "ëα¢áíµ¬  :");
  685.             w4(2, 1, "Å£¿áÜ¿ÿ¡π:");
  686.             g4delimiter("[]");
  687.             g4attribute(custom[MAIN_I]);
  688.             memcpy(code, space(code_len), code_len);
  689.             memcpy(desc, space(desc_len), desc_len);
  690.             for(;;) { /* ==L2== */
  691.                 g4(1, 12, code); g4width(code_len,code_len);
  692.                 g4(2, 12, desc); g4width(desc_len,desc_len);
  693.                 if(g4read() != ESC) {
  694.                     for(count=0; count<= desc_len -1; count ++)
  695.                         desc[count] = gtoupper(desc[count]);
  696.                     for(count=0; count<= code_len -1; count ++)
  697.                         code[count] = gtoupper(code[count]);
  698.                     d4tag_select(dbfile , d4tag_prev(dbfile, d4tag(dbfile,"DESC_T")));
  699.                     if(! memcmp(code, space(code_len), code_len)) {
  700.                         w4display("",mes[ME+7],mes[MH+16], (char *) 0);
  701.                         continue;
  702.                         }
  703.                     if(d4seek(dbfile, code) == 0) {   /* If code exists. */
  704.                         d4unlock_index(dbfile);
  705.                         w4display("",mes[ME+5],mes[MH+16], (char *) 0);
  706.                         continue;
  707.                         }
  708.                     d4unlock_index(dbfile);
  709.                     d4tag_select(dbfile , d4tag(dbfile,"DESC_T"));
  710.                     d4append_start(dbfile, 0);
  711.                     d4blank(dbfile);
  712.                     f_code = d4field_j(dbfile, 1);
  713.                     f_desc = d4field_j(dbfile, 2);
  714.                     f4assign_n(f_code, code, code_len);
  715.                     f4assign_n(f_desc, desc, desc_len);
  716.                     d4append(dbfile);
  717.                     d4flush_all(dbfile);
  718.                     d4unlock_all_data(dbfile);
  719.                     d4unlock_index(dbfile);
  720.                     update_flag = TRUE;
  721.                     }
  722.                 break;
  723.                 } /* ==L2== */
  724.             w4deactivate(append_wref);
  725.             w4close(append_wref);
  726.             if(update_flag) {
  727.                 update_flag = FALSE;
  728.                 d4seek(dbfile, desc);   /* Seek new description. */
  729.                 records_found = TRUE;
  730.                 gfb_fillwindow(dbfile, desc_len, code_len, maxrow, desc_len);
  731.                 cur_row = 0;
  732.                 }
  733.             }
  734.         /* ==If Alphanumeric== */
  735.         if( ((key_val == BACK_SPACE) || \
  736.             (key_val >= 32 && key_val <= 175) || \
  737.             (key_val >= 224 && key_val <=233)) && records_found) {
  738.  
  739.             if(key_val == BACK_SPACE) {
  740.                 if(skp == 0) {
  741.                     g4bell_set(1);
  742.                     g4bell();
  743.                     g4bell_set(0);
  744.                     skp_flag = 1;
  745.                     }
  746.                 else if(skp > 1) {
  747.                     skp --;
  748.                     skp --;
  749.                     }
  750.                 else if(skp == 1) {
  751.                     skp = 0;
  752.                     skp_flag = 1;
  753.                     d4top(dbfile);
  754.                     gfb_fillwindow(dbfile, desc_len, code_len, maxrow, desc_len);
  755.                     cur_row = 0;
  756.                     }
  757.                 }
  758.             else if(skp == desc_len){
  759.                 g4bell_set(1);
  760.                 g4bell();
  761.                 g4bell_set(0);
  762.                 skp --;
  763.                 }
  764.             else {
  765.                 sk[skp] = key_val;
  766.                 }
  767.  
  768.             if( !skp_flag) { /* ==If normal mode== */
  769.                 sk[skp + 1] = '\0';
  770.                 for(count=0 ; count <= skp; count ++)
  771.                     sk[count] = gtoupper(sk[count]);
  772.                 cur_record = d4recno(dbfile);
  773.                 seek_val = d4seek(dbfile, sk);
  774.                 d4unlock_index(dbfile);
  775.  
  776.                 /* ==If found or just after it.==*/
  777.                 if(seek_val == r4after || seek_val == 0 || seek_val == r4eof) {
  778.                     /* If NOT really found... */
  779.                     if( memcmp(sk, f4str( d4field_j(dbfile, 2)), skp + 1)) {
  780.                         g4bell_set(1);
  781.                         g4bell();
  782.                         g4bell_set(0);
  783.                         seek_val = d4go(dbfile, cur_record);
  784.                         if( seek_val != 0 ) { /* If the record no longer exists. */
  785.                             d4top(dbfile);
  786.                             gfb_fillwindow(dbfile, desc_len, code_len, maxrow, desc_len);
  787.                             cur_row = 0;
  788.                             } /* If the record no longer exists. */
  789.                         } /* If NOT really found. */
  790.                     else { /* If really found... */
  791.                         /* Fill the window with records. (normal attribute).                     */
  792.                         gfb_fillwindow(dbfile, desc_len, code_len, maxrow, skp + 1);
  793.                         cur_row = 0;
  794.                         skp ++;
  795.                         } /* If really found... */
  796.                     } /* ==If found or just after it.==*/
  797.                 } /* If normal mode */
  798.             skp_flag = 0;
  799.             } /* ==If Alphanumeric== */
  800.  
  801.  
  802.         if(key_val == RETURN && records_found) {
  803.             free(code);
  804.             free(desc);
  805.             free(sk);
  806.             w4deactivate(browse_wref);
  807.             w4close(browse_wref);
  808.             /* Fill the buffer with the correct code and print the description */
  809.             /* Next to the field.                                              */
  810.             d4tag_select(dbfile , d4tag_prev(dbfile, d4tag(dbfile,"DESC_T")));
  811.             memcpy(data_buffer, f4str( d4field_j(dbfile, 1)), code_len);
  812.             d4seek(dbfile, data_buffer);
  813.             d4unlock_index(dbfile);
  814.             w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  815.                             f4str(d4field_j(dbfile, 2)), desc_len, custom[MAIN_I]);
  816.             return(TAB);
  817.             }
  818.         if(key_val == ESC) {
  819.             break;
  820.             }
  821.         if(key_val == DOWN && records_found) {
  822.             skp = 0;
  823.             /* Display with normal attribute the current row. */
  824.             w4num_att(cur_row, 0, f4str( d4field_j(dbfile, 2)), desc_len, custom[BROWSER_N]);
  825.             w4num_att(cur_row, desc_len, "│", 1, custom[BROWSER_N]);
  826.             w4num_att(cur_row, desc_len +1, f4str( d4field_j(dbfile ,1)), code_len, custom[BROWSER_N]);
  827.  
  828.             if (d4skip(dbfile, 1) == r4eof) {
  829.                 d4bottom(dbfile);
  830.                 cur_row --;
  831.                 }
  832.             d4unlock_index(dbfile);
  833.             if (cur_row == maxrow) {
  834.                 cur_row --;
  835.                 w4scroll(1);
  836.                 }
  837.             cur_row ++;
  838.             /* Display the bar */
  839.             w4num_att(cur_row, 0, f4str( d4field_j(dbfile, 2)), desc_len, custom[BROWSER_S]);
  840.             w4num_att(cur_row, desc_len, "│", 1, custom[BROWSER_S]);
  841.             w4num_att(cur_row, desc_len +1, f4str( d4field_j(dbfile ,1)), code_len, custom[BROWSER_S]);
  842.             }
  843.  
  844.         else if (key_val == UP && records_found) {
  845.             skp = 0;
  846.             /* Display with normal attribute the current row. */
  847.             w4num_att(cur_row, 0, f4str( d4field_j(dbfile, 2)), desc_len, custom[BROWSER_N]);
  848.             w4num_att(cur_row, desc_len, "│", 1, custom[BROWSER_N]);
  849.             w4num_att(cur_row, desc_len +1, f4str( d4field_j(dbfile ,1)), code_len, custom[BROWSER_N]);
  850.  
  851.             if (d4skip(dbfile, -1)) {
  852.                 d4top(dbfile);
  853.                 cur_row ++;
  854.                 }
  855.             d4unlock_index(dbfile);
  856.  
  857.             if (cur_row == 0) {
  858.                 cur_row ++;
  859.                 w4scroll(-1);
  860.                 }
  861.             cur_row --;
  862.             w4num_att(cur_row, 0, f4str( d4field_j(dbfile, 2)), desc_len, custom[BROWSER_S]);
  863.             w4num_att(cur_row, desc_len, "│", 1, custom[BROWSER_S]);
  864.             w4num_att(cur_row, desc_len +1, f4str( d4field_j(dbfile ,1)), code_len, custom[BROWSER_S]);
  865.             }
  866.         }    /* ==L1== */
  867.  
  868.     /* Close the window and send to g4read() the key to execute. */
  869.     free(code);
  870.     free(desc);
  871.     free(sk);
  872.     w4deactivate(browse_wref);
  873.     w4close(browse_wref);
  874.     return(HOME);
  875.     }
  876.  
  877. /*******************************************************************/
  878. static gfb_fillwindow(dbfile, desc_len, code_len, maxrow, to_skp)
  879. D4DATA *dbfile;
  880. int    desc_len, code_len, to_skp;
  881. int   maxrow;
  882. {
  883.     int count;
  884.     int cur_row;
  885.  
  886.     w4clear(0);
  887.     for(cur_row = 0; cur_row <= maxrow ; cur_row ++) {
  888.         w4num_att(cur_row, 0, f4str( d4field_j(dbfile, 2)), desc_len, custom[BROWSER_N]);
  889.         w4num_att(cur_row, desc_len, "│", 1, custom[BROWSER_N]);
  890.         w4num_att(cur_row, desc_len +1, f4str( d4field_j(dbfile ,1)), code_len, custom[BROWSER_N]);
  891.         if( d4skip(dbfile, 1))
  892.             break;
  893.         d4unlock_index(dbfile);
  894.         }
  895.     d4unlock_index(dbfile);
  896.     d4unlock_all_data(dbfile);
  897.     if(cur_row > maxrow)
  898.         cur_row = maxrow;
  899.     /* Skip to the first record found. */
  900.     for(count = 0 ; count <= cur_row; count ++) {
  901.         d4skip(dbfile, -1);
  902.         d4unlock_index(dbfile);
  903.         }
  904.     cur_row = 0;
  905.     /* Display the bar */
  906.     w4num_att(cur_row, 0, f4str( d4field_j(dbfile, 2)), to_skp, custom[BROWSER_S]);
  907.     w4num_att(cur_row, desc_len, "│", 1, custom[BROWSER_S]);
  908.     w4num_att(cur_row, desc_len +1, f4str( d4field_j(dbfile ,1)), code_len, custom[BROWSER_S]);
  909.     }
  910.  
  911. /*****************************************************************************/
  912. /* Function: int gfmaster_help(GET *get_ptr, char *data_buffer, int file_ref)     */
  913. /* Description: This function is not called directly. It is used as a        */
  914. /*              parameter to g4call(): g4call( gfb_menu, file_ref);          */
  915. /*              Actually gfb_help() calls gfb() if F3 is pressed.            */
  916. /* Parameters: GET *get_ptr        -> The get structure of the field.        */
  917. /*             char *data_buffer   -> The currently entered information.     */
  918. /*             int file_ref        -> The file reference number used for the */
  919. /*                                    menu entries.                          */
  920. /* Returns: A value significant for g4call routine.                          */
  921. /*          >0  input data(as if it was read from the keyboard).             */
  922. /*          =0  Read the next keyboard character as normal input data.       */
  923. /*          -1  Call this call routine again without getting any keyboard    */
  924. /*              data from the user.                                          */
  925. /* Uses: gfb().                                                              */
  926. /*****************************************************************************/
  927. gfmaster_help( get_ptr, data_buffer, file_ref )
  928. GET *get_ptr;
  929. char *data_buffer;
  930. int file_ref;
  931. {
  932.     D4DATA *dbfile;                /* Database file used for the menu. */
  933.     int code_len;                    /* Length of frequently used fields. */
  934.     int surn_len;
  935.     int key_val ;                    /* Key Pressed. */
  936.     int count;                        /* Counter. */
  937.     int already_openf;            /* Already open file flag. */
  938.     char hs[150];
  939.     char ss[150];
  940.  
  941.     static changed_flag = FALSE;
  942.  
  943.     code_len  = get_ptr->width_data;
  944.  
  945.     key_val =  g4char() ;
  946.  
  947.     /* If F3 is pressed call gfb(). If gfb() returns Esc call the routine again.*/
  948.     if ( key_val == GETFROMBROWSE_KEY ) {
  949.         dbfile = d4data( &set, dbf[file_ref]);
  950.         if( dbfile == 0 ) {
  951.             dbfile = d4open( &set, files(file_ref));
  952.             already_openf = FALSE; /* I shall close the file later. */
  953.             }
  954.         else
  955.             already_openf = TRUE;
  956.         d4tag_select(dbfile , d4tag(dbfile,"CODE_T"));
  957.  
  958.         strcpy(hs, helpline_save);
  959.         strcpy(ss, statusline_save);
  960.         helpline(mes[MH+67]);
  961.         statline(mes[MS+34]);
  962.         key_val =  gfmaster( get_ptr, data_buffer, file_ref ) ;
  963.         helpline(hs);
  964.         statline(ss);
  965.         d4tag_select(dbfile , d4tag(dbfile,"CODE_T"));
  966.         if( already_openf == FALSE ) {
  967.             d4close(dbfile);
  968.             }
  969.         if ( key_val == ESC )  key_val = -1 ;
  970.         return( key_val ) ;
  971.         }
  972.  
  973.     /* If a key, which causes g4read to change field, is pressed, if the value */
  974.     /* entered is found in the data base print the description. Otherwise ring */
  975.     /* the bell and stay to the field.                                         */
  976.     else if(key_val == RETURN || key_val == TAB || key_val == DOWN || key_val == UP \
  977.                 || key_val == SHIFT_TAB) {
  978.         if(!memcmp(data_buffer, space(code_len),code_len)) {
  979.             if(! changed_flag)
  980.                 return(key_val);
  981.             }
  982.  
  983.         changed_flag = FALSE;
  984.         dbfile = d4data( &set, dbf[file_ref]);
  985.         if( dbfile == 0 ) {
  986.             dbfile = d4open( &set, files(file_ref));
  987.             already_openf = FALSE; /* I shall close the file later. */
  988.             }
  989.         else
  990.             already_openf = TRUE;
  991.  
  992.         d4tag_select(dbfile , d4tag(dbfile,"CODE_T"));
  993.  
  994.         surn_len  = f4len(d4field(dbfile, "SURNAME"));
  995.  
  996.         /* If the data_buffer is blank...            */
  997.         if(!memcmp(data_buffer, space(code_len),code_len)) {
  998.             w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  999.                 space(surn_len), surn_len, custom[MAIN_I]);
  1000.             if(already_openf == FALSE)
  1001.                 d4close(dbfile);
  1002.             return(key_val);
  1003.             }
  1004.  
  1005.         /* Convert to uppercase.  */
  1006.         for(count=0; count<= code_len -1; count ++)
  1007.             data_buffer[count] = gtoupper(data_buffer[count]);
  1008.  
  1009.         /* If a code was entered. */
  1010.         zerofill(data_buffer+1, code_len-1);
  1011.         switch(data_buffer[0]) {
  1012.             case 'ü':
  1013.                 data_buffer[0] = 'B';
  1014.                 break;
  1015.             case 'ä':
  1016.                 data_buffer[0] = 'E';
  1017.                 break;
  1018.             case 'I':
  1019.                 data_buffer[0] = 'I';
  1020.                 break;
  1021.             case 'ì':
  1022.                 data_buffer[0] = 'J';
  1023.                 break;
  1024.             case 'ë':
  1025.                 data_buffer[0] = 'K';
  1026.                 break;
  1027.             case 'Ä':
  1028.                 data_buffer[0] = 'O';
  1029.                 break;
  1030.             case 'Æ':
  1031.                 data_buffer[0] = 'T';
  1032.                 break;
  1033.             case 'à':
  1034.                 data_buffer[0] = 'Z';
  1035.                 break;
  1036.             }
  1037.         w4num_att(get_ptr->row, get_ptr->col, data_buffer,\
  1038.                      code_len, custom[MAIN_I]);
  1039.  
  1040.         /* Get file pointer and set some frequently used variables. */
  1041.  
  1042.         /* If the code was not found. */
  1043.         if( d4seek(dbfile, data_buffer) != 0 ) {
  1044.             d4unlock_index(dbfile);
  1045.             w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  1046.                 space(surn_len), surn_len, custom[MAIN_I]);
  1047.             w4display("",mes[ME+4],mes[MH+16], (char *) 0);
  1048.             memcpy(data_buffer, space(code_len),code_len);
  1049.             if(already_openf == FALSE)
  1050.                 d4close(dbfile);
  1051.             return(HOME);
  1052.             }
  1053.         d4unlock_index(dbfile);
  1054.         w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  1055.                 f4str(d4field(dbfile, "SURNAME")), surn_len, custom[MAIN_I]);
  1056.         if(already_openf == FALSE)
  1057.             d4close(dbfile);
  1058.         return(key_val);
  1059.         }
  1060.     else {
  1061.         changed_flag = TRUE;
  1062.         return(key_val);
  1063.         }
  1064.     }
  1065.  
  1066. /*****************************************************************************/
  1067. /* Function: int gfmaster(GET *get_ptr, char *data_buffer, int file_ref)          */
  1068. /* Description: This function is not called directly. It is used as a        */
  1069. /*              parameter to g4call(): g4call( gfb, file_ref);               */
  1070. /* Parameters: GET *get_ptr        -> The get structure of the field.        */
  1071. /*             char *data_buffer   -> The currently entered information.     */
  1072. /*             int file_ref        -> The file reference number used for the */
  1073. /*                                    menu entries.                          */
  1074. /* Returns: A value significant for g4call routine.                          */
  1075. /*          >0  input data(as if it was read from the keyboard).             */
  1076. /*          =0  Read the next keyboard character as normal input data.       */
  1077. /*          -1  Call this call routine again without getting any keyboard    */
  1078. /*              data from the user.                                          */
  1079. /* Uses: Nothing.                                                            */
  1080. /*****************************************************************************/
  1081. int gfmaster(get_ptr, data_buffer, file_ref)
  1082. GET *get_ptr;
  1083. char *data_buffer;
  1084. int file_ref;
  1085. {
  1086.     D4DATA *dbfile;                /* Database file used for the menu. */
  1087.     int browse_wref;            /* Windows References. */
  1088.     int previous_wref;
  1089.     int code_len;                    /* Length of frequently used fields. */
  1090.     int surn_len;
  1091.     int surnk_len;
  1092.     int win_s, win_e;                /* Browse y and y1 coordinates. */
  1093.     int maxrow;                        /* maxrow -1 = Maximum number of items in menu. */
  1094.     int cur_row;
  1095.     int key_val;                    /* Key pressed. */
  1096.     int count;
  1097.     int records_found;
  1098.  
  1099.     int skp;
  1100.     int seek_val;
  1101.     long cur_record;
  1102.     int skp_flag;
  1103.     char *sk;
  1104.  
  1105.     maxrow = 5;
  1106.     skp = 0;
  1107.     skp_flag = 0;
  1108.  
  1109.  
  1110.     /* Set the file pointer and set some frequently used variables. */
  1111.     dbfile = d4data( &set, dbf[file_ref]);
  1112.  
  1113.     records_found = TRUE;
  1114.     code_len  = get_ptr->width_data;
  1115.     surn_len  = f4len(d4field(dbfile, "SURNAME"));
  1116.     surnk_len = f4len(d4field(dbfile, "SURNAMEKEY"));
  1117.  
  1118.     win_s = 78 - (code_len + surn_len + 2);
  1119.     win_e = 78;
  1120.  
  1121.     if((sk = calloc(surnk_len + 1, sizeof(char))) == NULL) {
  1122.         w4display(mes[MT], mes[ME+1], (char *) 0);
  1123.         w4exit(1);
  1124.         }
  1125.  
  1126.     memcpy(sk, space(surnk_len), surnk_len);
  1127.  
  1128.     /* Select Code TAG and try to find the CODE in the entry */
  1129.     /* field in order to set the database pointer correctly. */
  1130.     d4tag_select(dbfile , d4tag(dbfile,"CODE_T"));
  1131.     /* Convert to uppercase. */
  1132.     for(count=0; count<= code_len -1; count ++)
  1133.         data_buffer[count] = gtoupper(data_buffer[count]);
  1134.     /* If the code was not found. */
  1135.     if( d4seek(dbfile, data_buffer) != 0) {
  1136.         d4unlock_index(dbfile);
  1137.         d4tag_select(dbfile , d4tag(dbfile,"SURNAMEKEY_T"));
  1138.         if(d4top(dbfile)) {
  1139.             records_found = FALSE;
  1140.             }
  1141.         else
  1142.             records_found = TRUE;
  1143.         d4unlock_index(dbfile);
  1144.         }
  1145.     d4unlock_index(dbfile);
  1146.  
  1147.     /* The records are ordered with SURNAMEKEY_T TAG. */
  1148.     d4tag_select(dbfile , d4tag(dbfile,"SURNAMEKEY_T"));
  1149.  
  1150.     previous_wref = w4select(-1);
  1151.     /* Open the browse window.                             */
  1152.     browse_wref = w4define(get_ptr->row + 1, win_s,\
  1153.                         get_ptr->row + maxrow+3, win_e);
  1154.     w4attribute(custom[BROWSER_N]);
  1155.     w4border(SINGLE, custom[BROWSER_B]);
  1156.     w4title(0, 1, mes[MT+16], custom[BROWSER_B]);
  1157.     w4popup();
  1158.     w4memory();
  1159.     w4activate( browse_wref );
  1160.     w4cursor(-1, -1);
  1161.  
  1162.     gfmaster_fillwindow(dbfile, surn_len, code_len, maxrow, surn_len);
  1163.     cur_row = 0;
  1164.  
  1165.     for (;;) {                    /* ==L1== */
  1166.         key_val = g4char();
  1167.  
  1168.         if ( key_val == F1 ) {
  1169.             help("GET_FROM_MASTER");
  1170.             continue ;
  1171.             }
  1172.         /* ==If Alphanumeric== */
  1173.         if( ((key_val == BACK_SPACE) || \
  1174.             (key_val >= 32 && key_val <= 175) || \
  1175.             (key_val >= 224 && key_val <=233)) && records_found) {
  1176.  
  1177.             if(key_val == BACK_SPACE) {
  1178.                 if(skp == 0) {
  1179.                     g4bell_set(1);
  1180.                     g4bell();
  1181.                     g4bell_set(0);
  1182.                     skp_flag = 1;
  1183.                     }
  1184.                 else if(skp > 1) {
  1185.                     skp --;
  1186.                     skp --;
  1187.                     }
  1188.                 else if(skp == 1) {
  1189.                     skp = 0;
  1190.                     skp_flag = 1;
  1191.                     d4top(dbfile);
  1192.                     gfmaster_fillwindow(dbfile, surn_len, code_len, maxrow, surn_len);
  1193.                     cur_row = 0;
  1194.                     }
  1195.                 }
  1196.             else if(skp == surnk_len){
  1197.                 g4bell_set(1);
  1198.                 g4bell();
  1199.                 g4bell_set(0);
  1200.                 skp --;
  1201.                 }
  1202.             else {
  1203.                 sk[skp] = key_val;
  1204.                 }
  1205.  
  1206.             if( !skp_flag) { /* ==If normal mode== */
  1207.                 sk[skp + 1] = '\0';
  1208.                 for(count=0 ; count <= skp; count ++)
  1209.                     sk[count] = gtoupper(sk[count]);
  1210.                 cur_record = d4recno(dbfile);
  1211.                 seek_val = d4seek(dbfile, sk);
  1212.                 d4unlock_index(dbfile);
  1213.  
  1214.                 /* ==If found or just after it.==*/
  1215.                 if(seek_val == r4after || seek_val == 0 || seek_val == r4eof) {
  1216.                     /* If NOT really found... */
  1217.                     if( memcmp(sk, f4str( d4field(dbfile, "SURNAMEKEY")), skp + 1)) {
  1218.                         g4bell_set(1);
  1219.                         g4bell();
  1220.                         g4bell_set(0);
  1221.                         seek_val = d4go(dbfile, cur_record);
  1222.                         if( seek_val != 0 ) { /* If the record no longer exists. */
  1223.                             d4top(dbfile);
  1224.                             gfmaster_fillwindow(dbfile, surn_len, code_len, maxrow, surn_len);
  1225.                             cur_row = 0;
  1226.                             } /* If the record no longer exists. */
  1227.                         } /* If NOT really found. */
  1228.                     else { /* If really found... */
  1229.                         /* Fill the window with records. (normal attribute).                     */
  1230.                         gfmaster_fillwindow(dbfile, surn_len, code_len, maxrow, skp + 1);
  1231.                         cur_row = 0;
  1232.                         skp ++;
  1233.                         } /* If really found... */
  1234.                     } /* ==If found or just after it.==*/
  1235.                 } /* If normal mode */
  1236.             skp_flag = 0;
  1237.             } /* ==If Alphanumeric== */
  1238.  
  1239.         if(key_val == RETURN && records_found) {
  1240.             free(sk);
  1241.             w4deactivate(browse_wref);
  1242.             w4close(browse_wref);
  1243.             /* Fill the buffer with the correct code and print the surname     */
  1244.             /* Next to the field.                                              */
  1245.             w4select(previous_wref);
  1246.             d4tag_select(dbfile , d4tag(dbfile,"CODE_T"));
  1247.             memcpy(data_buffer, f4str( d4field_j(dbfile, 1)), code_len);
  1248.             d4seek(dbfile, data_buffer);
  1249.             d4unlock_index(dbfile);
  1250.             w4num_att(get_ptr->row, get_ptr->col + code_len + 2, \
  1251.             f4str(d4field(dbfile,"SURNAME")), surn_len, custom[MAIN_I]);
  1252.             return(TAB);
  1253.             }
  1254.         if(key_val == ESC) {
  1255.             break;
  1256.             }
  1257.         if(key_val == DOWN && records_found) {
  1258.             skp = 0;
  1259.             /* Display with normal attribute the current row. */
  1260.             w4num_att(cur_row, 0, f4str( d4field(dbfile,"SURNAME")), surn_len, custom[BROWSER_N]);
  1261.             w4num_att(cur_row, surn_len, "│", 1, custom[BROWSER_N]);
  1262.             w4num_att(cur_row, surn_len +1, f4str( d4field(dbfile ,"CODE")), code_len, custom[BROWSER_N]);
  1263.  
  1264.             if (d4skip(dbfile, 1) == r4eof) {
  1265.                 d4bottom(dbfile);
  1266.                 cur_row --;
  1267.                 }
  1268.             d4unlock_index(dbfile);
  1269.             if (cur_row == maxrow) {
  1270.                 cur_row --;
  1271.                 w4scroll(1);
  1272.                 }
  1273.             cur_row ++;
  1274.             /* Display the bar */
  1275.             w4num_att(cur_row, 0, f4str( d4field(dbfile, "SURNAME")), surn_len, custom[BROWSER_S]);
  1276.             w4num_att(cur_row, surn_len, "│", 1, custom[BROWSER_S]);
  1277.             w4num_att(cur_row, surn_len +1, f4str( d4field(dbfile ,"CODE")), code_len, custom[BROWSER_S]);
  1278.             }
  1279.  
  1280.         else if (key_val == UP && records_found) {
  1281.             skp = 0;
  1282.             /* Display with normal attribute the current row. */
  1283.             w4num_att(cur_row, 0, f4str( d4field(dbfile, "SURNAME")), surn_len, custom[BROWSER_N]);
  1284.             w4num_att(cur_row, surn_len, "│", 1, custom[BROWSER_N]);
  1285.             w4num_att(cur_row, surn_len +1, f4str( d4field(dbfile ,"CODE")), code_len, custom[BROWSER_N]);
  1286.  
  1287.             if (d4skip(dbfile, -1)) {
  1288.                 d4top(dbfile);
  1289.                 cur_row ++;
  1290.                 }
  1291.             d4unlock_index(dbfile);
  1292.  
  1293.             if (cur_row == 0) {
  1294.                 cur_row ++;
  1295.                 w4scroll(-1);
  1296.                 }
  1297.             cur_row --;
  1298.             w4num_att(cur_row, 0, f4str( d4field(dbfile, "SURNAME")), surn_len, custom[BROWSER_S]);
  1299.             w4num_att(cur_row, surn_len, "│", 1, custom[BROWSER_S]);
  1300.             w4num_att(cur_row, surn_len +1, f4str( d4field(dbfile ,"CODE")), code_len, custom[BROWSER_S]);
  1301.             }
  1302.         }    /* ==L1== */
  1303.  
  1304.     /* Close the window and send to g4read() the key to execute. */
  1305.     free(sk);
  1306.     w4deactivate(browse_wref);
  1307.     w4close(browse_wref);
  1308.     w4select(previous_wref);
  1309.     return(HOME);
  1310.     }
  1311.  
  1312. static gfmaster_fillwindow(dbfile, surn_len, code_len, maxrow, to_skp)
  1313. D4DATA *dbfile;
  1314. int surn_len;
  1315. int code_len;
  1316. int maxrow;
  1317. int to_skp;
  1318. {
  1319.     int cur_row;
  1320.     int count;
  1321.  
  1322.     /* Fill the window with records. (normal attribute).                     */
  1323.     w4clear(0);
  1324.     for(cur_row = 0; cur_row <= maxrow ; cur_row ++) {
  1325.         w4num_att(cur_row, 0, f4str( d4field(dbfile, "SURNAME")), surn_len, custom[BROWSER_N]);
  1326.         w4num_att(cur_row, surn_len, "│", 1, custom[BROWSER_N]);
  1327.         w4num_att(cur_row, surn_len +1, f4str( d4field(dbfile ,"CODE")), code_len, custom[BROWSER_N]);
  1328.         if( d4skip(dbfile, 1))
  1329.             break;
  1330.         d4unlock_index(dbfile);
  1331.         }
  1332.     d4unlock_index(dbfile);
  1333.     d4unlock_all_data(dbfile);
  1334.  
  1335.     if(cur_row > maxrow)
  1336.         cur_row = maxrow;
  1337.     /* Skip to the first record found. */
  1338.     for(count = 0 ; count <= cur_row; count ++) {
  1339.         d4skip(dbfile, -1);
  1340.         d4unlock_index(dbfile);
  1341.         }
  1342.     cur_row = 0;
  1343.  
  1344.     /* Display the bar */
  1345.     w4num_att(cur_row, 0, f4str( d4field(dbfile, "SURNAME")), to_skp, custom[BROWSER_S]);
  1346.     w4num_att(cur_row, surn_len, "│", 1, custom[BROWSER_S]);
  1347.     w4num_att(cur_row, surn_len +1, f4str( d4field(dbfile , "CODE")), code_len, custom[BROWSER_S]);
  1348.     }
  1349.  
  1350.  
  1351. /*****************************************************************************/
  1352. /* Function: int gtoupper(char ch)                                           */
  1353. /* Description: Converts a greek or latin character to upper case            */
  1354. /* Parameters: char ch     -> The character to be converted.                 */
  1355. /* Returns: The converted character as integer.                              */
  1356. /* Uses: Nothing.                                                            */
  1357. /*****************************************************************************/
  1358. int gtoupper(ch)
  1359. int ch;
  1360. {
  1361.     char strlow[61];    /* Mattrix of lower case chars (always the same). */
  1362.     char strcap[61];    /* Mattrix of upper case chars (depends on definitions). */
  1363.     int  offset;          /* Offset of character in the mattrixes. */
  1364.  
  1365.     if((ch >= 152 && ch <= 175) || (ch >= 224 && ch <= 233) || (ch >= 97 && ch <= 122)) {
  1366.         strcpy(strlow, "abcdefghijklmnopqrstuvwxyzÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐½¼¡«»α¬ßΓπσΣτΦµΘ");
  1367. #ifdef CSET437
  1368.         strcpy(strcap, "ABCDEFGHIJKLMNOPQRSTUVWXYZÇüéâäàåçêëèïîìÄÅÉæÆôöòûùæÇäåêêôôÄù");
  1369. #endif
  1370.         offset = strchr(strlow, ch) - strlow;
  1371.         return(strcap[offset]);
  1372.         }
  1373.     else
  1374.         return(ch);
  1375.     }
  1376.  
  1377.  
  1378. /*****************************************************************************/
  1379. /* Function: int grtolat(char ch)                                            */
  1380. /* Description: Converts a greek character to latin.                         */
  1381. /* Parameters: char ch     -> The character to be converted.                 */
  1382. /* Returns: The converted character as integer.                              */
  1383. /* Uses: Nothing.                                                            */
  1384. /*****************************************************************************/
  1385. int grtolat(int ch)
  1386. {
  1387.     char  strgr[59];    /* Mattrix of greek characters. */
  1388.     char strlat[59];    /* Mattrix of latin characters. */
  1389.     int  offset;          /* Offset of character in the mattrixes. */
  1390.  
  1391.     if( (ch >= 152 && ch <= 175) ||
  1392.          (ch >= 224 && ch <= 233) ||
  1393.          (ch >= 128 && ch <= 151) ) {
  1394.  
  1395.         strcpy(strgr,  "ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐½¼¡«»α¬ßΓπστµΘΣΦ");
  1396.         strcpy(strlat, "ABGDEZHUIKLMNJOPRSTYFXCVabgdezhuiklmnjoprstyfxcvsaehiyoviy");
  1397.         offset = strchr(strgr, ch) - strgr;
  1398.         return(strlat[offset]);
  1399.         }
  1400.     else
  1401.         return(ch);
  1402.     }
  1403.  
  1404. cd_iep()
  1405. {
  1406. #ifndef IEP_UNIX
  1407.     if(memcmp(iepdrive, space(3), 3)) {
  1408.         _chdrive(iepdrive[0] - 64);
  1409.         }
  1410. #endif
  1411.     ieppath[strlen(ieppath) -1] = '\0';
  1412.     chdir(ieppath);
  1413.     ieppath[strlen(ieppath)] = '\\';
  1414.     }
  1415.  
  1416.  
  1417. cd_doc()
  1418. {
  1419. #ifndef IEP_UNIX
  1420.     if(memcmp(docdrive, space(3), 3)) {
  1421.         _chdrive(docdrive[0] - 64);
  1422.         }
  1423. #endif
  1424.     docpath[strlen(docpath) -1] = '\0';
  1425.     chdir(docpath);
  1426.     docpath[strlen(docpath)] = '\\';
  1427.     }
  1428.