1//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 2// Confidential Trade Secret. 3// Copyright 1987-1994 Data Access Corporation, Miami FL, USA 4// All Rights reserved 5// DataFlex is a registered trademark of Data Access Corporation. 6// 7// Module: 8// seq_chnl.pkg 9// 10// Purpose: 11// Defines global sequential device management operations. 12// 13// Author: 14// Lee Smith 15// 16// Date: 17// 11/2/94 18// 19//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 20// 12/13/2001 JJT: If channel not open, don't declare error during close 21//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 22Use LanguageText.pkg 23use VDFBase.pkg 24#INCLUDE errornum.inc 25 26define DF_SEQ_CHANNEL_NOT_AVAILABLE for -2 27define DF_SEQ_CHANNEL_ERROR for -1 28define DF_SEQ_CHANNEL_MIN for 0 29define DF_SEQ_CHANNEL_MAX for 9 30define DF_SEQ_START_CHANNEL for 2 // leave 0 and 1 til last 31 // so that programs that use direct_input/output 32 // w/o specifying a channel will work. 33enum_list 34 define DF_SEQ_CHANNEL_MODE_CLOSED 35 define DF_SEQ_CHANNEL_MODE_OPEN 36 define DF_SEQ_CHANNEL_MODE_OUTPUT 37 define DF_SEQ_CHANNEL_MODE_INPUT 38end_enum_list 39 40enum_list 41 define DF_SEQ_CHANNEL_ERROR_MODE_NONE 42 define DF_SEQ_CHANNEL_ERROR_MODE_ALL 43end_enum_list 44 45integer Seq$Channel$Error$Mode 46 47 48procedure set Seq_Channel_Error_Mode GLOBAL integer Mode 49 move Mode to Seq$Channel$Error$Mode 50end_procedure 51 52 53function Seq_Channel_Error_Mode GLOBAL returns integer 54 function_return Seq$Channel$Error$Mode 55end_procedure 56 57object Seq_Channel_List is an Array 58 procedure Initialize 59 integer Itm 60 61 move DF_SEQ_CHANNEL_MIN to Itm 62 63 while Itm LE DF_SEQ_CHANNEL_MAX 64 set Array_Value item Itm to DF_SEQ_CHANNEL_MODE_CLOSED 65 increment Itm 66 end 67 end_procedure 68 69 send Initialize 70end_object 71 72set Seq_Channel_Error_Mode to DF_SEQ_CHANNEL_ERROR_MODE_ALL 73 74 75function Seq_Channel_Mode GLOBAL integer Chnl returns integer 76 function_return (Integer_Value(Seq_Channel_List(self), Chnl)) 77end_function 78 79 80procedure set Seq_Channel_Mode GLOBAL integer Chnl integer Mode 81 set Array_Value of (Seq_Channel_List(self)) item Chnl to Mode 82end_procedure 83 84function Seq_New_Channel GLOBAL returns integer 85 integer Obj Chnl 86 87 move DF_SEQ_START_CHANNEL to Chnl 88 89 while Chnl LE DF_SEQ_CHANNEL_MAX 90 if (Seq_Channel_Mode(Chnl)) EQ DF_SEQ_CHANNEL_MODE_CLOSED begin 91 set Seq_Channel_Mode Chnl to DF_SEQ_CHANNEL_MODE_OPEN 92 function_return Chnl 93 end 94 95 increment Chnl 96 end 97 98 // wrap back to beginning 99 move 0 to Chnl 100 101 while Chnl LT DF_SEQ_START_CHANNEL 102 if (Seq_Channel_Mode(Chnl)) EQ DF_SEQ_CHANNEL_MODE_CLOSED begin 103 set Seq_Channel_Mode Chnl to DF_SEQ_CHANNEL_MODE_OPEN 104 function_return Chnl 105 end 106 107 increment Chnl 108 end 109 110 function_return DF_SEQ_CHANNEL_NOT_AVAILABLE 111end_procedure 112 113procedure Seq_Release_Channel GLOBAL integer Chnl 114 if ((Chnl >= DF_SEQ_CHANNEL_MIN) and (Chnl <= DF_SEQ_CHANNEL_MAX)) ; 115 set Seq_Channel_Mode Chnl to DF_SEQ_CHANNEL_MODE_CLOSED 116end_procedure 117 118 119function Seq_Open_Input_Channel GLOBAL string Dvc returns integer 120 integer Chnl 121 122 get Seq_New_Channel to Chnl 123 124 if Chnl LE DF_SEQ_CHANNEL_ERROR begin 125 if (Seq_Channel_Error_Mode()) EQ DF_SEQ_CHANNEL_ERROR_MODE_ALL ; 126 error DFERR_CANT_OPEN_INPUT_FILE (Dvc + ":" *C_$NoOpenChannels) 127 function_return Chnl 128 end 129 130 indicate Err FALSE 131 direct_input channel Chnl Dvc 132 133 [Err] begin 134 send Seq_Release_Channel Chnl 135 function_return DF_SEQ_CHANNEL_ERROR 136 end 137 138 set Seq_Channel_Mode Chnl to DF_SEQ_CHANNEL_MODE_INPUT 139 140 function_return Chnl 141end_function 142 143 144function Seq_Open_Output_Channel GLOBAL string Dvc returns integer 145 integer Chnl 146 147 get Seq_New_Channel to Chnl 148 149 if Chnl LE DF_SEQ_CHANNEL_ERROR begin 150 if (Seq_Channel_Error_Mode()) EQ DF_SEQ_CHANNEL_ERROR_MODE_ALL begin 151 error DFERR_CANT_OPEN_OUTPUT_FILE (Dvc + ":" *C_$ChannelNotAvailable) 152 move DF_SEQ_CHANNEL_ERROR to Chnl 153 end 154 155 function_return Chnl 156 end 157 158 indicate Err FALSE 159 direct_output channel Chnl Dvc 160 161 [Err] begin 162 send Seq_Release_Channel Chnl 163 function_return DF_SEQ_CHANNEL_ERROR 164 end 165 166 set Seq_Channel_Mode Chnl to DF_SEQ_CHANNEL_MODE_OUTPUT 167 168 function_return Chnl 169end_function 170 171 172function Seq_Append_Output_Channel GLOBAL string Dvc returns integer 173 integer Chnl 174 175 get Seq_New_Channel to Chnl 176 177 if Chnl LE DF_SEQ_CHANNEL_ERROR begin 178 if (Seq_Channel_Error_Mode()) EQ DF_SEQ_CHANNEL_ERROR_MODE_ALL begin 179 error DFERR_CANT_OPEN_OUTPUT_FILE (Dvc + ":" *C_$ChannelNotAvailable) 180 move DF_SEQ_CHANNEL_ERROR to Chnl 181 end 182 183 function_return Chnl 184 end 185 186 indicate Err FALSE 187 append_output channel Chnl Dvc 188 189 [Err] begin 190 send Seq_Release_Channel Chnl 191 function_return DF_SEQ_CHANNEL_ERROR 192 end 193 194 set Seq_Channel_Mode Chnl to DF_SEQ_CHANNEL_MODE_OUTPUT 195 196 function_return Chnl 197end_function 198 199 200procedure Seq_Close_Channel GLOBAL integer Chnl 201 integer Mode 202 203 if ((Chnl >= DF_SEQ_CHANNEL_MIN) and (Chnl <= DF_SEQ_CHANNEL_MAX)) begin 204 get Seq_Channel_Mode Chnl to Mode 205 206 if Mode EQ DF_SEQ_CHANNEL_MODE_OUTPUT ; 207 close_output channel Chnl 208 else if Mode EQ DF_SEQ_CHANNEL_MODE_INPUT ; 209 close_input channel Chnl 210 // 12/13/2001 - If channel not open, release it! No (fatal) Error. 211 //else begin 212 // Error DFERR_FILE_NOT_OPEN ("Channel: " + string(Chnl)) 213 // procedure_return 214 //end 215 216 send Seq_Release_Channel Chnl 217 end 218end_procedure