
! script name: archive.d/archtreetable
! topic: make a table from the archive directory tree.

!A
!A NAME:
!A
!A 	make a table from the archive directory tree
!A
!A DESCRIPTION:
!A
!A
!B INSTRUCTIONS:
!B
!B
!# see also - htdocs/help.d/archive.htm

DIM Answer$[256],Destination$[256]
DIM Archive$[512]
DIM Filename$[512]
DIM A$[512]
DIM B$[512]
DIM Table_name$[512]
DIM Table_title$[512]

DeActivateUndo
Html_table= 0
IF ARGC > 1 THEN
        Answer$= ARGV(1)
        Html_table= VAL(Answer$)
END IF

Table_name$= "ARCHIVE TABLE"
Table_title$= "ARCHIVE TABLE"

Stat=ChangeLabelStr("ScriptNameStatus","Function: directory tree table ")

Stat= NamedVarStr("archive dir",WsSystemVars,"/usr/weber/archive/",Archive$)
Filename$= "tempdata"

File_type=3
List_type=2
Tab$= CHR$(9)
Suffix$= ".d"

Grid_color= 18
Entry_color= 12
Entry_text_height= GetDefault(WsTextHeight)
Entry_text_width= GetDefault(WsTextWidth)

Sub_color= 10
Dir_color= 17
Dir_text_height= 1.2*Entry_text_height
Dir_text_width= 1.2*Entry_text_width
Dir_slant= TAN(20)

Table_pos:!
IF Html_table THEN
        Pc= PointXYZ(0,0,0)
ELSE
        Stat=SetInputFormat("n4","")
        Pc=XyzInput("TABLE LOCATION ",WsXyzInput)
        IF (ExitScript(Destination$)) THEN Leave
        IF NOT ValidGeometry(Pc) THEN Table_pos
END IF

Table1= FindNamedEntity(Table_name$)
IF Table1 THEN Stat= DeleteEntity(Table1)

PlotOff
Stat= DirTreeListFile(Archive$,Filename$,List_type,File_type)
Table1= ImportTable(Filename$,Pc,WsUpperLeft,Tab$)
Stat= DeleteEntity(Pc)

Set_table_props:!
Nrows= NumberTableRows(Table1)
Ncols= NumberTableCols(Table1)
Stat= TableTextOrigin(Table1,0,0,WsCenterText)
Stat= SetTableColors(Table1,0,0,Entry_color)
Stat= SetTableColors(Table1,0,1,Dir_color)
Stat= SetColor(Table1,Grid_color)

Color_subs:!
FOR I=1 TO Nrows
FOR J=1 TO Ncols
	A$= TableEntryStr(Table1,I,J)
	N= LEN(A$)
	IF N> 2 THEN
		B$= A$[N-1,N]
		IF B$= Suffix$ THEN
			Stat= TableTextSizes(Table1,I,J,Dir_text_width,Dir_text_height,Dir_slant)
			Stat= SetTableColors(Table1,I,J,Sub_color)
		END IF
	END IF
NEXT J
NEXT I
Stat= TableTextSizes(Table1,0,1,Dir_text_width,Dir_text_height,Dir_slant)
Stat= SetTableColors(Table1,0,1,Dir_color)
Stat= NameEntity(Table1,Table_name$)
PlotOn

IF Html_table THEN
        LOAD "datatable.d/exporthtml: 0,"&Table_name$&",1,"&Table_title$
ELSE
        Stat= PlotEntity(Table1)
END IF

Leave:!
PlotOn
Stat=SetInputFormat("n4","")
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
