<?xml version="1.0" ?>

<Define> ^cur-dir <GetCwd /> </Define>
<PrintStd> ^cur-dir </PrintStd>
<If> (= (CutString cur-dir (- (StringLength cur-dir) 1) 1) "/")
<Else>
<set> ^cur-dir (+ cur-dir "/") </set>
</Else>
</If>
<Define Order="Applicative"> ^GetUserInfo
   ()
   <Arguments>^path ^agent ^ltype ^cmd </Arguments>
   <Switch>
   <Case> (= cmd "ip")
	(List (GetLocalHostIP))
   </Case>
   <Case> (= cmd "user")
	server
   </Case>
   <Case> (= cmd "passwd")
	abc
   </Case>
   </Switch>
</Define>
<Load option="exec"> xlconf/std/agent.xl </Load>
<Load option="exec"> xlscript/std/agent.prefix.xl </Load>
<Load option="exec"> xlscript/gbs/meta.xl </Load>
<Load option="exec"> xlscript/gbs/map.xl </Load>

<If> (Not (= (CutString cur-dir 0 (+ (StringLength docs-root) 1))
		(+ docs-root "/")))
<Then>
<Define> ^target-path ^"" </Define>
</Then>
<Else>
<Define> ^target-path (CutString cur-dir (+ (StringLength docs-root) 1)
				(StringLength cur-dir))
</Define>
</Else>
</If>

<PrintStd> ^target-path </PrintStd>

<Define> ^docs (+  "xldocs/" target-path) </Define>
<Define> ^sys (+ "xlsys/" target-path) </Define>

(PrintStd docs)

<Chdir> ^DatabaseRoot </Chdir>

<Rule target="1by1">
	<Accept> (+ docs "**/*.crd") </Accept>
	<Accept> (+ docs "*.crd") </Accept>
	<Define> ^to (+ "xlsys/" (Leaf 1 from) ".mta") </Define>
	<Define> ^dir (Leaf 1 (Directory from)) </Define>
	<Target dir="make" mode="0755"> ^to ^from </Target>
	<PrintStd>(+ from "" to)</PrintStd>
	<Load option="exec"> ^from </Load>
	<Sequence> ()
		<Define> ^ses (OpenSession) </Define>
		<RemoteSession> ^ses
			<URL> (+ "xlp://localhost:" ServerPort "/")
			</URL>
			<Agent> gbstd </Agent>
			<Command> Get </Command>
			([MPTrigger mode="force"] (Local (Leaf 1 from)))
		</RemoteSession>
		(CloseSession ses)
	</Sequence>
</Rule>

<Rule target="1by1">
	<Accept> (+ docs "**/*.crd") </Accept>
	<Accept> (+ docs "**/*.lst") </Accept>
	<Accept> (+ docs "**/*.vct") </Accept>
	<Accept> (+ docs "*.crd") </Accept>
	<Accept> (+ docs "*.lst") </Accept>
	<Accept> (+ docs "*.vct") </Accept>
	<Define> ^to (+ "xlsys/" (Leaf 1 from) ".par") </Define>
	<Define> ^dir (Leaf 1 (Directory from)) </Define>
	<Target dir="make" mode="0755"> ^to ^from </Target>
	<Touch> ^to </Touch>
</Rule>

<Rule target="1by1">
	<Accept> (+ docs "**/*.crd") </Accept>
	<Accept> (+ docs "*.crd") </Accept>
	<Define> ^to (+ "xlsys/" (Leaf 1 from) ".chi") </Define>
	<Define> ^dir (Leaf 1 (Directory from)) </Define>
	<Target dir="make" mode="0755"> ^to ^from </Target>
	<Touch> ^to </Touch>
</Rule>


<Rule target="1by1">
	<Accept> (+ docs "**/*.lst") </Accept>
	<Accept> (+ docs "*.lst") </Accept>
	<Define> ^to (+ "xlsys/" (Leaf 1 from) ".mta") </Define>
	<Define> ^dir (Leaf 1 (Directory from)) </Define>
	<Target dir="make" mode="0755"> ^to ^from </Target>
	<PrintStd>(+ from " " to)</PrintStd>
	<Load option="exec"> ^from </Load>
</Rule>


<Rule target="1by1">
	<Accept> (+ docs "**/*.vct") </Accept>
	<Accept> (+ docs "*.vct") </Accept>
	<Define> ^to (+ "xlsys/" (Leaf 1 from) ".mta") </Define>
	<Define> ^dir (Leaf 1 (Directory from)) </Define>
	<Target dir="make" mode="0755"> ^to ^from </Target>
	<PrintStd>(+ from " " to)</PrintStd>
	<Load option="exec"> ^from </Load>
</Rule>

<Rule target="1by1">
	<Accept> (+ docs "**/*.map") </Accept>
	<Accept> (+ docs "*.map") </Accept>
	<Define> ^to (+ "xlsys/" (Leaf 1 from) ".sts") </Define>
	<Define> ^dir (Leaf 1 (Directory from)) </Define>
	<Target dir="make" mode="0755"> ^to ^from </Target>
	<Save option="xl" oflag="creat:trunc" mode="0644"> ^to
		<quote>
			<status> new </status>
		</quote>
	</Save>
</Rule>


<Rule target="1by1">
	<Accept> (+ docs "**/*.map") </Accept>
	<Accept> (+ docs "*.map") </Accept>
	<Define> ^to (+ "xlsys/" (Leaf 1 from) ".mta") </Define>
	<Define> ^dir (Leaf 1 (Directory from)) </Define>
	<Target dir="make" mode="0755"> ^to ^from </Target>
	<PrintStd>(+ from " " to)</PrintStd>
	<Load option="exec"> ^from </Load>
	<MapResistration> ^to </MapResistration>
</Rule>


<!-- delete operation -->

<Define> ^ses <OpenSession/> </Define>

<Rule target="1by1">
	<Accept> (+ sys "**/*.map.mta") </Accept>
	<Accept> (+ sys "*.map.mta") </Accept>
	<Define> ^to (+ "xldocs/" (Trunc (Leaf 1 from) ".mta")) </Define>
	<NotExist> ^to </NotExist>

	<Define> ^map (+ "xlp://localhost:" ServerPort "/" (Leaf 1 to))
	</Define>
	<PrintStd> ^map </PrintStd>

	<RemoteSession> ^ses
		<URL> ^map </URL>
		<Command> Get </Command>
		<MPTrigger mode="delete">
			(Local (+ SessionPath SessionResource))
		</MPTrigger>
	</RemoteSession>
</Rule>


<Rule target="1by1">
	<Accept> (+ sys "**/*.mta") </Accept>
	<Accept> (+ sys "*.mta") </Accept>
	<Define> ^to (+ "xldocs/" (Trunc (Leaf 1 from) ".mta")) </Define>
	<NotExist> ^to </NotExist>
	<Rm> ^from </Rm>
</Rule>

<Rule target="1by1">
	<Accept> (+ sys "**/*.mpt") </Accept>
	<Accept> (+ sys "*.mpt") </Accept>
	<Define> ^to (+ "xldocs/" (Trunc (Leaf 1 from) ".mpt")) </Define>
	<NotExist> ^to </NotExist>
	<Rm> ^from </Rm>
</Rule>

<Rule target="1by1">
	<Accept> (+ sys "**/*.par") </Accept>
	<Accept> (+ sys "*.par") </Accept>
	<Define> ^to (+ "xldocs/" (Trunc (Leaf 1 from) ".par")) </Define>
	<NotExist> ^to </NotExist>
	<Rm> ^from </Rm>
</Rule>

<Rule target="1by1">
	<Accept> (+ sys "**/*.chi") </Accept>
	<Accept> (+ sys "*.chi") </Accept>
	<Define> ^to (+ "xldocs/" (Trunc (Leaf 1 from) ".chi")) </Define>
	<NotExist> ^to </NotExist>
	<Rm> ^from </Rm>
</Rule>

<Rule target="1by1">
	<Accept> (+ sys "**/*.sts") </Accept>
	<Accept> (+ sys "*.sts") </Accept>
	<Define> ^to (+ "xldocs/" (Trunc (Leaf 1 from) ".sts")) </Define>
	<NotExist> ^to </NotExist>
	<Rm> ^from </Rm>
</Rule>

<Rule target="1by1">
	<Accept> (+ sys "**/*.lmp") </Accept>
	<Accept> (+ sys "*.lmp") </Accept>
	<Define> ^to (+ "xldocs/" (Trunc (Leaf 1 from) ".lmp")) </Define>
	<NotExist> ^to </NotExist>
	<Rm> ^from </Rm>
</Rule>

