OSDN Git Service

2009-03-28 Daniel Kraft <d@domob.eu>
[pf3gnuchains/gcc-fork.git] / libgfortran / intrinsics / string_intrinsics.c
1 /* String intrinsics helper functions.
2    Copyright 2008 Free Software Foundation, Inc.
3
4 This file is part of the GNU Fortran runtime library (libgfortran).
5
6 Libgfortran is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file.  (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
19
20 Libgfortran is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public
26 License along with libgfortran; see the file COPYING.  If not,
27 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA.  */
29
30
31 /* Unlike what the name of this file suggests, we don't actually
32    implement the Fortran intrinsics here.  At least, not with the
33    names they have in the standard.  The functions here provide all
34    the support we need for the standard string intrinsics, and the
35    compiler translates the actual intrinsics calls to calls to
36    functions in this file.  */
37
38 #include "libgfortran.h"
39
40 #include <stdlib.h>
41 #include <string.h>
42 #include <assert.h>
43
44
45 /* Helper function to set parts of wide strings to a constant (usually
46    spaces).  */
47
48 static gfc_char4_t *
49 memset_char4 (gfc_char4_t *b, gfc_char4_t c, size_t len)
50 {
51   size_t i;
52
53   for (i = 0; i < len; i++)
54     b[i] = c;
55
56   return b;
57 }
58
59
60 /* All other functions are defined using a few generic macros in
61    string_intrinsics_inc.c, so we avoid code duplication between the
62    various character type kinds.  */
63
64 #undef  CHARTYPE
65 #define CHARTYPE char
66 #undef  UCHARTYPE
67 #define UCHARTYPE unsigned char
68 #undef  SUFFIX
69 #define SUFFIX(x) x
70 #undef  MEMSET
71 #define MEMSET memset
72
73 #include "string_intrinsics_inc.c"
74
75
76 #undef  CHARTYPE
77 #define CHARTYPE gfc_char4_t
78 #undef  UCHARTYPE
79 #define UCHARTYPE gfc_char4_t
80 #undef  SUFFIX
81 #define SUFFIX(x) x ## _char4
82 #undef  MEMSET
83 #define MEMSET memset_char4
84
85 #include "string_intrinsics_inc.c"
86