home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / lrm / chap14.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  97.3 KB  |  4,094 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. The following document is a draft  of  the  corresponding  chapter  of  the
  7. version  of  the  Ada  Reference  Manual  produced  in response to the Ansi
  8. Canvass.  It is given a limited circulation  to  Ada  implementers  and  to
  9. other groups contributing comments (according to the conventions defined in
  10. RRM.comments).  This draft should not be referred to in any publication.
  11.  
  12.  
  13.  
  14.                       ANSI-RM-14.v23 - Draft Chapter
  15.  
  16.                               14 Input-Output
  17.                                 version 23
  18.  
  19.  
  20.                                  83-02-11
  21.  
  22. This revision has addressed all comments up to #5795
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                              14. Input-Output
  78.  
  79.  
  80.  
  81. Input-output  is  provided in the language by means of predefined packages.
  82. The  generic  packages  SEQUENTIAL_IO  and  DIRECT_IO  define  input-output
  83. operations  applicable  to  files  containing  elements  of  a  given type.
  84. Additional operations for text input-output are  supplied  in  the  package
  85. TEXT_IO.   The  package  IO_EXCEPTIONS defines the exceptions needed by the
  86. above three packages.  Finally, a  package  LOW_LEVEL_IO  is  provided  for
  87. direct control of peripheral devices.
  88.  
  89. References:   direct_io  package  14.2  14.2.4, io_exceptions package 14.5,
  90. low_level_io package  14.6,  sequential_io  package  14.2  14.2.2,  text_io
  91. package 14.3
  92.  
  93.  
  94.  
  95. 14.1  External Files and File Objects
  96.  
  97.  
  98. Values input from the external environment of the program, or output to the
  99. environment, are considered to occupy external files.  An external file can
  100. be  anything external to the program that can produce a value to be read or
  101. receive a value to be written.  An external file is identified by a  string
  102. (the  name).   A  second  string  (the form) gives further system-dependent
  103. characteristics that may be associated with the file, such as the  physical
  104. organization   or   access   rights.    The   conventions   governing   the
  105. interpretation of such strings must be documented in Appendix F.
  106.  
  107. Input and output operations are expressed as operations on objects of  some
  108. file  type,  rather  than  directly in terms of the external files.  In the
  109. remainder of this chapter, the term file is always used to refer to a  file
  110. object;   the term external file is used otherwise.  The values transferred
  111. for a given file must all be of one type.
  112.  
  113. Input-output for sequential files of values of a  single  element  type  is
  114. defined  by  means  of  the generic package SEQUENTIAL_IO.  The skeleton of
  115. this package is given below.
  116.  
  117.     with IO_EXCEPTIONS;
  118.     generic
  119.        type ELEMENT_TYPE is private;
  120.     package SEQUENTIAL_IO is
  121.        type FILE_TYPE is limited private;
  122.  
  123.        type FILE_MODE is (IN_FILE, OUT_FILE);
  124.        ...
  125.        procedure OPEN (FILE : in out FILE_TYPE; ...);
  126.        ...
  127.  
  128.  
  129.                                   14 - 1
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.        procedure READ (FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE);
  139.        procedure WRITE(FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE);
  140.        ...
  141.     end SEQUENTIAL_IO;
  142.  
  143. In order to define sequential input-output for a  given  element  type,  an
  144. instantiation  of  this  generic  unit,  with  the  given  type  as  actual
  145. parameter,  must  be  declared.   The  resulting   package   contains   the
  146. declaration  of  a file type (called FILE_TYPE) for files of such elements,
  147. as well as the operations applicable to these  files,  such  as  the  OPEN,
  148. READ, and WRITE procedures.
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                   14 - 2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. Input-output  for  direct  access  files  is  likewise defined by a generic
  205. package called DIRECT_IO.  Input-output in human-readable form  is  defined
  206. by the (nongeneric) package TEXT_IO.
  207.  
  208. Before input or output operations can be performed on a file, the file must
  209. first be associated with an external file.  While such an association is in
  210. effect,  the  file is said to be open, and otherwise the file is said to be
  211. closed.
  212.  
  213. The language does not define what  happens  to  external  files  after  the
  214. completion  of the main program (in particular, if corresponding files have
  215. not  been  closed).   The  effect  of  input-output  for  access  types  is
  216. implementation-dependent.
  217.  
  218. An open file has a current mode, which is a value of one of the enumeration
  219. types
  220.  
  221.     type FILE_MODE is (IN_FILE, INOUT_FILE, OUT_FILE);  --  for DIRECT_IO
  222.     type FILE_MODE is (IN_FILE, OUT_FILE);              --  for SEQUENTIAL_IO and TEXT_IO
  223.  
  224. These  values correspond respectively to the cases where only reading, both
  225. reading and writing, or only writing are to be performed.  The  mode  of  a
  226. file can be changed.
  227.  
  228. Several  file  management  operations  are common to the three input-output
  229. packages.  These operations are described in section 14.2.1 for  sequential
  230. and  direct files.  Any additional effects concerning text input-output are
  231. described in section 14.3.1.
  232.  
  233. The exceptions that can be raised by a call of an  input-output  subprogram
  234. are  all  defined  in  the  package IO_EXCEPTIONS;  the situations in which
  235. they can be raised are described, either following the description  of  the
  236. subprogram  (and  in  section  14.4), or in Appendix F in the case of error
  237. situations that are implementation-dependent.
  238.  
  239. Notes:
  240.  
  241. Each instantiation of the  generic  packages  SEQUENTIAL_IO  and  DIRECT_IO
  242. declares  a  different  type  FILE_TYPE;   in the case of TEXT_IO, the type
  243. FILE_TYPE is unique.
  244.  
  245. A bidirectional device  can  often  be  modeled  as  two  sequential  files
  246. associated  with the device, one of mode IN_FILE, and one of mode OUT_FILE.
  247. An implementation may restrict the number of files that may  be  associated
  248. with a given external file.  The effect of sharing an external file in this
  249. way by several file objects is implementation-dependent.
  250.  
  251. References:   create  procedure  14.2.1,  current  index 14.2, current size
  252. 14.2, delete procedure 14.2.1, direct access 14.2,  direct  file  procedure
  253. 14.2,  direct_io  package  14.1 14.2, enumeration type 3.5.1, exception 11,
  254. file mode 14.2.3,  generic  instantiation  12.3,  index  14.2,  input  file
  255. 14.2.2,  io_exceptions package 14.5, open file 14.1, open procedure 14.2.1,
  256. output  file  14.2.2,  read  procedure  14.2.4,  sequential  access   14.2,
  257. sequential file 14.2, sequential input-output 14.2.2, sequential_io package
  258. 14.2 14.2.2, string 3.6.3, text_io package 14.3, write procedure 14.2.4
  259.  
  260.  
  261.                                   14 - 3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. 14.2  Sequential and Direct Files
  271.  
  272.  
  273. Two  kinds  of access to external files are defined:  sequential access and
  274. direct access.  The corresponding file types and the associated  operations
  275. are  provided  by the generic packages SEQUENTIAL_IO and DIRECT_IO.  A file
  276. object to be used for sequential access is called a  sequential  file,  and
  277. one to be used for direct access is called a direct file.
  278.  
  279. For  sequential access, the file is viewed as a sequence of values that are
  280. transferred in the order of their appearance (as produced by the program or
  281. by the environment).  When the file is opened,  transfer  starts  from  the
  282. beginning of the file.
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                   14 - 4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. For  direct  access,  the  file  is  viewed  as a set of elements occupying
  337. consecutive positions in linear order;  a value can be  transferred  to  or
  338. from  an  element of the file at any selected position.  The position of an
  339. element is specified by its index, which is a number, greater than zero, of
  340. the implementation-defined integer type COUNT.  The first element, if  any,
  341. has  index  one;   the  index  of  the  last element, if any, is called the
  342. current size;  the current size is zero if  there  are  no  elements.   The
  343. current size is a property of the external file.
  344.  
  345. An  open  direct  file has a current index, which is the index that will be
  346. used by the next read or write operation.  When a direct  file  is  opened,
  347. the  current  index is set to one.  The current index of a direct file is a
  348. property of a file object, not of an external file.
  349.  
  350. All three file modes are allowed for direct files.  The only allowed  modes
  351. for sequential files are the modes IN_FILE and OUT_FILE.
  352.  
  353. References:  count type 14.3, file mode 14.1, in_file 14.1, out_file 14.1
  354.  
  355.  
  356.  
  357. 14.2.1  File Management
  358.  
  359.  
  360. The  procedures  and  functions  described  in this section provide for the
  361. control of external files;  their declarations are repeated in each of  the
  362. three  packages  for  sequential,  direct, and text input-output.  For text
  363. input-output, the  procedures  CREATE,  OPEN,  and  RESET  have  additional
  364. effects described in section 14.3.1.
  365.  
  366.     procedure CREATE(FILE : in out FILE_TYPE;
  367.                      MODE : in FILE_MODE := DEFAULT_MODE;
  368.                      NAME : in STRING := "";
  369.                      FORM : in STRING := "");
  370.  
  371.           Establishes  a  new  external file, with the given name and form,
  372.           and associates this external file with the given file.  The given
  373.           file is left open.  The current mode of the given file is set  to
  374.           the  given  access  mode.   The  default  access mode is the mode
  375.           OUT_FILE for sequential and text input-output;  it  is  the  mode
  376.           INOUT_FILE  for direct input-output.  For direct access, the size
  377.           of the created file is implementation-dependent.  A  null  string
  378.           for  NAME specifies an external file that is not accessible after
  379.           the completion of the main program (a temporary  file).   A  null
  380.           string  for  FORM specifies the use of the default options of the
  381.           implementation for the external file.
  382.  
  383.           The exception STATUS_ERROR is raised if the given file is already
  384.           open.  The exception NAME_ERROR is raised if the string given  as
  385.           NAME  does not allow the identification of an external file.  The
  386.           exception USE_ERROR is raised if, for  the  specified  mode,  the
  387.           environment  does  not  support creation of an external file with
  388.           the given name (in the absence of NAME_ERROR) and form.
  389.  
  390.  
  391.  
  392.  
  393.                                   14 - 5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.     procedure OPEN(FILE : in out FILE_TYPE;
  404.                    MODE : in FILE_MODE;
  405.                    NAME : in STRING;
  406.                    FORM : in STRING := "");
  407.  
  408.           Associates the given file with an existing external  file  having
  409.           the  given  name and form, and sets the current mode of the given
  410.           file to the given mode.  The given file is left open.
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                   14 - 6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.           The exception STATUS_ERROR is raised if the given file is already
  469.           open.  The exception NAME_ERROR is raised if the string given  as
  470.           NAME  does  not allow the identification of an external file;  in
  471.           particular, this exception is raised if no external file with the
  472.           given name exists.  The exception USE_ERROR is raised if, for the
  473.           specified mode, the environment does not support opening  for  an
  474.           external  file with the given name (in the absence of NAME_ERROR)
  475.           and form.
  476.  
  477.  
  478.     procedure CLOSE(FILE : in out FILE_TYPE);
  479.  
  480.           Severs the association between the given file and its  associated
  481.           external file.  The given file is left closed.
  482.  
  483.           The  exception  STATUS_ERROR  is  raised if the given file is not
  484.           open.
  485.  
  486.  
  487.     procedure DELETE(FILE : in out FILE_TYPE);
  488.  
  489.           Deletes the external file associated with the  given  file.   The
  490.           given file is closed, and the external file ceases to exist.
  491.  
  492.           The  exception  STATUS_ERROR  is  raised if the given file is not
  493.           open.  The exception USE_ERROR is raised if (as fully defined  in
  494.           Appendix F) deletion of the external file is not supported by the
  495.           environment.
  496.  
  497.  
  498.     procedure RESET(FILE : in out FILE_TYPE; MODE : in FILE_MODE);
  499.     procedure RESET(FILE : in out FILE_TYPE);
  500.  
  501.           Resets  the  given  file  so  that reading from or writing to its
  502.           elements can be restarted from the beginning  of  the  file;   in
  503.           particular,  for  direct access this means that the current index
  504.           is set to one.  If a MODE parameter is supplied, the current mode
  505.           of the given file is set to the given mode.
  506.  
  507.           The exception STATUS_ERROR is raised if the  file  is  not  open.
  508.           The  exception  USE_ERROR  is  raised if the environment does not
  509.           support resetting  for  the  external  file  and,  also,  if  the
  510.           environment  does not support resetting to the specified mode for
  511.           the external file.
  512.  
  513.  
  514.     function MODE(FILE : in FILE_TYPE) return FILE_MODE;
  515.  
  516.           Returns the current mode of the given file.
  517.  
  518.           The exception STATUS_ERROR is raised if the file is not open.
  519.  
  520.  
  521.     function NAME(FILE : in FILE_TYPE) return STRING;
  522.  
  523.  
  524.  
  525.                                   14 - 7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.           Returns a string which  uniquely  identifies  the  external  file
  535.           currently associated with the given file (and may thus be used in
  536.           an   OPEN  operation).   If  an  environment  allows  alternative
  537.           specifications of the  name  (for  example,  abbreviations),  the
  538.           string  returned  by  the  function  should  correspond to a full
  539.           specification of the name.
  540.  
  541.           The exception STATUS_ERROR is raised if the  given  file  is  not
  542.           open.
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                   14 - 8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.     function FORM(FILE : in FILE_TYPE) return STRING;
  602.  
  603.           Returns   the   form  string  for  the  external  file  currently
  604.           associated  with  the  given  file.   If  an  environment  allows
  605.           alternative    specifications   of   the   form   (for   example,
  606.           abbreviations using default options), the string returned by  the
  607.           function  should  correspond to a full specification (that is, it
  608.           should  indicate  explicitly  all  options  selected,   including
  609.           default options).
  610.  
  611.           The  exception  STATUS_ERROR  is  raised if the given file is not
  612.           open.
  613.  
  614.  
  615.     function IS_OPEN(FILE : in FILE_TYPE) return BOOLEAN;
  616.  
  617.           Returns TRUE if the file is open (that is, if  it  is  associated
  618.           with an external file), otherwise returns FALSE.
  619.  
  620. References:  current mode 14.1, current size 14.1, closed file 14.1, direct
  621. access  14.2, external file 14.1, file 14.1, file_mode type 14.1, file_type
  622. type 14.1, form string 14.1, inout_file  14.2.4,  mode  14.1,  name  string
  623. 14.1,   name_error   exception   14.4,   open  file  14.1,  out_file  14.1,
  624. status_error exception 14.4, use_error exception 14.4
  625.  
  626.  
  627.  
  628. 14.2.2  Sequential Input-Output
  629.  
  630.  
  631. The operations available for sequential input and output are  described  in
  632. this  section.   The  exception  STATUS_ERROR  is  raised  if  any of these
  633. operations is attempted for a file that is not open.
  634.  
  635.  
  636.     procedure READ(FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE);
  637.  
  638.           Operates on a file of mode IN_FILE.  Reads an  element  from  the
  639.           given  file,  and  returns  the value of this element in the ITEM
  640.           parameter.
  641.  
  642.           The exception MODE_ERROR is raised if the mode  is  not  IN_FILE.
  643.           The exception END_ERROR is raised if no more elements can be read
  644.           from  the  given file.  The exception DATA_ERROR is raised if the
  645.           element read cannot  be  interpreted  as  a  value  of  the  type
  646.           ELEMENT_TYPE;  however, an implementation is allowed to omit this
  647.           check if performing the check is too complex.
  648.  
  649.  
  650.     procedure WRITE(FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE);
  651.  
  652.           Operates on a file of mode OUT_FILE.  Writes the value of ITEM to
  653.           the given file.
  654.  
  655.  
  656.  
  657.                                   14 - 9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.           The  exception  MODE_ERROR is raised if the mode is not OUT_FILE.
  667.           The exception USE_ERROR is raised if the capacity of the external
  668.           file is exceeded.
  669.  
  670.  
  671.     function END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
  672.  
  673.           Operates on a file of mode IN_FILE.   Returns  TRUE  if  no  more
  674.           elements  can  be  read  from  the given file;  otherwise returns
  675.           FALSE.
  676.  
  677.           The exception MODE_ERROR is raised if the mode is not IN_FILE.
  678.  
  679. References:  data_error exception 14.4, element  14.1,  element_type  14.1,
  680. end_error  exception  14.4,  external file 14.1, file 14.1, file mode 14.1,
  681. file_type 14.1, in_file 14.1, mode_error  exception  14.4,  out_file  14.1,
  682. status_error exception 14.4, use_error exception 14.4
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                   14 - 10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. 14.2.3  Specification of the Package Sequential_IO
  733.  
  734.  
  735.  
  736.     with IO_EXCEPTIONS;
  737.     generic
  738.        type ELEMENT_TYPE is private;
  739.     package SEQUENTIAL_IO is
  740.  
  741.        type FILE_TYPE is limited private;
  742.  
  743.        type FILE_MODE is (IN_FILE, OUT_FILE);
  744.  
  745.  
  746.        -- File management
  747.  
  748.        procedure CREATE(FILE : in out FILE_TYPE;
  749.                         MODE : in FILE_MODE := OUT_FILE;
  750.                         NAME : in STRING := "";
  751.                         FORM : in STRING := "");
  752.  
  753.        procedure OPEN  (FILE : in out FILE_TYPE;
  754.                         MODE : in FILE_MODE;
  755.                         NAME : in STRING;
  756.                         FORM : in STRING := "");
  757.  
  758.        procedure CLOSE (FILE : in out FILE_TYPE);
  759.        procedure DELETE(FILE : in out FILE_TYPE);
  760.        procedure RESET (FILE : in out FILE_TYPE; MODE : in FILE_MODE);
  761.        procedure RESET (FILE : in out FILE_TYPE);
  762.  
  763.        function MODE   (FILE : in FILE_TYPE) return FILE_MODE;
  764.        function NAME   (FILE : in FILE_TYPE) return STRING;
  765.        function FORM   (FILE : in FILE_TYPE) return STRING;
  766.  
  767.        function IS_OPEN(FILE : in FILE_TYPE) return BOOLEAN;
  768.  
  769.        -- Input and output operations
  770.  
  771.        procedure READ  (FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE);
  772.        procedure WRITE (FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE);
  773.  
  774.        function END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
  775.  
  776.        -- Exceptions
  777.  
  778.        STATUS_ERROR : exception renames IO_EXCEPTIONS.STATUS_ERROR;
  779.        MODE_ERROR   : exception renames IO_EXCEPTIONS.MODE_ERROR;
  780.        NAME_ERROR   : exception renames IO_EXCEPTIONS.NAME_ERROR;
  781.        USE_ERROR    : exception renames IO_EXCEPTIONS.USE_ERROR;
  782.        DEVICE_ERROR : exception renames IO_EXCEPTIONS.DEVICE_ERROR;
  783.        END_ERROR    : exception renames IO_EXCEPTIONS.END_ERROR;
  784.        DATA_ERROR   : exception renames IO_EXCEPTIONS.DATA_ERROR;
  785.  
  786.  
  787.  
  788.  
  789.                                   14 - 11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.     private
  799.        -- implementation-dependent
  800.     end SEQUENTIAL_IO;
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                   14 - 12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. References:   close  procedure  14.2.1, create procedure 14.2.1, data_error
  865. exception 14.4,  delete  procedure  14.2.1,  device_error  exception  14.4,
  866. end_error  exception  14.4,  end_of_file  function  14.2.2, file_mode 14.1,
  867. file_type 14.1, form function 14.2.1,  in_file  14.1,  io_exceptions  14.4,
  868. is_open  function  14.2.1, mode function 14.2.1, mode_error exception 14.4,
  869. name function 14.2.1, name_error exception  14.4,  open  procedure  14.2.1,
  870. out_file 14.1, read procedure 14.2.2, reset procedure 14.2.1, sequential_io
  871. package 14.2 14.2.2, status_error exception 14.4, use_error exception 14.4,
  872. write procedure 14.2.2,
  873.  
  874.  
  875.  
  876.  
  877. 14.2.4  Direct Input-Output
  878.  
  879.  
  880. The  operations available for direct input and output are described in this
  881. section.  The exception STATUS_ERROR is raised if any of  these  operations
  882. is attempted for a file that is not open.
  883.  
  884.     procedure READ(FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE;
  885.                                         FROM : in  POSITIVE_COUNT);
  886.     procedure READ(FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE);
  887.  
  888.           Operates on a file of mode IN_FILE or INOUT_FILE.  In the case of
  889.           the  first  form, sets the current index of the given file to the
  890.           index value given by the parameter FROM.  Then (for  both  forms)
  891.           returns,  in  the  parameter ITEM, the value of the element whose
  892.           position in the given file is specified by the current  index  of
  893.           the file;  finally, increases the current index by one.
  894.  
  895.           The  exception MODE_ERROR is raised if the mode of the given file
  896.           is OUT_FILE.  The exception END_ERROR is raised if the  index  to
  897.           be  used  exceeds  the  size of the external file.  The exception
  898.           DATA_ERROR is raised if the element read cannot be interpreted as
  899.           a value of the type ELEMENT_TYPE;  however, an implementation  is
  900.           allowed  to  omit  this  check  if  performing  the  check is too
  901.           complex.
  902.  
  903.  
  904.     procedure WRITE(FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE;
  905.                                          TO   : in POSITIVE_COUNT);
  906.     procedure WRITE(FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE);
  907.  
  908.           Operates on a file of mode INOUT_FILE or OUT_FILE.  In  the  case
  909.           of  the first form, sets the index of the given file to the index
  910.           value given by the parameter TO.  Then (for both forms) gives the
  911.           value of the parameter ITEM to the element whose position in  the
  912.           given  file  is  specified  by  the  current  index  of the file;
  913.           finally, increases the current index by one.
  914.  
  915.           The exception MODE_ERROR is raised if the mode of the given  file
  916.           is IN_FILE.  The exception USE_ERROR is raised if the capacity of
  917.           the external file is exceeded.
  918.  
  919.  
  920.  
  921.                                   14 - 13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.     procedure SET_INDEX(FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
  932.  
  933.           Operates  on  a  file of any mode.  Sets the current index of the
  934.           given file to the given index value (which may exceed the current
  935.           size of the file).
  936.  
  937.  
  938.     function INDEX(FILE : in FILE_TYPE) return POSITIVE_COUNT;
  939.  
  940.           Operates on a file of any mode.  Returns the current index of the
  941.           given file.
  942.  
  943.  
  944.  
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956.  
  957.  
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.                                   14 - 14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.     function SIZE(FILE : in FILE_TYPE) return COUNT;
  998.  
  999.           Operates on a file of any mode.  Returns the current size of  the
  1000.           external file that is associated with the given file.
  1001.  
  1002.     function END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
  1003.  
  1004.           Operates  on  a file of mode IN_FILE or INOUT_FILE.  Returns TRUE
  1005.           if the current index exceeds  the  size  of  the  external  file;
  1006.           otherwise returns FALSE.
  1007.  
  1008.           The  exception MODE_ERROR is raised if the mode of the given file
  1009.           is OUT_FILE.
  1010.  
  1011. References:  count type  14.2,  current  index  14.2,  current  size  14.2,
  1012. data_error  exception  14.4,  element  14.1,  element_type  14.1, end_error
  1013. exception 14.4, external file 14.1, file 14.1, file  mode  14.1,  file_type
  1014. 14.1, in_file 14.1, index 14.2, inout_file 14.1, mode_error exception 14.4,
  1015. open file 14.1, positive_count 14.3, status_error exception 14.4, use_error
  1016. exception 14.4
  1017.  
  1018.  
  1019.  
  1020.  
  1021. 14.2.5  Specification of the Package Direct_IO
  1022.  
  1023.  
  1024.  
  1025.     with IO_EXCEPTIONS;
  1026.     generic
  1027.        type ELEMENT_TYPE is private;
  1028.     package DIRECT_IO is
  1029.  
  1030.        type FILE_TYPE is limited private;
  1031.  
  1032.        type    FILE_MODE is (IN_FILE, INOUT_FILE, OUT_FILE);
  1033.        type    COUNT     is range 0 .. IMPLEMENTATION_DEFINED;
  1034.        subtype POSITIVE_COUNT is COUNT range 1 .. COUNT'LAST;
  1035.  
  1036.  
  1037.        -- File management
  1038.  
  1039.        procedure CREATE(FILE : in out FILE_TYPE;
  1040.                         MODE : in FILE_MODE := INOUT_FILE;
  1041.                         NAME : in STRING := "";
  1042.                         FORM : in STRING := "");
  1043.  
  1044.        procedure OPEN  (FILE : in out FILE_TYPE;
  1045.                         MODE : in FILE_MODE;
  1046.                         NAME : in STRING;
  1047.                         FORM : in STRING := "");
  1048.  
  1049.        procedure CLOSE (FILE : in out FILE_TYPE);
  1050.        procedure DELETE(FILE : in out FILE_TYPE);
  1051.  
  1052.  
  1053.                                   14 - 15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.        procedure RESET (FILE : in out FILE_TYPE; MODE : in FILE_MODE);
  1063.        procedure RESET (FILE : in out FILE_TYPE);
  1064.  
  1065.        function MODE   (FILE : in FILE_TYPE) return FILE_MODE;
  1066.        function NAME   (FILE : in FILE_TYPE) return STRING;
  1067.        function FORM   (FILE : in FILE_TYPE) return STRING;
  1068.  
  1069.        function IS_OPEN(FILE : in FILE_TYPE) return BOOLEAN;
  1070.  
  1071.  
  1072.  
  1073.  
  1074.  
  1075.  
  1076.  
  1077.  
  1078.  
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                   14 - 16
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.        -- Input and output operations
  1129.  
  1130.        procedure READ (FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE; FROM : POSITIVE_COUNT);
  1131.        procedure READ (FILE : in FILE_TYPE; ITEM : out ELEMENT_TYPE);
  1132.  
  1133.        procedure WRITE(FILE : in FILE_TYPE; ITEM : in  ELEMENT_TYPE; TO : POSITIVE_COUNT);
  1134.        procedure WRITE(FILE : in FILE_TYPE; ITEM : in ELEMENT_TYPE);
  1135.  
  1136.        procedure SET_INDEX(FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
  1137.  
  1138.        function INDEX(FILE : in FILE_TYPE) return POSITIVE_COUNT;
  1139.        function SIZE (FILE : in FILE_TYPE) return COUNT;
  1140.  
  1141.        function END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
  1142.  
  1143.        -- Exceptions
  1144.  
  1145.        STATUS_ERROR : exception renames IO_EXCEPTIONS.STATUS_ERROR;
  1146.        MODE_ERROR   : exception renames IO_EXCEPTIONS.MODE_ERROR;
  1147.        NAME_ERROR   : exception renames IO_EXCEPTIONS.NAME_ERROR;
  1148.        USE_ERROR    : exception renames IO_EXCEPTIONS.USE_ERROR;
  1149.        DEVICE_ERROR : exception renames IO_EXCEPTIONS.DEVICE_ERROR;
  1150.        END_ERROR    : exception renames IO_EXCEPTIONS.END_ERROR;
  1151.        DATA_ERROR   : exception renames IO_EXCEPTIONS.DATA_ERROR;
  1152.  
  1153.     private
  1154.        -- implementation-dependent
  1155.     end DIRECT_IO;
  1156.  
  1157.  
  1158. References  close  procedure  14.2.1,  count  type  14.2,  create procedure
  1159. 14.2.1, data_error exception 14.4, default_mode  14.2.5,  delete  procedure
  1160. 14.2.1,   device_error   exception  14.4,  element_type  14.2.4,  end_error
  1161. exception 14.4, end_of_file function 14.2.4,  file_mode  14.2.5,  file_type
  1162. 14.2.4,  form  function  14.2.1,  in_file  14.2.4,  index  function 14.2.4,
  1163. inout_file 14.2.4 14.2.1,  io_exceptions  package  14.4,  is_open  function
  1164. 14.2.1,  mode  function  14.2.1,  mode_error  exception 14.4, name function
  1165. 14.2.1, name_error exception 14.4, open procedure 14.2.1, out_file  14.2.1,
  1166. read  procedure  14.2.4,  set_index procedure 14.2.4, size function 14.2.4,
  1167. status_error exception 14.4,  use_error  exception  14.4,  write  procedure
  1168. 14.2.4 14.2.1
  1169.  
  1170.  
  1171.  
  1172.  
  1173. 14.3  Text Input-Output
  1174.  
  1175.  
  1176. This  section  describes the package TEXT_IO, which provides facilities for
  1177. input and output in human-readable form.  Each  file  is  read  or  written
  1178. sequentially,  as  a  sequence  of  characters grouped into lines, and as a
  1179. sequence of lines grouped into pages.  The specification of the package  is
  1180. given below in section 14.3.10.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                   14 - 17
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194. The  facilities  for  file  management  given above, in sections 14.2.1 and
  1195. 14.2.2, are available for text input-output.  In place of READ  and  WRITE,
  1196. however,  there  are  procedures  GET and PUT that input values of suitable
  1197. types from text files,  and  output  values  to  them.   These  values  are
  1198. provided  to  the  PUT procedures, and returned by the GET procedures, in a
  1199. parameter ITEM.  Several overloaded procedures of these  names  exist,  for
  1200. different  types of ITEM.  These GET procedures analyze the input sequences
  1201. of  characters  as  lexical  elements  (see  Chapter  2)  and  return   the
  1202. corresponding  values;   the  PUT  procedures  output  the  given values as
  1203. appropriate lexical elements.  Procedures GET and PUT  are  also  available
  1204. that  input  and  output  individual characters treated as character values
  1205. rather than as lexical elements.
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                   14 - 18
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260. In addition to the procedures GET and PUT for numeric and enumeration types
  1261. of ITEM that operate on text files, analogous procedures are provided  that
  1262. read  from  and  write  to  a  parameter  of type STRING.  These procedures
  1263. perform the same analysis and composition of character sequences  as  their
  1264. counterparts which have a file parameter.
  1265.  
  1266. For  all  GET  and  PUT procedures that operate on text files, and for many
  1267. other subprograms, there are forms with and without a file parameter.  Each
  1268. such GET procedure operates on an input file, and each such  PUT  procedure
  1269. operates  on an output file.  If no file is specified, a default input file
  1270. or a default output file is used.
  1271.  
  1272. At the beginning of program execution the default input  and  output  files
  1273. are  the  so-called  standard  input  file and standard output file.  These
  1274. files are open, have respectively the current modes IN_FILE  and  OUT_FILE,
  1275. and   are   associated  with  two  implementation-defined  external  files.
  1276. Procedures are provided to change the current default input  file  and  the
  1277. current default output file.
  1278.  
  1279. From a logical point of view, a text file is a sequence of pages, a page is
  1280. a  sequence of lines, and a line is a sequence of characters;  the end of a
  1281. line is marked by a line terminator;  the end of a page is  marked  by  the
  1282. combination of a line terminator immediately followed by a page terminator;
  1283. and  the  end  of  a file is marked by the combination of a line terminator
  1284. immediately followed by a page  terminator  and  then  a  file  terminator.
  1285. Terminators  are  generated  during  output;  either by calls of procedures
  1286. provided expressly for that  purpose;   or  implicitly  as  part  of  other
  1287. operations, for example, when a bounded line length, a bounded page length,
  1288. or both, have been specified for a file.
  1289.  
  1290. The  actual  nature of terminators is not defined by the language and hence
  1291. depends on the implementation.   Although  terminators  are  recognized  or
  1292. generated   by  certain  of  the  procedures  that  follow,  they  are  not
  1293. necessarily implemented  as  characters  or  as  sequences  of  characters.
  1294. Whether  they  are  characters  (and  if  so  which ones) in any particular
  1295. implementation need not concern a user who neither explicitly  outputs  nor
  1296. explicitly  inputs  control  characters.   The effect of input or output of
  1297. control characters (other than horizontal tabulation) is not defined by the
  1298. language.
  1299.  
  1300. The characters of a line are numbered, starting from one;  the number of  a
  1301. character  is  called  its  column number.  For a line terminator, a column
  1302. number is also defined:  it is one more than the number  of  characters  in
  1303. the  line.   The  lines  of  a page, and the pages of a file, are similarly
  1304. numbered.  The current column number is  the  column  number  of  the  next
  1305. character or line terminator to be transferred.  The current line number is
  1306. the  number  of the current line.  The current page number is the number of
  1307. the current page.  These numbers are values of the  subtype  POSITIVE_COUNT
  1308. of  the type COUNT (by convention, the value zero of the type COUNT is used
  1309. to indicate special conditions).
  1310.  
  1311.     type COUNT is range 0 .. implementation_defined;
  1312.     subtype POSITIVE_COUNT is COUNT range 1 .. COUNT'LAST;
  1313.  
  1314.  
  1315.  
  1316.  
  1317.                                   14 - 19
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326. For an output file, a maximum line length can be specified  and  a  maximum
  1327. page  length  can  be specified.  If a value to be output cannot fit on the
  1328. current line, for a specified maximum line  length,  then  a  new  line  is
  1329. automatically  started  before  the value is output;  if, further, this new
  1330. line cannot fit on the current page, for a specified maximum  page  length,
  1331. then  a  new  page  is  automatically  started  before the value is output.
  1332. Functions are provided to determine the maximum line length and the maximum
  1333. page length.  When a file is opened with mode  OUT_FILE,  both  values  are
  1334. zero:  by convention, this means that the line lengths and page lengths are
  1335. unbounded.   (Consequently,  output  consists  of  a  single  line  if  the
  1336. subprograms for explicit control of line and page structure are not  used.)
  1337. The constant UNBOUNDED is provided for this purpose.
  1338.  
  1339. References:  count type 14.3.10, default current input file 14.3.2, default
  1340. current  output  file  14.3.2, external file 14.1, file 14.1, get procedure
  1341. 14.3.5, in_file 14.1, out_file 14.1, put  procedure  14.3.5,  read  14.2.2,
  1342. sequential  access  14.1,  standard input file 14.3.2, standard output file
  1343. 14.3.2
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                   14 - 20
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392. 14.3.1  File Management
  1393.  
  1394.  
  1395. The only allowed file modes for  text  files  are  the  modes  IN_FILE  and
  1396. OUT_FILE.   The  subprograms  given  in  section  14.2.1 for the control of
  1397. external files, and the function END_OF_FILE given in  section  14.2.2  for
  1398. sequential  input-output, are also available for text files.  There is also
  1399. a version of END_OF_FILE that refers to the  current  default  input  file.
  1400. For text files, the procedures have the following additional effects:
  1401.  
  1402.   -  For the procedures CREATE and OPEN:  After opening a  file  with  mode
  1403.      OUT_FILE, the page length and line length are unbounded (both have the
  1404.      conventional  value  zero).  After opening a file with mode IN_FILE or
  1405.      OUT_FILE, the current column, current line, and current  page  numbers
  1406.      are set to one.
  1407.  
  1408.   -  For the procedure CLOSE:  If the file has the current  mode  OUT_FILE,
  1409.      has the effect of calling NEW_PAGE, unless the current page is already
  1410.      terminated; then outputs a file terminator.
  1411.  
  1412.   -  For the procedure RESET:  If the file has the current  mode  OUT_FILE,
  1413.      has the effect of calling NEW_PAGE, unless the current page is already
  1414.      terminated;   then outputs a file terminator.  If the new file mode is
  1415.      OUT_FILE, the page and line lengths are unbounded.  For all modes, the
  1416.      current column, line, and page numbers are set to one.
  1417.  
  1418. The exception MODE_ERROR is raised by the procedure RESET upon  an  attempt
  1419. to change the mode of a file that is either the current default input file,
  1420. or the current default output file.
  1421.  
  1422. References:   create  procedure 14.2.1, current column number 14.3, current
  1423. default input file 14.3, current line  number  14.3,  current  page  number
  1424. 14.3, end_of_file 14.3, external file 14.1, file 14.1, file mode 14.1, file
  1425. terminator 14.3, in_file 14.1, line length 14.3, mode_error exception 14.4,
  1426. open  procedure  14.2.1,  out_file  14.1, page length 14.3, reset procedure
  1427. 14.2.1
  1428.  
  1429.  
  1430.  
  1431. 14.3.2  Default Input and Output Files
  1432.  
  1433.  
  1434. The following subprograms provide for the control of the particular default
  1435. files that are used when a file parameter is omitted from  a  GET,  PUT  or
  1436. other operation of text input-output described below.
  1437.  
  1438.  
  1439.     procedure SET_INPUT(FILE : in FILE_TYPE);
  1440.  
  1441.           Operates  on  a  file  of mode IN_FILE.  Sets the current default
  1442.           input file to FILE.
  1443.  
  1444.           The exception STATUS_ERROR is raised if the  given  file  is  not
  1445.           open.   The  exception  MODE_ERROR  is  raised if the mode of the
  1446.           given file is not IN_FILE.
  1447.  
  1448.  
  1449.                                   14 - 21
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.     procedure SET_OUTPUT(FILE : in FILE_TYPE);
  1460.  
  1461.           Operates on a file of mode OUT_FILE.  Sets  the  current  default
  1462.           output file to FILE.
  1463.  
  1464.           The  exception  STATUS_ERROR  is  raised if the given file is not
  1465.           open.  The exception MODE_ERROR is raised  if  the  mode  of  the
  1466.           given file is not OUT_FILE.
  1467.  
  1468.  
  1469.  
  1470.  
  1471.  
  1472.  
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                   14 - 22
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.     function STANDARD_INPUT return FILE_TYPE;
  1526.  
  1527.           Returns the standard input file (see 14.3).
  1528.  
  1529.  
  1530.     function STANDARD_OUTPUT return FILE_TYPE;
  1531.  
  1532.           Returns the standard output file (see 14.3).
  1533.  
  1534.  
  1535.     function CURRENT_INPUT return FILE_TYPE;
  1536.  
  1537.           Returns the current default input file.
  1538.  
  1539.  
  1540.     function CURRENT_OUTPUT return FILE_TYPE;
  1541.  
  1542.           Returns the current default output file.
  1543.  
  1544.  
  1545. Note:
  1546.  
  1547. The  standard input and the standard output files cannot be opened, closed,
  1548. reset,  or  deleted,  because  the  parameter  FILE  of  the  corresponding
  1549. procedures has the mode in out.
  1550.  
  1551. References:   current default file 14.3, default file 14.3, file_type 14.1,
  1552. get procedure 14.3.5, mode_error  exception  14.4,  put  procedure  14.3.5,
  1553. status_error exception 14.4
  1554.  
  1555.  
  1556.  
  1557. 14.3.3  Specification of Line and Page Lengths
  1558.  
  1559.  
  1560. The  subprograms  described in this section are concerned with the line and
  1561. page structure of a file of mode OUT_FILE.  They operate either on the file
  1562. given as the first parameter, or, in the absence of such a file  parameter,
  1563. on the current default output file.  They provide for output of text with a
  1564. specified  maximum  line  length  or page length.  In these cases, line and
  1565. page terminators are output implicitly and automatically when needed.  When
  1566. line  and  page  lengths  are  unbounded  (that  is,  when  they  have  the
  1567. conventional  value zero), as in the case of a newly opened file, new lines
  1568. and new pages are only started when explicitly called for.
  1569.  
  1570. In all cases, the exception STATUS_ERROR is raised if the file to  be  used
  1571. is  not open; the exception MODE_ERROR is raised if the mode of the file is
  1572. not OUT_FILE.
  1573.  
  1574.  
  1575.     procedure SET_LINE_LENGTH(FILE : in FILE_TYPE; TO : in COUNT);
  1576.     procedure SET_LINE_LENGTH(TO   : in COUNT);
  1577.  
  1578.  
  1579.  
  1580.  
  1581.                                   14 - 23
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.           Sets the maximum line length of the specified output file to  the
  1591.           number  of  characters  specified  by  TO.  The value zero for TO
  1592.           specifies an unbounded line length.
  1593.  
  1594.           The exception USE_ERROR is raised if the specified line length is
  1595.           inappropriate for the associated external file.
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608.  
  1609.  
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.  
  1621.  
  1622.  
  1623.  
  1624.  
  1625.  
  1626.  
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.                                   14 - 24
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.     procedure SET_PAGE_LENGTH(FILE : in FILE_TYPE; TO : in COUNT);
  1657.     procedure SET_PAGE_LENGTH(TO   : in COUNT);
  1658.  
  1659.           Sets the maximum page length of the specified output file to  the
  1660.           number of lines specified by TO.  The value zero for TO specifies
  1661.           an unbounded page length.
  1662.  
  1663.           The exception USE_ERROR is raised if the specified page length is
  1664.           inappropriate for the associated external file.
  1665.  
  1666.  
  1667.     function LINE_LENGTH(FILE : in FILE_TYPE) return COUNT;
  1668.     function LINE_LENGTH return COUNT;
  1669.  
  1670.           Returns  the  maximum line length currently set for the specified
  1671.           output file, or zero if the line length is unbounded.
  1672.  
  1673.  
  1674.     function PAGE_LENGTH(FILE : in FILE_TYPE) return COUNT;
  1675.     function PAGE_LENGTH return COUNT;
  1676.  
  1677.           Returns the maximum page length currently set for  the  specified
  1678.           output file, or zero if the page length is unbounded.
  1679.  
  1680.  
  1681. References:   count  type  14.3, current default output file 14.3, external
  1682. file 14.1, file 14.1, file_type 14.1, line 14.3,  line  length  14.3,  line
  1683. terminator  14.3,  maximum  line  length  14.3,  maximum  page length 14.3,
  1684. mode_error exception 14.4, open file 14.1, out_file 14.1, page  14.3,  page
  1685. length  14.3,  page terminator 14.3, status_error exception 14.4, unbounded
  1686. page length 14.3, use_error exception 14.4
  1687.  
  1688.  
  1689.  
  1690. 14.3.4  Operations on Columns, Lines, and Pages
  1691.  
  1692.  
  1693. The subprograms described in this section provide for explicit  control  of
  1694. line  and  page  structure;   they  operate either on the file given as the
  1695. first parameter, or, in the absence  of  such  a  file  parameter,  on  the
  1696. appropriate   (input  or  output)  current  default  file.   The  exception
  1697. STATUS_ERROR is raised by any of these subprograms if the file to  be  used
  1698. is not open.
  1699.  
  1700.  
  1701.     procedure NEW_LINE(FILE : in FILE_TYPE; SPACING : in POSITIVE_COUNT := 1);
  1702.     procedure NEW_LINE(SPACING : in POSITIVE_COUNT := 1);
  1703.  
  1704.           Operates on a file of mode OUT_FILE.
  1705.  
  1706.           For  a  SPACING  of  one:  Outputs a line terminator and sets the
  1707.           current column number to one.  Then increments the  current  line
  1708.           number by one, except in the case that the current line number is
  1709.           already  greater  than or equal to the maximum page length, for a
  1710.           bounded page length;  in that case a page terminator  is  output,
  1711.  
  1712.  
  1713.                                   14 - 25
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.           the  current  page  number is incremented by one, and the current
  1723.           line number is set to one.
  1724.  
  1725.           For a SPACING greater than one, the above actions  are  performed
  1726.           SPACING times.
  1727.  
  1728.           The  exception  MODE_ERROR is raised if the mode is not OUT_FILE.
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.  
  1736.  
  1737.  
  1738.  
  1739.  
  1740.  
  1741.  
  1742.  
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748.  
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.                                   14 - 26
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.     procedure SKIP_LINE(FILE    : in FILE_TYPE; SPACING : in POSITIVE_COUNT := 1);
  1790.     procedure SKIP_LINE(SPACING : in POSITIVE_COUNT := 1);
  1791.  
  1792.           Operates on a file of mode IN_FILE.
  1793.  
  1794.           For a SPACING of one:  Reads and discards all characters until  a
  1795.           line  terminator  has been read, and then sets the current column
  1796.           number to  one.   If  the  line  terminator  is  not  immediately
  1797.           followed  by  a  page  terminator,  the  current  line  number is
  1798.           incremented  by  one.   Otherwise,  if  the  line  terminator  is
  1799.           immediately   followed  by  a  page  terminator,  then  the  page
  1800.           terminator is skipped, the current page number is incremented  by
  1801.           one, and the current line number is set to one.
  1802.  
  1803.           For  a  SPACING greater than one, the above actions are performed
  1804.           SPACING times.
  1805.  
  1806.           The exception MODE_ERROR is raised if the mode  is  not  IN_FILE.
  1807.           The exception END_ERROR is raised if an attempt is made to read a
  1808.           file terminator.
  1809.  
  1810.  
  1811.     function END_OF_LINE(FILE : in FILE_TYPE) return BOOLEAN;
  1812.     function END_OF_LINE return BOOLEAN;
  1813.  
  1814.           Operates  on  a  file  of  mode IN_FILE.  Returns TRUE if  a line
  1815.           terminator or a  file  terminator  is  next;   otherwise  returns
  1816.           FALSE.
  1817.  
  1818.           The exception MODE_ERROR is raised if the mode is not IN_FILE.
  1819.  
  1820.  
  1821.     procedure NEW_PAGE(FILE : in FILE_TYPE);
  1822.     procedure NEW_PAGE;
  1823.  
  1824.           Operates  on  a file of mode OUT_FILE.  Outputs a line terminator
  1825.           if the current line is not terminated, or if the current page  is
  1826.           empty  (that  is, if the current column and line numbers are both
  1827.           equal to one).  Then outputs a page terminator, which  terminates
  1828.           the  current  page.  Adds one to the current page number and sets
  1829.           the current column and line numbers to one.
  1830.  
  1831.           The exception MODE_ERROR is raised if the mode is  not  OUT_FILE.
  1832.  
  1833.  
  1834.     procedure SKIP_PAGE(FILE: in FILE_TYPE);
  1835.     procedure SKIP_PAGE;
  1836.  
  1837.           Operates  on  a  file  of  mode  IN_FILE.  Reads and discards all
  1838.           characters and line terminators until a page terminator has  been
  1839.           read.   Then  adds  one  to the current page number, and sets the
  1840.           current column and line numbers to one.
  1841.  
  1842.  
  1843.  
  1844.  
  1845.                                   14 - 27
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.           The exception MODE_ERROR is raised if the mode  is  not  IN_FILE.
  1855.           The exception END_ERROR is raised if an attempt is made to read a
  1856.           file terminator.
  1857.  
  1858.  
  1859.  
  1860.  
  1861.  
  1862.  
  1863.  
  1864.  
  1865.  
  1866.  
  1867.  
  1868.  
  1869.  
  1870.  
  1871.  
  1872.  
  1873.  
  1874.  
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.  
  1886.  
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892.  
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.                                   14 - 28
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.     function END_OF_PAGE(FILE : in FILE_TYPE) return BOOLEAN;
  1922.     function END_OF_PAGE return BOOLEAN;
  1923.  
  1924.           Operates  on  a  file  of  mode  IN_FILE.   Returns  TRUE  if the
  1925.           combination of a line terminator and a page terminator  is  next,
  1926.           or if a file terminator is next;  otherwise returns FALSE.
  1927.  
  1928.           The exception MODE_ERROR is raised if the mode is not IN_FILE.
  1929.  
  1930.  
  1931.     function END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
  1932.     function END_OF_FILE return BOOLEAN;
  1933.  
  1934.           Operates  on  a  file  of  mode  IN_FILE.  Returns TRUE if a file
  1935.           terminator is next, or if the combination of a line, a page,  and
  1936.           a file terminator is next;  otherwise returns FALSE.
  1937.  
  1938.           The exception MODE_ERROR is raised if the mode is not IN_FILE.
  1939.  
  1940.  
  1941. The  following  subprograms provide for the control of the current position
  1942. of reading or writing in a file.  In all cases, the  default  file  is  the
  1943. current output file.
  1944.  
  1945.     procedure SET_COL(FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
  1946.     procedure SET_COL(TO   : in POSITIVE_COUNT);
  1947.  
  1948.           If the file mode is OUT_FILE:
  1949.  
  1950.                If  the  value  specified  by TO is greater than the current
  1951.                column number, outputs spaces, adding  one  to  the  current
  1952.                column  number  after  each  space, until the current column
  1953.                number equals the specified value.  If the  value  specified
  1954.                by  TO  is  equal  to the current column number, there is no
  1955.                effect.  If the value specified  by  TO  is  less  than  the
  1956.                current  column  number,  has the effect of calling NEW_LINE
  1957.                (with a spacing of one), then outputs (TO - 1)  spaces,  and
  1958.                sets the current column number to the specified value.
  1959.  
  1960.                The  exception LAYOUT_ERROR is raised if the value specified
  1961.                by TO exceeds LINE_LENGTH when the line  length  is  bounded
  1962.                (that  is,  when  it  does  not  have the conventional value
  1963.                zero).
  1964.  
  1965.  
  1966.           If the file mode is IN_FILE:
  1967.  
  1968.                Reads   (and   discards)   individual    characters,    line
  1969.                terminators,  and page terminators, until the next character
  1970.                to be read  has  a  column  number  that  equals  the  value
  1971.                specified  by  TO;  there is no effect if the current column
  1972.                number already  equals  this  value.   Each  transfer  of  a
  1973.                character  or terminator maintains the current column, line,
  1974.                and page numbers in the same way as  a  GET  procedure  (see
  1975.  
  1976.  
  1977.                                   14 - 29
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.                14.3.5).   (Short  lines  will  be  skipped  until a line is
  1987.                reached  that  has  a  character  at  the  specified  column
  1988.                position.)
  1989.  
  1990.                The  exception  END_ERROR is raised if an attempt is made to
  1991.                read a file terminator.
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030.  
  2031.  
  2032.  
  2033.  
  2034.  
  2035.  
  2036.  
  2037.  
  2038.  
  2039.  
  2040.  
  2041.  
  2042.  
  2043.                                   14 - 30
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.     procedure SET_LINE(FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
  2053.     procedure SET_LINE(TO   : in POSITIVE_COUNT);
  2054.  
  2055.  
  2056.           If the file mode is OUT_FILE:
  2057.  
  2058.                If the value specified by TO is  greater  than  the  current
  2059.                line  number,  has the effect of repeatedly calling NEW_LINE
  2060.                (with a spacing of  one),  until  the  current  line  number
  2061.                equals the specified value.  If the value specified by TO is
  2062.                equal  to  the  current line number, there is no effect.  If
  2063.                the value specified by TO is  less  than  the  current  line
  2064.                number,  has  the  effect  of calling NEW_PAGE followed by a
  2065.                call of NEW_LINE with a spacing equal to (TO - 1).
  2066.  
  2067.                The exception LAYOUT_ERROR is raised if the value  specified
  2068.                by  TO  exceeds  PAGE_LENGTH when the page length is bounded
  2069.                (that is, when it  does  not  have  the  conventional  value
  2070.                zero).
  2071.  
  2072.  
  2073.           If the mode is IN_FILE:
  2074.  
  2075.                Has  the  effect  of  repeatedly  calling  SKIP_LINE (with a
  2076.                spacing of one), until the current line  number  equals  the
  2077.                value  specified  by  TO;  there is no effect if the current
  2078.                line number already equals this value.  (Short pages will be
  2079.                skipped until a page is reached  that  has  a  line  at  the
  2080.                specified line position.)
  2081.  
  2082.                The  exception  END_ERROR is raised if an attempt is made to
  2083.                read a file terminator.
  2084.  
  2085.  
  2086.     function COL(FILE : in FILE_TYPE) return POSITIVE_COUNT;
  2087.     function COL return POSITIVE_COUNT;
  2088.  
  2089.           Returns the current column number.
  2090.  
  2091.           The exception LAYOUT_ERROR  is  raised  if  this  number  exceeds
  2092.           COUNT'LAST.
  2093.  
  2094.  
  2095.     function LINE(FILE : in FILE_TYPE) return POSITIVE_COUNT;
  2096.     function LINE return POSITIVE_COUNT;
  2097.  
  2098.           Returns the current line number.
  2099.  
  2100.           The  exception  LAYOUT_ERROR  is  raised  if  this number exceeds
  2101.           COUNT'LAST.
  2102.  
  2103.  
  2104.     function PAGE(FILE : in FILE_TYPE) return POSITIVE_COUNT;
  2105.     function PAGE return POSITIVE_COUNT;
  2106.  
  2107.  
  2108.  
  2109.                                   14 - 31
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.           Returns the current page number.
  2119.  
  2120.           The exception LAYOUT_ERROR  is  raised  if  this  number  exceeds
  2121.           COUNT'LAST.
  2122.  
  2123.  
  2124. The  column  number,  line  number,  or  page  number are allowed to exceed
  2125. COUNT'LAST (as a consequence of the input or output  of  sufficiently  many
  2126. characters,  lines,  or pages).  These events do not cause any exception to
  2127. be raised.  However, a call of COL, LINE,  or  PAGE  raises  the  exception
  2128. LAYOUT_ERROR if the corresponding number exceeds COUNT'LAST.
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.  
  2142.  
  2143.  
  2144.  
  2145.  
  2146.  
  2147.  
  2148.  
  2149.  
  2150.  
  2151.  
  2152.  
  2153.  
  2154.  
  2155.  
  2156.  
  2157.  
  2158.  
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.                                   14 - 32
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184. Note:
  2185.  
  2186. A  page terminator is always skipped whenever the preceding line terminator
  2187. is skipped.  An implementation  may  represent  the  combination  of  these
  2188. terminators  by a single character, provided that it is properly recognized
  2189. at input.
  2190.  
  2191. References:  current column number 14.3, current default file 14.3, current
  2192. line number 14.3, current page number 14.3, end_error exception 14.4,  file
  2193. 14.1,   file   terminator   14.3,   get  procedure  14.3.5,  in_file  14.1,
  2194. layout_error exception 14.4, line 14.3, line number 14.3,  line  terminator
  2195. 14.3,  maximum page length 14.3, mode_error exception 14.4, open file 14.1,
  2196. page 14.3, page length 14.3, page terminator  14.3,  positive  count  14.3,
  2197. status_error exception 14.4
  2198.  
  2199.  
  2200.  
  2201. 14.3.5  Get and Put Procedures
  2202.  
  2203.  
  2204. The  procedures  GET  and  PUT  for  items  of the types CHARACTER, STRING,
  2205. numeric types, and enumeration types are described in subsequent  sections.
  2206. Features  of  these  procedures  that are common to most of these types are
  2207. described in this section.  The GET and PUT procedures for  items  of  type
  2208. CHARACTER  and  STRING  deal with individual character values;  the GET and
  2209. PUT procedures for numeric and enumeration types treat the items as lexical
  2210. elements.
  2211.  
  2212. All procedures GET and PUT have forms with a file parameter, written first.
  2213. Where this parameter is omitted, the appropriate (input or output)  current
  2214. default file is understood to be specified.  Each procedure GET operates on
  2215. a  file  of  mode  IN_FILE.   Each procedure PUT operates on a file of mode
  2216. OUT_FILE.
  2217.  
  2218. All procedures GET and PUT maintain the  current  column,  line,  and  page
  2219. numbers of the specified file:  the effect of each of these procedures upon
  2220. these  numbers  is  the resultant of the effects of individual transfers of
  2221. characters and of individual  output  or  skipping  of  terminators.   Each
  2222. transfer of a character adds one to the current column number.  Each output
  2223. of  a line terminator sets the current column number to one and adds one to
  2224. the current line number.   Each  output  of  a  page  terminator  sets  the
  2225. current  column  and  line  numbers to one and adds one to the current page
  2226. number.  For input, each skipping of a line  terminator  sets  the  current
  2227. column  number  to  one  and  adds  one  to  the current line number;  each
  2228. skipping of a page terminator sets the current column and line  numbers  to
  2229. one  and adds one to the current page number.  Similar considerations apply
  2230. to the procedures GET_LINE, PUT_LINE, and SET_COL.
  2231.  
  2232. Several GET and PUT procedures, for numeric  and  enumeration  types,  have
  2233. format parameters which specify field lengths;  these parameters are of the
  2234. nonnegative subtype FIELD of the type INTEGER.
  2235.  
  2236. Input-output  of  enumeration  values  uses the syntax of the corresponding
  2237. lexical elements.  Any GET procedure for  an  enumeration  type  begins  by
  2238. skipping  any  leading  blanks, or line or page terminators;  a blank being
  2239.  
  2240.  
  2241.                                   14 - 33
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250. defined as a space or a horizontal tabulation character.  Next,  characters
  2251. are  input  only so long as the sequence input is an initial sequence of an
  2252. identifier or of a character literal (in particular, input  ceases  when  a
  2253. line  terminator  is  encountered).   The character or line terminator that
  2254. causes input to cease remains available for subsequent input.
  2255.  
  2256. For a numeric type, the GET  procedures  have  a  format  parameter  called
  2257. WIDTH.   If  the  value given for this parameter is zero, the GET procedure
  2258. proceeds in the same manner as for enumeration types, but using the  syntax
  2259. of  numeric literals instead of that of enumeration literals.  If a nonzero
  2260. value is given, then exactly WIDTH characters are input, or the  characters
  2261. up to a line terminator, whichever comes first;  any skipped leading blanks
  2262. are  included  in  the  count.   The syntax used for numeric literals is an
  2263. extended syntax that allows a leading sign (but no intervening  blanks,  or
  2264. line or page terminators).
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.                                   14 - 34
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.  
  2316. Any PUT procedure, for an item of a numeric or an enumeration type, outputs
  2317. the  value  of  the  item  as  a  numeric literal, identifier, or character
  2318. literal, as appropriate.  This is preceded by leading spaces if required by
  2319. the format parameters WIDTH or FORE (as described in later  sections),  and
  2320. then  a  minus  sign  for  a  negative value;  for an enumeration type, the
  2321. spaces follow instead of leading.  The format given for a PUT procedure  is
  2322. overridden if it is insufficiently wide.
  2323.  
  2324. Two  further  cases  arise  for  PUT procedures for numeric and enumeration
  2325. types, if the line length of the specified output file is bounded (that is,
  2326. if it does not have  the  conventional  value  zero).   If  the  number  of
  2327. characters  to  be  output  does not exceed the maximum line length, but is
  2328. such that they cannot fit on the current line, starting  from  the  current
  2329. column,  then (in effect) NEW_LINE is called (with a spacing of one) before
  2330. output of the item.  Otherwise, if the number  of  characters  exceeds  the
  2331. maximum  line  length,  then  the  exception  LAYOUT_ERROR is raised and no
  2332. characters are output.
  2333.  
  2334. The exception  STATUS_ERROR  is  raised  by  any  of  the  procedures  GET,
  2335. GET_LINE,  PUT,  and  PUT_LINE  if  the  file  to be used is not open.  The
  2336. exception MODE_ERROR is raised by the procedures GET and  GET_LINE  if  the
  2337. mode  of the file to be used is not IN_FILE;  and by the procedures PUT and
  2338. PUT_LINE, if the mode is not OUT_FILE.
  2339.  
  2340. The exception END_ERROR is raised by a GET procedure if an attempt is  made
  2341. to  skip  a  file  terminator.  The exception DATA_ERROR is raised by a GET
  2342. procedure  if  the  sequence  finally  input  is  not  a  lexical   element
  2343. corresponding  to the type, in particular if no characters were input;  for
  2344. this test, leading blanks are ignored;  for an item of a numeric type, when
  2345. a sign is input, this rule applies to the succeeding numeric literal.   The
  2346. exception  LAYOUT_ERROR  is  raised  by  a  PUT procedure that outputs to a
  2347. parameter  of  type  STRING,  if  the  length  of  the  actual  string   is
  2348. insufficient for the output of the item.
  2349.  
  2350. Examples:
  2351.  
  2352. In  the examples, here and in sections 14.3.7 and 14.3.8, the string quotes
  2353. and the lower case letter b are not transferred:  they are  shown  only  to
  2354. reveal the layout and spaces.
  2355.  
  2356.     N : INTEGER;
  2357.        ...
  2358.     GET(N);
  2359.  
  2360.     -- Characters at input       Sequence input       Value of N
  2361.  
  2362.     --      bb-12535b            -12535               -12535
  2363.     --      bb12_535E1b           12_535E1             125350
  2364.     --      bb12_535E;            12_535E              (none) DATA_ERROR raised
  2365.  
  2366. Example of overridden width parameter:
  2367.  
  2368.     PUT(ITEM => -23, WIDTH => 2);  --  "-23"
  2369.  
  2370.  
  2371.  
  2372.  
  2373.                                   14 - 35
  2374.  
  2375.  
  2376.  
  2377.  
  2378.  
  2379.  
  2380.  
  2381.  
  2382. References:   blank  14.3.9, column number 14.3, current default file 14.3,
  2383. data_error exception  14.4,  end_error  exception  14.4,  file  14.1,  fore
  2384. 14.3.8,   get   procedure   14.3.6  14.3.7  14.3.8  14.3.9,  in_file  14.1,
  2385. layout_error exception  14.4,  line  number  14.1,  line  terminator  14.1,
  2386. maximum  line  length  14.3, mode 14.1, mode_error exception 14.4, new_file
  2387. procedure 14.3.4, out_file 14.1, page number 14.1,  page  terminator  14.1,
  2388. put  procedure  14.3.6 14.3.7 14.3.8 14.3.9, skipping 14.3.7 14.3.8 14.3.9,
  2389. status_error exception 14.4, width 14.3.5 14.3.7 14.3.9
  2390.  
  2391.  
  2392.  
  2393.  
  2394.  
  2395.  
  2396.  
  2397.  
  2398.  
  2399.  
  2400.  
  2401.  
  2402.  
  2403.  
  2404.  
  2405.  
  2406.  
  2407.  
  2408.  
  2409.  
  2410.  
  2411.  
  2412.  
  2413.  
  2414.  
  2415.  
  2416.  
  2417.  
  2418.  
  2419.  
  2420.  
  2421.  
  2422.  
  2423.  
  2424.  
  2425.  
  2426.  
  2427.  
  2428.  
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.                                   14 - 36
  2440.  
  2441.  
  2442.  
  2443.  
  2444.  
  2445.  
  2446.  
  2447.  
  2448. 14.3.6  Input-Output of Characters and Strings
  2449.  
  2450.  
  2451. For an item of type CHARACTER the following procedures are provided:
  2452.  
  2453.     procedure GET(FILE : in FILE_TYPE; ITEM : out CHARACTER);
  2454.     procedure GET(ITEM : out CHARACTER);
  2455.  
  2456.           After skipping any line terminators  and  any  page  terminators,
  2457.           reads  the  next  character  from  the  specified  input file and
  2458.           returns the value of this character in the out parameter ITEM.
  2459.  
  2460.           The exception END_ERROR is raised if an attempt is made to skip a
  2461.           file terminator.
  2462.  
  2463.  
  2464.     procedure PUT(FILE : in FILE_TYPE; ITEM : in CHARACTER);
  2465.     procedure PUT(ITEM : in CHARACTER);
  2466.  
  2467.           If the line length of the specified output file is bounded  (that
  2468.           is,  does  not have the conventional value zero), and the current
  2469.           column number exceeds it, has the effect of calling NEW_LINE with
  2470.           a  spacing  of  one.   Then,  or  otherwise,  outputs  the  given
  2471.           character to the file.
  2472.  
  2473.  
  2474. For an item of type STRING the following procedures are provided:
  2475.  
  2476.     procedure GET(FILE : in FILE_TYPE; ITEM : out STRING);
  2477.     procedure GET(ITEM : out STRING);
  2478.  
  2479.           Determines  the  length  of  the  given  string and attempts that
  2480.           number of GET operations for successive characters of the  string
  2481.           (in particular, no operation is performed if the string is null).
  2482.  
  2483.  
  2484.     procedure PUT(FILE : in FILE_TYPE; ITEM : in STRING);
  2485.     procedure PUT(ITEM : in STRING);
  2486.  
  2487.           Determines  the  length  of  the  given  string and attempts that
  2488.           number of PUT operations for successive characters of the  string
  2489.           (in particular, no operation is performed if the string is null).
  2490.  
  2491.  
  2492.     procedure GET_LINE(FILE : in FILE_TYPE; ITEM : out STRING; LAST : out NATURAL);
  2493.     procedure GET_LINE(ITEM : out STRING;   LAST : out NATURAL);
  2494.  
  2495.           Replaces   successive  characters  of  the  specified  string  by
  2496.           successive  characters  read  from  the  specified  input   file.
  2497.           Reading  stops  if  the end of the line is met, in which case the
  2498.           procedure SKIP_LINE is then called (in effect) with a spacing  of
  2499.           one;   reading  also  stops  if  the  end  of  the string is met.
  2500.           Characters not replaced are left undefined.
  2501.  
  2502.  
  2503.  
  2504.  
  2505.                                   14 - 37
  2506.  
  2507.  
  2508.  
  2509.  
  2510.  
  2511.  
  2512.  
  2513.  
  2514.           If characters are read, returns in LAST the index value such that
  2515.           ITEM(LAST) is the last character replaced (the index of the first
  2516.           character replaced is ITEM'FIRST).  If no  characters  are  read,
  2517.           returns  in LAST an index value that is one less than ITEM'FIRST.
  2518.  
  2519.           The exception END_ERROR is raised if an attempt is made to skip a
  2520.           file terminator.
  2521.  
  2522.  
  2523.  
  2524.  
  2525.  
  2526.  
  2527.  
  2528.  
  2529.  
  2530.  
  2531.  
  2532.  
  2533.  
  2534.  
  2535.  
  2536.  
  2537.  
  2538.  
  2539.  
  2540.  
  2541.  
  2542.  
  2543.  
  2544.  
  2545.  
  2546.  
  2547.  
  2548.  
  2549.  
  2550.  
  2551.  
  2552.  
  2553.  
  2554.  
  2555.  
  2556.  
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.  
  2569.  
  2570.  
  2571.                                   14 - 38
  2572.  
  2573.  
  2574.  
  2575.  
  2576.  
  2577.  
  2578.  
  2579.  
  2580.     procedure PUT_LINE(FILE : in FILE_TYPE; ITEM : in STRING);
  2581.     procedure PUT_LINE(ITEM : in STRING);
  2582.  
  2583.           Calls the procedure PUT  for  the  given  string,  and  then  the
  2584.           procedure NEW_LINE with a spacing of one.
  2585.  
  2586. Notes:
  2587.  
  2588. In  a  literal  string  parameter  of  PUT,  the  enclosing  string bracket
  2589. characters are not output.  Each doubled string bracket  character  in  the
  2590. enclosed  string  is  output  as  a  single  string bracket character, as a
  2591. consequence of the rule for string literals (see 2.6).
  2592.  
  2593. A string read by GET or written by PUT can extend over several lines.
  2594.  
  2595. References:  current column number 14.3,  end_error  exception  14.4,  file
  2596. 14.1,  file  terminator  14.3, get procedure 14.3.5, line 14.3, line length
  2597. 14.3, new_line  procedure  14.3.4,  page  terminator  14.3,  put  procedure
  2598. 14.3.4, skipping 14.3.5
  2599.  
  2600.  
  2601.  
  2602.  
  2603. 14.3.7  Input-Output for Integer Types
  2604.  
  2605.  
  2606. The  following  procedures  are  defined in the generic package INTEGER_IO.
  2607. This must be instantiated for the appropriate integer  type  (indicated  by
  2608. NUM in the specification).
  2609.  
  2610. Values   are  output  as  decimal  or  based  literals,  without  underline
  2611. characters or exponent, and preceded by a  minus  sign  if  negative.   The
  2612. format  (which includes any leading spaces and minus sign) can be specified
  2613. by an optional field width parameter.  Values of widths of fields in output
  2614. formats are of the nonnegative integer subtype FIELD.  Values of bases  are
  2615. of the integer subtype NUMBER_BASE.
  2616.  
  2617.     subtype NUMBER_BASE is INTEGER range 2 .. 16;
  2618.  
  2619. The  default  field  width  and  base  to  be used by output procedures are
  2620. defined by the following variables that are declared in the generic package
  2621. INTEGER_IO:
  2622.  
  2623.     DEFAULT_WIDTH : FIELD := NUM'WIDTH;
  2624.     DEFAULT_BASE  : NUMBER_BASE := 10;
  2625.  
  2626. The following procedures are provided:
  2627.  
  2628.     procedure GET(FILE : in FILE_TYPE; ITEM : out NUM; WIDTH : in FIELD := 0);
  2629.     procedure GET(ITEM : out NUM; WIDTH : in FIELD := 0);
  2630.  
  2631.           If the value of the parameter WIDTH is zero,  skips  any  leading
  2632.           blanks,  line terminators, or page terminators, then reads a plus
  2633.           or a minus sign if present, then reads according to the syntax of
  2634.           an integer literal (which may be a based literal).  If a  nonzero
  2635.  
  2636.  
  2637.                                   14 - 39
  2638.  
  2639.  
  2640.  
  2641.  
  2642.  
  2643.  
  2644.  
  2645.  
  2646.           value  of  WIDTH  is  supplied, then exactly WIDTH characters are
  2647.           input, or the characters (possibly none) up to a line terminator,
  2648.           whichever comes first;  any skipped leading blanks  are  included
  2649.           in the count.
  2650.  
  2651.           Returns,  in  the  parameter  ITEM,  the  value  of type NUM that
  2652.           corresponds to the sequence input.
  2653.  
  2654.           The exception DATA_ERROR is raised if the sequence input does not
  2655.           have the required syntax or if the value obtained is not  of  the
  2656.           subtype NUM.
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662.  
  2663.  
  2664.  
  2665.  
  2666.  
  2667.  
  2668.  
  2669.  
  2670.  
  2671.  
  2672.  
  2673.  
  2674.  
  2675.  
  2676.  
  2677.  
  2678.  
  2679.  
  2680.  
  2681.  
  2682.  
  2683.  
  2684.  
  2685.  
  2686.  
  2687.  
  2688.  
  2689.  
  2690.  
  2691.  
  2692.  
  2693.  
  2694.  
  2695.  
  2696.  
  2697.  
  2698.  
  2699.  
  2700.  
  2701.  
  2702.  
  2703.                                   14 - 40
  2704.  
  2705.  
  2706.  
  2707.  
  2708.  
  2709.  
  2710.  
  2711.  
  2712.     procedure PUT(FILE  : in FILE_TYPE;
  2713.                   ITEM  : in NUM;
  2714.                   WIDTH : in FIELD := DEFAULT_WIDTH;
  2715.                   BASE  : in NUMBER_BASE := DEFAULT_BASE);
  2716.  
  2717.     procedure PUT(ITEM  : in NUM;
  2718.                   WIDTH : in FIELD := DEFAULT_WIDTH;
  2719.                   BASE  : in NUMBER_BASE := DEFAULT_BASE);
  2720.  
  2721.           Outputs  the  value  of the parameter ITEM as an integer literal,
  2722.           with no underlines, no exponent, and  no  leading  zeros  (but  a
  2723.           single zero for the value zero), and a preceding minus sign for a
  2724.           negative value.
  2725.  
  2726.           If  the  resulting  sequence of characters to be output has fewer
  2727.           than WIDTH characters, then leading spaces are  first  output  to
  2728.           make up the difference.
  2729.  
  2730.           Uses the syntax for decimal literal if the parameter BASE has the
  2731.           value   ten   (either   explicitly   or   through  DEFAULT_BASE);
  2732.           otherwise, uses the syntax for based literal, with any letters in
  2733.           upper case.
  2734.  
  2735.  
  2736.     procedure GET(FROM : in STRING; ITEM : out NUM; LAST : out POSITIVE);
  2737.  
  2738.           Reads an integer value from the beginning of  the  given  string,
  2739.           following  the  same  rules  as  the  GET procedure that reads an
  2740.           integer value from a file, but treating the end of the string  as
  2741.           a  file terminator.  Returns, in the parameter ITEM, the value of
  2742.           type NUM that corresponds to the sequence input.  Returns in LAST
  2743.           the index value such that FROM(LAST) is the last character  read.
  2744.  
  2745.           The exception DATA_ERROR is raised if the sequence input does not
  2746.           have  the  required syntax or if the value obtained is not of the
  2747.           subtype NUM.
  2748.  
  2749.  
  2750.     procedure PUT(TO   : out STRING;
  2751.                   ITEM : in NUM;
  2752.                   BASE : in NUMBER_BASE := DEFAULT_BASE);
  2753.  
  2754.           Outputs the value of the parameter  ITEM  to  the  given  string,
  2755.           following the same rule as for output to a file, using the length
  2756.           of the given string as the value for WIDTH.
  2757.  
  2758.  
  2759. Examples:
  2760.  
  2761.     package INT_IO is new INTEGER_IO(SMALL_INT); use INT_IO;
  2762.     -- default format used at instantiation, DEFAULT_WIDTH = 4, DEFAULT_BASE = 10
  2763.  
  2764.     PUT(126);                            -- "b126"
  2765.     PUT(-126, 7);                        -- "bbb-126"
  2766.     PUT(126, WIDTH => 13, BASE => 2);    -- "bbb2#1111110#"
  2767.  
  2768.  
  2769.                                   14 - 41
  2770.  
  2771.  
  2772.  
  2773.  
  2774.  
  2775.  
  2776.  
  2777.  
  2778. References:   based literal 2.4.2, blank 14.3.5, data_error exception 14.4,
  2779. decimal literal 2.4.1, field subtype 14.3.5, file_type 14.1, get  procedure
  2780. 14.3.5,  integer_io  package  14.3.10,  integer  literal  2.4, layout_error
  2781. exception 14.4,  line  terminator  14.3,  put  procedure  14.3.5,  skipping
  2782. 14.3.5, width 14.3.5
  2783.  
  2784.  
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
  2792.  
  2793.  
  2794.  
  2795.  
  2796.  
  2797.  
  2798.  
  2799.  
  2800.  
  2801.  
  2802.  
  2803.  
  2804.  
  2805.  
  2806.  
  2807.  
  2808.  
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.                                   14 - 42
  2836.  
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844. 14.3.8  Input-Output for Real Types
  2845.  
  2846.  
  2847. The  following  procedures are defined in the generic packages FLOAT_IO and
  2848. FIXED_IO, which must be instantiated for the appropriate floating point  or
  2849. fixed point type respectively (indicated by NUM in the specifications).
  2850.  
  2851. Values  are  output  as decimal literals without underline characters.  The
  2852. format of each value output consists of a FORE field, a decimal  point,  an
  2853. AFT field, and (if a nonzero EXP parameter is supplied) the letter E and an
  2854. EXP field.  The two possible formats thus correspond to:
  2855.  
  2856.     FORE  .  AFT
  2857.  
  2858. and to:
  2859.  
  2860.     FORE  .  AFT  E  EXP
  2861.  
  2862. without  any  spaces  between  these  fields.   The  FORE field may include
  2863. leading spaces, and a minus sign  for  negative  values.    The  AFT  field
  2864. includes only decimal digits (possibly with trailing zeros).  The EXP field
  2865. includes  the  sign (plus or minus) and the exponent (possibly with leading
  2866. zeros).
  2867.  
  2868. For floating point types, the default lengths of these fields  are  defined
  2869. by  the  following  variables  that  are  declared  in  the generic package
  2870. FLOAT_IO:
  2871.  
  2872.     DEFAULT_FORE : FIELD := 2;
  2873.     DEFAULT_AFT  : FIELD := NUM'DIGITS-1;
  2874.     DEFAULT_EXP  : FIELD := 3;
  2875.  
  2876. For fixed point types, the default lengths of these fields are  defined  by
  2877. the  following variables that are declared in the generic package FIXED_IO:
  2878.  
  2879.  
  2880.     DEFAULT_FORE : FIELD := NUM'FORE;
  2881.     DEFAULT_AFT  : FIELD := NUM'AFT;
  2882.     DEFAULT_EXP  : FIELD := 0;
  2883.  
  2884. The following procedures are provided:
  2885.  
  2886.     procedure GET(FILE : in FILE_TYPE; ITEM : out NUM; WIDTH : in FIELD := 0);
  2887.     procedure GET(ITEM : out NUM; WIDTH : in FIELD := 0);
  2888.  
  2889.           If the value of the parameter WIDTH is zero,  skips  any  leading
  2890.           blanks,  line terminators, or page terminators, then reads a plus
  2891.           or a minus sign if present, then reads according to the syntax of
  2892.           a real literal (which may be a  based  literal).   If  a  nonzero
  2893.           value  of  WIDTH  is  supplied, then exactly WIDTH characters are
  2894.           input, or the characters (possibly none) up to a line terminator,
  2895.           whichever comes first;  any skipped leading blanks  are  included
  2896.           in the count.
  2897.  
  2898.  
  2899.  
  2900.  
  2901.                                   14 - 43
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910.           Returns,  in  the  parameter  ITEM,  the  value  of type NUM that
  2911.           corresponds to the sequence input.
  2912.  
  2913.           The exception DATA_ERROR is raised if the sequence input does not
  2914.           have the required syntax or if the value obtained is not  of  the
  2915.           subtype NUM.
  2916.  
  2917.  
  2918.  
  2919.  
  2920.  
  2921.  
  2922.  
  2923.  
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.  
  2954.  
  2955.  
  2956.  
  2957.  
  2958.  
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.  
  2965.  
  2966.  
  2967.                                   14 - 44
  2968.  
  2969.  
  2970.  
  2971.  
  2972.  
  2973.  
  2974.  
  2975.  
  2976.  
  2977.     procedure PUT(FILE : in FILE_TYPE;
  2978.                   ITEM : in NUM;
  2979.                   FORE : in FIELD := DEFAULT_FORE;
  2980.                   AFT  : in FIELD := DEFAULT_AFT;
  2981.                   EXP  : in FIELD := DEFAULT_EXP);
  2982.  
  2983.     procedure PUT(ITEM : in NUM;
  2984.                   FORE : in FIELD := DEFAULT_FORE;
  2985.                   AFT  : in FIELD := DEFAULT_AFT;
  2986.                   EXP  : in FIELD := DEFAULT_EXP);
  2987.  
  2988.           Outputs the value of the parameter ITEM as a decimal literal with
  2989.           the  format  defined  by  FORE,  AFT  and  EXP.   If the value is
  2990.           negative, a minus sign is included in the integer part.   If  EXP
  2991.           has  the  value  zero,  then the integer part to be output has as
  2992.           many digits as are needed to represent the integer  part  of  the
  2993.           value  of  ITEM, overriding FORE if necessary, or consists of the
  2994.           digit zero if the value of ITEM has no integer part.
  2995.  
  2996.           If EXP has a value greater than zero, then the integer part to be
  2997.           output has a single digit, which is nonzero except for the  value
  2998.           0.0 of ITEM.
  2999.  
  3000.           In  both  cases,  however,  if  the integer part to be output has
  3001.           fewer than  FORE  characters,  including  any  minus  sign,  then
  3002.           leading  spaces  are first output to make up the difference.  The
  3003.           number of digits of the fractional part is given by  AFT,  or  is
  3004.           one  if  AFT  equals  zero.   The  value  is rounded;  a value of
  3005.           exactly one half in the last place may be rounded  either  up  or
  3006.           down.
  3007.  
  3008.           If EXP has the value zero, there is no exponent part.  If EXP has
  3009.           a  value  greater  than zero, then the exponent part to be output
  3010.           has as many digits as are needed to represent the  exponent  part
  3011.           of  the  value  of ITEM (for which a single digit integer part is
  3012.           used), and includes an initial  sign (plus  or  minus).   If  the
  3013.           exponent  part  to  be  output  has  fewer  than  EXP characters,
  3014.           including the sign, then leading zeros  precede  the  digits,  to
  3015.           make  up the difference.  For the value 0.0 of ITEM, the exponent
  3016.           has the value zero.
  3017.  
  3018.  
  3019.     procedure GET(FROM : in STRING; ITEM : out NUM; LAST : out POSITIVE);
  3020.  
  3021.           Reads a real value  from  the  beginning  of  the  given  string,
  3022.           following  the  same  rule as the GET procedure that reads a real
  3023.           value from a file, but treating the end of the string as  a  file
  3024.           terminator.   Returns,  in  the parameter ITEM, the value of type
  3025.           NUM that corresponds to the sequence input.  Returns in LAST  the
  3026.           index value such that FROM(LAST) is the last character read.
  3027.  
  3028.           The exception DATA_ERROR is raised if the sequence input does not
  3029.           have  the required syntax, or if the value obtained is not of the
  3030.           subtype NUM.
  3031.  
  3032.  
  3033.                                   14 - 45
  3034.  
  3035.  
  3036.  
  3037.  
  3038.  
  3039.  
  3040.  
  3041.  
  3042.  
  3043.     procedure PUT(TO   : out STRING;
  3044.                   ITEM : in NUM;
  3045.                   AFT  : in FIELD := DEFAULT_AFT;
  3046.                   EXP  : in INTEGER := DEFAULT_EXP);
  3047.  
  3048.           Outputs the value of the parameter  ITEM  to  the  given  string,
  3049.           following  the  same  rule as for output to a file, using a value
  3050.           for FORE such that the  sequence  of  characters  output  exactly
  3051.           fills the string, including any leading spaces.
  3052.  
  3053.  
  3054.  
  3055.  
  3056.  
  3057.  
  3058.  
  3059.  
  3060.  
  3061.  
  3062.  
  3063.  
  3064.  
  3065.  
  3066.  
  3067.  
  3068.  
  3069.  
  3070.  
  3071.  
  3072.  
  3073.  
  3074.  
  3075.  
  3076.  
  3077.  
  3078.  
  3079.  
  3080.  
  3081.  
  3082.  
  3083.  
  3084.  
  3085.  
  3086.  
  3087.  
  3088.  
  3089.  
  3090.  
  3091.  
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.                                   14 - 46
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.  
  3108. Examples:
  3109.  
  3110.     package REAL_IO is new FLOAT_IO(REAL); use REAL_IO;
  3111.     -- default format used at instantiation, DEFAULT_EXP = 3
  3112.  
  3113.     X : REAL := -123.4567;  --  digits 8      (see 3.5.7)
  3114.  
  3115.     PUT(X); -- default format                   "-1.2345670E+02"
  3116.     PUT(X, FORE => 5, AFT => 3, EXP => 2);  --  "bbb-1.235E+2"
  3117.     PUT(X, 5, 3, 0);                        --  "b-123.457"
  3118.  
  3119. Note:
  3120.  
  3121. For  an item with a positive value, if output to a string exactly fills the
  3122. string without leading spaces, then output of  the  corresponding  negative
  3123. value will raise LAYOUT_ERROR.
  3124.  
  3125. References:   aft  attribute  3.5.10,  based  literal  2.4.2, blank 14.3.5,
  3126. data_error exception 14.3.5, decimal literal 2.4.1, field  subtype  14.3.5,
  3127. file_type 14.1, fixed_io package 14.3.10, floating_io package 14.3.10, fore
  3128. attribute   3.5.10,   get   procedure  14.3.5,  layout_error  14.3.5,  line
  3129. terminator 14.3.5, put procedure 14.3.5, real literal 2.4, skipping 14.3.5,
  3130. width 14.3.5
  3131.  
  3132.  
  3133.  
  3134.  
  3135. 14.3.9  Input-Output for Enumeration Types
  3136.  
  3137.  
  3138. The following procedures are defined in the generic package ENUMERATION_IO,
  3139. which must be instantiated for the appropriate enumeration type  (indicated
  3140. by ENUM in the specification).
  3141.  
  3142. Values are output using either upper or lower case letters for identifiers.
  3143. This  is  specified  by the parameter SET, which is of the enumeration type
  3144. TYPE_SET.
  3145.  
  3146.     type TYPE_SET is (LOWER_CASE, UPPER_CASE);
  3147.  
  3148. The format (which includes any trailing spaces)  can  be  specified  by  an
  3149. optional  field  width  parameter.  The default field width and letter case
  3150. are defined by the following variables that are  declared  in  the  generic
  3151. package ENUMERATION_IO:
  3152.  
  3153.     DEFAULT_WIDTH   : FIELD := 0;
  3154.     DEFAULT_SETTING : TYPE_SET := UPPER_CASE;
  3155.  
  3156. The following procedures are provided:
  3157.  
  3158.     procedure GET(FILE : in FILE_TYPE; ITEM : out ENUM);
  3159.     procedure GET(ITEM : out ENUM);
  3160.  
  3161.           After  skipping  any  leading  blanks,  line terminators, or page
  3162.           terminators, reads an identifier according to the syntax of  this
  3163.  
  3164.  
  3165.                                   14 - 47
  3166.  
  3167.  
  3168.  
  3169.  
  3170.  
  3171.  
  3172.  
  3173.  
  3174.           lexical   element   (lower   and   upper  case  being  considered
  3175.           equivalent), or a character literal according to  the  syntax  of
  3176.           this  lexical  element  (including the apostrophes).  Returns, in
  3177.           the parameter ITEM, the value of type ENUM  that  corresponds  to
  3178.           the sequence input.
  3179.  
  3180.           The exception DATA_ERROR is raised if the sequence input does not
  3181.           have  the  required  syntax,  or  if  the identifier or character
  3182.           literal does not correspond to a value of the subtype ENUM.
  3183.  
  3184.  
  3185.  
  3186.  
  3187.  
  3188.  
  3189.  
  3190.  
  3191.  
  3192.  
  3193.  
  3194.  
  3195.  
  3196.  
  3197.  
  3198.  
  3199.  
  3200.  
  3201.  
  3202.  
  3203.  
  3204.  
  3205.  
  3206.  
  3207.  
  3208.  
  3209.  
  3210.  
  3211.  
  3212.  
  3213.  
  3214.  
  3215.  
  3216.  
  3217.  
  3218.  
  3219.  
  3220.  
  3221.  
  3222.  
  3223.  
  3224.  
  3225.  
  3226.  
  3227.  
  3228.  
  3229.  
  3230.  
  3231.                                   14 - 48
  3232.  
  3233.  
  3234.  
  3235.  
  3236.  
  3237.  
  3238.  
  3239.  
  3240.     procedure PUT(FILE  : in FILE_TYPE;
  3241.                   ITEM  : in ENUM;
  3242.                   WIDTH : in FIELD := DEFAULT_WIDTH;
  3243.                   SET   : in TYPE_SET := DEFAULT_SETTING);
  3244.  
  3245.     procedure PUT(ITEM  : in ENUM;
  3246.                   WIDTH : in FIELD := DEFAULT_WIDTH;
  3247.                   SET   : in TYPE_SET := DEFAULT_SETTING);
  3248.  
  3249.           Outputs the value of the parameter ITEM as an enumeration literal
  3250.           (either an identifier or  a  character  literal).   The  optional
  3251.           parameter  SET indicates whether lower case or upper case is used
  3252.           for identifiers;  it has no effect for  character  literals.   If
  3253.           the   sequence  of  characters  produced  has  fewer  than  WIDTH
  3254.           characters, then trailing spaces are finally output  to  make  up
  3255.           the difference.
  3256.  
  3257.  
  3258.     procedure GET(FROM : in STRING; ITEM : out ENUM; LAST : out POSITIVE);
  3259.  
  3260.           Reads  an  enumeration  value  from  the  beginning  of the given
  3261.           string, following the same rule as the GET  procedure that  reads
  3262.           an  enumeration  value  from  a file, but treating the end of the
  3263.           string as a file terminator.  Returns, in the parameter ITEM, the
  3264.           value of type  ENUM  that  corresponds  to  the  sequence  input.
  3265.           Returns  in LAST the index value such that FROM(LAST) is the last
  3266.           character read.
  3267.  
  3268.           The exception DATA_ERROR is raised if the sequence input does not
  3269.           have the required syntax,  or  if  the  identifier  or  character
  3270.           literal does not correspond to a value of the subtype ENUM.
  3271.  
  3272.  
  3273.     procedure PUT(TO   : out STRING;
  3274.                   ITEM : in ENUM;
  3275.                   SET  : in TYPE_SET := DEFAULT_SETTING);
  3276.  
  3277.           Outputs  the  value  of  the  parameter ITEM to the given string,
  3278.           following the same rule as for output to a file, using the length
  3279.           of the given string as the value for WIDTH.
  3280.  
  3281.  
  3282. Although the  specification  of  the  package  ENUMERATION_IO  would  allow
  3283. instantiation for an integer type, this is not the intended purpose of this
  3284. generic  package,  and  the effect of such instantiations is not defined by
  3285. the language.
  3286.  
  3287. Notes:
  3288.  
  3289. There  is  a  difference  between  PUT  defined  for  characters,  and  for
  3290. enumeration values.  Thus
  3291.  
  3292.     TEXT_IO.PUT('A');  --  outputs the character A
  3293.  
  3294.  
  3295.  
  3296.  
  3297.                                   14 - 49
  3298.  
  3299.  
  3300.  
  3301.  
  3302.  
  3303.  
  3304.  
  3305.  
  3306.     package CHAR_IO is new TEXT_IO.ENUMERATION_IO(CHARACTER);
  3307.     CHAR_IO.PUT('A');  --  outputs the character 'A', between single quotes
  3308.  
  3309. The  type  BOOLEAN  is  an  enumeration  type,  hence ENUMERATION_IO can be
  3310. instantiated for this type.
  3311.  
  3312. References:   blank  14.3.5,  data_error  14.3.5,  enumeration_io   package
  3313. 14.3.10,  field  subtype 14.3.5, file_type 14.1, get procedure 14.3.5, line
  3314. terminator 14.3.5, put procedure 14.3.5, skipping 14.3.5, width 14.3.5
  3315.  
  3316.  
  3317.  
  3318.  
  3319.  
  3320.  
  3321.  
  3322.  
  3323.  
  3324.  
  3325.  
  3326.  
  3327.  
  3328.  
  3329.  
  3330.  
  3331.  
  3332.  
  3333.  
  3334.  
  3335.  
  3336.  
  3337.  
  3338.  
  3339.  
  3340.  
  3341.  
  3342.  
  3343.  
  3344.  
  3345.  
  3346.  
  3347.  
  3348.  
  3349.  
  3350.  
  3351.  
  3352.  
  3353.  
  3354.  
  3355.  
  3356.  
  3357.  
  3358.  
  3359.  
  3360.  
  3361.  
  3362.  
  3363.                                   14 - 50
  3364.  
  3365.  
  3366.  
  3367.  
  3368.  
  3369.  
  3370.  
  3371.  
  3372. 14.3.10  Specification of the Package Text_IO
  3373.  
  3374.  
  3375.  
  3376.     with IO_EXCEPTIONS;
  3377.     package TEXT_IO is
  3378.  
  3379.        type FILE_TYPE is limited private;
  3380.  
  3381.        type FILE_MODE is (IN_FILE, OUT_FILE);
  3382.  
  3383.        type COUNT is range 0 .. IMPLEMENTATION_DEFINED;
  3384.        subtype POSITIVE_COUNT is COUNT range 1 .. COUNT'LAST;
  3385.        UNBOUNDED : constant COUNT := 0; -- line and page length
  3386.  
  3387.        subtype FIELD       is INTEGER range 0 .. IMPLEMENTATION_DEFINED;
  3388.        subtype NUMBER_BASE is INTEGER range 2 .. 16;
  3389.  
  3390.        type TYPE_SET is (LOWER_CASE, UPPER_CASE);
  3391.  
  3392.        -- File Management
  3393.  
  3394.        procedure CREATE (FILE : in out FILE_TYPE;
  3395.                          MODE : in FILE_MODE := OUT_FILE;
  3396.                          NAME : in STRING    := "";
  3397.                          FORM : in STRING    := "");
  3398.  
  3399.        procedure OPEN   (FILE : in out FILE_TYPE;
  3400.                          MODE : in FILE_MODE;
  3401.                          NAME : in STRING;
  3402.                          FORM : in STRING := "");
  3403.  
  3404.        procedure CLOSE  (FILE : in out FILE_TYPE);
  3405.        procedure DELETE (FILE : in out FILE_TYPE);
  3406.        procedure RESET  (FILE : in out FILE_TYPE; MODE : in FILE_MODE);
  3407.        procedure RESET  (FILE : in out FILE_TYPE);
  3408.  
  3409.        function  MODE   (FILE : in FILE_TYPE) return FILE_MODE;
  3410.        function  NAME   (FILE : in FILE_TYPE) return STRING;
  3411.        function  FORM   (FILE : in FILE_TYPE) return STRING;
  3412.  
  3413.        function  IS_OPEN(FILE : in FILE_TYPE) return BOOLEAN;
  3414.  
  3415.        -- Control of default input and output files
  3416.  
  3417.        procedure SET_INPUT (FILE : in FILE_TYPE);
  3418.        procedure SET_OUTPUT(FILE : in FILE_TYPE);
  3419.  
  3420.  
  3421.        function STANDARD_INPUT  return FILE_TYPE;
  3422.        function STANDARD_OUTPUT return FILE_TYPE;
  3423.  
  3424.        function CURRENT_INPUT   return FILE_TYPE;
  3425.        function CURRENT_OUTPUT  return FILE_TYPE;
  3426.  
  3427.  
  3428.  
  3429.                                   14 - 51
  3430.  
  3431.  
  3432.  
  3433.  
  3434.  
  3435.  
  3436.  
  3437.  
  3438.        -- Specification of line and page lengths
  3439.  
  3440.        procedure SET_LINE_LENGTH(FILE : in FILE_TYPE; TO : in COUNT);
  3441.        procedure SET_LINE_LENGTH(TO : in COUNT);
  3442.  
  3443.        procedure SET_PAGE_LENGTH(FILE : in FILE_TYPE; TO : in COUNT);
  3444.        procedure SET_PAGE_LENGTH(TO : in COUNT);
  3445.  
  3446.        function  LINE_LENGTH(FILE : in FILE_TYPE) return COUNT;
  3447.        function  LINE_LENGTH return COUNT;
  3448.  
  3449.        function  PAGE_LENGTH(FILE : in FILE_TYPE) return COUNT;
  3450.        function  PAGE_LENGTH return COUNT;
  3451.  
  3452.        -- Column, Line, and Page Control
  3453.  
  3454.        procedure NEW_LINE   (FILE : in FILE_TYPE; SPACING : in POSITIVE_COUNT := 1);
  3455.        procedure NEW_LINE   (SPACING : in POSITIVE_COUNT := 1);
  3456.  
  3457.        procedure SKIP_LINE  (FILE : in FILE_TYPE; SPACING : in POSITIVE_COUNT := 1);
  3458.        procedure SKIP_LINE  (SPACING : in POSITIVE_COUNT := 1);
  3459.  
  3460.        function  END_OF_LINE(FILE : in FILE_TYPE) return BOOLEAN;
  3461.        function  END_OF_LINE return BOOLEAN;
  3462.  
  3463.        procedure NEW_PAGE   (FILE : in FILE_TYPE);
  3464.        procedure NEW_PAGE;
  3465.  
  3466.        procedure SKIP_PAGE  (FILE : in FILE_TYPE);
  3467.        procedure SKIP_PAGE;
  3468.  
  3469.        function  END_OF_PAGE(FILE : in FILE_TYPE) return BOOLEAN;
  3470.        function  END_OF_PAGE return BOOLEAN;
  3471.  
  3472.        function  END_OF_FILE(FILE : in FILE_TYPE) return BOOLEAN;
  3473.        function  END_OF_FILE return BOOLEAN;
  3474.  
  3475.  
  3476.        procedure SET_COL (FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
  3477.        procedure SET_COL (TO   : in POSITIVE_COUNT);
  3478.  
  3479.        procedure SET_LINE(FILE : in FILE_TYPE; TO : in POSITIVE_COUNT);
  3480.        procedure SET_LINE(TO   : in POSITIVE_COUNT);
  3481.  
  3482.  
  3483.        function COL (FILE : in FILE_TYPE) return POSITIVE_COUNT;
  3484.        function COL  return POSITIVE_COUNT;
  3485.  
  3486.        function LINE(FILE : in FILE_TYPE) return POSITIVE_COUNT;
  3487.        function LINE return POSITIVE_COUNT;
  3488.  
  3489.        function PAGE(FILE : in FILE_TYPE) return POSITIVE_COUNT;
  3490.        function PAGE return POSITIVE_COUNT;
  3491.  
  3492.  
  3493.  
  3494.  
  3495.                                   14 - 52
  3496.  
  3497.  
  3498.  
  3499.  
  3500.  
  3501.  
  3502.  
  3503.  
  3504.        -- Character Input-Output
  3505.  
  3506.        procedure GET(FILE : in  FILE_TYPE; ITEM : out CHARACTER);
  3507.        procedure GET(ITEM : out CHARACTER);
  3508.        procedure PUT(FILE : in  FILE_TYPE; ITEM : in CHARACTER);
  3509.        procedure PUT(ITEM : in  CHARACTER);
  3510.  
  3511.        -- String Input-Output
  3512.  
  3513.        procedure GET(FILE : in  FILE_TYPE; ITEM : out STRING);
  3514.        procedure GET(ITEM : out STRING);
  3515.        procedure PUT(FILE : in  FILE_TYPE; ITEM : in STRING);
  3516.        procedure PUT(ITEM : in  STRING);
  3517.  
  3518.        procedure GET_LINE(FILE : in  FILE_TYPE; ITEM : out STRING; LAST : out NATURAL);
  3519.        procedure GET_LINE(ITEM : out STRING; LAST : out NATURAL);
  3520.        procedure PUT_LINE(FILE : in  FILE_TYPE; ITEM : in STRING);
  3521.        procedure PUT_LINE(ITEM : in  STRING);
  3522.  
  3523.        -- Generic package for Input-Output of Integer Types
  3524.  
  3525.        generic
  3526.           type NUM is range <>;
  3527.        package INTEGER_IO is
  3528.  
  3529.           DEFAULT_WIDTH : FIELD := NUM'WIDTH;
  3530.           DEFAULT_BASE  : NUMBER_BASE := 10;
  3531.  
  3532.           procedure GET(FILE : in  FILE_TYPE; ITEM : out NUM; WIDTH : in FIELD := 0);
  3533.           procedure GET(ITEM : out NUM; WIDTH : in FIELD := 0);
  3534.  
  3535.           procedure PUT(FILE  : in FILE_TYPE;
  3536.                         ITEM  : in NUM;
  3537.                         WIDTH : in FIELD := DEFAULT_WIDTH;
  3538.                         BASE  : in NUMBER_BASE := DEFAULT_BASE);
  3539.           procedure PUT(ITEM  : in NUM;
  3540.                         WIDTH : in FIELD := DEFAULT_WIDTH;
  3541.                         BASE  : in NUMBER_BASE := DEFAULT_BASE);
  3542.  
  3543.           procedure GET(FROM : in  STRING; ITEM : out NUM; LAST : out POSITIVE);
  3544.           procedure PUT(TO   : out STRING;
  3545.                         ITEM : in NUM;
  3546.                         BASE : in NUMBER_BASE := DEFAULT_BASE);
  3547.  
  3548.        end INTEGER_IO;
  3549.  
  3550.  
  3551.  
  3552.  
  3553.  
  3554.  
  3555.  
  3556.  
  3557.  
  3558.  
  3559.  
  3560.  
  3561.                                   14 - 53
  3562.  
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568.  
  3569.  
  3570.        -- Generic packages for Input-Output of Real Types
  3571.  
  3572.        generic
  3573.           type NUM is digits <>;
  3574.        package FLOAT_IO is
  3575.  
  3576.           DEFAULT_FORE : FIELD := 2;
  3577.           DEFAULT_AFT  : FIELD := NUM'DIGITS-1;
  3578.           DEFAULT_EXP  : FIELD := 3;
  3579.  
  3580.           procedure GET(FILE : in FILE_TYPE; ITEM : out NUM; WIDTH : in FIELD := 0);
  3581.           procedure GET(ITEM : out NUM; WIDTH : in FIELD := 0);
  3582.  
  3583.           procedure PUT(FILE : in FILE_TYPE;
  3584.                         ITEM : in NUM;
  3585.                         FORE : in FIELD := DEFAULT_FORE;
  3586.                         AFT  : in FIELD := DEFAULT_AFT;
  3587.                         EXP  : in FIELD := DEFAULT_EXP);
  3588.           procedure PUT(ITEM : in NUM;
  3589.                         FORE : in FIELD := DEFAULT_FORE;
  3590.                         AFT  : in FIELD := DEFAULT_AFT;
  3591.                         EXP  : in FIELD := DEFAULT_EXP);
  3592.  
  3593.           procedure GET(FROM : in STRING; ITEM : out NUM; LAST : out POSITIVE);
  3594.           procedure PUT(TO   : out STRING;
  3595.                         ITEM : in NUM;
  3596.                         AFT  : in FIELD := DEFAULT_AFT;
  3597.                         EXP  : in FIELD := DEFAULT_EXP);
  3598.        end FLOAT_IO;
  3599.  
  3600.        generic
  3601.           type NUM is delta <>;
  3602.        package FIXED_IO is
  3603.  
  3604.           DEFAULT_FORE : FIELD := NUM'FORE;
  3605.           DEFAULT_AFT  : FIELD := NUM'AFT;
  3606.           DEFAULT_EXP  : FIELD := 0;
  3607.  
  3608.           procedure GET(FILE : in FILE_TYPE; ITEM : out NUM; WIDTH : in FIELD := 0);
  3609.           procedure GET(ITEM : out NUM; WIDTH : in FIELD := 0);
  3610.  
  3611.           procedure PUT(FILE : in FILE_TYPE;
  3612.                         ITEM : in NUM;
  3613.                         FORE : in FIELD := DEFAULT_FORE;
  3614.                         AFT  : in FIELD := DEFAULT_AFT;
  3615.                         EXP  : in FIELD := DEFAULT_EXP);
  3616.           procedure PUT(ITEM : in NUM;
  3617.                         FORE : in FIELD := DEFAULT_FORE;
  3618.                         AFT  : in FIELD := DEFAULT_AFT;
  3619.                         EXP  : in FIELD := DEFAULT_EXP);
  3620.  
  3621.           procedure GET(FROM : in  STRING; ITEM : out NUM; LAST : out POSITIVE);
  3622.           procedure PUT(TO   : out STRING;
  3623.                         ITEM : in NUM;
  3624.                         AFT  : in FIELD := DEFAULT_AFT;
  3625.  
  3626.  
  3627.                                   14 - 54
  3628.  
  3629.  
  3630.  
  3631.  
  3632.  
  3633.  
  3634.  
  3635.  
  3636.                         EXP  : in FIELD := DEFAULT_EXP);
  3637.  
  3638.        end FIXED_IO;
  3639.  
  3640.  
  3641.  
  3642.  
  3643.  
  3644.  
  3645.  
  3646.  
  3647.  
  3648.  
  3649.  
  3650.  
  3651.  
  3652.  
  3653.  
  3654.  
  3655.  
  3656.  
  3657.  
  3658.  
  3659.  
  3660.  
  3661.  
  3662.  
  3663.  
  3664.  
  3665.  
  3666.  
  3667.  
  3668.  
  3669.  
  3670.  
  3671.  
  3672.  
  3673.  
  3674.  
  3675.  
  3676.  
  3677.  
  3678.  
  3679.  
  3680.  
  3681.  
  3682.  
  3683.  
  3684.  
  3685.  
  3686.  
  3687.  
  3688.  
  3689.  
  3690.  
  3691.  
  3692.  
  3693.                                   14 - 55
  3694.  
  3695.  
  3696.  
  3697.  
  3698.  
  3699.  
  3700.  
  3701.  
  3702.        -- Generic package for Input-Output of Enumeration Types
  3703.  
  3704.        generic
  3705.           type ENUM is (<>);
  3706.        package ENUMERATION_IO is
  3707.  
  3708.           DEFAULT_WIDTH   : FIELD := 0;
  3709.           DEFAULT_SETTING : TYPE_SET := UPPER_CASE;
  3710.  
  3711.           procedure GET(FILE  : in FILE_TYPE; ITEM : out ENUM);
  3712.           procedure GET(ITEM  : out ENUM);
  3713.  
  3714.           procedure PUT(FILE  : in FILE_TYPE;
  3715.                         ITEM  : in ENUM;
  3716.                         WIDTH : in FIELD    := DEFAULT_WIDTH;
  3717.                         SET   : in TYPE_SET := DEFAULT_SETTING);
  3718.           procedure PUT(ITEM  : in ENUM;
  3719.                         WIDTH : in FIELD    := DEFAULT_WIDTH;
  3720.                         SET   : in TYPE_SET := DEFAULT_SETTING);
  3721.  
  3722.           procedure GET(FROM : in  STRING; ITEM : out ENUM; LAST : out POSITIVE);
  3723.           procedure PUT(TO   : out STRING;
  3724.                         ITEM : in  ENUM;
  3725.                         SET  : in  TYPE_SET := DEFAULT_SETTING);
  3726.        end ENUMERATION_IO;
  3727.  
  3728.        -- Exceptions
  3729.  
  3730.        STATUS_ERROR : exception renames IO_EXCEPTIONS.STATUS_ERROR;
  3731.        MODE_ERROR   : exception renames IO_EXCEPTIONS.MODE_ERROR;
  3732.        NAME_ERROR   : exception renames IO_EXCEPTIONS.NAME_ERROR;
  3733.        USE_ERROR    : exception renames IO_EXCEPTIONS.USE_ERROR;
  3734.        DEVICE_ERROR : exception renames IO_EXCEPTIONS.DEVICE_ERROR;
  3735.        END_ERROR    : exception renames IO_EXCEPTIONS.END_ERROR;
  3736.        DATA_ERROR   : exception renames IO_EXCEPTIONS.DATA_ERROR;
  3737.        LAYOUT_ERROR : exception renames IO_EXCEPTIONS.LAYOUT_ERROR;
  3738.  
  3739.     private
  3740.        -- implementation-dependent
  3741.     end TEXT_IO;
  3742.  
  3743.  
  3744.  
  3745.  
  3746. 14.4  Exceptions in Input-Output
  3747.  
  3748.  
  3749. The following exceptions can be raised by  input-output  operations.   They
  3750. are  declared  in the package IO_EXCEPTIONS, defined in section 14.5;  this
  3751. package is named in the context clause for each of the  three  input-output
  3752. packages.   Only  outline  descriptions  are  given of the conditions under
  3753. which NAME_ERROR, USE_ERROR, and DEVICE_ERROR are raised;  for full details
  3754. see Appendix F.  If more than one error condition exists, the corresponding
  3755. exception that appears earliest in the following list is the  one  that  is
  3756. raised.
  3757.  
  3758.  
  3759.                                   14 - 56
  3760.  
  3761.  
  3762.  
  3763.  
  3764.  
  3765.  
  3766.  
  3767.  
  3768. The  exception  STATUS_ERROR is raised by an attempt to operate upon a file
  3769. that is not open, and by an attempt to open a file that is already open.
  3770.  
  3771.  
  3772.  
  3773.  
  3774.  
  3775.  
  3776.  
  3777.  
  3778.  
  3779.  
  3780.  
  3781.  
  3782.  
  3783.  
  3784.  
  3785.  
  3786.  
  3787.  
  3788.  
  3789.  
  3790.  
  3791.  
  3792.  
  3793.  
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815.  
  3816.  
  3817.  
  3818.  
  3819.  
  3820.  
  3821.  
  3822.  
  3823.  
  3824.  
  3825.                                   14 - 57
  3826.  
  3827.  
  3828.  
  3829.  
  3830.  
  3831.  
  3832.  
  3833.  
  3834. The exception MODE_ERROR is raised by an attempt to read from, or test  for
  3835. the  end  of, a file whose current mode is OUT_FILE, and also by an attempt
  3836. to write to a file whose current mode is IN_FILE.  In the case of  TEXT_IO,
  3837. the  exception MODE_ERROR is also raised by specifying a file whose current
  3838. mode is OUT_FILE in a call of SET_INPUT, SKIP_LINE, END_OF_LINE, SKIP_PAGE,
  3839. or END_OF_PAGE;  and by specifying a file whose current mode is IN_FILE  in
  3840. a   call  of  SET_OUTPUT,  SET_LINE_LENGTH,  SET_PAGE_LENGTH,  LINE_LENGTH,
  3841. PAGE_LENGTH, NEW_LINE, or NEW_PAGE.
  3842.  
  3843. The exception NAME_ERROR is raised by a call  of  CREATE  or  OPEN  if  the
  3844. string given for the parameter NAME does not allow the identification of an
  3845. external  file.   For  example,  this  exception is raised if the string is
  3846. improper, or, alternatively, if either none or more than one external  file
  3847. corresponds to the string.
  3848.  
  3849. The  exception USE_ERROR is raised if an operation is attempted that is not
  3850. possible for reasons that depend on characteristics of the  external  file.
  3851. For  example, this exception is raised by the procedure CREATE, among other
  3852. circumstances, if the given mode is OUT_FILE  but  the  form  specifies  an
  3853. input  only  device, if the parameter FORM specifies invalid access rights,
  3854. or if an external file with the given name already exists  and  overwriting
  3855. is not allowed.
  3856.  
  3857. The exception DEVICE_ERROR is raised if an input-output operation cannot be
  3858. completed because of a malfunction of the underlying system.
  3859.  
  3860. The exception END_ERROR is raised by an attempt to skip (read past) the end
  3861. of a file.
  3862.  
  3863. The exception DATA_ERROR may be raised by the procedure READ if the element
  3864. read cannot be interpreted as a value of the required type.  This exception
  3865. is  also  raised by a procedure GET (defined in the package TEXT_IO) if the
  3866. input character sequence fails to satisfy the required syntax,  or  if  the
  3867. value  input  does not belong to the range of the required type or subtype.
  3868.  
  3869. The exception LAYOUT_ERROR is raised (in text input-output) by  COL,  LINE,
  3870. or   PAGE   if  the  value  returned  exceeds  COUNT'LAST.   The  exception
  3871. LAYOUT_ERROR is also raised on output by an attempt to set column  or  line
  3872. numbers  in  excess of specified maximum line or page lengths, respectively
  3873. (excluding the unbounded cases).  It is also raised by an attempt   to  PUT
  3874. too many characters to a string.
  3875.  
  3876. References:   col  function  14.3.4,  create  procedure 14.2.1, end_of_line
  3877. function 14.3.4, end_of_page function  14.3.4,  external  file  14.1,  file
  3878. 14.1,  form  string 14.1, get procedure 14.3.5, in_file 14.1, io_exceptions
  3879. package 14.5, line  function  14.3.4,  line_length  function  14.3.4,  name
  3880. string  14.1,  new_line  procedure  14.3.4, new_page procedure 14.3.4, open
  3881. procedure 14.2.1, out_file 14.1, page function 14.3.4, page_length function
  3882. 14.3.4, put procedure  14.3.5,  read  procedure  14.2.2  14.2.3,  set_input
  3883. procedure   14.3.2,   set_line_length   14.3.3,   set_page_length   14.3.3,
  3884. set_output 14.3.2, skip_line procedure 14.3.4, skip_page procedure  14.3.4,
  3885. text_io package 14.3
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.                                   14 - 58
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  
  3899.  
  3900. 14.5  Specification of the Package IO_Exceptions
  3901.  
  3902.  
  3903. This  package  defines the exceptions needed by the packages SEQUENTIAL_IO,
  3904. DIRECT_IO, and TEXT_IO.
  3905.  
  3906.     package IO_EXCEPTIONS is
  3907.  
  3908.        STATUS_ERROR : exception;
  3909.        MODE_ERROR   : exception;
  3910.        NAME_ERROR   : exception;
  3911.        USE_ERROR    : exception;
  3912.        DEVICE_ERROR : exception;
  3913.        END_ERROR    : exception;
  3914.        DATA_ERROR   : exception;
  3915.        LAYOUT_ERROR : exception;
  3916.  
  3917.     end IO_EXCEPTIONS;
  3918.  
  3919.  
  3920.  
  3921.  
  3922. 14.6  Low Level Input-Output
  3923.  
  3924.  
  3925. A low level input-output operation is an operation  acting  on  a  physical
  3926. device.   Such  an  operation  is  handled by using one of the (overloaded)
  3927. predefined procedures SEND_CONTROL and RECEIVE_CONTROL.
  3928.  
  3929. A procedure SEND_CONTROL may be used  to  send  control  information  to  a
  3930. physical  device.   A  procedure RECEIVE_CONTROL may be used to monitor the
  3931. execution of an input-output operation by requesting information  from  the
  3932. physical device.
  3933.  
  3934. Such  procedures are declared in the standard package LOW_LEVEL_IO and have
  3935. two parameters identifying the device and the data.  However, the kinds and
  3936. formats  of  the  control  information  will   depend   on   the   physical
  3937. characteristics  of  the  machine  and the device.  Hence, the types of the
  3938. parameters are implementation-defined.   Overloaded  definitions  of  these
  3939. procedures should be provided for the supported devices.
  3940.  
  3941. The  visible  part  of the package defining these procedures is outlined as
  3942. follows:
  3943.  
  3944.     package LOW_LEVEL_IO is
  3945.        --  declarations of the possible types for DEVICE and DATA;
  3946.        --  declarations of overloaded procedures for these types:
  3947.        procedure SEND_CONTROL    (DEVICE : DEVICE_TYPE; DATA : in out DATA_TYPE);
  3948.        procedure RECEIVE_CONTROL (DEVICE : DEVICE_TYPE; DATA : in out DATA_TYPE);
  3949.     end;
  3950.  
  3951. The bodies of the procedures SEND_CONTROL and RECEIVE_CONTROL  for  various
  3952. devices  can  be  supplied  in the body of the package LOW_LEVEL_IO.  These
  3953. procedure bodies may be written with code statements.
  3954.  
  3955.  
  3956.  
  3957.                                   14 - 59
  3958.  
  3959.  
  3960.  
  3961.  
  3962.  
  3963.  
  3964.  
  3965.  
  3966. 14.7  Example of Input-Output
  3967.  
  3968.  
  3969. The following example shows the  use  of  some  of  the  text  input-output
  3970. facilities  in  a dialogue with a user at a terminal.  The user is prompted
  3971. to type a color, and the program responds by giving the number of items  of
  3972. that  color  available  in  stock,  according to an inventory.  The default
  3973. input and output  files  are  used.   For  simplicity,  all  the  requisite
  3974. instantiations  are  given  within one subprogram;  in practice, a package,
  3975. separate from the procedure, would be used.
  3976.  
  3977.     with TEXT_IO; use TEXT_IO;
  3978.     procedure DIALOGUE is
  3979.        type COLOR is (WHITE, RED, ORANGE, YELLOW, GREEN, BLUE, BROWN);
  3980.        package COLOR_IO is new ENUMERATION_IO(ENUM => COLOR);
  3981.        package NUMBER_IO is new INTEGER_IO(INTEGER);
  3982.        use COLOR_IO, NUMBER_IO;
  3983.  
  3984.        INVENTORY : array (COLOR) of INTEGER := (20, 17, 43, 10, 28, 173, 87);
  3985.        CHOICE : COLOR;
  3986.  
  3987.        procedure ENTER_COLOR (SELECTION : out COLOR) is
  3988.        begin
  3989.           loop
  3990.              begin
  3991.                 PUT("Color selected: ");  --  prompts user
  3992.                 GET(SELECTION);           --  accepts color typed, or raises exception
  3993.                 return;
  3994.              exception
  3995.                 when DATA_ERROR =>
  3996.                    PUT("Invalid color, try again.  ");  --  user has typed new line
  3997.                    NEW_LINE(2);
  3998.                    --  completes execution of the block statement
  3999.              end;
  4000.           end loop;  --  repeats the block statement until color accepted
  4001.        end;
  4002.     begin --  statements of DIALOGUE;
  4003.  
  4004.        NUMBER_IO.DEFAULT_WIDTH := 5;
  4005.  
  4006.        loop
  4007.  
  4008.           ENTER_COLOR(CHOICE);  --  user types color and new line
  4009.  
  4010.           SET_COL(5);  PUT(CHOICE); PUT(" items available:");
  4011.           SET_COL(40); PUT(INVENTORY(CHOICE));  --  default width is 5
  4012.           NEW_LINE;
  4013.        end loop;
  4014.     end DIALOGUE;
  4015.  
  4016. Example of an interaction (characters typed by the user are italicized):
  4017.  
  4018.     Color selected:  Black
  4019.     Invalid color, try again.
  4020.  
  4021.  
  4022.  
  4023.                                   14 - 60
  4024.  
  4025.  
  4026.  
  4027.  
  4028.  
  4029.  
  4030.  
  4031.  
  4032.     Color selected:  Blue
  4033.         BLUE items available:         173
  4034.     Color selected:  Yellow
  4035.         YELLOW items available:        10
  4036.  
  4037.  
  4038.  
  4039.  
  4040.  
  4041.  
  4042.  
  4043.  
  4044.  
  4045.  
  4046.  
  4047.  
  4048.  
  4049.  
  4050.  
  4051.  
  4052.  
  4053.  
  4054.  
  4055.  
  4056.  
  4057.  
  4058.  
  4059.  
  4060.  
  4061.  
  4062.  
  4063.  
  4064.  
  4065.  
  4066.  
  4067.  
  4068.  
  4069.  
  4070.  
  4071.  
  4072.  
  4073.  
  4074.  
  4075.  
  4076.  
  4077.  
  4078.  
  4079.  
  4080.  
  4081.  
  4082.  
  4083.  
  4084.  
  4085.  
  4086.  
  4087.  
  4088.  
  4089.                                   14 - 61
  4090.  
  4091.  
  4092.  
  4093.  
  4094.