aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2021-04-14 11:18:49 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2021-04-14 11:18:49 -0400
commit137bcd5810c49fcecd75f4d51f2043f55c3a96f2 (patch)
tree01d13c6d614a3fd95527795a3a5f9838e7dbdcfe
parent05b91a7ca0aace044621d8db1e82f4772181d893 (diff)
downloadlevitating-137bcd5810c49fcecd75f4d51f2043f55c3a96f2.tar.gz
levitating-137bcd5810c49fcecd75f4d51f2043f55c3a96f2.zip
Added Windows support for getting directory and file listings
-rw-r--r--common/utilities.F9044
-rw-r--r--player/tasks.f9010
2 files changed, 38 insertions, 16 deletions
diff --git a/common/utilities.F90 b/common/utilities.F90
index 981dee3..0c659ac 100644
--- a/common/utilities.F90
+++ b/common/utilities.F90
@@ -285,21 +285,36 @@ contains
tempfile => generate_temporary_filename()
res => null()
-
+
+#ifdef WINDOWS
+ call execute_command_line("dir /b/ad-h"//trim(directory)//" > "//trim(tempfile), &
+ wait=.true.)
+#else
call execute_command_line("ls -l "//trim(directory)//" > "//trim(tempfile), &
wait=.true.)
+#endif
open(newunit=unum, file=tempfile, action='read')
-
+
+#ifndef WINDOWS
! First line is "total ###"
read(unum, '(A)', iostat=ierr) line
-
+#endif
+
dcount = 0
read(unum, '(A)', iostat=ierr) line
do while(ierr == 0)
+
+#ifdef WINDOWS
+ if(len_trim(line) > 0) then
+ dcount = dcount + 1
+ end if
+#else
if(line(1:1) == 'd') then
dcount = dcount + 1
end if
+#endif
+
read(unum, '(A)', iostat=ierr) line
end do
@@ -308,9 +323,13 @@ contains
if(dcount > 0) then
allocate(res(dcount))
+ ! Windows is all set, don't call anything
+#ifndef WINDOWS
! Now call ls, but group directories first
call execute_command_line("ls --group-directories-first "//trim(directory)//" > "//trim(tempfile), &
wait=.true.)
+#endif
+
open(newunit=unum, file=tempfile, action='read')
i = 0
read(unum, '(A)', iostat=ierr) line
@@ -338,9 +357,14 @@ contains
tempfile => generate_temporary_filename()
res => null()
-
+
+#ifdef WINDOWS
+ call execute_command_line("dir /b/a-d-h"//trim(directory)//" > "//trim(tempfile), &
+ wait=.true.)
+#else
call execute_command_line("ls -l "//trim(directory)//" > "//trim(tempfile), &
wait=.true.)
+#endif
open(newunit=unum, file=tempfile, action='read')
@@ -350,13 +374,15 @@ contains
! Count directories first
read(unum, '(A)', iostat=ierr) line
do while(ierr == 0)
-
+
+#ifndef WINDOWS
if(line(1:1) == 'd') then
dcount = dcount + 1
end if
-
+#endif
+
! ls puts a nonsense entry first. harmless, but we don't want it
- if(line(1:6) /= "total ") then
+ if(line(1:6) /= "total " .and. len_trim(line) > 0) then
total_count = total_count + 1
end if
@@ -372,9 +398,13 @@ contains
allocate(res(n))
!print *, "Size: ", size(res)
+ ! We don't need to recreate the file on Windows. It's fine.
+#ifndef WINDOWS
! Now call ls, but group directories first
call execute_command_line("ls --group-directories-first "//trim(directory)//" > "//trim(tempfile), &
wait=.true.)
+#endif
+
open(newunit=unum, file=tempfile, action='read')
i = 0
diff --git a/player/tasks.f90 b/player/tasks.f90
index 2487e73..451bc5a 100644
--- a/player/tasks.f90
+++ b/player/tasks.f90
@@ -109,7 +109,7 @@ contains
end function upload_glob
- recursive function upload(url, source_filename) result(res)
+ function upload(url, source_filename) result(res)
use config, only: token, captain
use gemini_protocol, only: titan_post_url, STATUS_SUCCESS
implicit none
@@ -123,14 +123,6 @@ contains
integer(kind=8)::file_size
integer::unit_number, istatus, url_length, i
- ! Check for globbing - sloppy, but still...
- if(index(source_filename, "*") > 0 .or. index(source_filename, "?") > 0) then
-
- res = upload_glob(url, source_filename)
- return
-
- end if
-
! If we're here, we have a single filename to upload
inquire(file=source_filename, size=file_size)