gnoga_2.1.2_5f127c56/deps/zanyblue/src/os/zanyblue-directories.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 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
 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
--  -*- coding: utf-8 -*-
--
--  ZanyBlue, an Ada library and framework for finite element analysis.
--
--  Copyright (c) 2017, Michael Rohan <mrohan@zanyblue.com>
--  All rights reserved.
--
--  Redistribution and use in source and binary forms, with or without
--  modification, are permitted provided that the following conditions
--  are met:
--
--    * Redistributions of source code must retain the above copyright
--      notice, this list of conditions and the following disclaimer.
--
--    * Redistributions in binary form must reproduce the above copyright
--      notice, this list of conditions and the following disclaimer in the
--      documentation and/or other materials provided with the distribution.
--
--    * Neither the name of ZanyBlue nor the names of its contributors may
--      be used to endorse or promote products derived from this software
--      without specific prior written permission.
--
--  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
--  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
--  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
--  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
--  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
--  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
--  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
--  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
--  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
--  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--

--
--  This is a simple wrapper package around the standard Ada.Directories
--  package with String arguments and functions.  The underlying
--  Strings from Ada.Directories are simply interpreted as UTF-8 encoded
--  strings and are decoded to UXStrings.
--

package body ZanyBlue.Directories is

   use Ada.Directories;

   ---------------
   -- Base_Name --
   ---------------

   function Base_Name
     (Name : String)
      return String
   is
   begin
      return From_UTF_8 (Base_Name (To_UTF_8 (Name)));
   end Base_Name;

   -------------
   -- Compose --
   -------------

   function Compose
     (Containing_Directory : String := "";
      Name                 : String;
      Extension            : String := "")
      return String
   is
   begin
      return
        From_UTF_8
          (Compose
             (To_UTF_8 (Containing_Directory), To_UTF_8 (Name),
              To_UTF_8 (Extension)));
   end Compose;

   --------------------------
   -- Containing_Directory --
   --------------------------

   function Containing_Directory
     (Name : String)
      return String
   is
   begin
      return From_UTF_8 (Containing_Directory (To_UTF_8 (Name)));
   end Containing_Directory;

   ---------------
   -- Copy_File --
   ---------------

   procedure Copy_File
     (Source_Name : String;
      Target_Name : String;
      Form        : String := "")
   is
   begin
      Copy_File
        (To_UTF_8 (Source_Name), To_UTF_8 (Target_Name), To_UTF_8 (Form));
   end Copy_File;

   ----------------------
   -- Create_Directory --
   ----------------------

   procedure Create_Directory
     (New_Directory : String;
      Form          : String := "")
   is
   begin
      Create_Directory (To_UTF_8 (New_Directory), To_UTF_8 (Form));
   end Create_Directory;

   -----------------
   -- Create_Path --
   -----------------

   procedure Create_Path
     (New_Directory : String;
      Form          : String := "")
   is
   begin
      Create_Path (To_UTF_8 (New_Directory), To_UTF_8 (Form));
   end Create_Path;

   -----------------------
   -- Current_Directory --
   -----------------------

   function Current_Directory return String is
   begin
      return From_UTF_8 (Current_Directory);
   end Current_Directory;

   ----------------------
   -- Delete_Directory --
   ----------------------

   procedure Delete_Directory (Directory : String) is
   begin
      Delete_Directory (To_UTF_8 (Directory));
   end Delete_Directory;

   -----------------
   -- Delete_File --
   -----------------

   procedure Delete_File (Name : String) is
   begin
      Delete_File (To_UTF_8 (Name));
   end Delete_File;

   -----------------
   -- Delete_Tree --
   -----------------

   procedure Delete_Tree (Directory : String) is
   begin
      Delete_Tree (To_UTF_8 (Directory));
   end Delete_Tree;

   ----------------
   -- End_Search --
   ----------------

   procedure End_Search (Search : in out Search_Type) renames
     Ada.Directories.End_Search;

   ------------
   -- Exists --
   ------------

   function Exists
     (Name : String)
      return Boolean
   is
   begin
      return Exists (To_UTF_8 (Name));
   end Exists;

   ---------------
   -- Extension --
   ---------------

   function Extension
     (Name : String)
      return String
   is
   begin
      return From_UTF_8 (Extension (To_UTF_8 (Name)));
   end Extension;

   ---------------
   -- Full_Name --
   ---------------

   function Full_Name
     (Name : String)
      return String
   is
   begin
      return From_UTF_8 (Full_Name (To_UTF_8 (Name)));
   end Full_Name;

   ---------------
   -- Full_Name --
   ---------------

   function Full_Name
     (Directory_Entry : Directory_Entry_Type)
      return String
   is
   begin
      return From_UTF_8 (Full_Name (Directory_Entry));
   end Full_Name;

   --------------------
   -- Get_Next_Entry --
   --------------------

   procedure Get_Next_Entry
     (Search          : in out Search_Type;
      Directory_Entry :    out Directory_Entry_Type) renames
     Ada.Directories.Get_Next_Entry;

   ----------
   -- Kind --
   ----------

   function Kind
     (Name : String)
      return File_Kind
   is
   begin
      return Kind (To_UTF_8 (Name));
   end Kind;

   ----------
   -- Kind --
   ----------

   function Kind
     (Directory_Entry : Directory_Entry_Type)
      return File_Kind renames Ada.Directories.Kind;

   -----------------------
   -- Modification_Time --
   -----------------------

   function Modification_Time
     (Name : String)
      return Ada.Calendar.Time
   is
   begin
      return Modification_Time (To_UTF_8 (Name));
   end Modification_Time;

   -----------------------
   -- Modification_Time --
   -----------------------

   function Modification_Time
     (Directory_Entry : Directory_Entry_Type)
      return Ada.Calendar.Time renames Ada.Directories.Modification_Time;

   ------------------
   -- More_Entries --
   ------------------

   function More_Entries
     (Search : Search_Type)
      return Boolean renames Ada.Directories.More_Entries;

   ------------
   -- Rename --
   ------------

   procedure Rename (Old_Name, New_Name : String) is
   begin
      Rename (To_UTF_8 (Old_Name), To_UTF_8 (New_Name));
   end Rename;

   ------------
   -- Search --
   ------------

   procedure Search
     (Directory : String;
      Pattern   : String;
      Filter    : Filter_Type := (others => True);
      Process   : not null access procedure
        (Directory_Entry : Directory_Entry_Type))
   is
   begin
      Search (To_UTF_8 (Directory), To_UTF_8 (Pattern), Filter, Process);
   end Search;

   -------------------
   -- Set_Directory --
   -------------------

   procedure Set_Directory (Directory : String) is
   begin
      Set_Directory (To_UTF_8 (Directory));
   end Set_Directory;

   -----------------
   -- Simple_Name --
   -----------------

   function Simple_Name
     (Name : String)
      return String
   is
   begin
      return From_UTF_8 (Simple_Name (To_UTF_8 (Name)));
   end Simple_Name;

   -----------------
   -- Simple_Name --
   -----------------

   function Simple_Name
     (Directory_Entry : Directory_Entry_Type)
      return String
   is
   begin
      return From_UTF_8 (Simple_Name (Directory_Entry));
   end Simple_Name;

   ----------
   -- Size --
   ----------

   function Size
     (Name : String)
      return File_Size
   is
   begin
      return Size (To_UTF_8 (Name));
   end Size;

   ----------
   -- Size --
   ----------

   function Size
     (Directory_Entry : Directory_Entry_Type)
      return File_Size renames Ada.Directories.Size;

   ------------------
   -- Start_Search --
   ------------------

   procedure Start_Search
     (Search    : in out Search_Type;
      Directory :        String;
      Pattern   :        String;
      Filter    :        Filter_Type := (others => True))
   is
   begin
      Start_Search (Search, To_UTF_8 (Directory), To_UTF_8 (Pattern), Filter);
   end Start_Search;

end ZanyBlue.Directories;