<?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>Ish &#187; Uncategorized</title>
	<atom:link href="http://unx.ca/log/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://unx.ca/log</link>
	<description></description>
	<lastBuildDate>Thu, 22 Apr 2010 17:28:25 +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>Back to the Mac</title>
		<link>http://unx.ca/log/2010/04/22/back-to-the-mac/</link>
		<comments>http://unx.ca/log/2010/04/22/back-to-the-mac/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 17:28:25 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macbook]]></category>

		<guid isPermaLink="false">http://unx.ca/log/?p=77</guid>
		<description><![CDATA[Recent issues with Linux on a laptop has given me the desire to try working on a Mac again. Even though I have a pretty well supported laptop (Lenovo x61), its the little issues that have begun to bother me which include not great sleep/suspend support, wireless and audio issues and an almost never ending [...]]]></description>
			<content:encoded><![CDATA[<p>Recent issues with Linux on a laptop has given me the desire to try working on a Mac again.  Even though I have a pretty well supported laptop (Lenovo x61), its the little issues that have begun to bother me which include not great sleep/suspend support, wireless and audio issues and an almost never ending stream of updates.  Yes, you Linux people may say it works fine, but if you&#8217;ve ever used a Mac before you&#8217;ll know its not as good as a could be, by far.</p>
<p>I&#8217;ve also found that its really nice to have the real Microsoft Office handy when you swap documents with other non-Linux using people (yeah, OpenOffice doesn&#8217;t quite cut it when taking turns editing documents) which meant often having a Windows VM running.</p>
<p>The other factor that helps the Mac be a viable option is the majority of the software I develop already builds and installs on a Mac, or can do so with very minor modifications.  The stuff that doesn&#8217;t is so tied to a specific environment that it really requires a virtual machine even when running Linux as the host operating system.  This really makes the Mac sound like an ideal system.</p>
<p>So yesterday while heading out just before dinner to grab some hamburger buns I walked by the local Mac retailer (hey, its about 20 steps from Safeway) and grabbed a high-res 15&#8243; MacBook with the Core i5 2.53ghz processor.  They weren&#8217;t able to upgrade the ram to 8GB on the spot but I decided I couldn&#8217;t wait.</p>
<p>Aesthetically its a beautiful machine.  The display is about the best computer display I&#8217;ve ever seen.  The 3 primary pieces of software I work on compile out of the box.  Its also nice to have Microsoft Office running natively.  The thing that drove me away from the Mac before was some of the UI behaviours, like Cmd-Tab switching applications, not just windows of applications.  But I&#8217;m going to give this a true go and may update this blog now and then with issues that I run into as a developer, developing network-level apps primarily for Linux, making the shift to Mac as a development platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://unx.ca/log/2010/04/22/back-to-the-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FVWM: Moving a Window to Another Screen</title>
		<link>http://unx.ca/log/2009/10/07/fvwm-moving-a-window-to-another-screen/</link>
		<comments>http://unx.ca/log/2009/10/07/fvwm-moving-a-window-to-another-screen/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 20:34:47 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fvwm]]></category>
		<category><![CDATA[multiple displays]]></category>
		<category><![CDATA[multiple monitors]]></category>

		<guid isPermaLink="false">http://unx.ca/log/?p=39</guid>
		<description><![CDATA[Probably the most lacking feature in most multi-screen setups is the ability to move a window from one screen to another with a keyboard shortcut. I do this to bring the window I&#8217;m currently working on into my centre monitor so its directly in front of me. There are 2 ways to go about this. [...]]]></description>
			<content:encoded><![CDATA[<p>Probably the most lacking feature in most multi-screen setups is the ability to move a window from one screen to another with a keyboard shortcut.  I do this to bring the window I&#8217;m currently working on into my centre monitor so its directly in front of me.  There are 2 ways to go about this.  The first is moving a window to a specific display and the second is to move (shift) the window to the left or right display (which would just be back and forth in a dual monitor setup).</p>
<p>For the first case you could define the following function:</p>
<div class="code".>
# This function will move a window to the X screen provided in the<br />
# first argument.  If the window is in the maximized it will be taken<br />
# out of the maximized state before moving.  If we don&#8217;t do this it<br />
# will be moved back to the original screen when the maximized state<br />
# is toggled.<br />
#<br />
# If you do not want the pointer to be moved to the windows new<br />
# location then comment out the line containing WarpToWindow.<br />
DestroyFunc MoveWindowToScreen<br />
AddToFunc MoveWindowToScreen<br />
+ I Current (Maximized) Maximize<br />
+ I SetEnv PWX $[pointer.wx]<br />
+ I Setenv PWY $[pointer.wy]<br />
+ I MoveToScreen $[0]<br />
+ I WindowId $[w.id] WarpToWindow $[PWX]p $[PWY]p
</div>
<p>And then add the following to your window operations menu:</p>
<div class="code">
+ &#8220;&amp;1 Move to Screen 1&#8243; MoveWindowToScreen 2<br />
+ &#8220;&amp;2 Move to Screen 2&#8243; MoveWindowToScreen 0<br />
+ &#8220;&amp;3 Move to Screen 3&#8243; MoveWindowToScreen 1
</div>
<p>Note that the argument you provide to the MoveWindowToScreen function takes the X display number which may not directly map to the order of the screens on your desk.</p>
<p>The second method is to move the screen to the left or the right.  Or in the case of a dual monitor setup you could just continually move right to have the window flip/flop between your 2 screens.</p>
<p>First download the following file and save it to ~/.fvwm/ShiftToScreen.py: <a href='http://unx.ca/log/wp-content/uploads/2009/10/ShiftToScreen_py.txt'>ShiftToScreen.py</a><br />
You will also need to update variables <i>screenWidth</i> and <i>screens</i> in ShiftToScreen.py as they are currently setup for my configuration of 3 screens with a width of 1920 pixels each.</p>
<p>Then define the following function:</p>
<div class="code">
# This function will move a window to the left or right screen<br />
# depending on the first argument which should be on of &#8220;left&#8221; or<br />
# &#8220;right&#8221;.  It depends on the auxiliary python script<br />
# ShiftToScreen.py.<br />
DestroyFunc ShiftToScreen<br />
AddToFunc ShiftToScreen<br />
+ I Current (Maximized) Maximize<br />
+ I SetEnv PWX $[pointer.wx]<br />
+ I Setenv PWY $[pointer.wy]<br />
+ I PipeRead &#8220;python $./ShiftToScreen.py $[0] $[w.x]&#8221;<br />
+ I WindowId $[w.id] WarpToWindow $[PWX]p $[PWY]p
</div>
<p>You could then add the following to your windows operations menu:</p>
<div class="code">
+ &#8220;&#038;Left Screen&#8221;       ShiftToScreen left<br />
+ &#8220;&#038;Right Screen&#8221;	ShiftToScreen right
</div>
<p>or define some keyboard shortcuts.  For example I have bound Shift-Alt-Left and Shift-Alt-Right to shift the window to the left or right screen:</p>
<div class="code">
Key Left WTSF12468 SM ShiftToScreen left<br />
Key Right WTSF12468 SM ShiftToScreen right
</div>
<p>If you are only working with 2 screens you will only need to define one shortcut to get flip/flop like behaviour as shifting left beyond the leftmost screen will wrap the window around to the right most screen.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://unx.ca/log/2009/10/07/fvwm-moving-a-window-to-another-screen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ideal Multi-Monitor Setup</title>
		<link>http://unx.ca/log/2009/09/22/ideal-multi-monitor-setup/</link>
		<comments>http://unx.ca/log/2009/09/22/ideal-multi-monitor-setup/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 21:36:20 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fvwm]]></category>
		<category><![CDATA[multiple displays]]></category>
		<category><![CDATA[multiple monitors]]></category>

		<guid isPermaLink="false">http://unx.ca/log/?p=37</guid>
		<description><![CDATA[Multi-monitor configurations are great but I think they leave out some usability aspects that could really make life easier for the keyboard user. When I was just using dual displays I really wanted keyboard shortcuts to do the following: * Move a window from one screen to the other. * Swap what is seen on [...]]]></description>
			<content:encoded><![CDATA[<p>Multi-monitor configurations are great but I think they leave out some usability aspects that could really make life easier for the keyboard user.  When I was just using dual displays I really wanted keyboard shortcuts to do the following:</p>
<p>* Move a window from one screen to the other.<br />
* Swap what is seen on each display.</p>
<p>When I moved to 3 monitors my needs changed a little.</p>
<p>* Shift a window to the screen to the left or the right, rotating around.<br />
* Swap a display with the one to the left or the right.<br />
* Shift all displays to the left or the right.</p>
<p>This would make it extremely fast to move the window you are currently working on to your primary display, then push it back to where it came from.  Or swap the contents of your right screen with your centre screen if you need to shift your work focus for a while.</p>
<p>As far as I know this is not possible with Windows, Mac or most Linux configurations.  However, I believe using FVWM as your Linux (ok, *nix) window manager will make this all possible, at least my experiments with dual screens have been positive.  I&#8217;ll update this blog with various functions that should make all of the above achievable.</p>
]]></content:encoded>
			<wfw:commentRss>http://unx.ca/log/2009/09/22/ideal-multi-monitor-setup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making that Caps-Lock key an extra Control key</title>
		<link>http://unx.ca/log/2009/03/16/making-that-caps-lock-key-an-extra-control-key/</link>
		<comments>http://unx.ca/log/2009/03/16/making-that-caps-lock-key-an-extra-control-key/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 06:05:56 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[xmodmap]]></category>

		<guid isPermaLink="false">http://unx.ca/log/?p=10</guid>
		<description><![CDATA[Yes, covered everywhere and I&#8217;ve done it enough time I should know it off by heart now&#8230;  I used to swap caps and control, but now I just make the caps an additional control and leave the original control as is&#8230; ~/.xmodmap snippet: remove Lock = Caps_Lock keysym Caps_Lock = Control_L add Control = Control_L]]></description>
			<content:encoded><![CDATA[<p>Yes, covered everywhere and I&#8217;ve done it enough time I should know it off by heart now&#8230;  I used to swap caps and control, but now I just make the caps an additional control and leave the original control as is&#8230;</p>
<p>~/.xmodmap snippet:</p>
<p style="padding-left: 30px;">remove Lock = Caps_Lock<br />
keysym Caps_Lock = Control_L<br />
add Control = Control_L</p>
]]></content:encoded>
			<wfw:commentRss>http://unx.ca/log/2009/03/16/making-that-caps-lock-key-an-extra-control-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moved to Victoria</title>
		<link>http://unx.ca/log/2009/03/15/moved-to-victoria/</link>
		<comments>http://unx.ca/log/2009/03/15/moved-to-victoria/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 05:53:46 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://unx.ca/log/?p=5</guid>
		<description><![CDATA[Just a quick update to let everyone know that we are no longer live in Saskatoon but haved moved out to Victoria, BC.]]></description>
			<content:encoded><![CDATA[<p>Just a quick update to let everyone know that we are no longer live in Saskatoon but haved moved out to Victoria, BC.</p>
]]></content:encoded>
			<wfw:commentRss>http://unx.ca/log/2009/03/15/moved-to-victoria/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://unx.ca/log/2008/10/12/hello-world/</link>
		<comments>http://unx.ca/log/2008/10/12/hello-world/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 09:45:00 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://unx.ca/log/?p=1</guid>
		<description><![CDATA[Due to catatstrophic failures over at vpsville.ca I&#8217;m left without a server.  This was the first time I completely removed myself from managing my own servers, and it hasn&#8217;t turned out well.  Oh well, I think I will move to managed services for the next little while.]]></description>
			<content:encoded><![CDATA[<p>Due to catatstrophic failures over at vpsville.ca I&#8217;m left without a server.  This was the first time I completely removed myself from managing my own servers, and it hasn&#8217;t turned out well.  Oh well, I think I will move to managed services for the next little while.</p>
]]></content:encoded>
			<wfw:commentRss>http://unx.ca/log/2008/10/12/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TAILQ Example</title>
		<link>http://unx.ca/log/2006/08/19/tailq-example/</link>
		<comments>http://unx.ca/log/2006/08/19/tailq-example/#comments</comments>
		<pubDate>Sat, 19 Aug 2006 17:43:26 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tailq]]></category>

		<guid isPermaLink="false">http://unx.ca/log/?p=14</guid>
		<description><![CDATA[[Reposted on May 1, 2009 - recovered from old blog.] I plan to use this blog to post codebits that I find myself sending to people over and over again. The first example is how to use a TAILQ from sys/queue.h found on the BSDs. Many Linux distributions also have sys/queue.h but may be missing [...]]]></description>
			<content:encoded><![CDATA[<p>[Reposted on May 1, 2009 - recovered from old blog.]</p>
<p>I plan to use this blog to post codebits that I find myself sending to people over and over again. The first example is how to use a TAILQ from sys/queue.h found on the BSDs. Many Linux distributions also have sys/queue.h but may be missing certain macros such as TAILQ_FOREACH(). At the very least I hope this enticies some newer C programmer to use queue.h rather than rolling their own linked list. I’ll jump directly to the code as I feel it is more or less self explanatory.</p>
<p>The following code can be downloaded <a href="/log/wp-content/uploads/2006/08/tailq_ex.tar.gz"><span style="text-decoration: underline;"><span style="color: #810081;">here</span></span></a>.</p>
<div style="border: solid; border-width: 1px; background: lightgrey">
<font face="monospace"><br />
<font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;* TAILQ example program.</font><br />
<font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font></p>
<p><font color="#a020f0">#include </font><font color="#ff00ff">&lt;stdlib.h&gt;</font><br />
<font color="#a020f0">#include </font><font color="#ff00ff">&lt;stdio.h&gt;</font></p>
<p><font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;* On many OpenBSD/NetBSD/FreeBSD you could include &lt;sys/queue.h&gt;, but</font><br />
<font color="#0000ff">&nbsp;* for portability we&#8217;ll include the local copy.</font><br />
<font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font><br />
<font color="#a020f0">#include </font><font color="#ff00ff">&quot;queue.h&quot;</font></p>
<p><font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;* This structure defines each item in our tail queue.&nbsp;&nbsp;It must also</font><br />
<font color="#0000ff">&nbsp;* contain an item (TAILQ_ENTRY) that points to the next and previous</font><br />
<font color="#0000ff">&nbsp;* items in the tail queue.</font><br />
<font color="#0000ff">&nbsp;*</font><br />
<font color="#0000ff">&nbsp;* For simplicity, we will be creating a list of integers.</font><br />
<font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font><br />
<font color="#2e8b57"><b>struct</b></font>&nbsp;tailq_entry {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;value;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * This holds the pointers to the next and previous entries in</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the tail queue.</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_ENTRY(tailq_entry) entries;<br />
};</p>
<p><font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;* Our tail queue requires a head, this is defined using the</font><br />
<font color="#0000ff">&nbsp;* TAILQ_HEAD macro.</font><br />
<font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font><br />
TAILQ_HEAD(, tailq_entry) my_tailq_head;</p>
<p><font color="#2e8b57"><b>int</b></font><br />
main(<font color="#2e8b57"><b>int</b></font>&nbsp;argc, <font color="#2e8b57"><b>char</b></font>&nbsp;**argv)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Define a pointer to an item in the tail queue. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>struct</b></font>&nbsp;tailq_entry *item;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;In some cases we have to track a temporary item. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>struct</b></font>&nbsp;tailq_entry *tmp_item;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;i;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Initialize the tail queue. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_INIT(&amp;my_tailq_head);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Add 10 items to the tailq queue. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>&nbsp;(i = <font color="#ff00ff">0</font>; i &lt; <font color="#ff00ff">10</font>; i++) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Each item we want to add to the tail queue must be</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * allocated.</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item = malloc(<font color="#a52a2a"><b>sizeof</b></font>(*item));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>&nbsp;(item == <font color="#ff00ff">NULL</font>) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perror(<font color="#ff00ff">&quot;malloc failed&quot;</font>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(<font color="#ff00ff">EXIT_FAILURE</font>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Set the value. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;item-&gt;value = i;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Add our item to the end of tail queue. The first</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * argument is a pointer to the head of our tail</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * queue, the second is the item we want to add, and</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * the third argument is the name of the struct</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * variable that points to the next and previous items</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * in the tail queue.</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_INSERT_TAIL(&amp;my_tailq_head, item, entries);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Traverse the tail queue forward. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;Forward traversal: &quot;</font>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_FOREACH(item, &amp;my_tailq_head, entries) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;</font><font color="#6a5acd">%d</font><font color="#ff00ff">&nbsp;&quot;</font>, item-&gt;value);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Insert a new item after the item with value 5. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;Adding new item after 5: &quot;</font>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_FOREACH(item, &amp;my_tailq_head, entries) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>&nbsp;(item-&gt;value == <font color="#ff00ff">5</font>) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>struct</b></font>&nbsp;tailq_entry *new_item =<br />
&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;malloc(<font color="#a52a2a"><b>sizeof</b></font>(*new_item));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>&nbsp;(new_item == <font color="#ff00ff">NULL</font>) {<br />
&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;perror(<font color="#ff00ff">&quot;malloc failed&quot;</font>);<br />
&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;exit(<font color="#ff00ff">EXIT_FAILURE</font>);<br />
&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new_item-&gt;value = <font color="#ff00ff">10</font>;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_INSERT_AFTER(&amp;my_tailq_head, item, new_item,<br />
&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;entries);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>break</b></font>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Do another forward traversal to show the newly added item. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_FOREACH(item, &amp;my_tailq_head, entries) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;</font><font color="#6a5acd">%d</font><font color="#ff00ff">&nbsp;&quot;</font>, item-&gt;value);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * Delete the item with the value 3.</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * We can&#8217;t use TAILQ_FOREACH here as TAILQ_FOREACH is not</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * safe against deletions during the traversal.&nbsp;&nbsp;Some variants</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * of queue.h have TAILQ_FOREACH_MUTABLE or TAILQ_FOREACH_SAFE</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * which are safe against deletions.</font><br />
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;Deleting item with value 3: &quot;</font>);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>&nbsp;(item = TAILQ_FIRST(&amp;my_tailq_head); item != <font color="#ff00ff">NULL</font>; item = tmp_item)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp_item = TAILQ_NEXT(item, entries);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>&nbsp;(item-&gt;value == <font color="#ff00ff">3</font>) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Remove the item from the tail queue. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_REMOVE(&amp;my_tailq_head, item, entries);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Free the item as we don&#8217;t need it anymore. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;free(item);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>break</b></font>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Another forward traversal to show that the value 3 is now gone. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_FOREACH(item, &amp;my_tailq_head, entries) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;</font><font color="#6a5acd">%d</font><font color="#ff00ff">&nbsp;&quot;</font>, item-&gt;value);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;Free the entire tail queue. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>while</b></font>&nbsp;(item = TAILQ_FIRST(&amp;my_tailq_head)) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TAILQ_REMOVE(&amp;my_tailq_head, item, entries);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;free(item);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/*</font><font color="#0000ff">&nbsp;The tail queue should now be empty. </font><font color="#0000ff">*/</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>&nbsp;(!TAILQ_EMPTY(&amp;my_tailq_head))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<font color="#ff00ff">&quot;tail queue is NOT empty!</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;<font color="#ff00ff">0</font>;<br />
}<br />
</font>
</div>
]]></content:encoded>
			<wfw:commentRss>http://unx.ca/log/2006/08/19/tailq-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
