fbuf.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Copyright (C) 2009-2015 Free Software Foundation, Inc.
  2. Contributed by Janne Blomqvist
  3. This file is part of the GNU Fortran runtime library (libgfortran).
  4. Libgfortran is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. Libgfortran is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. Under Section 7 of GPL version 3, you are granted additional
  13. permissions described in the GCC Runtime Library Exception, version
  14. 3.1, as published by the Free Software Foundation.
  15. You should have received a copy of the GNU General Public License and
  16. a copy of the GCC Runtime Library Exception along with this program;
  17. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  18. <http://www.gnu.org/licenses/>. */
  19. #ifndef GFOR_FBUF_H
  20. #define GFOR_FBUF_H
  21. #include "io.h"
  22. /* Formatting buffer. This is a temporary scratch buffer used by
  23. formatted read and writes. After every formatted I/O statement,
  24. this buffer is flushed. This buffer is needed since not all devices
  25. are seekable, and T or TL edit descriptors require moving backwards
  26. in the record. However, advance='no' complicates the situation, so
  27. the buffer must only be partially flushed from the end of the last
  28. flush until the current position in the record. */
  29. struct fbuf
  30. {
  31. char *buf; /* Start of buffer. */
  32. int len; /* Length of buffer. */
  33. int act; /* Active bytes in buffer. */
  34. int pos; /* Current position in buffer. */
  35. };
  36. extern void fbuf_init (gfc_unit *, int);
  37. internal_proto(fbuf_init);
  38. extern void fbuf_destroy (gfc_unit *);
  39. internal_proto(fbuf_destroy);
  40. extern int fbuf_reset (gfc_unit *);
  41. internal_proto(fbuf_reset);
  42. extern char * fbuf_alloc (gfc_unit *, int);
  43. internal_proto(fbuf_alloc);
  44. extern int fbuf_flush (gfc_unit *, unit_mode);
  45. internal_proto(fbuf_flush);
  46. extern int fbuf_flush_list (gfc_unit *, unit_mode);
  47. internal_proto(fbuf_flush_list);
  48. extern int fbuf_seek (gfc_unit *, int, int);
  49. internal_proto(fbuf_seek);
  50. extern char * fbuf_read (gfc_unit *, int *);
  51. internal_proto(fbuf_read);
  52. /* Never call this function, only use fbuf_getc(). */
  53. extern int fbuf_getc_refill (gfc_unit *);
  54. internal_proto(fbuf_getc_refill);
  55. static inline int
  56. fbuf_getc (gfc_unit * u)
  57. {
  58. if (u->fbuf->pos < u->fbuf->act)
  59. return (unsigned char) u->fbuf->buf[u->fbuf->pos++];
  60. return fbuf_getc_refill (u);
  61. }
  62. static inline char *
  63. fbuf_getptr (gfc_unit * u)
  64. {
  65. return (char*) (u->fbuf->buf + u->fbuf->pos);
  66. }
  67. #endif