|
11 | 11 |
|
12 | 12 | #include "vim.h" |
13 | 13 |
|
| 14 | +/* define _generic_64 for use in time functions */ |
| 15 | +#ifndef VAX |
| 16 | +# include <gen64def.h> |
| 17 | +#else |
| 18 | +/* based on Alpha's gen64def.h; the file is absent on VAX */ |
| 19 | +typedef struct _generic_64 { |
| 20 | +# pragma __nomember_alignment |
| 21 | + __union { /* You can treat me as... */ |
| 22 | + /* long long is not available on VAXen */ |
| 23 | + /* unsigned __int64 gen64$q_quadword; ...a single 64-bit value, or */ |
| 24 | +
|
| 25 | + unsigned int gen64$l_longword [2]; /* ...two 32-bit values, or */ |
| 26 | + unsigned short int gen64$w_word [4]; /* ...four 16-bit values */ |
| 27 | + } gen64$r_quad_overlay; |
| 28 | +} GENERIC_64; |
| 29 | +#endif |
| 30 | + |
14 | 31 | typedef struct |
15 | 32 | { |
16 | 33 | char class; |
@@ -669,3 +686,92 @@ vms_remove_version(void * fname) |
669 | 686 | } |
670 | 687 | return ; |
671 | 688 | } |
| 689 | + |
| 690 | +struct typeahead_st { |
| 691 | + unsigned short numchars; |
| 692 | + unsigned char firstchar; |
| 693 | + unsigned char reserved0; |
| 694 | + unsigned long reserved1; |
| 695 | +} typeahead; |
| 696 | + |
| 697 | +/* |
| 698 | + * Wait "msec" msec until a character is available from file descriptor "fd". |
| 699 | + * "msec" == 0 will check for characters once. |
| 700 | + * "msec" == -1 will block until a character is available. |
| 701 | + */ |
| 702 | + int |
| 703 | +RealWaitForChar(fd, msec, check_for_gpm) |
| 704 | + int fd UNUSED; /* always read from iochan */ |
| 705 | + long msec; |
| 706 | + int *check_for_gpm UNUSED; |
| 707 | +{ |
| 708 | + int status; |
| 709 | + struct _generic_64 time_curr; |
| 710 | + struct _generic_64 time_diff; |
| 711 | + struct _generic_64 time_out; |
| 712 | + unsigned int convert_operation = LIB$K_DELTA_SECONDS_F; |
| 713 | + float sec = (float) msec / 1000; |
| 714 | + |
| 715 | + /* make sure the iochan is set */ |
| 716 | + if (!iochan) |
| 717 | + get_tty(); |
| 718 | + |
| 719 | + if (msec > 0) { |
| 720 | + /* time-out specified; convert it to absolute time */ |
| 721 | + |
| 722 | + /* get current time (number of 100ns ticks since the VMS Epoch) */ |
| 723 | + status = sys$gettim(&time_curr); |
| 724 | + if (status != SS$_NORMAL) |
| 725 | + return 0; /* error */ |
| 726 | + |
| 727 | + /* construct the delta time */ |
| 728 | + status = lib$cvtf_to_internal_time( |
| 729 | + &convert_operation, &sec, &time_diff); |
| 730 | + if (status != LIB$_NORMAL) |
| 731 | + return 0; /* error */ |
| 732 | + |
| 733 | + /* add them up */ |
| 734 | + status = lib$add_times( |
| 735 | + &time_curr, |
| 736 | + &time_diff, |
| 737 | + &time_out); |
| 738 | + if (status != LIB$_NORMAL) |
| 739 | + return 0; /* error */ |
| 740 | + } |
| 741 | + |
| 742 | + while (TRUE) { |
| 743 | + /* select() */ |
| 744 | + status = sys$qiow(0, iochan, IO$_SENSEMODE | IO$M_TYPEAHDCNT, iosb, |
| 745 | + 0, 0, &typeahead, 8, 0, 0, 0, 0); |
| 746 | + if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) |
| 747 | + return 0; /* error */ |
| 748 | + |
| 749 | + if (typeahead.numchars) |
| 750 | + return 1; /* ready to read */ |
| 751 | + |
| 752 | + /* there's nothing to read; what now? */ |
| 753 | + if (msec == 0) { |
| 754 | + /* immediate time-out; return impatiently */ |
| 755 | + return 0; |
| 756 | + } |
| 757 | + else if (msec < 0) { |
| 758 | + /* no time-out; wait on indefinitely */ |
| 759 | + continue; |
| 760 | + } |
| 761 | + else { |
| 762 | + /* time-out needs to be checked */ |
| 763 | + status = sys$gettim(&time_curr); |
| 764 | + if (status != SS$_NORMAL) |
| 765 | + return 0; /* error */ |
| 766 | + |
| 767 | + status = lib$sub_times( |
| 768 | + &time_out, |
| 769 | + &time_curr, |
| 770 | + &time_diff); |
| 771 | + if (status != LIB$_NORMAL) |
| 772 | + return 0; /* error, incl. time_diff < 0 (i.e. time-out) */ |
| 773 | + |
| 774 | + /* otherwise wait some more */ |
| 775 | + } |
| 776 | + } |
| 777 | +} |
0 commit comments