<?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>~chuck/blog &#187; programming</title>
	<atom:link href="http://www.ozymo.com/explosions/tag/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ozymo.com</link>
	<description>What more could you want?</description>
	<lastBuildDate>Tue, 17 Oct 2023 03:57:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Teensy ELF executables</title>
		<link>http://www.ozymo.com/explosions/321</link>
		<comments>http://www.ozymo.com/explosions/321#comments</comments>
		<pubDate>Wed, 17 Mar 2010 06:13:34 +0000</pubDate>
		<dc:creator>chuck</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[compiling]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ozymo.com/?p=321</guid>
		<description><![CDATA[Holy crap. I wish I was at awesome as systems programming as this guy. /cs]]></description>
			<content:encoded><![CDATA[<p>Holy crap. I wish I was at awesome as systems programming as <a title="Teensy ELF executables" href="http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html" target="_blank">this guy</a>.</p>
<p>/cs</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozymo.com/explosions/321/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>warning: incompatible implicit declaration of built-in function ‘strlen’</title>
		<link>http://www.ozymo.com/explosions/22</link>
		<comments>http://www.ozymo.com/explosions/22#comments</comments>
		<pubDate>Sun, 02 Mar 2008 20:31:30 +0000</pubDate>
		<dc:creator>chuck</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[compiling]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.ozymo.com/~chuck/blog/2008/03/02/warning-incompatible-implicit-declaration-of-built-in-function-%e2%80%98strlen%e2%80%99/</guid>
		<description><![CDATA[This is an error presented by the GNU Compiler Collection (which I still like to call the GNU C Compiler) when compiling a piece of code that calls to a function in the &#60;string.h&#62; header file if it cannot find the function. Typically, this is caused by a call to the strlen function when the]]></description>
			<content:encoded><![CDATA[<p>This is an error presented by the <a title="GNU C Compiler, and others" href="http://gcc.gnu.org/" target="_blank">GNU Compiler Collection</a> (which I still like to call the GNU <a title="The K&amp;R Book Homepage" href="http://cm.bell-labs.com/cm/cs/cbook/" target="_blank">C</a> Compiler) when compiling a piece of code that calls to a function in the &lt;string.h&gt; <a title="Wikipedia article on Header Files" href="http://en.wikipedia.org/wiki/Header_file" target="_blank">header file</a> if it cannot find the function.</p>
<p>Typically, this is caused by a call to the strlen function when the &lt;string.h&gt; header has not been included.</p>
<blockquote><p><strong>$ grep &#8216;#include&#8217; whiteout.c</strong><br />
#include &lt;stdio.h&gt;<br />
<strong> $ gcc -o ../whiteout whiteout.c</strong><br />
whiteout.c: In function ‘trim’:<br />
whiteout.c:49: warning: incompatible implicit declaration of built-in function ‘strlen’<br />
whiteout.c: In function ‘add’:<br />
whiteout.c:64: warning: incompatible implicit declaration of built-in function ‘strlen’</p>
<p><strong>$ grep &#8216;#include&#8217; whiteout.c</strong><br />
#include &lt;stdio.h&gt;<br />
#include &lt;string.h&gt;<br />
<strong>$ gcc -o ../whiteout whiteout.c</strong><br />
$</p></blockquote>
<p>As you can see, simply placing the statement &#8216;#include &lt;string.h&gt;&#8217; into your includes section of your code will alleviate the issue.</p>
<p>/cs</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozymo.com/explosions/22/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adding Arguments to your Scripts</title>
		<link>http://www.ozymo.com/explosions/8</link>
		<comments>http://www.ozymo.com/explosions/8#comments</comments>
		<pubDate>Tue, 05 Feb 2008 07:10:37 +0000</pubDate>
		<dc:creator>chuck</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.ozymo.com/~chuck/blog/?p=8</guid>
		<description><![CDATA[I like bash. It is simple and straight forward. In the words of Master Foo, &#8220;Is it he who writes the ten thousand lines, or he who, perceiving the emptiness of the task, gains merit by not coding?&#8221; One of the easiest things to do in a bash script that has more than one function]]></description>
			<content:encoded><![CDATA[<p>I like bash.</p>
<p>It is simple and straight forward. In the words of <a href="http://www.catb.org/~esr/writings/unix-koans/" title="The Cathedral and the Bazaar">Master Foo</a>, &#8220;<span class="quote">Is it he who writes the ten thousand lines, or he who, perceiving the emptiness of the task, gains merit by not coding?&#8221;</span></p>
<p>One of the easiest things to do in a bash script that has more than one function is to add the capability of the script to allow arguments to specify it&#8217;s action.</p>
<p><span id="more-8"></span> You&#8217;ll notice, if you look at an init script (for instance, /etc/init.d/httpd on a Red Hat server), that roughly this same method is used to allow for arguments like &#8220;start&#8221; and &#8220;stop&#8221; et al.</p>
<p>I was working on an <a href="http://www.linuxfromscratch.org/" title="Best Linux Tutorial Ever">LFS</a> installation, and scripted a little foo to get the sources and patches without having to manually download each one.  Basically, it used this command to parse the pages with the listings of source tarballs or patches, and find the URL:</p>
<blockquote><p>lynx -source file:///home/chuck/src/lfs-clfs/book/ppc/materials/packages.html | grep -A1 Download: | grep -v Download: | awk -F&#8217;&#8221;&#8216; &#8216;{print $2}&#8217; | grep -v &#8216;^$</p></blockquote>
<p>As you can see, I downloaded the book source so that I wouldn&#8217;t spam their site (a little Internet courtesy).  I was presented with a list of links to source files.  Hooray!</p>
<p>I expanded into cross-compiling linux for a PPC laptop I had laying around, and ended up needing to expand my script to be able to tell it which sources and patches to download.  After a little <a href="http://www.oreilly.com/catalog/bash3/index.html" title="Bash - every noob's nightmare">research</a>, I came across the &#8220;case&#8221; control statement.  In the case statement, I was able to specify which sources and/or patches I wanted by adding an argument to the script.  Here is the case statement:</p>
<blockquote><p> case $1 in<br />
gens)<br />
ARGS=$GENERAL_SOURCES<br />
;;<br />
genp)<br />
ARGS=$GENERAL_PATCHES<br />
;;<br />
ppcs)<br />
ARGS=$PPC_SOURCES<br />
;;<br />
ppcp)<br />
ARGS=$PPC_PATCHES<br />
;;<br />
all)<br />
ARGS=`echo $GENERAL_SOURCES $GENERAL_PATCHES $PPC_SOURCES $PPC_PATCHES`<br />
;;<br />
*)<br />
ARGS=&#8221;"<br />
;;<br />
esac</p></blockquote>
<p>As an added bonus, you can see that on the last argument (denoted by &#8220;*)&#8221;), I was able to catch all other arguments besides the ones I specified.  If the argument didn&#8217;t match what was supposed to be there, it would set the $ARGS variable to NULL, or &#8220;&#8221;.</p>
<p>With a little &#8220;if/else&#8221; statement, I then was able to specify that if the $ARGS variable had no value, to echo the usage of the script, or else run the command and download my sources.</p>
<p>Bear in mind, though that the $ARGS variable should be subject to some pretty good input checking before putting a script like this into production, because someone could easily hack it:</p>
<blockquote><p>$ ARGS=&#8221;(rm -rf /)&#8221;; ./script.sh</p></blockquote>
<p>WARNING: do NOT run the above command, as your box will be broke!  I will not fix it for you!  You&#8217;ve been warned!</p>
<p>/cs</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ozymo.com/explosions/8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
