|
| 1 | +% Taken from pl-9.2.9-build/swipl-9.2.9/src/test.pl |
| 2 | +% 0'. can be a troble. |
| 3 | + |
| 4 | +/* Part of SWI-Prolog |
| 5 | +
|
| 6 | + Author: Jan Wielemaker and Anjo Anjewierden |
| 7 | + |
| 8 | + WWW: http://www.swi-prolog.org |
| 9 | + Copyright (c) 1996-2023, University of Amsterdam |
| 10 | + VU University Amsterdam |
| 11 | + CWI, Amsterdam |
| 12 | + SWI-Prolog Solutions b.v. |
| 13 | + All rights reserved. |
| 14 | +
|
| 15 | + Redistribution and use in source and binary forms, with or without |
| 16 | + modification, are permitted provided that the following conditions |
| 17 | + are met: |
| 18 | +
|
| 19 | + 1. Redistributions of source code must retain the above copyright |
| 20 | + notice, this list of conditions and the following disclaimer. |
| 21 | +
|
| 22 | + 2. Redistributions in binary form must reproduce the above copyright |
| 23 | + notice, this list of conditions and the following disclaimer in |
| 24 | + the documentation and/or other materials provided with the |
| 25 | + distribution. |
| 26 | +
|
| 27 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 | + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 | + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 30 | + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 31 | + COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 33 | + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 34 | + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 36 | + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 37 | + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 38 | + POSSIBILITY OF SUCH DAMAGE. |
| 39 | +*/ |
| 40 | + /******************************* |
| 41 | + * UNICODE FILENAMES * |
| 42 | + *******************************/ |
| 43 | + |
| 44 | +unicode_file_name(Name) :- |
| 45 | + current_prolog_flag(pid, Pid), |
| 46 | + atom_codes(Name0, [1074, 1086, 1079, 1076, 1091, 1093, 1072]), |
| 47 | + atomic_list_concat([Name0, -, Pid], Name). |
| 48 | + |
| 49 | +unicode_file(mkdir-1) :- % create Cyrillic directory |
| 50 | + unicode_file_name(Dir), |
| 51 | + catch(delete_directory(Dir), _, true), |
| 52 | + make_directory(Dir), |
| 53 | + exists_directory(Dir), |
| 54 | + working_directory(Old, Dir), |
| 55 | + working_directory(O2, '..'), |
| 56 | + same_file(Old, '.'), |
| 57 | + same_file(O2, Dir), |
| 58 | + delete_directory(Dir). |
| 59 | +unicode_file(file-1) :- % create Cyrillic file |
| 60 | + unicode_file_name(File), |
| 61 | + Term = hello(world), |
| 62 | + catch(delete_file(File), _, true), |
| 63 | + open(File, write, Out), |
| 64 | + format(Out, '~q.~n', [Term]), |
| 65 | + close(Out), |
| 66 | + exists_file(File), |
| 67 | + open(File, read, In), |
| 68 | + read(In, Read), |
| 69 | + close(In), |
| 70 | + Read =@= Term, |
| 71 | + delete_file(File). |
| 72 | +unicode_file(absfile-1) :- |
| 73 | + unicode_file_name(File), |
| 74 | + absolute_file_name(File, Path), |
| 75 | + file_directory_name(Path, Dir), |
| 76 | + same_file(Dir, '.'), |
| 77 | + file_base_name(Path, Base), |
| 78 | + Base == File. |
| 79 | +unicode_file(ext-1) :- |
| 80 | + atom_codes(File, [1074, 1086, 1079, 1076, 0'., 1091, 1093, 1072]), |
| 81 | + file_name_extension(Base, Ext, File), |
| 82 | + atom_codes(Base, [1074, 1086, 1079, 1076]), |
| 83 | + atom_codes(Ext, [1091, 1093, 1072]). |
| 84 | + |
| 85 | + |
| 86 | + /******************************* |
| 87 | + * SEEK * |
| 88 | + *******************************/ |
| 89 | + |
| 90 | +seek(write-1) :- |
| 91 | + tmp_file(seek, File), |
| 92 | + open(File, write, S, [type(binary)]), |
| 93 | + Max = 999, |
| 94 | + forall(between(0, Max, _), |
| 95 | + format(S, '1234567890~n', [])), |
| 96 | + forall(between(0, Max, N), |
| 97 | + ( Pos is N * 11 + 6, |
| 98 | + seek(S, Pos, bof, _), |
| 99 | + format(S, 'x', []) |
| 100 | + )), |
| 101 | + close(S), |
| 102 | + |
| 103 | + open(File, read, In, [type(binary)]), |
| 104 | + atom_codes('123456x890\n', Bytes), |
| 105 | + forall(between(0, Max, N), |
| 106 | + must_read(Bytes, In)), |
| 107 | + close(In), |
| 108 | + delete_file(File). |
0 commit comments