!
!  simcvax.bas  VAX BASIC V3.3
!
!  converts the index file SIMIBM.IDX into the
!  easily read file SIMIBM.LST (for the entire list)
!  or SIMIBM.LSTyymmdd (if the starting date is yymmdd)
!
!
!  Gives the user the option to include in the list file only those
!  files added to the index after a specified date.
!
!  Gives the user the option to include in the list file only those
!  files whose names, directories, or descriptions contain a given
!  substring.
!
!  Part of this program was translated from Dustin Fu's SIMCVT.FOR
!  to VAX BASIC V3.3
!
!   Improvements by
!                     Don Chodrow
!                     Physics Department
!                     James Madison University
!                     Harrisonburg, VA 22807
!                     BITNET:      FAC_CHOD@JMUVAX1
!                     INTERNET:    dc@dirac.physics.jmu.edu
!
!    Further improvements suggested by
!		Mark Harris, Digital Eq, Littleton, MA 01460
!
!
!  This program will convert the file SIMIBM.IDX into a readable form,
!  sending the output to the file SIMIBM.LST.  Because it is written in
!  BASIC instead of FORTRAN, there is no need to convert quotes to
!  apostrophes.
!
!  This program may be loaded into the VAX BASIC environment and run, or
!  it may be compiled and linked to produce an .exe file:
!
!           $ basic simcvax
!           $ link simcvax
!           $ run simcvax
!
external string function ucase$ (string)

print
print
!
print "Do you wish to locate a specific file or files with their DIRECTORY,"
input "FILENAME, or DESCRIPTION containing a substring <Y/N>",yesno$
yesno$ = ucase$(left$(yesno$,1))
substring$=""
!
while substring$="" and yesno$="Y"
   print "The search is not case sensitive."
   input "Please enter the substring to locate ", substring$
next
print
print
!
yesno$ = ""
print "Do you want to list only those files added to the index"
input "after a certain date <Y/N>",yesno$
yesno$ = ucase$(left$(yesno$,1))
starter$ = "0"
if (yesno$ = "Y") then
   yr%=0
   while (yr% <87) or (yr% > 99)
      input "Enter the last 2 digits of the starting year: ",yr%
   next
   month% = 0
   while (month% < 1) or (month% > 12)
      input "Enter the number of the starting month, 1 to 12: ",month%
   next
   day% = 0
   while (day% < 1) or (day% > 31)
     input "Enter the starting day, 1 to 31: ",day%
   next

   starter$ = str$(yr%)

   if (month% < 10) then
      starter$=starter$ + "0"+str$(month%)
   else
      starter$ = starter$ + str$(month%)
   end if

   if (day% < 10) then
      starter$ = starter$ + "0" + str$(day%)
   else
      starter$ = starter$ + str$(day%)
   end if
end if

outfile$ = "simibm.lst"
if starter$ <> "0" then
   outfile$ = "simibm.lst" + starter$
end if
if substring$ <> "" then
  outfile$ = outfile$ + left(substring$,8)
end if

start% = val%(starter$)

open "SIMIBM.IDX" for input as file #1
open outfile$ for output as file #2
margin #2,80%
print #2, "WSMR-SIMTEL20.ARMY.MIL PUBLIC DOMAIN LISTING AS OF ";date$(0)
if starter$ <> "0" then
   print #2, " "
   print #2, "This list contains files dated ";starter$;" or later."
end if
if substring$ <> "" then
   print #2, " "
   print #2, "This list contains files with names and/or description"
   print #2, "containing the substring : ";substring$
end if
print #2," "
print #2, "NOTE: Type B is Binary; Type A is ASCII"

fs1$ = " "      ! initialize
dir1$ = " "     ! initialize

qq$ = "'LLLLLLLLLLLL 'L ####### ###### "
qq$ = qq$ + "'LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"
!
!  qq$ is the PRINT USING format string
!

when error use closer  ! terminate program when end of file #1 is reached
  print 
  print "Working ....  Please wait."
  while 1 = 1  ! "endless" loop, terminated by end of file #1 "error"
    input #1, fs2$,dir2$,filnam$,rev,lngth%,bits%,dt,descr$
    dummy$ = fs2$ + "  " + dir2$ + "  " + filnam$ + "  " + descr$
    dummy$ = ucase$(dummy$)           ! make searches
    substring$ = ucase$(substring$)   ! case insensitive
    if ((dt >= start%) and ((substring$ = "") or ((substring$ <>"") and  &
               pos(dummy$,substring$,1)))) then
      if ((fs1$ <> fs2$) or (dir1$ <> dir2$)) then
          print #2," "
          print #2,"Directory ";fs2$;dir2$
          print #2," Filename   Type Length   Date    Description"
          print #2,"=============================================="
          dir1$ = dir2$
          fs1$ = fs2$
      end if

      if (bits% = 8) then
         style$ = "B"
      else
         style$ = "A"
      end if

      print #2 using qq$ ; filnam$,style$,lngth%,dt,descr$
    end if
  next  ! end of "endless" loop

end when
print
print "Output has been written to the file ";outfile$
print
print

handler closer
   if err = 11 then
      close #1
      close #2
   end if
end handler

end

!----------------- function module starts here -------------
function string ucase$(a$)
!
!   Turns a string to all upper case
!
n = len(a$)
up$ = ""

for i = 1 to n
   q$ = mid$(a$,i,1)
   if (q$ >= "a") and (q$ <= "z") then
      q$ = chr$(asc(q$) - 32)
   end if
   up$ = up$ + q$
next i

ucase$ = up$

end function
