@@ -824,26 +824,35 @@ bool InquireUnitState::Inquire(
824
824
const char *str{nullptr };
825
825
switch (inquiry) {
826
826
case HashInquiryKeyword (" ACCESS" ):
827
- switch (unit ().access ) {
828
- case Access::Sequential:
829
- str = " SEQUENTIAL" ;
830
- break ;
831
- case Access::Direct:
832
- str = " DIRECT" ;
833
- break ;
834
- case Access::Stream:
835
- str = " STREAM" ;
836
- break ;
827
+ if (!unit ().IsConnected ()) {
828
+ str = " UNDEFINED" ;
829
+ } else {
830
+ switch (unit ().access ) {
831
+ case Access::Sequential:
832
+ str = " SEQUENTIAL" ;
833
+ break ;
834
+ case Access::Direct:
835
+ str = " DIRECT" ;
836
+ break ;
837
+ case Access::Stream:
838
+ str = " STREAM" ;
839
+ break ;
840
+ }
837
841
}
838
842
break ;
839
843
case HashInquiryKeyword (" ACTION" ):
840
- str = unit ().mayWrite () ? unit ().mayRead () ? " READWRITE" : " WRITE" : " READ" ;
844
+ str = !unit ().IsConnected () ? " UNDEFINED"
845
+ : unit ().mayWrite () ? unit ().mayRead () ? " READWRITE" : " WRITE"
846
+ : " READ" ;
841
847
break ;
842
848
case HashInquiryKeyword (" ASYNCHRONOUS" ):
843
- str = unit ().mayAsynchronous () ? " YES" : " NO" ;
849
+ str = !unit ().IsConnected () ? " UNDEFINED"
850
+ : unit ().mayAsynchronous () ? " YES"
851
+ : " NO" ;
844
852
break ;
845
853
case HashInquiryKeyword (" BLANK" ):
846
- str = unit ().isUnformatted .value_or (true ) ? " UNDEFINED"
854
+ str = !unit ().IsConnected () || unit ().isUnformatted .value_or (true )
855
+ ? " UNDEFINED"
847
856
: unit ().modes .editingFlags & blankZero ? " ZERO"
848
857
: " NULL" ;
849
858
break ;
@@ -854,12 +863,13 @@ bool InquireUnitState::Inquire(
854
863
str = unit ().swapEndianness () ? " SWAP" : " NATIVE" ;
855
864
break ;
856
865
case HashInquiryKeyword (" DECIMAL" ):
857
- str = unit ().isUnformatted .value_or (true ) ? " UNDEFINED"
866
+ str = !unit ().IsConnected () || unit ().isUnformatted .value_or (true )
867
+ ? " UNDEFINED"
858
868
: unit ().modes .editingFlags & decimalComma ? " COMMA"
859
869
: " POINT" ;
860
870
break ;
861
871
case HashInquiryKeyword (" DELIM" ):
862
- if (unit ().isUnformatted .value_or (true )) {
872
+ if (! unit (). IsConnected () || unit ().isUnformatted .value_or (true )) {
863
873
str = " UNDEFINED" ;
864
874
} else {
865
875
switch (unit ().modes .delim ) {
@@ -876,23 +886,26 @@ bool InquireUnitState::Inquire(
876
886
}
877
887
break ;
878
888
case HashInquiryKeyword (" DIRECT" ):
879
- str = unit ().access == Access::Direct ||
889
+ str = !unit ().IsConnected () ? " UNKNOWN"
890
+ : unit ().access == Access::Direct ||
880
891
(unit ().mayPosition () && unit ().isFixedRecordLength )
881
892
? " YES"
882
893
: " NO" ;
883
894
break ;
884
895
case HashInquiryKeyword (" ENCODING" ):
885
- str = unit ().isUnformatted .value_or (true ) ? " UNDEFINED"
896
+ str = !unit ().IsConnected () ? " UNKNOWN"
897
+ : unit ().isUnformatted .value_or (true ) ? " UNDEFINED"
886
898
: unit ().isUTF8 ? " UTF-8"
887
899
: " ASCII" ;
888
900
break ;
889
901
case HashInquiryKeyword (" FORM" ):
890
- str = !unit ().isUnformatted ? " UNDEFINED"
891
- : *unit ().isUnformatted ? " UNFORMATTED"
892
- : " FORMATTED" ;
902
+ str = !unit ().IsConnected () || ! unit (). isUnformatted ? " UNDEFINED"
903
+ : *unit ().isUnformatted ? " UNFORMATTED"
904
+ : " FORMATTED" ;
893
905
break ;
894
906
case HashInquiryKeyword (" FORMATTED" ):
895
- str = !unit ().isUnformatted ? " UNKNOWN"
907
+ str = !unit ().IsConnected () ? " UNDEFINED"
908
+ : !unit ().isUnformatted ? " UNKNOWN"
896
909
: *unit ().isUnformatted ? " NO"
897
910
: " YES" ;
898
911
break ;
@@ -903,33 +916,38 @@ bool InquireUnitState::Inquire(
903
916
}
904
917
break ;
905
918
case HashInquiryKeyword (" PAD" ):
906
- str = unit ().isUnformatted .value_or (true ) ? " UNDEFINED"
907
- : unit ().modes .pad ? " YES"
908
- : " NO" ;
919
+ str = !unit ().IsConnected () || unit ().isUnformatted .value_or (true )
920
+ ? " UNDEFINED"
921
+ : unit ().modes .pad ? " YES"
922
+ : " NO" ;
909
923
break ;
910
924
case HashInquiryKeyword (" POSITION" ):
911
- if (unit ().access == Access::Direct) {
925
+ if (! unit (). IsConnected () || unit ().access == Access::Direct) {
912
926
str = " UNDEFINED" ;
913
927
} else {
914
- auto size{unit ().knownSize ()};
915
- auto pos{unit ().position ()};
916
- if (pos == size.value_or (pos + 1 )) {
917
- str = " APPEND" ;
918
- } else if (pos == 0 && unit ().mayPosition ()) {
928
+ switch (unit ().InquirePosition ()) {
929
+ case Position::Rewind:
919
930
str = " REWIND" ;
920
- } else {
921
- str = " ASIS" ; // processor-dependent & no common behavior
931
+ break ;
932
+ case Position::Append:
933
+ str = " APPEND" ;
934
+ break ;
935
+ case Position::AsIs:
936
+ str = " ASIS" ;
937
+ break ;
922
938
}
923
939
}
924
940
break ;
925
941
case HashInquiryKeyword (" READ" ):
926
- str = unit ().mayRead () ? " YES" : " NO" ;
942
+ str = ! unit (). IsConnected () ? " UNDEFINED " : unit ().mayRead () ? " YES" : " NO" ;
927
943
break ;
928
944
case HashInquiryKeyword (" READWRITE" ):
929
- str = unit ().mayRead () && unit ().mayWrite () ? " YES" : " NO" ;
945
+ str = !unit ().IsConnected () ? " UNDEFINED"
946
+ : unit ().mayRead () && unit ().mayWrite () ? " YES"
947
+ : " NO" ;
930
948
break ;
931
949
case HashInquiryKeyword (" ROUND" ):
932
- if (unit ().isUnformatted .value_or (true )) {
950
+ if (! unit (). IsConnected () || unit ().isUnformatted .value_or (true )) {
933
951
str = " UNDEFINED" ;
934
952
} else {
935
953
switch (unit ().modes .round ) {
@@ -954,23 +972,28 @@ bool InquireUnitState::Inquire(
954
972
case HashInquiryKeyword (" SEQUENTIAL" ):
955
973
// "NO" for Direct, since Sequential would not work if
956
974
// the unit were reopened without RECL=.
957
- str = unit ().access == Access::Sequential ? " YES" : " NO" ;
975
+ str = !unit ().IsConnected () ? " UNKNOWN"
976
+ : unit ().access == Access::Sequential ? " YES"
977
+ : " NO" ;
958
978
break ;
959
979
case HashInquiryKeyword (" SIGN" ):
960
- str = unit ().isUnformatted .value_or (true ) ? " UNDEFINED"
980
+ str = !unit ().IsConnected () || unit ().isUnformatted .value_or (true )
981
+ ? " UNDEFINED"
961
982
: unit ().modes .editingFlags & signPlus ? " PLUS"
962
983
: " SUPPRESS" ;
963
984
break ;
964
985
case HashInquiryKeyword (" STREAM" ):
965
- str = unit ().access == Access::Stream ? " YES" : " NO" ;
966
- break ;
967
- case HashInquiryKeyword (" WRITE" ):
968
- str = unit ().mayWrite () ? " YES" : " NO" ;
986
+ str = !unit ().IsConnected () ? " UNKNOWN"
987
+ : unit ().access == Access::Stream ? " YES"
988
+ : " NO" ;
969
989
break ;
970
990
case HashInquiryKeyword (" UNFORMATTED" ):
971
- str = !unit ().isUnformatted ? " UNKNOWN"
972
- : *unit ().isUnformatted ? " YES"
973
- : " NO" ;
991
+ str = !unit ().IsConnected () || !unit ().isUnformatted ? " UNKNOWN"
992
+ : *unit ().isUnformatted ? " YES"
993
+ : " NO" ;
994
+ break ;
995
+ case HashInquiryKeyword (" WRITE" ):
996
+ str = !unit ().IsConnected () ? " UNKNOWN" : unit ().mayWrite () ? " YES" : " NO" ;
974
997
break ;
975
998
}
976
999
if (str) {
@@ -991,7 +1014,7 @@ bool InquireUnitState::Inquire(InquiryKeywordHash inquiry, bool &result) {
991
1014
result = unit ().path () != nullptr ;
992
1015
return true ;
993
1016
case HashInquiryKeyword (" OPENED" ):
994
- result = true ;
1017
+ result = unit (). IsConnected () ;
995
1018
return true ;
996
1019
case HashInquiryKeyword (" PENDING" ):
997
1020
result = false ; // asynchronous I/O is not implemented
@@ -1023,13 +1046,15 @@ bool InquireUnitState::Inquire(
1023
1046
}
1024
1047
return true ;
1025
1048
case HashInquiryKeyword (" NUMBER" ):
1026
- result = unit ().unitNumber ();
1049
+ result = unit ().IsConnected () ? unit (). unitNumber () : - 1 ;
1027
1050
return true ;
1028
1051
case HashInquiryKeyword (" POS" ):
1029
1052
result = unit ().position ();
1030
1053
return true ;
1031
1054
case HashInquiryKeyword (" RECL" ):
1032
- if (unit ().access == Access::Stream) {
1055
+ if (!unit ().IsConnected ()) {
1056
+ result = -1 ;
1057
+ } else if (unit ().access == Access::Stream) {
1033
1058
result = -2 ;
1034
1059
} else if (unit ().isFixedRecordLength && unit ().recordLength ) {
1035
1060
result = *unit ().recordLength ;
@@ -1038,10 +1063,11 @@ bool InquireUnitState::Inquire(
1038
1063
}
1039
1064
return true ;
1040
1065
case HashInquiryKeyword (" SIZE" ):
1041
- if (auto size{unit ().knownSize ()}) {
1042
- result = *size;
1043
- } else {
1044
- result = -1 ;
1066
+ result = -1 ;
1067
+ if (unit ().IsConnected ()) {
1068
+ if (auto size{unit ().knownSize ()}) {
1069
+ result = *size;
1070
+ }
1045
1071
}
1046
1072
return true ;
1047
1073
default :
0 commit comments