1 /* Copyright (C) 2002-2003 Free Software Foundation, Inc.
2 Contributed by Paul Brook
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. */
24 #include "libgfortran.h"
27 /* Compare a C-style string with a fortran style string in a case-insensitive
28 manner. Used for decoding string options to various statements. Returns
29 zero if not equal, nonzero if equal. */
32 compare0 (const char *s1, int s1_len, const char *s2)
36 if (strncasecmp (s1, s2, s1_len) != 0)
39 /* The rest of s1 needs to be blanks for equality. */
41 for (i = strlen (s2); i < s1_len; i++)
49 /* Given a fortran string, return its length exclusive of the trailing
52 fstrlen (const char *string, int len)
55 for (len--; len >= 0; len--)
56 if (string[len] != ' ')
65 fstrcpy (char *dest, int destlen, const char *src, int srclen)
68 if (srclen >= destlen)
70 /* This will truncate if too long. */
71 memcpy (dest, src, destlen);
75 memcpy (dest, src, srclen);
76 /* Pad with spaces. */
77 memset (&dest[srclen], ' ', destlen - srclen);
83 cf_strcpy (char *dest, int dest_len, const char *src)
87 src_len = strlen (src);
89 if (src_len >= dest_len)
91 /* This will truncate if too long. */
92 memcpy (dest, src, dest_len);
96 memcpy (dest, src, src_len);
97 /* Pad with spaces. */
98 memset (&dest[src_len], ' ', dest_len - src_len);
103 /* Given a fortran string and an array of st_option structures, search through
104 the array to find a match. If the option is not found, we generate an error
105 if no default is provided. */
108 find_option (const char *s1, int s1_len, st_option * opts,
109 const char *error_message)
112 for (; opts->name; opts++)
113 if (compare0 (s1, s1_len, opts->name))
116 generate_error (ERROR_BAD_OPTION, error_message);