From 8e685426015c5a014ee0d6a5734985eb9570a610 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 14 Apr 2020 13:37:12 -0600 Subject: [PATCH 01/36] [Changes in parallel to fsunix.pro and fswin32.pro]. Re-ordered exports to better group related predicates; placed files related predicates before directory-related predicates. Moved file_status/2 to first to make it available for use in examples with other predicates in the file. Completed in-code documentation of file_status/2 including description and examples, for future use with doctools. --- core/alsp_src/builtins/fsunix.pro | 132 ++++++++++-------- core/alsp_src/builtins/fswin32.pro | 127 ++++++++++------- core/alsp_src/tests/atest_db.pro | 2 + .../tests/tsuite/fsunix_mswin32_test.pro | 38 +++++ 4 files changed, 189 insertions(+), 110 deletions(-) create mode 100644 core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index fb84d0481..1cb1f8796 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -9,23 +9,94 @@ | Date: Begun 4/88 | Revision: Ken Bowen -- 11/88, 1/91 | -- library version: 11/91 + | + | Note: Depends on core/alsp_src/unix/unix_makefile & friends + | Note: Some examples below utilize ls/0 as defined in blt_sys.pro. *===========================================================================*/ module builtins. +export file_status/2. +export files/2. +export files/3. +export move_file/2. export make_subdir/1. export make_subdir/2. export remove_subdir/1. export kill_subdir/1. -export file_status/2. -export files/2. -export files/3. export subdirs/1. export subdirs_red/1. export directory/3. export get_current_drive/1. export change_current_drive/1. -export move_file/2. +/*!------------------------------------------------------------------ + | file_status/2 + | file_status(FileName, Status) + | file_status(+, -) + | + | - Returns OS information about a file named FileName + | + | If FileName is the name associated with an entry in the + | OS filesystem, returns OS information about that entry, + | as in the following two examples: + | + | Examples + | ?- file_status(alspro, Status). + | + | Status=[type = regular,permissions = [read,write,execute], + | mod_time = 1586731762.0,size = 462720] + | + | ?- file_status(alsdir, Status). + | + | Status=[type = directory,permissions = [read,write,execute], + | mod_time = 1586652989.0,size = 204] + *!-----------------------------------------------------------------*/ +file_status(FileName, Status) + :- + '$getFileStatus'(FileName, + fileStatus(FileTypeCode, ModTime, OwnerPermiss, + ByteSize,NBlocks)), + fileTypeCode(FileTypeCode,FileType), + ownerPermissionsCoding(OwnerPermiss, Permissions), + Status = [type=FileType, permissions=Permissions, + mod_time=ModTime, size=ByteSize]. + +/*--------------------------------------------------------------- + | File types/attributes -- at the abstract (Prolog) level: + | regular -- an ordinary file + | directory + *---------------------------------------------------------------*/ + +/*---------------------------------------------------------------- + | Unix file status/type codes: + | + | 0 = unknown + | 1 = directory + | 2 = character_special + | 3 = block_special + | 4 = regular + | 5 = symbolic_link + | 6 = socket + | 7 = fifo_pipe + *----------------------------------------------------------------*/ + +fileTypeCode(0, unknown). +fileTypeCode(1, directory). +fileTypeCode(2, character_special). +fileTypeCode(3, block_special). +fileTypeCode(4, regular). +fileTypeCode(5, symbolic_link). +fileTypeCode(6, socket). +fileTypeCode(7, fifo_pipe). + +ownerPermissionsCoding(0,[]). +ownerPermissionsCoding(1,[execute]). +ownerPermissionsCoding(2,[write]). +ownerPermissionsCoding(3,[write,execute]). +ownerPermissionsCoding(4,[read]). +ownerPermissionsCoding(5,[read,execute]). +ownerPermissionsCoding(6,[read,write]). +ownerPermissionsCoding(7,[read,write,execute]). /*!-------------------------------------------------------------- | make_subdir/1 @@ -193,59 +264,6 @@ subdirs_red(SubdirList) list_delete(SubdirList0, '.', SubdirList1), list_delete(SubdirList1, '..', SubdirList). -/*--------------------------------------------------------------- - | File types/attributes: - | -- at the abstract (Prolog) level: - | - | regular -- an ordinary file - | directory - *---------------------------------------------------------------*/ - -/*---------------------------------------------------------------- - | Unix file status/type codes: - | - | 0 = unknown - | 1 = directory - | 2 = character_special - | 3 = block_special - | 4 = regular - | 5 = symbolic_link - | 6 = socket - | 7 = fifo_pipe - *----------------------------------------------------------------*/ - -fileTypeCode(0, unknown). -fileTypeCode(1, directory). -fileTypeCode(2, character_special). -fileTypeCode(3, block_special). -fileTypeCode(4, regular). -fileTypeCode(5, symbolic_link). -fileTypeCode(6, socket). -fileTypeCode(7, fifo_pipe). - -ownerPermissionsCoding(0,[]). -ownerPermissionsCoding(1,[execute]). -ownerPermissionsCoding(2,[write]). -ownerPermissionsCoding(3,[write,execute]). -ownerPermissionsCoding(4,[read]). -ownerPermissionsCoding(5,[read,execute]). -ownerPermissionsCoding(6,[read,write]). -ownerPermissionsCoding(7,[read,write,execute]). - -/*!------------------------------------------------------------------ - | file_status/2 - | file_status(FileName, Status) - | file_status(+, -) - *!-----------------------------------------------------------------*/ -file_status(FileName, Status) - :- - '$getFileStatus'(FileName, - fileStatus(FileTypeCode, ModTime, OwnerPermiss, - ByteSize,NBlocks)), - fileTypeCode(FileTypeCode,FileType), - ownerPermissionsCoding(OwnerPermiss, Permissions), - Status = [type=FileType, permissions=Permissions, - mod_time=ModTime, size=ByteSize]. /*!------------------------------------------------------------------ | directory/3 diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 5fc6e1167..5094a5209 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -7,25 +7,93 @@ | | Authors: Chuck Hoput (based on other fs-xxx.pro files) | Date: 1/96 + | + | Note: Depends on core/alsp_src/win32/win32_makefile & friends + | Note: Some examples below utilize dir/0 as defined in blt_sys.pro. *====================================================================*/ - module builtins. +export file_status/2. +export files/2. +export files/3. +export move_file/2. export make_subdir/1. export make_subdir/2. export remove_subdir/1. -export file_status/2. -export files/2. -export files/3. +export kill_subdir/1. + export subdirs/1. export subdirs_red/1. export directory/3. - export get_current_drive/1. export change_current_drive/1. -export move_file/2. +/*!------------------------------------------------------------------ + | file_status/2 + | file_status(FileName, Status) + | file_status(+, -) + | + | - Returns OS information about a file named FileName + | + | If FileName is the name associated with an entry in the + | OS filesystem, returns OS information about that entry, + | as in the following two examples: + | + | Examples + | ?- file_status(alspro, Status). + | + | Status=[type = regular,permissions = [read,write,execute], + | mod_time = 1586731762.0,size = 462720] + | + | ?- file_status(alsdir, Status). + | + | Status=[type = directory,permissions = [read,write,execute], + | mod_time = 1586652989.0,size = 204] + *!-----------------------------------------------------------------*/ +file_status(FileName,Status) :- + '$getFileStatus'(FileName, + fileStatus(FileTypeCode,ModTime,OwnerPermiss,ByteSize,NBlocks)), + fileTypeCode(FileTypeCode,FileType), + ownerPermissionsCoding(OwnerPermiss,Permissions), + Status = [type=FileType,permissions=Permissions,mod_time=ModTime,size=ByteSize]. + + /*--------------------------------------------------------------- + | File types/attributes -- at the abstract (Prolog) level: + | regular -- an ordinary file + | directory + *---------------------------------------------------------------*/ + +/* +fileTypeCode('????', unknown). +fileTypeCode('Fldr', directory). +fileTypeCode('TEXT', regular). +fileTypeCode(_,unknown). +*/ + +/* +ownerPermissionCoding(0,[]). +ownerPermissionCoding(4,[read]). +ownerPermissionCoding(6,[read,write]). +*/ + + +fileTypeCode(0, unknown). +fileTypeCode(1, directory). +fileTypeCode(4, regular). +fileTypeCode(5, symbolic_link). +fileTypeCode(5, alias). + +%fileTypeCode(30 , mac_type('TEXT')). + +ownerPermissionsCoding(0,[]). +ownerPermissionsCoding(1,[execute]). +ownerPermissionsCoding(2,[write]). +ownerPermissionsCoding(3,[write,execute]). +ownerPermissionsCoding(4,[read]). +ownerPermissionsCoding(5,[read,execute]). +ownerPermissionsCoding(6,[read,write]). +ownerPermissionsCoding(7,[read,write,execute]). /*!-------------------------------------------------------------- | make_subdir/1 @@ -146,53 +214,6 @@ subdirs_red(SubdirList) list_delete(SubdirList0, '.', SubdirList1), list_delete(SubdirList1, '..', SubdirList). - /*--------------------------------------------------------------- - | File types/attributes: - | -- at the abstract (Prolog) level: - | - | regular -- an ordinary file - | directory - *---------------------------------------------------------------*/ - -/* -fileTypeCode('????', unknown). -fileTypeCode('Fldr', directory). -fileTypeCode('TEXT', regular). -fileTypeCode(_,unknown). -*/ - -ownerPermissionCoding(0,[]). -ownerPermissionCoding(4,[read]). -ownerPermissionCoding(6,[read,write]). - - -fileTypeCode(0, unknown). -fileTypeCode(1, directory). -fileTypeCode(4, regular). -fileTypeCode(5, symbolic_link). -fileTypeCode(5, alias). - -fileTypeCode(30 , mac_type('TEXT')). - - -ownerPermissionsCoding(0,[]). -ownerPermissionsCoding(1,[execute]). -ownerPermissionsCoding(2,[write]). -ownerPermissionsCoding(3,[write,execute]). -ownerPermissionsCoding(4,[read]). -ownerPermissionsCoding(5,[read,execute]). -ownerPermissionsCoding(6,[read,write]). -ownerPermissionsCoding(7,[read,write,execute]). - -/*!------------------------------------------------------------------ - *!-----------------------------------------------------------------*/ -file_status(FileName,Status) :- - '$getFileStatus'(FileName, - fileStatus(FileTypeCode,ModTime,OwnerPermiss,ByteSize,NBlocks)), - fileTypeCode(FileTypeCode,FileType), -% ownerPermissionCoding(OwnerPermiss,Permissions), - ownerPermissionsCoding(OwnerPermiss,Permissions), - Status = [type=FileType,permissions=Permissions,mod_time=ModTime,size=ByteSize]. /*!------------------------------------------------------------------ | directory/3 diff --git a/core/alsp_src/tests/atest_db.pro b/core/alsp_src/tests/atest_db.pro index b134007d6..0d1806d57 100644 --- a/core/alsp_src/tests/atest_db.pro +++ b/core/alsp_src/tests/atest_db.pro @@ -81,6 +81,8 @@ test_info(par4, par4, user, main, test_info(filepath_test, filepath_test, user, test_filepath, 'tests for file system paths.'). +test_info(fsunix_mswin32_test, fsunix_mswin32_test, user, test_fsunix_mswin32, 'tests for misc filesystem functions.'). + %test_info(freeze_test, freeze, user, test_freeze, ' tests for freeze.'). % test_info Format: diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro new file mode 100644 index 000000000..399aafea6 --- /dev/null +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -0,0 +1,38 @@ +:-[test]. + +test_fsunix_mswin32 + :- + sys_env(OS,_,_), + do_test_fs(OS). + +do_test_fs(OS) + :- + test([ + test_file_status, + +% test_make_subdir1, +% test_make_subdir2, +% test_recursive_dir_path, +% test_recursive_dir_paths, + true]). + +do_test_fs(OS) + :- + test([ + true]). + + +test_file_status + :- + system('rm -rf regFile1.txt'), + system('echo "hi" > regFile1.txt'), + test([ + (file_status('regFile1.txt', Status), + nonvar(Status), + member(mod_time = M, Status), + Status == [type = regular,permissions = [read,write], mod_time = M, size = 3]), + true]), + system('rm -rf regFile1.txt'). + + + From c925047f7f014580f61c11c29b812ceb8082fc14 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 14 Apr 2020 13:37:12 -0600 Subject: [PATCH 02/36] [Changes in parallel to fsunix.pro and fswin32.pro]. Re-ordered exports to better group related predicates; placed files related predicates before directory-related predicates. Moved file_status/2 to first to make it available for use in examples with other predicates in the file. Completed in-code documentation of file_status/2 including description and examples, for future use with doctools. Create test file fsunix_mswin32_test.pro with current framework, and add test_file_status. --- core/alsp_src/builtins/fsunix.pro | 132 ++++++++++-------- core/alsp_src/builtins/fswin32.pro | 127 ++++++++++------- core/alsp_src/tests/atest_db.pro | 2 + .../tests/tsuite/fsunix_mswin32_test.pro | 38 +++++ 4 files changed, 189 insertions(+), 110 deletions(-) create mode 100644 core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index fb84d0481..1cb1f8796 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -9,23 +9,94 @@ | Date: Begun 4/88 | Revision: Ken Bowen -- 11/88, 1/91 | -- library version: 11/91 + | + | Note: Depends on core/alsp_src/unix/unix_makefile & friends + | Note: Some examples below utilize ls/0 as defined in blt_sys.pro. *===========================================================================*/ module builtins. +export file_status/2. +export files/2. +export files/3. +export move_file/2. export make_subdir/1. export make_subdir/2. export remove_subdir/1. export kill_subdir/1. -export file_status/2. -export files/2. -export files/3. export subdirs/1. export subdirs_red/1. export directory/3. export get_current_drive/1. export change_current_drive/1. -export move_file/2. +/*!------------------------------------------------------------------ + | file_status/2 + | file_status(FileName, Status) + | file_status(+, -) + | + | - Returns OS information about a file named FileName + | + | If FileName is the name associated with an entry in the + | OS filesystem, returns OS information about that entry, + | as in the following two examples: + | + | Examples + | ?- file_status(alspro, Status). + | + | Status=[type = regular,permissions = [read,write,execute], + | mod_time = 1586731762.0,size = 462720] + | + | ?- file_status(alsdir, Status). + | + | Status=[type = directory,permissions = [read,write,execute], + | mod_time = 1586652989.0,size = 204] + *!-----------------------------------------------------------------*/ +file_status(FileName, Status) + :- + '$getFileStatus'(FileName, + fileStatus(FileTypeCode, ModTime, OwnerPermiss, + ByteSize,NBlocks)), + fileTypeCode(FileTypeCode,FileType), + ownerPermissionsCoding(OwnerPermiss, Permissions), + Status = [type=FileType, permissions=Permissions, + mod_time=ModTime, size=ByteSize]. + +/*--------------------------------------------------------------- + | File types/attributes -- at the abstract (Prolog) level: + | regular -- an ordinary file + | directory + *---------------------------------------------------------------*/ + +/*---------------------------------------------------------------- + | Unix file status/type codes: + | + | 0 = unknown + | 1 = directory + | 2 = character_special + | 3 = block_special + | 4 = regular + | 5 = symbolic_link + | 6 = socket + | 7 = fifo_pipe + *----------------------------------------------------------------*/ + +fileTypeCode(0, unknown). +fileTypeCode(1, directory). +fileTypeCode(2, character_special). +fileTypeCode(3, block_special). +fileTypeCode(4, regular). +fileTypeCode(5, symbolic_link). +fileTypeCode(6, socket). +fileTypeCode(7, fifo_pipe). + +ownerPermissionsCoding(0,[]). +ownerPermissionsCoding(1,[execute]). +ownerPermissionsCoding(2,[write]). +ownerPermissionsCoding(3,[write,execute]). +ownerPermissionsCoding(4,[read]). +ownerPermissionsCoding(5,[read,execute]). +ownerPermissionsCoding(6,[read,write]). +ownerPermissionsCoding(7,[read,write,execute]). /*!-------------------------------------------------------------- | make_subdir/1 @@ -193,59 +264,6 @@ subdirs_red(SubdirList) list_delete(SubdirList0, '.', SubdirList1), list_delete(SubdirList1, '..', SubdirList). -/*--------------------------------------------------------------- - | File types/attributes: - | -- at the abstract (Prolog) level: - | - | regular -- an ordinary file - | directory - *---------------------------------------------------------------*/ - -/*---------------------------------------------------------------- - | Unix file status/type codes: - | - | 0 = unknown - | 1 = directory - | 2 = character_special - | 3 = block_special - | 4 = regular - | 5 = symbolic_link - | 6 = socket - | 7 = fifo_pipe - *----------------------------------------------------------------*/ - -fileTypeCode(0, unknown). -fileTypeCode(1, directory). -fileTypeCode(2, character_special). -fileTypeCode(3, block_special). -fileTypeCode(4, regular). -fileTypeCode(5, symbolic_link). -fileTypeCode(6, socket). -fileTypeCode(7, fifo_pipe). - -ownerPermissionsCoding(0,[]). -ownerPermissionsCoding(1,[execute]). -ownerPermissionsCoding(2,[write]). -ownerPermissionsCoding(3,[write,execute]). -ownerPermissionsCoding(4,[read]). -ownerPermissionsCoding(5,[read,execute]). -ownerPermissionsCoding(6,[read,write]). -ownerPermissionsCoding(7,[read,write,execute]). - -/*!------------------------------------------------------------------ - | file_status/2 - | file_status(FileName, Status) - | file_status(+, -) - *!-----------------------------------------------------------------*/ -file_status(FileName, Status) - :- - '$getFileStatus'(FileName, - fileStatus(FileTypeCode, ModTime, OwnerPermiss, - ByteSize,NBlocks)), - fileTypeCode(FileTypeCode,FileType), - ownerPermissionsCoding(OwnerPermiss, Permissions), - Status = [type=FileType, permissions=Permissions, - mod_time=ModTime, size=ByteSize]. /*!------------------------------------------------------------------ | directory/3 diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 5fc6e1167..5094a5209 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -7,25 +7,93 @@ | | Authors: Chuck Hoput (based on other fs-xxx.pro files) | Date: 1/96 + | + | Note: Depends on core/alsp_src/win32/win32_makefile & friends + | Note: Some examples below utilize dir/0 as defined in blt_sys.pro. *====================================================================*/ - module builtins. +export file_status/2. +export files/2. +export files/3. +export move_file/2. export make_subdir/1. export make_subdir/2. export remove_subdir/1. -export file_status/2. -export files/2. -export files/3. +export kill_subdir/1. + export subdirs/1. export subdirs_red/1. export directory/3. - export get_current_drive/1. export change_current_drive/1. -export move_file/2. +/*!------------------------------------------------------------------ + | file_status/2 + | file_status(FileName, Status) + | file_status(+, -) + | + | - Returns OS information about a file named FileName + | + | If FileName is the name associated with an entry in the + | OS filesystem, returns OS information about that entry, + | as in the following two examples: + | + | Examples + | ?- file_status(alspro, Status). + | + | Status=[type = regular,permissions = [read,write,execute], + | mod_time = 1586731762.0,size = 462720] + | + | ?- file_status(alsdir, Status). + | + | Status=[type = directory,permissions = [read,write,execute], + | mod_time = 1586652989.0,size = 204] + *!-----------------------------------------------------------------*/ +file_status(FileName,Status) :- + '$getFileStatus'(FileName, + fileStatus(FileTypeCode,ModTime,OwnerPermiss,ByteSize,NBlocks)), + fileTypeCode(FileTypeCode,FileType), + ownerPermissionsCoding(OwnerPermiss,Permissions), + Status = [type=FileType,permissions=Permissions,mod_time=ModTime,size=ByteSize]. + + /*--------------------------------------------------------------- + | File types/attributes -- at the abstract (Prolog) level: + | regular -- an ordinary file + | directory + *---------------------------------------------------------------*/ + +/* +fileTypeCode('????', unknown). +fileTypeCode('Fldr', directory). +fileTypeCode('TEXT', regular). +fileTypeCode(_,unknown). +*/ + +/* +ownerPermissionCoding(0,[]). +ownerPermissionCoding(4,[read]). +ownerPermissionCoding(6,[read,write]). +*/ + + +fileTypeCode(0, unknown). +fileTypeCode(1, directory). +fileTypeCode(4, regular). +fileTypeCode(5, symbolic_link). +fileTypeCode(5, alias). + +%fileTypeCode(30 , mac_type('TEXT')). + +ownerPermissionsCoding(0,[]). +ownerPermissionsCoding(1,[execute]). +ownerPermissionsCoding(2,[write]). +ownerPermissionsCoding(3,[write,execute]). +ownerPermissionsCoding(4,[read]). +ownerPermissionsCoding(5,[read,execute]). +ownerPermissionsCoding(6,[read,write]). +ownerPermissionsCoding(7,[read,write,execute]). /*!-------------------------------------------------------------- | make_subdir/1 @@ -146,53 +214,6 @@ subdirs_red(SubdirList) list_delete(SubdirList0, '.', SubdirList1), list_delete(SubdirList1, '..', SubdirList). - /*--------------------------------------------------------------- - | File types/attributes: - | -- at the abstract (Prolog) level: - | - | regular -- an ordinary file - | directory - *---------------------------------------------------------------*/ - -/* -fileTypeCode('????', unknown). -fileTypeCode('Fldr', directory). -fileTypeCode('TEXT', regular). -fileTypeCode(_,unknown). -*/ - -ownerPermissionCoding(0,[]). -ownerPermissionCoding(4,[read]). -ownerPermissionCoding(6,[read,write]). - - -fileTypeCode(0, unknown). -fileTypeCode(1, directory). -fileTypeCode(4, regular). -fileTypeCode(5, symbolic_link). -fileTypeCode(5, alias). - -fileTypeCode(30 , mac_type('TEXT')). - - -ownerPermissionsCoding(0,[]). -ownerPermissionsCoding(1,[execute]). -ownerPermissionsCoding(2,[write]). -ownerPermissionsCoding(3,[write,execute]). -ownerPermissionsCoding(4,[read]). -ownerPermissionsCoding(5,[read,execute]). -ownerPermissionsCoding(6,[read,write]). -ownerPermissionsCoding(7,[read,write,execute]). - -/*!------------------------------------------------------------------ - *!-----------------------------------------------------------------*/ -file_status(FileName,Status) :- - '$getFileStatus'(FileName, - fileStatus(FileTypeCode,ModTime,OwnerPermiss,ByteSize,NBlocks)), - fileTypeCode(FileTypeCode,FileType), -% ownerPermissionCoding(OwnerPermiss,Permissions), - ownerPermissionsCoding(OwnerPermiss,Permissions), - Status = [type=FileType,permissions=Permissions,mod_time=ModTime,size=ByteSize]. /*!------------------------------------------------------------------ | directory/3 diff --git a/core/alsp_src/tests/atest_db.pro b/core/alsp_src/tests/atest_db.pro index b134007d6..0d1806d57 100644 --- a/core/alsp_src/tests/atest_db.pro +++ b/core/alsp_src/tests/atest_db.pro @@ -81,6 +81,8 @@ test_info(par4, par4, user, main, test_info(filepath_test, filepath_test, user, test_filepath, 'tests for file system paths.'). +test_info(fsunix_mswin32_test, fsunix_mswin32_test, user, test_fsunix_mswin32, 'tests for misc filesystem functions.'). + %test_info(freeze_test, freeze, user, test_freeze, ' tests for freeze.'). % test_info Format: diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro new file mode 100644 index 000000000..399aafea6 --- /dev/null +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -0,0 +1,38 @@ +:-[test]. + +test_fsunix_mswin32 + :- + sys_env(OS,_,_), + do_test_fs(OS). + +do_test_fs(OS) + :- + test([ + test_file_status, + +% test_make_subdir1, +% test_make_subdir2, +% test_recursive_dir_path, +% test_recursive_dir_paths, + true]). + +do_test_fs(OS) + :- + test([ + true]). + + +test_file_status + :- + system('rm -rf regFile1.txt'), + system('echo "hi" > regFile1.txt'), + test([ + (file_status('regFile1.txt', Status), + nonvar(Status), + member(mod_time = M, Status), + Status == [type = regular,permissions = [read,write], mod_time = M, size = 3]), + true]), + system('rm -rf regFile1.txt'). + + + From 96484583f7a1679022c6ecd6838d0fd86abf4c73 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Wed, 15 Apr 2020 11:20:25 -0600 Subject: [PATCH 03/36] Pass OS to test_file_status; Modify target of file_status. --- .../tests/tsuite/fsunix_mswin32_test.pro | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 399aafea6..474b7b91a 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -8,7 +8,7 @@ test_fsunix_mswin32 do_test_fs(OS) :- test([ - test_file_status, + test_file_status(OS), % test_make_subdir1, % test_make_subdir2, @@ -21,18 +21,27 @@ do_test_fs(OS) test([ true]). - -test_file_status +test_file_status(mswin32) :- - system('rm -rf regFile1.txt'), - system('echo "hi" > regFile1.txt'), test([ - (file_status('regFile1.txt', Status), - nonvar(Status), - member(mod_time = M, Status), - Status == [type = regular,permissions = [read,write], mod_time = M, size = 3]), - true]), - system('rm -rf regFile1.txt'). + (file_status('alspro.exe', Status), + %Status == [type = regular,permissions = [read,write,execute], mod_time = M, size = 3]), + member(type = regular, Status), + member(permissions = [read,write,execute], Status), + member(mod_time = _, Status), + member(size = _, Status)), + true]). + +test_file_status(unix) + :- + test([ + (file_status(alspro, Status), + %Status == [type = regular,permissions = [read,write,execute], mod_time = M, size = 3]), + member(type = regular, Status), + member(permissions = [read,write,execute], Status), + member(mod_time = _, Status), + member(size = _, Status)), + true]). From 00a1af2fca245c2779cc498ec88f1816f2f617cb Mon Sep 17 00:00:00 2001 From: kenbowen Date: Wed, 15 Apr 2020 19:40:55 -0600 Subject: [PATCH 04/36] For fsunix.pro & fswin32.pro: Relocate files/[2,3] & move_file/2 according to exports order; add examples to in-code doc for files/[2,3] (for use by doctools); add full in-code doc for move_file/2, including examples. In fsunix_mswin32_test: Revise test code for file_status/2 to deal with mswin32; add test code for files/[2,3] & move_file/2. --- core/alsp_src/builtins/fsunix.pro | 126 +++++++++++---- core/alsp_src/builtins/fswin32.pro | 145 ++++++++++++------ .../tests/tsuite/fsunix_mswin32_test.pro | 59 ++++++- 3 files changed, 251 insertions(+), 79 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index 1cb1f8796..4947d5df3 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -98,6 +98,95 @@ ownerPermissionsCoding(5,[read,execute]). ownerPermissionsCoding(6,[read,write]). ownerPermissionsCoding(7,[read,write,execute]). +/*!---------------------------------------------------------------- + | files/2 + | files(Pattern,FileList) + | files(+,-) + | + | - returns a list of regular files in the current directory matching a pattern + | + | Returns the list (FileList) of all ordinary (regular) files + | in the current directory which match Pattern, which can + | includethe usual '*' and '?' wildcard characters. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | ?- files('*.pst', F). + | + | F=['alsdev.pst','alspro.pst'] + | + | ?- files('*', F). + | + | F=['LICENSE.txt','README.txt','als-prolog-manual.pdf', + | 'als-ref-manual.pdf',alsdev,'alsdev.pst',alspro,'alspro.1', + | 'alspro.pst','libalspro.a','libalspro.dylib','test.pro'] + *!----------------------------------------------------------------*/ +files(Pattern, FileList) + :- + directory(Pattern, 4, FileList). + +/*!---------------------------------------------------------------- + | files/3 + | files(Directory, Pattern,FileList) + | files(+,+,-) + | + | - returns a list of regular files residing in Directory matching a pattern + | + | Returns the list (FileList) of all ordinary files in the + | directory Directory which match Pattern, which can include + | the usual '*' and '?' wildcard characters. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | ?- files('examples/more', '*', F). + | + | F=['concurrent_interrupts.pro','core_concurrent.pro', + | 'finger.pro','freeze.pro','interrupts_coroutine.pro', + | 'mathserv1.pro','mathserv2.pro','primes_coroutine.pro', + | 'simple_coroutine.pro'] + | + | ?- files('examples/more', 'p*', F). + | + | F=['primes_coroutine.pro'] + *!----------------------------------------------------------------*/ +files(Directory, Pattern, List) + :- + getDirEntries(Directory, Pattern, FirstResult), + !, + fixFileType(regular, InternalFileType), + filterForFileType(FirstResult, Directory, InternalFileType, List). + +/*!---------------------------------------------------------------- + | move_file/2 + | move_file(Source, Target) + | move_file(+, +) + | + | - Change the name of a file from Source to Target + | + | If both Source and Target are atoms which can be the + | names of a file, and if Source is the name of a file + | existing in the file system, then the name of that file + | will be changed from Source to Target. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | ls i* + | > ls i* + | ls: i*: No such file or directory + | ?- move_file('README.txt', 'intro-README.txt'). + | > ls i* + | intro-README.txt + *!----------------------------------------------------------------*/ +move_file(Source, Target) + :- + sprintf(atom(Cmd),'mv %t %t', [Source, Target]), + system(Cmd). + + + + + + /*!-------------------------------------------------------------- | make_subdir/1 | make_subdir(NewDir) @@ -182,6 +271,11 @@ indv_perm_code(read, 4). indv_perm_code(write, 2). indv_perm_code(execute, 1). + + + + + /*!-------------------------------------------------------------- | remove_subdir/1 | remove_subdir(SubDir) @@ -201,38 +295,6 @@ kill_subdir(SubDir) sprintf(atom(Cmd),'rm -r %t',[SubDir]), system(Cmd). -/*!---------------------------------------------------------------- - | files/2 - | files(Pattern,FileList) - | files(+,-) - | - | - returns a list of files in the current directory matching a pattern - | - | Returns the list (FileList) of all ordinary files in the - | current directory which match Pattern, which can include - | the usual '*' and '?' wildcard characters. - *!----------------------------------------------------------------*/ -files(Pattern, FileList) - :- - directory(Pattern, 4, FileList). - -/*!---------------------------------------------------------------- - | files/3 - | files(Directory, Pattern,FileList) - | files(+,+,-) - | - | - returns a list of files residing in Directory matching a pattern - | - | Returns the list (FileList) of all ordinary files in the - | directory Directory which match Pattern, which can include - | the usual '*' and '?' wildcard characters. - *!----------------------------------------------------------------*/ -files(Directory, Pattern, List) - :- - getDirEntries(Directory, Pattern, FirstResult), - !, - fixFileType(regular, InternalFileType), - filterForFileType(FirstResult, Directory, InternalFileType, List). /*!---------------------------------------------------------------- | subdirs/1 diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 5094a5209..1c888b34a 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -41,15 +41,15 @@ export change_current_drive/1. | as in the following two examples: | | Examples - | ?- file_status(alspro, Status). + | ?- file_status('alspro.exe', Status). | | Status=[type = regular,permissions = [read,write,execute], - | mod_time = 1586731762.0,size = 462720] + | mod_time = 1524876154.0,size = 783127] | | ?- file_status(alsdir, Status). | | Status=[type = directory,permissions = [read,write,execute], - | mod_time = 1586652989.0,size = 204] + | mod_time = 1524503247.0,size = 0] *!-----------------------------------------------------------------*/ file_status(FileName,Status) :- '$getFileStatus'(FileName, @@ -95,6 +95,105 @@ ownerPermissionsCoding(5,[read,execute]). ownerPermissionsCoding(6,[read,write]). ownerPermissionsCoding(7,[read,write,execute]). + /*!---------------------------------------------------------------- + | files/2 + | files(Pattern,FileList) + | files(+,-) + | + | - returns a list of files in the current directory matching a pattern + | + | Returns the list (FileList) of all ordinary (regular) files + | in the current directory which match Pattern, which can + | include the usual '*' and '?' wildcard characters. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | ?- files('*.pst', F). + | + | F = ['alsdev.exe.pst','alspro.exe.pst'] + | + | ?- files('*', F). + | + | F = ['als-prolog-manual.pdf','als-ref-manual.pdf','alsdev.exe', + | 'alsdev.exe.pst','alshelp.css','alspro.exe','alspro.exe.pst', + | 'als_help.html','libalspro.a','libalspro.dll','LICENSE.txt', + | 'README.txt','tcl86.dll','tk86.dll','zlib1.dll']. + *!----------------------------------------------------------------*/ +files(Pattern, FileList) + :- + directory(Pattern, regular, FileList). + +/*!---------------------------------------------------------------- + | files/3 + | files(Directory, Pattern,FileList) + | files(+,+,-) + | + | - returns a list of files residing in Directory matching a pattern + | + | Returns the list (FileList) of all ordinary files in the + | directory Directory which match Pattern, which can include + | the usual '*' and '?' wildcard characters. + | Examples + | Executed in the ALS Prolog distribution directory: + | ?- files('examples/more', '*', F). + | + | F=['concurrent_interrupts.pro','core_concurrent.pro', + | 'finger.pro','freeze.pro','interrupts_coroutine.pro', + | 'mathserv1.pro','mathserv2.pro','primes_coroutine.pro', + | 'simple_coroutine.pro'] + | + | ?- files('examples/more', 'p*', F). + | + | F=['primes_coroutine.pro'] + *!----------------------------------------------------------------*/ + + files(Directory, Pattern, List) + :- + getDirEntries(Directory, Pattern, FirstResult), + !, + fixFileType(regular, InternalFileType), + filterForFileType(FirstResult, Directory, InternalFileType, List). + +/*!---------------------------------------------------------------- + | move_file/2 + | move_file(Source, Target) + | move_file(+, +) + | + | - Change the name of a file from Source to Target + | + | If both Source and Target are atoms which can be the + | names of a file, and if Source is the name of a file + | existing in the file system, then the name of that file + | will be changed from Source to Target. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | ...\als-prolog> dir i* + | ...\als-prolog> + | ?- move_file('README.txt', 'intro-README.txt'). + | ...\als-prolog> dir i* + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | -a---- 4/13/2018 5:29 PM 3387 intro-README.txt + *!----------------------------------------------------------------*/ +move_file(Source, Target) + :- + sprintf(atom(Cmd),'rename %t %t', [Source, Target]), + system(Cmd). + + + + + + + + + + + + + /*!-------------------------------------------------------------- | make_subdir/1 | make_subdir(NewDir) @@ -150,39 +249,6 @@ make_subdir(NewDir,Permissions) :- rmdir(SubDir). - /*!---------------------------------------------------------------- - | files/2 - | files(Pattern,FileList) - | files(+,-) - | - | - returns a list of files in the current directory matching a pattern - | - | Returns the list (FileList) of all ordinary files in the - | current directory which match Pattern, which can include - | the usual '*' and '?' wildcard characters. - *!----------------------------------------------------------------*/ -files(Pattern, FileList) - :- - directory(Pattern, regular, FileList). - -/*!---------------------------------------------------------------- - | files/3 - | files(Directory, Pattern,FileList) - | files(+,+,-) - | - | - returns a list of files residing in Directory matching a pattern - | - | Returns the list (FileList) of all ordinary files in the - | directory Directory which match Pattern, which can include - | the usual '*' and '?' wildcard characters. - *!----------------------------------------------------------------*/ - - files(Directory, Pattern, List) - :- - getDirEntries(Directory, Pattern, FirstResult), - !, - fixFileType(regular, InternalFileType), - filterForFileType(FirstResult, Directory, InternalFileType, List). /*!---------------------------------------------------------------- | subdirs/1 @@ -382,13 +448,6 @@ change_current_drive(DriveName) :- name(ProperDriveName,ProperDriveList), change_cwd(ProperDriveName). -/*!---------------------------------------------------------------- - *!----------------------------------------------------------------*/ -move_file(Source, Target) - :- - sprintf(atom(Cmd),'rename %t %t', [Source, Target]), - system(Cmd). - endmod. diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 474b7b91a..7c48a407e 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -9,6 +9,9 @@ do_test_fs(OS) :- test([ test_file_status(OS), + test_files2(OS), + test_files3(OS), + test_move_file(_), % test_make_subdir1, % test_make_subdir2, @@ -25,23 +28,71 @@ test_file_status(mswin32) :- test([ (file_status('alspro.exe', Status), - %Status == [type = regular,permissions = [read,write,execute], mod_time = M, size = 3]), member(type = regular, Status), member(permissions = [read,write,execute], Status), member(mod_time = _, Status), - member(size = _, Status)), + member(size = _, Status), + all_eq(Status) ), true]). + test_file_status(unix) :- test([ (file_status(alspro, Status), - %Status == [type = regular,permissions = [read,write,execute], mod_time = M, size = 3]), member(type = regular, Status), member(permissions = [read,write,execute], Status), member(mod_time = _, Status), - member(size = _, Status)), + member(size = _, Status), + all_eq(Status) ), + true]). + +all_eq([]). +all_eq([T | Status]) + :- + T = (G = B), + (G==type; G==permissions; G==mod_time; G==size), + all_eq(Status). + +test_files2(mswin32) + :- + test([ + (files('*.pst', Files), + member('alsdev.exe.pst', Files), + member('alspro.exe.pst', Files), + all_f(Files, mswin32) ), + true]). + +test_files2(unix) + :- + test([ + (files('*.pst', Files), + member('alsdev.pst', Files), + member('alspro.pst', Files), + all_f2(Files, unix) ), + true]). + +all_f2([], _). +all_f2([F | Files], OS) + :- + (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst') + ; + (F == 'alsdev.pst' ; F == 'alspro.pst') ), + all_f2(Files, OS). + +test_files3(_) + :- + test([ + (files('examples/more', 'p*', Files), + Files == ['primes_coroutine.pro']), true]). +test_move_file(_) + :- + test([ + (move_file('README.txt', 'intro-README.txt'), + file_status('intro-README.txt', Status), + member(type = regular, Status)), + true]). From 635ed8eb996ec515a2f19f487895f12a4f1368fa Mon Sep 17 00:00:00 2001 From: kenbowen Date: Fri, 17 Apr 2020 13:26:55 -0600 Subject: [PATCH 05/36] Revisions to reflect that tests run in the build directories, not the distribution directories. --- core/alsp_src/builtins/fsunix.pro | 5 --- core/alsp_src/builtins/fswin32.pro | 12 ------ .../tests/tsuite/fsunix_mswin32_test.pro | 38 ++++++++++++------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index 4947d5df3..0412ba53f 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -182,11 +182,6 @@ move_file(Source, Target) sprintf(atom(Cmd),'mv %t %t', [Source, Target]), system(Cmd). - - - - - /*!-------------------------------------------------------------- | make_subdir/1 | make_subdir(NewDir) diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 1c888b34a..ac0e8ce98 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -182,18 +182,6 @@ move_file(Source, Target) sprintf(atom(Cmd),'rename %t %t', [Source, Target]), system(Cmd). - - - - - - - - - - - - /*!-------------------------------------------------------------- | make_subdir/1 | make_subdir(NewDir) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 7c48a407e..79ca3fb2b 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -13,15 +13,10 @@ do_test_fs(OS) test_files3(OS), test_move_file(_), -% test_make_subdir1, -% test_make_subdir2, -% test_recursive_dir_path, -% test_recursive_dir_paths, - true]). - -do_test_fs(OS) - :- - test([ +% test_make_subdir1(OS), +% test_make_subdir2(OS), +% test_recursive_dir_path(OS), +% test_recursive_dir_paths(OS), true]). test_file_status(mswin32) @@ -76,9 +71,11 @@ test_files2(unix) all_f2([], _). all_f2([F | Files], OS) :- - (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst') + (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst'; libalspro.dll.pst') ; - (F == 'alsdev.pst' ; F == 'alspro.pst') ), + (F == 'alsdev.pst' ; F == 'alspro.pst'; + F == 'app_image0.pst'; F == 'app_image1.pst'; F == 'app_image2.pst'; + F == 'libalspro.dylib.pst') ), all_f2(Files, OS). test_files3(_) @@ -88,11 +85,24 @@ test_files3(_) Files == ['primes_coroutine.pro']), true]). -test_move_file(_) +test_move_file(mswin32) + :- + system('del /f barFile-beer.txt'), + system('echo foo > barFile.txt'), + test([ + (move_file('barFile.txt', 'barFile-beer.txt'), + file_status('barFile-beer.txt', Status), + member(type = regular, Status)), + system('del /f barFile-beer.txt'), + true]). +test_move_file(unix) :- + system('rm -rf barFile-beer.txt'), + system('echo foo > barFile.txt'), test([ - (move_file('README.txt', 'intro-README.txt'), - file_status('intro-README.txt', Status), + (move_file('barFile.txt', 'barFile-beer.txt'), + file_status('barFile-beer.txt', Status), member(type = regular, Status)), + system('rm -rf barFile-beer.txt'), true]). From c64cc8c9fa6f88dda30a321399b621800a67ed43 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Fri, 17 Apr 2020 15:22:13 -0600 Subject: [PATCH 06/36] repair typos; account for non-existence of examples dir in windows build dir --- .../tests/tsuite/fsunix_mswin32_test.pro | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 79ca3fb2b..0e67e5b4c 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -56,7 +56,7 @@ test_files2(mswin32) (files('*.pst', Files), member('alsdev.exe.pst', Files), member('alspro.exe.pst', Files), - all_f(Files, mswin32) ), + all_f2(Files, mswin32) ), true]). test_files2(unix) @@ -71,14 +71,22 @@ test_files2(unix) all_f2([], _). all_f2([F | Files], OS) :- - (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst'; libalspro.dll.pst') + (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst'; 'libalspro.dll.pst') ; (F == 'alsdev.pst' ; F == 'alspro.pst'; F == 'app_image0.pst'; F == 'app_image1.pst'; F == 'app_image2.pst'; - F == 'libalspro.dylib.pst') ), + F == 'libalspro.dylib.pst') + ), all_f2(Files, OS). -test_files3(_) +test_files3(mswin32) + :- + test([ + (files('alsdir\builtins', 'j*', Files), + Files == ['julian.pro']), + true]). + +test_files3(unix) :- test([ (files('examples/more', 'p*', Files), From 999f9697b572b5c5c61508463e4c5c1464271df3 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 14:40:25 -0600 Subject: [PATCH 07/36] Added missing F == ; changed 'j*' to 'c*' --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 0e67e5b4c..8f2743e82 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -71,7 +71,7 @@ test_files2(unix) all_f2([], _). all_f2([F | Files], OS) :- - (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst'; 'libalspro.dll.pst') + (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst'; F == 'libalspro.dll.pst') ; (F == 'alsdev.pst' ; F == 'alspro.pst'; F == 'app_image0.pst'; F == 'app_image1.pst'; F == 'app_image2.pst'; @@ -82,8 +82,8 @@ all_f2([F | Files], OS) test_files3(mswin32) :- test([ - (files('alsdir\builtins', 'j*', Files), - Files == ['julian.pro']), + (files('alsdir\\builtins', 'c*', Files), + Files == ['comp_d10.pro', 'cutils.pro']), true]). test_files3(unix) From 17118f9d0f2c4268d027417f20f2a6e963a8ce6c Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 14:58:12 -0600 Subject: [PATCH 08/36] debugging test_files2 on mswin32 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 1 + 1 file changed, 1 insertion(+) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 8f2743e82..52b5492e7 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -63,6 +63,7 @@ test_files2(unix) :- test([ (files('*.pst', Files), +pbi_write(files=Files),pbi_nl, member('alsdev.pst', Files), member('alspro.pst', Files), all_f2(Files, unix) ), From ea8f94c6c151551c0243539d5037a60199f65bb0 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 15:14:31 -0600 Subject: [PATCH 09/36] Needed F == 'libalspro.dylib.pst' ; F == 'libalspro.so.pst' for unix --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 52b5492e7..a0f97d005 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -76,7 +76,7 @@ all_f2([F | Files], OS) ; (F == 'alsdev.pst' ; F == 'alspro.pst'; F == 'app_image0.pst'; F == 'app_image1.pst'; F == 'app_image2.pst'; - F == 'libalspro.dylib.pst') + (F == 'libalspro.dylib.pst' ; F == 'libalspro.so.pst') ) ), all_f2(Files, OS). From 3aef5c5e73aa46d4e119a3e28d417d5914fc47e7 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 15:23:24 -0600 Subject: [PATCH 10/36] debugging test_files2 on mswin32 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index a0f97d005..e9f3970ae 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -54,6 +54,7 @@ test_files2(mswin32) :- test([ (files('*.pst', Files), +pbi_write(files=Files),pbi_nl, member('alsdev.exe.pst', Files), member('alspro.exe.pst', Files), all_f2(Files, mswin32) ), @@ -63,7 +64,6 @@ test_files2(unix) :- test([ (files('*.pst', Files), -pbi_write(files=Files),pbi_nl, member('alsdev.pst', Files), member('alspro.pst', Files), all_f2(Files, unix) ), From 4a98276c0c4058f2542ad124875c58abb8aa5d89 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 15:42:26 -0600 Subject: [PATCH 11/36] Replaced test_move_file(_) with test_move_file(OS) --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index e9f3970ae..83f9a54e7 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -11,7 +11,7 @@ do_test_fs(OS) test_file_status(OS), test_files2(OS), test_files3(OS), - test_move_file(_), + test_move_file(OS), % test_make_subdir1(OS), % test_make_subdir2(OS), From dc2ca6b552207a5dd380da74e49b5a64a229d308 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 15:56:44 -0600 Subject: [PATCH 12/36] debugging test_files2 on mswin32 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 83f9a54e7..5b1ef68ee 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -52,9 +52,10 @@ all_eq([T | Status]) test_files2(mswin32) :- +printf(user_output,'>>Enter test_files2(mswin32)\n',[]), test([ (files('*.pst', Files), -pbi_write(files=Files),pbi_nl, +printf(user_output,'>>file=%t)\n',[Files]), member('alsdev.exe.pst', Files), member('alspro.exe.pst', Files), all_f2(Files, mswin32) ), From 936d3aacb643f53175cd6f2d025a25c1b30c49ac Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 16:43:39 -0600 Subject: [PATCH 13/36] debugging test_files2 on mswin32 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 5b1ef68ee..430847ed0 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -73,7 +73,9 @@ test_files2(unix) all_f2([], _). all_f2([F | Files], OS) :- - (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst'; F == 'libalspro.dll.pst') + (OS==mswin32 -> (F == 'alsdev.exe.pst' ; F == 'alspro.exe.pst'; + F == 'app_image0.exe.pst'; F == 'app_image1.exe.pst'; + F == 'app_image2.exe.pst'; F == 'libalspro.dll.pst') ; (F == 'alsdev.pst' ; F == 'alspro.pst'; F == 'app_image0.pst'; F == 'app_image1.pst'; F == 'app_image2.pst'; From 366becf488857513099d4e4c2472626654cec387 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 18:18:57 -0600 Subject: [PATCH 14/36] remove debugging printf's --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 430847ed0..185fdf437 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -52,10 +52,8 @@ all_eq([T | Status]) test_files2(mswin32) :- -printf(user_output,'>>Enter test_files2(mswin32)\n',[]), test([ (files('*.pst', Files), -printf(user_output,'>>file=%t)\n',[Files]), member('alsdev.exe.pst', Files), member('alspro.exe.pst', Files), all_f2(Files, mswin32) ), From 1dcc11e874cad5b915967b880862a34609e941dd Mon Sep 17 00:00:00 2001 From: kenbowen Date: Sun, 19 Apr 2020 19:58:39 -0600 Subject: [PATCH 15/36] For make_subdir/[1,2]: Add in-code comments including examples (for use with doctors), together with tests. --- core/alsp_src/builtins/fsunix.pro | 79 +++++++++++--- core/alsp_src/builtins/fswin32.pro | 102 ++++++++++++++++++ .../tests/tsuite/fsunix_mswin32_test.pro | 74 ++++++++++++- 3 files changed, 240 insertions(+), 15 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index 0412ba53f..cd4d1291d 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -187,6 +187,39 @@ move_file(Source, Target) | make_subdir(NewDir) | make_subdir(+) | + | - creates a subdirectory in the current working directory + | - with default permissions + | + | If NewDir is an atom, creates a subdirectory named NewDir in + | the current working directory, if possible. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev* alspro.pst + | LICENSE.txt alsdev.pst docs/ + | README.txt alsdir/ examples/ + | als-prolog-manual.pdf alspro* libalspro.a + | als-ref-manual.pdf alspro.1 libalspro.dylib* + | ..... + | ?- make_subdir(myNewTestSubdir). + | + | yes. + | ?- halt. + | ls + | ALS_Prolog_Foreign_SDK/ alsdev.pst examples/ + | LICENSE.txt alsdir/ libalspro.a + | README.txt alspro* libalspro.dylib* + | als-prolog-manual.pdf alspro.1 myNewTestSubdir/ + | als-ref-manual.pdf alspro.pst + | alsdev* docs/ + *!--------------------------------------------------------------*/ +make_subdir(NewDir) + :- + %%[rwx,rwx,rwx] + make_subdir(NewDir,511). + +/*!-------------------------------------------------------------- | make_subdir/2 | make_subdir(NewDir,Permissions) | make_subdir(+,+) @@ -208,19 +241,39 @@ move_file(Source, Target) | [[read,write,execute], | [read,write], | [execute] ] - *!--------------------------------------------------------------*/ - %% This may go away later: -make_subdir(NewDir) - :- - sys_env(unix,djgpp,_), - !, - mkdir(NewDir). - -make_subdir(NewDir) - :- - %%[rwx,rwx,rwx] - make_subdir(NewDir,511). - + | + | Examples + | Executed in the ALS Prolog distribution directory: + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev* alspro.pst + | LICENSE.txt alsdev.pst docs/ + | README.txt alsdir/ examples/ + | als-prolog-manual.pdf alspro* libalspro.a + | als-ref-manual.pdf alspro.1 libalspro.dylib* + | ..... + | ?- make_subdir(myNewTestSubdir,457). + | + | yes. + | ?- halt. + | > ls -l + | total 26448 + | drwxr-xr-x 6 user staff 204 Apr 17 15:01 ALS_Prolog_Foreign_SDK/ + | -rw-r--r-- 1 user staff 1101 Apr 17 15:01 LICENSE.txt + | -rw-r--r-- 1 user staff 2738 Apr 9 09:33 README.txt + | -rw-r--r-- 1 user staff 1938443 Apr 9 09:33 als-prolog-manual.pdf + | -rw-r--r-- 1 user staff 1136668 Apr 9 09:33 als-ref-manual.pdf + | -rwxr-xr-x 1 user staff 482560 Apr 17 14:58 alsdev* + | -rw-r--r-- 1 user staff 4194488 Apr 17 14:58 alsdev.pst + | drwxr-xr-x 6 user staff 204 Apr 17 14:57 alsdir/ + | -rwxr-xr-x 1 user staff 462720 Apr 17 14:58 alspro* + | -rw-r--r-- 1 user staff 8181 Apr 9 09:33 alspro.1 + | -rw-r--r-- 1 user staff 4194488 Apr 17 14:58 alspro.pst + | drwxr-xr-x 7 user staff 238 Apr 17 14:58 docs/ + | drwxr-xr-x 9 user staff 306 Apr 17 15:01 examples/ + | -rw-r--r-- 1 user staff 634664 Apr 17 14:58 libalspro.a + | -rwxr-xr-x 1 user staff 463764 Apr 17 14:58 libalspro.dylib* + | drwx--x--x 2 user staff 68 Apr 19 19:03 myNewTestSubdir/ + *!----------------------------------------------------------------*/ make_subdir(NewDir,Permissions) :- integer(Permissions), diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index ac0e8ce98..3278a7835 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -208,12 +208,114 @@ move_file(Source, Target) | [[read,write,execute], | [read,write], | [execute] ] + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | + | ?- make_subdir(myNewTestSubdir). + | + | yes. + | ?- halt. + | + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/19/2020 7:35 PM myNewTestSubdir + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | + | *!--------------------------------------------------------------*/ make_subdir(NewDir) :- make_subdir(NewDir,511). +/*!-------------------------------------------------------------- + | make_subdir/2 + | make_subdir(NewDir,Permissions) + | make_subdir(+,+) + | + | - creates a subdirectory in the current working directory + | - with the indicated permissions + | + | If NewDir is an atom, creates a subdirectory named NewDir in + | the current working directory, if possible; if Permissions + | is an integer of appropriate value, assigns the indicated + | permissions to the directory. + | + | Permissions can appear in one of three forms: + | + | * An appropriate integer: 0 =< N =< 511 + | * A list of approriate atoms, for example + | [rwx,rx,x] + | * A list of lists of appropriate atoms, for example: + | [[read,write,execute], + | [read,write], + | [execute] ] + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | + | ?- make_subdir(myNewTestSubdir, 457). + | + | yes. + | ?- halt. + | + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/19/2020 7:35 PM myNewTestSubdir + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + *!----------------------------------------------------------------*/ + make_subdir(NewDir,Permissions) :- integer(Permissions), diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 185fdf437..314558a1c 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -13,8 +13,8 @@ do_test_fs(OS) test_files3(OS), test_move_file(OS), -% test_make_subdir1(OS), -% test_make_subdir2(OS), + test_make_subdir1(OS), + test_make_subdir2(OS), % test_recursive_dir_path(OS), % test_recursive_dir_paths(OS), true]). @@ -116,3 +116,73 @@ test_move_file(unix) system('rm -rf barFile-beer.txt'), true]). +test_make_subdir1(mswin32) + :- + system('RMDIR myNewTestSubdir'), + test([ + (get_cwd(TestDir), + make_subdir(myNewTestSubdir), + path_directory_tail(SubdirPath, TestDir, myNewTestSubdir), + change_cwd(myNewTestSubdir), + get_cwd(ThisPath), + SubdirPath == ThisPath, + change_cwd('..')), + %% next make_subdir fails because myNewTestSubdir exists: + (not(make_subdir(myNewTestSubdir))), + true]), + system('RMDIR myNewTestSubdir'). + +test_make_subdir1(unix) + :- + system('rm -rf myNewTestSubdir'), + test([ + (get_cwd(TestDir), + make_subdir(myNewTestSubdir), + path_directory_tail(SubdirPath, TestDir, myNewTestSubdir), + change_cwd(myNewTestSubdir), + get_cwd(ThisPath), + SubdirPath == ThisPath, + change_cwd('..')), + %% next make_subdir fails because myNewTestSubdir exists: + (not(make_subdir(myNewTestSubdir))), + true]), + system('rm -rf myNewTestSubdir'). + + + +test_make_subdir2(mswin32) + :- + system('RMDIR myNewTestSubdir'), + test([ + (get_cwd(TestDir), + make_subdir(myNewTestSubdir,457), + file_status(myNewTestSubdir, Status), + member(permissions=Permissions, Status), + Permissions = [read,write,execute], + path_directory_tail(SubdirPath, TestDir, myNewTestSubdir), + change_cwd(myNewTestSubdir), + get_cwd(ThisPath), + SubdirPath == ThisPath, + change_cwd('..')), + (not(make_subdir(myNewTestSubdir))), + true]), + system('RMDIR myNewTestSubdir'). + +test_make_subdir2(unix) + :- + system('rm -rf myNewTestSubdir'), + test([ + (get_cwd(TestDir), + make_subdir(myNewTestSubdir,457), + file_status(myNewTestSubdir, Status), + member(permissions=Permissions, Status), + Permissions = [read,write,execute], + path_directory_tail(SubdirPath, TestDir, myNewTestSubdir), + change_cwd(myNewTestSubdir), + get_cwd(ThisPath), + SubdirPath == ThisPath, + change_cwd('..')), + (not(make_subdir(myNewTestSubdir))), + true]), + system('rm -rf myNewTestSubdir'). + From ba7e7be4adb5c4b465b12bbcea075af1603be456 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 18:01:17 -0600 Subject: [PATCH 16/36] Moved subdirs[_red]/1 up in ordering so as to utilize subdirs/1 in examples and tests for subsequent predicates. Add examples to in-code comments (for use with doctools), and add tests for subdirs[_red]/1 to fsunix_mswin32_test.pro. Add examples to in-code comments for remove_subdir/1,kill_subdir/1 (for use with doctools), and add tests for remove_subdir/1,kill_subdir/1. --- core/alsp_src/builtins/fsunix.pro | 143 ++++++++++++++---- core/alsp_src/builtins/fswin32.pro | 143 +++++++++++++++--- .../tests/tsuite/fsunix_mswin32_test.pro | 88 +++++++++++ 3 files changed, 324 insertions(+), 50 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index cd4d1291d..3f16c8f25 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -21,10 +21,10 @@ export files/3. export move_file/2. export make_subdir/1. export make_subdir/2. -export remove_subdir/1. -export kill_subdir/1. export subdirs/1. export subdirs_red/1. +export remove_subdir/1. +export kill_subdir/1. export directory/3. export get_current_drive/1. export change_current_drive/1. @@ -319,31 +319,6 @@ indv_perm_code(read, 4). indv_perm_code(write, 2). indv_perm_code(execute, 1). - - - - - -/*!-------------------------------------------------------------- - | remove_subdir/1 - | remove_subdir(SubDir) - | remove_subdir(+) - | - | - removes a subdirectory from the current working directory - | - | If SubDir is an atom, remove the subdirectory named SubDir from - | the current working directory, if it exists. - *!--------------------------------------------------------------*/ -remove_subdir(SubDir) - :- - rmdir(SubDir). - -kill_subdir(SubDir) - :- - sprintf(atom(Cmd),'rm -r %t',[SubDir]), - system(Cmd). - - /*!---------------------------------------------------------------- | subdirs/1 | subdirs(SubdirList) @@ -352,7 +327,24 @@ kill_subdir(SubDir) | - returns a list of subdirectories | | Returns the list of all subdirectories of the current - | working directory. + | working directory. On unix, the system files '.' and '..' + | are removed from the list; on mswin32, they are included. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev* alspro.pst + | LICENSE.txt alsdev.pst docs/ + | README.txt alsdir/ examples/ + | als-prolog-manual.pdf alspro* libalspro.a + | als-ref-manual.pdf alspro.1 libalspro.dylib* + | ..... + | ?- subdirs(SDs). + | + | SDs=['ALS_Prolog_Foreign_SDK',alsdir,docs,examples] + | + | yes. *!----------------------------------------------------------------*/ subdirs(SubdirList) :- @@ -367,6 +359,22 @@ subdirs(SubdirList) | | Returns the list of all subdirectories of the current | working directory, omitting '.' and '..' + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev* alspro.pst + | LICENSE.txt alsdev.pst docs/ + | README.txt alsdir/ examples/ + | als-prolog-manual.pdf alspro* libalspro.a + | als-ref-manual.pdf alspro.1 libalspro.dylib* + | ..... + | ?- subdirs(SDs). + | + | SDs=['ALS_Prolog_Foreign_SDK',alsdir,docs,examples] + | + | yes. *!----------------------------------------------------------------*/ subdirs_red(SubdirList) :- @@ -374,6 +382,85 @@ subdirs_red(SubdirList) list_delete(SubdirList0, '.', SubdirList1), list_delete(SubdirList1, '..', SubdirList). +/*!-------------------------------------------------------------- + | remove_subdir/1 + | remove_subdir(SubDir) + | remove_subdir(+) + | + | - removes a subdirectory from the current working directory + | + | If SubDir is an atom, remove the subdirectory named SubDir from + | the current working directory, if it exists AND is empty. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | > mkdir funnyFolder + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev.pst examples/ + | LICENSE.txt alsdir/ funnyFolder/ + | README.txt alspro* libalspro.a + | als-prolog-manual.pdf alspro.1 libalspro.dylib* + | als-ref-manual.pdf alspro.pst + | alsdev* docs/ + | ..... + | ?- remove_subdir(funnyFolder). + | + | yes. + | ..... + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev* alspro.pst + | LICENSE.txt alsdev.pst docs/ + | README.txt alsdir/ examples/ + | als-prolog-manual.pdf alspro* libalspro.a + | als-ref-manual.pdf alspro.1 libalspro.dylib* + *!--------------------------------------------------------------*/ +remove_subdir(SubDir) + :- + rmdir(SubDir). + +/*!-------------------------------------------------------------- + | kill_subdir/1 + | kill_subdir(SubDir) + | kill_subdir(+) + | + | - removes a subdirectory from the current working directory + | + | If SubDir is an atom, remove the subdirectory named SubDir from + | the current working directory, if it exists; SubDir may + | contain files and other subdirs. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | > mkdir funnyFolder + | > echo hiThere > funnyFolder/AFile + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev.pst examples/ + | LICENSE.txt alsdir/ funnyFolder/ + | README.txt alspro* libalspro.a + | als-prolog-manual.pdf alspro.1 libalspro.dylib* + | als-ref-manual.pdf alspro.pst + | alsdev* docs/ + | > cat funnyFolder/AFile + | hiThere + | ..... + | ?- kill_subdir(funnyFolder). + | + | yes. + | ..... + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev* alspro.pst + | LICENSE.txt alsdev.pst docs/ + | README.txt alsdir/ examples/ + | als-prolog-manual.pdf alspro* libalspro.a + | als-ref-manual.pdf alspro.1 libalspro.dylib* + *!--------------------------------------------------------------*/ +kill_subdir(SubDir) + :- + sprintf(atom(Cmd),'rm -r %t',[SubDir]), + system(Cmd). + /*!------------------------------------------------------------------ | directory/3 diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 3278a7835..ed3d81ef1 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -19,12 +19,12 @@ export files/3. export move_file/2. export make_subdir/1. export make_subdir/2. +export subdirs/1. +export subdirs_red/1. export remove_subdir/1. export kill_subdir/1. -export subdirs/1. -export subdirs_red/1. export directory/3. export get_current_drive/1. export change_current_drive/1. @@ -245,8 +245,6 @@ move_file(Source, Target) | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf | d----- ..... ..... ..... ..... | d----- 4/13/2018 5:29 PM 84480 zlib1.dll - | - | *!--------------------------------------------------------------*/ make_subdir(NewDir) @@ -323,23 +321,6 @@ make_subdir(NewDir,Permissions) 0 =< Permissions, Permissions =< 512, mkdir(NewDir,Permissions). - -/*!-------------------------------------------------------------- - | remove_subdir/1 - | remove_subdir(SubDir) - | remove_subdir(+) - | - | - removes a subdirectory from the current working directory - | - | If SubDir is an atom, remove the subdirectory named SubDir from - | the current working directory, if it exists. - *!--------------------------------------------------------------*/ - - remove_subdir(SubDir) - :- - rmdir(SubDir). - - /*!---------------------------------------------------------------- | subdirs/1 | subdirs(SubdirList) @@ -348,7 +329,32 @@ make_subdir(NewDir,Permissions) | - returns a list of subdirectories | | Returns the list of all subdirectories of the current - | working directory. + | working directory. On unix, the system files '.' and '..' + | are removed from the list; on mswin32, they are included. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | ..... + | ?- subdirs(SDs). + | + | SDs=['.','..',alsdir,alshelp,'ALS_Prolog_Foreign_SDK',docs,examples,lib]. + | + | yes. *!----------------------------------------------------------------*/ subdirs(SubdirList) :- @@ -363,6 +369,30 @@ subdirs(SubdirList) | | Returns the list of all subdirectories of the current | working directory, omitting '.' and '..' + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | ..... + | ?- subdirs_red(SDs). + | + | SDs=[alsdir,alshelp,'ALS_Prolog_Foreign_SDK',docs,examples,lib]. + | + | yes. *!----------------------------------------------------------------*/ subdirs_red(SubdirList) :- @@ -370,6 +400,75 @@ subdirs_red(SubdirList) list_delete(SubdirList0, '.', SubdirList1), list_delete(SubdirList1, '..', SubdirList). +/*!-------------------------------------------------------------- + | remove_subdir/1 + | remove_subdir(SubDir) + | remove_subdir(+) + | + | - removes a subdirectory from the current working directory + | + | If SubDir is an atom, remove the subdirectory named SubDir from + | the current working directory, if it exists AND is empty. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | mkdir funnyFolder + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/20/2020 5:29 PM funnyFolder + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | + | ?- remove_subdir(funnyFolder). + | + | yes. + | + | C:Users\user\ALSPrlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + *!--------------------------------------------------------------*/ + remove_subdir(SubDir) + :- + rmdir(SubDir). + +/*!-------------------------------------------------------------- + | kill_subdir/1 + | kill_subdir(SubDir) + | kill_subdir(+) + | + | - removes a subdirectory from the current working directory + | + | If SubDir is an atom, remove the subdirectory named SubDir from + | the current working directory, if it exists. + *!--------------------------------------------------------------*/ +kill_subdir(SubDir) + :- + sprintf(atom(Cmd),'Remove-Item -Recurse -Force %t',[SubDir]), + system(Cmd). + + /*!------------------------------------------------------------------ | directory/3 diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 314558a1c..0273e258e 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -15,6 +15,11 @@ do_test_fs(OS) test_make_subdir1(OS), test_make_subdir2(OS), + test_subdirs(OS), + test_subdirs_red(OS), + + test_remove_subdir(OS), + test_kill_subdir(OS), % test_recursive_dir_path(OS), % test_recursive_dir_paths(OS), true]). @@ -186,3 +191,86 @@ test_make_subdir2(unix) true]), system('rm -rf myNewTestSubdir'). +test_remove_subdir(mswin32) + :- + system('rmdir myNewTestSubdir'), + test([ + (make_subdir(myNewTestSubdir), + subdirs(List1), + member(myNewTestSubdir, List1), + remove_subdir(myNewTestSubdir), + subdirs(List2), + not(member(myNewTestSubdir, List2)) ), + true]), + system('rmdir myNewTestSubdir'). + +test_remove_subdir(unix) + :- + system('rm -rf myNewTestSubdir'), + test([ + (make_subdir(myNewTestSubdir), + subdirs(List1), + member(myNewTestSubdir, List1), + remove_subdir(myNewTestSubdir), + subdirs(List2), + not(member(myNewTestSubdir, List2)) ), + true]), + system('rm -rf myNewTestSubdir'). + +test_kill_subdir(mswin32) + :- + system('rmdir myNewTestSubdir'), + test([ + (make_subdir(myNewTestSubdir), + subdirs(List1), + member(myNewTestSubdir, List1), + kill_subdir(myNewTestSubdir), + subdirs(List2), + not(member(myNewTestSubdir, List2)) ), + true]), + system('rmdir myNewTestSubdir'). + +test_kill_subdir(unix) + :- + system('rm -rf myNewTestSubdir'), + test([ + (make_subdir(myNewTestSubdir), + subdirs(List1), + member(myNewTestSubdir, List1), + kill_subdir(myNewTestSubdir), + subdirs(List2), + not(member(myNewTestSubdir, List2)) ), + true]), + system('rmdir myNewTestSubdir'). + +test_subdirs(mswin32) + :- + test([ + (subdirs(SDList), +printf(user_output, 'SDL=%t\n', [SDList]), + SDList == ['.','..',alsdir]), + true]). + +test_subdirs(unix) + :- + test([ + (subdirs_red(SDList), + SDList == [alsdir,darwin,examples]), + true]). + +test_subdirs_red(mswin32) + :- + test([ + (subdirs_red(SDList), +printf(user_output, 'SDL=%t\n', [SDList]), + SDList == [alsdir]), + true]). + +test_subdirs_red(unix) + :- + test([ + (subdirs_red(SDList), + SDList == [alsdir,darwin,examples]), + true]). + + From 894795a2ba76761f788e0e1481c36c94d89bdd9f Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 18:31:59 -0600 Subject: [PATCH 17/36] Correct typos in test_subdirs[_red]/1 --- .../tests/tsuite/fsunix_mswin32_test.pro | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 0273e258e..4ea6ddb4d 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -191,6 +191,38 @@ test_make_subdir2(unix) true]), system('rm -rf myNewTestSubdir'). +test_subdirs(mswin32) + :- + test([ + (subdirs(SDList), +printf(user_output, 'SDL=%t\n', [SDList]), + SDList == ['.','..',alsdir]), + true]). + +test_subdirs(unix) + :- + test([ + (subdirs(SDList), +printf(user_output, 'SDL=%t\n', [SDList]), + SDList == [alsdir,darwin,examples]), + true]). + +test_subdirs_red(mswin32) + :- + test([ + (subdirs_red(SDList), +printf(user_output, 'SDL=%t\n', [SDList]), + SDList == [alsdir]), + true]). + +test_subdirs_red(unix) + :- + test([ + (subdirs_red(SDList), +printf(user_output, 'SDL=%t\n', [SDList]), + SDList == [alsdir,darwin,examples]), + true]). + test_remove_subdir(mswin32) :- system('rmdir myNewTestSubdir'), @@ -242,35 +274,3 @@ test_kill_subdir(unix) not(member(myNewTestSubdir, List2)) ), true]), system('rmdir myNewTestSubdir'). - -test_subdirs(mswin32) - :- - test([ - (subdirs(SDList), -printf(user_output, 'SDL=%t\n', [SDList]), - SDList == ['.','..',alsdir]), - true]). - -test_subdirs(unix) - :- - test([ - (subdirs_red(SDList), - SDList == [alsdir,darwin,examples]), - true]). - -test_subdirs_red(mswin32) - :- - test([ - (subdirs_red(SDList), -printf(user_output, 'SDL=%t\n', [SDList]), - SDList == [alsdir]), - true]). - -test_subdirs_red(unix) - :- - test([ - (subdirs_red(SDList), - SDList == [alsdir,darwin,examples]), - true]). - - From 0920eba7d742a9c564ca1c65c92d369b2782e5fe Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 18:51:25 -0600 Subject: [PATCH 18/36] Correct list of subdirs returned by subdirs[_red]/1 in test_subdir[_red]/1.s --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 4ea6ddb4d..d9d23760a 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -204,7 +204,7 @@ test_subdirs(unix) test([ (subdirs(SDList), printf(user_output, 'SDL=%t\n', [SDList]), - SDList == [alsdir,darwin,examples]), + SDList == [alsdir,examples,linux]), true]). test_subdirs_red(mswin32) @@ -220,7 +220,7 @@ test_subdirs_red(unix) test([ (subdirs_red(SDList), printf(user_output, 'SDL=%t\n', [SDList]), - SDList == [alsdir,darwin,examples]), + SDList == [alsdir,examples,linux]), true]). test_remove_subdir(mswin32) From ecd589a7382994a5f8d1ef6abd4296fd6110503c Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 19:16:56 -0600 Subject: [PATCH 19/36] Change Remove-Item to rmdir; add debugging printfs --- core/alsp_src/builtins/fswin32.pro | 2 +- .../tests/tsuite/fsunix_mswin32_test.pro | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index ed3d81ef1..3dafb0530 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -465,7 +465,7 @@ subdirs_red(SubdirList) *!--------------------------------------------------------------*/ kill_subdir(SubDir) :- - sprintf(atom(Cmd),'Remove-Item -Recurse -Force %t',[SubDir]), + sprintf(atom(Cmd),'rmdir %t',[SubDir]), system(Cmd). diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index d9d23760a..1c4737631 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -2,10 +2,10 @@ test_fsunix_mswin32 :- - sys_env(OS,_,_), - do_test_fs(OS). + sys_env(OS,OSVar,_), + do_test_fs(OS,OSVar). -do_test_fs(OS) +do_test_fs(OS,OSVar) :- test([ test_file_status(OS), @@ -15,8 +15,8 @@ do_test_fs(OS) test_make_subdir1(OS), test_make_subdir2(OS), - test_subdirs(OS), - test_subdirs_red(OS), + test_subdirs(OS,OSVar), + test_subdirs_red(OS,OSVar), test_remove_subdir(OS), test_kill_subdir(OS), @@ -193,34 +193,42 @@ test_make_subdir2(unix) test_subdirs(mswin32) :- +printf(user_output, 'BEGIN test_subdirs\n', []), test([ (subdirs(SDList), printf(user_output, 'SDL=%t\n', [SDList]), SDList == ['.','..',alsdir]), true]). -test_subdirs(unix) +test_subdirs(unix,OSVar) :- test([ (subdirs(SDList), printf(user_output, 'SDL=%t\n', [SDList]), - SDList == [alsdir,examples,linux]), + (OSVar == linux -> + SDList == [alsdir,darwin,examples] + ; + SDList == [alsdir,darwin,examples]) ), true]). test_subdirs_red(mswin32) :- test([ +printf(user_output, 'BEGIN test_subdirs_red\n', []), (subdirs_red(SDList), printf(user_output, 'SDL=%t\n', [SDList]), SDList == [alsdir]), true]). -test_subdirs_red(unix) +test_subdirs_red(unix,OSVar) :- test([ (subdirs_red(SDList), printf(user_output, 'SDL=%t\n', [SDList]), - SDList == [alsdir,examples,linux]), + (OSVar == linux -> + SDList == [alsdir,examples,linux] + ; + SDList == [alsdir,examples,linux]) ), true]). test_remove_subdir(mswin32) From e939ffbae13f1893edbf8731f0bf47cf2004ebd1 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 19:39:56 -0600 Subject: [PATCH 20/36] Correct OSVar darwin/linux conditional; add debug printfs for mswin32 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 1c4737631..62cebbc5a 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -1,4 +1,4 @@ -:-[test]. +y-[test]. test_fsunix_mswin32 :- @@ -191,7 +191,7 @@ test_make_subdir2(unix) true]), system('rm -rf myNewTestSubdir'). -test_subdirs(mswin32) +test_subdirs(mswin32,_) :- printf(user_output, 'BEGIN test_subdirs\n', []), test([ @@ -202,19 +202,20 @@ printf(user_output, 'SDL=%t\n', [SDList]), test_subdirs(unix,OSVar) :- +printf(user_output, 'BEGIN test_subdirs - OSVar=%t\n', [OSVar]), test([ (subdirs(SDList), printf(user_output, 'SDL=%t\n', [SDList]), (OSVar == linux -> - SDList == [alsdir,darwin,examples] + SDList == [alsdir,examples,linux] ; SDList == [alsdir,darwin,examples]) ), true]). -test_subdirs_red(mswin32) +test_subdirs_red(mswin32,_) :- - test([ printf(user_output, 'BEGIN test_subdirs_red\n', []), + test([ (subdirs_red(SDList), printf(user_output, 'SDL=%t\n', [SDList]), SDList == [alsdir]), @@ -222,13 +223,14 @@ printf(user_output, 'SDL=%t\n', [SDList]), test_subdirs_red(unix,OSVar) :- +printf(user_output, 'BEGIN test_subdirs_red - OSVar=%t\n', [OSVar]), test([ (subdirs_red(SDList), printf(user_output, 'SDL=%t\n', [SDList]), (OSVar == linux -> SDList == [alsdir,examples,linux] ; - SDList == [alsdir,examples,linux]) ), + SDList == [alsdir,darwin,examples]) ), true]). test_remove_subdir(mswin32) From 3539460f3884708e5774a5b37669ce2907fcd9f4 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 19:55:26 -0600 Subject: [PATCH 21/36] Correct typo (y- for :-) in fsunix_mswin32_test.pro --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 62cebbc5a..2d1058dfa 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -1,4 +1,4 @@ -y-[test]. +:-[test]. test_fsunix_mswin32 :- From 485a79cfd08961b6faed75f51a10eefc994ce754 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 20:44:56 -0600 Subject: [PATCH 22/36] Add mswinnt subdir for mswin32: test_subdirs[_red]/1; Remove unix debug printfs for test_subdirs[_red]/1 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 2d1058dfa..04a169497 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -197,15 +197,13 @@ printf(user_output, 'BEGIN test_subdirs\n', []), test([ (subdirs(SDList), printf(user_output, 'SDL=%t\n', [SDList]), - SDList == ['.','..',alsdir]), + SDList == ['.','..',alsdir,mswinnt]), true]). test_subdirs(unix,OSVar) :- -printf(user_output, 'BEGIN test_subdirs - OSVar=%t\n', [OSVar]), test([ (subdirs(SDList), -printf(user_output, 'SDL=%t\n', [SDList]), (OSVar == linux -> SDList == [alsdir,examples,linux] ; @@ -218,15 +216,13 @@ printf(user_output, 'BEGIN test_subdirs_red\n', []), test([ (subdirs_red(SDList), printf(user_output, 'SDL=%t\n', [SDList]), - SDList == [alsdir]), + SDList == [alsdir,mswinnt]), true]). test_subdirs_red(unix,OSVar) :- -printf(user_output, 'BEGIN test_subdirs_red - OSVar=%t\n', [OSVar]), test([ (subdirs_red(SDList), -printf(user_output, 'SDL=%t\n', [SDList]), (OSVar == linux -> SDList == [alsdir,examples,linux] ; From 846c8f7a4820ef13179762e0f88099851084dd1e Mon Sep 17 00:00:00 2001 From: kenbowen Date: Tue, 21 Apr 2020 21:50:43 -0600 Subject: [PATCH 23/36] Remove debug printfs for mswin32 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 04a169497..20ab6b0ed 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -193,16 +193,14 @@ test_make_subdir2(unix) test_subdirs(mswin32,_) :- -printf(user_output, 'BEGIN test_subdirs\n', []), test([ (subdirs(SDList), -printf(user_output, 'SDL=%t\n', [SDList]), SDList == ['.','..',alsdir,mswinnt]), true]). test_subdirs(unix,OSVar) :- - test([ + test([ (subdirs(SDList), (OSVar == linux -> SDList == [alsdir,examples,linux] @@ -212,16 +210,14 @@ test_subdirs(unix,OSVar) test_subdirs_red(mswin32,_) :- -printf(user_output, 'BEGIN test_subdirs_red\n', []), test([ (subdirs_red(SDList), -printf(user_output, 'SDL=%t\n', [SDList]), SDList == [alsdir,mswinnt]), true]). test_subdirs_red(unix,OSVar) :- - test([ + test([ (subdirs_red(SDList), (OSVar == linux -> SDList == [alsdir,examples,linux] From 112213cb4d50933e079ca5cce106118603f4735c Mon Sep 17 00:00:00 2001 From: kenbowen Date: Wed, 22 Apr 2020 15:09:35 -0600 Subject: [PATCH 24/36] Added example for fswin32.pro:kill_subdir/1. Added examples for fs[unix/win32].pro:directory/3, together with tests for directory/3. --- core/alsp_src/builtins/fsunix.pro | 30 +++++- core/alsp_src/builtins/fswin32.pro | 98 ++++++++++++++++--- .../tests/tsuite/fsunix_mswin32_test.pro | 35 ++++++- 3 files changed, 140 insertions(+), 23 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index 3f16c8f25..8a455f8d7 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -370,7 +370,7 @@ subdirs(SubdirList) | als-prolog-manual.pdf alspro* libalspro.a | als-ref-manual.pdf alspro.1 libalspro.dylib* | ..... - | ?- subdirs(SDs). + | ?- subdirs_red(SDs). | | SDs=['ALS_Prolog_Foreign_SDK',alsdir,docs,examples] | @@ -471,10 +471,32 @@ kill_subdir(SubDir) | | If Pattern is a file name pattern, including possible '*' and | '?' wildcard characters, and FileType is a numeric (internal) - | file type or a symbolic (abstract) file type, directory/3 - | unifies List with a sorted list of atoms of names of file of - | type FileType, matching Pattern, and found in the + | file type or a symbolic (abstract) file type, (see fileTypeCode/2 + | and ownerPermissionsCoding/2 following fileStatus above), + | directory/3 unifies List with a sorted list of atoms of names + | of file of type FileType, matching Pattern, and found in the | current directory. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | > ls + | ALS_Prolog_Foreign_SDK/ alsdev* alspro.pst + | LICENSE.txt alsdev.pst docs/ + | README.txt alsdir/ examples/ + | als-prolog-manual.pdf alspro* libalspro.a + | als-ref-manual.pdf alspro.1 libalspro.dylib* + | ..... + | ?- directory('*', 1, X). + | + | X=['ALS_Prolog_Foreign_SDK',alsdir,darwin,docs,examples] + | + | yes. + | ?- directory('*.pst', 4, FL). + | + | FL=['alsdev.pst','alspro.pst'] + | + | yes. *!------------------------------------------------------------------*/ % If no pattern has been give, assume a complete wildcard is wanted: diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 3dafb0530..6c027f553 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -22,9 +22,7 @@ export make_subdir/2. export subdirs/1. export subdirs_red/1. export remove_subdir/1. - export kill_subdir/1. - export directory/3. export get_current_drive/1. export change_current_drive/1. @@ -212,7 +210,7 @@ move_file(Source, Target) | Examples | Executed in the ALS Prolog distribution directory: | - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -230,7 +228,7 @@ move_file(Source, Target) | yes. | ?- halt. | - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -277,7 +275,7 @@ make_subdir(NewDir) | Examples | Executed in the ALS Prolog distribution directory: | - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -297,7 +295,7 @@ make_subdir(NewDir) | yes. | ?- halt. | - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -335,7 +333,7 @@ make_subdir(NewDir,Permissions) | Examples | Executed in the ALS Prolog distribution directory: | - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -373,7 +371,7 @@ subdirs(SubdirList) | Examples | Executed in the ALS Prolog distribution directory: | - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -414,7 +412,7 @@ subdirs_red(SubdirList) | Executed in the ALS Prolog distribution directory: | | mkdir funnyFolder - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -434,7 +432,7 @@ subdirs_red(SubdirList) | | yes. | - | C:Users\user\ALSPrlog> dir + | C:Users\user\ALSProlog> dir | | Directory: C:\Users\user\ALSProlog | @@ -461,15 +459,53 @@ subdirs_red(SubdirList) | - removes a subdirectory from the current working directory | | If SubDir is an atom, remove the subdirectory named SubDir from - | the current working directory, if it exists. + | the current working directory, if it exists; SubDir may + | contain files and other subdirs. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | mkdir funnyFolder + | C:Users\user\ALSProlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/20/2020 5:29 PM funnyFolder + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | + | ?- remove_subdir(funnyFolder). + | + | yes. + | + | C:Users\user\ALSProlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll *!--------------------------------------------------------------*/ kill_subdir(SubDir) :- sprintf(atom(Cmd),'rmdir %t',[SubDir]), system(Cmd). - - /*!------------------------------------------------------------------ | directory/3 | directory(Pattern,FileType,List) @@ -479,10 +515,40 @@ kill_subdir(SubDir) | | If Pattern is a file name pattern, including possible '*' and | '?' wildcard characters, and FileType is a numeric (internal) - | file type or a symbolic (abstract) file type, directory/3 - | unifies List with a sorted list of atoms of names of file of - | type FileType, matching Pattern, and found in the + | file type or a symbolic (abstract) file type (see fileTypeCode/2 + | and ownerPermissionsCoding/2 following fileStatus above), + | directory/3 unifies List with a sorted list of atoms of names + | of files of type FileType, matching Pattern, and found in the | current directory. + | + | Examples + | Executed in the ALS Prolog distribution directory: + | + | C:Users\user\ALSProlog> dir + | + | Directory: C:\Users\user\ALSProlog + | + | Mode LastWriteTime Length Name + | ---- ------------- ------ ---- + | d----- 4/13/2018 5:29 PM alsdir + | d----- 4/13/2018 5:29 PM alshelp + | d----- 4/13/2018 5:29 PM ALS_Prolog_Foreign_SDK + | d----- 4/13/2018 5:29 PM examples + | d----- 4/13/2018 5:29 PM lib + | d----- 4/13/2018 5:29 PM 1938443 als-prolog-manual.pdf + | d----- ..... ..... ..... ..... + | d----- 4/13/2018 5:29 PM 84480 zlib1.dll + | + | ?- directory('*', 1, FL). + | + | FL=[alsdir,alshelp,'ALS_Prolog_Foreign_SDK',docs,examples,lib] + | + | yes. + | ?- directory('*.pst', 4, FL). + | + | FL=['alsdev.exe.pst','alspro.exe.pst','libalspro.dll.pst'] + | + | yes. *!------------------------------------------------------------------*/ % If no pattern has been give, assume a complete wildcard is wanted: diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 20ab6b0ed..17f9006c0 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -20,6 +20,8 @@ do_test_fs(OS,OSVar) test_remove_subdir(OS), test_kill_subdir(OS), + + test_directory(OS, OSVar), % test_recursive_dir_path(OS), % test_recursive_dir_paths(OS), true]). @@ -200,7 +202,7 @@ test_subdirs(mswin32,_) test_subdirs(unix,OSVar) :- - test([ + test([ (subdirs(SDList), (OSVar == linux -> SDList == [alsdir,examples,linux] @@ -217,7 +219,7 @@ test_subdirs_red(mswin32,_) test_subdirs_red(unix,OSVar) :- - test([ + test([ (subdirs_red(SDList), (OSVar == linux -> SDList == [alsdir,examples,linux] @@ -275,4 +277,31 @@ test_kill_subdir(unix) subdirs(List2), not(member(myNewTestSubdir, List2)) ), true]), - system('rmdir myNewTestSubdir'). + system('rm -rf myNewTestSubdir'). + +test_directory(mswin32,_) + :- + test([ + (directory('*', 1, FL0), + FL0 == [alsdir,mswinnt], + directory('*.pst', 4, FL1), + FL1 == ['alsdev.exe.pst','alspro.exe.pst','libalspro.dll.pst']), + true]). + +test_directory(unix,OSVar) + :- + test([ + (directory('*', 1, FL0), + (OSVar == linux -> + FL0 == [alsdir,examples,linux] + ; + FL0 == [alsdir,darwin,examples]), + directory('*.pst', 4, FL1), + (OSVar == linux -> + FL1 == ['alsdev.pst','alspro.pst','app_image0.pst','app_image1.pst', + 'app_image2.pst','libalspro.so.pst'] + ; + FL1 == ['alsdev.pst','alspro.pst','app_image0.pst','app_image1.pst', + 'app_image2.pst','libalspro.dylib.pst'])), + true]). + From 5fdbeb7c9ce9ffd0abccc98f63f86b399ec2f3bf Mon Sep 17 00:00:00 2001 From: kenbowen Date: Wed, 22 Apr 2020 15:23:16 -0600 Subject: [PATCH 25/36] add debug printfs for mswin32:directory/3 --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 17f9006c0..434cc5759 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -283,8 +283,10 @@ test_directory(mswin32,_) :- test([ (directory('*', 1, FL0), +printf(user_output, 'd1 = %t\n', [FL0]), FL0 == [alsdir,mswinnt], directory('*.pst', 4, FL1), +printf(user_output, 'd4 = %t\n', [FL1]), FL1 == ['alsdev.exe.pst','alspro.exe.pst','libalspro.dll.pst']), true]). From 80235ee43a4ba664d97fee7f59355d24cfd728e6 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Wed, 22 Apr 2020 15:35:40 -0600 Subject: [PATCH 26/36] Added '.','..' to test for mswin32:directory('*',1,FL) --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 434cc5759..736a8ca4b 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -284,7 +284,7 @@ test_directory(mswin32,_) test([ (directory('*', 1, FL0), printf(user_output, 'd1 = %t\n', [FL0]), - FL0 == [alsdir,mswinnt], + FL0 == ['.','..',alsdir,mswinnt], directory('*.pst', 4, FL1), printf(user_output, 'd4 = %t\n', [FL1]), FL1 == ['alsdev.exe.pst','alspro.exe.pst','libalspro.dll.pst']), From dc091b5aa7b2db71c0f2557344d8535f7b52c033 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Wed, 22 Apr 2020 15:50:11 -0600 Subject: [PATCH 27/36] Added missing 'app_image[0,1,2].exe.pst' to test for mswin32:directory('*.pst',4,FL) --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 736a8ca4b..dcf2cf609 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -287,7 +287,8 @@ printf(user_output, 'd1 = %t\n', [FL0]), FL0 == ['.','..',alsdir,mswinnt], directory('*.pst', 4, FL1), printf(user_output, 'd4 = %t\n', [FL1]), - FL1 == ['alsdev.exe.pst','alspro.exe.pst','libalspro.dll.pst']), + FL1 == ['alsdev.exe.pst','alspro.exe.pst','app_image0.exe.pst','app_image1.exe.pst', + 'app_image2.exe.pst','libalspro.dll.pst']), true]). test_directory(unix,OSVar) From c81669231294d0ffa19061fdebda2003c7e01692 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Wed, 22 Apr 2020 16:04:23 -0600 Subject: [PATCH 28/36] Remove debug printfs --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index dcf2cf609..2a5c64e48 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -283,10 +283,8 @@ test_directory(mswin32,_) :- test([ (directory('*', 1, FL0), -printf(user_output, 'd1 = %t\n', [FL0]), FL0 == ['.','..',alsdir,mswinnt], directory('*.pst', 4, FL1), -printf(user_output, 'd4 = %t\n', [FL1]), FL1 == ['alsdev.exe.pst','alspro.exe.pst','app_image0.exe.pst','app_image1.exe.pst', 'app_image2.exe.pst','libalspro.dll.pst']), true]). From 2f10ca6679ddcd77766c2bb4af24f0a57761bc59 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 14:38:47 -0600 Subject: [PATCH 29/36] Add examples to in-code comments for fsunix/fswin32:get_current_drive/1,change_current_drive/1 (for doctools use), together with tests for those predicates. --- core/alsp_src/builtins/fsunix.pro | 18 ++---- core/alsp_src/builtins/fswin32.pro | 55 +++++++++++++++---- .../tests/tsuite/fsunix_mswin32_test.pro | 28 ++++++++++ 3 files changed, 77 insertions(+), 24 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index 8a455f8d7..8665b6d64 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -660,22 +660,14 @@ file_size(_,0) :- prolog_system_error(nyi, ['file_size/2',unix]). -/* +/* ---- * The following are essentially no-ops on unix, but - * need to do something for portability. In accordance - * with the conventions in filepath.pro, the "drive" - * is taken to be: root. - */ - + * need to do something for portability to mswin32. + * In accordance with the conventions in filepath.pro, + * the "drive" is taken to be: root. + *----*/ get_current_drive(root). change_current_drive(_). -/*!---------------------------------------------------------------- - *!----------------------------------------------------------------*/ -move_file(Source, Target) - :- - sprintf(atom(Cmd),'mv %t %t', [Source, Target]), - system(Cmd). - endmod. diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 6c027f553..4f91ca71e 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -673,23 +673,57 @@ file_size(_,0) :- prolog_system_error(nyi, ['file_size/2',unix]). -%-------------------------------------------------------------------- -% get_current_drive/1 -%-------------------------------------------------------------------- +/*!---------------------------------------------------------------- + | get_current_drive/1 + | get_current_drive(Drive) + | get_current_drive(-) + | + | - returns the descriptor for the current drive + | + | Returns the descriptor for the current drive in the form + | Drive = 'XYZ:\\', where 'XYZ:' is a proper Windows drive + | descriptor, and 'XYZ:\\' is an acceptable component for + | expressing file path names in Windows. Note that + | both 'C:' and 'C' are acceptable drive descriptors for + | change_current_drive/1 below, but that 'C:\\' is not. + | + | Examples (Drive is currently C): + | + | ?- get_current_drive(Drive). + | + | Drive = 'C:\\' + *!----------------------------------------------------------------*/ get_current_drive(Drive) :- getcwd(Path), -% rootPathFile(Drive,_,_,Path). split_path(Path, [Drive | _]). -%-------------------------------------------------------------------- -% change_current_drive/1. -% -% We check to make sure that the final character in the drive name -% is a colon, otherwise it is not a valid drive descriptor. -%-------------------------------------------------------------------- +/*!---------------------------------------------------------------- + | change_current_drive/1. + | change_current_drive(NewDrive) + | change_current_drive(+) + | + | - Changes the current drive to NewDrive if it is valid. + | + | If NewDrive is a valid drive descriptor, changes the + | current OS drive to NewDrive. + | + | Examples (Drive is currently C, and is the only drive): + | + | ?- change_current_drive('E:'). + | + | Error: System error: change_cwd('E:') + | - change_cwd: 'E:' + | - Throw pattern: error(system_error, [change_cwd('E:')]) + | + | ?- change_current_drive('C:'). + | + | yes. + *!----------------------------------------------------------------*/ + % We check to make sure that the final character in the drive name + % is a colon, otherwise it is not a valid drive descriptor. change_current_drive(DriveName) :- name(DriveName,DriveList), @@ -702,7 +736,6 @@ change_current_drive(DriveName) :- append(DriveList,[0':],ProperDriveList), name(ProperDriveName,ProperDriveList), change_cwd(ProperDriveName). - endmod. diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 2a5c64e48..79a46d982 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -22,6 +22,9 @@ do_test_fs(OS,OSVar) test_kill_subdir(OS), test_directory(OS, OSVar), + test_get_current_drive(OS), + test_change_current_drive(OS), + % test_recursive_dir_path(OS), % test_recursive_dir_paths(OS), true]). @@ -306,3 +309,28 @@ test_directory(unix,OSVar) 'app_image2.pst','libalspro.dylib.pst'])), true]). + /* -----------------------------* + | Only meaningful for mwwin32 + * -----------------------------*/ + + %% Assumes we're running on drive C: (on Appveyor). +test_get_current_drive(mswin32) + :- + test([ + (get_current_drive(Drive), + atom_codes(Drive, DriveCs), + reverse(DriveCs, RevCs), + RevCs == "\\:C" ), + true]). + +test_get_current_drive(unix). + +etest(Goal, Error) + :- + catch((Goal, !, fail), error(Error, _), true). + +test_change_current_drive(mswin32) + :- + etest(change_current_drive('E'), system_error). + +test_change_current_drive(unix). From 59722ae0cc38a592dbb5a4c1c35d4d0330f7507f Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 16:50:40 -0600 Subject: [PATCH 30/36] In both fsunix/fswin32.pro, add recursive_dir_path[s]/2 code, in-code comments (with examples), and tests in fsunix_win32.pro. --- core/alsp_src/builtins/fsunix.pro | 133 ++++++++++++++++++ core/alsp_src/builtins/fswin32.pro | 105 ++++++++++++++ .../tests/tsuite/fsunix_mswin32_test.pro | 101 ++++++++++++- 3 files changed, 337 insertions(+), 2 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index 8665b6d64..d7c4c5d27 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -26,6 +26,8 @@ export subdirs_red/1. export remove_subdir/1. export kill_subdir/1. export directory/3. +export recursive_dir_path/2. +export recursive_dir_paths/2. export get_current_drive/1. export change_current_drive/1. @@ -660,6 +662,137 @@ file_size(_,0) :- prolog_system_error(nyi, ['file_size/2',unix]). +/*!---------------------------------------------------------------- + | recursive_dir_path/2 + | recursive_dir_path(Path_List, Path) + | recursive_dir_path(+, -) + | + | Creates a nested directories path + | + | If Path_List is a list of atoms which potentially describe + | a nested path of directories in the filesystem, (and which may + | need to be created), and if the last atom either describes a + | directory or a file, then: + | 1) Path is an atom describing the path described by Path_List + | (as created by join_path/2), and + | 2) That Path is created in the filesystem, if possible; + | 2a) Moreover, either Path is absolute, + | 2b) Or path is not absolute, and so is created relative to + | the current working directory. + | Fails if the mkdir command in the underlying filesystem (unix + | or mswin32) throws an error. + | If the underlying OS is mswin32, the first element of Path_List + | is permitted to be a drive letter atom (e.g., 'C:'). + | If the underlying OS is mswin32, enableextensions must be active. + | + | Examples + | + | ?- recursive_dir_path([dir1,dir2,dir3], PL). + | + | PL='dir1/dir2/dir3' + | + | yes. + | ..... + | > ls -d dir1 + | dir1/ + | + | > ls -R dir1 + | dir2/ + | + | dir1/dir2: + | dir3/ + | + | dir1/dir2/dir3: + *!----------------------------------------------------------------*/ +recursive_dir_path(Path_List, Path) + :- + join_path(Path_List, Path), + sprintf(atom(Cmd), 'mkdir -p -- %t\n', [Path]), + system(Cmd). + +/*!---------------------------------------------------------------- + | recursive_dir_paths/2 + | recursive_dir_paths(List_of_Path_Lists, Paths) + | recursive_dir_paths(+, -) + | + | Creates multiple nested directory paths + | + | If List_of_Path_Lists is a list of lists of atoms each of which + | potentially describe a nested path of directories in the + | filesystem, (and which may need to be created), and if the + | last atom of each list either describes a directory or a file, + | then: + | 1) The length of Paths equals the length of List_of_Path_Lists, + | and each element of Paths is an atom; + | 2) For each list Path_List on List_of_Path_Lists, Path is the + | corresponding atom on Paths and + | recursive_dir_path(Path_List, Path) + | holds. + | + | Examples + | Multiple paths forming a tree: + | + | rr/ + | qq/ pp/ + | kk/ mm/ nn/ aa/ + | jj/ bb/ + | + | [[rr,qq,kk],[rr,qq,mm,jj],[rr,qq,nn],[rr,pp,aa,bb]] + | + | ?- recursive_dir_paths([[rr,qq,kk],[rr,qq,mm,jj],[rr,qq,nn],[rr,pp,aa,bb]], PL). + | + | PL=['rr/qq/kk','rr/qq/mm/jj','rr/qq/nn','rr/pp/aa/bb'] + | + | yes. + | ..... + | > ls -d rr + | rr/ + | + | > ls -R rr + | pp/ qq/ + | + | rr/pp: + | aa/ + | + | rr/pp/aa: + | bb/ + | + | rr/pp/aa/bb: + | + | rr/qq: + | kk/ mm/ nn/ + | + | rr/qq/kk: + | + | rr/qq/mm: + | jj/ + | + | rr/qq/mm/jj: + | + | rr/qq/nn: + | > + *!----------------------------------------------------------------*/ +recursive_dir_paths(List_of_Path_Lists, Paths) + :- + prepare_path_cmd_list(List_of_Path_Lists, Paths, Markers), + sys_env(OS, _, _), + (OS == unix -> + catenate(['mkdir -p -- ' | Markers], Pattern), + sprintf(atom(Cmd), Pattern, Paths) + ; + catenate(['mkdir ' | Markers], Pattern), + sprintf(atom(Cmd), Pattern, Paths) + ), + system(Cmd). + +prepare_path_cmd_list([], [], []). +prepare_path_cmd_list([Path_List | RestList_of_Path_Lists], + [Path | RestCmdList], ['%t ' | RestMarkers]) + :- + join_path(Path_List, Path), + prepare_path_cmd_list(RestList_of_Path_Lists, RestCmdList, RestMarkers). + + /* ---- * The following are essentially no-ops on unix, but * need to do something for portability to mswin32. diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index 4f91ca71e..c78ea7b36 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -658,6 +658,111 @@ make_reg_exp([C | RestPattern],[C | RestRegex]) :- make_reg_exp(RestPattern,RestRegex). +/*!---------------------------------------------------------------- + | recursive_dir_path/2 + | recursive_dir_path(Path_List, Path) + | recursive_dir_path(+, -) + | + | Creates a nested directories path + | + | If Path_List is a list of atoms which potentially describe + | a nested path of directories in the filesystem, (and which may + | need to be created), and if the last atom either describes a + | directory or a file, then: + | 1) Path is an atom describing the path described by Path_List + | (as created by join_path/2), and + | 2) That Path is created in the filesystem, if possible; + | 2a) Moreover, either Path is absolute, + | 2b) Or path is not absolute, and so is created relative to + | the current working directory. + | Fails if the mkdir command in the underlying filesystem (unix + | or mswin32) throws an error. + | If the underlying OS is mswin32, the first element of Path_List + | is permitted to be a drive letter atom (e.g., 'C:'). + | If the underlying OS is mswin32, enableextensions must be active. + | + | Examples + | + | ?- recursive_dir_path([dir1,dir2,dir3], PL). + | + | PL='dir1\\dir2\\dir3' + | + | yes. + | + | Creates a tower of subfolders: dir1\\dir2\\dir3. + | Use dir to manually examine these folders. + *!----------------------------------------------------------------*/ +recursive_dir_path(Path_List, Path) + :- + join_path(Path_List, Path), + sprintf(atom(Cmd), 'mkdir -p -- %t\n', [Path]), + system(Cmd). + +/*!---------------------------------------------------------------- + | recursive_dir_paths/2 + | recursive_dir_paths(List_of_Path_Lists, Paths) + | recursive_dir_paths(+, -) + | + | Creates multiple nested directory paths + | + | If List_of_Path_Lists is a list of lists of atoms each of which + | potentially describe a nested path of directories in the + | filesystem, (and which may need to be created), and if the + | last atom of each list either describes a directory or a file, + | then: + | 1) The length of Paths equals the length of List_of_Path_Lists, + | and each element of Paths is an atom; + | 2) For each list Path_List on List_of_Path_Lists, Path is the + | corresponding atom on Paths and + | recursive_dir_path(Path_List, Path) + | holds. + | + | Examples + | Multiple paths forming a tree: + | + | rr\\ + | qq\\ pp\\ + | kk\\ mm\\ nn\\ aa\\ + | jj\\ bb\\ + | + | [[rr,qq,kk],[rr,qq,mm,jj],[rr,qq,nn],[rr,pp,aa,bb]] + | + | ?- recursive_dir_paths([[rr,qq,kk],[rr,qq,mm,jj],[rr,qq,nn],[rr,pp,aa,bb]], PL). + | + | PL=['rr/qq/kk','rr/qq/mm/jj','rr/qq/nn','rr/pp/aa/bb'] + | + | Creates a tree of subfolders as illustrated above. + | Use dir to manually examine these folders. + *!----------------------------------------------------------------*/ +recursive_dir_paths(List_of_Path_Lists, Paths) + :- + prepare_path_cmd_list(List_of_Path_Lists, Paths, Markers), + sys_env(OS, _, _), + (OS == unix -> + catenate(['mkdir -p -- ' | Markers], Pattern), + sprintf(atom(Cmd), Pattern, Paths) + ; + catenate(['mkdir ' | Markers], Pattern), + sprintf(atom(Cmd), Pattern, Paths) + ), + system(Cmd). + +prepare_path_cmd_list([], [], []). +prepare_path_cmd_list([Path_List | RestList_of_Path_Lists], + [Path | RestCmdList], ['%t ' | RestMarkers]) + :- + join_path(Path_List, Path), + prepare_path_cmd_list(RestList_of_Path_Lists, RestCmdList, RestMarkers). + + + + + + + + + + /*!---------------------------------------------------------------- | file_size/2 | file_size(FileName,Size) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 79a46d982..02b1ebf5c 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -25,8 +25,8 @@ do_test_fs(OS,OSVar) test_get_current_drive(OS), test_change_current_drive(OS), -% test_recursive_dir_path(OS), -% test_recursive_dir_paths(OS), + test_recursive_dir_path(OS), + test_recursive_dir_paths(OS), true]). test_file_status(mswin32) @@ -309,6 +309,103 @@ test_directory(unix,OSVar) 'app_image2.pst','libalspro.dylib.pst'])), true]). +test_recursive_dir_path(_) + :- + get_cwd(TestDir), + clean_dirs(TestDir, [dir1,dir2,dir3], _), + + test([ + (Path_List = [dir1,dir2,dir3], + recursive_dir_path(Path_List, Path), + clean_dirs(TestDir, [dir1,dir2,dir3], Status), + Status == ok, + change_cwd(TestDir)), + true ]). + +clean_dirs(TestDir, DirsList, Status) :- + do_clean_dirs([TestDir | DirsList], [], Status). + +do_clean_dirs([], Stack, Status) :- + climb_and_clean(Stack, Status). + +do_clean_dirs([Dir | DirsList], Stack, Status) :- + (exists_file(Dir) -> + change_cwd(Dir), + do_clean_dirs(DirsList, [Dir | Stack], Status) + ; + Status = fail + ). + +climb_and_clean([], ok). +climb_and_clean([Top], ok) :- !, + change_cwd('..'). +climb_and_clean([Dir | Stack], Status) :- + change_cwd('..'), + remove_subdir(Dir), + climb_and_clean(Stack, Status). + + +climb_dirs([], TestDir, Status). +climb_dirs([Dir | Stack], TestDir, Status) :- + change_cwd('..'), + climb_dirs(Stack, TestDir, Status). + +/* Multiple paths forming a tree: + + rr/ + qq/ pp/ + kk/ mm/ nn/ aa/ + jj/ bb/ + + [[rr,qq,kk],[rr,qq,mm,jj],[rr,qq,nn],[rr,pp,aa,bb]] + */ + +test_recursive_dir_paths(_) + :- + List_of_Path_Lists = [[rr,qq,kk],[rr,qq,mm,jj],[rr,qq,nn],[rr,pp,aa,bb]], + get_cwd(TestDir), + + test([ + (recursive_dir_paths(List_of_Path_Lists, Paths), + check_multi_dirs(List_of_Path_Lists, Tops, TestDir, Status), + Status == ok, + change_cwd(TestDir), + remove_list_dirs(Tops)), + true ]). + +check_multi_dirs([], [], TestDir, ok). +check_multi_dirs([Path_List], [Top], TestDir, Status) :- + Path_List = [Top | _], + check_list(Path_List, TestDir, [], Status), + Status = ok. +check_multi_dirs([Path_List | List_of_Path_Lists], [Top | Tops], TestDir, Status) :- + Path_List = [Top | _], + check_list(Path_List, TestDir, [], Status), + check_multi_dirs(List_of_Path_Lists, Tops, TestDir, Status). + +check_list([], TestDir, Stack, Status) :- + climb_dirs(Stack, TestDir, Status). + +check_list([Dir | DirsList], TestDir, Stack, Status) :- + (exists_file(Dir) -> + change_cwd(Dir), + check_list(DirsList, TestDir, [Dir | Stack], Status) + ; + Status = fail, + change_cwd(TestDir) + ). + +climb_dirs([], TestDir, Status). +climb_dirs([Dir | Stack], TestDir, Status) :- + change_cwd('..'), + climb_dirs(Stack, TestDir, Status). + +remove_list_dirs([]). +remove_list_dirs([Top | Tops]) :- + (exists_file(Top) -> + kill_subdir(Top) ; true), + remove_list_dirs(Tops). + /* -----------------------------* | Only meaningful for mwwin32 * -----------------------------*/ From 0b2003853a8cef915103bda6d92a015754c3faab Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 17:49:49 -0600 Subject: [PATCH 31/36] Add missing exports for recursive_dir_path[s]/2 --- core/alsp_src/builtins/fswin32.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index c78ea7b36..cd2955103 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -24,6 +24,8 @@ export subdirs_red/1. export remove_subdir/1. export kill_subdir/1. export directory/3. +export recursive_dir_path/2. +export recursive_dir_paths/2. export get_current_drive/1. export change_current_drive/1. From 97ce13e1536875db7729fcf33cef643890d1480d Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 19:45:05 -0600 Subject: [PATCH 32/36] Repair errors from earlier merge resolution, and improve test cleanup for test_recursive_dir_path. --- core/alsp_src/builtins/fsunix.pro | 16 ------------ core/alsp_src/builtins/fswin32.pro | 25 ------------------- .../tests/tsuite/fsunix_mswin32_test.pro | 1 + 3 files changed, 1 insertion(+), 41 deletions(-) diff --git a/core/alsp_src/builtins/fsunix.pro b/core/alsp_src/builtins/fsunix.pro index c85c61336..8fa6f6e41 100644 --- a/core/alsp_src/builtins/fsunix.pro +++ b/core/alsp_src/builtins/fsunix.pro @@ -647,22 +647,6 @@ make_reg_exp([C | RestPattern],[C | RestRegex]) :- make_reg_exp(RestPattern,RestRegex). -<<<<<<< HEAD -/*!---------------------------------------------------------------- - | file_size/2 - | file_size(FileName,Size) - | file_size(+,-) - | - | - returns the size of a file - | - | If File is an atom (possibly quoted) which is the name of a - | file in the current working directory, Size is the size of - | that file in bytes. - *!----------------------------------------------------------------*/ -file_size(_,0) - :- - prolog_system_error(nyi, ['file_size/2',unix]). - /*!---------------------------------------------------------------- | recursive_dir_path/2 | recursive_dir_path(Path_List, Path) diff --git a/core/alsp_src/builtins/fswin32.pro b/core/alsp_src/builtins/fswin32.pro index db8297718..b9ec7c9a2 100644 --- a/core/alsp_src/builtins/fswin32.pro +++ b/core/alsp_src/builtins/fswin32.pro @@ -660,7 +660,6 @@ make_reg_exp([C | RestPattern],[C | RestRegex]) :- make_reg_exp(RestPattern,RestRegex). -<<<<<<< HEAD /*!---------------------------------------------------------------- | recursive_dir_path/2 | recursive_dir_path(Path_List, Path) @@ -757,30 +756,6 @@ prepare_path_cmd_list([Path_List | RestList_of_Path_Lists], join_path(Path_List, Path), prepare_path_cmd_list(RestList_of_Path_Lists, RestCmdList, RestMarkers). - - - - - - - - - -/*!---------------------------------------------------------------- - | file_size/2 - | file_size(FileName,Size) - | file_size(+,-) - | - | - returns the size of a file - | - | If File is an atom (possibly quoted) which is the name of a - | file in the current working directory, Size is the size of - | that file in bytes. - *!----------------------------------------------------------------*/ -file_size(_,0) - :- - prolog_system_error(nyi, ['file_size/2',unix]). - /*!---------------------------------------------------------------- | get_current_drive/1 | get_current_drive(Drive) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 02b1ebf5c..7a5a74ada 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -341,6 +341,7 @@ climb_and_clean([Top], ok) :- !, change_cwd('..'). climb_and_clean([Dir | Stack], Status) :- change_cwd('..'), + system('del *'), remove_subdir(Dir), climb_and_clean(Stack, Status). From a0671a9cd011327af07464016cb27e68327a49d9 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 20:03:07 -0600 Subject: [PATCH 33/36] Work to suppress Windows prompts on cleanup in fswin32.pro --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 7a5a74ada..f171d10be 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -341,8 +341,16 @@ climb_and_clean([Top], ok) :- !, change_cwd('..'). climb_and_clean([Dir | Stack], Status) :- change_cwd('..'), - system('del *'), - remove_subdir(Dir), + (Dir == dir2 -> + system('del dir3') + ; + (Dir == dir1 + system('del dir2') + ; + system('del dir1') + ) + ), +% remove_subdir(Dir), climb_and_clean(Stack, Status). From 1f2b80cdb9110a1fb5e9c9fc757924858d666aed Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 20:53:57 -0600 Subject: [PATCH 34/36] More work to suppress Windows prompts on cleanup in fswin32.pro --- .../tests/tsuite/fsunix_mswin32_test.pro | 52 ++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index f171d10be..9121ef3dc 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -309,49 +309,65 @@ test_directory(unix,OSVar) 'app_image2.pst','libalspro.dylib.pst'])), true]). -test_recursive_dir_path(_) +test_recursive_dir_path(OS) :- get_cwd(TestDir), - clean_dirs(TestDir, [dir1,dir2,dir3], _), + clean_dirs(TestDir, OS, [dir1,dir2,dir3], _), test([ (Path_List = [dir1,dir2,dir3], recursive_dir_path(Path_List, Path), - clean_dirs(TestDir, [dir1,dir2,dir3], Status), + clean_dirs(TestDir, OS, [dir1,dir2,dir3], Status), Status == ok, change_cwd(TestDir)), true ]). -clean_dirs(TestDir, DirsList, Status) :- - do_clean_dirs([TestDir | DirsList], [], Status). +clean_dirs(TestDir, OS, DirsList, Status) :- + do_clean_dirs([TestDir | DirsList], [], OS, Status). -do_clean_dirs([], Stack, Status) :- - climb_and_clean(Stack, Status). +do_clean_dirs([], Stack, OS, Status) :- + climb_and_clean(Stack, OS, Status). -do_clean_dirs([Dir | DirsList], Stack, Status) :- +do_clean_dirs([Dir | DirsList], Stack, OS, Status) :- (exists_file(Dir) -> change_cwd(Dir), - do_clean_dirs(DirsList, [Dir | Stack], Status) + do_clean_dirs(DirsList, [Dir | Stack], OS, Status) ; Status = fail ). -climb_and_clean([], ok). -climb_and_clean([Top], ok) :- !, +climb_and_clean([], OS, ok). +climb_and_clean([Top], OS, ok) :- !, change_cwd('..'). -climb_and_clean([Dir | Stack], Status) :- +climb_and_clean([Dir | Stack], OS, Status) :- change_cwd('..'), - (Dir == dir2 -> - system('del dir3') + (Dir == dir3 -> + (OS == mswin32 -> + system('del /f dir3') + ; + system('rm -rf dir3') + ) ; - (Dir == dir1 - system('del dir2') + (Dir == dir2 -> + (OS == mswin32 -> + system('del /f dir2') + ; + system('rm -rf dir2') + ) ; - system('del dir1') + (Dir == dir1 -> + (OS == mswin32 -> + system('del /f dir1') + ; + system('rm -rf dir1') + ) + ; + true + ) ) ), % remove_subdir(Dir), - climb_and_clean(Stack, Status). + climb_and_clean(Stack, OS, Status). climb_dirs([], TestDir, Status). From 3e57ebc903abb58125c6c957e69592d2dd7db120 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 22:12:11 -0600 Subject: [PATCH 35/36] In fswin32.pro:climb_and_clean/3, change del /f to rmdir/f --- core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 9121ef3dc..91844d32d 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -343,21 +343,21 @@ climb_and_clean([Dir | Stack], OS, Status) :- change_cwd('..'), (Dir == dir3 -> (OS == mswin32 -> - system('del /f dir3') + system('rmdir /f dir3') ; system('rm -rf dir3') ) ; (Dir == dir2 -> (OS == mswin32 -> - system('del /f dir2') + system('rmdir /f dir2') ; system('rm -rf dir2') ) ; (Dir == dir1 -> (OS == mswin32 -> - system('del /f dir1') + system('rmdir /f dir1') ; system('rm -rf dir1') ) From 2dc3ad8216839ff53007edd9ea28b447d44fff57 Mon Sep 17 00:00:00 2001 From: kenbowen Date: Thu, 23 Apr 2020 22:35:26 -0600 Subject: [PATCH 36/36] Experiment using kill_subdir instead of system(...) --- .../tests/tsuite/fsunix_mswin32_test.pro | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro index 91844d32d..bb2bdcb56 100644 --- a/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro +++ b/core/alsp_src/tests/tsuite/fsunix_mswin32_test.pro @@ -342,30 +342,54 @@ climb_and_clean([Top], OS, ok) :- !, climb_and_clean([Dir | Stack], OS, Status) :- change_cwd('..'), (Dir == dir3 -> +/* (OS == mswin32 -> system('rmdir /f dir3') ; system('rm -rf dir3') ) +*/ + kill_subdir(dir3) ; +/* (Dir == dir2 -> (OS == mswin32 -> system('rmdir /f dir2') ; system('rm -rf dir2') ) +*/ + kill_subdir(dir2) ; +/* (Dir == dir1 -> (OS == mswin32 -> system('rmdir /f dir1') ; system('rm -rf dir1') ) +*/ kill_subdir(dir1) + ; + true +% ) +% ) + ), + + (Dir == dir3 -> + kill_subdir(dir3) + ; + (Dir == dir2 -> + kill_subdir(dir2) + ; + (Dir == dir1 -> + kill_subdir(dir1) ; true ) ) - ), + ), + + % remove_subdir(Dir), climb_and_clean(Stack, OS, Status).