home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-29 | 31.9 KB | 1,097 lines |
- /*************************************************************************
- * *
- * VisageCom *
- * *
- * By Philippe "Elwood" FERRUCCI Decines FRANCE *
- * *
- *************************************************************************/
-
- MODULE 'dos/dos', -> SIGBREAKF_CTRL_D,SHARED_LOCK
- 'intuition/screens','intuition/intuition',
- 'gadtools','libraries/gadtools','reqtools','libraries/reqtools',
- 'utility/tagitem','graphics/gfxbase',
- 'graphics/gfx', -> rectangle
- 'graphics/rastport', -> rastport
- 'graphics/view', -> viewport
- 'graphics/text','exec/ports','exec/nodes',
- 'graphics/modeid', -> MONITOR_ID_MASK
- 'graphics/displayinfo',
- 'dos/dosextens','exec/tasks',
-
- 'intuition/intuitionbase',
-
- 'exec/io', -> iostdreq
- 'devices/input', -> CMD_WAITEVENT
- 'devices/inputevent', -> inputevent
- 'exec/memory' -> MEMF_PUBLIC
-
- ENUM NONE,NOARGS,NOMEM,NOLIB,NOGAD,NOFILE1,NOFILE2,NOSCREEN,NOMODE
-
- CONST LACE=2
-
- DEF progname[50]:STRING,args:PTR TO LONG,template,rdargs,modeid=NIL
-
- -> filename can be 108 chars long
- DEF filename[108]:STRING,destination[78]:STRING,
- pathname[78]:STRING,basename[30]:STRING,validdest
-
- DEF p_filelock=NIL,fib=NIL:PTR TO fileinfoblock -> init with NIL
-
- DEF scr=NIL:PTR TO screen,win=NIL:PTR TO window,wintitle[100]:STRING,topscreen
- DEF p_ta=NIL:PTR TO textattr,p_tf:PTR TO textfont -> default font
-
- DEF visual,glist=NIL,p_gad:PTR TO gadget
- DEF idcmp
-
- DEF getout=0,useranswer,visagetask:PTR TO task -> to store the visage task
-
- DEF tmpstr[108]:STRING
-
- OBJECT button -> used to create a list of button
- item:PTR TO CHAR
- ENDOBJECT
-
- RAISE NOARGS IF ReadArgs() = NIL, -> automatic error handling :
- NOLIB IF OpenLibrary() = NIL, -> when the program is done
- NOMEM IF OpenScreenTagList() = NIL, -> I sequentially pick each
- NOGAD IF GetVisualInfoA() = NIL, -> potential failure of the
- NOGAD IF CreateContext() = NIL, -> program and I build this
- NOGAD IF CreateGadgetA() = NIL, -> list.
- NOMEM IF OpenWindowTagList() = NIL, -> Thanks to Wouter, the
- NOFILE1 IF Read() = -1, -> source is easier to read
- NOMEM IF New() = NIL, -> and understand.
- NOFILE2 IF AddPart() = NIL,
- NOMEM IF RtAllocRequestA() = NIL
-
- PROC main() HANDLE
- VOID '$VER: VisageCom 1.5 By Philippe "Elwood" FERRUCCI (01/07/97)'
-
- init()
-
- opengui()
-
- mainloop()
-
- Raise(NONE) -> everything is done we get out of here.
-
- EXCEPT
- IF fib THEN FreeDosObject(DOS_FIB,fib)
-
- IF scr THEN ScreenToBack(scr)
- IF win THEN CloseWindow(win); win := NIL -> close the window first !
- IF glist THEN FreeGadgets(glist) -> and this line second.
- IF visual THEN FreeVisualInfo(visual)
- IF gadtoolsbase THEN CloseLibrary(gadtoolsbase)
- IF reqtoolsbase THEN CloseLibrary(reqtoolsbase)
-
- IF scr THEN CloseScreen(scr); scr := NIL
-
- -> I close everything before saying Visage to continue to avoid problems
- -> I encoutered in double buffering mode
- -> (the new selected window wasn't the "in front" one)
-
- -> when Visage is showing an image it (Visage itself or the datatype it
- -> is using) locks that file, so before deleting I have to say to Visage
- -> to continue in order to remove the lock on the file
-
- IF (getout = -1) OR (getout = 1) THEN
- IF visagetask THEN Signal(visagetask,SIGBREAKF_CTRL_D)
-
- IF getout = 1
- Delay(50) -> I wait a while to be sure lock is dead
- DeleteFile(filename) -> guess what this dos library function do ?
- ENDIF
-
- SELECT exception
- CASE NOARGS
- StrCopy(wintitle,'Usage: ',ALL)
- StrAdd(wintitle,progname,ALL)
- StrAdd(wintitle,' <filename> [destination] [MODEID]',ALL)
- dowarn(wintitle)
- CASE NOMEM
- dowarn('Not enough memory !')
- CASE NOLIB
- dowarn('Can''t open required libraries !')
- CASE NOGAD
- dowarn('Failure in a gadtools function !')
- CASE NOFILE1
- dowarn('Can''t read file correctly !')
- CASE NOFILE2
- dowarn('Can''t write file !')
- CASE NOSCREEN
- dowarn('Can''t find Visage screen !')
- CASE NOMODE
- dowarn('Incorrect modeid !')
- ENDSELECT
- CleanUp(0) -> Amiga E cleans used RAM
-
- ENDPROC
-
- PROC init()
-
- -> this is only for writing a good 'Usage' message (if you changed the
- -> name of the prog (in 'Vcom' for instance)
- IF (GetProgramName(progname,50)) = 1 THEN StrCopy(progname,'VisageCom',ALL)
-
- args:=[NIL,NIL,NIL,NIL] -> init args structure.
- template:='FILE/A,DEST,MODEID/K,TOPSCREEN/K/N' -> 1 argument needed.
- rdargs:=ReadArgs(template,args,NIL) -> dos library function.
-
- StrCopy(filename,args[],ALL) -> copy of args in Estring
- IF args[1]
- StrCopy(destination,args[1],ALL)
- ELSE
- StrCopy(destination,'nothing/:',ALL)
- ENDIF
- IF args[2] THEN modeid := Val(args[2])
- IF args[3]
- topscreen := args[3]
- topscreen := Long(topscreen)
- ENDIF
- FreeArgs(rdargs) -> dos library function.
-
- IF modeid THEN IF ModeNotAvailable(modeid) <> NIL THEN Raise(NOMODE)
-
- getfilefib(filename)
- extractfilenames(filename,pathname,basename)
-
- checkdest() -> check if destination is valid and copy is possible
-
- gadtoolsbase := OpenLibrary('gadtools.library',39) -> open needed libs
- reqtoolsbase := OpenLibrary('reqtools.library',38)
-
- getdefaultfont()
-
- ENDPROC
-
- PROC getfilefib(name:PTR TO CHAR)
- DEF tmp
-
- IF (p_filelock := Lock(name,SHARED_LOCK)) = NIL THEN Raise(NOFILE1)
-
- -> we fill the FIB structure with file informations
- IF fib = NIL THEN IF (fib := AllocDosObject(DOS_FIB,NIL)) = NIL THEN Raise(NOFILE1)
-
- tmp := Examine(p_filelock,fib)
- IF tmp = 0 -> fills 'fib' structure
- FreeDosObject(DOS_FIB,fib) -> with infos about the file
- fib := NIL
- ENDIF
- UnLock(p_filelock)
-
- ENDPROC
-
- PROC extractfilenames(file:PTR TO CHAR,path:PTR TO CHAR,name:PTR TO CHAR)
- DEF tmpptr:PTR TO CHAR,tmplock,pos
-
- IF tmplock := Lock(file,SHARED_LOCK)
-
- -> we get the complete filename (even if not specified)
- NameFromLock(tmplock,file,108)
-
- tmpptr := FilePart(file) -> extract only the file name
- StrCopy(name,tmpptr,ALL)
-
- -> we get the path name
- tmpptr := PathPart(file) - file
- MidStr(path,file,0,tmpptr)
-
- UnLock(tmplock)
-
- ELSE -> file doesn't exist
-
- pos := FilePart(file)
- IF pos = file -> only the file
- GetCurrentDirName(path,78)
- StrCopy(name,file,ALL)
- ELSE
- MidStr(path,file,0,pos-file)
- MidStr(name,file,pos-file,ALL)
- IF tmplock := Lock(path,SHARED_LOCK) -> from ram: to Ram Disk:
- NameFromLock(tmplock,path,78)
- UnLock(tmplock)
- ENDIF
- ENDIF
- ENDIF
-
- ENDPROC
-
- PROC checkdest()
- DEF tmplock
-
- -> we check if destination is valid
- IF tmplock := Lock(destination,SHARED_LOCK)
- UnLock(tmplock)
- validdest := TRUE
- ELSE
- validdest := FALSE
- StrCopy(destination,'<Invalid>',ALL)
- ENDIF
-
- ENDPROC
-
- PROC validname()
- DEF tmplock,tmpname,strlen,valid
-
- -> we check if a filename with this name exists in destination
-
- strlen := EstrLen(destination)+EstrLen(basename)+1 -> extra 1 char for /:
-
- tmpname := String(strlen)
- StrCopy(tmpname,destination,ALL)
- AddPart(tmpname,basename,108)
-
- IF tmplock := Lock(tmpname,SHARED_LOCK)
- UnLock(tmplock)
- valid := FALSE
- ELSE
- valid := TRUE
- ENDIF
-
- DisposeLink(tmpname)
-
- ENDPROC valid
-
- PROC getdefaultfont()
- DEF gfx:PTR TO gfxbase,node:PTR TO node
-
- -> we look for the default font
- gfx := gfxbase -> we get a pointer to the gfxbase structure
- p_tf := gfx.defaultfont -> in gfxbase we get a pointer to a textfont struct
- node := p_tf.message.node -> and another pointer to get the fontname
- p_ta := [node.name,p_tf.ysize,p_tf.style,p_tf.flags]:textattr
-
- ENDPROC
-
- PROC getintuilen(str:PTR TO CHAR)
- DEF len,intui:PTR TO intuitext
-
- len := 0
- IF p_ta
- intui := [1,0,RP_JAM1,0,0,p_ta,str,NIL]:intuitext
- len := IntuiTextLength(intui)
- ENDIF
-
- ENDPROC len
-
- PROC opengui()
- DEF displayid,p_vp:PTR TO viewport,p_disinfo:displayinfo,p_diminfo:dimensioninfo
- DEF p_drawinfo:PTR TO drawinfo, -> to get the Wb pen array
- pens=NIL:PTR TO INT -> to store the pen array
- DEF wbscr:PTR TO screen,islace,y
-
- -> we get the Visage screen to see which monitor it use
- scr := findscreen('Visage')
- IF scr = NIL THEN Raise(NOSCREEN)
- p_vp := scr.viewport
-
- -> if the modeid is not specified as argument we get the visage screen one
- IF modeid
- displayid := modeid
- ELSE
- displayid := GetVPModeID(p_vp)
- IF displayid = INVALID_ID THEN displayid := 0
- displayid := BestModeIDA([BIDTAG_VIEWPORT,p_vp,
- BIDTAG_NOMINALWIDTH,640,
- TAG_END])
- displayid := displayid OR $8000 -> at least HIRES
- ENDIF
-
- -> get infos about the desired screen (if not found, set default)
- islace := 0
- IF topscreen = FALSE
- IF GetDisplayInfoData(NIL,p_disinfo,SIZEOF displayinfo,DTAG_DISP,displayid)
- islace := p_disinfo.propertyflags AND DIPF_IS_LACE
- IF GetDisplayInfoData(NIL,p_diminfo,SIZEOF dimensioninfo,DTAG_DIMS,displayid)
- y := p_diminfo.nominal.maxy
- ELSE
- islace := FALSE
- y := 256
- ENDIF
- ELSE
- islace := FALSE
- y := 256
- ENDIF
- IF islace -> 1: INTERLACE
- topscreen := y - miniwinsize(2,1,LACE)
- ELSE
- topscreen := y - miniwinsize(2,1)
- ENDIF
- ENDIF
-
- wbscr := LockPubScreen('Workbench')
- IF wbscr
- p_drawinfo := GetScreenDrawInfo(wbscr)
- pens := NewR(p_drawinfo.numpens)
- pens := p_drawinfo.pens
- FreeScreenDrawInfo(wbscr,p_drawinfo)
- UnlockPubScreen(NIL,wbscr)
- ELSE
- pens:=[0,1,1,2,1,3,1,0,2,1,2,1]:INT
- ENDIF
-
- scr := OpenScreenTagList(NIL,[SA_DISPLAYID,displayid, -> same monitor
- SA_DEPTH,4, -> # of bitplanes
- SA_PENS,pens,
-
- SA_TOP,topscreen, -> open here
-
- SA_TYPE,PUBLICSCREEN,
- SA_PUBNAME,'VisageCom',
- SA_DRAGGABLE,FALSE,
- SA_AUTOSCROLL,FALSE,
- SA_BEHIND,TRUE,
- SA_QUIET,TRUE,
- TAG_DONE]) -> end of tag list
-
- visual := GetVisualInfoA(scr,NIL) -> initialises some gadtools structures
-
- p_gad := CreateContext({glist}) -> creates the shadow gadget used as
- -> the first gadget of the window
-
- -> the same thing is done 6 times (each gadget) so it would be too long
- -> and unreadable here. That's why I used a PROC routine.
- p_gad:=preparegadget(p_gad,['_Copy','_Delete','_Move','_Rename',
- 'C_omment','_Set Dir','C_ancel']:button)
-
- win := OpenWindowTagList(NIL,[WA_PUBSCREEN,scr, -> screen to open on
- WA_CLOSEGADGET,TRUE,
- WA_GADGETS,glist, -> gadget list prepared
- WA_ACTIVATE, TRUE,
- -> I want to be warned by the great Amiga IDCMP system when those
- -> events occured: key/mousebutton pressed or window is inactivated or
- -> a gadget has been used...
- WA_IDCMP, IDCMP_VANILLAKEY OR
- -> IDCMP_MOUSEBUTTONS OR
- IDCMP_CLOSEWINDOW OR
- -> IDCMP_INACTIVEWINDOW OR
- -> IDCMP_INTUITICKS OR
- IDCMP_GADGETUP,
- WA_TITLE, wintitle,
- TAG_DONE])
-
- Gt_RefreshWindow(win,NIL) -> needed by gadtools after window is opened
-
- IF validdest = FALSE THEN disablegad(win,[1,3])
-
- setwindow() -> sets the window title and writes the comment
-
- ScreenToFront(scr) -> the screen is ready to be introduced to you
-
- p_gad := getgadget(win,7)
- setmouse(scr,p_gad.leftedge,p_gad.topedge) -> mouse goes to last gadget
-
- ENDPROC
-
- PROC setwindow()
- DEF oldrast,p_gad:PTR TO gadget
-
- StrCopy(wintitle,'Image: ',ALL)
- StrAdd(wintitle,basename,ALL)
- StrAdd(wintitle,' Dest.: ',ALL)
- StrAdd(wintitle,destination,ALL)
- SetWindowTitles(win,wintitle,-1) -> updates the window title
-
- IF fib
-
- oldrast := SetStdRast(win.rport)
- SetAPen(win.rport,1)
-
- -> Write the comment (if set)
- IF StrLen(fib.comment)
- StrCopy(tmpstr,fib.comment,ALL)
- ELSE
- StrCopy(tmpstr,'<No comment set>',ALL)
- ENDIF
-
- p_gad := getgadget(win,1) -> get gadget 1 (where we'll write text)
-
- -> if comment is shorter than previous, it must erase the previous
- fillstring(tmpstr,80)
- stripstr(tmpstr,p_gad.leftedge)
- TextF(p_gad.leftedge,getrow(1,[0,0,1]),'\s',tmpstr)
-
- StringF(tmpstr,'\d',fib.size)
- numformat(tmpstr)
- StrAdd(tmpstr,' bytes.',ALL)
- TextF(p_gad.leftedge,getrow(2,[0,0,1]),'\s',tmpstr)
-
- SetStdRast(oldrast)
- ENDIF
-
- ENDPROC
-
- PROC mainloop()
- DEF int:PTR TO intuitionbase,screen:PTR TO screen
-
- -> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- -> Please pay attention that if you use gadtools features you have to
- -> use gadtools version of message managing: GT_GetIMsg and GT_ReplyIMsg
- -> instead of the intuition equivalent (GetMsg and ReplyMsg) included in
- -> in the E procedure WaitIMessage (have a look at this one in the E doc)
- -> used here (I know I'm a bad boy ! )
-
- WHILE getout = 0
-
- idcmp := WaitIMessage(win) -> we wait one of the wanted IDCMP
-
- SELECT idcmp
-
- CASE IDCMP_CLOSEWINDOW
- getout := -2
-
- CASE IDCMP_INTUITICKS
- -> 10 times a second, I'll receive this IDCMP
- int := intuitionbase
- screen := int.firstscreen.nextscreen -> must be the Visage screen
- IF StrCmp(screen.title,'Visage') = FALSE THEN getout := -2
-
- CASE IDCMP_GADGETUP -> a gadget has been pressed/released
- p_gad := MsgIaddr() -> which one ?
- getout := p_gad.gadgetid -> 'getout' is set with the gadget id
-
- CASE IDCMP_MOUSEBUTTONS -> button pressed
- -> left mouse button pressed outside the window
- IF (MsgCode() = SELECTUP) AND (scr.mousey < 0) THEN getout := -2
-
- CASE IDCMP_INACTIVEWINDOW
- ActivateWindow(win) -> makes the window be the active one again
-
- CASE IDCMP_VANILLAKEY -> a key pressed
- useranswer := MsgCode() -> which one ?
- SELECT useranswer
- CASE "c" -> Copy
- getout:=1
- CASE "d" -> Delete
- getout:=2
- CASE "m" -> Move
- getout:=3
- CASE "r" -> Rename
- getout:=4
- CASE "o" -> Comment
- getout:=5
- CASE "s" -> Set dir
- getout:=6
- CASE "a" -> Cancel
- getout:=-2
- CASE "q" -> Cancel
- getout:=-2
- CASE "0" -> Cancel
- getout:=-2
- CASE 27 -> ESC
- getout:=-2
- CASE 32 -> SPACE => Cancel and continue
- getout:=-1
- ENDSELECT
-
- ENDSELECT
-
- -> Action !!!
- SELECT getout
-
- -> all delete actions are made later, see below for explanation
-
- CASE 1 -> copy
- docopy()
- getout := 0
- CASE 2 -> delete
- getout := 1
- CASE 3
- IF domove() -> move done with no error
- getout := 1
- ELSE
- getout := 0
- ENDIF
- CASE 4
- dorename() -> rename
- setwindow()
- getout := 0
- CASE 5
- docomment()
- getfilefib(filename)
- setwindow()
- getout := 0
- CASE 6
- setdir() -> we change destination
- setwindow()
- getout := 0 -> we continue
- ENDSELECT
-
- ENDWHILE
-
- ENDPROC
-
- PROC preparegadget(gad:PTR TO gadget,buttonlist:PTR TO button)
- DEF saveptr,id,len,text[100]:STRING
- DEF intuilen,leftedge,topedge,underscorelen,totalsize=0
- DEF posarray:PTR TO LONG,sizearray:PTR TO LONG
-
- -> fasten your seat belt and here we go
- -> I hope this is the good way to do it
-
- len := ListLen(buttonlist) -> how much gadget we have to create
-
- saveptr := buttonlist
-
- -> I use the RtSpread function which says where each gadget must be placed
-
- underscorelen := getintuilen('_')
-
- -> RtSpread gives the position of each gadget
- sizearray := [0,0,0,0,0,0,0]:LONG
-
- FOR id := 0 TO len-1 -> BAD: FOR ind := 1 TO ListLen(buttonlist)
- StrCopy(text,^buttonlist,ALL)
- buttonlist++ -> we get the next one
- intuilen := getintuilen(text) - underscorelen + 10
- PutLong(4*id + sizearray,intuilen) -> puts intuilen in sizearray
- totalsize := totalsize + intuilen
- ENDFOR
-
- posarray := [0,0,0,0,0,0,0]:LONG
- RtSpread(posarray,sizearray,totalsize,20,scr.width-30,7)
- -> extra pixels at beginning ^ and end ^
-
- topedge := getrow(3,[0,0,1]) -> line for gadgets
-
- buttonlist := saveptr
- FOR id := 1 TO len -> BAD: FOR ind := 1 TO ListLen(buttonlist)
- StrCopy(text,^buttonlist,ALL) -> we get the text of the current object
- buttonlist++ -> we get the next one for next run
-
- leftedge := ^posarray
- posarray++
-
- -> length of current gadget text
- intuilen := getintuilen(text)
-
- IF ((id = 1) OR (id = 3)) AND (validdest = FALSE) -> Copy/Move disabled
- gad := CreateGadgetA(
- BUTTON_KIND,gad, -> type,previous gadget
- [leftedge,topedge,
- intuilen+10,(p_tf.ysize*2), -> leftedge,topedge,width,height
- text,p_ta, -> gadgettext,font
- id,PLACETEXT_IN, -> ID,position
- visual,0]:newgadget, -> visual,userdata
- [GT_UNDERSCORE,"_",
- GFLG_DISABLED,TRUE,TAG_END]) -> additional taglist
- ELSE
- gad := CreateGadgetA(
- BUTTON_KIND,gad, -> type,previous gadget
- [leftedge,topedge,
- intuilen+10,(p_tf.ysize*2), -> leftedge,topedge,width,height
- text,p_ta, -> gadgettext,font
- id,PLACETEXT_IN, -> ID,position
- visual,0]:newgadget, -> visual,userdata
- [GT_UNDERSCORE,"_",TAG_END]) -> additional taglist
- ENDIF
- ENDFOR
-
- ENDPROC gad
-
- -> enables gadgets of a specific window
- PROC enablegad(p_win:PTR TO window,idlist:PTR TO LONG)
- DEF len,i,gadid,p_gad:PTR TO gadget
-
- -> instead of saving the gadget address of the 2 gadgets I wanted to
- -> enable/disable, I wrote this PROC which allows you to enable the
- -> first and the third gadget of a specific window calling:
- -> enablegad(win,[1,3])
-
- len := ListLen(idlist)
- p_gad := p_win.firstgadget -> we get the address of the first gadget
-
- FOR i := 1 TO len -> for each number of gadget, we look for it
- gadid := ^idlist; idlist++ -> in the gadget list
- WHILE p_gad.gadgetid <> gadid -> of the window
- p_gad := p_gad.nextgadget -> and we enable the one
- ENDWHILE -> we want: the first one and the
- OnGadget(p_gad,p_win,NIL) -> third one here.
- ENDFOR
-
- ENDPROC
-
- PROC disablegad(p_win:PTR TO window,idlist:PTR TO LONG)
- DEF len,i,gadid,p_gad:PTR TO gadget
-
- len := ListLen(idlist)
- p_gad := p_win.firstgadget
-
- FOR i := 1 TO len
- gadid := ^idlist; idlist++
- WHILE p_gad.gadgetid <> gadid
- p_gad := p_gad.nextgadget
- ENDWHILE
- OffGadget(p_gad,p_win,NIL)
- ENDFOR
-
- ENDPROC
-
- -> look for a specified gadget (id) in a window
- PROC getgadget(p_win:PTR TO window,id)
- DEF p_gad:PTR TO gadget
-
- p_gad := p_win.firstgadget
-
- WHILE p_gad <> NIL
- IF p_gad.gadgetid = id
- RETURN p_gad
- ELSE
- p_gad := p_gad.nextgadget
- ENDIF
- ENDWHILE
-
- ENDPROC p_gad
-
- PROC docopy()
-
- IF validname() = FALSE
- DisplayBeep(scr)
- IF getnewname(destination,basename) = FALSE THEN RETURN FALSE
- ELSE
- StrCopy(tmpstr,destination,ALL)
- AddPart(tmpstr,basename,108)
- ENDIF
-
- ENDPROC copyfile(filename,tmpstr)
-
- PROC domove()
-
- IF validname() = FALSE
- DisplayBeep(scr)
- IF getnewname(destination,basename) = FALSE THEN RETURN FALSE
- ELSE
- StrCopy(tmpstr,destination,ALL)
- AddPart(tmpstr,basename,108)
- ENDIF
-
- ENDPROC movefile(filename,tmpstr)
-
- PROC getdiskinfos(dir:PTR TO CHAR)
- DEF tmplock,p_info:PTR TO infodata,freespace,diskstate
-
- freespace := 0; diskstate := 0
- IF (tmplock := Lock(dir,SHARED_LOCK))
- p_info := NewR(SIZEOF infodata)
- IF Info(tmplock,p_info)
- diskstate := p_info.diskstate
- freespace := p_info.numblocks-p_info.numblocksused*p_info.bytesperblock
- ENDIF
- Dispose(p_info)
- UnLock(tmplock)
- ENDIF
-
- ENDPROC diskstate,freespace
-
- PROC writeabledisk(dest:PTR TO CHAR)
- DEF destdir[78]:STRING,destfile[30]:STRING,diskstate,freespace
-
- extractfilenames(dest,destdir,destfile)
-
- diskstate,freespace := getdiskinfos(destdir)
- IF diskstate = ID_WRITE_PROTECTED THEN Raise(1)
- IF StrCmp(destdir,'Ram Disk:',ALL) THEN freespace := AvailMem(MEMF_TOTAL)
-
- ENDPROC freespace
-
- PROC copyfile(src:PTR TO CHAR,dest:PTR TO CHAR) HANDLE
- DEF filelen,filehandler=NIL,mem=NIL,freespace
-
- freespace := writeabledisk(dest)
-
- IF (filehandler := Open(src,OLDFILE)) = NIL THEN Raise(NOFILE1)
-
- filelen := FileLength(src)
- IF freespace < filelen THEN Raise(2)
-
- mem := NewR(filelen) -> we allocate memory to store the file
- Read(filehandler,mem,filelen) -> we store the file in memory
- Close(filehandler) -> close the file
-
- IF (filehandler := Open(dest,NEWFILE)) = NIL THEN Raise(NOFILE2)
- IF Write(filehandler,mem,filelen) = -1 -> error (e.g. no free space)
- Close(filehandler)
- DeleteFile(dest)
- Raise(3)
- ELSE
- Close(filehandler)
- -> copy date and filecomment found in 'fib'
- IF fib
- SetFileDate(dest,fib.datestamp)
- SetComment(dest,fib.comment)
- SetProtection(dest,fib.protection)
- ENDIF
- ENDIF
-
- RETURN TRUE
-
- EXCEPT
- IF filehandler THEN Close(filehandler)
- SELECT exception
- CASE 1
- dowarn('Disk is write protected')
- CASE 2
- dowarn('Not enough space on disk')
- CASE 3
- dowarn('An error has occured (disk full ?)')
- ENDSELECT
-
- RETURN FALSE
-
- ENDPROC
-
- PROC movefile(src:PTR TO CHAR,dst:PTR TO CHAR)
- DEF path1[78]:STRING,path2[78]:STRING,name[30]:STRING
-
- extractfilenames(src,path1,name)
- extractfilenames(dst,path2,name)
- IF samedevice(path1,path2)
- IF Rename(src,dst) = FALSE
- DeleteFile(dst) -> if newname already exists
- Rename(src,dst)
- ENDIF
- ELSE
- IF copyfile(src,dst) = NIL THEN RETURN FALSE
- -> delete of 'filename' is done exiting Visage
- ENDIF
-
- RETURN TRUE
-
- ENDPROC
-
- PROC dorename()
- DEF wintitle[130]:STRING,path[78]:STRING,name[30]:STRING
-
- StrCopy(wintitle,'Enter new name for ',ALL)
- StrAdd(wintitle,basename,ALL)
-
- -> if user closed the requester with return/OK then rename file
- IF getnewname(pathname,basename) = 1
-
- -> extracts the path and name
- extractfilenames(tmpstr,path,name)
- IF samedevice(path,pathname)
- IF Rename(filename,tmpstr) = FALSE
- DeleteFile(tmpstr) -> if newname already exists
- Rename(filename,tmpstr)
- ENDIF
- ELSE
- IF copyfile(filename,tmpstr) = NIL THEN RETURN FALSE
- DeleteFile(filename)
- ENDIF
- StrCopy(filename,tmpstr,ALL)
- extractfilenames(filename,pathname,basename)
-
- ENDIF
-
- RETURN TRUE
-
- ENDPROC
-
- PROC samedevice(path1:PTR TO CHAR,path2:PTR TO CHAR)
- DEF same=FALSE,lock1,lock2
-
- IF (lock1 := Lock(path1,SHARED_LOCK)) = NIL THEN RETURN FALSE
- IF (lock2 := Lock(path2,SHARED_LOCK)) = NIL THEN RETURN FALSE
-
- same := SameDevice(lock1,lock2)
-
- UnLock(lock1)
- UnLock(lock2)
-
- ENDPROC same
-
- -> opens a file requester to ask the user a filename
- -> useranswer: TRUE if user OKs the requester else FALSE
- -> tmpstr: set to full filename if TRUE
- PROC getnewname(path:PTR TO CHAR,file:PTR TO CHAR)
- DEF req:PTR TO rtfilerequester,answer[108]:ARRAY
-
- req := RtAllocRequestA(RT_FILEREQ,NIL)
-
- ScreenPosition(scr,SPOS_ABSOLUTE OR SPOS_FORCEDRAG,0,0,0,0)
-
- IF path THEN RtChangeReqAttrA(req,[RTFI_DIR,path,TAG_DONE])
-
- StrCopy(answer,file,ALL)
- useranswer := RtFileRequestA(req,
- answer,'Choose a new name',
- [RT_SCREEN,scr, -> screen,
- RT_REQPOS,REQPOS_CENTERSCR,
- RTFI_FLAGS,FREQF_SAVE,
- TAG_DONE])
- IF useranswer
- StrCopy(tmpstr,req.dir,ALL) -> if we change directory too
- AddPart(tmpstr,answer,108)
- ENDIF
-
- RtFreeRequest(req)
-
- ScreenPosition(scr,SPOS_ABSOLUTE OR SPOS_FORCEDRAG,0,topscreen,0,0)
-
- ENDPROC useranswer
-
- PROC docomment()
- DEF oldcomment[108]:STRING,wintitle[130]:STRING
-
- StrCopy(wintitle,'Enter comment for ',ALL)
- StrAdd(wintitle,basename,ALL)
-
- IF fib THEN StrCopy(oldcomment,fib.comment,ALL)
-
- -> if user closed the requester with return/OK then save comment
- StrCopy(tmpstr,oldcomment,ALL)
- IF askstring(wintitle,TRUE)
- SetComment(filename,tmpstr)
- getfilefib(filename)
- ENDIF
-
- ENDPROC -> used to know if setcomment has been done
-
- PROC setdir()
- DEF req:PTR TO rtfilerequester,answer[108]:ARRAY
-
- req := RtAllocRequestA(RT_FILEREQ,NIL)
-
- ScreenPosition(scr,SPOS_ABSOLUTE OR SPOS_FORCEDRAG,0,0,0,0)
-
- IF validdest THEN RtChangeReqAttrA(req,[RTFI_DIR,destination,TAG_DONE])
- useranswer := RtFileRequestA(req,
- answer,'Choose a new destination',
- [RT_SCREEN,scr,
- RT_REQPOS,REQPOS_CENTERSCR,
- RTFI_FLAGS,FREQF_NOFILES,
- TAG_DONE])
- IF useranswer
- validdest := TRUE
- StrCopy(destination,req.dir,ALL)
- enablegad(win,[1,3])
- ENDIF
-
- RtFreeRequest(req)
-
- ScreenPosition(scr,SPOS_ABSOLUTE OR SPOS_FORCEDRAG,0,topscreen,0,0)
-
- ENDPROC
-
- PROC setmouse(scr:PTR TO screen,x,y)
- -> based upon SetMouse from Ketil Hunn
-
- DEF p_iostdreq:PTR TO iostdreq,mp:PTR TO msgport,p_ievent:PTR TO inputevent
- DEF ppix:PTR TO iepointerpixel
-
- IF (mp := CreateMsgPort())
- IF (p_ievent := AllocVec(SIZEOF inputevent, MEMF_PUBLIC))
- IF (ppix := AllocVec(SIZEOF iepointerpixel, MEMF_PUBLIC))
- IF p_iostdreq := CreateIORequest(mp,SIZEOF iostdreq)
- IF Not (OpenDevice('input.device', NIL, p_iostdreq, NIL))
- ppix.screen := scr
- ppix.positionx := x
- ppix.positiony := y
-
- p_ievent.nextevent := NIL
- p_ievent.class := IECLASS_NEWPOINTERPOS
- p_ievent.subclass := IESUBCLASS_PIXEL
- p_ievent.code := 0
- p_ievent.qualifier := NIL
- p_ievent.eventaddress := ppix
-
- p_iostdreq.data := p_ievent
- p_iostdreq.length := SIZEOF inputevent
- p_iostdreq.command := IND_WRITEEVENT
- DoIO(p_iostdreq)
-
- CloseDevice(p_iostdreq)
- ENDIF
- DeleteIORequest(p_iostdreq)
- ENDIF
- FreeVec(ppix)
- ENDIF
- FreeVec(p_ievent)
- ENDIF
- DeleteMsgPort(mp)
- ENDIF
-
- ENDPROC
-
- PROC findscreen(name:PTR TO CHAR)
- DEF screen:PTR TO screen,int=NIL:PTR TO intuitionbase,found=FALSE
- DEF p_mp:PTR TO msgport
-
- int := intuitionbase
- screen := int.firstscreen
-
- WHILE (found = FALSE) AND (screen <> NIL)
- IF StrCmp(screen.title,name,ALL)
- found := TRUE
- ELSE
- screen := screen.nextscreen
- ENDIF
- ENDWHILE
-
- IF found = FALSE
- screen := NIL
- visagetask := NIL
- ELSE
- -> task associated with the window on the visage screen used to
- -> signal Visage to continue
- p_mp := screen.firstwindow.userport
- visagetask := p_mp.sigtask
- ENDIF
-
- ENDPROC screen
-
- PROC dowarn(message:PTR TO CHAR)
- DEF req,answer
-
- IF reqtoolsbase
- req := RtAllocRequestA(RT_REQINFO,NIL)
- answer := RtEZRequestA(message,
- 'Ok',
- NIL,
- req,
- [RT_WINDOW,win,
- RT_IDCMPFLAGS,IDCMP_INACTIVEWINDOW,
- TAG_DONE])
- RtFreeRequest(req)
- ELSE
- EasyRequestArgs(NIL, -> window
- [SIZEOF easystruct,0,'Error...',message,'OK'],
- [IDCMP_INACTIVEWINDOW OR
- IDCMP_RAWKEY],NIL)
- ENDIF
-
- ENDPROC
-
- -> ask a string to the user via a reqtools requester.
- -> tmpstr: string used in input/output
- PROC askstring(wintitle:PTR TO CHAR,allowempty=FALSE)
- DEF req,answer
-
- req := RtAllocRequestA(RT_REQINFO,NIL) -> allocate what is needed (!)
- answer := RtGetStringA(tmpstr,79,wintitle,req,
- [RT_WINDOW,win,
- RT_IDCMPFLAGS,IDCMP_INACTIVEWINDOW,
- RTGS_WIDTH,win.width,
- RTGS_ALLOWEMPTY,allowempty,
- RT_TOPOFFSET,0,
- TAG_DONE]) -> taglists should end like this
- RtFreeRequest(req) -> free what was allocated
-
- -> if window is unactivated requester is canceled
- IF answer = IDCMP_INACTIVEWINDOW THEN answer := 0
-
- ENDPROC answer
-
- -> fills a string with spaces until len is reached
- PROC fillstring(str:PTR TO CHAR,len)
- DEF ind
-
- ind := StrLen(str)
-
- WHILE ind <= len
- str[ind] := " "
- INC ind
- ENDWHILE
- str[ind] := "\0"
-
- ENDPROC
-
- -> says the minimum height of a window according to the default font
- PROC miniwinsize(txtlines,gadlines,islace=1)
- ENDPROC 11+2+ (((p_tf.ysize+5*txtlines)+(p_tf.ysize+5*gadlines)) * islace)
- -> bordertop, borderbottom,,,at bottom
-
- -> returns the X position to be used to display a text/gadget
- PROC getrow(row,rowlst:PTR TO LONG)
- DEF rowlen,ind,rowtype,y
-
- DEC row
- ind := 0
- y := scr.wbortop + p_tf.ysize + 1
- rowlen := ListLen(rowlst) - 1
-
- WHILE ind < row
- rowtype := rowlst[ind]
- IF rowtype = 0 -> text
- y := y + p_tf.ysize + 3
- ELSE -> gadget
- y := y + p_tf.ysize + 10
- ENDIF
- INC ind
- ENDWHILE
- rowtype := rowlst[ind]
- IF rowtype = 0 -> text
- y := y + p_tf.ysize + 3
- ELSE
- y := y + 5
- ENDIF
-
- ENDPROC y
-
- -> limite une chaine pour qu'elle entre dans la fenetre
- -> str: chaine à écrire
- -> orig: x d'origine ou sera écrite la chaine
- PROC stripstr(str:PTR TO CHAR,orig)
- DEF len,ok=FALSE,maxx,strlen
-
- maxx := win.width - win.borderright
- strlen := StrLen(str)
-
- REPEAT
-
- len := getintuilen(str)
- IF (orig + len) <= maxx
- ok := TRUE
- ELSE
- DEC strlen
- str[strlen] := "\0"
- ENDIF
-
- UNTIL ok
-
- ENDPROC
-
- -> formate une chaine contenant un numérique (MAX=999 999 999)
- -> 12 345 678
- -> 0123456789
- PROC numformat(p_str:PTR TO CHAR)
- DEF str,len,ind,indtmp,indstr,spaces,tmp,mod
-
- str := p_str
- len := StrLen(str)
-
- IF (len < 4) OR (len > 9) THEN RETURN -> jusqu'à un Giga
-
- mod := Mod(len,3)
- IF mod = 0
- spaces := (len / 3) - 1
- ELSE
- spaces := len / 3
- ENDIF
-
- tmp := String(len+spaces)
- indstr := 0
- indtmp := 0
- ind := len - (3 * spaces) -> position du premier " "
- len := len + spaces - 1 -> longueur de tmp (condition d'arrêt)
-
- WHILE indtmp <= len
-
- IF indtmp = ind
- tmp[indtmp] := " "
- spaces := 0
- ind := ind + 4 -> position de l'espace suivant
- ELSE
- tmp[indtmp] := str[indstr]
- INC indstr
- ENDIF
- INC indtmp
-
- ENDWHILE
- tmp[indtmp] := "\0"
- StrCopy(str,tmp,ALL)
- DisposeLink(tmp)
-
- ENDPROC
-