2004-05-13 08:41:07 +02:00
|
|
|
/* String intrinsics helper functions.
|
2014-01-02 23:25:45 +01:00
|
|
|
Copyright (C) 2008-2014 Free Software Foundation, Inc.
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
This file is part of the GNU Fortran runtime library (libgfortran).
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
Libgfortran is free software; you can redistribute it and/or
|
2005-01-12 22:27:33 +01:00
|
|
|
modify it under the terms of the GNU General Public
|
2004-05-13 08:41:07 +02:00
|
|
|
License as published by the Free Software Foundation; either
|
2009-04-09 17:00:19 +02:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
Libgfortran is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-01-12 22:27:33 +01:00
|
|
|
GNU General Public License for more details.
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2009-04-09 17:00:19 +02:00
|
|
|
Under Section 7 of GPL version 3, you are granted additional
|
|
|
|
permissions described in the GCC Runtime Library Exception, version
|
|
|
|
3.1, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License and
|
|
|
|
a copy of the GCC Runtime Library Exception along with this program;
|
|
|
|
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* Unlike what the name of this file suggests, we don't actually
|
|
|
|
implement the Fortran intrinsics here. At least, not with the
|
|
|
|
names they have in the standard. The functions here provide all
|
|
|
|
the support we need for the standard string intrinsics, and the
|
|
|
|
compiler translates the actual intrinsics calls to calls to
|
|
|
|
functions in this file. */
|
|
|
|
|
2007-08-31 16:01:34 +02:00
|
|
|
#include "libgfortran.h"
|
|
|
|
|
2004-05-13 08:41:07 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-03-28 16:18:59 +01:00
|
|
|
#include <assert.h>
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
/* Helper function to set parts of wide strings to a constant (usually
|
|
|
|
spaces). */
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
static gfc_char4_t *
|
|
|
|
memset_char4 (gfc_char4_t *b, gfc_char4_t c, size_t len)
|
2004-05-13 08:41:07 +02:00
|
|
|
{
|
2008-05-14 23:51:27 +02:00
|
|
|
size_t i;
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
b[i] = c;
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
return b;
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
2007-08-06 22:47:17 +02:00
|
|
|
|
2011-08-29 11:05:11 +02:00
|
|
|
/* Compare wide character types, which are handled internally as
|
|
|
|
unsigned 4-byte integers. */
|
|
|
|
int
|
|
|
|
memcmp_char4 (const void *a, const void *b, size_t len)
|
|
|
|
{
|
|
|
|
const GFC_UINTEGER_4 *pa = a;
|
|
|
|
const GFC_UINTEGER_4 *pb = b;
|
|
|
|
while (len-- > 0)
|
|
|
|
{
|
|
|
|
if (*pa != *pb)
|
|
|
|
return *pa < *pb ? -1 : 1;
|
|
|
|
pa ++;
|
|
|
|
pb ++;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-06 22:47:17 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
/* All other functions are defined using a few generic macros in
|
|
|
|
string_intrinsics_inc.c, so we avoid code duplication between the
|
|
|
|
various character type kinds. */
|
2007-08-06 22:47:17 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
#undef CHARTYPE
|
|
|
|
#define CHARTYPE char
|
|
|
|
#undef UCHARTYPE
|
|
|
|
#define UCHARTYPE unsigned char
|
|
|
|
#undef SUFFIX
|
|
|
|
#define SUFFIX(x) x
|
|
|
|
#undef MEMSET
|
|
|
|
#define MEMSET memset
|
2011-08-29 11:05:11 +02:00
|
|
|
#undef MEMCMP
|
|
|
|
#define MEMCMP memcmp
|
2007-08-06 22:47:17 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
#include "string_intrinsics_inc.c"
|
2007-08-06 22:47:17 +02:00
|
|
|
|
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
#undef CHARTYPE
|
|
|
|
#define CHARTYPE gfc_char4_t
|
|
|
|
#undef UCHARTYPE
|
|
|
|
#define UCHARTYPE gfc_char4_t
|
|
|
|
#undef SUFFIX
|
|
|
|
#define SUFFIX(x) x ## _char4
|
|
|
|
#undef MEMSET
|
|
|
|
#define MEMSET memset_char4
|
2011-08-29 11:05:11 +02:00
|
|
|
#undef MEMCMP
|
|
|
|
#define MEMCMP memcmp_char4
|
2007-08-06 22:47:17 +02:00
|
|
|
|
2008-05-14 23:51:27 +02:00
|
|
|
#include "string_intrinsics_inc.c"
|
2007-08-06 22:47:17 +02:00
|
|
|
|