Natools

Check-in [c30800d3c3]
Login
Overview
Comment:s_expressions-file_writers: add primitive to open or create when needed
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c30800d3c381128be995cd62c389c2c99bd52fb4
User & Date: nat on 2017-06-26 20:11:38
Other Links: manifest | tags
Context
2017-07-05
20:57
s_expressions-parsers-tests: improve coverage of Close_Current_List check-in: b150b39643 user: nat tags: trunk
2017-06-26
20:11
s_expressions-file_writers: add primitive to open or create when needed check-in: c30800d3c3 user: nat tags: trunk
2017-06-25
21:14
smaz_implementations-base_64: fix encoding issue with with multiblock check-in: 418ab16bcf user: nat tags: trunk
Changes

Modified src/natools-s_expressions-file_writers.adb from [96c31e5d5b] to [f0ef6fde5e].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
-- Copyright (c) 2014-2017, Natacha Porté                                   --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
70
71
72
73
74
75
76




























77
78
79
80
81
82
83
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







      Name : in String;
      Form : in String := "") is
   begin
      Finalize (Self.Holder);
      Stream_IO.Open (Self.Holder.File, Stream_IO.Append_File, Name, Form);
   end Open;


   function Open_Or_Create (Name : String; Form : String := "")
     return Writer is
   begin
      return Result : Writer do
         Open_Or_Create (Result, Name, Form);
      end return;
   end Open_Or_Create;


   procedure Open_Or_Create
     (Self : in out Writer;
      Name : in String;
      Form : in String := "") is
   begin
      Finalize (Self.Holder);

      Open_Attempt :
      begin
         Stream_IO.Open (Self.Holder.File, Stream_IO.Append_File, Name, Form);
         return;
      exception
         when Stream_IO.Name_Error => null;
      end Open_Attempt;

      Stream_IO.Create (Self.Holder.File, Stream_IO.Append_File, Name, Form);
   end Open_Or_Create;


   function Name (Self : Writer) return String is
   begin
      return Stream_IO.Name (Self.Holder.File);
   end Name;

end Natools.S_Expressions.File_Writers;

Modified src/natools-s_expressions-file_writers.ads from [01b696634e] to [595ca22ff2].

1
2

3
4
5
6
7
8
9
1

2
3
4
5
6
7
8
9

-
+







------------------------------------------------------------------------------
-- Copyright (c) 2014, Natacha Porté                                        --
-- Copyright (c) 2014-2017, Natacha Porté                                   --
--                                                                          --
-- Permission to use, copy, modify, and distribute this software for any    --
-- purpose with or without fee is hereby granted, provided that the above   --
-- copyright notice and this permission notice appear in all copies.        --
--                                                                          --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF         --
37
38
39
40
41
42
43










44
45
46
47
48
49
50
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60







+
+
+
+
+
+
+
+
+
+







      Name : in String;
      Form : in String := "");
   procedure Open
     (Self : in out Writer;
      Name : in String;
      Form : in String := "");
      --  Reinitialize Self using Stream_IO.Create or Stream_IO.Open

   function Open_Or_Create (Name : String; Form : String := "") return Writer;
   procedure Open_Or_Create
     (Self : in out Writer;
      Name : in String;
      Form : in String := "");
      --  Construct or reinitialize a writer, trying a regular open first
      --  and attempting to create if it doesn't work.
      --  Note that there is some time between failure to open and actual
      --  file creation, which might lead to race conditions.

   function Name (Self : Writer) return String;
      --  Return the underlying file name

private

   type Autoclose is new Ada.Finalization.Limited_Controlled with record