pause.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Implementation of the PAUSE statement.
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. Contributed by Paul Brook <paul@nowt.org>
  4. This file is part of the GNU Fortran runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #include <string.h>
  22. #ifdef HAVE_UNISTD_H
  23. #include <unistd.h>
  24. #endif
  25. static void
  26. do_pause (void)
  27. {
  28. char buff[4];
  29. estr_write ("To resume execution, type go. "
  30. "Other input will terminate the job.\n");
  31. fgets(buff, 4, stdin);
  32. if (strncmp(buff, "go\n", 3) != 0)
  33. stop_string ('\0', 0);
  34. estr_write ("RESUMED\n");
  35. }
  36. /* A numeric PAUSE statement. */
  37. extern void pause_numeric (GFC_INTEGER_4);
  38. export_proto(pause_numeric);
  39. void
  40. pause_numeric (GFC_INTEGER_4 code)
  41. {
  42. st_printf ("PAUSE %d\n", (int) code);
  43. do_pause ();
  44. }
  45. /* A character string or blank PAUSE statement. */
  46. extern void pause_string (char *string, GFC_INTEGER_4 len);
  47. export_proto(pause_string);
  48. void
  49. pause_string (char *string, GFC_INTEGER_4 len)
  50. {
  51. estr_write ("PAUSE ");
  52. ssize_t w = write (STDERR_FILENO, string, len);
  53. (void) sizeof (w); /* Avoid compiler warning about not using write
  54. return val. */
  55. estr_write ("\n");
  56. do_pause ();
  57. }