hsk-libs-scripts  270
High Speed Karlsruhe XC878 build scripts
Functions
xml.awk File Reference

This script provides a small command line XML editor. More...

Functions

void filter34 ()
 Parse arguments and initialise globals. More...
 
var empty (var array)
 Return whether an array is empty. More...
 
var explode (var str, var results)
 Split a string containing attributes into a string array with "attribute=value" entries. More...
 
var escape (var str)
 Escapes quotation marks and backslashes with backslashes. More...
 
void cmdSelect (var str)
 This function lets you define a selection. More...
 
void cmdSearch (var str)
 This function selects any subtree of the current selection that matches the given selection filter. More...
 
void cmdSet (var value)
 Changes the content of a node. More...
 
void cmdRename (var name)
 Changes the tag name of a node. More...
 
void cmdAttrib (var str)
 Changes an attribute of a node. More...
 
void cmdRenameAttrib (var str)
 Changes the name of an attribute. More...
 
void cmdInsert (var str)
 Inserts new nodes into all selected nodes, uses the same syntax as cmdSelect() does. More...
 
void cmdSelectInserted ()
 Select the nodes created during the last insert operation. More...
 
void cmdDelete ()
 Unhooks a selected node from the tree, it's still there and can be navigated out of by selecting "..". More...
 
void cmdDeleteAttrib (var name)
 Deletes a named attribute. More...
 
void cmdPrint ()
 Print the current selection. More...
 
void printNode (var indent, var node)
 Prints children and contents of the given node. More...
 
void filter567 ()
 Parse the XML tree. More...
 
void filter631 ()
 Execute the specified commands. More...
 

Detailed Description

This script provides a small command line XML editor.

It parses the subset of XML used by ARM Keil µVision configuration files and provides arguments to navigate, search, edit and print the parsed XML tree.

Every command applies to the current selection. The current selection may refer to several nodes in the tree.

The command syntax is: "-" command [ ":" argument ]

The following command line arguments are supported:

Command Function Description
select cmdSelect() Selects a path using a filter argument
search cmdSearch() Selects all the subtrees matching the given filter argument
set cmdSet() Sets the data of a node
rename cmdRename() Changes the tag name of a node
attrib cmdAttrib() Sets a named attribute
renameAttrib cmdRenameAttrib() Renames an attribute
insert cmdInsert() Inserts a new child node into the selected nodes
selectInserted cmdSelectInserted() Select all nodes created during the last insert operation
delete cmdDelete() Removes the selected nodes from the tree
deleteAttrib cmdDeleteAttrib() Removes an attribute from the selected nodes
print cmdPrint() Print the children and data of the selected nodes

Function Documentation

§ filter34()

void filter34 ( )

Parse arguments and initialise globals.

Precondition
BEGIN  

§ empty()

var empty ( var  array)

Return whether an array is empty.

Parameters
arrayThe array to check
Return values
1The array is empty
0The array contains at least one element

§ explode()

var explode ( var  str,
var  results 
)

Split a string containing attributes into a string array with "attribute=value" entries.

Parameters
strThe string to split into attributes
resultsThe array to store the results in
Returns
The count of attributes

§ escape()

var escape ( var  str)

Escapes quotation marks and backslashes with backslashes.

Parameters
strThe string to escape
Returns
The escaped string

§ cmdSelect()

void cmdSelect ( var  str)

This function lets you define a selection.

A selection filter is a series of node defintions divided by /. Identifiers may contain glob patterns.

A / at the beginning of the filter selects the root node, which contains the root nodes of all XML trees parsed. Other wise the filter is relative to the current selections.

The node ./ refers to the current node and ../ to the parent node. This can be used to move through the tree relative to the current selection or to select the parent of a node that matches a filtering condition.

A node selection has the following syntax: node = tag [ "[" attributes "]" ] [ "=" value ]

Attributes have the following syntax: attributes = attribute "=" ( value | '"' value '"' ) [ " " attributes ]

Values are strings or glob patterns.

Parameters
strThe selection filter

§ cmdSearch()

void cmdSearch ( var  str)

This function selects any subtree of the current selection that matches the given selection filter.

The filter syntax is identical with that of cmdSelect().

Parameters
strThe selection filter

§ cmdSet()

void cmdSet ( var  value)

Changes the content of a node.

This does not affect subnodes.

Parameters
valueThe value to set the node content to

§ cmdRename()

void cmdRename ( var  name)

Changes the tag name of a node.

Parameters
nameThe new tag name

§ cmdAttrib()

void cmdAttrib ( var  str)

Changes an attribute of a node.

It accepts a singe string in the shape: attribute "=" value

Parameters
strA single attribute definition

§ cmdRenameAttrib()

void cmdRenameAttrib ( var  str)

Changes the name of an attribute.

If the original attribute does not exist the new one will be added.

If an attribute with the new name already exists it will be overwritten.

It accepts a singe string in the shape: oldname "=" newname

Parameters
strA single attribute renaming instruction

§ cmdInsert()

void cmdInsert ( var  str)

Inserts new nodes into all selected nodes, uses the same syntax as cmdSelect() does.

Parameters
strA node definition like the ones used for selection filters

§ cmdSelectInserted()

void cmdSelectInserted ( )

Select the nodes created during the last insert operation.

§ cmdDelete()

void cmdDelete ( )

Unhooks a selected node from the tree, it's still there and can be navigated out of by selecting "..".

§ cmdDeleteAttrib()

void cmdDeleteAttrib ( var  name)

Deletes a named attribute.

Parameters
nameThe name of the attribute to remove

§ cmdPrint()

void cmdPrint ( )

Print the current selection.

§ printNode()

void printNode ( var  indent,
var  node 
)

Prints children and contents of the given node.

Parameters
indentThe indention depth of the current node
nodeThe node to print

§ filter567()

void filter567 ( )

Parse the XML tree.

Abbreviations:

  • d = depth
  • c = count

Properties:

  • tags [d, c]
  • contents [d, c]
  • attributeNames [d, c, i]
  • attributeValues [d, c, i]
  • children [d, c, i]
  • parent [d, c]

§ filter631()

void filter631 ( )

Execute the specified commands.

Precondition
END