home *** CD-ROM | disk | FTP | other *** search
/ Amiga Computing 57 / ac057a.adf / Demos / GetFile.bas < prev    next >
BASIC Source File  |  1989-06-28  |  2KB  |  76 lines

  1.  
  2. ' a program showing the use of the ARP File Requestor
  3. ' IMPORTANT: will *not* work on versions of the compiler
  4. ' prior to 1.04 due to a bug; it will compile but not run correctly
  5.  
  6. ' new version allows it to appear on any screen
  7.  
  8. DEFINT a-z
  9.  
  10. LIBRARY "arp.library"
  11. DECLARE FUNCTION FileRequest&(buffer&) LIBRARY
  12. DECLARE FUNCTION BaseName&(pathptr&) LIBRARY
  13. DECLARE SUB TackOn(path&,file&) LIBRARY
  14.  
  15. ' passed a complete pathname, breaks it up into path/filename
  16. ' then calls the ARP selector
  17. ' returns -1 if OK, 0 means Cancelled
  18. ' changes the parameter if OK selected
  19. ' if scrnum%<>0 then it is used as the screen number
  20.  
  21. FUNCTION GetFile%(fname$,message$,VAL scrnum%)
  22. LOCAL path$,file$,buffer&(11),result&,term%,scr&,buf&
  23.  
  24. ' split up the pathname as required
  25. path$=SPACE$(80)
  26. LSET path$=fname$+CHR$(0)
  27. file$=SPACE$(40)
  28. result&=BaseName(SADD(path$))
  29. POKEB result&,0                'into path$
  30. term%=result&-SADD(path$)
  31. LSET file$=RIGHT$(fname$,LEN(fname$)-term%)+CHR$(0)
  32.  
  33. ' get the FR_buffer set up and call ARP
  34. buf&=VARPTR(buffer&(0))
  35. POKEL buf&,SADD(message$+CHR$(0))
  36. POKEL buf&+4,SADD(file$)
  37. POKEL buf&+8,SADD(path$)
  38. POKEL buf&+12,0
  39. POKEW buf&+16,0            'flag
  40. POKEL buf&+18,0            'function
  41. POKEL buf&+22,0            'reserved
  42.  
  43. ' handle custom screens (this is a bit messy, but it works...)
  44. IF scrnum% THEN
  45.     scr&=PEEKL(SYSTAB+8+4*scrnum%)
  46.     IF (scr&=0) OR (scrnum%<1) OR (scrnum%>4) THEN PRINT "Error":STOP
  47.     POKEW buf&+26,&h217C
  48.     POKEL buf&+28,scr&
  49.     POKEL buf&+32,&h001E317C
  50.     POKEL buf&+36,&h000F002E
  51.     POKEW buf&+40,&h4E75
  52.     POKEL buf&+18,buf&+26
  53.     POKEB buf&+16,8
  54. END IF
  55.  
  56. result&=FileRequest(buf&)
  57. IF result&=0 THEN
  58.     GetFile%=0
  59. ELSE
  60.     TackOn SADD(path$),SADD(file$)
  61.     fname$=LEFT$(path$,INSTR(path$,CHR$(0))-1)
  62.     GetFile%=-1
  63. END IF
  64. END FUNCTION
  65.  
  66.  
  67.  
  68. ' example code:
  69.  
  70. file$="test.bas"
  71. DO
  72. worked=GetFile(file$,"Select File",0)    '0=on Workbench screen
  73. PRINT file$
  74. LOOP UNTIL worked=0            'until cancelled
  75.  
  76.