
		opt !

		incdir include/

		include exec/exec_lib.i
		include exec/memory.i
		include exec/libraries.i
		include intuition/intuition.i
		include intuition/intuition_lib.i
		include dos/dos.i
		include dos/dosextens.i
		include dos/datetime.i
		include dos/dos_lib.i
		include utility/utility_lib.i
		include graphics/graphics_lib.i
		include workbench/startup.i
		include workbench/workbench.i
		include libraries/reqtools.i
		include libraries/gadtools.i
		include libraries/asl.i
		include reqtools_lib.i
		include gadtools_lib.i
		include asl_lib.i
		include icon_lib.i

		include mymacros.i

		include /src/diskorg/diskorg.i

		include /src/diskorg/defs.i


		XDEF    MainCloseWindow
		XDEF    CategoriesClicked
		XDEF    ParentClicked
		XDEF    RootClicked
		XDEF    ExportClicked
		XDEF    EditClicked
		XDEF    FindClicked
		XDEF    SortClicked
		XDEF    MoveClicked
		XDEF    OpenClicked
		XDEF    AboutMenued
		XDEF    OpenMenued
		XDEF    SaveMenued
		XDEF    SaveAsMenued
		XDEF    ExAllMenued
		XDEF    ExFieldsMenued
		XDEF    QuitMenued
		XDEF    AutoScanMenued
		XDEF    ScanMenued
		XDEF    AllDrivesMenued
		XDEF    df0Menued
		XDEF    df1Menued
		XDEF    df2Menued
		XDEF    df3Menued
		XDEF    EditMenued
		XDEF    MoveMenued
		XDEF    FindMenued
		XDEF    DupesMenued
		XDEF    RemoveSelMenued
		XDEF    AddCatMenued
		XDEF    RemCatMenued
		XDEF    RenCatMenued
		XDEF    OrderNameMenued
		XDEF    OrderSizeMenued
		XDEF    SortDiskMenued
		XDEF    OrderDateMenued
		XDEF    MainDiskInserted
		XDEF    MainDiskRemoved
		XDEF    MainGadgetHelp
		XDEF    MainIntuiTicks
		XDEF    EditVanillaKey
		XDEF    CommentClicked
		XDEF    ED_OkClicked
		XDEF    ED_CancelClicked
		XDEF    ED_DelClicked
		XDEF    MainActiveWindow
		XDEF    MainInactiveWindow
		XDEF    MainVanillaKey
		XDEF    MainRawKey
		XDEF    PatSelMenued
		XDEF    NewMenued
		XDEF    RecurseMenued
		XDEF    LastSearchMenued
		XDEF    SearchResCloseWindow
		XDEF    ShowClicked
		XDEF    FI_MoveClicked
		XDEF    FI_ExportClicked
		XDEF    FI_FilesClicked
		XDEF    FI_DelClicked
		XDEF    MoveCloseWindow
		XDEF    ToClicked
		XDEF    FromClicked
		XDEF    ParentFromClicked
		XDEF    RootFromClicked
		XDEF    ParentToClicked
		XDEF    RootToClicked
		XDEF    MoveFromClicked
		XDEF    AllFromClicked
		XDEF    MoveToClicked
		XDEF    AllToClicked
		XDEF    SearchResIntuiTicks
		XDEF    FindVanillaKey
		XDEF    FindOkClicked
		XDEF    FindCancClicked
		XDEF    SearchForClicked
		XDEF    ComClicked
		XDEF    FI_ByDiskClicked
		XDEF    SaveSetMenued
		XDEF    DeviceMenued
		XDEF    Dr0Clicked
		XDEF    Dr1Clicked
		XDEF    Dr2Clicked
		XDEF    Dr3Clicked
		XDEF    Dev_OkClicked
		XDEF    Dev_CancClicked
		XDEF    DeviceVanillaKey
		XDEF    ViewersMenued
		XDEF    V_ListClicked
		XDEF    AddViewClicked
		XDEF    DelViewClicked
		XDEF    OtherViewClicked
		XDEF    ViewOkClicked
		XDEF    ViewCancClicked
		XDEF    VExtClicked
		XDEF    ViewerClicked
		XDEF    AddV_OkClicked
		XDEF    AddV_CancClicked
		XDEF    ViewersVanillaKey
		XDEF    AddViewVanillaKey
		XDEF    ViewersIntuiTicks
		XDEF    OutClicked
		XDEF    GetViewClicked
		XDEF    FiltersCloseWindow
		XDEF    FiltersIntuiTicks
		XDEF    FiltersVanillaKey
		XDEF    FilterClicked
		XDEF    AddFilterClicked
		XDEF    DelFilterClicked
		XDEF    SetFiltersMenued
		XDEF    ExNameClicked
		XDEF    ExDiskClicked
		XDEF    ExPathClicked
		XDEF    ExDateClicked
		XDEF    ExSizeClicked
		XDEF    ExCommentClicked
		XDEF    ExCatClicked
		XDEF    ExOkClicked
		XDEF    ExCancClicked
		XDEF    ExportVanillaKey
		XDEF    SetExportMenued

		XREF    PubScreenName


stat            macro
		lea     \1,a0
		bsr     Status
		endm



		SECTION Main,CODE


		include iconstartup.i

		move.l  4,a6
		openlib int,37,exit
		openlib gfx,37,closeint
		openlib gad,37,closegfx
		openlib dos,37,closegad
		openlib req,37,closedos
		openlib uti,37,closereq
		openlib asl,37,closeuti
		openlib ico,37,closeasl

		bsr     LoadSettings

		bsr     NewMenued
		tst.l   d0
		beq.s   freesets

		bsr     ParseStartupArgs

		jsr     SetupScreen
		tst.l   d0
		beq.s   .ok

		cmp.w   #1,d0
		bne     closescr

		jsr     CloseDownScreen

		clr.l   PubScreenName

		jsr     SetupScreen
		tst.l   d0
		bne     closescr

.ok             move.l  Scr,a0          ; apro la finestra in
		move.w  sc_Height(a0),d0        ; mezzo allo schermo
		move.w  sc_Width(a0),d1
		move.b  sc_WBorTop(a0),d2
		ext.w   d2
		inc.w   d2
		move.b  sc_WBorBottom(a0),d3
		ext.w   d3
		move.l  sc_Font(a0),a1
		add.w   ta_YSize(a1),d2
		move.w  d2,MainZoom+6
		lea     MainWTags,a0
		subq.w  #7,d2
		add.w   d3,d2
		add.w   d2,WT_HEIGHT(a0)
		sub.w   WT_HEIGHT(a0),d0
		lsr.w   #1,d0
		move.w  d0,WT_TOP(a0)
		sub.w   WT_WIDTH(a0),d1
		lsr.w   #1,d1
		move.w  d1,WT_LEFT(a0)

		bsr     DecryptHeader

		move.w  YOffset,d0
		sub.w   #10,d0

		add.w   d0,WT_HEIGHT+EditWTags  ; Sistema l'altezza
		add.w   d0,WT_HEIGHT+AddViewWTags
		add.w   d0,WT_HEIGHT+ViewersWTags
		add.w   d0,WT_HEIGHT+SearchResWTags
		add.w   d0,WT_HEIGHT+MoveWTags
		add.w   d0,WT_HEIGHT+FindWTags
		add.w   d0,WT_HEIGHT+DeviceWTags
		add.w   d0,WT_HEIGHT+FiltersWTags
		add.w   d0,WT_HEIGHT+ExportWTags

		jsr     OpenMainWindow
		tst.l   d0
		bne     closewnd

		lea     MainWTags,a0
		cmp.w   #640,WT_WIDTH(a0)
		bne.s   .re_calc

		cmp.w   #177,WT_HEIGHT(a0)
		beq.s   .dont_calc

.re_calc        bsr     MainNewSize

.dont_calc      move.l  MainWnd,d0
		move.l  d0,req_win

		lea     Asl_tags,a0
		move.l  d0,4(a0)

		move.l  Scr,a1
		move.w  sc_Height(a1),d1
		sub.w   #40,d1
		move.w  d1,asl_height+2-Asl_tags(a0)

		bsr     GetDrivesInfo

;               bsr     ComputeFileFmt

		move.l  int_base,a6
		move.l  Scr,a0
		call    ScreenToFront

		IFND    REGISTERED
		bsr     AboutMenued
		ENDC

		move.l  4,a6
		cladd   a1
		call    FindTask

		move.l  d0,a0
		move.l  pr_WindowPtr(a0),old_WindowPtr
		move.l  #-1,pr_WindowPtr(a0)
		move.l  a0,MyTask

		cmp.w   #39,LIB_VERSION(a6)          ; Kickstart 3.0+ ?
		blt.s   .no30

		move.l  #GTLV_MakeVisible,List_tag2

		move.l  int_base,a6                  ; attivo l'help
		move.l  MainWnd,a0
		move.l  #HC_GADGETHELP,d0
		call    HelpControl

.no30

mainloop        move.l  4,a6            ; ciclo principale
		move.l  MainWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleMainIDCMP
		tst.b   QuitPrg
		beq.s   mainloop

quit            btst    #SAVED,MainFlags
		bne.s   .dont_save

		clr.b   QuitPrg

		move.l  req_base,a6
		lea     not_saved_txt,a1
		lea     yes_no_canc_txt,a2
		cladd   a3
		cladd   a4
		lea     req_tags2,a0
		call    rtEZRequestA
		cmp.w   #1,d0
		blt.s   mainloop
		bgt.s   .dont_save

		bsr     SaveMenued

.dont_save      bsr     StaccaLista

		lea     DataList,a5
		bsr     FreeNodes

		move.l  MyTask,a0
		move.l  old_WindowPtr,pr_WindowPtr(a0)

closewnd        jsr     CloseMainWindow
closescr        jsr     CloseDownScreen
freesets        bsr     FreeSettings
closeico        closelib        ico
closeasl        closelib        asl
closeuti        closelib        uti
closereq        closelib        req
closedos        closelib        dos
closegad        closelib        gad
closegfx        closelib        gfx
closeint        closelib        int
exit            rts



**
**  Esegue la startup
**
**

ParseStartupArgs        pushm.l d0-d4/a0-a4/a6

		tst.l   returnMsg               ; se sono partito dal WB
		beq.s   .clistart               ; faccio un CD nella
		move.l  returnMsg,a1            ; directory di partenza
		move.l  sm_ArgList(a1),a2

		move.l  dos_base,a6

		cmp.l   #1,sm_NumArgs(a1)       ; controllo se ci sono
		ble.s   .no                     ; altri argomenti

		move.l  8(a2),d1
		move.l  #AllPath,d2
		move.l  #200,d3
		call    NameFromLock

		lea     AllPath,a0
		lea     InitialDrawer,a1
		strcopy a0,a1

		move.l  #AllPath,d1
		move.l  12(a2),d2       ; copio il nome del file da caricare
		move.l  #200,d3
		call    AddPart

		move.l  12(a2),a0
		lea     InitialFile,a1
		strcopy a0,a1

		bra.s   .load

.no             move.l  wa_Lock(a2),d1
		call    CurrentDir

		move.l  ico_base,a6

		move.l  wa_Name(a2),a0
		call    GetDiskObject
		tst.l   d0
		beq.s   .quit

		move.l  d0,a2

		move.l  do_ToolTypes(a2),a0
		lea     ScreenToolType,a1
		call    FindToolType
		tst.l   d0
		beq.s   .no_scr

		move.l  d0,a0
		lea     ScreenName,a1
		move.l  a1,PubScreenName
		strcopy a0,a1

.no_scr         move.l  do_ToolTypes(a2),a0
		lea     FileToolType,a1
		call    FindToolType
		tst.l   d0
		beq.s   .free

		move.l  d0,a0
		lea     AllPath,a1
		strcopy a0,a1

.free           move.l  a2,a0
		call    FreeDiskObject

		tst.b   AllPath
		bne.s   .load

		bra.s   .quit

.clistart       move.l  dos_base,a6             ; leggo gli argomenti della
		move.l  #Template,d1            ; linea di comando
		clr.l   -(sp)
		clr.l   -(sp)
		move.l  sp,d2
		cldat   d3
		call    ReadArgs
		move.l  (sp)+,a3
		move.l  (sp)+,a4
		tst.l   d0
		beq.s   .quit

		move.l  a4,d1
		beq.s   .no_scr2

		lea     ScreenName,a1
		move.l  a1,PubScreenName
		strcopy a4,a1

.no_scr2        move.l  a3,d1
		beq.s   .quit

		lea     AllPath,a0
		strcopy a3,a0

.load           bsr     LoadDatabase

.quit           popm.l  d0-d4/a0-a4/a6
		rts


**
**  Quando la finestra principale viene disattivata
**
**

MainInactiveWindow      pushm.l d0-d1/a0-a1/a6
		move.l  int_base,a6
		move.l  MainWnd,a0
		move.l  wd_IDCMPFlags(a0),d0
		and.l   #~(IDCMP_DISKREMOVED!IDCMP_DISKINSERTED),d0
		call    ModifyIDCMP
		popm.l  d0-d1/a0-a1/a6
		rts


**
**  Quando la finestra principale viene attivata
**
**

MainActiveWindow        pushm.l d0-d1/a0-a1/a6
		move.l  int_base,a6
		move.l  MainWnd,a0
		move.l  wd_IDCMPFlags(a0),d0
		or.l    #IDCMP_DISKREMOVED!IDCMP_DISKINSERTED,d0
		call    ModifyIDCMP
		popm.l  d0-d1/a0-a1/a6
		rts



**
**  Quando la finestra principale viene ridimensionata
**
**
		XDEF    MainNewSize
MainNewSize     pushm.l d0-d7/a0-a6

		move.l  int_base,a6             ; rimuove i vecchi gadgets
		move.l  MainWnd,a0
		lea     OpenGadget,a1
		moveq   #-1,d0
		call    RemoveGList

		move.l  gad_base,a6             ; li libera
		move.l  MainGList,a0
		call    FreeGadgets

		lea     MainNGads,a0            ; modifica le dimensioni
		move.l  MainWnd,a1              ; e le posizioni
		moveq   #0,d1
		move.b  wd_BorderRight(a1),d1
		move.w  wd_Width(a1),d0
		sub.w   d1,d0
		move.b  wd_BorderLeft(a1),d1
		addq.w  #6,d1
		sub.w   d1,d0
		move.w  d0,gng_Width(a0)
		lea     gng_SIZEOF(a0),a2
		move.w  d0,gng_Width(a2)
		cldat   d0
		move.b  wd_BorderBottom(a1),d0
		addq.w  #2,d0
		move.w  wd_Height(a1),d1
		sub.w   d0,d1
		sub.w   gng_Height(a0),d1
		sub.w   YOffset,d1
		move.w  d1,gng_TopEdge(a0)
		sub.w   gng_TopEdge(a2),d1
		subq.w  #1,d1
		move.w  d1,gng_Height(a2)

		moveq   #Main_CNT-1,d7  ; ricrea i gadgets
		move.l  #MainGadgets,d5
		move.l  #MainNGads,d2
		move.w  YOffset,d3
		lea     MainGList,a0
		clr.l   (a0)
		lea     MainGTypes,a4
		lea     MainGTags,a3
		XREF    MakeGadgets
		jsr     MakeGadgets
		tst.l   d0
		beq.s   .ok
		st      QuitPrg
		bra.s   .quit

.ok             move.l  gfx_base,a6             ; cancella la finestra
		move.l  MainWnd,a0
		move.l  wd_RPort(a0),a1
		moveq   #0,d0
		move.b  wd_BorderLeft(a0),d0
		inc.w   d0
		move.w  YOffset,d1
		inc.w   d1
		move.w  wd_Width(a0),d2
		sub.b   wd_BorderRight(a0),d2
		dec.w   d2
		move.w  wd_Height(a0),d3
		sub.b   wd_BorderBottom(a0),d3
		dec.w   d3
		call    EraseRect

		move.l  int_base,a6

		move.l  MainWnd,a0              ; riattacca i gadgets
		lea     OpenGadget,a1
		sub.l   a2,a2
		moveq   #-1,d0
		moveq   #-1,d1
		call    AddGList

		lea     OpenGadget,a0           ; rinfresca la finestra
		move.l  MainWnd,a1
		sub.l   a2,a2
		moveq   #-1,d0
		call    RefreshGList

		move.l  gad_base,a6
		move.l  MainWnd,a0
		cladd   a1
		call    GT_RefreshWindow

		move.l  int_base,a6
		move.l  MainWnd,a0
		call    RefreshWindowFrame

		bsr.s   ComputeFileFmt

		lea     DataList,a5             ; crea le nuove labels
		bsr.s   ChangeShow

		bsr     AttaccaLista

		move.l  gad_base,a6
		move.l  CategoriesGadget,a0
		move.l  MainWnd,a1
		cladd   a2
		lea     List_tag2,a3
		call    GT_SetGadgetAttrsA

.quit           popm.l  d0-d7/a0-a6
		rts


**
**  Modifica il File_fmt
**
**

ComputeFileFmt  pushm.l d0-d7/a0-a6

		cldat   d0              ; calcola i nuovi valori
		move.w  MainNGads+gng_SIZEOF+gng_Width,d6
		sub.w   #18,d6          ; del listview
		asr.w   #3,d6           ; d6 = larghezza in
		subq.w  #8,d6           ;      caratteri

		move.w  d6,d0
		divu.w  #8,d0
		mulu.w  #3,d0

		move.w  d0,d1           ; d1 = caratteri per il
		divu.w  #11,d1          ;      nome del file
		mulu.w  #5,d1

		cmp.w   #32,d1
		ble.s   .ok1

		move.w  #32,d1

.ok1            move.w  d0,d2           ; d2 = caratteri per il
		sub.w   d1,d2           ;      nome del disco

		cmp.w   #32,d2
		ble.s   .ok2

		move.w  #32,d2

.ok2            move.l  4,a6
		push.w  d2
		push.w  d2
		push.w  d1
		push.w  d1
		lea     File_new_fmt,a0
		move.l  sp,a1
		lea     putch(pc),a2
		lea     File_fmt,a3
		call    RawDoFmt

		addq.l  #8,sp

		popm.l  d0-d7/a0-a6
		rts


**
**  Cambia le label mostrate nella ListView
**  a5 = Lista
**

ChangeShow      pushm.l d0-d1/a0-a3/a5-a6

.loop           move.l  (a5),a5
		tst.l   (a5)
		beq.s   .quit

		tst.b   LN_TYPE(a5)             ; categoria?
		bne.s   .no

		push.l  a5
		lea     cat_Files(a5),a5
		bsr.s   ChangeShow
		pop.l   a5

		bra.s   .loop

.no             lea     fi_Name(a5),a0
		lea     fi_Disk(a5),a1
		lea     fi_Comment(a5),a2
		movem.l a0-a2,Show_args

		lea     File_fmt,a0
		lea     Show_args,a1
		lea     putch(pc),a2
		lea     fi_Show(a5),a3
		move.l  4,a6
		call    RawDoFmt

		bra.s   .loop

.quit           popm.l  d0-d1/a0-a3/a5-a6
		rts



**
**  Libera la memoria allocata per i vari nodi
**  a5 = Prima lista
**

FreeNodes       pushm.l d0-d1/a0-a1/a6
		move.l  4,a6

.loop           move.l  a5,a0
		REMTAIL

		tst.l   d0
		beq.s   .quit

		move.l  d0,a1

		tst.b   LN_TYPE(a1)     ; è una categoria?
		bne.s   .no

		push.l  a5

		lea     cat_Files(a1),a5        ; devo prima liberare il
		bsr.s   FreeNodes       ; contenuto della categoria...

		pop.l   a5

		move.l  #cat_SIZEOF,d0
		bra.s   .free

.no             move.l  #fi_SIZEOF,d0   ; libero un file info
.free           call    FreeMem

		bra.s   .loop

.quit           popm.l  d0-d1/a0-a1/a6
		rts


**
**  Cambia la scritta nella status line
**  a0 = ^testo
**

Status          pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		lea     Text_tag,a3
		move.l  a0,4(a3)
		move.l  StatusGadget,a0
		move.l  MainWnd,a1
		cladd   a2
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts


**
**  Controlla quali drive sono presenti
**
**

GetDrivesInfo   pushm.l d0-d7/a0-a6

		moveq   #-1,d6

		move.l  dos_base,a6

		move.l  #LDF_DEVICES!LDF_READ,d1        ; blocco la lista
		call    LockDosList
		move.l  d0,d7

		move.l  d7,d1           ; c'è il df1 ?
		move.l  #df1_txt,d2
		move.l  #LDF_DEVICES,d3
		call    FindDosEntry
		tst.l   d0
		beq.s   .no

		inc.w   d6

		move.l  d7,d1           ; c'è il df2 ?
		move.l  #df2_txt,d2
		move.l  #LDF_DEVICES,d3
		call    FindDosEntry
		tst.l   d0
		beq.s   .no

		inc.w   d6

		move.l  d7,d1           ; c'è il df3 ?
		move.l  #df3_txt,d2
		move.l  #LDF_DEVICES,d3
		call    FindDosEntry
		tst.l   d0
		beq.s   .no

		inc.w   d6

.no             move.l  #LDF_DEVICES!LDF_READ,d1        ; sblocco la lista
		call    UnLockDosList

		tst.w   d6
		bmi.s   .quit

		move.w  d6,NumDrives
		inc.w   NumDrives

		move.l  int_base,a6             ; attivo i menu giusti
		lea     drive_menus,a3

.loop           move.l  MainWnd,a0
		move.l  (a3)+,d0
		call    OnMenu
		dbra    d6,.loop

.quit           popm.l  d0-d7/a0-a6
		rts


**
**  Fanno uscire dal prg
**
**

QuitMenued
MainCloseWindow st      QuitPrg
		rts



**
**  Funzione GadgetHelp
**
**

MainGadgetHelp  pushm.l d0-d7/a0-a6
		move.l  im_IAddress(a5),d0
		beq     .quit

		cmp.l   MainWnd,d0
		beq     .quit

		move.l  d0,a4
		move.w  gg_GadgetType(a4),d0
		and.w   #$F0,d0

		cmp.w   #GTYP_SIZING,d0
		bne.s   .no_size

		stat    Size_hlp
		bra     .quit

.no_size        cmp.w   #GTYP_WDRAGGING,d0
		bne.s   .no_drag

		stat    Drag_hlp
		bra     .quit

.no_drag        cmp.w   #GTYP_WUPFRONT,d0
		bne.s   .no_depth

		stat    Depth_hlp
		bra     .quit

.no_depth       cmp.w   #GTYP_WDOWNBACK,d0
		bne.s   .no_zip

		stat    Zoom_hlp
		bra     .quit

.no_zip         cmp.w   #GTYP_CLOSE,d0
		bne.s   .no_close

		stat    Quit_hlp
		bra     .quit

.no_close       tst.w   d0
		bne     .quit

		lea     Gadgets_tab,a0
		lea     Help_tab-4,a1
		moveq   #GADS_TAB_LEN-1,d0

.loop           move.w  (a0)+,d1
		addq.l  #4,a1
		cmp.w   gg_GadgetID(a4),d1
		dbeq    d0,.loop

		tst.w   d0
		bmi.s   .quit

		move.l  (a1),a0
		bsr     Status

.quit           popm.l  d0-d7/a0-a6
		rts



**
**  Controlla quando i dischi vengono rimossi
**
**

MainDiskRemoved pushm.l d0-d1/d5/a0-a1/a3-a4/a6
		btst    #AUTOSCAN,MainFlags
		beq.s   .quit

		move.l  dos_base,a6

		move.w  NumDrives,d5

		lea     Drives,a4
		lea     df0,a3

.loop           move.l  (a4)+,d1

		tst.b   (a3)+   ; c'era il disco?
		bge.s   .next   ; se no (o se il drive non è
					; selezionato) passa al succ.

		move.l  #ACCESS_READ,d2
		call    Lock    ; c'è il disco _ora_?

		move.l  d0,d1
		beq.s   .no

		call    UnLock

		st      -1(a3)

		bra.s   .next

.no             sf      -1(a3)

.next           dbra    d5,.loop

.quit           popm.l  d0-d1/d5/a0-a1/a3-a4/a6
		rts




**
**  Esamina un disco
**  d7 = Lock
**

ScanDisk        pushm.l d1-d7/a0-a6
		bsr     StaccaLista
		stat    Scanning_txt

		move.l  d7,d1
		call    CurrentDir      ; cd sul disco
		move.l  d0,d6

		lea     fib,a4

		move.l  dos_base,a6

		move.l  d7,d1
		move.l  a4,d2
		call    Examine ; root
		tst.l   d0
		beq.s   .err    ; hmm, dir vuota?

		lea     fib_FileName(a4),a0
		lea     DiskName,a1
		move.l  a1,a3
		strcopy a0,a1

		clr.b   DirName

		bsr     RecursiveScan
		tst.l   d0
		bne.s   .scan_complete

.err            call    IoErr   ; c'è stato un errore?
		cmp.l   #ERROR_NO_MORE_ENTRIES,d0
		beq.s   .scan_complete

		stat    ScanError_txt
.error          beep
		cldat   d0
		bra.s   .quit

.scan_complete  stat    Ready_txt
		moveq   #-1,d0

.quit           move.l  d6,d1
		call    CurrentDir      ; cd dove ero...

		bsr     AttaccaLista
		popm.l  d1-d7/a0-a6
		rts





**
**  Esamina ricorsivamente le directory di un disco
**  d7 = Lock; a3 = DiskName; a4 = Fib
**

RecursiveScan   pushm.l d1-d3/a0-a6

.scanloop       move.l  dos_base,a6
		move.l  d7,d1
		move.l  a4,d2
		call    ExNext
		tst.l   d0
		beq.s   .err

		tst.l   fib_DirEntryType(a4)    ; directory o file?
		bmi.s   .file

		btst    #RECURSE,MainFlags
		beq.s   .scanloop

		move.l  #DirName,d1             ; aggiorno il nome della
		lea     fib_FileName(a4),a0     ; dir attuale
		move.l  a0,d2
		move.l  #300,d3
		call    AddPart

		pushm.l d7/a4

		move.w  #fib_SIZEOF,d3
		lea     -fib_SIZEOF(sp),sp      ; ricavo un nuovo fib
		move.l  sp,d0
		and.l   #3,d0   ; allineato alla long?
		beq.s   .ok
		subq.w  #2,sp
		addq.w  #2,d3

.ok             move.l  sp,a4

		move.l  #DirName,d1
		move.l  #ACCESS_READ,d2
		call    Lock

		move.l  d0,d7
		beq.s   .check_fail

		move.l  d0,d1
		move.l  a4,d2
		call    Examine

		move.l  d7,d1

		bsr.s   RecursiveScan
.check_fail     move.l  d0,d2

		call    UnLock

		add.w   d3,sp

		move.l  #DirName,d1     ; tolgo il nome dell'ultima dir
		call    PathPart        ; letta

		move.l  d0,a0
		clr.b   (a0)

		popm.l  d7/a4

		tst.l   d2
		bne.s   .scanloop

		bra.s   .error

.file           lea     FiltersList,a2  ; lo posso accettare?
.check_loop     move.l  (a2),a2
		tst.l   (a2)
		beq.s   .passed

		move.l  uti_base,a6
		lea     fn_Filter(a2),a5

.conv_loop      move.b  (a5),d0
		beq.s   .up
		call    ToUpper
		move.b  d0,(a5)+
		bra.s   .conv_loop

.up             move.l  dos_base,a6

		lea     fn_Filter(a2),a0
		move.l  a0,d1
		move.l  #FilterBuffer,d2
		moveq   #62,d3
		call    ParsePatternNoCase

		move.l  #FilterBuffer,d1
		lea     fib_FileName(a4),a0
		move.l  a0,d2
		call    MatchPatternNoCase

		tst.l   d0              ; va bene?
		bne.s   .check_loop

		bra.s   .scanloop

.passed         move.l  dos_base,a6

		push.l  a3      ; è un file vecchio?
		lea     fib_FileName(a4),a3
		lea     DataList,a2
		bsr     FindFile
		pop.l   a3

		move.l  d0,d2
		beq.s   .nuovo

		move.l  d2,a5

		move.l  a3,a0   ; stesso disco?
		lea     fi_Disk(a5),a1
		move.l  uti_base,a6
		call    Stricmp
		tst.l   d0
		bne.s   .nuovo

		bra.s   .vecchio        ; aggiorno solo i suoi dati

.nuovo          move.l  4,a6    ; alloco la memoria per il nodo
		move.l  #fi_SIZEOF,d0
		move.l  #MEMF_CLEAR,d1
		call    AllocMem
		tst.l   d0
		bne.s   .mem_ok

		stat    MemIns_txt      ; no memory...
		bra.s   .error

.mem_ok         move.l  d0,a5

		move.l  Uncat,a0        ; aggiungo il nodo alla lista
		move.l  d0,a1   ; degli incatalogati
		ADDTAIL

		lea     fi_Show(a5),a0  ; sistemo le info nel nodo
		move.l  a0,LN_NAME(a5)
		move.b  #DO_FILE,LN_TYPE(a5)
		bset    #FI_EDIT,LN_PRI(a5)

		lea     fib_Comment(a4),a0      ; copio il Commento
		lea     fi_Comment(a5),a1
		strcopy a0,a1

		move.l  a3,a0           ; Disco
		lea     fi_Disk(a5),a1
		strcopy a0,a1

		lea     fib_FileName(a4),a0     ; Nome del file
		lea     fi_Name(a5),a1
		strcopy a0,a1

.vecchio        lea     DirName,a0              ; Directory
		lea     fi_Drawer(a5),a1
		strcopy a0,a1

		move.l  fib_Size(a4),fi_Size(a5)        ; Size

		movem.l fib_DateStamp(a4),a0-a2         ; DateStamp
		movem.l a0-a2,fi_Date(a5)

		move.l  fib_Protection(a4),fi_Protection(a5)

		lea     fi_Name(a5),a0
		lea     fi_Disk(a5),a1
		lea     fi_Comment(a5),a2
		movem.l a0-a2,Show_args

		push.l  a3

		lea     File_fmt,a0
		lea     Show_args,a1
		lea     putch(pc),a2
		lea     fi_Show(a5),a3
		move.l  4,a6
		call    RawDoFmt

		pop.l   a3

		bclr    #SAVED,MainFlags

		bra.s   .scanloop

.err            call    IoErr   ; c'è stato un errore?
		cmp.l   #ERROR_NO_MORE_ENTRIES,d0
		beq.s   .scan_complete

.error          cldat   d0
		bra.s   .quit

.scan_complete  moveq   #-1,d0
.quit           popm.l  d1-d3/a0-a6
		rts


putch           move.b  d0,(a3)+
		rts




**
**  Cerca un file
**  a2 = Lista; a3 = File name
**

FindFile        pushm.l d1/a0-a2/a6

		move.l  uti_base,a6

.loop           move.l  (a2),a2

		moveq   #0,d0

		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		bne.s   .file

		push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   FindFile
		pop.l   a2

		tst.l   d0
		bne.s   .quit

		bra.s   .loop

.file           move.l  a3,a0
		lea     fi_Name(a2),a1
		call    Stricmp
		tst.l   d0
		bne.s   .loop

		move.l  a2,d0

.quit           popm.l  d1/a0-a2/a6
		rts





**
**  Controlla quando i dischi vengono inseriti
**
**

MainDiskInserted        pushm.l d0-d7/a0-a6
		btst    #AUTOSCAN,MainFlags
		beq.s   .quit

		move.l  dos_base,a6

		lea     df0,a4
		move.w  NumDrives,d5
		lea     Drives,a5

.loop           tst.b   (a4)+   ; c'era già il disco?
		bne.s   .next

		move.l  (a5),d1 ; c'è _ora_ il disco?
		move.l  #ACCESS_READ,d2
		call    Lock
		move.l  d0,d7
		beq.s   .next

		bsr     ScanDisk

		move.l  d7,d1
		call    UnLock

		st      -1(a4)

.next           addq.l  #4,a5
		dbra    d5,.loop

.quit           popm.l  d0-d7/a0-a6
		rts





**
**  Mostra la finestra About
**
**

AboutMenued     pushm.l d0-d1/a0-a4/a6
		move.l  req_base,a6
		lea     req_tags,a0
		lea     about_txt,a1
		lea     ok_txt,a2
		cladd   a3
		cladd   a4
		call    rtEZRequestA
		popm.l  d0-d1/a0-a4/a6
		rts


**
**  Stacca la lista generale dal gadget
**
**

StaccaLista     pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  CategoriesGadget,a0
		move.l  MainWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #-1,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts




**
**  Attacca la lista generale dal gadget
**
**

AttaccaLista    pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  CategoriesGadget,a0
		move.l  MainWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  CurrentCat,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts





**
**  Aggiunge una categoria
**
**

AddCatMenued    pushm.l d0-d1/a0-a6

		move.l  4,a6
		move.l  #cat_SIZEOF,d0
		move.l  #MEMF_CLEAR,d1
		call    AllocMem
		tst.l   d0
		bne.s   .ok

		stat    MemIns_txt
		beep
		bra     .quit

.ok             move.l  d0,a5

		lea     cat_Files(a5),a0
		NEWLIST a0

		lea     cat_Name(a5),a0
		move.l  a0,LN_NAME(a5)
		move.b  #DO_CATEGORY,LN_TYPE(a5)

		move.l  #'»»  ',cat_Name(a5)

		move.l  req_base,a6

		lea     cat_Name+4(a5),a1
		moveq   #76,d0
		lea     TitoloCat_txt,a2
		cladd   a3
		lea     req_tags2,a0
		call    rtGetStringA
		tst.l   d0
		bne.s   .go

		move.l  4,a6
		move.l  a5,a1
		move.l  #cat_SIZEOF,d0
		call    FreeMem

		stat    Cancel_txt

		bra.s   .quit

.go             bsr     StaccaLista

		move.l  uti_base,a6

		move.l  CurrentCat,a4
		move.l  a4,cat_Parent(a5)

		move.l  (a4),a0 ; lista vuota?
		tst.l   (a0)
		bne.s   .loop

		move.l  a4,a0
		move.l  a5,a1
		ADDTAIL

		bra.s   .inserted

.loop           move.l  (a4),a4
		tst.l   (a4)
		beq.s   .prima

		cmp.b   #DO_FILE,LN_TYPE(a4)    ; prima dei files
		beq.s   .prima

		move.l  LN_NAME(a5),a0
		move.l  LN_NAME(a4),a1

		call    Stricmp
		tst.l   d0
		beq.s   .dopo
		bgt.s   .loop

.prima          move.l  LN_PRED(a4),a4

.dopo           movem.l (a4),a0
		move.l  a5,(a4)
		move.l  a5,LN_PRED(a0)
		movem.l a0/a4,(a5)

.inserted       bsr     Deselect
		bsr     AttaccaLista

		bclr    #SAVED,MainFlags

.quit           popm.l  d0-d1/a0-a6
		rts




**
**  Inserisce un file in una lista in ordine alfabetico
**  a0 = Lista; a1 = Nodo
**

InsertByName    pushm.l d0-d1/a0-a5/a6
		move.l  uti_base,a6

		move.l  a0,a4
		move.l  a1,a5

.loop           move.l  (a4),a4
		tst.l   (a4)
		beq.s   .prima

		tst.b   LN_TYPE(a4)             ; dopo le categorie
		beq.s   .loop

		lea     fi_Name(a5),a0
		lea     fi_Name(a4),a1

		call    Stricmp
		tst.l   d0
		beq.s   .dopo
		bgt.s   .loop

.prima          move.l  LN_PRED(a4),a4

.dopo           move.l  (a4),a0
		move.l  a5,(a4)
		move.l  a5,LN_PRED(a0)
		movem.l a0/a4,(a5)

.quit           popm.l  d0-d1/a0-a5/a6
		rts




**
**  Inserisce un file in una lista in ordine alfabetico (secondo il disco)
**  a0 = Lista; a1 = Nodo
**

InsertByDisk    pushm.l d0-d1/a0-a5/a6
		move.l  uti_base,a6

		move.l  a0,a4
		move.l  a1,a5

.loop           move.l  (a4),a4
		tst.l   (a4)
		beq.s   .prima

		tst.b   LN_TYPE(a4)             ; dopo le categorie
		beq.s   .loop

		lea     fi_Disk(a5),a0
		lea     fi_Disk(a4),a1

		call    Stricmp
		tst.l   d0
		bge.s   .loop

.prima          move.l  LN_PRED(a4),a4

.dopo           move.l  (a4),a0
		move.l  a5,(a4)
		move.l  a5,LN_PRED(a0)
		movem.l a0/a4,(a5)

.quit           popm.l  d0-d1/a0-a5/a6
		rts



**
**  Inserisce un file in una lista in ordine di dimensioni
**  a0 = Lista; a1 = Nodo
**

InsertBySize    pushm.l d0-d1/a0-a2

.loop           move.l  (a0),a0
		tst.l   (a0)
		beq.s   .prima

		tst.b   LN_TYPE(a0)             ; dopo le categorie
		beq.s   .loop

		move.l  fi_Size(a0),d0

		cmp.l   fi_Size(a1),d0
		bge.s   .loop

.prima          move.l  LN_PRED(a0),a0

.dopo           move.l  (a0),a2
		move.l  a1,(a0)
		move.l  a1,LN_PRED(a2)
		move.l  a2,(a1)+
		move.l  a0,(a1)

.quit           popm.l  d0-d1/a0-a2
		rts




**
**  Inserisce un file in una lista in ordine di data
**  a0 = Lista; a1 = Nodo
**

InsertByDate    pushm.l d0-d1/a0-a3

.loop           move.l  (a0),a0
		tst.l   (a0)
		beq.s   .prima

		tst.b   LN_TYPE(a0)             ; dopo le categorie
		beq.s   .loop

		lea     fi_Date(a0),a2
		lea     fi_Date(a1),a3

		cmp.l   (a2)+,(a3)+
		bgt.s   .loop
		blt.s   .prima
		cmp.l   (a2)+,(a3)+
		bgt.s   .loop
		blt.s   .prima
		cmp.l   (a2)+,(a3)+
		bge.s   .loop

.prima          move.l  LN_PRED(a0),a0

.dopo           move.l  (a0),a2
		move.l  a1,(a0)
		move.l  a1,LN_PRED(a2)
		move.l  a2,(a1)+
		move.l  a0,(a1)

.quit           popm.l  d0-d1/a0-a3
		rts




**
**  Contatore
**
**

MainIntuiTicks
SearchResIntuiTicks
ViewersIntuiTicks
FiltersIntuiTicks
		inc.w   Ticks
		rts




**
**  Collegato alla listview principale
**
**

CategoriesClicked       pushm.l d0-d1/a0-a1
		move.w  Ticks,d1
		clr.w   Ticks

		move.w  im_Code(a5),d0

		move.w  d0,List_tag2+6

		move.l  CurrentCat,a0

.loop           move.l  (a0),a0
		dbra    d0,.loop

		move.l  NodeID,a1
		move.l  a0,NodeID

		tst.b   LN_TYPE(a0)
		bne.s   .file

		bsr     Deselect

		bset    #NO_SELECTED,LN_PRI(a0)

		cmp.l   a0,a1
		bne.s   .quit

		cmp.w   #2,d1
		bgt.s   .quit

		bsr     StaccaLista
		lea     cat_Files(a0),a0
		move.l  a0,CurrentCat
		move.w  #-1,List_tag2+6
		bsr     AttaccaLista

		bra.s   .quit

.file           move.w  im_Qualifier(a5),d0
		and.b   #%11,d0
		bne.s   .no_des

		bsr     Deselect

.no_des         bset    #NO_SELECTED,LN_PRI(a0)
		move.b  #'×',fi_Show(a0)

		pushm.l d1/a0-a1/a6
		move.l  gad_base,a6
		move.l  MainWnd,a0
		cladd   a1
		call    GT_RefreshWindow
		popm.l  d1/a0-a1/a6

		cmp.l   a0,a1
		bne.s   .quit

		cmp.w   #2,d1
		bgt.s   .quit

		bsr     EditFiles

.quit           popm.l  d0-d1/a0-a1
		rts


**
**  Deseleziona tutti i nodi
**
**

Deselect        push.l  a0
		move.l  CurrentCat,a0
.loop           move.l  (a0),a0
		tst.l   (a0)
		beq.s   .quit

		bclr    #NO_SELECTED,LN_PRI(a0)

		tst.b   LN_TYPE(a0)
		beq.s   .loop

		move.b  #' ',fi_Show(a0)
		bra.s   .loop

.quit           pop.l   a0
		rts



**
**  Mostra la categoria precedente
**
**

ParentClicked   push.l  a0
		move.l  CurrentCat,a0
		cmp.l   #DataList,a0
		beq.s   .quit
		move.l  cat_Parent-cat_Files(a0),CurrentCat
		bsr     StaccaLista
		bsr     AttaccaLista
.quit           pop.l   a0
		rts



**
**  Mostra la categoria principale
**
**

RootClicked     move.l  #DataList,CurrentCat
		bsr     StaccaLista
		bra     AttaccaLista




**
**  Elimina i file selezionati
**
**

RemoveSelMenued pushm.l d0-d7/a0-a6
		bsr     StaccaLista

		move.l  4,a6

.loop           move.l  CurrentCat,a1
.search         move.l  (a1),a1
		tst.l   (a1)
		beq.s   .quit

		tst.b   LN_TYPE(a1)
		beq.s   .search

		btst    #NO_SELECTED,LN_PRI(a1)
		beq.s   .search

		move.l  a1,a2
		REMOVE

		move.l  a2,a1
		move.l  #fi_SIZEOF,d0
		call    FreeMem

		bclr    #SAVED,MainFlags

		bra.s   .loop

.quit           bsr     AttaccaLista
		stat    Ready_txt
		popm.l  d0-d7/a0-a6
		rts




**
**  Rimuove la categoria selezionata
**
**

RemCatMenued    pushm.l d0-d1/a0-a1/a5-a6
		move.l  CurrentCat,a1

.loop           move.l  (a1),a1
		tst.l   (a1)
		beq.s   .quit

		tst.b   LN_TYPE(a1)
		bne.s   .loop

		btst    #NO_SELECTED,LN_PRI(a1)
		beq.s   .loop

		lea     cat_Files(a1),a5
		cmp.l   Uncat,a5
		beq.s   .quit

		bsr     StaccaLista

		bsr     FreeNodes

		push.l  a1
		REMOVE
		pop.l   a1

		move.l  4,a6
		move.l  #cat_SIZEOF,d0
		call    FreeMem

		bsr     AttaccaLista

		bclr    #SAVED,MainFlags

		stat    Ready_txt
.quit           popm.l  d0-d1/a0-a1/a5-a6
		rts



**
**  Crea un nuovo database
**
**

NewMenued       pushm.l d1/a0-a4/a6

		btst    #SAVED,MainFlags
		bne.s   .dont_save

		move.l  req_base,a6
		lea     not_saved_txt,a1
		lea     yes_no_canc_txt,a2
		cladd   a3
		cladd   a4
		lea     req_tags2,a0
		call    rtEZRequestA
		cmp.w   #1,d0
		blt.s   .quit
		bgt.s   .dont_save

		bsr     SaveMenued

.dont_save      bsr     StaccaLista

		lea     DataList,a5
		bsr     FreeNodes

		move.l  4,a6
		move.l  #cat_SIZEOF,d0
		move.l  #MEMF_CLEAR,d1
		call    AllocMem
		tst.l   d0
		beq.s   .quit

		move.l  d0,a1
		move.l  d0,a2
		move.l  #Uncataloged_txt,LN_NAME(a1)
		move.b  #DO_CATEGORY,LN_TYPE(a1)
		bset    #NO_UNCAT,LN_PRI(a1)

		lea     DataList,a0
		NEWLIST a0

		lea     DataList,a0
		move.l  a0,CurrentCat
		move.l  a0,cat_Parent(a1)
		ADDTAIL

		lea     cat_Files(a2),a0
		move.l  a0,Uncat
		NEWLIST a0

		bsr     AttaccaLista

		bset    #SAVED,MainFlags

		moveq   #-1,d0
.quit           popm.l  d1/a0-a4/a6
		rts



**
**  Rinomina la categoria selezionata
**
**

RenCatMenued    pushm.l d0-d1/a0-a6

		move.l  CurrentCat,a0
.loop           move.l  (a0),a0
		tst.l   (a0)
		beq.s   .quit

		tst.b   LN_TYPE(a0)
		bne.s   .loop

		btst    #NO_SELECTED,LN_PRI(a0)
		beq.s   .loop

		lea     cat_Files(a0),a1
		cmp.l   Uncat,a1
		beq.s   .quit

		move.l  req_base,a6

		lea     cat_Name+4(a0),a1
		moveq   #76,d0
		lea     TitoloCat_txt,a2
		cladd   a3
		lea     req_tags2,a0
		call    rtGetStringA

		move.l  gad_base,a6
		move.l  MainWnd,a0
		cladd   a1
		call    GT_RefreshWindow

		bclr    #SAVED,MainFlags

.quit           popm.l  d0-d1/a0-a6
		rts



**
**  Seleziona i file in base ad un filtro
**
**

PatSelMenued    pushm.l d0-d7/a0-a6
		move.l  CurrentCat,a0
.search         move.l  (a0),a0
		tst.l   (a0)
		beq.s   .quit

		tst.b   LN_TYPE(a0)
		beq.s   .search

		move.l  req_base,a6
		lea     SelectPattern,a1
		moveq   #30,d0
		lea     EnterPattern_txt,a2
		cladd   a3
		lea     req_tags2,a0
		call    rtGetStringA
		tst.l   d0
		beq.s   .quit

		move.l  uti_base,a6
		lea     SelectPattern,a2

.conv_loop      move.b  (a2),d0
		beq.s   .ok
		call    ToUpper
		move.b  d0,(a2)+
		bra.s   .conv_loop

.ok             move.l  dos_base,a6

		move.l  #SelectPattern,d1
		move.l  #TokenPattern,d2
		moveq   #62,d3
		call    ParsePatternNoCase

		bsr     Deselect

		move.l  CurrentCat,a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .done

		tst.b   LN_TYPE(a2)
		beq.s   .loop

		move.l  #TokenPattern,d1
		lea     fi_Name(a2),a0
		move.l  a0,d2
		call    MatchPatternNoCase
		tst.l   d0
		beq.s   .loop

		bset    #NO_SELECTED,LN_PRI(a2)
		move.b  #'×',fi_Show(a2)

		bra.s   .loop

.done           move.l  gad_base,a6
		move.l  MainWnd,a0
		cladd   a1
		call    GT_RefreshWindow

.quit           popm.l  d0-d7/a0-a6
		rts




**
**  Routines che stabiliscono quali drives usare
**
**

AllDrivesMenued clr.l   df0
		rts

df0Menued       move.l  #$00010101,df0
		rts

df1Menued       move.l  #$01000101,df0
		rts

df2Menued       move.l  #$01010001,df0
		rts

df3Menued       move.l  #$01010100,df0
		rts





**
**  Gestisce i raw key della finestra principale
**
**

MainRawKey      pushm.l d0-d1/a0-a3/a6
		lea     List_tag2,a3

		move.w  6(a3),d0

.ok             move.w  im_Code(a5),d1

		cmp.b   #$4C,d1         ; Freccia su
		bne.s   .no_su

		tst.w   d0
		ble.s   .quit

		dec.w   d0

		bra.s   .check

.no_su          cmp.b   #$4D,d1         ; Freccia giù
		bne.s   .no_giu

		tst.w   d0
		bmi.s   .primo

		move.w  d0,d1

		move.l  CurrentCat,a0
.loop           move.l  (a0),a0
		dbra    d1,.loop

		move.l  (a0),a0 ; ce n'è un altro?
		tst.l   (a0)
		beq.s   .quit

.primo          inc.w   d0

.check          move.w  im_Qualifier(a5),d1
		and.w   #($10!$20),d1           ; alt ?
		bne.s   .no_deselect

		bsr     Deselect

.no_deselect    move.l  CurrentCat,a0
		move.w  d0,d1
.search         move.l  (a0),a0
		dbra    d1,.search

		tst.b   LN_TYPE(a0)
		bne.s   .file

		bsr     Deselect
		bra.s   .set_tag

.file           move.b  #'×',fi_Show(a0)

.set_tag        bset    #NO_SELECTED,LN_PRI(a0)

		move.l  gad_base,a6
		move.l  CategoriesGadget,a0
		move.l  MainWnd,a1
		cladd   a2
		move.w  d0,6(a3)
		move.w  d0,14(a3)
		move.l  CurrentCat,20(a3)
		call    GT_SetGadgetAttrsA

		bra.s   .quit

.no_giu

.quit           popm.l  d0-d1/a0-a3/a6
		rts



**
**  Gestisce i vanilla key della finestra principale
**
**

MainVanillaKey  push.l  d0
		move.w  im_Code(a5),d0

		cmp.b   #13,d0
		bne.s   .no_ret

		bsr     EditMenued
		bra.s   .quit

.no_ret         nop

.quit           pop.l   d0
		rts




**
**  Attiva/Disattiva l'autoscan dei dischi
**
**

AutoScanMenued  bchg    #AUTOSCAN,MainFlags
		rts



**
**  Scan manuale di una directory
**
**

ScanMenued      pushm.l d0-d7/a0-a6
		move.l  asl_base,a6

		sf      savemode

		moveq   #ASL_FileRequest,d0
		lea     Asl_tags2,a0
		move.l  #SelectVolume_txt,asl_title-Asl_tags2(a0)
		call    AllocAslRequest
		move.l  d0,d7
		beq.s   .error


		move.l  d0,a0   ; apri il requester
		cladd   a1
		call    AslRequest
		tst.l   d0
		bne.s   .asl_ok


		cmp.w   #38,LIB_VERSION(a6)
		blt.s   .ready

		move.l  dos_base,a6     ; c'è stato un errore?
		call    IoErr
		tst.l   d0
		beq.s   .ready

		bra.s   .error

.asl_ok         move.l  d7,a0
		lea     Asl_tags,a1

		move.w  fr_LeftEdge(a0),asl_left+2-Asl_tags(a1)
		move.w  fr_TopEdge(a0),asl_top+2-Asl_tags(a1)
		move.w  fr_Width(a0),asl_width+2-Asl_tags(a1)
		move.w  fr_Height(a0),asl_height+2-Asl_tags(a1)

		move.l  fr_Drawer(a0),a0
		lea     ScanDrawer,a1
		strcopy a0,a1

		move.l  dos_base,a6     ; Lock sulla directory
.lock_loop      move.l  #ScanDrawer,d1
		move.l  #ACCESS_READ,d2
		call    Lock
		move.l  d0,d6
		bne.s   .lock_ok

		call    IoErr

		cmp.w   #ERROR_DEVICE_NOT_MOUNTED,d0
		beq.s   .not_found

		stat    IOError_txt
		bra.s   .free

.not_found      move.l  MyTask,a2
		move.l  MainWnd,pr_WindowPtr(a2)

		move.l  d0,d1
		move.l  #REPORT_INSERT,d2
		move.l  #ScanDrawer,d3
		moveq   #0,d4
		call    ErrorReport

		move.l  #-1,pr_WindowPtr(a2)

		tst.l   d0
		beq.s   .lock_loop

.lock_ok        lea     -256(sp),sp

		move.l  d6,d1   ; ottengo il nome del lock
		move.l  sp,d2
		move.l  #256,d3
		call    NameFromLock

		move.l  sp,a2   ; cerco i ':' del disco...
.search_colons  cmp.b   #':',(a2)+
		bne.s   .search_colons

		clr.b   -(a2)   ; tronco il resto...

		move.l  sp,a0   ; copio il nome del disco
		lea     ScanDrawer,a3
		strcopy a0,a3

		addq.l  #1,a2   ; copio il nome della dir
		lea     DirName,a1
		strcopy a2,a1

		lea     256(sp),sp

		move.b  #':',-1(a3)
		clr.b   (a3)

		move.l  #ScanDrawer,d1
		move.l  #ACCESS_READ,d2
		call    Lock
		move.l  d0,d4

		clr.b   -1(a3)

		move.l  #DOS_FIB,d1
		moveq   #0,d2
		call    AllocDosObject
		move.l  d0,d5
		bne.s   .scan

		move.l  d6,d1
		call    UnLock

		stat    MemIns_txt
		beep
		bra.s   .free

.scan           move.l  d6,d1
		move.l  d5,d2
		call    Examine

		move.l  d4,d1
		call    CurrentDir

		bsr     StaccaLista
		stat    Scanning_txt

		pushm.l d0/d4-d7/a3-a4
		move.l  d6,d7
		lea     ScanDrawer,a3
		move.l  d5,a4
		bsr     RecursiveScan
		popm.l  d0/d4-d7/a3-a4

		bsr     AttaccaLista

		move.l  d0,d1
		call    CurrentDir

		move.l  d4,d1
		call    UnLock

		move.l  #DOS_FIB,d1     ; free the fib
		move.l  d5,d2
		call    FreeDosObject

		move.l  d6,d1   ; sblocco la directory
		call    UnLock

.ready          stat    Ready_txt

.free           move.l  d7,a0
		move.l  asl_base,a6
		call    FreeAslRequest

.quit           popm.l  d0-d7/a0-a6
		rts

.error          stat    NoAsl_txt
		beep
		bra.s   .quit



**
**  Attiva/Disattiva la recursione
**
**

RecurseMenued   bchg    #RECURSE,MainFlags
		rts


**
**  Cerca uno o piu' file
**
**

FindClicked
FindMenued      pushm.l d0-d7/a0-a6

		lea     FindWTags,a0
		bsr     LayoutWindow

		jsr     OpenFindWindow
		tst.l   d0
		beq.s   .wnd_ok

		stat    NoWindow_txt
		beep
		jsr     CloseFindWindow
		bra     .quit

.wnd_ok         move.b  MainFlags,d0
		bchg    #SEARCHBYCOM,d0
		bchg    #SEARCHBYDISK,d0
		move.b  d0,MainFlags

		bsr     ComClicked
		bsr     FI_ByDiskClicked

		bsr     AttivaSearchFor

		clr.b   SearchQuit

.wnd_loop       move.l  4,a6
		move.l  FindWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleFindIDCMP
		tst.b   SearchQuit
		beq.s   .wnd_loop
		bmi.s   .continue

		jsr     CloseFindWindow
		bra     .quit

.continue       move.l  SearchForGadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     SelectPattern,a1
		move.w  #'#?',(a1)+
		strcopy a0,a1

		jsr     CloseFindWindow

		move.l  uti_base,a6
		lea     SelectPattern,a2

.conv_loop      move.b  (a2),d0
		beq.s   .ok
		call    ToUpper
		move.b  d0,(a2)+
		bra.s   .conv_loop

.ok             move.b  #'#',(a2)+
		move.b  #'?',(a2)+
		clr.b   (a2)

		move.l  dos_base,a6

		move.l  #SelectPattern,d1
		move.l  #TokenPattern,d2
		moveq   #62,d3
		call    ParsePatternNoCase

		stat    Searching_txt

		lea     FindList,a0
		NEWLIST a0

		bsr     StaccaLista

		lea     DataList,a2
		bsr.s   FindRecursive

		bsr     LastSearchMenued

		bsr     AttaccaLista
.quit           popm.l  d0-d7/a0-a6
		rts


**
**  Ricerca ricorsivamente un file
**  a2 = Lista iniziale; a6 = dos_base
**

FindRecursive   pushm.l d0-d2/a0-a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .done

		tst.b   LN_TYPE(a2)
		bne.s   .file

		push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   FindRecursive
		pop.l   a2

		bra.s   .loop

.file           bclr    #FI_FOUND,LN_PRI(a2)

		lea     fi_Name(a2),a0
		move.l  #TokenPattern,d1
		move.l  a0,d2
		call    MatchPatternNoCase
		tst.l   d0
		beq.s   .com

.found          bset    #FI_FOUND,LN_PRI(a2)
		bra.s   .loop

.com            btst    #SEARCHBYCOM,MainFlags
		beq.s   .disk

		lea     fi_Comment(a2),a0
		move.l  #TokenPattern,d1
		move.l  a0,d2
		call    MatchPatternNoCase
		tst.l   d0
		bne.s   .found

.disk           btst    #SEARCHBYDISK,MainFlags
		beq.s   .loop

		lea     fi_Disk(a2),a0
		move.l  #TokenPattern,d1
		move.l  a0,d2
		call    MatchPatternNoCase
		tst.l   d0
		bne.s   .found

		bra.s   .loop

.done           popm.l  d0-d2/a0-a2
		rts




ComClicked      bchg    #SEARCHBYCOM,MainFlags
		seq     d0
		move.l  ComGadget,a0
		bra.s   SetFindCheck

FI_ByDiskClicked        bchg    #SEARCHBYDISK,MainFlags
		seq     d0
		move.l  FI_ByDiskGadget,a0

SetFindCheck    pushm.l a1-a3/a6
		move.l  gad_base,a6
		move.l  FindWnd,a1
		cladd   a2
		lea     Check_tag,a3
		move.b  d0,7(a3)
		call    GT_SetGadgetAttrsA
		popm.l  a1-a3/a6
		rts

**
**  Processa i VanillaKey della finestra Find file(s)
**
**

FindVanillaKey  move.w  im_Code(a5),d0

		cmp.b   #13,d0
		beq.s   FindOkClicked

		cmp.b   #27,d0
		beq.s   FindCancClicked

		or.b    #$20,d0

		cmp.b   #'m',d0
		beq.s   ComClicked

		cmp.b   #'d',d0
		beq.s   FI_ByDiskClicked

		cmp.b   #'s',d0
		beq.s   AttivaSearchFor

SearchForClicked        rts


**
**  Attiva il gadget Search for
**
**

AttivaSearchFor pushm.l d0-d1/a0-a2/a6
		move.l  int_base,a6
		move.l  SearchForGadget,a0
		move.l  FindWnd,a1
		cladd   a2
		call    ActivateGadget
		popm.l  d0-d1/a0-a2/a6
		rts


**
**  Routine associate ai pulsanti Ok e Cancel
**
**

FindOkClicked   st      SearchQuit
		rts

FindCancClicked move.b  #1,SearchQuit
		rts



**
**  Prepara la lista dei file trovati
**  a2 = Lista iniziale
**

MakeFindList    pushm.l d0-d1/a0-a3
		move.l  a2,a3
.big_loop       move.l  a3,a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		bne.s   .file

		push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   MakeFindList
		pop.l   a2

		bra.s   .loop

.file           btst    #FI_FOUND,LN_PRI(a2)
		beq.s   .loop

		move.l  a3,fi_OldCat(a2)

		move.l  a2,a1
		REMOVE

		lea     FindList,a0
		move.l  a2,a1
		bsr     InsertByName

		bra.s   .big_loop

.quit           popm.l  d0-d1/a0-a3
		rts


**
**  Rimette come erano i file trovati
**
**

UndoFindList    pushm.l d0-d1/a0-a1
.loop           lea     FindList,a0
		REMTAIL
		tst.l   d0
		beq.s   .quit

		move.l  d0,a1

		move.l  fi_OldCat(a1),a0
		bsr     InsertByName

		bra.s   .loop

.quit           popm.l  d0-d1/a0-a1
		rts



**
**  Mostra l'esito dell'ultima ricerca
**
**

LastSearchMenued        pushm.l d0-d7/a0-a6
		lea     DataList,a2
		bsr     MakeFindList

		move.l  CurrentCat,d7
		move.l  #FindList,CurrentCat

		lea     FindList,a2
		move.l  (a2),a1
		tst.l   (a1)
		bne.s   .ok

		stat    NoFileFound_txt
		bra     .quit

.ok             lea     SearchResWTags,a0
		bsr     LayoutWindow

		jsr     OpenSearchResWindow
		tst.l   d0
		bne.s   .close

		bsr     Deselect
		bsr     AttaccaFind

		clr.b   FindQuit

		clr.w   Ticks

.loop           move.l  4,a6
		move.l  SearchResWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleSearchResIDCMP
		tst.b   FindQuit
		beq.s   .loop

.close          jsr     CloseSearchResWindow

.quit           bsr     UndoFindList

		move.l  d7,CurrentCat

		popm.l  d0-d7/a0-a6
		rts


**
**  Attacca la lista al gadget Find
**
**

AttaccaFind     pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  FI_FilesGadget,a0
		move.l  SearchResWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #FindList,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts


**
**  Stacca la   lista al gadget Find
**
**

StaccaFind      pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  FI_FilesGadget,a0
		move.l  SearchResWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #-1,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts


**
**  Fa chiudere la finestra dei file trovati
**
**

SearchResCloseWindow
AddV_OkClicked
FiltersCloseWindow
ExOkClicked
		st      FindQuit
		rts

ExCancClicked
AddV_CancClicked        move.b  #1,FindQuit
		rts


**
**  Elimina il file selezionato
**
**

FI_DelClicked   pushm.l d0-d1/a0-a2/a6
		bsr     StaccaFind

		move.l  4,a6

.big_loop       lea     FindList,a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		btst    #NO_SELECTED,LN_PRI(a2)
		beq.s   .loop

		move.l  a2,a1
		REMOVE

		move.l  a2,a1
		move.l  #fi_SIZEOF,d0
		call    FreeMem

		bra.s   .big_loop

.quit           bsr     AttaccaFind
		popm.l  d0-d1/a0-a2/a6
		rts




**
**  Associata alla listview
**
**

FI_FilesClicked pushm.l d0-d1
		move.w  Ticks,d1
		clr.w   Ticks

		move.w  im_Code(a5),d0

		lea     FindList,a0

.loop           move.l  (a0),a0
		dbra    d0,.loop

		move.l  NodeID,a1
		move.l  a0,NodeID

		move.w  im_Qualifier(a5),d0
		and.b   #%11,d0
		bne.s   .no_des

		bsr     Deselect

.no_des         bset    #NO_SELECTED,LN_PRI(a0)
		move.b  #'×',fi_Show(a0)

		pushm.l d1/a0-a1/a6
		move.l  gad_base,a6
		move.l  SearchResWnd,a0
		cladd   a1
		call    GT_RefreshWindow
		popm.l  d1/a0-a1/a6

		cmp.l   a0,a1
		bne.s   .quit

		cmp.w   #2,d1
		bgt.s   .quit

		bsr     StaccaFind
		bsr     EditFiles
		bsr     AttaccaFind

.quit           popm.l  d0-d1
		rts



**
**  Apre la finestra degli spostamenti usando la lista dei file trovati
**
**

FI_MoveClicked  bsr     StaccaFind
		move.l  #FindList,From
		move.l  #DataList,To
		bsr.s   MoveFiles
		bra     AttaccaFind



MoveClicked
MoveMenued      move.l  CurrentCat,From
		move.l  #DataList,To
		bsr     StaccaLista
		bsr.s   MoveFiles
		bra     AttaccaLista


**
**  Sposta i file da una categoria ad un'altra
**
**

MoveFiles       pushm.l d0-d7/a0-a6

		lea     MoveWTags,a0
		bsr     LayoutWindow

		jsr     OpenMoveWindow
		tst.l   d0
		bne.s   .close

		bsr     AttaccaFrom
		bsr     AttaccaTo

		clr.b   MoveQuit

.loop           move.l  4,a6
		move.l  MoveWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleMoveIDCMP
		tst.b   MoveQuit
		beq.s   .loop

.close          jsr     CloseMoveWindow

		popm.l  d0-d7/a0-a6
		rts


**
**  Fa chiudere la finestra Move
**
**

MoveCloseWindow st      MoveQuit
		rts


**
**  Stacca la lista From
**
**

StaccaFrom      pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  FromGadget,a0
		move.l  MoveWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #-1,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts

**
**  Stacca la lista To
**
**

StaccaTo        pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  ToGadget,a0
		move.l  MoveWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #-1,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts


**
**  Attacca la lista From
**
**

AttaccaFrom     pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  FromGadget,a0
		move.l  MoveWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  From,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts

**
**  Attacca la lista TO
**
**

AttaccaTo       pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  ToGadget,a0
		move.l  MoveWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  To,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts


**
**  Mostra la lista root nel gadget From
**
**

RootFromClicked cmp.l   #FindList,From
		bne.s   .ok
		rts
.ok             bsr     StaccaFrom
		move.l  #DataList,From
		bra     AttaccaFrom


**
**  Mostra la lista root nel gadget To
**
**

RootToClicked   cmp.l   #FindList,To
		bne.s   .ok
		rts
.ok             bsr     StaccaTo
		move.l  #DataList,To
		bra     AttaccaTo


**
**  Mostra la categoria From precedente
**
**

ParentFromClicked       push.l  a0
		move.l  From,a0
		cmp.l   #DataList,a0
		beq.s   .quit
		cmp.l   #FindList,a0
		beq.s   .quit
		bsr     StaccaFrom
		move.l  cat_Parent-cat_Files(a0),From
		bsr     AttaccaFrom
.quit           pop.l   a0
		rts


**
**  Mostra la categoria To precedente
**
**

ParentToClicked push.l  a0
		move.l  To,a0
		cmp.l   #DataList,a0
		beq.s   .quit
		cmp.l   #FindList,a0
		beq.s   .quit
		bsr     StaccaTo
		move.l  cat_Parent-cat_Files(a0),To
		bsr     AttaccaTo
.quit           pop.l   a0
		rts


**
**  Routine associata alla listview From
**
**

FromClicked     pushm.l d0-d1/a0-a1/a6

		move.w  im_Code(a5),d0
		move.l  From,a0
.loop           move.l  (a0),a0
		dbra    d0,.loop

		tst.b   LN_TYPE(a0)
		bne.s   .file

		bsr     StaccaFrom
		lea     cat_Files(a0),a0
		move.l  a0,From
		bsr     AttaccaFrom

		bra.s   .quit

.file           move.l  CurrentCat,d1

		move.w  im_Qualifier(a5),d0
		and.b   #%11,d0
		bne.s   .no_des

		move.l  From,CurrentCat
		bsr     Deselect

.no_des         bset    #NO_SELECTED,LN_PRI(a0)
		move.b  #'×',fi_Show(a0)

		move.l  To,CurrentCat
		bsr     Deselect

		move.l  d1,CurrentCat

		move.l  gad_base,a6
		move.l  MoveWnd,a0
		cladd   a1
		call    GT_RefreshWindow

.quit           popm.l  d0-d1/a0-a1/a6
		rts


**
**  Routine associata alla listview To
**
**

ToClicked       pushm.l d0-d1/a0-a1/a6

		move.w  im_Code(a5),d0
		move.l  To,a0
.loop           move.l  (a0),a0
		dbra    d0,.loop

		tst.b   LN_TYPE(a0)
		bne.s   .file

		bsr     StaccaTo
		lea     cat_Files(a0),a0
		move.l  a0,To
		bsr     AttaccaTo

		bra.s   .quit

.file           move.l  CurrentCat,d1

		move.w  im_Qualifier(a5),d0
		and.b   #%11,d0
		bne.s   .no_des

		move.l  To,CurrentCat
		bsr     Deselect

.no_des         bset    #NO_SELECTED,LN_PRI(a0)
		move.b  #'×',fi_Show(a0)

		move.l  From,CurrentCat
		bsr     Deselect

		move.l  d1,CurrentCat

		move.l  gad_base,a6
		move.l  MoveWnd,a0
		cladd   a1
		call    GT_RefreshWindow

.quit           popm.l  d0-d1/a0-a1/a6
		rts


**
**  Sposta i file selezionati da From a To
**
**

MoveFromClicked pushm.l d0-d7/a0-a6
		move.l  To,a2           ; non si può spostare nella
		cmp.l   #DataList,a2            ; root
		beq.s   .quit

		bsr     StaccaFrom
		bsr     StaccaTo

.loop           move.l  From,a1
.search_loop    move.l  (a1),a1
		tst.l   (a1)
		beq.s   .done

		tst.b   LN_TYPE(a1)
		beq.s   .search_loop

		btst    #NO_SELECTED,LN_PRI(a1)
		beq.s   .search_loop

		move.l  a1,a3
		REMOVE

		move.l  a2,a0
		move.l  a3,a1
		bsr     InsertByName

		bclr    #SAVED,MainFlags

		bra.s   .loop

.done           bsr     AttaccaFrom
		bsr     AttaccaTo

.quit           popm.l  d0-d7/a0-a6
		rts



**
**  Sposta tutti i file da From a To
**
**

AllFromClicked  pushm.l d0-d7/a0-a6
		move.l  To,a2           ; non si può spostare nella
		cmp.l   #DataList,a2            ; root
		beq.s   .quit

		bsr     StaccaFrom
		bsr     StaccaTo

.loop           move.l  From,a1
.search_loop    move.l  (a1),a1
		tst.l   (a1)
		beq.s   .done

		tst.b   LN_TYPE(a1)
		beq.s   .search_loop

		move.l  a1,a3
		REMOVE

		move.l  a2,a0
		move.l  a3,a1
		bsr     InsertByName

		bclr    #SAVED,MainFlags

		bra.s   .loop

.done           bsr     AttaccaFrom
		bsr     AttaccaTo

.quit           popm.l  d0-d7/a0-a6
		rts



**
**  Sposta i file selezionati da To a From
**
**

MoveToClicked   pushm.l d0-d7/a0-a6
		move.l  From,a2         ; non si può spostare nella
		cmp.l   #DataList,a2            ; root
		beq.s   .quit

		bsr     StaccaFrom
		bsr     StaccaTo

.loop           move.l  To,a1
.search_loop    move.l  (a1),a1
		tst.l   (a1)
		beq.s   .done

		tst.b   LN_TYPE(a1)
		beq.s   .search_loop

		btst    #NO_SELECTED,LN_PRI(a1)
		beq.s   .search_loop

		move.l  a1,a3
		REMOVE

		move.l  a2,a0
		move.l  a3,a1
		bsr     InsertByName

		bclr    #SAVED,MainFlags

		bra.s   .loop

.done           bsr     AttaccaFrom
		bsr     AttaccaTo

.quit           popm.l  d0-d7/a0-a6
		rts


**
**  Sposta tutti i file da To a From
**
**

AllToClicked    pushm.l d0-d7/a0-a6
		move.l  From,a2         ; non si può spostare nella
		cmp.l   #DataList,a2            ; root
		beq.s   .quit

		bsr     StaccaFrom
		bsr     StaccaTo

.loop           move.l  To,a1
.search_loop    move.l  (a1),a1
		tst.l   (a1)
		beq.s   .done

		tst.b   LN_TYPE(a1)
		beq.s   .search_loop

		move.l  a1,a3
		REMOVE

		move.l  a2,a0
		move.l  a3,a1
		bsr     InsertByName

		bclr    #SAVED,MainFlags

		bra.s   .loop

.done           bsr     AttaccaFrom
		bsr     AttaccaTo

.quit           popm.l  d0-d7/a0-a6
		rts



**
**  Salva come
**
**

SaveAsMenued    pushm.l d0/d7/a0
		st      savemode
		lea     DiskOrg_ext,a0
		move.l  #SaveAs_txt,asl_title
		move.l  #Data_pat,asl_pattern
		bsr     GetFile
		tst.l   d0
		beq.s   .quit
		tst.l   d7
		beq.s   .quit
		bsr     SaveMenued
.quit           popm.l  d0/d7/a0
		rts


**
**  Salva il database corrente
**
**

SaveMenued      tst.b   AllPath
		beq.s   SaveAsMenued
		pushm.l d0-d4/d7/a0-a2/a6

		stat    Saving_txt

		move.l  dos_base,a6

		move.l  #AllPath,d1
		move.l  #MODE_NEWFILE,d2
		call    Open

		move.l  d0,d7
		beq.s   .error

		move.l  d7,d1
		move.l  #Header,d2
		moveq   #4,d3
		moveq   #1,d4
		call    FWrite

		lea     DataList,a2
		bsr.s   WriteCat

		bset    #SAVED,MainFlags

		stat    Ready_txt

.close          move.l  d7,d1
		call    Close

.quit           popm.l  d0-d4/d7/a0-a2/a6
		rts

.error          stat    CantOpenFile_txt
		beep
		bra.s   .quit


**
**  Scrive i dati nel file
**  a2 = Start list; d7 = FileHandle; a6 = dos_base
**

WriteCat        pushm.l d0-d1/a0-a2
		move.l  a2,a0
		bsr     CountNodes

		push.w  d0

		move.l  d7,d1   ; numero dei nodi che seguono
		move.l  sp,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FWrite

		addq.l  #2,sp

.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		move.l  d7,d1   ; tipo dei dati che seguono
		move.b  LN_TYPE(a2),d2
		ext.w   d2
		ext.l   d2
		call    FPutC

		tst.b   LN_TYPE(a2)
		bne.s   .file

		move.l  d7,d1   ; è il nodo Uncataloged?
		move.b  LN_PRI(a2),d2
		ext.w   d2
		ext.l   d2
		and.b   #(1<<NO_UNCAT),d2
		call    FPutC

		btst    #NO_UNCAT,LN_PRI(a2)
		bne.s   .uncat

		lea     cat_Name(a2),a0
		bsr     PutStr

.uncat          push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   WriteCat
		pop.l   a2

		bra.s   .loop

.file           move.l  d7,d1   ; pad
		moveq   #0,d2
		call    FPutC

		lea     fi_Size(a2),a0
		move.l  d7,d1
		move.l  a0,d2
		moveq   #20,d3
		moveq   #1,d4
		call    FWrite

		lea     fi_Disk(a2),a0
		bsr     PutStr

		lea     fi_Name(a2),a0
		bsr     PutStr

		lea     fi_Drawer(a2),a0
		bsr     PutStr

		lea     fi_Comment(a2),a0
		bsr     PutStr

		bra.s   .loop

.quit           popm.l  d0-d1/a0-a2
		rts



**
**  Legge una stringa dal file, saltando il byte di pad se c'è
**  d7 = FileHandle; a0 = ^buffer
**

GetStr          pushm.l d0-d5/a0/a2/a6

		move.l  a0,a2

		move.l  d7,d1           ; lunghezza
		call    FGetC
		move.l  d0,d5

		move.l  d7,d1           ; stringa
		move.l  a2,d2
		move.l  d0,d3
		moveq   #1,d4
		call    FRead

		and.b   #1,d5
		bne.s   .quit

		move.l  d7,d1           ; pad
		call    FGetC

.quit           popm.l  d0-d5/a0/a2/a6
		rts



**
**  Scrive una  stringa nel file mettendo un byte di pad se necessario
**  d7 = FileHandle; a0 = ^Stringa
**

PutStr          pushm.l d0-d4/d6/a0/a6
		push.l  a0

		strlen  a0
		move.l  d0,d6

		move.l  d7,d1   ; lunghezza
		move.l  d6,d2
		call    FPutC

		move.l  d7,d1   ; stringa
		pop.l   d2
		move.l  d6,d3
		moveq   #1,d4
		call    FWrite

		and.w   #1,d6   ; ci vuole il pad?
		bne.s   .quit

		move.l  d7,d1   ; pad
		moveq   #0,d2
		call    FPutC

.quit           popm.l  d0-d4/d6/a0/a6
		rts



**
**  Carica un database
**
**

OpenClicked
OpenMenued      pushm.l d0-d1/d7/a0

		sf      savemode
		lea     DiskOrg_ext,a0
		move.l  #Load_txt,asl_title
		move.l  #Data_pat,asl_pattern
		bsr     GetFile
		tst.l   d0
		beq.s   .quit
		tst.l   d7
		beq.s   .quit

		bsr.s   LoadDatabase

.quit           popm.l  d0-d1/d7/a0
		rts



**
**  Carica il database
**
**

LoadDatabase    pushm.l d0-d4/d7/a0-a2/a6

		stat    Loading_txt

		move.l  dos_base,a6

		move.l  #AllPath,d1
		move.l  #MODE_OLDFILE,d2
		call    Open

		move.l  d0,d7
		beq.s   .error

		subq.l  #4,sp

		move.l  d7,d1
		move.l  sp,d2
		moveq   #4,d3
		moveq   #1,d4
		call    FRead

		pop.l   d0
		cmp.l   Header,d0
		bne.s   .not_my_file

		bsr     NewMenued
		tst.l   d0
		bgt.s   .close

		bsr     StaccaLista

		lea     DataList,a2
		bsr.s   ReadCat

		move.l  Uncat,a1
		lea     -cat_Files(a1),a1
		move.l  a1,a2
		REMOVE

		lea     DataList,a0
		move.l  a2,a1
		bsr     InsertByName

		bsr     AttaccaLista

		bset    #SAVED,MainFlags

		stat    Ready_txt

.close          move.l  d7,d1
		call    Close

.quit           popm.l  d0-d4/d7/a0-a2/a6
		rts

.error          stat    CantOpenFile_txt
.exit           beep
		bra.s   .quit

.not_my_file    stat    NotMyfile_txt
	bra.s   .exit


**
**  Legge i dati dal file
**  a2 = Start list; d7 = FileHandle
**

ReadCat         pushm.l d1/d5/a0-a4/a6
		move.l  dos_base,a6

		subq.l  #2,sp

		move.l  d7,d1   ; numero dei nodi che seguono
		move.l  sp,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FRead

		pop.w   d5
		beq.s   .quit

		dec.w   d5

.loop           move.l  d7,d1   ; tipo dei dati che seguono
		call    FGetC

		move.b  d0,d6
		bgt.s   .file

		move.l  #cat_SIZEOF,d0
		bra.s   .size_ok

.file           move.l  #fi_SIZEOF,d0
.size_ok        move.l  #MEMF_CLEAR,d1
		move.l  4,a6
		call    AllocMem
		tst.l   d0
		beq.s   .error

		move.l  d0,a3

		move.l  a2,a0
		move.l  a3,a1
		ADDTAIL

		move.l  dos_base,a6

		tst.b   d6
		bne.s   .file2

		lea     cat_Files(a3),a0
		NEWLIST a0

		move.l  d7,d1   ; è il nodo Uncataloged?
		call    FGetC

		tst.b   d0
		beq.s   .no_uncat

		move.l  a2,a0
		REMTAIL

		move.l  4,a6
		move.l  a3,a1
		move.l  #cat_SIZEOF,d0
		call    FreeMem

		move.l  dos_base,a6

		move.l  Uncat,a4
		bra.s   .ok

.no_uncat       lea     cat_Name(a3),a0
		move.l  a0,LN_NAME(a3)
		bsr     GetStr

		lea     cat_Files(a3),a4
		move.l  a2,cat_Parent(a3)

.ok             push.l  a2
		move.l  a4,a2
		bsr.s   ReadCat
		pop.l   a2

		tst.l   d0
		beq.s   .quit

		bra.s   .next

.file2          move.l  d7,d1           ; file
		call    FGetC

		lea     fi_Size(a3),a0
		move.l  d7,d1
		move.l  a0,d2
		moveq   #20,d3
		moveq   #1,d4
		call    FRead

		lea     fi_Disk(a3),a0
		bsr     GetStr

		lea     fi_Name(a3),a0
		bsr     GetStr

		lea     fi_Drawer(a3),a0
		bsr     GetStr

		lea     fi_Comment(a3),a0
		bsr     GetStr

		pushm.l a2-a3/a6

		lea     fi_Name(a3),a0
		lea     fi_Disk(a3),a1
		lea     fi_Comment(a3),a2
		movem.l a0-a2,Show_args

		lea     File_fmt,a0
		lea     Show_args,a1
		lea     putch(pc),a2
		lea     fi_Show(a3),a3
		move.l  4,a6
		call    RawDoFmt

		popm.l  a2-a3/a6

		lea     fi_Show(a3),a0
		move.l  a0,LN_NAME(a3)

		move.b  #DO_FILE,LN_TYPE(a3)

.next           dbra    d5,.loop

.quit           moveq   #-1,d0

.exit           popm.l  d1/d5/a0-a4/a6
		rts

.error          stat    MemIns_txt
		beep
		moveq   #0,d0
		bra.s   .exit




**
**  Ricerca i file con lo stesso nome
**
**

DupesMenued     pushm.l d0-d1/a0-a2

		stat    Searching_txt

		lea     FindList,a0
		NEWLIST a0

		bsr     StaccaLista

		move.l  uti_base,a6

		lea     DataList,a2
		bsr.s   TogliFirst
		bsr.s   FindDoubleRec1

		bsr     LastSearchMenued

		bsr     AttaccaLista

		popm.l  d0-d1/a0-a2
		rts

**
**  Cancella    il bit FI_FIRST e il bit FI_FOUND
**
**

TogliFirst      push.l  a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		bne.s   .file

		push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   TogliFirst
		pop.l   a2
		bra.s   .loop

.file           and.b   #~((1<<FI_FIRST)!(1<<FI_FOUND)),LN_PRI(a2)
		bra.s   .loop

.quit           pop.l   a2
		rts


**
**  Esegue la ricerca ricorsivamente
**  a2 = List; a6 = uti_base
**

FindDoubleRec1  pushm.l a2-a3
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		bne.s   .file

		push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   FindDoubleRec1
		pop.l   a2
		bra.s   .loop

.file           move.l  a2,a3
		bset    #FI_FIRST,LN_PRI(a2)
		push.l  a2
		lea     DataList,a2
		bsr.s   FindDoubleRec2
		pop.l   a2

		bra.s   .loop

.quit           popm.l  a2-a3
		rts

FindDoubleRec2  pushm.l d0-d1/a0-a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		bne.s   .file

		push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   FindDoubleRec2
		pop.l   a2

		bra.s   .loop


.file           btst    #FI_FIRST,LN_PRI(a2)
		bne.s   .loop

		lea     fi_Name(a3),a0
		lea     fi_Name(a2),a1
		call    Stricmp
		tst.l   d0
		bne.s   .loop

		bset    #FI_FOUND,LN_PRI(a2)
		bset    #FI_FOUND,LN_PRI(a3)

		bra.s   .loop

.quit           popm.l  d0-d1/a0-a2
		rts



*************************************************************************
*           P R E F E R E N Z E    P E R   I L   D E V I C E            *
*************************************************************************


**
**  Preferenze per il device
**
**

DeviceMenued    pushm.l d0-d1/a0-a6

		lea     DeviceWTags,a0
		bsr     LayoutWindow

		jsr     OpenDeviceWindow
		tst.l   d0
		beq.s   .wnd_ok

		stat    NoWindow_txt
		beep
		bra.s   .quit

.wnd_ok         clr.b   EditQuit

		move.l  DeviceWnd,a4
		lea     Str_tag,a5

		move.l  gad_base,a6
		move.l  Dr0Gadget,a0
		move.l  a4,a1
		cladd   a2
		move.l  a5,a3
		move.l  #df0_txt2,4(a3)
		call    GT_SetGadgetAttrsA

		move.l  Dr1Gadget,a0
		move.l  a4,a1
		cladd   a2
		move.l  a5,a3
		move.l  #df1_txt2,4(a3)
		call    GT_SetGadgetAttrsA

		move.l  Dr2Gadget,a0
		move.l  a4,a1
		cladd   a2
		move.l  a5,a3
		move.l  #df2_txt2,4(a3)
		call    GT_SetGadgetAttrsA

		move.l  Dr3Gadget,a0
		move.l  a4,a1
		cladd   a2
		move.l  a5,a3
		move.l  #df3_txt2,4(a3)
		call    GT_SetGadgetAttrsA

		bsr     AttivaDr0

.loop           move.l  4,a6
		move.l  DeviceWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleDeviceIDCMP
		tst.b   EditQuit
		beq.s   .loop
		bgt.s   .quit

		move.l  Dr0Gadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     df0_txt2,a1
		strcopy a0,a1

		move.l  Dr1Gadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     df1_txt2,a1
		strcopy a0,a1

		move.l  Dr2Gadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     df2_txt2,a1
		strcopy a0,a1

		move.l  Dr3Gadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     df3_txt2,a1
		strcopy a0,a1

.quit           jsr     CloseDeviceWindow
		popm.l  d0-d1/a0-a6
		rts


**
**  Attivano i vari string gadget
**
**

AttivaDr0       move.l  Dr0Gadget,a0
		bra.s   AttivaDevStr

Dr0Clicked      move.l  Dr1Gadget,a0
		bra.s   AttivaDevStr

Dr1Clicked      move.l  Dr2Gadget,a0
		bra.s   AttivaDevStr

Dr2Clicked      move.l  Dr3Gadget,a0

AttivaDevStr    pushm.l a1-a2/a6
		move.l  DeviceWnd,a1
		cladd   a2
		move.l  int_base,a6
		call    ActivateGadget
		popm.l  a1-a2/a6
		rts

**
**  Ridirige la pressione dei tasti
**
**

DeviceVanillaKey        move.w  im_Code(a5),d0

		cmp.b   #13,d0
		beq.s   Dev_OkClicked

		cmp.b   #27,d0
		beq.s   Dev_CancClicked

		or.b    #$20,d0

		cmp.b   #'0',d0
		beq.s   AttivaDr0

		cmp.b   #'1',d0
		beq.s   Dr0Clicked

		cmp.b   #'2',d0
		beq.s   Dr1Clicked

		cmp.b   #'3',d0
		beq.s   Dr2Clicked

		cmp.b   #'o',d0
		beq.s   Dev_OkClicked

		cmp.b   #'c',d0
		beq.s   Dev_CancClicked

		rts

**
**  Chiudono il requester
**
**

ViewOkClicked
Dev_OkClicked   st      EditQuit
Dr3Clicked      rts

ViewCancClicked
Dev_CancClicked move.b  #1,EditQuit
		rts



*************************************************************************
*    S A L V A T A G G I O /  L E T T U R A   D E I  S E T T A G G I    *
*************************************************************************

**
**  Salva i parametri
**
**

SaveSetMenued   pushm.l d0-d7/a0-a6
		move.l  dos_base,a6

		move.l  #PrefsFile,d1
		move.l  #MODE_NEWFILE,d2
		call    Open

		move.l  d0,d7
		bne.s   .file_ok

		stat    CantOpenFile_txt
		beep
		bra.s   .quit

.file_ok        lea     Drives,a3

		moveq   #4-1,d2

.loop           move.l  (a3)+,a0
		bsr     PutStr
		dbra    d2,.loop

		lea     OutWin,a0
		bsr     PutStr

		lea     OtherViewer,a0
		bsr     PutStr

		move.l  d7,d1
		move.l  #NumViewers,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FWrite

		lea     ViewList,a2
		move.w  NumViewers,d2
		beq.s   .no_view
		dec.w   d2

.view_loop      move.l  (a2),a2

		lea     vn_Ext(a2),a0
		bsr     PutStr

		lea     vn_Viewer(a2),a0
		bsr     PutStr

		dbra    d2,.view_loop
.no_view

		move.l  d7,d1
		move.l  #NumFilters,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FWrite

		lea     FiltersList,a2
		move.w  NumFilters,d2
		beq.s   .no_filter
		dec.w   d2

.filter_loop    move.l  (a2),a2

		lea     fn_Filter(a2),a0
		bsr     PutStr

		dbra    d2,.filter_loop
.no_filter

		move.l  d7,d1
		moveq   #0,d2
		move.b  ExportFields,d2
		call    FPutC

		move.l  d7,d1
		moveq   #0,d2
		call    FPutC

		move.l  MainWnd,a2
		move.w  wd_Height(a2),d0

		move.l  Scr,a0
		move.b  sc_WBorTop(a0),d2
		ext.w   d2
		inc.w   d2
		move.b  sc_WBorBottom(a0),d3
		ext.w   d3
		move.l  sc_Font(a0),a1
		add.w   ta_YSize(a1),d2
		subq.w  #7,d2
		add.w   d3,d2
		move.w  wd_Height(a2),d0
		sub.w   d2,d0
		push.w  d0
		push.w  wd_Width(a2)

		move.l  d7,d1
		move.l  sp,d2
		moveq   #4,d3
		moveq   #1,d4
		call    FWrite

		addq.l  #4,sp

		move.l  d7,d1
		call    Close

.quit           popm.l  d0-d7/a0-a6
		rts



**
**  Carica i parametri
**
**

LoadSettings    pushm.l d0-d7/a0-a6
		move.l  dos_base,a6

		move.l  #PrefsFile,d1
		move.l  #MODE_OLDFILE,d2
		call    Open

		move.l  d0,d7
		beq.s   .quit

		lea     Drives,a3

		moveq   #4-1,d2

.loop           move.l  (a3)+,a0
		bsr     GetStr
		dbra    d2,.loop

		lea     OutWin,a0
		bsr     GetStr

		lea     OtherViewer,a0
		bsr     GetStr



		move.l  d7,d1
		move.l  #NumViewers,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FRead

		lea     ViewList,a3
		move.w  NumViewers,d2
		beq.s   .no_view
		dec.w   d2

.view_loop      move.l  4,a6
		move.l  #vn_SIZEOF,d0
		move.l  #MEMF_CLEAR,d1
		call    AllocMem
		tst.l   d0
		bne.s   .mem_ok

		stat    MemIns_txt
		beep
		bra.s   .close

.mem_ok         move.l  d0,a2

		move.l  dos_base,a6

		lea     vn_Ext(a2),a0
		move.l  a0,LN_NAME(a2)
		bsr     GetStr

		lea     vn_Viewer(a2),a0
		bsr     GetStr

		move.l  a3,a0
		move.l  a2,a1
		ADDTAIL

		dbra    d2,.view_loop
.no_view

		move.l  dos_base,a6

		move.l  d7,d1
		move.l  #NumFilters,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FRead

		lea     FiltersList,a3
		move.w  NumFilters,d2
		beq.s   .no_filter
		dec.w   d2

.filter_loop    move.l  4,a6
		moveq   #fn_SIZEOF,d0
		move.l  #MEMF_CLEAR,d1
		call    AllocMem
		tst.l   d0
		bne.s   .mem_ok2

		stat    MemIns_txt
		beep
		bra.s   .close

.mem_ok2        move.l  d0,a2

		move.l  dos_base,a6

		lea     fn_Filter(a2),a0
		move.l  a0,LN_NAME(a2)
		bsr     GetStr

		move.l  a3,a0
		move.l  a2,a1
		ADDTAIL

		dbra    d2,.filter_loop
.no_filter


		move.l  d7,d1
		call    FGetC
		move.b  d0,ExportFields

		move.l  d7,d1
		call    FGetC

		move.l  d7,d1
		move.l  #MainWTags+WT_WIDTH,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FRead

		move.l  d7,d1
		move.l  #MainWTags+WT_HEIGHT,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FRead

.close          move.l  dos_base,a6
		move.l  d7,d1
		call    Close

.quit           popm.l  d0-d7/a0-a6
		rts


**
**  Libera la memoria allocata da LoadSettings
**
**

FreeSettings    pushm.l d0-d1/a0-a1/a6

		move.l  4,a6

.loop           lea     ViewList,a0
		REMTAIL
		tst.l   d0
		beq.s   .loop2

		move.l  d0,a1
		move.l  #vn_SIZEOF,d0
		call    FreeMem

		bra.s   .loop

.loop2          lea     FiltersList,a0
		REMTAIL
		tst.l   d0
		beq.s   .quit

		move.l  d0,a1
		moveq   #fn_SIZEOF,d0
		call    FreeMem

		bra.s   .loop2

.quit           popm.l  d0-d1/a0-a1/a6
		rts



*************************************************************************
*            S E T T A G G I O    D E I    V I E W E R S                *
*************************************************************************


**
**  Settaggi per i Viewers
**
**

ViewersMenued   pushm.l d0-d1/a0-a6

		lea     ViewersWTags,a0
		bsr     LayoutWindow

		jsr     OpenViewersWindow
		tst.l   d0
		beq.s   .wnd_ok

		stat    NoWindow_txt
		beep
		bra.s   .quit

.wnd_ok         clr.b   EditQuit

		move.l  ViewersWnd,a4

		move.l  gad_base,a6

		move.l  OtherViewGadget,a0
		move.l  a4,a1
		cladd   a2
		lea     Str_tag,a3
		move.l  #OtherViewer,4(a3)
		call    GT_SetGadgetAttrsA

		move.l  OutGadget,a0
		move.l  a4,a1
		cladd   a2
		lea     Str_tag,a3
		move.l  #OutWin,4(a3)
		call    GT_SetGadgetAttrsA

		bsr     AttaccaViewers

.loop           move.l  4,a6
		move.l  ViewersWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleViewersIDCMP
		tst.b   EditQuit
		beq.s   .loop
		bgt.s   .quit

		move.l  OtherViewGadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     OtherViewer,a1
		strcopy a0,a1

		move.l  OutGadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     OutWin,a1
		strcopy a0,a1

.quit           jsr     CloseViewersWindow

		popm.l  d0-d1/a0-a6
OtherViewClicked        rts


AttaccaViewers  pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  V_ListGadget,a0
		move.l  ViewersWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #ViewList,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts


StaccaViewers   pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  V_ListGadget,a0
		move.l  ViewersWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #-1,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts



V_ListClicked   pushm.l d0-d1/a0/a4

		move.w  Ticks,d1
		clr.w   Ticks

		lea     ViewList,a4
		move.w  im_Code(a5),d0

.second_loop    move.l  (a4),a4
		dbra    d0,.second_loop

		lea     ViewList,a0
.first_loop     move.l  (a0),a0
		tst.l   (a0)
		beq.s   .done

		cmp.l   a0,a4
		beq.s   .first_loop

		bclr    #NO_SELECTED,LN_PRI(a0)

		bra.s   .first_loop

.done           bset    #NO_SELECTED,LN_PRI(a4)
		beq.s   .quit

		cmp.w   #2,d1
		bgt.s   .quit

		bsr     EditViewer

.quit           popm.l  d0-d1/a0/a4
		rts




DelViewClicked  pushm.l d0-d1/a0-a2/a6
		lea     ViewList,a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		btst    #NO_SELECTED,LN_PRI(a2)
		beq.s   .loop

		bsr     StaccaViewers

		move.l  a2,a1
		REMOVE

		bsr     AttaccaViewers

		move.l  4,a6
		move.l  a2,a1
		move.l  #vn_SIZEOF,d0
		call    FreeMem

		dec.w   NumViewers

.quit           popm.l  d0-d1/a0-a2/a6
		rts

AttivaOut       move.l  OutGadget,a0
		bra.s   AttivaViewersStr

AttivaOtherView move.l  OtherViewGadget,a0

AttivaViewersStr        pushm.l d0-d1/a0-a2/a6
		move.l  int_base,a6
		move.l  ViewersWnd,a1
		cladd   a2
		call    ActivateGadget
		popm.l  d0-d1/a0-a2/a6
OutClicked      rts


ViewersVanillaKey       move.w  im_Code(a5),d0

		cmp.b   #13,d0
		beq     ViewOkClicked

		cmp.b   #27,d0
		beq     ViewCancClicked

		or.b    #$20,d0

		cmp.b   #'a',d0
		beq     AddViewClicked

		cmp.b   #'d',d0
		beq     DelViewClicked

		cmp.b   #'t',d0
		beq.s   AttivaOtherView

		cmp.b   #'p',d0
		beq.s   AttivaOut

ViewerClicked   rts



**
**  Aggiunge/Edita un viewer
**
**

AttivaVExt      move.l  VExtGadget,a0
		bra.s   AttivaAddView

VExtClicked     move.l  ViewerGadget,a0

AttivaAddView   pushm.l d0-d1/a1-a2/a6
		move.l  int_base,a6
		move.l  AddViewWnd,a1
		cladd   a2
		call    ActivateGadget
		popm.l  d0-d1/a1-a2/a6
		rts



AddViewVanillaKey       move.w  im_Code(a5),d0

		cmp.b   #13,d0
		beq     AddV_OkClicked

		cmp.b   #27,d0
		beq     AddV_CancClicked

		or.b    #$20,d0

		cmp.b   #'o',d0
		beq     AddV_OkClicked

		cmp.b   #'c',d0
		beq     AddV_CancClicked

		cmp.b   #'v',d0
		beq.s   VExtClicked

		cmp.b   #'e',d0
		beq.s   AttivaVExt

		rts



GetViewClicked  pushm.l d0-d1/d7/a0-a3/a6
		sf      savemode
		cladd   a0
		move.l  #GetView_txt,asl_title
		move.l  #TAG_IGNORE,asl_pattern-4
		bsr     GetFile
		move.l  #ASLFR_InitialPattern,asl_pattern-4
		tst.l   d0
		beq.s   .quit
		tst.l   d7
		beq.s   .quit

		move.l  gad_base,a6
		move.l  ViewerGadget,a0
		move.l  AddViewWnd,a1
		cladd   a2
		lea     Str_tag,a3
		move.l  #AllPath,4(a3)
		call    GT_SetGadgetAttrsA

.quit           popm.l  d0-d1/d7/a0-a3/a6
		rts



AddViewClicked  pushm.l d0-d1/a0-a1/a4/a6

		move.l  4,a6
		move.l  #vn_SIZEOF,d0
		move.l  #MEMF_CLEAR,d1
		call    AllocMem
		tst.l   d0
		bne.s   .mem_ok

		stat    MemIns_txt
		beep
		bra.s   .quit

.mem_ok         move.l  d0,a4

		bsr.s   EditViewer

		tst.l   d0
		bne.s   .ok

		move.l  a4,a1
		move.l  #vn_SIZEOF,d0
		call    FreeMem

		bra.s   .quit

.ok             lea     vn_Ext(a4),a1
		move.l  a1,LN_NAME(a4)

		bsr     StaccaViewers

		lea     ViewList,a0
		move.l  a4,a1
		ADDTAIL

		bsr     AttaccaViewers

		inc.w   NumViewers

.quit           popm.l  d0-d1/a0-a1/a4/a6
		rts



**
**  Modifica i parametri del viewer
**  a4 = ^ViewerNode
**

EditViewer      pushm.l d1-d7/a0-a6

		lea     AddViewWTags,a0
		bsr     LayoutWindow

		jsr     OpenAddViewWindow
		tst.l   d0
		beq.s   .wnd_ok

		stat    NoWindow_txt
		beep
		moveq   #0,d0
		bra.s   .exit

.wnd_ok         move.l  gad_base,a6

		move.l  VExtGadget,a0
		move.l  AddViewWnd,a1
		cladd   a2
		lea     Str_tag,a3
		move.l  LN_NAME(a4),4(a3)
		call    GT_SetGadgetAttrsA

		move.l  ViewerGadget,a0
		move.l  AddViewWnd,a1
		lea     Str_tag,a3
		lea     vn_Viewer(a4),a2
		move.l  a2,4(a3)
		cladd   a2
		call    GT_SetGadgetAttrsA

		bsr     AttivaVExt

		clr.b   FindQuit

.loop           move.l  4,a6
		move.l  AddViewWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleAddViewIDCMP
		tst.b   FindQuit
		beq.s   .loop
		bmi.s   .ok

		moveq   #0,d0
		bra.s   .exit

.ok             move.l  VExtGadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     vn_Ext(a4),a1
		strcopy a0,a1

		move.l  ViewerGadget,a0
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     vn_Viewer(a4),a1
		strcopy a0,a1

		moveq   #-1,d0

.exit           jsr     CloseAddViewWindow

.quit           popm.l  d1-d7/a0-a6
		rts





**
**  Mostra gli item selezionati
**
**

ShowClicked
EditClicked     pushm.l d0-d1/a0-a6
		lea     -1000(sp),sp

		move.l  MyTask,a0
		move.l  old_WindowPtr,pr_WindowPtr(a0)

		move.l  CurrentCat,a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		beq.s   .loop

		btst    #NO_SELECTED,LN_PRI(a2)
		beq.s   .loop

		lea     fi_Name(a2),a3

.to_end         tst.b   (a3)+
		bne.s   .to_end

.search_point   cmp.b   #'.',-(a3)
		bne.s   .search_point

		addq.l  #1,a3

		move.l  uti_base,a6

		lea     ViewList,a4

.search_viewer  move.l  (a4),a4
		tst.l   (a4)
		beq.s   .not_found

		move.l  a3,a0
		lea     vn_Ext(a4),a1
		call    Stricmp
		tst.l   d0
		bne.s   .search_viewer

		lea     vn_Viewer(a4),a0
		bra.s   .found

.not_found      lea     OtherViewer,a0

.found          move.l  sp,a1

		strcopy a0,a1
		move.b  #' ',-1(a1)

		lea     fi_Disk(a2),a0
		strcopy a0,a1
		move.b  #':',-1(a1)

		lea     fi_Drawer(a2),a0
		tst.b   (a0)
		beq.s   .no_path
		strcopy a0,a1
		move.b  #'/',-1(a1)

.no_path        lea     fi_Name(a2),a0
		strcopy a0,a1
		move.b  #' ',-1(a1)

		lea     OutWin-2,a0
		strcopy a0,a1
		move.b  #'"',-1(a1)
		clr.b   (a1)

		move.l  dos_base,a6
		move.l  sp,d1
		moveq   #0,d2
		moveq   #0,d3
		call    Execute

		bra.s   .loop

.quit           lea     1000(sp),sp
		move.l  MyTask,a0
		move.l  #-1,pr_WindowPtr(a0)
		popm.l  d0-d1/a0-a6
		rts




*************************************************************************
*       C O N F I G U R A Z I O N E     D E L L ' E  X P O R T          *
*************************************************************************


SetExportMenued pushm.l d0-d7/a0-a6

		lea     ExportWTags,a0
		bsr     LayoutWindow

		jsr     OpenExportWindow
		tst.l   d0
		beq.s   .wnd_ok

		stat    NoWindow_txt
		beep
		bra.s   .quit

.wnd_ok         bsr.s   ResetFieldsChecks

		clr.b   FindQuit

		move.b  ExportFields,MoveQuit

.loop           move.l  4,a6
		move.l  ExportWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleExportIDCMP
		tst.b   FindQuit
		beq.s   .loop
		bmi.s   .quit

		move.b  MoveQuit,ExportFields

.quit           jsr     CloseExportWindow

		popm.l  d0-d7/a0-a6
		rts



ResetFieldsChecks pushm.l d0-d2/a0-a4/a6

		move.l  gad_base,a6

		push.l  ExCatGadget
		push.l  ExCommentGadget
		push.l  ExSizeGadget
		push.l  ExDateGadget
		push.l  ExPathGadget
		push.l  ExDiskGadget
		push.l  ExNameGadget

		moveq   #7-1,d2

		lea     ExChecks,a4

.loop           pop.l   a0
		move.l  ExportWnd,a1
		cladd   a2
		lea     Check_tag,a3
		move.b  (a4)+,d0
		btst    d0,ExportFields
		sne     7(a3)
		call    GT_SetGadgetAttrsA
		dbra    d2,.loop

		popm.l  d0-d2/a0-a4/a6
		rts


ExNameClicked   moveq   #EX_NAME,d0
		move.l  ExNameGadget,a0
		bra.s   ExSetCheck

ExDiskClicked   moveq   #EX_DISK,d0
		move.l  ExDiskGadget,a0
		bra.s   ExSetCheck

ExPathClicked   moveq   #EX_PATH,d0
		move.l  ExPathGadget,a0
		bra.s   ExSetCheck

ExDateClicked   moveq   #EX_DATE,d0
		move.l  ExDateGadget,a0
		bra.s   ExSetCheck

ExSizeClicked   moveq   #EX_SIZE,d0
		move.l  ExSizeGadget,a0
		bra.s   ExSetCheck

ExCommentClicked        moveq   #EX_COMMENT,d0
		move.l  ExCommentGadget,a0
		bra.s   ExSetCheck

ExCatClicked    moveq   #EX_CATEGORY,d0
		move.l  ExCatGadget,a0


ExSetCheck      pushm.l d1/a1-a3/a6
		move.l  ExportWnd,a1
		cladd   a2
		lea     Check_tag,a3
		bchg    d0,ExportFields
		seq     7(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d1/a1-a3/a6
		rts



ExportVanillaKey        move.w  im_Code(a5),d0

		cmp.w   #13,d0
		beq     ExOkClicked

		cmp.w   #27,d0
		beq     ExCancClicked

		or.b    #$20,d0

		cmp.b   #'o',d0
		beq     ExOkClicked

		cmp.b   #'c',d0
		beq     ExCancClicked

		cmp.b   #'n',d0
		beq     ExNameClicked

		cmp.b   #'d',d0
		beq     ExDiskClicked

		cmp.b   #'p',d0
		beq     ExPathClicked

		cmp.b   #'t',d0
		beq     ExDateClicked

		cmp.b   #'s',d0
		beq     ExSizeClicked

		cmp.b   #'m',d0
		beq     ExCommentClicked

		cmp.b   #'a',d0
		beq     ExCatClicked

		rts



*************************************************************************
*                R O U T I N E S    D I    E X P O R T                  *
*************************************************************************


FI_ExportClicked        pushm.l d5-d7/a2
		lea     FindList,a2
		moveq   #0,d5
		moveq   #0,d6
		bsr.s   GoExport
		popm.l  d5-d7/a2
		rts

ExAllMenued     pushm.l d5-d7/a2
		lea     DataList,a2
		moveq   #0,d5
		moveq   #-1,d6
		bsr.s   GoExport
		popm.l  d5-d7/a2
		rts

ExportClicked
ExFieldsMenued  pushm.l d5-d7/a2
		move.l  CurrentCat,a2
		moveq   #-1,d5
		moveq   #0,d6
		bsr.s   GoExport
		popm.l  d5-d7/a2
		rts


GoExport        pushm.l d0-d4/d7/a0-a1/a6
		st      savemode
		lea     Txt_ext,a0
		move.l  #Export_txt,asl_title
		move.l  #Export_pat,asl_pattern
		bsr     GetFile
		tst.l   d0
		beq.s   .quit
		tst.l   d7
		beq.s   .quit

		move.l  dos_base,a6

		move.l  #AllPath,d1
		move.l  #MODE_NEWFILE,d2
		call    Open

		move.l  d0,d7
		bne.s   .file_ok

		stat    CantOpenFile_txt
		beep
		bra.s   .quit

.file_ok        stat    Exporting_txt

		move.l  d7,d1
		move.l  #Header_txt,d2
		move.l  #Header_len,d3
		moveq   #1,d4
		call    FWrite

		clr.b   MoveQuit

		lea     CatBuffer,a3
		clr.b   (a3)
		bsr.s   ExportRoutine

		move.l  d7,d1
		call    Close

		stat    Ready_txt

.quit           popm.l  d0-d4/d7/a0-a1/a6
		rts

**
**  Routine di  export
**  a2 = Lista; d5 = only selected?; d6 = do recursion?; d7 = File Handle
**  a6 = dos_base; a3 = Category buffer
**

ExportRoutine   pushm.l d0-d1/a0-a2

.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		bne.s   .file

		tst.l   d6
		beq.s   .loop

		pushm.l a2-a3

		btst    #EX_CATEGORY,ExportFields
		beq.s   .no_cat

		cmp.l   #CatBuffer,a3
		beq.s   .no_slash

		move.b  #'/',(a3)+

.no_slash       move.l  LN_NAME(a2),a0
		addq.l  #4,a0
		strcopy a0,a3
		dec.l   a3

		lea     cat_Files(a2),a2
		bsr.s   ExportRoutine

		clr.b   MoveQuit

.no_cat         popm.l  a2-a3

		clr.b   (a3)

		bra.s   .loop

.file           tst.b   MoveQuit        ; è il primo file che scrivo?
		bne.s   .not_first

		st      MoveQuit

		move.l  d7,d1
		move.l  #Category_fmt,d2
		pea     CatBuffer
		move.l  sp,d3
		call    VFPrintf
		addq.l  #4,sp


.not_first      tst.l   d5
		beq.s   .all

		btst    #NO_SELECTED,LN_PRI(a2)
		beq.s   .loop

.all            btst    #EX_NAME,ExportFields
		beq.s   .no_name

		move.l  d7,d1
		move.l  #Name_fmt,d2
		pea     fi_Name(a2)
		move.l  sp,d3
		call    VFPrintf
		addq.l  #4,sp

.no_name        btst    #EX_SIZE,ExportFields
		beq.s   .no_size

		move.l  d7,d1
		move.l  #Size_fmt,d2
		push.l  fi_Size(a2)
		move.l  sp,d3
		call    VFPrintf
		addq.l  #4,sp

.no_size        btst    #EX_DISK,ExportFields
		beq.s   .no_disk

		move.l  d7,d1
		move.l  #Disk_fmt,d2
		pea     fi_Disk(a2)
		move.l  sp,d3
		call    VFPrintf
		addq.l  #4,sp

.no_disk        btst    #EX_PATH,ExportFields
		beq.s   .no_path

		move.l  d7,d1
		move.l  #Path_fmt,d2
		pea     fi_Drawer(a2)
		move.l  sp,d3
		call    VFPrintf
		addq.l  #4,sp

.no_path        btst    #EX_DATE,ExportFields
		beq.s   .no_date

		lea     Date_Time,a0
		movem.l fi_Date(a2),d0-d2
		movem.l d0-d2,(a0)

		move.l  a0,d1
		call    DateToStr

		move.l  d7,d1
		move.l  #Date_fmt,d2
		pea     FileDate
		move.l  sp,d3
		call    VFPrintf
		addq.l  #4,sp

.no_date        btst    #EX_COMMENT,ExportFields
		beq.s   .no_comment

		move.l  d7,d1
		move.l  #Comment_fmt,d2
		pea     fi_Comment(a2)
		move.l  sp,d3
		call    VFPrintf
		addq.l  #4,sp

.no_comment     move.l  d7,d1
		move.l  #CR,d2
		moveq   #2,d3
		moveq   #1,d4
		call    FWrite


		bra.s   .loop

.quit           popm.l  d0-d1/a0-a2
		rts



*************************************************************************
*         R O U T I N E S    P E R    L ' O R D I N A M E N T O         *
*************************************************************************


**
**  Cambia il criterio di ordinamento
**
**

SortClicked     move.b  SortCrit,d0
		ext.w   d0
		move.w  d0,d2
		inc.w   d0
		cmp.w   #4,d0
		bne.s   .ok
		cldat   d0
.ok             move.b  d0,SortCrit

		pushm.l d0/a1-a2/a6

		move.l  int_base,a6

		lea     SortMenus,a2

		move.l  MainWnd,a0
		call    ClearMenuStrip

		lsl.w   #2,d2
		move.l  0(a2,d2.w),d0

		move.l  MainMenu,a0
		call    ItemAddress

		move.l  d0,a0
		and.w   #~CHECKED,mi_Flags(a0)

		pull.l  d0
		lsl.w   #2,d0
		move.l  0(a2,d0.w),d0
		move.l  MainMenu,a0
		call    ItemAddress

		move.l  d0,a0
		or.w    #CHECKED,mi_Flags(a0)

		move.l  MainWnd,a0
		move.l  MainMenu,a1
		call    ResetMenuStrip

		popm.l  d0/a1-a2/a6

		lea     SortRoutines,a0
		lsl.w   #2,d0
		move.l  0(a0,d0.w),a0
		jmp     (a0)



OrderSizeMenued pushm.l a2/a4
		bsr     StaccaLista
		lea     DataList,a2
		lea     InsertBySize(pc),a4
		bsr.s   Sort
		bsr     AttaccaLista
		move.b  #3,SortCrit
		popm.l  a2/a4
		rts


OrderDateMenued pushm.l a2/a4
		bsr     StaccaLista
		lea     DataList,a2
		lea     InsertByDate(pc),a4
		bsr.s   Sort
		bsr     AttaccaLista
		move.b  #2,SortCrit
		popm.l  a2/a4
		rts



SortDiskMenued  pushm.l a2/a4
		bsr     StaccaLista
		lea     DataList,a2
		lea     InsertByDisk(pc),a4
		bsr.s   Sort
		bsr     AttaccaLista
		move.b  #1,SortCrit
		popm.l  a2/a4
		rts



OrderNameMenued pushm.l a2/a4
		bsr     StaccaLista
		lea     DataList,a2
		lea     InsertByName(pc),a4
		bsr.s   Sort
		bsr     AttaccaLista
		move.b  #0,SortCrit
		popm.l  a2/a4
		rts



**
**  Ordina tutte le categorie
**  a2 = Lista; a4 = ^ Routine di inserimento
**

Sort            pushm.l d0-d2/a0-a3/a5

		move.l  a2,a3

		moveq   #-1,d2

.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		tst.b   LN_TYPE(a2)
		bne.s   .file

		push.l  a2
		lea     cat_Files(a2),a2
		bsr.s   Sort
		pop.l   a2

		bra.s   .loop

.loop2          move.l  (a2),a2 ; rimuovo tutti i nodi...
		tst.l   (a2)
		beq.s   .done

.file           inc.w   d2

		move.l  a2,a1
		REMOVE

		push.l  a2
		bra.s   .loop2

.done           move.w  d2,d1

		inc.w   d2
		lsl.w   #2,d2
		lea     0(sp,d2.w),a5

.loop3          move.l  -(a5),a1        ; ...e li reinserisco in ordine
		move.l  a3,a0
		jsr     (a4)

		dbra    d1,.loop3

		add.w   d2,sp

.quit           popm.l  d0-d2/a0-a3/a5
		rts



*************************************************************************
*              S E T T A G G I O    D E I    F I L T R I                *
*************************************************************************


SetFiltersMenued        pushm.l d0-d7/a0-a6

		lea     FiltersWTags,a0
		bsr     LayoutWindow

		jsr     OpenFiltersWindow
		tst.l   d0
		beq.s   .wnd_ok

		stat    NoWindow_txt
		beep
		bra.s   .quit

.wnd_ok         bsr     AttaccaFilter

		clr.b   FindQuit

.loop           move.l  4,a6
		move.l  FiltersWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleFiltersIDCMP
		tst.b   FindQuit
		beq.s   .loop

.quit           jsr     CloseFiltersWindow

		popm.l  d0-d7/a0-a6
		rts




StaccaFilter    pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  FilterGadget,a0
		move.l  FiltersWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #-1,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts



AttaccaFilter   pushm.l d0-d1/a0-a3/a6
		move.l  gad_base,a6
		move.l  FilterGadget,a0
		move.l  FiltersWnd,a1
		cladd   a2
		lea     List_tag,a3
		move.l  #FiltersList,4(a3)
		call    GT_SetGadgetAttrsA
		popm.l  d0-d1/a0-a3/a6
		rts



FiltersVanillaKey       move.w  im_Code(a5),d0

		cmp.b   #13,d0
		beq     FiltersCloseWindow

		cmp.b   #27,d0
		beq     FiltersCloseWindow

		or.b    #$20,d0

		cmp.b   #'a',d0
		beq.s   AddFilterClicked

		cmp.b   #'d',d0
		beq.s   DelFilterClicked

		rts




AddFilterClicked        pushm.l d0-d1/a0-a2/a6

		move.l  4,a6
		moveq   #fn_SIZEOF,d0
		move.l  #MEMF_CLEAR,d1
		call    AllocMem
		tst.l   d0
		bne.s   .mem_ok

		stat    MemIns_txt
		beep
		bra.s   .quit

.mem_ok         move.l  d0,a2

		pushm.l a2/a6

		move.l  req_base,a6
		lea     fn_Filter(a2),a1
		moveq   #30,d0
		lea     EditFilter_txt,a2
		cladd   a3
		lea     req_tags2,a0
		call    rtGetStringA

		popm.l  a2/a6

		tst.l   d0
		bne.s   .ok

		move.l  a2,a1
		moveq   #fn_SIZEOF,d0
		call    FreeMem
		bra.s   .quit

.ok             lea     fn_Filter(a2),a0
		move.l  a0,LN_NAME(a2)

		bsr     StaccaFilter

		lea     FiltersList,a0
		move.l  a2,a1
		ADDTAIL

		bsr     AttaccaFilter

		inc.w   NumFilters

.quit           popm.l  d0-d1/a0-a2/a6
		rts




DelFilterClicked        pushm.l d0-d1/a0-a2/a6

		lea     FiltersList,a2
.loop           move.l  (a2),a2
		tst.l   (a2)
		beq.s   .quit

		btst    #NO_SELECTED,LN_PRI(a2)
		beq.s   .loop

		bsr     StaccaFilter

		move.l  a2,a1
		REMOVE

		move.l  4,a6
		move.l  a2,a1
		moveq   #fn_SIZEOF,d0
		call    FreeMem

		bsr     AttaccaFilter

		dec.w   NumFilters

.quit           popm.l  d0-d1/a0-a2/a6
		rts




FilterClicked   pushm.l d0-d1/a0-a4/a6

		move.w  Ticks,d1
		clr.w   Ticks

		lea     FiltersList,a4
		move.w  im_Code(a5),d0

.second_loop    move.l  (a4),a4
		dbra    d0,.second_loop

		lea     FiltersList,a0
.first_loop     move.l  (a0),a0
		tst.l   (a0)
		beq.s   .done

		cmp.l   a0,a4
		beq.s   .first_loop

		bclr    #NO_SELECTED,LN_PRI(a0)

		bra.s   .first_loop

.done           bset    #NO_SELECTED,LN_PRI(a4)
		beq.s   .quit

		cmp.w   #2,d1
		bgt.s   .quit

		move.l  req_base,a6
		lea     fn_Filter(a4),a1
		moveq   #30,d0
		lea     EditFilter_txt,a2
		cladd   a3
		lea     req_tags2,a0
		call    rtGetStringA

.quit           popm.l  d0-d1/a0-a4/a6
		rts



**************************************************************************
*          G E S T I O N E   F I N E S T R A   E D I T                   *
**************************************************************************


**
**  Edita tutti i files selezionati
**
**

EditMenued
EditFiles       pushm.l d0-d7/a0-a6
		lea     EditWTags,a0
		bsr     LayoutWindow

		move.l  CurrentCat,a4

.big_loop       move.l  (a4),a4
		tst.l   (a4)
		beq.s   .close

.big_loop_entry2        tst.b   LN_TYPE(a4)
		beq.s   .big_loop

		btst    #NO_SELECTED,LN_PRI(a4)
		beq.s   .big_loop

		tst.l   EditWnd
		bne.s   .already_open

		jsr     OpenEditWindow
		tst.l   d0
		bne.s   .close

.already_open   move.l  dos_base,a6

		lea     Date_Time,a0
		movem.l fi_Date(a4),d0-d2
		movem.l d0-d2,(a0)

		move.l  a0,d1
		call    DateToStr

		move.l  gad_base,a6
		move.l  EditWnd,a5

		move.l  FileGadget,a0           ; File
		move.l  a5,a1
		lea     Text_tag,a3
		lea     fi_Name(a4),a2
		move.l  a2,4(a3)
		cladd   a2
		call    GT_SetGadgetAttrsA

		move.l  DiskGadget,a0           ; Disk
		move.l  a5,a1
		lea     Text_tag,a3
		lea     fi_Disk(a4),a2
		move.l  a2,4(a3)
		cladd   a2
		call    GT_SetGadgetAttrsA

		move.l  PathGadget,a0           ; Path
		move.l  a5,a1
		lea     Text_tag,a3
		lea     fi_Drawer(a4),a2
		move.l  a2,4(a3)
		cladd   a2
		call    GT_SetGadgetAttrsA

		move.l  DateGadget,a0           ; Date
		move.l  a5,a1
		lea     Text_tag,a3
		move.l  #FileDate,4(a3)
		cladd   a2
		call    GT_SetGadgetAttrsA

		move.l  SizeGadget,a0           ; Size
		move.l  a5,a1
		lea     Num_tag,a3
		move.l  fi_Size(a4),4(a3)
		cladd   a2
		call    GT_SetGadgetAttrsA

		move.l  CommentGadget,a0                ; Comment
		move.l  a5,a1
		lea     Str_tag,a3
		lea     fi_Comment(a4),a2
		move.l  a2,4(a3)
		cladd   a2
		call    GT_SetGadgetAttrsA

		bsr     AttivaComment

		clr.b   EditQuit

.little_loop    move.l  4,a6
		move.l  EditWnd,a0
		move.l  wd_UserPort(a0),a0
		call    WaitPort
		jsr     HandleEditIDCMP
		move.b  EditQuit,d6
		beq.s   .little_loop

		cmp.b   #1,d6   ; Annullato?
		beq.s   .close  ; esci...
		bgt.s   .delete

		bclr    #SAVED,MainFlags

		move.l  CommentGadget,a0                ; copio il commento
		move.l  gg_SpecialInfo(a0),a0
		move.l  si_Buffer(a0),a0
		lea     fi_Comment(a4),a1
		strcopy a0,a1

		lea     fi_Name(a4),a0  ; risistemo la linea che
		lea     fi_Disk(a4),a1  ; appare nel listview
		lea     fi_Comment(a4),a2
		movem.l a0-a2,Show_args

		lea     File_fmt,a0
		lea     Show_args,a1
		lea     putch(pc),a2
		lea     fi_Show(a4),a3
		move.l  4,a6
		call    RawDoFmt

		move.b  #'×',fi_Show(a4)

		bra.s   .big_loop

.delete         move.l  (a4),a5

		move.l  a4,a1
		REMOVE

		move.l  4,a6
		move.l  a4,a1
		move.l  #fi_SIZEOF,d0
		call    FreeMem

		move.l  a5,a4
		tst.l   (a4)
		bne.s   .big_loop_entry2

.close          jsr     CloseEditWindow

		move.l  gad_base,a6
		move.l  MainWnd,a0
		cladd   a1
		call    GT_RefreshWindow

		popm.l  d0-d7/a0-a6
CommentClicked  rts




**
**  Routines associate ai pulsanti della finestra Edit
**
**

ED_OkClicked    st      EditQuit
		rts

ED_CancelClicked        move.b  #1,EditQuit
		rts

ED_DelClicked   move.b  #2,EditQuit
		rts


**
**  Gestore dei vanilla key della finestra "Edit file data"
**
**

EditVanillaKey  move.w  im_Code(a5),d0

		cmp.b   #13,d0
		beq.s   ED_OkClicked

		cmp.b   #27,d0
		beq.s   ED_CancelClicked

		or.b    #$20,d0

		cmp.b   #'o',d0
		beq.s   ED_OkClicked

		cmp.b   #'d',d0
		beq.s   ED_DelClicked

		cmp.b   #'a',d0
		beq.s   ED_CancelClicked

		cmp.b   #'c',d0
		beq.s   AttivaComment

		rts

AttivaComment   pushm.l d1/a0-a2/a6
		move.l  int_base,a6
		move.l  CommentGadget,a0
		move.l  EditWnd,a1
		cladd   a2
		call    ActivateGadget
		popm.l  d1/a0-a2/a6
		rts




**************************************************************************
*                     R O U T I N E S   V A R I E                        *
**************************************************************************


**
**  Centra la finestra nella finestra principale
**  a0 = ^WTags
**

LayoutWindow    pushm.l d0-d2/a0-a3
		move.l  MainWnd,a1
		movem.w wd_Width(a1),d0-d1
		sub.w   WT_WIDTH(a0),d0
		lsr.w   #1,d0
		sub.w   WT_HEIGHT(a0),d1
		lsr.w   #1,d1
		add.w   wd_LeftEdge(a1),d0
		add.w   wd_TopEdge(a1),d1
		move.w  d0,WT_LEFT(a0)
		move.w  d1,WT_TOP(a0)
		popm.l  d0-d2/a0-a3
		rts



**
**  Attiva l'ASL File Requester
**  a0 = ^ .ext | NULL
**

GetFile         pushm.l d1-d3/a0-a2/a5-a6
		move.l  a0,d1
		beq.s   .no_file_
		lea     InitialFile,a1
		tst.b   (a1)
		beq.s   .no_file_
.ext_loop       move.b  (a1)+,d1
		beq.s   .punto
		cmp.b   #'.',d1
		beq.s   .dopo_punto
		bra.s   .ext_loop
.punto          move.b  #'.',-1(a1)
.dopo_punto     strcopy a0,a1

.no_file_       move.l  asl_base,a6

		lea     Asl_tags,a0

		move.l  Scr,a1                 ; sistemo l'altezza del
		move.w  sc_Height(a1),d0       ; requester
		sub.w   #40,d0
		move.w  d0,asl_height+2-Asl_tags(a0)

		moveq   #ASL_FileRequest,d0
		call    AllocAslRequest
		tst.l   d0
		beq     RequestError
		move.l  d0,a5

		move.l  a5,a0
		lea     Asl_tags3,a1
		call    AslRequest
		move.l  d0,d7
		bne.s   .ok

		move.l  dos_base,a6
		call    IoErr
		tst.l   d0
		beq.s   .LiberaAsl

		bra.s   RequestError

.ok             lea     Asl_tags,a1

		move.w  fr_LeftEdge(a5),asl_left+2-Asl_tags(a1)
		move.w  fr_TopEdge(a5),asl_top+2-Asl_tags(a1)
		move.w  fr_Width(a5),asl_width+2-Asl_tags(a1)
		move.w  fr_Height(a5),asl_height+2-Asl_tags(a1)

		move.l  fr_Pattern(a5),a0
		move.l  asl_pattern,a1
		moveq   #24,d0
.copy_pat       move.b  (a0)+,(a1)+
		beq.s   .pat_copied
		dbra    d0,.copy_pat

		clr.b   (a1)

.pat_copied     move.l  fr_File(a5),a1
		move.l  a1,d2
		lea     InitialFile,a2
		strcopy a1,a2

		move.l  fr_Drawer(a5),a1
		lea     InitialDrawer,a2
		strcopy a1,a2

		move.l  fr_Drawer(a5),a1
		lea     AllPath,a2
		move.l  a2,a3
		move.l  a2,d1
		strcopy a1,a2

		move.l  dos_base,a6

		move.l  #300,d3
		call    AddPart

.LiberaAsl      move.l  asl_base,a6
		move.l  a5,a0
		call    FreeAslRequest

		moveq   #-1,d0

EsciGetFile     popm.l  d1-d3/a0-a2/a5-a6
		rts

RequestError    stat    NoAsl_txt
		beep
		moveq   #0,d0
		bra.s   EsciGetFile



**
**  Conta i nodi di una lista
**  a0 = Lista
**

CountNodes      push.l  a0
		cldat   d0
.loop           TSTNODE a0,a0
		beq.s   .quit
		inc.l   d0
		bra.s   .loop
.quit           pop.l   a0
		rts



**
**  Decritta l'header degli export
**
**

DecryptHeader   pushm.l d0-d1/a0
		move.w  #Header_len-1,d0
		lea     Header_txt,a0
.loop           move.b  (a0),d1
		bclr    #7,d1
		bchg    #2,d1
		move.b  d1,(a0)+
		dbra    d0,.loop
		popm.l  d0-d1/a0
		rts



**************************************************************************
*                               D A T I                                  *
**************************************************************************


Date_Time       ds.l 3
		dc.b FORMAT_DOS,0
		ds.l 1
		dc.l FileDate
		ds.l 1



FiltersList     dc.l FiltersList+4,0,FiltersList

ViewList        dc.l ViewList+4,0,ViewList

FindList        dc.l FindList+4,0,FindList

DataList        dc.l DataList+4,0,DataList



Asl_tags3       dc.l ASLFR_InitialFile
asl_file        dc.l InitialFile,ASLFR_InitialDrawer
asl_drawer      dc.l InitialDrawer,ASLFR_InitialPattern
asl_pattern     dc.l 0
		dc.l TAG_END

Asl_tags2       dc.l ASLFR_DrawersOnly,-1

Asl_tags        dc.l ASLFR_Window,0,ASLFR_SleepWindow,-1
		dc.l ASLFR_DoPatterns,-1,ASLFR_TitleText
asl_title       dc.l 0,ASLFR_InitialLeftEdge
asl_left        dc.l 0,ASLFR_InitialTopEdge
asl_top         dc.l 0,ASLFR_InitialWidth
asl_width       dc.l 300,ASLFR_InitialHeight
asl_height      dc.l 300,ASLFR_RejectIcons,-1,ASLFR_DoSaveMode
		ds.b 3
savemode        ds.b 1
		dc.l TAG_END


req_tags        dc.l RTEZ_Flags,EZREQF_CENTERTEXT
req_tags2       dc.l RT_ReqPos,REQPOS_CENTERWIN,RT_Window
req_win         dc.l 0,RT_LockWindow,-1,RT_Underscore,'_'
		dc.l TAG_END

drive_menus     dc.l (2<<11)!(5<<5)!1,(3<<11)!(5<<5)!1,(4<<11)!(5<<5)!1

SortMenus       dc.l (12<<5)!2,(2<<11)!(12<<5)!2,(3<<11)!(12<<5)!2
		dc.l (1<<11)!(12<<5)!2

Text_tag        dc.l GTTX_Text,0,TAG_END
Num_tag         dc.l GTNM_Number,0,TAG_END
Str_tag         dc.l GTST_String,0,TAG_END
List_tag2       dc.l GTLV_Top,0,GTLV_Selected,0
List_tag        dc.l GTLV_Labels,0,TAG_END
Check_tag       dc.l GTCB_Checked,0,TAG_END

Gadgets_tab     dc.w GD_Open,GD_Export,GD_Edit,GD_Find
		dc.w GD_Sort,GD_Move,GD_Parent,GD_Root
		dc.w GD_Status

GADS_TAB_LEN    equ (*-Gadgets_tab)>>1

Help_tab        dc.l Load_hlp,Export_hlp,Edit_hlp,Find_hlp
		dc.l Sort_hlp,Move_hlp,Parent_hlp,Root_hlp
		dc.l Version

Drives          dc.l df0_txt2,df1_txt2,df2_txt2,df3_txt2

SortRoutines    dc.l OrderNameMenued,SortDiskMenued
		dc.l OrderDateMenued,OrderSizeMenued


gad_name        dc.b 'gadtools.library',0
int_name        dc.b 'intuition.library',0
dos_name        dc.b 'dos.library',0
req_name        dc.b 'reqtools.library',0
uti_name        dc.b 'utility.library',0
asl_name        dc.b 'asl.library',0
ico_name        dc.b 'icon.library',0
gfx_name        dc.b 'graphics.library',0

PrefsFile       dc.b 'S:DiskOrg.prefs',0

Template        dc.b 'FILE,PUBSCREEN/K',0
FileToolType    dc.b 'FILENAME',0
ScreenToolType  dc.b 'PUBSCREEN',0

Version         dc.b '$VER: DiskOrg 1.4 (19.9.96) by Simone Tellini',0


DiskOrg_ext     dc.b 'do',0
Txt_ext         dc.b 'txt',0

Data_pat        dc.b '#?.do',0
		ds.b 20

Export_pat      dc.b '#?.txt',0
		ds.b 20

Header          dc.b 'DskO'

ok_txt          dc.b '_Ok',0
about_txt       dc.b 'Disk Organiser - ©1995-1996 by Simone Tellini Software',10,10
		dc.b 'Compiled using PhxAss 4.22 by Frank Wille',10,10
		dc.b 'GUI designed with Interface Editor by... me! ;)',10,10
		dc.b 'reqtools.library is © Copyright by Nico François',10,10
		dc.b 'This is SHAREWARE, NOT PD!  See docs for details.',0

not_saved_txt   dc.b 'Some changes have been made!',10
		dc.b 'Do  you  want  to save them?',0
yes_no_canc_txt dc.b '_Yes|_No|_Cancel',0


Ready_txt       dc.b 'Ready.',0
Saving_txt      dc.b 'Saving...',0
Loading_txt     dc.b 'Loading...',0
Scanning_txt    dc.b 'Scanning directories...',0
Searching_txt   dc.b 'Searching...',0
NoFileFound_txt dc.b 'No file found.',0
Exporting_txt   dc.b 'Export in progress...',0

Cancel_txt      dc.b 'Operation aborted.',0

Load_hlp        dc.b 'Load a database...',0
Export_hlp      dc.b 'Export selected field(s)...',0
Edit_hlp        dc.b 'View the selected item(s)...',0
Find_hlp        dc.b 'Search file(s)...',0
Sort_hlp        dc.b 'Change sort criteria.',0
Move_hlp        dc.b 'Move file(s) between categories...',0
Parent_hlp      dc.b 'Parent category.',0
Root_hlp        dc.b 'Root category.',0

Quit_hlp        dc.b 'Quit Disk Organiser.',0
Zoom_hlp        dc.b 'Zoom my window.',0
Depth_hlp       dc.b 'Depth-arrange my window.',0
Drag_hlp        dc.b 'Move my window.',0
Size_hlp        dc.b 'Resize my window.',0


Uncataloged_txt dc.b '»»  Uncataloged',0

File_new_fmt    dc.b '  %%-%d.%ds   %%-%d.%ds   %%-s',0

File_fmt        dc.b '  %-15.15s   %-10.10s   %-s',0
		ds.b 10

TitoloCat_txt   dc.b 'Enter the title of the category...',0
EnterPattern_txt        dc.b 'Enter a pattern...',0
SelectVolume_txt        dc.b 'Select a VOLUME to scan...',0
SaveAs_txt      dc.b 'Save file as...',0
Load_txt        dc.b 'Select the file to load...',0
GetView_txt     dc.b 'Select a viewer...',0
EditFilter_txt  dc.b 'Edit filter...',0
Export_txt      dc.b 'Export fields...',0

ScanError_txt   dc.b "I/O Error while reading the disk!",0
MemIns_txt      dc.b "Out of memory!",0
NoAsl_txt       dc.b "Couldn't allocate an ASL file requester!",0
IOError_txt     dc.b "I/O Error!",0
CantOpenFile_txt        dc.b "Couldn't open the file!",0
NotMyfile_txt   dc.b "This file hasn't been created by DiskOrg!",0
NoWindow_txt    dc.b "Unable to open the window!",0


		IFND    REGISTERED

Header_txt      incbin /src/diskorg/Header.bin
Header_len      EQU     *-Header_txt

		ELSE

Header_txt      incbin /src/diskorg/Header_REG.bin
Header_len      EQU     *-Header_txt

		ENDC


Category_fmt    dc.b 10,10,"        CATEGORY:  %s"
CRCR            dc.b 10
CR              dc.b 10,0

Name_fmt        dc.b "File name :  %s",10,0
Disk_fmt        dc.b "Disk      :  %s",10,0
Path_fmt        dc.b "Path      :  %s",10,0
Date_fmt        dc.b "Date      :  %s",10,0
Size_fmt        dc.b "Size      :  %ld",10,0
Comment_fmt     dc.b "Comment   :  %s",10,0


df1_txt         dc.b 'df1',0
df2_txt         dc.b 'df2',0
df3_txt         dc.b 'df3'
null            dc.b 0

df0_txt2        dc.b 'df0:',0
		ds.b 6
df1_txt2        dc.b 'df1:',0
		ds.b 6
df2_txt2        dc.b 'df2:',0
		ds.b 6
df3_txt2        dc.b 'df3:',0
		ds.b 6


OtherViewer     dc.b 'MultiView',0
		ds.b 120-9

		dc.b '>"'
OutWin          dc.b 'CON:0/20/640/150/DiskOrg: Viewing a file.../AUTO/WAIT/CLOSE',0
		ds.b 55



MainFlags       dc.b (1<<SAVED)!(1<<AUTOSCAN)!(1<<RECURSE)!(1<<SEARCHBYCOM)!(1<<SEARCHBYDISK)


ExChecks        dc.b EX_NAME,EX_DISK,EX_PATH,EX_DATE
		dc.b EX_SIZE,EX_COMMENT,EX_CATEGORY

ExportFields    dc.b -1


		SECTION DataSpace,BSS


		XDEF    gad_base
		XDEF    int_base
gad_base        ds.l 1
int_base        ds.l 1
dos_base        ds.l 1
req_base        ds.l 1
uti_base        ds.l 1
asl_base        ds.l 1
ico_base        ds.l 1
gfx_base        ds.l 1

old_WindowPtr   ds.l 1

MyTask          ds.l 1

CurrentCat      ds.l 1

Uncat           ds.l 1

NodeID          ds.l 1

Show_args       ds.l 3

From            ds.l 1
To              ds.l 1

		cnop 0,4
fib             ds.b fib_SIZEOF

NumDrives       ds.w 1          ; numero drive - 1

Ticks           ds.w 1

NumViewers      ds.w 1          ; numero visualizzatori
NumFilters      ds.w 1          ; numero filtri

df0             ds.b 1          ; c'è il disco?
df1             ds.b 1
df2             ds.b 1
df3             ds.b 1

ScreenName      ds.b 256

DiskName        ds.b 40

DirName         ds.b 300

SelectPattern   ds.b 30
TokenPattern    ds.b 62

ScanDrawer      ds.b 256

FilterBuffer    ds.b 62

InitialFile     ds.b 30
InitialDrawer   ds.b 200
AllPath         ds.b 300

CatBuffer       ds.b 500

FileDate        ds.b LEN_DATSTRING

SortCrit        ds.b 1

QuitPrg         ds.b 1
EditQuit        ds.b 1
FindQuit        ds.b 1
MoveQuit        ds.b 1
SearchQuit      ds.b 1

		END
