| 114 | |
| 115 | |
| 116 | SLONG SDL_compute_subscript(CheckStatusWrapper* status_vector, |
| 117 | const Ods::InternalArrayDesc* desc, |
| 118 | USHORT dimensions, |
| 119 | const SLONG* subscripts) |
| 120 | { |
| 121 | /************************************** |
| 122 | * |
| 123 | * S D L _ c o m p u t e _ s u b s c r i p t |
| 124 | * |
| 125 | ************************************** |
| 126 | * |
| 127 | * Functional description |
| 128 | * Collapse a multi-dimension array reference into a vector |
| 129 | * reference. |
| 130 | * |
| 131 | **************************************/ |
| 132 | if (dimensions != desc->iad_dimensions) |
| 133 | { |
| 134 | error(status_vector, Arg::Gds(isc_invalid_dimension) << Arg::Num(desc->iad_dimensions) << |
| 135 | Arg::Num(dimensions)); |
| 136 | return -1; |
| 137 | } |
| 138 | |
| 139 | SLONG subscript = 0; |
| 140 | |
| 141 | const Ods::InternalArrayDesc::iad_repeat* range = desc->iad_rpt; |
| 142 | for (const Ods::InternalArrayDesc::iad_repeat* const end = range + desc->iad_dimensions; |
| 143 | range < end; ++range) |
| 144 | { |
| 145 | const SLONG n = *subscripts++; |
| 146 | if (n < range->iad_lower || n > range->iad_upper) |
| 147 | { |
| 148 | error(status_vector, Arg::Gds(isc_ss_out_of_bounds) << |
| 149 | Arg::Num(n) << Arg::Num(range->iad_lower) << Arg::Num(range->iad_upper)); |
| 150 | return -1; |
| 151 | } |
| 152 | subscript += (n - range->iad_lower) * range->iad_length; |
| 153 | } |
| 154 | |
| 155 | return subscript; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | ISC_STATUS SDL_info(CheckStatusWrapper* status_vector, |