
| Current Path : /usr/share/doc/libcaca-dev/html/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //usr/share/doc/libcaca-dev/html/libcaca-style.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>libcaca documentation</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Generated by Doxygen 1.8.17 -->
</div><!-- top -->
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Libcaca coding style </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="sty1"></a>
General guidelines</h1>
<p>A pretty safe rule of thumb is: look at what has already been done and try to do the same.</p>
<ul>
<li>Tabulations should be avoided and replaced with <em>eight</em> spaces.</li>
<li>Indentation is generally 4 spaces.</li>
<li>Lines should wrap at most at 79 characters.</li>
<li>Do not leave whitespace at the end of lines.</li>
<li>Do not use multiple spaces for anything else than indentation.</li>
<li>Code qui fait des warnings == code de porc == deux baffes dans ta gueule</li>
</ul>
<h1><a class="anchor" id="sty2"></a>
C coding style</h1>
<p>Try to use short names whenever possible (<code>i</code> for indices, <code>w</code> for width, <code>cv</code> for canvas...). Macros are always uppercase, variable and function names are always lowercase. Use the underscore to separate words within names:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#define BROKEN 0</span></div>
<div class="line"><span class="preprocessor">#define MAX(x, y) ((x > y) ? (x) : (y))</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> x, y, w, h;</div>
<div class="line"><span class="keywordtype">char</span> *font_name;</div>
<div class="line"><span class="keywordtype">void</span> frobulate_every_three_seconds(<span class="keywordtype">void</span>);</div>
</div><!-- fragment --><p><code>const</code> is a <em>suffix</em>. It's <code>char</code> <code>const</code> <code>*foo</code>, not <code>const</code> <code>char</code> <code>*foo</code>.</p>
<p>Use spaces after commas and between operators. Do not use spaces after an opening parenthesis or before a closing one:</p>
<div class="fragment"><div class="line">a += 2;</div>
<div class="line">b = (a * (c + d));</div>
<div class="line">x = min(x1, x2, x3);</div>
</div><!-- fragment --><p>Do not put a space between functions and the corresponding opening parenthesis:</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> <span class="keyword">function</span>(int);</div>
</div><!-- fragment --><p>A space can be inserted after keywords such as <code>for</code>, <code>while</code> or <code>if</code>, but consistency with the rest of the page is encouraged:</p>
<div class="fragment"><div class="line"><span class="keywordflow">if</span>(a == b)</div>
<div class="line"> <span class="keywordflow">return</span>;</div>
<div class="line"> </div>
<div class="line"><span class="keywordflow">if</span> (p == NULL)</div>
</div><!-- fragment --><p>Do not put parentheses around return values:</p>
<div class="fragment"><div class="line"><span class="keywordflow">return</span> a + (b & x) + d[10];</div>
</div><!-- fragment --><p>Opening braces should be on a line of their own, aligned with the current block. Braces are optional for one-liners:</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> <span class="keyword">function</span>(<span class="keywordtype">int</span> a)</div>
<div class="line">{</div>
<div class="line"> <span class="keywordflow">if</span>(a & 0x84)</div>
<div class="line"> <span class="keywordflow">return</span> a;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>(a < 0)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">return</span> -a;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> {</div>
<div class="line"> a /= 2;</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">switch</span>(a)</div>
<div class="line"> {</div>
<div class="line"> <span class="keywordflow">case</span> 0:</div>
<div class="line"> <span class="keywordflow">case</span> 1:</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> <span class="keywordflow">break</span>;</div>
<div class="line"> <span class="keywordflow">default</span>:</div>
<div class="line"> <span class="keywordflow">return</span> a;</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line">}</div>
</div><!-- fragment --><h1><a class="anchor" id="sty3"></a>
C++ coding style</h1>
<p>Nothing here yet. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</body>
</html>