1 /* Implement the SELECT statement for character variables.
2 Contributed by Andy Vaught
4 This file is part of the GNU Fortran 95 runtime library (libgfor).
6 Libgfor is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Libgfor is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libgfor; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "libgfortran.h"
34 #define select_string prefix(select_string)
37 /* select_string()-- Given a selector string and a table of
38 * select_struct structures, return the address to jump to. */
40 void *select_string (select_struct *table, int table_len, void *default_jump,
41 const char *selector, int selector_len)
44 int i, low, high, mid;
49 /* Record the default address if present */
51 if (table->low == NULL && table->high == NULL)
53 default_jump = table->address;
61 /* Try the high and low bounds if present. */
63 if (table->low == NULL)
65 if (compare_string (table->high_len, table->high,
66 selector_len, selector) >= 0)
67 return table->address;
75 t = table + table_len - 1;
79 if (compare_string (t->low_len, t->low,
80 selector_len, selector) <= 0)
88 /* At this point, the only table entries are bounded entries. Find
89 the right entry with a binary chop. */
94 while (low + 1 < high)
96 mid = (low + high) / 2;
99 i = compare_string (t->low_len, t->low, selector_len, selector);
110 /* The string now lies between the low indeces of the now-adjacent
111 high and low entries. Because it is less than the low entry of
112 'high', it can't be that one. If low is still -1, then no
113 entries match. Otherwise, we have to check the high entry of
120 if (compare_string (selector_len, selector,
121 t->high_len, t->high) <= 0)