<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Maris Labs</title>
	<atom:link href="http://marislabs.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://marislabs.org</link>
	<description></description>
	<lastBuildDate>Fri, 10 May 2013 16:18:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Hyperlinking Tracking Numbers in Magento</title>
		<link>http://marislabs.org/2013/04/19/hyperlinking-tracking-numbers-in-magento/</link>
		<comments>http://marislabs.org/2013/04/19/hyperlinking-tracking-numbers-in-magento/#comments</comments>
		<pubDate>Fri, 19 Apr 2013 15:56:09 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=787</guid>
		<description><![CDATA[In: &#60;magento_root&#62;/app/design/frontend/base/default/template/email/order/shipment 1234567891011121314151617181920212223242526272829303132333435363738394041424344&#60;?php /** &#160;* ... all that license bull ... &#160;*/ ?&#62; &#60;?php $_shipment=$this-&#62;getShipment&#40;&#41; ?&#62; &#60;?php $_order=$this-&#62;getOrder&#40;&#41; ?&#62; &#60;?php if &#40;$_shipment &#38;&#38; $_order &#38;&#38; $_shipment-&#62;getAllTracks&#40;&#41;&#41;: ?&#62; &#60;table cellspacing=&#34;0&#34; cellpadding=&#34;0&#34; border=&#34;0&#34; width=&#34;650&#34; style=&#34;border:1px solid #EAEAEA;&#34;&#62; &#160; &#160; &#60;thead&#62; &#160; &#160; &#160; &#160; &#60;tr&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;th align=&#34;left&#34; bgcolor=&#34;#EAEAEA&#34; style=&#34;font-size:13px; padding:3px 9px&#34;&#62;&#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>In:<br />
&lt;magento_root&gt;/app/design/frontend/base/default/template/email/order/shipment</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br /></div></td><td><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009933; font-style: italic;">/**<br />
&nbsp;* ... all that license bull ...<br />
&nbsp;*/</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$_shipment</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getShipment</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$_order</span><span style="color: #339933;">=</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOrder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_shipment</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_order</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_shipment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAllTracks</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: #000000; font-weight: bold;">?&gt;</span><br />
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;650&quot; style=&quot;border:1px solid #EAEAEA;&quot;&gt;<br />
&nbsp; &nbsp; &lt;thead&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th align=&quot;left&quot; bgcolor=&quot;#EAEAEA&quot; style=&quot;font-size:13px; padding:3px 9px&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Shipped By'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/th&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th align=&quot;center&quot; bgcolor=&quot;#EAEAEA&quot; style=&quot;font-size:13px; padding:3px 9px&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tracking Number'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/th&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />
&nbsp; &nbsp; &lt;/thead&gt;<br />
&nbsp; &nbsp; &lt;tbody&gt;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_shipment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAllTracks</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_item</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$service</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$tracking_number</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumber</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$tracking_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$service</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'DHL'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$tracking_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://webtrack.dhlglobalmail.com/?mobile=&amp;trackingnumber='</span><span style="color: #339933;">.</span><span style="color: #000088;">$tracking_number</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'Federal Express'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$tracking_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.fedex.com/Tracking?action=track&amp;tracknumbers='</span><span style="color: #339933;">.</span><span style="color: #000088;">$tracking_number</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'United Parcel Service'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$tracking_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://wwwapps.ups.com/WebTracking/track?track=yes&amp;trackNums='</span><span style="color: #339933;">.</span><span style="color: #000088;">$tracking_number</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'United States Postal Service'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$tracking_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'https://tools.usps.com/go/TrackConfirmAction_input?qtc_tLabels1='</span><span style="color: #339933;">.</span><span style="color: #000088;">$tracking_number</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;tr <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$i</span><span style="color: #339933;">%</span><span style="color:#800080;">2</span>?<span style="color: #0000ff;">'bgcolor=&quot;#F6F6F6&quot;'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td align=&quot;left&quot; valign=&quot;top&quot; style=&quot;padding:3px 9px&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTitle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td align=&quot;center&quot; valign=&quot;top&quot; style=&quot;padding:3px 9px&quot;&gt;&lt;a href = &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$tracking_url</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNumber</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;/tbody&gt;<br />
&lt;/table&gt;<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/04/19/hyperlinking-tracking-numbers-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deal With it</title>
		<link>http://marislabs.org/2013/04/16/deal-with-it/</link>
		<comments>http://marislabs.org/2013/04/16/deal-with-it/#comments</comments>
		<pubDate>Tue, 16 Apr 2013 18:25:11 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[fuckit]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=785</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><img src="http://i.imgur.com/JyoCCab.gif" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/04/16/deal-with-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xstdlib Update v188</title>
		<link>http://marislabs.org/2013/04/14/xstdlib-update-v188/</link>
		<comments>http://marislabs.org/2013/04/14/xstdlib-update-v188/#comments</comments>
		<pubDate>Sun, 14 Apr 2013 20:24:23 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac OS]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=777</guid>
		<description><![CDATA[readfile function has been added to the library. The function will read an entire file and write its contents to another opened file stream. Definition and usage example: 1long long readfile&#40;const char *path, FILE *des&#41; 1234567891011121314/* &#160;* readfile.c &#160;* rashaudteague &#160;* Sun Apr 14 14:20:13 2013 &#160;*/ #include &#60;stdio.h&#62; #include &#60;xstdlib.h&#62; int main&#40;void&#41; &#123; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>readfile function has been added to the library. The function will read an entire file and write its contents to another opened file stream.</p>
<p>Definition and usage example:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">long</span> <span style="color: #993333;">long</span> readfile<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>path<span style="color: #339933;">,</span> FILE <span style="color: #339933;">*</span>des<span style="color: #009900;">&#41;</span></div></td></tr></tbody></table></div>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/*<br />
&nbsp;* readfile.c<br />
&nbsp;* rashaudteague<br />
&nbsp;* Sun Apr 14 14:20:13 2013<br />
&nbsp;*/</span><br />
<br />
<span style="color: #339933;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #339933;">#include &lt;xstdlib.h&gt;</span><br />
<br />
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; readfile<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;fappend.c&quot;</span><span style="color: #339933;">,</span> stdout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Since we are reading from the file &#8220;fappend.c&#8221; and writing to stdout, the contents of &#8220;fappend.c&#8221; will print to the terminal.</p>
<p>Be sure to <a href="http://marislabs.org/projects/extended-standard-library/">DOWNLOAD</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/04/14/xstdlib-update-v188/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Source make code drop&#8230;.</title>
		<link>http://marislabs.org/2013/03/19/source-make-code-drop/</link>
		<comments>http://marislabs.org/2013/03/19/source-make-code-drop/#comments</comments>
		<pubDate>Tue, 19 Mar 2013 01:52:03 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=766</guid>
		<description><![CDATA[123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315/******************************************************************** &#160;* Name: smk.c &#160;* Author: rashaudteague &#160;* Date: 03/09/2013 &#160;* License: GNU GPL &#60;http://www.gnu.org/licenses/&#62; &#160;* Description: &#60;description&#62; &#160;********************************************************************/ #include &#60;unistd.h&#62; #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; #include &#60;string.h&#62; #include &#60;math.h&#62; #include &#60;stdarg.h&#62; #include &#60;sys/stat.h&#62; #include &#60;sys/types.h&#62; #include &#60;sys/fcntl.h&#62; #include &#60;getopt.h&#62; #include &#60;limits.h&#62; #include &#60;time.h&#62; #include &#60;dirent.h&#62; char *substr&#40;const char *s, char *buffer, int start, int length&#41; [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br />240<br />241<br />242<br />243<br />244<br />245<br />246<br />247<br />248<br />249<br />250<br />251<br />252<br />253<br />254<br />255<br />256<br />257<br />258<br />259<br />260<br />261<br />262<br />263<br />264<br />265<br />266<br />267<br />268<br />269<br />270<br />271<br />272<br />273<br />274<br />275<br />276<br />277<br />278<br />279<br />280<br />281<br />282<br />283<br />284<br />285<br />286<br />287<br />288<br />289<br />290<br />291<br />292<br />293<br />294<br />295<br />296<br />297<br />298<br />299<br />300<br />301<br />302<br />303<br />304<br />305<br />306<br />307<br />308<br />309<br />310<br />311<br />312<br />313<br />314<br />315<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">/********************************************************************<br />
&nbsp;* Name: smk.c<br />
&nbsp;* Author: rashaudteague<br />
&nbsp;* Date: 03/09/2013<br />
&nbsp;* License: GNU GPL &lt;http://www.gnu.org/licenses/&gt;<br />
&nbsp;* Description: &lt;description&gt;<br />
&nbsp;********************************************************************/</span><br />
<br />
<span style="color: #339933;">#include &lt;unistd.h&gt;</span><br />
<span style="color: #339933;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span><br />
<span style="color: #339933;">#include &lt;string.h&gt;</span><br />
<span style="color: #339933;">#include &lt;math.h&gt;</span><br />
<span style="color: #339933;">#include &lt;stdarg.h&gt;</span><br />
<span style="color: #339933;">#include &lt;sys/stat.h&gt;</span><br />
<span style="color: #339933;">#include &lt;sys/types.h&gt;</span><br />
<span style="color: #339933;">#include &lt;sys/fcntl.h&gt;</span><br />
<span style="color: #339933;">#include &lt;getopt.h&gt;</span><br />
<span style="color: #339933;">#include &lt;limits.h&gt;</span><br />
<span style="color: #339933;">#include &lt;time.h&gt;</span><br />
<span style="color: #339933;">#include &lt;dirent.h&gt;</span><br />
<br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>substr<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>s<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> start<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; size_t s_len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>length <span style="color: #339933;">&gt;</span> s_len <span style="color: #339933;">||</span> start <span style="color: #339933;">&gt;</span> s_len <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>start <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> start <span style="color: #339933;">=</span> s_len <span style="color: #339933;">+</span> start<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>length <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; start <span style="color: #339933;">=</span> start <span style="color: #339933;">+</span> length<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; length <span style="color: #339933;">*=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>start <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">&amp;&amp;</span> length <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>start <span style="color: #339933;">+</span> length <span style="color: #339933;">&gt;</span> s_len<span style="color: #009900;">&#41;</span> length <span style="color: #339933;">=</span> s_len <span style="color: #339933;">-</span> start<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memcpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> s <span style="color: #339933;">+</span> start<span style="color: #339933;">,</span> length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; length <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; buffer<span style="color: #009900;">&#91;</span>length<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">int</span> strpos<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>needle<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>haystack<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> offset<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> pos <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> haystack_size <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>haystack<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> needle_size <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>needle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>search<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>search <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> needle_size <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf<span style="color: #009900;">&#40;</span>stderr<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;error in malloc in strpos<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exit<span style="color: #009900;">&#40;</span>EXIT_FAILURE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> haystack_size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; substr<span style="color: #009900;">&#40;</span>haystack<span style="color: #339933;">,</span> search<span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> needle_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span>search<span style="color: #339933;">,</span> needle<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>offset <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i <span style="color: #339933;">=</span> i <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>needle_size <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; offset<span style="color: #339933;">--;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; free<span style="color: #009900;">&#40;</span>search<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; free<span style="color: #009900;">&#40;</span>search<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> pos<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str_replace<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>find<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>replace<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>source<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> p <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> c <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t find_len &nbsp; &nbsp;<span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>find<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t replace_len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>replace<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t source_len &nbsp;<span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>c <span style="color: #339933;">=</span> strpos<span style="color: #009900;">&#40;</span>find<span style="color: #339933;">,</span> source<span style="color: #339933;">,</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strncpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">+</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> source<span style="color: #339933;">+</span>p<span style="color: #339933;">,</span> c<span style="color: #339933;">-</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strncpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">+</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> replace<span style="color: #339933;">,</span> replace_len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; p <span style="color: #339933;">=</span> c <span style="color: #339933;">+</span> find_len<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; strncpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">+</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> source<span style="color: #339933;">+</span>p<span style="color: #339933;">,</span> source_len <span style="color: #339933;">-</span> p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; buffer<span style="color: #009900;">&#91;</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>strrev<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; size_t str_size <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> temp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t middle <span style="color: #339933;">=</span> ceil<span style="color: #009900;">&#40;</span>str_size <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> middle<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; temp <span style="color: #339933;">=</span> str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> str<span style="color: #009900;">&#91;</span>str_size <span style="color: #339933;">-</span> i <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; str<span style="color: #009900;">&#91;</span>str_size <span style="color: #339933;">-</span> i <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> temp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> str<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span> strtoupper<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> str_size <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span> strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> str_size<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> toupper<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> str<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">int</span> copy<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>source<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>dest<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> c<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> in<span style="color: #339933;">,</span> out<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> stat fs<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>in <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span>source<span style="color: #339933;">,</span> O_RDONLY<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; stat<span style="color: #009900;">&#40;</span>source<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>fs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>out <span style="color: #339933;">=</span> open<span style="color: #009900;">&#40;</span>dest<span style="color: #339933;">,</span> O_WRONLY <span style="color: #339933;">|</span> O_CREAT<span style="color: #339933;">,</span> fs.<span style="color: #202020;">st_mode</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>read<span style="color: #009900;">&#40;</span>in<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>c<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> write<span style="color: #009900;">&#40;</span>out<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>c<span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; close<span style="color: #009900;">&#40;</span>in<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> close<span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">int</span> file_get_contents<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> filename<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> maxlen<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; FILE <span style="color: #339933;">*</span>fp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fp <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>filename<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> c<span style="color: #339933;">,</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>c <span style="color: #339933;">=</span> getc<span style="color: #009900;">&#40;</span>fp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> EOF <span style="color: #339933;">&amp;&amp;</span> i <span style="color: #339933;">&lt;</span> maxlen<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> buffer<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> c<span style="color: #339933;">;</span> i<span style="color: #339933;">++;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; buffer<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; fclose<span style="color: #009900;">&#40;</span>fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> i<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">int</span> filesize<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> stat fbuf<span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stat<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>fbuf<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> fbuf.<span style="color: #202020;">st_size</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">int</span> file_exists<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> stat fbuf<span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>stat<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>fbuf<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> print_usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;Source maker (smk)<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;options:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;-p, --project make a project, specify the project's name after p option, this will create a new directory<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> \<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;-v, --verbose verbose of the what is going on<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;-h, --help prints program information<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;examples:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;smk c_code.c<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;smk -p myproject c_code.c c_code.h<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;smk c_code.c c_code.h<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;smk script.py &amp;&amp; chmod a+x script.py<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;smk script1.sh script2.sh script3.sh &amp;&amp; chmod a+x *.sh<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<br />
&nbsp; &nbsp; <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Copyright (c) 2009-2013 Maris Labs<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">void</span> open_write_template<span style="color: #009900;">&#40;</span>FILE <span style="color: #339933;">*</span>fp<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>path<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fp <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>path<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Warning: Could not write file %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>data <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> fputs<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> next_option <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>short_options <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;p:vh&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">const</span> <span style="color: #993333;">struct</span> option long_options<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;project&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #ff0000;">'p'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;help&quot;</span><span style="color: #339933;">,</span> &nbsp; &nbsp;<span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #ff0000;">'h'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #ff0000;">&quot;verbose&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #ff0000;">'v'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span>NULL<span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp;<span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> NULL<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span> &nbsp;<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> verbose <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> verbose_buffer<span style="color: #009900;">&#91;</span>LINE_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; memset<span style="color: #009900;">&#40;</span>verbose_buffer<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> LINE_MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> template_buffer<span style="color: #009900;">&#91;</span>LINE_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> content<span style="color: #009900;">&#91;</span>LINE_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> template_path<span style="color: #009900;">&#91;</span>PATH_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> template_path_buffer<span style="color: #009900;">&#91;</span>LINE_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> cwd<span style="color: #009900;">&#91;</span>PATH_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; getcwd<span style="color: #009900;">&#40;</span>cwd<span style="color: #339933;">,</span> PATH_MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>template_path<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s/.smk&quot;</span><span style="color: #339933;">,</span> getenv<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;HOME&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> dirent <span style="color: #339933;">*</span>dp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; DIR <span style="color: #339933;">*</span>dfd<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">struct</span> stat temp_stat<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> var_smk<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;/var/smk&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> var_template<span style="color: #009900;">&#91;</span>PATH_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// the name of the template file from /var/smk</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> dest_template<span style="color: #009900;">&#91;</span>PATH_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// path/to/userhomedir/.smk/template filename</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>file_exists<span style="color: #009900;">&#40;</span>template_path<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Warning: %s does not exist, needed for looking up and loading templates, creating /.smk in ~/.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> template_path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mkdir<span style="color: #009900;">&#40;</span>template_path<span style="color: #339933;">,</span> S_IRUSR <span style="color: #339933;">|</span> S_IWUSR <span style="color: #339933;">|</span> S_IXUSR <span style="color: #339933;">|</span> S_IRGRP <span style="color: #339933;">|</span> S_IXGRP <span style="color: #339933;">|</span> S_IROTH <span style="color: #339933;">|</span> S_IXOTH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>dfd <span style="color: #339933;">=</span> opendir<span style="color: #009900;">&#40;</span>var_smk<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>dp <span style="color: #339933;">=</span> readdir<span style="color: #009900;">&#40;</span>dfd<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span>dp<span style="color: #339933;">-&gt;</span>d_name<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">||</span> strcmp<span style="color: #009900;">&#40;</span>dp<span style="color: #339933;">-&gt;</span>d_name<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;..&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>temp_stat<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> stat<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stat<span style="color: #009900;">&#40;</span>dp<span style="color: #339933;">-&gt;</span>d_name<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>temp_stat<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>temp_stat.<span style="color: #202020;">st_mode</span> <span style="color: #339933;">&amp;</span> S_IFDIR<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>var_template<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s/%s&quot;</span><span style="color: #339933;">,</span> var_smk<span style="color: #339933;">,</span> dp<span style="color: #339933;">-&gt;</span>d_name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>dest_template<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s/%s&quot;</span><span style="color: #339933;">,</span> template_path<span style="color: #339933;">,</span> dp<span style="color: #339933;">-&gt;</span>d_name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>copy<span style="color: #009900;">&#40;</span>var_template<span style="color: #339933;">,</span> dest_template<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chown<span style="color: #009900;">&#40;</span>dest_template<span style="color: #339933;">,</span> getuid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> getgid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Warning: Could not copy %s to %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> var_template<span style="color: #339933;">,</span> template_path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closedir<span style="color: #009900;">&#40;</span>dfd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Warning: could not open %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> var_smk<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>next_option <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; next_option <span style="color: #339933;">=</span> getopt_long<span style="color: #009900;">&#40;</span>argc<span style="color: #339933;">,</span> argv<span style="color: #339933;">,</span> short_options<span style="color: #339933;">,</span> long_options<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span>next_option<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'p'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>verbose_buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>creating project: %s&quot;</span><span style="color: #339933;">,</span> verbose_buffer<span style="color: #339933;">,</span> optarg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>cwd<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s/%s&quot;</span><span style="color: #339933;">,</span> cwd<span style="color: #339933;">,</span> optarg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>file_exists<span style="color: #009900;">&#40;</span>cwd<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mkdir<span style="color: #009900;">&#40;</span>cwd<span style="color: #339933;">,</span> S_IRUSR <span style="color: #339933;">|</span> S_IWUSR <span style="color: #339933;">|</span> S_IXUSR <span style="color: #339933;">|</span> S_IRGRP <span style="color: #339933;">|</span> S_IXGRP <span style="color: #339933;">|</span> S_IROTH <span style="color: #339933;">|</span> S_IXOTH<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'v'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; verbose <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'h'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print_usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'?'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print_usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exit<span style="color: #009900;">&#40;</span>EXIT_FAILURE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">default</span><span style="color: #339933;">:;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> i<span style="color: #339933;">,</span> k<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t argv_len<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> file_ext<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">8</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> c_header<span style="color: #009900;">&#91;</span>NAME_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> file_path<span style="color: #009900;">&#91;</span>NAME_MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; time_t tc<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// tc = time capture</span><br />
&nbsp; &nbsp; time<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>tc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> date<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">32</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; strcpy<span style="color: #009900;">&#40;</span>date<span style="color: #339933;">,</span> ctime<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>tc<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; date<span style="color: #009900;">&#91;</span>strlen<span style="color: #009900;">&#40;</span>date<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; FILE <span style="color: #339933;">*</span>fp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// create the files</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>verbose_buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>creating source file: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> verbose_buffer<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>file_path<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s/%s&quot;</span><span style="color: #339933;">,</span> cwd<span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">//find and read the template</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; memset<span style="color: #009900;">&#40;</span>file_ext<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; argv_len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> argv_len <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> k <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">&amp;&amp;</span> argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #208080;">0x2E</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--,</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file_ext<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strrev<span style="color: #009900;">&#40;</span>file_ext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; memset<span style="color: #009900;">&#40;</span>template_buffer<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> LINE_MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>template_path_buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s/%s_template&quot;</span><span style="color: #339933;">,</span> template_path<span style="color: #339933;">,</span> file_ext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>verbose_buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>using template: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> verbose_buffer<span style="color: #339933;">,</span> template_path_buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>file_get_contents<span style="color: #009900;">&#40;</span>template_path_buffer<span style="color: #339933;">,</span> template_buffer<span style="color: #339933;">,</span> LINE_MAX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>strcmp<span style="color: #009900;">&#40;</span>file_ext<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;h&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strtoupper<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset<span style="color: #009900;">&#40;</span>c_header<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> NAME_MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str_replace<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;_&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> c_header<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcat<span style="color: #009900;">&#40;</span>c_header<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;_&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy<span style="color: #009900;">&#40;</span>argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> c_header<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset<span style="color: #009900;">&#40;</span>content<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> LINE_MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str_replace<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$filename&quot;</span><span style="color: #339933;">,</span> argv<span style="color: #009900;">&#91;</span>optind<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> template_buffer<span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy<span style="color: #009900;">&#40;</span>template_buffer<span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> memset<span style="color: #009900;">&#40;</span>content<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> LINE_MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str_replace<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$author&quot;</span><span style="color: #339933;">,</span> getenv<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;USER&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> template_buffer<span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy<span style="color: #009900;">&#40;</span>template_buffer<span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> memset<span style="color: #009900;">&#40;</span>content<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> LINE_MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; str_replace<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;$date&quot;</span><span style="color: #339933;">,</span> date<span style="color: #339933;">,</span> template_buffer<span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; open_write_template<span style="color: #009900;">&#40;</span>fp<span style="color: #339933;">,</span> file_path<span style="color: #339933;">,</span> content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; open_write_template<span style="color: #009900;">&#40;</span>fp<span style="color: #339933;">,</span> file_path<span style="color: #339933;">,</span> NULL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf<span style="color: #009900;">&#40;</span>verbose_buffer<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\t</span>Warning: Could not load template %s_template<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> verbose_buffer<span style="color: #339933;">,</span> file_ext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fp <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span> fclose<span style="color: #009900;">&#40;</span>fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; optind<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>verbose<span style="color: #009900;">&#41;</span> <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> verbose_buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/03/19/source-make-code-drop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Source Maker 2000</title>
		<link>http://marislabs.org/2013/03/10/source-maker-2000/</link>
		<comments>http://marislabs.org/2013/03/10/source-maker-2000/#comments</comments>
		<pubDate>Sun, 10 Mar 2013 16:34:51 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=731</guid>
		<description><![CDATA[I&#8217;ve reprogrammed a simple tool to create source files with coding templates in the command line. It now executes faster and it&#8217;s easier to install. Download Source Maker 2000 For systems that are UNIX-like. Installation 1) Unpack the source maker. 2) Go to the source_maker directory and run this command: sudo ./install.sh Uninstallation 1) Return [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve reprogrammed a simple tool to create source files with coding templates in the command line. It now executes faster and it&#8217;s easier to install. <a href="http://marislabs.org/dl.php?f=source_maker2020.tar.gz">Download Source Maker 2000</a></p>
<p>For systems that are UNIX-like.</p>
<p><strong>Installation</strong></p>
<p>1) Unpack the source maker.<br />
2) Go to the source_maker directory and run this command: sudo ./install.sh</p>
<p><strong>Uninstallation</strong></p>
<p>1) Return to the source maker downloaded package<br />
2) Run: sudo ./uninstall.sh</p>
<p><strong>Usage Report</strong></p>
<p>Source maker (smk)<br />
options:<br />
-p, &#8211;project make a project, specify the project&#8217;s name after p option, this will create a new directory<br />
-v, &#8211;verbose verbose of the what is going on<br />
-h, &#8211;help prints program information</p>
<p>examples:<br />
smk c_code.c<br />
smk -p myproject c_code.c c_code.h<br />
smk c_code.c c_code.h<br />
smk script.py &#038;&#038; chmod a+x script.py<br />
smk script1.sh script2.sh script3.sh &#038;&#038; chmod a+x *.sh</p>
<p>Copyright (c) 2009-2013 Maris Labs</p>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/03/10/source-maker-2000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>str_replace at the low level</title>
		<link>http://marislabs.org/2013/03/09/str_replace-at-the-low-level/</link>
		<comments>http://marislabs.org/2013/03/09/str_replace-at-the-low-level/#comments</comments>
		<pubDate>Sat, 09 Mar 2013 23:47:01 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=721</guid>
		<description><![CDATA[It uses strpos from the eXtended Standard C Library. 1234567891011121314char *str_replace&#40;const char *find, const char *replace, const char *source, char *buffer&#41; &#123; &#160; &#160; int i = 0, p = 0, c = 0; &#160; &#160; size_t find_len &#160; &#160;= strlen&#40;find&#41;; &#160; &#160; size_t replace_len = strlen&#40;replace&#41;; &#160; &#160; size_t source_len &#160;= strlen&#40;source&#41;; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>It uses strpos from the <a href="http://marislabs.org/projects/extended-standard-library/">eXtended Standard C Library</a>.</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str_replace<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>find<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>replace<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>source<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> p <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> c <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t find_len &nbsp; &nbsp;<span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>find<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t replace_len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>replace<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t source_len &nbsp;<span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>source<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>c <span style="color: #339933;">=</span> strpos<span style="color: #009900;">&#40;</span>find<span style="color: #339933;">,</span> source<span style="color: #339933;">,</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strncpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">+</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> source<span style="color: #339933;">+</span>p<span style="color: #339933;">,</span> c<span style="color: #339933;">-</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strncpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">+</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> replace<span style="color: #339933;">,</span> replace_len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; p <span style="color: #339933;">=</span> c <span style="color: #339933;">+</span> find_len<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; strncpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">+</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> source<span style="color: #339933;">+</span>p<span style="color: #339933;">,</span> source_len <span style="color: #339933;">-</span> p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; buffer<span style="color: #009900;">&#91;</span>strlen<span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Usage:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#define BUF_SIZE 255</span><br />
<br />
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> text<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">255</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot; finding all spaces in this string is a fun, i guess? &quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> buf<span style="color: #009900;">&#91;</span>BUF_SIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; memset<span style="color: #009900;">&#40;</span>buf<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> BUF_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; str_replace<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;==&quot;</span><span style="color: #339933;">,</span> text<span style="color: #339933;">,</span> buf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;buf = <span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> buf<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Output:</p>
<p>buf = &#8220;==finding==all==spaces==in==this==string==is==a==fun,==i==guess?==&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/03/09/str_replace-at-the-low-level/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixed file() memory leak and access violations</title>
		<link>http://marislabs.org/2013/03/09/fixed-file-memory-leak-and-access-violations/</link>
		<comments>http://marislabs.org/2013/03/09/fixed-file-memory-leak-and-access-violations/#comments</comments>
		<pubDate>Sat, 09 Mar 2013 02:43:08 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=707</guid>
		<description><![CDATA[New function definition: 123456789101112131415161718192021222324252627282930313233343536int file&#40;const char * filename, char *elements&#91;&#93;, unsigned char flags&#41; &#123; &#160; &#160; int line_count = 0; &#160; &#160; &#160; &#160; FILE *fp; &#160; &#160; if &#40;&#40;fp = fopen&#40;filename, &#34;r&#34;&#41;&#41; == NULL&#41; return -1; &#160; &#160; char *s; &#160; &#160; size_t s_len; &#160; &#160; &#160; &#160; while &#40;!feof&#40;fp&#41;&#41; &#123; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>New function definition:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">int</span> file<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> filename<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>elements<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> flags<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> line_count <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; FILE <span style="color: #339933;">*</span>fp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>fp <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span>filename<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>s<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; size_t s_len<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>feof<span style="color: #009900;">&#40;</span>fp<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>s <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span> calloc<span style="color: #009900;">&#40;</span>LINE_MAX<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose<span style="color: #009900;">&#40;</span>fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; fgets<span style="color: #009900;">&#40;</span>s<span style="color: #339933;">,</span> LINE_MAX<span style="color: #339933;">,</span> fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; s_len <span style="color: #339933;">=</span> strlen<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>flags <span style="color: #339933;">&amp;</span> FILE_NO_FLAGS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>flags <span style="color: #339933;">&amp;</span> FILE_SKIP_EMPTY_LINES<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> s_len <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; free<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> s <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>flags <span style="color: #339933;">&amp;</span> FILE_IGNORE_NEW_LINES<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> s_len <span style="color: #339933;">&gt;</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#91;</span>s_len <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #ff0000;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #009900;">&#41;</span> s<span style="color: #009900;">&#91;</span>s_len <span style="color: #339933;">-</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; elements<span style="color: #009900;">&#91;</span>line_count<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> s<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; line_count<span style="color: #339933;">++;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; fclose<span style="color: #009900;">&#40;</span>fp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> line_count<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Valgrind memory diagnostic report:</p>
<pre>
==62234== Memcheck, a memory error detector
==62234== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==62234== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==62234== Command: ./program
==62234==
--62234-- ./program:
--62234-- dSYM directory is missing; consider using --dsymutil=yes
The most useful information for each sync...
sync path = *******
sync path = *******
sync path = *******
==62234==
==62234== HEAP SUMMARY:
==62234==     in use at exit: 6,069 bytes in 33 blocks
==62234==   total heap usage: 41 allocs, 8 frees, 24,501 bytes allocated
==62234==
==62234== LEAK SUMMARY:
==62234==    definitely lost: 0 bytes in 0 blocks
==62234==    indirectly lost: 0 bytes in 0 blocks
==62234==      possibly lost: 0 bytes in 0 blocks
==62234==    still reachable: 6,069 bytes in 33 blocks
==62234==         suppressed: 0 bytes in 0 blocks
==62234== Rerun with --leak-check=full to see details of leaked memory
==62234==
==62234== For counts of detected and suppressed errors, rerun with: -v
==62234== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/03/09/fixed-file-memory-leak-and-access-violations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>str_pad() new to xstdlib</title>
		<link>http://marislabs.org/2013/03/04/str_pad-new-to-xstdlib/</link>
		<comments>http://marislabs.org/2013/03/04/str_pad-new-to-xstdlib/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 02:00:46 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=694</guid>
		<description><![CDATA[I added a new function for the xstdlib, &#8220;str_pad()&#8221;. It&#8217;s similar to PHP&#8217;s str_pad. Pad a string to a certain length with another string. Definition: 123456789101112131415161718192021222324252627char *str_pad&#40;const char *str, char *buffer, unsigned int pad_length, const char *pad_str, unsigned short pad_type&#41; &#123; &#160; &#160; int str_size = &#40;int&#41;strlen&#40;str&#41;; &#160; &#160; int pad_str_size = &#40;int&#41;strlen&#40;pad_str&#41;; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>I added a new function for the xstdlib, &#8220;str_pad()&#8221;. It&#8217;s similar to PHP&#8217;s str_pad.</p>
<p>Pad a string to a certain length with another string.</p>
<p>Definition:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str_pad<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> pad_length<span style="color: #339933;">,</span> <span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>pad_str<span style="color: #339933;">,</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">short</span> pad_type<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> str_size <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> pad_str_size <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>strlen<span style="color: #009900;">&#40;</span>pad_str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> pads <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>pad_length <span style="color: #339933;">-</span> str_size<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> pad_str_size<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> left_over <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>pad_length <span style="color: #339933;">-</span> str_size<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> pads <span style="color: #339933;">*</span> pad_str_size<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> i<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>str_size <span style="color: #339933;">==</span> pad_length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> strcpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pad_type <span style="color: #339933;">==</span> STR_PAD_BOTH<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> pads <span style="color: #339933;">/=</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span> pad_type <span style="color: #339933;">|=</span> STR_PAD_LEFT <span style="color: #339933;">|</span> STR_PAD_RIGHT<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pad_type <span style="color: #339933;">&amp;</span> STR_PAD_LEFT<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strcpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> pad_str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> pads<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> strcat<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> pad_str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>pad_type <span style="color: #339933;">&amp;</span> STR_PAD_RIGHT<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> strncat<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> pad_str<span style="color: #339933;">,</span> left_over<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strcat<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pad_type <span style="color: #339933;">&amp;</span> STR_PAD_RIGHT<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>pad_type <span style="color: #339933;">&amp;</span> STR_PAD_LEFT<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> strcpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> pads<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> strncat<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> pad_str<span style="color: #339933;">,</span> pad_str_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; strncat<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> pad_str<span style="color: #339933;">,</span> left_over<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; buffer<span style="color: #009900;">&#91;</span>pad_length<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Usage:</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #339933;">#include &lt;string.h&gt;</span><br />
<span style="color: #339933;">#include &lt;xstdlib.h&gt;</span><br />
<br />
<span style="color: #339933;">#define NAME_STR_SIZE 16</span><br />
<br />
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> name<span style="color: #009900;">&#91;</span>NAME_STR_SIZE<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Rashaud&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> padded_name<span style="color: #009900;">&#91;</span>NAME_STR_SIZE<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; str_pad<span style="color: #009900;">&#40;</span>name<span style="color: #339933;">,</span> padded_name<span style="color: #339933;">,</span> NAME_STR_SIZE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;_&quot;</span><span style="color: #339933;">,</span> STR_PAD_LEFT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;padded_name &nbsp; &nbsp; = %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> padded_name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;padded_str_size = %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>strlen<span style="color: #009900;">&#40;</span>padded_name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Output:</p>
<p>padded_name = _________Rashaud<br />
padded_str_size = 16</p>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/03/04/str_pad-new-to-xstdlib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic object attributes (properties) Python (DOAP)</title>
		<link>http://marislabs.org/2013/03/02/dynamic-object-attributes-properties-python-doap/</link>
		<comments>http://marislabs.org/2013/03/02/dynamic-object-attributes-properties-python-doap/#comments</comments>
		<pubDate>Sat, 02 Mar 2013 02:58:32 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=689</guid>
		<description><![CDATA[12345678910111213141516171819202122232425262728293031323334#!/usr/bin/python ################################################################ # Name: dynamic_class.py # Version: &#60;version&#62; # Author: rashaudteague # Date: 03/01/2013 # License: GNU GPL &#60;http://www.gnu.org/licenses/&#62; # Copy: Copyright (c) 2013 Unknown # Description: &#60;description&#62; ################################################################# # a class called &#34;User&#34; with absolutely nothing (no properties, no methods... nothing) class User: &#160; &#160; pass # pretend user_data is coming from a database [...]]]></description>
			<content:encoded><![CDATA[<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span><br />
<br />
<span style="color: #808080; font-style: italic;">################################################################</span><br />
<span style="color: #808080; font-style: italic;"># Name: dynamic_class.py</span><br />
<span style="color: #808080; font-style: italic;"># Version: &lt;version&gt;</span><br />
<span style="color: #808080; font-style: italic;"># Author: rashaudteague</span><br />
<span style="color: #808080; font-style: italic;"># Date: 03/01/2013</span><br />
<span style="color: #808080; font-style: italic;"># License: GNU GPL &lt;http://www.gnu.org/licenses/&gt;</span><br />
<span style="color: #808080; font-style: italic;"># Copy: Copyright (c) 2013 Unknown</span><br />
<span style="color: #808080; font-style: italic;"># Description: &lt;description&gt;</span><br />
<span style="color: #808080; font-style: italic;">#################################################################</span><br />
<br />
<span style="color: #808080; font-style: italic;"># a class called &quot;User&quot; with absolutely nothing (no properties, no methods... nothing)</span><br />
<span style="color: #ff7700;font-weight:bold;">class</span> User:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">pass</span><br />
<br />
<span style="color: #808080; font-style: italic;"># pretend user_data is coming from a database or something and not really getting assigned here</span><br />
<span style="color: #808080; font-style: italic;"># already assigned and indexed... whatever</span><br />
user_data = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span><br />
user_data<span style="color: black;">&#91;</span><span style="color: #483d8b;">'name'</span><span style="color: black;">&#93;</span> &nbsp; &nbsp; = <span style="color: #483d8b;">'Mike Jones'</span><br />
user_data<span style="color: black;">&#91;</span><span style="color: #483d8b;">'username'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'mjones'</span><br />
user_data<span style="color: black;">&#91;</span><span style="color: #483d8b;">'phone'</span><span style="color: black;">&#93;</span> &nbsp; &nbsp;= <span style="color: #483d8b;">'281-330-8004'</span><br />
<br />
<span style="color: #808080; font-style: italic;"># instantiate the class</span><br />
u = User<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># now &quot;dynamically&quot; add properties to the User class</span><br />
<span style="color: #ff7700;font-weight:bold;">for</span> k,v <span style="color: #ff7700;font-weight:bold;">in</span> user_data.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:<br />
&nbsp; &nbsp; <span style="color: #008000;">setattr</span><span style="color: black;">&#40;</span>u, k, v<span style="color: black;">&#41;</span><br />
<br />
<span style="color: #808080; font-style: italic;"># test print 1 or 2 of these from the 'u' object</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> u.<span style="color: black;">name</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> u.<span style="color: black;">username</span><br />
<span style="color: #ff7700;font-weight:bold;">print</span> u.<span style="color: black;">phone</span></div></td></tr></tbody></table></div>
<p>Outputs:</p>
<p>Mike Jones<br />
mjones<br />
281-330-8004</p>
<p>Instead of assigning them tediously like:</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">u.<span style="color: black;">name</span> &nbsp; &nbsp; = <span style="color: #483d8b;">'Mike Jones'</span><br />
u.<span style="color: black;">username</span> = <span style="color: #483d8b;">'mjones'</span><br />
u.<span style="color: black;">phone</span> &nbsp; &nbsp;= <span style="color: #483d8b;">'281-330-8004'</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/03/02/dynamic-object-attributes-properties-python-doap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concaving Strings in C</title>
		<link>http://marislabs.org/2013/02/17/concaving-strings-in-c/</link>
		<comments>http://marislabs.org/2013/02/17/concaving-strings-in-c/#comments</comments>
		<pubDate>Sun, 17 Feb 2013 21:10:03 +0000</pubDate>
		<dc:creator>Rashaud Teague</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://marislabs.org/?p=671</guid>
		<description><![CDATA[Ever want to shorten a string if it&#8217;s too long but do not want to cut off the beginning or end of it? Concave the string. 1234567891011121314151617181920212223242526272829303132333435363738#include &#60;stdio.h&#62; #include &#60;string.h&#62; #define STR_SIZE_LIMIT 25 char *str_concave&#40;const char *str, char *buffer, int size_limit&#41; &#123; &#160; &#160; int str_size = &#40;int&#41;strlen&#40;str&#41;; &#160; &#160; &#160; &#160; if &#40;str_size &#60;= [...]]]></description>
			<content:encoded><![CDATA[<p>Ever want to shorten a string if it&#8217;s too long but do not want to cut off the beginning or end of it?</p>
<p>Concave the string.</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:500px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">#include &lt;stdio.h&gt;</span><br />
<span style="color: #339933;">#include &lt;string.h&gt;</span><br />
<br />
<span style="color: #339933;">#define STR_SIZE_LIMIT 25</span><br />
<br />
<span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str_concave<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>str<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span>buffer<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> size_limit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> str_size <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>strlen<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>str_size <span style="color: #339933;">&lt;=</span> size_limit<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> strcpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> str<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> half <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>size_limit <span style="color: #339933;">/</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> i <span style="color: #339933;">=</span> half<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> left_over <span style="color: #339933;">=</span> size_limit <span style="color: #339933;">%</span> <span style="color: #0000dd;">2</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> apposition_size <span style="color: #339933;">=</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">int</span> end <span style="color: #339933;">=</span> half <span style="color: #339933;">-</span> apposition_size <span style="color: #339933;">+</span> left_over<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; memcpy<span style="color: #009900;">&#40;</span>buffer<span style="color: #339933;">,</span> str<span style="color: #339933;">,</span> half<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; memcpy<span style="color: #009900;">&#40;</span>buffer <span style="color: #339933;">+</span> half<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;...&quot;</span><span style="color: #339933;">,</span> apposition_size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* add the apposition */</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i <span style="color: #339933;">+=</span> apposition_size<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; memcpy<span style="color: #009900;">&#40;</span>buffer <span style="color: #339933;">+</span> i<span style="color: #339933;">,</span> str <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>str_size <span style="color: #339933;">-</span> half<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> apposition_size <span style="color: #339933;">-</span> left_over<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> end<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> i <span style="color: #339933;">+=</span> end<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; buffer<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'<span style="color: #006699; font-weight: bold;">\0</span>'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> buffer<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> old_string<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">64</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;The black fox jumped over the whatever, I forgot the phrase!&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> new_string<span style="color: #009900;">&#91;</span>STR_SIZE_LIMIT<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; str_concave<span style="color: #009900;">&#40;</span>old_string<span style="color: #339933;">,</span> new_string<span style="color: #339933;">,</span> STR_SIZE_LIMIT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> old_string<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> new_string<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>strlen(old_string) = %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>strlen<span style="color: #009900;">&#40;</span>old_string<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;strlen(new_string) = %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>strlen<span style="color: #009900;">&#40;</span>new_string<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Output:</p>
<p>The black fox jumped over the whatever, I forgot the phrase!<br />
The black fo&#8230;he phrase!</p>
<p>strlen(old_string) = 60<br />
strlen(new_string) = 25</p>
]]></content:encoded>
			<wfw:commentRss>http://marislabs.org/2013/02/17/concaving-strings-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
