2004-05-13 08:41:07 +02:00
|
|
|
/* String intrinsics helper functions.
|
2007-08-06 22:47:17 +02:00
|
|
|
Copyright 2002, 2005, 2007 Free Software Foundation, Inc.
|
2004-05-13 08:41:07 +02:00
|
|
|
Contributed by Paul Brook <paul@nowt.org>
|
|
|
|
|
2005-01-12 22:27:33 +01:00
|
|
|
This file is part of the GNU Fortran 95 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
|
2005-01-12 22:27:33 +01:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
In addition to the permissions in the GNU General Public License, the
|
|
|
|
Free Software Foundation gives you unlimited permission to link the
|
|
|
|
compiled version of this file into combinations with other programs,
|
|
|
|
and to distribute those combinations without any restriction coming
|
|
|
|
from the use of this file. (The General Public License restrictions
|
|
|
|
do apply in other respects; for example, they cover modification of
|
|
|
|
the file, and distribution when not linked into a combine
|
|
|
|
executable.)
|
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
|
|
|
|
2005-01-12 22:27:33 +01:00
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with libgfortran; see the file COPYING. If not,
|
2005-08-17 04:49:08 +02:00
|
|
|
write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA. */
|
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. */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-08-06 22:47:17 +02:00
|
|
|
#include <stdarg.h>
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
#include "libgfortran.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* String functions. */
|
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern void concat_string (GFC_INTEGER_4, char *,
|
|
|
|
GFC_INTEGER_4, const char *,
|
|
|
|
GFC_INTEGER_4, const char *);
|
|
|
|
export_proto(concat_string);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern GFC_INTEGER_4 string_len_trim (GFC_INTEGER_4, const char *);
|
|
|
|
export_proto(string_len_trim);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern void adjustl (char *, GFC_INTEGER_4, const char *);
|
|
|
|
export_proto(adjustl);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern void adjustr (char *, GFC_INTEGER_4, const char *);
|
|
|
|
export_proto(adjustr);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern GFC_INTEGER_4 string_index (GFC_INTEGER_4, const char *, GFC_INTEGER_4,
|
|
|
|
const char *, GFC_LOGICAL_4);
|
|
|
|
export_proto(string_index);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern GFC_INTEGER_4 string_scan (GFC_INTEGER_4, const char *, GFC_INTEGER_4,
|
|
|
|
const char *, GFC_LOGICAL_4);
|
|
|
|
export_proto(string_scan);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern GFC_INTEGER_4 string_verify (GFC_INTEGER_4, const char *, GFC_INTEGER_4,
|
|
|
|
const char *, GFC_LOGICAL_4);
|
|
|
|
export_proto(string_verify);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
extern void string_trim (GFC_INTEGER_4 *, void **, GFC_INTEGER_4, const char *);
|
|
|
|
export_proto(string_trim);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2007-08-06 22:47:17 +02:00
|
|
|
extern void string_minmax (GFC_INTEGER_4 *, void **, int, int, ...);
|
|
|
|
export_proto(string_minmax);
|
|
|
|
|
2007-08-17 15:09:23 +02:00
|
|
|
|
|
|
|
/* Use for functions which can return a zero-length string. */
|
|
|
|
static char zero_length_string = '\0';
|
|
|
|
|
|
|
|
|
2004-05-13 08:41:07 +02:00
|
|
|
/* Strings of unequal length are extended with pad characters. */
|
|
|
|
|
2007-08-11 23:31:35 +02:00
|
|
|
int
|
2004-05-13 08:41:07 +02:00
|
|
|
compare_string (GFC_INTEGER_4 len1, const char * s1,
|
|
|
|
GFC_INTEGER_4 len2, const char * s2)
|
|
|
|
{
|
|
|
|
int res;
|
2007-01-21 21:51:53 +01:00
|
|
|
const unsigned char *s;
|
2004-05-13 08:41:07 +02:00
|
|
|
int len;
|
|
|
|
|
2006-05-28 22:25:15 +02:00
|
|
|
res = memcmp (s1, s2, (len1 < len2) ? len1 : len2);
|
2004-05-13 08:41:07 +02:00
|
|
|
if (res != 0)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
if (len1 == len2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (len1 < len2)
|
|
|
|
{
|
|
|
|
len = len2 - len1;
|
2007-01-21 21:51:53 +01:00
|
|
|
s = (unsigned char *) &s2[len1];
|
2004-05-13 08:41:07 +02:00
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
len = len1 - len2;
|
2007-01-21 21:51:53 +01:00
|
|
|
s = (unsigned char *) &s1[len2];
|
2004-05-13 08:41:07 +02:00
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (len--)
|
|
|
|
{
|
|
|
|
if (*s != ' ')
|
|
|
|
{
|
|
|
|
if (*s > ' ')
|
|
|
|
return res;
|
|
|
|
else
|
|
|
|
return -res;
|
|
|
|
}
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
2004-12-12 09:59:05 +01:00
|
|
|
iexport(compare_string);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* The destination and source should not overlap. */
|
|
|
|
|
|
|
|
void
|
|
|
|
concat_string (GFC_INTEGER_4 destlen, char * dest,
|
|
|
|
GFC_INTEGER_4 len1, const char * s1,
|
|
|
|
GFC_INTEGER_4 len2, const char * s2)
|
|
|
|
{
|
|
|
|
if (len1 >= destlen)
|
|
|
|
{
|
|
|
|
memcpy (dest, s1, destlen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy (dest, s1, len1);
|
|
|
|
dest += len1;
|
|
|
|
destlen -= len1;
|
|
|
|
|
|
|
|
if (len2 >= destlen)
|
|
|
|
{
|
|
|
|
memcpy (dest, s2, destlen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (dest, s2, len2);
|
|
|
|
memset (&dest[len2], ' ', destlen - len2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Return string with all trailing blanks removed. */
|
|
|
|
|
|
|
|
void
|
c99_functions.c, [...]: Whitespace fixes.
* intrinsics/c99_functions.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/exit.c, intrinsics/flush.c,
intrinsics/ishftc.c, intrinsics/mvbits.c, intrinsics/pack_generic.c,
intrinsics/random.c, intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system_clock.c,
intrinsics/transpose_generic.c, intrinsics/unlink.c,
intrinsics/unpack_generic.c, io/backspace.c, io/format.c,
io/list_read.c, io/lock.c, io/open.c, io/transfer.c, io/unix.c,
io/write.c, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c, runtime/main.c,
runtime/memory.c, runtime/pause.c, runtime/stop.c,
runtime/string.c: Whitespace fixes.
From-SVN: r91794
2004-12-07 01:01:01 +01:00
|
|
|
string_trim (GFC_INTEGER_4 * len, void ** dest, GFC_INTEGER_4 slen,
|
|
|
|
const char * src)
|
2004-05-13 08:41:07 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Determine length of result string. */
|
|
|
|
for (i = slen - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (src[i] != ' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*len = i + 1;
|
|
|
|
|
2007-08-17 15:09:23 +02:00
|
|
|
if (*len == 0)
|
|
|
|
*dest = &zero_length_string;
|
|
|
|
else
|
2004-05-13 08:41:07 +02:00
|
|
|
{
|
|
|
|
/* Allocate space for result string. */
|
cshift0.c, [...]: Use internal_malloc_size instead of internal_malloc.
* intrinsics/cshift0.c, intrinsics/eoshift0.c, intrinsics/eoshift2.c,
intrinsics/pack_generic.c, intrinsics/string_intrinsics.c,
intrinsics/transpose_generic.c, m4/ifunction.m4, m4/matmul.m4,
m4/matmull.m4, m4/transpose.m4: Use internal_malloc_size instead
of internal_malloc.
* generated/*: Rebuild.
From-SVN: r91799
2004-12-07 01:24:44 +01:00
|
|
|
*dest = internal_malloc_size (*len);
|
2004-05-13 08:41:07 +02:00
|
|
|
|
2007-08-17 15:09:23 +02:00
|
|
|
/* Copy string if necessary. */
|
2004-05-13 08:41:07 +02:00
|
|
|
memmove (*dest, src, *len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* The length of a string not including trailing blanks. */
|
|
|
|
|
|
|
|
GFC_INTEGER_4
|
|
|
|
string_len_trim (GFC_INTEGER_4 len, const char * s)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = len - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (s[i] != ' ')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Find a substring within a string. */
|
|
|
|
|
|
|
|
GFC_INTEGER_4
|
|
|
|
string_index (GFC_INTEGER_4 slen, const char * str, GFC_INTEGER_4 sslen,
|
|
|
|
const char * sstr, GFC_LOGICAL_4 back)
|
|
|
|
{
|
|
|
|
int start;
|
|
|
|
int last;
|
|
|
|
int i;
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
if (sslen == 0)
|
|
|
|
return 1;
|
|
|
|
|
2004-08-25 02:14:07 +02:00
|
|
|
if (sslen > slen)
|
|
|
|
return 0;
|
|
|
|
|
2004-05-13 08:41:07 +02:00
|
|
|
if (!back)
|
|
|
|
{
|
|
|
|
last = slen + 1 - sslen;
|
|
|
|
start = 0;
|
|
|
|
delta = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last = -1;
|
|
|
|
start = slen - sslen;
|
|
|
|
delta = -1;
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
for (; start != last; start+= delta)
|
|
|
|
{
|
|
|
|
for (i = 0; i < sslen; i++)
|
|
|
|
{
|
|
|
|
if (str[start + i] != sstr[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == sslen)
|
|
|
|
return (start + 1);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Remove leading blanks from a string, padding at end. The src and dest
|
|
|
|
should not overlap. */
|
|
|
|
|
|
|
|
void
|
|
|
|
adjustl (char *dest, GFC_INTEGER_4 len, const char *src)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (i<len && src[i] == ' ')
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (i < len)
|
|
|
|
memcpy (dest, &src[i], len - i);
|
|
|
|
if (i > 0)
|
|
|
|
memset (&dest[len - i], ' ', i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Remove trailing blanks from a string. */
|
|
|
|
|
|
|
|
void
|
|
|
|
adjustr (char *dest, GFC_INTEGER_4 len, const char *src)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = len;
|
|
|
|
while (i > 0 && src[i - 1] == ' ')
|
2004-05-13 12:11:02 +02:00
|
|
|
i--;
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
if (i < len)
|
|
|
|
memset (dest, ' ', len - i);
|
2004-05-13 12:11:02 +02:00
|
|
|
memcpy (dest + (len - i), src, i );
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Scan a string for any one of the characters in a set of characters. */
|
|
|
|
|
|
|
|
GFC_INTEGER_4
|
|
|
|
string_scan (GFC_INTEGER_4 slen, const char * str, GFC_INTEGER_4 setlen,
|
|
|
|
const char * set, GFC_LOGICAL_4 back)
|
|
|
|
{
|
2005-11-12 20:16:40 +01:00
|
|
|
int i, j;
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
if (slen == 0 || setlen == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (back)
|
|
|
|
{
|
2005-11-12 20:16:40 +01:00
|
|
|
for (i = slen - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
for (j = 0; j < setlen; j++)
|
|
|
|
{
|
|
|
|
if (str[i] == set[j])
|
|
|
|
return (i + 1);
|
|
|
|
}
|
|
|
|
}
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-12 20:16:40 +01:00
|
|
|
for (i = 0; i < slen; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < setlen; j++)
|
|
|
|
{
|
|
|
|
if (str[i] == set[j])
|
|
|
|
return (i + 1);
|
|
|
|
}
|
|
|
|
}
|
2004-05-13 08:41:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Verify that a set of characters contains all the characters in a
|
2005-11-12 20:16:40 +01:00
|
|
|
string by identifying the position of the first character in a
|
|
|
|
characters that does not appear in a given set of characters. */
|
2004-05-13 08:41:07 +02:00
|
|
|
|
|
|
|
GFC_INTEGER_4
|
|
|
|
string_verify (GFC_INTEGER_4 slen, const char * str, GFC_INTEGER_4 setlen,
|
|
|
|
const char * set, GFC_LOGICAL_4 back)
|
|
|
|
{
|
|
|
|
int start;
|
|
|
|
int last;
|
|
|
|
int i;
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
if (slen == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (back)
|
|
|
|
{
|
2004-10-07 22:19:32 +02:00
|
|
|
last = -1;
|
2004-05-13 08:41:07 +02:00
|
|
|
start = slen - 1;
|
|
|
|
delta = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-10-07 22:19:32 +02:00
|
|
|
last = slen;
|
2004-05-13 08:41:07 +02:00
|
|
|
start = 0;
|
|
|
|
delta = 1;
|
|
|
|
}
|
|
|
|
for (; start != last; start += delta)
|
|
|
|
{
|
|
|
|
for (i = 0; i < setlen; i++)
|
|
|
|
{
|
|
|
|
if (str[start] == set[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == setlen)
|
|
|
|
return (start + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-08-06 22:47:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* MIN and MAX intrinsics for strings. The front-end makes sure that
|
|
|
|
nargs is at least 2. */
|
|
|
|
|
|
|
|
void
|
|
|
|
string_minmax (GFC_INTEGER_4 *rlen, void **dest, int op, int nargs, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int i;
|
|
|
|
char * next, * res;
|
|
|
|
GFC_INTEGER_4 nextlen, reslen;
|
|
|
|
|
|
|
|
va_start (ap, nargs);
|
|
|
|
reslen = va_arg (ap, GFC_INTEGER_4);
|
|
|
|
res = va_arg (ap, char *);
|
|
|
|
*rlen = reslen;
|
|
|
|
|
|
|
|
if (res == NULL)
|
|
|
|
runtime_error ("First argument of '%s' intrinsic should be present",
|
|
|
|
op > 0 ? "MAX" : "MIN");
|
|
|
|
|
|
|
|
for (i = 1; i < nargs; i++)
|
|
|
|
{
|
|
|
|
nextlen = va_arg (ap, GFC_INTEGER_4);
|
|
|
|
next = va_arg (ap, char *);
|
|
|
|
|
|
|
|
|
|
|
|
if (next == NULL)
|
|
|
|
{
|
|
|
|
if (i == 1)
|
|
|
|
runtime_error ("Second argument of '%s' intrinsic should be "
|
|
|
|
"present", op > 0 ? "MAX" : "MIN");
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextlen > *rlen)
|
|
|
|
*rlen = nextlen;
|
|
|
|
|
|
|
|
if (op * compare_string (reslen, res, nextlen, next) < 0)
|
|
|
|
{
|
|
|
|
reslen = nextlen;
|
|
|
|
res = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end (ap);
|
|
|
|
|
2007-08-17 15:09:23 +02:00
|
|
|
if (*rlen == 0)
|
|
|
|
*dest = &zero_length_string;
|
|
|
|
else
|
2007-08-06 22:47:17 +02:00
|
|
|
{
|
|
|
|
char * tmp = internal_malloc_size (*rlen);
|
|
|
|
memcpy (tmp, res, reslen);
|
|
|
|
memset (&tmp[reslen], ' ', *rlen - reslen);
|
|
|
|
*dest = tmp;
|
|
|
|
}
|
|
|
|
}
|