"Fossies" - the Fresh Open Source Software Archive

Member "KASH3-lib-archindep-2008-07-31/lib/XML.g" (3 Sep 2008, 6129 Bytes) of package /linux/misc/old/KASH3-lib-archindep-2008-07-31.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 if not(IsBound(xml)) then
    2   NewType("xml",0);
    3 fi;
    4 
    5 _PrintXML:=
    6   function(xml)
    7     Print("XML Data Structure");
    8   end;
    9 
   10 ## initialise an XML tree structure
   11 InitialiseXML:=
   12   function(arg)
   13     local rootelm;
   14     CheckArgs(arg,["rootelm"],["xml"]);
   15     rootelm:=__ARGREC.("rootelm");
   16     
   17     return
   18       rec(
   19         root:=rootelm,
   20         type:=xml,
   21         operations:=
   22           rec(
   23             Print:=_PrintXML)
   24         );
   25   end;
   26 
   27 AttachRootElement:=
   28   function(xml,elm)
   29     ##
   30     return xml;
   31   end;
   32 
   33 AttachElement:=
   34   function(xml,elm)
   35     ##
   36     return xml;
   37   end;
   38 
   39 PrintDocumentationAsXML:=
   40   function(hash)
   41     local xmlout;
   42     xmlout:=InitialiseXML;
   43     return xmlout;
   44   end;
   45 
   46 
   47 _QuoteStringForXML:=
   48   function(strin)
   49     strin:=
   50       Replace(strin,"&","&");
   51     strin:=
   52       Replace(strin,"\"",""");
   53     strin:=
   54       Replace(strin,"<","&lt;");
   55     strin:=
   56       Replace(strin,">","&gt;");
   57     strin:=
   58       Replace(strin,"\n","<br/>\n");
   59     return strin;
   60   end;
   61 
   62 ##
   63 ## major XMLise-with-depth functions
   64 PrintWalkedXML:=
   65   function(trec)
   66     local trecf;
   67     if Type(trec)=record then
   68       trecf:=RecFields(trec);
   69       if "kind" in trecf then
   70         Print("<",trec.("kind"),">");
   71         if "node" in trecf then
   72           PrintWalkedXML(trec.("node"));
   73         fi;
   74         Print("</",trec.("kind"),">");
   75       fi;
   76     elif Type(trec)=type then
   77       Print(trec);
   78     elif Type(trec)=list then
   79       Mapc(PrintWalkedXML,trec);
   80     else
   81       Print("unsupported: ",trec,"\n");
   82     fi;
   83   end;
   84 
   85 PrintXMLisedType:=
   86   function(type)
   87     local ttree;
   88     ttree:=TypeToTree(type);
   89     PrintWalkedXML(ttree);
   90   end;
   91 
   92 ## more trivial output routines
   93 
   94 PrintXMLname:=
   95   function(docrec,indent)
   96     Print(indent*" ","<name>",
   97       _QuoteStringForXML(GetEntry(docrec,"name",rec(Fail:="unknown"))),
   98       "</name>\n");
   99   end;
  100 _PrintXMLargs:=
  101   function(sin,indent)
  102     Print(indent*" ","<arg");
  103     if IsBound(sin[2]) then
  104       Print(" name=\"",sin[2],"\"");
  105     fi;
  106     if IsBound(sin[1]) then
  107       Print(" filename=\"",DocHash(SPrint(sin[1])),"\"");
  108     fi;
  109     if IsBound(sin[4]) then
  110       Print(" default=\"",_QuoteStringForXML(SPrint(GetEntry(sin[4],"Default",rec(Fail:="")))),"\"");
  111     fi;
  112     if IsBound(sin[3]) then
  113       Print(" description=\"",_QuoteStringForXML(sin[3]),"\"");
  114     fi;
  115     Print(">\n");
  116     if IsBound(sin[1]) then
  117       Print((indent+2)*" ");
  118       PrintXMLisedType(sin[1]);
  119       Print("\n");
  120     fi;
  121     Print(indent*" ","</arg>\n");
  122   end;
  123 PrintXMLinargs:=
  124   function(docrec,indent)
  125     local sin;
  126     sin:=GetEntry(docrec,"sin");
  127     if IsSuccess(sin) then
  128       Print(indent*" ","<inargs>\n");
  129       Mapc(i->_PrintXMLargs(i,indent+2),sin);
  130       Print(indent*" ","</inargs>\n");
  131     fi;
  132   end;
  133 PrintXMLoutargs:=
  134   function(docrec,indent)
  135     local sou;
  136     sou:=GetEntry(docrec,"sou");
  137     if IsSuccess(sou) then
  138       Print(indent*" ","<outargs>\n");
  139       Mapc(i->_PrintXMLargs(i,indent+2),sou);
  140       Print(indent*" ","</outargs>\n");
  141     fi;
  142   end;
  143 PrintXMLoptargs:=
  144   function(docrec,indent)
  145     local opt;
  146     opt:=GetEntry(docrec,"opt");
  147     if IsSuccess(opt) then
  148       Print(indent*" ","<optargs>\n");
  149       Mapc(i->_PrintXMLargs(i,indent+2),opt);
  150       Print(indent*" ","</optargs>\n");
  151     fi;
  152   end;
  153 PrintXMLsyntax:=
  154   function(docrec,indent)
  155     local syn;
  156     syn:=GetEntry(docrec,"syntax");
  157     if IsSuccess(syn) then
  158       Print(indent*" ","<syntax>\n");
  159       ## fsck have to quote stuff :\
  160       ## < -> &lt;
  161       ## > -> &gt;
  162       Print((2+indent)*" ",_QuoteStringForXML(syn),"\n");
  163       Print(indent*" ","</syntax>\n");
  164     fi;
  165   end;
  166 PrintXMLsignature:=
  167   function(docrec,indent)
  168     Print(indent*" ","<signature>\n");
  169     PrintXMLname(docrec,indent+2);
  170     PrintXMLinargs(docrec,indent+2);
  171     PrintXMLoutargs(docrec,indent+2);
  172     PrintXMLoptargs(docrec,indent+2);
  173     PrintXMLsyntax(docrec,indent+2);
  174     Print(indent*" ","</signature>\n");
  175   end;
  176 
  177 PrintXMLshort:=
  178   function(docrec,indent)
  179     Print(indent*" ","<shortdoc>\n");
  180     Print((2+indent)*" ",_QuoteStringForXML(GetEntry(docrec,"short",rec(Fail:=""))),"\n");
  181     Print(indent*" ","</shortdoc>\n");
  182   end;
  183 _PrintXMLex:=
  184   function(ex,indent)
  185     Print(indent*" ","<example>\n");
  186     Print((2+indent)*" ","<input>\n");
  187     Print((4+indent)*" ",_QuoteStringForXML(ex),"\n");
  188     Print((2+indent)*" ","</input>\n");
  189     Print(indent*" ","</example>\n");
  190   end;
  191 PrintXMLexamples:=
  192   function(docrec,indent)
  193     Print(indent*" ","<examples>\n");
  194     Mapc(i->_PrintXMLex(i,2+indent),GetEntry(docrec,"ex",rec(Fail:=[])));
  195     Print(indent*" ","</examples>\n");
  196   end;
  197 _PrintXMLsee:=
  198   function(see,indent)
  199     if IsSuccess(Assoc(__DOC,see)) then
  200       Print(indent*" ","<see>",see,"</see>\n");
  201     fi;
  202   end;
  203 PrintXMLseealso:=
  204   function(docrec,indent)
  205     Print(indent*" ","<seealso>\n");
  206     Mapc(i->_PrintXMLsee(i,2+indent),GetEntry(docrec,"see",rec(Fail:=[])));
  207     Print(indent*" ","</seealso>\n");
  208   end;
  209 PrintXMLdocumentation:=
  210   function(docrec,indent)
  211     Print(indent*" ","<documentation>\n");
  212     PrintXMLshort(docrec,2+indent);
  213     PrintXMLexamples(docrec,2+indent);
  214     PrintXMLseealso(docrec,2+indent);
  215     Print(indent*" ","</documentation>\n");
  216   end;
  217 
  218 
  219 
  220 PrintXML:=
  221   function(hash)
  222     local docrec,indent;
  223     indent:=2;
  224     docrec:=RetrieveDocumentation(hash);
  225     Print("<record name=\"",hash,"\" kind=\"",docrec.kind,"\">\n");
  226     PrintXMLsignature(docrec,indent);
  227 
  228     PrintXMLdocumentation(docrec,indent);
  229 
  230     Print("</record>\n");
  231   end;
  232 
  233 PrintStruct:=
  234   function(struct,indent)
  235     Print(indent*" ", "<entry hash=\"",struct.main,"\">\n");
  236     if IsBound(struct.sub) then
  237       Mapc(i->PrintStruct(i, 2+indent), struct.sub);
  238     fi;
  239     Print(indent*" ", "</entry>\n");
  240   end;
  241 
  242 DumpXML:=
  243   function(arg)
  244     SizeScreen([255,70]);
  245     Print("\n\n<database>\n\n");
  246     Mapc(PrintXML,__DOC.keys);
  247     Print("\n\n</database>\n");
  248   end;
  249 
  250 ## call like this DumpStruct(kashtut);
  251 DumpStruct:=
  252   function(struct)
  253     SizeScreen([255,70]);
  254     Print("\n\n<struct>\n\n");
  255     PrintStruct(struct,2);
  256     Print("\n\n</struct>\n");
  257   end;
  258 
  259 
  260 #<struct>
  261 #  <main hash="938493">
  262 #    <main