PROGRAM FileRequester

? By DNS, Inc. Spring, 1993
? Program shows how to use the AmigaDOS system's built-in file
?  requester (requires Version 2.0, 2.1, or 3.0 of DOS)
? As written, always open the requester with ram:example as the
?  default file

CONSTANT ASL_FileRequest=0
INTEGER I,J,K,L,AslLibPtr,Result
TEXT*80 TextStr,FileDirName,FileName

TYPE FileRequester IS RECORD
   BYTE Reserved0(4)
   PTR_TO TEXT File
   PTR_TO TEXT Drawer
   BYTE Reserved1(10)
   WORD LeftEdge,TopEdge,Width,Height
   BYTE Reserved2(2)
   INTEGER NumArgs
   INTEGER ArgList
   INTEGER UserData
   BYTE Reserved3(8)
   PTR_TO TEXT Pattern
ENDTYPE

TYPE TagItem IS RECORD
   INTEGER  Tag
   INTEGER  Data
ENDTYPE

TagItem TAGS(4)
PTR_TO FileRequester FreqPtr

DATA (TextStr,"This Is The TitleBar"),(FileDirName,"ram:"),(FileName,"example")

? This is the string of tags necessary to display the title,
? the initial drawer, and the initial file name
TAGS(1).Tag=80080001'16
TAGS(1).Data=@TextStr
TAGS(2).Tag=80080008'16
TAGS(2).Data=@FileName
TAGS(3).Tag=80080009'16
TAGS(3).Data=@FileDirName
TAGS(4).Tag=0
TAGS(4).Data=0

TextStr(LENGTH(TextStr)+1)=CHAR(0)
FileDirName(LENGTH(FileDirName)+1)=CHAR(0)
FileName(LENGTH(FileName)+1)=CHAR(0)

&SYSLIB 1

AslLibPtr=OPENLIB("asl.library",0)
IF AslLibPtr THEN
   ? allocates system resources for the file requester
   FreqPtr=AllocAslRequest(AslLibPtr,ASL_FileRequest,@TAGS)
   IF FreqPtr<>0 THEN
      ? displays the file requester
      Result=AslRequest(AslLibPtr,FreqPtr,NIL)
      IF Result THEN
         ? Note, prints the first characters of the file
         ? name and the drawer name until it finds a CHAR(0)
         ? in the buffer, signifying the end of the string.
         PRINT "The Chosen File Was: ",
         J=FreqPtr.File
         WHILE ^J<>0 DO
            PRINT CHAR(^J),
            INC(J)
         ENDWHILE
         PRINT
         PRINT "The Chosen Drawer Was: ",
         J=FreqPtr.Drawer
         WHILE ^J<>0 DO
            PRINT CHAR(^J),
            INC(J)
         ENDWHILE
         PRINT
         ? deallocates system resources for the file requester
         FreeAslRequest(AslLibPtr,FreqPtr)
      ENDIF
   ENDIF
ENDIF
I=CLOSELIB(AslLibPtr)
END
