[comp.sys.acorn] Another useful util.

nbvs@cl.cam.ac.uk (Nicko van Someren) (03/15/91)

Here is another short bit of useful code.
The DoOpen application takes a file name and tries to 'open' that file.
First it broadcasts an open request to all the running applications and if
none of them accept it DoOpen tries to run the file.  The effect is that if
you try to open, say, a sprite file and !Paint is already running the file
will get loaded by the version of paint the is there rather than a new copy
getting started which is what would happen if you just ran the file.

This is handy for things like obey files that call an application, put the
output into a file and then can have !Edit (or !uEmacs) put the output onto
the screen without having to start another copy.

I hope people don't find this too long (roll on comp.bin.acorn...)

Share and enjoy...

(P.S. You may want to set the WimpSlot quite small before running DoOpen as it
potentially starts another application but it needs little space for itself.)

REM > DoOpen
DIM taskid%4:$taskid%="TASK"
SYS "Wimp_Initialise",200,!taskid%,"DoOpen" TO ,taskhand%
DIM q% 256,b% 512

SYS "OS_GetEnv" TO params$
SYS "OS_ReadArgs","quit/s,basic,prog,file",params$,b%,512

a% = !(b%+12)
IF a%=0 ERROR 0,"Need a file to open"
a$="":WHILE ?a%:a$+=CHR$(?a%):a%+=1:ENDWHILE

SYS "OS_File",5,a$ TO x%,,l%,,s%
IF x%=0 ERROR 0,"File "+a$+" not found"

$(q%+44)=a$
?(q%+44+LEN(a$))=0
q%!0= (48+LEN(a$))AND NOT 3
q%!12=0
q%!16=5
q%!36=s%
q%!40=(l% AND &FFF00)>>8

SYS "Wimp_SendMessage",18,q%

REPEAT
SYS "Wimp_Poll",,q% TO A%
CASE A% OF
WHEN 0:PROCdie
WHEN 19:SYS "Wimp_StartTask","Run "+a$
  PROCdie
ENDCASE
UNTIL FALSE

DEFPROCdie
SYS "Wimp_CloseDown",taskhand%,!taskid%
END
ENDPROC
+-----------------------------------------------------------------------------+
| Nicko van Someren, nbvs@cl.cam.ac.uk, (44) 223 358707 or (44) 860 498903    |
|       "Go and buy an Aleph One ARM3 card and stop whining!!!"               |
+-----------------------------------------------------------------------------+