aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>2010-09-01 08:33:11 +0000
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2010-09-01 08:33:11 +0000
commitc14c81552aa7c5f7cf837f3728580e29fe94c5ef (patch)
tree152b99416a290e053058a7bd41350fbc94980279 /gcc
parentd78552bd0f5b2494ef2efa26d9eb6c59247772ef (diff)
downloadgcc-c14c81552aa7c5f7cf837f3728580e29fe94c5ef.zip
gcc-c14c81552aa7c5f7cf837f3728580e29fe94c5ef.tar.gz
gcc-c14c81552aa7c5f7cf837f3728580e29fe94c5ef.tar.bz2
intrinsic.c: Add EXECUTE_COMMAND_LINE intrinsic.
* intrinsic.c: Add EXECUTE_COMMAND_LINE intrinsic. * intrinsic.h (gfc_resolve_execute_command_line): New function. * iresolve.c (gfc_resolve_execute_command_line): New function. * gfortran.h (GFC_ISYM_EXECUTE_COMMAND_LINE): New value. * intrinsic.texi: Document EXECUTE_COMMAND_LINE. * intrinsics/execute_command_line.c: New file. * gfortran.map (_gfortran_execute_command_line_i4, _gfortran_execute_command_line_i8): New symbols. * Makefile.am: Add new file intrinsics/execute_command_line.c. * Makefile.in: Regenerated. * gfortran.dg/execute_command_line_1.f90: New test. From-SVN: r163719
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog8
-rw-r--r--gcc/fortran/gfortran.h1
-rw-r--r--gcc/fortran/intrinsic.c9
-rw-r--r--gcc/fortran/intrinsic.h1
-rw-r--r--gcc/fortran/intrinsic.texi79
-rw-r--r--gcc/fortran/iresolve.c11
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gfortran.dg/execute_command_line_1.f9060
8 files changed, 173 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index cdceae8..e943469 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-01 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+
+ * intrinsic.c: Add EXECUTE_COMMAND_LINE intrinsic.
+ * intrinsic.h (gfc_resolve_execute_command_line): New function.
+ * iresolve.c (gfc_resolve_execute_command_line): New function.
+ * gfortran.h (GFC_ISYM_EXECUTE_COMMAND_LINE): New value.
+ * intrinsic.texi: Document EXECUTE_COMMAND_LINE.
+
2010-08-31 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/38282
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 1ee9bd5..b23c647 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -362,6 +362,7 @@ enum gfc_isym_id
GFC_ISYM_ERFC,
GFC_ISYM_ERFC_SCALED,
GFC_ISYM_ETIME,
+ GFC_ISYM_EXECUTE_COMMAND_LINE,
GFC_ISYM_EXIT,
GFC_ISYM_EXP,
GFC_ISYM_EXPONENT,
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index c14e14d..0b469ae 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -2812,6 +2812,15 @@ add_subroutines (void)
gfc_check_dtime_etime_sub, NULL, gfc_resolve_dtime_sub,
vl, BT_REAL, 4, REQUIRED, tm, BT_REAL, 4, REQUIRED);
+ add_sym_5s ("execute_command_line", GFC_ISYM_EXECUTE_COMMAND_LINE,
+ CLASS_IMPURE , BT_UNKNOWN, 0, GFC_STD_F2008,
+ NULL, NULL, gfc_resolve_execute_command_line,
+ "command", BT_CHARACTER, dc, REQUIRED, INTENT_IN,
+ "wait", BT_LOGICAL, dl, OPTIONAL, INTENT_IN,
+ "exitstat", BT_INTEGER, di, OPTIONAL, INTENT_INOUT,
+ "cmdstat", BT_INTEGER, di, OPTIONAL, INTENT_OUT,
+ "cmdmsg", BT_CHARACTER, dc, OPTIONAL, INTENT_INOUT);
+
add_sym_1s ("fdate", GFC_ISYM_FDATE, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
gfc_check_fdate_sub, NULL, gfc_resolve_fdate_sub,
dt, BT_CHARACTER, dc, REQUIRED);
diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h
index 383ada0..b06c65b 100644
--- a/gcc/fortran/intrinsic.h
+++ b/gcc/fortran/intrinsic.h
@@ -538,6 +538,7 @@ void gfc_resolve_chdir_sub (gfc_code *);
void gfc_resolve_chmod_sub (gfc_code *);
void gfc_resolve_cpu_time (gfc_code *);
void gfc_resolve_ctime_sub (gfc_code *);
+void gfc_resolve_execute_command_line (gfc_code *);
void gfc_resolve_exit (gfc_code *);
void gfc_resolve_fdate_sub (gfc_code *);
void gfc_resolve_flush (gfc_code *);
diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi
index 49b9d53..6603fb5 100644
--- a/gcc/fortran/intrinsic.texi
+++ b/gcc/fortran/intrinsic.texi
@@ -104,6 +104,7 @@ Some basic guidelines for editing this document:
* @code{ERFC}: ERFC, Complementary error function
* @code{ERFC_SCALED}: ERFC_SCALED, Exponentially-scaled complementary error function
* @code{ETIME}: ETIME, Execution time subroutine (or function)
+* @code{EXECUTE_COMMAND_LINE}: EXECUTE_COMMAND_LINE, Execute a shell command
* @code{EXIT}: EXIT, Exit the program with status.
* @code{EXP}: EXP, Exponential function
* @code{EXPONENT}: EXPONENT, Exponent function
@@ -3817,6 +3818,82 @@ end program test_etime
+@node EXECUTE_COMMAND_LINE
+@section @code{EXECUTE_COMMAND_LINE} --- Execute a shell command
+@fnindex EXECUTE_COMMAND_LINE
+@cindex system, system call
+@cindex command line
+
+@table @asis
+@item @emph{Description}:
+@code{EXECUTE_COMMAND_LINE} runs a shell command, synchronously or
+asynchronously.
+
+The @code{COMMAND} argument is passed to the shell and executed, using
+the C library's @code{system()} call. (The shell is @code{sh} on Unix
+systems, and @code{cmd.exe} on Windows.) If @code{WAIT} is present and
+has the value false, the execution of the command is asynchronous if the
+system supports it; otherwise, the command is executed synchronously.
+
+The three last arguments allow the user to get status information. After
+synchronous execution, @code{EXITSTAT} contains the integer exit code of
+the command, as returned by @code{system}. @code{CMDSTAT} is set to zero
+if the command line was executed (whatever its exit status was).
+@code{CMDMSG} is assigned an error message if an error has occurred.
+
+
+@item @emph{Standard}:
+Fortran 2008 and later
+
+@item @emph{Class}:
+Subroutine
+
+@item @emph{Syntax}:
+@code{CALL EXECUTE_COMMAND_LINE(COMMAND [, WAIT, EXITSTAT, CMDSTAT, CMDMSG ])}
+
+@item @emph{Arguments}:
+@multitable @columnfractions .15 .70
+@item @var{COMMAND} @tab Shall be a default @code{CHARACTER} scalar.
+@item @var{WAIT} @tab (Optional) Shall be a default @code{LOGICAL} scalar.
+@item @var{EXITSTAT} @tab (Optional) Shall be an @code{INTEGER} of the
+default kind.
+@item @var{CMDSTAT} @tab (Optional) Shall be an @code{INTEGER} of the
+default kind.
+@item @var{CMDMSG} @tab (Optional) Shall be an @code{CHARACTER} scalar of the
+default kind.
+@end multitable
+
+@item @emph{Example}:
+@smallexample
+program test_exec
+ integer :: i
+
+ call execute_command_line ("external_prog.exe", exitstat=i)
+ print *, "Exit status of external_prog.exe was ", i
+
+ call execute_command_line ("reindex_files.exe", wait=.false.)
+ print *, "Now reindexing files in the background"
+
+end program test_exec
+@end smallexample
+
+
+@item @emph{Note}:
+
+Because this intrinsic is implemented in terms of the @code{system()}
+function call, its behavior with respect to signalling is processor
+dependent. In particular, on POSIX-compliant systems, the SIGINT and
+SIGQUIT signals will be ignored, and the SIGCHLD will be blocked. As
+such, if the parent process is terminated, the child process might not be
+terminated alongside.
+
+
+@item @emph{See also}:
+@ref{SYSTEM}
+@end table
+
+
+
@node EXIT
@section @code{EXIT} --- Exit the program with status.
@fnindex EXIT
@@ -10955,6 +11032,8 @@ Subroutine, function
@end multitable
@item @emph{See also}:
+@ref{EXECUTE_COMMAND_LINE}, which is part of the Fortran 2008 standard
+and should considered in new code for future portability.
@end table
diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c
index 5a187ee..66df99e 100644
--- a/gcc/fortran/iresolve.c
+++ b/gcc/fortran/iresolve.c
@@ -3184,6 +3184,17 @@ gfc_resolve_system_clock (gfc_code *c)
}
+/* Resolve the EXECUTE_COMMAND_LINE intrinsic subroutine. */
+void
+gfc_resolve_execute_command_line (gfc_code *c)
+{
+ const char *name;
+ name = gfc_get_string (PREFIX ("execute_command_line_i%d"),
+ gfc_default_integer_kind);
+ c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
+}
+
+
/* Resolve the EXIT intrinsic subroutine. */
void
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d9f26d9..3acadbc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2010-09-01 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+
+ * gfortran.dg/execute_command_line_1.f90: New test.
+
2010-08-31 Jakub Jelinek <jakub@redhat.com>
PR preprocessor/45457
diff --git a/gcc/testsuite/gfortran.dg/execute_command_line_1.f90 b/gcc/testsuite/gfortran.dg/execute_command_line_1.f90
new file mode 100644
index 0000000..faaa860
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/execute_command_line_1.f90
@@ -0,0 +1,60 @@
+! { dg-do compile }
+!
+! Check that we accept all variants of the EXECUTE_COMMAND_LINE intrinsic.
+!
+ integer :: i, j
+ character(len=100) :: s
+
+ s = ""
+
+ call execute_command_line ("ls *.f90")
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("sleep 1 ; ls *.f90", .false.)
+ print *, "I'm not waiting"
+ call sleep(2)
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("sleep 1 ; ls *.f90", .true.)
+ print *, "I did wait"
+ call sleep(2)
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("ls *.f90", .true., i)
+ print *, "Exist status was: ", i
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("ls *.doesnotexist", .true., i)
+ print *, "Exist status was: ", i
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("echo foo", .true., i, j)
+ print *, "Exist status was: ", i
+ print *, "Command status was: ", j
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("echo foo", .true., i, j, s)
+ print *, "Exist status was: ", i
+ print *, "Command status was: ", j
+ print *, "Error message is: ", trim(s)
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("ls *.doesnotexist", .true., i, j, s)
+ print *, "Exist status was: ", i
+ print *, "Command status was: ", j
+ print *, "Error message is: ", trim(s)
+
+ print *, "-----------------------------"
+
+ call execute_command_line ("sleep 20", .false.)
+ print *, "Please kill me with ^C"
+ call sleep (10)
+
+ end