<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Jigcode</title>
	
	<link>http://www.jigcode.com</link>
	<description>jig. n. a device that holds a piece of machine work and guides the tools operating on it</description>
	<lastBuildDate>Fri, 06 Aug 2010 18:44:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Jigcode" /><feedburner:info uri="jigcode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Ruby: What percentage of the code do I own?</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/CRFD_eL5Vvw/</link>
		<comments>http://www.jigcode.com/2010/08/06/ruby-what-percentage-of-the-code-do-i-own/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 18:44:53 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=159</guid>
		<description><![CDATA[mine = 0 total = 0 require 'find' Find.find&#40;&#34;.&#34;&#41; do &#124;p&#124; Find.prune if File.basename&#40;p&#41;.downcase == &#34;.git&#34; next unless p =~ /\.java$/i system &#34;git annotate #{p} &#62; c:\\temp\\foo.txt&#34; &#160; lines = File.open&#40;&#34;C:\\temp\\foo.txt&#34;,&#34;r&#34;&#41; &#123; &#124;f&#124; f.read.split&#40;/\n/&#41; &#125; mine += lines.grep&#40;/jfelice/&#41;.size total += lines.size print &#34;#{p}: #{mine}/#{total}\n&#34; # Just to show progress end &#160; print &#34;#{mine}\n&#34;]]></description>
				<content:encoded><![CDATA[
<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">mine = <span style="color:#006666;">0</span>
total = <span style="color:#006666;">0</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'find'</span>
<span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">prune</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">downcase</span> == <span style="color:#996600;">&quot;.git&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC0066; font-weight:bold;">p</span> =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#9900CC;">java</span>$<span style="color:#006600; font-weight:bold;">/</span>i
  <span style="color:#CC0066; font-weight:bold;">system</span> <span style="color:#996600;">&quot;git annotate #{p} &gt; c:<span style="color:#000099;">\\</span>temp<span style="color:#000099;">\\</span>foo.txt&quot;</span>
&nbsp;
  lines = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;C:<span style="color:#000099;">\\</span>temp<span style="color:#000099;">\\</span>foo.txt&quot;</span>,<span style="color:#996600;">&quot;r&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> f.<span style="color:#9900CC;">read</span>.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>\n<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  mine <span style="color:#006600; font-weight:bold;">+</span>= lines.<span style="color:#9900CC;">grep</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>jfelice<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">size</span>
  total <span style="color:#006600; font-weight:bold;">+</span>= lines.<span style="color:#9900CC;">size</span>
  <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;#{p}: #{mine}/#{total}<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#008000; font-style:italic;"># Just to show progress</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;#{mine}<span style="color:#000099;">\n</span>&quot;</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/CRFD_eL5Vvw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2010/08/06/ruby-what-percentage-of-the-code-do-i-own/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2010/08/06/ruby-what-percentage-of-the-code-do-i-own/</feedburner:origLink></item>
		<item>
		<title>Ruby: Find ini files containing an entry</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/QCbgOilZGnE/</link>
		<comments>http://www.jigcode.com/2009/12/01/ruby-find-ini-files-containing-an-entry/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:31:16 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=149</guid>
		<description><![CDATA[Ruby&#8217;s always good with the &#8220;find&#8221;: require 'find' &#160; Find.find&#40;&#34;.&#34;&#41; do &#124;path&#124; Find.prune if path =~ /\.svn$/ Find.prune if path =~ /XPay$/i next unless path =~ /\.ini$/i File.open&#40;path,'r'&#41; do &#124;f&#124; f.each_line do &#124;l&#124; next unless l =~ /^\s*dasserver\.exe\s*=\s*&#40;?:&#91;0-9&#93;+\.&#41;&#123;3&#125;&#40;&#91;0-9&#93;+&#41;\s*$/ print &#34;#{path} (2.0.2.#{$1})\n&#34; if $1.to_i &#62;= 1885 end end end]]></description>
				<content:encoded><![CDATA[<p>Ruby&#8217;s always good with the &#8220;find&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'find'</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;.&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>path<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">prune</span> <span style="color:#9966CC; font-weight:bold;">if</span> path =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#9900CC;">svn</span>$<span style="color:#006600; font-weight:bold;">/</span>
  <span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">prune</span> <span style="color:#9966CC; font-weight:bold;">if</span> path =~ <span style="color:#006600; font-weight:bold;">/</span>XPay$<span style="color:#006600; font-weight:bold;">/</span>i
  <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">unless</span> path =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#9900CC;">ini</span>$<span style="color:#006600; font-weight:bold;">/</span>i
  <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>path,<span style="color:#996600;">'r'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
    f.<span style="color:#9900CC;">each_line</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>l<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">unless</span> l =~ <span style="color:#006600; font-weight:bold;">/</span>^\s<span style="color:#006600; font-weight:bold;">*</span>dasserver\.<span style="color:#9900CC;">exe</span>\s<span style="color:#006600; font-weight:bold;">*</span>=\s<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>\.<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span>
      <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;#{path} (2.0.2.#{$1})<span style="color:#000099;">\n</span>&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> $1.<span style="color:#9900CC;">to_i</span> <span style="color:#006600; font-weight:bold;">&gt;</span>= <span style="color:#006666;">1885</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/QCbgOilZGnE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/12/01/ruby-find-ini-files-containing-an-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/12/01/ruby-find-ini-files-containing-an-entry/</feedburner:origLink></item>
		<item>
		<title>Scala: Ugly hairy rewrite C++ code jig</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/_Eo7BVMEuUA/</link>
		<comments>http://www.jigcode.com/2009/10/05/scala-ugly-hairy-rewrite-c-code-jig/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 20:23:30 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=146</guid>
		<description><![CDATA[I think this might be the first time I&#8217;ve gotten to use a real algorithm at work in several years. This is also my first attempt at Scala (pretty nice!), and one ugly jig. It had to be adjusted every fourth or fifth component I used it on because of strangeness in the way that [...]]]></description>
				<content:encoded><![CDATA[<p>I think this might be the first time I&#8217;ve gotten to use a real algorithm at work in several years.  This is also my first attempt at Scala (pretty nice!), and one ugly jig.  It had to be adjusted every fourth or fifth component I used it on because of strangeness in the way that component was written, or in the way Java handles regular expressions, or both.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scala" style="font-family:monospace;">&nbsp;
<span style="color: #0000ff; font-weight: bold;">import</span> java.<span style="color: #000000;">io</span>.<span style="color: #F78811;">&#123;</span>File,FileReader,FileWriter<span style="color: #F78811;">&#125;</span>
<span style="color: #0000ff; font-weight: bold;">import</span> java.<span style="color: #000000;">util</span>.<span style="color: #000000;">regex</span>.<span style="color: #F78811;">&#123;</span>Pattern,Matcher<span style="color: #F78811;">&#125;</span>
<span style="color: #0000ff; font-weight: bold;">import</span> java.<span style="color: #000000;">lang</span>.<span style="color: #000000;">Math</span>.<span style="color: #000000;">min</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">class</span> Fixer<span style="color: #F78811;">&#40;</span>path <span style="color: #000080;">:</span> String<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> files <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> File<span style="color: #F78811;">&#40;</span>path<span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">listFiles</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> isCppFile <span style="color: #F78811;">&#40;</span>f <span style="color: #000080;">:</span> File<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> f.<span style="color: #000000;">getName</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">toLowerCase</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span> endsWith <span style="color: #6666FF;">&quot;.cpp&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> isHFile <span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> File<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> name <span style="color: #000080;">=</span> f.<span style="color: #000000;">getName</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">toLowerCase</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>
    name.<span style="color: #000000;">endsWith</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;.h&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">&amp;&amp;</span> name <span style="color: #000080;">!=</span> <span style="color: #6666FF;">&quot;resource.h&quot;</span> <span style="color: #000080;">&amp;&amp;</span> <span style="color: #000080;">!</span>name.<span style="color: #000000;">startsWith</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;test_&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">&amp;&amp;</span> name <span style="color: #000080;">!=</span> <span style="color: #6666FF;">&quot;vxnapi3.h&quot;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> mostSimilarFile<span style="color: #F78811;">&#40;</span>fs <span style="color: #000080;">:</span> <span style="color: #000080;">=&gt;</span> Array<span style="color: #F78811;">&#91;</span>File<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> result <span style="color: #000080;">:</span> File <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> bestDistance <span style="color: #000080;">=</span> <span style="color: #F78811;">9999</span>
    <span style="color: #0000ff; font-weight: bold;">for</span> <span style="color: #F78811;">&#40;</span>f <span style="color: #000080;">&lt;</span>- fs<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">val</span> dist <span style="color: #000080;">=</span> editDistance<span style="color: #F78811;">&#40;</span>
          f.<span style="color: #000000;">getName</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">replaceAll</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>.[^<span style="color: #6666ff; font-weight: bold;">\\</span>.]*$&quot;</span>, <span style="color: #6666FF;">&quot;&quot;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">toLowerCase</span>,
          <span style="color: #0000ff; font-weight: bold;">new</span> File<span style="color: #F78811;">&#40;</span>path<span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">getName</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">toLowerCase</span>
          <span style="color: #F78811;">&#41;</span>
      <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>dist <span style="color: #000080;">&lt;</span> bestDistance<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
        bestDistance <span style="color: #000080;">=</span> dist
        result <span style="color: #000080;">=</span> f
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
    result
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> cppFile <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> result <span style="color: #000080;">=</span> mostSimilarFile<span style="color: #F78811;">&#40;</span>files filter isCppFile<span style="color: #F78811;">&#41;</span>
    println<span style="color: #F78811;">&#40;</span>result<span style="color: #F78811;">&#41;</span>
    result
  <span style="color: #F78811;">&#125;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> hFile <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> result <span style="color: #000080;">=</span> mostSimilarFile<span style="color: #F78811;">&#40;</span>files filter isHFile<span style="color: #F78811;">&#41;</span>
    println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;hFile:&quot;</span>+result<span style="color: #F78811;">&#41;</span>
    result
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> readFile <span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> File<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> r <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> FileReader<span style="color: #F78811;">&#40;</span>f<span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> b <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Array<span style="color: #F78811;">&#91;</span>Char<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1024</span><span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> sb <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> StringBuffer
    <span style="color: #0000ff; font-weight: bold;">var</span> l <span style="color: #000080;">=</span> <span style="color: #F78811;">0</span>
    <span style="color: #0000ff; font-weight: bold;">do</span> <span style="color: #F78811;">&#123;</span>
      l <span style="color: #000080;">=</span> r.<span style="color: #000000;">read</span><span style="color: #F78811;">&#40;</span>b<span style="color: #F78811;">&#41;</span>
      <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>l <span style="color: #000080;">&gt;</span> <span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span> sb.<span style="color: #000000;">append</span><span style="color: #F78811;">&#40;</span>b, <span style="color: #F78811;">0</span>, l<span style="color: #F78811;">&#41;</span>
    <span style="color: #F78811;">&#125;</span> <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>l <span style="color: #000080;">&gt;</span> <span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span>
    r.<span style="color: #000000;">close</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>
    sb.<span style="color: #000000;">toString</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> writeFile <span style="color: #F78811;">&#40;</span>f<span style="color: #000080;">:</span> File, s <span style="color: #000080;">:</span> String<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> w <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> FileWriter<span style="color: #F78811;">&#40;</span>f<span style="color: #F78811;">&#41;</span> 
    w.<span style="color: #000000;">write</span><span style="color: #F78811;">&#40;</span>s<span style="color: #F78811;">&#41;</span>
    w.<span style="color: #000000;">close</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">var</span> cppText<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> cppText <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>cppText<span style="color: #000080;">_</span> <span style="color: #000080;">==</span> <span style="color: #0000ff; font-weight: bold;">null</span><span style="color: #F78811;">&#41;</span> cppText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span> readFile<span style="color: #F78811;">&#40;</span>cppFile<span style="color: #F78811;">&#41;</span>
    cppText<span style="color: #000080;">_</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">var</span> hText<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> hText <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>hText<span style="color: #000080;">_</span> <span style="color: #000080;">==</span> <span style="color: #0000ff; font-weight: bold;">null</span><span style="color: #F78811;">&#41;</span> hText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span> readFile<span style="color: #F78811;">&#40;</span>hFile<span style="color: #F78811;">&#41;</span>
    hText<span style="color: #000080;">_</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">class</span> RegInfo<span style="color: #F78811;">&#40;</span>
      guid<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String,
      compId<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String,
      compType<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String,
      compSubType<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String,
      friendlyName<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String,
      progId<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String,
      className<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String,
      baseClassName<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> String
    <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> guid <span style="color: #000080;">=</span> guid<span style="color: #000080;">_</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> compId <span style="color: #000080;">=</span> compId<span style="color: #000080;">_</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> compType <span style="color: #000080;">=</span> compType<span style="color: #000080;">_</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> compSubType <span style="color: #000080;">=</span> compSubType<span style="color: #000080;">_</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> friendlyName <span style="color: #000080;">=</span> friendlyName<span style="color: #000080;">_</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> progId <span style="color: #000080;">=</span> progId<span style="color: #000080;">_</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> className <span style="color: #000080;">=</span> className<span style="color: #000080;">_</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> baseClassName <span style="color: #000080;">=</span> baseClassName<span style="color: #000080;">_</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">def</span> traitClassName <span style="color: #000080;">=</span> className + <span style="color: #6666FF;">&quot;Traits&quot;</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> declareTraits <span style="color: #000080;">=</span>
      <span style="color: #6666FF;">&quot;struct &quot;</span> + traitClassName + <span style="color: #6666FF;">&quot; {<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    static const int COMPID;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    static const int TYPE;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    static const int SUBTYPE;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    static const GUID IID;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    static const char* PROG_ID;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    static const char* FRIENDLY_NAME;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;};<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">def</span> rightPad<span style="color: #F78811;">&#40;</span>s <span style="color: #000080;">:</span> String, l <span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span>
      <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>s.<span style="color: #000000;">length</span> <span style="color: #000080;">&gt;=</span> l<span style="color: #F78811;">&#41;</span> s <span style="color: #0000ff; font-weight: bold;">else</span> rightPad<span style="color: #F78811;">&#40;</span>s+<span style="color: #6666FF;">&quot; &quot;</span>, l<span style="color: #F78811;">&#41;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">def</span> implementItem<span style="color: #F78811;">&#40;</span>typ <span style="color: #000080;">:</span> String, name <span style="color: #000080;">:</span> String, value <span style="color: #000080;">:</span> String<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span>
      <span style="color: #6666FF;">&quot;const &quot;</span> + rightPad<span style="color: #F78811;">&#40;</span>typ, <span style="color: #F78811;">5</span><span style="color: #F78811;">&#41;</span> + <span style="color: #6666FF;">&quot; &quot;</span> + traitClassName + <span style="color: #6666FF;">&quot;::&quot;</span> + rightPad<span style="color: #F78811;">&#40;</span>name, <span style="color: #F78811;">14</span><span style="color: #F78811;">&#41;</span> +
      <span style="color: #6666FF;">&quot;= &quot;</span> + value + <span style="color: #6666FF;">&quot;;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">def</span> implementTraits <span style="color: #000080;">=</span>
      <span style="color: #6666FF;">&quot;//////////////////////////////////////////////////////////////////////////////<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;// &quot;</span> + traitClassName + <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      implementItem<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;int&quot;</span>, <span style="color: #6666FF;">&quot;COMPID&quot;</span>, compId<span style="color: #F78811;">&#41;</span> +
      implementItem<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;int&quot;</span>, <span style="color: #6666FF;">&quot;TYPE&quot;</span>, compType<span style="color: #F78811;">&#41;</span> +
      implementItem<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;int&quot;</span>, <span style="color: #6666FF;">&quot;SUBTYPE&quot;</span>, compSubType<span style="color: #F78811;">&#41;</span> +
      implementItem<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;GUID&quot;</span>, <span style="color: #6666FF;">&quot;IID&quot;</span>, guid<span style="color: #F78811;">&#41;</span> +
      implementItem<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;char*&quot;</span>, <span style="color: #6666FF;">&quot;PROG_ID&quot;</span>, progId<span style="color: #F78811;">&#41;</span> +
      implementItem<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;char*&quot;</span>, <span style="color: #6666FF;">&quot;FRIENDLY_NAME&quot;</span>, friendlyName<span style="color: #F78811;">&#41;</span> +
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">var</span> regInfo<span style="color: #000080;">_</span> <span style="color: #000080;">:</span> RegInfo <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> regInfo <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>regInfo<span style="color: #000080;">_</span> <span style="color: #000080;">==</span> <span style="color: #0000ff; font-weight: bold;">null</span><span style="color: #F78811;">&#41;</span> regInfo<span style="color: #000080;">_</span> <span style="color: #000080;">=</span> makeRegInfo
    regInfo<span style="color: #000080;">_</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> extract<span style="color: #F78811;">&#40;</span>re <span style="color: #000080;">:</span> String, g <span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> matcher <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>re, Pattern.<span style="color: #000000;">MULTILINE</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>hText + cppText<span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span><span style="color: #000080;">!</span>matcher.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">null</span>
    <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">val</span> result <span style="color: #000080;">=</span> matcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span>g<span style="color: #F78811;">&#41;</span>
      <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>matcher.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">throw</span> <span style="color: #0000ff; font-weight: bold;">new</span> Exception<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Found more than one!! &quot;</span> + re<span style="color: #F78811;">&#41;</span>
      result
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">val</span> fdataTerm <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>s*([^,]*),<span style="color: #6666ff; font-weight: bold;">\\</span>s*(?://[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*)?&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> fdataPattern <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>
    <span style="color: #6666FF;">&quot;CFactoryData<span style="color: #6666ff; font-weight: bold;">\\</span>s+g_FactoryDataArray[^=]*=<span style="color: #6666ff; font-weight: bold;">\\</span>s*&quot;</span> +
    <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>{<span style="color: #6666ff; font-weight: bold;">\\</span>s*&quot;</span> +
    <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>{&quot;</span> +
      fdataTerm +
      fdataTerm +
      fdataTerm +
      fdataTerm +
      fdataTerm +
      fdataTerm +
    <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>}<span style="color: #6666ff; font-weight: bold;">\\</span>s*&quot;</span> +
    <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>}<span style="color: #6666ff; font-weight: bold;">\\</span>s*;&quot;</span>
    <span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #00ff00; font-style: italic;">/*
  ** Yet again, a regexp broken down into code because the Java regexp
  ** NFA runner takes exponential time for things that should have no
  ** backtracking whatsoever.  Argh!!!
  */</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> scanFactoryData <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> begin <span style="color: #000080;">=</span> <span style="color: #F78811;">0</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> end <span style="color: #000080;">=</span> <span style="color: #F78811;">0</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> nextLine <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
      begin <span style="color: #000080;">=</span> end
      <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>begin <span style="color: #000080;">&gt;=</span> cppText.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">null</span>
      <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #F78811;">&#123;</span>
        end <span style="color: #000080;">=</span> begin
        <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>end <span style="color: #000080;">&lt;</span> cppText.<span style="color: #000000;">length</span> <span style="color: #000080;">&amp;&amp;</span> cppText<span style="color: #F78811;">&#40;</span>end<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">!=</span> <span style="color: #6666FF;">'<span style="color: #6666ff; font-weight: bold;">\n</span>'</span><span style="color: #F78811;">&#41;</span> end +<span style="color: #000080;">=</span> <span style="color: #F78811;">1</span>
        <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>end <span style="color: #000080;">&lt;</span> cppText.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span> end +<span style="color: #000080;">=</span> <span style="color: #F78811;">1</span>
        cppText.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span>begin, end<span style="color: #F78811;">&#41;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">var</span> state <span style="color: #000080;">=</span> -<span style="color: #F78811;">1</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> startPattern <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;^<span style="color: #6666ff; font-weight: bold;">\\</span>s*CFactoryData<span style="color: #6666ff; font-weight: bold;">\\</span>s+g_FactoryDataArray.*&quot;</span><span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> valuePattern <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;^<span style="color: #6666ff; font-weight: bold;">\\</span>s*([^,]*),<span style="color: #6666ff; font-weight: bold;">\\</span>s*(?://[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*)?<span style="color: #6666ff; font-weight: bold;">\n</span>?&quot;</span><span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> line <span style="color: #000080;">=</span> nextLine
    <span style="color: #0000ff; font-weight: bold;">var</span> friendlyName <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> progId <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
    <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>line <span style="color: #000080;">!=</span> <span style="color: #0000ff; font-weight: bold;">null</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      state <span style="color: #0000ff; font-weight: bold;">match</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">case</span> -<span style="color: #F78811;">1</span> <span style="color: #000080;">=&gt;</span>
        <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>startPattern.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>line<span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span>
          state <span style="color: #000080;">=</span> <span style="color: #F78811;">0</span>
      <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #000080;">_</span> <span style="color: #000080;">=&gt;</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> m <span style="color: #000080;">=</span> valuePattern.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>line<span style="color: #F78811;">&#41;</span>
        <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>m.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          state <span style="color: #0000ff; font-weight: bold;">match</span> <span style="color: #F78811;">&#123;</span>
          <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #F78811;">2</span> <span style="color: #000080;">=&gt;</span>
            friendlyName <span style="color: #000080;">=</span> m.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>
          <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #F78811;">3</span> <span style="color: #000080;">=&gt;</span>
            progId <span style="color: #000080;">=</span> m.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>
          <span style="color: #0000ff; font-weight: bold;">case</span> <span style="color: #000080;">_</span> <span style="color: #000080;">=&gt;</span>
            <span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>
          <span style="color: #F78811;">&#125;</span>
          state +<span style="color: #000080;">=</span> <span style="color: #F78811;">1</span>
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span>
      line <span style="color: #000080;">=</span> nextLine
    <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#40;</span> friendlyName, progId <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> editDistance<span style="color: #F78811;">&#40;</span>cname <span style="color: #000080;">:</span> String, fname <span style="color: #000080;">:</span> String<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> dp <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Array<span style="color: #F78811;">&#91;</span>Array<span style="color: #F78811;">&#91;</span>Int<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">100</span>, <span style="color: #F78811;">100</span><span style="color: #F78811;">&#41;</span>
    dp<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">0</span><span style="color: #000080;">;</span>
    <span style="color: #0000ff; font-weight: bold;">for</span> <span style="color: #F78811;">&#40;</span>i <span style="color: #000080;">&lt;</span>- <span style="color: #F78811;">1</span> to cname.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span>
      dp<span style="color: #F78811;">&#40;</span>i<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> i
    <span style="color: #0000ff; font-weight: bold;">for</span> <span style="color: #F78811;">&#40;</span>j <span style="color: #000080;">&lt;</span>- <span style="color: #F78811;">1</span> to fname.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span>
      dp<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>j<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> j
    <span style="color: #0000ff; font-weight: bold;">for</span> <span style="color: #F78811;">&#40;</span>i <span style="color: #000080;">&lt;</span>- <span style="color: #F78811;">1</span> to cname.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span>
      <span style="color: #0000ff; font-weight: bold;">for</span> <span style="color: #F78811;">&#40;</span>j <span style="color: #000080;">&lt;</span>- <span style="color: #F78811;">1</span> to fname.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span>
        dp<span style="color: #F78811;">&#40;</span>i<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>j<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> min<span style="color: #F78811;">&#40;</span>
                     min<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span>+dp<span style="color: #F78811;">&#40;</span>i-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>j<span style="color: #F78811;">&#41;</span>, <span style="color: #F78811;">1</span>+dp<span style="color: #F78811;">&#40;</span>i<span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>j-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>,
                     dp<span style="color: #F78811;">&#40;</span>i-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>j-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span> + <span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>cname<span style="color: #F78811;">&#40;</span>i-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">==</span> fname<span style="color: #F78811;">&#40;</span>j-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">0</span> <span style="color: #0000ff; font-weight: bold;">else</span> <span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>
                     <span style="color: #F78811;">&#41;</span>
&nbsp;
    dp<span style="color: #F78811;">&#40;</span>cname.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#40;</span>fname.<span style="color: #000000;">length</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> findClassName <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> constructorMatcher <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;^([A-Z][A-Z0-9a-z_]*)<span style="color: #6666ff; font-weight: bold;">\\</span>s*::<span style="color: #6666ff; font-weight: bold;">\\</span>s*([A-Z][A-Za-z0-9_]*)<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>(&quot;</span>,
      Pattern.<span style="color: #000000;">MULTILINE</span>
      <span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>cppText<span style="color: #F78811;">&#41;</span>
&nbsp;
    <span style="color: #008000; font-style: italic;">// There can be many constructors - find the one with the closest Levenshtein</span>
    <span style="color: #008000; font-style: italic;">// edit distance to the filename (sans extension).</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">var</span> bestDistance <span style="color: #000080;">=</span> <span style="color: #F78811;">9999</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> className <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
    <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>constructorMatcher.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>constructorMatcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">==</span> constructorMatcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">2</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> cname <span style="color: #000080;">=</span> constructorMatcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> fname <span style="color: #000080;">=</span> cppFile.<span style="color: #000000;">getName</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">replaceAll</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>.[^<span style="color: #6666ff; font-weight: bold;">\\</span>.]*$&quot;</span>, <span style="color: #6666FF;">&quot;&quot;</span><span style="color: #F78811;">&#41;</span>
        <span style="color: #0000ff; font-weight: bold;">val</span> dist <span style="color: #000080;">=</span> editDistance<span style="color: #F78811;">&#40;</span>cname, fname<span style="color: #F78811;">&#41;</span>
        <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>dist <span style="color: #000080;">&lt;</span> bestDistance<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
          bestDistance <span style="color: #000080;">=</span> dist
          className <span style="color: #000080;">=</span> cname
        <span style="color: #F78811;">&#125;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
&nbsp;
    className
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> findDIID <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> matcher <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;DIID_[A-Z0-9a-z_]*&quot;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>cppText<span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> fname <span style="color: #000080;">=</span> cppFile.<span style="color: #000000;">getName</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">replaceAll</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>.[^<span style="color: #6666ff; font-weight: bold;">\\</span>.]*$&quot;</span>, <span style="color: #6666FF;">&quot;&quot;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">toUpperCase</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">var</span> bestDistance <span style="color: #000080;">=</span> <span style="color: #F78811;">9999</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> diid <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>
    <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>matcher.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">val</span> dist <span style="color: #000080;">=</span> editDistance<span style="color: #F78811;">&#40;</span>
        matcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">replaceAll</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;^DIID_&quot;</span>, <span style="color: #6666FF;">&quot;&quot;</span><span style="color: #F78811;">&#41;</span>,
        fname
      <span style="color: #F78811;">&#41;</span>
      println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;diid = &quot;</span> + matcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span> + <span style="color: #6666FF;">&quot;; dist = &quot;</span> + dist<span style="color: #F78811;">&#41;</span>
      <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>dist <span style="color: #000080;">&lt;</span> bestDistance<span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
        println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;accept&quot;</span><span style="color: #F78811;">&#41;</span>
        bestDistance <span style="color: #000080;">=</span> dist
        diid <span style="color: #000080;">=</span> matcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span>
      <span style="color: #F78811;">&#125;</span>
    <span style="color: #F78811;">&#125;</span>
    diid
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> makeRegInfo <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> <span style="color: #F78811;">&#40;</span> friendlyName, progId <span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> scanFactoryData
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">var</span> baseClassName <span style="color: #000080;">:</span> String <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">null</span>  
    <span style="color: #0000ff; font-weight: bold;">val</span> className <span style="color: #000080;">=</span> findClassName
    <span style="color: #0000ff; font-weight: bold;">val</span> bcMatcher <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;class<span style="color: #6666ff; font-weight: bold;">\\</span>s+&quot;</span> + className + <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>s*:<span style="color: #6666ff; font-weight: bold;">\\</span>s*public<span style="color: #6666ff; font-weight: bold;">\\</span>s+([A-Za-z0-9_]+(?:&lt;[^&gt;]*&gt;)?)&quot;</span>
      <span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>hText<span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>bcMatcher.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span>
      baseClassName <span style="color: #000080;">=</span> bcMatcher.<span style="color: #000000;">group</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">new</span> RegInfo<span style="color: #F78811;">&#40;</span>
      findDIID,
      extract<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;m_iCompId<span style="color: #6666ff; font-weight: bold;">\\</span>s*=<span style="color: #6666ff; font-weight: bold;">\\</span>s*([^;]*?)<span style="color: #6666ff; font-weight: bold;">\\</span>s*;&quot;</span>, <span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>,
      extract<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;m_iType<span style="color: #6666ff; font-weight: bold;">\\</span>s*=<span style="color: #6666ff; font-weight: bold;">\\</span>s*([^;]*?)<span style="color: #6666ff; font-weight: bold;">\\</span>s*;&quot;</span>, <span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>,
      extract<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;m_iSubType<span style="color: #6666ff; font-weight: bold;">\\</span>s*=<span style="color: #6666ff; font-weight: bold;">\\</span>s*([^;]*?)<span style="color: #6666ff; font-weight: bold;">\\</span>s*;&quot;</span>, <span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>,
      friendlyName,
      progId,
      className,
      baseClassName
    <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">val</span> precedingComments <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>s*(?://[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span><span style="color: #6666ff; font-weight: bold;">\\</span>s*)*&quot;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> roughPrecedingComment <span style="color: #F78811;">&#40;</span>text <span style="color: #000080;">:</span> String, bp <span style="color: #000080;">:</span> Int<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #008000; font-style: italic;">// Why, oh why, does Java use the NFA matcher for regular expressions?</span>
    <span style="color: #008000; font-style: italic;">// There isn't enough stack space to properly match optional leading</span>
    <span style="color: #008000; font-style: italic;">// C-style comments, so here is a rough approximation by backward scanning</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> b <span style="color: #000080;">=</span> bp - <span style="color: #F78811;">1</span>
    <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>b <span style="color: #000080;">&gt;</span> <span style="color: #F78811;">0</span> <span style="color: #000080;">&amp;&amp;</span> Character.<span style="color: #000000;">isSpace</span><span style="color: #F78811;">&#40;</span>text<span style="color: #F78811;">&#40;</span>b-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> b -<span style="color: #000080;">=</span> <span style="color: #F78811;">1</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>b <span style="color: #000080;">&gt;</span> <span style="color: #F78811;">4</span> <span style="color: #000080;">&amp;&amp;</span> text<span style="color: #F78811;">&#40;</span>b-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #6666FF;">'/'</span> <span style="color: #000080;">&amp;&amp;</span> text<span style="color: #F78811;">&#40;</span>b-<span style="color: #F78811;">2</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #6666FF;">'*'</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      b -<span style="color: #000080;">=</span> <span style="color: #F78811;">4</span>
      <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>b <span style="color: #000080;">&gt;</span> <span style="color: #F78811;">0</span> <span style="color: #000080;">&amp;&amp;</span> <span style="color: #F78811;">&#40;</span>text<span style="color: #F78811;">&#40;</span>b<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">!=</span> <span style="color: #6666FF;">'/'</span> || text<span style="color: #F78811;">&#40;</span>b+<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">!=</span> <span style="color: #6666FF;">'*'</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
        b -<span style="color: #000080;">=</span> <span style="color: #F78811;">1</span>
      <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>b <span style="color: #000080;">&gt;</span> <span style="color: #F78811;">0</span> <span style="color: #000080;">&amp;&amp;</span> Character.<span style="color: #000000;">isSpace</span><span style="color: #F78811;">&#40;</span>text<span style="color: #F78811;">&#40;</span>b-<span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
        b -<span style="color: #000080;">=</span> <span style="color: #F78811;">1</span>
    <span style="color: #F78811;">&#125;</span>
    b
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> removeNDQI <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> pm <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;^HRESULT<span style="color: #6666ff; font-weight: bold;">\\</span>s+[a-zA-Z0-9_<span style="color: #6666ff; font-weight: bold;">\\</span>s]*::NondelegatingQueryInterface<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>(&quot;</span> +
        <span style="color: #6666FF;">&quot;[^)]*<span style="color: #6666ff; font-weight: bold;">\\</span>)<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>{<span style="color: #6666ff; font-weight: bold;">\\</span>s*&quot;</span> +
        <span style="color: #6666FF;">&quot;.*?&quot;</span> +
        <span style="color: #6666FF;">&quot;^<span style="color: #6666ff; font-weight: bold;">\\</span>}[<span style="color: #6666ff; font-weight: bold;">\t</span> ]*<span style="color: #6666ff; font-weight: bold;">\\</span>n?&quot;</span>,
        Pattern.<span style="color: #000000;">DOTALL</span> | Pattern.<span style="color: #000000;">MULTILINE</span>
      <span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>cppText<span style="color: #F78811;">&#41;</span>
&nbsp;
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>pm.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">val</span> b <span style="color: #000080;">=</span> roughPrecedingComment<span style="color: #F78811;">&#40;</span>cppText, pm.<span style="color: #000000;">start</span><span style="color: #F78811;">&#41;</span>
      <span style="color: #0000ff; font-weight: bold;">val</span> e <span style="color: #000080;">=</span> pm.<span style="color: #000000;">end</span>
&nbsp;
      cppText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span>
        cppText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span>, b<span style="color: #F78811;">&#41;</span> +
        <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
        cppText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span>e<span style="color: #F78811;">&#41;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> removeGUIDDecl <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> p <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>s+^EXTERN_C.*GUID.*=.*;[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>, Pattern.<span style="color: #000000;">MULTILINE</span><span style="color: #F78811;">&#41;</span>
    cppText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span> p.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>cppText<span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">replaceAll</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;&quot;</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> replace<span style="color: #F78811;">&#40;</span>re <span style="color: #000080;">:</span> String, s <span style="color: #000080;">:</span> String<span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> p <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>re, Pattern.<span style="color: #000000;">MULTILINE</span><span style="color: #F78811;">&#41;</span>
    cppText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span> p.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>cppText<span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">replaceAll</span><span style="color: #F78811;">&#40;</span>s<span style="color: #F78811;">&#41;</span>
    hText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span> p.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>hText<span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">replaceAll</span><span style="color: #F78811;">&#40;</span>s<span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> removeFactoryData <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    replace<span style="color: #F78811;">&#40;</span>
      precedingComments +
      <span style="color: #6666FF;">&quot;CFactoryData<span style="color: #6666ff; font-weight: bold;">\\</span>s+g_FactoryDataArray[^=]*=<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>{<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>{[^}]*<span style="color: #6666ff; font-weight: bold;">\\</span>},?<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>}<span style="color: #6666ff; font-weight: bold;">\\</span>s*;[^<span style="color: #6666ff; font-weight: bold;">\\</span>n]*<span style="color: #6666ff; font-weight: bold;">\\</span>n?&quot;</span>,
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
      <span style="color: #F78811;">&#41;</span>
    replace<span style="color: #F78811;">&#40;</span>
      precedingComments +
      <span style="color: #6666FF;">&quot;int<span style="color: #6666ff; font-weight: bold;">\\</span>s+g_cFactoryDataEntries<span style="color: #6666ff; font-weight: bold;">\\</span>s*=[^;]*;[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>,
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
      <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> removeGetRegName <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    replace<span style="color: #F78811;">&#40;</span>
      precedingComments +
      <span style="color: #6666FF;">&quot;STDAPI<span style="color: #6666ff; font-weight: bold;">\\</span>s+GetRegName<span style="color: #6666ff; font-weight: bold;">\\</span>([^<span style="color: #6666ff; font-weight: bold;">\\</span>)]*<span style="color: #6666ff; font-weight: bold;">\\</span>)<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>{[^<span style="color: #6666ff; font-weight: bold;">\\</span>}]*<span style="color: #6666ff; font-weight: bold;">\\</span>}[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>,
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
      <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> removeSillyInstance <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    replace<span style="color: #F78811;">&#40;</span>
      precedingComments +
      regInfo.<span style="color: #000000;">className</span> + <span style="color: #6666FF;">&quot; [A-Za-z_0-9]+<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>(<span style="color: #6666ff; font-weight: bold;">\\</span>s*NULL<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>)<span style="color: #6666ff; font-weight: bold;">\\</span>s*;[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>?&quot;</span>,
      <span style="color: #6666FF;">&quot;&quot;</span>
      <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> fixConstructor <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    replace<span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;^<span style="color: #6666ff; font-weight: bold;">\\</span>s*(m_iCompId|m_iType|m_iSubType)<span style="color: #6666ff; font-weight: bold;">\\</span>s*=<span style="color: #6666ff; font-weight: bold;">\\</span>s*[^;]*;[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>,
      <span style="color: #6666FF;">&quot;&quot;</span>
      <span style="color: #F78811;">&#41;</span>
    replace<span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;(?:&quot;</span> + regInfo.<span style="color: #000000;">baseClassName</span> + <span style="color: #6666FF;">&quot;|CInterleaveCommTempl_)<span style="color: #6666ff; font-weight: bold;">\\</span>s*(<span style="color: #6666ff; font-weight: bold;">\\</span>([^)]*<span style="color: #6666ff; font-weight: bold;">\\</span>))&quot;</span>,
      <span style="color: #6666FF;">&quot;ComponentImpl_$1&quot;</span>
      <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> addRegisterMacro <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span><span style="color: #000080;">!</span>cppText.<span style="color: #000000;">endsWith</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span> cppText<span style="color: #000080;">_</span> +<span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
    cppText<span style="color: #000080;">_</span> +<span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>REGISTER(&quot;</span> + regInfo.<span style="color: #000000;">className</span> + <span style="color: #6666FF;">&quot;);<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> addTraitImpl <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> matcher <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;(?:^<span style="color: #6666ff; font-weight: bold;">\\</span>s*#<span style="color: #6666ff; font-weight: bold;">\\</span>s*include[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>|^<span style="color: #6666ff; font-weight: bold;">\\</span>s*using<span style="color: #6666ff; font-weight: bold;">\\</span>s+namespace<span style="color: #6666ff; font-weight: bold;">\\</span>s[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>)&quot;</span>,
      Pattern.<span style="color: #000000;">MULTILINE</span>
      <span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>cppText<span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> last <span style="color: #000080;">=</span> <span style="color: #F78811;">0</span>
    <span style="color: #0000ff; font-weight: bold;">while</span> <span style="color: #F78811;">&#40;</span>matcher.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> last <span style="color: #000080;">=</span> matcher.<span style="color: #000000;">end</span>
&nbsp;
    cppText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span>
      cppText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span>, last<span style="color: #F78811;">&#41;</span> +
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      regInfo.<span style="color: #000000;">implementTraits</span> +
      <span style="color: #6666FF;">&quot;//////////////////////////////////////////////////////////////////////////////<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;// &quot;</span> + regInfo.<span style="color: #000000;">className</span> + <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      cppText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span>last<span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> addTraitDecl <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> cmatcher <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;^<span style="color: #6666ff; font-weight: bold;">\\</span>s*class<span style="color: #6666ff; font-weight: bold;">\\</span>s+&quot;</span> + regInfo.<span style="color: #000000;">className</span> + <span style="color: #6666FF;">&quot;[^a-zA-Z0-9_]&quot;</span>,
      Pattern.<span style="color: #000000;">MULTILINE</span>
      <span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>hText<span style="color: #F78811;">&#41;</span>
&nbsp;
    assert<span style="color: #F78811;">&#40;</span>cmatcher.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">val</span> pos <span style="color: #000080;">=</span> cmatcher.<span style="color: #000000;">start</span>
&nbsp;
    hText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span>
      hText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span>, pos<span style="color: #F78811;">&#41;</span> +
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      regInfo.<span style="color: #000000;">declareTraits</span> +
      hText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span>pos<span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> removeNDQIDecl <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">var</span> pm <span style="color: #000080;">=</span> Pattern.<span style="color: #000000;">compile</span><span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;(?m)^<span style="color: #6666ff; font-weight: bold;">\\</span>s*(?:virtual<span style="color: #6666ff; font-weight: bold;">\\</span>s+)?HRESULT<span style="color: #6666ff; font-weight: bold;">\\</span>s+_?_stdcall<span style="color: #6666ff; font-weight: bold;">\\</span>s+NondelegatingQueryInterface<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>([^)]*<span style="color: #6666ff; font-weight: bold;">\\</span>)<span style="color: #6666ff; font-weight: bold;">\\</span>s*;[^<span style="color: #6666ff; font-weight: bold;">\n</span>]*<span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
      <span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">matcher</span><span style="color: #F78811;">&#40;</span>hText<span style="color: #F78811;">&#41;</span>
    <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>pm.<span style="color: #000000;">find</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      <span style="color: #0000ff; font-weight: bold;">val</span> b <span style="color: #000080;">=</span> roughPrecedingComment<span style="color: #F78811;">&#40;</span>hText, pm.<span style="color: #000000;">start</span><span style="color: #F78811;">&#41;</span>
      <span style="color: #0000ff; font-weight: bold;">val</span> e <span style="color: #000080;">=</span> pm.<span style="color: #000000;">end</span>
&nbsp;
      hText<span style="color: #000080;">_</span> <span style="color: #000080;">=</span>
        hText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span>, b<span style="color: #F78811;">&#41;</span> +
        <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
        hText<span style="color: #000080;">_</span>.<span style="color: #000000;">substring</span><span style="color: #F78811;">&#40;</span>e<span style="color: #F78811;">&#41;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> fixDerivation <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    replace<span style="color: #F78811;">&#40;</span>
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>s*:<span style="color: #6666ff; font-weight: bold;">\\</span>s*public<span style="color: #6666ff; font-weight: bold;">\\</span>s+&quot;</span> + regInfo.<span style="color: #000000;">baseClassName</span> + <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\\</span>s*<span style="color: #6666ff; font-weight: bold;">\\</span>{<span style="color: #6666ff; font-weight: bold;">\\</span>s*&quot;</span>,
      <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    : public ComponentImpl&lt;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;          &quot;</span> + regInfo.<span style="color: #000000;">className</span> + <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;        , &quot;</span> + regInfo.<span style="color: #000000;">baseClassName</span> + <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;        , &quot;</span> + regInfo.<span style="color: #000000;">traitClassName</span> + <span style="color: #6666FF;">&quot;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;    &gt;<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span> +
      <span style="color: #6666FF;">&quot;{<span style="color: #6666ff; font-weight: bold;">\r</span><span style="color: #6666ff; font-weight: bold;">\n</span>&quot;</span>
      <span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> fixCppFile <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    removeNDQI
    removeGUIDDecl
    removeFactoryData
    removeGetRegName
    removeSillyInstance
    fixConstructor
    addRegisterMacro
    addTraitImpl
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> fixHFile <span style="color: #000080;">=</span> <span style="color: #F78811;">&#123;</span>
    addTraitDecl
    removeNDQIDecl
    fixDerivation
  <span style="color: #F78811;">&#125;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> fix <span style="color: #F78811;">&#123;</span>
    fixHFile
    fixCppFile
&nbsp;
    writeFile<span style="color: #F78811;">&#40;</span>cppFile, cppText<span style="color: #F78811;">&#41;</span>
    writeFile<span style="color: #F78811;">&#40;</span>hFile, hText<span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">object</span> fixreg <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> main<span style="color: #F78811;">&#40;</span>args <span style="color: #000080;">:</span> Array<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">new</span> Fixer<span style="color: #F78811;">&#40;</span>args<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">0</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>.<span style="color: #000000;">fix</span>
<span style="color: #F78811;">&#125;</span>
&nbsp;
<span style="color: #008000; font-style: italic;">// vi:set ft=scala sts=2 sw=2 ai et:</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/_Eo7BVMEuUA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/10/05/scala-ugly-hairy-rewrite-c-code-jig/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/10/05/scala-ugly-hairy-rewrite-c-code-jig/</feedburner:origLink></item>
		<item>
		<title>Ruby: Remove instances of a method</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/KPZYSbnHTQM/</link>
		<comments>http://www.jigcode.com/2009/09/03/ruby-remove-instances-of-a-method/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 14:24:29 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Jigs]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=143</guid>
		<description><![CDATA[Here&#8217;s an &#8220;old school&#8221; style jig. I first attempted this in Haskell, but I needed Perl-compatible regular expressions (Posix can&#8217;t handle the negative lookahead needed for correctly identifying C-style comments), and installing the PCRE library for Haskell on Windows is painful, though I&#8217;ll get around to it one of these days. &#160; require 'find' &#160; [...]]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s an &#8220;old school&#8221; style jig. I first attempted this in Haskell, but I needed Perl-compatible regular expressions (Posix can&#8217;t handle the negative lookahead needed for correctly identifying C-style comments), and installing the PCRE library for Haskell on Windows is painful, though I&#8217;ll get around to it one of these days.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'find'</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">find</span> <span style="color:#996600;">&quot;Components<span style="color:#000099;">\\</span>CommComponents&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span><span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC00FF; font-weight:bold;">Find</span>.<span style="color:#9900CC;">prune</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC0066; font-weight:bold;">p</span> =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#9900CC;">svn</span>$<span style="color:#006600; font-weight:bold;">/</span>i
  <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#CC0066; font-weight:bold;">p</span> =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#006600; font-weight:bold;">&#40;</span>cpp<span style="color:#006600; font-weight:bold;">|</span>cxx<span style="color:#006600; font-weight:bold;">|</span>h<span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>i
&nbsp;
  data = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span>,<span style="color:#996600;">&quot;rb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> f.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#125;</span>
  orig_data = data.<span style="color:#9900CC;">clone</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC0066; font-weight:bold;">p</span> =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#9900CC;">h</span>$<span style="color:#006600; font-weight:bold;">/</span>
    data.<span style="color:#CC0066; font-weight:bold;">gsub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>
      \s<span style="color:#006600; font-weight:bold;">*</span>
      <span style="color:#006600; font-weight:bold;">&#40;</span>?:^<span style="color:#006600; font-weight:bold;">&#91;</span>\ \t<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\n<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>\n<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span>
      ^<span style="color:#006600; font-weight:bold;">&#91;</span>\ \t<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>?:virtual\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>?HRESULT\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">&#91;</span>A<span style="color:#006600; font-weight:bold;">-</span>Za<span style="color:#006600; font-weight:bold;">-</span>z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span>_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>::<span style="color:#006600; font-weight:bold;">&#41;</span>?GetAttributes\s\<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">*</span>;<span style="color:#006600; font-weight:bold;">&#91;</span>\ \t<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>
      <span style="color:#006600; font-weight:bold;">/</span>mx, <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">elsif</span> <span style="color:#CC0066; font-weight:bold;">p</span> =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#006600; font-weight:bold;">&#40;</span>cpp<span style="color:#006600; font-weight:bold;">|</span>cxx<span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">/</span>
    data.<span style="color:#CC0066; font-weight:bold;">gsub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>
      \s<span style="color:#006600; font-weight:bold;">*</span>
      <span style="color:#006600; font-weight:bold;">&#40;</span>?:\<span style="color:#006600; font-weight:bold;">/</span>\<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>?:<span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">|</span>\<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#40;</span>?!\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span>?\s<span style="color:#006600; font-weight:bold;">*</span>
      HRESULT\s<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#91;</span>A<span style="color:#006600; font-weight:bold;">-</span>Za<span style="color:#006600; font-weight:bold;">-</span>z_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>A<span style="color:#006600; font-weight:bold;">-</span>Za<span style="color:#006600; font-weight:bold;">-</span>z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span>_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>::GetAttributes\s<span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">&#40;</span>\s<span style="color:#006600; font-weight:bold;">*</span>
        ATTRIBUTES\s<span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span>^,<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>,\s<span style="color:#006600; font-weight:bold;">*</span>int\s<span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span>^,<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">&#41;</span>\s<span style="color:#006600; font-weight:bold;">*</span>
        \<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>\<span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#006600; font-weight:bold;">/</span>mx, <span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> data != orig_data
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">p</span>,<span style="color:#996600;">&quot;wb&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span> f.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/KPZYSbnHTQM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/09/03/ruby-remove-instances-of-a-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/09/03/ruby-remove-instances-of-a-method/</feedburner:origLink></item>
		<item>
		<title>Haskell: Filter C++ Classes</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/tLLSzmRinYM/</link>
		<comments>http://www.jigcode.com/2009/08/18/haskell-filter-c-classes/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 02:59:53 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Jigs]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=132</guid>
		<description><![CDATA[I&#8217;ve needed a jig to separate a C++ class&#8217;s declaration and implementation for quite some time. Compile with &#8220;ghc -O2 &#8211;make classfilt.hs&#8221; and invoke with &#8220;classfilt &#8211;impl&#8221; or &#8220;classfilt &#8211;decl&#8221;, piping in the class source with inline methods. It certainly doesn&#8217;t handle all the corners of the C++ language, but it does most of the [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve needed a jig to separate a C++ class&#8217;s declaration and implementation for quite some time. Compile with &#8220;ghc -O2 &#8211;make classfilt.hs&#8221; and invoke with &#8220;classfilt &#8211;impl&#8221; or &#8220;classfilt &#8211;decl&#8221;, piping in the class source with inline methods.  It certainly doesn&#8217;t handle all the corners of the C++ language, but it does most of the job.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> <span style="color: #cccc00; font-weight: bold;">Char</span> <span style="color: green;">&#40;</span>isAlpha<span style="color: #339933; font-weight: bold;">,</span> isDigit<span style="color: #339933; font-weight: bold;">,</span> isSpace<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">Maybe</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Environment <span style="color: green;">&#40;</span>getArgs<span style="color: green;">&#41;</span>
&nbsp;
isCSymF c <span style="color: #339933; font-weight: bold;">=</span> isAlpha c <span style="color: #339933; font-weight: bold;">||</span> c <span style="color: #339933; font-weight: bold;">==</span> <span style="background-color: #3cb371;">'_'</span>
isCSym c  <span style="color: #339933; font-weight: bold;">=</span> isCSymF c <span style="color: #339933; font-weight: bold;">||</span> isDigit c
&nbsp;
spanEscapedQuote q <span style="color: green;">&#40;</span>c:cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">|</span> c <span style="color: #339933; font-weight: bold;">==</span> q <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="color: green;">&#91;</span>c<span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span> cs<span style="color: green;">&#41;</span>
spanEscapedQuote q <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\\</span>'</span>:c:cs<span style="color: green;">&#41;</span>     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> spanEscapedQuote q cs <span style="color: #06c; font-weight: bold;">of</span>
                                       <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\\</span>'</span>:c:t<span style="color: #339933; font-weight: bold;">,</span> r<span style="color: green;">&#41;</span>
spanEscapedQuote q <span style="color: green;">&#40;</span>c:cs<span style="color: green;">&#41;</span>          <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> spanEscapedQuote q cs <span style="color: #06c; font-weight: bold;">of</span>
                                       <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>c:t<span style="color: #339933; font-weight: bold;">,</span> r<span style="color: green;">&#41;</span>
&nbsp;
isNonNLSpace c <span style="color: #339933; font-weight: bold;">=</span> isSpace c <span style="color: #339933; font-weight: bold;">&amp;&amp;</span> c <span style="color: #339933; font-weight: bold;">/=</span> <span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\n</span>'</span>
&nbsp;
maybeLBrace <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>       <span style="color: #339933; font-weight: bold;">=</span> Nothing
maybeLBrace <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'{'</span>:cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> Just <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;{&quot;</span><span style="color: #339933; font-weight: bold;">,</span> cs<span style="color: green;">&#41;</span>
maybeLBrace <span style="color: green;">&#40;</span>c:cs<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">|</span> isSpace c         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> maybeLBrace cs <span style="color: #06c; font-weight: bold;">of</span>
                            Just <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Just <span style="color: green;">&#40;</span>c:t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>
                            Nothing    <span style="color: #339933; font-weight: bold;">-&gt;</span> Nothing
    <span style="color: #339933; font-weight: bold;">|</span> True              <span style="color: #339933; font-weight: bold;">=</span> Nothing
&nbsp;
hasLBrace s <span style="color: #339933; font-weight: bold;">=</span> isJust <span style="color: #339933; font-weight: bold;">$</span> maybeLBrace s
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Primitive C++ lexical scanner.  It knows enough not to get confused by</span>
<span style="color: #5d478b; font-style: italic;">-- things in comments and quotation marks, and things on preprocessor directive</span>
<span style="color: #5d478b; font-style: italic;">-- lines.  It returns a list of pairs, and one invariant is that collecting and</span>
<span style="color: #5d478b; font-style: italic;">-- concatenating all of the 'snd' elements of the pair will return the original</span>
<span style="color: #5d478b; font-style: italic;">-- file.</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">data</span> Token <span style="color: #339933; font-weight: bold;">=</span> Comment
             <span style="color: #339933; font-weight: bold;">|</span> Identifier
             <span style="color: #339933; font-weight: bold;">|</span> LBrace
             <span style="color: #339933; font-weight: bold;">|</span> RBrace
             <span style="color: #339933; font-weight: bold;">|</span> LParen
             <span style="color: #339933; font-weight: bold;">|</span> Semi
             <span style="color: #339933; font-weight: bold;">|</span> OtherStuff
             <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: #cccc00; font-weight: bold;">Eq</span><span style="color: green;">&#41;</span>
&nbsp;
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>           <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'/'</span>:<span style="background-color: #3cb371;">'*'</span>:cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> finishCStyleComment cs <span style="color: #06c; font-weight: bold;">of</span>
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>Comment<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;/*&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> t<span style="color: green;">&#41;</span> : tokens False r
                        <span style="color: #06c; font-weight: bold;">where</span>
                          finishCStyleComment <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'*'</span>:<span style="background-color: #3cb371;">'/'</span>:cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot;*/&quot;</span><span style="color: #339933; font-weight: bold;">,</span> cs<span style="color: green;">&#41;</span>
                          finishCStyleComment <span style="color: green;">&#40;</span>c:cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> finishCStyleComment cs <span style="color: #06c; font-weight: bold;">of</span>
                                                         <span style="color: green;">&#40;</span>s<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>c:s<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'/'</span>:<span style="background-color: #3cb371;">'/'</span>:cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> <span style="font-weight: bold;">span</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">/=</span> <span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\n</span>'</span><span style="color: green;">&#41;</span> cs <span style="color: #06c; font-weight: bold;">of</span>
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\n</span>'</span>:r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>Comment<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;//&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> t <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span><span style="color: green;">&#41;</span> : tokens True r
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>Comment<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;//&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> t<span style="color: green;">&#41;</span> : tokens False r
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'&quot;'</span>:cs<span style="color: green;">&#41;</span>     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> spanEscapedQuote <span style="background-color: #3cb371;">'&quot;'</span> cs <span style="color: #06c; font-weight: bold;">of</span>
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>OtherStuff<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">'&quot;'</span> : t<span style="color: green;">&#41;</span> : tokens False r <span style="color: #5d478b; font-style: italic;">-- &quot;</span>
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\'</span>'</span>:cs<span style="color: green;">&#41;</span>    <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> spanEscapedQuote <span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\'</span>'</span> cs <span style="color: #06c; font-weight: bold;">of</span>
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>OtherStuff<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\'</span>'</span> : t<span style="color: green;">&#41;</span> : tokens False r
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'{'</span>:cs<span style="color: green;">&#41;</span>     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;{&quot;</span><span style="color: green;">&#41;</span> : tokens False cs
tokens <span style="color: #339933; font-weight: bold;">_</span> s
    <span style="color: #339933; font-weight: bold;">|</span> hasLBrace s     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> maybeLBrace s <span style="color: #06c; font-weight: bold;">of</span>
                          Just <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,</span>t<span style="color: green;">&#41;</span> : tokens False r
&nbsp;
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'}'</span>:cs<span style="color: green;">&#41;</span>     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>RBrace<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;}&quot;</span><span style="color: green;">&#41;</span> : tokens False cs
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">';'</span>:cs<span style="color: green;">&#41;</span>     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>Semi<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;;&quot;</span><span style="color: green;">&#41;</span> : tokens False cs
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'('</span>:cs<span style="color: green;">&#41;</span>     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>LParen<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;(&quot;</span><span style="color: green;">&#41;</span> : tokens False cs
&nbsp;
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\n</span>'</span>:cs<span style="color: green;">&#41;</span>    <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>OtherStuff<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span><span style="color: green;">&#41;</span> : tokens True cs
tokens True <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'#'</span>:cs<span style="color: green;">&#41;</span>  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> <span style="font-weight: bold;">span</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">/=</span> <span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\n</span>'</span><span style="color: green;">&#41;</span> cs <span style="color: #06c; font-weight: bold;">of</span>
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\n</span>'</span>:r<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>OtherStuff<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;#&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> t <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;<span style="background-color: #3cb371; font-weight: bold;">\n</span>&quot;</span><span style="color: green;">&#41;</span> : tokens True r
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>OtherStuff<span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;#&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> t<span style="color: green;">&#41;</span> : tokens False r
tokens <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span>c:cs<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">|</span> isCSymF c       <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> <span style="font-weight: bold;">span</span> isCSym cs <span style="color: #06c; font-weight: bold;">of</span>
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>Identifier<span style="color: #339933; font-weight: bold;">,</span> c:t<span style="color: green;">&#41;</span> : tokens False r
    <span style="color: #339933; font-weight: bold;">|</span> isNonNLSpace c  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> <span style="font-weight: bold;">span</span> isNonNLSpace cs <span style="color: #06c; font-weight: bold;">of</span>
                          <span style="color: green;">&#40;</span>t<span style="color: #339933; font-weight: bold;">,</span>r<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#40;</span>OtherStuff<span style="color: #339933; font-weight: bold;">,</span> c:t<span style="color: green;">&#41;</span> : tokens False r
tokens s <span style="color: green;">&#40;</span>c:cs<span style="color: green;">&#41;</span>       <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>OtherStuff<span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>c<span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> : tokens s cs
&nbsp;
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- filter method bodies from class declarations and replace with ';'</span>
rewriteAsClassDeclaration s <span style="color: #339933; font-weight: bold;">=</span>
        rTopLevel <span style="color: #339933; font-weight: bold;">$</span> tokens True s
    <span style="color: #06c; font-weight: bold;">where</span>
        rTopLevel <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>                         <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;&quot;</span>
        rTopLevel <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Identifier<span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;class&quot;</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>  <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;class&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> rClassDecl ts
        rTopLevel <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>                 <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rTopLevel ts
&nbsp;
        rClassDecl <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Semi<span style="color: #339933; font-weight: bold;">,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>             <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rTopLevel ts
        rClassDecl <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>           <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rClassBody ts
        rClassDecl <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>                <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rClassDecl ts
&nbsp;
        rClassBody <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>RBrace<span style="color: #339933; font-weight: bold;">,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>           <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rTopLevel ts
        rClassBody <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>           <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;;&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> rMethodImpl <span style="color: red;">0</span> ts
        rClassBody <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>                <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rClassBody ts
&nbsp;
        rMethodImpl <span style="color: red;">0</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>RBrace<span style="color: #339933; font-weight: bold;">,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>        <span style="color: #339933; font-weight: bold;">=</span> rClassBody ts
        rMethodImpl n <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>RBrace<span style="color: #339933; font-weight: bold;">,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>        <span style="color: #339933; font-weight: bold;">=</span> rMethodImpl <span style="color: green;">&#40;</span>n<span style="color: #339933; font-weight: bold;">+</span><span style="color: red;">1</span><span style="color: green;">&#41;</span> ts
        rMethodImpl n <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>        <span style="color: #339933; font-weight: bold;">=</span> rMethodImpl <span style="color: green;">&#40;</span>n<span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">1</span><span style="color: green;">&#41;</span> ts
        rMethodImpl n <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>             <span style="color: #339933; font-weight: bold;">=</span> rMethodImpl n ts
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- filter everything except method implementations and add class</span>
<span style="color: #5d478b; font-style: italic;">-- name prefix.</span>
&nbsp;
minimumIndentation s <span style="color: #339933; font-weight: bold;">=</span>
        <span style="font-weight: bold;">minimum</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">/=</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> findIndent <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">lines</span> s
    <span style="color: #06c; font-weight: bold;">where</span>
        findIndent <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">' '</span>:cs<span style="color: green;">&#41;</span>  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">1</span> <span style="color: #339933; font-weight: bold;">+</span> findIndent cs
        findIndent <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\t</span>'</span>:cs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">4</span> <span style="color: #339933; font-weight: bold;">+</span> findIndent cs
        findIndent <span style="color: #339933; font-weight: bold;">_</span>         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">0</span>
&nbsp;
unindent n s <span style="color: #339933; font-weight: bold;">=</span>
        <span style="font-weight: bold;">init</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">unlines</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">map</span> <span style="color: green;">&#40;</span>unindentLine n<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">lines</span> s
    <span style="color: #06c; font-weight: bold;">where</span>
        unindentLine n s <span style="color: #339933; font-weight: bold;">|</span> n <span style="color: #339933; font-weight: bold;">&lt;=</span> <span style="color: red;">0</span> <span style="color: #339933; font-weight: bold;">=</span> s
        unindentLine n <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">' '</span>:cs<span style="color: green;">&#41;</span>   <span style="color: #339933; font-weight: bold;">=</span> unindentLine <span style="color: green;">&#40;</span>n<span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">1</span><span style="color: green;">&#41;</span> cs
        unindentLine n <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">'<span style="background-color: #3cb371; font-weight: bold;">\t</span>'</span>:cs<span style="color: green;">&#41;</span>  <span style="color: #339933; font-weight: bold;">=</span> unindentLine <span style="color: green;">&#40;</span>n<span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">4</span><span style="color: green;">&#41;</span> cs
        unindentLine n s          <span style="color: #339933; font-weight: bold;">=</span> s
&nbsp;
reformatMethod name s <span style="color: #339933; font-weight: bold;">=</span> unindent <span style="color: green;">&#40;</span>minimumIndentation s<span style="color: green;">&#41;</span> s
&nbsp;
qualifyMethodName cname s <span style="color: #339933; font-weight: bold;">=</span>
        leader <span style="color: #339933; font-weight: bold;">++</span> cname <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;::&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> methodName
    <span style="color: #06c; font-weight: bold;">where</span>
        methodName <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">reverse</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">takeWhile</span> isCSym <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">dropWhile</span> isSpace <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">reverse</span> s
        leader <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">reverse</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">dropWhile</span> isCSym <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">dropWhile</span> isSpace <span style="color: #339933; font-weight: bold;">$</span> <span style="font-weight: bold;">reverse</span> s
&nbsp;
rewriteAsClassImplementation s <span style="color: #339933; font-weight: bold;">=</span>
        rTopLevel <span style="color: #339933; font-weight: bold;">$</span> tokens True s
    <span style="color: #06c; font-weight: bold;">where</span>
        rTopLevel <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>                                  <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;&quot;</span>
        rTopLevel <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Identifier<span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;class&quot;</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>           <span style="color: #339933; font-weight: bold;">=</span> rClassDecl <span style="background-color: #3cb371;">&quot;class&quot;</span> Nothing ts
        rTopLevel <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span>s<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>                          <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rTopLevel ts
&nbsp;
        rClassDecl s <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>                             <span style="color: #339933; font-weight: bold;">=</span> s
        rClassDecl s <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Semi<span style="color: #339933; font-weight: bold;">,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>                 <span style="color: #339933; font-weight: bold;">=</span> s <span style="color: #339933; font-weight: bold;">++</span> rs <span style="color: #339933; font-weight: bold;">++</span> rTopLevel ts
        rClassDecl s <span style="color: green;">&#40;</span>Nothing<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Identifier<span style="color: #339933; font-weight: bold;">,</span>name<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rClassDecl <span style="color: green;">&#40;</span>s <span style="color: #339933; font-weight: bold;">++</span> name<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>Just name<span style="color: green;">&#41;</span> ts
        rClassDecl s <span style="color: green;">&#40;</span>Just name<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">=</span> rClassBodyStmt name False <span style="background-color: #3cb371;">&quot;&quot;</span> ts
        rClassDecl s maybeName <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>            <span style="color: #339933; font-weight: bold;">=</span> rClassDecl <span style="color: green;">&#40;</span>s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> maybeName ts
&nbsp;
        rClassBodyStmt cname <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Semi<span style="color: #339933; font-weight: bold;">,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>        <span style="color: #339933; font-weight: bold;">=</span> rClassBodyStmt cname False <span style="background-color: #3cb371;">&quot;&quot;</span> ts
        rClassBodyStmt cname <span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">_</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>RBrace<span style="color: #339933; font-weight: bold;">,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>      <span style="color: #339933; font-weight: bold;">=</span> rClassBodySemi ts
        rClassBodyStmt cname <span style="color: #339933; font-weight: bold;">_</span> s <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>     <span style="color: #339933; font-weight: bold;">=</span> rMethodBody cname <span style="color: green;">&#40;</span>s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> <span style="color: red;">0</span> ts
        rClassBodyStmt cname False s <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>LParen<span style="color: #339933; font-weight: bold;">,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rClassBodyStmt cname True <span style="color: green;">&#40;</span>qualifyMethodName cname s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> ts
        rClassBodyStmt cname m s <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Identifier<span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;virtual&quot;</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> rClassBodyStmt cname m s ts
        rClassBodyStmt cname m s <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>          <span style="color: #339933; font-weight: bold;">=</span> rClassBodyStmt cname m <span style="color: green;">&#40;</span>s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> ts
&nbsp;
        rMethodBody name s <span style="color: red;">0</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>RBrace<span style="color: #339933; font-weight: bold;">,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>reformatMethod name <span style="color: #339933; font-weight: bold;">$</span> s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> rClassBodyStmt name False <span style="background-color: #3cb371;">&quot;&quot;</span> ts
        rMethodBody name s n <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>RBrace<span style="color: #339933; font-weight: bold;">,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>         <span style="color: #339933; font-weight: bold;">=</span> rMethodBody name <span style="color: green;">&#40;</span>s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>n<span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">1</span><span style="color: green;">&#41;</span> ts
        rMethodBody name s n <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>LBrace<span style="color: #339933; font-weight: bold;">,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>         <span style="color: #339933; font-weight: bold;">=</span> rMethodBody name <span style="color: green;">&#40;</span>s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>n<span style="color: #339933; font-weight: bold;">+</span><span style="color: red;">1</span><span style="color: green;">&#41;</span> ts
        rMethodBody name s n <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,</span>rs<span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>              <span style="color: #339933; font-weight: bold;">=</span> rMethodBody name <span style="color: green;">&#40;</span>s <span style="color: #339933; font-weight: bold;">++</span> rs<span style="color: green;">&#41;</span> n ts
&nbsp;
        rClassBodySemi <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>Semi<span style="color: #339933; font-weight: bold;">,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>                  <span style="color: #339933; font-weight: bold;">=</span> rTopLevel ts
        rClassBodySemi <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">_,_</span><span style="color: green;">&#41;</span>:ts<span style="color: green;">&#41;</span>                     <span style="color: #339933; font-weight: bold;">=</span> rClassBodySemi ts
&nbsp;
classfilt <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;--decl&quot;</span><span style="color: green;">&#93;</span> s <span style="color: #339933; font-weight: bold;">=</span> rewriteAsClassDeclaration s
classfilt <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;--impl&quot;</span><span style="color: green;">&#93;</span> s <span style="color: #339933; font-weight: bold;">=</span> rewriteAsClassImplementation s
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span> args <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgs
          <span style="font-weight: bold;">interact</span> <span style="color: green;">&#40;</span>classfilt args<span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- vi:set sts=4 sw=4 ai et:</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/tLLSzmRinYM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/08/18/haskell-filter-c-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/08/18/haskell-filter-c-classes/</feedburner:origLink></item>
		<item>
		<title>Erlang: Remove #include directives from all cpp files</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/Zb9-4c0NM_Y/</link>
		<comments>http://www.jigcode.com/2009/08/03/erlang-remove-include-directives-from-all-cpp-files/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 20:54:19 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Jigs]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[erlang]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=128</guid>
		<description><![CDATA[I'm certain this can be done better and with fewer lines of code, but it's my first Erlang jig.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m certain this can be done better and with fewer lines of code, but it&#8217;s my first Erlang jig.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #014ea4;">-</span><span style="color: #5400b3;">module</span><span style="color: #109ab8;">&#40;</span>cppdev<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
<span style="color: #014ea4;">-</span><span style="color: #5400b3;">compile</span><span style="color: #109ab8;">&#40;</span>export_all<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">quote_re</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">quote_re</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span>$<span style="color: #6bb810;">.</span>|Rest<span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff7800;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>.&quot;</span> <span style="color: #014ea4;">++</span> <span style="color: #ff3c00;">quote_re</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Rest</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">quote_re</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">C</span>|Rest<span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">C</span>|<span style="color: #ff3c00;">quote_re</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Rest</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">filter_include</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Data</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Include</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #109ab8;">&#123;</span>ok<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#125;</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">re</span>:<span style="color: #ff3c00;">compile</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff7800;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>s*#<span style="color: #000099; font-weight: bold;">\\</span>s*include<span style="color: #000099; font-weight: bold;">\\</span>s*[&lt;<span style="color: #000099; font-weight: bold;">\&quot;</span>](?:(?i)&quot;</span> <span style="color: #014ea4;">++</span> <span style="color: #ff3c00;">quote_re</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Include</span><span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">++</span> <span style="color: #ff7800;">&quot;)[&gt;<span style="color: #000099; font-weight: bold;">\&quot;</span>]<span style="color: #000099; font-weight: bold;">\\</span>s*$&quot;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #ff3c00;">grep_v</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Data</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">extract_line</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Text</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #186895;">case</span> <span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">splitwith</span><span style="color: #109ab8;">&#40;</span><span style="color: #186895;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">C</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">C</span> <span style="color: #014ea4;">=/=</span> $\n <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Text</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">of</span>
        <span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">Line</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">C</span>|Rest<span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">Line</span> <span style="color: #014ea4;">++</span> <span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">C</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span><span style="color: #45b3e6;">Rest</span><span style="color: #109ab8;">&#125;</span><span style="color: #6bb810;">;</span>
        <span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">Line</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Rest</span><span style="color: #109ab8;">&#125;</span>     <span style="color: #6bb810;">-&gt;</span> <span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">Line</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Rest</span><span style="color: #109ab8;">&#125;</span>
    <span style="color: #186895;">end</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">grep_v</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Data</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff3c00;">grep_v</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Data</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">grep_v</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Accum</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">_</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">flatten</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">reverse</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Accum</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">grep_v</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Accum</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Data</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">Line</span><span style="color: #6bb810;">,</span><span style="color: #45b3e6;">Rest</span><span style="color: #109ab8;">&#125;</span> <span style="color: #014ea4;">=</span> <span style="color: #ff3c00;">extract_line</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Data</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #186895;">case</span> <span style="color: #ff4e18;">re</span>:<span style="color: #ff3c00;">run</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Line</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">of</span>
        <span style="color: #109ab8;">&#123;</span>match<span style="color: #6bb810;">,</span><span style="color: #45b3e6;">_</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">grep_v</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Accum</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Rest</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
        <span style="color: #45b3e6;">_</span>         <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">grep_v</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">Line</span>|Accum<span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Rest</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Pattern</span><span style="color: #109ab8;">&#41;</span>
    <span style="color: #186895;">end</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">transform_file</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Fun</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Filename</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #109ab8;">&#123;</span>ok<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Data</span><span style="color: #109ab8;">&#125;</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">file</span>:<span style="color: #ff3c00;">read_file</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Filename</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	<span style="color: #45b3e6;">NewData</span> <span style="color: #014ea4;">=</span> <span style="color: #fa6fff;">list_to_binary</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">F</span><span style="color: #ff3c00;">un</span><span style="color: #109ab8;">&#40;</span><span style="color: #fa6fff;">binary_to_list</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Data</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	<span style="color: #186895;">if</span>
	  <span style="color: #45b3e6;">Data</span> <span style="color: #014ea4;">=:=</span> <span style="color: #45b3e6;">NewData</span> <span style="color: #6bb810;">-&gt;</span>
        <span style="color: #006600;">nochange</span><span style="color: #6bb810;">;</span>
	  true <span style="color: #6bb810;">-&gt;</span>
        <span style="color: #006600;">ok</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">file</span>:<span style="color: #ff3c00;">write_file</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Filename</span> <span style="color: #014ea4;">++</span> <span style="color: #ff7800;">&quot;-&quot;</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Data</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
        ok <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">file</span>:<span style="color: #ff3c00;">write_file</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Filename</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">NewData</span><span style="color: #109ab8;">&#41;</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">find_files</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Fun</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Root</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #ff3c00;">find_files</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Fun</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">Root</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">find_files</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Accum</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">_</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #45b3e6;">Accum</span><span style="color: #6bb810;">;</span>
<span style="color: #ff3c00;">find_files</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Accum</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Fun</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#91;</span><span style="color: #45b3e6;">Root</span>|RestOfRoots<span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #109ab8;">&#123;</span>ok<span style="color: #6bb810;">,</span><span style="color: #45b3e6;">Files</span><span style="color: #109ab8;">&#125;</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">file</span>:<span style="color: #ff3c00;">list_dir</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Root</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #45b3e6;">Files2</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">filter</span><span style="color: #109ab8;">&#40;</span><span style="color: #186895;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">FN</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff4e18;">string</span>:<span style="color: #ff3c00;">to_lower</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">FN</span><span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">=/=</span> <span style="color: #ff7800;">&quot;.svn&quot;</span> <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Files</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #45b3e6;">PathedFiles</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">map</span><span style="color: #109ab8;">&#40;</span><span style="color: #186895;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">FN</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">Root</span> <span style="color: #014ea4;">++</span> <span style="color: #ff7800;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>&quot;</span> <span style="color: #014ea4;">++</span> <span style="color: #45b3e6;">FN</span> <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Files2</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #45b3e6;">Dirs</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">filter</span><span style="color: #109ab8;">&#40;</span><span style="color: #186895;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">P</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff4e18;">filelib</span>:<span style="color: #ff3c00;">is_dir</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">P</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">PathedFiles</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #45b3e6;">FilteredFiles</span> <span style="color: #014ea4;">=</span> <span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">filter</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Fun</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">PathedFiles</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
    <span style="color: #ff3c00;">find_files</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Accum</span> <span style="color: #014ea4;">++</span> <span style="color: #45b3e6;">FilteredFiles</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Fun</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">RestOfRoots</span> <span style="color: #014ea4;">++</span> <span style="color: #45b3e6;">Dirs</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
&nbsp;
<span style="color: #ff3c00;">fix</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
    <span style="color: #45b3e6;">StripHeaderF</span> <span style="color: #014ea4;">=</span> <span style="color: #186895;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">D</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">filter_include</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">D</span><span style="color: #6bb810;">,</span> <span style="color: #ff7800;">&quot;ISOMsgEx.h&quot;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span>
    <span style="color: #45b3e6;">TransformF</span> <span style="color: #014ea4;">=</span> <span style="color: #186895;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">FN</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">transform_file</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">StripHeaderF</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">FN</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span>
    <span style="color: #45b3e6;">FilenameTestF</span> <span style="color: #014ea4;">=</span> <span style="color: #186895;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">FN</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff4e18;">string</span>:<span style="color: #ff3c00;">to_lower</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff4e18;">string</span>:<span style="color: #ff3c00;">right</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">FN</span><span style="color: #6bb810;">,</span> <span style="color: #ff9600;">4</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">=:=</span> <span style="color: #ff7800;">&quot;.cpp&quot;</span> <span style="color: #186895;">end</span><span style="color: #6bb810;">,</span>
    <span style="color: #ff4e18;">lists</span>:<span style="color: #ff3c00;">map</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">TransformF</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">find_files</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">FilenameTestF</span><span style="color: #6bb810;">,</span> <span style="color: #ff7800;">&quot;Components&quot;</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/Zb9-4c0NM_Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/08/03/erlang-remove-include-directives-from-all-cpp-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/08/03/erlang-remove-include-directives-from-all-cpp-files/</feedburner:origLink></item>
		<item>
		<title>Python: Generate Test Case Stubs For All Classes In A Module</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/uuyHRfIAPdE/</link>
		<comments>http://www.jigcode.com/2009/07/09/python-generate-test-case-stubs-for-all-classes-in-a-module/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 00:39:28 +0000</pubDate>
		<dc:creator>David Andrzejewski</dc:creator>
				<category><![CDATA[Jigs]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=111</guid>
		<description><![CDATA[I had a module full of classes. I wanted to generate a unittest.TestCase stub for every class, such as this: # TODO: Finish this class Test_className&#40;unittest.TestCase&#41;: def setUp&#40;self&#41;: pass So, I wrote the following Python script: if __name__==&#34;__main__&#34;: file = &#34;c:/dev/sourceFile.py&#34; f = open&#40;file, &#34;r&#34;&#41; line = f.readline&#40;&#41; count = 0 thing = &#91; &#93; [...]]]></description>
				<content:encoded><![CDATA[<p>I had a module full of classes.  I wanted to generate a <a href="http://docs.python.org/library/unittest.html#unittest.TestCase">unittest.TestCase</a> stub for every class, such as this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># TODO: Finish this</span>
<span style="color: #ff7700;font-weight:bold;">class</span> Test_className<span style="color: black;">&#40;</span><span style="color: #dc143c;">unittest</span>.<span style="color: black;">TestCase</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> setUp<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span></pre></td></tr></table></div>

<p>So, I wrote the following Python script:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">if</span> __name__<span style="color: #66cc66;">==</span><span style="color: #483d8b;">&quot;__main__&quot;</span>:
    <span style="color: #008000;">file</span> <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">&quot;c:/dev/sourceFile.py&quot;</span>
    f <span style="color: #66cc66;">=</span> <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
    line <span style="color: #66cc66;">=</span> f.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    count <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0</span>
    thing <span style="color: #66cc66;">=</span> <span style="color: black;">&#91;</span> <span style="color: black;">&#93;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">while</span> line:
        <span style="color: #ff7700;font-weight:bold;">if</span> line<span style="color: black;">&#91;</span>:<span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span> <span style="color: #66cc66;">==</span> <span style="color: #483d8b;">&quot;class&quot;</span>:
            count +<span style="color: #66cc66;">=</span> <span style="color: #ff4500;">1</span>
            parenpos <span style="color: #66cc66;">=</span> line.<span style="color: black;">find</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;(&quot;</span><span style="color: black;">&#41;</span>
            classname <span style="color: #66cc66;">=</span> line<span style="color: black;">&#91;</span><span style="color: #ff4500;">6</span>:parenpos<span style="color: black;">&#93;</span>
            thing.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'# TODO: Finish this'</span><span style="color: black;">&#41;</span>
            thing.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'class Test_%s(unittest.TestCase):'</span> % classname<span style="color: black;">&#41;</span>
            thing.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'    def setUp(self):'</span><span style="color: black;">&#41;</span>
            thing.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'        pass'</span><span style="color: black;">&#41;</span>
            thing.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
        line <span style="color: #66cc66;">=</span> f.<span style="color: #dc143c;">readline</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">for</span> item <span style="color: #ff7700;font-weight:bold;">in</span> thing:
        <span style="color: #ff7700;font-weight:bold;">print</span> item</pre></td></tr></table></div>

<p>Just a quick way to save myself some mundane typing.</p>
<img src="http://feeds.feedburner.com/~r/Jigcode/~4/uuyHRfIAPdE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/07/09/python-generate-test-case-stubs-for-all-classes-in-a-module/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/07/09/python-generate-test-case-stubs-for-all-classes-in-a-module/</feedburner:origLink></item>
		<item>
		<title>Scheme: Translate static data from C++ to XML</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/iqmmuxk5siI/</link>
		<comments>http://www.jigcode.com/2009/06/23/scheme-translate-static-data-from-c-to-xml/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 14:13:04 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Jigs]]></category>
		<category><![CDATA[bigloo]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[scheme]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=105</guid>
		<description><![CDATA[The C++ was extracted and munged with vim to make nice Scheme syntax elements before running this script. &#40;with-input-from-file &#34;das.cpp&#34; &#40;lambda &#40;&#41; &#40;do &#40;&#40;field-type &#40;read&#41; &#40;read&#41;&#41; &#40;field-length &#40;read&#41; &#40;read&#41;&#41; &#40;field-description &#40;read&#41; &#40;read&#41;&#41; &#40;bit-number &#40;read&#41; &#40;read&#41;&#41;&#41; &#40;&#40;eof-object? field-type&#41; #f&#41; &#40;printf &#34;&#60;isofield id=\&#34;~a\&#34; length=\&#34;~a\&#34; name=\&#34;~a\&#34; pad=\&#34;true\&#34; class=\&#34;org.jpos.iso.~a\&#34;/&#62;~n&#34; bit-number field-length field-description field-type&#41;&#41;&#41;&#41;]]></description>
				<content:encoded><![CDATA[<p>The C++ was extracted and munged with vim to make nice Scheme syntax elements before running this script.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">with-input-from-file</span> <span style="color: #ff0000;">&quot;das.cpp&quot;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">do</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>field<span style="color: #66cc66;">-</span>type <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>field<span style="color: #66cc66;">-</span><span style="color: #b1b100;">length</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>field<span style="color: #66cc66;">-</span>description <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	  <span style="color: #66cc66;">&#40;</span>bit<span style="color: #66cc66;">-</span>number <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">read</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eof-object?</span> field<span style="color: #66cc66;">-</span>type<span style="color: #66cc66;">&#41;</span> #f<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>printf <span style="color: #ff0000;">&quot;&lt;isofield id=<span style="color: #000099; font-weight: bold;">\&quot;</span>~a<span style="color: #000099; font-weight: bold;">\&quot;</span> length=<span style="color: #000099; font-weight: bold;">\&quot;</span>~a<span style="color: #000099; font-weight: bold;">\&quot;</span> name=<span style="color: #000099; font-weight: bold;">\&quot;</span>~a<span style="color: #000099; font-weight: bold;">\&quot;</span> pad=<span style="color: #000099; font-weight: bold;">\&quot;</span>true<span style="color: #000099; font-weight: bold;">\&quot;</span> class=<span style="color: #000099; font-weight: bold;">\&quot;</span>org.jpos.iso.~a<span style="color: #000099; font-weight: bold;">\&quot;</span>/&gt;~n&quot;</span>
	     bit<span style="color: #66cc66;">-</span>number
	     field<span style="color: #66cc66;">-</span><span style="color: #b1b100;">length</span>
	     field<span style="color: #66cc66;">-</span>description
	     field<span style="color: #66cc66;">-</span>type<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/iqmmuxk5siI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/06/23/scheme-translate-static-data-from-c-to-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/06/23/scheme-translate-static-data-from-c-to-xml/</feedburner:origLink></item>
		<item>
		<title>Java: JFrame tester</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/BexSM_iU8Ac/</link>
		<comments>http://www.jigcode.com/2009/06/18/java-jframe-tester/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 01:34:24 +0000</pubDate>
		<dc:creator>Jason Felice</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=101</guid>
		<description><![CDATA[Our first submission: So here is my silly Java JFrame that I use to test all sorts of things; Swing components, logging frameworks or just to see pretty colors on my screen. Really though, just follow the comments and play with what a JFrame can do. In addition there is a convenient comment that instructs [...]]]></description>
				<content:encoded><![CDATA[<p>Our first submission:<br />
<blockquote>
So here is my silly Java JFrame that I use to test all sorts of things; Swing components, logging frameworks or just to see pretty colors on my screen.</p>
<p>Really though, just follow the comments and play with what a JFrame can do. In addition there is a convenient comment that instructs you where to place your code to make this handy JFrame do something you need it to do.</p>
<p>It only relies on standard Java stuff like Swing and AWT libraries so it should work for most anyone.
</p></blockquote>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.BorderLayout</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Dimension</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.Toolkit</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.KeyEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.KeyListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.awt.event.WindowEvent</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JFrame</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.JLabel</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.swing.WindowConstants</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * It is a Java Swing Window or JFrame to be specific.
 *
 * @author MasterJigger
 *
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JavaTestFrame <span style="color: #000000; font-weight: bold;">extends</span> <span style="color: #003399;">JFrame</span> <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">KeyListener</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> 1L<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> JavaTestFrame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Jigcode Java Test Frame&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        setSize<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Dimension</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">700</span>, <span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>       <span style="color: #666666; font-style: italic;">//This is a usable window size</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Center me on the screen</span>
        <span style="color: #003399;">Toolkit</span> toolkit <span style="color: #339933;">=</span> <span style="color: #003399;">Toolkit</span>.<span style="color: #006633;">getDefaultToolkit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Dimension</span> screenSize <span style="color: #339933;">=</span> toolkit.<span style="color: #006633;">getScreenSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>screenSize.<span style="color: #006633;">width</span> <span style="color: #339933;">-</span> getWidth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>screenSize.<span style="color: #006633;">height</span> <span style="color: #339933;">-</span> getHeight<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
        setLocation<span style="color: #009900;">&#40;</span>x, y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//close and exit when the user request it!</span>
        setDefaultCloseOperation<span style="color: #009900;">&#40;</span><span style="color: #003399;">WindowConstants</span>.<span style="color: #006633;">DISPOSE_ON_CLOSE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                  
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">addWindowListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">awt</span>.<span style="color: #006633;">event</span>.<span style="color: #003399;">WindowAdapter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> windowClosing<span style="color: #009900;">&#40;</span><span style="color: #003399;">WindowEvent</span> winEvt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        addKeyListener<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>              <span style="color: #666666; font-style: italic;">//Lets show keystrokes in the consol for something to do!</span>
&nbsp;
        <span style="color: #008000; font-style: italic; font-weight: bold;">/**
         * This is where the usefulness comes in, place what you need on the JFrame here.
         * Try Swing components out, test logging frameworks, see pretty colors.
         */</span>
        <span style="color: #666666; font-style: italic;">//*********************************************************************************************</span>
        getContentPane<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">setLayout</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BorderLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>               <span style="color: #666666; font-style: italic;">//Setup to put something useful on the JFrame</span>
        add<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">JLabel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello fellow Jigcoders&quot;</span><span style="color: #009900;">&#41;</span>, <span style="color: #003399;">BorderLayout</span>.<span style="color: #006633;">CENTER</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">//Time for something useful</span>
        <span style="color: #666666; font-style: italic;">//*********************************************************************************************</span>
&nbsp;
        setUndecorated<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//false will display frame decorations ha ha! that's what Java says, these are the min/max/close etc on the title bar</span>
        setResizable<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>           <span style="color: #666666; font-style: italic;">//pretty self-explanatory                                             </span>
        setFocusable<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>         <span style="color: #666666; font-style: italic;">//a must have for any good frame</span>
        setVisible<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>              <span style="color: #666666; font-style: italic;">//unless you want to keep this for yourself it should be visible.</span>
        requestFocus<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>              <span style="color: #666666; font-style: italic;">//selfish but necessary</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * @param args
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> JavaTestFrame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                           
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> keyPressed<span style="color: #009900;">&#40;</span><span style="color: #003399;">KeyEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getKeyChar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> keyReleased<span style="color: #009900;">&#40;</span><span style="color: #003399;">KeyEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> keyTyped<span style="color: #009900;">&#40;</span><span style="color: #003399;">KeyEvent</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/BexSM_iU8Ac" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/06/18/java-jframe-tester/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/06/18/java-jframe-tester/</feedburner:origLink></item>
		<item>
		<title>Quick and Dirty WordPress Backup Script (*NIX Shell)</title>
		<link>http://feedproxy.google.com/~r/Jigcode/~3/MVXHNZRx-8I/</link>
		<comments>http://www.jigcode.com/2009/06/11/quick-and-dirty-wordpress-backup-script-nix-shell/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 03:50:56 +0000</pubDate>
		<dc:creator>David Andrzejewski</dc:creator>
				<category><![CDATA[Jigs]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.jigcode.com/?p=81</guid>
		<description><![CDATA[Here&#8217;s a quick and dirty script to back up a wordpress blog.  In fact, it&#8217;s the backup script we use to back up Jigcode.  Of course, all of the hostnames, usernames and passwords have been removed. This runs from a crontab which gets e-mailed to me, so I do an &#8216;ls&#8217; at the end so [...]]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s a quick and dirty script to back up a wordpress blog.  In fact, it&#8217;s the backup script we use to back up Jigcode.  Of course, all of the hostnames, usernames and passwords have been removed.</p>
<p>This runs from a crontab which gets e-mailed to me, so I do an &#8216;ls&#8217; at the end so I can see the fruits of my labor.</p>
<p>A prerequisite is that you set up SSH keys to connect to the host, so you don&#8217;t need to store a plaintext password.</p>
<p>This script runs on <a href="http://www.freebsd.org/">FreeBSD</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tank<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>jigcode
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> wordpress_blog.sql.gz.003
<span style="color: #c20cb9; font-weight: bold;">mv</span> wordpress_blog.sql.gz.002 wordpress_blog.sql.gz.003
<span style="color: #c20cb9; font-weight: bold;">mv</span> wordpress_blog.sql.gz.001 wordpress_blog.sql.gz.002
<span style="color: #c20cb9; font-weight: bold;">mv</span> wordpress_blog.sql.gz wordpress_blog.sql.gz.001
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mysqldump <span style="color: #660033;">-h</span> HOSTNAME <span style="color: #660033;">-uUSERNAME</span> <span style="color: #660033;">-pPASSWORD</span> DATABASENAME <span style="color: #660033;">--complete-insert</span> <span style="color: #660033;">--create-options</span> <span style="color: #000000; font-weight: bold;">&gt;</span> wordpress_blog.sql
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error returned from MYSQLDUMP!&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>rsync <span style="color: #660033;">--del</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">--verbose</span> USERNAME<span style="color: #000000; font-weight: bold;">@</span>HOSTNAME:jigcode <span style="color: #000000; font-weight: bold;">/</span>tank<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>jigcode<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error returned from rsync!&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #660033;">-9</span> wordpress_blog.sql
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error returned from gzip!&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-alth</span> <span style="color: #000000; font-weight: bold;">/</span>tank<span style="color: #000000; font-weight: bold;">/</span>backup<span style="color: #000000; font-weight: bold;">/</span>jigcode</pre></td></tr></table></div>

<img src="http://feeds.feedburner.com/~r/Jigcode/~4/MVXHNZRx-8I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.jigcode.com/2009/06/11/quick-and-dirty-wordpress-backup-script-nix-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.jigcode.com/2009/06/11/quick-and-dirty-wordpress-backup-script-nix-shell/</feedburner:origLink></item>
	</channel>
</rss>
