public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Cagney <cagney@redhat.com>
To: Mark Wielaard <mark@klomp.org>
Cc: frysk <frysk@sourceware.org>
Subject: Re: Put refpurposes one line for easy manpage generation.
Date: Thu, 03 Apr 2008 21:03:00 -0000	[thread overview]
Message-ID: <47F4EC2C.7000707@redhat.com> (raw)
In-Reply-To: <1207232684.4284.24.camel@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 1124 bytes --]

Mark,

I'm not fluent in XML either, however I still managed to hack up the 
attached (from htdocs/bugzilla).  Can we do something with that?

Andrew



Mark Wielaard wrote:
> Hi Andrew,
>
> On Thu, 2008-04-03 at 10:09 -0400, Andrew Cagney wrote:
>   
>> Mark Wielaard wrote:
>>     
>>> This puts all refpurpose tags and content on one line for better manpage
>>> generation. Also did an upload-manpages. The currrent script expects
>>> this tag and matching closing tag on one line, if it isn't the
>>> description on the man index page will be empty (if someone knows some
>>> sed foo to make this more flexible that would be appreciated).
>>> http://sourceware.org/frysk/manpages/
>>>       
>> Our man pages are in XML for a reason; surely we can make use of that.  
>> A short script should do it.
>>     
>
> Then instead of someone with sed foo, we are looking for someone with
> some xslt foo :) I am sure both could be used to generate the index
> page, I am just not fluent in either. See common/manpages.sh for the
> current script which currently uses just a simple sed invocation.
>
> Cheers,
>
> Mark
>
>   


[-- Attachment #2: Bug.java --]
[-- Type: text/x-java, Size: 4750 bytes --]

import java.io.File;
import java.io.FilenameFilter;
import java.util.Map;
import java.util.TreeMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Iterator;
import java.util.Collection;
import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory;  
import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class Bug
    implements Comparable
{
    private final File file;
    private final String id;
    private final int hash;
    Bug (File file)
    {
	this.file = file;
	this.id = file.getName ().split ("\\.")[0];
	this.hash = Integer.parseInt (this.id);
    }
    /**
     * Is the object equals to this one.
     */
    public boolean equals (Object o)
    {
	return ((Bug)o).hash == hash;
    }
    /**
     * Return the hash code for this ID (hash on the underlying ID
     * value).
     */
    public int hashCode ()
    {
	return hash;
    }
    /**
     * Assuming that the two objects are the same, do a relative
     * comparison.
     */
    public int compareTo (Object o)
    {
	Bug rhs = (Bug)o;
	return rhs.hash - this.hash;
    }
    /**
     * The bug as a simplified string.
     */
    public String toString ()
    {
	return id;
    }
    public String toPrint ()
    {
	return ""
	    + id
	    + " " + reporter
	    + " " + duplicate
	    + " " + dependson
	    + " " + blocked
	    + " " + description;
    }


    String bug_id = "?";
    String description = "";
    List blocked = new LinkedList ();
    List dependson = new LinkedList ();
    boolean duplicate = false;
    String reporter;
    String assigned_to;

    private void walk (Map map, Node parent)
    {
	for (Node child = parent.getFirstChild ();
	     child != null;
	     child = child.getNextSibling ()) {
	    if (child.getNodeType () == Node.TEXT_NODE
		&& parent.getNodeType () == Node.ELEMENT_NODE) {
		// Grab the bug-id as it flies by.
		String name = parent.getNodeName ();
		String value = child.getNodeValue ();
		if (name.equals ("bug_id"))
		    bug_id = value;
		if (name.equals ("short_desc"))
		    description = description + value;
		// Print anything this blocks
		if (name.equals ("blocked"))
		    blocked.add (map.get (value));
		if (name.equals ("dependson"))
		    dependson.add (map.get (value));
		if (name.equals ("resolution"))
		    duplicate = value.equals("DUPLICATE");
		if (name.equals ("reporter"))
		    reporter = value;
		if (name.equals ("assigned_to"))
		    assigned_to = value;
	    }
	    walk (map, child);
	}
    }

    private static final DocumentBuilderFactory documentBuilderFactory
	= DocumentBuilderFactory.newInstance();
    public void parse (Map map)
    {
	try {
	    DocumentBuilder documentBuilder
		= documentBuilderFactory.newDocumentBuilder ();
	    String file = id + ".xml";
	    Document document = documentBuilder.parse (file);
	    walk (map, document);
	}
	catch (javax.xml.parsers.ParserConfigurationException e) {
	    throw new RuntimeException (e);
	}
	catch (org.xml.sax.SAXException e) {
	    throw new RuntimeException (e);
	}
	catch (java.io.IOException e)  {
	    throw new RuntimeException (e);
	}
	catch (gnu.xml.dom.ls.DomLSException e) {
	    System.err.println (id + " parse error");
	}
    }

    public static TreeMap slurp ()
    {
	TreeMap map = new TreeMap ();
	File[] dotXml = new File (".").listFiles (new FilenameFilter ()
	    {
		public boolean accept (File path, String filename)
		{
		    return filename.matches ("^[0-9]*.xml$");
		}
	    });
	System.out.println ("Loading bugs");
	for (int i = 0; i < dotXml.length; i++) {
	    File file = dotXml[i];
	    Bug bug = new Bug (file);
	    map.put (bug.id, bug);
	}
	System.out.println ("Parsing bugs");
	for (Iterator i = map.values ().iterator ();
	     i.hasNext (); ) {
	    Bug bug = (Bug)i.next ();
	    bug.parse (map);
	    System.out.println (bug.id + " " + bug.description);
	}
	return map;
    }

    public static void main (String[] args)
    {
	TreeMap map = slurp ();

	{
	    System.out.println ("Roots:");
	    Collection roots = ((Map) (map.clone())).values ();
	    for (Iterator i = roots.iterator ();
		 i.hasNext (); ) {
		Bug bug = (Bug)i.next ();
		if (bug.blocked.size () > 0)
		    i.remove ();
	    }
	    for (Iterator i = roots.iterator (); i.hasNext (); ) {
		Bug bug = (Bug)i.next ();
		System.out.println ("Root: " + bug.toPrint ());
	    }
	}

	{
	    System.out.println ("Duplicates:");
	    for (Iterator i = map.values ().iterator (); i.hasNext (); ) {
		Bug bug = (Bug)i.next ();
		if (!bug.duplicate)
		    continue;
		if (bug.dependson.size () > 0)
		    System.out.println ("dependson: " + bug.toPrint ());
		if (bug.blocked.size () != 1)
		    System.out.println ("blocked: " + bug.toPrint ());
	    }
	}
    }
}

  reply	other threads:[~2008-04-03 14:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-03 14:10 Mark Wielaard
2008-04-03 14:25 ` Andrew Cagney
2008-04-03 14:40   ` Mark Wielaard
2008-04-03 21:03     ` Andrew Cagney [this message]
2008-04-03 21:11       ` Mark Wielaard
2008-04-04  8:32         ` Petr Machata
2008-04-04  9:16           ` Mark Wielaard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47F4EC2C.7000707@redhat.com \
    --to=cagney@redhat.com \
    --cc=frysk@sourceware.org \
    --cc=mark@klomp.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).